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

The following are Jave code examples for showing how to use playEvent() 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: Backmemed   File: ItemRecord.java   Source Code and License Vote up 6 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);

    if (iblockstate.getBlock() == Blocks.JUKEBOX && !((Boolean)iblockstate.getValue(BlockJukebox.HAS_RECORD)).booleanValue())
    {
        if (!playerIn.isRemote)
        {
            ItemStack itemstack = stack.getHeldItem(pos);
            ((BlockJukebox)Blocks.JUKEBOX).insertRecord(playerIn, worldIn, iblockstate, itemstack);
            playerIn.playEvent((EntityPlayer)null, 1010, worldIn, Item.getIdFromItem(this));
            itemstack.func_190918_g(1);
            stack.addStat(StatList.RECORD_PLAYED);
        }

        return EnumActionResult.SUCCESS;
    }
    else
    {
        return EnumActionResult.PASS;
    }
}
 
Example 2
Project: CustomWorldGen   File: ItemRecord.java   Source Code and License Vote up 6 votes
/**
 * Called when a Block is right-clicked with this Item
 */
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    IBlockState iblockstate = worldIn.getBlockState(pos);

    if (iblockstate.getBlock() == Blocks.JUKEBOX && !((Boolean)iblockstate.getValue(BlockJukebox.HAS_RECORD)).booleanValue())
    {
        if (!worldIn.isRemote)
        {
            ((BlockJukebox)Blocks.JUKEBOX).insertRecord(worldIn, pos, iblockstate, stack);
            worldIn.playEvent((EntityPlayer)null, 1010, pos, Item.getIdFromItem(this));
            --stack.stackSize;
            playerIn.addStat(StatList.RECORD_PLAYED);
        }

        return EnumActionResult.SUCCESS;
    }
    else
    {
        return EnumActionResult.PASS;
    }
}
 
Example 3
Project: Backmemed   File: BlockDispenser.java   Source Code and License Vote up 6 votes
protected void dispense(World worldIn, BlockPos pos)
{
    BlockSourceImpl blocksourceimpl = new BlockSourceImpl(worldIn, pos);
    TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.getBlockTileEntity();

    if (tileentitydispenser != null)
    {
        int i = tileentitydispenser.getDispenseSlot();

        if (i < 0)
        {
            worldIn.playEvent(1001, pos, 0);
        }
        else
        {
            ItemStack itemstack = tileentitydispenser.getStackInSlot(i);
            IBehaviorDispenseItem ibehaviordispenseitem = this.getBehavior(itemstack);

            if (ibehaviordispenseitem != IBehaviorDispenseItem.DEFAULT_BEHAVIOR)
            {
                tileentitydispenser.setInventorySlotContents(i, ibehaviordispenseitem.dispense(blocksourceimpl, itemstack));
            }
        }
    }
}
 
Example 4
Project: Backmemed   File: BlockDoor.java   Source Code and License Vote up 6 votes
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing heldItem, float side, float hitX, float hitY)
{
    if (this.blockMaterial == Material.IRON)
    {
        return false;
    }
    else
    {
        BlockPos blockpos = state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
        IBlockState iblockstate = pos.equals(blockpos) ? state : worldIn.getBlockState(blockpos);

        if (iblockstate.getBlock() != this)
        {
            return false;
        }
        else
        {
            state = iblockstate.cycleProperty(OPEN);
            worldIn.setBlockState(blockpos, state, 10);
            worldIn.markBlockRangeForRenderUpdate(blockpos, pos);
            worldIn.playEvent(playerIn, ((Boolean)state.getValue(OPEN)).booleanValue() ? this.getOpenSound() : this.getCloseSound(), pos, 0);
            return true;
        }
    }
}
 
Example 5
Project: Backmemed   File: BlockDoor.java   Source Code and License Vote up 6 votes
public void toggleDoor(World worldIn, BlockPos pos, boolean open)
{
    IBlockState iblockstate = worldIn.getBlockState(pos);

    if (iblockstate.getBlock() == this)
    {
        BlockPos blockpos = iblockstate.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
        IBlockState iblockstate1 = pos == blockpos ? iblockstate : worldIn.getBlockState(blockpos);

        if (iblockstate1.getBlock() == this && ((Boolean)iblockstate1.getValue(OPEN)).booleanValue() != open)
        {
            worldIn.setBlockState(blockpos, iblockstate1.withProperty(OPEN, Boolean.valueOf(open)), 10);
            worldIn.markBlockRangeForRenderUpdate(blockpos, pos);
            worldIn.playEvent((EntityPlayer)null, open ? this.getOpenSound() : this.getCloseSound(), pos, 0);
        }
    }
}
 
