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

The following examples show how to use net.minecraft.world.World#getBlockLightValue() . 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: MoCBlockGrass.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
{
		
    if (!MoCreatures.isServer())
    {
        return;
    }

    
    if (par1World.getBlockLightValue(par2, par3 + 1, par4) < 4 && Block.lightOpacity[par1World.getBlockId(par2, par3 + 1, par4)] > 2)
    {
        //par1World.setBlockWithNotify(par2, par3, par4, MoCreatures.mocDirt.blockID);
        par1World.setBlock(par2, par3, par4, MoCreatures.mocDirt.blockID, this.getDamageValue(par1World, par2, par3, par4), 3);
    }
    else if (par1World.getBlockLightValue(par2, par3 + 1, par4) >= 9)
    {
        for (int i = 0; i < 45; i++)
        {
            int j = (par2 + par5Random.nextInt(3)) - 1;
            int k = (par3 + par5Random.nextInt(5)) - 3;
            int l = (par4 + par5Random.nextInt(3)) - 1;
            int i1 = par1World.getBlockId(j, k + 1, l);

            if (par1World.getBlockId(j, k, l) == MoCreatures.mocDirt.blockID && par1World.getBlockLightValue(j, k + 1, l) >= 4 && Block.lightOpacity[i1] <= 2)
            {
                par1World.setBlock(j, k, l, MoCreatures.mocGrass.blockID, this.getDamageValue(par1World, j, k, l), 3);
            }
        }
    }
}
 
Example 2
Source File: ComponentLight.java    From Artifacts with MIT License 4 votes vote down vote up
@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean held) {
	//Check that the artifact is in a baubles slot if it should be
	if(DragonArtifacts.baublesLoaded && stack.stackTagCompound != null && 
			UtilsForComponents.equipableByBaubles(stack.stackTagCompound.getString("iconName")) && 
			DragonArtifacts.baublesMustBeEquipped && slot >= 0) {
		return;
	}
	
	//If armor check if equipped
	if(slot >= 0 && stack.stackTagCompound != null &&
			UtilsForComponents.isArmor(stack.stackTagCompound.getString("iconName"))) {
		return;
	}
	
	if(!world.isRemote) {
		
		int lx = stack.stackTagCompound.getInteger("lastLightX");
		int ly = stack.stackTagCompound.getInteger("lastLightY");
		int lz = stack.stackTagCompound.getInteger("lastLightZ");
		
		if(entity instanceof EntityPlayer) {
			
			int nlx = MathHelper.floor_double(entity.posX);
			int nly = MathHelper.floor_double(entity.posY);
			int nlz = MathHelper.floor_double(entity.posZ);
			boolean setLightBlock = false;
			
			if(nlx != lx || nly != ly || nlz != lz) {
				int d = (nlx - lx)*(nlx - lx)+(nly - ly)*(nly - ly)+(nlz - lz)*(nlz - lz);
				if(world.getBlockLightValue(nlx,nly,nlz) < 10) {
					if(d > 13) {
						//updating lighting info isn't fast :(
						if(ly >= 0 && ly < 256 && world.getBlock(lx, ly, lz) == BlockLight.instance) {
							world.setBlockToAir(lx, ly, lz);
							//System.out.println("Removed: " + lx + "," + ly + "," + lz);
						}
						//Set the light block at the player's feet (if possible)
						setLightBlock = true;
					}
					else {
						if(world.getBlock(lx, ly, lz) != BlockLight.instance) {

							if(world.isAirBlock(lx, ly, lz) && world.getBlock(lx, ly, lz) != BlockSolidAir.instance) {
								//Reset the block if it disappeared
								world.setBlock(lx, ly, lz, BlockLight.instance);
							}
							else {
								//Set the new light block at the player's feet (if possible)
								setLightBlock = true;
							}
						}
					}
				}
				
				if(setLightBlock && nly >= 0 && nly < 256 && world.isAirBlock(nlx, nly, nlz) && world.getBlock(nlx, nly, nlz) != BlockSolidAir.instance) {
					world.setBlock(nlx, nly, nlz, BlockLight.instance);
					stack.stackTagCompound.setInteger("lastLightX",nlx);
					stack.stackTagCompound.setInteger("lastLightY",nly);
					stack.stackTagCompound.setInteger("lastLightZ",nlz);
				}
			}
		}
	}
}