Added line support for ICustomNpc

This commit is contained in:
Luis C.M committed 2023-12-03 20:48:37 -06:00
1 parent 8fe2bb89ea
commit eed9dbb92e
5 files changed
+104 -20

No files matched your search

+5 -5
View File
@@ -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) {
@@ -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;
}
}
@@ -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]);
}
}
@@ -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<EntityPlayer> 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;
@@ -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<T extends EntityNPCInterface> extends ScriptLiving<T> 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
*/