public void tickEnd(EntityPlayer player) {
    ItemStack offhand = ((InventoryPlayerBattle) player.inventory).getCurrentOffhandWeapon();
    Battlegear.proxy.tryUseDynamicLight(player, offhand);
    // If we use a shield
    if (offhand != null && offhand.getItem() instanceof IShield) {
      if (mc.gameSettings.keyBindUseItem.isKeyDown() && !player.isSwingInProgress && blockBar > 0) {
        player.motionX = player.motionX / 5;
        player.motionZ = player.motionZ / 5;
      }
    }

    // If we JUST swung an Item
    if (player.swingProgressInt == 1 && !player.isSpectator()) {
      double extendedReach = BattlemodeHookContainerClass.INSTANCE.maxReachDistance(player);
      if (extendedReach
          > BattlemodeHookContainerClass.defaultReachDistance(player.capabilities.isCreativeMode)) {
        MovingObjectPosition mouseOver = Battlegear.proxy.getMouseOver(partialTick, extendedReach);
        if (mouseOver != null
            && mouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY) {
          Entity target = mouseOver.entityHit;
          if (target instanceof EntityLivingBase
              && target != player
              && player.getDistanceToEntity(target) > mc.playerController.getBlockReachDistance()) {
            if (target.hurtResistantTime != ((EntityLivingBase) target).maxHurtResistantTime) {
              player.attackTargetEntityWithCurrentItem(target);
              // send packet
              Battlegear.packetHandler.sendPacketToServer(
                  new ReachTargetPacket(target).generatePacket());
            }
          }
        }
      }
    }
  }
Пример #2
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
  public ItemStack onFocusRightClick(
      ItemStack itemstack, World world, EntityPlayer p, MovingObjectPosition movingobjectposition) {
    ItemWandCasting wand = (ItemWandCasting) itemstack.getItem();
    if (!ConfigHandler.enableFlight) {
      return itemstack;
    }
    if (wand.consumeAllVis(itemstack, p, getVisCost(), true, false)) {
      Vec3 vec = p.getLookVec();
      double force =
          1
              / 1.5
              * (1
                  + EnchantmentHelper.getEnchantmentLevel(
                          Config.enchPotency.effectId, wand.getFocusItem(itemstack))
                      * 0.2);
      p.motionX = vec.xCoord * force;
      p.motionY = vec.yCoord * force;
      p.motionZ = vec.zCoord * force;
      p.fallDistance = 0F;
      if (p instanceof EntityPlayerMP) {
        ((EntityPlayerMP) p).playerNetServerHandler.floatingTickCount = 0;
      }
      for (int i = 0; i < 5; i++)
        ThaumicTinkerer.tcProxy.smokeSpiral(
            world,
            p.posX,
            p.posY - p.motionY,
            p.posZ,
            2F,
            (int) (Math.random() * 360),
            (int) p.posY);
      world.playSoundAtEntity(p, "thaumcraft:wind", 0.4F, 1F);
    }

    if (world.isRemote) p.swingItem();

    return itemstack;
  }
Пример #4
0
  @Override
  public void control(EntityPlayerCustom playerCustom, EntityPlayer player, Side side) {
    int x = MathHelper.floor_double(player.posX);
    int y = MathHelper.floor_double(player.posY);
    int z = MathHelper.floor_double(player.posZ);
    int heading = MathHelper.floor_double((double) (player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
    if (!playerCustom.isSneaking) {
      if (((((Util.isCube(player.worldObj.getBlock(x, y, z - 1)) && heading == 2)
                  || (Util.isCube(player.worldObj.getBlock(x, y, z + 1)) && heading == 0)
                  || (Util.isCube(player.worldObj.getBlock(x - 1, y, z)) && heading == 1)
                  || (Util.isCube(player.worldObj.getBlock(x + 1, y, z)) && heading == 3))
              && ((!Util.isCube(player.worldObj.getBlock(x, y + 1, z - 1)) && heading == 2)
                  || (!Util.isCube(player.worldObj.getBlock(x, y + 1, z + 1)) && heading == 0)
                  || (!Util.isCube(player.worldObj.getBlock(x - 1, y + 1, z)) && heading == 1)
                  || (!Util.isCube(player.worldObj.getBlock(x + 1, y + 1, z)) && heading == 3))
              && (!Util.isCube(player.worldObj.getBlock(x, y - 2, z)))))
          && player.worldObj.getBlock(x, y, z) != Blocks.ladder
          && player.getCurrentEquippedItem() == null) {
        playerCustom.isGrabbing = true;
        playerCustom.rotationYaw = player.rotationYaw;
        playerCustom.rotationPitch = player.rotationPitch;
        playerCustom.prevRotationPitch = player.prevRotationPitch;
        playerCustom.prevRotationYaw = player.prevRotationYaw;
        playerCustom.grabbingDirections[heading] = true;
        if (heading == 0) {
          playerCustom.grabbingDirections[3] = true;
        } else {
          playerCustom.grabbingDirections[heading - 1] = true;
        }

        if (heading == 3) {
          playerCustom.grabbingDirections[0] = true;
        } else {
          playerCustom.grabbingDirections[heading + 1] = true;
        }
      } else {
        playerCustom.isGrabbing = false;
        playerCustom.rotationYaw = 0;
        if (!playerCustom.isRolling) {
          playerCustom.rotationPitch = 0;
        }
        playerCustom.prevRotationPitch = 0;
        playerCustom.prevRotationYaw = 0;
        playerCustom.grabbingDirections[0] = false;
        playerCustom.grabbingDirections[1] = false;
        playerCustom.grabbingDirections[2] = false;
        playerCustom.grabbingDirections[3] = false;
      }
      if (playerCustom.isGrabbing && !playerCustom.wasSneaking && player.isSneaking()) {
        playerCustom.wasSneaking = true;
      }
      if (!playerCustom.isGrabbing) {
        playerCustom.wasSneaking = false;
      }
      if (playerCustom.wasSneaking) {
        return;
      }
      if (!player.isSneaking()
          && !(Boolean)
              ObfuscationReflectionHelper.getPrivateValue(
                  EntityLivingBase.class, (EntityLivingBase) player, 41)
          && playerCustom.isGrabbing) {
        if (heading == 1 || heading == 3) {
          player.setPosition(x + 0.5F, y + 0.9F, player.posZ);
          player.motionX = 0;
        }
        if (heading == 2 || heading == 0) {
          player.setPosition(player.posX, y + 0.9F, z + 0.5F);
          player.motionZ = 0;
        }
        player.motionY = 0.0;
        if (player.isSprinting()) {
          player.setSprinting(false);
        }
      } else if ((Boolean)
              ObfuscationReflectionHelper.getPrivateValue(
                  EntityLivingBase.class, (EntityLivingBase) player, 41)
          && playerCustom.isGrabbing) {
        player.motionY = 0.55D;
      }
    }

    //		if(side == Side.CLIENT){
    ////			Util.channel.sendToServer(new CPacketPlayerAction(playerCustom.isGrabbing ? 0 : 1));
    //		}
    //
    //		if(side == Side.SERVER){
    //			System.out.println("1 : " + playerCustom.isGrabbing);
    //		}
    /*    CLIENT    */
    if (!player.worldObj.isRemote) {
      if (playerCustom.isGrabbing && !player.capabilities.isCreativeMode) {
        PotionEffect potioneffect = player.getActivePotionEffect(Potion.jump);
        float f1 = potioneffect != null ? (float) (potioneffect.getAmplifier() + 1) : 0.0F;
        int i = MathHelper.ceiling_float_int(player.fallDistance - 3.0F - f1);
        if (i > 0) {
          player.playSound(
              i > 4 ? "game.neutral.hurt.fall.big" : "game.neutral.hurt.fall.small", 1.0F, 1.0F);
          damageEntity(EntityLivingBase.class, player, DamageSource.fall, (float) i);
        }
        player.fallDistance = 0;
      }
    }
  }
Пример #5
0
  @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);
  }
