From 55aff7cbf80b7727705e8a1f883904946df9b5c8 Mon Sep 17 00:00:00 2001 From: trinsdar <30245301+Trinsdar@users.noreply.github.com> Date: Mon, 19 Aug 2024 18:59:26 -0400 Subject: [PATCH] added system for saving/reading display slots of item filters to/from data sticks --- .../single/BlockEntityItemFilter.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityItemFilter.java b/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityItemFilter.java index 83a3664f5..5afbd61c0 100644 --- a/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityItemFilter.java +++ b/common/src/main/java/muramasa/gregtech/blockentity/single/BlockEntityItemFilter.java @@ -13,18 +13,24 @@ import muramasa.antimatter.gui.event.IGuiEvent; import muramasa.antimatter.machine.event.IMachineEvent; import muramasa.antimatter.machine.types.Machine; +import muramasa.antimatter.tool.AntimatterToolType; import muramasa.antimatter.util.AntimatterPlatformUtils; import muramasa.antimatter.util.Utils; +import muramasa.gregtech.data.GregTechItems; import muramasa.gregtech.gui.ButtonOverlays; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.BlockHitResult; +import org.jetbrains.annotations.Nullable; import tesseract.TesseractCapUtils; import tesseract.api.item.ExtendedItemContainer; @@ -51,6 +57,29 @@ public boolean canOutput(Direction direction) { } } + @Override + public InteractionResult onInteractServer(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit, @Nullable AntimatterToolType type) { + ItemStack stack = player.getItemInHand(hand); + if (stack.getItem() == GregTechItems.DataStick){ + if (stack.getTagElement("displaySlots") == null){ + CompoundTag displaySlots = stack.getOrCreateTagElement("displaySlots"); + this.itemHandler.ifPresent(i -> { + i.getHandler(SlotType.DISPLAY_SETTABLE).serialize(displaySlots); + }); + displaySlots.putString("machineType", this.getMachineType().getLoc().toString()); + return InteractionResult.SUCCESS; + } else { + CompoundTag displaySlots = stack.getTagElement("displaySlots"); + if (!displaySlots.isEmpty() && displaySlots.getString("machineType").equals(this.getMachineType().getLoc().toString())){ + this.itemHandler.ifPresent(i -> i.getHandler(SlotType.DISPLAY_SETTABLE).deserialize(displaySlots)); + return InteractionResult.SUCCESS; + } + + } + } + return super.onInteractServer(state, world, pos, player, hand, hit, type); + } + @Override public boolean test(SlotType slotType, int slot, ItemStack stack) { if (slotType == SlotType.STORAGE){