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

The following examples show how to use net.minecraft.world.World#isAreaLoaded() . 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: BlockBambooShoot.java    From Sakura_mod with 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 growing cactus from loading unloaded chunks with block update
    BlockPos blockpos = pos.up();

    if (worldIn.isAirBlock(blockpos)) {
    	if(worldIn.getLightFor(EnumSkyBlock.BLOCK, pos) > 6 + worldIn.rand.nextInt(6)){
        int j = state.getValue(AGE).intValue();
        if (net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, blockpos, state, true)) {
            if (j == 6) {
                if(rand.nextInt() ==0){
                	if(worldIn.isAirBlock(blockpos.up(2)))worldIn.setBlockState(blockpos.up(2), BlockLoader.BAMBOO.getDefaultState());
                }
            	if(worldIn.isAirBlock(blockpos.up()))worldIn.setBlockState(blockpos.up(), BlockLoader.BAMBOO.getDefaultState());
            	if(worldIn.isAirBlock(blockpos)) worldIn.setBlockState(blockpos, BlockLoader.BAMBOO.getDefaultState());
                worldIn.setBlockState(pos, BlockLoader.BAMBOO.getDefaultState());
            } else {
                worldIn.setBlockState(pos, state.withProperty(AGE, Integer.valueOf(j + 1)), 4);
            }
            net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state, worldIn.getBlockState(pos));
        }
    	}
    }
}
 
Example 2
Source File: BlockGravity.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
protected void fall(World worldIn, BlockPos pos, IBlockState state)
{
	int i = 32;

	if ((!BlockFalling.fallInstantly) && (worldIn.isAreaLoaded(pos.add(-i, -i, -i), pos.add(i, i, i))))
	{
		if (!worldIn.isRemote)
		{
			EntityFallingBlockTFC entityfallingblock = new EntityFallingBlockTFC(worldIn, pos.getX() + 0.5D, pos.getY(), pos.getZ() + 0.5D, state);
			onStartFalling(entityfallingblock);
			worldIn.spawnEntity(entityfallingblock);
		}
	}
	else
	{
		((World)worldIn).setBlockToAir(pos);

		BlockPos blockpos;
		for (blockpos = pos.down(); (canFallInto(worldIn, blockpos)) && (blockpos.getY() > 0); blockpos = blockpos.down()) {}

		if (blockpos.getY() > 0)
		{
			worldIn.setBlockState(blockpos.up(), getDefaultState());
		}
	}
}
 
Example 3
Source File: BlockChestnut.java    From Sakura_mod with MIT License 6 votes vote down vote up
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 < 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 File: BlockHighCrop.java    From Sakura_mod with 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 5
Source File: BlockRiceCrop.java    From Sakura_mod with 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 6
Source File: BlockVanillaCrop.java    From Sakura_mod with 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 7
Source File: BlockPepperCrop.java    From Sakura_mod with 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 8
Source File: BlockRice.java    From TofuCraftReload with 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 9
Source File: BlockGrapeVine.java    From Sakura_mod with 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 10
Source File: BlockGrapeLeaves.java    From Sakura_mod with 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 11
Source File: BlockTofuTerrain.java    From TofuCraftReload with 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 12
Source File: BlockTataraSmelting.java    From Sakura_mod with MIT License 5 votes vote down vote up
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
        int i = this.getTime(state);
        setSmelting(worldIn, pos);
        if (i < this.getFinishTime()){
            if(rand.nextInt(1) == 0){
                worldIn.setBlockState(pos, this.withTime(i + 1), 2);
            }
        }
    
}
 
Example 13
Source File: BlockGregSapling.java    From GregTech with GNU Lesser 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.isAreaLoaded(pos, 1))
            return;
        if (worldIn.getLightFromNeighbors(pos.up()) >= 9 && rand.nextInt(7) == 0) {
            this.grow(worldIn, rand, pos, state);
        }
    }
}
 
Example 14
Source File: BlockValkyriumOre.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
private void tryFallingUp(World worldIn, BlockPos pos) {
    BlockPos downPos = pos.up();
    if ((worldIn.isAirBlock(downPos) || canFallThrough(worldIn.getBlockState(downPos)))
        && pos.getY() >= 0) {
        int i = 32;

        if (!BlockFalling.fallInstantly && worldIn
            .isAreaLoaded(pos.add(-32, -32, -32), pos.add(32, 32, 32))) {
            if (!worldIn.isRemote) {
                // Start falling up
                EntityFallingUpBlock entityfallingblock = new EntityFallingUpBlock(worldIn,
                    (double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D,
                    worldIn.getBlockState(pos));
                worldIn.spawnEntity(entityfallingblock);
            }
        } else {
            IBlockState state = worldIn.getBlockState(pos);
            worldIn.setBlockToAir(pos);
            BlockPos blockpos;

            for (blockpos = pos.up(); (worldIn.isAirBlock(blockpos) || canFallThrough(
                worldIn.getBlockState(blockpos))) && blockpos.getY() < 255;
                blockpos = blockpos.up()) {
            }

            if (blockpos.getY() < 255) {
                worldIn.setBlockState(blockpos.down(), state, 3);
            }
        }
    }
}
 
Example 15
Source File: int3.java    From GT-Classic with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean isLoaded(World world, int radius) {
	return world.isAreaLoaded(pos, radius, false);
}
 
Example 16
Source File: Core.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isHexFullyLoaded(World world, IslandMap map, Center c)
{
	return world.isAreaLoaded(c.point.toBlockPos().add(map.getParams().getWorldX(), 0, map.getParams().getWorldZ()), 20);
}
 
Example 17
Source File: BlockLeaves.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand)
{
	if(world.isRemote || state.getBlock() != this)
		return;
	IBlockState scanState;
	WoodType wood = (WoodType)state.getValue(getMetaProperty());
	BlockPos scanPos;

	if(wood == WoodType.Palm)
	{
		scanState = world.getBlockState(pos.down());
		if(scanState.getBlock() != TFCBlocks.LogNaturalPalm)
			world.setBlockToAir(pos);
		return;
	}

	if (world.isAreaLoaded(pos.add(-5, -5, -5), pos.add(5, 5, 5)))
	{
		for(int y = -4; y <= 4; y++)
		{
			for(int x = -4; x <= 4; x++)
			{
				for(int z = -4; z <= 4; z++)
				{
					scanPos = pos.add(x, y, z);
					scanState = world.getBlockState(pos.add(x, y, z));
					if((state.getBlock() == TFCBlocks.Leaves && scanState.getBlock() == TFCBlocks.LogNatural && scanState.getValue(BlockLogNatural.WOOD) == wood) ||
							(state.getBlock() == TFCBlocks.Leaves2 && scanState.getBlock() == TFCBlocks.LogNatural2 && scanState.getValue(BlockLogNatural2.WOOD) == wood))
						return;
				}
			}
		}

		for(int y = -1; y <= 1; y++)
		{
			for(int x = -1; x <= 1; x++)
			{
				for(int z = -1; z <= 1; z++)
				{
					world.scheduleUpdate(pos.add(x, y, z), this, tickRate(world));
				}
			}
		}
		world.setBlockToAir(pos);
	}
}