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

The following are Jave code examples for showing how to use getBlockState() 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: Bewitchment   File: HarvestBrew.java   View Source Code Vote up 7 votes
@Override
public void safeImpact(BlockPos pos, @Nullable EnumFacing side, World world, int amplifier) {
	int box = 1 + (int) ((float) amplifier / 2F);

	BlockPos posI = pos.add(box, 1, box);
	BlockPos posF = pos.add(-box, -1, -box);

	Iterable<BlockPos> spots = BlockPos.getAllInBox(posI, posF);
	int chance = 10 + amplifier * 2;
	int fortune = MathHelper.clamp(amplifier, 0, 5);
	for (BlockPos spot : spots) {
		IBlockState state = world.getBlockState(spot);
		boolean place = amplifier > 1 || world.rand.nextBoolean();
		if (place && state.getBlock() instanceof BlockCrops) {
			BlockCrops crop = (BlockCrops) state.getBlock();
			if (crop.isMaxAge(state)) {
				crop.dropBlockAsItemWithChance(world, spot, state, chance, fortune);
				world.setBlockToAir(spot);
			}
		}
	}
}
 
Example 2
Project: BaseClient   File: ItemSlab.java   View Source Code Vote up 6 votes
private boolean tryPlace(ItemStack stack, World worldIn, BlockPos pos, Object variantInStack)
{
    IBlockState iblockstate = worldIn.getBlockState(pos);

    if (iblockstate.getBlock() == this.singleSlab)
    {
        Comparable comparable = iblockstate.getValue(this.singleSlab.getVariantProperty());

        if (comparable == variantInStack)
        {
            IBlockState iblockstate1 = this.doubleSlab.getDefaultState().withProperty((IProperty)this.singleSlab.getVariantProperty(), comparable);

            if (worldIn.checkNoEntityCollision(this.doubleSlab.getCollisionBoundingBox(worldIn, pos, iblockstate1)) && worldIn.setBlockState(pos, iblockstate1, 3))
            {
                worldIn.playSoundEffect((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), this.doubleSlab.stepSound.getPlaceSound(), (this.doubleSlab.stepSound.getVolume() + 1.0F) / 2.0F, this.doubleSlab.stepSound.getFrequency() * 0.8F);
                --stack.stackSize;
            }

            return true;
        }
    }

    return false;
}
 
Example 3
Project: DecompiledMinecraft   File: EntityRabbit.java   View Source Code Vote up 6 votes
protected boolean shouldMoveTo(World worldIn, BlockPos pos)
{
    Block block = worldIn.getBlockState(pos).getBlock();

    if (block == Blocks.farmland)
    {
        pos = pos.up();
        IBlockState iblockstate = worldIn.getBlockState(pos);
        block = iblockstate.getBlock();

        if (block instanceof BlockCarrot && ((Integer)iblockstate.getValue(BlockCarrot.AGE)).intValue() == 7 && this.field_179498_d && !this.field_179499_e)
        {
            this.field_179499_e = true;
            return true;
        }
    }

    return false;
}
 
Example 4
Project: ExPetrum   File: ItemBlockOre.java   View Source Code Vote up 6 votes
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState)
{
	if (!world.setBlockState(pos, newState, 11)) return false;

       IBlockState state = world.getBlockState(pos);
       if (state.getBlock() == this.block)
       {
           setTileEntityNBT(world, player, pos, stack);
           TileEntity tile = world.getTileEntity(pos);
           if (tile instanceof TileOre)
           {
           	int oreIndex = (stack.getMetadata() / EnumRockClass.values().length) % EnumOre.values().length;
       		int oreRichnessIndex = stack.getMetadata() / (EnumRockClass.values().length * EnumOre.values().length);
       		((TileOre)tile).type = EnumOre.values()[oreIndex];
       		((TileOre)tile).amount = (byte) (oreRichnessIndex == 0 ? 20 : oreRichnessIndex == 1 ? 30 : 50);
           }
           
           this.block.onBlockPlacedBy(world, pos, state, player, stack);
       }

       return true;
}
 
