Moved item inventory into Engine object.
This commit is contained in:
parent
685310fd79
commit
1098c2ef72
4 changed files with 119 additions and 37 deletions
common/net/minecraft/src/buildcraft/energy
|
@ -10,6 +10,7 @@
|
|||
package net.minecraft.src.buildcraft.energy;
|
||||
|
||||
import net.minecraft.src.ICrafting;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.buildcraft.api.APIProxy;
|
||||
import net.minecraft.src.buildcraft.api.LiquidSlot;
|
||||
|
@ -165,4 +166,11 @@ public abstract class Engine {
|
|||
return currentOutput;
|
||||
}
|
||||
|
||||
/* IINVENTORY */
|
||||
public int getSizeInventory() { return 0; }
|
||||
public ItemStack getStackInSlot(int i) { return null; }
|
||||
public ItemStack decrStackSize(int i, int j) { return null; }
|
||||
public ItemStack getStackInSlotOnClosing(int i) { return getStackInSlot(i); }
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack) {}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ public class EngineIron extends Engine {
|
|||
public static int MAX_HEAT = 100000;
|
||||
public static int COOLANT_THRESHOLD = 49000;
|
||||
|
||||
private ItemStack itemInInventory;
|
||||
|
||||
int burnTime = 0;
|
||||
int liquidQty = 0;
|
||||
int liquidId = 0;
|
||||
|
@ -120,8 +122,6 @@ public class EngineIron extends Engine {
|
|||
public void update() {
|
||||
super.update();
|
||||
|
||||
ItemStack itemInInventory = tile.getStackInSlot(0);
|
||||
|
||||
if (itemInInventory != null) {
|
||||
int liquidId = BuildCraftAPI.getLiquidForFilledItem(itemInInventory);
|
||||
|
||||
|
@ -245,6 +245,12 @@ public class EngineIron extends Engine {
|
|||
coolantQty = nbttagcompound.getInteger("coolantQty");
|
||||
heat = nbttagcompound.getInteger("heat");
|
||||
penaltyCooling = nbttagcompound.getInteger("penaltyCooling");
|
||||
|
||||
if (nbttagcompound.hasKey("itemInInventory")) {
|
||||
NBTTagCompound cpt = nbttagcompound.getCompoundTag("itemInInventory");
|
||||
itemInInventory = ItemStack.loadItemStackFromNBT(cpt);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -255,7 +261,14 @@ public class EngineIron extends Engine {
|
|||
nbttagcompound.setInteger("coolantId", coolantId);
|
||||
nbttagcompound.setInteger("coolantQty", coolantQty);
|
||||
nbttagcompound.setInteger("heat", heat);
|
||||
nbttagcompound.setInteger("penaltyCooling", penaltyCooling);
|
||||
nbttagcompound.setInteger("penaltyCooling", penaltyCooling);
|
||||
|
||||
if (itemInInventory != null) {
|
||||
NBTTagCompound cpt = new NBTTagCompound();
|
||||
itemInInventory.writeToNBT(cpt);
|
||||
nbttagcompound.setTag("itemInInventory", cpt);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getScaledCoolant(int i) {
|
||||
|
@ -320,4 +333,34 @@ public class EngineIron extends Engine {
|
|||
public int getHeat() {
|
||||
return heat;
|
||||
}
|
||||
|
||||
/* IINVENTORY */
|
||||
@Override public int getSizeInventory() { return 1; }
|
||||
@Override public ItemStack getStackInSlot(int i) { return itemInInventory; }
|
||||
@Override public void setInventorySlotContents(int i, ItemStack itemstack) { itemInInventory = itemstack; }
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
if (itemInInventory != null) {
|
||||
ItemStack newStack = itemInInventory.splitStack(j);
|
||||
|
||||
if (itemInInventory.stackSize == 0) {
|
||||
itemInInventory = null;
|
||||
}
|
||||
|
||||
return newStack;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int var1) {
|
||||
if (itemInInventory == null)
|
||||
return null;
|
||||
ItemStack toReturn = itemInInventory;
|
||||
itemInInventory = null;
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ public class EngineStone extends Engine {
|
|||
int burnTime = 0;
|
||||
int totalBurnTime = 0;
|
||||
|
||||
private ItemStack itemInInventory;
|
||||
|
||||
public EngineStone(TileEngine engine) {
|
||||
super(engine);
|
||||
|
||||
|
@ -112,16 +114,30 @@ public class EngineStone extends Engine {
|
|||
}
|
||||
}
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
burnTime = nbttagcompound.getInteger("burnTime");
|
||||
totalBurnTime = nbttagcompound.getInteger("totalBurnTime");
|
||||
|
||||
if (nbttagcompound.hasKey("itemInInventory")) {
|
||||
NBTTagCompound cpt = nbttagcompound.getCompoundTag("itemInInventory");
|
||||
itemInInventory = ItemStack.loadItemStackFromNBT(cpt);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound.setInteger("burnTime", burnTime);
|
||||
nbttagcompound.setInteger("totalBurnTime", totalBurnTime);
|
||||
|
||||
if (itemInInventory != null) {
|
||||
NBTTagCompound cpt = new NBTTagCompound();
|
||||
itemInInventory.writeToNBT(cpt);
|
||||
nbttagcompound.setTag("itemInInventory", cpt);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -161,4 +177,34 @@ public class EngineStone extends Engine {
|
|||
public int getHeat() {
|
||||
return energy;
|
||||
}
|
||||
|
||||
/* IINVENTORY */
|
||||
@Override public int getSizeInventory() { return 1; }
|
||||
@Override public ItemStack getStackInSlot(int i) { return itemInInventory; }
|
||||
@Override public void setInventorySlotContents(int i, ItemStack itemstack) { itemInInventory = itemstack; }
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
if (itemInInventory != null) {
|
||||
ItemStack newStack = itemInInventory.splitStack(j);
|
||||
|
||||
if (itemInInventory.stackSize == 0) {
|
||||
itemInInventory = null;
|
||||
}
|
||||
|
||||
return newStack;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int var1) {
|
||||
if (itemInInventory == null)
|
||||
return null;
|
||||
ItemStack toReturn = itemInInventory;
|
||||
itemInInventory = null;
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -53,8 +53,6 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven
|
|||
|
||||
public int orientation;
|
||||
|
||||
private ItemStack itemInInventory;
|
||||
|
||||
PowerProvider provider;
|
||||
|
||||
public boolean isRedstonePowered = false;
|
||||
|
@ -229,11 +227,6 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven
|
|||
engine.orientation = Orientations.values()[orientation];
|
||||
}
|
||||
|
||||
if (nbttagcompound.hasKey("itemInInventory")) {
|
||||
NBTTagCompound cpt = nbttagcompound.getCompoundTag("itemInInventory");
|
||||
itemInInventory = ItemStack.loadItemStackFromNBT(cpt);
|
||||
}
|
||||
|
||||
if (engine != null) {
|
||||
engine.readFromNBT(nbttagcompound);
|
||||
}
|
||||
|
@ -251,58 +244,48 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven
|
|||
nbttagcompound.setInteger("energy", engine.energy);
|
||||
}
|
||||
|
||||
if (itemInInventory != null) {
|
||||
NBTTagCompound cpt = new NBTTagCompound();
|
||||
itemInInventory.writeToNBT(cpt);
|
||||
nbttagcompound.setTag("itemInInventory", cpt);
|
||||
}
|
||||
|
||||
if (engine != null) {
|
||||
engine.writeToNBT(nbttagcompound);
|
||||
}
|
||||
}
|
||||
|
||||
/* IINVENTORY IMPLEMENTATION */
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
if (engine instanceof EngineStone) {
|
||||
return 1;
|
||||
} else {
|
||||
if(engine != null)
|
||||
return engine.getSizeInventory();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i) {
|
||||
return itemInInventory;
|
||||
if(engine != null)
|
||||
return engine.getStackInSlot(i);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
if (itemInInventory != null) {
|
||||
ItemStack newStack = itemInInventory.splitStack(j);
|
||||
|
||||
if (itemInInventory.stackSize == 0) {
|
||||
itemInInventory = null;
|
||||
}
|
||||
|
||||
return newStack;
|
||||
} else {
|
||||
if(engine != null)
|
||||
return engine.decrStackSize(i, j);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int var1) {
|
||||
if (itemInInventory == null)
|
||||
public ItemStack getStackInSlotOnClosing(int i) {
|
||||
if(engine != null)
|
||||
return engine.getStackInSlotOnClosing(i);
|
||||
else
|
||||
return null;
|
||||
ItemStack toReturn = itemInInventory;
|
||||
itemInInventory = null;
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||
itemInInventory = itemstack;
|
||||
if(engine != null)
|
||||
engine.setInventorySlotContents(i, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -320,6 +303,7 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven
|
|||
return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this;
|
||||
}
|
||||
|
||||
/* STATE INFORMATION */
|
||||
public boolean isBurning() {
|
||||
return engine != null && engine.isBurning();
|
||||
}
|
||||
|
@ -332,6 +316,7 @@ public class TileEngine extends TileBuildCraft implements IPowerReceptor, IInven
|
|||
}
|
||||
}
|
||||
|
||||
/* SMP UPDATING */
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
createEngineIfNeeded();
|
||||
|
|
Loading…
Add table
Reference in a new issue