diff options
author | Draknyte1 <Draknyte1@hotmail.com> | 2016-11-06 19:32:27 +1000 |
---|---|---|
committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-11-06 19:32:27 +1000 |
commit | cbe0e497be8e466c380a5b4fa781b314ede9ada3 (patch) | |
tree | b85848b432adf458e3abda466ee46d9dfc3e454b /src/Java/gtPlusPlus/core/tileentities | |
parent | c40416b036c0e89451e1558253ccf07bbee028d0 (diff) | |
download | GT5-Unofficial-cbe0e497be8e466c380a5b4fa781b314ede9ada3.tar.gz GT5-Unofficial-cbe0e497be8e466c380a5b4fa781b314ede9ada3.tar.bz2 GT5-Unofficial-cbe0e497be8e466c380a5b4fa781b314ede9ada3.zip |
Revert "$ Cleaned up the entire project."
This reverts commit 0669f5eb9d5029a8b94ec552171b0837605f7747.
# Conflicts:
# src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMTE_NuclearReactor.java
# src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntity_MassFabricator.java
Revert "% Cleaned up Imports."
This reverts commit 3654052fb63a571c5eaca7f20714b87c17f7e966.
Diffstat (limited to 'src/Java/gtPlusPlus/core/tileentities')
7 files changed, 1004 insertions, 951 deletions
diff --git a/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java b/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java index eebe106e58..a228021c82 100644 --- a/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java +++ b/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java @@ -1,26 +1,22 @@ package gtPlusPlus.core.tileentities; -import cpw.mods.fml.common.registry.GameRegistry; import gtPlusPlus.core.tileentities.machines.TileEntityWorkbench; import gtPlusPlus.core.tileentities.machines.TileEntityWorkbenchAdvanced; import gtPlusPlus.core.util.Utils; +import cpw.mods.fml.common.registry.GameRegistry; public class ModTileEntities { - public static void init() { + + public static void init(){ Utils.LOG_INFO("Registering Tile Entities."); - // GameRegistry.registerTileEntity(TileEntityReverter.class, - // "TE_blockGriefSaver"); - // GameRegistry.registerTileEntity(TileEntityReverter.class, "Tower - // Reverter"); - // GameRegistry.registerTileEntity(TileEntityNHG.class, - // "NuclearFueledHeliumGenerator"); - // GameRegistry.registerTileEntity(TileEntityCharger.class, - // "TE_Charger"); - // GameRegistry.registerTileEntity(TileEntityHeliumGenerator.class, - // "Helium"); + //GameRegistry.registerTileEntity(TileEntityReverter.class, "TE_blockGriefSaver"); + //GameRegistry.registerTileEntity(TileEntityReverter.class, "Tower Reverter"); + //GameRegistry.registerTileEntity(TileEntityNHG.class, "NuclearFueledHeliumGenerator"); + //GameRegistry.registerTileEntity(TileEntityCharger.class, "TE_Charger"); + // GameRegistry.registerTileEntity(TileEntityHeliumGenerator.class, "Helium"); GameRegistry.registerTileEntity(TileEntityWorkbench.class, "TileWorkbench"); GameRegistry.registerTileEntity(TileEntityWorkbenchAdvanced.class, "TileWorkbenchAdvanced"); } - + } diff --git a/src/Java/gtPlusPlus/core/tileentities/base/TILE_ENTITY_BASE.java b/src/Java/gtPlusPlus/core/tileentities/base/TILE_ENTITY_BASE.java index 196c01a018..67c592c79c 100644 --- a/src/Java/gtPlusPlus/core/tileentities/base/TILE_ENTITY_BASE.java +++ b/src/Java/gtPlusPlus/core/tileentities/base/TILE_ENTITY_BASE.java @@ -9,34 +9,31 @@ import net.minecraft.tileentity.TileEntity; public class TILE_ENTITY_BASE extends TileEntity { @Override - public Packet getDescriptionPacket() { - final NBTTagCompound tag = new NBTTagCompound(); - this.writeCustomNBT(tag); - return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, -999, tag); + public void writeToNBT(NBTTagCompound tag) { + super.writeToNBT(tag); + writeCustomNBT(tag); } @Override - public void onDataPacket(final NetworkManager net, final S35PacketUpdateTileEntity packet) { - super.onDataPacket(net, packet); - this.readCustomNBT(packet.func_148857_g()); + public void readFromNBT(NBTTagCompound tag) { + super.readFromNBT(tag); + readCustomNBT(tag); } - public void readCustomNBT(final NBTTagCompound tag) { - } + public void writeCustomNBT(NBTTagCompound tag) {} + public void readCustomNBT(NBTTagCompound tag) {} @Override - public void readFromNBT(final NBTTagCompound tag) { - super.readFromNBT(tag); - this.readCustomNBT(tag); - } - - public void writeCustomNBT(final NBTTagCompound tag) { + public Packet getDescriptionPacket() { + NBTTagCompound tag = new NBTTagCompound(); + writeCustomNBT(tag); + return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, -999, tag); } @Override - public void writeToNBT(final NBTTagCompound tag) { - super.writeToNBT(tag); - this.writeCustomNBT(tag); + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { + super.onDataPacket(net, packet); + readCustomNBT(packet.func_148857_g()); } } diff --git a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityReverter.java b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityReverter.java index 535af68200..8767b6607c 100644 --- a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityReverter.java +++ b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityReverter.java @@ -1,96 +1,90 @@ package gtPlusPlus.core.tileentities.general; +import gtPlusPlus.core.block.ModBlocks; + import java.util.Random; -import gtPlusPlus.core.block.ModBlocks; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.tileentity.TileEntity; -public class TileEntityReverter extends TileEntity { - private static final int REVERT_CHANCE = 10; - public int radius = 16; - public int diameter = 8 * this.radius + 4; - public double requiredPlayerRange = 64.0D; - public Random rand = new Random(); - private int tickCount; - private boolean slowScan; - private int ticksSinceChange; - private Block[] blockData; - private byte[] metaData; - public boolean anyPlayerInRange() { - return this.worldObj.getClosestPlayer(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D, - this.requiredPlayerRange) != null; - } - @Override - public boolean canUpdate() { +public class TileEntityReverter extends TileEntity +{ + private static final int REVERT_CHANCE = 10; + public int radius = 16; + public int diameter = 8 * this.radius + 4; + public double requiredPlayerRange = 64.0D; + public Random rand = new Random(); + private int tickCount; + private boolean slowScan; + private int ticksSinceChange; + private Block[] blockData; + private byte[] metaData; + + public boolean canUpdate(){ return true; } - private void captureBlockData() { - this.blockData = new Block[this.diameter * this.diameter * this.diameter]; - this.metaData = new byte[this.diameter * this.diameter * this.diameter]; - - int index = 0; - for (int x = -this.radius; x <= this.radius; x++) { - for (int y = -this.radius; y <= this.radius; y++) { - for (int z = -this.radius; z <= this.radius; z++) { - final Block blockID = this.worldObj.getBlock(this.xCoord + x, this.yCoord + y, this.zCoord + z); - final int meta = this.worldObj.getBlockMetadata(this.xCoord + x, this.yCoord + y, this.zCoord + z); - - this.blockData[index] = blockID; - this.metaData[index] = (byte) meta; + public void updateEntity() + { + if (anyPlayerInRange()) + { + this.tickCount += 1; + if (this.worldObj.isRemote) + { + double var1 = this.xCoord + this.worldObj.rand.nextFloat(); + double var3 = this.yCoord + this.worldObj.rand.nextFloat(); + double var5 = this.zCoord + this.worldObj.rand.nextFloat(); - index++; + this.worldObj.spawnParticle("enchantmenttable", var1, var3, var5, 0.0D, 0.0D, 0.0D); + if (this.rand.nextInt(5) == 0) + { + makeRandomOutline(); + makeRandomOutline(); + makeRandomOutline(); + } + } + else + { + if ((this.blockData == null) || (this.metaData == null)) + { + captureBlockData(); + this.slowScan = true; + } + if ((!this.slowScan) || (this.tickCount % 20 == 0)) { + if (scanAndRevertChanges()) + { + this.slowScan = false; + this.ticksSinceChange = 0; + } + else + { + this.ticksSinceChange += 1; + if (this.ticksSinceChange > 20) { + this.slowScan = true; + } + } } } } - } - - protected void drawParticleLine(final double srcX, final double srcY, final double srcZ, final double destX, - final double destY, final double destZ) { - final int particles = 16; - for (int i = 0; i < particles; i++) { - final double trailFactor = i / (particles - 1.0D); + else + { + this.blockData = null; + this.metaData = null; - final double tx = srcX + (destX - srcX) * trailFactor + this.rand.nextFloat() * 0.005D; - final double ty = srcY + (destY - srcY) * trailFactor + this.rand.nextFloat() * 0.005D; - final double tz = srcZ + (destZ - srcZ) * trailFactor + this.rand.nextFloat() * 0.005D; - this.worldObj.spawnParticle("portal", tx, ty, tz, 0.0D, 0.0D, 0.0D); + this.tickCount = 0; } } - private boolean isUnrevertable(final Block thereBlockID, final byte thereMeta, final Block replaceBlockID, - final byte replaceMeta) { - if (thereBlockID == ModBlocks.blockGriefSaver || replaceBlockID == ModBlocks.blockGriefSaver) { - return true; - } - /* - * if (((thereBlockID == towerTranslucent) && (thereMeta != 4)) || - * ((replaceBlockID == towerTranslucent) && (replaceMeta != 4))) { - * return true; } - */ - if (thereBlockID == Blocks.redstone_lamp && replaceBlockID == Blocks.lit_redstone_lamp) { - return true; - } - if (thereBlockID == Blocks.lit_redstone_lamp && replaceBlockID == Blocks.redstone_lamp) { - return true; - } - /* - * if ((thereBlockID == Blocks.water) || (replaceBlockID == - * Blocks.flowing_water)) { return true; } if ((thereBlockID == - * Blocks.flowing_water) || (replaceBlockID == Blocks.water)) { return - * true; } - */ - if (replaceBlockID == Blocks.tnt) { - return true; - } - return false; + private void makeRandomOutline() + { + makeOutline(this.rand.nextInt(12)); } - private void makeOutline(final int outline) { + private void makeOutline(int outline) + { double sx = this.xCoord; double sy = this.yCoord; double sz = this.zCoord; @@ -98,143 +92,126 @@ public class TileEntityReverter extends TileEntity { double dx = this.xCoord; double dy = this.yCoord; double dz = this.zCoord; - switch (outline) { - case 0: - sx -= this.radius; - dx -= this.radius; - sz -= this.radius; - dz += this.radius + 1; - case 8: - sx -= this.radius; - dx += this.radius + 1; - sz -= this.radius; - dz -= this.radius; - break; - case 1: - case 9: - sx -= this.radius; - dx -= this.radius; - sz -= this.radius; - dz += this.radius + 1; - break; - case 2: - case 10: - sx -= this.radius; - dx += this.radius + 1; - sz += this.radius + 1; - dz += this.radius + 1; - break; - case 3: - case 11: - sx += this.radius + 1; - dx += this.radius + 1; - sz -= this.radius; - dz += this.radius + 1; - break; - case 4: - sx -= this.radius; - dx -= this.radius; - sz -= this.radius; - dz -= this.radius; - break; - case 5: - sx += this.radius + 1; - dx += this.radius + 1; - sz -= this.radius; - dz -= this.radius; - break; - case 6: - sx += this.radius + 1; - dx += this.radius + 1; - sz += this.radius + 1; - dz += this.radius + 1; - break; - case 7: - sx -= this.radius; - dx -= this.radius; - sz += this.radius + 1; - dz += this.radius + 1; + switch (outline) + { + case 0: + sx -= this.radius; + dx -= this.radius; + sz -= this.radius; + dz += this.radius + 1; + case 8: + sx -= this.radius; + dx += this.radius + 1; + sz -= this.radius; + dz -= this.radius; + break; + case 1: + case 9: + sx -= this.radius; + dx -= this.radius; + sz -= this.radius; + dz += this.radius + 1; + break; + case 2: + case 10: + sx -= this.radius; + dx += this.radius + 1; + sz += this.radius + 1; + dz += this.radius + 1; + break; + case 3: + case 11: + sx += this.radius + 1; + dx += this.radius + 1; + sz -= this.radius; + dz += this.radius + 1; + break; + case 4: + sx -= this.radius; + dx -= this.radius; + sz -= this.radius; + dz -= this.radius; + break; + case 5: + sx += this.radius + 1; + dx += this.radius + 1; + sz -= this.radius; + dz -= this.radius; + break; + case 6: + sx += this.radius + 1; + dx += this.radius + 1; + sz += this.radius + 1; + dz += this.radius + 1; + break; + case 7: + sx -= this.radius; + dx -= this.radius; + sz += this.radius + 1; + dz += this.radius + 1; } - switch (outline) { - case 0: - case 1: - case 2: - case 3: - sy += this.radius + 1; - dy += this.radius + 1; - break; - case 4: - case 5: - case 6: - case 7: - sy -= this.radius; - dy += this.radius + 1; - break; - case 8: - case 9: - case 10: - case 11: - sy -= this.radius; - dy -= this.radius; + switch (outline) + { + case 0: + case 1: + case 2: + case 3: + sy += this.radius + 1; + dy += this.radius + 1; + break; + case 4: + case 5: + case 6: + case 7: + sy -= this.radius; + dy += this.radius + 1; + break; + case 8: + case 9: + case 10: + case 11: + sy -= this.radius; + dy -= this.radius; } if (this.rand.nextBoolean()) { - this.drawParticleLine(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D, dx, dy, dz); + drawParticleLine(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D, dx, dy, dz); + } else { + drawParticleLine(sx, sy, sz, this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D); } - else { - this.drawParticleLine(sx, sy, sz, this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D); - } - this.drawParticleLine(sx, sy, sz, dx, dy, dz); + drawParticleLine(sx, sy, sz, dx, dy, dz); } - private void makeRandomOutline() { - this.makeOutline(this.rand.nextInt(12)); - } + protected void drawParticleLine(double srcX, double srcY, double srcZ, double destX, double destY, double destZ) + { + int particles = 16; + for (int i = 0; i < particles; i++) + { + double trailFactor = i / (particles - 1.0D); - private boolean revertBlock(final int x, final int y, final int z, final Block thereBlockID, final byte thereMeta, - final Block replaceBlockID, byte replaceMeta) { - /* - * if ((thereBlockID == Blocks.air) && - * (!replaceBlockID.getMaterial().blocksMovement())) { - * System.out.println("Not replacing block " + replaceBlockID + - * " because it doesn't block movement"); - * - * return false; } - */ - if (this.isUnrevertable(thereBlockID, thereMeta, replaceBlockID, replaceMeta)) { - return false; - } - if (this.rand.nextInt(5) == 0) { - if (replaceBlockID != Blocks.air) { - // replaceBlockID = null; - replaceMeta = 4; - } - this.worldObj.setBlock(x, y, z, replaceBlockID, replaceMeta, 2); - if (thereBlockID == Blocks.air) { - this.worldObj.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(replaceBlockID) + (replaceMeta << 12)); - } - else if (replaceBlockID == Blocks.air) { - this.worldObj.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(thereBlockID) + (thereMeta << 12)); - thereBlockID.dropBlockAsItem(this.worldObj, x, y, z, thereMeta, 0); - } + double tx = srcX + (destX - srcX) * trailFactor + this.rand.nextFloat() * 0.005D; + double ty = srcY + (destY - srcY) * trailFactor + this.rand.nextFloat() * 0.005D; + double tz = srcZ + (destZ - srcZ) * trailFactor + this.rand.nextFloat() * 0.005D; + this.worldObj.spawnParticle("portal", tx, ty, tz, 0.0D, 0.0D, 0.0D); } - return true; } - private boolean scanAndRevertChanges() { + private boolean scanAndRevertChanges() + { int index = 0; boolean reverted = false; for (int x = -this.radius; x <= this.radius; x++) { for (int y = -this.radius; y <= this.radius; y++) { - for (int z = -this.radius; z <= this.radius; z++) { - final Block blockID = this.worldObj.getBlock(this.xCoord + x, this.yCoord + y, this.zCoord + z); - final byte meta = (byte) this.worldObj.getBlockMetadata(this.xCoord + x, this.yCoord + y, - this.zCoord + z); + for (int z = -this.radius; z <= this.radius; z++) + { + Block blockID = this.worldObj.getBlock(this.xCoord + x, this.yCoord + y, this.zCoord + z); + byte meta = (byte)this.worldObj.getBlockMetadata(this.xCoord + x, this.yCoord + y, this.zCoord + z); if (this.blockData[index] != blockID) { - if (this.revertBlock(this.xCoord + x, this.yCoord + y, this.zCoord + z, blockID, meta, - this.blockData[index], this.metaData[index])) { + if (revertBlock(this.xCoord + x, this.yCoord + y, this.zCoord + z, blockID, meta, this.blockData[index], this.metaData[index])) + { reverted = true; } - else { + else + { this.blockData[index] = blockID; this.metaData[index] = meta; } @@ -246,46 +223,88 @@ public class TileEntityReverter extends TileEntity { return reverted; } - @Override - public void updateEntity() { - if (this.anyPlayerInRange()) { - this.tickCount += 1; - if (this.worldObj.isRemote) { - final double var1 = this.xCoord + this.worldObj.rand.nextFloat(); - final double var3 = this.yCoord + this.worldObj.rand.nextFloat(); - final double var5 = this.zCoord + this.worldObj.rand.nextFloat(); + private boolean revertBlock(int x, int y, int z, Block thereBlockID, byte thereMeta, Block replaceBlockID, byte replaceMeta) + { + /*if ((thereBlockID == Blocks.air) && (!replaceBlockID.getMaterial().blocksMovement())) + { + System.out.println("Not replacing block " + replaceBlockID + " because it doesn't block movement"); - this.worldObj.spawnParticle("enchantmenttable", var1, var3, var5, 0.0D, 0.0D, 0.0D); - if (this.rand.nextInt(5) == 0) { - this.makeRandomOutline(); - this.makeRandomOutline(); - this.makeRandomOutline(); - } + return false; + }*/ + if (isUnrevertable(thereBlockID, thereMeta, replaceBlockID, replaceMeta)) { + return false; + } + if (this.rand.nextInt(5) == 0) + { + if (replaceBlockID != Blocks.air) + { + //replaceBlockID = null; + replaceMeta = 4; } - else { - if (this.blockData == null || this.metaData == null) { - this.captureBlockData(); - this.slowScan = true; - } - if (!this.slowScan || this.tickCount % 20 == 0) { - if (this.scanAndRevertChanges()) { - this.slowScan = false; - this.ticksSinceChange = 0; - } - else { - this.ticksSinceChange += 1; - if (this.ticksSinceChange > 20) { - this.slowScan = true; - } - } - } + this.worldObj.setBlock(x, y, z, replaceBlockID, replaceMeta, 2); + if (thereBlockID == Blocks.air) + { + this.worldObj.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(replaceBlockID) + (replaceMeta << 12)); + } + else if (replaceBlockID == Blocks.air) + { + this.worldObj.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(thereBlockID) + (thereMeta << 12)); + thereBlockID.dropBlockAsItem(this.worldObj, x, y, z, thereMeta, 0); } } - else { - this.blockData = null; - this.metaData = null; + return true; + } - this.tickCount = 0; + private boolean isUnrevertable(Block thereBlockID, byte thereMeta, Block replaceBlockID, byte replaceMeta) + { + if ((thereBlockID == ModBlocks.blockGriefSaver) || (replaceBlockID == ModBlocks.blockGriefSaver)) { + return true; } + /*if (((thereBlockID == towerTranslucent) && (thereMeta != 4)) || ((replaceBlockID == towerTranslucent) && (replaceMeta != 4))) { + return true; + }*/ + if ((thereBlockID == Blocks.redstone_lamp) && (replaceBlockID == Blocks.lit_redstone_lamp)) { + return true; + } + if ((thereBlockID == Blocks.lit_redstone_lamp) && (replaceBlockID == Blocks.redstone_lamp)) { + return true; + } + /*if ((thereBlockID == Blocks.water) || (replaceBlockID == Blocks.flowing_water)) { + return true; + } + if ((thereBlockID == Blocks.flowing_water) || (replaceBlockID == Blocks.water)) { + return true; + }*/ + if (replaceBlockID == Blocks.tnt) { + return true; + } + return false; + } + + private void captureBlockData() + { + this.blockData = new Block[this.diameter * this.diameter * this.diameter]; + this.metaData = new byte[this.diameter * this.diameter * this.diameter]; + + int index = 0; + for (int x = -this.radius; x <= this.radius; x++) { + for (int y = -this.radius; y <= this.radius; y++) { + for (int z = -this.radius; z <= this.radius; z++) + { + Block blockID = this.worldObj.getBlock(this.xCoord + x, this.yCoord + y, this.zCoord + z); + int meta = this.worldObj.getBlockMetadata(this.xCoord + x, this.yCoord + y, this.zCoord + z); + + this.blockData[index] = blockID; + this.metaData[index] = ((byte)meta); + + index++; + } + } + } + } + + public boolean anyPlayerInRange() + { + return this.worldObj.getClosestPlayer(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D, this.requiredPlayerRange) != null; } } diff --git a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityCharger.java b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityCharger.java index cc260527c4..9ec6aa3b24 100644 --- a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityCharger.java +++ b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityCharger.java @@ -9,165 +9,178 @@ import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.Constants; -public class TileEntityCharger extends TileEntity implements IInventory { - private ItemStack[] items = new ItemStack[1]; // 18 - private int progress_Current = 1; - private final int progress_Max = 1000; - public float charge_Current; - public float charge_Max = 10000; - private float tempItemChargeValue; +public class TileEntityCharger extends TileEntity implements IInventory +{ + private ItemStack[] items = new ItemStack[1]; //18 + private int progress_Current = 1; + private int progress_Max = 1000; + public float charge_Current; + public float charge_Max = 10000; + private float tempItemChargeValue; + + public float getCharge(){ + return charge_Current; + } + + public int getProgress(){ + return progress_Current; + } @Override - public void closeInventory() { + public int getSizeInventory() + { + return items.length; } @Override - public ItemStack decrStackSize(final int slot, final int amount) { - if (this.items[slot] != null) { + public ItemStack getStackInSlot(int slot) + { + return items[slot]; + } + + @Override + public ItemStack decrStackSize(int slot, int amount) + { + if (items[slot] != null) + { ItemStack itemstack; - if (this.items[slot].stackSize == amount) { - itemstack = this.items[slot]; - this.items[slot] = null; - this.markDirty(); + if (items[slot].stackSize == amount) + { + itemstack = items[slot]; + items[slot] = null; + markDirty(); return itemstack; } - itemstack = this.items[slot].splitStack(amount); - if (this.items[slot].stackSize == 0) { - this.items[slot] = null; - } - this.markDirty(); + itemstack = items[slot].splitStack(amount); + if (items[slot].stackSize == 0) items[slot] = null; + markDirty(); return itemstack; } return null; } - public float getCharge() { - return this.charge_Current; - } - @Override - public String getInventoryName() { - return "container.Charger"; + public ItemStack getStackInSlotOnClosing(int slot) + { + if (items[slot] != null) + { + ItemStack itemstack = items[slot]; + items[slot] = null; + return itemstack; + } + return null; } @Override - public int getInventoryStackLimit() { - return 64; - } + public void setInventorySlotContents(int slot, ItemStack stack) + { + if (stack != null){ + items[slot] = stack; + if (stack != null && stack.stackSize > getInventoryStackLimit()) + { + stack.stackSize = getInventoryStackLimit(); + } - public int getProgress() { - return this.progress_Current; + + markDirty(); + } } @Override - public int getSizeInventory() { - return this.items.length; + public String getInventoryName() + { + return "container.Charger"; } @Override - public ItemStack getStackInSlot(final int slot) { - return this.items[slot]; + public boolean hasCustomInventoryName() + { + return false; } @Override - public ItemStack getStackInSlotOnClosing(final int slot) { - if (this.items[slot] != null) { - final ItemStack itemstack = this.items[slot]; - this.items[slot] = null; - return itemstack; + public void readFromNBT(NBTTagCompound nbt) + { + super.readFromNBT(nbt); + NBTTagList list = nbt.getTagList("Items", Constants.NBT.TAG_COMPOUND); + items = new ItemStack[getSizeInventory()]; + + for (int i = 0; i < list.tagCount(); ++i) { NBTTagCompound comp = list.getCompoundTagAt(i); int j = comp.getByte("Slot") & 255; if (j >= 0 && j < items.length) + { + items[j] = ItemStack.loadItemStackFromNBT(comp); + } } - return null; } @Override - public boolean hasCustomInventoryName() { - return false; - } + public void writeToNBT(NBTTagCompound nbt) + { + super.writeToNBT(nbt); + NBTTagList list = new NBTTagList(); + + for (int i = 0; i < items.length; ++i) + { + if (items[i] != null) + { + NBTTagCompound comp = new NBTTagCompound(); + comp.setByte("Slot", (byte)i); + items[i].writeToNBT(comp); + list.appendTag(comp); + } + } - @Override - public boolean isItemValidForSlot(final int slot, final ItemStack stack) { - return true; + nbt.setTag("Items", list); } @Override - public boolean isUseableByPlayer(final EntityPlayer player) { - return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false - : player.getDistanceSq(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D) <= 64.0D; + public int getInventoryStackLimit() + { + return 64; } @Override - public void openInventory() { + public boolean isUseableByPlayer(EntityPlayer player) + { + return worldObj.getTileEntity(xCoord, yCoord, zCoord) != this ? false : player.getDistanceSq((double)xCoord + 0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64.0D; } @Override - public void readFromNBT(final NBTTagCompound nbt) { - super.readFromNBT(nbt); - final NBTTagList list = nbt.getTagList("Items", Constants.NBT.TAG_COMPOUND); - this.items = new ItemStack[this.getSizeInventory()]; - - for (int i = 0; i < list.tagCount(); ++i) { - final NBTTagCompound comp = list.getCompoundTagAt(i); - final int j = comp.getByte("Slot") & 255; - if (j >= 0 && j < this.items.length) { - this.items[j] = ItemStack.loadItemStackFromNBT(comp); - } - } - } + public void openInventory() {} @Override - public void setInventorySlotContents(final int slot, final ItemStack stack) { - if (stack != null) { - this.items[slot] = stack; - if (stack != null && stack.stackSize > this.getInventoryStackLimit()) { - stack.stackSize = this.getInventoryStackLimit(); - } + public void closeInventory() {} - this.markDirty(); - } + @Override + public boolean isItemValidForSlot(int slot, ItemStack stack) + { + return true; } @Override public void updateEntity() { - if (!this.worldObj.isRemote) { - if (this.progress_Current < this.progress_Max) { - this.progress_Current++; + if(!this.worldObj.isRemote){ + if (progress_Current < progress_Max){ + progress_Current++; } - else if (this.progress_Current >= this.progress_Max) { - if (this.charge_Current < this.charge_Max) { - this.charge_Current = this.charge_Current + 500; - } - if (this.getStackInSlot(0).getItem() instanceof BaseItemWithCharge) { + else if (progress_Current >= progress_Max){ + if (charge_Current < charge_Max){ + charge_Current = charge_Current+500; + } + if (getStackInSlot(0).getItem() instanceof BaseItemWithCharge){ float tempCharge; - final ItemStack output = this.getStackInSlot(0).copy(); - if (output.stackTagCompound != null) { + ItemStack output = getStackInSlot(0).copy(); + if (output.stackTagCompound != null){ tempCharge = output.stackTagCompound.getFloat("charge_Current"); output.stackTagCompound = new NBTTagCompound(); - output.stackTagCompound.setFloat("charge_Current", tempCharge + 40); - this.charge_Current = this.charge_Current - 40; + output.stackTagCompound.setFloat("charge_Current", tempCharge+40); + this.charge_Current = charge_Current-40; tempCharge = 0; } } - this.progress_Current = 0; + progress_Current = 0; } } } - @Override - public void writeToNBT(final NBTTagCompound nbt) { - super.writeToNBT(nbt); - final NBTTagList list = new NBTTagList(); - - for (int i = 0; i < this.items.length; ++i) { - if (this.items[i] != null) { - final NBTTagCompound comp = new NBTTagCompound(); - comp.setByte("Slot", (byte) i); - this.items[i].writeToNBT(comp); - list.appendTag(comp); - } - } - - nbt.setTag("Items", list); - } - }
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityNHG.java b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityNHG.java index 1183b906dc..3a9dbbd4c7 100644 --- a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityNHG.java +++ b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityNHG.java @@ -12,486 +12,491 @@ import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.Constants; -public class TileEntityNHG extends TileEntity implements IInventory { - private ItemStack[] items = new ItemStack[19]; // 18 - private int progress = 1; - private final int maxProgress = 180; - private int heatCycleProgress = 12; - public float coreTemp; - public float maxTemp = 10000; - private boolean fuelrod_1 = false; - private boolean fuelrod_2 = false; - private boolean fuelrod_3 = false; - private boolean fuelrod_4 = false; - private boolean fuelrod_5 = false; - private boolean fuelrod_6 = false; - private boolean fuelrod_7 = false; - private boolean fuelrod_8 = false; - private boolean fuelrod_9 = false; - private boolean fuelrod_10 = false; - private boolean fuelrod_11 = false; - private boolean fuelrod_12 = false; - private boolean fuelrod_13 = false; - private boolean fuelrod_14 = false; - private boolean fuelrod_15 = false; - private boolean fuelrod_16 = false; - private boolean fuelrod_17 = false; - private boolean fuelrod_18 = false; - - // Machine Code - TODO - private ItemStack neutrons; +public class TileEntityNHG extends TileEntity implements IInventory +{ + private ItemStack[] items = new ItemStack[19]; //18 + private int progress = 1; + private int maxProgress = 180; + private int heatCycleProgress = 12; + public float coreTemp; + public float maxTemp = 10000; + private boolean fuelrod_1 = false; + private boolean fuelrod_2 = false; + private boolean fuelrod_3 = false; + private boolean fuelrod_4 = false; + private boolean fuelrod_5 = false; + private boolean fuelrod_6 = false; + private boolean fuelrod_7 = false; + private boolean fuelrod_8 = false; + private boolean fuelrod_9 = false; + private boolean fuelrod_10 = false; + private boolean fuelrod_11 = false; + private boolean fuelrod_12 = false; + private boolean fuelrod_13 = false; + private boolean fuelrod_14 = false; + private boolean fuelrod_15 = false; + private boolean fuelrod_16 = false; + private boolean fuelrod_17 = false; + private boolean fuelrod_18 = false; + + public float getCoreTemp(){ + return coreTemp; + } - public boolean calculateHeat() { - /* - * if (!fuelrod_1 || !fuelrod_2 || !fuelrod_3 || !fuelrod_4 || - * !fuelrod_5 || !fuelrod_6 || !fuelrod_7 || !fuelrod_8 || !fuelrod_9 || - * !fuelrod_10 || !fuelrod_11 || !fuelrod_12 || !fuelrod_13 || - * !fuelrod_14 || !fuelrod_15 || !fuelrod_16 || !fuelrod_17 || - * !fuelrod_18){ coreTemp = 0; } else { - */ - if (!this.worldObj.isRemote) { - for (int i = 0; i < this.getSizeInventory(); i++) { - if (this.items[i] != null) { - if (this.items[i].getItem() instanceof FuelRod_Base) { - final ItemStack fuelRodStack = this.getStackInSlot(i).copy(); - // if (fuelRodStack.stackTagCompound.getFloat("heat") != - // 0){ - this.doFuelRodHeatDamage(fuelRodStack); - this.coreTemp = this.coreTemp + fuelRodStack.stackTagCompound.getFloat("heat"); - return true; - // } + public int getProgress(){ + return progress; + } + + public boolean isValidFuelRod(ItemStack input){ + if(!this.worldObj.isRemote){ + if (input != null){ + if (input.getItem() instanceof FuelRod_Base){ + int fuelRodFuelLevel = getRodFuelValue(input); + float fuelRodHeatLevel = getRodHeatValue(input); + Utils.LOG_WARNING("Fuel Left: "+fuelRodFuelLevel+" Current Temp: "+fuelRodHeatLevel); + return true; + //return input.stackTagCompound.getInteger("code"); + } + } + + } + return false; + } + + public ItemStack doFuelRodHeatDamage(ItemStack input){ + if(!this.worldObj.isRemote){ + if (input != null){ + if (isValidFuelRod(input)){ + int fuelRodFuelLevel = getRodFuelValue(input); + float fuelRodHeatLevel = getRodHeatValue(input); + if(fuelRodFuelLevel <= 0 || fuelRodFuelLevel == 0){ + return null; + } + if(fuelRodHeatLevel == 0 && fuelRodFuelLevel > 0){ + if(fuelRodFuelLevel >= 5){ + int tempInt=fuelRodFuelLevel; + float tempFloat=fuelRodHeatLevel; + ItemStack output = input.copy(); + if (input.stackTagCompound != null){ + output.stackTagCompound = new NBTTagCompound(); + output.stackTagCompound.setInteger("fuelRemaining", tempInt-40); + output.stackTagCompound.setFloat("heat", tempFloat+20); + } + return output; + } + return null; + } + else if(fuelRodHeatLevel >= 5 && fuelRodFuelLevel > 0){ + int tempInt=fuelRodFuelLevel; + float tempFloat=fuelRodHeatLevel; + ItemStack output = input.copy(); + if (input.stackTagCompound != null){ + output.stackTagCompound = new NBTTagCompound(); + output.stackTagCompound.setInteger("fuelRemaining", tempInt-5); + output.stackTagCompound.setFloat("heat", tempFloat+5); + } + return output; + } + + else if(fuelRodHeatLevel >= 5 && fuelRodFuelLevel == 0){ + ItemStack output = input.copy(); + if (input.stackTagCompound != null){ + output.stackTagCompound = new NBTTagCompound(); + output.stackTagCompound.setInteger("heat", -5); + } + return output; + } + else { + return null; } } } } - // } + return null; + } - return false; + public float getRodHeatValue(ItemStack value){ + if (value != null){ + if (value.stackTagCompound != null){ + return value.stackTagCompound.getFloat("heat"); + } + } + return 0f; + } + + public int getRodFuelValue(ItemStack value){ + if (value != null){ + if (value.stackTagCompound != null){ + int tempInt = value.stackTagCompound.getInteger("fuelRemaining"); + return tempInt; + } + } + return 0; } - public void checkFuelRods() { - - if (!this.worldObj.isRemote) { - for (int i = 0; i < this.getSizeInventory(); i++) { - if (this.items[i] != null) { - if (this.items[i].getItem() instanceof FuelRod_Base) { - final ItemStack fuelRodStack = this.getStackInSlot(i).copy(); - // setInventorySlotContents(i, - // doFuelRodHeatDamage(fuelRodStack)); - if (i == 0) { - this.fuelrod_1 = true; - final ItemStack r = this.doFuelRodHeatDamage(fuelRodStack); - this.setInventorySlotContents(i, r); + public void checkFuelRods(){ + + if(!this.worldObj.isRemote){ + for (int i = 0; i < getSizeInventory(); i++){ + if (items[i] != null){ + if (items[i].getItem() instanceof FuelRod_Base){ + ItemStack fuelRodStack = getStackInSlot(i).copy(); + //setInventorySlotContents(i, doFuelRodHeatDamage(fuelRodStack)); + if (i == 0){ + fuelrod_1 = true; + ItemStack r = doFuelRodHeatDamage(fuelRodStack); + setInventorySlotContents(i, r); } - else if (i == 1) { - this.fuelrod_2 = true; - final ItemStack r = this.doFuelRodHeatDamage(fuelRodStack); - this.setInventorySlotContents(i, r); + else if (i == 1){ + fuelrod_2 = true; + ItemStack r = doFuelRodHeatDamage(fuelRodStack); + setInventorySlotContents(i, r); } - else if (i == 2) { - this.fuelrod_3 = true; - final ItemStack r = this.doFuelRodHeatDamage(fuelRodStack); - this.setInventorySlotContents(i, r); + else if (i == 2){ + fuelrod_3 = true; + ItemStack r = doFuelRodHeatDamage(fuelRodStack); + setInventorySlotContents(i, r); } - else if (i == 3) { - this.fuelrod_4 = true; - final ItemStack r = this.doFuelRodHeatDamage(fuelRodStack); - this.setInventorySlotContents(i, r); + else if (i == 3){ + fuelrod_4 = true; + ItemStack r = doFuelRodHeatDamage(fuelRodStack); + setInventorySlotContents(i, r); } - else if (i == 4) { - this.fuelrod_5 = true; - final ItemStack r = this.doFuelRodHeatDamage(fuelRodStack); - this.setInventorySlotContents(i, r); + else if (i == 4){ + fuelrod_5 = true; + ItemStack r = doFuelRodHeatDamage(fuelRodStack); + setInventorySlotContents(i, r); } - else if (i == 5) { - this.fuelrod_6 = true; - final ItemStack r = this.doFuelRodHeatDamage(fuelRodStack); - this.setInventorySlotContents(i, r); + else if (i == 5){ + fuelrod_6 = true; + ItemStack r = doFuelRodHeatDamage(fuelRodStack); + setInventorySlotContents(i, r); } - else if (i == 6) { - this.fuelrod_7 = true; - final ItemStack r = this.doFuelRodHeatDamage(fuelRodStack); - this.setInventorySlotContents(i, r); + else if (i == 6){ + fuelrod_7 = true; + ItemStack r = doFuelRodHeatDamage(fuelRodStack); + setInventorySlotContents(i, r); } - else if (i == 7) { - this.fuelrod_8 = true; - final ItemStack r = this.doFuelRodHeatDamage(fuelRodStack); - this.setInventorySlotContents(i, r); + else if (i == 7){ + fuelrod_8 = true; + ItemStack r = doFuelRodHeatDamage(fuelRodStack); + setInventorySlotContents(i, r); } - else if (i == 8) { - this.fuelrod_9 = true; - final ItemStack r = this.doFuelRodHeatDamage(fuelRodStack); - this.setInventorySlotContents(i, r); + else if (i == 8){ + fuelrod_9 = true; + ItemStack r = doFuelRodHeatDamage(fuelRodStack); + setInventorySlotContents(i, r); } - else if (i == 9) { - this.fuelrod_10 = true; - final ItemStack r = this.doFuelRodHeatDamage(fuelRodStack); - this.setInventorySlotContents(i, r); + else if (i == 9){ + fuelrod_10 = true; + ItemStack r = doFuelRodHeatDamage(fuelRodStack); + setInventorySlotContents(i, r); } - else if (i == 10) { - this.fuelrod_11 = true; - final ItemStack r = this.doFuelRodHeatDamage(fuelRodStack); - this.setInventorySlotContents(i, r); + else if (i == 10){ + fuelrod_11 = true; + ItemStack r = doFuelRodHeatDamage(fuelRodStack); + setInventorySlotContents(i, r); } - else if (i == 11) { - this.fuelrod_12 = true; - final ItemStack r = this.doFuelRodHeatDamage(fuelRodStack); - this.setInventorySlotContents(i, r); + else if (i == 11){ + fuelrod_12 = true; + ItemStack r = doFuelRodHeatDamage(fuelRodStack); + setInventorySlotContents(i, r); } - else if (i == 12) { - this.fuelrod_13 = true; - final ItemStack r = this.doFuelRodHeatDamage(fuelRodStack); - this.setInventorySlotContents(i, r); + else if (i == 12){ + fuelrod_13 = true; + ItemStack r = doFuelRodHeatDamage(fuelRodStack); + setInventorySlotContents(i, r); } - else if (i == 13) { - this.fuelrod_14 = true; - final ItemStack r = this.doFuelRodHeatDamage(fuelRodStack); - this.setInventorySlotContents(i, r); + else if (i == 13){ + fuelrod_14 = true; + ItemStack r = doFuelRodHeatDamage(fuelRodStack); + setInventorySlotContents(i, r); } - else if (i == 14) { - this.fuelrod_15 = true; - final ItemStack r = this.doFuelRodHeatDamage(fuelRodStack); - this.setInventorySlotContents(i, r); + else if (i == 14){ + fuelrod_15 = true; + ItemStack r = doFuelRodHeatDamage(fuelRodStack); + setInventorySlotContents(i, r); } - else if (i == 15) { - this.fuelrod_16 = true; - final ItemStack r = this.doFuelRodHeatDamage(fuelRodStack); - this.setInventorySlotContents(i, r); + else if (i == 15){ + fuelrod_16 = true; + ItemStack r = doFuelRodHeatDamage(fuelRodStack); + setInventorySlotContents(i, r); } - else if (i == 16) { - this.fuelrod_17 = true; - final ItemStack r = this.doFuelRodHeatDamage(fuelRodStack); - this.setInventorySlotContents(i, r); + else if (i == 16){ + fuelrod_17 = true; + ItemStack r = doFuelRodHeatDamage(fuelRodStack); + setInventorySlotContents(i, r); } - else if (i == 17) { - this.fuelrod_18 = true; - final ItemStack r = this.doFuelRodHeatDamage(fuelRodStack); - this.setInventorySlotContents(i, r); + else if (i == 17){ + fuelrod_18 = true; + ItemStack r = doFuelRodHeatDamage(fuelRodStack); + setInventorySlotContents(i, r); } + } } } - Utils.LOG_WARNING( - "|" + this.fuelrod_1 + "|" + this.fuelrod_2 + "|" + this.fuelrod_3 + "| " + "|" - + this.fuelrod_10 + "|" + this.fuelrod_11 + "|" + this.fuelrod_12 + "|"); - Utils.LOG_WARNING( - "|" + this.fuelrod_4 + "|" + this.fuelrod_5 + "|" + this.fuelrod_6 + "| " + "|" - + this.fuelrod_13 + "|" + this.fuelrod_14 + "|" + this.fuelrod_15 + "|"); - Utils.LOG_WARNING( - "|" + this.fuelrod_7 + "|" + this.fuelrod_8 + "|" + this.fuelrod_9 + "| " + "|" - + this.fuelrod_16 + "|" + this.fuelrod_17 + "|" + this.fuelrod_18 + "|"); + Utils.LOG_WARNING("|"+fuelrod_1+"|"+fuelrod_2+"|"+fuelrod_3+"| "+"|"+fuelrod_10+"|"+fuelrod_11+"|"+fuelrod_12+"|"); + Utils.LOG_WARNING("|"+fuelrod_4+"|"+fuelrod_5+"|"+fuelrod_6+"| "+"|"+fuelrod_13+"|"+fuelrod_14+"|"+fuelrod_15+"|"); + Utils.LOG_WARNING("|"+fuelrod_7+"|"+fuelrod_8+"|"+fuelrod_9+"| "+"|"+fuelrod_16+"|"+fuelrod_17+"|"+fuelrod_18+"|"); } } - @Override - public void closeInventory() { - } - - @Override - public ItemStack decrStackSize(final int slot, final int amount) { - if (this.items[slot] != null) { - ItemStack itemstack; - - if (this.items[slot].stackSize == amount) { - itemstack = this.items[slot]; - this.items[slot] = null; - this.markDirty(); - return itemstack; - } - itemstack = this.items[slot].splitStack(amount); - if (this.items[slot].stackSize == 0) { - this.items[slot] = null; - } - this.markDirty(); - return itemstack; + public boolean calculateHeat(){ + /*if (!fuelrod_1 || !fuelrod_2 || !fuelrod_3 || !fuelrod_4 || !fuelrod_5 || !fuelrod_6 || !fuelrod_7 || !fuelrod_8 || !fuelrod_9 || !fuelrod_10 || !fuelrod_11 || !fuelrod_12 || !fuelrod_13 || !fuelrod_14 || !fuelrod_15 || !fuelrod_16 || !fuelrod_17 || !fuelrod_18){ + coreTemp = 0; } - return null; - } - - public ItemStack doFuelRodHeatDamage(final ItemStack input) { - if (!this.worldObj.isRemote) { - if (input != null) { - if (this.isValidFuelRod(input)) { - final int fuelRodFuelLevel = this.getRodFuelValue(input); - final float fuelRodHeatLevel = this.getRodHeatValue(input); - if (fuelRodFuelLevel <= 0 || fuelRodFuelLevel == 0) { - return null; - } - if (fuelRodHeatLevel == 0 && fuelRodFuelLevel > 0) { - if (fuelRodFuelLevel >= 5) { - final int tempInt = fuelRodFuelLevel; - final float tempFloat = fuelRodHeatLevel; - final ItemStack output = input.copy(); - if (input.stackTagCompound != null) { - output.stackTagCompound = new NBTTagCompound(); - output.stackTagCompound.setInteger("fuelRemaining", tempInt - 40); - output.stackTagCompound.setFloat("heat", tempFloat + 20); - } - return output; - } - return null; - } - else if (fuelRodHeatLevel >= 5 && fuelRodFuelLevel > 0) { - final int tempInt = fuelRodFuelLevel; - final float tempFloat = fuelRodHeatLevel; - final ItemStack output = input.copy(); - if (input.stackTagCompound != null) { - output.stackTagCompound = new NBTTagCompound(); - output.stackTagCompound.setInteger("fuelRemaining", tempInt - 5); - output.stackTagCompound.setFloat("heat", tempFloat + 5); - } - return output; - } - - else if (fuelRodHeatLevel >= 5 && fuelRodFuelLevel == 0) { - final ItemStack output = input.copy(); - if (input.stackTagCompound != null) { - output.stackTagCompound = new NBTTagCompound(); - output.stackTagCompound.setInteger("heat", -5); - } - return output; - } - else { - return null; + else {*/ + if(!this.worldObj.isRemote){ + for (int i = 0; i < getSizeInventory(); i++){ + if (items[i] != null){ + if (items[i].getItem() instanceof FuelRod_Base){ + ItemStack fuelRodStack = getStackInSlot(i).copy(); + //if (fuelRodStack.stackTagCompound.getFloat("heat") != 0){ + doFuelRodHeatDamage(fuelRodStack); + coreTemp = coreTemp+fuelRodStack.stackTagCompound.getFloat("heat"); + return true; + //} } } } } - return null; - } + //} + + - public float getCoreTemp() { - return this.coreTemp; + return false; } @Override - public String getInventoryName() { - return "container.NHG"; + public int getSizeInventory() + { + return items.length; } @Override - public int getInventoryStackLimit() { - return 64; - } + public ItemStack getStackInSlot(int slot) + { - public int getProgress() { - return this.progress; - } + return items[slot]; - public int getRodFuelValue(final ItemStack value) { - if (value != null) { - if (value.stackTagCompound != null) { - final int tempInt = value.stackTagCompound.getInteger("fuelRemaining"); - return tempInt; - } - } - return 0; } - public float getRodHeatValue(final ItemStack value) { - if (value != null) { - if (value.stackTagCompound != null) { - return value.stackTagCompound.getFloat("heat"); + @Override + public ItemStack decrStackSize(int slot, int amount) + { + if (items[slot] != null) + { + ItemStack itemstack; + + if (items[slot].stackSize == amount) + { + itemstack = items[slot]; + items[slot] = null; + markDirty(); + return itemstack; } + itemstack = items[slot].splitStack(amount); + if (items[slot].stackSize == 0) items[slot] = null; + markDirty(); + return itemstack; } - return 0f; + return null; } @Override - public int getSizeInventory() { - return this.items.length; + public ItemStack getStackInSlotOnClosing(int slot) + { + if (items[slot] != null) + { + ItemStack itemstack = items[slot]; + items[slot] = null; + return itemstack; + } + return null; } @Override - public ItemStack getStackInSlot(final int slot) { + public void setInventorySlotContents(int slot, ItemStack stack) + { + if (stack != null){ + items[slot] = stack; + if (stack != null && stack.stackSize > getInventoryStackLimit()) + { + stack.stackSize = getInventoryStackLimit(); + } - return this.items[slot]; + markDirty(); + } } @Override - public ItemStack getStackInSlotOnClosing(final int slot) { - if (this.items[slot] != null) { - final ItemStack itemstack = this.items[slot]; - this.items[slot] = null; - return itemstack; - } - return null; + public String getInventoryName() + { + return "container.NHG"; } @Override - public boolean hasCustomInventoryName() { + public boolean hasCustomInventoryName() + { return false; } @Override - public boolean isItemValidForSlot(final int slot, final ItemStack stack) { - return true; - } + public void readFromNBT(NBTTagCompound nbt) + { + super.readFromNBT(nbt); + NBTTagList list = nbt.getTagList("Items", Constants.NBT.TAG_COMPOUND); + items = new ItemStack[getSizeInventory()]; - @Override - public boolean isUseableByPlayer(final EntityPlayer player) { - return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false - : player.getDistanceSq(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D) <= 64.0D; + for (int i = 0; i < list.tagCount(); ++i) { NBTTagCompound comp = list.getCompoundTagAt(i); int j = comp.getByte("Slot") & 255; if (j >= 0 && j < items.length) + { + items[j] = ItemStack.loadItemStackFromNBT(comp); + } + } } - public boolean isValidFuelRod(final ItemStack input) { - if (!this.worldObj.isRemote) { - if (input != null) { - if (input.getItem() instanceof FuelRod_Base) { - final int fuelRodFuelLevel = this.getRodFuelValue(input); - final float fuelRodHeatLevel = this.getRodHeatValue(input); - Utils.LOG_WARNING("Fuel Left: " + fuelRodFuelLevel + " Current Temp: " + fuelRodHeatLevel); - return true; - // return input.stackTagCompound.getInteger("code"); - } + @Override + public void writeToNBT(NBTTagCompound nbt) + { + super.writeToNBT(nbt); + NBTTagList list = new NBTTagList(); + + for (int i = 0; i < items.length; ++i) + { + if (items[i] != null) + { + NBTTagCompound comp = new NBTTagCompound(); + comp.setByte("Slot", (byte)i); + items[i].writeToNBT(comp); + list.appendTag(comp); } - } - return false; + + nbt.setTag("Items", list); } @Override - public void openInventory() { + public int getInventoryStackLimit() + { + return 64; } - public void readCustomNBT(final NBTTagCompound tag) { - this.neutrons = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("Neutrons")); - this.progress = tag.getInteger("Progress"); - this.coreTemp = tag.getFloat("coreTemp"); + @Override + public boolean isUseableByPlayer(EntityPlayer player) + { + return worldObj.getTileEntity(xCoord, yCoord, zCoord) != this ? false : player.getDistanceSq((double)xCoord + 0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64.0D; } @Override - public void readFromNBT(final NBTTagCompound nbt) { - super.readFromNBT(nbt); - final NBTTagList list = nbt.getTagList("Items", Constants.NBT.TAG_COMPOUND); - this.items = new ItemStack[this.getSizeInventory()]; - - for (int i = 0; i < list.tagCount(); ++i) { - final NBTTagCompound comp = list.getCompoundTagAt(i); - final int j = comp.getByte("Slot") & 255; - if (j >= 0 && j < this.items.length) { - this.items[j] = ItemStack.loadItemStackFromNBT(comp); - } - } - } + public void openInventory() {} @Override - public void setInventorySlotContents(final int slot, final ItemStack stack) { - if (stack != null) { - this.items[slot] = stack; - if (stack != null && stack.stackSize > this.getInventoryStackLimit()) { - stack.stackSize = this.getInventoryStackLimit(); - } + public void closeInventory() {} - this.markDirty(); - } + @Override + public boolean isItemValidForSlot(int slot, ItemStack stack) + { + return true; } + //Machine Code - TODO + private ItemStack neutrons; + @Override public void updateEntity() { - if (!this.worldObj.isRemote) { + if(!this.worldObj.isRemote){ - if (this.progress >= this.heatCycleProgress) { - // Utils.LOG_SPECIFIC_WARNING("NFHG", "Updating Entity - // "+this.getBlockType().getUnlocalizedName(), 376); - if (MathUtils.divideXintoY(this.heatCycleProgress, this.maxProgress)) { - Utils.LOG_SPECIFIC_WARNING("NFHG", "Updating Entity " + this.getBlockType().getUnlocalizedName(), - 378); - this.calculateHeat(); - this.heatCycleProgress = 0; + if(progress >= heatCycleProgress){ + //Utils.LOG_SPECIFIC_WARNING("NFHG", "Updating Entity "+this.getBlockType().getUnlocalizedName(), 376); + if (MathUtils.divideXintoY(heatCycleProgress, maxProgress)){ + Utils.LOG_SPECIFIC_WARNING("NFHG", "Updating Entity "+this.getBlockType().getUnlocalizedName(), 378); + calculateHeat(); + heatCycleProgress=0; } - } + } - if (++this.progress >= this.maxProgress) { + if(++progress >= maxProgress){ - Utils.LOG_SPECIFIC_WARNING("NFHG", "Updating Entity " + this.getBlockType().getUnlocalizedName(), 338); - if (this.items[18] != null) { - final ItemStack checkOutput = this.getStackInSlot(18); - if (this.neutrons == null) { - this.neutrons = new ItemStack(ModItems.itemHeliumBlob, 1); - if (checkOutput == null) { + + Utils.LOG_SPECIFIC_WARNING("NFHG", "Updating Entity "+this.getBlockType().getUnlocalizedName(), 338); + if (items[18] != null){ + ItemStack checkOutput = getStackInSlot(18); + if(neutrons == null){ + neutrons = new ItemStack(ModItems.itemHeliumBlob, 1); + if (checkOutput == null){ Utils.LOG_WARNING("ItemStack in Output slot is definitely null, making a new ItemStack."); - this.setInventorySlotContents(18, this.neutrons); - this.progress = 0; - this.markDirty(); + setInventorySlotContents(18, neutrons); + progress = 0; + markDirty(); } else { checkOutput.stackSize++; - Utils.LOG_WARNING("Found an ItemStack to increase the size of. Current size is " - + this.neutrons.stackSize); + Utils.LOG_WARNING("Found an ItemStack to increase the size of. Current size is "+neutrons.stackSize); - this.progress = 0; - this.markDirty(); + progress = 0; + markDirty(); } } - else if (checkOutput.getItem() == ModItems.itemHeliumBlob && checkOutput.stackSize < 64) { + else if(checkOutput.getItem() == ModItems.itemHeliumBlob && checkOutput.stackSize < 64){ checkOutput.stackSize++; - Utils.LOG_WARNING( - "Found an ItemStack to increase size of. Current size is " + checkOutput.stackSize); - this.progress = 0; - this.markDirty(); + Utils.LOG_WARNING("Found an ItemStack to increase size of. Current size is "+checkOutput.stackSize); + progress = 0; + markDirty(); } - else if (checkOutput.getItem() == ModItems.itemHeliumBlob && checkOutput.stackSize == 64) { + else if(checkOutput.getItem() == ModItems.itemHeliumBlob && checkOutput.stackSize == 64){ Utils.LOG_WARNING("Output stack is full."); - this.progress = 0; - this.markDirty(); + progress = 0; + markDirty(); } } - else if (this.items[18] == null) { + else if (items[18] == null){ Utils.LOG_WARNING("ItemStack in Output slot is null"); - this.neutrons = new ItemStack(ModItems.itemHeliumBlob, 1); - final ItemStack checkOutput = this.getStackInSlot(18); - if (checkOutput == null) { + neutrons = new ItemStack(ModItems.itemHeliumBlob, 1); + ItemStack checkOutput = getStackInSlot(18); + if (checkOutput == null){ Utils.LOG_WARNING("ItemStack in Output slot is definitely null, making a new ItemStack."); - this.setInventorySlotContents(18, this.neutrons); - this.progress = 0; - this.markDirty(); + setInventorySlotContents(18, neutrons); + progress = 0; + markDirty(); } else { Utils.LOG_WARNING("Found an ItemStack to increase the size of."); - checkOutput.stackSize++; - this.progress = 0; - this.markDirty(); + checkOutput.stackSize++; + progress = 0; + markDirty(); } } - this.checkFuelRods(); + checkFuelRods(); } - this.progress++; + progress++; } } - public void writeCustomNBT(final NBTTagCompound tag) { + public void readCustomNBT(NBTTagCompound tag) + { + this.neutrons = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("Neutrons")); + this.progress = tag.getInteger("Progress"); + this.coreTemp = tag.getFloat("coreTemp"); + } + + public void writeCustomNBT(NBTTagCompound tag) + { tag.setInteger("Progress", this.progress); tag.setFloat("coreTemp", this.coreTemp); - if (this.neutrons != null) { - final NBTTagCompound produce = new NBTTagCompound(); - this.neutrons.writeToNBT(produce); + if(neutrons != null) { + NBTTagCompound produce = new NBTTagCompound(); + neutrons.writeToNBT(produce); tag.setTag("Neutrons", produce); } - else { + else tag.removeTag("Neutrons"); - } } - @Override - public void writeToNBT(final NBTTagCompound nbt) { - super.writeToNBT(nbt); - final NBTTagList list = new NBTTagList(); - for (int i = 0; i < this.items.length; ++i) { - if (this.items[i] != null) { - final NBTTagCompound comp = new NBTTagCompound(); - comp.setByte("Slot", (byte) i); - this.items[i].writeToNBT(comp); - list.appendTag(comp); - } - } - - nbt.setTag("Items", list); - } }
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityWorkbench.java b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityWorkbench.java index 2a87d4a7ab..9cbd963572 100644 --- a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityWorkbench.java +++ b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityWorkbench.java @@ -1,13 +1,18 @@ package gtPlusPlus.core.tileentities.machines; -import java.util.List; -import java.util.Vector; - -import gtPlusPlus.core.inventories.*; +import gtPlusPlus.core.inventories.InventoryWorkbenchChest; +import gtPlusPlus.core.inventories.InventoryWorkbenchHoloCrafting; +import gtPlusPlus.core.inventories.InventoryWorkbenchHoloSlots; +import gtPlusPlus.core.inventories.InventoryWorkbenchTools; import ic2.api.network.INetworkDataProvider; import ic2.api.network.INetworkUpdateListener; import ic2.api.tile.IWrenchable; import ic2.core.IC2; +import ic2.core.network.NetworkManager; + +import java.util.List; +import java.util.Vector; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCraftResult; @@ -16,150 +21,154 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; -public class TileEntityWorkbench extends TileEntity - implements INetworkDataProvider, INetworkUpdateListener, IWrenchable { - - // Credit to NovaViper in - // http://www.minecraftforge.net/forum/index.php?topic=26439.0 - Helped me - // restructure my Inventory system and now the crafting matrix works better. - - public InventoryWorkbenchChest inventoryChest; - public InventoryWorkbenchTools inventoryTool; - public InventoryWorkbenchHoloSlots inventoryHolo; - public InventoryWorkbenchHoloCrafting inventoryCrafting; +public class TileEntityWorkbench extends TileEntity implements INetworkDataProvider, INetworkUpdateListener, IWrenchable{ - public IInventory inventoryCraftResult = new InventoryCraftResult(); + //Credit to NovaViper in http://www.minecraftforge.net/forum/index.php?topic=26439.0 - Helped me restructure my Inventory system and now the crafting matrix works better. - private short facing = 0; + public InventoryWorkbenchChest inventoryChest; + public InventoryWorkbenchTools inventoryTool; + public InventoryWorkbenchHoloSlots inventoryHolo; + public InventoryWorkbenchHoloCrafting inventoryCrafting; - public short prevFacing = 0; + public IInventory inventoryCraftResult = new InventoryCraftResult(); - public TileEntityWorkbench() { - this.inventoryTool = new InventoryWorkbenchTools();// number of slots - - // without product - // slot - this.inventoryChest = new InventoryWorkbenchChest();// number of slots - - // without product - // slot + public TileEntityWorkbench(){ + this.inventoryTool = new InventoryWorkbenchTools();//number of slots - without product slot + this.inventoryChest = new InventoryWorkbenchChest();//number of slots - without product slot this.inventoryHolo = new InventoryWorkbenchHoloSlots(); this.inventoryCrafting = new InventoryWorkbenchHoloCrafting(); this.canUpdate(); } - @Override - public short getFacing() { - return this.facing; - } - - @Override - public List<String> getNetworkedFields() { - final List<String> ret = new Vector(2); - ret.add("facing"); - return ret; - } - @SuppressWarnings("static-method") - public NBTTagCompound getTag(final NBTTagCompound nbt, final String tag) { - if (!nbt.hasKey(tag)) { + public NBTTagCompound getTag(NBTTagCompound nbt, String tag) + { + if(!nbt.hasKey(tag)) + { nbt.setTag(tag, new NBTTagCompound()); } return nbt.getCompoundTag(tag); } @Override - public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) { - return new ItemStack(this.worldObj.getBlock(this.xCoord, this.yCoord, this.zCoord), 1, - this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord)); - } - @Override - public float getWrenchDropRate() { - return 1.0F; - } + public void writeToNBT(NBTTagCompound nbt) + { + super.writeToNBT(nbt); + + nbt.setShort("facing", this.facing); + + inventoryChest.writeToNBT(getTag(nbt, "ContentsChest")); + inventoryTool.writeToNBT(getTag(nbt, "ContentsTools")); + //inventoryCrafting.writeToNBT(getTag(nbt, "ContentsCrafting")); + inventoryHolo.writeToNBT(getTag(nbt, "ContentsHolo")); - @Override - public void onNetworkUpdate(final String field) { + // Write Crafting Matrix to NBT + NBTTagList craftingTag = new NBTTagList(); + for (int currentIndex = 0; currentIndex < inventoryCrafting.getSizeInventory(); ++currentIndex) { + if (inventoryCrafting.getStackInSlot(currentIndex) != null) { + NBTTagCompound tagCompound = new NBTTagCompound(); + tagCompound.setByte("Slot", (byte) currentIndex); + inventoryCrafting.getStackInSlot(currentIndex).writeToNBT(tagCompound); + craftingTag.appendTag(tagCompound); + } + } - this.prevFacing = this.facing; + nbt.setTag("CraftingMatrix", craftingTag); + // Write craftingResult to NBT + if (inventoryCraftResult.getStackInSlot(0) != null) + nbt.setTag("CraftingResult", inventoryCraftResult.getStackInSlot(0).writeToNBT(new NBTTagCompound())); } @Override - public void readFromNBT(final NBTTagCompound nbt) { + public void readFromNBT(NBTTagCompound nbt) + { super.readFromNBT(nbt); - this.prevFacing = this.facing = nbt.getShort("facing"); - - this.inventoryChest.readFromNBT(nbt.getCompoundTag("ContentsChest")); - this.inventoryTool.readFromNBT(nbt.getCompoundTag("ContentsTools")); - // inventoryCrafting.readFromNBT(nbt.getCompoundTag("ContentsCrafting")); - this.inventoryHolo.readFromNBT(nbt.getCompoundTag("ContentsHolo")); + this.prevFacing = (this.facing = nbt.getShort("facing")); + + inventoryChest.readFromNBT(nbt.getCompoundTag("ContentsChest")); + inventoryTool.readFromNBT(nbt.getCompoundTag("ContentsTools")); + //inventoryCrafting.readFromNBT(nbt.getCompoundTag("ContentsCrafting")); + inventoryHolo.readFromNBT(nbt.getCompoundTag("ContentsHolo")); // Read in the Crafting Matrix from NBT - final NBTTagList craftingTag = nbt.getTagList("CraftingMatrix", 10); - this.inventoryCrafting = new InventoryWorkbenchHoloCrafting(); // TODO: - // magic - // number + NBTTagList craftingTag = nbt.getTagList("CraftingMatrix", 10); + inventoryCrafting = new InventoryWorkbenchHoloCrafting(); //TODO: magic number for (int i = 0; i < craftingTag.tagCount(); ++i) { - final NBTTagCompound tagCompound = craftingTag.getCompoundTagAt(i); - final byte slot = tagCompound.getByte("Slot"); - if (slot >= 0 && slot < this.inventoryCrafting.getSizeInventory()) { - this.inventoryCrafting.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(tagCompound)); + NBTTagCompound tagCompound = (NBTTagCompound) craftingTag.getCompoundTagAt(i); + byte slot = tagCompound.getByte("Slot"); + if (slot >= 0 && slot < inventoryCrafting.getSizeInventory()) { + inventoryCrafting.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(tagCompound)); } } + // Read craftingResult from NBT - final NBTTagCompound tagCraftResult = nbt.getCompoundTag("CraftingResult"); - this.inventoryCraftResult.setInventorySlotContents(0, ItemStack.loadItemStackFromNBT(tagCraftResult)); + NBTTagCompound tagCraftResult = nbt.getCompoundTag("CraftingResult"); + inventoryCraftResult.setInventorySlotContents(0, ItemStack.loadItemStackFromNBT(tagCraftResult)); } @Override - public void setFacing(final short facing1) { + public List<String> getNetworkedFields(){ + List<String> ret = new Vector(2); + ret.add("facing"); + return ret; + } + + + @Override + public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) + { + return false; + } + + private short facing = 0; + public short prevFacing = 0; + + @Override + public void setFacing(short facing1) + { this.facing = facing1; if (this.prevFacing != facing1) { - IC2.network.get().updateTileEntityField(this, "facing"); + ((NetworkManager)IC2.network.get()).updateTileEntityField(this, "facing"); } this.prevFacing = facing1; } @Override - public boolean wrenchCanRemove(final EntityPlayer entityPlayer) { - return true; + public short getFacing() + { + return this.facing; } + @Override - public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final int side) { - return false; + public boolean wrenchCanRemove(EntityPlayer entityPlayer) + { + return true; } @Override - public void writeToNBT(final NBTTagCompound nbt) { - super.writeToNBT(nbt); + public float getWrenchDropRate() + { + return 1.0F; + } - nbt.setShort("facing", this.facing); + @Override + public ItemStack getWrenchDrop(EntityPlayer entityPlayer) + { + return new ItemStack(this.worldObj.getBlock(this.xCoord, this.yCoord, this.zCoord), 1, this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord)); + } - this.inventoryChest.writeToNBT(this.getTag(nbt, "ContentsChest")); - this.inventoryTool.writeToNBT(this.getTag(nbt, "ContentsTools")); - // inventoryCrafting.writeToNBT(getTag(nbt, "ContentsCrafting")); - this.inventoryHolo.writeToNBT(this.getTag(nbt, "ContentsHolo")); + @Override + public void onNetworkUpdate(String field) { - // Write Crafting Matrix to NBT - final NBTTagList craftingTag = new NBTTagList(); - for (int currentIndex = 0; currentIndex < this.inventoryCrafting.getSizeInventory(); ++currentIndex) { - if (this.inventoryCrafting.getStackInSlot(currentIndex) != null) { - final NBTTagCompound tagCompound = new NBTTagCompound(); - tagCompound.setByte("Slot", (byte) currentIndex); - this.inventoryCrafting.getStackInSlot(currentIndex).writeToNBT(tagCompound); - craftingTag.appendTag(tagCompound); - } - } + this.prevFacing = this.facing; + + } - nbt.setTag("CraftingMatrix", craftingTag); - // Write craftingResult to NBT - if (this.inventoryCraftResult.getStackInSlot(0) != null) { - nbt.setTag("CraftingResult", this.inventoryCraftResult.getStackInSlot(0).writeToNBT(new NBTTagCompound())); - } - } }
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityWorkbenchAdvanced.java b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityWorkbenchAdvanced.java index 0cd730d4c8..63770a6efd 100644 --- a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityWorkbenchAdvanced.java +++ b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityWorkbenchAdvanced.java @@ -1,9 +1,9 @@ package gtPlusPlus.core.tileentities.machines; -import java.util.List; -import java.util.Vector; - -import gtPlusPlus.core.inventories.*; +import gtPlusPlus.core.inventories.InventoryWorkbenchChest; +import gtPlusPlus.core.inventories.InventoryWorkbenchHoloCrafting; +import gtPlusPlus.core.inventories.InventoryWorkbenchHoloSlots; +import gtPlusPlus.core.inventories.InventoryWorkbenchToolsElectric; import ic2.api.energy.event.EnergyTileLoadEvent; import ic2.api.energy.event.EnergyTileUnloadEvent; import ic2.api.energy.tile.IEnergySink; @@ -11,6 +11,11 @@ import ic2.api.network.INetworkDataProvider; import ic2.api.network.INetworkUpdateListener; import ic2.api.tile.IWrenchable; import ic2.core.IC2; +import ic2.core.network.NetworkManager; + +import java.util.List; +import java.util.Vector; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCraftResult; @@ -21,214 +26,223 @@ import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.ForgeDirection; -public class TileEntityWorkbenchAdvanced extends TileEntity - implements IEnergySink, INetworkDataProvider, INetworkUpdateListener, IWrenchable { - - // Credit to NovaViper in - // http://www.minecraftforge.net/forum/index.php?topic=26439.0 - Helped me - // restructure my Inventory system and now the crafting matrix works better. - - public InventoryWorkbenchChest inventoryChest; - public InventoryWorkbenchToolsElectric inventoryTool; - public InventoryWorkbenchHoloSlots inventoryHolo; - public InventoryWorkbenchHoloCrafting inventoryCrafting; - - public IInventory inventoryCraftResult = new InventoryCraftResult(); - - // Wrench Code - private short facing = 0; - public short prevFacing = 0; - - // E-Net Code - public double energy = 0.0D; - public int maxEnergy; - private boolean addedToEnergyNet = false; - private int tier; - private float guiChargeLevel; - - public TileEntityWorkbenchAdvanced(final int maxenergy, final int tier1) { - this.inventoryTool = new InventoryWorkbenchToolsElectric();// number of - // slots - - // without - // product - // slot - this.inventoryChest = new InventoryWorkbenchChest();// number of slots - - // without product - // slot - this.inventoryHolo = new InventoryWorkbenchHoloSlots(); - this.inventoryCrafting = new InventoryWorkbenchHoloCrafting(); - this.canUpdate(); +public class TileEntityWorkbenchAdvanced extends TileEntity implements IEnergySink, INetworkDataProvider, INetworkUpdateListener, IWrenchable{ - // Electric Stats - this.maxEnergy = maxenergy; - this.tier = tier1; + //Credit to NovaViper in http://www.minecraftforge.net/forum/index.php?topic=26439.0 - Helped me restructure my Inventory system and now the crafting matrix works better. - } + public InventoryWorkbenchChest inventoryChest; + public InventoryWorkbenchToolsElectric inventoryTool; + public InventoryWorkbenchHoloSlots inventoryHolo; + public InventoryWorkbenchHoloCrafting inventoryCrafting; - @Override - public boolean acceptsEnergyFrom(final TileEntity emitter, final ForgeDirection direction) { - return true; - } + public IInventory inventoryCraftResult = new InventoryCraftResult(); - public final float getChargeLevel() { - return this.guiChargeLevel; - } + //Wrench Code + private short facing = 0; + public short prevFacing = 0; - @Override - public double getDemandedEnergy() { - return this.maxEnergy - this.energy; - } + //E-Net Code + public double energy = 0.0D; + public int maxEnergy; + private boolean addedToEnergyNet = false; + private int tier; + private float guiChargeLevel; - @Override - public short getFacing() { - return this.facing; - } - @Override - public List<String> getNetworkedFields() { - final List<String> ret = new Vector(2); - ret.add("facing"); - return ret; - } + public TileEntityWorkbenchAdvanced(int maxenergy, int tier1){ + this.inventoryTool = new InventoryWorkbenchToolsElectric();//number of slots - without product slot + this.inventoryChest = new InventoryWorkbenchChest();//number of slots - without product slot + this.inventoryHolo = new InventoryWorkbenchHoloSlots(); + this.inventoryCrafting = new InventoryWorkbenchHoloCrafting(); + this.canUpdate(); + + //Electric Stats + this.maxEnergy = maxenergy; + this.tier = tier1; - @Override - public int getSinkTier() { - return this.tier; } @SuppressWarnings("static-method") - public NBTTagCompound getTag(final NBTTagCompound nbt, final String tag) { - if (!nbt.hasKey(tag)) { + public NBTTagCompound getTag(NBTTagCompound nbt, String tag) + { + if(!nbt.hasKey(tag)) + { nbt.setTag(tag, new NBTTagCompound()); } return nbt.getCompoundTag(tag); } @Override - public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) { - return new ItemStack(this.worldObj.getBlock(this.xCoord, this.yCoord, this.zCoord), 1, - this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord)); - } + public void writeToNBT(NBTTagCompound nbt) + { + super.writeToNBT(nbt); + nbt.setDouble("energy", this.energy); + nbt.setShort("facing", this.facing); - @Override - public float getWrenchDropRate() { - return 1.0F; - } + inventoryChest.writeToNBT(getTag(nbt, "ContentsChest")); + inventoryTool.writeToNBT(getTag(nbt, "ContentsTools")); + //inventoryCrafting.writeToNBT(getTag(nbt, "ContentsCrafting")); + inventoryHolo.writeToNBT(getTag(nbt, "ContentsHolo")); - @Override - public double injectEnergy(final ForgeDirection directionFrom, final double amount, final double voltage) { - if (this.energy >= this.maxEnergy) { - return amount; + // Write Crafting Matrix to NBT + NBTTagList craftingTag = new NBTTagList(); + for (int currentIndex = 0; currentIndex < inventoryCrafting.getSizeInventory(); ++currentIndex) { + if (inventoryCrafting.getStackInSlot(currentIndex) != null) { + NBTTagCompound tagCompound = new NBTTagCompound(); + tagCompound.setByte("Slot", (byte) currentIndex); + inventoryCrafting.getStackInSlot(currentIndex).writeToNBT(tagCompound); + craftingTag.appendTag(tagCompound); + } } - this.energy += amount; - return 0.0D; - } - - @Override - public void onNetworkUpdate(final String field) { - this.prevFacing = this.facing; + nbt.setTag("CraftingMatrix", craftingTag); + // Write craftingResult to NBT + if (inventoryCraftResult.getStackInSlot(0) != null) + nbt.setTag("CraftingResult", inventoryCraftResult.getStackInSlot(0).writeToNBT(new NBTTagCompound())); } @Override - public void readFromNBT(final NBTTagCompound nbt) { + public void readFromNBT(NBTTagCompound nbt) + { super.readFromNBT(nbt); this.energy = nbt.getDouble("energy"); - this.prevFacing = this.facing = nbt.getShort("facing"); + this.prevFacing = (this.facing = nbt.getShort("facing")); - this.inventoryChest.readFromNBT(nbt.getCompoundTag("ContentsChest")); - this.inventoryTool.readFromNBT(nbt.getCompoundTag("ContentsTools")); - // inventoryCrafting.readFromNBT(nbt.getCompoundTag("ContentsCrafting")); - this.inventoryHolo.readFromNBT(nbt.getCompoundTag("ContentsHolo")); + inventoryChest.readFromNBT(nbt.getCompoundTag("ContentsChest")); + inventoryTool.readFromNBT(nbt.getCompoundTag("ContentsTools")); + //inventoryCrafting.readFromNBT(nbt.getCompoundTag("ContentsCrafting")); + inventoryHolo.readFromNBT(nbt.getCompoundTag("ContentsHolo")); // Read in the Crafting Matrix from NBT - final NBTTagList craftingTag = nbt.getTagList("CraftingMatrix", 10); - this.inventoryCrafting = new InventoryWorkbenchHoloCrafting(); // TODO: - // magic - // number + NBTTagList craftingTag = nbt.getTagList("CraftingMatrix", 10); + inventoryCrafting = new InventoryWorkbenchHoloCrafting(); //TODO: magic number for (int i = 0; i < craftingTag.tagCount(); ++i) { - final NBTTagCompound tagCompound = craftingTag.getCompoundTagAt(i); - final byte slot = tagCompound.getByte("Slot"); - if (slot >= 0 && slot < this.inventoryCrafting.getSizeInventory()) { - this.inventoryCrafting.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(tagCompound)); + NBTTagCompound tagCompound = (NBTTagCompound) craftingTag.getCompoundTagAt(i); + byte slot = tagCompound.getByte("Slot"); + if (slot >= 0 && slot < inventoryCrafting.getSizeInventory()) { + inventoryCrafting.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(tagCompound)); } } + // Read craftingResult from NBT - final NBTTagCompound tagCraftResult = nbt.getCompoundTag("CraftingResult"); - this.inventoryCraftResult.setInventorySlotContents(0, ItemStack.loadItemStackFromNBT(tagCraftResult)); + NBTTagCompound tagCraftResult = nbt.getCompoundTag("CraftingResult"); + inventoryCraftResult.setInventorySlotContents(0, ItemStack.loadItemStackFromNBT(tagCraftResult)); } @Override - public void setFacing(final short facing1) { - this.facing = facing1; - if (this.prevFacing != facing1) { - IC2.network.get().updateTileEntityField(this, "facing"); + public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction) + { + return true; + } + + @Override + public double getDemandedEnergy() + { + return this.maxEnergy - this.energy; + } + + @Override + public int getSinkTier() + { + return this.tier; + } + + @Override + public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage) + { + if (this.energy >= this.maxEnergy) { + return amount; } - this.prevFacing = facing1; + this.energy += amount; + return 0.0D; + } + + public final float getChargeLevel() + { + return this.guiChargeLevel; } - public void setTier(final int tier1) { + public void setTier(int tier1) + { if (this.tier == tier1) { return; } - final boolean addedToENet = this.addedToEnergyNet; - if (addedToENet) { + boolean addedToENet = this.addedToEnergyNet; + if (addedToENet) + { MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this)); this.addedToEnergyNet = false; } this.tier = tier1; - for (int i = 0; i < this.inventoryTool.getSizeInventory(); i++) { - // this.inventoryTool..setTier(tier1); TODO + for (int i=0; i<inventoryTool.getSizeInventory(); i++){ + //this.inventoryTool..setTier(tier1); TODO } - if (addedToENet) { + if (addedToENet) + { MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this)); this.addedToEnergyNet = true; } } @Override - public boolean wrenchCanRemove(final EntityPlayer entityPlayer) { - return true; + public List<String> getNetworkedFields(){ + List<String> ret = new Vector(2); + ret.add("facing"); + return ret; } + @Override - public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final int side) { + public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) + { return false; } @Override - public void writeToNBT(final NBTTagCompound nbt) { - super.writeToNBT(nbt); - nbt.setDouble("energy", this.energy); - nbt.setShort("facing", this.facing); + public void setFacing(short facing1) + { + this.facing = facing1; + if (this.prevFacing != facing1) { + ((NetworkManager)IC2.network.get()).updateTileEntityField(this, "facing"); + } + this.prevFacing = facing1; + } - this.inventoryChest.writeToNBT(this.getTag(nbt, "ContentsChest")); - this.inventoryTool.writeToNBT(this.getTag(nbt, "ContentsTools")); - // inventoryCrafting.writeToNBT(getTag(nbt, "ContentsCrafting")); - this.inventoryHolo.writeToNBT(this.getTag(nbt, "ContentsHolo")); + @Override + public short getFacing() + { + return this.facing; + } - // Write Crafting Matrix to NBT - final NBTTagList craftingTag = new NBTTagList(); - for (int currentIndex = 0; currentIndex < this.inventoryCrafting.getSizeInventory(); ++currentIndex) { - if (this.inventoryCrafting.getStackInSlot(currentIndex) != null) { - final NBTTagCompound tagCompound = new NBTTagCompound(); - tagCompound.setByte("Slot", (byte) currentIndex); - this.inventoryCrafting.getStackInSlot(currentIndex).writeToNBT(tagCompound); - craftingTag.appendTag(tagCompound); - } - } - nbt.setTag("CraftingMatrix", craftingTag); - // Write craftingResult to NBT - if (this.inventoryCraftResult.getStackInSlot(0) != null) { - nbt.setTag("CraftingResult", this.inventoryCraftResult.getStackInSlot(0).writeToNBT(new NBTTagCompound())); - } + @Override + public boolean wrenchCanRemove(EntityPlayer entityPlayer) + { + return true; + } + + @Override + public float getWrenchDropRate() + { + return 1.0F; + } + + @Override + public ItemStack getWrenchDrop(EntityPlayer entityPlayer) + { + return new ItemStack(this.worldObj.getBlock(this.xCoord, this.yCoord, this.zCoord), 1, this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord)); + } + + @Override + public void onNetworkUpdate(String field) { + + this.prevFacing = this.facing; } |