Example 6
Project: CustomWorldGen   File: BlockDoor.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 (this.blockMaterial == Material.IRON)
    {
        return false; //Allow items to interact with the door
    }
    else
    {
        BlockPos blockpos = state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down();
        IBlockState iblockstate = pos.equals(blockpos) ? state : worldIn.getBlockState(blockpos);

        if (iblockstate.getBlock() != this)
        {
            return false;
        }
        else
        {
            state = iblockstate.cycleProperty(OPEN);
            worldIn.setBlockState(blockpos, state, 10);
            worldIn.markBlockRangeForRenderUpdate(blockpos, pos);
            worldIn.playEvent(playerIn, ((Boolean)state.getValue(OPEN)).booleanValue() ? this.getOpenSound() : this.getCloseSound(), pos, 0);
            return true;
        }
    }
}
 
Example 7
Project: Backmemed   File: BlockFenceGate.java   Source Code and License Vote up 6 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 (!worldIn.isRemote)
    {
        boolean flag = worldIn.isBlockPowered(pos);

        if (((Boolean)state.getValue(POWERED)).booleanValue() != flag)
        {
            worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(flag)).withProperty(OPEN, Boolean.valueOf(flag)), 2);

            if (((Boolean)state.getValue(OPEN)).booleanValue() != flag)
            {
                worldIn.playEvent((EntityPlayer)null, flag ? 1008 : 1014, pos, 0);
            }
        }
    }
}
 
Example 8
Project: CustomWorldGen   File: BlockFenceGate.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 (((Boolean)state.getValue(OPEN)).booleanValue())
    {
        state = state.withProperty(OPEN, Boolean.valueOf(false));
        worldIn.setBlockState(pos, state, 10);
    }
    else
    {
        EnumFacing enumfacing = EnumFacing.fromAngle((double)playerIn.rotationYaw);

        if (state.getValue(FACING) == enumfacing.getOpposite())
        {
            state = state.withProperty(FACING, enumfacing);
        }

        state = state.withProperty(OPEN, Boolean.valueOf(true));
        worldIn.setBlockState(pos, state, 10);
    }

    worldIn.playEvent(playerIn, ((Boolean)state.getValue(OPEN)).booleanValue() ? 1008 : 1014, pos, 0);
    return true;
}
 
Example 9
Project: HeroUtils   File: EntityDummy.java   Source Code and License Vote up 5 votes
/**
 * Updates the task
 */
public void updateTask()
{
    EntityLivingBase entitylivingbase = this.parentEntity.getAttackTarget();
    if (entitylivingbase.getDistanceSqToEntity(this.parentEntity) < 4096.0D && this.parentEntity.canEntityBeSeen(entitylivingbase))
    {
        World world = this.parentEntity.worldObj;
        ++this.attackTimer;

        if (this.attackTimer == 10)
        {
            world.playEvent((EntityPlayer)null, 1015, new BlockPos(this.parentEntity), 0);
        }

        if (this.attackTimer == 20)
        {
            Vec3d vec3d = this.parentEntity.getLook(1.0F);
            double d2 = entitylivingbase.posX - (this.parentEntity.posX + vec3d.xCoord * 4.0D);
            double d3 = entitylivingbase.getEntityBoundingBox().minY + (double)(entitylivingbase.height / 2.0F) - (0.5D + this.parentEntity.posY + (double)(this.parentEntity.height / 2.0F));
            double d4 = entitylivingbase.posZ - (this.parentEntity.posZ + vec3d.zCoord * 4.0D);
            world.playEvent((EntityPlayer)null, 1016, new BlockPos(this.parentEntity), 0);
            EntityLargeFireball entitylargefireball = new EntityLargeFireball(world, this.parentEntity, d2, d3, d4);
            entitylargefireball.explosionPower = this.parentEntity.getFireballStrength();
            entitylargefireball.posX = this.parentEntity.posX + vec3d.xCoord * 4.0D;
            entitylargefireball.posY = this.parentEntity.posY + (double)(this.parentEntity.height / 2.0F) + 0.5D;
            entitylargefireball.posZ = this.parentEntity.posZ + vec3d.zCoord * 4.0D;
            world.spawnEntityInWorld(entitylargefireball);
            this.attackTimer = -40;
        }
    }
    else if (this.attackTimer > 0)
    {
        --this.attackTimer;
    }

    this.parentEntity.setAttacking(this.attackTimer > 10);
}
 
