@Override
  public void onUpdate(
      ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) {
    super.onUpdate(par1ItemStack, par2World, par3Entity, par4, par5);
    if (par3Entity instanceof EntityPlayer) {
      EntityPlayer player = (EntityPlayer) par3Entity;
      PotionEffect haste = player.getActivePotionEffect(Potion.digSpeed);
      float check = haste == null ? 0.16666667F : haste.getAmplifier() == 1 ? 0.5F : 0.4F;

      if (player.getCurrentEquippedItem() == par1ItemStack
          && player.swingProgress == check
          && !par2World.isRemote
          && par2World.rand.nextInt(2) == 0) {
        MovingObjectPosition pos = ToolCommons.raytraceFromEntity(par2World, par3Entity, true, 48);
        if (pos != null) {
          Vector3 posVec = new Vector3(pos.blockX, pos.blockY, pos.blockZ);
          Vector3 motVec = new Vector3((Math.random() - 0.5) * 18, 24, (Math.random() - 0.5) * 18);
          posVec.add(motVec);
          motVec.normalize().negate().multiply(1.5);

          EntityFallingStar star = new EntityFallingStar(par2World, player);
          star.setPosition(posVec.x, posVec.y, posVec.z);
          star.motionX = motVec.x;
          star.motionY = motVec.y;
          star.motionZ = motVec.z;
          par2World.spawnEntityInWorld(star);

          ToolCommons.damageItem(par1ItemStack, 1, player, MANA_PER_DAMAGE);
          par2World.playSoundAtEntity(player, "botania:starcaller", 0.4F, 1.4F);
        }
      }
    }
  }
  @Override
  protected void onImpact(@Nonnull RayTraceResult pos) {
    if (isReturning()) return;

    switch (pos.typeOfHit) {
      case BLOCK:
        {
          Block block = worldObj.getBlockState(pos.getBlockPos()).getBlock();
          if (block instanceof BlockBush || block instanceof BlockLeaves) return;

          int bounces = getTimesBounced();
          if (bounces < MAX_BOUNCES) {
            Vector3 currentMovementVec = new Vector3(motionX, motionY, motionZ);
            EnumFacing dir = pos.sideHit;
            Vector3 normalVector =
                new Vector3(dir.getFrontOffsetX(), dir.getFrontOffsetY(), dir.getFrontOffsetZ())
                    .normalize();
            Vector3 movementVec =
                normalVector
                    .multiply(-2 * currentMovementVec.dotProduct(normalVector))
                    .add(currentMovementVec);

            motionX = movementVec.x;
            motionY = movementVec.y;
            motionZ = movementVec.z;
            bounced = true;

            if (!worldObj.isRemote) setTimesBounced(getTimesBounced() + 1);
          }

          break;
        }
      case ENTITY:
        {
          if (!worldObj.isRemote
              && pos.entityHit != null
              && pos.entityHit instanceof EntityLivingBase
              && pos.entityHit != getThrower()) {
            EntityLivingBase thrower = getThrower();
            pos.entityHit.attackEntityFrom(
                thrower != null
                    ? thrower instanceof EntityPlayer
                        ? DamageSource.causeThrownDamage(this, thrower)
                        : DamageSource.causeMobDamage(thrower)
                    : DamageSource.generic,
                12);
            if (isFire()) pos.entityHit.setFire(5);
            else if (worldObj.rand.nextInt(3) == 0)
              ((EntityLivingBase) pos.entityHit)
                  .addPotionEffect(new PotionEffect(MobEffects.POISON, 60, 0));
          }

          break;
        }
    }
  }
  @Override
  public void onUpdate() {
    // Standard motion
    double mx = motionX;
    double my = motionY;
    double mz = motionZ;

    super.onUpdate();

    if (!bounced) {
      // Reset the drag applied by super
      motionX = mx;
      motionY = my;
      motionZ = mz;
    }

    bounced = false;

    // Returning motion
    if (isReturning()) {
      Entity thrower = worldObj.getEntityByID(getEntityToReturnTo());
      Vector3 motion =
          Vector3.fromEntityCenter(thrower).subtract(Vector3.fromEntityCenter(this)).normalize();
      motionX = motion.x;
      motionY = motion.y;
      motionZ = motion.z;
    }

    // Client FX
    if (worldObj.isRemote && isFire()) {
      double r = 0.1;
      double m = 0.1;
      for (int i = 0; i < 3; i++)
        worldObj.spawnParticle(
            EnumParticleTypes.FLAME,
            posX + r * (Math.random() - 0.5),
            posY + r * (Math.random() - 0.5),
            posZ + r * (Math.random() - 0.5),
            m * (Math.random() - 0.5),
            m * (Math.random() - 0.5),
            m * (Math.random() - 0.5));
    }

    // Server state control
    if (!worldObj.isRemote && (getTimesBounced() >= MAX_BOUNCES || ticksExisted > 60)) {
      EntityLivingBase thrower = getThrower();
      if (thrower == null) {
        dropAndKill();
      } else {
        setEntityToReturnTo(thrower.getEntityId());
        if (getDistanceSqToEntity(thrower) < 2) dropAndKill();
      }
    }
  }
