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

The following are Jave code examples for showing how to use getLightFromNeighbors() of the net.minecraft.world.World class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: genera   File: BlockGeneraCrop.java   View Source Code Vote up 6 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    super.updateTick(worldIn, pos, state, rand);

    if (worldIn.getLightFromNeighbors(pos.up()) >= 1)
    {
        int i = state.getValue(AGE);

        if (i < 2)
        {
            float f = getGrowthChance(this, worldIn, pos);

            if (rand.nextInt((int)(25.0F / f) + 1) == 0)
            {
                worldIn.setBlockState(pos, state.withProperty(AGE, i + 1), 2);
            }
        }
    }
}
 
Example 2
Project: uniquecrops   File: Collis.java   View Source Code Vote up 6 votes
private void checkHighplant(World world, BlockPos pos, IBlockState state, int age) {
	
	int chanceByHeight = Math.round(pos.getY() / 16);
	
	if (world.getLightFromNeighbors(pos.up()) >= 9) {
		if (age < ((BlockCrops)state.getBlock()).getMaxAge() && world.rand.nextInt(16 - chanceByHeight) == 0) {
			world.setBlockState(pos, ((BlockCrops)state.getBlock()).withAge(age + 1));
		}
	}
}
 
Example 3
Project: BaseClient   File: BlockCrops.java   View Source Code Vote up 6 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    super.updateTick(worldIn, pos, state, rand);

    if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
    {
        int i = ((Integer)state.getValue(AGE)).intValue();

        if (i < 7)
        {
            float f = getGrowthChance(this, worldIn, pos);

            if (rand.nextInt((int)(25.0F / f) + 1) == 0)
            {
                worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(i + 1)), 2);
            }
        }
    }
}
 
Example 4
Project: DecompiledMinecraft   File: BlockCrops.java   View Source Code Vote up 6 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    super.updateTick(worldIn, pos, state, rand);

    if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
    {
        int i = ((Integer)state.getValue(AGE)).intValue();

        if (i < 7)
        {
            float f = getGrowthChance(this, worldIn, pos);

            if (rand.nextInt((int)(25.0F / f) + 1) == 0)
            {
                worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(i + 1)), 2);
            }
        }
    }
}
 
Example 5
Project: BaseClient   File: BlockCrops.java   View Source Code Vote up 6 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    super.updateTick(worldIn, pos, state, rand);

    if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
    {
        int i = ((Integer)state.getValue(AGE)).intValue();

        if (i < 7)
        {
            float f = getGrowthChance(this, worldIn, pos);

            if (rand.nextInt((int)(25.0F / f) + 1) == 0)
            {
                worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(i + 1)), 2);
            }
        }
    }
}
 
Example 6
Project: Firma   File: SparseGrassBlock.java   View Source Code Vote up 5 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,Util.getDirt(state));
           }
           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 (Util.isDirt(iblockstate1.getBlock()) && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && iblockstate.getLightOpacity(worldIn, pos.up()) <= 2)
                       {
                           worldIn.setBlockState(blockpos, Util.getGrass(iblockstate1));
                       }
                   }
               }
           }
       }
   }
 
Example 7
Project: Firma   File: GrassBlock2.java   View Source Code Vote up 5 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,Util.getDirt(state));
           }
           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 (Util.isDirt(iblockstate1.getBlock()) && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && iblockstate.getLightOpacity(worldIn, pos.up()) <= 2)
                       {
                           worldIn.setBlockState(blockpos, Util.getGrass(iblockstate1));
                       }
                   }
               }
           }
       }
   }
 
Example 8
Project: BaseClient   File: BlockStem.java   View Source Code Vote up 5 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
	super.updateTick(worldIn, pos, state, rand);

	if (worldIn.getLightFromNeighbors(pos.up()) >= 9) {
		float f = BlockCrops.getGrowthChance(this, worldIn, pos);

		if (rand.nextInt((int) (25.0F / f) + 1) == 0) {
			int i = ((Integer) state.getValue(AGE)).intValue();

			if (i < 7) {
				state = state.withProperty(AGE, Integer.valueOf(i + 1));
				worldIn.setBlockState(pos, state, 2);
			} else {
				for (Object enumfacing0 : EnumFacing.Plane.HORIZONTAL) {
					EnumFacing enumfacing = (EnumFacing) enumfacing0;
					if (worldIn.getBlockState(pos.offset(enumfacing)).getBlock() == this.crop) {
						return;
					}
				}

				pos = pos.offset(EnumFacing.Plane.HORIZONTAL.random(rand));
				Block block = worldIn.getBlockState(pos.down()).getBlock();

				if (worldIn.getBlockState(pos).getBlock().blockMaterial == Material.air
						&& (block == Blocks.farmland || block == Blocks.dirt || block == Blocks.grass)) {
					worldIn.setBlockState(pos, this.crop.getDefaultState());
				}
			}
		}
	}
}
 
