protected int calculateInputStrength(World worldIn, BlockPos pos, IBlockState state) { int i = super.calculateInputStrength(worldIn, pos, state); EnumFacing enumfacing = (EnumFacing) state.getValue(FACING); BlockPos blockpos = pos.offset(enumfacing); IBlockState iblockstate = worldIn.getBlockState(blockpos); if (iblockstate.hasComparatorInputOverride()) { i = iblockstate.getComparatorInputOverride(worldIn, blockpos); } else if (i < 15 && iblockstate.isNormalCube()) { blockpos = blockpos.offset(enumfacing); iblockstate = worldIn.getBlockState(blockpos); if (iblockstate.hasComparatorInputOverride()) { i = iblockstate.getComparatorInputOverride(worldIn, blockpos); } else if (iblockstate.getMaterial() == Material.AIR) { EntityItemFrame entityitemframe = this.findItemFrame(worldIn, enumfacing, blockpos); if (entityitemframe != null) { i = entityitemframe.getAnalogOutput(); } } } return i; }
@Override public void processBlockWithinRadius( Spellcast cast, BlockPos blockPos, IBlockState currentState, float r, @Nullable RayTraceResult mop) { if (mop != null) { blockPos = blockPos.offset(mop.sideHit); currentState = cast.world.getBlockState(blockPos); } Block block = currentState.getBlock(); if (block == Blocks.AIR) { if (spawnSourceBlocks) { cast.world.setBlockState( blockPos, Blocks.FLOWING_WATER.getDefaultState().withProperty(BlockDynamicLiquid.LEVEL, 0)); } else { cast.world.setBlockState( blockPos, Blocks.FLOWING_WATER.getDefaultState().withProperty(BlockDynamicLiquid.LEVEL, 15)); } } }
private void runThroughNetwork(BlockPos pos) { for (EnumFacing facing : EnumFacing.values()) { BlockPos searchPos = pos.offset(facing); if (worldObj.getTileEntity(pos) instanceof INetworkPart && !((INetworkPart) worldObj.getTileEntity(pos)).getNeighborFaces().contains(facing)) continue; if (worldObj.getTileEntity(searchPos) instanceof INetworkPart && !((INetworkPart) worldObj.getTileEntity(searchPos)) .getNeighborFaces() .contains(facing.getOpposite())) continue; if (!getWorld().isAirBlock(searchPos)) { TileEntity tile = getWorld().getTileEntity(searchPos); if (tile != null) { if (tile instanceof TileNetworkCore && !tile.getPos().equals(this.pos)) { worldObj.setBlockToAir(searchPos); worldObj.playEvent(2001, searchPos, Block.getIdFromBlock(Registry.networkCore)); StackHelper.spawnItemStack(worldObj, searchPos, new ItemStack(Registry.networkCore)); markForNetworkInit(); } else if (tile instanceof INetworkPart && !network.networkParts.contains(tile)) { network.addPart((INetworkPart) tile); } else if (InvHelper.hasItemHandler(tile, facing.getOpposite()) && !network.networkParts.contains( InvHelper.getItemHandler(tile, facing.getOpposite()))) { network.addPart( new InventoryNetworkPart( tile.getWorld(), searchPos, InvHelper.getItemHandler(tile, facing.getOpposite()))); } else continue; runThroughNetwork(searchPos); } } } }
private int getNeighborEncouragement(World worldIn, BlockPos pos) { if (!worldIn.isAirBlock(pos)) return 0; else { int i = 0; for (EnumFacing enumfacing : EnumFacing.values()) i = Math.max( worldIn .getBlockState(pos.offset(enumfacing)) .getBlock() .getFlammability(worldIn, pos.offset(enumfacing), enumfacing.getOpposite()), i); return i; } }
/** * Gets a list of all capabilities that touch a BlockPos. This will search for tile entities * touching the BlockPos and then query them for access to their capabilities. * * @param capability The capability you want to retrieve. * @param world The world that this is happening in. * @param pos The position to search around. * @return A list of all capabilities that are being held by connected blocks. */ public static <T> List<T> getConnectedCapabilities( Capability<T> capability, World world, BlockPos pos) { final List<T> capabilities = new ArrayList<T>(); for (final EnumFacing side : EnumFacing.values()) { final TileEntity tile = world.getTileEntity(pos.offset(side)); if (tile != null && !tile.isInvalid() && tile.hasCapability(capability, side.getOpposite())) capabilities.add(tile.getCapability(capability, side.getOpposite())); } return capabilities; }
private boolean canNeighborCatchFire(World worldIn, BlockPos pos) { for (EnumFacing enumfacing : EnumFacing.values()) if (this.canCatchFire(worldIn, pos.offset(enumfacing), enumfacing.getOpposite())) return true; return false; }
// 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; }