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

The following examples show how to use net.minecraft.world.World#playEvent() . 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: BlockFenceGate.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    if (!content.opensWithHands)
        return true;

    if (state.getValue(OPEN))
    {
        state = state.withProperty(OPEN, Boolean.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.TRUE);
        worldIn.setBlockState(pos, state, 10);
    }

    worldIn.playEvent(playerIn, state.getValue(OPEN) ? 1008 : 1014, pos, 0);
    return true;
}
 
Example 2
Source File: BlockFenceGate.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
{
    if (!worldIn.isRemote && content.opensWithRedstone)
    {
        boolean flag = worldIn.isBlockPowered(pos);

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

            if (state.getValue(OPEN) != flag)
            {
                worldIn.playEvent(null, flag ? 1008 : 1014, pos, 0);
            }
        }
    }
}
 
Example 3
Source File: BlockMetalDoor.java    From BaseMetals with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
  public boolean onBlockActivated(final World world, final BlockPos coord, IBlockState blockstate, 
  		                        final EntityPlayer player,
                                  final EnumHand hand, ItemStack heldItem,
                                  final EnumFacing face,
  		                        final float partialX, final float partialY, final float partialZ) {
if (this.metal.getToolHarvestLevel() > 1) {
          return false;
      }
      final BlockPos pos = (blockstate.getValue(BlockDoor.HALF) == EnumDoorHalf.LOWER) ? coord : coord.down();
      final IBlockState bs = coord.equals(pos) ? blockstate : world.getBlockState(pos);
      if (bs.getBlock() != this) {
          return false;
      }
      blockstate = bs.cycleProperty(BlockDoor.OPEN);
      world.setBlockState(pos, blockstate, 2);
      world.markBlockRangeForRenderUpdate(pos, coord);
      world.playEvent(player, ((Boolean)blockstate.getValue(BlockDoor.OPEN)) ? 1003 : 1006, coord, 0);
      return true;
  }
 
Example 4
Source File: BlockShoji.java    From Sakura_mod with MIT License 5 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    state = state.cycleProperty(OPEN);
    worldIn.setBlockState(pos, state, 10);
    worldIn.markBlockRangeForRenderUpdate(pos, pos);
    worldIn.playEvent(playerIn, state.getValue(OPEN) ? 1006 : 1012, pos, 0);
    TileEntityShoji te = (TileEntityShoji) worldIn.getTileEntity(pos);
    if (te != null) {
        te.setOpen(!te.isOpen());
        te.setAnimation(10);
    }
    return true;
}
 
Example 5
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 6
Source File: BonemealWrapper.java    From AgriCraft with MIT License 5 votes vote down vote up
@Override
public boolean applyFertilizer(EntityPlayer player, World world, BlockPos pos, IAgriFertilizable target, ItemStack stack, Random random) {
    if (target.acceptsFertilizer(this) && target.onApplyFertilizer(this, random) == MethodResult.SUCCESS) {
        world.playEvent(2005, pos, 1); // Bonemeal particle effect. Last parameter (data) is num of particles.
        if (player == null || !player.capabilities.isCreativeMode) {
            stack.setCount(stack.getCount() - 1);
        }
        return true;
    } else {
        return false;
    }
}
 
Example 7
Source File: UpgradeBreaker.java    From BetterChests with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * see PlayerInteractionManager.tryHarvestBlock
 */
public boolean breakBlock(EntityPlayerMP player, BlockPos pos) {
	World world = player.world;
	IBlockState state = world.getBlockState(pos);
	TileEntity te = world.getTileEntity(pos);

	if (state.getBlockHardness(world, pos) < 0 || !state.getBlock().canHarvestBlock(world, pos, player))
	{
		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(state));
		ItemStack itemHand = player.getHeldItemMainhand();
		ItemStack itemHandCopy = itemHand.isEmpty() ? ItemStack.EMPTY : itemHand.copy();
		boolean canHarvest = state.getBlock().canHarvestBlock(world, pos, player);

		if (!itemHand.isEmpty()) {
			itemHand.onBlockDestroyed(world, state, pos, player);
			if (itemHand.isEmpty()) {
				ForgeEventFactory.onPlayerDestroyItem(player, itemHandCopy, EnumHand.MAIN_HAND);
			}
		}

		boolean didRemove = removeBlock(player, pos, canHarvest);
		if (didRemove && canHarvest) {
			state.getBlock().harvestBlock(world, player, pos, state, te, itemHandCopy);
		}
		return didRemove;
	}
}
 