Example 5
Project: DecompiledMinecraft   File: BlockDynamicLiquid.java   View Source Code Vote up 5 votes
private Set<EnumFacing> getPossibleFlowDirections(World worldIn, BlockPos pos)
{
    int i = 1000;
    Set<EnumFacing> set = EnumSet.<EnumFacing>noneOf(EnumFacing.class);

    for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
    {
        BlockPos blockpos = pos.offset(enumfacing);
        IBlockState iblockstate = worldIn.getBlockState(blockpos);

        if (!this.isBlocked(worldIn, blockpos, iblockstate) && (iblockstate.getBlock().getMaterial() != this.blockMaterial || ((Integer)iblockstate.getValue(LEVEL)).intValue() > 0))
        {
            int j;

            if (this.isBlocked(worldIn, blockpos.down(), worldIn.getBlockState(blockpos.down())))
            {
                j = this.func_176374_a(worldIn, blockpos, 1, enumfacing.getOpposite());
            }
            else
            {
                j = 0;
            }

            if (j < i)
            {
                set.clear();
            }

            if (j <= i)
            {
                set.add(enumfacing);
                i = j;
            }
        }
    }

    return set;
}
 
Example 6
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 7
Project: Thermionics   File: BlockTNTCreative.java   View Source Code Vote up 5 votes
public static boolean ignitesThings(World world, BlockPos pos) {
	IBlockState state = world.getBlockState(pos);
	if (state.getMaterial()==Material.FIRE) return true;
	if (state.getBlock()==Blocks.FIRE) return true;
	if (state.getBlock().isBurning(world, pos)) return true;
	
	return false;
}
 
Example 8
Project: Backmemed   File: BlockRedstoneComparator.java   View Source Code Vote up 5 votes
protected int calculateInputStrength(World worldIn, BlockPos pos, IBlockState state)
{
    int i = super.calculateInputStrength(worldIn, pos, state);
    EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
    BlockPos blockpos = pos.offset(enumfacing);
    IBlockState iblockstate = worldIn.getBlockState(blockpos);

    if (iblockstate.hasComparatorInputOverride())
    {
        i = iblockstate.getComparatorInputOverride(worldIn, blockpos);
    }
    else if (i < 15 && iblockstate.isNormalCube())
    {
        blockpos = blockpos.offset(enumfacing);
        iblockstate = worldIn.getBlockState(blockpos);

        if (iblockstate.hasComparatorInputOverride())
        {
            i = iblockstate.getComparatorInputOverride(worldIn, blockpos);
        }
        else if (iblockstate.getMaterial() == Material.AIR)
        {
            EntityItemFrame entityitemframe = this.findItemFrame(worldIn, enumfacing, blockpos);

            if (entityitemframe != null)
            {
                i = entityitemframe.getAnalogOutput();
            }
        }
    }

    return i;
}
 
Example 9
Project: DecompiledMinecraft   File: BlockMushroom.java   View Source Code Vote up 5 votes
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
{
    if (pos.getY() >= 0 && pos.getY() < 256)
    {
        IBlockState iblockstate = worldIn.getBlockState(pos.down());
        return iblockstate.getBlock() == Blocks.mycelium ? true : (iblockstate.getBlock() == Blocks.dirt && iblockstate.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.PODZOL ? true : worldIn.getLight(pos) < 13 && this.canPlaceBlockOn(iblockstate.getBlock()));
    }
    else
    {
        return false;
    }
}
 
Example 10
Project: ChopDown   File: ChopDown.java   View Source Code Vote up 5 votes
private static void drop(World world, BlockPos pos, BlockPos newPos) {
    EntityFallingBlock fallingBlock = new EntityFallingBlock(world, newPos.getX(), newPos.getY(), newPos.getZ(), world.getBlockState(pos));
    fallingBlock.setEntityBoundingBox(new AxisAlignedBB(newPos.add(0, 0, 0), newPos.add(1, 1, 1)));
    fallingBlock.fallTime = 1;
    world.spawnEntityInWorld(fallingBlock);
    world.setBlockState(pos, Blocks.AIR.getDefaultState());
}
 
