Example #1
0
  @Override
  public void onUpdate() {
    super.onUpdate();

    if ((this.ticksExisted - 1) % 20 == 0
        && this.worldObj.isRemote
        && FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
      this.flagData =
          ClientUtil.updateFlagData(
              this.getOwner(),
              Minecraft.getMinecraft().thePlayer.getDistanceToEntity(this) < 50.0D);
    }

    Vector3 vec = new Vector3(this.posX, this.posY, this.posZ);
    vec = vec.translate(new Vector3(0, -1, 0));
    final Block blockAt = vec.getBlock(this.worldObj);

    if (blockAt != null) {
      if (blockAt instanceof BlockFence) {

      } else if (blockAt.isAir(this.worldObj, vec.intX(), vec.intY(), vec.intZ())) {
        this.motionY -= 0.02F;
      }
    }

    this.moveEntity(this.motionX, this.motionY, this.motionZ);
  }
Example #2
0
  public static EntityBlock create(
      EntityPlayer player, World world, int x, int y, int z, Class<? extends EntityBlock> klazz) {

    Block block = world.getBlock(x, y, z);

    if (block.isAir(world, x, y, z)) return null;

    int meta = world.getBlockMetadata(x, y, z);

    final EntityBlock entity;
    try {
      entity = klazz.getConstructor(World.class).newInstance(world);
    } catch (Throwable t) {
      Log.warn(t, "Failed to create EntityBlock(%s) at %d,%d,%d", klazz, x, y, z);
      return null;
    }

    entity.setBlockNameAndMeta(BlockProperties.getBlockName(block), meta);

    final TileEntity te = world.getTileEntity(x, y, z);
    if (te != null) {
      entity.tileEntity = new NBTTagCompound();
      te.writeToNBT(entity.tileEntity);
    }

    final boolean blockRemoved =
        new BlockManipulator(world, player, x, y, z).setSilentTeRemove(true).remove();
    if (!blockRemoved) return null;

    entity.setPositionAndRotation(x + 0.5, y + 0.5, z + 0.5, 0, 0);

    return entity;
  }
Example #3
0
 public static boolean isAirBlock(World aWorld, int aX, int aY, int aZ) {
   Block tID = aWorld.getBlock(aX, aY, aZ);
   if (tID != Blocks.air) {
     return tID.isAir(aWorld, aX, aY, aZ);
   }
   return true;
 }
  @Override
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer player,
      int side,
      float xOffset,
      float yOffset,
      float zOffset) {

    ItemStack ci = player.inventory.mainInventory[player.inventory.currentItem];
    if (ci != null && Block.getBlockFromItem(ci.getItem()).equals(this)) {
      for (int i = y + 1, e = world.getActualHeight(); i < e; ++i) {
        Block block = world.getBlock(x, i, z);
        if (block.isAir(world, x, i, z) || block.isReplaceable(world, x, i, z)) {
          if (!world.isRemote && world.setBlock(x, i, z, this, 0, 3)) {
            world.playAuxSFXAtEntity(null, 2001, x, i, z, Block.getIdFromBlock(this));
            if (!player.capabilities.isCreativeMode) {
              ci.stackSize--;
              if (ci.stackSize == 0) {
                player.inventory.mainInventory[player.inventory.currentItem] = null;
              }
            }
          }
          return true;
        } else if (!block.equals(this)) {
          return false;
        }
      }
    }
    return false;
  }
  public void setBlock(World world, int x, int y, int z, Block block, int metadata) {
    Block b1 = world.getBlock(x, y, z);

    if (b1.isAir(world, x, y, z) || b1.isLeaves(world, x, y, z)) {
      world.setBlock(x, y, z, block, metadata, 2);
    }
  }
 protected boolean isReplaceable(World world, int x, int y, int z) {
   Block block = world.getBlock(x, y, z);
   return block.isAir(world, x, y, z)
       || block.isLeaves(world, x, y, z)
       || block.isWood(world, x, y, z)
       || func_150523_a(block);
 }
 @Override
 public void updateTick(World world, int x, int y, int z, Random rand) {
   // they don't disappear anymore
   int blocks = 0;
   for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
     ForgeDirection dir = ForgeDirection.VALID_DIRECTIONS[i];
     Block block = world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ);
     if (!block.isAir(world, x, y, z)) {
       blocks++;
     }
   }
   if (blocks != 6) {
     int randInt = 0;
     if (leafType == 3) {
       randInt = rand.nextInt(20);
     } else if (leafType < 2) {
       randInt = rand.nextInt(8);
     } else {
       randInt = rand.nextInt(10);
     }
     if (randInt == 2) {
       int meta = world.getBlockMetadata(x, y, z);
       if (meta != 5) {
         world.setBlockMetadataWithNotify(x, y, z, meta + 2, 2);
       }
     }
   }
 }
Example #8
0
  /* Tests a block to see if it can be mined with the current equipment
   * Returns 0 if it can't, -1 if it is cobble
   * Will return 2 if mined with pick, 3 if shovel, 1 if none
   * return 4 if just need to fill using the filler upgrade  */
  public int canMineBlock(int x, int y, int z) {
    BlockPos minePos = new BlockPos(x, y, z);
    IBlockState tryState = worldObj.getBlockState(minePos);
    Block tryBlock = tryState.getBlock();

    if (tryBlock != null) {
      int meta = tryBlock.getMetaFromState(tryState);
      if ((tryBlock.getBlockHardness(tryState, worldObj, minePos) >= 0)
          && (!tryBlock.isAir(tryState, worldObj, minePos))) {
        boolean mine = false;
        // ProgressiveAutomation.logger.info("Tool: "+tryBlock.getHarvestTool(meta)+", Level:
        // "+tryBlock.getHarvestLevel(meta)+", Can use Pick: "+tryBlock.isToolEffective("pickaxe",
        // meta));
        // ProgressiveAutomation.logger.info("Harvestable:
        // "+ForgeHooks.canToolHarvestBlock(tryBlock, meta, getStackInSlot(2)));
        if (tryBlock == Blocks.COBBLESTONE) {
          return -1;
        }
        if (tryBlock.getHarvestTool(tryState) == "chisel") { // this is compatibility for chisel 1
          return 2;
        } else if (tryBlock.getHarvestTool(tryState) == "pickaxe") {
          if (ForgeHooks.canToolHarvestBlock(worldObj, minePos, getStackInSlot(2))) {
            // ProgressiveAutomation.logger.info("Tool can harvest");
            return 2;
          }
        } else if (tryBlock.getHarvestTool(tryState) == "shovel") {
          if (ForgeHooks.canToolHarvestBlock(worldObj, minePos, getStackInSlot(3))) {
            return 3;
          }
        } else {
          if (!tryBlock.getMaterial(tryState).isLiquid()) {
            return 1;
          }
        }
      }

      // see if the filler upgrade is active, if it is then the block will need to be filled.
      if (hasUpgrade(UpgradeType.FILLER)) {
        if ((tryBlock.isAir(tryState, worldObj, minePos))
            || (tryBlock.getMaterial(tryState).isLiquid())) {
          return 4;
        }
      }
    }
    return 0;
  }
