public void generateArchEW(World world, Random rand, BlockPos position) {
   int height = 3 + rand.nextInt(1);
   int width = 1 + rand.nextInt(2);
   for (int sides = 0; sides < height; sides++) {
     world.setBlockState(
         position.up(sides).north(width / 2), ModBlocks.frozenCobblestone.getDefaultState(), 3);
     world.setBlockState(
         position.up(sides).south(width / 2), ModBlocks.frozenCobblestone.getDefaultState(), 3);
   }
   for (int way = 0; way < width; way++) {
     world.setBlockState(
         position.up(height).south(way), ModBlocks.frozenCobblestone.getDefaultState(), 3);
   }
 }
예제 #2
0
  @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;
              }
            }
          }
        }
      }
    }
  }
  @Override
  public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
    if (worldIn.getGameRules().getBoolean("doFireTick")) {
      if (!canPlaceBlockAt(worldIn, pos)) worldIn.setBlockToAir(pos);

      if (worldIn.isRaining() && canDie(worldIn, pos)) worldIn.setBlockToAir(pos);
      else {
        int i = state.getValue(AGE).intValue();

        if (i < 4) {
          state = state.withProperty(AGE, Integer.valueOf(i + rand.nextInt(3) / 2));
          worldIn.setBlockState(pos, state, 4);
        }

        worldIn.scheduleUpdate(pos, this, tickRate(worldIn) + rand.nextInt(10));

        if (!canNeighborCatchFire(worldIn, pos)) {
          if (!worldIn.getBlockState(pos.down()).isSideSolid(worldIn, pos.down(), EnumFacing.UP)
              || i > 3) worldIn.setBlockToAir(pos);

          return;
        }

        if (!this.canCatchFire(worldIn, pos.down(), EnumFacing.UP)
            && i >= 4
            && rand.nextInt(4) == 0) {
          worldIn.setBlockToAir(pos);
          return;
        }

        boolean flag1 = worldIn.isBlockinHighHumidity(pos);
        int j = 0;

        if (flag1) j = -50;

        tryCatchFire(worldIn, pos.east(), 300 + j, rand, i, EnumFacing.WEST);
        tryCatchFire(worldIn, pos.west(), 300 + j, rand, i, EnumFacing.EAST);
        tryCatchFire(worldIn, pos.down(), 250 + j, rand, i, EnumFacing.UP);
        tryCatchFire(worldIn, pos.up(), 250 + j, rand, i, EnumFacing.DOWN);
        tryCatchFire(worldIn, pos.north(), 300 + j, rand, i, EnumFacing.SOUTH);
        tryCatchFire(worldIn, pos.south(), 300 + j, rand, i, EnumFacing.NORTH);

        for (int k = -1; k <= 1; ++k)
          for (int l = -1; l <= 1; ++l)
            for (int i1 = -1; i1 <= 4; ++i1)
              if (k != 0 || i1 != 0 || l != 0) {
                int j1 = 100;

                if (i1 > 1) j1 += (i1 - 1) * 100;

                BlockPos blockpos = pos.add(k, i1, l);
                int k1 = getNeighborEncouragement(worldIn, blockpos);

                if (k1 > 0) {
                  int l1 = (k1 + 40 + worldIn.getDifficulty().getDifficultyId() * 7) / (i + 30);

                  if (flag1) l1 /= 2;

                  if (l1 > 0
                      && rand.nextInt(j1) <= l1
                      && (!worldIn.isRaining() || !canDie(worldIn, blockpos))) {
                    int i2 = i + rand.nextInt(5) / 4;

                    if (i2 > 15) i2 = 15;

                    worldIn.setBlockState(
                        blockpos, state.withProperty(AGE, Integer.valueOf(i2)), 3);
                  }
                }
              }
      }
    }
  }
