Fix slot config, some changes to the way Inventory works as well to allow for this.

This commit is contained in:
modmuss50 2018-09-13 19:33:14 +01:00
parent 305f74b107
commit 01644e4f65
35 changed files with 114 additions and 108 deletions

View file

@ -55,7 +55,7 @@ public class UpgradeSlot extends BaseSlot implements IRightClickHandler {
public boolean handleRightClick(int slotID, EntityPlayer player, BuiltContainer container) { public boolean handleRightClick(int slotID, EntityPlayer player, BuiltContainer container) {
if (inventory instanceof Inventory) { if (inventory instanceof Inventory) {
Inventory inv = (Inventory) inventory; Inventory inv = (Inventory) inventory;
TileEntity tileEntity = inv.getTileBase(); TileEntity tileEntity = inv.getTile();
if (tileEntity instanceof IUpgradeable) { if (tileEntity instanceof IUpgradeable) {
IUpgradeable upgradeable = (IUpgradeable) tileEntity; IUpgradeable upgradeable = (IUpgradeable) tileEntity;
if (upgradeable.canBeUpgraded()) { if (upgradeable.canBeUpgraded()) {

View file

@ -32,6 +32,9 @@ import net.minecraft.inventory.Slot;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.client.event.GuiScreenEvent; import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; 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 org.lwjgl.input.Keyboard;
import reborncore.client.gui.GuiUtil; import reborncore.client.gui.GuiUtil;
import reborncore.common.network.NetworkManager; import reborncore.common.network.NetworkManager;
@ -64,10 +67,16 @@ public class GuiSlotConfiguration {
public static void init(GuiBase guiBase) { public static void init(GuiBase guiBase) {
reset(); reset();
slotElementMap.clear(); slotElementMap.clear();
IItemHandler itemHandler = getMachine().getInventoryForTile().orElseGet(null);
if(itemHandler == null){
return;
}
BuiltContainer container = guiBase.container; BuiltContainer container = guiBase.container;
for (Slot slot : container.inventorySlots) { for (Slot slot : container.inventorySlots) {
if (guiBase.tile != slot.inventory) { if(!(slot instanceof SlotItemHandler)){
continue;
} else if (((SlotItemHandler) slot).getItemHandler() != itemHandler){
continue; continue;
} }
ConfigSlotElement slotElement = new ConfigSlotElement(guiBase.getMachine().getInventoryForTile().get(), slot.getSlotIndex(), SlotType.NORMAL, slot.xPos - guiBase.guiLeft + 50, slot.yPos - guiBase.guiTop - 25, guiBase); 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) { public static void draw(GuiBase guiBase, int mouseX, int mouseY) {
IItemHandler itemHandler = getMachine().getInventoryForTile().orElseGet(null);
if(itemHandler == null){
return;
}
BuiltContainer container = guiBase.container; BuiltContainer container = guiBase.container;
for (Slot slot : container.inventorySlots) { for (Slot slot : container.inventorySlots) {
if (guiBase.tile != slot.inventory) { if(!(slot instanceof SlotItemHandler)){
continue;
} else if (((SlotItemHandler) slot).getItemHandler() != itemHandler){
continue; continue;
} }
GlStateManager.color(255, 0, 0); GlStateManager.color(255, 0, 0);
@ -172,8 +187,11 @@ public class GuiSlotConfiguration {
BuiltContainer container = guiBase.container; BuiltContainer container = guiBase.container;
if(getVisibleElements().isEmpty()) { if(getVisibleElements().isEmpty()) {
IItemHandler itemHandler = getMachine().getInventoryForTile().orElseGet(null);
for (Slot slot : container.inventorySlots) { for (Slot slot : container.inventorySlots) {
if (guiBase.tile != slot.inventory) { if(!(slot instanceof SlotItemHandler)){
continue;
} else if (((SlotItemHandler) slot).getItemHandler() != itemHandler){
continue; continue;
} }
if (guiBase.isPointInRect(slot.xPos, slot.yPos, 18, 18, mouseX, mouseY)) { if (guiBase.isPointInRect(slot.xPos, slot.yPos, 18, 18, mouseX, mouseY)) {

View file

@ -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)") @ConfigRegistry(config = "machines", category = "charge_bench", key = "ChargeBenchMaxEnergy", comment = "Charge Bench Max Energy (Value in EU)")
public static int maxEnergy = 100_000_000; public static int maxEnergy = 100_000_000;
public Inventory inventory = new Inventory(6, "TileChargeOMat", 64, this); public Inventory<TileChargeOMat> inventory = new Inventory<>(6, "TileChargeOMat", 64, this);
public TileChargeOMat() { public TileChargeOMat() {
super(); super();

View file

@ -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") // @ConfigRegistry(config = "machines", category = "chunk_loader", key = "ChunkLoaderWrenchDropRate", comment = "Chunk Loader Wrench Drop Rate")
public static float wrenchDropRate = 1.0F; public static float wrenchDropRate = 1.0F;
public Inventory inventory = new Inventory(1, "TileChunkLoader", 64, this); public Inventory<TileChunkLoader> inventory = new Inventory<>(1, "TileChunkLoader", 64, this);
public boolean isRunning; public boolean isRunning;
public int tickTime; public int tickTime;

View file

@ -53,7 +53,7 @@ public class TileIndustrialCentrifuge extends TileGenericMachine implements ICon
super("IndustrialCentrifuge", maxInput, maxEnergy, ModBlocks.INDUSTRIAL_CENTRIFUGE, 6); super("IndustrialCentrifuge", maxInput, maxEnergy, ModBlocks.INDUSTRIAL_CENTRIFUGE, 6);
final int[] inputs = new int[] { 0, 1 }; final int[] inputs = new int[] { 0, 1 };
final int[] outputs = new int[] { 2, 3, 4, 5 }; 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); this.crafter = new RecipeCrafter(Reference.CENTRIFUGE_RECIPE, this, 2, 4, this.inventory, inputs, outputs);
} }

View file

@ -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") @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 static int energyPerAmp = 5;
public Inventory inventory = new Inventory(12, "TileMatterFabricator", 64, this); public Inventory<TileMatterFabricator> inventory = new Inventory<>(12, "TileMatterFabricator", 64, this);
private int amplifier = 0; private int amplifier = 0;
public TileMatterFabricator() { public TileMatterFabricator() {

View file

@ -55,7 +55,7 @@ public class TileQuantumTank extends TileLegacyMachineBase
public static int maxStorage = Integer.MAX_VALUE; public static int maxStorage = Integer.MAX_VALUE;
public Tank tank = new Tank("TileQuantumTank", maxStorage, this); public Tank tank = new Tank("TileQuantumTank", maxStorage, this);
public Inventory inventory = new Inventory(3, "TileQuantumTank", 64, this); public Inventory<TileQuantumTank> inventory = new Inventory<>(3, "TileQuantumTank", 64, this);
public void readFromNBTWithoutCoords(final NBTTagCompound tagCompound) { public void readFromNBTWithoutCoords(final NBTTagCompound tagCompound) {
tank.readFromNBT(tagCompound); tank.readFromNBT(tagCompound);

View file

@ -53,7 +53,7 @@ public class TileTechStorageBase extends TileLegacyMachineBase
public TileTechStorageBase(String name, int maxCapacity) { public TileTechStorageBase(String name, int maxCapacity) {
this.maxCapacity = maxCapacity; this.maxCapacity = maxCapacity;
storedItem = ItemStack.EMPTY; storedItem = ItemStack.EMPTY;
inventory = new Inventory(3, name, maxCapacity, this); inventory = new Inventory<>(3, name, maxCapacity, this);
} }
public void readFromNBTWithoutCoords(NBTTagCompound tagCompound) { public void readFromNBTWithoutCoords(NBTTagCompound tagCompound) {

View file

@ -78,7 +78,7 @@ public class TileFusionControlComputer extends TilePowerAcceptor
public TileFusionControlComputer() { public TileFusionControlComputer() {
super(); super();
checkOverfill = false; checkOverfill = false;
this.inventory = new Inventory(3, "TileFusionControlComputer", 64, this); this.inventory = new Inventory<>(3, "TileFusionControlComputer", 64, this);
} }
/** /**

View file

@ -62,7 +62,7 @@ public abstract class TileBaseFluidGenerator extends TilePowerAcceptor implement
super(); super();
recipes = GeneratorRecipeHelper.getFluidRecipesForGenerator(type); recipes = GeneratorRecipeHelper.getFluidRecipesForGenerator(type);
tank = new Tank(tileName, tankCapacity, this); tank = new Tank(tileName, tankCapacity, this);
inventory = new Inventory(3, tileName, 64, this); inventory = new Inventory<>(3, tileName, 64, this);
this.euTick = euTick; this.euTick = euTick;
this.ticksSinceLastChange = 0; this.ticksSinceLastChange = 0;
} }

View file

@ -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)") @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 static int energyPerTick = 4;
public Inventory inventory = new Inventory(3, "TileDragonEggSyphon", 64, this); public Inventory<TileDragonEggSyphon> inventory = new Inventory<>(3, "TileDragonEggSyphon", 64, this);
private long lastOutput = 0; private long lastOutput = 0;
public TileDragonEggSyphon() { public TileDragonEggSyphon() {

View file

@ -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)") @ConfigRegistry(config = "generators", category = "generator", key = "GeneratorEnergyOutput", comment = "Solid Fuel Generator Energy Output Amount (Value in EU)")
public static int outputAmount = 10; public static int outputAmount = 10;
public Inventory inventory = new Inventory(2, "TileSolidFuelGenerator", 64, this); public Inventory<TileSolidFuelGenerator> inventory = new Inventory<>(2, "TileSolidFuelGenerator", 64, this);
public int fuelSlot = 0; public int fuelSlot = 0;
public int burnTime; public int burnTime;
public int totalBurnTime = 0; public int totalBurnTime = 0;

View file

@ -53,7 +53,7 @@ public class TileDistillationTower extends TileGenericMachine implements IContai
super("DistillationTower", maxInput, maxEnergy, ModBlocks.DISTILLATION_TOWER, 6); super("DistillationTower", maxInput, maxEnergy, ModBlocks.DISTILLATION_TOWER, 6);
final int[] inputs = new int[] { 0, 1 }; final int[] inputs = new int[] { 0, 1 };
final int[] outputs = new int[] { 2, 3, 4, 5 }; 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); this.crafter = new RecipeCrafter(Reference.DISTILLATION_TOWER_RECIPE, this, 2, 4, this.inventory, inputs, outputs);
} }

View file

@ -28,10 +28,12 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import reborncore.common.recipes.RecipeCrafter; import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.registration.RebornRegistry; import reborncore.common.registration.RebornRegistry;
import reborncore.common.registration.impl.ConfigRegistry; import reborncore.common.registration.impl.ConfigRegistry;
import reborncore.common.util.FluidUtils; import reborncore.common.util.FluidUtils;
import reborncore.common.util.IInventoryAccess;
import reborncore.common.util.Inventory; import reborncore.common.util.Inventory;
import reborncore.common.util.Tank; import reborncore.common.util.Tank;
import techreborn.api.fluidreplicator.FluidReplicatorRecipeCrafter; import techreborn.api.fluidreplicator.FluidReplicatorRecipeCrafter;
@ -66,7 +68,7 @@ public class TileFluidReplicator extends TileGenericMachine implements IContaine
public TileFluidReplicator() { public TileFluidReplicator() {
super("FluidReplicator", maxInput, maxEnergy, ModBlocks.FLUID_REPLICATOR, 3); super("FluidReplicator", maxInput, maxEnergy, ModBlocks.FLUID_REPLICATOR, 3);
final int[] inputs = new int[] { 0 }; 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.crafter = new FluidReplicatorRecipeCrafter(this, this.inventory, inputs, null);
this.tank = new Tank("TileFluidReplicator", TileFluidReplicator.TANK_CAPACITY, this); this.tank = new Tank("TileFluidReplicator", TileFluidReplicator.TANK_CAPACITY, this);
} }
@ -123,17 +125,13 @@ public class TileFluidReplicator extends TileGenericMachine implements IContaine
return tagCompound; return tagCompound;
} }
// TileLegacyMachineBase private static IInventoryAccess<TileFluidReplicator> getInventoryAccess(){
@Override return (slotID, stack, face, direction, tile) -> {
public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack) { if(slotID == 0){
if (slotIndex == 0) { return stack.isItemEqual(TRIngredients.Parts.UU_MATTER.getStack());
if (itemStack.isItemEqual(TRIngredients.Parts.UU_MATTER.getStack())) { }
return true; return true;
} else { };
return false;
}
}
return super.isItemValidForSlot(slotIndex, itemStack);
} }
// IContainerProvider // IContainerProvider

View file

@ -52,7 +52,7 @@ public class TileImplosionCompressor extends TileGenericMachine implements ICont
super("ImplosionCompressor", maxInput, maxEnergy, ModBlocks.IMPLOSION_COMPRESSOR, 4); super("ImplosionCompressor", maxInput, maxEnergy, ModBlocks.IMPLOSION_COMPRESSOR, 4);
final int[] inputs = new int[] { 0, 1 }; final int[] inputs = new int[] { 0, 1 };
final int[] outputs = new int[] { 2, 3 }; 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); this.crafter = new RecipeCrafter(Reference.IMPLOSION_COMPRESSOR_RECIPE, this, 2, 2, this.inventory, inputs, outputs);
} }

View file

@ -64,7 +64,7 @@ public class TileIndustrialBlastFurnace extends TileGenericMachine implements IC
super("IndustrialBlastFurnace", maxInput, maxEnergy, ModBlocks.INDUSTRIAL_BLAST_FURNACE, 4); super("IndustrialBlastFurnace", maxInput, maxEnergy, ModBlocks.INDUSTRIAL_BLAST_FURNACE, 4);
final int[] inputs = new int[] { 0, 1 }; final int[] inputs = new int[] { 0, 1 };
final int[] outputs = new int[] { 2, 3 }; 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); this.crafter = new RecipeCrafter(Reference.BLAST_FURNACE_RECIPE, this, 2, 2, this.inventory, inputs, outputs);
} }

View file

@ -39,6 +39,7 @@ import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.registration.RebornRegistry; import reborncore.common.registration.RebornRegistry;
import reborncore.common.registration.impl.ConfigRegistry; import reborncore.common.registration.impl.ConfigRegistry;
import reborncore.common.util.FluidUtils; import reborncore.common.util.FluidUtils;
import reborncore.common.util.IInventoryAccess;
import reborncore.common.util.Inventory; import reborncore.common.util.Inventory;
import reborncore.common.util.Tank; import reborncore.common.util.Tank;
import techreborn.api.Reference; import techreborn.api.Reference;
@ -48,6 +49,7 @@ import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer; import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder; import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks; import techreborn.init.ModBlocks;
import techreborn.init.TRIngredients;
import techreborn.lib.ModInfo; import techreborn.lib.ModInfo;
import techreborn.tiles.TileGenericMachine; import techreborn.tiles.TileGenericMachine;
@ -70,7 +72,7 @@ public class TileIndustrialGrinder extends TileGenericMachine implements IContai
super("IndustrialGrinder", maxInput, maxEnergy, ModBlocks.INDUSTRIAL_GRINDER, 7); super("IndustrialGrinder", maxInput, maxEnergy, ModBlocks.INDUSTRIAL_GRINDER, 7);
final int[] inputs = new int[] { 0, 1 }; final int[] inputs = new int[] { 0, 1 };
final int[] outputs = new int[] {2, 3, 4, 5}; 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.crafter = new RecipeCrafter(Reference.INDUSTRIAL_GRINDER_RECIPE, this, 1, 4, this.inventory, inputs, outputs);
this.tank = new Tank("TileIndustrialGrinder", TileIndustrialGrinder.TANK_CAPACITY, this); this.tank = new Tank("TileIndustrialGrinder", TileIndustrialGrinder.TANK_CAPACITY, this);
this.ticksSinceLastChange = 0; this.ticksSinceLastChange = 0;
@ -128,18 +130,13 @@ public class TileIndustrialGrinder extends TileGenericMachine implements IContai
return tagCompound; return tagCompound;
} }
// TileLegacyMachineBase private static IInventoryAccess<TileIndustrialGrinder> getInventoryAccess(){
@Override return (slotID, stack, face, direction, tile) -> {
public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack) { if(slotID == 1){
if (slotIndex == 1) { return stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
if (itemStack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)){ }
return true; return true;
} };
else {
return false;
}
}
return super.isItemValidForSlot(slotIndex, itemStack);
} }
// IContainerProvider // IContainerProvider

View file

@ -31,6 +31,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidBlock; import net.minecraftforge.fluids.IFluidBlock;
@ -39,6 +40,7 @@ import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.registration.RebornRegistry; import reborncore.common.registration.RebornRegistry;
import reborncore.common.registration.impl.ConfigRegistry; import reborncore.common.registration.impl.ConfigRegistry;
import reborncore.common.util.FluidUtils; import reborncore.common.util.FluidUtils;
import reborncore.common.util.IInventoryAccess;
import reborncore.common.util.Inventory; import reborncore.common.util.Inventory;
import reborncore.common.util.Tank; import reborncore.common.util.Tank;
import techreborn.api.Reference; import techreborn.api.Reference;
@ -50,6 +52,7 @@ import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks; import techreborn.init.ModBlocks;
import techreborn.lib.ModInfo; import techreborn.lib.ModInfo;
import techreborn.tiles.TileGenericMachine; import techreborn.tiles.TileGenericMachine;
import techreborn.tiles.tier1.TileAutoCraftingTable;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -70,7 +73,7 @@ public class TileIndustrialSawmill extends TileGenericMachine implements IContai
super("IndustrialSawmill", maxInput, maxEnergy, ModBlocks.INDUSTRIAL_SAWMILL, 6); super("IndustrialSawmill", maxInput, maxEnergy, ModBlocks.INDUSTRIAL_SAWMILL, 6);
final int[] inputs = new int[] { 0, 1 }; final int[] inputs = new int[] { 0, 1 };
final int[] outputs = new int[] { 2, 3, 4 }; 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.crafter = new RecipeCrafter(Reference.INDUSTRIAL_SAWMILL_RECIPE, this, 1, 3, this.inventory, inputs, outputs);
this.tank = new Tank("TileSawmill", TileIndustrialSawmill.TANK_CAPACITY, this); this.tank = new Tank("TileSawmill", TileIndustrialSawmill.TANK_CAPACITY, this);
this.ticksSinceLastChange = 0; this.ticksSinceLastChange = 0;
@ -128,19 +131,16 @@ public class TileIndustrialSawmill extends TileGenericMachine implements IContai
return tagCompound; return tagCompound;
} }
// TileLegacyMachineBase private static IInventoryAccess<TileIndustrialSawmill> getInventoryAccess(){
@Override return (slotID, stack, face, direction, tile) -> {
public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack) { if(direction == IInventoryAccess.AccessDirection.INSERT){
if (slotIndex == 1) { return stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
if (itemStack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) { }
return true; return true;
} else { };
return false;
}
}
return super.isItemValidForSlot(slotIndex, itemStack);
} }
// IContainerProvider // IContainerProvider
@Override @Override
public BuiltContainer createContainer(final EntityPlayer player) { public BuiltContainer createContainer(final EntityPlayer player) {

View file

@ -51,7 +51,7 @@ public class TileVacuumFreezer extends TileGenericMachine implements IContainerP
super("VacuumFreezer", maxInput, maxEnergy, ModBlocks.VACUUM_FREEZER, 2); super("VacuumFreezer", maxInput, maxEnergy, ModBlocks.VACUUM_FREEZER, 2);
final int[] inputs = new int[] { 0 }; final int[] inputs = new int[] { 0 };
final int[] outputs = new int[] { 1 }; 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); this.crafter = new RecipeCrafter(Reference.VACUUM_FREEZER_RECIPE, this, 2, 1, this.inventory, inputs, outputs);
} }

View file

@ -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)") @ConfigRegistry(config = "machines", category = "aesu", key = "AesuMaxEnergy", comment = "AESU Max Energy (Value in EU)")
public static int maxEnergy = 100_000_000; public static int maxEnergy = 100_000_000;
public Inventory inventory = new Inventory(4, "TileAdjustableSU", 64, this); public Inventory<TileAdjustableSU> inventory = new Inventory<>(4, "TileAdjustableSU", 64, this);
private int OUTPUT = 64; // The current output private int OUTPUT = 64; // The current output
public TileAdjustableSU() { public TileAdjustableSU() {

View file

@ -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) { public TileEnergyStorage(String name, int invSize, Block wrenchDrop, EnumPowerTier tier, int maxInput, int maxOuput, int maxStorage) {
super(); super();
inventory = new Inventory(invSize, "Tile" + name, 64, this); inventory = new Inventory<>(invSize, "Tile" + name, 64, this);
this.wrenchDrop = wrenchDrop; this.wrenchDrop = wrenchDrop;
this.tier = tier; this.tier = tier;
this.name = name; this.name = name;

View file

@ -53,7 +53,7 @@ public class TileIronAlloyFurnace extends TileLegacyMachineBase
implements IToolDrop, ItemHandlerProvider, IContainerProvider { implements IToolDrop, ItemHandlerProvider, IContainerProvider {
public int tickTime; public int tickTime;
public Inventory inventory = new Inventory(4, "TileIronAlloyFurnace", 64, this); public Inventory<TileIronAlloyFurnace> inventory = new Inventory<>(4, "TileIronAlloyFurnace", 64, this);
public int burnTime; public int burnTime;
public int currentItemBurnTime; public int currentItemBurnTime;
public int cookTime; public int cookTime;

View file

@ -29,9 +29,11 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.EnumFacing;
import reborncore.api.tile.ItemHandlerProvider; import reborncore.api.tile.ItemHandlerProvider;
import reborncore.common.blocks.BlockMachineBase; import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.tile.TileLegacyMachineBase; import reborncore.common.tile.TileLegacyMachineBase;
import reborncore.common.util.IInventoryAccess;
import reborncore.common.util.Inventory; import reborncore.common.util.Inventory;
import reborncore.common.util.ItemUtils; import reborncore.common.util.ItemUtils;
import techreborn.client.container.IContainerProvider; import techreborn.client.container.IContainerProvider;
@ -42,7 +44,7 @@ public class TileIronFurnace extends TileLegacyMachineBase
implements ItemHandlerProvider, IContainerProvider { implements ItemHandlerProvider, IContainerProvider {
public int tickTime; public int tickTime;
public Inventory inventory = new Inventory(3, "TileIronFurnace", 64, this); public Inventory<TileIronFurnace> inventory = new Inventory<>(3, "TileIronFurnace", 64, this, getInvetoryAccess());
public int fuel; public int fuel;
public int fuelGague; public int fuelGague;
public int progress; public int progress;
@ -168,16 +170,20 @@ public class TileIronFurnace extends TileLegacyMachineBase
return this.inventory; return this.inventory;
} }
@Override public static IInventoryAccess<TileIronFurnace> getInvetoryAccess(){
public boolean isItemValidForSlot(int index, ItemStack stack) { return (slotID, stack, face, direction, tile) -> {
if(direction == IInventoryAccess.AccessDirection.INSERT){
boolean isFuel = TileEntityFurnace.isItemFuel(stack); boolean isFuel = TileEntityFurnace.isItemFuel(stack);
if(isFuel){ if(isFuel){
ItemStack fuelSlotStack = inventory.getStackInSlot(fuelslot); ItemStack fuelSlotStack = tile.inventory.getStackInSlot(tile.fuelslot);
if(fuelSlotStack.isEmpty() || ItemUtils.isItemEqual(stack, fuelSlotStack, true, true) && fuelSlotStack.getMaxStackSize() != fuelSlotStack.getCount()){ if(fuelSlotStack.isEmpty() || ItemUtils.isItemEqual(stack, fuelSlotStack, true, true) && fuelSlotStack.getMaxStackSize() != fuelSlotStack.getCount()){
return index == fuelslot; return slotID == tile.fuelslot;
} }
} }
return index != output; return slotID != tile.output;
}
return true;
};
} }
public int getBurnTime() { public int getBurnTime() {

View file

@ -52,7 +52,7 @@ public class TileAlloySmelter extends TileGenericMachine implements IContainerPr
super("AlloySmelter", maxInput, maxEnergy, ModBlocks.ALLOY_SMELTER, 3); super("AlloySmelter", maxInput, maxEnergy, ModBlocks.ALLOY_SMELTER, 3);
final int[] inputs = new int[] { 0, 1 }; final int[] inputs = new int[] { 0, 1 };
final int[] outputs = new int[] { 2 }; 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); this.crafter = new RecipeCrafter(Reference.ALLOY_SMELTER_RECIPE, this, 2, 1, this.inventory, inputs, outputs);
} }

View file

@ -49,7 +49,7 @@ public class TileAssemblingMachine extends TileGenericMachine implements IContai
super("AssemblingMachine", maxInput, maxEnergy, ModBlocks.ASSEMBLY_MACHINE, 3); super("AssemblingMachine", maxInput, maxEnergy, ModBlocks.ASSEMBLY_MACHINE, 3);
final int[] inputs = new int[] { 0, 1 }; final int[] inputs = new int[] { 0, 1 };
final int[] outputs = new int[] { 2 }; 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); this.crafter = new RecipeCrafter(Reference.ASSEMBLING_MACHINE_RECIPE, this, 2, 2, this.inventory, inputs, outputs);
} }

View file

@ -41,6 +41,8 @@ import reborncore.api.tile.ItemHandlerProvider;
import reborncore.common.powerSystem.TilePowerAcceptor; import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.registration.RebornRegistry; import reborncore.common.registration.RebornRegistry;
import reborncore.common.registration.impl.ConfigRegistry; 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.Inventory;
import reborncore.common.util.ItemUtils; import reborncore.common.util.ItemUtils;
import techreborn.client.container.IContainerProvider; 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)") @ConfigRegistry(config = "machines", category = "autocrafter", key = "AutoCrafterMaxEnergy", comment = "AutoCrafting Table Max Energy (Value in EU)")
public static int maxEnergy = 10_000; public static int maxEnergy = 10_000;
public Inventory inventory = new Inventory(11, "TileAutoCraftingTable", 64, this); public Inventory<TileAutoCraftingTable> inventory = new Inventory<>(11, "TileAutoCraftingTable", 64, this, getInventoryAccess());
public int progress; public int progress;
public int maxProgress = 120; public int maxProgress = 120;
public int euTick = 10; public int euTick = 10;
@ -396,38 +398,23 @@ public class TileAutoCraftingTable extends TilePowerAcceptor
return false; return false;
} }
@Override private static IInventoryAccess<TileAutoCraftingTable> getInventoryAccess(){
public boolean isItemValidForSlot(int index, ItemStack stack) { return (slotID, stack, facing, direction, tile) -> {
int bestSlot = findBestSlotForStack(getIRecipe(), stack); switch (direction){
if (bestSlot != -1) { case INSERT:
return index == bestSlot; if (slotID > 8) {
}
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; return false;
} }
int bestSlot = findBestSlotForStack(getIRecipe(), stack); int bestSlot = tile.findBestSlotForStack(tile.getIRecipe(), stack);
if (bestSlot != -1) { if (bestSlot != -1) {
return index == bestSlot; return slotID == bestSlot;
} }
return true; return true;
case EXTRACT:
return slotID > 8;
} }
@Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) {
if (index > 8) {
return true; return true;
} };
return false;
} }
// This machine doesnt have a facing // This machine doesnt have a facing

View file

@ -49,7 +49,7 @@ public class TileChemicalReactor extends TileGenericMachine implements IContaine
super("ChemicalReactor", maxInput, maxEnergy, ModBlocks.CHEMICAL_REACTOR, 3); super("ChemicalReactor", maxInput, maxEnergy, ModBlocks.CHEMICAL_REACTOR, 3);
final int[] inputs = new int[] { 0, 1 }; final int[] inputs = new int[] { 0, 1 };
final int[] outputs = new int[] { 2 }; 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); this.crafter = new RecipeCrafter(Reference.CHEMICAL_REACTOR_RECIPE, this, 2, 2, this.inventory, inputs, outputs);
} }

View file

@ -49,7 +49,7 @@ public class TileCompressor extends TileGenericMachine implements IContainerProv
super("Compressor", maxInput, maxEnergy, ModBlocks.COMPRESSOR, 2); super("Compressor", maxInput, maxEnergy, ModBlocks.COMPRESSOR, 2);
final int[] inputs = new int[] { 0 }; final int[] inputs = new int[] { 0 };
final int[] outputs = new int[] { 1 }; 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); this.crafter = new RecipeCrafter(Reference.COMPRESSOR_RECIPE, this, 2, 1, this.inventory, inputs, outputs);
} }

View file

@ -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)") @ConfigRegistry(config = "machines", category = "electric_furnace", key = "ElectricFurnaceMaxEnergy", comment = "Electric Furnace Max Energy (Value in EU)")
public static int maxEnergy = 1000; public static int maxEnergy = 1000;
public Inventory inventory = new Inventory(3, "TileElectricFurnace", 64, this); public Inventory<TileElectricFurnace> inventory = new Inventory<>(3, "TileElectricFurnace", 64, this);
public int progress; public int progress;
public int fuelScale = 100; public int fuelScale = 100;
public int cost = 6; public int cost = 6;

View file

@ -49,7 +49,7 @@ public class TileExtractor extends TileGenericMachine implements IContainerProvi
super("Extractor", maxInput, maxEnergy, ModBlocks.EXTRACTOR, 2); super("Extractor", maxInput, maxEnergy, ModBlocks.EXTRACTOR, 2);
final int[] inputs = new int[] { 0 }; final int[] inputs = new int[] { 0 };
final int[] outputs = new int[] { 1 }; 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); this.crafter = new RecipeCrafter(Reference.EXTRACTOR_RECIPE, this, 2, 1, this.inventory, inputs, outputs);
} }

View file

@ -49,7 +49,7 @@ public class TileGrinder extends TileGenericMachine implements IContainerProvide
super("Grinder", maxInput, maxEnergy, ModBlocks.GRINDER, 2); super("Grinder", maxInput, maxEnergy, ModBlocks.GRINDER, 2);
final int[] inputs = new int[] { 0 }; final int[] inputs = new int[] { 0 };
final int[] outputs = new int[] { 1 }; 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); this.crafter = new RecipeCrafter(Reference.GRINDER_RECIPE, this, 2, 1, this.inventory, inputs, outputs);
} }

View file

@ -51,7 +51,7 @@ public class TileIndustrialElectrolyzer extends TileGenericMachine implements IC
super("IndustrialElectrolyzer", maxInput, maxEnergy, ModBlocks.INDUSTRIAL_ELECTROLYZER, 6); super("IndustrialElectrolyzer", maxInput, maxEnergy, ModBlocks.INDUSTRIAL_ELECTROLYZER, 6);
final int[] inputs = new int[] { 0, 1 }; final int[] inputs = new int[] { 0, 1 };
final int[] outputs = new int[] { 2, 3, 4, 5 }; 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); this.crafter = new RecipeCrafter(Reference.INDUSTRIAL_ELECTROLYZER_RECIPE, this, 2, 4, this.inventory, inputs, outputs);
} }

View file

@ -51,7 +51,7 @@ public class TileRecycler extends TilePowerAcceptor
@ConfigRegistry(config = "machines", category = "recycler", key = "RecyclerMaxEnergy", comment = "Recycler Max Energy (Value in EU)") @ConfigRegistry(config = "machines", category = "recycler", key = "RecyclerMaxEnergy", comment = "Recycler Max Energy (Value in EU)")
public static int maxEnergy = 1000; 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 cost = 2;
private final int time = 15; private final int time = 15;
private final int chance = 6; private final int chance = 6;

View file

@ -69,7 +69,7 @@ public class TileRollingMachine extends TilePowerAcceptor
public int[] craftingSlots = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; public int[] craftingSlots = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
private InventoryCrafting craftCache; private InventoryCrafting craftCache;
public Inventory inventory = new Inventory(12, "TileRollingMachine", 64, this); public Inventory<TileRollingMachine> inventory = new Inventory<>(12, "TileRollingMachine", 64, this);
public boolean isRunning; public boolean isRunning;
public int tickTime; public int tickTime;
@Nonnull @Nonnull

View file

@ -49,7 +49,7 @@ public class TileScrapboxinator extends TileGenericMachine implements IContainer
super("Scrapboxinator", maxInput, maxEnergy, ModBlocks.SCRAPBOXINATOR, 2); super("Scrapboxinator", maxInput, maxEnergy, ModBlocks.SCRAPBOXINATOR, 2);
final int[] inputs = new int[] { 0 }; final int[] inputs = new int[] { 0 };
final int[] outputs = new int[] { 1 }; 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); this.crafter = new ScrapboxRecipeCrafter(this, this.inventory, inputs, outputs);
} }