Advertisement
Guest User

TileEntityAssemblyCounter

a guest
Mar 25th, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.27 KB | None | 0 0
  1. List<Integer> counted = new ArrayList(); // entityId of counted items
  2. HashMap<int[], Integer> counter = new HashMap(); // int[]{ id, damage } => count
  3.  
  4.  
  5.  
  6. public Packet getDescriptionPacket() {
  7.     NBTTagCompound nbttagcompound = new NBTTagCompound();
  8.     writeToNBT(nbttagcompound);
  9.     return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbttagcompound);
  10. }
  11.  
  12. public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
  13.     if (packet.func_148857_g() == null) {
  14.         Assembly.logger.warn("AssemblyCounter received description packet with NBT=null?! (" + packet + ")");
  15.         return;
  16.     }
  17.     readFromNBT(packet.func_148857_g());
  18. }
  19.  
  20. public void readFromNBT(NBTTagCompound nbttagcompound) {
  21.     if (nbttagcompound == null) {
  22.         Assembly.logger.warn("AssemblyCounter should read from null NBT ?!");
  23.         return;
  24.     }
  25.     super.readFromNBT(nbttagcompound);
  26.     NBTTagCompound nbt = nbttagcompound.getCompoundTag("counterdata");
  27.     doublecount = nbt.getBoolean("doublecount");
  28.  
  29.     int countedsize = nbt.getInteger("countedsize");
  30.     int countersize = nbt.getInteger("countersize");
  31.  
  32.     for (int i = 0; i < countedsize; i++) {
  33.         counted.add(Integer.valueOf(nbt.getInteger("counted" + i)));
  34.     }
  35.     for (int i = 0; i < countersize; i++) {
  36.         int id = nbt.getInteger("counter" + i + "_id");
  37.         int damage = nbt.getInteger("counter" + i + "_damage");
  38.         int count = nbt.getInteger("counter" + i + "_count");
  39.         counter.put(new int[] { id, damage }, Integer.valueOf(count));
  40.     }
  41. }
  42.  
  43. public void writeToNBT(NBTTagCompound nbttagcompound) {
  44.     super.writeToNBT(nbttagcompound);
  45.     NBTTagCompound nbt = new NBTTagCompound();
  46.  
  47.     nbt.setInteger("countedsize", counted.size());
  48.     nbt.setInteger("countersize", counter.size());
  49.     nbt.setBoolean("doublecount", doublecount);
  50.     for (int i = 0; i < counted.size(); i++) {
  51.         nbt.setInteger("counted" + i, ((Integer) counted.get(i)).intValue());
  52.     }
  53.     Iterator it = counter.entrySet().iterator();
  54.     int i = 0;
  55.     while (it.hasNext()) {
  56.         Entry<int[], Integer> entry = (Entry) it.next();
  57.         nbt.setInteger("counter" + i + "_id", ((int[]) entry.getKey())[0]);
  58.         nbt.setInteger("counter" + i + "_damage", ((int[]) entry.getKey())[1]);
  59.         nbt.setInteger("counter" + i + "_count", ((Integer) entry.getValue()).intValue());
  60.         i++;
  61.     }
  62.     nbttagcompound.setTag("counterdata", nbt);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement