diff --git a/src/main/java/techreborn/client/container/builder/slot/UpgradeSlot.java b/src/main/java/techreborn/client/container/builder/slot/UpgradeSlot.java index a26ed2635..e02d60962 100644 --- a/src/main/java/techreborn/client/container/builder/slot/UpgradeSlot.java +++ b/src/main/java/techreborn/client/container/builder/slot/UpgradeSlot.java @@ -55,7 +55,7 @@ public class UpgradeSlot extends BaseSlot implements IRightClickHandler { public boolean handleRightClick(int slotID, EntityPlayer player, BuiltContainer container) { if (inventory instanceof Inventory) { Inventory inv = (Inventory) inventory; - TileEntity tileEntity = inv.getTileBase(); + TileEntity tileEntity = inv.getTile(); if (tileEntity instanceof IUpgradeable) { IUpgradeable upgradeable = (IUpgradeable) tileEntity; if (upgradeable.canBeUpgraded()) { diff --git a/src/main/java/techreborn/client/gui/slot/GuiSlotConfiguration.java b/src/main/java/techreborn/client/gui/slot/GuiSlotConfiguration.java index 388172007..43f8bed94 100644 --- a/src/main/java/techreborn/client/gui/slot/GuiSlotConfiguration.java +++ b/src/main/java/techreborn/client/gui/slot/GuiSlotConfiguration.java @@ -32,6 +32,9 @@ import net.minecraft.inventory.Slot; import net.minecraft.util.text.TextComponentString; import net.minecraftforge.client.event.GuiScreenEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.items.CapabilityItemHandler; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.SlotItemHandler; import org.lwjgl.input.Keyboard; import reborncore.client.gui.GuiUtil; import reborncore.common.network.NetworkManager; @@ -64,10 +67,16 @@ public class GuiSlotConfiguration { public static void init(GuiBase guiBase) { reset(); slotElementMap.clear(); + IItemHandler itemHandler = getMachine().getInventoryForTile().orElseGet(null); + if(itemHandler == null){ + return; + } BuiltContainer container = guiBase.container; for (Slot slot : container.inventorySlots) { - if (guiBase.tile != slot.inventory) { + if(!(slot instanceof SlotItemHandler)){ + continue; + } else if (((SlotItemHandler) slot).getItemHandler() != itemHandler){ continue; } ConfigSlotElement slotElement = new ConfigSlotElement(guiBase.getMachine().getInventoryForTile().get(), slot.getSlotIndex(), SlotType.NORMAL, slot.xPos - guiBase.guiLeft + 50, slot.yPos - guiBase.guiTop - 25, guiBase); @@ -77,9 +86,15 @@ public class GuiSlotConfiguration { } public static void draw(GuiBase guiBase, int mouseX, int mouseY) { + IItemHandler itemHandler = getMachine().getInventoryForTile().orElseGet(null); + if(itemHandler == null){ + return; + } BuiltContainer container = guiBase.container; for (Slot slot : container.inventorySlots) { - if (guiBase.tile != slot.inventory) { + if(!(slot instanceof SlotItemHandler)){ + continue; + } else if (((SlotItemHandler) slot).getItemHandler() != itemHandler){ continue; } GlStateManager.color(255, 0, 0); @@ -172,8 +187,11 @@ public class GuiSlotConfiguration { BuiltContainer container = guiBase.container; if(getVisibleElements().isEmpty()) { + IItemHandler itemHandler = getMachine().getInventoryForTile().orElseGet(null); for (Slot slot : container.inventorySlots) { - if (guiBase.tile != slot.inventory) { + if(!(slot instanceof SlotItemHandler)){ + continue; + } else if (((SlotItemHandler) slot).getItemHandler() != itemHandler){ continue; } if (guiBase.isPointInRect(slot.xPos, slot.yPos, 18, 18, mouseX, mouseY)) { diff --git a/src/main/java/techreborn/tiles/TileChargeOMat.java b/src/main/java/techreborn/tiles/TileChargeOMat.java index 1701050fa..9f8ec2fc1 100644 --- a/src/main/java/techreborn/tiles/TileChargeOMat.java +++ b/src/main/java/techreborn/tiles/TileChargeOMat.java @@ -51,7 +51,7 @@ public class TileChargeOMat extends TilePowerAcceptor @ConfigRegistry(config = "machines", category = "charge_bench", key = "ChargeBenchMaxEnergy", comment = "Charge Bench Max Energy (Value in EU)") public static int maxEnergy = 100_000_000; - public Inventory inventory = new Inventory(6, "TileChargeOMat", 64, this); + public Inventory inventory = new Inventory<>(6, "TileChargeOMat", 64, this); public TileChargeOMat() { super(); diff --git a/src/main/java/techreborn/tiles/TileChunkLoader.java b/src/main/java/techreborn/tiles/TileChunkLoader.java index af5c0ec03..11b735d1f 100644 --- a/src/main/java/techreborn/tiles/TileChunkLoader.java +++ b/src/main/java/techreborn/tiles/TileChunkLoader.java @@ -49,7 +49,7 @@ public class TileChunkLoader extends TilePowerAcceptor implements IToolDrop, Ite // @ConfigRegistry(config = "machines", category = "chunk_loader", key = "ChunkLoaderWrenchDropRate", comment = "Chunk Loader Wrench Drop Rate") public static float wrenchDropRate = 1.0F; - public Inventory inventory = new Inventory(1, "TileChunkLoader", 64, this); + public Inventory inventory = new Inventory<>(1, "TileChunkLoader", 64, this); public boolean isRunning; public int tickTime; diff --git a/src/main/java/techreborn/tiles/TileIndustrialCentrifuge.java b/src/main/java/techreborn/tiles/TileIndustrialCentrifuge.java index de68b533a..70c6428d4 100644 --- a/src/main/java/techreborn/tiles/TileIndustrialCentrifuge.java +++ b/src/main/java/techreborn/tiles/TileIndustrialCentrifuge.java @@ -53,7 +53,7 @@ public class TileIndustrialCentrifuge extends TileGenericMachine implements ICon super("IndustrialCentrifuge", maxInput, maxEnergy, ModBlocks.INDUSTRIAL_CENTRIFUGE, 6); final int[] inputs = new int[] { 0, 1 }; final int[] outputs = new int[] { 2, 3, 4, 5 }; - this.inventory = new Inventory(7, "TileIndustrialCentrifuge", 64, this); + this.inventory = new Inventory<>(7, "TileIndustrialCentrifuge", 64, this); this.crafter = new RecipeCrafter(Reference.CENTRIFUGE_RECIPE, this, 2, 4, this.inventory, inputs, outputs); } diff --git a/src/main/java/techreborn/tiles/TileMatterFabricator.java b/src/main/java/techreborn/tiles/TileMatterFabricator.java index 08cfb019f..d4f86c845 100644 --- a/src/main/java/techreborn/tiles/TileMatterFabricator.java +++ b/src/main/java/techreborn/tiles/TileMatterFabricator.java @@ -55,7 +55,7 @@ public class TileMatterFabricator extends TilePowerAcceptor @ConfigRegistry(config = "machines", category = "matter_fabricator", key = "MatterFabricatorEnergyPerAmp", comment = "Matter Fabricator EU per amplifier unit, multiply this with the rate for total EU") public static int energyPerAmp = 5; - public Inventory inventory = new Inventory(12, "TileMatterFabricator", 64, this); + public Inventory inventory = new Inventory<>(12, "TileMatterFabricator", 64, this); private int amplifier = 0; public TileMatterFabricator() { diff --git a/src/main/java/techreborn/tiles/TileQuantumTank.java b/src/main/java/techreborn/tiles/TileQuantumTank.java index 70b99d673..1ca0fb886 100644 --- a/src/main/java/techreborn/tiles/TileQuantumTank.java +++ b/src/main/java/techreborn/tiles/TileQuantumTank.java @@ -55,7 +55,7 @@ public class TileQuantumTank extends TileLegacyMachineBase public static int maxStorage = Integer.MAX_VALUE; public Tank tank = new Tank("TileQuantumTank", maxStorage, this); - public Inventory inventory = new Inventory(3, "TileQuantumTank", 64, this); + public Inventory inventory = new Inventory<>(3, "TileQuantumTank", 64, this); public void readFromNBTWithoutCoords(final NBTTagCompound tagCompound) { tank.readFromNBT(tagCompound); diff --git a/src/main/java/techreborn/tiles/TileTechStorageBase.java b/src/main/java/techreborn/tiles/TileTechStorageBase.java index 38ffd1f2d..9148215cc 100644 --- a/src/main/java/techreborn/tiles/TileTechStorageBase.java +++ b/src/main/java/techreborn/tiles/TileTechStorageBase.java @@ -53,7 +53,7 @@ public class TileTechStorageBase extends TileLegacyMachineBase public TileTechStorageBase(String name, int maxCapacity) { this.maxCapacity = maxCapacity; storedItem = ItemStack.EMPTY; - inventory = new Inventory(3, name, maxCapacity, this); + inventory = new Inventory<>(3, name, maxCapacity, this); } public void readFromNBTWithoutCoords(NBTTagCompound tagCompound) { diff --git a/src/main/java/techreborn/tiles/fusionReactor/TileFusionControlComputer.java b/src/main/java/techreborn/tiles/fusionReactor/TileFusionControlComputer.java index 5afdd1282..b33b2859f 100644 --- a/src/main/java/techreborn/tiles/fusionReactor/TileFusionControlComputer.java +++ b/src/main/java/techreborn/tiles/fusionReactor/TileFusionControlComputer.java @@ -78,7 +78,7 @@ public class TileFusionControlComputer extends TilePowerAcceptor public TileFusionControlComputer() { super(); checkOverfill = false; - this.inventory = new Inventory(3, "TileFusionControlComputer", 64, this); + this.inventory = new Inventory<>(3, "TileFusionControlComputer", 64, this); } /** diff --git a/src/main/java/techreborn/tiles/generator/TileBaseFluidGenerator.java b/src/main/java/techreborn/tiles/generator/TileBaseFluidGenerator.java index 6b5a8c031..4bf781cf8 100644 --- a/src/main/java/techreborn/tiles/generator/TileBaseFluidGenerator.java +++ b/src/main/java/techreborn/tiles/generator/TileBaseFluidGenerator.java @@ -62,7 +62,7 @@ public abstract class TileBaseFluidGenerator extends TilePowerAcceptor implement super(); recipes = GeneratorRecipeHelper.getFluidRecipesForGenerator(type); tank = new Tank(tileName, tankCapacity, this); - inventory = new Inventory(3, tileName, 64, this); + inventory = new Inventory<>(3, tileName, 64, this); this.euTick = euTick; this.ticksSinceLastChange = 0; } diff --git a/src/main/java/techreborn/tiles/generator/TileDragonEggSyphon.java b/src/main/java/techreborn/tiles/generator/TileDragonEggSyphon.java index 64e728a8f..35adf610d 100644 --- a/src/main/java/techreborn/tiles/generator/TileDragonEggSyphon.java +++ b/src/main/java/techreborn/tiles/generator/TileDragonEggSyphon.java @@ -50,7 +50,7 @@ public class TileDragonEggSyphon extends TilePowerAcceptor @ConfigRegistry(config = "generators", category = "dragon_egg_siphoner", key = "DragonEggSiphonerEnergyPerTick", comment = "Dragon Egg Siphoner Energy Per Tick (Value in EU)") public static int energyPerTick = 4; - public Inventory inventory = new Inventory(3, "TileDragonEggSyphon", 64, this); + public Inventory inventory = new Inventory<>(3, "TileDragonEggSyphon", 64, this); private long lastOutput = 0; public TileDragonEggSyphon() { diff --git a/src/main/java/techreborn/tiles/generator/TileSolidFuelGenerator.java b/src/main/java/techreborn/tiles/generator/TileSolidFuelGenerator.java index f57b62116..65668c407 100644 --- a/src/main/java/techreborn/tiles/generator/TileSolidFuelGenerator.java +++ b/src/main/java/techreborn/tiles/generator/TileSolidFuelGenerator.java @@ -54,7 +54,7 @@ public class TileSolidFuelGenerator extends TilePowerAcceptor implements IToolDr @ConfigRegistry(config = "generators", category = "generator", key = "GeneratorEnergyOutput", comment = "Solid Fuel Generator Energy Output Amount (Value in EU)") public static int outputAmount = 10; - public Inventory inventory = new Inventory(2, "TileSolidFuelGenerator", 64, this); + public Inventory inventory = new Inventory<>(2, "TileSolidFuelGenerator", 64, this); public int fuelSlot = 0; public int burnTime; public int totalBurnTime = 0; diff --git a/src/main/java/techreborn/tiles/multiblock/TileDistillationTower.java b/src/main/java/techreborn/tiles/multiblock/TileDistillationTower.java index ec4c9de82..75ca4e4ab 100644 --- a/src/main/java/techreborn/tiles/multiblock/TileDistillationTower.java +++ b/src/main/java/techreborn/tiles/multiblock/TileDistillationTower.java @@ -53,7 +53,7 @@ public class TileDistillationTower extends TileGenericMachine implements IContai super("DistillationTower", maxInput, maxEnergy, ModBlocks.DISTILLATION_TOWER, 6); final int[] inputs = new int[] { 0, 1 }; final int[] outputs = new int[] { 2, 3, 4, 5 }; - this.inventory = new Inventory(7, "TileDistillationTower", 64, this); + this.inventory = new Inventory<>(7, "TileDistillationTower", 64, this); this.crafter = new RecipeCrafter(Reference.DISTILLATION_TOWER_RECIPE, this, 2, 4, this.inventory, inputs, outputs); } diff --git a/src/main/java/techreborn/tiles/multiblock/TileFluidReplicator.java b/src/main/java/techreborn/tiles/multiblock/TileFluidReplicator.java index 30418174f..05295358d 100644 --- a/src/main/java/techreborn/tiles/multiblock/TileFluidReplicator.java +++ b/src/main/java/techreborn/tiles/multiblock/TileFluidReplicator.java @@ -28,10 +28,12 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import reborncore.common.recipes.RecipeCrafter; import reborncore.common.registration.RebornRegistry; import reborncore.common.registration.impl.ConfigRegistry; import reborncore.common.util.FluidUtils; +import reborncore.common.util.IInventoryAccess; import reborncore.common.util.Inventory; import reborncore.common.util.Tank; import techreborn.api.fluidreplicator.FluidReplicatorRecipeCrafter; @@ -66,7 +68,7 @@ public class TileFluidReplicator extends TileGenericMachine implements IContaine public TileFluidReplicator() { super("FluidReplicator", maxInput, maxEnergy, ModBlocks.FLUID_REPLICATOR, 3); final int[] inputs = new int[] { 0 }; - this.inventory = new Inventory(4, "TileFluidReplicator", 64, this); + this.inventory = new Inventory<>(4, "TileFluidReplicator", 64, this, getInventoryAccess()); this.crafter = new FluidReplicatorRecipeCrafter(this, this.inventory, inputs, null); this.tank = new Tank("TileFluidReplicator", TileFluidReplicator.TANK_CAPACITY, this); } @@ -123,17 +125,13 @@ public class TileFluidReplicator extends TileGenericMachine implements IContaine return tagCompound; } - // TileLegacyMachineBase - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack) { - if (slotIndex == 0) { - if (itemStack.isItemEqual(TRIngredients.Parts.UU_MATTER.getStack())) { - return true; - } else { - return false; + private static IInventoryAccess getInventoryAccess(){ + return (slotID, stack, face, direction, tile) -> { + if(slotID == 0){ + return stack.isItemEqual(TRIngredients.Parts.UU_MATTER.getStack()); } - } - return super.isItemValidForSlot(slotIndex, itemStack); + return true; + }; } // IContainerProvider diff --git a/src/main/java/techreborn/tiles/multiblock/TileImplosionCompressor.java b/src/main/java/techreborn/tiles/multiblock/TileImplosionCompressor.java index bd321d29f..d545092fc 100644 --- a/src/main/java/techreborn/tiles/multiblock/TileImplosionCompressor.java +++ b/src/main/java/techreborn/tiles/multiblock/TileImplosionCompressor.java @@ -52,7 +52,7 @@ public class TileImplosionCompressor extends TileGenericMachine implements ICont super("ImplosionCompressor", maxInput, maxEnergy, ModBlocks.IMPLOSION_COMPRESSOR, 4); final int[] inputs = new int[] { 0, 1 }; final int[] outputs = new int[] { 2, 3 }; - this.inventory = new Inventory(5, "TileImplosionCompressor", 64, this); + this.inventory = new Inventory<>(5, "TileImplosionCompressor", 64, this); this.crafter = new RecipeCrafter(Reference.IMPLOSION_COMPRESSOR_RECIPE, this, 2, 2, this.inventory, inputs, outputs); } diff --git a/src/main/java/techreborn/tiles/multiblock/TileIndustrialBlastFurnace.java b/src/main/java/techreborn/tiles/multiblock/TileIndustrialBlastFurnace.java index db126caea..fc47a0671 100644 --- a/src/main/java/techreborn/tiles/multiblock/TileIndustrialBlastFurnace.java +++ b/src/main/java/techreborn/tiles/multiblock/TileIndustrialBlastFurnace.java @@ -64,7 +64,7 @@ public class TileIndustrialBlastFurnace extends TileGenericMachine implements IC super("IndustrialBlastFurnace", maxInput, maxEnergy, ModBlocks.INDUSTRIAL_BLAST_FURNACE, 4); final int[] inputs = new int[] { 0, 1 }; final int[] outputs = new int[] { 2, 3 }; - this.inventory = new Inventory(5, "TileIndustrialBlastFurnace", 64, this); + this.inventory = new Inventory<>(5, "TileIndustrialBlastFurnace", 64, this); this.crafter = new RecipeCrafter(Reference.BLAST_FURNACE_RECIPE, this, 2, 2, this.inventory, inputs, outputs); } diff --git a/src/main/java/techreborn/tiles/multiblock/TileIndustrialGrinder.java b/src/main/java/techreborn/tiles/multiblock/TileIndustrialGrinder.java index 9a6d5742a..ccc108107 100644 --- a/src/main/java/techreborn/tiles/multiblock/TileIndustrialGrinder.java +++ b/src/main/java/techreborn/tiles/multiblock/TileIndustrialGrinder.java @@ -39,6 +39,7 @@ import reborncore.common.recipes.RecipeCrafter; import reborncore.common.registration.RebornRegistry; import reborncore.common.registration.impl.ConfigRegistry; import reborncore.common.util.FluidUtils; +import reborncore.common.util.IInventoryAccess; import reborncore.common.util.Inventory; import reborncore.common.util.Tank; import techreborn.api.Reference; @@ -48,6 +49,7 @@ import techreborn.client.container.IContainerProvider; import techreborn.client.container.builder.BuiltContainer; import techreborn.client.container.builder.ContainerBuilder; import techreborn.init.ModBlocks; +import techreborn.init.TRIngredients; import techreborn.lib.ModInfo; import techreborn.tiles.TileGenericMachine; @@ -70,7 +72,7 @@ public class TileIndustrialGrinder extends TileGenericMachine implements IContai super("IndustrialGrinder", maxInput, maxEnergy, ModBlocks.INDUSTRIAL_GRINDER, 7); final int[] inputs = new int[] { 0, 1 }; final int[] outputs = new int[] {2, 3, 4, 5}; - this.inventory = new Inventory(8, "TileIndustrialGrinder", 64, this); + this.inventory = new Inventory<>(8, "TileIndustrialGrinder", 64, this, getInventoryAccess()); this.crafter = new RecipeCrafter(Reference.INDUSTRIAL_GRINDER_RECIPE, this, 1, 4, this.inventory, inputs, outputs); this.tank = new Tank("TileIndustrialGrinder", TileIndustrialGrinder.TANK_CAPACITY, this); this.ticksSinceLastChange = 0; @@ -128,18 +130,13 @@ public class TileIndustrialGrinder extends TileGenericMachine implements IContai return tagCompound; } - // TileLegacyMachineBase - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack) { - if (slotIndex == 1) { - if (itemStack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)){ - return true; + private static IInventoryAccess getInventoryAccess(){ + return (slotID, stack, face, direction, tile) -> { + if(slotID == 1){ + return stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); } - else { - return false; - } - } - return super.isItemValidForSlot(slotIndex, itemStack); + return true; + }; } // IContainerProvider diff --git a/src/main/java/techreborn/tiles/multiblock/TileIndustrialSawmill.java b/src/main/java/techreborn/tiles/multiblock/TileIndustrialSawmill.java index 64ba18d50..2f009a55c 100644 --- a/src/main/java/techreborn/tiles/multiblock/TileIndustrialSawmill.java +++ b/src/main/java/techreborn/tiles/multiblock/TileIndustrialSawmill.java @@ -31,6 +31,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidBlock; @@ -39,6 +40,7 @@ import reborncore.common.recipes.RecipeCrafter; import reborncore.common.registration.RebornRegistry; import reborncore.common.registration.impl.ConfigRegistry; import reborncore.common.util.FluidUtils; +import reborncore.common.util.IInventoryAccess; import reborncore.common.util.Inventory; import reborncore.common.util.Tank; import techreborn.api.Reference; @@ -50,6 +52,7 @@ import techreborn.client.container.builder.ContainerBuilder; import techreborn.init.ModBlocks; import techreborn.lib.ModInfo; import techreborn.tiles.TileGenericMachine; +import techreborn.tiles.tier1.TileAutoCraftingTable; import javax.annotation.Nullable; @@ -70,7 +73,7 @@ public class TileIndustrialSawmill extends TileGenericMachine implements IContai super("IndustrialSawmill", maxInput, maxEnergy, ModBlocks.INDUSTRIAL_SAWMILL, 6); final int[] inputs = new int[] { 0, 1 }; final int[] outputs = new int[] { 2, 3, 4 }; - this.inventory = new Inventory(7, "TileSawmill", 64, this); + this.inventory = new Inventory<>(7, "TileSawmill", 64, this, getInventoryAccess()); this.crafter = new RecipeCrafter(Reference.INDUSTRIAL_SAWMILL_RECIPE, this, 1, 3, this.inventory, inputs, outputs); this.tank = new Tank("TileSawmill", TileIndustrialSawmill.TANK_CAPACITY, this); this.ticksSinceLastChange = 0; @@ -128,19 +131,16 @@ public class TileIndustrialSawmill extends TileGenericMachine implements IContai return tagCompound; } - // TileLegacyMachineBase - @Override - public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack) { - if (slotIndex == 1) { - if (itemStack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) { - return true; - } else { - return false; + private static IInventoryAccess getInventoryAccess(){ + return (slotID, stack, face, direction, tile) -> { + if(direction == IInventoryAccess.AccessDirection.INSERT){ + return stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); } - } - return super.isItemValidForSlot(slotIndex, itemStack); + return true; + }; } + // IContainerProvider @Override public BuiltContainer createContainer(final EntityPlayer player) { diff --git a/src/main/java/techreborn/tiles/multiblock/TileVacuumFreezer.java b/src/main/java/techreborn/tiles/multiblock/TileVacuumFreezer.java index 46651f182..8832165be 100644 --- a/src/main/java/techreborn/tiles/multiblock/TileVacuumFreezer.java +++ b/src/main/java/techreborn/tiles/multiblock/TileVacuumFreezer.java @@ -51,7 +51,7 @@ public class TileVacuumFreezer extends TileGenericMachine implements IContainerP super("VacuumFreezer", maxInput, maxEnergy, ModBlocks.VACUUM_FREEZER, 2); final int[] inputs = new int[] { 0 }; final int[] outputs = new int[] { 1 }; - this.inventory = new Inventory(3, "TileVacuumFreezer", 64, this); + this.inventory = new Inventory<>(3, "TileVacuumFreezer", 64, this); this.crafter = new RecipeCrafter(Reference.VACUUM_FREEZER_RECIPE, this, 2, 1, this.inventory, inputs, outputs); } diff --git a/src/main/java/techreborn/tiles/storage/TileAdjustableSU.java b/src/main/java/techreborn/tiles/storage/TileAdjustableSU.java index 389f1fde1..9cad28b60 100644 --- a/src/main/java/techreborn/tiles/storage/TileAdjustableSU.java +++ b/src/main/java/techreborn/tiles/storage/TileAdjustableSU.java @@ -47,7 +47,7 @@ public class TileAdjustableSU extends TileEnergyStorage implements IContainerPro @ConfigRegistry(config = "machines", category = "aesu", key = "AesuMaxEnergy", comment = "AESU Max Energy (Value in EU)") public static int maxEnergy = 100_000_000; - public Inventory inventory = new Inventory(4, "TileAdjustableSU", 64, this); + public Inventory inventory = new Inventory<>(4, "TileAdjustableSU", 64, this); private int OUTPUT = 64; // The current output public TileAdjustableSU() { diff --git a/src/main/java/techreborn/tiles/storage/TileEnergyStorage.java b/src/main/java/techreborn/tiles/storage/TileEnergyStorage.java index 8e1b4fa85..d252b2c41 100644 --- a/src/main/java/techreborn/tiles/storage/TileEnergyStorage.java +++ b/src/main/java/techreborn/tiles/storage/TileEnergyStorage.java @@ -54,7 +54,7 @@ public class TileEnergyStorage extends TilePowerAcceptor public TileEnergyStorage(String name, int invSize, Block wrenchDrop, EnumPowerTier tier, int maxInput, int maxOuput, int maxStorage) { super(); - inventory = new Inventory(invSize, "Tile" + name, 64, this); + inventory = new Inventory<>(invSize, "Tile" + name, 64, this); this.wrenchDrop = wrenchDrop; this.tier = tier; this.name = name; diff --git a/src/main/java/techreborn/tiles/tier0/TileIronAlloyFurnace.java b/src/main/java/techreborn/tiles/tier0/TileIronAlloyFurnace.java index 33a1836d3..09ab5f4be 100644 --- a/src/main/java/techreborn/tiles/tier0/TileIronAlloyFurnace.java +++ b/src/main/java/techreborn/tiles/tier0/TileIronAlloyFurnace.java @@ -53,7 +53,7 @@ public class TileIronAlloyFurnace extends TileLegacyMachineBase implements IToolDrop, ItemHandlerProvider, IContainerProvider { public int tickTime; - public Inventory inventory = new Inventory(4, "TileIronAlloyFurnace", 64, this); + public Inventory inventory = new Inventory<>(4, "TileIronAlloyFurnace", 64, this); public int burnTime; public int currentItemBurnTime; public int cookTime; diff --git a/src/main/java/techreborn/tiles/tier0/TileIronFurnace.java b/src/main/java/techreborn/tiles/tier0/TileIronFurnace.java index ad27fa468..6c19d6342 100644 --- a/src/main/java/techreborn/tiles/tier0/TileIronFurnace.java +++ b/src/main/java/techreborn/tiles/tier0/TileIronFurnace.java @@ -29,9 +29,11 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.tileentity.TileEntityFurnace; +import net.minecraft.util.EnumFacing; import reborncore.api.tile.ItemHandlerProvider; import reborncore.common.blocks.BlockMachineBase; import reborncore.common.tile.TileLegacyMachineBase; +import reborncore.common.util.IInventoryAccess; import reborncore.common.util.Inventory; import reborncore.common.util.ItemUtils; import techreborn.client.container.IContainerProvider; @@ -42,7 +44,7 @@ public class TileIronFurnace extends TileLegacyMachineBase implements ItemHandlerProvider, IContainerProvider { public int tickTime; - public Inventory inventory = new Inventory(3, "TileIronFurnace", 64, this); + public Inventory inventory = new Inventory<>(3, "TileIronFurnace", 64, this, getInvetoryAccess()); public int fuel; public int fuelGague; public int progress; @@ -168,16 +170,20 @@ public class TileIronFurnace extends TileLegacyMachineBase return this.inventory; } - @Override - public boolean isItemValidForSlot(int index, ItemStack stack) { - boolean isFuel = TileEntityFurnace.isItemFuel(stack); - if(isFuel){ - ItemStack fuelSlotStack = inventory.getStackInSlot(fuelslot); - if(fuelSlotStack.isEmpty() || ItemUtils.isItemEqual(stack, fuelSlotStack, true, true) && fuelSlotStack.getMaxStackSize() != fuelSlotStack.getCount()){ - return index == fuelslot; + public static IInventoryAccess getInvetoryAccess(){ + return (slotID, stack, face, direction, tile) -> { + if(direction == IInventoryAccess.AccessDirection.INSERT){ + boolean isFuel = TileEntityFurnace.isItemFuel(stack); + if(isFuel){ + ItemStack fuelSlotStack = tile.inventory.getStackInSlot(tile.fuelslot); + if(fuelSlotStack.isEmpty() || ItemUtils.isItemEqual(stack, fuelSlotStack, true, true) && fuelSlotStack.getMaxStackSize() != fuelSlotStack.getCount()){ + return slotID == tile.fuelslot; + } + } + return slotID != tile.output; } - } - return index != output; + return true; + }; } public int getBurnTime() { diff --git a/src/main/java/techreborn/tiles/tier1/TileAlloySmelter.java b/src/main/java/techreborn/tiles/tier1/TileAlloySmelter.java index d47c7d28b..c3bb2db50 100644 --- a/src/main/java/techreborn/tiles/tier1/TileAlloySmelter.java +++ b/src/main/java/techreborn/tiles/tier1/TileAlloySmelter.java @@ -52,7 +52,7 @@ public class TileAlloySmelter extends TileGenericMachine implements IContainerPr super("AlloySmelter", maxInput, maxEnergy, ModBlocks.ALLOY_SMELTER, 3); final int[] inputs = new int[] { 0, 1 }; final int[] outputs = new int[] { 2 }; - this.inventory = new Inventory(4, "TileAlloySmelter", 64, this); + this.inventory = new Inventory<>(4, "TileAlloySmelter", 64, this); this.crafter = new RecipeCrafter(Reference.ALLOY_SMELTER_RECIPE, this, 2, 1, this.inventory, inputs, outputs); } diff --git a/src/main/java/techreborn/tiles/tier1/TileAssemblingMachine.java b/src/main/java/techreborn/tiles/tier1/TileAssemblingMachine.java index b5e8738c5..de852bf18 100644 --- a/src/main/java/techreborn/tiles/tier1/TileAssemblingMachine.java +++ b/src/main/java/techreborn/tiles/tier1/TileAssemblingMachine.java @@ -49,7 +49,7 @@ public class TileAssemblingMachine extends TileGenericMachine implements IContai super("AssemblingMachine", maxInput, maxEnergy, ModBlocks.ASSEMBLY_MACHINE, 3); final int[] inputs = new int[] { 0, 1 }; final int[] outputs = new int[] { 2 }; - this.inventory = new Inventory(4, "TileAssemblingMachine", 64, this); + this.inventory = new Inventory<>(4, "TileAssemblingMachine", 64, this); this.crafter = new RecipeCrafter(Reference.ASSEMBLING_MACHINE_RECIPE, this, 2, 2, this.inventory, inputs, outputs); } diff --git a/src/main/java/techreborn/tiles/tier1/TileAutoCraftingTable.java b/src/main/java/techreborn/tiles/tier1/TileAutoCraftingTable.java index 86c37d432..e6c24e368 100644 --- a/src/main/java/techreborn/tiles/tier1/TileAutoCraftingTable.java +++ b/src/main/java/techreborn/tiles/tier1/TileAutoCraftingTable.java @@ -41,6 +41,8 @@ import reborncore.api.tile.ItemHandlerProvider; import reborncore.common.powerSystem.TilePowerAcceptor; import reborncore.common.registration.RebornRegistry; import reborncore.common.registration.impl.ConfigRegistry; +import reborncore.common.tile.TileLegacyMachineBase; +import reborncore.common.util.IInventoryAccess; import reborncore.common.util.Inventory; import reborncore.common.util.ItemUtils; import techreborn.client.container.IContainerProvider; @@ -66,7 +68,7 @@ public class TileAutoCraftingTable extends TilePowerAcceptor @ConfigRegistry(config = "machines", category = "autocrafter", key = "AutoCrafterMaxEnergy", comment = "AutoCrafting Table Max Energy (Value in EU)") public static int maxEnergy = 10_000; - public Inventory inventory = new Inventory(11, "TileAutoCraftingTable", 64, this); + public Inventory inventory = new Inventory<>(11, "TileAutoCraftingTable", 64, this, getInventoryAccess()); public int progress; public int maxProgress = 120; public int euTick = 10; @@ -396,38 +398,23 @@ public class TileAutoCraftingTable extends TilePowerAcceptor return false; } - @Override - public boolean isItemValidForSlot(int index, ItemStack stack) { - int bestSlot = findBestSlotForStack(getIRecipe(), stack); - if (bestSlot != -1) { - return index == bestSlot; - } - return super.isItemValidForSlot(index, stack); - } - - @Override - public int[] getSlotsForFace(EnumFacing side) { - return new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - } - - @Override - public boolean canInsertItem(int index, ItemStack stack, EnumFacing direction) { - if (index > 8) { - return false; - } - int bestSlot = findBestSlotForStack(getIRecipe(), stack); - if (bestSlot != -1) { - return index == bestSlot; - } - return true; - } - - @Override - public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) { - if (index > 8) { + private static IInventoryAccess getInventoryAccess(){ + return (slotID, stack, facing, direction, tile) -> { + switch (direction){ + case INSERT: + if (slotID > 8) { + return false; + } + int bestSlot = tile.findBestSlotForStack(tile.getIRecipe(), stack); + if (bestSlot != -1) { + return slotID == bestSlot; + } + return true; + case EXTRACT: + return slotID > 8; + } return true; - } - return false; + }; } // This machine doesnt have a facing diff --git a/src/main/java/techreborn/tiles/tier1/TileChemicalReactor.java b/src/main/java/techreborn/tiles/tier1/TileChemicalReactor.java index e12897c3e..39ad7ecab 100644 --- a/src/main/java/techreborn/tiles/tier1/TileChemicalReactor.java +++ b/src/main/java/techreborn/tiles/tier1/TileChemicalReactor.java @@ -49,7 +49,7 @@ public class TileChemicalReactor extends TileGenericMachine implements IContaine super("ChemicalReactor", maxInput, maxEnergy, ModBlocks.CHEMICAL_REACTOR, 3); final int[] inputs = new int[] { 0, 1 }; final int[] outputs = new int[] { 2 }; - this.inventory = new Inventory(4, "TileChemicalReactor", 64, this); + this.inventory = new Inventory<>(4, "TileChemicalReactor", 64, this); this.crafter = new RecipeCrafter(Reference.CHEMICAL_REACTOR_RECIPE, this, 2, 2, this.inventory, inputs, outputs); } diff --git a/src/main/java/techreborn/tiles/tier1/TileCompressor.java b/src/main/java/techreborn/tiles/tier1/TileCompressor.java index eb008f1f4..12311e353 100644 --- a/src/main/java/techreborn/tiles/tier1/TileCompressor.java +++ b/src/main/java/techreborn/tiles/tier1/TileCompressor.java @@ -49,7 +49,7 @@ public class TileCompressor extends TileGenericMachine implements IContainerProv super("Compressor", maxInput, maxEnergy, ModBlocks.COMPRESSOR, 2); final int[] inputs = new int[] { 0 }; final int[] outputs = new int[] { 1 }; - this.inventory = new Inventory(3, "TileCompressor", 64, this); + this.inventory = new Inventory<>(3, "TileCompressor", 64, this); this.crafter = new RecipeCrafter(Reference.COMPRESSOR_RECIPE, this, 2, 1, this.inventory, inputs, outputs); } diff --git a/src/main/java/techreborn/tiles/tier1/TileElectricFurnace.java b/src/main/java/techreborn/tiles/tier1/TileElectricFurnace.java index a34bc3747..2d0c71009 100644 --- a/src/main/java/techreborn/tiles/tier1/TileElectricFurnace.java +++ b/src/main/java/techreborn/tiles/tier1/TileElectricFurnace.java @@ -51,7 +51,7 @@ public class TileElectricFurnace extends TilePowerAcceptor @ConfigRegistry(config = "machines", category = "electric_furnace", key = "ElectricFurnaceMaxEnergy", comment = "Electric Furnace Max Energy (Value in EU)") public static int maxEnergy = 1000; - public Inventory inventory = new Inventory(3, "TileElectricFurnace", 64, this); + public Inventory inventory = new Inventory<>(3, "TileElectricFurnace", 64, this); public int progress; public int fuelScale = 100; public int cost = 6; diff --git a/src/main/java/techreborn/tiles/tier1/TileExtractor.java b/src/main/java/techreborn/tiles/tier1/TileExtractor.java index 1fb64a1cf..50fcc00ca 100644 --- a/src/main/java/techreborn/tiles/tier1/TileExtractor.java +++ b/src/main/java/techreborn/tiles/tier1/TileExtractor.java @@ -49,7 +49,7 @@ public class TileExtractor extends TileGenericMachine implements IContainerProvi super("Extractor", maxInput, maxEnergy, ModBlocks.EXTRACTOR, 2); final int[] inputs = new int[] { 0 }; final int[] outputs = new int[] { 1 }; - this.inventory = new Inventory(3, "TileExtractor", 64, this); + this.inventory = new Inventory<>(3, "TileExtractor", 64, this); this.crafter = new RecipeCrafter(Reference.EXTRACTOR_RECIPE, this, 2, 1, this.inventory, inputs, outputs); } diff --git a/src/main/java/techreborn/tiles/tier1/TileGrinder.java b/src/main/java/techreborn/tiles/tier1/TileGrinder.java index 059d76c2b..0cf966f73 100644 --- a/src/main/java/techreborn/tiles/tier1/TileGrinder.java +++ b/src/main/java/techreborn/tiles/tier1/TileGrinder.java @@ -49,7 +49,7 @@ public class TileGrinder extends TileGenericMachine implements IContainerProvide super("Grinder", maxInput, maxEnergy, ModBlocks.GRINDER, 2); final int[] inputs = new int[] { 0 }; final int[] outputs = new int[] { 1 }; - this.inventory = new Inventory(3, "TileGrinder", 64, this); + this.inventory = new Inventory<>(3, "TileGrinder", 64, this); this.crafter = new RecipeCrafter(Reference.GRINDER_RECIPE, this, 2, 1, this.inventory, inputs, outputs); } diff --git a/src/main/java/techreborn/tiles/tier1/TileIndustrialElectrolyzer.java b/src/main/java/techreborn/tiles/tier1/TileIndustrialElectrolyzer.java index 9fe2e7adc..4f906ebbf 100644 --- a/src/main/java/techreborn/tiles/tier1/TileIndustrialElectrolyzer.java +++ b/src/main/java/techreborn/tiles/tier1/TileIndustrialElectrolyzer.java @@ -51,7 +51,7 @@ public class TileIndustrialElectrolyzer extends TileGenericMachine implements IC super("IndustrialElectrolyzer", maxInput, maxEnergy, ModBlocks.INDUSTRIAL_ELECTROLYZER, 6); final int[] inputs = new int[] { 0, 1 }; final int[] outputs = new int[] { 2, 3, 4, 5 }; - this.inventory = new Inventory(7, "TileIndustrialElectrolyzer", 64, this); + this.inventory = new Inventory<>(7, "TileIndustrialElectrolyzer", 64, this); this.crafter = new RecipeCrafter(Reference.INDUSTRIAL_ELECTROLYZER_RECIPE, this, 2, 4, this.inventory, inputs, outputs); } diff --git a/src/main/java/techreborn/tiles/tier1/TileRecycler.java b/src/main/java/techreborn/tiles/tier1/TileRecycler.java index acfd333d2..ba9da1d20 100644 --- a/src/main/java/techreborn/tiles/tier1/TileRecycler.java +++ b/src/main/java/techreborn/tiles/tier1/TileRecycler.java @@ -51,7 +51,7 @@ public class TileRecycler extends TilePowerAcceptor @ConfigRegistry(config = "machines", category = "recycler", key = "RecyclerMaxEnergy", comment = "Recycler Max Energy (Value in EU)") public static int maxEnergy = 1000; - private final Inventory inventory = new Inventory(3, "TileRecycler", 64, this); + private final Inventory inventory = new Inventory<>(3, "TileRecycler", 64, this); private final int cost = 2; private final int time = 15; private final int chance = 6; diff --git a/src/main/java/techreborn/tiles/tier1/TileRollingMachine.java b/src/main/java/techreborn/tiles/tier1/TileRollingMachine.java index f656f2bb5..175f489b2 100644 --- a/src/main/java/techreborn/tiles/tier1/TileRollingMachine.java +++ b/src/main/java/techreborn/tiles/tier1/TileRollingMachine.java @@ -69,7 +69,7 @@ public class TileRollingMachine extends TilePowerAcceptor public int[] craftingSlots = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; private InventoryCrafting craftCache; - public Inventory inventory = new Inventory(12, "TileRollingMachine", 64, this); + public Inventory inventory = new Inventory<>(12, "TileRollingMachine", 64, this); public boolean isRunning; public int tickTime; @Nonnull diff --git a/src/main/java/techreborn/tiles/tier1/TileScrapboxinator.java b/src/main/java/techreborn/tiles/tier1/TileScrapboxinator.java index cbd32aa8d..62681dde8 100644 --- a/src/main/java/techreborn/tiles/tier1/TileScrapboxinator.java +++ b/src/main/java/techreborn/tiles/tier1/TileScrapboxinator.java @@ -49,7 +49,7 @@ public class TileScrapboxinator extends TileGenericMachine implements IContainer super("Scrapboxinator", maxInput, maxEnergy, ModBlocks.SCRAPBOXINATOR, 2); final int[] inputs = new int[] { 0 }; final int[] outputs = new int[] { 1 }; - this.inventory = new Inventory(3, "TileScrapboxinator", 64, this); + this.inventory = new Inventory<>(3, "TileScrapboxinator", 64, this); this.crafter = new ScrapboxRecipeCrafter(this, this.inventory, inputs, outputs); }