From c6ca3b28e7e17af157b6e2cb87dabf3d09a65a22 Mon Sep 17 00:00:00 2001 From: Krapht Date: Sat, 31 Aug 2013 22:17:50 +0200 Subject: [PATCH] Move implementation of IInventory from TileEngine to new abstract class TileEngineWithInventory. This will effectivly remove IInventory from redstone engines. Fixes #1180 --- common/buildcraft/energy/GuiHandler.java | 14 +-- common/buildcraft/energy/TileEngine.java | 90 +++--------------- common/buildcraft/energy/TileEngineIron.java | 32 +++---- .../buildcraft/energy/TileEngineLegacy.java | 5 - common/buildcraft/energy/TileEngineStone.java | 17 ++-- .../energy/TileEngineWithInventory.java | 91 +++++++++++++++++++ common/buildcraft/energy/TileEngineWood.java | 4 - .../energy/gui/ContainerEngine.java | 10 +- .../energy/gui/GuiCombustionEngine.java | 12 ++- .../buildcraft/energy/gui/GuiStoneEngine.java | 11 ++- 10 files changed, 157 insertions(+), 129 deletions(-) create mode 100644 common/buildcraft/energy/TileEngineWithInventory.java diff --git a/common/buildcraft/energy/GuiHandler.java b/common/buildcraft/energy/GuiHandler.java index 1e084b0f..580a9867 100644 --- a/common/buildcraft/energy/GuiHandler.java +++ b/common/buildcraft/energy/GuiHandler.java @@ -1,13 +1,13 @@ package buildcraft.energy; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; import buildcraft.core.GuiIds; import buildcraft.energy.gui.ContainerEngine; import buildcraft.energy.gui.GuiCombustionEngine; import buildcraft.energy.gui.GuiStoneEngine; import cpw.mods.fml.common.network.IGuiHandler; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; public class GuiHandler implements IGuiHandler { @@ -18,10 +18,10 @@ public class GuiHandler implements IGuiHandler { return null; TileEntity tile = world.getBlockTileEntity(x, y, z); - if (!(tile instanceof TileEngine)) + if (!(tile instanceof TileEngineWithInventory)) return null; - TileEngine engine = (TileEngine) tile; + TileEngineWithInventory engine = (TileEngineWithInventory) tile; switch (ID) { @@ -43,10 +43,10 @@ public class GuiHandler implements IGuiHandler { return null; TileEntity tile = world.getBlockTileEntity(x, y, z); - if (!(tile instanceof TileEngine)) + if (!(tile instanceof TileEngineWithInventory)) return null; - TileEngine engine = (TileEngine) tile; + TileEngineWithInventory engine = (TileEngineWithInventory) tile; switch (ID) { diff --git a/common/buildcraft/energy/TileEngine.java b/common/buildcraft/energy/TileEngine.java index 2013c9ae..bc8b5da1 100644 --- a/common/buildcraft/energy/TileEngine.java +++ b/common/buildcraft/energy/TileEngine.java @@ -7,6 +7,16 @@ */ package buildcraft.energy; +import java.util.LinkedList; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ICrafting; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagFloat; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.ForgeDirection; import buildcraft.BuildCraftEnergy; import buildcraft.api.core.Position; import buildcraft.api.gates.IOverrideDefaultTriggers; @@ -21,24 +31,11 @@ import buildcraft.api.transport.IPipeTile.PipeType; import buildcraft.core.DefaultProps; import buildcraft.core.TileBuffer; import buildcraft.core.TileBuildCraft; -import buildcraft.core.inventory.InvUtils; -import buildcraft.core.inventory.SimpleInventory; import buildcraft.core.network.TileNetworkData; import buildcraft.core.proxy.CoreProxy; import buildcraft.energy.gui.ContainerEngine; -import java.util.LinkedList; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagFloat; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.common.ForgeDirection; -public abstract class TileEngine extends TileBuildCraft implements IPowerReceptor, IPowerEmitter, IInventory, IOverrideDefaultTriggers, IPipeConnection { +public abstract class TileEngine extends TileBuildCraft implements IPowerReceptor, IPowerEmitter, IOverrideDefaultTriggers, IPipeConnection { public static final ResourceLocation WOOD_TEXTURE = new ResourceLocation(DefaultProps.TEXTURE_PATH_BLOCKS + "/base_wood.png"); public static final ResourceLocation STONE_TEXTURE = new ResourceLocation(DefaultProps.TEXTURE_PATH_BLOCKS + "/base_stone.png"); @@ -60,7 +57,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto public float progress; public float energy; public float heat = MIN_HEAT; - private final SimpleInventory inv; + // public @TileNetworkData EnergyStage energyStage = EnergyStage.BLUE; @@ -69,13 +66,11 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto public @TileNetworkData boolean isPumping = false; // Used for SMP synch - public TileEngine(int invSize) { + public TileEngine(){ powerHandler = new PowerHandler(this, Type.ENGINE); powerHandler.configurePowerPerdition(1, 100); - - inv = new SimpleInventory(invSize, "Engine", 64); } - + @Override public void initialize() { if (!CoreProxy.proxy.isRenderWorld(worldObj)) { @@ -287,7 +282,6 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto NBTBase tag = data.getTag("heat"); if (tag instanceof NBTTagFloat) heat = data.getFloat("heat"); - inv.readFromNBT(data); } @Override @@ -297,7 +291,6 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto data.setFloat("progress", progress); data.setFloat("energyF", energy); data.setFloat("heat", heat); - inv.writeToNBT(data); } public void getGUINetworkData(int id, int value) { @@ -327,55 +320,10 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto iCrafting.sendProgressBarUpdate(containerEngine, 2, Math.round(currentOutput * 10)); iCrafting.sendProgressBarUpdate(containerEngine, 3, Math.round(heat * 100)); } - /* IINVENTORY IMPLEMENTATION */ - - @Override - public int getSizeInventory() { - return inv.getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot(int slot) { - return inv.getStackInSlot(slot); - } - - @Override - public ItemStack decrStackSize(int slot, int amount) { - return inv.decrStackSize(slot, amount); - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) { - return inv.getStackInSlotOnClosing(slot); - } - - @Override - public void setInventorySlotContents(int slot, ItemStack itemstack) { - inv.setInventorySlotContents(slot, itemstack); - } - - @Override - public boolean isItemValidForSlot(int i, ItemStack itemstack) { - return true; - } + public void delete() { - InvUtils.dropItems(worldObj, inv, xCoord, yCoord, zCoord); - } - @Override - public String getInvName() { - return "Engine"; - } - - @Override - public int getInventoryStackLimit() { - return 64; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) { - return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this; } /* STATE INFORMATION */ @@ -444,14 +392,6 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto return false; } - @Override - public void openChest() { - } - - @Override - public void closeChest() { - } - public abstract float getMaxEnergy(); public float minEnergyReceived() { diff --git a/common/buildcraft/energy/TileEngineIron.java b/common/buildcraft/energy/TileEngineIron.java index c87229fc..c0b31023 100644 --- a/common/buildcraft/energy/TileEngineIron.java +++ b/common/buildcraft/energy/TileEngineIron.java @@ -7,6 +7,21 @@ */ package buildcraft.energy; +import java.util.LinkedList; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ICrafting; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraftforge.common.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; import buildcraft.BuildCraftCore; import buildcraft.BuildCraftEnergy; import buildcraft.api.fuels.IronEngineCoolant; @@ -21,24 +36,9 @@ import buildcraft.core.fluids.Tank; import buildcraft.core.fluids.TankManager; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.Utils; -import static buildcraft.energy.TileEngine.MIN_HEAT; import buildcraft.energy.gui.ContainerEngine; -import java.util.LinkedList; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.ICrafting; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.biome.BiomeGenBase; -import net.minecraftforge.common.ForgeDirection; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidContainerRegistry; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidTankInfo; -import net.minecraftforge.fluids.IFluidHandler; -public class TileEngineIron extends TileEngine implements IFluidHandler { +public class TileEngineIron extends TileEngineWithInventory implements IFluidHandler { public static int MAX_LIQUID = FluidContainerRegistry.BUCKET_VOLUME * 10; public static float HEAT_PER_MJ = 0.0023F; diff --git a/common/buildcraft/energy/TileEngineLegacy.java b/common/buildcraft/energy/TileEngineLegacy.java index c33dfa4b..10364828 100644 --- a/common/buildcraft/energy/TileEngineLegacy.java +++ b/common/buildcraft/energy/TileEngineLegacy.java @@ -7,7 +7,6 @@ */ package buildcraft.energy; -import buildcraft.core.DefaultProps; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; @@ -23,10 +22,6 @@ public class TileEngineLegacy extends TileEngine { private NBTTagCompound nbt; - public TileEngineLegacy() { - super(0); - } - @Override public void updateEntity() { worldObj.removeBlockTileEntity(xCoord, yCoord, zCoord); diff --git a/common/buildcraft/energy/TileEngineStone.java b/common/buildcraft/energy/TileEngineStone.java index e5d53c1f..6f385d79 100644 --- a/common/buildcraft/energy/TileEngineStone.java +++ b/common/buildcraft/energy/TileEngineStone.java @@ -7,14 +7,8 @@ */ package buildcraft.energy; -import buildcraft.BuildCraftCore; -import buildcraft.BuildCraftEnergy; -import buildcraft.api.gates.ITrigger; -import buildcraft.core.GuiIds; -import buildcraft.core.proxy.CoreProxy; -import buildcraft.core.utils.Utils; -import buildcraft.energy.gui.ContainerEngine; import java.util.LinkedList; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ICrafting; import net.minecraft.item.ItemStack; @@ -22,8 +16,15 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.ForgeDirection; +import buildcraft.BuildCraftCore; +import buildcraft.BuildCraftEnergy; +import buildcraft.api.gates.ITrigger; +import buildcraft.core.GuiIds; +import buildcraft.core.proxy.CoreProxy; +import buildcraft.core.utils.Utils; +import buildcraft.energy.gui.ContainerEngine; -public class TileEngineStone extends TileEngine { +public class TileEngineStone extends TileEngineWithInventory { final float MAX_OUTPUT = 1f; final float MIN_OUTPUT = MAX_OUTPUT / 3; diff --git a/common/buildcraft/energy/TileEngineWithInventory.java b/common/buildcraft/energy/TileEngineWithInventory.java new file mode 100644 index 00000000..1eba264f --- /dev/null +++ b/common/buildcraft/energy/TileEngineWithInventory.java @@ -0,0 +1,91 @@ +package buildcraft.energy; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import buildcraft.core.inventory.InvUtils; +import buildcraft.core.inventory.SimpleInventory; + +public abstract class TileEngineWithInventory extends TileEngine implements IInventory{ + + private final SimpleInventory inv; + + public TileEngineWithInventory(int invSize) { + inv = new SimpleInventory(invSize, "Engine", 64); + } + + /* IINVENTORY IMPLEMENTATION */ + + @Override + public int getSizeInventory() { + return inv.getSizeInventory(); + } + + @Override + public ItemStack getStackInSlot(int slot) { + return inv.getStackInSlot(slot); + } + + @Override + public ItemStack decrStackSize(int slot, int amount) { + return inv.decrStackSize(slot, amount); + } + + @Override + public ItemStack getStackInSlotOnClosing(int slot) { + return inv.getStackInSlotOnClosing(slot); + } + + @Override + public void setInventorySlotContents(int slot, ItemStack itemstack) { + inv.setInventorySlotContents(slot, itemstack); + } + + @Override + public boolean isItemValidForSlot(int i, ItemStack itemstack) { + return true; + } + + @Override + public String getInvName() { + return "Engine"; + } + + @Override + public int getInventoryStackLimit() { + return 64; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer entityplayer) { + return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this; + } + + @Override + public void openChest() { + } + + @Override + public void closeChest() { + } + + @Override + public void readFromNBT(NBTTagCompound data) { + super.readFromNBT(data); + inv.readFromNBT(data); + } + + @Override + public void writeToNBT(NBTTagCompound data) { + super.writeToNBT(data); + inv.writeToNBT(data); + } + + @Override + public void delete() { + super.delete(); + InvUtils.dropItems(worldObj, inv, xCoord, yCoord, zCoord); + } + +} \ No newline at end of file diff --git a/common/buildcraft/energy/TileEngineWood.java b/common/buildcraft/energy/TileEngineWood.java index df753a29..19fa9b4f 100644 --- a/common/buildcraft/energy/TileEngineWood.java +++ b/common/buildcraft/energy/TileEngineWood.java @@ -16,10 +16,6 @@ public class TileEngineWood extends TileEngine { public static final float OUTPUT = 0.05F; - public TileEngineWood() { - super(0); - } - @Override public ResourceLocation getTextureFile() { return WOOD_TEXTURE; diff --git a/common/buildcraft/energy/gui/ContainerEngine.java b/common/buildcraft/energy/gui/ContainerEngine.java index 9c90557d..5b8d017a 100644 --- a/common/buildcraft/energy/gui/ContainerEngine.java +++ b/common/buildcraft/energy/gui/ContainerEngine.java @@ -7,19 +7,19 @@ */ package buildcraft.energy.gui; -import buildcraft.core.gui.BuildCraftContainer; -import buildcraft.energy.TileEngine; -import buildcraft.energy.TileEngineStone; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; +import buildcraft.core.gui.BuildCraftContainer; +import buildcraft.energy.TileEngineStone; +import buildcraft.energy.TileEngineWithInventory; public class ContainerEngine extends BuildCraftContainer { - protected TileEngine engine; + protected TileEngineWithInventory engine; - public ContainerEngine(InventoryPlayer inventoryplayer, TileEngine tileEngine) { + public ContainerEngine(InventoryPlayer inventoryplayer, TileEngineWithInventory tileEngine) { super(tileEngine.getSizeInventory()); engine = tileEngine; diff --git a/common/buildcraft/energy/gui/GuiCombustionEngine.java b/common/buildcraft/energy/gui/GuiCombustionEngine.java index a76ae901..c29a4c0a 100644 --- a/common/buildcraft/energy/gui/GuiCombustionEngine.java +++ b/common/buildcraft/energy/gui/GuiCombustionEngine.java @@ -7,24 +7,26 @@ */ package buildcraft.energy.gui; -import buildcraft.core.DefaultProps; -import buildcraft.core.utils.StringUtils; -import buildcraft.energy.TileEngine; -import buildcraft.energy.TileEngineIron; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.Icon; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; + import org.lwjgl.opengl.GL11; +import buildcraft.core.DefaultProps; +import buildcraft.core.utils.StringUtils; +import buildcraft.energy.TileEngineIron; +import buildcraft.energy.TileEngineWithInventory; + public class GuiCombustionEngine extends GuiEngine { private static final ResourceLocation TEXTURE = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/combustion_engine_gui.png"); private static final ResourceLocation BLOCK_TEXTURE = TextureMap.field_110575_b; - public GuiCombustionEngine(InventoryPlayer inventoryplayer, TileEngine tileEngine) { + public GuiCombustionEngine(InventoryPlayer inventoryplayer, TileEngineWithInventory tileEngine) { super(new ContainerEngine(inventoryplayer, tileEngine), tileEngine); } diff --git a/common/buildcraft/energy/gui/GuiStoneEngine.java b/common/buildcraft/energy/gui/GuiStoneEngine.java index dee51ab7..12209ac5 100644 --- a/common/buildcraft/energy/gui/GuiStoneEngine.java +++ b/common/buildcraft/energy/gui/GuiStoneEngine.java @@ -7,18 +7,21 @@ */ package buildcraft.energy.gui; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + import buildcraft.core.DefaultProps; import buildcraft.core.utils.StringUtils; import buildcraft.energy.TileEngine; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.opengl.GL11; +import buildcraft.energy.TileEngineWithInventory; public class GuiStoneEngine extends GuiEngine { private static final ResourceLocation TEXTURE = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/steam_engine_gui.png"); - public GuiStoneEngine(InventoryPlayer inventoryplayer, TileEngine tileEngine) { + public GuiStoneEngine(InventoryPlayer inventoryplayer, TileEngineWithInventory tileEngine) { super(new ContainerEngine(inventoryplayer, tileEngine), tileEngine); }