Beispiel #1
0
  public void readFromItemNBT(NBTTagCompound nbt) {
    temperature = nbt.getInteger("temp");

    NBTTagList nbttaglist = nbt.getTagList("Metals");

    for (int i = 0; i < nbttaglist.tagCount(); i++) {
      NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i);
      int id = nbttagcompound1.getInteger("ID");
      float amount = nbttagcompound1.getShort("Amount");
      // Added so that hopefully old worlds that stored metal as shorts wont break
      float amountF = amount + nbttagcompound1.getFloat("AmountF");
      Metal m = MetalRegistry.instance.getMetalFromItem(Item.itemsList[id]);
      addMetal(MetalRegistry.instance.getMetalFromItem(Item.itemsList[id]), amount);
    }

    nbttaglist = nbt.getTagList("Items");
    storage = new ItemStack[getSizeInventory()];
    for (int i = 0; i < nbttaglist.tagCount(); i++) {
      NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i);
      byte byte0 = nbttagcompound1.getByte("Slot");
      if (byte0 >= 0 && byte0 < storage.length) {
        storage[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
      }
    }

    if (currentAlloy != null) {
      currentAlloy.outputAmount = nbt.getInteger("outputAmount");
    }
  }
Beispiel #2
0
 @Override
 public void handleDataPacket(DataInputStream inStream) throws IOException {
   byte id = inStream.readByte();
   if (id == 0 && inStream.available() > 0) {
     this.currentAlloy = new Alloy().fromPacket(inStream);
   } else if (id == 1) {
     currentAlloy.outputAmount = inStream.readInt();
   } else if (id == 2) {
     currentAlloy = null;
   }
 }
Beispiel #3
0
  private void updateCurrentAlloy() {
    List<AlloyMetal> a = new ArrayList<AlloyMetal>();

    Iterator iter = metals.values().iterator();
    int totalAmount = getTotalMetal();

    iter = metals.values().iterator();
    while (iter.hasNext()) {
      MetalPair m = (MetalPair) iter.next();
      if (m != null) {
        a.add(new AlloyMetal(m.type, (m.amount / totalAmount) * 100f));
      }
    }

    Metal match = AlloyManager.instance.matchesAlloy(a, Alloy.EnumTier.TierV);
    if (match != null) {
      currentAlloy = new Alloy(match, totalAmount);
      currentAlloy.AlloyIngred = a;
    } else {
      currentAlloy = new Alloy(Global.UNKNOWN, totalAmount);
      currentAlloy.AlloyIngred = a;
    }
  }
Beispiel #4
0
 public Packet createUpdatePacket(byte id) {
   ByteArrayOutputStream bos = new ByteArrayOutputStream(140);
   DataOutputStream dos = new DataOutputStream(bos);
   try {
     dos.writeByte(PacketHandler.Packet_Data_Block_Client);
     dos.writeInt(xCoord);
     dos.writeInt(yCoord);
     dos.writeInt(zCoord);
     if (id == 0 && currentAlloy != null) {
       dos.writeByte(0);
       currentAlloy.toPacket(dos);
     } else if (id == 1 && currentAlloy != null) {
       dos.writeByte(1);
       dos.writeInt(this.getTotalMetal());
     } else if (id == 2) {
       dos.writeByte(2);
     }
   } catch (IOException e) {
   }
   return this.setupCustomPacketData(bos.toByteArray(), bos.size());
 }