Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
added Plastic Storage Box
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Jun 8, 2024
1 parent 98fae52 commit 0d3fe3c
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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()) {
Expand Down

0 comments on commit 0d3fe3c

Please sign in to comment.