Exemple #4
0
  @Override
  public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random) {
    int color = getRenderColor(par1World.getBlockMetadata(par2, par3, par4));
    int colorBright = new Color(color).brighter().getRGB();
    int colorDark = new Color(color).darker().getRGB();

    Vector3 origVector = new Vector3(par2 + 0.5, par3 + 0.5, par4 + 0.5);
    Vector3 endVector =
        origVector
            .copy()
            .add(
                par1World.rand.nextDouble() * 2 - 1,
                par1World.rand.nextDouble() * 2 - 1,
                par1World.rand.nextDouble() * 2 - 1);
    Botania.proxy.lightningFX(par1World, origVector, endVector, 5F, colorDark, colorBright);
  }
  @Override
  public boolean onItemUse(
      ItemStack par1ItemStack,
      EntityPlayer par2EntityPlayer,
      World par3World,
      int par4,
      int par5,
      int par6,
      int par7,
      float par8,
      float par9,
      float par10) {
    Block block = par3World.getBlock(par4, par5, par6);
    ChunkCoordinates boundSpreader = getBoundSpreader(par1ItemStack);

    if (boundSpreader.posY != -1
        && par2EntityPlayer.isSneaking()
        && (boundSpreader.posX != par4
            || boundSpreader.posY != par5
            || boundSpreader.posZ != par6)) {
      TileEntity tile =
          par3World.getTileEntity(boundSpreader.posX, boundSpreader.posY, boundSpreader.posZ);
      if (tile instanceof TileSpreader) {
        TileSpreader spreader = (TileSpreader) tile;

        Vector3 spreaderVec = Vector3.fromTileEntityCenter(spreader);
        Vector3 blockVec = new Vector3(par4 + 0.5, par5 + 0.5, par6 + 0.5);

        AxisAlignedBB axis =
            par3World
                .getBlock(par4, par5, par6)
                .getCollisionBoundingBoxFromPool(par3World, par4, par5, par6);
        if (axis == null)
          axis = AxisAlignedBB.getBoundingBox(par4, par5, par6, par4 + 1, par5 + 1, par6 + 1);

        if (!blockVec.isInside(axis))
          blockVec =
              new Vector3(
                  axis.minX + (axis.maxX - axis.minX) / 2,
                  axis.minY + (axis.maxY - axis.minY) / 2,
                  axis.minZ + (axis.maxZ - axis.minZ) / 2);

        Vector3 diffVec = blockVec.copy().sub(spreaderVec);
        Vector3 diffVec2D = new Vector3(diffVec.x, diffVec.z, 0);
        Vector3 rotVec = new Vector3(0, 1, 0);
        double angle = rotVec.angle(diffVec2D) / Math.PI * 180.0;

        if (blockVec.x < spreaderVec.x) angle = -angle;

        spreader.rotationX = (float) angle + 90;

        rotVec = new Vector3(diffVec.x, 0, diffVec.z);
        angle = diffVec.angle(rotVec) * 180F / Math.PI;
        if (blockVec.y < spreaderVec.y) angle = -angle;
        spreader.rotationY = (float) angle;

        spreader.checkForReceiver();
        par3World.markBlockForUpdate(boundSpreader.posX, boundSpreader.posY, boundSpreader.posZ);
        return true;
      } else setBoundSpreader(par1ItemStack, 0, -1, 0);
    } else if (par2EntityPlayer.isSneaking()) {
      block.rotateBlock(par3World, par4, par5, par6, ForgeDirection.getOrientation(par7));
      if (par3World.isRemote) par2EntityPlayer.swingItem();
    }

    if (block == Blocks.lapis_block && ConfigHandler.enchanterEnabled) {
      int meta = -1;
      if (TileEnchanter.canEnchanterExist(par3World, par4, par5, par6, 0)) meta = 0;
      else if (TileEnchanter.canEnchanterExist(par3World, par4, par5, par6, 1)) meta = 1;

      if (meta != -1 && !par3World.isRemote) {
        par3World.setBlock(par4, par5, par6, ModBlocks.enchanter, meta, 1 | 2);
        par3World.playSoundEffect(par4, par5, par6, "botania:enchanterBlock", 0.5F, 0.6F);
        for (int i = 0; i < 50; i++) {
          float red = (float) Math.random();
          float green = (float) Math.random();
          float blue = (float) Math.random();

          double x = (Math.random() - 0.5) * 6;
          double y = (Math.random() - 0.5) * 6;
          double z = (Math.random() - 0.5) * 6;

          float velMul = 0.07F;

          Botania.proxy.wispFX(
              par3World,
              par4 + 0.5 + x,
              par5 + 0.5 + y,
              par6 + 0.5 + z,
              red,
              green,
              blue,
              (float) Math.random() * 0.15F + 0.15F,
              (float) -x * velMul,
              (float) -y * velMul,
              (float) -z * velMul);
        }
      }
    } else if (block instanceof IWandable) {
      boolean spreader = par3World.getTileEntity(par4, par5, par6) instanceof TileSpreader;
      int ticks = getTicksSinceSpreaderUse(par1ItemStack);
      boolean wanded = false;
      if (spreader && ticks == 5 && par2EntityPlayer.isSneaking()) {
        if (boundSpreader.posX == par4 && boundSpreader.posY == par5 && boundSpreader.posZ == par6)
          setBoundSpreader(par1ItemStack, 0, -1, 0);
        else setBoundSpreader(par1ItemStack, par4, par5, par6);

        if (par3World.isRemote) par2EntityPlayer.swingItem();
        par3World.playSoundAtEntity(par2EntityPlayer, "botania:ding", 0.1F, 1F);

        setTicksSinceSpreaderUse(par1ItemStack, 0);
        wanded = true;
      } else {
        wanded =
            ((IWandable) block)
                .onUsedByWand(par2EntityPlayer, par1ItemStack, par3World, par4, par5, par6, par7);
        if (wanded) {
          if (par3World.isRemote) par2EntityPlayer.swingItem();

          if (spreader) setTicksSinceSpreaderUse(par1ItemStack, 0);
        }
      }

      return wanded;
    } else if (BlockPistonRelay.playerPositions.containsKey(
        par2EntityPlayer.getCommandSenderName())) {
      String bindPos =
          BlockPistonRelay.playerPositions.get(par2EntityPlayer.getCommandSenderName());
      String currentPos =
          BlockPistonRelay.getCoordsAsString(par3World.provider.dimensionId, par4, par5, par6);

      BlockPistonRelay.playerPositions.remove(par2EntityPlayer.getCommandSenderName());
      BlockPistonRelay.mappedPositions.put(bindPos, currentPos);
      BlockPistonRelay.WorldData.get(par3World).markDirty();

      if (par3World.isRemote) par2EntityPlayer.swingItem();
    }

    return false;
  }