net.minecraft.world.World.playSound()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(167)

本文整理了Java中net.minecraft.world.World.playSound()方法的一些代码示例,展示了World.playSound()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。World.playSound()方法的具体详情如下:
包路径:net.minecraft.world.World
类名称:World
方法名:playSound

World.playSound介绍

暂无

代码示例

代码示例来源:origin: Vazkii/Botania

public static void playSound(World world, ItemStack stack, double x, double y, double z, SoundCategory category, float volume) {
  if(stack.isEmpty())
    return;
  SoundEvent sound = getSound(stack);
  if(sound != null)
    world.playSound(null, x, y, z, sound, category, volume, sound == ModSounds.doit ? 1F : (world.rand.nextFloat() - world.rand.nextFloat()) * 0.2F + 1.0F);
}

代码示例来源:origin: Vazkii/Botania

public void playSound() {
  supertile.getWorld().playSound(null, supertile.getPos(), SoundEvents.ENTITY_GENERIC_DRINK, SoundCategory.BLOCKS, 0.01F, 0.5F + (float) Math.random() * 0.5F);
}

代码示例来源:origin: Vazkii/Botania

@Override
public void playSound() {
  supertile.getWorld().playSound(null, supertile.getPos(), ModSounds.thermalily, SoundCategory.BLOCKS, 0.2F, 1F);
}

代码示例来源:origin: Vazkii/Botania

public boolean effectOnDamage(LivingHurtEvent event, EntityPlayer player, ItemStack stack) {
  if(!event.getSource().isMagicDamage()) {
    event.setCanceled(true);
    player.world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.holyCloak, SoundCategory.PLAYERS, 1F, 1F);
    for(int i = 0; i < 30; i++) {
      double x = player.posX + Math.random() * player.width * 2 - player.width;
      double y = player.posY + Math.random() * player.height;
      double z = player.posZ + Math.random() * player.width * 2 - player.width;
      boolean yellow = Math.random() > 0.5;
      Botania.proxy.sparkleFX(x, y, z, yellow ? 1F : 0.3F, yellow ? 1F : 0.3F, yellow ? 0.3F : 1F, 0.8F + (float) Math.random() * 0.4F, 3);
    }
    return true;
  }
  return false;
}

代码示例来源:origin: Vazkii/Botania

@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
  ItemStack stack = player.getHeldItem(hand);
  int dmg = stack.getItemDamage();
  stack.setItemDamage(~dmg & 1);
  world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.NEUTRAL, 0.3F, 0.1F);
  return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}

代码示例来源:origin: Vazkii/Botania

private void craftingFanciness() {
  if(soundTicks == 0) {
    world.playSound(null, pos, ModSounds.manaPoolCraft, SoundCategory.BLOCKS, 0.4F, 4F);
    soundTicks = 6;
  }
  world.addBlockEvent(getPos(), getBlockType(), CRAFT_EFFECT_EVENT, 0);
}

代码示例来源:origin: Vazkii/Botania

@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float par8, float par9, float par10) {
  if(player.isSneaking() && !world.isRemote) {
    TileEntity tile = world.getTileEntity(pos);
    if(tile != null && tile instanceof IManaPool) {
      bindPool(player.getHeldItem(hand), tile);
      world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.ding, SoundCategory.PLAYERS, 1F, 1F);
      return EnumActionResult.SUCCESS;
    }
  }
  return EnumActionResult.PASS;
}

代码示例来源:origin: Vazkii/Botania

private static void moveParticlesAndSound(Entity entity) {
  PacketHandler.sendToNearby(entity.world, entity, new PacketBotaniaEffect(PacketBotaniaEffect.EffectType.FLUGEL_EFFECT, entity.posX, entity.posY, entity.posZ, entity.getEntityId()));
  entity.world.playSound(null, entity.posX, entity.posY, entity.posZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.PLAYERS, 1F, 1F);
}

代码示例来源:origin: Vazkii/Botania

private boolean teleportTo(double x, double y, double z) {
  /* Botania - no events
  net.minecraftforge.event.entity.living.EnderTeleportEvent event = new net.minecraftforge.event.entity.living.EnderTeleportEvent(this, x, y, z, 0);
  if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event)) return false;
  boolean flag = this.attemptTeleport(event.getTargetX(), event.getTargetY(), event.getTargetZ());
  */
  boolean flag = this.attemptTeleport(x, y, z);
  if (flag)
  {
    this.world.playSound((EntityPlayer)null, this.prevPosX, this.prevPosY, this.prevPosZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, this.getSoundCategory(), 1.0F, 1.0F);
    this.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
  }
  return flag;
}

代码示例来源:origin: Vazkii/Botania

@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
  if(!player.capabilities.isCreativeMode)
    player.getHeldItem(hand).shrink(1);
  world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
  if(!world.isRemote) {
    EntityVineBall ball = new EntityVineBall(player, true);
    ball.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F);
    world.spawnEntity(ball);
  }
  return ActionResult.newResult(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}

代码示例来源:origin: Vazkii/Botania

@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
  ItemStack stack = player.getHeldItem(hand);
  getMana(stack);
  int level = getLevel(stack);
  if(level != 0) {
    setEnabled(stack, !isEnabled(stack));
    if(!world.isRemote)
      world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.terraPickMode, SoundCategory.PLAYERS, 0.5F, 0.4F);
  }
  return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}

代码示例来源:origin: Vazkii/Botania

@Override
public void onUsingTick(ItemStack stack, EntityLivingBase player, int time) {
  if(!player.world.isRemote) {
    if(time != getMaxItemUseDuration(stack) && time % 5 == 0)
      breakGrass(player.world, stack, stack.getItemDamage(), new BlockPos(player));
    player.world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.BLOCK_NOTE_BASS, SoundCategory.BLOCKS, 1F, 0.001F);
  }
}