Example 11
Project: CustomWorldGen   File: WorldGenCanopyTree.java   View Source Code Vote up 5 votes
private void placeLeafAt(World worldIn, int x, int y, int z)
{
    BlockPos blockpos = new BlockPos(x, y, z);
    IBlockState state = worldIn.getBlockState(blockpos);

    if (state.getBlock().isAir(state, worldIn, blockpos))
    {
        this.setBlockAndNotifyAdequately(worldIn, blockpos, DARK_OAK_LEAVES);
    }
}
 
Example 12
Project: Backmemed   File: BlockDoor.java   View Source Code Vote up 4 votes
/**
 * Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
 * change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
 * block, etc.
 */
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos p_189540_5_)
{
    if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER)
    {
        BlockPos blockpos = pos.down();
        IBlockState iblockstate = worldIn.getBlockState(blockpos);

        if (iblockstate.getBlock() != this)
        {
            worldIn.setBlockToAir(pos);
        }
        else if (blockIn != this)
        {
            iblockstate.neighborChanged(worldIn, blockpos, blockIn, p_189540_5_);
        }
    }
    else
    {
        boolean flag1 = false;
        BlockPos blockpos1 = pos.up();
        IBlockState iblockstate1 = worldIn.getBlockState(blockpos1);

        if (iblockstate1.getBlock() != this)
        {
            worldIn.setBlockToAir(pos);
            flag1 = true;
        }

        if (!worldIn.getBlockState(pos.down()).isFullyOpaque())
        {
            worldIn.setBlockToAir(pos);
            flag1 = true;

            if (iblockstate1.getBlock() == this)
            {
                worldIn.setBlockToAir(blockpos1);
            }
        }

        if (flag1)
        {
            if (!worldIn.isRemote)
            {
                this.dropBlockAsItem(worldIn, pos, state, 0);
            }
        }
        else
        {
            boolean flag = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockpos1);

            if (blockIn != this && (flag || blockIn.getDefaultState().canProvidePower()) && flag != ((Boolean)iblockstate1.getValue(POWERED)).booleanValue())
            {
                worldIn.setBlockState(blockpos1, iblockstate1.withProperty(POWERED, Boolean.valueOf(flag)), 2);

                if (flag != ((Boolean)state.getValue(OPEN)).booleanValue())
                {
                    worldIn.setBlockState(pos, state.withProperty(OPEN, Boolean.valueOf(flag)), 2);
                    worldIn.markBlockRangeForRenderUpdate(pos, pos);
                    worldIn.playEvent((EntityPlayer)null, flag ? this.getOpenSound() : this.getCloseSound(), pos, 0);
                }
            }
        }
    }
}
 
Example 13
Project: CustomWorldGen   File: BlockCrops.java   View Source Code Vote up 4 votes
protected static float getGrowthChance(Block blockIn, World worldIn, BlockPos pos)
{
    float f = 1.0F;
    BlockPos blockpos = pos.down();

    for (int i = -1; i <= 1; ++i)
    {
        for (int j = -1; j <= 1; ++j)
        {
            float f1 = 0.0F;
            IBlockState iblockstate = worldIn.getBlockState(blockpos.add(i, 0, j));

            if (iblockstate.getBlock().canSustainPlant(iblockstate, worldIn, blockpos.add(i, 0, j), net.minecraft.util.EnumFacing.UP, (net.minecraftforge.common.IPlantable)blockIn))
            {
                f1 = 1.0F;

                if (iblockstate.getBlock().isFertile(worldIn, blockpos.add(i, 0, j)))
                {
                    f1 = 3.0F;
                }
            }

            if (i != 0 || j != 0)
            {
                f1 /= 4.0F;
            }

            f += f1;
        }
    }

    BlockPos blockpos1 = pos.north();
    BlockPos blockpos2 = pos.south();
    BlockPos blockpos3 = pos.west();
    BlockPos blockpos4 = pos.east();
    boolean flag = blockIn == worldIn.getBlockState(blockpos3).getBlock() || blockIn == worldIn.getBlockState(blockpos4).getBlock();
    boolean flag1 = blockIn == worldIn.getBlockState(blockpos1).getBlock() || blockIn == worldIn.getBlockState(blockpos2).getBlock();

    if (flag && flag1)
    {
        f /= 2.0F;
    }
    else
    {
        boolean flag2 = blockIn == worldIn.getBlockState(blockpos3.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos4.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos4.south()).getBlock() || blockIn == worldIn.getBlockState(blockpos3.south()).getBlock();

        if (flag2)
        {
            f /= 2.0F;
        }
    }

    return f;
}
 
