001 package net.minecraft.tileentity;
002
003 import cpw.mods.fml.relauncher.Side;
004 import cpw.mods.fml.relauncher.SideOnly;
005 import net.minecraft.nbt.NBTTagCompound;
006 import net.minecraft.network.packet.Packet;
007 import net.minecraft.network.packet.Packet130UpdateSign;
008
009 public class TileEntitySign extends TileEntity
010 {
011 /** An array of four strings storing the lines of text on the sign. */
012 public String[] signText = new String[] {"", "", "", ""};
013
014 /**
015 * The index of the line currently being edited. Only used on client side, but defined on both. Note this is only
016 * really used when the > < are going to be visible.
017 */
018 public int lineBeingEdited = -1;
019 private boolean isEditable = true;
020
021 /**
022 * Writes a tile entity to NBT.
023 */
024 public void writeToNBT(NBTTagCompound par1NBTTagCompound)
025 {
026 super.writeToNBT(par1NBTTagCompound);
027 par1NBTTagCompound.setString("Text1", this.signText[0]);
028 par1NBTTagCompound.setString("Text2", this.signText[1]);
029 par1NBTTagCompound.setString("Text3", this.signText[2]);
030 par1NBTTagCompound.setString("Text4", this.signText[3]);
031 }
032
033 /**
034 * Reads a tile entity from NBT.
035 */
036 public void readFromNBT(NBTTagCompound par1NBTTagCompound)
037 {
038 this.isEditable = false;
039 super.readFromNBT(par1NBTTagCompound);
040
041 for (int var2 = 0; var2 < 4; ++var2)
042 {
043 this.signText[var2] = par1NBTTagCompound.getString("Text" + (var2 + 1));
044
045 if (this.signText[var2].length() > 15)
046 {
047 this.signText[var2] = this.signText[var2].substring(0, 15);
048 }
049 }
050 }
051
052 /**
053 * Overriden in a sign to provide the text.
054 */
055 public Packet getDescriptionPacket()
056 {
057 String[] var1 = new String[4];
058 System.arraycopy(this.signText, 0, var1, 0, 4);
059 return new Packet130UpdateSign(this.xCoord, this.yCoord, this.zCoord, var1);
060 }
061
062 public boolean isEditable()
063 {
064 return this.isEditable;
065 }
066
067 @SideOnly(Side.CLIENT)
068
069 /**
070 * Sets the sign's isEditable flag to the specified parameter.
071 */
072 public void setEditable(boolean par1)
073 {
074 this.isEditable = par1;
075 }
076 }