protected void setBlockAndMetadata(World world, BlockPos pos, IBlockState stateNew) { IBlockState state = world.getBlockState(pos); Block block = state.getBlock(); if(block.isAir(state, world, pos) || block.canPlaceBlockAt(world, pos) || world.getBlockState(pos) == leaves) { world.setBlockState(pos, stateNew, 2); } } }
@Override public boolean isAirBlock( BlockPos pos ) { IBlockState state = this.getBlockState( pos ); return state.getBlock().isAir( state, this.world, pos ); }
protected void placeTrunk(World world, BlockPos pos, int height) { while(height >= 0) { IBlockState state = world.getBlockState(pos); Block block = state.getBlock(); if(block.isAir(state, world, pos) || block.isReplaceable(world, pos) || block.isLeaves(state, world, pos)) { this.setBlockAndMetadata(world, pos, log); } pos = pos.up(); height--; } }
public static boolean isBlockAir( final World w, final BlockPos pos ) { try { return w.getBlockState( pos ).getBlock().isAir( w.getBlockState( pos ), w, pos ); } catch( final Throwable e ) { return false; } }
@Override public boolean matches(World world, BlockPos pos) { IBlockState state = world.getBlockState(pos); return !state.getBlock().isAir(state, world, pos) && state.getCollisionBoundingBox(world, pos) != null; }
if(!state.getBlock().isAir(state, world, pos)) {
private boolean checkPosition(BlockPos pos, IBlockState state, boolean onlyCheckBlock) { BlockPos pos_ = getPos().add(pos); IBlockState stateat = world.getBlockState(pos_); Block blockat = stateat.getBlock(); if(state.getBlock() == Blocks.AIR ? blockat.isAir(stateat, world, pos_) : blockat == state.getBlock()) return onlyCheckBlock || stateat == state; return false; }
public boolean canEject() { IBlockState stateBelow = world.getBlockState(pos.down()); Block blockBelow = stateBelow.getBlock(); return blockBelow.isAir(stateBelow, world, pos.down()) || stateBelow.getCollisionBoundingBox(world, pos.down()) == null; }
void setBlockForGeneration(BlockPos pos, int gen, int prevGen) { World world = supertile.getWorld(); IBlockState stateAt = world.getBlockState(pos); Block blockAt = stateAt.getBlock(); TileEntity tile = world.getTileEntity(pos); if(gen == -2) { int val = Math.min(MAX_MANA_GENERATIONS, prevGen) * MANA_PER_GEN; mana = Math.min(getMaxMana(), mana + val); //world.setBlockToAir(x, y, z); } else if(blockAt == ModBlocks.cellBlock) { if(gen < 0) world.setBlockToAir(pos); else ((TileCell) tile).setGeneration(supertile, gen); } else if(gen >= 0 && blockAt.isAir(stateAt, supertile.getWorld(), pos)) { world.setBlockState(pos, ModBlocks.cellBlock.getDefaultState()); tile = world.getTileEntity(pos); ((TileCell) tile).setGeneration(supertile, gen); } }
@Override protected void onImpact(RayTraceResult pos) { if (world.isRemote) return; EntityLivingBase thrower = getThrower(); if(pos.entityHit != null && thrower != null && pos.entityHit != thrower && !pos.entityHit.isDead) { if(thrower instanceof EntityPlayer) pos.entityHit.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) thrower), Math.random() < 0.25 ? 10 : 5); else pos.entityHit.attackEntityFrom(DamageSource.GENERIC, Math.random() < 0.25 ? 10 : 5); } if (pos.getBlockPos() != null) { IBlockState state = world.getBlockState(pos.getBlockPos()); if(ConfigHandler.blockBreakParticles && !state.getBlock().isAir(state, world, pos.getBlockPos())) world.playEvent(2001, pos.getBlockPos(), Block.getStateId(state)); } setDead(); }
BlockPos pos_ = pos.offset(dir); Block block_ = world.getBlockState(pos_).getBlock(); if(block_.isAir(world.getBlockState(pos_), world, pos_) || block_.isReplaceable(world, pos_) || block_ instanceof BlockFlower && !(block_ instanceof ISpecialFlower) || block_ == Blocks.DOUBLE_PLANT) { airBlocks.add(pos_);
@Override protected void onImpact(@Nonnull RayTraceResult var1) { if(!world.isRemote) { if(var1 != null) { EnumFacing dir = var1.sideHit; if(dir != null && dir.getAxis() != EnumFacing.Axis.Y) { BlockPos pos = var1.getBlockPos().offset(dir); while(pos.getY() > 0) { IBlockState state = world.getBlockState(pos); Block block = state.getBlock(); if(block.isAir(state, world, pos)) { IBlockState stateSet = ModBlocks.solidVines.getDefaultState().withProperty(propMap.get(dir.getOpposite()), true); world.setBlockState(pos, stateSet, 1 | 2); world.playEvent(2001, pos, Block.getStateId(stateSet)); pos = pos.down(); } else break; } } } this.world.setEntityState(this, (byte)3); setDead(); } }
@Override public void onAvatarUpdate(IAvatarTile tile, ItemStack stack) { TileEntity te = (TileEntity) tile; World world = te.getWorld(); if(!world.isRemote && tile.getCurrentMana() >= COST && tile.getElapsedFunctionalTicks() % 4 == 0 && world.rand.nextInt(8) == 0 && tile.isEnabled()) { BlockPos pos = ((TileEntity) tile).getPos().offset(tile.getAvatarFacing()); IBlockState state = world.getBlockState(pos); if(state.getBlock().isAir(state, world, pos)) { world.setBlockState(pos, Blocks.DIRT.getDefaultState()); world.playEvent(2001, pos, Block.getStateId(Blocks.DIRT.getDefaultState())); tile.recieveMana(-COST); } } }
if(side != EnumFacing.DOWN && world.getBlockState(pos.up()).getBlock().isAir(world.getBlockState(pos.up()), world, pos.up()) && (block == Blocks.GRASS || block == Blocks.DIRT || block == Blocks.GRASS_PATH)) { Block block1 = Blocks.GRASS_PATH; if(block == block1)
public static void removeBlockWithDrops(EntityPlayer player, ItemStack stack, World world, BlockPos pos, Predicate<IBlockState> filter, boolean dispose, boolean particles) { if(!world.isBlockLoaded(pos)) return; IBlockState state = world.getBlockState(pos); Block block = state.getBlock(); if(!world.isRemote && filter.test(state) && !block.isAir(state, world, pos) && state.getPlayerRelativeBlockHardness(player, world, pos) > 0 && block.canHarvestBlock(player.world, pos, player)) { int exp = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) player).interactionManager.getGameType(), (EntityPlayerMP) player, pos); if(exp == -1) return; if(!player.capabilities.isCreativeMode) { TileEntity tile = world.getTileEntity(pos); if(block.removedByPlayer(state, world, pos, player, true)) { block.onPlayerDestroy(world, pos, state); if(!dispose || !ItemElementiumPick.isDisposable(block)) { block.harvestBlock(world, player, pos, state, tile, stack); block.dropXpOnBlockBreak(world, pos, exp); } } damageItem(stack, 1, player, 80); } else world.setBlockToAir(pos); if(particles && ConfigHandler.blockBreakParticles && ConfigHandler.blockBreakParticlesTool) world.playEvent(2001, pos, Block.getStateId(state)); } }
Block block1 = state1.getBlock(); if(player.world.getWorldBorder().contains(newPos) && (block1.isAir(state1, player.world, newPos) || block1.isReplaceable(player.world, newPos))) coords.add(newPos);
@Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, RayTraceResult rtr, boolean isManaBlock, boolean dead, ItemStack stack) { BlockPos coords = burst.getBurstSourceBlockPos(); BlockPos pos = rtr.getBlockPos(); if(!entity.world.isRemote && pos != null && !coords.equals(pos) && !burst.isFake() && !isManaBlock) { EnumFacing dir = rtr.sideHit; BlockPos offPos = pos.offset(dir); Block blockAt = entity.world.getBlockState(pos).getBlock(); Block blockAtOffset = entity.world.getBlockState(offPos).getBlock(); if(blockAt == Blocks.PORTAL) entity.world.setBlockState(pos, Blocks.AIR.getDefaultState()); if(blockAtOffset == Blocks.PORTAL) entity.world.setBlockState(offPos, Blocks.AIR.getDefaultState()); else if(blockAt == ModBlocks.incensePlate) { TileIncensePlate plate = (TileIncensePlate) entity.world.getTileEntity(pos); plate.ignite(); VanillaPacketDispatcher.dispatchTEToNearbyPlayers(plate); } else if(blockAtOffset.isAir(entity.world.getBlockState(offPos), entity.world, offPos)) entity.world.setBlockState(offPos, Blocks.FIRE.getDefaultState()); } return dead; }
public boolean exchange(World world, EntityPlayer player, BlockPos pos, ItemStack stack, IBlockState state) { TileEntity tile = world.getTileEntity(pos); if(tile != null) return false; ItemStack placeStack = removeFromInventory(player, stack, state.getBlock(), state.getBlock().getMetaFromState(state), false); if(!placeStack.isEmpty()) { IBlockState stateAt = world.getBlockState(pos); Block blockAt = stateAt.getBlock(); if(!blockAt.isAir(world.getBlockState(pos), world, pos) && stateAt.getPlayerRelativeBlockHardness(player, world, pos) > 0 && stateAt != state) { if(!world.isRemote) { world.destroyBlock(pos, !player.capabilities.isCreativeMode); if(!player.capabilities.isCreativeMode) { removeFromInventory(player, stack, state.getBlock(), state.getBlock().getMetaFromState(state), true); } world.setBlockState(pos, state, 1 | 2); state.getBlock().onBlockPlacedBy(world, pos, state, player, placeStack); } displayRemainderCounter(player, stack); return true; } } return false; }
@SubscribeEvent public static void onMinecartUpdate(MinecartUpdateEvent event) { BlockPos entPos = new BlockPos(event.getEntity()); IBlockState state = event.getEntity().world.getBlockState(entPos); Block block = state.getBlock(); boolean air = block.isAir(state, event.getEntity().world, entPos); int floatTicks = event.getEntity().getEntityData().getInteger(TAG_FLOAT_TICKS); if(block == ModBlocks.ghostRail) event.getEntity().getEntityData().setInteger(TAG_FLOAT_TICKS, 20); else if(block instanceof BlockRailBase || block == ModBlocks.dreamwood) { event.getEntity().getEntityData().setInteger(TAG_FLOAT_TICKS, 0); if(floatTicks > 0) event.getEntity().world.playEvent(2003, entPos, 0); } floatTicks = event.getEntity().getEntityData().getInteger(TAG_FLOAT_TICKS); if(floatTicks > 0) { IBlockState stateBelow = event.getEntity().world.getBlockState(entPos.down()); Block blockBelow = stateBelow.getBlock(); boolean airBelow = blockBelow.isAir(stateBelow, event.getEntity().world, entPos.down()); if(air && airBelow || !air && !airBelow) event.getEntity().noClip = true; event.getEntity().motionY = 0.2; event.getEntity().motionX *= 1.4; event.getEntity().motionZ *= 1.4; event.getEntity().getEntityData().setInteger(TAG_FLOAT_TICKS, floatTicks - 1); event.getEntity().world.playEvent(2000, entPos, 0); } else event.getEntity().noClip = false; }
@Override public boolean collideBurst(IManaBurst burst, EntityThrowable entity, RayTraceResult pos, boolean isManaBlock, boolean dead, ItemStack stack) { BlockPos coords = burst.getBurstSourceBlockPos(); if(!entity.world.isRemote && pos.getBlockPos() != null && !coords.equals(pos.getBlockPos()) && !burst.isFake() && !isManaBlock) { BlockPos pos_ = pos.getBlockPos().offset(pos.sideHit); Block blockAt = entity.world.getBlockState(pos.getBlockPos()).getBlock(); Block blockAt_ = entity.world.getBlockState(pos_).getBlock(); if(blockAt == ModBlocks.manaFlame) entity.world.setBlockState(pos.getBlockPos(), Blocks.AIR.getDefaultState()); else if(blockAt_.isAir(entity.world.getBlockState(pos_), entity.world, pos_) || blockAt_.isReplaceable(entity.world, pos_)) { entity.world.setBlockState(pos_, ModBlocks.manaFlame.getDefaultState()); TileEntity tile = entity.world.getTileEntity(pos_); if(tile instanceof TileManaFlame) ((TileManaFlame) tile).setColor(burst.getColor()); } } return dead; }