Example #9
0
  private void genTreeLayer(int par1, int par2, int par3, float par4, byte par5, Block b) {
    int var7 = (int) (par4 + 0.618D);
    byte var8 = OTHER_COORD_PAIRS[par5];
    byte var9 = OTHER_COORD_PAIRS[par5 + 3];
    int[] var10 = new int[] {par1, par2, par3};
    int[] var11 = new int[] {0, 0, 0};
    int var12 = -var7;
    int var13 = -var7;

    for (var11[par5] = var10[par5]; var12 <= var7; ++var12) {
      var11[var8] = var10[var8] + var12;
      var13 = -var7;

      while (var13 <= var7) {
        double var15 =
            Math.sqrt(
                Math.pow(Math.abs(var12) + 0.5D, 2.0D) + Math.pow(Math.abs(var13) + 0.5D, 2.0D));

        if (var15 > par4) {
          ++var13;
        } else {
          var11[var9] = var10[var9] + var13;
          Block var14 = this.worldObj.getBlock(var11[0], var11[1], var11[2]);

          if (!var14.isAir(worldObj, var11[0], var11[1], var11[2])
              && (var14 != TFCBlocks.leaves || var14 != TFCBlocks.leaves2)
              && var14 != TFCBlocks.vine) {
            ++var13;
          } else {
            this.setBlockAndNotifyAdequately(worldObj, var11[0], var11[1], var11[2], b, treeId);
            if (rand.nextInt(8) > 0) {
              int side = rand.nextInt(4);
              if (side == 0 && worldObj.isAirBlock(var11[0] - 1, var11[1], var11[2])) {
                this.setBlockAndNotifyAdequately(
                    worldObj, var11[0] - 1, var11[1], var11[2], TFCBlocks.vine, 8);
              } else if (side == 1 && worldObj.isAirBlock(var11[0], var11[1], var11[2] - 1)) {
                this.setBlockAndNotifyAdequately(
                    worldObj, var11[0], var11[1], var11[2] - 1, TFCBlocks.vine, 1);
              } else if (side == 2 && worldObj.isAirBlock(var11[0] + 1, var11[1], var11[2])) {
                this.setBlockAndNotifyAdequately(
                    worldObj, var11[0] + 1, var11[1], var11[2], TFCBlocks.vine, 2);
              } else if (side == 3 && worldObj.isAirBlock(var11[0], var11[1], var11[2] + 1)) {
                this.setBlockAndNotifyAdequately(
                    worldObj, var11[0], var11[1], var11[2] + 1, TFCBlocks.vine, 4);
              }
            }
            ++var13;
          }
        }
      }
    }
  }
Example #10
0
 public void updateConnections() {
   for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
     Pos pos = new Pos(this).add(dir);
     Block b = pos.getBlock(getWorldObj());
     if (connectedBlocks.containsKey(dir)) {
       // TODO notify that a block has changed
       if (connectedBlocks.get(dir) != b) connectedBlocks.remove(dir);
     }
     if (b != null && !b.isAir(getWorldObj(), xCoord, yCoord, zCoord)) {
       connectedBlocks.put(dir, b);
     }
   }
 }
  public static boolean func_149831_e(
      World p_149831_0_, int p_149831_1_, int p_149831_2_, int p_149831_3_) {
    Block block = p_149831_0_.getBlock(p_149831_1_, p_149831_2_, p_149831_3_);

    if (block.isAir(p_149831_0_, p_149831_1_, p_149831_2_, p_149831_3_)) {
      return true;
    } else if (block == Blocks.fire) {
      return true;
    } else {
      Material material = block.getMaterial();
      return material == Material.water ? true : material == Material.lava;
    }
  }
Example #12
0
  public static int getTopBlockY(World world, int x, int z) {

    int y = world.getChunkFromBlockCoords(x, z).getTopFilledSegment() + 16;

    Block block;
    do {
      if (--y < 0) {
        break;
      }
      block = world.getBlock(x, y, z);
    } while (block.isAir(world, x, y, z));
    return y;
  }
  public static boolean isPowerProviderOrWire(IBlockAccess world, int i, int j, int k, int l) {
    Block block = world.getBlock(i, j, k);

    if (block == AllDemDimensions.floatingWire || block == Blocks.redstone_wire) {
      return true;
    } else if (block.isAir(world, i, j, k)) {
      return false;
    } else if (block != Blocks.unpowered_repeater && block != Blocks.powered_repeater) {
      return (block != null && block.canConnectRedstone(world, i, j, k, l));
    } else {
      int metadata = world.getBlockMetadata(i, j, k);
      return l == (metadata & 3) || l == Direction.rotateOpposite[metadata & 3];
    }
  }
Example #14
0
  public static int getSurfaceBlockY(World world, int x, int z) {

    int y = world.getChunkFromBlockCoords(x, z).getTopFilledSegment() + 16;

    Block block;
    do {
      if (--y < 0) {
        break;
      }
      block = world.getBlock(x, y, z);
    } while (block.isAir(world, x, y, z)
        || block.isReplaceable(world, x, y, z)
        || block.isLeaves(world, x, y, z)
        || block.isFoliage(world, x, y, z)
        || block.canBeReplacedByLeaves(world, x, y, z));
    return y;
  }
Example #15
0
 @Override
 public boolean onItemUse(
     ItemStack stack,
     EntityPlayer player,
     World world,
     int x,
     int y,
     int z,
     int side,
     float sx,
     float sy,
     float sz) {
   TileEntity te = world.getTileEntity(x, y, z);
   NBTTagCompound tagCompound = stack.getTagCompound();
   if (tagCompound == null) {
     tagCompound = new NBTTagCompound();
   }
   if (te instanceof CounterTileEntity) {
     tagCompound.setInteger("dim", world.provider.dimensionId);
     tagCompound.setInteger("monitorx", x);
     tagCompound.setInteger("monitory", y);
     tagCompound.setInteger("monitorz", z);
     Block block = player.worldObj.getBlock(x, y, z);
     String name = "<invalid>";
     if (block != null && !block.isAir(world, x, y, z)) {
       name = BlockInfo.getReadableName(block, world.getBlockMetadata(x, y, z));
     }
     tagCompound.setString("monitorname", name);
     if (world.isRemote) {
       Logging.message(player, "Counter module is set to block '" + name + "'");
     }
   } else {
     tagCompound.removeTag("dim");
     tagCompound.removeTag("monitorx");
     tagCompound.removeTag("monitory");
     tagCompound.removeTag("monitorz");
     tagCompound.removeTag("monitorname");
     if (world.isRemote) {
       Logging.message(player, "Counter module is cleared");
     }
   }
   stack.setTagCompound(tagCompound);
   return true;
 }
Example #16
0
  BlockPos getHorizon(World world, BlockPos pos) {
    if (!world.getChunkProvider().chunkExists(pos.getX() >> 4, pos.getZ() >> 4)) {
      return null;
    }

    BlockPos horizon = world.getHorizon(pos);
    Block block = world.getBlockState(horizon.down()).getBlock();

    // This stuff is probably no longer needed but to lazy to test the code without it atm
    while (block instanceof BlockLeavesVC
        || block instanceof BlockLogVC
        || block instanceof BlockVineVC
        || block.isAir(world, pos)) {
      horizon = horizon.down();
      block = world.getBlockState(horizon).getBlock();

      if (horizon.getY() < 100) return null;
    }

    return horizon;
  }
 /**
  * Equivalent code to the creative pick block
  *
  * @param target The client target vector
  * @param player The player trying to pick
  * @return the stack expected for the creative pick button
  */
 private static ItemStack getItemFromPointedAt(MovingObjectPosition target, EntityPlayer player) {
   if (target != null) {
     if (target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
       BlockPos pos = target.getBlockPos();
       World world = player.getEntityWorld();
       Block block = world.getBlockState(pos).getBlock();
       if (block.isAir(world, pos)) {
         return null;
       }
       return block.getPickBlock(target, world, pos);
     } else {
       if (target.typeOfHit != MovingObjectPosition.MovingObjectType.ENTITY
           || target.entityHit == null
           || !player.capabilities.isCreativeMode) {
         return null;
       }
       return target.entityHit.getPickedResult(target);
     }
   }
   return null;
 }
  private int getTopBlock(World world, int x, int z) {
    Chunk chunk = world.getChunkFromBlockCoords(x, z);
    int y = chunk.getTopFilledSegment() + 15;

    int trimmedX = x & 15;
    int trimmedZ = z & 15;

    for (; y > 0; --y) {
      Block block = chunk.getBlock(trimmedX, y, trimmedZ);

      if (block.isAir(world, x, y, z)) {
        continue;
      }

      if (block instanceof BlockStaticLiquid) {
        return y;
      }

      if (block instanceof BlockFluidBase) {
        return y;
      }

      if (block instanceof IFluidBlock) {
        return y;
      }

      if (!block.getMaterial().blocksMovement()) {
        continue;
      }

      if (block instanceof BlockFlower) {
        continue;
      }

      return y - 1;
    }

    return -1;
  }
