2012-12-17 21:21:53 +01:00
|
|
|
package com.pahimar.ee3.tileentity;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2013-03-07 22:12:19 +01:00
|
|
|
import net.minecraft.network.packet.Packet;
|
2012-12-17 21:21:53 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
|
2012-12-19 19:09:56 +01:00
|
|
|
import com.pahimar.ee3.lib.Strings;
|
2013-03-07 22:12:19 +01:00
|
|
|
import com.pahimar.ee3.network.PacketTypeHandler;
|
|
|
|
import com.pahimar.ee3.network.packet.PacketTileUpdate;
|
2012-12-19 19:09:56 +01:00
|
|
|
|
2012-12-17 21:21:53 +01:00
|
|
|
/**
|
2013-03-08 19:40:59 +01:00
|
|
|
* Equivalent-Exchange-3
|
2012-12-17 21:21:53 +01:00
|
|
|
*
|
2013-03-08 19:40:59 +01:00
|
|
|
* TileEE
|
2012-12-17 21:21:53 +01:00
|
|
|
*
|
|
|
|
* @author pahimar
|
|
|
|
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class TileEE extends TileEntity {
|
2012-12-19 19:09:56 +01:00
|
|
|
|
|
|
|
private short state;
|
|
|
|
private String owner;
|
2013-03-07 03:46:19 +01:00
|
|
|
private String customName;
|
2013-03-08 19:40:59 +01:00
|
|
|
|
2013-03-07 22:12:19 +01:00
|
|
|
public TileEE() {
|
2013-03-08 19:40:59 +01:00
|
|
|
|
|
|
|
state = 0;
|
|
|
|
owner = "";
|
|
|
|
customName = "";
|
2013-03-07 22:12:19 +01:00
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
|
|
|
|
public short getState() {
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setState(short state) {
|
|
|
|
|
|
|
|
this.state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getOwner() {
|
|
|
|
|
|
|
|
return owner;
|
|
|
|
}
|
2013-03-08 19:40:59 +01:00
|
|
|
|
2013-03-07 03:46:19 +01:00
|
|
|
public boolean hasOwner() {
|
2013-03-08 19:40:59 +01:00
|
|
|
|
|
|
|
return owner != null && owner.length() > 0;
|
2013-03-07 03:46:19 +01:00
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
|
|
|
|
public void setOwner(String owner) {
|
|
|
|
|
|
|
|
this.owner = owner;
|
|
|
|
}
|
2013-03-08 19:40:59 +01:00
|
|
|
|
2013-03-07 03:46:19 +01:00
|
|
|
public boolean hasCustomName() {
|
2013-03-08 19:40:59 +01:00
|
|
|
|
|
|
|
return customName != null && customName.length() > 0;
|
2013-03-07 03:46:19 +01:00
|
|
|
}
|
2013-03-08 19:40:59 +01:00
|
|
|
|
2013-03-07 03:46:19 +01:00
|
|
|
public String getCustomName() {
|
2013-03-08 19:40:59 +01:00
|
|
|
|
2013-03-07 03:46:19 +01:00
|
|
|
return customName;
|
|
|
|
}
|
2013-03-08 19:40:59 +01:00
|
|
|
|
2013-03-07 03:46:19 +01:00
|
|
|
public void setCustomName(String customName) {
|
2013-03-08 19:40:59 +01:00
|
|
|
|
2013-03-07 03:46:19 +01:00
|
|
|
this.customName = customName;
|
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
|
|
|
|
public boolean isUseableByPlayer(EntityPlayer player) {
|
|
|
|
|
|
|
|
return owner.equals(player.username);
|
|
|
|
}
|
|
|
|
|
2013-03-08 19:40:59 +01:00
|
|
|
@Override
|
2012-12-19 19:09:56 +01:00
|
|
|
public void readFromNBT(NBTTagCompound nbtTagCompound) {
|
|
|
|
|
2012-12-17 21:21:53 +01:00
|
|
|
super.readFromNBT(nbtTagCompound);
|
2013-03-08 19:40:59 +01:00
|
|
|
|
2013-03-07 03:46:19 +01:00
|
|
|
if (nbtTagCompound.hasKey(Strings.NBT_TE_STATE_KEY)) {
|
2013-03-08 19:40:59 +01:00
|
|
|
state = nbtTagCompound.getShort(Strings.NBT_TE_STATE_KEY);
|
2013-03-07 03:46:19 +01:00
|
|
|
}
|
2013-03-08 19:40:59 +01:00
|
|
|
|
2013-03-07 03:46:19 +01:00
|
|
|
if (nbtTagCompound.hasKey(Strings.NBT_TE_OWNER_KEY)) {
|
2013-03-08 19:40:59 +01:00
|
|
|
owner = nbtTagCompound.getString(Strings.NBT_TE_OWNER_KEY);
|
2013-03-07 03:46:19 +01:00
|
|
|
}
|
2013-03-08 19:40:59 +01:00
|
|
|
|
2013-03-07 03:46:19 +01:00
|
|
|
if (nbtTagCompound.hasKey(Strings.NBT_TE_CUSTOM_NAME)) {
|
2013-03-08 19:40:59 +01:00
|
|
|
customName = nbtTagCompound.getString(Strings.NBT_TE_CUSTOM_NAME);
|
2013-03-07 03:46:19 +01:00
|
|
|
}
|
2012-12-17 21:21:53 +01:00
|
|
|
}
|
|
|
|
|
2013-03-08 19:40:59 +01:00
|
|
|
@Override
|
2012-12-17 21:21:53 +01:00
|
|
|
public void writeToNBT(NBTTagCompound nbtTagCompound) {
|
2012-12-19 19:09:56 +01:00
|
|
|
|
2012-12-17 21:21:53 +01:00
|
|
|
super.writeToNBT(nbtTagCompound);
|
2012-12-19 19:09:56 +01:00
|
|
|
|
2013-03-08 19:40:59 +01:00
|
|
|
nbtTagCompound.setShort(Strings.NBT_TE_STATE_KEY, state);
|
|
|
|
|
2013-03-07 03:46:19 +01:00
|
|
|
if (hasOwner()) {
|
2013-03-08 19:40:59 +01:00
|
|
|
nbtTagCompound.setString(Strings.NBT_TE_OWNER_KEY, owner);
|
2013-03-07 03:46:19 +01:00
|
|
|
}
|
2013-03-08 19:40:59 +01:00
|
|
|
|
2013-03-07 03:46:19 +01:00
|
|
|
if (this.hasCustomName()) {
|
2013-03-08 19:40:59 +01:00
|
|
|
nbtTagCompound.setString(Strings.NBT_TE_CUSTOM_NAME, customName);
|
2012-12-17 21:21:53 +01:00
|
|
|
}
|
|
|
|
}
|
2013-03-08 19:40:59 +01:00
|
|
|
|
2013-03-07 22:12:19 +01:00
|
|
|
@Override
|
|
|
|
public Packet getDescriptionPacket() {
|
|
|
|
|
2013-03-08 19:40:59 +01:00
|
|
|
return PacketTypeHandler.populatePacket(new PacketTileUpdate(xCoord, yCoord, zCoord, state, owner, customName));
|
2013-03-07 22:12:19 +01:00
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
|
2012-12-17 21:21:53 +01:00
|
|
|
}
|