summaryrefslogtreecommitdiff
path: root/eclipse/Jewelrycraft/common/darkknight/jewelrycraft/tileentity/TileEntityJewelrsCraftingTable.java
blob: 5a883d6ec29e16c625e6febae4304207af9969c2 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package darkknight.jewelrycraft.tileentity;

import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import darkknight.jewelrycraft.config.ConfigHandler;
import darkknight.jewelrycraft.util.JewelryNBT;

public class TileEntityJewelrsCraftingTable extends TileEntity
{
    public boolean hasJewelry, hasModifier, hasEndItem, isDirty, hasJewel;
    public ItemStack jewelry, modifier, endItem, jewel;
    public int       timer, effect;
    public float angle;

    public TileEntityJewelrsCraftingTable()
    {
        this.jewelry = new ItemStack(Item.getItemById(0), 0, 0);
        this.modifier = new ItemStack(Item.getItemById(0), 0, 0);
        this.endItem = new ItemStack(Item.getItemById(0), 0, 0);
        this.jewel = new ItemStack(Item.getItemById(0), 0, 0);
        this.hasJewelry = false;
        this.hasModifier = false;
        this.hasEndItem = false;
        this.hasJewel = false;
        this.timer = 0;
        this.effect = 0;
        this.angle = 0;
        this.isDirty = false;
    }

    @Override
    public void writeToNBT(NBTTagCompound nbt)
    {
        super.writeToNBT(nbt);
        nbt.setBoolean("hasJewelry", hasJewelry);
        nbt.setBoolean("hasModifier", hasModifier);
        nbt.setBoolean("hasEndItem", hasEndItem);
        nbt.setBoolean("hasJewel", hasJewel);
        nbt.setInteger("timer", timer);
        nbt.setInteger("effect", effect);
        nbt.setFloat("angle", angle);

        NBTTagCompound tag = new NBTTagCompound();
        NBTTagCompound tag1 = new NBTTagCompound();
        NBTTagCompound tag2 = new NBTTagCompound();
        NBTTagCompound tag3 = new NBTTagCompound();

        this.jewelry.writeToNBT(tag);
        nbt.setTag("jewelry", tag);
        this.modifier.writeToNBT(tag1);
        nbt.setTag("modifier", tag1);
        this.endItem.writeToNBT(tag2);
        nbt.setTag("endItem", tag2);
        this.jewel.writeToNBT(tag3);
        nbt.setTag("jewel", tag3);
    }

    @Override
    public void readFromNBT(NBTTagCompound nbt)
    {
        super.readFromNBT(nbt);
        this.hasJewelry = nbt.getBoolean("hasJewelry");
        this.hasModifier = nbt.getBoolean("hasModifier");
        this.hasEndItem = nbt.getBoolean("hasEndItem");
        this.hasJewel = nbt.getBoolean("hasJewel");

        this.timer = nbt.getInteger("timer");
        this.effect = nbt.getInteger("effect");
        this.angle = nbt.getFloat("angle");
        this.jewelry = new ItemStack(Item.getItemById(0), 0, 0);
        this.jewelry.readFromNBT(nbt.getCompoundTag("jewelry"));
        this.modifier = new ItemStack(Item.getItemById(0), 0, 0);
        this.modifier.readFromNBT(nbt.getCompoundTag("modifier"));
        this.endItem = new ItemStack(Item.getItemById(0), 0, 0);
        this.endItem.readFromNBT(nbt.getCompoundTag("endItem"));
        this.jewel = new ItemStack(Item.getItemById(0), 0, 0);
        this.jewel.readFromNBT(nbt.getCompoundTag("jewel"));
    }

    @Override
    public void updateEntity()
    {
        super.updateEntity();
        if(isDirty){
            worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
            isDirty = true;
        }
        if(angle<360F)angle+=3F;
        else angle=0F;
        if (this.hasJewelry && (this.hasModifier || this.hasJewel) && !this.hasEndItem)
        {
            if (timer > 0)
            {
                timer--;
                for (int l = 0; l < ConfigHandler.jewelryCraftingTime/(timer + 2); ++l)
                {
                    if(this.getBlockMetadata() == 0) this.worldObj.spawnParticle("witchMagic", xCoord + 0.5F, (double) yCoord + 0.8F, zCoord + 0.2F, 0.0D, 0.0D, 0.0D);
                    if(this.getBlockMetadata() == 1) this.worldObj.spawnParticle("witchMagic", xCoord + 0.8F, (double) yCoord + 0.8F, zCoord + 0.5F, 0.0D, 0.0D, 0.0D);
                    if(this.getBlockMetadata() == 2) this.worldObj.spawnParticle("witchMagic", xCoord + 0.5F, (double) yCoord + 0.8F, zCoord + 0.8F, 0.0D, 0.0D, 0.0D);
                    if(this.getBlockMetadata() == 3) this.worldObj.spawnParticle("witchMagic", xCoord + 0.2F, (double) yCoord + 0.8F, zCoord + 0.5F, 0.0D, 0.0D, 0.0D);
                }
            }
            if (timer == 0)
            {
                this.hasEndItem = true;
                this.endItem = jewelry.copy();
                if (hasModifier && modifier != new ItemStack(Item.getItemById(0), 0, 0)) JewelryNBT.addModifier(endItem, modifier);
                if (hasJewel && jewel != new ItemStack(Item.getItemById(0), 0, 0)) JewelryNBT.addJewel(endItem, jewel);
                if (hasJewel && hasModifier && JewelryNBT.isJewelX(endItem, new ItemStack(Items.nether_star)) && JewelryNBT.isModifierX(endItem, new ItemStack(Items.book))) JewelryNBT.addMode(endItem, "Disenchant");
                if (hasModifier && JewelryNBT.isModifierEffectType(endItem)) JewelryNBT.addMode(endItem, "Activated");
                this.hasJewelry = false;
                this.jewelry = new ItemStack(Item.getItemById(0), 0, 0);
                this.hasModifier = false;
                this.modifier = new ItemStack(Item.getItemById(0), 0, 0);
                this.hasJewel = false;
                this.jewel = new ItemStack(Item.getItemById(0), 0, 0);
                timer = -1;
            }
        }
    }
}