Example 14
Project: CustomWorldGen   File: CommandBlockData.java   View Source Code Vote up 4 votes
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 4)
    {
        throw new WrongUsageException("commands.blockdata.usage", new Object[0]);
    }
    else
    {
        sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
        BlockPos blockpos = parseBlockPos(sender, args, 0, false);
        World world = sender.getEntityWorld();

        if (!world.isBlockLoaded(blockpos))
        {
            throw new CommandException("commands.blockdata.outOfWorld", new Object[0]);
        }
        else
        {
            IBlockState iblockstate = world.getBlockState(blockpos);
            TileEntity tileentity = world.getTileEntity(blockpos);

            if (tileentity == null)
            {
                throw new CommandException("commands.blockdata.notValid", new Object[0]);
            }
            else
            {
                NBTTagCompound nbttagcompound = tileentity.writeToNBT(new NBTTagCompound());
                NBTTagCompound nbttagcompound1 = nbttagcompound.copy();
                NBTTagCompound nbttagcompound2;

                try
                {
                    nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 3).getUnformattedText());
                }
                catch (NBTException nbtexception)
                {
                    throw new CommandException("commands.blockdata.tagError", new Object[] {nbtexception.getMessage()});
                }

                nbttagcompound.merge(nbttagcompound2);
                nbttagcompound.setInteger("x", blockpos.getX());
                nbttagcompound.setInteger("y", blockpos.getY());
                nbttagcompound.setInteger("z", blockpos.getZ());

                if (nbttagcompound.equals(nbttagcompound1))
                {
                    throw new CommandException("commands.blockdata.failed", new Object[] {nbttagcompound.toString()});
                }
                else
                {
                    tileentity.readFromNBT(nbttagcompound);
                    tileentity.markDirty();
                    world.notifyBlockUpdate(blockpos, iblockstate, iblockstate, 3);
                    sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
                    notifyCommandListener(sender, this, "commands.blockdata.success", new Object[] {nbttagcompound.toString()});
                }
            }
        }
    }
}
 
Example 15
Project: genera   File: BlockGeneraCrop.java   View Source Code Vote up 4 votes
protected static float getGrowthChance(Block blockIn, World worldIn, BlockPos pos)
{
    float f = 1.0F;
    BlockPos blockpos1 = pos.down();

    for (int i = -1; i <= 1; ++i)
    {
        for (int j = -1; j <= 1; ++j)
        {
            float f1 = 0.0F;
            IBlockState iblockstate = worldIn.getBlockState(blockpos1.add(i, 0, j));

            if (iblockstate.getBlock().canSustainPlant(worldIn.getBlockState(blockpos1.add(i, 0, j)),
                    worldIn, blockpos1.add(i, 0, j), EnumFacing.UP, (IPlantable)blockIn))
            {
                f1 = 1.0F;

                if (iblockstate.getBlock().isFertile(worldIn, blockpos1.add(i, 0, j)))
                {
                    f1 = 3.0F;
                }
            }

            if (i != 0 || j != 0)
            {
                f1 /= 4.0F;
            }

            f += f1;
        }
    }

    BlockPos blockpos2 = pos.north();
    BlockPos blockpos3 = pos.south();
    BlockPos blockpos4 = pos.west();
    BlockPos blockpos5 = pos.east();
    boolean flag = blockIn == worldIn.getBlockState(blockpos4).getBlock() || blockIn == worldIn.getBlockState(blockpos5).getBlock();
    boolean flag1 = blockIn == worldIn.getBlockState(blockpos2).getBlock() || blockIn == worldIn.getBlockState(blockpos3).getBlock();

    if (flag && flag1)
    {
        f /= 2.0F;
    }
    else
    {
        boolean flag2 = blockIn == worldIn.getBlockState(blockpos4.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos5.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos5.south()).getBlock() || blockIn == worldIn.getBlockState(blockpos4.south()).getBlock();

        if (flag2)
        {
            f /= 2.0F;
        }
    }

    return f;
}
 
