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

The following examples show how to use net.minecraft.world.World#setBlockState() . 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: 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 2
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 3
Source File: BlockButton.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (!worldIn.isRemote)
    {
        if (state.getValue(POWERED))
        {
            if (content.triggeredByArrows)
            {
                this.checkPressed(state, worldIn, pos);
            } else
            {
                worldIn.setBlockState(pos, state.withProperty(POWERED, false));
                this.notifyNeighbors(worldIn, pos, state.getValue(FACING));
                this.playReleaseSound(worldIn, pos);
                worldIn.markBlockRangeForRenderUpdate(pos, pos);
            }
        }
    }
}
 
Example 4
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 5
Source File: BlockCrops.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
@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 6
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 7
Source File: ItemEngineeringTable.java    From Cyberware with MIT License 5 votes vote down vote up
public static void placeDoor(World worldIn, BlockPos pos, EnumFacing facing, Block door)
{
	BlockPos blockpos = pos.offset(facing.rotateY());
	BlockPos blockpos1 = pos.offset(facing.rotateYCCW());
	int i = (worldIn.getBlockState(blockpos1).isNormalCube() ? 1 : 0) + (worldIn.getBlockState(blockpos1.up()).isNormalCube() ? 1 : 0);
	int j = (worldIn.getBlockState(blockpos).isNormalCube() ? 1 : 0) + (worldIn.getBlockState(blockpos.up()).isNormalCube() ? 1 : 0);
	BlockPos blockpos2 = pos.up();
	
	IBlockState iblockstate = door.getDefaultState().withProperty(BlockEngineeringTable.FACING, facing);
	worldIn.setBlockState(pos, iblockstate.withProperty(BlockEngineeringTable.HALF, BlockEngineeringTable.EnumEngineeringHalf.LOWER), 2);
	worldIn.setBlockState(blockpos2, iblockstate.withProperty(BlockEngineeringTable.HALF, BlockEngineeringTable.EnumEngineeringHalf.UPPER), 2);
	worldIn.notifyNeighborsOfStateChange(pos, door);
	worldIn.notifyNeighborsOfStateChange(blockpos2, door);
}
 
Example 8
Source File: BlockShoji.java    From Sakura_mod with MIT License 5 votes vote down vote up
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    worldIn.setBlockState(pos, state.withProperty(FACING, EnumFacing.getDirectionFromEntityLiving(pos, placer))
            .withProperty(OPEN, false), 2);
    if (!worldIn.isRemote) {
        TileEntityShoji te = (TileEntityShoji) worldIn.getTileEntity(pos);
        if (te != null) {
            te.setType(RecipesUtil.getItemTagCompound(stack).getInteger("type"));
            te.setFacing(EnumFacing.getDirectionFromEntityLiving(pos, placer));
            te.setOpen(false);
        }
    }
}
 
Example 9
Source File: BiomeHandler.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
public static void changeBiome(World world, int biomeId, BlockPos pos) {
	Chunk chunk = world.getChunkFromBlockCoords(pos);

	Biome biome = world.getBiome(pos);
	Biome biomeTo = Biome.getBiome(biomeId);
	
	if(biome == biomeTo)
		return;
	
	int y = 60;
	if(biome.topBlock != biomeTo.topBlock) {
		BlockPos yy = world.getHeight(pos);
		
		while(!world.getBlockState(yy.down()).isOpaqueCube() && yy.getY() > 0)
			yy = yy.down();
		
		if(world.getBlockState(yy.down()) == biome.topBlock)
			world.setBlockState(yy.down(), biomeTo.topBlock);
	}

	byte[] biomeArr = chunk.getBiomeArray();
	try {
		biomeArr[(pos.getX() & 15) + (pos.getZ() & 15)*16] = (byte)biomeId;
	} catch (IndexOutOfBoundsException e) {
		e.printStackTrace();
	}

	PacketHandler.sendToNearby(new PacketBiomeIDChange(chunk, world, new HashedBlockPosition(pos)), world.provider.getDimension(), pos, 256);
}
 
Example 10
Source File: PistonBlockEntity_movableTEMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
/**
 * @author 2No2Name
 */