Example #19
0
  private void updateStorageList() {
    SyncedValueList<InvBlockInfo> inventories = tileEntity.getInventories();
    if (inventories.getClientVersion() != clientVersion) {
      clientVersion = inventories.getClientVersion();
      storageList.removeChildren();
      for (InvBlockInfo blockInfo : inventories) {
        Coordinate c = blockInfo.getCoordinate();
        Block block = mc.theWorld.getBlock(c.getX(), c.getY(), c.getZ());
        int meta = mc.theWorld.getBlockMetadata(c.getX(), c.getY(), c.getZ());
        String displayName;
        if (block == null || block.isAir(mc.theWorld, c.getX(), c.getY(), c.getZ())) {
          displayName = "[REMOVED]";
          block = null;
        } else {
          displayName = BlockInfo.getReadableName(block, meta);
        }

        Panel panel = new Panel(mc, this).setLayout(new HorizontalLayout());
        panel.addChild(new BlockRender(mc, this).setRenderItem(block));
        panel.addChild(
            new Label(mc, this)
                .setText(displayName)
                .setHorizontalAlignment(HorizontalAlignment.ALIGH_LEFT)
                .setDesiredWidth(90));
        panel.addChild(new Label(mc, this).setDynamic(true).setText(c.toString()));
        storageList.addChild(panel);
      }
    }
    storageList.clearHilightedRows();
    Set<Coordinate> coordinates = fromServer_coordinates;
    int i = 0;
    for (InvBlockInfo blockInfo : inventories) {
      Coordinate c = blockInfo.getCoordinate();
      if (coordinates.contains(c)) {
        storageList.addHilightedRow(i);
      }
      i++;
    }
  }
Example #20
0
  /**
   * Checks a line of blocks in the world from the first coordinate to triplet to the second,
   * returning the distance (in blocks) before a non-air, non-leaf block is encountered and/or the
   * end is encountered.
   */
  private int checkBlockLine(int[] par1ArrayOfInteger, int[] par2ArrayOfInteger) {
    int[] var3 = new int[] {0, 0, 0};
    byte var4 = 0;
    byte var5;

    for (var5 = 0; var4 < 3; ++var4) {
      var3[var4] = par2ArrayOfInteger[var4] - par1ArrayOfInteger[var4];
      if (Math.abs(var3[var4]) > Math.abs(var3[var5])) var5 = var4;
    }

    if (var3[var5] == 0) {
      return -1;
    } else {
      byte var6 = OTHER_COORD_PAIRS[var5];
      byte var7 = OTHER_COORD_PAIRS[var5 + 3];
      byte var8;

      if (var3[var5] > 0) var8 = 1;
      else var8 = -1;

      double var9 = (double) var3[var6] / (double) var3[var5];
      double var11 = (double) var3[var7] / (double) var3[var5];
      int[] var13 = new int[] {0, 0, 0};
      int var14 = 0;
      int var15;

      for (var15 = var3[var5] + var8; var14 != var15; var14 += var8) {
        var13[var5] = par1ArrayOfInteger[var5] + var14;
        var13[var6] = MathHelper.floor_double(par1ArrayOfInteger[var6] + var14 * var9);
        var13[var7] = MathHelper.floor_double(par1ArrayOfInteger[var7] + var14 * var11);
        Block var16 = this.worldObj.getBlock(var13[0], var13[1], var13[2]);
        if (!var16.isAir(worldObj, var13[0], var13[1], var13[2])
            && (var16 != TFCBlocks.leaves || var16 != TFCBlocks.leaves2)
            && var16 != TFCBlocks.vine) break;
      }
      return var14 == var15 ? -1 : Math.abs(var14);
    }
  }
Example #21
0
  public static void removeBlockWithDrops(
      SpellContext context,
      EntityPlayer player,
      World world,
      ItemStack tool,
      BlockPos pos,
      boolean particles) {
    if (!world.isBlockLoaded(pos)
        || context.positionBroken != null && pos.equals(context.positionBroken.getBlockPos()))
      return;

    int harvestLevel = ConfigHandler.cadHarvestLevel;
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    if (!world.isRemote
        && block != null
        && !block.isAir(world, pos)
        && !(block instanceof BlockLiquid)
        && block.getPlayerRelativeBlockHardness(player, world, pos) > 0) {
      int neededHarvestLevel = block.getHarvestLevel(state);
      if (neededHarvestLevel > harvestLevel) return;

      BreakEvent event = new BreakEvent(world, pos, state, player);
      MinecraftForge.EVENT_BUS.post(event);
      if (!event.isCanceled()) {
        if (!player.capabilities.isCreativeMode) {
          block.onBlockHarvested(world, pos, state, player);

          if (block.removedByPlayer(world, pos, player, true)) {
            block.onBlockDestroyedByPlayer(world, pos, state);
            block.harvestBlock(world, player, pos, state, world.getTileEntity(pos));
          }
        } else world.setBlockToAir(pos);
      }

      if (particles) world.playAuxSFX(2001, pos, Block.getStateId(state));
    }
  }
