Advertisement
Guest User

Untitled

a guest
Feb 4th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.57 KB | None | 0 0
  1. package com.JV.WTTI.GearBed.Block;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import net.minecraft.item.ItemStack;
  6. import net.minecraft.nbt.NBTTagCompound;
  7. import net.minecraft.nbt.NBTTagList;
  8. import net.minecraft.server.gui.IUpdatePlayerListBox;
  9. import net.minecraft.tileentity.TileEntity;
  10.  
  11. public class GearBedTileEntity extends TileEntity implements IUpdatePlayerListBox {
  12.       private boolean aBoolean;
  13.         private byte aByte;
  14.         private short aShort;
  15.         private int anInt;
  16.         private long aLong;
  17.         private float aFloat;
  18.         private double aDouble;
  19.         private String aString;
  20.         private byte[] aByteArray;
  21.         private int[] anIntArray;
  22.         private ItemStack anItemStack;
  23.         private ArrayList aList = new ArrayList();
  24.        
  25.         private String Owner;
  26.        
  27.     @Override
  28.     public void update() {
  29.        // if (!this.worldObj.isRemote)
  30.         //    System.out.println("Hello, I'm a TileEntity!");
  31.     }
  32.     @Override
  33.     public void writeToNBT(NBTTagCompound compound) {
  34.         super.writeToNBT(compound);
  35.  
  36.         //Primitives:
  37.         compound.setBoolean("aBoolean", this.aBoolean);
  38.         compound.setByte("aByte", this.aByte);
  39.         compound.setShort("aShort", this.aShort);
  40.         compound.setInteger("anInt", this.anInt);
  41.         compound.setLong("aLong", this.aLong);
  42.         compound.setFloat("aFloat", this.aFloat);
  43.         compound.setDouble("aDouble", this.aDouble);
  44.         compound.setString("aString", this.aString);
  45.         compound.setByteArray("aByteArray", this.aByteArray);
  46.         compound.setIntArray("anIntArray", this.anIntArray);
  47.  
  48.         compound.setString("Owner", this.Owner);
  49.        
  50.         //Item Stack:
  51.         NBTTagCompound stack = new NBTTagCompound();
  52.         this.anItemStack.writeToNBT(stack);
  53.         compound.setTag("anItemStack", stack);
  54.  
  55.         //TagList of Integer Tags:
  56.         NBTTagList list = new NBTTagList();
  57.         for (int i = 0; i < this.aList.size(); i++) {
  58.             NBTTagCompound nbt = new NBTTagCompound();
  59.             nbt.setInteger("id", i);
  60.             nbt.setInteger("value", (Integer) this.aList.get(i));
  61.             list.appendTag(nbt);
  62.         }
  63.         compound.setTag("aList", list);
  64.     }
  65.  
  66.     @Override
  67.     public void readFromNBT(NBTTagCompound compound) {
  68.         super.readFromNBT(compound);
  69.  
  70.         //Primitives:
  71.         this.aBoolean = compound.getBoolean("aBoolean");
  72.         this.aByte = compound.getByte("aByte");
  73.         this.aShort = compound.getShort("aShort");
  74.         this.anInt = compound.getInteger("anInt");
  75.         this.aLong = compound.getLong("aLong");
  76.         this.aFloat = compound.getFloat("aFloat");
  77.         this.aDouble = compound.getDouble("aDouble");
  78.         this.aString = compound.getString("aString");
  79.         this.aByteArray = compound.getByteArray("aByteArray");
  80.         this.anIntArray = compound.getIntArray("anIntArray");
  81.  
  82.         this.Owner = compound.getString("Owner");
  83.        
  84.         //ItemStack:
  85.         this.anItemStack = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("anItemStack"));
  86.  
  87.         //TagList of Integer Tags:
  88.         NBTTagList list = compound.getTagList("aList", 10);
  89.         this.aList.clear();
  90.         for (int i = 0; i < list.tagCount(); i++) {
  91.             NBTTagCompound nbt = list.getCompoundTagAt(i);
  92.             int id = nbt.getInteger("id");
  93.             int value = nbt.getInteger("value");
  94.             this.aList.ensureCapacity(id);
  95.             this.aList.set(id, value);
  96.         }
  97.     }
  98. public String GetOwner(){
  99. return this.Owner;
  100. }
  101. public void SetOwner(String S){
  102. this.Owner = S;
  103. }
  104.  
  105.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement