for(int k = 2; k >= -2; k--) { BlockPos pos_ = pos.add(i + 1, k + 1, j + 1); if(world.isAirBlock(pos_) && (!world.provider.isNether() || pos_.getY() < 255) && ModBlocks.flower.canPlaceBlockAt(world, pos_)) validCoords.add(pos_);
@Nonnull @Override public ItemStack dispenseStack(IBlockSource par1IBlockSource, ItemStack par2ItemStack) { EnumFacing facing = par1IBlockSource.getBlockState().getValue(BlockDispenser.FACING); BlockPos pos = par1IBlockSource.getBlockPos().offset(facing); World world = par1IBlockSource.getWorld(); if(world.isAirBlock(pos) && block.canPlaceBlockAt(world, pos)) { world.setBlockState(pos, block.getDefaultState()); par2ItemStack.shrink(1); return par2ItemStack; } return super.dispenseStack(par1IBlockSource, par2ItemStack); }
int z1 = z + event.getRand().nextInt(dist * 2) - dist; BlockPos pos2 = new BlockPos(x1, y1, z1); if(event.getWorld().isAirBlock(pos2) && (!event.getWorld().provider.isNether() || y1 < 127) && ModBlocks.flower.canPlaceBlockAt(event.getWorld(), pos2)) { event.getWorld().setBlockState(pos2, ModBlocks.flower.getDefaultState().withProperty(BotaniaStateProps.COLOR, color), 2); if(event.getRand().nextDouble() < ConfigHandler.flowerTallChance && ((BlockModFlower) ModBlocks.flower).canGrow(event.getWorld(), pos2, event.getWorld().getBlockState(pos2), false)) BlockPos pos3 = new BlockPos(x, y, z); EnumDyeColor color = EnumDyeColor.byMetadata(event.getRand().nextInt(16)); if(event.getWorld().isAirBlock(pos3) && ModBlocks.mushroom.canPlaceBlockAt(event.getWorld(), pos3)) event.getWorld().setBlockState(pos3, ModBlocks.mushroom.getDefaultState().withProperty(BotaniaStateProps.COLOR, color), 2);
@Nonnull @Override public ItemStack dispenseStack(IBlockSource par1IBlockSource, ItemStack par2ItemStack) { if(par2ItemStack.getItemDamage() == EnumDyeColor.BROWN.getDyeDamage()) { Block block = Blocks.COCOA; EnumFacing facing = par1IBlockSource.getBlockState().getValue(BlockDispenser.FACING); BlockPos pos = par1IBlockSource.getBlockPos().offset(facing); World world = par1IBlockSource.getWorld(); BlockPos logPos = pos.offset(facing); IBlockState logState = world.getBlockState(logPos); if(logState.getBlock() == Blocks.LOG && logState.getValue(BlockOldLog.VARIANT) == BlockPlanks.EnumType.JUNGLE && world.isAirBlock(pos) && block.canPlaceBlockAt(world, pos)) { world.setBlockState(pos, block.getDefaultState().withProperty(BlockHorizontal.FACING, facing)); par2ItemStack.shrink(1); return par2ItemStack; } } return vanillaBehaviour.dispense(par1IBlockSource, par2ItemStack); }
@Override public void onUpdate() { super.onUpdate(); if(supertile.getWorld().isRemote || redstoneSignal > 0) return; if(ticksExisted % 30 == 0 && mana >= COST) { BlockPos pos = new BlockPos( supertile.getPos().getX() - RANGE + supertile.getWorld().rand.nextInt(RANGE * 2 + 1), supertile.getPos().getY() + RANGE, supertile.getPos().getZ() - RANGE + supertile.getWorld().rand.nextInt(RANGE * 2 + 1) ); BlockPos up = pos.up(); for(int i = 0; i < RANGE * 2; i++) { IBlockState stateAbove = supertile.getWorld().getBlockState(up); Block blockAbove = stateAbove.getBlock(); if((supertile.getWorld().isAirBlock(up) || blockAbove.isReplaceable(supertile.getWorld(), up)) && stateAbove.getMaterial() != Material.WATER && ModBlocks.flower.canPlaceBlockAt(supertile.getWorld(), up)) { EnumDyeColor color = EnumDyeColor.byMetadata(supertile.getWorld().rand.nextInt(16)); IBlockState state = ModBlocks.flower.getDefaultState().withProperty(BotaniaStateProps.COLOR, color); if(ConfigHandler.blockBreakParticles) supertile.getWorld().playEvent(2001, up, Block.getStateId(state)); supertile.getWorld().setBlockState(up, state, 1 | 2); mana -= COST; sync(); break; } up = pos; pos = pos.down(); } } }
if(stateToPlace.getBlock().canPlaceBlockAt(supertile.getWorld(), coords)) { supertile.getWorld().setBlockState(coords, stateToPlace, 1 | 2); if(ConfigHandler.blockBreakParticles)
@Override public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) { if (!plantedState.getBlock().canPlaceBlockAt(world, pos)) { return false; } return BlockUtil.setBlockWithPlaceSound(world, pos, plantedState); }
@Override public boolean canPlaceBlockAt(World worldIn, BlockPos pos) { return super.canPlaceBlockAt(worldIn, pos) && canBePlacedOn(worldIn, pos.add(0, -1, 0)); }
private static boolean tryPlant(IBlockState toPlant, World world, BlockPos pos) { if (toPlant.getBlock().canPlaceBlockAt(world, pos)) { world.setBlockState(pos, toPlant); return true; } return false; }
@Override public boolean generate(World world, Random rand, BlockPos pos) { for (int attempt = 0; attempt < 300; ++attempt) { int xx = rand.nextInt(8) - rand.nextInt(8); int yy = rand.nextInt(4) - rand.nextInt(4); int zz = rand.nextInt(8) - rand.nextInt(8); if (world.isAirBlock(pos.add(xx, yy, zz)) && ModBlocks.ALGAE.canPlaceBlockAt(world, pos.add(xx, yy, zz))) world.setBlockState(pos.add(xx, yy, zz), ModBlocks.ALGAE.getDefaultState(), 2); } return true; } }
protected boolean canPlant(@Nonnull IFarmer farm, @Nonnull World world, @Nonnull BlockPos bc, @Nonnull IPlantable plantable) { IBlockState target = getPlant(farm, plantable); BlockPos groundPos = bc.down(); IBlockState groundBS = world.getBlockState(groundPos); Block ground = groundBS.getBlock(); if (target != null && target.getBlock().canPlaceBlockAt(world, bc) && ground.canSustainPlant(groundBS, world, groundPos, EnumFacing.UP, plantable)) { return true; } return false; }
@Override public boolean generate(World world, Random rng, BlockPos start) { for (int i = 0; i < 32; ++i) { BlockPos pos = start.add(rng.nextInt(8) - rng.nextInt(8), rng.nextInt(4) - rng.nextInt(4), rng.nextInt(8) - rng.nextInt(8)); if (!world.isAirBlock(pos) && !pumpkin.canPlaceBlockAt(world, pos)) continue; if (!BlocksTFC.isSoil(world.getBlockState(pos.add(0, -1, 0)))) continue; world.setBlockState(pos, pumpkin.getDefaultState().withProperty(BlockPumpkin.FACING, EnumFacing.Plane.HORIZONTAL.random(rng)), 2); } return true; } }
protected boolean canPlant(@Nonnull IFarmer farm, @Nonnull World world, @Nonnull BlockPos bc) { Block target = getPlantedBlock(); BlockPos groundPos = bc.down(); IBlockState bs = world.getBlockState(groundPos); Block ground = bs.getBlock(); IPlantable plantable = (IPlantable) getPlantedBlock(); if (target.canPlaceBlockAt(world, bc) && (ground.canSustainPlant(bs, world, groundPos, EnumFacing.UP, plantable) || ignoreSustainCheck) && (!isCheckGroundForFarmland() || isGroundTilled(farm, bc))) { return true; } return false; }
@Override public boolean canPlaceBlockAt(World world, BlockPos pos) { IBlockState below = world.getBlockState(pos.down()); return super.canPlaceBlockAt(world, pos) && this.canBlockStay(world, pos) && (below.isFullCube()); }
final boolean canMultiPartBePlaced = maybeMultiPartBlock.get().canPlaceBlockAt( world, te_pos );
@Override protected void placeFootprintBlock(EntityTameableDragon dragon, BlockPos blockPos) { // place snow layer blocks, but only if the biome is cold enough World world = dragon.worldObj; if (world.getBiome(blockPos).getFloatTemperature(blockPos) > 0.8f) { return; } Block footprint = Blocks.SNOW_LAYER; if (!footprint.canPlaceBlockAt(world, blockPos)) { return; } world.setBlockState(blockPos, footprint.getDefaultState()); }
public boolean placeBlockAtTested(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, IBlockState newState) { return player.canPlayerEdit(pos, facing, stack) && world.getBlockState(pos).getBlock().isReplaceable(world, pos) && block.canPlaceBlockAt(world, pos) && block.canPlaceBlockOnSide(world, pos, facing) && super.placeBlockAt(stack, player, world, pos, facing, hitX, hitY, hitZ, newState); }
@Override public ItemStack dispenseStack(IBlockSource par1IBlockSource, ItemStack par2ItemStack) { EnumFacing facing = par1IBlockSource.getBlockState().getValue(BlockDispenser.FACING); BlockPos pos = par1IBlockSource.getBlockPos().offset(facing); World world = par1IBlockSource.getWorld(); if(world.isAirBlock(pos) && placeState.getBlock().canPlaceBlockAt(world, pos)) { world.setBlockState(pos, placeState); par2ItemStack.shrink(1); return par2ItemStack; } return super.dispenseStack(par1IBlockSource, par2ItemStack); }
private boolean canSnowAt(BlockPos pos) { if (!world.isAirBlock(pos) && !world.isAirBlock(pos.add(0, -1, 0)) && !SNOW.getBlock().canPlaceBlockAt(world, pos)) return false; if (ClimateTFC.getHeightAdjustedTemp(world, pos) >= 0F) return false; if (world.getLightFor(EnumSkyBlock.BLOCK, pos) < 10 /* todo: why? && CalenderTFC.getTotalMonths() < 1*/) return false; return world.getBlockState(pos.add(0, -1, 0)).getMaterial().blocksMovement(); }
@Override public void place(World world, BlockPos pos, Rotation rotation) { setWorld(world); BlockPos start = pos.add(RotationUtil.x(rotation, -offX, -offZ), -offY, RotationUtil.z(rotation, -offX, -offZ)); for(int x = 0; x < sizeX; x++) for(int y = 0; y < sizeY; y++) for(int z = 0; z < sizeZ; z++) { BlockPos placePos = start.add(RotationUtil.x(rotation, x, z), y, RotationUtil.z(rotation, x, z)); IBlockState targetState = stateTargets[x][y][z].getDisplayedState().withRotation(rotation); Block targetBlock = targetState.getBlock(); if(!targetBlock.isAir(targetState, world, placePos) && targetBlock.canPlaceBlockAt(world, placePos) && world.getBlockState(placePos).getBlock().isReplaceable(world, placePos)) world.setBlockState(placePos, targetState); } }