Java Code Examples for net.minecraft.world.World#getLightFromNeighbors()

The following examples show how to use net.minecraft.world.World#getLightFromNeighbors() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@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 Project: Sakura_mod   File: BlockPepperCrop.java    License: MIT License 6 votes vote down vote up
@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 3
Source Project: Sakura_mod   File: BlockVanillaCrop.java    License: MIT License 6 votes vote down vote up
@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 4
Source Project: Sakura_mod   File: BlockRiceCrop.java    License: MIT License 6 votes vote down vote up
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 5
Source Project: Sakura_mod   File: BlockHighCrop.java    License: MIT License 6 votes vote down vote up
@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 6
@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 7
Source Project: TofuCraftReload   File: BlockTofuTerrain.java    License: MIT License 5 votes vote down vote up
@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 8
Source Project: TofuCraftReload   File: BlockApricotSapling.java    License: MIT License 5 votes vote down vote up
@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 9
Source Project: TofuCraftReload   File: BlockTofuSapling.java    License: MIT License 5 votes vote down vote up
@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 10
Source Project: TFC2   File: BlockSapling.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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 11
Source Project: Sakura_mod   File: BlockGrapeVine.java    License: MIT License 5 votes vote down vote up
@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 12
Source Project: Sakura_mod   File: BlockGrapeLeaves.java    License: MIT License 5 votes vote down vote up
@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 13
Source Project: Sakura_mod   File: BlockMapleSaplingGreen.java    License: MIT License 5 votes vote down vote up
@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 Project: Sakura_mod   File: BlockSakuraSapling.java    License: MIT License 5 votes vote down vote up
@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 15
Source Project: AgriCraft   File: GrowthRequirement.java    License: MIT License 5 votes vote down vote up
@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 16
Source Project: Sakura_mod   File: BlockMapleSaplingRed.java    License: MIT License 5 votes vote down vote up
@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 17
Source Project: Sakura_mod   File: BlockMapleSaplingOrange.java    License: MIT License 5 votes vote down vote up
@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 18
Source Project: AgriCraft   File: LightHelper.java    License: MIT License 5 votes vote down vote up
@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 19
@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 20
Source Project: EmergingTechnology   File: PlantHelper.java    License: MIT License 4 votes vote down vote up
public static int getPlantLightAtPosition(World world, BlockPos position) {
    return world.getLightFromNeighbors(position.add(0, 1, 0));
}