@Override public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase entity, EnumHand hand) { if(entity instanceof EntityLiving) { EntityLiving living = (EntityLiving) entity; SoundEvent sound = null; if(living instanceof EntityCreeper) sound = SoundEvents.ENTITY_CREEPER_PRIMED; else if(living instanceof EntitySlime) sound = ((EntitySlime) living).isSmallSlime() ? SoundEvents.ENTITY_SMALL_SLIME_SQUISH : SoundEvents.ENTITY_SLIME_SQUISH; else { try { sound = (SoundEvent) ReflectionHelper.findMethod(EntityLiving.class, LibObfuscation.GET_LIVING_SOUND[0], LibObfuscation.GET_LIVING_SOUND[1]).invoke(living); } catch (InvocationTargetException | IllegalAccessException ignored) { Botania.LOGGER.debug("Couldn't get living sound"); } } if(sound != null) { String s = EntityList.getEntityString(entity); if(s == null) s = "generic"; ItemNBTHelper.setString(stack, TAG_SOUND, sound.getRegistryName().toString()); ItemNBTHelper.setString(stack, TAG_SOUND_NAME, "entity." + s + ".name"); player.setHeldItem(hand, stack); if(player.world.isRemote) player.swingArm(hand); return true; } } return false; }
private static SoundEvent getInstrument(String name) { ResourceLocation id = new ResourceLocation(name); for (SoundEvent sound : instruments) { if (sound.getRegistryName().equals(id)) { return sound; } } return null; }
public PacketSound(BlockPos p, SoundEvent t, SoundCategory cat) { pos = p; ResourceLocation r = t.getRegistryName(); domain = r.getNamespace(); type = r.getPath(); category = cat.getName(); //SoundCategory.BLOCKS.getName() }
public NBTTagCompound writeToNBT(NBTTagCompound tag) { if (sound != null) { //noinspection ConstantConditions tag.setString("name", sound.getRegistryName().toString()); } tag.setFloat("length", length); tag.setInteger("volume", volume); return tag; } }
public static void playSoundFromServer(SoundEvent soundEvent, SoundCategory cat, BlockPos nextPos, int dim, int range) { //https://github.com/PrinceOfAmber/Cyclic/issues/506 if (soundEvent != null && soundEvent.getRegistryName() != null) // dont crash trying to play invalid sound ModCyclic.network.sendToAllAround(new PacketSound(nextPos, soundEvent, cat), new NetworkRegistry.TargetPoint(dim, nextPos.getX(), nextPos.getY(), nextPos.getZ(), range)); } }