diff --git a/common/src/main/java/io/github/gregtechintergalactical/gtcore/blockentity/BlockEntityItemBarrel.java b/common/src/main/java/io/github/gregtechintergalactical/gtcore/blockentity/BlockEntityItemBarrel.java new file mode 100644 index 0000000..82c02bb --- /dev/null +++ b/common/src/main/java/io/github/gregtechintergalactical/gtcore/blockentity/BlockEntityItemBarrel.java @@ -0,0 +1,66 @@ +package io.github.gregtechintergalactical.gtcore.blockentity; + +import io.github.gregtechintergalactical.gtcore.machine.ItemBarrelMachine; +import io.github.gregtechintergalactical.gtcore.machine.ItemBarreltItemHandler; +import io.github.gregtechintergalactical.gtcore.machine.MaterialMachine; +import muramasa.antimatter.machine.types.Machine; +import muramasa.antimatter.tool.AntimatterToolType; +import muramasa.antimatter.util.Utils; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +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 net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.Nullable; + +public class BlockEntityItemBarrel extends BlockEntityMaterial { + public BlockEntityItemBarrel(ItemBarrelMachine type, BlockPos pos, BlockState state) { + super(type, pos, state); + this.itemHandler.set(() -> new ItemBarreltItemHandler(this)); + } + + @Override + public InteractionResult onInteractServer(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit, @Nullable AntimatterToolType type) { + Vec3 vec = hit.getLocation(); + if (hit.getDirection().getAxis().isHorizontal()){ + double x = hit.getDirection().getAxis() == Direction.Axis.Z ? vec.x() - hit.getBlockPos().getX() : vec.z() - hit.getBlockPos().getZ(), y = vec.y() - hit.getBlockPos().getY(); + int amountToExtract = 0; + + + if (x > 0.0625 && x < 0.1875) { + if (y > 0.0625 && y < 0.1875){ + amountToExtract = 1; + } + + } else if (x > 0.8125 && x < 0.9375) { + if (y > 0.0625 && y < 0.1875){ + amountToExtract = 16; + } + + } else if (x > 0.25 && x < 0.75){ + if (y > 0.0625 && y < 0.625){ + ItemStack stack = player.getItemInHand(hand); + + } + } + } + + return super.onInteractServer(state, world, pos, player, hand, hit, type); + } + + //TODO + /*@Override + public void drawInfo(MatrixStack stack, FontRenderer renderer, int left, int top) { + this.itemHandler.ifPresent(m -> { + if (m instanceof QuantumChestItemHandler){ + QuantumChestItemHandler handler = (QuantumChestItemHandler) m; + handler.drawInfo(stack, renderer, left, top); + } + }); + }*/ +} diff --git a/common/src/main/java/io/github/gregtechintergalactical/gtcore/machine/ItemBarrelMachine.java b/common/src/main/java/io/github/gregtechintergalactical/gtcore/machine/ItemBarrelMachine.java new file mode 100644 index 0000000..5096dde --- /dev/null +++ b/common/src/main/java/io/github/gregtechintergalactical/gtcore/machine/ItemBarrelMachine.java @@ -0,0 +1,17 @@ +package io.github.gregtechintergalactical.gtcore.machine; + +import io.github.gregtechintergalactical.gtcore.blockentity.BlockEntityItemBarrel; +import muramasa.antimatter.material.Material; + +public class ItemBarrelMachine extends MaterialMachine{ + final int capacity; + public ItemBarrelMachine(String domain, String id, Material material, int capacity) { + super(domain, id, material); + this.setTile((m, p, s) -> new BlockEntityItemBarrel(this, p, s)); + this.capacity = capacity; + } + + public int getCapacity() { + return capacity; + } +} diff --git a/common/src/main/java/io/github/gregtechintergalactical/gtcore/machine/ItemBarreltItemHandler.java b/common/src/main/java/io/github/gregtechintergalactical/gtcore/machine/ItemBarreltItemHandler.java new file mode 100644 index 0000000..ed874c6 --- /dev/null +++ b/common/src/main/java/io/github/gregtechintergalactical/gtcore/machine/ItemBarreltItemHandler.java @@ -0,0 +1,73 @@ +package io.github.gregtechintergalactical.gtcore.machine; + + +import io.github.gregtechintergalactical.gtcore.blockentity.BlockEntityItemBarrel; +import muramasa.antimatter.capability.IGuiHandler; +import muramasa.antimatter.capability.item.TrackedItemHandler; +import muramasa.antimatter.capability.machine.MachineItemHandler; +import muramasa.antimatter.gui.SlotType; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.Tag; +import net.minecraft.world.item.ItemStack; + +import javax.annotation.Nonnull; +import java.util.function.BiPredicate; + +public class ItemBarreltItemHandler extends MachineItemHandler { + int maxSize = Integer.MAX_VALUE; + int digitalCount; + public ItemBarreltItemHandler(BlockEntityItemBarrel tile) { + super(tile); + inventories.put(SlotType.STORAGE, new QuantumSlotTrackedHandler(tile, SlotType.STORAGE, 1, SlotType.STORAGE.output, SlotType.STORAGE.input, SlotType.STORAGE.tester, ((ItemBarrelMachine)tile.getMachineType()).getCapacity())); + } + + public static class QuantumSlotTrackedHandler extends TrackedItemHandler { + + public QuantumSlotTrackedHandler(BlockEntityItemBarrel tile, SlotType type, int size, boolean output, boolean input, BiPredicate validator, int limit) { + super(tile, type, size, output, input, validator, limit); + } + + @Override + protected int getStackLimit(int slot, @Nonnull ItemStack stack) { + return getSlotLimit(slot); + } + + @Override + public CompoundTag serialize(CompoundTag nbt) { + ListTag nbtTagList = new ListTag(); + for (int i = 0; i < stacks.size(); i++) { + if (!stacks.get(i).isEmpty()) { + CompoundTag itemTag = new CompoundTag(); + itemTag.putInt("Slot", i); + stacks.get(i).save(itemTag); + itemTag.putInt("count", stacks.get(i).getCount()); + nbtTagList.add(itemTag); + } + } + nbt.put("Items", nbtTagList); + return nbt; + } + + @Override + public void deserialize(CompoundTag nbt) { + ListTag tagList = nbt.getList("Items", Tag.TAG_COMPOUND); + for (int i = 0; i < tagList.size(); i++) { + CompoundTag itemTags = tagList.getCompound(i); + int slot = itemTags.getInt("Slot"); + if (slot >= 0 && slot < stacks.size()) { + stacks.set(slot, ItemStack.of(itemTags)); + stacks.get(slot).setCount(itemTags.getInt("count")); + } + } + onLoad(); + } + + + } + + /*public void drawInfo(MatrixStack stack, FontRenderer renderer, int left, int top) { + // TODO: Replace by new TranslationTextComponent() + renderer.draw(stack,"Item amount: " + digitalCount, left + 10, top + 19, 16448255); + }*/ +}