代码示例来源:origin: Vazkii/Botania

@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float par8, float par9, float par10) {
  if(!world.isRemote && pos.getY() < 160 && !world.provider.doesWaterVaporize()) {
    world.playSound(null, pos, ModSounds.laputaStart, SoundCategory.BLOCKS, 1.0F + world.rand.nextFloat(), world.rand.nextFloat() * 0.7F + 1.3F);
    ItemStack stack = player.getHeldItem(hand);
    spawnBurstFirst(world, pos, stack);
    UseItemSuccessTrigger.INSTANCE.trigger((EntityPlayerMP) player, stack, (WorldServer) world, pos.getX(), pos.getY(), pos.getZ());
    stack.shrink(1);
  }
  return EnumActionResult.SUCCESS;
}

代码示例来源:origin: Vazkii/Botania

@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer p, @Nonnull EnumHand hand) {
  ItemStack stack = p.getHeldItem(hand);
  if(ManaItemHandler.requestManaExactForTool(stack, p, COST, true)) {
    if(world.isRemote) {
      int range = IManaProficiencyArmor.Helper.hasProficiency(p, stack) ? 20 : 15;
      long seedxor = world.rand.nextLong();
      doHighlight(world, new BlockPos(p), range, seedxor);
      p.swingArm(hand);
    } else world.playSound(null, p.posX, p.posY, p.posZ, ModSounds.divinationRod, SoundCategory.PLAYERS, 1F, 1F);
    return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
  }
  return ActionResult.newResult(EnumActionResult.PASS, stack);
}

代码示例来源:origin: Vazkii/Botania

@Override
public void onEquipped(ItemStack stack, EntityLivingBase player) {
  if(player != null) {
    if(!player.world.isRemote) {
      player.world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.equipBauble, SoundCategory.PLAYERS, 0.1F, 1.3F);
      PlayerHelper.grantCriterion((EntityPlayerMP) player, new ResourceLocation(LibMisc.MOD_ID, "main/bauble_wear"), "code_triggered");
    }
    onEquippedOrLoadedIntoWorld(stack, player);
    setLastPlayerHashcode(stack, player.hashCode());
  }
}

代码示例来源:origin: Vazkii/Botania

@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, @Nonnull EnumHand hand) {
  ItemStack stack = playerIn.getHeldItem(hand);
  if(playerIn.isSneaking()) {
    int size = getSize(stack);
    int newSize = size == 11 ? 3 : size + 2;
    setSize(stack, newSize);
    ItemsRemainingRenderHandler.set(stack, newSize + "x" + newSize);
    worldIn.playSound(playerIn, playerIn.getPosition(), SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 0.5F, 1F);
    
    return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
  }
  return ActionResult.newResult(EnumActionResult.PASS, stack);
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

public void startFuse( final World w, final BlockPos pos, final EntityLivingBase igniter )
{
  if( !w.isRemote )
  {
    final EntityTinyTNTPrimed primedTinyTNTEntity = new EntityTinyTNTPrimed( w, pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, igniter );
    w.spawnEntity( primedTinyTNTEntity );
    w.playSound( null, primedTinyTNTEntity.posX, primedTinyTNTEntity.posY, primedTinyTNTEntity.posZ, SoundEvents.ENTITY_TNT_PRIMED,
        SoundCategory.BLOCKS, 1, 1 );
  }
}

代码示例来源:origin: Vazkii/Botania

@Override
public boolean onUsedByWand(EntityPlayer player, ItemStack stack, World world, BlockPos pos, EnumFacing side) {
  if(player == null || world.isRemote)
    return false;
  if(!player.isSneaking()) {
    playerPositions.put(player.getUniqueID(), new DimWithPos(world.provider.getDimension(), pos));
    world.playSound(null, pos, ModSounds.ding, SoundCategory.BLOCKS, 0.5F, 1F);
  } else {
    spawnAsEntity(world, pos, new ItemStack(this));
    world.setBlockToAir(pos);
    world.playEvent(2001, pos, Block.getStateId(getDefaultState()));
  }
  return true;
}

代码示例来源:origin: Vazkii/Botania

public void onWanded(EntityPlayer player, ItemStack wand) {
  if(player == null)
    return;
  if(player.isSneaking()) {
    outputting = !outputting;
    VanillaPacketDispatcher.dispatchTEToNearbyPlayers(world, pos);
  }
  if(!world.isRemote) {
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    writePacketNBT(nbttagcompound);
    nbttagcompound.setInteger(TAG_KNOWN_MANA, getCurrentMana());
    if(player instanceof EntityPlayerMP)
      ((EntityPlayerMP) player).connection.sendPacket(new SPacketUpdateTileEntity(pos, -999, nbttagcompound));
  }
  world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.ding, SoundCategory.PLAYERS, 0.11F, 1F);
}

代码示例来源:origin: Vazkii/Botania

public void trySpawnBurst(EntityPlayer player) {
  if (!player.getHeldItemMainhand().isEmpty()
      && player.getHeldItemMainhand().getItem() == this
      && player.getCooledAttackStrength(0) == 1) {
    EntityManaBurst burst = getBurst(player, player.getHeldItemMainhand());
    player.world.spawnEntity(burst);
    ToolCommons.damageItem(player.getHeldItemMainhand(), 1, player, MANA_PER_DAMAGE);
    player.world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.terraBlade, SoundCategory.PLAYERS, 0.4F, 1.4F);
  }
}

相关文章

微信公众号

最新文章

更多

World类方法