Example 9
Project: BaseClient   File: BlockGrass.java   View Source Code Vote up 5 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (!worldIn.isRemote)
    {
        if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getBlock().getLightOpacity() > 2)
        {
            worldIn.setBlockState(pos, Blocks.dirt.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);
                    Block block = worldIn.getBlockState(blockpos.up()).getBlock();
                    IBlockState iblockstate = worldIn.getBlockState(blockpos);

                    if (iblockstate.getBlock() == Blocks.dirt && iblockstate.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && block.getLightOpacity() <= 2)
                    {
                        worldIn.setBlockState(blockpos, Blocks.grass.getDefaultState());
                    }
                }
            }
        }
    }
}
 
Example 10
Project: Backmemed   File: BlockFrostedIce.java   View Source Code Vote up 5 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if ((rand.nextInt(3) == 0 || this.countNeighbors(worldIn, pos) < 4) && worldIn.getLightFromNeighbors(pos) > 11 - ((Integer)state.getValue(AGE)).intValue() - state.getLightOpacity())
    {
        this.slightlyMelt(worldIn, pos, state, rand, true);
    }
    else
    {
        worldIn.scheduleUpdate(pos, this, MathHelper.getInt(rand, 20, 40));
    }
}
 
Example 11
Project: DecompiledMinecraft   File: BlockGrass.java   View Source Code Vote up 5 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (!worldIn.isRemote)
    {
        if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getBlock().getLightOpacity() > 2)
        {
            worldIn.setBlockState(pos, Blocks.dirt.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);
                    Block block = worldIn.getBlockState(blockpos.up()).getBlock();
                    IBlockState iblockstate = worldIn.getBlockState(blockpos);

                    if (iblockstate.getBlock() == Blocks.dirt && iblockstate.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && block.getLightOpacity() <= 2)
                    {
                        worldIn.setBlockState(blockpos, Blocks.grass.getDefaultState());
                    }
                }
            }
        }
    }
}
 
Example 12
Project: Genesis   File: BlockGenesisSapling.java   View Source Code Vote up 5 votes
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random random) {
    if (!world.isRemote) {
        checkAndDropBlock(world, pos, state);
        if (world.getLightFromNeighbors(pos.up()) >= 9 && random.nextInt(7) == 0) {
            grow(world, pos, state, random);
        }
    }
}
 
Example 13
Project: Got-Wood   File: BlockWoodSapling.java   View Source Code Vote up 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, pos, state, rand);
		}
	}
}
 
Example 14
Project: CustomWorldGen   File: BlockFrostedIce.java   View Source Code Vote up 5 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if ((rand.nextInt(3) == 0 || this.countNeighbors(worldIn, pos) < 4) && worldIn.getLightFromNeighbors(pos) > 11 - ((Integer)state.getValue(AGE)).intValue() - state.getLightOpacity())
    {
        this.slightlyMelt(worldIn, pos, state, rand, true);
    }
    else
    {
        worldIn.scheduleUpdate(pos, this, MathHelper.getRandomIntegerInRange(rand, 20, 40));
    }
}
 
Example 15
Project: DecompiledMinecraft   File: BlockMycelium.java   View Source Code Vote up 5 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (!worldIn.isRemote)
    {
        if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getBlock().getLightOpacity() > 2)
        {
            worldIn.setBlockState(pos, Blocks.dirt.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT));
        }
        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);
                    IBlockState iblockstate = worldIn.getBlockState(blockpos);
                    Block block = worldIn.getBlockState(blockpos.up()).getBlock();

                    if (iblockstate.getBlock() == Blocks.dirt && iblockstate.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && block.getLightOpacity() <= 2)
                    {
                        worldIn.setBlockState(blockpos, this.getDefaultState());
                    }
                }
            }
        }
    }
}
 
Example 16
Project: uniquecrops   File: BlockOldGrass.java   View Source Code Vote up 5 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());
        }
        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() == Blocks.DIRT && iblockstate1.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && iblockstate.getLightOpacity(worldIn, pos.up()) <= 2)
                    {
                        worldIn.setBlockState(blockpos, UCBlocks.oldGrass.getDefaultState());
                    }
                }
            }
        }
    }
}
 
Example 17
Project: Backmemed   File: BlockSapling.java   View Source Code Vote up 5 votes
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, pos, state, rand);
        }
    }
}
 
Example 18
Project: DecompiledMinecraft   File: Render.java   View Source Code Vote up 4 votes
/**
 * Renders the entity shadows at the position, shadow alpha and partialTickTime. Args: entity, x, y, z, shadowAlpha,
 * partialTickTime
 */
