コード例 #1
0
ファイル: FakeFurnace.java プロジェクト: rippin/LibsMcpvp
  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);
  }
コード例 #2
0
ファイル: NPCEntity.java プロジェクト: mgone2010/NoHack
  @Override
  public void h() {
    super.h();
    this.C();

    npc.onTick();
    if (world
            .getType(MathHelper.floor(locX), MathHelper.floor(locY), MathHelper.floor(locZ))
            .getMaterial()
        == Material.FIRE) {
      setOnFire(15);
    }

    // Apply velocity etc.
    this.motY = onGround ? Math.max(0.0, motY) : motY;
    move(motX, motY, motZ);
    this.motX *= 0.800000011920929;
    this.motY *= 0.800000011920929;
    this.motZ *= 0.800000011920929;
    if (gravity && !this.onGround) {
      this.motY -= 0.1; // Most random value, don't judge.
    }
  }
コード例 #3
0
ファイル: NPCEntity.java プロジェクト: mgone2010/NoHack
  @Override
  public boolean damageEntity(DamageSource source, float damage) {
    if (invulnerable || noDamageTicks > 0) {
      return false;
    }

    DamageCause cause = null;
    org.bukkit.entity.Entity bEntity = null;
    if (source instanceof EntityDamageSource) {
      Entity damager = source.getEntity();
      cause = DamageCause.ENTITY_ATTACK;
      if (source instanceof EntityDamageSourceIndirect) {
        damager = ((EntityDamageSourceIndirect) source).getProximateDamageSource();
        if (damager.getBukkitEntity() instanceof ThrownPotion) {
          cause = DamageCause.MAGIC;
        } else if (damager.getBukkitEntity() instanceof Projectile) {
          cause = DamageCause.PROJECTILE;
        }
      }

      bEntity = damager.getBukkitEntity();
    } else if (source == DamageSource.FIRE) cause = DamageCause.FIRE;
    else if (source == DamageSource.STARVE) cause = DamageCause.STARVATION;
    else if (source == DamageSource.WITHER) cause = DamageCause.WITHER;
    else if (source == DamageSource.STUCK) cause = DamageCause.SUFFOCATION;
    else if (source == DamageSource.DROWN) cause = DamageCause.DROWNING;
    else if (source == DamageSource.BURN) cause = DamageCause.FIRE_TICK;
    else if (source == CraftEventFactory.MELTING) cause = DamageCause.MELTING;
    else if (source == CraftEventFactory.POISON) cause = DamageCause.POISON;
    else if (source == DamageSource.MAGIC) {
      cause = DamageCause.MAGIC;
    } else if (source == DamageSource.OUT_OF_WORLD) {
      cause = DamageCause.VOID;
    }

    if (cause != null) {
      NPCDamageEvent event = new NPCDamageEvent(npc, bEntity, cause, (double) damage);
      Bukkit.getPluginManager().callEvent(event);
      if (!event.isCancelled()) {
        return super.damageEntity(source, (float) event.getDamage());
      } else {
        return false;
      }
    }

    if (super.damageEntity(source, damage)) {
      if (bEntity != null) {
        Entity e = ((CraftEntity) bEntity).getHandle();
        double d0 = e.locX - this.locX;

        double d1;
        for (d1 = e.locZ - this.locZ;
            d0 * d0 + d1 * d1 < 0.0001D;
            d1 = (Math.random() - Math.random()) * 0.01D) {
          d0 = (Math.random() - Math.random()) * 0.01D;
        }

        a(e, damage, d0, d1);
      }

      return true;
    } else {
      return false;
    }
  }
コード例 #4
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;
  }