summaryrefslogtreecommitdiff
path: root/common/darkknight/jewelrycraft/tileentity/TileEntityMolder.java
blob: 092bb47e2d40859ea87425ab9b67ad773bcc8a06 (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
package darkknight.jewelrycraft.tileentity;

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

public class TileEntityMolder extends TileEntity
{
    public int cooling;
    public boolean hasMoltenMetal, hasJewelBase, hasMold;
    public ItemStack mold, jewelBase, moltenMetal;

    public TileEntityMolder()
    {
        this.moltenMetal = new ItemStack(0, 0, 0);
        this.jewelBase = new ItemStack(0, 0, 0);
        this.mold = new ItemStack(0, 0, 0);
        this.cooling = 0;
        this.hasJewelBase = false;
        this.hasMoltenMetal = false;
        this.hasMold = false;
    }

    @Override
    public void writeToNBT(NBTTagCompound nbt)
    {
        super.writeToNBT(nbt);
        nbt.setInteger("cooling", cooling);
        nbt.setBoolean("hasJewelBase", hasJewelBase);
        nbt.setBoolean("hasMoltenMetal", hasMoltenMetal);
        nbt.setBoolean("hasMold", hasMold);
        NBTTagCompound tag = new NBTTagCompound();
        NBTTagCompound tag1 = new NBTTagCompound();
        NBTTagCompound tag2 = new NBTTagCompound();
        this.mold.writeToNBT(tag);
        nbt.setCompoundTag("mold", tag);
        this.jewelBase.writeToNBT(tag1);
        nbt.setCompoundTag("jewelBase", tag1);
        this.moltenMetal.writeToNBT(tag2);
        nbt.setCompoundTag("moltenMetal", tag2);
    }

    @Override
    public void readFromNBT(NBTTagCompound nbt)
    {
        super.readFromNBT(nbt);
        this.cooling = nbt.getInteger("cooling");
        this.hasJewelBase = nbt.getBoolean("hasJewelBase");
        this.hasMoltenMetal = nbt.getBoolean("hasMoltenMetal");
        this.hasMold = nbt.getBoolean("hasMold");
        this.mold = new ItemStack(0, 0, 0);
        this.mold.readFromNBT(nbt.getCompoundTag("mold"));
        this.jewelBase = new ItemStack(0, 0, 0);
        this.jewelBase.readFromNBT(nbt.getCompoundTag("jewelBase"));
        this.moltenMetal = new ItemStack(0, 0, 0);
        this.moltenMetal.readFromNBT(nbt.getCompoundTag("moltenMetal"));
    }

    public void updateEntity()
    {
        super.updateEntity();
        if(this.hasMoltenMetal && !this.hasJewelBase)
        {            
            while(cooling > 0)
            {
                this.cooling--;
                System.out.println(cooling);
            }
            if(cooling == 0)
            {
                this.hasMoltenMetal = false;
                this.jewelBase = moltenMetal;
                this.moltenMetal = new ItemStack(0, 0, 0);
                this.hasJewelBase = true;
            }
        }
        System.out.print(hasJewelBase);
    }
    
    public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt)
    {
        readFromNBT(pkt.data);
    }

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