Example #22
0
  @Override
  public boolean generate(World world, Random rand, int x, int y, int z) {
    Block block;
    do {
      block = world.getBlock(x, y, z);
      if (!(block.isLeaves(world, x, y, z) || block.isAir(world, x, y, z))) {
        break;
      }
      --y;
    } while (y > 0);

    Block block1 = world.getBlock(x, y, z);

    if (TFC_Core.isSoil(block1)) {
      ++y;
      this.setBlockAndNotifyAdequately(world, x, y, z, TFCBlocks.logNatural, this.meta);

      for (int l = y; l <= y + 2; ++l) {
        int i1 = l - y;
        int j1 = 2 - i1;

        for (int k1 = x - j1; k1 <= x + j1; ++k1) {
          int l1 = k1 - x;

          for (int i2 = z - j1; i2 <= z + j1; ++i2) {
            int j2 = i2 - z;

            if ((Math.abs(l1) != j1 || Math.abs(j2) != j1 || rand.nextInt(2) != 0)
                && world.getBlock(k1, l, i2).canBeReplacedByLeaves(world, k1, l, i2)) {
              this.setBlockAndNotifyAdequately(world, k1, l, i2, TFCBlocks.leaves, this.meta);
            }
          }
        }
      }
    }
    return true;
  }
  @Override
  public void onUpdate() {
    super.onUpdate();

    if (supertile.getWorld().isRemote || redstoneSignal > 0) return;

    if (ticksExisted % 10 == 0) {
      IBlockState filter = getUnderlyingBlock();

      boolean scanned = false;
      List<BlockPos> validPositions = new ArrayList<>();

      int rangePlace = getRange();
      int rangePlaceY = getRangeY();

      BlockPos pos = supertile.getPos();

      List<EntityItem> items =
          supertile
              .getWorld()
              .getEntitiesWithinAABB(
                  EntityItem.class,
                  new AxisAlignedBB(
                      supertile.getPos().add(-RANGE, -RANGE_Y, -RANGE),
                      supertile.getPos().add(RANGE + 1, RANGE_Y + 1, RANGE + 1)));
      int slowdown = getSlowdownFactor();
      for (EntityItem item : items) {
        int age;
        try {
          age = (int) MethodHandles.itemAge_getter.invokeExact(item);
        } catch (Throwable t) {
          continue;
        }

        if (age < (60 + slowdown) || item.isDead) continue;

        ItemStack stack = item.getEntityItem();
        Item stackItem = stack.getItem();
        if (stackItem instanceof ItemBlock
            || stackItem instanceof ItemBlockSpecial
            || stackItem instanceof ItemRedstone
            || stackItem instanceof IFlowerPlaceable) {
          if (!scanned) {
            for (BlockPos pos_ :
                BlockPos.getAllInBox(
                    pos.add(-rangePlace, -rangePlaceY, -rangePlace),
                    pos.add(rangePlace, rangePlaceY, rangePlace))) {
              IBlockState stateAbove = supertile.getWorld().getBlockState(pos_.up());
              Block blockAbove = stateAbove.getBlock();
              BlockPos up = pos_.up();
              if (filter == supertile.getWorld().getBlockState(pos_)
                  && (blockAbove.isAir(stateAbove, supertile.getWorld(), up)
                      || blockAbove.isReplaceable(supertile.getWorld(), up)))
                validPositions.add(up);
            }

            scanned = true;
          }

          if (!validPositions.isEmpty()) {
            BlockPos coords =
                validPositions.get(supertile.getWorld().rand.nextInt(validPositions.size()));

            IBlockState stateToPlace = null;
            if (stackItem instanceof IFlowerPlaceable)
              stateToPlace =
                  ((IFlowerPlaceable) stackItem).getBlockToPlaceByFlower(stack, this, coords);
            if (stackItem instanceof ItemBlock)
              stateToPlace =
                  ((ItemBlock) stackItem)
                      .block.getStateFromMeta(stackItem.getMetadata(stack.getItemDamage()));
            else if (stackItem instanceof ItemBlockSpecial)
              stateToPlace =
                  ((Block)
                          ReflectionHelper.getPrivateValue(
                              ItemBlockSpecial.class,
                              (ItemBlockSpecial) stackItem,
                              LibObfuscation.REED_ITEM))
                      .getDefaultState();
            else if (stackItem instanceof ItemRedstone)
              stateToPlace = Blocks.REDSTONE_WIRE.getDefaultState();

            if (stateToPlace != null) {
              if (stateToPlace.getBlock().canPlaceBlockAt(supertile.getWorld(), coords)) {
                supertile.getWorld().setBlockState(coords, stateToPlace, 1 | 2);
                if (ConfigHandler.blockBreakParticles)
                  supertile.getWorld().playEvent(2001, coords, Block.getStateId(stateToPlace));
                validPositions.remove(coords);

                TileEntity tile = supertile.getWorld().getTileEntity(coords);
                if (tile != null && tile instanceof ISubTileContainer) {
                  ISubTileContainer container = (ISubTileContainer) tile;
                  String subtileName = ItemBlockSpecialFlower.getType(stack);
                  container.setSubTile(subtileName);
                  SubTileEntity subtile = container.getSubTile();
                  subtile.onBlockPlacedBy(
                      supertile.getWorld(),
                      coords,
                      supertile.getWorld().getBlockState(coords),
                      null,
                      stack);
                }

                if (stackItem instanceof IFlowerPlaceable)
                  ((IFlowerPlaceable) stackItem).onBlockPlacedByFlower(stack, this, coords);

                stack.stackSize--;
                if (stack.stackSize <= 0) item.setDead();

                if (mana > 1) mana--;
                return;
              }
            }
          }
        }
      }
    }
  }
  public static StorageChunk copyWorldBB(World world, AxisAlignedBB bb) {
    int actualMinX = (int) bb.maxX,
        actualMinY = (int) bb.maxY,
        actualMinZ = (int) bb.maxZ,
        actualMaxX = (int) bb.minX,
        actualMaxY = (int) bb.minY,
        actualMaxZ = (int) bb.minZ;

    // Try to fit to smallest bounds
    for (int x = (int) bb.minX; x <= bb.maxX; x++) {
      for (int z = (int) bb.minZ; z <= bb.maxZ; z++) {
        for (int y = (int) bb.minY; y <= bb.maxY; y++) {

          Block block = world.getBlock(x, y, z);

          if (!block.isAir(world, x, y, z)) {
            if (x < actualMinX) actualMinX = x;
            if (y < actualMinY) actualMinY = y;
            if (z < actualMinZ) actualMinZ = z;
            if (x > actualMaxX) actualMaxX = x;
            if (y > actualMaxY) actualMaxY = y;
            if (z > actualMaxZ) actualMaxZ = z;
          }
        }
      }
    }

    bb.setBounds(actualMinX, actualMinY, actualMinZ, actualMaxX, actualMaxY, actualMaxZ);

    StorageChunk ret =
        new StorageChunk(
            (actualMaxX - actualMinX + 1),
            (actualMaxY - actualMinY + 1),
            (actualMaxZ - actualMinZ + 1));

    // Iterate though the bounds given storing blocks/meta/tiles
    for (int x = actualMinX; x <= actualMaxX; x++) {
      for (int z = actualMinZ; z <= actualMaxZ; z++) {
        for (int y = actualMinY; y <= actualMaxY; y++) {

          ret.blocks[x - actualMinX][y - actualMinY][z - actualMinZ] = world.getBlock(x, y, z);
          ret.metas[x - actualMinX][y - actualMinY][z - actualMinZ] =
              (short) world.getBlockMetadata(x, y, z);

          TileEntity entity = world.getTileEntity(x, y, z);
          if (entity != null) {
            NBTTagCompound nbt = new NBTTagCompound();
            entity.writeToNBT(nbt);

            // Transform tileEntity coords
            nbt.setInteger("x", nbt.getInteger("x") - actualMinX);
            nbt.setInteger("y", nbt.getInteger("y") - actualMinY);
            nbt.setInteger("z", nbt.getInteger("z") - actualMinZ);

            TileEntity newTile = TileEntity.createAndLoadEntity(nbt);

            newTile.setWorldObj(world);

            if (isUsableBlock(newTile)) {
              ret.usableTiles.add(newTile);
            }

            ret.tileEntities.add(newTile);
          }
        }
      }
    }

    return ret;
  }
  public boolean generate(
      World p_76484_1_, Random p_76484_2_, int p_76484_3_, int p_76484_4_, int p_76484_5_) {
    int l = p_76484_2_.nextInt(2);

    if (this.mushroomType >= 0) {
      l = this.mushroomType;
    }

    int i1 = p_76484_2_.nextInt(3) + 4;
    boolean flag = true;

    if (p_76484_4_ >= 1 && p_76484_4_ + i1 + 1 < 256) {
      int k1;
      int l1;

      for (int j1 = p_76484_4_; j1 <= p_76484_4_ + 1 + i1; ++j1) {
        byte b0 = 3;

        if (j1 <= p_76484_4_ + 3) {
          b0 = 0;
        }

        for (k1 = p_76484_3_ - b0; k1 <= p_76484_3_ + b0 && flag; ++k1) {
          for (l1 = p_76484_5_ - b0; l1 <= p_76484_5_ + b0 && flag; ++l1) {
            if (j1 >= 0 && j1 < 256) {
              Block block = p_76484_1_.getBlock(k1, j1, l1);

              if (!block.isAir(p_76484_1_, k1, j1, l1) && !block.isLeaves(p_76484_1_, k1, j1, l1)) {
                flag = false;
              }
            } else {
              flag = false;
            }
          }
        }
      }

      if (!flag) {
        return false;
      } else {
        Block block1 = p_76484_1_.getBlock(p_76484_3_, p_76484_4_ - 1, p_76484_5_);

        if (block1 != Blocks.dirt
            && block1 != Blocks.grass
            && block1 != EnhancedBiomesBlocks.dirtEB
            && block1 != EnhancedBiomesBlocks.grassEB
            && block1 != Blocks.mycelium) {
          return false;
        } else {
          int k2 = p_76484_4_ + i1;

          if (l == 1) {
            k2 = p_76484_4_ + i1 - 3;
          }

          for (k1 = k2; k1 <= p_76484_4_ + i1; ++k1) {
            l1 = 1;

            if (k1 < p_76484_4_ + i1) {
              ++l1;
            }

            if (l == 0) {
              l1 = 3;
            }

            for (int l2 = p_76484_3_ - l1; l2 <= p_76484_3_ + l1; ++l2) {
              for (int i2 = p_76484_5_ - l1; i2 <= p_76484_5_ + l1; ++i2) {
                int j2 = 5;

                if (l2 == p_76484_3_ - l1) {
                  --j2;
                }

                if (l2 == p_76484_3_ + l1) {
                  ++j2;
                }

                if (i2 == p_76484_5_ - l1) {
                  j2 -= 3;
                }

                if (i2 == p_76484_5_ + l1) {
                  j2 += 3;
                }

                if (l == 0 || k1 < p_76484_4_ + i1) {
                  if ((l2 == p_76484_3_ - l1 || l2 == p_76484_3_ + l1)
                      && (i2 == p_76484_5_ - l1 || i2 == p_76484_5_ + l1)) {
                    continue;
                  }

                  if (l2 == p_76484_3_ - (l1 - 1) && i2 == p_76484_5_ - l1) {
                    j2 = 1;
                  }

                  if (l2 == p_76484_3_ - l1 && i2 == p_76484_5_ - (l1 - 1)) {
                    j2 = 1;
                  }

                  if (l2 == p_76484_3_ + (l1 - 1) && i2 == p_76484_5_ - l1) {
                    j2 = 3;
                  }

                  if (l2 == p_76484_3_ + l1 && i2 == p_76484_5_ - (l1 - 1)) {
                    j2 = 3;
                  }

                  if (l2 == p_76484_3_ - (l1 - 1) && i2 == p_76484_5_ + l1) {
                    j2 = 7;
                  }

                  if (l2 == p_76484_3_ - l1 && i2 == p_76484_5_ + (l1 - 1)) {
                    j2 = 7;
                  }

                  if (l2 == p_76484_3_ + (l1 - 1) && i2 == p_76484_5_ + l1) {
                    j2 = 9;
                  }

                  if (l2 == p_76484_3_ + l1 && i2 == p_76484_5_ + (l1 - 1)) {
                    j2 = 9;
                  }
                }

                if (j2 == 5 && k1 < p_76484_4_ + i1) {
                  j2 = 0;
                }

                if ((j2 != 0 || p_76484_4_ >= p_76484_4_ + i1 - 1)
                    && p_76484_1_
                        .getBlock(l2, k1, i2)
                        .canBeReplacedByLeaves(p_76484_1_, l2, k1, i2)) {
                  this.setBlockAndNotifyAdequately(
                      p_76484_1_,
                      l2,
                      k1,
                      i2,
                      Block.getBlockById(Block.getIdFromBlock(Blocks.brown_mushroom_block) + l),
                      j2);
                }
              }
            }
          }

          for (k1 = 0; k1 < i1; ++k1) {
            Block block2 = p_76484_1_.getBlock(p_76484_3_, p_76484_4_ + k1, p_76484_5_);

            if (block2.canBeReplacedByLeaves(p_76484_1_, p_76484_3_, p_76484_4_ + k1, p_76484_5_)) {
              this.setBlockAndNotifyAdequately(
                  p_76484_1_,
                  p_76484_3_,
                  p_76484_4_ + k1,
                  p_76484_5_,
                  Block.getBlockById(Block.getIdFromBlock(Blocks.brown_mushroom_block) + l),
                  10);
            }
          }

          return true;
        }
      }
    } else {
      return false;
    }
  }
  public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5) {
    int l = par2Random.nextInt(2);

    if (this.mushroomType >= 0) {
      l = this.mushroomType;
    }

    int i1 = par2Random.nextInt(3) + 4;
    boolean flag = true;

    if (par4 >= 1 && par4 + i1 + 1 < 256) {
      int k1;
      int l1;

      for (int j1 = par4; j1 <= par4 + 1 + i1; ++j1) {
        byte b0 = 3;

        if (j1 <= par4 + 3) {
          b0 = 0;
        }

        for (k1 = par3 - b0; k1 <= par3 + b0 && flag; ++k1) {
          for (l1 = par5 - b0; l1 <= par5 + b0 && flag; ++l1) {
            if (j1 >= 0 && j1 < 256) {
              Block block = par1World.getBlock(k1, j1, l1);

              if (!block.isAir(par1World, k1, j1, l1) && !block.isLeaves(par1World, k1, j1, l1)) {
                flag = false;
              }
            } else {
              flag = false;
            }
          }
        }
      }

      if (!flag) {
        return false;
      } else {
        Block block1 = par1World.getBlock(par3, par4 - 1, par5);

        if (block1 != Blocks.dirt && block1 != Blocks.grass && block1 != Blocks.mycelium) {
          return false;
        } else {
          int k2 = par4 + i1;

          if (l == 1) {
            k2 = par4 + i1 - 3;
          }

          for (k1 = k2; k1 <= par4 + i1; ++k1) {
            l1 = 1;

            if (k1 < par4 + i1) {
              ++l1;
            }

            if (l == 0) {
              l1 = 3;
            }

            for (int l2 = par3 - l1; l2 <= par3 + l1; ++l2) {
              for (int i2 = par5 - l1; i2 <= par5 + l1; ++i2) {
                int j2 = 5;

                if (l2 == par3 - l1) {
                  --j2;
                }

                if (l2 == par3 + l1) {
                  ++j2;
                }

                if (i2 == par5 - l1) {
                  j2 -= 3;
                }

                if (i2 == par5 + l1) {
                  j2 += 3;
                }

                if (l == 0 || k1 < par4 + i1) {
                  if ((l2 == par3 - l1 || l2 == par3 + l1)
                      && (i2 == par5 - l1 || i2 == par5 + l1)) {
                    continue;
                  }

                  if (l2 == par3 - (l1 - 1) && i2 == par5 - l1) {
                    j2 = 1;
                  }

                  if (l2 == par3 - l1 && i2 == par5 - (l1 - 1)) {
                    j2 = 1;
                  }

                  if (l2 == par3 + (l1 - 1) && i2 == par5 - l1) {
                    j2 = 3;
                  }

                  if (l2 == par3 + l1 && i2 == par5 - (l1 - 1)) {
                    j2 = 3;
                  }

                  if (l2 == par3 - (l1 - 1) && i2 == par5 + l1) {
                    j2 = 7;
                  }

                  if (l2 == par3 - l1 && i2 == par5 + (l1 - 1)) {
                    j2 = 7;
                  }

                  if (l2 == par3 + (l1 - 1) && i2 == par5 + l1) {
                    j2 = 9;
                  }

                  if (l2 == par3 + l1 && i2 == par5 + (l1 - 1)) {
                    j2 = 9;
                  }
                }

                if (j2 == 5 && k1 < par4 + i1) {
                  j2 = 0;
                }

                if ((j2 != 0 || par4 >= par4 + i1 - 1)
                    && par1World
                        .getBlock(l2, k1, i2)
                        .canBeReplacedByLeaves(par1World, l2, k1, i2)) {
                  this.setBlockAndNotifyAdequately(
                      par1World,
                      l2,
                      k1,
                      i2,
                      Block.getBlockById(Block.getIdFromBlock(Blocks.brown_mushroom_block) + l),
                      j2);
                }
              }
            }
          }

          for (k1 = 0; k1 < i1; ++k1) {
            Block block2 = par1World.getBlock(par3, par4 + k1, par5);

            if (block2.canBeReplacedByLeaves(par1World, par3, par4 + k1, par5)) {
              this.setBlockAndNotifyAdequately(
                  par1World,
                  par3,
                  par4 + k1,
                  par5,
                  Block.getBlockById(Block.getIdFromBlock(Blocks.brown_mushroom_block) + l),
                  10);
            }
          }

          return true;
        }
      }
    } else {
      return false;
    }
  }
