mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-25 21:34:29 +00:00
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.
This commit is contained in:
1 parent
e6e266f3b6
commit
d1762654ba
16 files changed
+566
-7
No files matched your search
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<EntityPlayer> 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];
|
||||
|
||||
@@ -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<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<T extends EntityPlayerMP> extends IEntityLivingBase<T>
|
||||
|
||||
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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
Reference in new issue
Block a user