summaryrefslogtreecommitdiff
path: root/src/main/java/jp/plusplus/fbs/storage/TileEntityMealTerminal.java
blob: 4414d6edebe9bb45b9ac33b9946ab91854293426 (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
package jp.plusplus.fbs.storage;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;

/**
 * Created by plusplus_F on 2016/03/08.
 */
public class TileEntityMealTerminal extends TileEntity implements IMealDevice {
    public ItemStack fragment;

    @Override
    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 pkt) {
        this.readFromNBT(pkt.func_148857_g());
    }

    @Override
    public void readFromNBT(NBTTagCompound par1NBTTagCompound){
        super.readFromNBT(par1NBTTagCompound);
        if(par1NBTTagCompound.hasKey("Fragment")) fragment=ItemStack.loadItemStackFromNBT(par1NBTTagCompound.getCompoundTag("Fragment"));
        else fragment=null;
    }
    @Override
    public void writeToNBT(NBTTagCompound par1NBTTagCompound){
        super.writeToNBT(par1NBTTagCompound);
        if(fragment!=null) par1NBTTagCompound.setTag("Fragment", fragment.writeToNBT(new NBTTagCompound()));
    }

    @Override
    public ItemStack getFragment() {
        return fragment;
    }

    @Override
    public void setFragment(ItemStack f){
        fragment=f;
        markDirty();
        worldObj.markBlockForUpdate(xCoord,yCoord,zCoord);
    }

    @Override
    public boolean hasFragment() {
        return fragment!=null;
    }
}