@Redirect(method = "tick", at = @At(value = "INVOKE",
          target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
private boolean movableTEsetBlockState0(World world, BlockPos blockPos_1, BlockState blockAState_2, int int_1)
{
    if (!CarpetSettings.movableBlockEntities)
        return world.setBlockState(blockPos_1, blockAState_2, int_1);
    else
        return ((WorldInterface) (world)).setBlockStateWithBlockEntity(blockPos_1, blockAState_2, this.carriedBlockEntity, int_1);
}
 
Example 11
Source File: LighterBehaviour.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean tryIgniteBlock(World world, BlockPos pos) {
    if (world.isAirBlock(pos)) {
        world.setBlockState(pos, Blocks.FIRE.getDefaultState());
        return true;
    }
    return false;
}
 
Example 12
Source File: BlockTofuFarmLand.java    From TofuCraftReload with MIT License 5 votes vote down vote up
protected static void turnToDirt(World p_190970_0_, BlockPos worldIn)
{
    p_190970_0_.setBlockState(worldIn, BlockLoader.tofuTerrain.getDefaultState());
    AxisAlignedBB axisalignedbb = field_194405_c.offset(worldIn);

    for (Entity entity : p_190970_0_.getEntitiesWithinAABBExcludingEntity((Entity)null, axisalignedbb))
    {
        double d0 = Math.min(axisalignedbb.maxY - axisalignedbb.minY, axisalignedbb.maxY - entity.getEntityBoundingBox().minY);
        entity.setPositionAndUpdate(entity.posX, entity.posY + d0 + 0.001D, entity.posZ);
    }
}
 
Example 13
Source File: SurfaceRockPopulator.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void setStoneBlock(World world, BlockPos blockPos, Collection<Material> undergroundMaterials) {
    boolean surfaceRockPlaced = world.setBlockState(blockPos, MetaBlocks.SURFACE_ROCK_NEW.getDefaultState());
    if (surfaceRockPlaced) {
        TileEntitySurfaceRock tileEntity = (TileEntitySurfaceRock) world.getTileEntity(blockPos);
        if (tileEntity != null)
            tileEntity.setData(this.material, undergroundMaterials);
    }
}
 
Example 14
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 15
Source File: BlockVanillaSplint.java    From Sakura_mod with MIT License 5 votes vote down vote up
protected void checkAndDropBlock(World worldIn, BlockPos pos, IBlockState state)
{
    if (!this.canBlockStay(worldIn, pos, state))
    {
        this.dropBlockAsItem(worldIn, pos, state, 0);
        worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
    }
}
 
Example 16
Source File: BlockBlueprintArchive.java    From Cyberware with MIT License 5 votes vote down vote up
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
	worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
	if (stack.hasDisplayName())
	{
		TileEntity tileentity = worldIn.getTileEntity(pos);

		if (tileentity instanceof TileEntityBlueprintArchive)
		{
			((TileEntityBlueprintArchive) tileentity).setCustomInventoryName(stack.getDisplayName());
		}
	}
}
 
Example 17
Source File: GTUtility.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean resetEndPortalFrame(World world, BlockPos pos, IBlockState portalFrameState) {
	if (portalFrameState.getBlock() == Blocks.END_PORTAL_FRAME
			&& portalFrameState.getValue(BlockEndPortalFrame.EYE).booleanValue()) {
		world.setBlockState(pos, portalFrameState.withProperty(BlockEndPortalFrame.EYE, false));
		world.playSound((EntityPlayer) null, pos, SoundEvents.BLOCK_END_PORTAL_FRAME_FILL, SoundCategory.BLOCKS, 0.5F, 0.5F
				+ world.rand.nextFloat());
		return true;
	}
	return false;
}
 
Example 18
Source File: Moment.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void apply(World world, BlockPos pos) {

		List<IBlockState> momentsOfBlock = blocks.get(pos);
		if (momentsOfBlock == null || momentsOfBlock.isEmpty())
			return;

		world.setBlockState(pos, momentsOfBlock.get(0));
	}
 
Example 19
Source File: BlockMetalTrapDoor.java    From BaseMetals with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public boolean onBlockActivated(final World world, final BlockPos coord, IBlockState state,
                                final EntityPlayer player, EnumHand hand, ItemStack heldItem, final EnumFacing facing,
                                final float partialX, final float partialY, final float partialZ) {
    if (this.metal.getToolHarvestLevel() > 1) {
        return true;
    }
    state = state.cycleProperty(BlockTrapDoor.OPEN);
    world.setBlockState(coord, state, 2);
    world.playEvent(player, ((Boolean)state.getValue(BlockTrapDoor.OPEN)) ? 1003 : 1006, coord, 0);
    return true;
}
 
Example 20
Source File: BlockFuton.java    From Sakura_mod with MIT License 4 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
		EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
	if (worldIn.isRemote) {
		return true;
	}
	if (state.getValue(PART) != EnumPartType.HEAD) {
		pos = pos.offset(state.getValue(FACING));
		state = worldIn.getBlockState(pos);

		if (state.getBlock() != this) {
			return true;
		}
	}

	if (worldIn.provider.canRespawnHere() && worldIn.getBiome(pos) != Biomes.HELL) {
		if (state.getValue(OCCUPIED).booleanValue()) {
			EntityPlayer entityplayer = this.getPlayerInBlanket(worldIn, pos);

			if (entityplayer != null) {
				playerIn.sendMessage(new TextComponentTranslation("tile.bed.occupied"));
				return true;
			}

			state = state.withProperty(OCCUPIED, Boolean.valueOf(false));
			worldIn.setBlockState(pos, state, 4);
		}

		EntityPlayer.SleepResult entityplayer$sleepresult = playerIn.trySleep(pos);

		if (entityplayer$sleepresult == EntityPlayer.SleepResult.OK) {
			state = state.withProperty(OCCUPIED, Boolean.valueOf(true));
			worldIn.setBlockState(pos, state, 4);
			return true;
		}
		if (entityplayer$sleepresult == EntityPlayer.SleepResult.NOT_POSSIBLE_NOW) {
			playerIn.sendMessage(new TextComponentTranslation("tile.bed.noSleep"));
		} else if (entityplayer$sleepresult == EntityPlayer.SleepResult.NOT_SAFE) {
			playerIn.sendMessage(new TextComponentTranslation("tile.bed.notSafe"));
		}

		return true;
	}
	worldIn.setBlockToAir(pos);
	BlockPos blockpos = pos.offset(state.getValue(FACING).getOpposite());

	if (worldIn.getBlockState(blockpos).getBlock() == this) {
		worldIn.setBlockToAir(blockpos);
	}

	worldIn.newExplosion(null, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, 5.0F, true, true);
	return true;
}