Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<Integer> counted = new ArrayList(); // entityId of counted items
- HashMap<int[], Integer> counter = new HashMap(); // int[]{ id, damage } => count
- public Packet getDescriptionPacket() {
- NBTTagCompound nbttagcompound = new NBTTagCompound();
- writeToNBT(nbttagcompound);
- return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbttagcompound);
- }
- public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
- if (packet.func_148857_g() == null) {
- Assembly.logger.warn("AssemblyCounter received description packet with NBT=null?! (" + packet + ")");
- return;
- }
- readFromNBT(packet.func_148857_g());
- }
- public void readFromNBT(NBTTagCompound nbttagcompound) {
- if (nbttagcompound == null) {
- Assembly.logger.warn("AssemblyCounter should read from null NBT ?!");
- return;
- }
- super.readFromNBT(nbttagcompound);
- NBTTagCompound nbt = nbttagcompound.getCompoundTag("counterdata");
- doublecount = nbt.getBoolean("doublecount");
- int countedsize = nbt.getInteger("countedsize");
- int countersize = nbt.getInteger("countersize");
- for (int i = 0; i < countedsize; i++) {
- counted.add(Integer.valueOf(nbt.getInteger("counted" + i)));
- }
- for (int i = 0; i < countersize; i++) {
- int id = nbt.getInteger("counter" + i + "_id");
- int damage = nbt.getInteger("counter" + i + "_damage");
- int count = nbt.getInteger("counter" + i + "_count");
- counter.put(new int[] { id, damage }, Integer.valueOf(count));
- }
- }
- public void writeToNBT(NBTTagCompound nbttagcompound) {
- super.writeToNBT(nbttagcompound);
- NBTTagCompound nbt = new NBTTagCompound();
- nbt.setInteger("countedsize", counted.size());
- nbt.setInteger("countersize", counter.size());
- nbt.setBoolean("doublecount", doublecount);
- for (int i = 0; i < counted.size(); i++) {
- nbt.setInteger("counted" + i, ((Integer) counted.get(i)).intValue());
- }
- Iterator it = counter.entrySet().iterator();
- int i = 0;
- while (it.hasNext()) {
- Entry<int[], Integer> entry = (Entry) it.next();
- nbt.setInteger("counter" + i + "_id", ((int[]) entry.getKey())[0]);
- nbt.setInteger("counter" + i + "_damage", ((int[]) entry.getKey())[1]);
- nbt.setInteger("counter" + i + "_count", ((Integer) entry.getValue()).intValue());
- i++;
- }
- nbttagcompound.setTag("counterdata", nbt);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement