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

The following are Jave code examples for showing how to use setBlockState() 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.
Example 1
Project: DecompiledMinecraft   File: BlockDynamicLiquid.java   Source Code and License Vote up 6 votes
private void tryFlowInto(World worldIn, BlockPos pos, IBlockState state, int level)
{
    if (this.canFlowInto(worldIn, pos, state))
    {
        if (state.getBlock() != Blocks.air)
        {
            if (this.blockMaterial == Material.lava)
            {
                this.triggerMixEffects(worldIn, pos);
            }
            else
            {
                state.getBlock().dropBlockAsItem(worldIn, pos, state, 0);
            }
        }

        worldIn.setBlockState(pos, this.getDefaultState().withProperty(LEVEL, Integer.valueOf(level)), 3);
    }
}
 
Example 2
Project: DecompiledMinecraft   File: ItemSeeds.java   Source Code and License Vote up 6 votes
/**
 * Called when a Block is right-clicked with this Item
 */
public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
{
    if (side != EnumFacing.UP)
    {
        return false;
    }
    else if (!playerIn.canPlayerEdit(pos.offset(side), side, stack))
    {
        return false;
    }
    else if (worldIn.getBlockState(pos).getBlock() == this.soilBlockID && worldIn.isAirBlock(pos.up()))
    {
        worldIn.setBlockState(pos.up(), this.crops.getDefaultState());
        --stack.stackSize;
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 3
Project: DecompiledMinecraft   File: StructureComponent.java   Source Code and License Vote up 6 votes
protected boolean generateDispenserContents(World worldIn, StructureBoundingBox boundingBoxIn, Random rand, int x, int y, int z, int meta, List<WeightedRandomChestContent> listIn, int max)
{
    BlockPos blockpos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z));

    if (boundingBoxIn.isVecInside(blockpos) && worldIn.getBlockState(blockpos).getBlock() != Blocks.dispenser)
    {
        worldIn.setBlockState(blockpos, Blocks.dispenser.getStateFromMeta(this.getMetadataWithOffset(Blocks.dispenser, meta)), 2);
        TileEntity tileentity = worldIn.getTileEntity(blockpos);

        if (tileentity instanceof TileEntityDispenser)
        {
            WeightedRandomChestContent.generateDispenserContents(rand, listIn, (TileEntityDispenser)tileentity, max);
        }

        return true;
    }
    else
    {
        return false;
    }
}
 
Example 4
Project: DecompiledMinecraft   File: WorldGenTallGrass.java   Source Code and License Vote up 6 votes
public boolean generate(World worldIn, Random rand, BlockPos position)
{
    Block block;

    while (((block = worldIn.getBlockState(position).getBlock()).getMaterial() == Material.air || block.getMaterial() == Material.leaves) && position.getY() > 0)
    {
        position = position.down();
    }

    for (int i = 0; i < 128; ++i)
    {
        BlockPos blockpos = position.add(rand.nextInt(8) - rand.nextInt(8), rand.nextInt(4) - rand.nextInt(4), rand.nextInt(8) - rand.nextInt(8));

        if (worldIn.isAirBlock(blockpos) && Blocks.tallgrass.canBlockStay(worldIn, blockpos, this.tallGrassState))
        {
            worldIn.setBlockState(blockpos, this.tallGrassState, 2);
        }
    }

    return true;
}
 
Example 5
Project: CustomWorldGen   File: BlockLever.java   Source Code and License Vote up 6 votes
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
{
    if (worldIn.isRemote)
    {
        return true;
    }
    else
    {
        state = state.cycleProperty(POWERED);
        worldIn.setBlockState(pos, state, 3);
        float f = ((Boolean)state.getValue(POWERED)).booleanValue() ? 0.6F : 0.5F;
        worldIn.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 0.3F, f);
        worldIn.notifyNeighborsOfStateChange(pos, this);
        EnumFacing enumfacing = ((BlockLever.EnumOrientation)state.getValue(FACING)).getFacing();
        worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing.getOpposite()), this);
        return true;
    }
}
 
Example 6
Project: BaseClient   File: StructureMineshaftPieces.java   Source Code and License Vote up 6 votes
protected boolean generateChestContents(World worldIn, StructureBoundingBox boundingBoxIn, Random rand, int x, int y, int z, List<WeightedRandomChestContent> listIn, int max)
{
    BlockPos blockpos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z));

    if (boundingBoxIn.isVecInside(blockpos) && worldIn.getBlockState(blockpos).getBlock().getMaterial() == Material.air)
    {
        int i = rand.nextBoolean() ? 1 : 0;
        worldIn.setBlockState(blockpos, Blocks.rail.getStateFromMeta(this.getMetadataWithOffset(Blocks.rail, i)), 2);
        EntityMinecartChest entityminecartchest = new EntityMinecartChest(worldIn, (double)((float)blockpos.getX() + 0.5F), (double)((float)blockpos.getY() + 0.5F), (double)((float)blockpos.getZ() + 0.5F));
        WeightedRandomChestContent.generateChestContents(rand, listIn, entityminecartchest, max);
        worldIn.spawnEntityInWorld(entityminecartchest);
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 7
Project: CustomWorldGen   File: BlockHugeMushroom.java   Source Code and License Vote up 6 votes
public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis)
{
    IBlockState state = world.getBlockState(pos);
    for (IProperty prop : (java.util.Set<IProperty<?>>)state.getProperties().keySet())
    {
        if (prop.getName().equals("variant"))
        {
            world.setBlockState(pos, state.cycleProperty(prop));
            return true;
        }
    }
    return false;
}
 
Example 8
Project: CustomWorldGen   File: BlockRedstoneLight.java   Source Code and License Vote up 5 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (!worldIn.isRemote)
    {
        if (this.isOn && !worldIn.isBlockPowered(pos))
        {
            worldIn.setBlockState(pos, Blocks.REDSTONE_LAMP.getDefaultState(), 2);
        }
    }
}
 
Example 9
Project: DecompiledMinecraft   File: BlockNetherWart.java   Source Code and License Vote up 5 votes
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    int i = ((Integer)state.getValue(AGE)).intValue();

    if (i < 3 && rand.nextInt(10) == 0)
    {
        state = state.withProperty(AGE, Integer.valueOf(i + 1));
        worldIn.setBlockState(pos, state, 2);
    }

    super.updateTick(worldIn, pos, state, rand);
}
 
Example 10
Project: BaseClient   File: BlockJukebox.java   Source Code and License Vote up 5 votes
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
{
    if (((Boolean)state.getValue(HAS_RECORD)).booleanValue())
    {
        this.dropRecord(worldIn, pos, state);
        state = state.withProperty(HAS_RECORD, Boolean.valueOf(false));
        worldIn.setBlockState(pos, state, 2);
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 11
Project: Bewitchment   File: BlockMoonbell.java   Source Code and License Vote up 5 votes
private void tryAndSpawn(World w, MutableBlockPos p) {
	int oy = p.getY();
	for (int dy = -5; dy <= 5; dy++) {
		p.setY(oy + dy);
		if ((w.isAirBlock(p) || w.getBlockState(p).getBlock().isReplaceable(w, p)) && w.getBlockState(p.down()).getBlock() == Blocks.DIRT) {
			w.setBlockState(p, this.getDefaultState().withProperty(placed, false), 3);
			return;
		}
	}
}
 
Example 12
Project: Backmemed   File: BlockFurnace.java   Source Code and License Vote up 5 votes
/**
 * Called by ItemBlocks after a block is set in the world, to allow post-place logic
 */
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 TileEntityFurnace)
        {
            ((TileEntityFurnace)tileentity).setCustomInventoryName(stack.getDisplayName());
        }
    }
}
 
Example 13
Project: harshencastle   File: BaseFluidBlock.java   Source Code and License Vote up 5 votes
public boolean checkForMixing(World worldIn, BlockPos pos, IBlockState state)
{
    boolean flag = false;

    for (EnumFacing enumfacing : EnumFacing.values())
    {
        if (enumfacing != EnumFacing.DOWN && (worldIn.getBlockState(pos.offset(enumfacing)).getMaterial().isLiquid() == true))
        {
        	if (worldIn.getBlockState(pos.offset(enumfacing)).getBlock() != this.getBlockState().getBlock())
        	{
             flag = true;
             break;
        	}
        }
    }

    if (flag)
    {
        Integer integer = (Integer)state.getValue(LEVEL);

        if (integer.intValue() == 0)
        {
            worldIn.setBlockState(pos, getBlockWhenSourceHit().getDefaultState(), 3);
            return true;
        }

        if (integer.intValue() <= 4)
        {
            worldIn.setBlockState(pos, getBlockWhenOtherHit().getDefaultState(), 3);
            return true;
        }
    }

    return false;
}
 
Example 14
Project: Backmemed   File: ItemEnderEye.java   Source Code and License Vote up 4 votes
/**
 * Called when a Block is right-clicked with this Item
 */
public EnumActionResult onItemUse(EntityPlayer stack, World playerIn, BlockPos worldIn, EnumHand pos, EnumFacing hand, float facing, float hitX, float hitY)
{
    IBlockState iblockstate = playerIn.getBlockState(worldIn);
    ItemStack itemstack = stack.getHeldItem(pos);

    if (stack.canPlayerEdit(worldIn.offset(hand), hand, itemstack) && iblockstate.getBlock() == Blocks.END_PORTAL_FRAME && !((Boolean)iblockstate.getValue(BlockEndPortalFrame.EYE)).booleanValue())
    {
        if (playerIn.isRemote)
        {
            return EnumActionResult.SUCCESS;
        }
        else
        {
            playerIn.setBlockState(worldIn, iblockstate.withProperty(BlockEndPortalFrame.EYE, Boolean.valueOf(true)), 2);
            playerIn.updateComparatorOutputLevel(worldIn, Blocks.END_PORTAL_FRAME);
            itemstack.func_190918_g(1);

            for (int i = 0; i < 16; ++i)
            {
                double d0 = (double)((float)worldIn.getX() + (5.0F + itemRand.nextFloat() * 6.0F) / 16.0F);
                double d1 = (double)((float)worldIn.getY() + 0.8125F);
                double d2 = (double)((float)worldIn.getZ() + (5.0F + itemRand.nextFloat() * 6.0F) / 16.0F);
                double d3 = 0.0D;
                double d4 = 0.0D;
                double d5 = 0.0D;
                playerIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, 0.0D, 0.0D, 0.0D, new int[0]);
            }

            BlockPattern.PatternHelper blockpattern$patternhelper = BlockEndPortalFrame.getOrCreatePortalShape().match(playerIn, worldIn);

            if (blockpattern$patternhelper != null)
            {
                BlockPos blockpos = blockpattern$patternhelper.getFrontTopLeft().add(-3, 0, -3);

                for (int j = 0; j < 3; ++j)
                {
                    for (int k = 0; k < 3; ++k)
                    {
                        playerIn.setBlockState(blockpos.add(j, 0, k), Blocks.END_PORTAL.getDefaultState(), 2);
                    }
                }
            }

            return EnumActionResult.SUCCESS;
        }
    }
    else
    {
        return EnumActionResult.FAIL;
    }
}
 
Example 15
Project: customstuff4   File: ItemSnow.java   Source Code and License Vote up 4 votes
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    ItemStack itemstack = player.getHeldItem(hand);

    if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack))
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();
        BlockPos blockpos = pos;

        if ((facing != EnumFacing.UP || block != this.block) && !block.isReplaceable(worldIn, pos))
        {
            blockpos = pos.offset(facing);
            iblockstate = worldIn.getBlockState(blockpos);
            block = iblockstate.getBlock();
        }

        if (block == this.block)
        {
            int i = iblockstate.getValue(BlockSnow.LAYERS);

            if (i < 8)
            {
                IBlockState iblockstate1 = iblockstate.withProperty(BlockSnow.LAYERS, i + 1);
                AxisAlignedBB axisalignedbb = iblockstate1.getCollisionBoundingBox(worldIn, blockpos);

                if (axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(blockpos)) && worldIn.setBlockState(blockpos, iblockstate1, 10))
                {
                    SoundType soundtype = this.block.getSoundType(iblockstate1, worldIn, pos, player);
                    worldIn.playSound(player, blockpos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);

                    if (player instanceof EntityPlayerMP)
                    {
                        CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos, itemstack);
                    }

                    itemstack.shrink(1);
                    return EnumActionResult.SUCCESS;
                }
            }
        }

        return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
    }
    else
    {
        return EnumActionResult.FAIL;
    }
}
 
Example 16
Project: BaseClient   File: ItemDye.java   Source Code and License Vote up 4 votes
/**
 * Called when a Block is right-clicked with this Item
 */