Example #27
0
  protected void updateAITasks() {
    int i;

    if (this.func_82212_n() > 0) {
      i = this.func_82212_n() - 1;

      if (i <= 0) {
        this.worldObj.newExplosion(
            this,
            this.posX,
            this.posY + (double) this.getEyeHeight(),
            this.posZ,
            7.0F,
            false,
            this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing"));
        this.worldObj.playBroadcastSound(
            1013, (int) this.posX, (int) this.posY, (int) this.posZ, 0);
      }

      this.func_82215_s(i);

      if (this.ticksExisted % 10 == 0) {
        this.heal(10.0F);
      }
    } else {
      super.updateAITasks();
      int i1;

      for (i = 1; i < 3; ++i) {
        if (this.ticksExisted >= this.field_82223_h[i - 1]) {
          this.field_82223_h[i - 1] = this.ticksExisted + 10 + this.rand.nextInt(10);

          if (this.worldObj.difficultySetting == EnumDifficulty.NORMAL
              || this.worldObj.difficultySetting == EnumDifficulty.HARD) {
            int k2 = i - 1;
            int l2 = this.field_82224_i[i - 1];
            this.field_82224_i[k2] = this.field_82224_i[i - 1] + 1;

            if (l2 > 15) {
              float f = 10.0F;
              float f1 = 5.0F;
              double d0 =
                  MathHelper.getRandomDoubleInRange(
                      this.rand, this.posX - (double) f, this.posX + (double) f);
              double d1 =
                  MathHelper.getRandomDoubleInRange(
                      this.rand, this.posY - (double) f1, this.posY + (double) f1);
              double d2 =
                  MathHelper.getRandomDoubleInRange(
                      this.rand, this.posZ - (double) f, this.posZ + (double) f);
              this.func_82209_a(i + 1, d0, d1, d2, true);
              this.field_82224_i[i - 1] = 0;
            }
          }

          i1 = this.getWatchedTargetId(i);

          if (i1 > 0) {
            Entity entity = this.worldObj.getEntityByID(i1);

            if (entity != null
                && entity.isEntityAlive()
                && this.getDistanceSqToEntity(entity) <= 900.0D
                && this.canEntityBeSeen(entity)) {
              this.func_82216_a(i + 1, (EntityLivingBase) entity);
              this.field_82223_h[i - 1] = this.ticksExisted + 40 + this.rand.nextInt(20);
              this.field_82224_i[i - 1] = 0;
            } else {
              this.func_82211_c(i, 0);
            }
          } else {
            List list =
                this.worldObj.selectEntitiesWithinAABB(
                    EntityLivingBase.class,
                    this.boundingBox.expand(20.0D, 8.0D, 20.0D),
                    attackEntitySelector);

            for (int k1 = 0; k1 < 10 && !list.isEmpty(); ++k1) {
              EntityLivingBase entitylivingbase =
                  (EntityLivingBase) list.get(this.rand.nextInt(list.size()));

              if (entitylivingbase != this
                  && entitylivingbase.isEntityAlive()
                  && this.canEntityBeSeen(entitylivingbase)) {
                if (entitylivingbase instanceof EntityPlayer) {
                  if (!((EntityPlayer) entitylivingbase).capabilities.disableDamage) {
                    this.func_82211_c(i, entitylivingbase.getEntityId());
                  }
                } else {
                  this.func_82211_c(i, entitylivingbase.getEntityId());
                }

                break;
              }

              list.remove(entitylivingbase);
            }
          }
        }
      }

      if (this.getAttackTarget() != null) {
        this.func_82211_c(0, this.getAttackTarget().getEntityId());
      } else {
        this.func_82211_c(0, 0);
      }

      if (this.field_82222_j > 0) {
        --this.field_82222_j;

        if (this.field_82222_j == 0
            && this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing")) {
          i = MathHelper.floor_double(this.posY);
          i1 = MathHelper.floor_double(this.posX);
          int j1 = MathHelper.floor_double(this.posZ);
          boolean flag = false;

          for (int l1 = -1; l1 <= 1; ++l1) {
            for (int i2 = -1; i2 <= 1; ++i2) {
              for (int j = 0; j <= 3; ++j) {
                int j2 = i1 + l1;
                int k = i + j;
                int l = j1 + i2;
                Block block = this.worldObj.getBlock(j2, k, l);

                if (!block.isAir(worldObj, j2, k, l)
                    && block.canEntityDestroy(worldObj, j2, k, l, this)) {
                  flag = this.worldObj.func_147480_a(j2, k, l, true) || flag;
                }
              }
            }
          }

          if (flag) {
            this.worldObj.playAuxSFXAtEntity(
                (EntityPlayer) null, 1012, (int) this.posX, (int) this.posY, (int) this.posZ, 0);
          }
        }
      }

      if (this.ticksExisted % 20 == 0) {
        this.heal(1.0F);
      }
    }
  }
  @Override
  @SuppressWarnings("unchecked")
  public void onUpdate() {
    super.onUpdate();

    if (this.ticksExisted > 400) {
      if (this.isHot) {
        this.isHot = false;
        this.setHot(this.isHot);
      }
    } else if (!this.worldObj.isRemote) {
      this.setHot(this.isHot);
    }

    if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) {
      float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
      this.prevRotationYaw =
          this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
      this.prevRotationPitch =
          this.rotationPitch = (float) (Math.atan2(this.motionY, f) * 180.0D / Math.PI);
    }

    BlockPos pos = new BlockPos(this.xTile, this.yTile, this.zTile);
    Block block = this.worldObj.getBlockState(pos).getBlock();

    if (!block.isAir(this.worldObj, pos)) {
      block.setBlockBoundsBasedOnState(this.worldObj, pos);
      AxisAlignedBB axisalignedbb =
          block.getCollisionBoundingBox(this.worldObj, pos, this.worldObj.getBlockState(pos));

      if (axisalignedbb != null
          && axisalignedbb.isVecInside(new Vec3(this.posX, this.posY, this.posZ))) {
        this.inGround = true;
      }
    }

    if (this.inGround) {
      Block j = this.worldObj.getBlockState(pos).getBlock();
      int k = j.getMetaFromState(this.worldObj.getBlockState(pos));

      if (j == this.inTile && k == this.inData) {
        ++this.ticksInGround;

        if (this.ticksInGround == 1200) {
          this.setDead();
        }
      } else {
        this.inGround = false;
        this.motionX *= this.rand.nextFloat() * 0.2F;
        this.motionY *= this.rand.nextFloat() * 0.2F;
        this.motionZ *= this.rand.nextFloat() * 0.2F;
        this.ticksInGround = 0;
        this.ticksInAir = 0;
      }
    } else {
      ++this.ticksInAir;
      Vec3 vec3 = new Vec3(this.posX, this.posY, this.posZ);
      Vec3 vec31 =
          new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
      MovingObjectPosition movingobjectposition =
          this.worldObj.rayTraceBlocks(vec3, vec31, false, true, false);
      vec3 = new Vec3(this.posX, this.posY, this.posZ);
      vec31 =
          new Vec3(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);

      if (movingobjectposition != null) {
        vec31 =
            new Vec3(
                movingobjectposition.hitVec.xCoord,
                movingobjectposition.hitVec.yCoord,
                movingobjectposition.hitVec.zCoord);
      }

      this.rotationPitch += 1F;

      Entity entity = null;
      List<Entity> list =
          this.worldObj.getEntitiesWithinAABBExcludingEntity(
              this,
              this.getEntityBoundingBox()
                  .addCoord(this.motionX, this.motionY, this.motionZ)
                  .expand(1.0D, 1.0D, 1.0D));
      double d0 = 0.0D;
      int l;
      float f1;

      for (l = 0; l < list.size(); ++l) {
        Entity entity1 = list.get(l);

        if (entity1.canBeCollidedWith()
            && (entity1 != this.shootingEntity || this.ticksInAir >= 5)) {
          f1 = 0.3F;
          AxisAlignedBB axisalignedbb1 = entity1.getEntityBoundingBox().expand(f1, f1, f1);
          MovingObjectPosition movingobjectposition1 =
              axisalignedbb1.calculateIntercept(vec3, vec31);

          if (movingobjectposition1 != null) {
            double d1 = vec3.distanceTo(movingobjectposition1.hitVec);

            if (d1 < d0 || d0 == 0.0D) {
              entity = entity1;
              d0 = d1;
            }
          }
        }
      }

      if (entity != null) {
        movingobjectposition = new MovingObjectPosition(entity);
      }

      if (movingobjectposition != null
          && movingobjectposition.entityHit != null
          && movingobjectposition.entityHit instanceof EntityPlayer) {
        EntityPlayer entityplayer = (EntityPlayer) movingobjectposition.entityHit;

        if (entityplayer.capabilities.disableDamage
            || this.shootingEntity instanceof EntityPlayer
                && !((EntityPlayer) this.shootingEntity).canAttackPlayer(entityplayer)) {
          movingobjectposition = null;
        }
      }

      float f2;
      float f3;
      double damage = ConfigManagerCore.hardMode ? 3.2D : 1.6D;

      if (movingobjectposition != null) {
        if (movingobjectposition.entityHit != null) {
          f2 =
              MathHelper.sqrt_double(
                  this.motionX * this.motionX
                      + this.motionY * this.motionY
                      + this.motionZ * this.motionZ);
          int i1 = MathHelper.ceiling_double_int(f2 * damage);

          DamageSource damagesource = null;

          if (this.shootingEntity == null) {
            damagesource =
                new EntityDamageSourceIndirect("meteorChunk", this, this).setProjectile();
          } else {
            damagesource =
                new EntityDamageSourceIndirect("meteorChunk", this, this.shootingEntity)
                    .setProjectile();
          }

          if (this.isBurning() && !(movingobjectposition.entityHit instanceof EntityEnderman)) {
            movingobjectposition.entityHit.setFire(2);
          }

          if (movingobjectposition.entityHit.attackEntityFrom(damagesource, i1)) {
            if (movingobjectposition.entityHit instanceof EntityLivingBase) {
              EntityLivingBase entitylivingbase = (EntityLivingBase) movingobjectposition.entityHit;

              if (!this.worldObj.isRemote) {
                entitylivingbase.setArrowCountInEntity(
                    entitylivingbase.getArrowCountInEntity() + 1);
              }

              if (this.knockbackStrength > 0) {
                f3 =
                    MathHelper.sqrt_double(
                        this.motionX * this.motionX + this.motionZ * this.motionZ);

                if (f3 > 0.0F) {
                  movingobjectposition.entityHit.addVelocity(
                      this.motionX * this.knockbackStrength * 0.6000000238418579D / f3,
                      0.1D,
                      this.motionZ * this.knockbackStrength * 0.6000000238418579D / f3);
                }
              }

              if (this.shootingEntity != null) {
                EnchantmentHelper.applyThornEnchantments(entitylivingbase, this.shootingEntity);
                EnchantmentHelper.applyArthropodEnchantments(
                    (EntityLivingBase) this.shootingEntity, entitylivingbase);
              }

              if (this.shootingEntity != null
                  && movingobjectposition.entityHit != this.shootingEntity
                  && movingobjectposition.entityHit instanceof EntityPlayer
                  && this.shootingEntity instanceof EntityPlayerMP) {
                ((EntityPlayerMP) this.shootingEntity)
                    .playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(6, 0.0F));
              }
            }

            if (!(movingobjectposition.entityHit instanceof EntityEnderman)) {
              this.setDead();
            }
          } else {
            this.motionX *= -0.10000000149011612D;
            this.motionY *= -0.10000000149011612D;
            this.motionZ *= -0.10000000149011612D;
            this.rotationYaw += 180.0F;
            this.prevRotationYaw += 180.0F;
            this.ticksInAir = 0;
          }
        } else {
          this.xTile = movingobjectposition.getBlockPos().getX();
          this.yTile = movingobjectposition.getBlockPos().getY();
          this.zTile = movingobjectposition.getBlockPos().getZ();
          IBlockState state = this.worldObj.getBlockState(movingobjectposition.getBlockPos());
          this.inTile = state.getBlock();
          this.inData = this.inTile.getMetaFromState(state);
          this.motionX = (float) (movingobjectposition.hitVec.xCoord - this.posX);
          this.motionY = (float) (movingobjectposition.hitVec.yCoord - this.posY);
          this.motionZ = (float) (movingobjectposition.hitVec.zCoord - this.posZ);
          f2 =
              MathHelper.sqrt_double(
                  this.motionX * this.motionX
                      + this.motionY * this.motionY
                      + this.motionZ * this.motionZ);
          this.posX -= this.motionX / f2 * 0.05000000074505806D;
          this.posY -= this.motionY / f2 * 0.05000000074505806D;
          this.posZ -= this.motionZ / f2 * 0.05000000074505806D;
          this.inGround = true;

          if (!this.inTile.isAir(this.worldObj, movingobjectposition.getBlockPos())) {
            this.inTile.onEntityCollidedWithBlock(
                this.worldObj, movingobjectposition.getBlockPos(), this);
          }
        }
      }

      this.posX += this.motionX;
      this.posY += this.motionY;
      this.posZ += this.motionZ;
      f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);

      if (!this.onGround) {
        this.rotationPitch += 10;
        this.rotationYaw += 2;
      }

      float f4 = 0.99F;
      f1 = 0.05F;

      if (this.isInWater()) {
        for (int j1 = 0; j1 < 4; ++j1) {
          f3 = 0.25F;
          this.worldObj.spawnParticle(
              EnumParticleTypes.WATER_BUBBLE,
              this.posX - this.motionX * f3,
              this.posY - this.motionY * f3,
              this.posZ - this.motionZ * f3,
              this.motionX,
              this.motionY,
              this.motionZ);
        }

        f4 = 0.8F;
      }

      this.motionX *= f4;
      this.motionY *= f4;
      this.motionZ *= f4;
      this.motionY -= WorldUtil.getGravityForEntity(this);
      this.setPosition(this.posX, this.posY, this.posZ);
      this.doBlockCollisions();
    }
  }
  //	public static ArrayListMultimap<ChunkCoordinates, AxisAlignedBB> additionalBlockBounds =
  // ArrayListMultimap.create();
  //	public static void addAdditionalBlockBounds(ChunkCoordinates cc, AxisAlignedBB aabb)
  //	{
  //		for(AxisAlignedBB aabb1 : additionalBlockBounds.get(cc))
  //			if(aabb1.toString().equals(aabb.toString()))
  //				return;
  //		additionalBlockBounds.put(cc, aabb);
  //	}
  @SubscribeEvent()
  public void renderAdditionalBlockBounds(DrawBlockHighlightEvent event) {
    if (event.subID == 0 && event.target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
      float f1 = 0.002F;
      double d0 =
          event.player.lastTickPosX
              + (event.player.posX - event.player.lastTickPosX) * (double) event.partialTicks;
      double d1 =
          event.player.lastTickPosY
              + (event.player.posY - event.player.lastTickPosY) * (double) event.partialTicks;
      double d2 =
          event.player.lastTickPosZ
              + (event.player.posZ - event.player.lastTickPosZ) * (double) event.partialTicks;
      //			if(additionalBlockBounds.containsKey(new
      // ChunkCoordinates(event.target.blockX,event.target.blockY,event.target.blockZ)))
      if (event.player.worldObj.getBlock(
              event.target.blockX, event.target.blockY, event.target.blockZ)
          instanceof IEBlockInterfaces.ICustomBoundingboxes) {
        ChunkCoordinates cc =
            new ChunkCoordinates(event.target.blockX, event.target.blockY, event.target.blockZ);
        IEBlockInterfaces.ICustomBoundingboxes block =
            (IEBlockInterfaces.ICustomBoundingboxes)
                event.player.worldObj.getBlock(
                    event.target.blockX, event.target.blockY, event.target.blockZ);
        Set<AxisAlignedBB> set =
            block.addCustomSelectionBoxesToList(
                event.player.worldObj, cc.posX, cc.posY, cc.posZ, event.player);
        if (!set.isEmpty()) {
          //
          //	if(!(event.player.worldObj.getTileEntity(event.target.blockX,event.target.blockY,event.target.blockZ) instanceof IEBlockInterfaces.ICustomBoundingboxes))
          //				{
          //					additionalBlockBounds.removeAll(cc);
          //					return;
          //				}
          GL11.glEnable(GL11.GL_BLEND);
          OpenGlHelper.glBlendFunc(770, 771, 1, 0);
          GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.4F);
          GL11.glLineWidth(2.0F);
          GL11.glDisable(GL11.GL_TEXTURE_2D);
          GL11.glDepthMask(false);
          for (AxisAlignedBB aabb : set)
            //				for(AxisAlignedBB aabb : additionalBlockBounds.get(cc))
            if (aabb != null)
              RenderGlobal.drawOutlinedBoundingBox(
                  aabb.getOffsetBoundingBox(cc.posX, cc.posY, cc.posZ)
                      .expand((double) f1, (double) f1, (double) f1)
                      .getOffsetBoundingBox(-d0, -d1, -d2),
                  -1);

          GL11.glDepthMask(true);
          GL11.glEnable(GL11.GL_TEXTURE_2D);
          GL11.glDisable(GL11.GL_BLEND);
          event.setCanceled(true);
        }
      }

      ItemStack stack = event.player.getCurrentEquippedItem();
      World world = event.player.worldObj;
      if (stack != null
          && stack.getItem() instanceof ItemDrill
          && ((ItemDrill) stack.getItem())
              .isEffective(
                  world
                      .getBlock(event.target.blockX, event.target.blockY, event.target.blockZ)
                      .getMaterial())) {
        ItemStack head = ((ItemDrill) stack.getItem()).getHead(stack);
        if (head != null) {
          int side = event.target.sideHit;
          int diameter =
              ((IDrillHead) head.getItem()).getMiningSize(head)
                  + ((ItemDrill) stack.getItem()).getUpgrades(stack).getInteger("size");
          int depth =
              ((IDrillHead) head.getItem()).getMiningDepth(head)
                  + ((ItemDrill) stack.getItem()).getUpgrades(stack).getInteger("depth");

          int startX = event.target.blockX;
          int startY = event.target.blockY;
          int startZ = event.target.blockZ;
          if (diameter % 2 == 0) // even numbers
          {
            float hx = (float) event.target.hitVec.xCoord - event.target.blockX;
            float hy = (float) event.target.hitVec.yCoord - event.target.blockY;
            float hz = (float) event.target.hitVec.zCoord - event.target.blockZ;
            if ((side < 2 && hx < .5) || (side < 4 && hx < .5)) startX -= diameter / 2;
            if (side > 1 && hy < .5) startY -= diameter / 2;
            if ((side < 2 && hz < .5) || (side > 3 && hz < .5)) startZ -= diameter / 2;
          } else // odd numbers
          {
            startX -= (side == 4 || side == 5 ? 0 : diameter / 2);
            startY -= (side == 0 || side == 1 ? 0 : diameter / 2);
            startZ -= (side == 2 || side == 3 ? 0 : diameter / 2);
          }

          GL11.glColor4f(0.1F, 0.1F, 0.1F, 0.4F);
          GL11.glLineWidth(1F);
          GL11.glDisable(GL11.GL_TEXTURE_2D);

          //					AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(startX,startY,startZ,
          // startX+(side==4||side==5?1:diameter),startY+(side==0||side==1?1:diameter),startZ+(side==2||side==3?1: diameter));
          //					RenderGlobal.drawOutlinedBoundingBox(aabb.expand((double)f1, (double)f1,
          // (double)f1).getOffsetBoundingBox(-d0, -d1, -d2), -1);
          for (int dd = 0; dd < depth; dd++)
            for (int dw = 0; dw < diameter; dw++)
              for (int dh = 0; dh < diameter; dh++) {
                int x = startX + (side == 4 || side == 5 ? dd : dw);
                int y = startY + (side == 0 || side == 1 ? dd : dh);
                int z = startZ + (side == 0 || side == 1 ? dh : side == 4 || side == 5 ? dw : dd);
                Block block = event.player.worldObj.getBlock(x, y, z);
                if (block != null
                    && !block.isAir(world, x, y, z)
                    && block.getPlayerRelativeBlockHardness(event.player, world, x, y, z) != 0) {
                  if (!((ItemDrill) stack.getItem())
                      .canBreakExtraBlock(
                          world,
                          block,
                          x,
                          y,
                          z,
                          world.getBlockMetadata(x, y, z),
                          event.player,
                          stack,
                          head,
                          false)) continue;
                  AxisAlignedBB aabb =
                      block.getSelectedBoundingBoxFromPool(event.player.worldObj, x, y, z);
                  if (aabb != null) {
                    RenderGlobal.drawOutlinedBoundingBox(
                        aabb.expand((double) f1, (double) f1, (double) f1)
                            .getOffsetBoundingBox(-d0, -d1, -d2),
                        -1);
                  }
                }
              }
          GL11.glDepthMask(true);
          GL11.glEnable(GL11.GL_TEXTURE_2D);
          GL11.glDisable(GL11.GL_BLEND);
        }
      }
    }
  }
  public boolean generate(
      World p_76484_1_, Random p_76484_2_, int p_76484_3_, int p_76484_4_, int p_76484_5_) {
    int l = p_76484_2_.nextInt(height * 2) + height * 2;
    int i1 = height + p_76484_2_.nextInt(height);
    int j1 = l - i1;
    int k1 = 2 + p_76484_2_.nextInt(2);
    boolean flag = true;

    if (p_76484_4_ >= 1 && p_76484_4_ + l + 1 <= 256) {
      int i2;
      int l3;

      for (int l1 = p_76484_4_; l1 <= p_76484_4_ + 1 + l && flag; ++l1) {
        boolean flag1 = true;

        if (l1 - p_76484_4_ < i1) {
          l3 = 0;
        } else {
          l3 = k1;
        }

        for (i2 = p_76484_3_ - l3; i2 <= p_76484_3_ + l3 && flag; ++i2) {
          for (int j2 = p_76484_5_ - l3; j2 <= p_76484_5_ + l3 && flag; ++j2) {
            if (l1 >= 0 && l1 < 256) {
              Block block = p_76484_1_.getBlock(i2, l1, j2);

              if (!block.isAir(p_76484_1_, i2, l1, j2)
                  && !block.isLeaves(p_76484_1_, i2, l1, j2)
                  && block != Blocks.snow_layer) {
                flag = false;
              }
            } else {
              flag = false;
            }
          }
        }
      }

      if (!flag) {
        return false;
      } else {
        Block block1 = p_76484_1_.getBlock(p_76484_3_, p_76484_4_ - 1, p_76484_5_);

        boolean isSoil =
            block1.canSustainPlant(
                p_76484_1_,
                p_76484_3_,
                p_76484_4_ - 1,
                p_76484_5_,
                ForgeDirection.UP,
                (BlockSapling) Blocks.sapling);
        if (isSoil && p_76484_4_ < 256 - l - 1) {
          block1.onPlantGrow(
              p_76484_1_,
              p_76484_3_,
              p_76484_4_ - 1,
              p_76484_5_,
              p_76484_3_,
              p_76484_4_,
              p_76484_5_);
          l3 = p_76484_2_.nextInt(2);
          i2 = 1;
          byte b0 = 0;
          int k2;
          int i4;

          for (i4 = 0; i4 <= j1; ++i4) {
            k2 = p_76484_4_ + l - i4;

            for (int l2 = p_76484_3_ - l3; l2 <= p_76484_3_ + l3; ++l2) {
              int i3 = l2 - p_76484_3_;

              for (int j3 = p_76484_5_ - l3; j3 <= p_76484_5_ + l3; ++j3) {
                int k3 = j3 - p_76484_5_;

                if ((Math.abs(i3) != l3 || Math.abs(k3) != l3 || l3 <= 0)
                    && p_76484_1_
                        .getBlock(l2, k2, j3)
                        .canBeReplacedByLeaves(p_76484_1_, l2, k2, j3)) {
                  p_76484_1_.setBlock(l2, k2, j3, Blocks.leaves, metadata, 0);
                }
              }
            }

            if (l3 >= i2) {
              l3 = b0;
              b0 = 1;
              ++i2;

              if (i2 > k1) {
                i2 = k1;
              }
            } else {
              ++l3;
            }
          }

          i4 = p_76484_2_.nextInt(3);

          for (k2 = 0; k2 < l - i4; ++k2) {
            Block block2 = p_76484_1_.getBlock(p_76484_3_, p_76484_4_ + k2, p_76484_5_);

            if (block2.isAir(p_76484_1_, p_76484_3_, p_76484_4_ + k2, p_76484_5_)
                || block2.isLeaves(p_76484_1_, p_76484_3_, p_76484_4_ + k2, p_76484_5_)
                || block2 == Blocks.snow_layer) {
              p_76484_1_.setBlock(p_76484_3_, p_76484_4_ + k2, p_76484_5_, Blocks.log, 0, 0);
            }
          }

          if (height > 4) {
            createTrunk(p_76484_1_, p_76484_2_, p_76484_3_, p_76484_4_, p_76484_5_);
          }

          return true;
        } else {
          return false;
        }
      }
    } else {
      return false;
    }
  }