Example 16
Project: ExPetrum   File: ItemWateringCan.java   View Source Code Vote up 4 votes
@SuppressWarnings("ConstantConditions")
@Override
public void onUsingTick(ItemStack stack, EntityLivingBase player, int count)
{
	if (!(player instanceof EntityPlayer))
	{
		return;
	}
	
	int tier = this.getStats(stack).getTier();
	RayTraceResult rtr = this.rayTrace(player.world, (EntityPlayer) player, true);
	if (rtr != null && rtr.typeOfHit == Type.BLOCK)
	{
		BlockPos pos = rtr.getBlockPos();
		World w = player.getEntityWorld();
		IBlockState blockHit = w.getBlockState(pos);
		Fluid f = FluidRegistry.lookupFluidForBlock(blockHit.getBlock());
		if (f == null && blockHit.getBlock() instanceof IFluidBlock)
		{
			f = ((IFluidBlock)blockHit.getBlock()).getFluid();
		}
		
		IFluidHandlerItem cap = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
		if (FluidRegistry.WATER.equals(f))
		{
			if (!player.world.isRemote)
			{
				this.tryFillWithWater(player, tier, pos, w, blockHit, f, cap);
			}
		}
		else
		{
			if (f == null)
			{
				tryWaterBasedOnTier(player, tier, pos, w, blockHit, cap, stack);
			}
		}
	}
	
	super.onUsingTick(stack, player, count);
}
 
Example 17
Project: BaseClient   File: ItemMinecart.java   View Source Code Vote up 4 votes
public ItemStack dispenseStack(IBlockSource source, ItemStack stack)
{
    EnumFacing enumfacing = BlockDispenser.getFacing(source.getBlockMetadata());
    World world = source.getWorld();
    double d0 = source.getX() + (double)enumfacing.getFrontOffsetX() * 1.125D;
    double d1 = Math.floor(source.getY()) + (double)enumfacing.getFrontOffsetY();
    double d2 = source.getZ() + (double)enumfacing.getFrontOffsetZ() * 1.125D;
    BlockPos blockpos = source.getBlockPos().offset(enumfacing);
    IBlockState iblockstate = world.getBlockState(blockpos);
    BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = iblockstate.getBlock() instanceof BlockRailBase ? (BlockRailBase.EnumRailDirection)iblockstate.getValue(((BlockRailBase)iblockstate.getBlock()).getShapeProperty()) : BlockRailBase.EnumRailDirection.NORTH_SOUTH;
    double d3;

    if (BlockRailBase.isRailBlock(iblockstate))
    {
        if (blockrailbase$enumraildirection.isAscending())
        {
            d3 = 0.6D;
        }
        else
        {
            d3 = 0.1D;
        }
    }
    else
    {
        if (iblockstate.getBlock().getMaterial() != Material.air || !BlockRailBase.isRailBlock(world.getBlockState(blockpos.down())))
        {
            return this.behaviourDefaultDispenseItem.dispense(source, stack);
        }

        IBlockState iblockstate1 = world.getBlockState(blockpos.down());
        BlockRailBase.EnumRailDirection blockrailbase$enumraildirection1 = iblockstate1.getBlock() instanceof BlockRailBase ? (BlockRailBase.EnumRailDirection)iblockstate1.getValue(((BlockRailBase)iblockstate1.getBlock()).getShapeProperty()) : BlockRailBase.EnumRailDirection.NORTH_SOUTH;

        if (enumfacing != EnumFacing.DOWN && blockrailbase$enumraildirection1.isAscending())
        {
            d3 = -0.4D;
        }
        else
        {
            d3 = -0.9D;
        }
    }

    EntityMinecart entityminecart = EntityMinecart.func_180458_a(world, d0, d1 + d3, d2, ((ItemMinecart)stack.getItem()).minecartType);

    if (stack.hasDisplayName())
    {
        entityminecart.setCustomNameTag(stack.getDisplayName());
    }

    world.spawnEntityInWorld(entityminecart);
    stack.splitStack(1);
    return stack;
}
 
