From 87601c1e6e131dcd5f86a5cef62283a93a15a5e2 Mon Sep 17 00:00:00 2001 From: Flanks255 <32142731+Flanks255@users.noreply.github.com> Date: Sat, 16 Mar 2024 12:25:35 -0500 Subject: [PATCH] Fixed removing filters from filterable inventories. Added the void sack recipe. Fixed the void sack. --- .../9cf54cdf67e16111ec482a2a3b607e8fd75a4246 | 3 +- .../actuallyadditions/recipes/void_sack.json | 21 ++++ .../data/ItemRecipeGenerator.java | 4 +- .../mod/ActuallyAdditions.java | 2 +- .../mod/ActuallyAdditionsClient.java | 87 +++++-------- .../mod/event/CommonEvents.java | 69 ++++++----- .../mod/inventory/ActuallyContainers.java | 3 +- .../mod/inventory/SackContainer.java | 53 +------- .../mod/inventory/VoidSackContainer.java | 117 ++++++++++++++++++ .../mod/inventory/gui/FilterSettingsGui.java | 7 +- .../gui/GuiLaserRelayItemWhitelist.java | 4 +- .../mod/inventory/gui/GuiRangedCollector.java | 2 +- .../mod/inventory/gui/SackGui.java | 14 +-- .../mod/inventory/gui/VoidSackGui.java | 105 ++++++++++++++++ .../mod/inventory/slot/SlotFilter.java | 14 +-- .../actuallyadditions/mod/items/Sack.java | 19 ++- .../mod/tile/TileEntityLaserRelayFluids.java | 2 +- .../assets/actuallyadditions/lang/en_us.json | 2 +- 18 files changed, 345 insertions(+), 183 deletions(-) create mode 100644 src/generated/resources/data/actuallyadditions/recipes/void_sack.json create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/inventory/VoidSackContainer.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/VoidSackGui.java diff --git a/src/generated/resources/.cache/9cf54cdf67e16111ec482a2a3b607e8fd75a4246 b/src/generated/resources/.cache/9cf54cdf67e16111ec482a2a3b607e8fd75a4246 index d5bf8cb4b..63a4dc166 100644 --- a/src/generated/resources/.cache/9cf54cdf67e16111ec482a2a3b607e8fd75a4246 +++ b/src/generated/resources/.cache/9cf54cdf67e16111ec482a2a3b607e8fd75a4246 @@ -1,4 +1,4 @@ -// 1.20.4 2024-03-14T17:01:13.6665594 Item Recipes +// 1.20.4 2024-03-16T12:15:55.7079887 Item Recipes d374edde9294d1a224b4b5610b50117a11328c00 data/actuallyadditions/recipes/advanced_coil.json f67629e45d152c96f3467a90a67520f78ecf9f07 data/actuallyadditions/recipes/advanced_leaf_blower.json d65e5a70232fa2f0e74d2a67c1cd4b0e87124242 data/actuallyadditions/recipes/basic_coil.json @@ -118,5 +118,6 @@ b4aa29ef0d47b557f354a23cb6ee8ef60d273de3 data/actuallyadditions/recipes/teleport 5745a05f877fce254a1990f1e89f80e91846e270 data/actuallyadditions/recipes/tiny_to_coal.json 91bebb02fc416a650eea26c2d87049de91866cf0 data/actuallyadditions/recipes/travelers_sack.json 89c9512eeb746befb1bdc31037baa9bd86220f74 data/actuallyadditions/recipes/triple_battery.json +babb9a9e8a18d124c235df9214265c84738b0c1d data/actuallyadditions/recipes/void_sack.json 0737014abee48f688982412297e04e994aa6f9a6 data/actuallyadditions/recipes/wings_of_the_bats.json c80073fcade3cdcb15f28c4a1cb12df4ae6cf4ec data/actuallyadditions/recipes/wooden_aiot.json diff --git a/src/generated/resources/data/actuallyadditions/recipes/void_sack.json b/src/generated/resources/data/actuallyadditions/recipes/void_sack.json new file mode 100644 index 000000000..c36c396d8 --- /dev/null +++ b/src/generated/resources/data/actuallyadditions/recipes/void_sack.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:crafting_shapeless", + "category": "misc", + "ingredients": [ + { + "item": "actuallyadditions:travelers_sack" + }, + { + "tag": "forge:ender_pearls" + }, + { + "tag": "forge:obsidian" + }, + { + "item": "actuallyadditions:void_crystal_block" + } + ], + "result": { + "item": "actuallyadditions:void_sack" + } +} \ No newline at end of file diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/ItemRecipeGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/ItemRecipeGenerator.java index 1735ff93a..349b6f2af 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/ItemRecipeGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/ItemRecipeGenerator.java @@ -109,12 +109,12 @@ public class ItemRecipeGenerator extends RecipeProvider { .define('V', ActuallyBlocks.VOID_CRYSTAL.getItem()).save(recipeOutput); //Void Bag -/* Recipe.shapeless(ActuallyItems.VOID_SACK.get()) + Recipe.shapeless(ActuallyItems.VOID_SACK.get()) .requires(ActuallyItems.TRAVELERS_SACK.get()) .requires(Tags.Items.ENDER_PEARLS) .requires(Tags.Items.OBSIDIAN) .requires(ActuallyBlocks.VOID_CRYSTAL.getItem()) - .save(recipeOutput);*/ //TODO not done yet + .save(recipeOutput); //Lens Recipe.shaped(ActuallyItems.LENS.get()) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java index c7c3ecb50..63f5deed9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java @@ -33,7 +33,6 @@ import de.ellpeck.actuallyadditions.mod.gen.village.ActuallyVillagers; import de.ellpeck.actuallyadditions.mod.gen.village.InitVillager; import de.ellpeck.actuallyadditions.mod.inventory.ActuallyContainers; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; -import de.ellpeck.actuallyadditions.mod.items.ItemCoffee; import de.ellpeck.actuallyadditions.mod.items.Worm; import de.ellpeck.actuallyadditions.mod.lootmodifier.ActuallyLootModifiers; import de.ellpeck.actuallyadditions.mod.misc.BannerHelper; @@ -142,6 +141,7 @@ public class ActuallyAdditions { if (FMLEnvironment.dist.isClient()) { eventBus.addListener(ActuallyAdditionsClient::setup); + eventBus.addListener(ActuallyAdditionsClient::setupMenus); eventBus.addListener(ActuallyAdditionsClient::setupSpecialRenders); eventBus.addListener(ActuallyAdditionsClient::registerParticleFactories); eventBus.register(new ClientRegistryHandler()); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java index 4c9d43d9c..1053ecfb6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java @@ -11,40 +11,12 @@ package de.ellpeck.actuallyadditions.mod; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; -import de.ellpeck.actuallyadditions.mod.blocks.render.ReconstructorRenderer; -import de.ellpeck.actuallyadditions.mod.blocks.render.RenderBatteryBox; -import de.ellpeck.actuallyadditions.mod.blocks.render.RenderDisplayStand; -import de.ellpeck.actuallyadditions.mod.blocks.render.RenderEmpowerer; -import de.ellpeck.actuallyadditions.mod.blocks.render.RenderLaserRelay; +import de.ellpeck.actuallyadditions.mod.blocks.render.*; import de.ellpeck.actuallyadditions.mod.entity.RenderWorm; import de.ellpeck.actuallyadditions.mod.event.ClientEvents; import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; import de.ellpeck.actuallyadditions.mod.inventory.ActuallyContainers; -import de.ellpeck.actuallyadditions.mod.inventory.gui.CrusherScreen; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiBioReactor; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiBreaker; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiCanolaPress; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiCoalGenerator; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiCoffeeMachine; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiDirectionalBreaker; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiDrill; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiDropper; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiEnergizer; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiEnervator; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiFarmer; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiFeeder; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiFermentingBarrel; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiFilter; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiFireworkBox; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiFluidCollector; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiFurnaceDouble; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiLaserRelayItemWhitelist; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiMiner; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiOilGenerator; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiPhantomPlacer; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiRangedCollector; -import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiXPSolidifier; -import de.ellpeck.actuallyadditions.mod.inventory.gui.SackGui; +import de.ellpeck.actuallyadditions.mod.inventory.gui.*; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; import de.ellpeck.actuallyadditions.mod.misc.special.SpecialRenderInit; import de.ellpeck.actuallyadditions.mod.particle.ActuallyParticles; @@ -52,7 +24,6 @@ import de.ellpeck.actuallyadditions.mod.particle.ParticleBeam; import de.ellpeck.actuallyadditions.mod.particle.ParticleLaserItem; import de.ellpeck.actuallyadditions.mod.patchouli.PatchouliPages; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.MenuScreens; import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.RenderType; @@ -63,37 +34,41 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.phys.BlockHitResult; import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; import net.neoforged.neoforge.client.event.EntityRenderersEvent; +import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent; import net.neoforged.neoforge.client.event.RegisterParticleProvidersEvent; import net.neoforged.neoforge.common.NeoForge; public class ActuallyAdditionsClient { + public static void setupMenus(RegisterMenuScreensEvent evt) { + evt.register(ActuallyContainers.SACK_CONTAINER.get(), SackGui::new); + evt.register(ActuallyContainers.VOID_SACK_CONTAINER.get(), VoidSackGui::new); + evt.register(ActuallyContainers.BIO_REACTOR_CONTAINER.get(), GuiBioReactor::new); + evt.register(ActuallyContainers.BREAKER_CONTAINER.get(), GuiBreaker::new); + evt.register(ActuallyContainers.CANOLA_PRESS_CONTAINER.get(), GuiCanolaPress::new); + evt.register(ActuallyContainers.COAL_GENERATOR_CONTAINER.get(), GuiCoalGenerator::new); + evt.register(ActuallyContainers.COFFEE_MACHINE_CONTAINER.get(), GuiCoffeeMachine::new); + evt.register(ActuallyContainers.DIRECTIONAL_BREAKER_CONTAINER.get(), GuiDirectionalBreaker::new); + evt.register(ActuallyContainers.DRILL_CONTAINER.get(), GuiDrill::new); + evt.register(ActuallyContainers.DROPPER_CONTAINER.get(), GuiDropper::new); + evt.register(ActuallyContainers.ENERVATOR_CONTAINER.get(), GuiEnervator::new); + evt.register(ActuallyContainers.ENERGIZER_CONTAINER.get(), GuiEnergizer::new); + evt.register(ActuallyContainers.FARMER_CONTAINER.get(), GuiFarmer::new); + evt.register(ActuallyContainers.FEEDER_CONTAINER.get(), GuiFeeder::new); + evt.register(ActuallyContainers.FERMENTING_BARREL_CONTAINER.get(), GuiFermentingBarrel::new); + evt.register(ActuallyContainers.FILTER_CONTAINER.get(), GuiFilter::new); + evt.register(ActuallyContainers.FIREWORK_BOX_CONTAINER.get(), GuiFireworkBox::new); + evt.register(ActuallyContainers.FLUID_COLLECTOR_CONTAINER.get(), GuiFluidCollector::new); + evt.register(ActuallyContainers.FURNACE_DOUBLE_CONTAINER.get(), GuiFurnaceDouble::new); + evt.register(ActuallyContainers.GRINDER_CONTAINER.get(), CrusherScreen::new); + evt.register(ActuallyContainers.LASER_RELAY_ITEM_WHITELIST_CONTAINER.get(), GuiLaserRelayItemWhitelist::new); + evt.register(ActuallyContainers.MINER_CONTAINER.get(), GuiMiner::new); + evt.register(ActuallyContainers.OIL_GENERATOR_CONTAINER.get(), GuiOilGenerator::new); + evt.register(ActuallyContainers.PHANTOM_PLACER_CONTAINER.get(), GuiPhantomPlacer::new); + evt.register(ActuallyContainers.RANGED_COLLECTOR_CONTAINER.get(), GuiRangedCollector::new); + evt.register(ActuallyContainers.XPSOLIDIFIER_CONTAINER.get(), GuiXPSolidifier::new); + } public static void setup(FMLClientSetupEvent event) { - MenuScreens.register(ActuallyContainers.BAG_CONTAINER.get(), SackGui::new); - MenuScreens.register(ActuallyContainers.BIO_REACTOR_CONTAINER.get(), GuiBioReactor::new); - MenuScreens.register(ActuallyContainers.BREAKER_CONTAINER.get(), GuiBreaker::new); - MenuScreens.register(ActuallyContainers.CANOLA_PRESS_CONTAINER.get(), GuiCanolaPress::new); - MenuScreens.register(ActuallyContainers.COAL_GENERATOR_CONTAINER.get(), GuiCoalGenerator::new); - MenuScreens.register(ActuallyContainers.COFFEE_MACHINE_CONTAINER.get(), GuiCoffeeMachine::new); - MenuScreens.register(ActuallyContainers.DIRECTIONAL_BREAKER_CONTAINER.get(), GuiDirectionalBreaker::new); - MenuScreens.register(ActuallyContainers.DRILL_CONTAINER.get(), GuiDrill::new); - MenuScreens.register(ActuallyContainers.DROPPER_CONTAINER.get(), GuiDropper::new); - MenuScreens.register(ActuallyContainers.ENERVATOR_CONTAINER.get(), GuiEnervator::new); - MenuScreens.register(ActuallyContainers.ENERGIZER_CONTAINER.get(), GuiEnergizer::new); - MenuScreens.register(ActuallyContainers.FARMER_CONTAINER.get(), GuiFarmer::new); - MenuScreens.register(ActuallyContainers.FEEDER_CONTAINER.get(), GuiFeeder::new); - MenuScreens.register(ActuallyContainers.FERMENTING_BARREL_CONTAINER.get(), GuiFermentingBarrel::new); - MenuScreens.register(ActuallyContainers.FILTER_CONTAINER.get(), GuiFilter::new); - MenuScreens.register(ActuallyContainers.FIREWORK_BOX_CONTAINER.get(), GuiFireworkBox::new); - MenuScreens.register(ActuallyContainers.FLUID_COLLECTOR_CONTAINER.get(), GuiFluidCollector::new); - MenuScreens.register(ActuallyContainers.FURNACE_DOUBLE_CONTAINER.get(), GuiFurnaceDouble::new); - MenuScreens.register(ActuallyContainers.GRINDER_CONTAINER.get(), CrusherScreen::new); - MenuScreens.register(ActuallyContainers.LASER_RELAY_ITEM_WHITELIST_CONTAINER.get(), GuiLaserRelayItemWhitelist::new); - MenuScreens.register(ActuallyContainers.MINER_CONTAINER.get(), GuiMiner::new); - MenuScreens.register(ActuallyContainers.OIL_GENERATOR_CONTAINER.get(), GuiOilGenerator::new); - MenuScreens.register(ActuallyContainers.PHANTOM_PLACER_CONTAINER.get(), GuiPhantomPlacer::new); - MenuScreens.register(ActuallyContainers.RANGED_COLLECTOR_CONTAINER.get(), GuiRangedCollector::new); - MenuScreens.register(ActuallyContainers.XPSOLIDIFIER_CONTAINER.get(), GuiXPSolidifier::new); // From old proxy NeoForge.EVENT_BUS.register(new ClientEvents()); NeoForge.EVENT_BUS.register(new SpecialRenderInit()); 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 5562803c4..d671497ea 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java @@ -16,7 +16,6 @@ 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.items.ActuallyItems; -import de.ellpeck.actuallyadditions.mod.items.DrillItem; import de.ellpeck.actuallyadditions.mod.items.Sack; import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; import de.ellpeck.actuallyadditions.mod.sack.SackManager; @@ -68,53 +67,57 @@ public class CommonEvents { if (i != player.getInventory().selected) { ItemStack invStack = player.getInventory().getItem(i); - if (StackUtil.isValid(invStack) && invStack.getItem() instanceof Sack && invStack.hasTag()) { + if (StackUtil.isValid(invStack) && (invStack.getItem() instanceof Sack) && invStack.hasTag()) { if (invStack.getOrCreateTag().getBoolean("AutoInsert")) { boolean changed = false; - boolean isVoid = ((Sack) invStack.getItem()).isVoid; - var optHandler = SackManager.get().getHandler(invStack); - - if (optHandler.isEmpty()) - continue; - - ItemStackHandlerAA inv = optHandler.get(); FilterSettings filter = new FilterSettings(4, false, false); filter.readFromNBT(invStack.getOrCreateTag(), "Filter"); - if (filter.check(stack)) { - if (isVoid) { + + if (isVoid) { + if (filter.check(stack)) { stack.setCount(0); changed = true; - } else { - for (int j = 0; j < inv.getSlots(); j++) { - ItemStack bagStack = inv.getStackInSlot(j); - if (StackUtil.isValid(bagStack)) { - if (ItemUtil.canBeStacked(bagStack, stack)) { - int maxTransfer = Math.min(stack.getCount(), stack.getMaxStackSize() - bagStack.getCount()); - if (maxTransfer > 0) { - inv.setStackInSlot(j, StackUtil.grow(bagStack, maxTransfer)); - stack.shrink(maxTransfer); - changed = true; - } - } - } else { - inv.setStackInSlot(j, stack.copy()); - stack.setCount(0); - changed = true; - } + } + } + else { + var optHandler = SackManager.get().getHandler(invStack); - if (!StackUtil.isValid(stack)) { - break; + if (optHandler.isEmpty()) + continue; + + ItemStackHandlerAA inv = optHandler.get(); + + if (filter.check(stack)) { + for (int j = 0; j < inv.getSlots(); j++) { + ItemStack bagStack = inv.getStackInSlot(j); + if (StackUtil.isValid(bagStack)) { + if (ItemUtil.canBeStacked(bagStack, stack)) { + int maxTransfer = Math.min(stack.getCount(), stack.getMaxStackSize() - bagStack.getCount()); + if (maxTransfer > 0) { + inv.setStackInSlot(j, StackUtil.grow(bagStack, maxTransfer)); + stack.shrink(maxTransfer); + changed = true; + } + } + } else { + inv.setStackInSlot(j, stack.copy()); + stack.setCount(0); + changed = true; + } + + if (stack.isEmpty()) { + break; + } } - } } } if (changed) { - if (!isVoid) { +/* if (!isVoid) { DrillItem.writeSlotsToNBT(inv, invStack); - } + }*/ event.setResult(Event.Result.ALLOW); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ActuallyContainers.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ActuallyContainers.java index a83d49703..96f3834b6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ActuallyContainers.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ActuallyContainers.java @@ -11,7 +11,8 @@ import java.util.function.Supplier; public class ActuallyContainers { public static final DeferredRegister> CONTAINERS = DeferredRegister.create(BuiltInRegistries.MENU, ActuallyAdditions.MODID); - public static final Supplier> BAG_CONTAINER = CONTAINERS.register("bag_container", () -> IMenuTypeExtension.create(SackContainer::fromNetwork)); + public static final Supplier> SACK_CONTAINER = CONTAINERS.register("sack_container", () -> IMenuTypeExtension.create(SackContainer::fromNetwork)); + public static final Supplier> VOID_SACK_CONTAINER = CONTAINERS.register("void_sack_container", () -> IMenuTypeExtension.create(VoidSackContainer::new)); public static final Supplier> BIO_REACTOR_CONTAINER = CONTAINERS.register("bioreactor_container", () -> IMenuTypeExtension.create(ContainerBioReactor::fromNetwork)); public static final Supplier> BREAKER_CONTAINER = CONTAINERS.register("breaker_container", () -> IMenuTypeExtension.create(ContainerBreaker::fromNetwork)); public static final Supplier> CANOLA_PRESS_CONTAINER = CONTAINERS.register("canola_press_container", () -> IMenuTypeExtension.create(ContainerCanolaPress::fromNetwork)); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/SackContainer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/SackContainer.java index f7563042e..c77602023 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/SackContainer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/SackContainer.java @@ -11,7 +11,6 @@ package de.ellpeck.actuallyadditions.mod.inventory; import de.ellpeck.actuallyadditions.api.ActuallyTags; -import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotDeletion; import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter; import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotImmovable; import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotItemHandlerUnconditioned; @@ -46,7 +45,7 @@ public class SackContainer extends AbstractContainerMenu implements IButtonReact } public SackContainer(int windowId, Inventory playerInventory, UUID uuid, ItemStackHandlerAA handler) { - super(ActuallyContainers.BAG_CONTAINER.get(), windowId); + super(ActuallyContainers.SACK_CONTAINER.get(), windowId); this.inventory = playerInventory; this.bagInventory = handler; @@ -55,15 +54,6 @@ public class SackContainer extends AbstractContainerMenu implements IButtonReact this.addSlot(new SlotFilter(this.filter, row, 155, 10 + row * 18)); } - if (false) { // TODO isvoid, move to its own container - this.addSlot(new SlotDeletion(this.bagInventory, 0, 64, 65) { - @Override - public boolean mayPlace(ItemStack stack) { - return SackContainer.this.filter.check(stack); - } - }); - } - // Sack inventory for (int row = 0; row < 4; row++) { for (int col = 0; col < 7; col++) { @@ -94,7 +84,6 @@ public class SackContainer extends AbstractContainerMenu implements IButtonReact ItemStack stack = playerInventory.getSelected(); if (!stack.isEmpty() && stack.getItem() instanceof Sack) { - //DrillItem.loadSlotsFromNBT(this.bagInventory, playerInventory.getSelected()); if (stack.hasTag()) { CompoundTag compound = stack.getOrCreateTag(); this.filter.readFromNBT(compound, "Filter"); @@ -103,46 +92,6 @@ public class SackContainer extends AbstractContainerMenu implements IButtonReact } } -/* @Override - public void broadcastChanges() { // TODO is this needed anymore? - super.broadcastChanges(); - - if (this.filter.needsUpdateSend() || this.autoInsert != this.oldAutoInsert) { - for (ContainerListener listener : this..containerListeners) { - listener.setContainerData(this, 0, this.filter.isWhitelist - ? 1 - : 0); - listener.setContainerData(this, 1, this.filter.respectMeta - ? 1 - : 0); - listener.setContainerData(this, 2, this.filter.respectNBT - ? 1 - : 0); - listener.setContainerData(this, 3, this.filter.respectOredict); - listener.setContainerData(this, 4, this.autoInsert - ? 1 - : 0); - listener.setContainerData(this, 5, this.filter.respectMod - ? 1 - : 0); - } - this.filter.updateLasts(); - this.oldAutoInsert = this.autoInsert; - } - } - - @Override - @OnlyIn(Dist.CLIENT) - public void setData(int id, int data) { - if (id == 0) { - this.filter.isWhitelist = data == 1; - } else if (id == 1) { - this.autoInsert = data == 1; - } else if (id == 2) { - this.filter.respectMod = data == 1; - } - }*/ - @Override public ItemStack quickMoveStack(@Nonnull Player player, int slot) { int inventoryStart = this.bagInventory.getSlots() + 4; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/VoidSackContainer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/VoidSackContainer.java new file mode 100644 index 000000000..b5e3966e0 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/VoidSackContainer.java @@ -0,0 +1,117 @@ +package de.ellpeck.actuallyadditions.mod.inventory; + +import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotDeletion; +import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter; +import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotImmovable; +import de.ellpeck.actuallyadditions.mod.items.Sack; +import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor; +import de.ellpeck.actuallyadditions.mod.tile.FilterSettings; +import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ClickType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; + +import javax.annotation.Nonnull; + +public class VoidSackContainer extends AbstractContainerMenu implements IButtonReactor { + public final FilterSettings filter = new FilterSettings(4, false,false); + + private final ItemStackHandlerAA bagInventory; + private final Inventory inventory; + public boolean autoInsert; + private boolean oldAutoInsert; + + protected VoidSackContainer(int windowId, Inventory inv, FriendlyByteBuf data) { + this(windowId, inv); + } + + public VoidSackContainer(int pContainerId, Inventory pPlayerInventory) { + super(ActuallyContainers.VOID_SACK_CONTAINER.get(), pContainerId); + + this.inventory = pPlayerInventory; + this.bagInventory = new ItemStackHandlerAA(1); + + for (int c = 0; c < 4; c++) { + this.addSlot(new SlotFilter(this.filter, c, 98 + c * 17, 17)); + } + + this.addSlot(new SlotDeletion(this.bagInventory, 0, 13, 18) { + @Override + public boolean mayPlace(ItemStack stack) { + return VoidSackContainer.this.filter.check(stack); + } + }); + + // Player Inventory + for (int row = 0; row < 3; row++) { + for (int col = 0; col < 9; col++) { + this.addSlot(new Slot(inventory, col + row * 9 + 9, 8 + col * 18, 47 + row * 18)); + } + } + + // Player Hotbar + for (int i = 0; i < 9; i++) { + if (i == inventory.selected) { + this.addSlot(new SlotImmovable(inventory, i, 8 + i * 18, 105)); + } else { + this.addSlot(new Slot(inventory, i, 8 + i * 18, 105)); + } + } + + ItemStack stack = inventory.getSelected(); + if (!stack.isEmpty() && stack.getItem() instanceof Sack) { + if (stack.hasTag()) { + CompoundTag compound = stack.getOrCreateTag(); + this.filter.readFromNBT(compound, "Filter"); + this.autoInsert = compound.getBoolean("AutoInsert"); + } + } + } + + @Override + public void clicked(int slotId, int dragType, @Nonnull ClickType clickTypeIn, @Nonnull Player player) { + if (SlotFilter.checkFilter(this, slotId, player)) { + return; + } else if (clickTypeIn == ClickType.SWAP && dragType == this.inventory.selected) { + return; + } else { + super.clicked(slotId, dragType, clickTypeIn, player); + } + } + + @Override + public void removed(@Nonnull Player player) { + ItemStack stack = this.inventory.getSelected(); + if (!stack.isEmpty() && stack.getItem() instanceof Sack) { + CompoundTag compound = stack.getOrCreateTag(); + this.filter.writeToNBT(compound, "Filter"); + compound.putBoolean("AutoInsert", this.autoInsert); + } + super.removed(player); + } + + @Override + public void onButtonPressed(int buttonID, Player player) { + if (buttonID == 0) { + this.autoInsert = !this.autoInsert; + } else { + this.filter.onButtonPressed(buttonID - 1); + } + } + + @Nonnull + @Override + public ItemStack quickMoveStack(@Nonnull Player pPlayer, int pIndex) { + return ItemStack.EMPTY; //TODO old behavior was shift clicking moved stacks around the normal inventory + } + + @Override + public boolean stillValid(@Nonnull Player pPlayer) { + return true; + } +} 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 9ff060dc3..d94d5dcde 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 @@ -33,7 +33,7 @@ public class FilterSettingsGui { public Button whitelistButton; public Button modButton; - public FilterSettingsGui(FilterSettings settings, int x, int y, Consumer buttonConsumer, Consumer clickConsumer, int idOffset) { + public FilterSettingsGui(FilterSettings settings, int x, int y, boolean vertical, Consumer buttonConsumer, Consumer clickConsumer, int idOffset) { this.theSettings = settings; this.whitelistButton = Button.builder(Component.literal("WH"), $ -> { @@ -42,7 +42,10 @@ public class FilterSettingsGui { }) .bounds(x, y, 16, 12).build(); buttonConsumer.accept(this.whitelistButton); - y += 14; + if (vertical) + y += 14; + else + x += 18; this.modButton = Button.builder(Component.literal("MO"), $ -> { theSettings.respectMod = !theSettings.respectMod; clickConsumer.accept(idOffset + 1); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java index 722f83b7a..a27d3f28e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java @@ -68,8 +68,8 @@ public class GuiLaserRelayItemWhitelist extends AAScreen { public void init() { super.init(); - this.filter = new FilterSettingsGui(this.collector.filter, this.leftPos + 3, this.topPos + 6, this::addRenderableWidget, this::buttonClicked, 0); + this.filter = new FilterSettingsGui(this.collector.filter, this.leftPos + 3, this.topPos + 6, true, this::addRenderableWidget, this::buttonClicked, 0); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/SackGui.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/SackGui.java index 0cc688483..ee670e250 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/SackGui.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/SackGui.java @@ -32,10 +32,8 @@ import java.util.Optional; public class SackGui extends AAScreen { private static final ResourceLocation RES_LOC = AssetUtil.getGuiLocation("gui_bag"); - private static final ResourceLocation RES_LOC_VOID = AssetUtil.getGuiLocation("gui_void_bag"); private final SackContainer container; - private final boolean isVoid; private FilterSettingsGui filter; private Button buttonAutoInsert; @@ -43,7 +41,6 @@ public class SackGui extends AAScreen { super(container, inventory, title); this.imageWidth = 176; this.imageHeight = 90 + 86; - this.isVoid = false; //TODO fix later this.container = container; } @@ -51,7 +48,7 @@ public class SackGui extends AAScreen { public void init() { super.init(); - this.filter = new FilterSettingsGui(this.container.filter, this.leftPos + 137, this.topPos + 10, this::addRenderableWidget, this::buttonClicked, 1); + this.filter = new FilterSettingsGui(this.container.filter, this.leftPos + 137, this.topPos + 10, true, this::addRenderableWidget, this::buttonClicked, 1); this.buttonAutoInsert = Button.builder( Component.literal("I") @@ -81,13 +78,6 @@ public class SackGui extends AAScreen { this.filter.tick(); } -/* @Override - public void drawGuiContainerForegroundLayer(int x, int y) { - AssetUtil.displayNameString(this.font, this.imageWidth, -10, StringUtil.localize("container." + ActuallyAdditions.MODID + "." + (this.isVoid - ? "voidBag" - : "bag") + ".name")); - }*/ - @Override public void render(@Nonnull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { super.render(guiGraphics, mouseX, mouseY, partialTicks); @@ -110,6 +100,6 @@ public class SackGui extends AAScreen { guiGraphics.blit(AssetUtil.GUI_INVENTORY_LOCATION, this.leftPos, this.topPos + 90, 0, 0, 176, 86); - guiGraphics.blit(this.isVoid ? RES_LOC_VOID : RES_LOC, this.leftPos, this.topPos, 0, 0, 176, 90); + guiGraphics.blit(RES_LOC, this.leftPos, this.topPos, 0, 0, 176, 90); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/VoidSackGui.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/VoidSackGui.java new file mode 100644 index 000000000..0b657f92d --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/VoidSackGui.java @@ -0,0 +1,105 @@ +/* + * This file ("GuiBag.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2017 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.inventory.gui; + +import com.mojang.blaze3d.systems.RenderSystem; +import de.ellpeck.actuallyadditions.mod.inventory.VoidSackContainer; +import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer; +import de.ellpeck.actuallyadditions.mod.network.PacketHandler; +import de.ellpeck.actuallyadditions.mod.util.AssetUtil; +import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.Button; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; +import net.neoforged.neoforge.network.PacketDistributor; + +import javax.annotation.Nonnull; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +public class VoidSackGui extends AAScreen { + private static final ResourceLocation RES_LOC_VOID = AssetUtil.getGuiLocation("gui_void_bag"); + + private final VoidSackContainer container; + private FilterSettingsGui filter; + private Button buttonAutoInsert; + + public VoidSackGui(VoidSackContainer container, Inventory inventory, Component title) { + super(container, inventory, title); + this.imageWidth = 176; + this.imageHeight = 90 + 43; + this.container = container; + } + + @Override + public void init() { + super.init(); + + this.filter = new FilterSettingsGui(this.container.filter, this.leftPos + 97, this.topPos + 3, false, this::addRenderableWidget, this::buttonClicked, 1); + + this.buttonAutoInsert = Button.builder( + Component.literal("I") + .withStyle(this.container.autoInsert? ChatFormatting.DARK_GREEN : ChatFormatting.RED), + (button) -> { + this.container.autoInsert = !this.container.autoInsert; + this.buttonAutoInsert.setMessage(Component.literal(this.container.autoInsert? "I" : "O") + .withStyle(this.container.autoInsert? ChatFormatting.DARK_GREEN : ChatFormatting.RED)); + this.buttonClicked(0); + }).pos(leftPos - 17, topPos + 16).size(20, 20) + .build(); + + this.addRenderableWidget(this.buttonAutoInsert); + } + + public void buttonClicked(int id) { + CompoundTag data = new CompoundTag(); + data.putInt("ButtonID", id); + data.putInt("PlayerID", Minecraft.getInstance().player.getId()); + data.putString("WorldID", Minecraft.getInstance().level.dimension().location().toString()); + PacketDistributor.SERVER.noArg().send(new PacketClientToServer(data, PacketHandler.GUI_BUTTON_TO_CONTAINER_HANDLER)); + } + + @Override + public void containerTick() { + super.containerTick(); + this.filter.tick(); + } + + @Override + public void render(@Nonnull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { + super.render(guiGraphics, mouseX, mouseY, partialTicks); + this.filter.drawHover(guiGraphics, mouseX, mouseY); + + if (this.buttonAutoInsert.isMouseOver(mouseX, mouseY)) { + List text = new ArrayList<>(); + text.add(Component.literal("Auto-Insert " + (this.container.autoInsert + ? "On" + : "Off")).withStyle(ChatFormatting.BOLD)); + text.add(Component.literal("Turn this on to make items that get picked up automatically go into the bag.")); //TODO how to word wrap these to 200? + text.add(Component.literal("Note that this WON'T work when you are holding the bag in your hand.").withStyle(ChatFormatting.GRAY).withStyle(ChatFormatting.ITALIC)); //TODO this too + guiGraphics.renderTooltip(font, text, Optional.empty(), mouseX, mouseY); //TODO i have no idea what im doing here... + } + } + + @Override + protected void renderBg(GuiGraphics guiGraphics, float partialTicks, int x, int y) { + RenderSystem.setShaderColor(1F, 1F, 1F, 1F); + + guiGraphics.blit(AssetUtil.GUI_INVENTORY_LOCATION, this.leftPos, this.topPos + 43, 0, 0, 176, 86); + + guiGraphics.blit( RES_LOC_VOID, this.leftPos, this.topPos, 0, 0, 176, 43); + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/slot/SlotFilter.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/slot/SlotFilter.java index b2465ca44..6dd30902f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/slot/SlotFilter.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/slot/SlotFilter.java @@ -45,23 +45,21 @@ public class SlotFilter extends SlotItemHandlerUnconditioned { } private void slotClick(Player player, ItemStack cursorItem) { - ItemStack heldStack = cursorItem; ItemStack stackInSlot = this.getItem(); - - if (StackUtil.isValid(stackInSlot) && !StackUtil.isValid(heldStack)) { + if (!stackInSlot.isEmpty() && cursorItem.isEmpty()) { if (isFilter(stackInSlot)) { - player.getInventory().setPickedItem(stackInSlot); + player.containerMenu.setCarried(stackInSlot); } this.set(ItemStack.EMPTY); - } else if (StackUtil.isValid(heldStack)) { + } else if (StackUtil.isValid(cursorItem)) { if (!isFilter(stackInSlot)) { - ItemStack s = heldStack.copy(); + ItemStack s = cursorItem.copy(); s.setCount(1); this.set(s); - if (isFilter(heldStack)) { - heldStack.shrink(1); + if (isFilter(cursorItem)) { + cursorItem.shrink(1); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/Sack.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/Sack.java index 4f81e49d5..7d3d70988 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/Sack.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/Sack.java @@ -11,11 +11,11 @@ package de.ellpeck.actuallyadditions.mod.items; import de.ellpeck.actuallyadditions.mod.inventory.SackContainer; +import de.ellpeck.actuallyadditions.mod.inventory.VoidSackContainer; import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; import de.ellpeck.actuallyadditions.mod.sack.SackData; import de.ellpeck.actuallyadditions.mod.sack.SackManager; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA; -import de.ellpeck.actuallyadditions.mod.util.StackUtil; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerPlayer; @@ -30,6 +30,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.neoforged.neoforge.capabilities.Capabilities; +import javax.annotation.Nonnull; import java.util.Optional; import java.util.UUID; @@ -41,6 +42,7 @@ public class Sack extends ItemBase { this.isVoid = isVoid; } + @Nonnull @Override public InteractionResult useOn(UseOnContext context) { ItemStack stack = context.getPlayer().getItemInHand(context.getHand()); @@ -59,13 +61,13 @@ public class Sack extends ItemBase { for (int j = 0; j < inv.getSlots(); j++) { ItemStack invStack = inv.getStackInSlot(j); - if (StackUtil.isValid(invStack)) { + if (!invStack.isEmpty()) { for (int i = 0; i < cap.getSlots(); i++) { ItemStack remain = cap.insertItem(i, invStack, false); if (!ItemStack.matches(remain, invStack)) { inv.setStackInSlot(j, remain.copy()); localChanged = true; - if (!StackUtil.isValid(remain)) { + if (remain.isEmpty()) { break; } invStack = remain; @@ -87,8 +89,9 @@ public class Sack extends ItemBase { return InteractionResult.PASS; } + @Nonnull @Override - public InteractionResultHolder use(Level world, Player player, InteractionHand hand) { + public InteractionResultHolder use(Level world, Player player, @Nonnull InteractionHand hand) { ItemStack sackStack = player.getItemInHand(hand); if (!world.isClientSide && hand == InteractionHand.MAIN_HAND && sackStack.getItem() instanceof Sack && player instanceof ServerPlayer) { @@ -104,12 +107,8 @@ public class Sack extends ItemBase { player.openMenu(new SimpleMenuProvider((id, inv, entity) -> new SackContainer(id, inv, uuid, data.getSpecialHandler()), sackStack.getHoverName()), (buffer -> buffer.writeUUID(uuid))); - } - - -/* NetworkHooks.openGui((ServerPlayerEntity) player, - new SimpleNamedContainerProvider((windowId, playerInventory, playerEntity) -> - new ContainerBag(windowId, playerInventory, playerEntity.getItemInHand(hand), this.isVoid), StringComponent.empty()));*/ + } else + player.openMenu(new SimpleMenuProvider((id, inv, entity) -> new VoidSackContainer(id, inv), sackStack.getHoverName())); } return InteractionResultHolder.pass(player.getItemInHand(hand)); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java index af4a23b58..c67249543 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java @@ -213,7 +213,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay { } //TODO dont send the entire tank at once, gg if (totalReceiverAmount > 0 && !relaysThatWork.isEmpty()) { - int amountPer = stack.getAmount() / totalReceiverAmount <= 0 + int amountPer = stack.getAmount() / totalReceiverAmount > 0 ? stack.getAmount() / totalReceiverAmount : stack.getAmount(); diff --git a/src/main/resources/assets/actuallyadditions/lang/en_us.json b/src/main/resources/assets/actuallyadditions/lang/en_us.json index 292acd235..54c2fd913 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_us.json +++ b/src/main/resources/assets/actuallyadditions/lang/en_us.json @@ -373,7 +373,7 @@ "item.actuallyadditions.player_probe": "Player Probe", "item.actuallyadditions.worm": "Worm", "item.actuallyadditions.travelers_sack": "Traveler's Sack", - "item.actuallyadditions.void_sack": "Void Sack (wip)", + "item.actuallyadditions.void_sack": "Void Sack", "item.actuallyadditions.crystallized_canola_seed": "Crystallized Canola Seed", "item.actuallyadditions.empowered_canola_seed": "Empowered Canola Seed", "item.actuallyadditions.lens_of_the_miner": "Lens of the Miner",