Exemplo n.º 1
0
  public void tick() {
    int newID = contents[0] == null ? 0 : Item.getId(contents[0].getItem());
    // Has the item been changed?
    if (newID != lastID) {
      // Then reset the progress!
      myCookTime = 0.0D;
      lastID = newID;
      // And, most important: change the melt speed
      meltSpeed = getMeltSpeed(contents[0]);
    }
    // So, can we now finally burn?
    if (canBurn() && !isBurning() && (getFuelTime(contents[1]) > 0)) {
      // I have no idea what "ticksForCurrentFuel" is good for, but it
      // works fine like this
      burnTime = ticksForCurrentFuel = getFuelTime(contents[1]);
      // Before we remove the item: how fast does it burn?
      burnSpeed = getBurnSpeed(contents[1]);
      // If it's a container item (lava bucket), we only consume its
      // contents (not like evil Notch!)

      // If it's not a container, consume it! Om nom nom nom!
      {
        contents[1].count--;
        // Let 0 be null
        if (contents[1].count <= 0) {
          contents[1] = null;
        }
      }
    }
    // Now, burning?
    if (isBurning()) {
      // Then move on
      burnTime--;
      // I'm using a double here because of the custom recipes.
      // The faster this fuel burns and the faster the recipe melts, the
      // faster we're done
      myCookTime += burnSpeed * meltSpeed;
      // Finished burning?
      if (myCookTime >= 200.0D) {
        myCookTime -= 200.0D;
        burn();
      }
    }
    // If it's not burning, we reset the burning progress!
    else {
      myCookTime = 0.0D;
    }
    // And for the display (I'm using floor rather than round to not cause
    // the client to do shit when we not really reached 200):
    cookTime = (int) Math.floor(myCookTime);
  }
Exemplo n.º 2
0
  // Accessing packets
  @SuppressWarnings("deprecation")
  public static PacketPlayOutSpawnEntityLiving getMobPacket(String text, Location loc) {
    PacketPlayOutSpawnEntityLiving mobPacket = new PacketPlayOutSpawnEntityLiving();

    try {
      Field a = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "a");
      a.setAccessible(true);
      a.set(mobPacket, (int) ENTITY_ID);

      Field b = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "b");
      b.setAccessible(true);
      b.set(mobPacket, (byte) EntityType.WITHER.getTypeId());

      Field c = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "c");
      c.setAccessible(true);
      c.set(mobPacket, (int) Math.floor(loc.getBlockX() * 32.0D));

      Field d = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "d");
      d.setAccessible(true);
      d.set(mobPacket, (int) Math.floor(loc.getBlockY() * 32.0D));

      Field e = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "e");
      e.setAccessible(true);
      e.set(mobPacket, (int) Math.floor(loc.getBlockZ() * 32.0D));

      Field f = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "f");
      f.setAccessible(true);
      f.set(mobPacket, (byte) 0);

      Field g = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "g");
      g.setAccessible(true);
      g.set(mobPacket, (byte) 0);

      Field h = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "h");
      h.setAccessible(true);
      h.set(mobPacket, (byte) 0);

      Field i = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "i");
      i.setAccessible(true);
      i.set(mobPacket, (byte) 0);

      Field j = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "j");
      j.setAccessible(true);
      j.set(mobPacket, (byte) 0);

      Field k = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "k");
      k.setAccessible(true);
      k.set(mobPacket, (byte) 0);

    } catch (IllegalArgumentException e1) {
      e1.printStackTrace();
    } catch (IllegalAccessException e1) {
      e1.printStackTrace();
    }

    DataWatcher watcher = getWatcher(text, 300);

    try {
      Field t = PacketPlayOutSpawnEntityLiving.class.getDeclaredField("l");
      t.setAccessible(true);
      t.set(mobPacket, watcher);
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    return mobPacket;
  }