Exemplo n.º 1
0
  @SubscribeEvent
  public void onLivingTick(LivingUpdateEvent evt) {
    if (!evt.entityLiving.worldObj.isRemote) {
      ParticleType jetpackState = null;
      ItemStack armor = evt.entityLiving.getEquipmentInSlot(3);
      Jetpack jetpack = null;
      if (armor != null && armor.getItem() instanceof ItemJetpack) {
        jetpack = ((ItemJetpack) armor.getItem()).getPack(armor);
        if (jetpack != null) {
          jetpackState =
              jetpack.getDisplayParticleType(
                  armor, (ItemJetpack) armor.getItem(), evt.entityLiving);
        }
      }

      if (jetpackState != lastJetpackState.get(evt.entityLiving.getEntityId())) {
        if (jetpackState == null) {
          lastJetpackState.remove(evt.entityLiving.getEntityId());
        } else {
          lastJetpackState.put(evt.entityLiving.getEntityId(), jetpackState);
        }
        PacketHandler.instance.sendToAllAround(
            new MessageJetpackSync(
                evt.entityLiving.getEntityId(), jetpackState != null ? jetpackState.ordinal() : -1),
            new TargetPoint(
                evt.entityLiving.dimension,
                evt.entityLiving.posX,
                evt.entityLiving.posY,
                evt.entityLiving.posZ,
                256));
      } else if (jetpack != null && evt.entityLiving.worldObj.getTotalWorldTime() % 160L == 0) {
        PacketHandler.instance.sendToAllAround(
            new MessageJetpackSync(
                evt.entityLiving.getEntityId(), jetpackState != null ? jetpackState.ordinal() : -1),
            new TargetPoint(
                evt.entityLiving.dimension,
                evt.entityLiving.posX,
                evt.entityLiving.posY,
                evt.entityLiving.posZ,
                256));
      }

      if (evt.entityLiving.worldObj.getTotalWorldTime() % 200L == 0) {
        Iterator<Integer> itr = lastJetpackState.keySet().iterator();
        while (itr.hasNext()) {
          int entityId = itr.next();
          if (evt.entityLiving.worldObj.getEntityByID(entityId) == null) {
            itr.remove();
          }
        }
      }
    }
  }
Exemplo n.º 2
0
 @SubscribeEvent
 public void mobUseJetpack(LivingUpdateEvent evt) {
   if (!evt.entityLiving.worldObj.isRemote && evt.entityLiving instanceof EntityMob) {
     ItemStack armor = evt.entityLiving.getEquipmentInSlot(3);
     if (armor != null && armor.getItem() instanceof ItemJetpack) {
       ItemJetpack jetpackItem = (ItemJetpack) armor.getItem();
       Jetpack jetpack = jetpackItem.getPack(armor);
       if (jetpack != null) {
         if (jetpack instanceof JetpackPotato || MathHelper.RANDOM.nextInt(3) == 0) {
           jetpack.setMobMode(armor);
           jetpack.flyUser(evt.entityLiving, armor, jetpackItem, false);
         }
       }
       if (evt.entityLiving.posY > evt.entityLiving.worldObj.getActualHeight() + 10) {
         evt.entityLiving.attackEntityFrom(DamageSource.generic, 80);
       }
     }
   }
 }