Example 10
Project: CustomWorldGen   File: EntityGhast.java   Source Code and License Vote up 5 votes
/**
 * Updates the task
 */
public void updateTask()
{
    EntityLivingBase entitylivingbase = this.parentEntity.getAttackTarget();
    double d0 = 64.0D;

    if (entitylivingbase.getDistanceSqToEntity(this.parentEntity) < 4096.0D && this.parentEntity.canEntityBeSeen(entitylivingbase))
    {
        World world = this.parentEntity.worldObj;
        ++this.attackTimer;

        if (this.attackTimer == 10)
        {
            world.playEvent((EntityPlayer)null, 1015, new BlockPos(this.parentEntity), 0);
        }

        if (this.attackTimer == 20)
        {
            double d1 = 4.0D;
            Vec3d vec3d = this.parentEntity.getLook(1.0F);
            double d2 = entitylivingbase.posX - (this.parentEntity.posX + vec3d.xCoord * 4.0D);
            double d3 = entitylivingbase.getEntityBoundingBox().minY + (double)(entitylivingbase.height / 2.0F) - (0.5D + this.parentEntity.posY + (double)(this.parentEntity.height / 2.0F));
            double d4 = entitylivingbase.posZ - (this.parentEntity.posZ + vec3d.zCoord * 4.0D);
            world.playEvent((EntityPlayer)null, 1016, new BlockPos(this.parentEntity), 0);
            EntityLargeFireball entitylargefireball = new EntityLargeFireball(world, this.parentEntity, d2, d3, d4);
            entitylargefireball.explosionPower = this.parentEntity.getFireballStrength();
            entitylargefireball.posX = this.parentEntity.posX + vec3d.xCoord * 4.0D;
            entitylargefireball.posY = this.parentEntity.posY + (double)(this.parentEntity.height / 2.0F) + 0.5D;
            entitylargefireball.posZ = this.parentEntity.posZ + vec3d.zCoord * 4.0D;
            world.spawnEntityInWorld(entitylargefireball);
            this.attackTimer = -40;
        }
    }
    else if (this.attackTimer > 0)
    {
        --this.attackTimer;
    }

    this.parentEntity.setAttacking(this.attackTimer > 10);
}
 
Example 11
Project: Got-Wood   File: FireHandler.java   Source Code and License Vote up 5 votes
public boolean extinguishFire(@Nullable EntityPlayer player, BlockPos pos, EnumFacing side, World world) {
	pos = pos.offset(side);
	if (world.getBlockState(pos).getBlock() == BlockRegistry.specialfire) {
		world.playEvent(player, 1009, pos, 0);
		world.setBlockToAir(pos);
		return true;
	}
	return false;
}
 
