summaryrefslogtreecommitdiff
path: root/common/darkknight/jewelrycraft/tileentity/TileEntitySmelter.java
blob: 85503c9fe5d88fd8c4c7ce2c2cdfc004253752c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package darkknight.jewelrycraft.tileentity;

import java.util.Random;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.tileentity.TileEntity;

public class TileEntitySmelter extends TileEntity
{
    public int melting, flow, n=0, p=0;
    public boolean hasMetal, hasMoltenMetal;
    public ItemStack metal, moltenMetal;

    public TileEntitySmelter()
    {
        this.melting = 0;
        this.flow = 0;
        this.hasMetal = false;
        this.hasMoltenMetal= false;
        this.metal = new ItemStack(0, 0, 0);
        this.moltenMetal = new ItemStack(0, 0, 0);
    }

    @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.setCompoundTag("metal", tag);
        this.moltenMetal.writeToNBT(tag1);
        nbt.setCompoundTag("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(0, 0, 0);
        this.metal.readFromNBT(nbt.getCompoundTag("metal"));
        this.moltenMetal = new ItemStack(0, 0, 0);
        this.moltenMetal.readFromNBT(nbt.getCompoundTag("moltenMetal"));
    }

    public void updateEntity()
    {
        super.updateEntity();
        Random rand = new Random();
        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.melting > 0)
        {           
            for (int l = 0; l < 5; ++l)
            {
                //EntityFX entityfx = new EntityReddustFX(this.worldObj, (double)xCoord + Math.random(), (double)yCoord + 0.2D, (double)zCoord + Math.random(), 0.0F, 0.0F, 0.0F);
                this.worldObj.spawnParticle("flame", (double)xCoord, (double)yCoord + 1.5F, (double)zCoord, 0.0D, 0.0D, 0.0D);
            }
        }
        if(rand.nextInt(65) == 0){
            double d5 = (double)((float)this.xCoord + rand.nextFloat());
            double d7 = (double)this.yCoord;
            double d6 = (double)((float)this.zCoord + rand.nextFloat());
            //this.worldObj.spawnParticle("lava", d5, d7, d6, 0.0D, 0.0D, 0.0D);
            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(0, 0, 0);
                this.hasMoltenMetal = true;
            }
        }
    }

    public Packet getDescriptionPacket() 
    {
        NBTTagCompound nbtTag = new NBTTagCompound();
        this.writeToNBT(nbtTag);
        return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
    }
}