From d1762654ba1eb4745c2b211055c977099a352dc3 Mon Sep 17 00:00:00 2001 From: c0508383 Date: Wed, 13 Jul 2022 19:27:27 -0500 Subject: [PATCH] ISound: -Allows for the changing of several sound attributes, including volume, pitch, repeating, etc. NpcAPI, IPlayer, IWorld: -Added more sound functions, with sounds that can be stopped and started based on an ID. --- .../java/noppes/npcs/NoppesUtilPlayer.java | 25 +++ .../java/noppes/npcs/NoppesUtilServer.java | 36 ++++ .../java/noppes/npcs/client/ClientProxy.java | 2 + .../noppes/npcs/client/ClientTickHandler.java | 2 + .../npcs/client/PacketHandlerClient.java | 22 +++ .../client/controllers/ScriptClientSound.java | 53 ++++++ .../controllers/ScriptSoundController.java | 68 +++++++ .../npcs/constants/EnumPacketClient.java | 7 +- .../java/noppes/npcs/scripted/NpcAPI.java | 33 +++- .../noppes/npcs/scripted/ScriptSound.java | 173 ++++++++++++++++++ .../noppes/npcs/scripted/ScriptWorld.java | 50 ++++- .../npcs/scripted/entity/ScriptPlayer.java | 26 ++- .../scripted/interfaces/AbstractNpcAPI.java | 17 ++ .../npcs/scripted/interfaces/IWorld.java | 11 ++ .../scripted/interfaces/entity/IPlayer.java | 11 ++ .../interfaces/handler/data/ISound.java | 37 ++++ 16 files changed, 566 insertions(+), 7 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/controllers/ScriptClientSound.java create mode 100644 src/main/java/noppes/npcs/client/controllers/ScriptSoundController.java create mode 100644 src/main/java/noppes/npcs/scripted/ScriptSound.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/handler/data/ISound.java diff --git a/src/main/java/noppes/npcs/NoppesUtilPlayer.java b/src/main/java/noppes/npcs/NoppesUtilPlayer.java index 80ae41d38..ed6a8f552 100644 --- a/src/main/java/noppes/npcs/NoppesUtilPlayer.java +++ b/src/main/java/noppes/npcs/NoppesUtilPlayer.java @@ -33,10 +33,12 @@ import noppes.npcs.controllers.data.*; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleFollower; import cpw.mods.fml.common.network.internal.FMLProxyPacket; +import noppes.npcs.scripted.ScriptSound; import noppes.npcs.scripted.event.DialogEvent; import noppes.npcs.scripted.event.QuestEvent; import noppes.npcs.scripted.interfaces.entity.IPlayer; import noppes.npcs.scripted.interfaces.handler.data.IQuestObjective; +import noppes.npcs.scripted.interfaces.handler.data.ISound; import noppes.npcs.scripted.interfaces.item.IItemStack; import noppes.npcs.scripted.NpcAPI; @@ -482,4 +484,27 @@ public class NoppesUtilPlayer { return list; } + + public static void playSoundTo(EntityPlayerMP player, int id, ScriptSound sound) { + NBTTagCompound compound = sound.writeToNBT(); + if (sound.sourceEntity == null || player.worldObj.provider.dimensionId == sound.sourceEntity.getDimension()) { + Server.sendData(player, EnumPacketClient.PLAY_SOUND_TO, id, compound); + } + } + + public static void stopSoundFor(EntityPlayerMP player, int id) { + Server.sendData(player, EnumPacketClient.STOP_SOUND_FOR, id); + } + + public static void pauseSoundsFor(EntityPlayerMP player) { + Server.sendData(player, EnumPacketClient.PAUSE_SOUNDS); + } + + public static void continueSoundsFor(EntityPlayerMP player) { + Server.sendData(player, EnumPacketClient.CONTINUE_SOUNDS); + } + + public static void stopSoundsFor(EntityPlayerMP player) { + Server.sendData(player, EnumPacketClient.STOP_SOUNDS); + } } diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index dd0012d60..4d4e1f2c3 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -71,6 +71,7 @@ import noppes.npcs.entity.EntityDialogNpc; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleTransporter; import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.ScriptSound; import noppes.npcs.scripted.event.DialogEvent; import noppes.npcs.scripted.interfaces.entity.IPlayer; @@ -324,6 +325,41 @@ public class NoppesUtilServer { } } + public static void playSound(int id, ScriptSound sound) { + List list = MinecraftServer.getServer().getConfigurationManager().playerEntityList; + for (EntityPlayer player : list) { + NoppesUtilPlayer.playSoundTo((EntityPlayerMP) player, id, sound); + } + } + + public static void stopSound(int id) { + List list = MinecraftServer.getServer().getConfigurationManager().playerEntityList; + for (EntityPlayer player : list) { + NoppesUtilPlayer.stopSoundFor((EntityPlayerMP) player, id); + } + } + + public static void pauseSounds() { + List list = MinecraftServer.getServer().getConfigurationManager().playerEntityList; + for (EntityPlayer player : list) { + NoppesUtilPlayer.pauseSoundsFor((EntityPlayerMP) player); + } + } + + public static void continueSounds() { + List list = MinecraftServer.getServer().getConfigurationManager().playerEntityList; + for (EntityPlayer player : list) { + NoppesUtilPlayer.continueSoundsFor((EntityPlayerMP) player); + } + } + + public static void stopSounds() { + List list = MinecraftServer.getServer().getConfigurationManager().playerEntityList; + for (EntityPlayer player : list) { + NoppesUtilPlayer.stopSoundsFor((EntityPlayerMP) player); + } + } + public static void deleteNpc(EntityNPCInterface npc,EntityPlayer player) { Server.sendAssociatedData(npc, EnumPacketClient.DELETE_NPC, npc.getEntityId()); } diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index 22b555211..58fd8ea89 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -131,6 +131,7 @@ import noppes.npcs.client.renderer.blocks.BlockWeaponRackRenderer; import noppes.npcs.config.StringCache; import noppes.npcs.constants.EnumGuiType; import noppes.npcs.containers.*; +import noppes.npcs.client.controllers.ScriptSoundController; import noppes.npcs.controllers.data.PlayerData; import noppes.npcs.entity.*; @@ -158,6 +159,7 @@ public class ClientProxy extends CommonProxy { CustomNpcs.Channel.register(new PacketHandlerClient()); CustomNpcs.ChannelPlayer.register(new PacketHandlerPlayer()); new MusicController(); + new ScriptSoundController(); RenderingRegistry.registerEntityRenderingHandler(EntityNpcPony.class, new RenderNPCPony()); RenderingRegistry.registerEntityRenderingHandler(EntityNpcCrystal.class, new RenderNpcCrystal(new ModelNpcCrystal(0.5F))); diff --git a/src/main/java/noppes/npcs/client/ClientTickHandler.java b/src/main/java/noppes/npcs/client/ClientTickHandler.java index 6fad3431c..b58c157d4 100644 --- a/src/main/java/noppes/npcs/client/ClientTickHandler.java +++ b/src/main/java/noppes/npcs/client/ClientTickHandler.java @@ -6,6 +6,7 @@ import net.minecraft.world.World; import noppes.npcs.CustomNpcs; import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.client.controllers.MusicController; +import noppes.npcs.client.controllers.ScriptSoundController; import noppes.npcs.client.gui.player.GuiQuestLog; import noppes.npcs.client.renderer.RenderNPCInterface; import noppes.npcs.constants.EnumPlayerPacket; @@ -43,6 +44,7 @@ public class ClientTickHandler{ prevWorld = mc.theWorld; MusicController.Instance.stopMusic(); } + ScriptSoundController.Instance.onUpdate(); } @SubscribeEvent diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index fca92c895..006977b35 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -25,6 +25,8 @@ import noppes.npcs.Server; import noppes.npcs.ServerEventsHandler; import noppes.npcs.client.ClientProxy.FontContainer; import noppes.npcs.client.controllers.MusicController; +import noppes.npcs.client.controllers.ScriptClientSound; +import noppes.npcs.client.controllers.ScriptSoundController; import noppes.npcs.client.gui.GuiNpcMobSpawnerAdd; import noppes.npcs.client.gui.OverlayQuestTracking; import noppes.npcs.client.gui.customoverlay.OverlayCustom; @@ -305,5 +307,25 @@ public class PacketHandlerClient extends PacketHandlerServer{ } } catch (Exception ignored) {} } + else if(type == EnumPacketClient.PLAY_SOUND_TO) { + int id = buffer.readInt(); + NBTTagCompound compound = Server.readNBT(buffer); + ScriptClientSound sound = ScriptClientSound.fromScriptSound(compound, player.worldObj); + + ScriptSoundController.Instance.playSound(id,sound); + } + else if(type == EnumPacketClient.STOP_SOUND_FOR) { + int id = buffer.readInt(); + ScriptSoundController.Instance.stopSound(id); + } + else if(type == EnumPacketClient.PAUSE_SOUNDS) { + ScriptSoundController.Instance.pauseAllSounds(); + } + else if(type == EnumPacketClient.CONTINUE_SOUNDS) { + ScriptSoundController.Instance.continueAllSounds(); + } + else if(type == EnumPacketClient.STOP_SOUNDS) { + ScriptSoundController.Instance.stopAllSounds(); + } } } diff --git a/src/main/java/noppes/npcs/client/controllers/ScriptClientSound.java b/src/main/java/noppes/npcs/client/controllers/ScriptClientSound.java new file mode 100644 index 000000000..f20738670 --- /dev/null +++ b/src/main/java/noppes/npcs/client/controllers/ScriptClientSound.java @@ -0,0 +1,53 @@ +package noppes.npcs.client.controllers; + +import net.minecraft.client.audio.ITickableSound; +import net.minecraft.client.audio.MovingSound; +import net.minecraft.entity.Entity; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; +import noppes.npcs.scripted.ScriptSound; + +public class ScriptClientSound extends MovingSound implements ITickableSound { + private Entity entity; + public boolean paused; + + protected ScriptClientSound(ResourceLocation location) { + super(location); + } + + public static ScriptClientSound fromScriptSound(NBTTagCompound compound, World world) { + ScriptSound sound = ScriptSound.fromNBT(compound); + ScriptClientSound clientSound = new ScriptClientSound(new ResourceLocation(sound.directory)); + clientSound.xPosF = sound.xPosF; + clientSound.yPosF = sound.yPosF; + clientSound.zPosF = sound.zPosF; + clientSound.volume = sound.volume; + clientSound.field_147663_c = sound.pitch; + clientSound.repeat = sound.repeat; + clientSound.field_147665_h = sound.repeatDelay; + if (compound.hasKey("EntityID")) { + clientSound.entity = world.getEntityByID(compound.getInteger("EntityID")); + clientSound.field_147666_i = AttenuationType.NONE; + } + return clientSound; + } + + public void stopSound() { + this.repeat = false; + this.volume = 0; + } + + @Override + public void update() { + if (entity != null) { + if (this.entity.isDead) { + this.donePlaying = true; + } else { + this.xPosF = (float) (this.entity.posX); + this.yPosF = (float) (this.entity.posY); + this.zPosF = (float) (this.entity.posZ); + } + } + } +} diff --git a/src/main/java/noppes/npcs/client/controllers/ScriptSoundController.java b/src/main/java/noppes/npcs/client/controllers/ScriptSoundController.java new file mode 100644 index 000000000..2b8d6324b --- /dev/null +++ b/src/main/java/noppes/npcs/client/controllers/ScriptSoundController.java @@ -0,0 +1,68 @@ +package noppes.npcs.client.controllers; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.SoundHandler; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class ScriptSoundController { + public HashMap sounds = new HashMap<>(); + public static ScriptSoundController Instance; + + public ScriptSoundController() { + Instance = this; + } + + public void onUpdate() { + SoundHandler soundHandler = Minecraft.getMinecraft().getSoundHandler(); + final Set> entrySet = sounds.entrySet(); + for (Map.Entry entry : entrySet) { + ScriptClientSound sound = entry.getValue(); + if (!soundHandler.isSoundPlaying(sound) && !sound.canRepeat() && !sound.paused) { + sounds.remove(entry.getKey()); + } + } + } + + public void playSound(int id, ScriptClientSound sound) { + SoundHandler soundHandler = Minecraft.getMinecraft().getSoundHandler(); + if (sounds.containsKey(id)) { + soundHandler.stopSound(sound); + sounds.get(id).stopSound(); + } + sounds.put(id,sound); + soundHandler.playSound(sound); + } + + public void stopSound(int id) { + SoundHandler soundHandler = Minecraft.getMinecraft().getSoundHandler(); + if (sounds.containsKey(id)) { + soundHandler.stopSound(sounds.get(id)); + sounds.get(id).stopSound(); + sounds.remove(id); + } + } + + public void pauseAllSounds() { + SoundHandler soundHandler = Minecraft.getMinecraft().getSoundHandler(); + soundHandler.pauseSounds(); + for (ScriptClientSound sound : sounds.values()) { + sound.paused = true; + } + } + + public void continueAllSounds() { + SoundHandler soundHandler = Minecraft.getMinecraft().getSoundHandler(); + soundHandler.resumeSounds(); + for (ScriptClientSound sound : sounds.values()) { + sound.paused = false; + } + } + + public void stopAllSounds() { + SoundHandler soundHandler = Minecraft.getMinecraft().getSoundHandler(); + soundHandler.stopSounds(); + sounds.clear(); + } +} diff --git a/src/main/java/noppes/npcs/constants/EnumPacketClient.java b/src/main/java/noppes/npcs/constants/EnumPacketClient.java index 47b9c1a20..c4ce35b9f 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketClient.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketClient.java @@ -40,5 +40,10 @@ public enum EnumPacketClient { UPDATE_ITEM, PLAYER_UPDATE_SKIN_OVERLAYS, OVERLAY_QUEST_TRACKING, - DISABLE_MOUSE_INPUT + DISABLE_MOUSE_INPUT, + PLAY_SOUND_TO, + STOP_SOUND_FOR, + PAUSE_SOUNDS, + CONTINUE_SOUNDS, + STOP_SOUNDS } diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index 8244fa40e..5f45e9e47 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -35,7 +35,6 @@ import net.minecraft.world.biome.BiomeGenBase; import noppes.npcs.CustomNpcs; import noppes.npcs.NoppesUtilServer; import noppes.npcs.controllers.*; -import noppes.npcs.controllers.data.Faction; import noppes.npcs.controllers.data.SkinOverlay; import noppes.npcs.items.ItemScripted; import noppes.npcs.containers.ContainerNpcInterface; @@ -50,6 +49,7 @@ import noppes.npcs.scripted.interfaces.entity.ICustomNpc; import noppes.npcs.scripted.interfaces.entity.IEntity; import noppes.npcs.scripted.interfaces.gui.ICustomGui; import noppes.npcs.scripted.interfaces.handler.data.IFaction; +import noppes.npcs.scripted.interfaces.handler.data.ISound; import noppes.npcs.scripted.interfaces.item.IItemStack; import noppes.npcs.scripted.interfaces.AbstractNpcAPI; import noppes.npcs.scripted.interfaces.overlay.ICustomOverlay; @@ -334,6 +334,13 @@ public class NpcAPI extends AbstractNpcAPI { return arr; } + public String[] getPlayerNames() { + IPlayer[] players = getAllServerPlayers(); + String[] names = new String[players.length]; + for (int i = 0; i < names.length; ++i) names[i] = players[i].getDisplayName(); + return names; + } + public void playSoundAtEntity(IEntity entity, String sound, float volume, float pitch){ entity.getWorld().getMCWorld().playSoundAtEntity(entity.getMCEntity(), sound, volume, pitch); } @@ -361,6 +368,30 @@ public class NpcAPI extends AbstractNpcAPI { return new ScriptParticle(directory); } + public ISound createSound(String directory) { + return new ScriptSound(directory); + } + + public void playSound(int id, ISound sound) { + NoppesUtilServer.playSound(id, (ScriptSound) sound); + } + + public void stopSound(int id) { + NoppesUtilServer.stopSound(id); + } + + public void pauseSounds() { + NoppesUtilServer.pauseSounds(); + } + + public void continueSounds() { + NoppesUtilServer.continueSounds(); + } + + public void stopSounds() { + NoppesUtilServer.stopSounds(); + } + public int getServerTime() { return MinecraftServer.getServer().getTickCounter(); } diff --git a/src/main/java/noppes/npcs/scripted/ScriptSound.java b/src/main/java/noppes/npcs/scripted/ScriptSound.java new file mode 100644 index 000000000..ed3359e56 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/ScriptSound.java @@ -0,0 +1,173 @@ +package noppes.npcs.scripted; + +import net.minecraft.nbt.*; +import net.minecraft.util.math.BlockPos; +import noppes.npcs.scripted.interfaces.IPos; +import noppes.npcs.scripted.interfaces.entity.IEntity; +import noppes.npcs.scripted.interfaces.handler.data.ISound; + +import java.lang.reflect.Field; + +public class ScriptSound implements ISound { + public IEntity sourceEntity; + public String directory; + public float volume = 1.0F; + public float pitch = 1.0F; + public float xPosF; + public float yPosF; + public float zPosF; + public boolean repeat = false; + public int repeatDelay = 0; + + public ScriptSound(String location) { + this.directory = location; + } + + public NBTTagCompound writeToNBT() { + NBTTagCompound compound = new NBTTagCompound(); + ScriptSound newSound = new ScriptSound(""); + + //Iterate through fields, check if they're not equal to a new object, write to NBT + for (Field field : ScriptSound.class.getDeclaredFields()) { + try { + if (field.getName().equals("sourceEntity") && this.sourceEntity != null) { + compound.setInteger("EntityID",this.sourceEntity.getEntityId()); + } else if (!field.get(this).equals(field.get(newSound))) { + compound = writeNBTTag(compound, field.getType(), field.getName(), field.get(this)); + } + } catch (Exception ignored) {} + } + + return compound; + } + + public NBTTagCompound writeNBTTag(NBTTagCompound compound, Class c, String key, Object value) { + if (c == boolean.class) { + compound.setBoolean(key, (Boolean) value); + } + if (c == int.class) { + compound.setInteger(key, (Integer) value); + } + if (c == double.class) { + compound.setDouble(key, (Double) value); + } + if (c == float.class) { + compound.setFloat(key, (Float) value); + } + if (c == String.class) { + compound.setString(key, (String) value); + } + + return compound; + } + + private static Object readNBTTag(NBTTagCompound compound, String key) { + if (compound.getTag(key) instanceof NBTTagByte) { + return compound.getBoolean(key); + } + if (compound.getTag(key) instanceof NBTTagInt) { + return compound.getInteger(key); + } + if (compound.getTag(key) instanceof NBTTagDouble) { + return compound.getDouble(key); + } + if (compound.getTag(key) instanceof NBTTagFloat) { + return compound.getFloat(key); + } + if (compound.getTag(key) instanceof NBTTagString) { + return compound.getString(key); + } + + return null; + } + + public static ScriptSound fromNBT(NBTTagCompound compound) { + ScriptSound particle = new ScriptSound(compound.getString("directory")); + + //Iterate through fields, check if compound has a key equal to the field's name, and if so set the field equal to that value from NBT. + for (Field field : ScriptSound.class.getDeclaredFields()) { + try { + if (compound.hasKey(field.getName())) { + if (!field.getName().equals("sourceEntity")) { + Object val = ScriptSound.readNBTTag(compound, field.getName()); + if (val != null) { + field.set(particle, val); + } + } + } + } catch (Exception ignored) {} + } + + return particle; + } + + public void setEntity(IEntity entity) { + this.sourceEntity = entity; + } + + public IEntity getEntity() { + return sourceEntity; + } + + public void setRepeat(boolean repeat) { + this.repeat = repeat; + } + + public boolean repeats() { + return this.repeat; + } + + public void setRepeatDelay(int delay) { + this.repeatDelay = delay; + } + + public int getRepeatDelay() { + return this.repeatDelay; + } + + public void setVolume(float volume) { + this.volume = volume; + } + + public float getVolume() + { + return this.volume; + } + + public void setPitch(float pitch) { + this.pitch = pitch; + } + + public float getPitch() + { + return this.pitch; + } + + public void setPosition(IPos pos) { + this.xPosF = pos.getX(); + this.yPosF = pos.getY(); + this.zPosF = pos.getZ(); + } + + public void setPosition(float x, float y, float z) { + this.xPosF = x; + this.yPosF = y; + this.zPosF = z; + } + + public IPos getPos() { + return new ScriptBlockPos(new BlockPos(xPosF,yPosF,zPosF)); + } + + public float getX() { + return this.xPosF; + } + + public float getY() { + return this.yPosF; + } + + public float getZ() { + return this.zPosF; + } +} diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index 8f9a26a47..b90b69092 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -31,6 +31,7 @@ import noppes.npcs.scripted.interfaces.IParticle; import noppes.npcs.scripted.interfaces.ITileEntity; import noppes.npcs.scripted.interfaces.entity.IEntity; import noppes.npcs.scripted.interfaces.entity.IPlayer; +import noppes.npcs.scripted.interfaces.handler.data.ISound; import noppes.npcs.scripted.interfaces.item.IItemStack; import noppes.npcs.scripted.interfaces.IWorld; @@ -152,6 +153,51 @@ public class ScriptWorld implements IWorld { world.playSoundToNearExcept((EntityPlayerMP) player.getMCEntity(), sound, volume, pitch); } + public void playSound(int id, ISound sound) { + IPlayer[] players = getAllServerPlayers(); + for (IPlayer player : players) { + if (player.getDimension() == this.getDimensionID()) { + player.playSound(id, sound); + } + } + } + + public void stopSound(int id) { + IPlayer[] players = getAllServerPlayers(); + for (IPlayer player : players) { + if (player.getDimension() == this.getDimensionID()) { + player.stopSound(id); + } + } + } + + public void pauseSounds() { + IPlayer[] players = getAllServerPlayers(); + for (IPlayer player : players) { + if (player.getDimension() == this.getDimensionID()) { + player.pauseSounds(); + } + } + } + + public void continueSounds() { + IPlayer[] players = getAllServerPlayers(); + for (IPlayer player : players) { + if (player.getDimension() == this.getDimensionID()) { + player.continueSounds(); + } + } + } + + public void stopSounds() { + IPlayer[] players = getAllServerPlayers(); + for (IPlayer player : players) { + if (player.getDimension() == this.getDimensionID()) { + player.stopSounds(); + } + } + } + public IEntity getEntityByID(int id){ return NpcAPI.Instance().getIEntity(world.getEntityByID(id)); } @@ -654,7 +700,8 @@ public class ScriptWorld implements IWorld { public void explode(double x, double y, double z, float range, boolean fire, boolean grief){ world.newExplosion(null, x, y, z, range, fire, grief); } - + + @Deprecated public IPlayer[] getAllServerPlayers(){ List list = MinecraftServer.getServer().getConfigurationManager().playerEntityList; IPlayer[] arr = new IPlayer[list.size()]; @@ -665,6 +712,7 @@ public class ScriptWorld implements IWorld { return arr; } + @Deprecated public String[] getPlayerNames() { IPlayer[] players = getAllServerPlayers(); String[] names = new String[players.length]; diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index 47577319e..e2ded2fcf 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -14,8 +14,6 @@ import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.ChatStyle; import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.Vec3; -import net.minecraft.util.math.BlockPos; import net.minecraft.world.WorldSettings; import noppes.npcs.*; import noppes.npcs.constants.EnumPacketClient; @@ -34,14 +32,14 @@ import noppes.npcs.controllers.QuestController; import noppes.npcs.controllers.data.QuestData; import noppes.npcs.entity.EntityDialogNpc; import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.ScriptBlockPos; import noppes.npcs.scripted.ScriptPixelmonPlayerData; +import noppes.npcs.scripted.ScriptSound; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.gui.ScriptGui; import noppes.npcs.scripted.interfaces.*; -import noppes.npcs.scripted.interfaces.handler.IPlayerData; import noppes.npcs.scripted.interfaces.handler.data.IQuest; import noppes.npcs.scripted.interfaces.gui.ICustomGui; +import noppes.npcs.scripted.interfaces.handler.data.ISound; import noppes.npcs.scripted.interfaces.overlay.ICustomOverlay; import noppes.npcs.scripted.interfaces.entity.IPlayer; import noppes.npcs.scripted.interfaces.entity.IEntity; @@ -479,6 +477,26 @@ public class ScriptPlayer extends ScriptLivingBase player.playSound(name, volume, pitch); } + public void playSound(int id, ISound sound) { + NoppesUtilPlayer.playSoundTo(player, id, (ScriptSound) sound); + } + + public void stopSound(int id) { + NoppesUtilPlayer.stopSoundFor(player, id); + } + + public void pauseSounds() { + NoppesUtilPlayer.pauseSoundsFor(player); + } + + public void continueSounds() { + NoppesUtilPlayer.continueSoundsFor(player); + } + + public void stopSounds() { + NoppesUtilPlayer.stopSoundsFor(player); + } + public void mountEntity(Entity ridingEntity){ player.mountEntity(ridingEntity); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java b/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java index 6d5546e14..19ff53c72 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java @@ -22,13 +22,16 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import noppes.npcs.CustomNpcs; +import noppes.npcs.NoppesUtilServer; import noppes.npcs.controllers.*; +import noppes.npcs.scripted.ScriptSound; import noppes.npcs.scripted.gui.ScriptGui; import noppes.npcs.scripted.interfaces.entity.ICustomNpc; import noppes.npcs.scripted.interfaces.entity.IEntity; import noppes.npcs.scripted.interfaces.entity.IPlayer; import noppes.npcs.scripted.interfaces.gui.ICustomGui; import noppes.npcs.scripted.interfaces.handler.*; +import noppes.npcs.scripted.interfaces.handler.data.ISound; import noppes.npcs.scripted.interfaces.item.IItemStack; import noppes.npcs.scripted.interfaces.overlay.ICustomOverlay; import noppes.npcs.scripted.overlay.ScriptOverlay; @@ -153,6 +156,8 @@ public abstract class AbstractNpcAPI { public abstract IPlayer[] getAllServerPlayers(); + public abstract String[] getPlayerNames(); + public abstract IItemStack createItem(String id, int damage, int size); public abstract void playSoundAtEntity(IEntity entity, String sound, float volume, float pitch); @@ -179,6 +184,18 @@ public abstract class AbstractNpcAPI { @Deprecated public abstract IParticle createEntityParticle(String directory); + public abstract ISound createSound(String directory); + + public abstract void playSound(int id, ISound sound); + + public abstract void stopSound(int id); + + public abstract void pauseSounds(); + + public abstract void continueSounds(); + + public abstract void stopSounds(); + /** * * @return The uptime of the server in MC ticks. diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java index 81ce7eef3..3539cb2ad 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java @@ -8,6 +8,7 @@ import noppes.npcs.scripted.ScriptBlockPos; import noppes.npcs.scripted.ScriptScoreboard; import noppes.npcs.scripted.interfaces.entity.IEntity; import noppes.npcs.scripted.interfaces.entity.IPlayer; +import noppes.npcs.scripted.interfaces.handler.data.ISound; import noppes.npcs.scripted.interfaces.item.IItemStack; public interface IWorld { @@ -82,6 +83,16 @@ public interface IWorld { void playSoundToNearExcept(IPlayer player, String sound, float volume, float pitch); + void playSound(int id, ISound sound); + + void stopSound(int id); + + void pauseSounds(); + + void continueSounds(); + + void stopSounds(); + IEntity getEntityByID(int id); boolean spawnEntityInWorld(IEntity entity); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/entity/IPlayer.java b/src/main/java/noppes/npcs/scripted/interfaces/entity/IPlayer.java index 7fe9c9bae..b76a5ad71 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/entity/IPlayer.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/entity/IPlayer.java @@ -9,6 +9,7 @@ import noppes.npcs.scripted.interfaces.handler.IPlayerData; import noppes.npcs.scripted.interfaces.handler.data.IQuest; import noppes.npcs.scripted.interfaces.*; import noppes.npcs.scripted.interfaces.gui.ICustomGui; +import noppes.npcs.scripted.interfaces.handler.data.ISound; import noppes.npcs.scripted.interfaces.item.IItemStack; import noppes.npcs.scripted.interfaces.overlay.ICustomOverlay; import noppes.npcs.scripted.ScriptPixelmonPlayerData; @@ -188,6 +189,16 @@ public interface IPlayer extends IEntityLivingBase void playSound(String name, float volume, float pitch); + void playSound(int id, ISound sound); + + void stopSound(int id); + + void pauseSounds(); + + void continueSounds(); + + void stopSounds(); + void mountEntity(Entity ridingEntity); IEntity dropOneItem(boolean dropStack); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/data/ISound.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/ISound.java new file mode 100644 index 000000000..c15effbaa --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/ISound.java @@ -0,0 +1,37 @@ +package noppes.npcs.scripted.interfaces.handler.data; + +import noppes.npcs.scripted.interfaces.IPos; +import noppes.npcs.scripted.interfaces.entity.IEntity; + +public interface ISound { + + void setEntity(IEntity entity); + + IEntity getEntity(); + + void setRepeat(boolean repeat); + + boolean repeats(); + + void setRepeatDelay(int delay); + + int getRepeatDelay(); + + void setVolume(float volume); + + float getVolume(); + + void setPitch(float pitch); + + float getPitch(); + + void setPosition(IPos pos); + + void setPosition(float x, float y, float z); + + float getX(); + + float getY(); + + float getZ(); +}