finished filter ui

This commit is contained in:
Ellpeck 2020-04-16 15:19:13 +02:00
parent 0cc6dfc3b7
commit 3409945c77
3 changed files with 35 additions and 2 deletions

View file

@ -1,6 +1,9 @@
package de.ellpeck.prettypipes.misc; package de.ellpeck.prettypipes.misc;
import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.PrettyPipes;
import de.ellpeck.prettypipes.packets.PacketButton;
import de.ellpeck.prettypipes.packets.PacketHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui; import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.inventory.ContainerScreen; import net.minecraft.client.gui.screen.inventory.ContainerScreen;
@ -11,6 +14,9 @@ import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.inventory.container.Slot; import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.util.INBTSerializable; import net.minecraftforge.common.util.INBTSerializable;
@ -50,10 +56,20 @@ public class ItemFilter extends ItemStackHandler {
Supplier<String> whitelistText = () -> I18n.format("info." + PrettyPipes.ID + "." + (this.isWhitelist ? "whitelist" : "blacklist")); Supplier<String> whitelistText = () -> I18n.format("info." + PrettyPipes.ID + "." + (this.isWhitelist ? "whitelist" : "blacklist"));
return Collections.singletonList( return Collections.singletonList(
new Button(x, y, 80, 20, whitelistText.get(), button -> { new Button(x, y, 80, 20, whitelistText.get(), button -> {
// TODO actually make whitelist button work PacketHandler.sendToServer(new PacketButton(BlockPos.ZERO, PacketButton.ButtonResult.FILTER_CHANGE, 0));
this.onButtonPacket(0);
button.setMessage(whitelistText.get());
})); }));
} }
public void onButtonPacket(int id) {
// whitelist
if (id == 0) {
this.isWhitelist = !this.isWhitelist;
}
this.save();
}
public boolean isAllowed(ItemStack stack) { public boolean isAllowed(ItemStack stack) {
for (int i = 0; i < this.getSlots(); i++) { for (int i = 0; i < this.getSlots(); i++) {
ItemStack other = this.getStackInSlot(i); ItemStack other = this.getStackInSlot(i);
@ -83,4 +99,8 @@ public class ItemFilter extends ItemStackHandler {
super.deserializeNBT(nbt); super.deserializeNBT(nbt);
this.isWhitelist = nbt.getBoolean("whitelist"); this.isWhitelist = nbt.getBoolean("whitelist");
} }
public interface IFilteredContainer {
ItemFilter getFilter();
}
} }

View file

@ -2,6 +2,8 @@ package de.ellpeck.prettypipes.packets;
import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.Utility;
import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.items.IModule;
import de.ellpeck.prettypipes.misc.ItemFilter;
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
import de.ellpeck.prettypipes.pipe.PipeTileEntity; import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
@ -84,6 +86,11 @@ public class PacketButton {
buf.writeInt(data[0]); buf.writeInt(data[0]);
}); });
} }
}),
FILTER_CHANGE((pos, data, player) -> {
IFilteredContainer container = (IFilteredContainer) player.openContainer;
ItemFilter filter = container.getFilter();
filter.onButtonPacket(data[0]);
}); });
public final TriConsumer<BlockPos, int[], PlayerEntity> action; public final TriConsumer<BlockPos, int[], PlayerEntity> action;

View file

@ -1,6 +1,7 @@
package de.ellpeck.prettypipes.pipe.extraction; package de.ellpeck.prettypipes.pipe.extraction;
import de.ellpeck.prettypipes.misc.ItemFilter; import de.ellpeck.prettypipes.misc.ItemFilter;
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.ContainerType;
@ -9,7 +10,7 @@ import net.minecraft.util.math.BlockPos;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class ExtractionModuleContainer extends AbstractPipeContainer<ExtractionModuleItem> { public class ExtractionModuleContainer extends AbstractPipeContainer<ExtractionModuleItem> implements IFilteredContainer {
public ItemFilter filter; public ItemFilter filter;
@ -29,4 +30,9 @@ public class ExtractionModuleContainer extends AbstractPipeContainer<ExtractionM
super.onContainerClosed(playerIn); super.onContainerClosed(playerIn);
this.filter.save(); this.filter.save();
} }
@Override
public ItemFilter getFilter() {
return this.filter;
}
} }