Guest User

TileEntity Class

a guest
Feb 28th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. public class TileEntityCPU extends TileEntity{
  2.  
  3.  
  4.     //string list (replace references of this with yours)
  5.     public List<String> stringList = new ArrayList<String>(9);
  6.    
  7.    
  8.     public TileEntityCPU() {
  9.         super();
  10.         this.stringList.add(0, "1");
  11.         this.stringList.add(1, "2");
  12.         this.stringList.add(2, "3");
  13.         this.stringList.add(3, "4");
  14.         this.stringList.add(4, "5");
  15.         this.stringList.add(5, "6");
  16.         this.stringList.add(6, "7");
  17.         this.stringList.add(7, "8");
  18.         this.stringList.add(8, "9");
  19.         System.out.println(this.stringList);
  20.     }
  21.  
  22.     public String getLine(int line) {
  23.         return this.stringList.get(line);
  24.     }
  25.    
  26.     public void setLine(String code, int line) {
  27.         this.stringList.set(line, code);
  28.     }
  29.    
  30.  
  31.     public void writeToNBT(NBTTagCompound comp)
  32.     {
  33.      super.writeToNBT(comp);
  34.      NBTTagList tagList = new NBTTagList();
  35.      for(int i = 0; i < stringList.size(); i++)
  36.      {
  37.       String s = stringList.get(i);
  38.       if(s != null)
  39.       {
  40.        NBTTagCompound tag = new NBTTagCompound();
  41.        tag.setString("Code" + i, s);
  42.        tagList.appendTag(tag);
  43.       }
  44.      }
  45.      comp.setTag("CodeList", tagList);
  46.     }
  47.  
  48.     public void readFromNBT(NBTTagCompound comp)
  49.     {
  50.      super.readFromNBT(comp);
  51.      NBTTagList tagList = comp.getTagList("CodeList", Constants.NBT.TAG_COMPOUND);
  52.      for(int i = 0; i < tagList.tagCount(); i++)
  53.      {
  54.       NBTTagCompound tag = tagList.getCompoundTagAt(i);
  55.       String s = tag.getString("Code" + i);
  56.       stringList.add(i, s);
  57.      }
  58.     }
  59.    
  60.     public Container createContainer() {
  61.         return new ContainerCPU();
  62.     }
  63.    
  64.     @Override
  65.     public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
  66.     {
  67.         this.readFromNBT(pkt.getNbtCompound());
  68.         this.markDirty();
  69.     }
  70.    
  71.     public void update(World world) {
  72.         worldObj.markBlockForUpdate(this.pos);
  73.     }
  74.    
  75. }
Add Comment
Please, Sign In to add comment