private void renderShadow(Entity entityIn, double x, double y, double z, float shadowAlpha, float partialTicks)
{
    GlStateManager.enableBlend();
    GlStateManager.blendFunc(770, 771);
    this.renderManager.renderEngine.bindTexture(shadowTextures);
    World world = this.getWorldFromRenderManager();
    GlStateManager.depthMask(false);
    float f = this.shadowSize;

    if (entityIn instanceof EntityLiving)
    {
        EntityLiving entityliving = (EntityLiving)entityIn;
        f *= entityliving.getRenderSizeModifier();

        if (entityliving.isChild())
        {
            f *= 0.5F;
        }
    }

    double d5 = entityIn.lastTickPosX + (entityIn.posX - entityIn.lastTickPosX) * (double)partialTicks;
    double d0 = entityIn.lastTickPosY + (entityIn.posY - entityIn.lastTickPosY) * (double)partialTicks;
    double d1 = entityIn.lastTickPosZ + (entityIn.posZ - entityIn.lastTickPosZ) * (double)partialTicks;
    int i = MathHelper.floor_double(d5 - (double)f);
    int j = MathHelper.floor_double(d5 + (double)f);
    int k = MathHelper.floor_double(d0 - (double)f);
    int l = MathHelper.floor_double(d0);
    int i1 = MathHelper.floor_double(d1 - (double)f);
    int j1 = MathHelper.floor_double(d1 + (double)f);
    double d2 = x - d5;
    double d3 = y - d0;
    double d4 = z - d1;
    Tessellator tessellator = Tessellator.getInstance();
    WorldRenderer worldrenderer = tessellator.getWorldRenderer();
    worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);

    for (BlockPos blockpos : BlockPos.getAllInBoxMutable(new BlockPos(i, k, i1), new BlockPos(j, l, j1)))
    {
        Block block = world.getBlockState(blockpos.down()).getBlock();

        if (block.getRenderType() != -1 && world.getLightFromNeighbors(blockpos) > 3)
        {
            this.func_180549_a(block, x, y, z, blockpos, shadowAlpha, f, d2, d3, d4);
        }
    }

    tessellator.draw();
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    GlStateManager.disableBlend();
    GlStateManager.depthMask(true);
}
 
Example 19
Project: uniquecrops   File: GrowthSteps.java   View Source Code Vote up 4 votes
@Override
public boolean canAdvance(World world, BlockPos pos, IBlockState state) {

	return world.getLightFromNeighbors(pos) >= 13;
}
 
Example 20
Project: BaseClient   File: Render.java   View Source Code Vote up 4 votes
/**
 * Renders the entity shadows at the position, shadow alpha and partialTickTime. Args: entity, x, y, z, shadowAlpha,
 * partialTickTime
 */
private void renderShadow(Entity entityIn, double x, double y, double z, float shadowAlpha, float partialTicks)
{
    if (!Config.isShaders() || !Shaders.shouldSkipDefaultShadow)
    {
        GlStateManager.enableBlend();
        GlStateManager.blendFunc(770, 771);
        this.renderManager.renderEngine.bindTexture(shadowTextures);
        World world = this.getWorldFromRenderManager();
        GlStateManager.depthMask(false);
        float f = this.shadowSize;

        if (entityIn instanceof EntityLiving)
        {
            EntityLiving entityliving = (EntityLiving)entityIn;
            f *= entityliving.getRenderSizeModifier();

            if (entityliving.isChild())
            {
                f *= 0.5F;
            }
        }

        double d5 = entityIn.lastTickPosX + (entityIn.posX - entityIn.lastTickPosX) * (double)partialTicks;
        double d0 = entityIn.lastTickPosY + (entityIn.posY - entityIn.lastTickPosY) * (double)partialTicks;
        double d1 = entityIn.lastTickPosZ + (entityIn.posZ - entityIn.lastTickPosZ) * (double)partialTicks;
        int i = MathHelper.floor_double(d5 - (double)f);
        int j = MathHelper.floor_double(d5 + (double)f);
        int k = MathHelper.floor_double(d0 - (double)f);
        int l = MathHelper.floor_double(d0);
        int i1 = MathHelper.floor_double(d1 - (double)f);
        int j1 = MathHelper.floor_double(d1 + (double)f);
        double d2 = x - d5;
        double d3 = y - d0;
        double d4 = z - d1;
        Tessellator tessellator = Tessellator.getInstance();
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();
        worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR);

        for (BlockPos blockpos : BlockPos.getAllInBoxMutable(new BlockPos(i, k, i1), new BlockPos(j, l, j1)))
        {
            Block block = world.getBlockState(blockpos.down()).getBlock();

            if (block.getRenderType() != -1 && world.getLightFromNeighbors(blockpos) > 3)
            {
                this.func_180549_a(block, x, y, z, blockpos, shadowAlpha, f, d2, d3, d4);
            }
        }

        tessellator.draw();
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        GlStateManager.disableBlend();
        GlStateManager.depthMask(true);
    }
}