Example 8
Source File: ModuleEffectThrive.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean run(@NotNull World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
	BlockPos targetPos = spell.getTargetPos();
	Entity targetEntity = spell.getVictim(world);
	Entity caster = spell.getCaster(world);
	Vec3d pos = spell.getTarget(world);

	if (pos == null) return true;

	if (targetEntity instanceof EntityLivingBase) {
		double potency = spellRing.getAttributeValue(world, AttributeRegistry.POTENCY, spell) / 2;

		if (!spellRing.taxCaster(world, spell, true)) return false;

		((EntityLivingBase) targetEntity).heal((float) potency);
		world.playSound(null, new BlockPos(pos), ModSounds.HEAL, SoundCategory.NEUTRAL, 1, 1);
	}

	if (targetPos != null) {
		BlockPos otherTargetPos = spell.getTargetPos().add(0, 1, 0); // beam missed crops and targets farmland

		if (world.getBlockState(targetPos).getBlock() instanceof IGrowable || world.getBlockState(otherTargetPos).getBlock() instanceof IGrowable) {
			if (!spellRing.taxCaster(world, spell, true)) return false;
			if (!(caster instanceof EntityPlayerMP) || BlockUtils.hasEditPermission(targetPos, (EntityPlayerMP) caster)) {
				ItemDye.applyBonemeal(new ItemStack(Items.DYE), world, targetPos);
				ItemDye.applyBonemeal(new ItemStack(Items.DYE), world, otherTargetPos);

				PacketThriveBlock ptb = new PacketThriveBlock(targetPos);
				PacketHandler.NETWORK.sendToAllAround(ptb, new NetworkRegistry.TargetPoint(world.provider.getDimension(), targetPos.getX(), targetPos.getY(), targetPos.getZ(), 100));

				if (!world.isRemote) {
					world.playEvent(2005, targetPos, 0);
					world.playEvent(2005, otherTargetPos, 0);
				}
			}
		} else if (world.getBlockState(targetPos).getBlock() instanceof IPlantable || world.getBlockState(otherTargetPos).getBlock() instanceof IPlantable) {
			IBlockState state = world.getBlockState(targetPos);
			Block block = state.getBlock();
			if (!spellRing.taxCaster(world, spell, true)) return false;
			if (caster == null || (caster instanceof EntityPlayer && BlockUtils.hasEditPermission(targetPos, (EntityPlayerMP) caster))) {
				while (world.getBlockState(targetPos.up()).getBlock() == block) {
					targetPos = targetPos.up();
					state = world.getBlockState(targetPos);
					block = state.getBlock();
				}
				world.immediateBlockTick(targetPos, state, RandUtil.random);
				world.playSound(null, new BlockPos(pos), ModSounds.HEAL, SoundCategory.NEUTRAL, 1, 1);
			}

			state = world.getBlockState(otherTargetPos);
			block = state.getBlock();

			if (caster == null || (caster instanceof EntityPlayer && BlockUtils.hasEditPermission(otherTargetPos, (EntityPlayerMP) caster))) {
				while (world.getBlockState(otherTargetPos.up()).getBlock() == block) {
					otherTargetPos = otherTargetPos.up();
					state = world.getBlockState(otherTargetPos);
					block = state.getBlock();
				}
				world.immediateBlockTick(otherTargetPos, state, RandUtil.random);
				world.playSound(null, new BlockPos(pos), ModSounds.HEAL, SoundCategory.NEUTRAL, 1, 1);
			}
		}
	}

	return true;
}