From a75848e1959263dae9cd3e451fb57ef9c3a98630 Mon Sep 17 00:00:00 2001 From: Flanks255 <32142731+Flanks255@users.noreply.github.com> Date: Wed, 15 Mar 2023 18:17:57 -0500 Subject: [PATCH] First pass at the sack, still wip. --- .../mod/event/CommonEvents.java | 5 +- .../mod/inventory/ContainerBag.java | 88 +++++----- .../mod/inventory/gui/FilterSettingsGui.java | 85 +++------- .../mod/inventory/gui/GuiBag.java | 8 +- .../gui/GuiLaserRelayItemWhitelist.java | 4 +- .../actuallyadditions/mod/items/ItemBag.java | 54 ++++--- .../actuallyadditions/mod/sack/SackData.java | 151 ++++++++++++++++++ .../mod/sack/SackManager.java | 91 +++++++++++ .../mod/tile/FilterSettings.java | 98 +++--------- .../TileEntityLaserRelayItemAdvanced.java | 13 +- .../mod/tile/TileEntityRangedCollector.java | 8 +- 11 files changed, 376 insertions(+), 229 deletions(-) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/sack/SackData.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/sack/SackManager.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java b/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java index 621d248ba..72dad948f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java @@ -15,7 +15,6 @@ import de.ellpeck.actuallyadditions.mod.config.CommonConfig; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.data.PlayerData; import de.ellpeck.actuallyadditions.mod.data.WorldData; -import de.ellpeck.actuallyadditions.mod.inventory.ContainerBag; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; import de.ellpeck.actuallyadditions.mod.items.DrillItem; import de.ellpeck.actuallyadditions.mod.items.ItemBag; @@ -72,10 +71,10 @@ public class CommonEvents { boolean changed = false; boolean isVoid = ((ItemBag) invStack.getItem()).isVoid; - ItemStackHandlerAA inv = new ItemStackHandlerAA(ContainerBag.getSlotAmount(isVoid)); + ItemStackHandlerAA inv = new ItemStackHandlerAA(28); //TODO whats going on here DrillItem.loadSlotsFromNBT(inv, invStack); - FilterSettings filter = new FilterSettings(4, false, false, false, false, 0, 0); + FilterSettings filter = new FilterSettings(4, false, false, false); filter.readFromNBT(invStack.getOrCreateTag(), "Filter"); if (filter.check(stack)) { if (isVoid) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerBag.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerBag.java index fa92c4431..69de80175 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerBag.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerBag.java @@ -10,8 +10,6 @@ package de.ellpeck.actuallyadditions.mod.inventory; -import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; -import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues; import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotDeletion; import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter; import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotImmovable; @@ -21,7 +19,6 @@ import de.ellpeck.actuallyadditions.mod.items.ItemBag; import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor; import de.ellpeck.actuallyadditions.mod.tile.FilterSettings; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA; -import de.ellpeck.actuallyadditions.mod.util.StackUtil; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.ClickType; @@ -31,77 +28,74 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.PacketBuffer; -import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.registries.ForgeRegistries; import org.apache.commons.lang3.tuple.Pair; import java.util.ArrayList; import java.util.List; +import java.util.UUID; public class ContainerBag extends Container implements IButtonReactor { - public final FilterSettings filter = new FilterSettings(4, false, true, false, false, 0, -1000); + public final FilterSettings filter = new FilterSettings(4, false, false, false); private final ItemStackHandlerAA bagInventory; private final PlayerInventory inventory; - public final boolean isVoid; public boolean autoInsert; private boolean oldAutoInsert; - private final ItemStack sack; + + public static final int SIZE = 28; public static ContainerBag fromNetwork(int windowId, PlayerInventory inv, PacketBuffer data) { - return new ContainerBag(windowId, inv, data.readItem(), data.readBoolean()); + return new ContainerBag(windowId, inv, data.readUUID(), new ItemStackHandlerAA(28)); } - public ContainerBag(int windowId, PlayerInventory inventory, ItemStack sack, boolean isVoid) { + public ContainerBag(int windowId, PlayerInventory playerInventory, UUID uuid, ItemStackHandlerAA handler) { super(ActuallyContainers.BAG_CONTAINER.get(), windowId); - this.inventory = inventory; - this.bagInventory = new ItemStackHandlerAA(getSlotAmount(isVoid), (slot, stack, automation) -> !isBlacklisted(stack), ItemStackHandlerAA.REMOVE_TRUE); - this.isVoid = isVoid; - this.sack = sack; + this.inventory = playerInventory; + this.bagInventory = handler; //new ItemStackHandlerAA(SIZE, (slot, stack, automation) -> !isBlacklisted(stack), ItemStackHandlerAA.REMOVE_TRUE); for (int i = 0; i < 4; i++) { this.addSlot(new SlotFilter(this.filter, i, 155, 10 + i * 18)); } - if (this.isVoid) { + if (false) { // isvoid, move to its own container this.addSlot(new SlotDeletion(this.bagInventory, 0, 64, 65) { @Override public boolean mayPlace(ItemStack stack) { return ContainerBag.this.filter.check(stack); } }); - } else { - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 7; j++) { - this.addSlot(new SlotItemHandlerUnconditioned(this.bagInventory, j + i * 7, 10 + j * 18, 10 + i * 18) { - @Override - public boolean mayPlace(ItemStack stack) { - return !isBlacklisted(stack) && ContainerBag.this.filter.check(stack); - } - }); - } + } + + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 7; j++) { + this.addSlot(new SlotItemHandlerUnconditioned(this.bagInventory, j + i * 7, 10 + j * 18, 10 + i * 18) { + @Override + public boolean mayPlace(ItemStack stack) { + return !isBlacklisted(stack) && ContainerBag.this.filter.check(stack); + } + }); } } for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { - this.addSlot(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 94 + i * 18)); + this.addSlot(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 94 + i * 18)); } } for (int i = 0; i < 9; i++) { - if (i == inventory.selected) { - this.addSlot(new SlotImmovable(inventory, i, 8 + i * 18, 152)); + if (i == playerInventory.selected) { + this.addSlot(new SlotImmovable(playerInventory, i, 8 + i * 18, 152)); } else { - this.addSlot(new Slot(inventory, i, 8 + i * 18, 152)); + this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 152)); } } - ItemStack stack = inventory.getSelected(); - if (StackUtil.isValid(stack) && stack.getItem() instanceof ItemBag) { - DrillItem.loadSlotsFromNBT(this.bagInventory, inventory.getSelected()); + ItemStack stack = playerInventory.getSelected(); + if (!stack.isEmpty() && stack.getItem() instanceof ItemBag) { + DrillItem.loadSlotsFromNBT(this.bagInventory, playerInventory.getSelected()); if (stack.hasTag()) { CompoundNBT compound = stack.getOrCreateTag(); this.filter.readFromNBT(compound, "Filter"); @@ -110,12 +104,6 @@ public class ContainerBag extends Container implements IButtonReactor { } } - public static int getSlotAmount(boolean isVoid) { - return isVoid - ? 1 - : 28; - } - @Override public void broadcastChanges() { super.broadcastChanges(); @@ -152,14 +140,10 @@ public class ContainerBag extends Container implements IButtonReactor { if (id == 0) { this.filter.isWhitelist = data == 1; } else if (id == 1) { - this.filter.respectMeta = data == 1; - } else if (id == 2) { this.filter.respectNBT = data == 1; - } else if (id == 3) { - this.filter.respectOredict = data; - } else if (id == 4) { + } else if (id == 2) { this.autoInsert = data == 1; - } else if (id == 5) { + } else if (id == 3) { this.filter.respectMod = data == 1; } } @@ -180,7 +164,7 @@ public class ContainerBag extends Container implements IButtonReactor { //Other Slots in Inventory excluded if (slot >= inventoryStart) { //Shift from Inventory - if (this.isVoid || !this.filter.check(newStack) || !this.moveItemStackTo(newStack, 4, 32, false)) { + if (!this.filter.check(newStack) || !this.moveItemStackTo(newStack, 4, 32, false)) { if (slot >= inventoryStart && slot <= inventoryEnd) { if (!this.moveItemStackTo(newStack, hotbarStart, hotbarEnd + 1, false)) { return ItemStack.EMPTY; @@ -195,7 +179,7 @@ public class ContainerBag extends Container implements IButtonReactor { return ItemStack.EMPTY; } - if (!StackUtil.isValid(newStack)) { + if (newStack.isEmpty()) { theSlot.set(ItemStack.EMPTY); } else { theSlot.setChanged(); @@ -225,7 +209,7 @@ public class ContainerBag extends Container implements IButtonReactor { @Override public void removed(PlayerEntity player) { ItemStack stack = this.inventory.getSelected(); - if (StackUtil.isValid(stack) && stack.getItem() instanceof ItemBag) { + if (!stack.isEmpty() && stack.getItem() instanceof ItemBag) { DrillItem.writeSlotsToNBT(this.bagInventory, this.inventory.getSelected()); CompoundNBT compound = stack.getOrCreateTag(); this.filter.writeToNBT(compound, "Filter"); @@ -236,7 +220,7 @@ public class ContainerBag extends Container implements IButtonReactor { @Override public boolean stillValid(PlayerEntity player) { - return !this.sack.isEmpty() && player.getMainHandItem() == this.sack; + return true; //!this.sack.isEmpty() && player.getMainHandItem() == this.sack; //TODO fix later } @Override @@ -244,7 +228,7 @@ public class ContainerBag extends Container implements IButtonReactor { if (buttonID == 0) { this.autoInsert = !this.autoInsert; } else { - this.filter.onButtonPressed(buttonID); + //this.filter.onButtonPressed(buttonID); //TODO } } @@ -254,7 +238,9 @@ public class ContainerBag extends Container implements IButtonReactor { // TODO: [port] FIX THIS public static boolean isBlacklisted(ItemStack stack) { - if (!runOnce) { + //TODO replace with modern tagging blocking etc + return false; +/* if (!runOnce) { runOnce = true; for (String s : ConfigStringListValues.SACK_BLACKLIST.getValue()) { String[] split = s.split("@"); @@ -270,6 +256,6 @@ public class ContainerBag extends Container implements IButtonReactor { } } } - return BLACKLIST.contains(Pair.of(stack.getItem(), 0)); + return BLACKLIST.contains(Pair.of(stack.getItem(), 0));*/ } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FilterSettingsGui.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FilterSettingsGui.java index 9933d8cec..714e08ca6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FilterSettingsGui.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/FilterSettingsGui.java @@ -10,17 +10,20 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; +import com.mojang.blaze3d.matrix.MatrixStack; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.tile.FilterSettings; -import de.ellpeck.actuallyadditions.mod.util.StringUtil; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.AbstractGui; +import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.button.Button; +import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TranslationTextComponent; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.fml.client.gui.GuiUtils; import java.util.ArrayList; import java.util.List; @@ -31,27 +34,19 @@ public class FilterSettingsGui extends AbstractGui { private final FilterSettings theSettings; public Buttons.SmallerButton whitelistButton; - public Buttons.SmallerButton metaButton; public Buttons.SmallerButton nbtButton; public Buttons.SmallerButton modButton; - public Buttons.SmallerButton oredictButton; - public FilterSettingsGui(FilterSettings settings, int x, int y, List