Example 12
Project: Backmemed   File: ItemEnderEye.java   Source Code and License Vote up 5 votes
public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn)
{
    ItemStack itemstack = worldIn.getHeldItem(playerIn);
    RayTraceResult raytraceresult = this.rayTrace(itemStackIn, worldIn, false);

    if (raytraceresult != null && raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK && itemStackIn.getBlockState(raytraceresult.getBlockPos()).getBlock() == Blocks.END_PORTAL_FRAME)
    {
        return new ActionResult(EnumActionResult.PASS, itemstack);
    }
    else
    {
        worldIn.setActiveHand(playerIn);

        if (!itemStackIn.isRemote)
        {
            BlockPos blockpos = ((WorldServer)itemStackIn).getChunkProvider().getStrongholdGen(itemStackIn, "Stronghold", new BlockPos(worldIn), false);

            if (blockpos != null)
            {
                EntityEnderEye entityendereye = new EntityEnderEye(itemStackIn, worldIn.posX, worldIn.posY + (double)(worldIn.height / 2.0F), worldIn.posZ);
                entityendereye.moveTowards(blockpos);
                itemStackIn.spawnEntityInWorld(entityendereye);
                itemStackIn.playSound((EntityPlayer)null, worldIn.posX, worldIn.posY, worldIn.posZ, SoundEvents.ENTITY_ENDEREYE_LAUNCH, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
                itemStackIn.playEvent((EntityPlayer)null, 1003, new BlockPos(worldIn), 0);

                if (!worldIn.capabilities.isCreativeMode)
                {
                    itemstack.func_190918_g(1);
                }

                worldIn.addStat(StatList.getObjectUseStats(this));
                return new ActionResult(EnumActionResult.SUCCESS, itemstack);
            }
        }

        return new ActionResult(EnumActionResult.SUCCESS, itemstack);
    }
}
 
Example 13
Project: CustomWorldGen   File: BlockChorusFlower.java   Source Code and License Vote up 4 votes
private void placeDeadFlower(World p_185605_1_, BlockPos p_185605_2_)
{
    p_185605_1_.setBlockState(p_185605_2_, this.getDefaultState().withProperty(AGE, Integer.valueOf(5)), 2);
    p_185605_1_.playEvent(1034, p_185605_2_, 0);
}
 
Example 14
Project: Adventurers-Toolbox   File: ItemATHammer.java   Source Code and License Vote up 4 votes
@Override
public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer player) {
	World world = player.getEntityWorld();

	if (!world.isRemote && player instanceof EntityPlayerMP) {

		RayTraceResult rt = this.rayTrace(world, player, false);
		if (rt.typeOfHit == RayTraceResult.Type.BLOCK) {
			EnumFacing side = rt.sideHit;

			List<BlockPos> extraBlocks = getExtraBlocks(world, rt, player);

			for (BlockPos pos2 : extraBlocks) {

				IBlockState state = world.getBlockState(pos2);

				if (!world.isBlockLoaded(pos2) || !player.canPlayerEdit(pos2, side, itemstack) || !(state.getBlock().canHarvestBlock(world, pos2, player))) {
					continue;
				}

				if (player.capabilities.isCreativeMode) {
					state.getBlock().onBlockHarvested(world, pos2, state, player);
					if (state.getBlock().removedByPlayer(state, world, pos2, player, false)) {
						state.getBlock().onBlockDestroyedByPlayer(world, pos2, state);
					}
				} else {
					int xp = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) player).interactionManager.getGameType(), (EntityPlayerMP) player, pos2);

					state.getBlock().onBlockHarvested(world, pos2, state, player);
					this.onBlockDestroyed(itemstack, world, state, pos2, player);
					if (state.getBlock().removedByPlayer(state, world, pos2, player, true)) {
						state.getBlock().onBlockDestroyedByPlayer(world, pos2, state);
						state.getBlock().harvestBlock(world, player, pos2, state, world.getTileEntity(pos2), itemstack);
						state.getBlock().dropXpOnBlockBreak(world, pos2, xp);
					}
				}

				world.playEvent(2001, pos, Block.getStateId(state));
				((EntityPlayerMP) player).connection.sendPacket(new SPacketBlockChange(world, pos));

			}

		}

	}

	return false;
}
 
Example 15
Project: Thermionics   File: ToolHelper.java   Source Code and License Vote up 4 votes
/**
 * Destroys and tries to harvest a block with the currently active tool, except that instead of calling
 * onBlockDestroyed, it calls onBlockAuxDestroyed on the tool, preventing infinite loops.
 */
