equivalent-exchange-3/src/main/java/com/pahimar/ee3/tileentity/TileEntityEE.java

132 lines
3 KiB
Java
Raw Normal View History

2014-04-02 04:47:08 +02:00
package com.pahimar.ee3.tileentity;
2014-04-29 03:24:31 +02:00
import com.pahimar.ee3.network.PacketHandler;
2014-04-30 03:46:59 +02:00
import com.pahimar.ee3.network.message.MessageTileEntityEE;
2014-04-02 04:47:08 +02:00
import com.pahimar.ee3.reference.Names;
import net.minecraft.nbt.NBTTagCompound;
2014-04-29 03:24:31 +02:00
import net.minecraft.network.Packet;
2014-04-02 04:47:08 +02:00
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityEE extends TileEntity
{
protected ForgeDirection orientation;
protected byte state;
protected String customName;
protected String owner;
public TileEntityEE()
{
orientation = ForgeDirection.SOUTH;
state = 0;
customName = "";
owner = "";
2014-04-02 04:47:08 +02:00
}
public ForgeDirection getOrientation()
{
return orientation;
}
2014-04-30 03:46:59 +02:00
public void setOrientation(ForgeDirection orientation)
2014-04-02 04:47:08 +02:00
{
2014-04-30 03:46:59 +02:00
this.orientation = orientation;
2014-04-02 04:47:08 +02:00
}
2014-04-30 03:46:59 +02:00
public void setOrientation(int orientation)
2014-04-02 04:47:08 +02:00
{
2014-04-30 03:46:59 +02:00
this.orientation = ForgeDirection.getOrientation(orientation);
2014-04-02 04:47:08 +02:00
}
public short getState()
{
return state;
}
public void setState(byte state)
{
this.state = state;
}
public String getCustomName()
{
return customName;
}
public void setCustomName(String customName)
{
this.customName = customName;
}
public String getOwner()
{
return owner;
}
public void setOwner(String owner)
{
this.owner = owner;
}
@Override
public void readFromNBT(NBTTagCompound nbtTagCompound)
{
super.readFromNBT(nbtTagCompound);
if (nbtTagCompound.hasKey(Names.NBT.DIRECTION))
{
this.orientation = ForgeDirection.getOrientation(nbtTagCompound.getByte(Names.NBT.DIRECTION));
}
if (nbtTagCompound.hasKey(Names.NBT.STATE))
{
this.state = nbtTagCompound.getByte(Names.NBT.STATE);
}
if (nbtTagCompound.hasKey(Names.NBT.CUSTOM_NAME))
{
this.customName = nbtTagCompound.getString(Names.NBT.CUSTOM_NAME);
}
if (nbtTagCompound.hasKey(Names.NBT.OWNER))
{
this.owner = nbtTagCompound.getString(Names.NBT.OWNER);
}
}
@Override
public void writeToNBT(NBTTagCompound nbtTagCompound)
{
super.writeToNBT(nbtTagCompound);
nbtTagCompound.setByte(Names.NBT.DIRECTION, (byte) orientation.ordinal());
nbtTagCompound.setByte(Names.NBT.STATE, state);
if (this.hasCustomName())
{
nbtTagCompound.setString(Names.NBT.CUSTOM_NAME, customName);
}
if (this.hasOwner())
{
nbtTagCompound.setString(Names.NBT.OWNER, owner);
}
}
2014-04-29 03:24:31 +02:00
public boolean hasCustomName()
{
return customName != null && customName.length() > 0;
}
public boolean hasOwner()
{
return owner != null && owner.length() > 0;
}
2014-04-29 03:24:31 +02:00
@Override
public Packet getDescriptionPacket()
{
2014-04-30 03:46:59 +02:00
return PacketHandler.INSTANCE.getPacketFrom(new MessageTileEntityEE(this));
2014-04-29 03:24:31 +02:00
}
2014-04-02 04:47:08 +02:00
}