From eed9dbb92eae3d13d8c766b23565a91f6223ac5f Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Sun, 3 Dec 2023 20:48:37 -0600 Subject: [PATCH] Added line support for ICustomNpc --- src/main/java/noppes/npcs/DataAdvanced.java | 10 ++--- .../noppes/npcs/controllers/data/Line.java | 44 +++++++++++++++++-- .../noppes/npcs/controllers/data/Lines.java | 30 ++++++++++++- .../npcs/entity/EntityNPCInterface.java | 19 ++++---- .../npcs/scripted/entity/ScriptNpc.java | 21 +++++++++ 5 files changed, 104 insertions(+), 20 deletions(-) diff --git a/src/main/java/noppes/npcs/DataAdvanced.java b/src/main/java/noppes/npcs/DataAdvanced.java index 2db06c527..406889b8d 100644 --- a/src/main/java/noppes/npcs/DataAdvanced.java +++ b/src/main/java/noppes/npcs/DataAdvanced.java @@ -161,23 +161,23 @@ public class DataAdvanced { } public Line getInteractLine() { - return interactLines.getLine(!orderedLines); + return (Line) interactLines.getLine(!orderedLines); } public Line getAttackLine() { - return attackLines.getLine(!orderedLines); + return (Line) attackLines.getLine(!orderedLines); } public Line getKilledLine() { - return killedLines.getLine(!orderedLines); + return (Line) killedLines.getLine(!orderedLines); } public Line getKillLine() { - return killLines.getLine(!orderedLines); + return (Line) killLines.getLine(!orderedLines); } public Line getWorldLine() { - return worldLines.getLine(!orderedLines); + return (Line) worldLines.getLine(!orderedLines); } public void setRole(int i) { diff --git a/src/main/java/noppes/npcs/controllers/data/Line.java b/src/main/java/noppes/npcs/controllers/data/Line.java index e9f5904fb..7385516fc 100644 --- a/src/main/java/noppes/npcs/controllers/data/Line.java +++ b/src/main/java/noppes/npcs/controllers/data/Line.java @@ -2,9 +2,11 @@ package noppes.npcs.controllers.data; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import noppes.npcs.api.entity.IEntityLivingBase; +import noppes.npcs.api.handler.data.ILine; -public class Line { +public class Line implements ILine { public Line(){ @@ -17,21 +19,55 @@ public class Line { public String sound = ""; public boolean hideText = false; - public Line copy() { + public ILine copy() { Line line = new Line(text); line.sound = sound; line.hideText = hideText; return line; } - public Line formatTarget(EntityLivingBase entity) { + public ILine formatTarget(EntityLivingBase entity) { if(entity == null) return this; - Line line = copy(); + Line line = (Line) copy(); if(entity instanceof EntityPlayer) line.text = line.text.replace("@target", ((EntityPlayer) entity).getDisplayName()); else line.text = line.text.replace("@target", entity.getCommandSenderName()); return line; } + + public ILine formatTarget(IEntityLivingBase entityLivingBase) { + return this.formatTarget(entityLivingBase.getMCEntity()); + } + + @Override + public String getText() { + return this.text; + } + + @Override + public void setText(String text) { + this.text = text; + } + + @Override + public String getSound() { + return this.sound; + } + + @Override + public void setSound(String sound) { + this.sound = sound; + } + + @Override + public void hideText(boolean hide) { + this.hideText = hide; + } + + @Override + public boolean hideText() { + return this.hideText; + } } diff --git a/src/main/java/noppes/npcs/controllers/data/Lines.java b/src/main/java/noppes/npcs/controllers/data/Lines.java index b649b2cb4..c8ffeb6e0 100644 --- a/src/main/java/noppes/npcs/controllers/data/Lines.java +++ b/src/main/java/noppes/npcs/controllers/data/Lines.java @@ -2,13 +2,15 @@ package noppes.npcs.controllers.data; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import noppes.npcs.api.handler.data.ILine; +import noppes.npcs.api.handler.data.ILines; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Random; -public class Lines { +public class Lines implements ILines { private static final Random random = new Random(); private int lastLine = -1; @@ -49,7 +51,11 @@ public class Lines { lines = map; } - public Line getLine(boolean isRandom) { + public ILine createLine(String text) { + return new Line(text); + } + + public ILine getLine(boolean isRandom) { if(lines.isEmpty()) return null; if(isRandom){ @@ -66,7 +72,27 @@ public class Lines { } } + public ILine getLine(int lineIndex) { + return lines.get(lineIndex); + } + + public void setLine(int lineIndex, ILine line) { + lines.put(lineIndex, (Line) line); + } + + public void removeLine(int lineIndex) { + lines.remove(lineIndex); + } + + public void clear() { + lines.clear(); + } + public boolean isEmpty() { return lines.isEmpty(); } + + public Integer[] getKeys() { + return lines.keySet().toArray(new Integer[0]); + } } diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 19475dfb2..f37f333c6 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -46,6 +46,7 @@ import noppes.npcs.ai.target.EntityAIClosestTarget; import noppes.npcs.ai.target.EntityAIOwnerHurtByTarget; import noppes.npcs.ai.target.EntityAIOwnerHurtTarget; import noppes.npcs.api.entity.ICustomNpc; +import noppes.npcs.api.handler.data.ILine; import noppes.npcs.api.item.IItemStack; import noppes.npcs.client.EntityUtil; import noppes.npcs.config.ConfigMain; @@ -914,28 +915,28 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti return chateventPlayer; } - public void saySurrounding(Line line) { - if (line == null || line.text == null || getFakePlayer() == null) + public void saySurrounding(ILine line) { + if (line == null || line.getText() == null || getFakePlayer() == null) return; - ServerChatEvent event = new ServerChatEvent(getFakePlayer(), line.text, new ChatComponentTranslation(line.text.replace("%", "%%"))); + ServerChatEvent event = new ServerChatEvent(getFakePlayer(), line.getText(), new ChatComponentTranslation(line.getText().replace("%", "%%"))); if (MinecraftForge.EVENT_BUS.post(event) || event.component == null){ return; } - line.text = event.component.getUnformattedText().replace("%%", "%"); + line.setText(event.component.getUnformattedText().replace("%%", "%")); List inRange = worldObj.getEntitiesWithinAABB( EntityPlayer.class, this.boundingBox.expand(20D, 20D, 20D)); for (EntityPlayer player : inRange) say(player, line); } - public void say(EntityPlayer player, Line line) { - if (line == null || !this.canSee(player) || line.text == null) + public void say(EntityPlayer player, ILine line) { + if (line == null || !this.canSee(player) || line.getText() == null) return; - if(!line.sound.isEmpty()){ - Server.sendData((EntityPlayerMP)player, EnumPacketClient.PLAY_SOUND, line.sound, (float)posX, (float)posY, (float)posZ); + if(!line.getSound().isEmpty()){ + Server.sendData((EntityPlayerMP)player, EnumPacketClient.PLAY_SOUND, line.getSound(), (float)posX, (float)posY, (float)posZ); } - Server.sendData((EntityPlayerMP)player, EnumPacketClient.CHATBUBBLE, this.getEntityId(), line.text, !line.hideText); + Server.sendData((EntityPlayerMP)player, EnumPacketClient.CHATBUBBLE, this.getEntityId(), line.getText(), !line.hideText()); } public boolean getAlwaysRenderNameTagForRender(){ return true; diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index 50814865e..8fde773b6 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -12,6 +12,7 @@ import noppes.npcs.api.handler.IOverlayHandler; import noppes.npcs.api.handler.data.IAnimationData; import noppes.npcs.api.handler.data.IDialog; import noppes.npcs.api.handler.data.IFaction; +import noppes.npcs.api.handler.data.ILines; import noppes.npcs.api.item.IItemStack; import noppes.npcs.api.jobs.IJob; import noppes.npcs.api.roles.IRole; @@ -351,6 +352,26 @@ public class ScriptNpc extends ScriptLiving imp NoppesUtilServer.setNpcDialog(slot,dialogId, this.npc); } + public ILines getInteractLines() { + return this.npc.advanced.interactLines; + } + + public ILines getWorldLines() { + return this.npc.advanced.worldLines; + } + + public ILines getAttackLines() { + return this.npc.advanced.attackLines; + } + + public ILines getKilledLines() { + return this.npc.advanced.killedLines; + } + + public ILines getKillLines() { + return this.npc.advanced.killLines; + } + /** * Kill the npc, doesnt't despawn it */