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

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

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

World.playSound介绍

暂无

代码示例

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

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

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

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

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

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

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

  1. public boolean effectOnDamage(LivingHurtEvent event, EntityPlayer player, ItemStack stack) {
  2. if(!event.getSource().isMagicDamage()) {
  3. event.setCanceled(true);
  4. player.world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.holyCloak, SoundCategory.PLAYERS, 1F, 1F);
  5. for(int i = 0; i < 30; i++) {
  6. double x = player.posX + Math.random() * player.width * 2 - player.width;
  7. double y = player.posY + Math.random() * player.height;
  8. double z = player.posZ + Math.random() * player.width * 2 - player.width;
  9. boolean yellow = Math.random() > 0.5;
  10. 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);
  11. }
  12. return true;
  13. }
  14. return false;
  15. }

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

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

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

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

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

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

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

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

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

  1. private boolean teleportTo(double x, double y, double z) {
  2. /* Botania - no events
  3. net.minecraftforge.event.entity.living.EnderTeleportEvent event = new net.minecraftforge.event.entity.living.EnderTeleportEvent(this, x, y, z, 0);
  4. if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event)) return false;
  5. boolean flag = this.attemptTeleport(event.getTargetX(), event.getTargetY(), event.getTargetZ());
  6. */
  7. boolean flag = this.attemptTeleport(x, y, z);
  8. if (flag)
  9. {
  10. this.world.playSound((EntityPlayer)null, this.prevPosX, this.prevPosY, this.prevPosZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, this.getSoundCategory(), 1.0F, 1.0F);
  11. this.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
  12. }
  13. return flag;
  14. }

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

  1. @Nonnull
  2. @Override
  3. public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
  4. if(!player.capabilities.isCreativeMode)
  5. player.getHeldItem(hand).shrink(1);
  6. 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));
  7. if(!world.isRemote) {
  8. EntityVineBall ball = new EntityVineBall(player, true);
  9. ball.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F);
  10. world.spawnEntity(ball);
  11. }
  12. return ActionResult.newResult(EnumActionResult.SUCCESS, player.getHeldItem(hand));
  13. }

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

  1. @Nonnull
  2. @Override
  3. public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
  4. ItemStack stack = player.getHeldItem(hand);
  5. getMana(stack);
  6. int level = getLevel(stack);
  7. if(level != 0) {
  8. setEnabled(stack, !isEnabled(stack));
  9. if(!world.isRemote)
  10. world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.terraPickMode, SoundCategory.PLAYERS, 0.5F, 0.4F);
  11. }
  12. return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
  13. }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. public void onWanded(EntityPlayer player, ItemStack wand) {
  2. if(player == null)
  3. return;
  4. if(player.isSneaking()) {
  5. outputting = !outputting;
  6. VanillaPacketDispatcher.dispatchTEToNearbyPlayers(world, pos);
  7. }
  8. if(!world.isRemote) {
  9. NBTTagCompound nbttagcompound = new NBTTagCompound();
  10. writePacketNBT(nbttagcompound);
  11. nbttagcompound.setInteger(TAG_KNOWN_MANA, getCurrentMana());
  12. if(player instanceof EntityPlayerMP)
  13. ((EntityPlayerMP) player).connection.sendPacket(new SPacketUpdateTileEntity(pos, -999, nbttagcompound));
  14. }
  15. world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.ding, SoundCategory.PLAYERS, 0.11F, 1F);
  16. }

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

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

相关文章

World类方法