예제 #4
0
  @Override
  public boolean generate(World world, Random rand, BlockPos pos) {
    int i1 = rand.nextInt(2) + 2;
    int j1 = -i1 - 1;
    int k1 = i1 + 1;
    int i2 = rand.nextInt(2) + 2;
    int j2 = -i2 - 1;
    int k2 = i2 + 1;
    int count = 0;

    for (int x = j1; x <= k1; ++x) {
      for (int y = -1; y <= 4; ++y) {
        for (int z = j2; z <= k2; ++z) {
          BlockPos blockpos = pos.add(x, y, z);
          Material material = world.getBlockState(blockpos).getMaterial();
          boolean flag = material.isSolid();

          if (y == -1 && !flag) {
            return false;
          }

          if (y == 4 && !flag) {
            return false;
          }

          if ((x == j1 || x == k1 || z == j2 || z == k2)
              && y == 0
              && world.isAirBlock(blockpos)
              && world.isAirBlock(blockpos.up())) {
            ++count;
          }
        }
      }
    }

    if (count >= 1 && count <= 5) {
      int type = rand.nextInt(2);
      IBlockState state1;
      IBlockState state2;

      switch (type) {
        case 1:
          state1 = Blocks.STONEBRICK.getDefaultState();
          state2 =
              Blocks.STONEBRICK
                  .getDefaultState()
                  .withProperty(BlockStoneBrick.VARIANT, BlockStoneBrick.EnumType.MOSSY);
        default:
          state1 = Blocks.COBBLESTONE.getDefaultState();
          state2 = Blocks.MOSSY_COBBLESTONE.getDefaultState();
      }

      for (int x = j1; x <= k1; ++x) {
        for (int y = 3; y >= -1; --y) {
          for (int z = j2; z <= k2; ++z) {
            BlockPos blockpos = pos.add(x, y, z);

            if (x != j1 && y != -1 && z != j2 && x != k1 && y != 4 && z != k2) {
              if (world.getBlockState(blockpos).getBlock() != Blocks.CHEST) {
                world.setBlockToAir(blockpos);
              }
            } else if (blockpos.getY() >= 0
                && !world.getBlockState(blockpos.down()).getMaterial().isSolid()) {
              world.setBlockToAir(blockpos);
            } else if (world.getBlockState(blockpos).getMaterial().isSolid()
                && world.getBlockState(blockpos).getBlock() != Blocks.CHEST) {
              if (y == -1 && rand.nextInt(4) != 0) {
                world.setBlockState(blockpos, state2, 2);
              } else {
                world.setBlockState(blockpos, state1, 2);
              }
            }
          }
        }
      }

      for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 3; ++j) {
          int x = pos.getX() + rand.nextInt(i1 * 2 + 1) - i1;
          int y = pos.getY();
          int z = pos.getZ() + rand.nextInt(i2 * 2 + 1) - i2;
          BlockPos blockpos = new BlockPos(x, y, z);

          if (world.isAirBlock(blockpos)) {
            count = 0;

            for (EnumFacing face : EnumFacing.Plane.HORIZONTAL) {
              if (world.getBlockState(blockpos.offset(face)).getMaterial().isSolid()) {
                ++count;
              }
            }

            if (count == 1) {
              world.setBlockState(
                  blockpos,
                  Blocks.CHEST.correctFacing(world, blockpos, Blocks.CHEST.getDefaultState()),
                  2);

              TileEntity tile = world.getTileEntity(blockpos);

              if (tile != null && tile instanceof TileEntityChest) {
                ((TileEntityChest) tile)
                    .setLootTable(LootTableList.CHESTS_SIMPLE_DUNGEON, rand.nextLong());
              }

              break;
            }
          }
        }
      }

      world.setBlockState(pos, Blocks.MOB_SPAWNER.getDefaultState(), 2);

      TileEntity tile = world.getTileEntity(pos);

      if (tile != null && tile instanceof TileEntityMobSpawner) {
        ((TileEntityMobSpawner) tile).getSpawnerBaseLogic().setEntityName(pickMobSpawner(rand));
      } else {
        CaveLog.warning(
            "Failed to fetch mob spawner entity at ("
                + pos.getX()
                + ", "
                + pos.getY()
                + ", "
                + pos.getZ()
                + ")");
      }

      return true;
    }

    return false;
  }