public static boolean auxHarvestBlock(World world, BlockPos pos, EntityPlayerMP player) {
	if (world.isRemote) return false; //Shouldn't even be possible if we have an EntityPlayerMP!
	
	GameType gameType = player.interactionManager.getGameType();
	
	int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(world, gameType, player, pos);
       if (exp == -1) {
           return false;
       } else {
           IBlockState iblockstate = world.getBlockState(pos);
           if (iblockstate.getBlockHardness(world, pos)<0) return false;
           TileEntity tileentity = world.getTileEntity(pos);
           Block block = iblockstate.getBlock();

           if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !player.canUseCommandBlock()) {
               world.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);
               return false;
           } else {
               ItemStack stack = player.getHeldItemMainhand();
               if (!stack.isEmpty() && stack.getItem().onBlockStartBreak(stack, pos, player)) return false;

               world.playEvent(player, 2001, pos, Block.getStateId(iblockstate));
               boolean removed = false;

               if (gameType==GameType.CREATIVE) {
                   removed = removeBlock(world, pos, player, false);
                   player.connection.sendPacket(new SPacketBlockChange(world, pos));
               } else {
                   ItemStack itemstack1 = player.getHeldItemMainhand();
                   ItemStack itemstack2 = itemstack1.isEmpty() ? ItemStack.EMPTY : itemstack1.copy();
                   boolean canHarvest = iblockstate.getBlock().canHarvestBlock(world, pos, player);

                   if (!itemstack1.isEmpty()) {
                   //    itemstack1.onBlockDestroyed(world, iblockstate, pos, player);
                    if (itemstack1.getItem() instanceof IAuxDestroyBlock) {
                    	((IAuxDestroyBlock)itemstack1.getItem()).onBlockAuxDestroyed(world, iblockstate, pos, player);
                    }
                   }
                   
                   removed = removeBlock(world, pos, player, canHarvest);
                   if (removed && canHarvest) {
                       iblockstate.getBlock().harvestBlock(world, player, pos, iblockstate, tileentity, itemstack2);
                   }
               }

               // Drop experience
               if (gameType!=GameType.CREATIVE && removed && exp > 0) {
                   iblockstate.getBlock().dropXpOnBlockBreak(world, pos, exp);
               }
               return removed;
           }
       }
}
 
Example 16
Project: AdvancedCombat   File: BlockTrackingDispenser.java   Source Code and License Vote up 4 votes
/** Custom dispense routines */
@Override
protected void dispense(World worldIn, BlockPos pos) {
       BlockSourceImpl src = new BlockSourceImpl(worldIn, pos);
       TileEntityDispenser tile = (TileEntityDispenser)src.getBlockTileEntity();

       if (tile != null) {
           int i = tile.getDispenseSlot();

           if (i < 0) {
               worldIn.playEvent(1001, pos, 0);
           } else {
           	
           	// get the active item from its slot
               ItemStack itemstack = tile.getStackInSlot(i);
               IBehaviorDispenseItem defaultbehavior = this.getBehavior(itemstack);

               // make sure it's not regular dropper behavior
               if (defaultbehavior != IBehaviorDispenseItem.DEFAULT_BEHAVIOR) {
               	ItemStack itemstack1 = null;
               	
               	// replace vanilla behavior
               	if(defaultbehavior instanceof BehaviorProjectileDispense) {
               		itemstack1 = this.dispenseProjectile((BehaviorProjectileDispense)defaultbehavior, src, itemstack);
               	} else if(itemstack.getItem() instanceof ItemSplashPotion || itemstack.getItem() instanceof ItemLingeringPotion) {
               		itemstack1 = this.dispensePotion(src, itemstack);
               	} else if(itemstack.getItem() instanceof ItemFireball) {
               		itemstack1 = this.dispenseFireball(src, itemstack);
               	}
               	
               	// revert to vanilla on failure
               	if(itemstack1 == null) {
               		itemstack1 = defaultbehavior.dispense(src, itemstack);
               	}
               	
               	// update the inventory
                   tile.setInventorySlotContents(i, itemstack1.getCount() <= 0 ? ItemStack.EMPTY : itemstack1);
               }
           }
       }
   }
 
Example 17
Project: Backmemed   File: BlockChorusFlower.java   Source Code and License Vote up 4 votes
private void placeDeadFlower(World p_185605_1_, BlockPos p_185605_2_)
{
    p_185605_1_.setBlockState(p_185605_2_, this.getDefaultState().withProperty(AGE, Integer.valueOf(5)), 2);
    p_185605_1_.playEvent(1034, p_185605_2_, 0);
}
 
Example 18
Project: Mods   File: TF2Util.java   Source Code and License 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: Backmemed   File: BlockChorusFlower.java   Source Code and License Vote up 4 votes
private void placeGrownFlower(World p_185602_1_, BlockPos p_185602_2_, int p_185602_3_)
{
    p_185602_1_.setBlockState(p_185602_2_, this.getDefaultState().withProperty(AGE, Integer.valueOf(p_185602_3_)), 2);
    p_185602_1_.playEvent(1033, p_185602_2_, 0);
}
 
Example 20
Project: Backmemed   File: BlockAnvil.java   Source Code and License Vote up 4 votes
public void onEndFalling(World worldIn, BlockPos pos)
{
    worldIn.playEvent(1031, pos, 0);
}