Move implementation of IInventory from TileEngine to new abstract class TileEngineWithInventory.

This will effectivly remove IInventory from redstone engines.
Fixes #1180
This commit is contained in:
Krapht 2013-08-31 22:17:50 +02:00
parent f6b0f8a1f2
commit c6ca3b28e7
10 changed files with 157 additions and 129 deletions

View file

@ -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) {

View file

@ -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() {

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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);
}

View file

@ -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);
}