在播放声音对时候游戏崩溃

FledgeXu


此贴为提问记录贴
提问者:慕凯
版本信息
你使用的IDE:未知
你使用的IDE版本:未知
Forge版本: 未知
Minecraft版本: 1.12.2

错误情况简述
在播放声音对时候游戏崩溃

报错日志

相关代码

public class EventLoader {
	public EventLoader(FMLPreInitializationEvent event) {
		MinecraftForge.EVENT_BUS.register(this);
	}

	public static final EventBus EVENT_BUS = new EventBus();

	@SubscribeEvent
	public void hello(PlayerEvent.PlayerLoggedInEvent event) {
		EntityPlayer player = event.player;
		String s1 = "\n";

		if (player.getName().equals("Herobrine_CZM")) {
			player.sendMessage(new TextComponentTranslation("omg.czm", s1));
		}

	}

	@SubscribeEvent
	public void PlayMusicRecord(PlaySoundEvent event) {
		event.getSound();
		ISound sound = event.getSound();

	}

	/*
	 * @SubscribeEvent public static void
	 * onEnchantmentRegistration(RegistryEvent.Register<Enchantment> event) {
	 * event.getRegistry().registerAll(new
	 * Enchantment_Music_Kill(Rarity.COMMON).setName("Music_Kill").setRegistryName(
	 * "Enchantment_Music_Kill")); }
	 */
	@SubscribeEvent
	public void HitDropMusic(LivingHurtEvent event) {
		Entity hit = event.getEntity();
		DamageSource source = event.getSource();
		if (hit instanceof EntityCreature) {
			if (event.getSource().getTrueSource() instanceof EntityPlayer) {
				// if (event.getSource().getTrueSource() != null) {
				EntityPlayer player = (EntityPlayer) event.getSource().getTrueSource();
				ItemStack item = player.getHeldItemMainhand();
				if (player.getHeldItemMainhand().isItemEnchanted()) {
					int lv = EnchantmentHelper.getEnchantmentLevel(EnchantmentLoader.musichit, item);
					Random random = new Random();
					int x = random.nextInt(4);
					int y = random.nextInt(10);
					ItemStack[] musics = new ItemStack[4];
					musics[0] = new ItemStack(ItemLoader.puremax);
					musics[1] = new ItemStack(ItemLoader.pure);
					musics[2] = new ItemStack(ItemLoader.far);
					musics[3] = new ItemStack(ItemLoader.grass);
					if (lv == 1) {
						if (y == 1) {
							hit.entityDropItem(musics[x], 1);
						}
					}
					if (lv == 2) {
						if (y <= 2) {
							hit.entityDropItem(musics[x], 1);
						}
					}
					if (lv == 4) {
						if (y <= 3) {
							hit.entityDropItem(musics[x], 1);
						}
					}
					if (lv == 4) {
						if (y <= 4) {
							hit.entityDropItem(musics[x], 1);
						}
					}
					if (lv == 5) {
						if (y <= 5) {
							hit.entityDropItem(musics[x], 1);
						}
					}
					// }
				}
			}
		}
	}

	@SubscribeEvent
	public void KillDropMusic(LivingExperienceDropEvent event) {
		EntityPlayer player = event.getAttackingPlayer();
		Entity die = event.getEntity();
		if (die instanceof EntityCreature) {
			// DamageSource source = event.getSource();
			// if(source.getDamageType().equals("Player")) {
			// List<EntityItem> drops = event.getDrops();

			ItemStack item = player.getHeldItemMainhand();
			// NBTTagList list;
			// World world = player.world;
			// BlockPos pos = event.getEntity().getPosition();
			// int t = 1;
			// if (event.getDrops().isEmpty()) {
			if (player.getHeldItemMainhand().isItemEnchanted()) {
				// list=player.getHeldItemMainhand().getEnchantmentTagList();
				int lv = EnchantmentHelper.getEnchantmentLevel(EnchantmentLoader.musickill, item);
				if (lv > 0) {
					Random random = new Random();
					int x = random.nextInt(4);
					int y = random.nextInt(4);

					ItemStack[] musics = new ItemStack[4];
					musics[0] = new ItemStack(ItemLoader.puremax);
					musics[1] = new ItemStack(ItemLoader.pure);
					musics[2] = new ItemStack(ItemLoader.far);
					musics[3] = new ItemStack(ItemLoader.grass);
					ItemStack[] musics2 = new ItemStack[4];
					musics2[0] = new ItemStack(ItemLoader.puremax, 2);
					musics2[1] = new ItemStack(ItemLoader.pure, 2);
					musics2[2] = new ItemStack(ItemLoader.far, 2);
					musics2[3] = new ItemStack(ItemLoader.grass, 2);
					// EntityItem music = new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(),
					// musics[x]);
					if (lv == 1) {

						// drops.add(music);
						die.entityDropItem(musics[x], 1);
					}
					if (lv == 2) {

						// drops.add(music);
						if (y == 1) {
							die.entityDropItem(musics2[x], 1);
						} else {
							die.entityDropItem(musics[y], 1);
						}
					}
					if (lv == 3) {
						if (y != 1) {
							die.entityDropItem(musics2[y], 1);
						} else {
							die.entityDropItem(musics[x], 1);
						}
					}
				}
			}
		}
	}
}

FledgeXu


回答者:3TUSK

@SubscribeEvent
	public void PlayMusicRecord(PlaySoundEvent event) {
		event.getSound();
		ISound sound = event.getSound();

	}

PlaySoundEvent是播放声音的事件,不应该在服务端调用,需要单独拆分到另一个事件处理类中。

可以用注释中的value参数指定注册的端。

@Mod.EventBusSubscriber(modid = "你的 modid", value = Side.CLIENT)

FledgeXu