@Override
 public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
   IBlockState soil = worldIn.getBlockState(pos.down());
   return super.canPlaceBlockAt(worldIn, pos)
       && soil.getBlock()
           .canSustainPlant(soil, worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this);
 }
 @Override
 protected void generateStalagmiteBase(World world, Random random, BlockPos botY, int aux) {
   if (world.getBlockState(botY.down()) == Blocks.stone)
     world.setBlockState(botY.down(), Blocks.sandstone.getDefaultState(), 2);
   super.generateStalagmiteBase(world, random, botY, aux);
   Utils.convertToSandType(world, random, botY);
 }
 public void generateStructures(World world, Random rand, BlockPos position, int radius) {
   for (int i = 0; radius >= 0 && i < 3; ++i) {
     int j = radius + rand.nextInt(2);
     int k = (radius + rand.nextInt(2));
     int l = radius + rand.nextInt(2);
     float f = (float) (j + k + l) * 0.333F + 0.5F;
     for (BlockPos blockpos :
         BlockPos.getAllInBox(position.add(-j, -k, -l), position.add(j, k, l))) {
       if (blockpos.distanceSq(position) <= (double) (f * f)
           && world.isAirBlock(blockpos)
           && world
               .getBlockState(blockpos.down())
               .getBlock()
               .getUnlocalizedName()
               .contains("frozen")) {
         int chance = rand.nextInt(100);
         if (chance < 4) {
           int chance2 = rand.nextInt(20);
           System.out.println(chance2);
           switch (chance2) {
             default:
               generateGoldPile(world, rand, blockpos);
               break;
             case 1:
               generateArchNS(world, rand, blockpos);
               break;
             case 2:
               generateArchEW(world, rand, blockpos);
               break;
           }
         }
       }
     }
   }
 }
  /**
   * returns whether or not there is dirt underneath the block where the tree will be grown. It also
   * generates dirt around the block in a 2x2 square if there is dirt underneath the blockpos.
   */
  private boolean ensureDirtsUnderneath(BlockPos pos, World worldIn) {
    BlockPos blockpos = pos.down();
    IBlockState state = worldIn.getBlockState(blockpos);
    boolean isSoil =
        state
            .getBlock()
            .canSustainPlant(
                state,
                worldIn,
                blockpos,
                net.minecraft.util.EnumFacing.UP,
                ((net.minecraft.block.BlockSapling) Blocks.SAPLING));

    if (isSoil && pos.getY() >= 2) {
      this.onPlantGrow(worldIn, blockpos, pos);
      this.onPlantGrow(worldIn, blockpos.east(), pos);
      this.onPlantGrow(worldIn, blockpos.south(), pos);
      this.onPlantGrow(worldIn, blockpos.south().east(), pos);
      return true;
    } else {
      return false;
    }
  }
  @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);
                  }
                }
              }
      }
    }
  }
Example #6
0
 public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
   return worldIn.getBlockState(pos.down()).getMaterial().isSolid()
       ? super.canPlaceBlockAt(worldIn, pos)
       : false;
 }
 public boolean canBlockStay(World world, BlockPos pos) {
   return world.getBlockState(pos.down()).isOpaqueCube();
 }
Example #8
0
  // Copied from vanila skull itemBlock. Relevant edits are indicated.
  @Nonnull
  @Override
  public EnumActionResult onItemUse(
      ItemStack stack,
      EntityPlayer playerIn,
      World worldIn,
      BlockPos pos,
      EnumHand hand,
      EnumFacing facing,
      float hitX,
      float hitY,
      float hitZ) {
    if (facing == EnumFacing.DOWN) {
      return EnumActionResult.FAIL;
    } else {
      if (worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos)) {
        facing = EnumFacing.UP;
        pos = pos.down();
      }
      IBlockState iblockstate = worldIn.getBlockState(pos);
      Block block = iblockstate.getBlock();
      boolean flag = block.isReplaceable(worldIn, pos);

      if (!flag) {
        if (!worldIn.getBlockState(pos).getMaterial().isSolid()
            && !worldIn.isSideSolid(pos, facing, true)) {
          return EnumActionResult.FAIL;
        }

        pos = pos.offset(facing);
      }

      if (playerIn.canPlayerEdit(pos, facing, stack)
          && Blocks.SKULL.canPlaceBlockAt(worldIn, pos)) {
        if (worldIn.isRemote) {
          return EnumActionResult.SUCCESS;
        } else {
          worldIn.setBlockState(
              pos,
              ModBlocks.gaiaHead.getDefaultState().withProperty(BlockSkull.FACING, facing),
              11); // Botania - skull -> gaia head
          int i = 0;

          if (facing == EnumFacing.UP) {
            i = MathHelper.floor_double(playerIn.rotationYaw * 16.0F / 360.0F + 0.5D) & 15;
          }

          TileEntity tileentity = worldIn.getTileEntity(pos);

          if (tileentity instanceof TileEntitySkull) {
            TileEntitySkull tileentityskull = (TileEntitySkull) tileentity;

            if (stack.getMetadata() == 3) // Botania - do not retrieve skins
            {
              /*GameProfile gameprofile = null;

              if (stack.hasTagCompound())
              {
              	NBTTagCompound nbttagcompound = stack.getTagCompound();

              	if (nbttagcompound.hasKey("SkullOwner", 10))
              	{
              		gameprofile = NBTUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("SkullOwner"));
              	}
              	else if (nbttagcompound.hasKey("SkullOwner", 8) && !nbttagcompound.getString("SkullOwner").isEmpty())
              	{
              		gameprofile = new GameProfile((UUID)null, nbttagcompound.getString("SkullOwner"));
              	}
              }

              tileentityskull.setPlayerProfile(gameprofile);*/
            } else {
              tileentityskull.setType(3); // Botania - Force type to 3 (humanoid)
            }

            tileentityskull.setSkullRotation(i);
            Blocks.SKULL.checkWitherSpawn(worldIn, pos, tileentityskull);
          }

          --stack.stackSize;
          return EnumActionResult.SUCCESS;
        }
      } else {
        return EnumActionResult.FAIL;
      }
    }
  }
  @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;
  }