示例#1
0
 protected JsonerItemArmor(Item item, boolean showRecipes) {
   super(item, 0, showRecipes);
   ItemArmor armor = (ItemArmor) item;
   this.armorType = armor.armorType;
   this.damageReduceAmount = armor.damageReduceAmount;
   this.armorMaterial =
       ReflectionHelper.getPrivateValue(
           ArmorMaterial.class, armor.getArmorMaterial(), "name", "field_179243_f");
 }
示例#2
0
 @Override
 public float getBlockHardness() {
   return ReflectionHelper.getPrivateValue(
       Block.class, Block.getBlockFromItem(stack.getItem()), "blockHardness");
 }
  @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;
              }
            }
          }
        }
      }
    }
  }
示例#4
0
 public int getSleepTimer(EntityPlayer player) {
   int timer = ReflectionHelper.getPrivateValue(EntityPlayer.class, player, 20);
   return timer;
 }