Beispiel #1
0
  @Override
  public void tick() {
    if (getParent() instanceof EntityPlayer) {
      if (Morph.config.getSessionInt("allowFlight") == 0) {
        return;
      }
      EntityPlayer player = (EntityPlayer) getParent();
      if (!player.capabilities.allowFlying) {
        player.capabilities.allowFlying = true;
        player.sendPlayerAbilities();
      }
      if (player.capabilities.isFlying && !player.capabilities.isCreativeMode) {
        double motionX =
            player.worldObj.isRemote ? player.motionX : player.posX - player.lastTickPosX;
        double motionZ =
            player.worldObj.isRemote ? player.motionZ : player.posZ - player.lastTickPosZ;
        int i = Math.round(MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ) * 100.0F);

        if (i > 0 && i < 10) {
          if (player.isInWater() && slowdownInWater) {
            player.addExhaustion(0.125F * (float) i * 0.01F);
          } else {
            player.addExhaustion(0.035F * (float) i * 0.01F);
          }
        } else {
          player.addExhaustion(0.002F);
        }

        if (player.worldObj.isRemote && player.isInWater() && slowdownInWater) {
          MorphInfo info =
              Morph.proxy.tickHandlerClient.playerMorphInfo.get(player.getCommandSenderName());

          if (info != null) {
            boolean swim = false;
            for (Ability ability : info.morphAbilities) {
              if (ability.getType().equalsIgnoreCase("swim")) {
                swim = true;
                break;
              }
            }
            if (!swim) {
              player.motionX *= 0.65D;
              player.motionZ *= 0.65D;

              player.motionY *= 0.2D;
            }
          }
        }
      }
    }
    getParent().fallDistance = 0.0F;
    // TODO make "Thing" take note of this so it can fly...
  }
  @Override
  @SuppressWarnings("rawtypes")
  public void onArmorTick(World world, EntityPlayer player, ItemStack stack) {
    coolDown--;
    if (coolDown == 0) {
      if (stack.getItemDamage() > 0) stack.setItemDamage(stack.getItemDamage() - 1);
      else if (stack.getItemDamage() < 0) stack.setItemDamage(0);
      coolDown = MAX_COOL_DOWN;
    }

    boolean isWaterproof = false;
    Map enchs = EnchantmentHelper.getEnchantments(stack);
    if (!enchs.isEmpty() && enchs.get(GanysEndManager.getImperviousnessID()) != null)
      isWaterproof = true;

    if (!isWaterproof)
      if (player.isInWater()) stack.damageItem(1, player);
      else if (player.handleLavaMovement() || player.isBurning())
        if (stack.getItemDamage() > 0) stack.setItemDamage(stack.getItemDamage() - 2);

    if (stack.getItemDamage() < 0) stack.setItemDamage(0);
    else if (stack.getItemDamage() >= this.getMaxDamage())
      for (int i = 0; i < player.inventory.armorInventory.length; i++)
        if (player.inventory.armorInventory[i] != null)
          if (player.inventory.armorInventory[i].getItemDamage() >= this.getMaxDamage()) {
            player.inventory.armorInventory[i] = null;
            player.renderBrokenItemStack(stack);
          }
  }
 private boolean checkPlayerWater(EntityPlayer thePlayer) {
   if (thePlayer.isInWater()) {
     int x = MathHelper.floor_double(thePlayer.posX + 0.5D);
     int y = MathHelper.floor_double(thePlayer.posY + thePlayer.getEyeHeight());
     int z = MathHelper.floor_double(thePlayer.posZ + 0.5D);
     return thePlayer.worldObj.getBlock(x, y, z).getMaterial() == Material.water;
   }
   return false;
 }
  @Override
  public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {

    if (!entityplayer.isInWater()) return itemstack;
    else {
      if (entityplayer.capabilities.isCreativeMode) {
        //	entityplayer.setItemInUse(itemstack, this.getMaxItemUseDuration(itemstack));
      }

      return itemstack;
    }
  }
  @SubscribeEvent
  public void livingUpdate(LivingUpdateEvent event) {
    if (event.entityLiving instanceof EntityPlayer) {
      EntityPlayer player = (EntityPlayer) event.entityLiving;
      ItemStack is = player.inventory.armorItemInSlot(3);

      if ((is != null) && (is.getItem() == InitItems.itemBrassGoggles))
        player.addPotionEffect(new PotionEffect(Potion.nightVision.id, 2, 0, true));
      if ((is != null) && (is.getItem() == InitItems.itemDivingHelmet) && player.isInWater())
        player.addPotionEffect(new PotionEffect(Potion.nightVision.id, 2, 0, true));

      // TODO Change tis!!
      ItemStack stack = player.inventory.armorItemInSlot(0);
      if (stack == null) player.stepHeight = 0.5F;
    }
  }
 @Override
 public boolean continueExecuting() {
   if (entity.worldObj != null) {
     if (targetEntity != null
         && targetEntity.getHeldItem(EnumHand.MAIN_HAND) != null) { // TODO Allow Left hand
       if (entity.isValidForPickup(targetEntity.getHeldItem(EnumHand.MAIN_HAND).getItem())
           && entity.isAnySpaceForItemPickup(targetEntity.getHeldItem(EnumHand.MAIN_HAND))
           && !targetEntity.isInWater()
           && !(entity.getDistanceToEntity(targetEntity) > 8)) return true;
     }
   }
   if (entity.worldObj != null && targetEntity != null) {
     switch (randInt) {
       case 0:
         pathFinder.tryMoveToXYZ(
             targetEntity.posX + (rand.nextInt(12) + 8),
             targetEntity.posY,
             targetEntity.posZ + (rand.nextInt(12) + 8),
             this.speed);
         break;
       case 1:
         pathFinder.tryMoveToXYZ(
             targetEntity.posX - (rand.nextInt(12) + 8),
             targetEntity.posY,
             targetEntity.posZ + (rand.nextInt(12) + 8),
             this.speed);
         break;
       case 2:
         pathFinder.tryMoveToXYZ(
             targetEntity.posX + (rand.nextInt(12) + 8),
             targetEntity.posY,
             targetEntity.posZ - (rand.nextInt(12) + 8),
             this.speed);
         break;
       case 3:
         pathFinder.tryMoveToXYZ(
             targetEntity.posX - (rand.nextInt(12) + 8),
             targetEntity.posY,
             targetEntity.posZ - (rand.nextInt(12) + 8),
             this.speed);
         break;
     }
   }
   targetEntity = null;
   return false;
 }
 @Override
 public boolean shouldExecute() {
   if (!pathFinder.noPath()) {
     return false;
   }
   if (entity.worldObj != null) {
     EntityPlayer player = entity.worldObj.getClosestPlayerToEntity(entity, 8);
     if (player != null
         && player.getHeldItem(EnumHand.MAIN_HAND) != null) { // TODO Allow Left hand
       if (entity.getEntitySenses().canSee(player)
           && entity.isValidForPickup(player.getHeldItem(EnumHand.MAIN_HAND).getItem())
           && entity.isAnySpaceForItemPickup(player.getHeldItem(EnumHand.MAIN_HAND))
           && !player.isInWater()) {
         targetEntity = player;
         randInt = rand.nextInt(4);
         return true;
       }
     }
   }
   return false;
 }
 @Override
 public void onPlayerTickActive(EntityPlayer player, ItemStack item) {
   if (player.isInWater() && !(player.isRiding())) {
     PlayerInputMap movementInput = PlayerInputMap.getInputMapFor(player.username);
     boolean jumpkey = movementInput.jumpKey;
     boolean sneakkey = movementInput.sneakKey;
     float forwardkey = movementInput.forwardKey;
     float strafekey = movementInput.strafeKey;
     if (forwardkey != 0 || strafekey != 0 || jumpkey || sneakkey) {
       double moveRatio = 0;
       if (forwardkey != 0) {
         moveRatio += forwardkey * forwardkey;
       }
       if (strafekey != 0) {
         moveRatio += strafekey * strafekey;
       }
       if (jumpkey || sneakkey) {
         moveRatio += 0.2 * 0.2;
       }
       double swimAssistRate =
           ModuleManager.computeModularProperty(item, SWIM_BOOST_AMOUNT) * 0.05;
       double swimEnergyConsumption =
           ModuleManager.computeModularProperty(item, SWIM_BOOST_ENERGY_CONSUMPTION);
       if (swimEnergyConsumption < ElectricItemUtils.getPlayerEnergy(player)) {
         Musique.playerSound(player, SoundLoader.SOUND_SWIMASSIST, 1.0f, 1.0f, true);
         MusePlayerUtils.thrust(player, swimAssistRate, true);
       } else {
         Musique.stopPlayerSound(player, SoundLoader.SOUND_SWIMASSIST);
       }
     } else {
       Musique.stopPlayerSound(player, SoundLoader.SOUND_SWIMASSIST);
     }
   } else {
     Musique.stopPlayerSound(player, SoundLoader.SOUND_SWIMASSIST);
   }
 }
  @SubscribeEvent
  public void onAttackEntity(AttackEntityEvent event) {
    if (event.entityLiving.worldObj.isRemote) return;

    EntityLivingBase attacker = event.entityLiving;
    EntityPlayer player = event.entityPlayer;
    Entity target = event.target;
    ItemStack stack = attacker.getEquipmentInSlot(0);
    if (stack != null && stack.getItem().onLeftClickEntity(stack, player, target)) return;

    if (target.canAttackWithItem()) {
      if (!target.hitByEntity(target)) {
        float damageAmount = TFC_MobData.STEVE_DAMAGE;
        if (stack != null) {
          damageAmount =
              (float)
                  player
                      .getEntityAttribute(SharedMonsterAttributes.attackDamage)
                      .getAttributeValue();
          // player.addChatMessage("Damage: " + i);
          if (damageAmount == 1.0f) {
            damageAmount = TFC_MobData.STEVE_DAMAGE;
            // i = player.inventory.getCurrentItem().getItem().getDamageVsEntity(target,
            // player.inventory.getCurrentItem());
          }
        }

        if (player.isPotionActive(Potion.damageBoost))
          damageAmount += 3 << player.getActivePotionEffect(Potion.damageBoost).getAmplifier();

        if (player.isPotionActive(Potion.weakness))
          damageAmount -= 2 << player.getActivePotionEffect(Potion.weakness).getAmplifier();

        int knockback = 0;
        float enchantmentDamage = 0;

        if (target instanceof EntityLiving) {
          enchantmentDamage =
              EnchantmentHelper.getEnchantmentModifierLiving(player, (EntityLiving) target);
          knockback += EnchantmentHelper.getKnockbackModifier(player, (EntityLiving) target);
        }

        if (player.isSprinting()) ++knockback;

        if (damageAmount > 0 || enchantmentDamage > 0) {
          boolean criticalHit =
              player.fallDistance > 0.0F
                  && !player.onGround
                  && !player.isOnLadder()
                  && !player.isInWater()
                  && !player.isPotionActive(Potion.blindness)
                  && player.ridingEntity == null
                  && target instanceof EntityLiving;

          if (criticalHit && damageAmount > 0)
            damageAmount += event.entity.worldObj.rand.nextInt((int) (damageAmount / 2 + 2));

          damageAmount += enchantmentDamage;
          boolean onFire = false;
          int fireAspect = EnchantmentHelper.getFireAspectModifier(player);

          if (target instanceof EntityLiving && fireAspect > 0 && !target.isBurning()) {
            onFire = true;
            target.setFire(1);
          }

          boolean entityAttacked =
              target.attackEntityFrom(DamageSource.causePlayerDamage(player), damageAmount);

          if (entityAttacked) {
            if (knockback > 0) {
              target.addVelocity(
                  -MathHelper.sin(player.rotationYaw * (float) Math.PI / 180.0F) * knockback * 0.5F,
                  0.1D,
                  MathHelper.cos(player.rotationYaw * (float) Math.PI / 180.0F) * knockback * 0.5F);
              player.motionX *= 0.6D;
              player.motionZ *= 0.6D;
              player.setSprinting(false);
            }

            if (criticalHit) player.onCriticalHit(target);

            if (enchantmentDamage > 0) player.onEnchantmentCritical(target);

            if (damageAmount >= 18) player.triggerAchievement(AchievementList.overkill);

            player.setLastAttacker(target);

            if (target instanceof EntityLiving)
              target.attackEntityFrom(DamageSource.causeThornsDamage(attacker), damageAmount);
          }

          ItemStack itemstack = player.getCurrentEquippedItem();
          Object object = target;

          if (target instanceof EntityDragonPart) {
            IEntityMultiPart ientitymultipart = ((EntityDragonPart) target).entityDragonObj;
            if (ientitymultipart instanceof EntityLiving) object = ientitymultipart;
          }

          if (itemstack != null && object instanceof EntityLiving) {
            itemstack.hitEntity((EntityLiving) object, player);
            if (itemstack.stackSize <= 0) player.destroyCurrentEquippedItem();
          }

          if (target instanceof EntityLivingBase) {
            player.addStat(StatList.damageDealtStat, Math.round(damageAmount * 10.0f));
            if (fireAspect > 0 && entityAttacked) target.setFire(fireAspect * 4);
            else if (onFire) target.extinguish();
          }

          player.addExhaustion(0.3F);
        }
      }
    }
    event.setCanceled(true);
  }
