diff options
| author | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2014-05-21 18:48:35 +0300 |
|---|---|---|
| committer | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2014-05-21 18:48:35 +0300 |
| commit | 27b6d250ba6005bfa9cdd9d291e0656f5e02fa65 (patch) | |
| tree | 89fd6b927e3cdd9391a2479cfa08dee2bda1c15e /src/main/java/darkknight/jewelrycraft/tileentity/TileEntitySmelter.java | |
| parent | 2b4aedb9fb90e02c8ec89130919fb9cfae82770c (diff) | |
Liquids!
Diffstat (limited to 'src/main/java/darkknight/jewelrycraft/tileentity/TileEntitySmelter.java')
| -rw-r--r-- | src/main/java/darkknight/jewelrycraft/tileentity/TileEntitySmelter.java | 254 |
1 files changed, 144 insertions, 110 deletions
diff --git a/src/main/java/darkknight/jewelrycraft/tileentity/TileEntitySmelter.java b/src/main/java/darkknight/jewelrycraft/tileentity/TileEntitySmelter.java index 53a9f82..5f4be83 100644 --- a/src/main/java/darkknight/jewelrycraft/tileentity/TileEntitySmelter.java +++ b/src/main/java/darkknight/jewelrycraft/tileentity/TileEntitySmelter.java @@ -2,6 +2,8 @@ package darkknight.jewelrycraft.tileentity; import java.util.Random; +import darkknight.jewelrycraft.config.ConfigHandler; + import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -12,114 +14,146 @@ import net.minecraft.tileentity.TileEntity; public class TileEntitySmelter extends TileEntity { - public int melting, flow, n = 0, p = 0; - public boolean hasMetal, hasMoltenMetal, isDirty; - public ItemStack metal, moltenMetal; - - public TileEntitySmelter() - { - this.melting = 0; - this.flow = 0; - this.hasMetal = false; - this.hasMoltenMetal = false; - this.metal = new ItemStack(Item.getItemById(0), 0, 0); - this.moltenMetal = new ItemStack(Item.getItemById(0), 0, 0); - this.isDirty = false; - } - - @Override - public void writeToNBT(NBTTagCompound nbt) - { - super.writeToNBT(nbt); - nbt.setInteger("melting", melting); - nbt.setBoolean("hasMetal", hasMetal); - nbt.setBoolean("hasMoltenMetal", hasMoltenMetal); - NBTTagCompound tag = new NBTTagCompound(); - NBTTagCompound tag1 = new NBTTagCompound(); - this.metal.writeToNBT(tag); - nbt.setTag("metal", tag); - this.moltenMetal.writeToNBT(tag1); - nbt.setTag("moltenMetal", tag1); - } - - @Override - public void readFromNBT(NBTTagCompound nbt) - { - super.readFromNBT(nbt); - this.melting = nbt.getInteger("melting"); - this.hasMetal = nbt.getBoolean("hasMetal"); - this.hasMoltenMetal = nbt.getBoolean("hasMoltenMetal"); - this.metal = new ItemStack(Item.getItemById(0), 0, 0); - this.metal.readFromNBT(nbt.getCompoundTag("metal")); - this.moltenMetal = new ItemStack(Item.getItemById(0), 0, 0); - this.moltenMetal.readFromNBT(nbt.getCompoundTag("moltenMetal")); - } - - @Override - public void updateEntity() - { - super.updateEntity(); - Random rand = new Random(); - if(isDirty){ - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - isDirty = false; - } - if (p > 0) - --p; - else - p = 5; - if (n == 0 && p == 0) - { - flow += 16; - if (flow >= 16 * 20) - n = 1; - } - if (n == 1 && p == 0) - { - flow -= 16; - if (flow <= 0) - n = 0; - } - if (this.hasMetal) - { - for (int l = 0; l < 2; ++l) - this.worldObj.spawnParticle("flame", xCoord + rand.nextFloat(), (double) yCoord + 0.3F, zCoord + rand.nextFloat(), 0.0D, 0.0D, 0.0D); - } - if (rand.nextInt(65) == 0) - { - double d5 = this.xCoord + rand.nextFloat(); - double d7 = this.yCoord; - double d6 = this.zCoord + rand.nextFloat(); - this.worldObj.playSound(d5, d7, d6, "liquid.lavapop", 0.2F + rand.nextFloat() * 0.2F, 0.9F + rand.nextFloat() * 0.15F, false); - } - if (this.hasMetal) - { - if (melting > 0) - this.melting--; - if (melting == 0) - { - this.hasMetal = false; - this.moltenMetal = metal; - this.metal = new ItemStack(Item.getItemById(0), 0, 0); - this.hasMoltenMetal = true; - melting = -1; - this.isDirty = true; - this.markDirty(); - } - } - } - - public Packet getDescriptionPacket() - { - NBTTagCompound nbttagcompound = new NBTTagCompound(); - this.writeToNBT(nbttagcompound); - return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbttagcompound); - } - - @Override - public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet) - { - readFromNBT(packet.func_148857_g()); - worldObj.func_147479_m(xCoord, yCoord, zCoord); - } + public int melting, flow, n = 0, p = 0; + public boolean hasMetal, hasMoltenMetal, isDirty, pouring; + public ItemStack metal, moltenMetal; + public float quantity; + + public TileEntitySmelter() + { + this.melting = 0; + this.pouring = false; + this.flow = 0; + this.quantity = 0f; + this.hasMetal = false; + this.hasMoltenMetal = false; + this.metal = new ItemStack(Item.getItemById(0), 0, 0); + this.moltenMetal = new ItemStack(Item.getItemById(0), 0, 0); + this.isDirty = false; + } + + @Override + public void writeToNBT(NBTTagCompound nbt) + { + super.writeToNBT(nbt); + nbt.setInteger("melting", melting); + nbt.setFloat("quantity", quantity); + nbt.setBoolean("hasMetal", hasMetal); + nbt.setBoolean("hasMoltenMetal", hasMoltenMetal); + nbt.setBoolean("pouring", pouring); + NBTTagCompound tag = new NBTTagCompound(); + NBTTagCompound tag1 = new NBTTagCompound(); + this.metal.writeToNBT(tag); + nbt.setTag("metal", tag); + this.moltenMetal.writeToNBT(tag1); + nbt.setTag("moltenMetal", tag1); + } + + @Override + public void readFromNBT(NBTTagCompound nbt) + { + super.readFromNBT(nbt); + this.melting = nbt.getInteger("melting"); + this.quantity = nbt.getFloat("quantity"); + this.hasMetal = nbt.getBoolean("hasMetal"); + this.hasMoltenMetal = nbt.getBoolean("hasMoltenMetal"); + this.pouring = nbt.getBoolean("pouring"); + this.metal = new ItemStack(Item.getItemById(0), 0, 0); + this.metal.readFromNBT(nbt.getCompoundTag("metal")); + this.moltenMetal = new ItemStack(Item.getItemById(0), 0, 0); + this.moltenMetal.readFromNBT(nbt.getCompoundTag("moltenMetal")); + } + + @Override + public void updateEntity() + { + super.updateEntity(); + Random rand = new Random(); + if(isDirty){ + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + isDirty = false; + } + if (p > 0) + --p; + else + p = 5; + if (n == 0 && p == 0) + { + flow += 16; + if (flow >= 16 * 20) + n = 1; + } + if (n == 1 && p == 0) + { + flow -= 16; + if (flow <= 0) + n = 0; + } + if (this.hasMetal) + { + for (int l = 0; l < 2; ++l) + this.worldObj.spawnParticle("flame", xCoord + rand.nextFloat(), (double) yCoord + 0.3F, zCoord + rand.nextFloat(), 0.0D, 0.0D, 0.0D); + } + if (rand.nextInt(65) == 0) + { + double d5 = this.xCoord + rand.nextFloat(); + double d7 = this.yCoord; + double d6 = this.zCoord + rand.nextFloat(); + this.worldObj.playSound(d5, d7, d6, "liquid.lavapop", 0.2F + rand.nextFloat() * 0.2F, 0.9F + rand.nextFloat() * 0.15F, false); + } + if (this.hasMetal) + { + if (melting > 0) + this.melting--; + if (melting == 0) + { + this.hasMetal = false; + this.moltenMetal = metal; + this.metal = new ItemStack(Item.getItemById(0), 0, 0); + this.hasMoltenMetal = true; + this.quantity = 1f; + melting = -1; + this.isDirty = true; + } + } + TileEntityMolder me = null; + if (worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 0 && worldObj.getTileEntity(xCoord, yCoord, zCoord - 1) != null && worldObj.getTileEntity(xCoord, yCoord, zCoord - 1) instanceof TileEntityMolder) + me = (TileEntityMolder) worldObj.getTileEntity(xCoord, yCoord, zCoord - 1); + else if (worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 1 && worldObj.getTileEntity(xCoord + 1, yCoord, zCoord) != null && worldObj.getTileEntity(xCoord + 1, yCoord, zCoord) instanceof TileEntityMolder) + me = (TileEntityMolder) worldObj.getTileEntity(xCoord + 1, yCoord, zCoord); + else if (worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 2 && worldObj.getTileEntity(xCoord, yCoord, zCoord + 1) != null && worldObj.getTileEntity(xCoord, yCoord, zCoord + 1) instanceof TileEntityMolder) + me = (TileEntityMolder) worldObj.getTileEntity(xCoord, yCoord, zCoord + 1); + else if (worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 3 && worldObj.getTileEntity(xCoord - 1, yCoord, zCoord) != null && worldObj.getTileEntity(xCoord - 1, yCoord, zCoord) instanceof TileEntityMolder) + me = (TileEntityMolder) worldObj.getTileEntity(xCoord - 1, yCoord, zCoord); + if(pouring){ + quantity -= 0.01f; + me.quantity += 0.01f; + if(!me.hasMoltenMetal) + { + me.moltenMetal = moltenMetal; + me.hasMoltenMetal = true; + } + if(quantity < 0){ + quantity = 0f; + hasMoltenMetal = false; + moltenMetal = new ItemStack(Item.getItemById(0), 0, 0); + pouring = false; + me.cooling = ConfigHandler.ingotCoolingTime; + } + } + } + + public Packet getDescriptionPacket() + { + NBTTagCompound nbttagcompound = new NBTTagCompound(); + this.writeToNBT(nbttagcompound); + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbttagcompound); + } + + @Override + public void onDataPacket (NetworkManager net, S35PacketUpdateTileEntity packet) + { + readFromNBT(packet.func_148857_g()); + worldObj.func_147479_m(xCoord, yCoord, zCoord); + } } |
