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;
|
2015-02-05 05:48:07 +01:00
|
|
|
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;
|
2015-02-05 05:48:07 +01:00
|
|
|
import net.minecraftforge.common.UsernameCache;
|
2014-04-02 04:47:08 +02:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
|
2015-02-05 05:48:07 +01:00
|
|
|
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;
|
2015-02-05 05:48:07 +01:00
|
|
|
protected UUID ownerUUID;
|
2014-04-02 04:47:08 +02:00
|
|
|
|
|
|
|
public TileEntityEE()
|
|
|
|
{
|
|
|
|
orientation = ForgeDirection.SOUTH;
|
|
|
|
state = 0;
|
|
|
|
customName = "";
|
2015-02-05 05:48:07 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-02-05 05:48:07 +01:00
|
|
|
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
|
|
|
{
|
2015-02-05 05:48:07 +01:00
|
|
|
this.ownerUUID = entityPlayer.getPersistentID();
|
2014-04-02 04:47:08 +02:00
|
|
|
}
|
|
|
|
|
2015-02-05 05:48:07 +01:00
|
|
|
public void setOwnerUUID(UUID ownerUUID)
|
2014-04-02 04:47:08 +02:00
|
|
|
{
|
2015-02-05 05:48:07 +01: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);
|
|
|
|
}
|
|
|
|
|
2015-02-05 05:48:07 +01:00
|
|
|
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
|
|
|
{
|
2015-03-05 05:31:43 +01: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())
|
|
|
|
{
|
2015-02-05 05:48:07 +01:00
|
|
|
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
|
|
|
|
2014-07-04 21:18:10 +02:00
|
|
|
public boolean hasCustomName()
|
|
|
|
{
|
|
|
|
return customName != null && customName.length() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasOwner()
|
|
|
|
{
|
2015-02-05 05:48:07 +01:00
|
|
|
return ownerUUID != null;
|
2014-07-04 21:18:10 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|