Пример #6
0
  @SubscribeEvent
  public void sleepInBed(PlayerSleepInBedEvent event) {
    SettingEntry se = null;
    if (event.entityPlayer.worldObj.isRemote) {
      se = PerfectSpawnClientHandler.currentServerSettings;
    } else {
      se = PerfectSpawn.settings.getValidSettingEntry();
    }

    if (se != null && se.forceBed) {
      WorldProvider provider = event.entityPlayer.worldObj.provider;
      EntityPlayer player = event.entityPlayer;
      World worldObj = player.worldObj;

      if (provider.dimensionId == se.spawnDimension) {
        event.result = EntityPlayer.EnumStatus.OK;
        if (player.isPlayerSleeping() || !player.isEntityAlive()) {
          event.result = EntityPlayer.EnumStatus.OTHER_PROBLEM;
        }

        if (!player.worldObj.isDaytime() && provider.isSurfaceWorld()) {
          event.result = EntityPlayer.EnumStatus.NOT_POSSIBLE_NOW;
        }

        if (Math.abs(player.posX - (double) event.x) > 3.0D
            || Math.abs(player.posY - (double) event.y) > 2.0D
            || Math.abs(player.posZ - (double) event.z) > 3.0D) {
          event.result = EntityPlayer.EnumStatus.TOO_FAR_AWAY;
        }

        double d0 = 8.0D;
        double d1 = 5.0D;
        List list =
            player.worldObj.getEntitiesWithinAABB(
                EntityMob.class,
                AxisAlignedBB.getBoundingBox(
                    (double) event.x - d0,
                    (double) event.y - d1,
                    (double) event.z - d0,
                    (double) event.x + d0,
                    (double) event.y + d1,
                    (double) event.z + d0));

        if (!list.isEmpty()) {
          event.result = EntityPlayer.EnumStatus.NOT_SAFE;
        }
      }

      if (player.isRiding()) {
        player.mountEntity((Entity) null);
      }

      this.setSize(player, 0.2F, 0.2F);
      player.yOffset = 0.2F;

      if (player.worldObj.blockExists(event.x, event.y, event.z)) {
        int l =
            worldObj
                .getBlock(event.x, event.y, event.z)
                .getBedDirection(worldObj, event.x, event.y, event.z);
        float f1 = 0.5F;
        float f = 0.5F;

        switch (l) {
          case 0:
            f = 0.9F;
            break;
          case 1:
            f1 = 0.1F;
            break;
          case 2:
            f = 0.1F;
            break;
          case 3:
            f1 = 0.9F;
        }

        this.func_71013_b(player, l);
        player.setPosition(
            (double) ((float) event.x + f1),
            (double) ((float) event.y + 0.9375F),
            (double) ((float) event.z + f));
      } else {
        player.setPosition(
            (double) ((float) event.x + 0.5F),
            (double) ((float) event.y + 0.9375F),
            (double) ((float) event.z + 0.5F));
      }

      try {
        sleepTimer.set(player, 0);
        sleeping.set(player, true);
      } catch (Exception e) {
        PerfectSpawn.instance.logger.log(Level.ERROR, "Couldn't reflect on player bed data");
        e.printStackTrace();
      }

      player.playerLocation = new ChunkCoordinates(event.x, event.y, event.z);
      player.motionX = player.motionZ = player.motionY = 0.0D;

      if (!player.worldObj.isRemote) {
        player.worldObj.updateAllPlayersSleepingFlag();
      }
    }
  }
Пример #7
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;
    }
  }