public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
{
    if (!playerIn.canPlayerEdit(pos.offset(side), side, stack))
    {
        return false;
    }
    else
    {
        EnumDyeColor enumdyecolor = EnumDyeColor.byDyeDamage(stack.getMetadata());

        if (enumdyecolor == EnumDyeColor.WHITE)
        {
            if (applyBonemeal(stack, worldIn, pos))
            {
                if (!worldIn.isRemote)
                {
                    worldIn.playAuxSFX(2005, pos, 0);
                }

                return true;
            }
        }
        else if (enumdyecolor == EnumDyeColor.BROWN)
        {
            IBlockState iblockstate = worldIn.getBlockState(pos);
            Block block = iblockstate.getBlock();

            if (block == Blocks.log && iblockstate.getValue(BlockPlanks.VARIANT) == BlockPlanks.EnumType.JUNGLE)
            {
                if (side == EnumFacing.DOWN)
                {
                    return false;
                }

                if (side == EnumFacing.UP)
                {
                    return false;
                }

                pos = pos.offset(side);

                if (worldIn.isAirBlock(pos))
                {
                    IBlockState iblockstate1 = Blocks.cocoa.onBlockPlaced(worldIn, pos, side, hitX, hitY, hitZ, 0, playerIn);
                    worldIn.setBlockState(pos, iblockstate1, 2);

                    if (!playerIn.capabilities.isCreativeMode)
                    {
                        --stack.stackSize;
                    }
                }

                return true;
            }
        }

        return false;
    }
}
 
Example 17
Project: Got-Wood   File: BlockSpecialFire.java   Source Code and License Vote up 4 votes
@Override
public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn) {
	System.out.println("doot");
	worldIn.setBlockState(pos.up(), Blocks.AIR.getDefaultState(), 2);
	super.onBlockClicked(worldIn, pos, playerIn);
}
 
Example 18
Project: DecompiledMinecraft   File: WorldGenLiquids.java   Source Code and License Vote up 4 votes
public boolean generate(World worldIn, Random rand, BlockPos position)
{
    if (worldIn.getBlockState(position.up()).getBlock() != Blocks.stone)
    {
        return false;
    }
    else if (worldIn.getBlockState(position.down()).getBlock() != Blocks.stone)
    {
        return false;
    }
    else if (worldIn.getBlockState(position).getBlock().getMaterial() != Material.air && worldIn.getBlockState(position).getBlock() != Blocks.stone)
    {
        return false;
    }
    else
    {
        int i = 0;

        if (worldIn.getBlockState(position.west()).getBlock() == Blocks.stone)
        {
            ++i;
        }

        if (worldIn.getBlockState(position.east()).getBlock() == Blocks.stone)
        {
            ++i;
        }

        if (worldIn.getBlockState(position.north()).getBlock() == Blocks.stone)
        {
            ++i;
        }

        if (worldIn.getBlockState(position.south()).getBlock() == Blocks.stone)
        {
            ++i;
        }

        int j = 0;

        if (worldIn.isAirBlock(position.west()))
        {
            ++j;
        }

        if (worldIn.isAirBlock(position.east()))
        {
            ++j;
        }

        if (worldIn.isAirBlock(position.north()))
        {
            ++j;
        }

        if (worldIn.isAirBlock(position.south()))
        {
            ++j;
        }

        if (i == 3 && j == 1)
        {
            worldIn.setBlockState(position, this.block.getDefaultState(), 2);
            worldIn.forceBlockUpdateTick(this.block, position, rand);
        }

        return true;
    }
}
 
