diff --git a/common/src/main/java/io/github/gregtechintergalactical/gtcore/blockentity/BlockEntityPlasticBin.java b/common/src/main/java/io/github/gregtechintergalactical/gtcore/blockentity/BlockEntityPlasticBin.java new file mode 100644 index 0000000..6c983c3 --- /dev/null +++ b/common/src/main/java/io/github/gregtechintergalactical/gtcore/blockentity/BlockEntityPlasticBin.java @@ -0,0 +1,71 @@ +package io.github.gregtechintergalactical.gtcore.blockentity; + +import io.github.gregtechintergalactical.gtcore.data.SlotTypes; +import io.github.gregtechintergalactical.gtcore.machine.MassStorageMachine; +import muramasa.antimatter.data.AntimatterDefaultTools; +import muramasa.antimatter.tool.AntimatterToolType; +import muramasa.antimatter.util.Utils; +import net.minecraft.core.BlockPos; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.BlockHitResult; +import org.jetbrains.annotations.Nullable; + +public class BlockEntityPlasticBin extends BlockEntityMassStorage { + int maxLimit = 128; + public BlockEntityPlasticBin(MassStorageMachine type, BlockPos pos, BlockState state) { + super(type, pos, state); + + } + + public int getMaxLimit() { + return maxLimit; + } + + @Override + public InteractionResult onInteractServer(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit, @Nullable AntimatterToolType type) { + if (type == AntimatterDefaultTools.WIRE_CUTTER){ + int addition = player.isCrouching() ? -64 : 64; + maxLimit += addition; + if (maxLimit == 0) { + maxLimit = 1024; + } + if (maxLimit > 1024) { + maxLimit = 64; + } + //TODO: translation component + player.sendMessage(Utils.literal("Max capacity set to: " + maxLimit), player.getUUID()); + Utils.damageStack(player.getItemInHand(hand), hand, player); + var handler = itemHandler.map(i -> i.getHandler(SlotTypes.UNLIMITED)).orElse(null); + int amountToExtract = handler.getItem(0).getCount() - maxLimit; + if (amountToExtract > 0) { + ItemStack stored = handler.getItem(0); + if (!stored.isEmpty()) { + if (amountToExtract > stored.getMaxStackSize()){ + int toExtract = amountToExtract; + while (toExtract > 0){ + ItemStack toAdd = Utils.ca(Math.min(stored.getMaxStackSize(), toExtract), stored); + toExtract -= toAdd.getCount(); + if (!player.addItem(toAdd)){ + player.drop(toAdd, true); + } + } + } else { + ItemStack toAdd = Utils.ca(amountToExtract, stored); + if (!player.addItem(toAdd)){ + player.drop(toAdd, true); + } + } + handler.extractItem(0, amountToExtract, false); + } + } + + return InteractionResult.SUCCESS; + } + return super.onInteractServer(state, world, pos, player, hand, hit, type); + } +} diff --git a/common/src/main/java/io/github/gregtechintergalactical/gtcore/data/GTCoreBlocks.java b/common/src/main/java/io/github/gregtechintergalactical/gtcore/data/GTCoreBlocks.java index fda7e06..687bfa6 100644 --- a/common/src/main/java/io/github/gregtechintergalactical/gtcore/data/GTCoreBlocks.java +++ b/common/src/main/java/io/github/gregtechintergalactical/gtcore/data/GTCoreBlocks.java @@ -2,6 +2,7 @@ import io.github.gregtechintergalactical.gtcore.GTCore; import io.github.gregtechintergalactical.gtcore.block.BlockSapBag; +import io.github.gregtechintergalactical.gtcore.blockentity.BlockEntityPlasticBin; import io.github.gregtechintergalactical.gtcore.blockentity.BlockEntitySapBag; import io.github.gregtechintergalactical.gtcore.blockentity.BlockEntityTrashCan; import io.github.gregtechintergalactical.gtcore.machine.*; @@ -17,6 +18,7 @@ import muramasa.antimatter.ore.StoneType; import muramasa.antimatter.texture.Texture; import muramasa.antimatter.util.AntimatterPlatformUtils; +import muramasa.antimatter.util.Utils; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.SoundType; @@ -65,6 +67,7 @@ public Texture[] getTextures() { public static final BlockEntityType SAP_BAG_BLOCK_ENTITY = BlockEntityType.Builder.of(BlockEntitySapBag::new, SAP_BAG).build(null); public static MaterialMachine WOOD_ITEM_BARREL; + public static MaterialMachine PLASTIC_STORAGE_BOX; @Nullable public static MaterialMachine IRONWOOD_ITEM_BARREL = null; @@ -96,6 +99,10 @@ public static void init() { public static void initItemBarrels(){ WOOD_ITEM_BARREL = new MassStorageMachine(GTCore.ID, AntimatterMaterials.Wood, "item_storage", 5000).addFlags(MachineFlag.GUI); + PLASTIC_STORAGE_BOX = new MassStorageMachine(GTCore.ID, Plastic, "storage_box", 128).setTile((type, pos, state) -> new BlockEntityPlasticBin((MassStorageMachine) type, pos, state)).addTooltipInfo((blockMachine, itemStack, blockGetter, list, tooltipFlag) -> { + list.remove(2); + list.add(2, Utils.translatable("machine.mass_storage.capacity", "Variable")); + }); if (AntimatterAPI.isModLoaded("twilightforest")){ IRONWOOD_ITEM_BARREL = new MassStorageMachine(GTCore.ID, Ironwood, "item_storage", 10000).addFlags(MachineFlag.GUI); } diff --git a/common/src/main/java/io/github/gregtechintergalactical/gtcore/machine/InfiniteSlotTrackedHandler.java b/common/src/main/java/io/github/gregtechintergalactical/gtcore/machine/InfiniteSlotTrackedHandler.java index f201342..e8001d8 100644 --- a/common/src/main/java/io/github/gregtechintergalactical/gtcore/machine/InfiniteSlotTrackedHandler.java +++ b/common/src/main/java/io/github/gregtechintergalactical/gtcore/machine/InfiniteSlotTrackedHandler.java @@ -1,6 +1,7 @@ package io.github.gregtechintergalactical.gtcore.machine; import io.github.gregtechintergalactical.gtcore.blockentity.BlockEntityMassStorage; +import io.github.gregtechintergalactical.gtcore.blockentity.BlockEntityPlasticBin; import muramasa.antimatter.blockentity.BlockEntityMachine; import muramasa.antimatter.capability.IGuiHandler; import muramasa.antimatter.capability.item.TrackedItemHandler; @@ -27,6 +28,14 @@ protected int getStackLimit(int slot, @NotNull ItemStack stack) { return getSlotLimit(slot); } + @Override + public int getSlotLimit(int slot) { + if (getTile() instanceof BlockEntityPlasticBin bin){ + return bin.getMaxLimit(); + } + return super.getSlotLimit(slot); + } + @Override public @NotNull ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) { if (getTile() instanceof BlockEntityMassStorage barrel && barrel.itemHandler.isPresent()) {