Example 18
Project: Mods   File: TF2Util.java   View Source Code Vote up 4 votes
public static float damageBlock(BlockPos pos, EntityLivingBase living, World world, ItemStack stack, int critical, float damage, Vec3d forwardVec, Explosion explosion) {
	IBlockState state = world.getBlockState(pos);
	Block block = state.getBlock();
	if (block.isAir(state, world, pos) || TF2ConfigVars.destTerrain == 0 || state.getBlockHardness(world, pos) < 0 ||
			(!(living instanceof EntityPlayer) && !world.getGameRules().getBoolean("mobGriefing")) || (living instanceof EntityPlayer && !world.isBlockModifiable((EntityPlayer) living, pos)))
		return 0;

	DestroyBlockEntry finalEntry = null;
	int entryId = 0;
	int emptyId = -1;
	for (int i = 0; i < TF2EventsCommon.destroyProgress.size(); i++) {
		DestroyBlockEntry entry = TF2EventsCommon.destroyProgress.get(i);
		if (emptyId == -1 && entry == null)
			emptyId = i;
		if (entry != null && entry.world == world && entry.pos.equals(pos)) {
			finalEntry = entry;
			entryId = i;
			break;
		}
	}
	if (finalEntry == null) {
		finalEntry = new DestroyBlockEntry(pos, world);
		if (emptyId != -1) {
			TF2EventsCommon.destroyProgress.set(emptyId, finalEntry);
			entryId = emptyId;
		} else {
			TF2EventsCommon.destroyProgress.add(finalEntry);
			entryId = TF2EventsCommon.destroyProgress.size() - 1;
		}

	}

	/*if (block instanceof BlockChest) {
		((TileEntityChest) world.getTileEntity(pos)).setLootTable(LootTableList.CHESTS_NETHER_BRIDGE, living.getRNG().nextLong());
	}*/
	float hardness = TF2Util.getHardness(state, world, pos);

	if (!stack.isEmpty() && stack.getItem() instanceof ItemSniperRifle && hardness > 100)
		damage *= 3;
	finalEntry.curDamage += damage;

	if (living != null)
		world.sendBlockBreakProgress(Math.min(Integer.MAX_VALUE, 0xFFFF + entryId), pos, (int) ((finalEntry.curDamage / hardness) * 10));

	if (finalEntry.curDamage >= hardness) {
		if (living != null && living instanceof EntityPlayer)
			block.harvestBlock(world, (EntityPlayer) living, pos, state, null, stack);
		else {
			block.dropBlockAsItem(world, pos, state, 0);
			block.onBlockExploded(world, pos, explosion);
		}
		TF2EventsCommon.destroyProgress.remove(finalEntry);

		boolean flag = (living == null || !(living instanceof EntityPlayer) && world.isAirBlock(pos)) || block.removedByPlayer(state, world, pos, (EntityPlayer) living, true);

		if (flag) {
			if (living != null) {
				world.playEvent(2001, pos, Block.getStateId(state));
				world.sendBlockBreakProgress(Math.min(Integer.MAX_VALUE, 0xFFFF + entryId), pos, -1);
			}
			block.onBlockDestroyedByPlayer(world, pos, state);

			if (forwardVec != null) {
				RayTraceResult trace = world.rayTraceBlocks(living.getPositionVector().addVector(0, living.getEyeHeight(), 0), forwardVec, false, true, false);
				if (trace != null)
					damageBlock(trace.getBlockPos(), living, world, stack, critical, finalEntry.curDamage - hardness, forwardVec, explosion);
			}
		}
		return finalEntry.curDamage - hardness;
	}
	return 0;
}
 
Example 19
Project: Zombe-Modpack   File: ZWrapper.java   View Source Code Vote up 4 votes
public static IBlockState getStateAt(World world, BlockPos pos) {
    return world.getBlockState(pos);
}
 
Example 20
Project: DecompiledMinecraft   File: BlockTallGrass.java   View Source Code Vote up 4 votes
public int getDamageValue(World worldIn, BlockPos pos)
{
    IBlockState iblockstate = worldIn.getBlockState(pos);
    return iblockstate.getBlock().getMetaFromState(iblockstate);
}