Java Code Examples for net.minecraft.world.World#getLightFromNeighbors()
The following examples show how to use
net.minecraft.world.World#getLightFromNeighbors() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockTorikkiGrass.java From Wizardry with GNU Lesser General Public License v3.0 | 7 votes |
@Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (!worldIn.isRemote) { if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getLightOpacity(worldIn, pos.up()) > 2) { worldIn.setBlockState(pos, Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, DirtType.DIRT)); } else { if (worldIn.getLightFromNeighbors(pos.up()) >= 9) { for (int i = 0; i < 4; ++i) { BlockPos posAt = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1); IBlockState stateAt = worldIn.getBlockState(posAt); IBlockState stateAbove = worldIn.getBlockState(posAt.up()); if (Blocks.DIRT.equals(stateAt.getBlock()) && DirtType.DIRT.equals(stateAt.getValue(BlockDirt.VARIANT)) && worldIn.getLightFromNeighbors(posAt.up()) >= 4 && stateAbove.getLightOpacity(worldIn, posAt.up()) <= 2) { worldIn.setBlockState(posAt, this.getDefaultState()); } } } } } }
Example 2
Source File: BlockCrops.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
@Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { checkAndDropBlock(worldIn, pos, state); if (worldIn.getLightFromNeighbors(pos.up()) >= 9) { int i = this.getAge(state); if (i < this.getMaxAge()) { float f = getGrowthChance(this, worldIn, pos); int growthChance = (int) ((25.0F / f + 1) / content.growthFactor); boolean shouldGrow = rand.nextInt(Math.max(growthChance, 1)) == 0; if (net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, shouldGrow)) { worldIn.setBlockState(pos, this.withAge(i + 1), 2); net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos)); } } } }
Example 3
Source File: BlockPepperCrop.java From Sakura_mod with MIT License | 6 votes |
@Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (!worldIn.isAreaLoaded(pos, 1)) return; // Forge: prevent loading unloaded chunks when checking // neighbor's light if (worldIn.getLightFromNeighbors(pos.up()) >= 9) { int i = this.getAge(state); if (i >= 2 && worldIn.getBlockState(pos.up()).getBlock() == BlockLoader.PEPPER_SPLINT) worldIn.setBlockState(pos.up(), this.withAge(0), 2); if (i < this.getMaxAge()) { float f = getGrowthChance(this, worldIn, pos); if (net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt((int) (25.0F / f) + 1) == 0)) { worldIn.setBlockState(pos, this.withAge(i + 1), 2); net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos)); } } } super.updateTick(worldIn, pos, state, rand); }
Example 4
Source File: BlockVanillaCrop.java From Sakura_mod with MIT License | 6 votes |
@Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { super.updateTick(worldIn, pos, state, rand); if (!worldIn.isAreaLoaded(pos, 1)) return; // Forge: prevent loading unloaded chunks when checking // neighbor's light if (worldIn.getLightFromNeighbors(pos.up()) >= 9) { int i = this.getAge(state); if (i >= 2 && worldIn.getBlockState(pos.up()).getBlock() == BlockLoader.VANILLA_SPLINT) worldIn.setBlockState(pos.up(), this.withAge(0), 2); if (i < this.getMaxAge()) { float f = getGrowthChance(this, worldIn, pos); if (net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt((int) (25.0F / f) + 1) == 0)) { worldIn.setBlockState(pos, this.withAge(i + 1), 2); net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos)); } } } }
Example 5
Source File: BlockRiceCrop.java From Sakura_mod with MIT License | 6 votes |
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { this.checkAndDropBlock(worldIn, pos, state); if (!worldIn.isAreaLoaded(pos, 1)) return; // Forge: prevent loading unloaded chunks when checking neighbor's light if (worldIn.getLightFromNeighbors(pos.up()) >= 9) { int i = this.getAge(state); if (i < this.getMaxAge()) { float f = getRiceGrowthChance(this, worldIn, pos); if (net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt((int) (25.0F / f) + 1) == 0)) { worldIn.setBlockState(pos, this.withAge(i + 1), 2); net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos)); } } } }
Example 6
Source File: BlockHighCrop.java From Sakura_mod with MIT License | 6 votes |
@Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { super.updateTick(worldIn, pos, state, rand); if (!worldIn.isAreaLoaded(pos, 1)) return; // Forge: prevent loading unloaded chunks when checking neighbor's light if (worldIn.getLightFromNeighbors(pos.up()) >= 9) { int i = this.getAge(state); if (i >= 4 && worldIn.getBlockState(pos.down()).getBlock() == Blocks.FARMLAND &&worldIn.isAirBlock(pos.up())) worldIn.setBlockState(pos.up(), this.withAge(0), 2); if (i < this.getMaxAge()) { float f = getGrowthChance(this, worldIn, pos); if(net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt((int)(25.0F / f) + 1) == 0)) { worldIn.setBlockState(pos, this.withAge(i + 1), 2); net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos)); } } } }
Example 7
Source File: BlockMapleSaplingGreen.java From Sakura_mod with MIT License | 5 votes |
@Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (!worldIn.isRemote) { super.updateTick(worldIn, pos, state, rand); if (worldIn.getLightFromNeighbors(pos.up()) >= 0 && rand.nextInt(7) == 0) { this.grow(worldIn, rand, pos, state); } } }
Example 8
Source File: BlockGregSapling.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (!worldIn.isRemote) { super.updateTick(worldIn, pos, state, rand); if (!worldIn.isAreaLoaded(pos, 1)) return; if (worldIn.getLightFromNeighbors(pos.up()) >= 9 && rand.nextInt(7) == 0) { this.grow(worldIn, rand, pos, state); } } }
Example 9
Source File: LightHelper.java From AgriCraft with MIT License | 5 votes |
@Nonnull public static byte[] getLightData(@Nonnull World world, @Nonnull BlockPos pos) { // Validate Preconditions.checkNotNull(world); Preconditions.checkNotNull(pos); // Create the array. final byte lightData[] = new byte[LIGHT_METHOD_COUNT]; // Fill the array. lightData[0] = (byte) world.getLight(pos); lightData[1] = (byte) world.getLight(pos, false); lightData[2] = (byte) world.getLight(pos, true); lightData[3] = (byte) world.getLightFor(EnumSkyBlock.SKY, pos); lightData[4] = (byte) world.getLightFor(EnumSkyBlock.BLOCK, pos); lightData[5] = (byte) world.getLightFromNeighbors(pos); if (world.isRemote) { lightData[6] = (byte) world.getLightFromNeighborsFor(EnumSkyBlock.SKY, pos); lightData[7] = (byte) world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, pos); } else { lightData[6] = (byte) 0; lightData[7] = (byte) 0; } lightData[8] = (byte) world.getLightBrightness(pos); // Return the array. return lightData; }
Example 10
Source File: BlockMapleSaplingOrange.java From Sakura_mod with MIT License | 5 votes |
@Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (!worldIn.isRemote) { super.updateTick(worldIn, pos, state, rand); if (worldIn.getLightFromNeighbors(pos.up()) >= 0 && rand.nextInt(7) == 0) { this.grow(worldIn, rand, pos, state); } } }
Example 11
Source File: BlockMapleSaplingRed.java From Sakura_mod with MIT License | 5 votes |
@Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (!worldIn.isRemote) { super.updateTick(worldIn, pos, state, rand); if (worldIn.getLightFromNeighbors(pos.up()) >= 0 && rand.nextInt(7) == 0) { this.grow(worldIn, rand, pos, state); } } }
Example 12
Source File: GrowthRequirement.java From AgriCraft with MIT License | 5 votes |
@Override public boolean hasValidLight(@Nonnull World world, @Nonnull BlockPos pos) { // Validate Preconditions.checkNotNull(world); Preconditions.checkNotNull(pos); // Determine the light level of the block, as per the vanilla method used in BlockCrop. final int light = world.getLightFromNeighbors(pos.up()); // Determine if the light level is in the proper range. return light >= this.getMinLight() && light <= this.getMaxLight(); }
Example 13
Source File: BlockSakuraSapling.java From Sakura_mod with MIT License | 5 votes |
@Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (!worldIn.isRemote) { super.updateTick(worldIn, pos, state, rand); if (worldIn.getLightFromNeighbors(pos.up()) >= 0 && rand.nextInt(7) == 0) { this.grow(worldIn, rand, pos, state); } } }
Example 14
Source File: BlockTofuTerrain.java From TofuCraftReload with MIT License | 5 votes |
@Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (!worldIn.isRemote && worldIn.getBlockState(pos) == BlockLoader.zundatofuTerrain.getDefaultState()) { if (!worldIn.isAreaLoaded(pos, 3)) return; // Forge: prevent loading unloaded chunks when checking neighbor's light and spreading if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getLightOpacity(worldIn, pos.up()) > 2) { worldIn.setBlockState(pos, BlockLoader.tofuTerrain.getDefaultState()); } else { if (worldIn.getLightFromNeighbors(pos.up()) >= 9) { for (int i = 0; i < 4; ++i) { BlockPos blockpos = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1); if (blockpos.getY() >= 0 && blockpos.getY() < 256 && !worldIn.isBlockLoaded(blockpos)) { return; } IBlockState iblockstate = worldIn.getBlockState(blockpos.up()); IBlockState iblockstate1 = worldIn.getBlockState(blockpos); if ((iblockstate1.getBlock() == BlockLoader.tofuTerrain || iblockstate1.getBlock() == BlockLoader.KINUTOFU) && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && iblockstate.getLightOpacity(worldIn, pos.up()) <= 2) { worldIn.setBlockState(blockpos, BlockLoader.zundatofuTerrain.getDefaultState()); } } } } } }
Example 15
Source File: BlockGrapeLeaves.java From Sakura_mod with MIT License | 5 votes |
@Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { super.updateTick(worldIn, pos, state, rand); if (!worldIn.isAreaLoaded(pos, 1)) return; // Forge: prevent loading unloaded chunks when checking // neighbor's light if (worldIn.getLightFromNeighbors(pos.up()) >= 9) { int i = this.getAge(state); if (i >= 2 && worldIn.getBlockState(pos.east()).getBlock() == BlockLoader.GRAPE_SPLINT) worldIn.setBlockState(pos.east(), this.withAge(0), 2); if (i >= 2 && worldIn.getBlockState(pos.north()).getBlock() == BlockLoader.GRAPE_SPLINT) worldIn.setBlockState(pos.north(), this.withAge(0), 2); if (i >= 2 && worldIn.getBlockState(pos.west()).getBlock() == BlockLoader.GRAPE_SPLINT) worldIn.setBlockState(pos.west(), this.withAge(0), 2); if (i >= 2 && worldIn.getBlockState(pos.south()).getBlock() == BlockLoader.GRAPE_SPLINT) worldIn.setBlockState(pos.south(), this.withAge(0), 2); if (i < this.getMaxAge()) { float f = getGrowthChance(this, worldIn, pos); if (net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt((int) (25.0F / f) + 1) == 0)) { worldIn.setBlockState(pos, this.withAge(i + 1), 2); net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos)); } } } }
Example 16
Source File: BlockGrapeVine.java From Sakura_mod with MIT License | 5 votes |
@Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { super.updateTick(worldIn, pos, state, rand); if (!worldIn.isAreaLoaded(pos, 1)) return; // Forge: prevent loading unloaded chunks when checking // neighbor's light if (worldIn.getLightFromNeighbors(pos.up()) >= 9) { int i = this.getAge(state); if (i >= 2 && worldIn.getBlockState(pos.up()).getBlock() == BlockLoader.GRAPE_SPLINT_STAND) worldIn.setBlockState(pos.up(), this.withAge(0), 2); if (i >= 5 && worldIn.getBlockState(pos.east()).getBlock() == BlockLoader.GRAPE_SPLINT) worldIn.setBlockState(pos.east(), BlockLoader.GRAPE_LEAVES.withAge(0), 2); if (i >= 5 && worldIn.getBlockState(pos.north()).getBlock() == BlockLoader.GRAPE_SPLINT) worldIn.setBlockState(pos.north(), BlockLoader.GRAPE_LEAVES.withAge(0), 2); if (i >= 5 && worldIn.getBlockState(pos.west()).getBlock() == BlockLoader.GRAPE_SPLINT) worldIn.setBlockState(pos.west(), BlockLoader.GRAPE_LEAVES.withAge(0), 2); if (i >= 5 && worldIn.getBlockState(pos.south()).getBlock() == BlockLoader.GRAPE_SPLINT) worldIn.setBlockState(pos.south(), BlockLoader.GRAPE_LEAVES.withAge(0), 2); if (i < this.getMaxAge()) { float f = getGrowthChance(this, worldIn, pos); if (net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, pos, state, rand.nextInt((int) (25.0F / f) + 1) == 0)) { worldIn.setBlockState(pos, this.withAge(i + 1), 2); net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos)); } } } }
Example 17
Source File: BlockSapling.java From TFC2 with GNU General Public License v3.0 | 5 votes |
@Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (!worldIn.isRemote) { super.updateTick(worldIn, pos, state, rand); if (worldIn.getLightFromNeighbors(pos.up()) >= 9 && rand.nextInt(7) == 0) { this.grow(worldIn, rand, pos, state); } } }
Example 18
Source File: BlockTofuSapling.java From TofuCraftReload with MIT License | 5 votes |
@Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (!worldIn.isRemote) { super.updateTick(worldIn, pos, state, rand); if (worldIn.getLightFromNeighbors(pos.up()) >= 0 && rand.nextInt(7) == 0) { this.grow(worldIn, rand, pos, state); } } }
Example 19
Source File: BlockApricotSapling.java From TofuCraftReload with MIT License | 5 votes |
@Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (!worldIn.isRemote) { super.updateTick(worldIn, pos, state, rand); if (worldIn.getLightFromNeighbors(pos.up()) >= 0 && rand.nextInt(7) == 0) { this.grow(worldIn, rand, pos, state); } } }
Example 20
Source File: PlantHelper.java From EmergingTechnology with MIT License | 4 votes |
public static int getPlantLightAtPosition(World world, BlockPos position) { return world.getLightFromNeighbors(position.add(0, 1, 0)); }