Beispiel #10
0
  @Override
  public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) {
    if (entity.canAttackWithItem()) {
      if (!entity.hitByEntity(player)) {
        float damage = (float) getAttackDamage(stack);
        int i = 0;
        float extraDamage = 0.0F;
        if (entity instanceof EntityLivingBase) {
          extraDamage =
              EnchantmentHelper.getEnchantmentModifierLiving(player, (EntityLivingBase) entity);
          i += EnchantmentHelper.getKnockbackModifier(player, (EntityLivingBase) entity);
        }
        if (player.isSprinting()) {
          i++;
        }
        if (damage > 0.0F || extraDamage > 0.0F) {
          boolean criricalHit =
              player.fallDistance > 0.0F
                  && !player.onGround
                  && !player.isOnLadder()
                  && !player.isInWater()
                  && !player.isPotionActive(Potion.blindness)
                  && player.ridingEntity == null
                  && entity instanceof EntityLivingBase;
          if (criricalHit && damage > 0.0F) {
            damage *= 1.5F;
          }
          damage += extraDamage;
          boolean fire = false;
          int j = EnchantmentHelper.getFireAspectModifier(player);
          if (entity instanceof EntityLivingBase && j > 0 && !entity.isBurning()) {
            fire = true;
            entity.setFire(1);
          }
          boolean attack = entity.attackEntityFrom(DamageSource.causePlayerDamage(player), damage);
          if (attack) {
            if (i > 0) {
              entity.addVelocity(
                  (double)
                      (-MathHelper.sin(player.rotationYaw * (float) Math.PI / 180.0F)
                          * (float) i
                          * 0.5F),
                  0.1D,
                  (double)
                      (MathHelper.cos(player.rotationYaw * (float) Math.PI / 180.0F)
                          * (float) i
                          * 0.5F));
              player.motionX *= 0.6D;
              player.motionZ *= 0.6D;
              player.setSprinting(false);
            }
            if (criricalHit) {
              player.onCriticalHit(entity);
            }
            if (extraDamage > 0.0F) {
              player.onEnchantmentCritical(entity);
            }
            if (damage >= 18.0F) {
              player.triggerAchievement(AchievementList.overkill);
            }
            player.setLastAttacker(entity);
            if (entity instanceof EntityLivingBase) {
              EnchantmentHelper.func_151384_a((EntityLivingBase) entity, player);
            }
          }

          ItemStack itemstack = player.getCurrentEquippedItem();
          Object object = entity;

          if (entity instanceof EntityDragonPart) {
            IEntityMultiPart entityMultipart = ((EntityDragonPart) entity).entityDragonObj;
            if (entityMultipart != null && entityMultipart instanceof EntityLivingBase) {
              object = (EntityLivingBase) entityMultipart;
            }
          }
          if (itemstack != null && object instanceof EntityLivingBase) {
            itemstack.hitEntity((EntityLivingBase) object, player);
            if (itemstack.stackSize <= 0) {
              player.destroyCurrentEquippedItem();
            }
          }
          if (entity instanceof EntityLivingBase) {
            player.addStat(StatList.damageDealtStat, Math.round(damage * 10.0F));
            if (j > 0 && attack) {
              entity.setFire(j * 4);
            } else if (fire) {
              entity.extinguish();
            }
          }
          player.addExhaustion(0.3F);
        }
      }
    }
    return true;
  }
  /**
   * Called to tick armor in the armor slot. Override to do something
   *
   * @param world
   * @param player
   * @param itemStack
   */
  @Override
  public void onArmorTickUpdate(World world, EntityPlayer player, ItemStack itemStack) {
    ItemStack item3 = player.inventory.armorInventory[3];
    ItemStack item0 = player.inventory.armorInventory[0];

    // snorkel stuff
    if (item3 != null && item3.itemID == TropicraftItems.snorkel.itemID) {
      outOfWater = !player.isInsideOfMaterial(Material.water) || !player.isInWater();

      if (outOfWaterLast && outOfWater) {
        player.setAir(300);
      }

      if (outOfWaterLast && !outOfWater) {
        player.setAir(1200);
        outOfWaterLast = false;
      }

      if (outOfWater) {
        outOfWaterLast = true;
      }
    } else if (player.getAir() > 300
        && (item3 == null || item3.itemID != TropicraftItems.snorkel.itemID)) {
      player.setAir(300);
    } else {
      outOfWater = true;
      outOfWaterLast = true;
    }

    // flippers stuff
    if (item0 != null && item0.itemID == TropicraftItems.flippers.itemID) {
      if (player.isInsideOfMaterial(Material.water)) {
        player.capabilities.isFlying = true;
        player.setAIMoveSpeed(player.capabilities.getWalkSpeed());
        if (item0.isItemEnchanted()) {
          player.moveFlying(1E-4F, 1E-4F, 0.00000000001f);
          player.motionX /= 1.06999999;
          player.motionZ /= 1.06999999;
          player.moveEntityWithHeading(-1E-4F, -1E-4F);
        } else {
          player.moveFlying(1E-4F, 1E-4F, 0.00000000001f);
          player.motionX /= 1.26999999;
          player.motionZ /= 1.26999999;
          player.moveEntityWithHeading(-1E-4F, -1E-4F);
        }

        int l =
            EnchantmentHelper.getEnchantmentLevel(EnchantmentManager.scubaSteve.effectId, item3);

        if (l > 0) player.moveEntityWithHeading(-1F, -1F);
        else player.moveEntityWithHeading(-1E-4F, -1E-4F);
      } else {
        player.setAIMoveSpeed((float) (player.getAIMoveSpeed() / 1.33333));
        player.capabilities.isFlying = false;
      }

      hasFlippers = true;
    }

    if ((item0 == null || item0.itemID != TropicraftItems.flippers.itemID) && hasFlippers) {
      if (!player.capabilities.isCreativeMode && player.capabilities.isFlying) {
        player.capabilities.isFlying = false;
      }

      hasFlippers = false;
    }
  }