Example 19
Project: BaseClient   File: WorldGenSpikes.java   Source Code and License Vote up 4 votes
public boolean generate(World worldIn, Random rand, BlockPos position)
{
    if (worldIn.isAirBlock(position) && worldIn.getBlockState(position.down()).getBlock() == this.baseBlockRequired)
    {
        int i = rand.nextInt(32) + 6;
        int j = rand.nextInt(4) + 1;
        BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();

        for (int k = position.getX() - j; k <= position.getX() + j; ++k)
        {
            for (int l = position.getZ() - j; l <= position.getZ() + j; ++l)
            {
                int i1 = k - position.getX();
                int j1 = l - position.getZ();

                if (i1 * i1 + j1 * j1 <= j * j + 1 && worldIn.getBlockState(blockpos$mutableblockpos.func_181079_c(k, position.getY() - 1, l)).getBlock() != this.baseBlockRequired)
                {
                    return false;
                }
            }
        }

        for (int l1 = position.getY(); l1 < position.getY() + i && l1 < 256; ++l1)
        {
            for (int i2 = position.getX() - j; i2 <= position.getX() + j; ++i2)
            {
                for (int j2 = position.getZ() - j; j2 <= position.getZ() + j; ++j2)
                {
                    int k2 = i2 - position.getX();
                    int k1 = j2 - position.getZ();

                    if (k2 * k2 + k1 * k1 <= j * j + 1)
                    {
                        worldIn.setBlockState(new BlockPos(i2, l1, j2), Blocks.obsidian.getDefaultState(), 2);
                    }
                }
            }
        }

        Entity entity = new EntityEnderCrystal(worldIn);
        entity.setLocationAndAngles((double)((float)position.getX() + 0.5F), (double)(position.getY() + i), (double)((float)position.getZ() + 0.5F), rand.nextFloat() * 360.0F, 0.0F);
        worldIn.spawnEntityInWorld(entity);
        worldIn.setBlockState(position.up(i), Blocks.bedrock.getDefaultState(), 2);
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 20
Project: harshencastle   File: PontusWorldGeneratorStone.java   Source Code and License Vote up 4 votes
@Override
public boolean generate(World worldIn, Random rand, BlockPos position) {
	if(worldIn.getTopSolidOrLiquidBlock(position).getY() > 90)
		return false;
	float f = rand.nextFloat() * (float)Math.PI;
	int numTime = numberOfBlocks  + rand.nextInt(23);
       double d0 = (double)((float)(position.getX() + 8) + MathHelper.sin(f) * (float)numTime / 8.0F);
       double d1 = (double)((float)(position.getX() + 8) - MathHelper.sin(f) * (float)numTime / 8.0F);
       double d2 = (double)((float)(position.getZ() + 8) + MathHelper.cos(f) * (float)numTime / 8.0F);
       double d3 = (double)((float)(position.getZ() + 8) - MathHelper.cos(f) * (float)numTime / 8.0F);
       double d4 = (double)(position.getY() + rand.nextInt(3) - 2);
       double d5 = (double)(position.getY() + rand.nextInt(3) - 2);
       for (int i = 0; i < numTime; ++i)
       {
           float f1 = (float)i / (float)numTime;
           double d6 = d0 + (d1 - d0) * (double)f1;
           double d7 = d4 + (d5 - d4) * (double)f1;
           double d8 = d2 + (d3 - d2) * (double)f1;
           double d9 = rand.nextDouble() * (double)numTime / 16.0D;
           double d10 = (double)(MathHelper.sin((float)Math.PI * f1) + 1.0F) * d9 + 1.0D;
           double d11 = (double)(MathHelper.sin((float)Math.PI * f1) + 1.0F) * d9 + 1.0D;
           int j = MathHelper.floor(d6 - d10 / 2.0D);
           int k = MathHelper.floor(d7 - d11 / 2.0D);
           int l = MathHelper.floor(d8 - d10 / 2.0D);
           int i1 = MathHelper.floor(d6 + d10 / 2.0D);
           int j1 = MathHelper.floor(d7 + d11 / 2.0D);
           int k1 = MathHelper.floor(d8 + d10 / 2.0D);

           for (int l1 = j; l1 <= i1; ++l1)
           {
               double d12 = ((double)l1 + 0.5D - d6) / (d10 / 2.0D);

               if (d12 * d12 < 1.0D)
               {
                   for (int i2 = k; i2 <= j1; ++i2)
                   {
                       double d13 = ((double)i2 + 0.5D - d7) / (d11 / 2.0D);

                       if (d12 * d12 + d13 * d13 < 1.0D)
                       {
                           for (int j2 = l; j2 <= k1; ++j2)
                           {
                               double d14 = ((double)j2 + 0.5D - d8) / (d10 / 2.0D);

                               if (d12 * d12 + d13 * d13 + d14 * d14 < 1.0D)
                               {
                                   BlockPos blockpos = new BlockPos(l1, i2, j2);
                                   if(HarshenUtils.toArray(HarshenBlocks.HARSHEN_DIMENSIONAL_DIRT, HarshenBlocks.HARSHEN_DIMENSIONAL_ROCK).contains(worldIn.getBlockState(blockpos).getBlock()))
                                   	if(primer == null)
                                   		worldIn.setBlockState(blockpos, this.state, 2);
                                   	else
                                   		primer.setBlockState(blockpos.getX(), blockpos.getY(), blockpos.getZ(), state);
                               }
                           }
                       }
                   }
               }
           }
       }

       return true;
}