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

152 lines
3.7 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.entity.player.EntityPlayer;
2014-04-02 04:47:08 +02:00
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.UsernameCache;
2014-04-02 04:47:08 +02:00
import net.minecraftforge.common.util.ForgeDirection;
import java.util.UUID;
2014-04-02 04:47:08 +02:00
public class TileEntityEE extends TileEntity
{
protected ForgeDirection orientation;
protected byte state;
protected String customName;
protected UUID ownerUUID;
2014-04-02 04:47:08 +02:00
public TileEntityEE()
{
orientation = ForgeDirection.SOUTH;
state = 0;
customName = "";
ownerUUID = null;
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 UUID getOwnerUUID()
{
return ownerUUID;
}
public String getOwnerName()
{
if (ownerUUID != null)
{
return UsernameCache.getLastKnownUsername(ownerUUID);
}
return "Unknown";
}
public void setOwner(EntityPlayer entityPlayer)
2014-04-02 04:47:08 +02:00
{
this.ownerUUID = entityPlayer.getPersistentID();
2014-04-02 04:47:08 +02:00
}
public void setOwnerUUID(UUID ownerUUID)
2014-04-02 04:47:08 +02:00
{
this.ownerUUID = ownerUUID;
2014-04-02 04:47:08 +02:00
}
@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_UUID_MOST_SIG) && nbtTagCompound.hasKey(Names.NBT.OWNER_UUID_LEAST_SIG))
2014-04-02 04:47:08 +02:00
{
this.ownerUUID = new UUID(nbtTagCompound.getLong(Names.NBT.OWNER_UUID_MOST_SIG), nbtTagCompound.getLong(Names.NBT.OWNER_UUID_LEAST_SIG));
2014-04-02 04:47:08 +02:00
}
}
@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.setLong(Names.NBT.OWNER_UUID_MOST_SIG, ownerUUID.getMostSignificantBits());
nbtTagCompound.setLong(Names.NBT.OWNER_UUID_LEAST_SIG, ownerUUID.getLeastSignificantBits());
2014-04-02 04:47:08 +02:00
}
}
2014-04-29 03:24:31 +02:00
public boolean hasCustomName()
{
return customName != null && customName.length() > 0;
}
public boolean hasOwner()
{
return ownerUUID != null;
}
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
}