From 0ed58870467f3de2249e182933ae56e7f8b55bc2 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Sun, 29 May 2022 03:06:57 -0500 Subject: [PATCH 01/40] Alex armor now renders correctly for NPCs. --- .../noppes/npcs/client/model/ModelMPM.java | 41 +++++++++++++++---- .../npcs/client/renderer/RenderCustomNpc.java | 2 +- .../client/renderer/RenderNPCHumanMale.java | 12 ++++++ 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/main/java/noppes/npcs/client/model/ModelMPM.java b/src/main/java/noppes/npcs/client/model/ModelMPM.java index a4d158aa0..1968ce49e 100644 --- a/src/main/java/noppes/npcs/client/model/ModelMPM.java +++ b/src/main/java/noppes/npcs/client/model/ModelMPM.java @@ -64,6 +64,7 @@ public class ModelMPM extends ModelNPCMale{ public boolean currentlyPlayerTexture; public boolean isArmor; + public boolean isAlexArmor; public float alpha = 1; // Steve 64x64 and Alex 64x64 @@ -194,10 +195,14 @@ public class ModelMPM extends ModelNPCMale{ } // Steve 64x32 - public ModelMPM(float par1) { + public ModelMPM(float par1, int alexArms) { super(par1); isArmor = par1 > 0; + if (isArmor && alexArms == 1) { + isAlexArmor = true; + } + float par2 = 0; this.bipedCloak = new ModelRenderer(this, 0, 0); @@ -219,14 +224,30 @@ public class ModelMPM extends ModelNPCMale{ this.bipedBody.addBox(-4.0F, 0.0F, -2.0F, 8, 12, 4, par1); this.bipedBody.setRotationPoint(0.0F, 0.0F + par2, 0.0F); - this.bipedRightArm = new ModelScaleRenderer(this, 40, 16); - this.bipedRightArm.addBox(-3.0F, -2.0F, -2.0F, 4, 12, 4, par1); - this.bipedRightArm.setRotationPoint(-5.0F, 2.0F + par2, 0.0F); + if (alexArms == 0) { + this.bipedRightArm = new ModelScaleRenderer(this, 40, 16); + this.bipedRightArm.addBox(-3.0F, -2.0F, -2.0F, 4, 12, 4, par1); + this.bipedRightArm.setRotationPoint(-5.0F, 2.0F + par2, 0.0F); - this.bipedLeftArm = new ModelScaleRenderer(this, 40, 16); - this.bipedLeftArm.mirror = true; - this.bipedLeftArm.addBox(-1.0F, -2.0F, -2.0F, 4, 12, 4, par1); - this.bipedLeftArm.setRotationPoint(5.0F, 2.0F + par2, 0.0F); + this.bipedLeftArm = new ModelScaleRenderer(this, 40, 16); + this.bipedLeftArm.mirror = true; + this.bipedLeftArm.addBox(-1.0F, -2.0F, -2.0F, 4, 12, 4, par1); + this.bipedLeftArm.setRotationPoint(5.0F, 2.0F + par2, 0.0F); + } else { + this.bipedRightArm = (new ModelScaleRenderer(this, 40, 16)); + this.bipedLeftArm = new ModelScaleRenderer(this, 40, 16); + this.bipedLeftArm.mirror = true; + + if (isArmor) { + this.bipedLeftArm.setRotationPoint(5.0F, 2.5F + par2, 0.0F); + this.bipedRightArm.addBox(-4.5F, -2.0F, -2.0F, 4, 12, 4, par1); + this.bipedLeftArm.addBox(0.25F, -2.0F, -2.0F, 4, 12, 4, par1); + } else { + this.bipedLeftArm.setRotationPoint(5.0F, 2.5F + par2, 0.0F); + this.bipedRightArm.addBox(-2.0F, -2.0F, -2.0F, 3, 12, 4, par1); + this.bipedLeftArm.addBox(-1.0F, -2.0F, -2.0F, 3, 12, 4, par1); + } + } this.bipedRightLeg = new ModelScaleRenderer(this, 0, 16); this.bipedRightLeg.addBox(-2.0F, 0.0F, -2.0F, 4, 12, 4, par1); @@ -588,6 +609,10 @@ public class ModelMPM extends ModelNPCMale{ GL11.glPushMatrix(); + if (isAlexArmor) { + GL11.glScalef(0.75F,1.0F,1.0F); + } + if(entity.currentAnimation == EnumAnimation.DANCING){ float dancing = entity.ticksExisted / 4f; GL11.glTranslatef((float)Math.sin(dancing) * 0.025F, (float)Math.abs(Math.cos(dancing)) * 0.125F - 0.02F, 0.0F); diff --git a/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java b/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java index 51a0ff9aa..22c619b99 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java @@ -29,7 +29,7 @@ public class RenderCustomNpc extends RenderNPCHumanMale{ // Default Renderer public RenderCustomNpc() { - super(new ModelMPM(0), new ModelMPM(1), new ModelMPM(0.5f)); + super(new ModelMPM(0,0), new ModelMPM(1,0), new ModelMPM(0.5f,0)); } @Override diff --git a/src/main/java/noppes/npcs/client/renderer/RenderNPCHumanMale.java b/src/main/java/noppes/npcs/client/renderer/RenderNPCHumanMale.java index b2ef80bab..60d119f52 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderNPCHumanMale.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderNPCHumanMale.java @@ -37,6 +37,12 @@ public class RenderNPCHumanMale extends RenderNPCInterface protected final static ModelMPM steve64 = new ModelMPM(0, false); protected final static ModelMPM alex = new ModelMPM(0, true); + protected final static ModelMPM steveArmorChest = new ModelMPM(1,0); + protected final static ModelMPM steveArmor = new ModelMPM(0.5F,0); + + protected final static ModelMPM alex32armorChest = new ModelMPM(1,1); + protected final static ModelMPM alex32armor = new ModelMPM(0.5F,1); + public RenderNPCHumanMale(ModelNPCMale mainmodel, ModelNPCMale armorChest, ModelNPCMale armor) { super(mainmodel, 0.5F); @@ -118,10 +124,14 @@ public class RenderNPCHumanMale extends RenderNPCInterface if(modelVal == 1){ this.mainModel = steve64; this.modelBipedMain = steve64; + this.modelArmorChestplate = steveArmorChest; + this.modelArmor = steveArmor; } else if(modelVal == 2){ this.mainModel = alex; this.modelBipedMain = alex; + this.modelArmorChestplate = alex32armorChest; + this.modelArmor = alex32armor; } else{ ((EntityCustomNpc) npc).modelData.bodywear = 0; @@ -129,6 +139,8 @@ public class RenderNPCHumanMale extends RenderNPCInterface ((EntityCustomNpc) npc).modelData.legwear = 0; this.mainModel = originalModel; this.modelBipedMain = originalBipedMain; + this.modelArmorChestplate = steveArmorChest; + this.modelArmor = steveArmor; } } } From e2df33fb5ff6848e3af3a33e010a0558168b0175 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Sun, 29 May 2022 04:45:38 -0500 Subject: [PATCH 02/40] Added quest objective and turnin data to the quest tracker. --- .../java/noppes/npcs/NoppesUtilPlayer.java | 22 ++++ .../java/noppes/npcs/PacketHandlerServer.java | 5 +- .../noppes/npcs/ScriptPlayerEventHandler.java | 7 +- .../npcs/client/gui/OverlayQuestTracking.java | 112 +++++++++++++----- .../controllers/data/PlayerQuestData.java | 6 +- 5 files changed, 113 insertions(+), 39 deletions(-) diff --git a/src/main/java/noppes/npcs/NoppesUtilPlayer.java b/src/main/java/noppes/npcs/NoppesUtilPlayer.java index df129a397..2c6bbe6c8 100644 --- a/src/main/java/noppes/npcs/NoppesUtilPlayer.java +++ b/src/main/java/noppes/npcs/NoppesUtilPlayer.java @@ -14,6 +14,9 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; import net.minecraft.server.MinecraftServer; import net.minecraft.util.ChatComponentText; import net.minecraft.world.WorldServer; @@ -33,6 +36,7 @@ import cpw.mods.fml.common.network.internal.FMLProxyPacket; 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.item.IItemStack; import noppes.npcs.scripted.NpcAPI; @@ -284,6 +288,24 @@ public class NoppesUtilPlayer { else Server.sendData(player, EnumPacketClient.GUI_CLOSE); } + public static void sendTrackedQuestData(EntityPlayerMP player, Quest trackedQuest) { + Quest quest = (Quest) PlayerDataController.instance.getPlayerData(player).questData.trackedQuest; + if (quest.id != trackedQuest.id) { + return; + } + + NBTTagCompound compound = new NBTTagCompound(); + compound.setTag("Quest",trackedQuest.writeToNBT(new NBTTagCompound())); + compound.setString("CategoryName", trackedQuest.getCategory().getName()); + compound.setString("TurnInNPC", trackedQuest.getNpcName()); + NBTTagList nbtTagList = new NBTTagList(); + for (IQuestObjective objective : trackedQuest.questInterface.getObjectives(player)) { + nbtTagList.appendTag(new NBTTagString(objective.getText())); + } + compound.setTag("ObjectiveList",nbtTagList); + Server.sendData(player, EnumPacketClient.OVERLAY_QUEST_TRACKING, compound); + } + public static void sendQuestLogData(EntityPlayerMP player) { if(!PlayerQuestController.hasActiveQuests(player)){ return; diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 0a030410c..71bfdab6d 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -154,10 +154,7 @@ public class PacketHandlerServer{ for (Quest quest : category.quests.values()) { if (quest.title.equals(questName)) { PlayerDataController.instance.getPlayerData(player).questData.trackedQuest = quest; - NBTTagCompound compound = new NBTTagCompound(); - compound.setTag("Quest",quest.writeToNBT(new NBTTagCompound())); - compound.setString("CategoryName", quest.getCategory().getName()); - Server.sendData(player, EnumPacketClient.OVERLAY_QUEST_TRACKING, compound); + NoppesUtilPlayer.sendTrackedQuestData(player, quest); return; } } diff --git a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java index 3bfed30b9..7ff56edce 100644 --- a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java @@ -14,7 +14,6 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.ContainerPlayer; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.WorldServer; @@ -28,7 +27,6 @@ import net.minecraftforge.event.entity.living.LivingFallEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.*; import net.minecraftforge.event.world.*; -import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.constants.EnumQuestType; import noppes.npcs.controllers.*; import noppes.npcs.controllers.data.PlayerData; @@ -435,10 +433,7 @@ public class ScriptPlayerEventHandler { Quest quest = (Quest) PlayerDataController.instance.getPlayerData(event.player).questData.trackedQuest; if (quest != null) { - NBTTagCompound compound = new NBTTagCompound(); - compound.setTag("Quest",quest.writeToNBT(new NBTTagCompound())); - compound.setString("CategoryName", quest.getCategory().getName()); - Server.sendData((EntityPlayerMP) event.player, EnumPacketClient.OVERLAY_QUEST_TRACKING, compound); + NoppesUtilPlayer.sendTrackedQuestData((EntityPlayerMP) event.player, quest); } } } diff --git a/src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java b/src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java index ef3f2cd25..dbfc6638c 100644 --- a/src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java +++ b/src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java @@ -10,6 +10,7 @@ import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraft.util.ResourceLocation; import noppes.npcs.CustomNpcs; import noppes.npcs.controllers.data.Quest; @@ -55,8 +56,10 @@ public class OverlayQuestTracking extends Gui { private float renderOffsetY; - public static Quest trackedQuest = new Quest(); - public static String categoryName = ""; + public ArrayList trackedQuestLines = new ArrayList<>(); + public ArrayList categoryNameLines = new ArrayList<>(); + public ArrayList objectiveLines = new ArrayList<>(); + public ArrayList turnInText = new ArrayList<>(); public OverlayQuestTracking(Minecraft mc) { this.mc = mc; @@ -102,11 +105,56 @@ public class OverlayQuestTracking extends Gui { } public void setOverlayData(NBTTagCompound compound) { + Quest trackedQuest = new Quest(); trackedQuest.readNBT(compound.getCompoundTag("Quest")); - categoryName = compound.getString("CategoryName"); + + trackedQuestLines = getLineList(trackedQuest.getName()); + categoryNameLines = getLineList(compound.getString("CategoryName")); + + NBTTagList nbtTagList = compound.getTagList("ObjectiveList",8); + for (int i = 0; i < nbtTagList.tagCount(); i++) { + String objective = nbtTagList.getStringTagAt(i); + + String[] split = objective.split(":"); + split = split[split.length-1].split("/"); + + int completed = Integer.parseInt(split[0].trim()); + int total = Integer.parseInt(split[1].trim()); + if (completed / total == 1) { + objective = "&a&o&m" + objective; + } else { + objective = "&o" + objective; + } + + objectiveLines.add(objective); + } + + String npcName = compound.getString("TurnInNPC"); + if (!npcName.isEmpty()) { + turnInText.add("Complete with " + npcName); + } + this.initOverlay(); } + public ArrayList getLineList(String string) { + String[] split = string.split(" "); + + ArrayList lines = new ArrayList<>(); + lines.add(split[0]); + + for (int i = 1; i < split.length; i++) { + String s = split[i]; + if (this.fontRenderer.getStringWidth(lines.get(lines.size() - 1) + " " + s) > 100) { + lines.add(s); + } else { + lines.set(lines.size() - 1, lines.get(lines.size() - 1) + " " + s); + } + } + + return lines; + } + public void renderGameOverlay(float partialTicks){ res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); scaledWidth = res.getScaledWidth(); @@ -129,24 +177,32 @@ public class OverlayQuestTracking extends Gui { this.renderOffsetY = -40; GL11.glPushMatrix(); GL11.glTranslatef(centerX, 0.0F, 0.0F); - this.renderStringLines(trackedQuest.getName(),1.2F, false, true); + this.renderStringLines(trackedQuestLines,1.2F, false, true, 0); GL11.glPopMatrix(); questTitleTop = this.renderOffsetY; - this.renderOffsetY -= 5; + this.renderOffsetY -= 10; GL11.glPushMatrix(); GL11.glTranslatef(centerX, 0.0F, 0.0F); - this.renderStringLines(categoryName,0.85F, false, false); + this.renderStringLines(categoryNameLines,0.85F, false, false, 0); GL11.glPopMatrix(); - //TODO: Add objectives list, with green strikethrough text for completed objectives. Then, add who the player should turn the quest in to. + this.renderOffsetY = -10; + GL11.glPushMatrix(); + this.renderStringLines(objectiveLines,1F, true, false, 2); + GL11.glPopMatrix(); - this.renderOffsetY = -25; + this.renderOffsetY += 10; + GL11.glPushMatrix(); + this.renderStringLines(turnInText,1F, false, false, 2); + GL11.glPopMatrix(); + + this.renderOffsetY = -20; GL11.glPushMatrix(); this.drawHorizontalLine((int)(-60 + centerX), (int)(60 + centerX), (int) (this.renderOffsetY+2), 0xFF777777); this.drawHorizontalLine((int)(-60 + centerX), (int)(60 + centerX), (int) (this.renderOffsetY+1), 0xFFA8A8A8); this.drawHorizontalLine((int)(-60 + centerX), (int)(60 + centerX), (int) (this.renderOffsetY), 0xFFFFFFFF); GL11.glPopMatrix(); - this.renderOffsetY = questTitleTop + 5; + this.renderOffsetY = questTitleTop + 2; GL11.glPushMatrix(); this.drawHorizontalLine((int)(-60 + centerX), (int)(60 + centerX), (int) (this.renderOffsetY), 0xFFFFFFFF); this.drawHorizontalLine((int)(-60 + centerX), (int)(60 + centerX), (int) (this.renderOffsetY-1), 0xFFA8A8A8); @@ -159,36 +215,38 @@ public class OverlayQuestTracking extends Gui { GL11.glEnable(GL11.GL_ALPHA_TEST); } - public void renderStringLines(String string, float scale, boolean upwards, boolean bold) { - String[] split = string.split(" "); - - ArrayList lines = new ArrayList<>(); - lines.add(split[0]); - - for (int i = 1; i < split.length; i++) { - String s = split[i]; - if (this.fontRenderer.getStringWidth(lines.get(lines.size() - 1) + " " + s) > 100) { - lines.add(s); - } else { - lines.set(lines.size() - 1, lines.get(lines.size() - 1) + " " + s); - } - } - + public void renderStringLines(ArrayList lines, float scale, boolean downwards, boolean bold, int justified) { for (int i = 0; i < lines.size(); i++) { String s = lines.get(i); - if (!upwards) { + if (!downwards) { s = lines.get(lines.size()-1 - i); } + int stringWidth = this.fontRenderer.getStringWidth(s.replace("&o","")); + if (s.startsWith("&a&o&m")) { + stringWidth = this.fontRenderer.getStringWidth(s.replace("&a&o&m","")); + } + GL11.glPushMatrix(); - GL11.glTranslatef(scale*(-this.fontRenderer.getStringWidth(s)/2.0F), this.renderOffsetY, 0.0F); + switch (justified) { + case 0://center + GL11.glTranslatef(scale * (-stringWidth / 2.0F), this.renderOffsetY, 0.0F); + break; + case 1://left + GL11.glTranslatef(scale * (stringWidth), this.renderOffsetY, 0.0F); + break; + case 2://right + GL11.glTranslatef(scale * (-stringWidth), this.renderOffsetY, 0.0F); + break; + } + GL11.glScalef(scale, scale, scale); this.drawString(s, 0, 0, this.color, true); if (bold) { GL11.glTranslatef(0.2F, 0.2F, 0.0F); this.drawString(s, 0, 0, this.color, false); } - this.renderOffsetY += upwards ? 10 : -10; + this.renderOffsetY += downwards ? 10 : -10; GL11.glPopMatrix(); } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java b/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java index d02218ef4..06e73e83f 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java @@ -7,6 +7,7 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import noppes.npcs.EventHooks; +import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.Server; import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.constants.EnumQuestCompletion; @@ -107,9 +108,10 @@ public class PlayerQuestData { for(QuestData data : this.activeQuests.values()){ if(data.quest.type != type && type != null) continue; - - QuestInterface inter = data.quest.questInterface; + NoppesUtilPlayer.sendTrackedQuestData((EntityPlayerMP) player,data.quest); + + QuestInterface inter = data.quest.questInterface; if(inter.isCompleted(playerData)){ if(!data.isCompleted){ if(!data.quest.complete(player,data)){ From e71ea4f4956497e07b0ea190dc4ad4ac56250b5a Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Sun, 29 May 2022 05:06:18 -0500 Subject: [PATCH 03/40] Fixed the quest tracking overlay alignment. --- src/main/java/noppes/npcs/CustomNpcs.java | 4 +-- .../npcs/client/gui/OverlayQuestTracking.java | 29 +++++++++++-------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index ad4842791..3a79c5fbd 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -63,8 +63,8 @@ public class CustomNpcs { @ConfigProp(info = "The amount of time that passes before a player's quests are checked for completion in seconds.") public static int PlayerQuestCheck = 300; - @ConfigProp(info = "Client sided! Determines where tracking quest info shows up on the screen based on a number from 0 to 8.") - public static int TrackingInfoAlignment = 5; + @ConfigProp(info = "Client sided! Determines where tracking quest info shows up on the screen based on a number from 0 to 8. Default: 3") + public static int TrackingInfoAlignment = 3; @ConfigProp(info = "Client sided! Offsets the tracking info GUI by this amount in the X direction.") public static int TrackingInfoX = 0; diff --git a/src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java b/src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java index dbfc6638c..87c02c435 100644 --- a/src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java +++ b/src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java @@ -55,6 +55,7 @@ public class OverlayQuestTracking extends Gui { private float posY; private float renderOffsetY; + private final int overlayWidth = 120; public ArrayList trackedQuestLines = new ArrayList<>(); public ArrayList categoryNameLines = new ArrayList<>(); @@ -166,13 +167,17 @@ public class OverlayQuestTracking extends Gui { GL11.glPushMatrix(); GL11.glTranslatef(CustomNpcs.TrackingInfoAlignment%3*((float)(scaledWidth)/2), (float) (Math.floor((float)(CustomNpcs.TrackingInfoAlignment/3))*((float)(scaledHeight)/2)),0.0F); - GL11.glTranslatef(CustomNpcs.TrackingInfoX - 10, CustomNpcs.TrackingInfoY, 0.0F); + + float offsetX = CustomNpcs.TrackingInfoAlignment%3 == 0 ? 5 : -5; + GL11.glTranslatef(CustomNpcs.TrackingInfoX + offsetX, CustomNpcs.TrackingInfoY, 0.0F); red = (color >> 16 & 255) / 255f; green = (color >> 8 & 255) / 255f; blue = (color & 255) / 255f; float centerX = -60; + centerX *= CustomNpcs.TrackingInfoAlignment%3 == 0 ? -1 : 1; + float questTitleTop; this.renderOffsetY = -40; GL11.glPushMatrix(); @@ -188,25 +193,25 @@ public class OverlayQuestTracking extends Gui { this.renderOffsetY = -10; GL11.glPushMatrix(); - this.renderStringLines(objectiveLines,1F, true, false, 2); + this.renderStringLines(objectiveLines,1F, true, false, CustomNpcs.TrackingInfoAlignment%3 == 0 ? 1 : 2); GL11.glPopMatrix(); this.renderOffsetY += 10; GL11.glPushMatrix(); - this.renderStringLines(turnInText,1F, false, false, 2); + this.renderStringLines(turnInText,1F, false, false, CustomNpcs.TrackingInfoAlignment%3 == 0 ? 1 : 2); GL11.glPopMatrix(); this.renderOffsetY = -20; GL11.glPushMatrix(); - this.drawHorizontalLine((int)(-60 + centerX), (int)(60 + centerX), (int) (this.renderOffsetY+2), 0xFF777777); - this.drawHorizontalLine((int)(-60 + centerX), (int)(60 + centerX), (int) (this.renderOffsetY+1), 0xFFA8A8A8); - this.drawHorizontalLine((int)(-60 + centerX), (int)(60 + centerX), (int) (this.renderOffsetY), 0xFFFFFFFF); + this.drawHorizontalLine((int)(-overlayWidth/2 + centerX), (int)(overlayWidth/2 + centerX), (int) (this.renderOffsetY+2), 0xFF777777); + this.drawHorizontalLine((int)(-overlayWidth/2 + centerX), (int)(overlayWidth/2 + centerX), (int) (this.renderOffsetY+1), 0xFFA8A8A8); + this.drawHorizontalLine((int)(-overlayWidth/2 + centerX), (int)(overlayWidth/2 + centerX), (int) (this.renderOffsetY), 0xFFFFFFFF); GL11.glPopMatrix(); this.renderOffsetY = questTitleTop + 2; GL11.glPushMatrix(); - this.drawHorizontalLine((int)(-60 + centerX), (int)(60 + centerX), (int) (this.renderOffsetY), 0xFFFFFFFF); - this.drawHorizontalLine((int)(-60 + centerX), (int)(60 + centerX), (int) (this.renderOffsetY-1), 0xFFA8A8A8); - this.drawHorizontalLine((int)(-60 + centerX), (int)(60 + centerX), (int) (this.renderOffsetY-2), 0xFF777777); + this.drawHorizontalLine((int)(-overlayWidth/2 + centerX), (int)(overlayWidth/2 + centerX), (int) (this.renderOffsetY), 0xFFFFFFFF); + this.drawHorizontalLine((int)(-overlayWidth/2 + centerX), (int)(overlayWidth/2 + centerX), (int) (this.renderOffsetY-1), 0xFFA8A8A8); + this.drawHorizontalLine((int)(-overlayWidth/2 + centerX), (int)(overlayWidth/2 + centerX), (int) (this.renderOffsetY-2), 0xFF777777); GL11.glPopMatrix(); GL11.glPopMatrix(); @@ -215,7 +220,7 @@ public class OverlayQuestTracking extends Gui { GL11.glEnable(GL11.GL_ALPHA_TEST); } - public void renderStringLines(ArrayList lines, float scale, boolean downwards, boolean bold, int justified) { + public void renderStringLines(ArrayList lines, float scale, boolean downwards, boolean bold, int facing) { for (int i = 0; i < lines.size(); i++) { String s = lines.get(i); if (!downwards) { @@ -228,12 +233,12 @@ public class OverlayQuestTracking extends Gui { } GL11.glPushMatrix(); - switch (justified) { + switch (facing) { case 0://center GL11.glTranslatef(scale * (-stringWidth / 2.0F), this.renderOffsetY, 0.0F); break; case 1://left - GL11.glTranslatef(scale * (stringWidth), this.renderOffsetY, 0.0F); + GL11.glTranslatef(0, this.renderOffsetY, 0.0F); break; case 2://right GL11.glTranslatef(scale * (-stringWidth), this.renderOffsetY, 0.0F); From 9928482c536aaa006cb33e7f6a838861736ee566 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Sun, 29 May 2022 05:09:30 -0500 Subject: [PATCH 04/40] Fixed null error with the quest tracker. --- src/main/java/noppes/npcs/NoppesUtilPlayer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/NoppesUtilPlayer.java b/src/main/java/noppes/npcs/NoppesUtilPlayer.java index 2c6bbe6c8..8357d655a 100644 --- a/src/main/java/noppes/npcs/NoppesUtilPlayer.java +++ b/src/main/java/noppes/npcs/NoppesUtilPlayer.java @@ -290,7 +290,7 @@ public class NoppesUtilPlayer { } public static void sendTrackedQuestData(EntityPlayerMP player, Quest trackedQuest) { Quest quest = (Quest) PlayerDataController.instance.getPlayerData(player).questData.trackedQuest; - if (quest.id != trackedQuest.id) { + if (quest == null || trackedQuest == null || quest.id != trackedQuest.id) { return; } From f9e92f3172bf80842cba6e9cca519067e1509e65 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Sun, 29 May 2022 05:23:39 -0500 Subject: [PATCH 05/40] Added blend attribute to skin overlays. --- .../client/gui/GuiNpcTextureOverlays.java | 5 +--- .../client/gui/mainmenu/GuiNpcDisplay.java | 5 +--- .../client/renderer/RenderCNPCPlayer.java | 12 ++++++--- .../client/renderer/RenderNPCInterface.java | 6 ++++- .../npcs/controllers/data/SkinOverlay.java | 26 ++++++++----------- .../npcs/entity/old/EntityNPCEnderman.java | 5 +--- .../scripted/interfaces/ISkinOverlay.java | 6 +++++ 7 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcTextureOverlays.java b/src/main/java/noppes/npcs/client/gui/GuiNpcTextureOverlays.java index d0152dcd6..e6e4c9fd6 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcTextureOverlays.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcTextureOverlays.java @@ -79,10 +79,7 @@ public class GuiNpcTextureOverlays extends GuiNpcSelectionInterface{ //npc.display.glowTexture = assets.getAsset(slot.selected); //npc.textureGlowLocation = null; - npc.display.skinOverlayData.overlayList.put(0,new SkinOverlay( - assets.getAsset(slot.selected), true, 1.0F, 1.0F, 0.0F, 0.0F, - 1.0F, 1.0F, 0.0F, 0.0F, 0.0F - )); + npc.display.skinOverlayData.overlayList.put(0,new SkinOverlay(assets.getAsset(slot.selected))); } } diff --git a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java index 2c1621059..e691f8342 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java @@ -132,10 +132,7 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene //npc.textureGlowLocation = null; //display.glowTexture = textfield.getText(); if (!textfield.getText().isEmpty()) { - npc.display.skinOverlayData.overlayList.put(0, new SkinOverlay( - textfield.getText(), true, 1.0F, 1.0F, 0.0F, 0.0F, - 1.0F, 1.0F, 0.0F, 0.0F, 0.0F - )); + npc.display.skinOverlayData.overlayList.put(0,new SkinOverlay(textfield.getText())); } } else if(textfield.id == 11){ diff --git a/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java b/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java index fe913ebe1..0821d0415 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java @@ -45,7 +45,7 @@ public class RenderCNPCPlayer extends RenderPlayer { this.setRenderManager(RenderManager.instance); } - private boolean preRenderOverlay(EntityPlayer player, ResourceLocation overlayLocation, boolean glow, + private boolean preRenderOverlay(EntityPlayer player, ResourceLocation overlayLocation, boolean glow, boolean blend, float alpha, float size, float speedX, float speedY, float scaleX, float scaleY, float offsetX, float offsetY, float offsetZ) { if (overlayLocation.getResourcePath().isEmpty()) @@ -67,7 +67,11 @@ public class RenderCNPCPlayer extends RenderPlayer { // Overlay & Glow GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + if (blend) { + GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE); + } else { + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + } GL11.glAlphaFunc(GL11.GL_GREATER, 0.003921569F); if (glow) { @@ -127,7 +131,7 @@ public class RenderCNPCPlayer extends RenderPlayer { } } - if (!preRenderOverlay(player, overlayData.location, overlayData.glow, overlayData.alpha, overlayData.size, + if (!preRenderOverlay(player, overlayData.location, overlayData.glow, overlayData.blend, overlayData.alpha, overlayData.size, overlayData.speedX, overlayData.speedY, overlayData.scaleX, overlayData.scaleY, overlayData.offsetX, overlayData.offsetY, overlayData.offsetZ )) @@ -330,7 +334,7 @@ public class RenderCNPCPlayer extends RenderPlayer { } } - if (!preRenderOverlay(player, overlayData.location, overlayData.glow, overlayData.alpha, overlayData.size, + if (!preRenderOverlay(player, overlayData.location, overlayData.glow, overlayData.blend, overlayData.alpha, overlayData.size, overlayData.speedX, overlayData.speedY, overlayData.scaleX, overlayData.scaleY, overlayData.offsetX, overlayData.offsetY, overlayData.offsetZ )) diff --git a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java index 9f79fb06d..22a6a2eeb 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java @@ -243,7 +243,11 @@ public class RenderNPCInterface extends RenderLiving{ // Overlay & Glow GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + if (overlayData.getBlend()) { + GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE); + } else { + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + } GL11.glAlphaFunc(GL11.GL_GREATER, 0.003921569F); if (overlayData.getGlow()) { diff --git a/src/main/java/noppes/npcs/controllers/data/SkinOverlay.java b/src/main/java/noppes/npcs/controllers/data/SkinOverlay.java index 750a76469..217ecedd6 100644 --- a/src/main/java/noppes/npcs/controllers/data/SkinOverlay.java +++ b/src/main/java/noppes/npcs/controllers/data/SkinOverlay.java @@ -10,6 +10,7 @@ public class SkinOverlay implements ISkinOverlay { public ResourceLocation location = null; public String texture; public boolean glow = true; + public boolean blend = false; public float alpha = 1.0F; public float size = 1.0F; @@ -30,21 +31,6 @@ public class SkinOverlay implements ISkinOverlay { this.texture = texture; } - public SkinOverlay(String texture, boolean glow, float alpha, float size, float speedX, float speedY, - float scaleX, float scaleY, float offsetX, float offsetY, float offsetZ) { - this.texture = texture; - this.glow = glow; - this.alpha = alpha; - this.size = size; - this.speedX = speedX; - this.speedY = speedY; - this.scaleX = scaleX; - this.scaleY = scaleY; - this.offsetX = offsetX; - this.offsetY = offsetY; - this.offsetZ = offsetZ; - } - public void setTexture(String texture) { this.texture = texture; this.updateClient(); @@ -61,6 +47,14 @@ public class SkinOverlay implements ISkinOverlay { return glow; } + public void setBlend(boolean blend) { + this.blend = blend; + this.updateClient(); + } + public boolean getBlend() { + return blend; + } + public void setAlpha(float alpha) { this.alpha = alpha; this.updateClient(); @@ -128,6 +122,7 @@ public class SkinOverlay implements ISkinOverlay { public void readFromNBT(NBTTagCompound compound) { this.texture = compound.getString("SkinOverlayTexture"); this.glow = compound.getBoolean("SkinOverlayGlow"); + this.blend = compound.getBoolean("SkinOverlayBlend"); this.alpha = compound.getFloat("SkinOverlayAlpha"); this.size = compound.getFloat("SkinOverlaySize"); this.speedX = compound.getFloat("SkinOverlaySpeedX"); @@ -142,6 +137,7 @@ public class SkinOverlay implements ISkinOverlay { public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setString("SkinOverlayTexture", this.getTexture()); compound.setBoolean("SkinOverlayGlow", this.getGlow()); + compound.setBoolean("SkinOverlayBlend", this.getBlend()); compound.setFloat("SkinOverlayAlpha", this.getAlpha()); compound.setFloat("SkinOverlaySize", this.getSize()); compound.setFloat("SkinOverlaySpeedX", this.getSpeedX()); diff --git a/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java b/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java index 62c4c224c..bfc85d14d 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java @@ -19,10 +19,7 @@ public class EntityNPCEnderman extends EntityNpcEnderchibi super(world); display.texture = "customnpcs:textures/entity/enderman/enderman.png"; //display.glowTexture = ; - display.skinOverlayData.overlayList.put(0,new SkinOverlay( - "customnpcs:textures/overlays/ender_eyes.png", true, 1.0F, 1.0F, 0.0F, 0.0F, - 1.0F, 1.0F, 0.0F, 0.0F, 0.0F - )); + display.skinOverlayData.overlayList.put(0,new SkinOverlay("customnpcs:textures/overlays/ender_eyes.png")); this.width = 0.6F; this.height = 2.9F; } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ISkinOverlay.java b/src/main/java/noppes/npcs/scripted/interfaces/ISkinOverlay.java index 637c52a7b..4bf83f0d8 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/ISkinOverlay.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/ISkinOverlay.java @@ -21,6 +21,12 @@ public interface ISkinOverlay { void setGlow(boolean glow); boolean getGlow(); + /** + * Sets whether this overlay blends on top of bottom textures at any alpha value. + */ + void setBlend(boolean blend); + boolean getBlend(); + /** * Sets the transparency of the overlay, from 0 to 1. */ From f301f8fcbb7628f3a5bd29ac8bc7d07e1040801c Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Sun, 29 May 2022 05:33:13 -0500 Subject: [PATCH 06/40] The player quest tracker now supports dialog and location quests as well. --- .../npcs/client/gui/OverlayQuestTracking.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java b/src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java index 87c02c435..dc7cbdbc7 100644 --- a/src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java +++ b/src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java @@ -119,9 +119,22 @@ public class OverlayQuestTracking extends Gui { String[] split = objective.split(":"); split = split[split.length-1].split("/"); - int completed = Integer.parseInt(split[0].trim()); - int total = Integer.parseInt(split[1].trim()); - if (completed / total == 1) { + boolean completed = false; + + try { + int killed = Integer.parseInt(split[0].trim()); + int total = Integer.parseInt(split[1].trim()); + + if (killed/total == 1) { + completed = true; + } + } catch (NumberFormatException e) { + if (objective.endsWith("(read)") || (objective.endsWith("Found") && !objective.endsWith("Not Found"))) { + completed = true; + } + } + + if (completed) { objective = "&a&o&m" + objective; } else { objective = "&o" + objective; From e4eb0e9cd800a903d2583170f8e1f2ee32034743 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Sun, 29 May 2022 14:49:42 -0500 Subject: [PATCH 07/40] Removed player completion checker. --- src/main/java/noppes/npcs/CustomNpcs.java | 6 ------ src/main/java/noppes/npcs/ScriptPlayerEventHandler.java | 6 ------ 2 files changed, 12 deletions(-) diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index 3a79c5fbd..450bb5fd6 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -60,9 +60,6 @@ public class CustomNpcs { @ConfigProp(info = "Set to true if you want the dialog command option to be able to use op commands like tp etc") public static boolean NpcUseOpCommands = false; - @ConfigProp(info = "The amount of time that passes before a player's quests are checked for completion in seconds.") - public static int PlayerQuestCheck = 300; - @ConfigProp(info = "Client sided! Determines where tracking quest info shows up on the screen based on a number from 0 to 8. Default: 3") public static int TrackingInfoAlignment = 3; @@ -171,9 +168,6 @@ public class CustomNpcs { if(NpcSizeLimit < 1) NpcSizeLimit = 1; - if(PlayerQuestCheck < 1) - PlayerQuestCheck = 1; - if (TrackingInfoAlignment < 0) TrackingInfoAlignment = 0; if (TrackingInfoAlignment > 8) diff --git a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java index 7ff56edce..1c5aa2272 100644 --- a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java @@ -59,12 +59,6 @@ public class ScriptPlayerEventHandler { if(playerData.timers.size() > 0) playerData.timers.update(); } - - if(player.ticksExisted%(20*CustomNpcs.PlayerQuestCheck) == 0){ - PlayerQuestData questData = playerData.questData; - for(EnumQuestType e : EnumQuestType.values()) - questData.checkQuestCompletion(playerData, e); - } } } From c0406958a3ecff227af0afd41f1b58c772bd656e Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Sun, 29 May 2022 16:01:05 -0500 Subject: [PATCH 08/40] The script controller now checks whether a language can have objects loaded into it on startup, catching an exception and skipping that language as available if so. --- src/main/java/noppes/npcs/client/gui/GuiScript.java | 3 +-- .../noppes/npcs/controllers/ScriptController.java | 8 +++++++- .../npcs/{ => controllers/data}/DataScript.java | 12 ++++++++++-- .../npcs/controllers/data/ForgeDataScript.java | 7 +++++++ .../noppes/npcs/controllers/data/NPCDataScript.java | 7 +++++++ .../npcs/controllers/data/PlayerDataScript.java | 7 +++++++ .../java/noppes/npcs/entity/EntityNPCInterface.java | 8 +------- 7 files changed, 40 insertions(+), 12 deletions(-) rename src/main/java/noppes/npcs/{ => controllers/data}/DataScript.java (93%) diff --git a/src/main/java/noppes/npcs/client/gui/GuiScript.java b/src/main/java/noppes/npcs/client/gui/GuiScript.java index 44ecae3ec..ea7e4f3a9 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiScript.java +++ b/src/main/java/noppes/npcs/client/gui/GuiScript.java @@ -8,8 +8,7 @@ import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.server.MinecraftServer; -import noppes.npcs.CustomNpcs; -import noppes.npcs.DataScript; +import noppes.npcs.controllers.data.DataScript; import noppes.npcs.NoppesStringUtils; import noppes.npcs.client.Client; import noppes.npcs.client.NoppesUtil; diff --git a/src/main/java/noppes/npcs/controllers/ScriptController.java b/src/main/java/noppes/npcs/controllers/ScriptController.java index 066ef7193..dac601506 100644 --- a/src/main/java/noppes/npcs/controllers/ScriptController.java +++ b/src/main/java/noppes/npcs/controllers/ScriptController.java @@ -67,7 +67,13 @@ public class ScriptController { for(ScriptEngineFactory fac : manager.getEngineFactories()){ if(fac.getExtensions().isEmpty()) continue; - fac.getScriptEngine(); + ScriptEngine scriptEngine = fac.getScriptEngine(); + try { + scriptEngine.put("$RunTest",null); + } catch (Exception e) { + continue; + } + String ext = "." + fac.getExtensions().get(0).toLowerCase(); LogWriter.info(fac.getLanguageName() + ": " + ext); languages.put(fac.getLanguageName(), ext); diff --git a/src/main/java/noppes/npcs/DataScript.java b/src/main/java/noppes/npcs/controllers/data/DataScript.java similarity index 93% rename from src/main/java/noppes/npcs/DataScript.java rename to src/main/java/noppes/npcs/controllers/data/DataScript.java index 883550e11..1fdaee109 100644 --- a/src/main/java/noppes/npcs/DataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/DataScript.java @@ -1,4 +1,4 @@ -package noppes.npcs; +package noppes.npcs.controllers.data; import java.util.*; @@ -10,6 +10,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.world.World; import net.minecraft.world.WorldServer; +import noppes.npcs.EventHooks; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.ScriptContainer; import noppes.npcs.controllers.IScriptHandler; @@ -58,7 +59,14 @@ public class DataScript implements IScriptHandler { public void readFromNBT(NBTTagCompound compound) { scripts = readScript(compound.getTagList("ScriptsContainers", 10)); - scriptLanguage = compound.getString("ScriptLanguage"); + this.scriptLanguage = compound.getString("ScriptLanguage"); + if (!ScriptController.Instance.languages.containsKey(scriptLanguage)) { + if (!ScriptController.Instance.languages.isEmpty()) { + this.scriptLanguage = (String) ScriptController.Instance.languages.keySet().toArray()[0]; + } else { + this.scriptLanguage = "ECMAScript"; + } + } enabled = compound.getBoolean("ScriptEnabled"); } diff --git a/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java b/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java index f4e548b1b..50c449e3c 100644 --- a/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java @@ -38,6 +38,13 @@ public class ForgeDataScript implements IScriptHandler { public void readFromNBT(NBTTagCompound compound) { this.scripts = NBTTags.GetScript(compound.getTagList("Scripts", 10), this); this.scriptLanguage = compound.getString("ScriptLanguage"); + if (!ScriptController.Instance.languages.containsKey(scriptLanguage)) { + if (!ScriptController.Instance.languages.isEmpty()) { + this.scriptLanguage = (String) ScriptController.Instance.languages.keySet().toArray()[0]; + } else { + this.scriptLanguage = "ECMAScript"; + } + } this.enabled = compound.getBoolean("ScriptEnabled"); } diff --git a/src/main/java/noppes/npcs/controllers/data/NPCDataScript.java b/src/main/java/noppes/npcs/controllers/data/NPCDataScript.java index 621a6877b..24ea16816 100644 --- a/src/main/java/noppes/npcs/controllers/data/NPCDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/NPCDataScript.java @@ -41,6 +41,13 @@ public class NPCDataScript implements IScriptHandler { public void readFromNBT(NBTTagCompound compound) { this.scripts = NBTTags.GetScript(compound.getTagList("Scripts", 10), this); this.scriptLanguage = compound.getString("ScriptLanguage"); + if (!ScriptController.Instance.languages.containsKey(scriptLanguage)) { + if (!ScriptController.Instance.languages.isEmpty()) { + this.scriptLanguage = (String) ScriptController.Instance.languages.keySet().toArray()[0]; + } else { + this.scriptLanguage = "ECMAScript"; + } + } this.enabled = compound.getBoolean("ScriptEnabled"); this.console = NBTTags.GetLongStringMap(compound.getTagList("ScriptConsole", 10)); } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java index 7f8ea2e60..94e464571 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java @@ -47,6 +47,13 @@ public class PlayerDataScript implements IScriptHandler { public void readFromNBT(NBTTagCompound compound) { this.scripts = NBTTags.GetScript(compound.getTagList("Scripts", 10), this); this.scriptLanguage = compound.getString("ScriptLanguage"); + if (!ScriptController.Instance.languages.containsKey(scriptLanguage)) { + if (!ScriptController.Instance.languages.isEmpty()) { + this.scriptLanguage = (String) ScriptController.Instance.languages.keySet().toArray()[0]; + } else { + this.scriptLanguage = "ECMAScript"; + } + } this.enabled = compound.getBoolean("ScriptEnabled"); this.console = NBTTags.GetLongStringMap(compound.getTagList("ScriptConsole", 10)); } diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 904b11d15..b637b4f17 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -62,17 +62,11 @@ import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.constants.EnumPotionType; import noppes.npcs.constants.EnumRoleType; import noppes.npcs.constants.EnumStandingType; -import noppes.npcs.controllers.data.Dialog; -import noppes.npcs.controllers.data.DialogOption; -import noppes.npcs.controllers.data.Faction; +import noppes.npcs.controllers.data.*; import noppes.npcs.controllers.FactionController; -import noppes.npcs.controllers.data.Line; import noppes.npcs.controllers.LinkedNpcController; import noppes.npcs.controllers.LinkedNpcController.LinkedData; import noppes.npcs.controllers.PlayerDataController; -import noppes.npcs.controllers.data.PlayerQuestData; -import noppes.npcs.controllers.data.QuestData; -import noppes.npcs.controllers.data.DataTransform; import noppes.npcs.entity.data.DataTimers; import noppes.npcs.roles.JobBard; import noppes.npcs.roles.JobFollower; From f0862e8a64239517c3696b3f8ece2d2c4eb9b702 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Sun, 29 May 2022 19:51:03 -0500 Subject: [PATCH 09/40] Fixed armor rendering twice when a player is using an overlay. --- src/main/java/noppes/npcs/client/ClientEventHandler.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/noppes/npcs/client/ClientEventHandler.java b/src/main/java/noppes/npcs/client/ClientEventHandler.java index a25950633..42ba6e216 100644 --- a/src/main/java/noppes/npcs/client/ClientEventHandler.java +++ b/src/main/java/noppes/npcs/client/ClientEventHandler.java @@ -3,6 +3,7 @@ package noppes.npcs.client; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemArmor; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderHandEvent; import net.minecraftforge.client.event.RenderPlayerEvent; @@ -41,6 +42,12 @@ public class ClientEventHandler { event.setCanceled(true); } + @SubscribeEvent + public void cancelSpecials(RenderPlayerEvent.SetArmorModel event) { + if (event.renderer instanceof RenderCNPCPlayer && event.stack.getItem() instanceof ItemArmor) + event.setCanceled(true); + } + @SubscribeEvent public void onClientTick(TickEvent.ClientTickEvent event) { Minecraft mc = Minecraft.getMinecraft(); From 2370c5e1f4e5ca54b27531840e44f83f1a36502e Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Mon, 30 May 2022 04:51:30 -0500 Subject: [PATCH 10/40] Added scrolling to dialogs --- .../client/gui/player/GuiDialogInteract.java | 261 +++++++++++++----- 1 file changed, 194 insertions(+), 67 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index 142fc1127..517509c3c 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -5,6 +5,7 @@ import java.util.List; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.entity.RenderManager; @@ -34,11 +35,35 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose { private Dialog dialog; private int selected = 0; - private List lines = new ArrayList(); + private List lineBlocks = new ArrayList(); private List options = new ArrayList(); private int rowStart = 0; private int rowTotal = 0; - private int dialogHeight = 180; + + private ScaledResolution scaledResolution; + + private int renderDialogType = 1; //0 - Instant (classic), 1 - Gradual + private String gradualText = ""; + private int currentBlock = 0; + private int currentLine = 0; + private int gradualTextTime = 0; + private static int gradualTextSpeed = 10; + + private boolean showPreviousBlocks = true; + + private int textOffsetX, textOffsetY = 100; + private int titleOffsetX, titleOffsetY; + + private int dialogWidth = 500; + private int dialogHeight = 100; + private int dialogTextBottom = 0; + + private int optionSpaceX, optionSpaceY; + private int optionOffsetX, optionOffsetY; + private int optionDefaultY = 175; + + private int scrollY; + private int totalRowHeight; private ResourceLocation wheel; private ResourceLocation[] wheelparts; @@ -64,6 +89,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose grabMouse(dialog.showWheel); guiTop = (height - ySize); calculateRowHeight(); + this.scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); this.drawDefaultBackground = dialog.darkenScreen; } @@ -134,32 +160,106 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose GL11.glEnable(GL11.GL_BLEND); OpenGlHelper.glBlendFunc(770, 771, 1, 0); GL11.glEnable(GL11.GL_ALPHA_TEST); + GL11.glPushMatrix(); - GL11.glTranslatef(0.0F, 0.5f, 100.065F); - int count = 0; - for(TextBlockClient block : lines){ - int size = ClientProxy.Font.width(block.getName() + ": "); - drawString(block.getName() + ": ", -4 - size, block.color, count); - for(IChatComponent line : block.lines){ - drawString(line.getFormattedText(), 0, block.color, count); - count++; - } - count++; - } - - if(!options.isEmpty()){ - if(!dialog.showWheel) - drawLinedOptions(j); - else - drawWheel(); - } + GL11.glTranslatef(0.0F, 0.5f, 100.065F); + if (renderDialogType == 1) { + drawString(fontRendererObj, "Text Speed: " + gradualTextSpeed, 10, 10, 0xFFFFFF); + } + + GL11.glPushMatrix(); + GL11.glTranslatef(textOffsetX, 0.0F, 0.0F); + if (renderDialogType == 0) { + int count = 0; + for (TextBlockClient block : lineBlocks) { + int size = ClientProxy.Font.width(block.getName() + " "); + GL11.glPushMatrix(); + GL11.glTranslatef(titleOffsetX, titleOffsetY, 0.0F); + drawDialogString(block.getName() + " ", -4 - size, block.color, count); + GL11.glPopMatrix(); + for (IChatComponent line : block.lines) { + drawDialogString(line.getFormattedText(), 0, block.color, count); + count++; + } + count++; + } + } else { + int count = 0; + for (int pastBlock = 0; pastBlock < currentBlock; pastBlock++) { + TextBlockClient block = lineBlocks.get(pastBlock); + + int size = ClientProxy.Font.width(block.getName() + " "); + GL11.glPushMatrix(); + GL11.glTranslatef(titleOffsetX, titleOffsetY, 0.0F); + drawDialogString(block.getName() + " ", -4 - size, block.color, count); + GL11.glPopMatrix(); + for (IChatComponent line : block.lines) { + drawDialogString(line.getFormattedText(), 0, block.color, count); + count++; + } + count++; + } + + if (currentBlock < lineBlocks.size()) { + TextBlockClient block = lineBlocks.get(currentBlock); + int size = ClientProxy.Font.width(block.getName() + " "); + GL11.glPushMatrix(); + GL11.glTranslatef(titleOffsetX, titleOffsetY, 0.0F); + drawDialogString(block.getName() + " ", -4 - size, block.color, count); + GL11.glPopMatrix(); + + for (int pastLine = 0; pastLine < currentLine; pastLine++) { + IChatComponent line = block.lines.get(pastLine); + drawDialogString(line.getFormattedText(), 0, block.color, count); + count++; + } + + if (currentLine < block.lines.size()) { + IChatComponent line = block.lines.get(currentLine); + try { + if (gradualTextSpeed > 10 || gradualTextTime%(11 - gradualTextSpeed) == 0) { + int addChar = gradualTextSpeed > 10 ? gradualTextSpeed - 9 : 1; + gradualText += line.getFormattedText().substring(gradualText.length(), gradualText.length() + addChar); + if (gradualTextTime%3 == 0) { + NoppesUtil.clickSound(); + } + } + } catch (IndexOutOfBoundsException exception) { + gradualText = line.getFormattedText(); + } + + drawDialogString(gradualText, 0, block.color, count); + + if (gradualText.length() == line.getFormattedText().length()) { + gradualText = ""; + currentLine++; + if (currentLine >= lineBlocks.get(currentBlock).lines.size()) { + currentBlock++; + } + } + + gradualTextTime++; + } + } + } + GL11.glPopMatrix(); + + GL11.glPushMatrix(); + GL11.glTranslatef(optionOffsetX, optionOffsetY, 0.0F); + if(!options.isEmpty()){ + if(!dialog.showWheel) + drawLinedOptions(j); + else + drawWheel(); + } GL11.glPopMatrix(); + GL11.glPopMatrix(); } private int selectedX = 0; private int selectedY = 0; private void drawWheel(){ - int yoffset = guiTop + dialogHeight + 14; + int yoffset = guiTop + optionDefaultY + 14; GL11.glColor4f(1, 1, 1, 1); mc.renderEngine.bindTexture(wheel); drawTexturedModalRect((width/2) - 31, yoffset, 0, 0, 63, 40); @@ -213,10 +313,10 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose drawTexturedModalRect(width/2 + selectedX/4 - 2,yoffset + 16 - selectedY/6, 0, 0, 8, 8); } private void drawLinedOptions(int j){ - drawHorizontalLine(guiLeft - 60, guiLeft + xSize + 120, guiTop + dialogHeight, 0xFFFFFFFF); - int offset = dialogHeight + 4; - if(j >= (int)((guiTop + offset))){ - int selected = (int) ((j - (guiTop + offset)) / (ClientProxy.Font.height())); + int offset = scaledResolution.getScaledHeight() - (options.size() + 2) * ClientProxy.Font.height(); + dialogTextBottom = offset - 100; + if(j >= offset){ + int selected = options.size() - (j - offset) / ClientProxy.Font.height(); if(selected < options.size()) this.selected = selected; } @@ -224,47 +324,67 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose selected = 0; if(selected < 0) selected = 0; - int count = 0; + + drawHorizontalLine(guiLeft - 60, guiLeft + xSize + 120, offset, 0xFFFFFFFF); + for(int k = 0; k < options.size(); k++){ - int id = options.get(k); + int id = options.get(options.size() - 1 - k); DialogOption option = dialog.options.get(id); - int y = (int)((guiTop + offset + (count * ClientProxy.Font.height()))); + int y = scaledResolution.getScaledHeight() - (k + 2) * ClientProxy.Font.height(); if(selected == k){ drawString(fontRendererObj, ">", guiLeft - 60, y, 0xe0e0e0); } - drawString(fontRendererObj, NoppesStringUtils.formatText(option.title, player, npc), guiLeft - 30, y, option.optionColor); - count++; + drawString(fontRendererObj, NoppesStringUtils.formatText(option.title, player, npc), guiLeft - 30 + optionSpaceX * k, y, option.optionColor); } } - - private void drawString(String text, int left, int color, int count){ - int height = count - rowStart; - drawString(fontRendererObj, text, guiLeft + left, guiTop + (height * ClientProxy.Font.height()), color); - } + + private void drawDialogString(String text, int left, int color, int count){ + int height = count - rowStart; + int y = (height * ClientProxy.Font.height()) + dialogTextBottom + scrollY; + if (y < dialogTextBottom - dialogHeight || y > dialogTextBottom + ClientProxy.Font.height() * 8) { + return; + } + drawString(fontRendererObj, text, guiLeft + left, y, color); + } public void drawString(FontRenderer fontRendererIn, String text, int x, int y, int color){ ClientProxy.Font.drawString(text, x, y, color); - //super.drawString(fontRendererIn, text, x, y, color); - } - - private int getSelected(){ - if(selected <= 0) - return 0; - - if(selected < options.size()) - return selected; - - return options.size() - 1; } @Override public void keyTyped(char c, int i){ if(i == mc.gameSettings.keyBindForward.getKeyCode() || i == Keyboard.KEY_UP){ - selected--; + if (dialog.showWheel) { + selected--; + } else { + selected++; + } } if(i == mc.gameSettings.keyBindBack.getKeyCode() || i == Keyboard.KEY_DOWN){ - selected++; + if (dialog.showWheel) { + selected++; + } else { + selected--; + } } + + if(i == mc.gameSettings.keyBindForward.getKeyCode() || i == Keyboard.KEY_LEFT){ + gradualTextSpeed--; + if (gradualTextSpeed < 1) { + gradualTextSpeed = 1; + } + } + if(i == mc.gameSettings.keyBindBack.getKeyCode() || i == Keyboard.KEY_RIGHT){ + gradualTextSpeed++; + } + + if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 201 && (scrollY < rowStart * ClientProxy.Font.height())) {//Page up + scrollY += ClientProxy.Font.height() * 2; + } + if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 209 && (scrollY > 0)) {//Page down + scrollY -= ClientProxy.Font.height() * 2; + } + if(i == 28){ handleDialogSelection(); } @@ -278,15 +398,17 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose @Override public void mouseClicked(int i,int j,int k){ - if(selected == -1 && options.isEmpty() || selected >= 0) - handleDialogSelection(); + if(selected == -1 && options.isEmpty() || selected >= 0) { + scrollY = 0; + handleDialogSelection(); + } } private void handleDialogSelection(){ int optionId = -1; if(dialog.showWheel) optionId = selected; else if(!options.isEmpty()) - optionId = options.get(selected); + optionId = options.get(options.size() - 1 - selected); NoppesUtilPlayer.sendData(EnumPlayerPacket.Dialog, dialog.id, optionId); if(dialog == null || !dialog.hasOtherOptions() || options.isEmpty()){ closed(); @@ -299,8 +421,15 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose close(); return; } - - lines.add(new TextBlockClient(player.getDisplayName(), option.title, 280, option.optionColor, player, npc)); + + if (!showPreviousBlocks) { + lineBlocks.clear(); + } + lineBlocks.add(new TextBlockClient(player.getDisplayName(), option.title, dialogWidth, option.optionColor, player, npc)); + gradualText = ""; + currentBlock = lineBlocks.size()-1; + currentLine = 0; + gradualTextTime = 0; calculateRowHeight(); NoppesUtil.clickSound(); @@ -324,9 +453,16 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose MusicController.Instance.stopMusic(); MusicController.Instance.playSound(dialog.sound, (float)npc.posX, (float)npc.posY, (float)npc.posZ); } - - lines.add(new TextBlockClient(npc, dialog.text, 280, 0xe0e0e0, player, npc)); - + + if (!showPreviousBlocks) { + lineBlocks.clear(); + } + lineBlocks.add(new TextBlockClient(npc, dialog.text, dialogWidth, 0xe0e0e0, player, npc)); + gradualText = ""; + currentBlock = lineBlocks.size()-1; + currentLine = 0; + gradualTextTime = 0; + for(int slot:dialog.options.keySet()){ DialogOption option = dialog.options.get(slot); if(option == null || option.optionType == EnumOptionType.Disabled) @@ -338,21 +474,12 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose grabMouse(dialog.showWheel); } private void calculateRowHeight(){ - if(dialog.showWheel){ - dialogHeight = ySize - 58; - } - else{ - dialogHeight = ySize - 3 * ClientProxy.Font.height() - 4; - if(dialog.options.size() > 3){ - dialogHeight -= (dialog.options.size() - 3) * ClientProxy.Font.height(); - } - } rowTotal = 0; - for(TextBlockClient block : lines){ + for(TextBlockClient block : lineBlocks){ rowTotal += block.lines.size() + 1; } int max = dialogHeight / ClientProxy.Font.height(); - + rowStart = rowTotal - max; if(rowStart < 0) rowStart = 0; From e7ceaa6d2adb9ba9cb09761ac9a012e04c049420 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Mon, 30 May 2022 04:53:17 -0500 Subject: [PATCH 11/40] Simplified logic on an if statement --- .../java/noppes/npcs/client/gui/player/GuiDialogInteract.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index 517509c3c..a54aa517e 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -378,10 +378,10 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose gradualTextSpeed++; } - if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 201 && (scrollY < rowStart * ClientProxy.Font.height())) {//Page up + if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 201 && scrollY < rowStart * ClientProxy.Font.height()) {//Page up scrollY += ClientProxy.Font.height() * 2; } - if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 209 && (scrollY > 0)) {//Page down + if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 209 && scrollY > 0) {//Page down scrollY -= ClientProxy.Font.height() * 2; } From bb65e7910204cd2bb4764a111ccac49840860d58 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Mon, 30 May 2022 18:31:58 -0500 Subject: [PATCH 12/40] Implemented dialog option spacing --- .../client/gui/player/GuiDialogInteract.java | 77 ++++++++++--------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index a54aa517e..ddf374c00 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -51,7 +51,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose private boolean showPreviousBlocks = true; - private int textOffsetX, textOffsetY = 100; + private int textOffsetX, textOffsetY; private int titleOffsetX, titleOffsetY; private int dialogWidth = 500; @@ -63,7 +63,6 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose private int optionDefaultY = 175; private int scrollY; - private int totalRowHeight; private ResourceLocation wheel; private ResourceLocation[] wheelparts; @@ -173,12 +172,10 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose int count = 0; for (TextBlockClient block : lineBlocks) { int size = ClientProxy.Font.width(block.getName() + " "); - GL11.glPushMatrix(); - GL11.glTranslatef(titleOffsetX, titleOffsetY, 0.0F); - drawDialogString(block.getName() + " ", -4 - size, block.color, count); - GL11.glPopMatrix(); + drawDialogString(block.getName() + " ", -4 - size, block.color, count, false); + for (IChatComponent line : block.lines) { - drawDialogString(line.getFormattedText(), 0, block.color, count); + drawDialogString(line.getFormattedText(), 0, block.color, count, true); count++; } count++; @@ -187,14 +184,11 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose int count = 0; for (int pastBlock = 0; pastBlock < currentBlock; pastBlock++) { TextBlockClient block = lineBlocks.get(pastBlock); - int size = ClientProxy.Font.width(block.getName() + " "); - GL11.glPushMatrix(); - GL11.glTranslatef(titleOffsetX, titleOffsetY, 0.0F); - drawDialogString(block.getName() + " ", -4 - size, block.color, count); - GL11.glPopMatrix(); + drawDialogString(block.getName() + " ", -4 - size, block.color, count, false); + for (IChatComponent line : block.lines) { - drawDialogString(line.getFormattedText(), 0, block.color, count); + drawDialogString(line.getFormattedText(), 0, block.color, count, true); count++; } count++; @@ -203,14 +197,11 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if (currentBlock < lineBlocks.size()) { TextBlockClient block = lineBlocks.get(currentBlock); int size = ClientProxy.Font.width(block.getName() + " "); - GL11.glPushMatrix(); - GL11.glTranslatef(titleOffsetX, titleOffsetY, 0.0F); - drawDialogString(block.getName() + " ", -4 - size, block.color, count); - GL11.glPopMatrix(); + drawDialogString(block.getName() + " ", -4 - size, block.color, count, false); for (int pastLine = 0; pastLine < currentLine; pastLine++) { IChatComponent line = block.lines.get(pastLine); - drawDialogString(line.getFormattedText(), 0, block.color, count); + drawDialogString(line.getFormattedText(), 0, block.color, count, true); count++; } @@ -228,7 +219,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose gradualText = line.getFormattedText(); } - drawDialogString(gradualText, 0, block.color, count); + drawDialogString(gradualText, 0, block.color, count, true); if (gradualText.length() == line.getFormattedText().length()) { gradualText = ""; @@ -245,7 +236,6 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose GL11.glPopMatrix(); GL11.glPushMatrix(); - GL11.glTranslatef(optionOffsetX, optionOffsetY, 0.0F); if(!options.isEmpty()){ if(!dialog.showWheel) drawLinedOptions(j); @@ -259,18 +249,19 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose private int selectedX = 0; private int selectedY = 0; private void drawWheel(){ - int yoffset = guiTop + optionDefaultY + 14; + int yoffset = scaledResolution.getScaledHeight() - 50 + optionOffsetY; + dialogTextBottom = yoffset - 100; GL11.glColor4f(1, 1, 1, 1); mc.renderEngine.bindTexture(wheel); - drawTexturedModalRect((width/2) - 31, yoffset, 0, 0, 63, 40); + drawTexturedModalRect((width/2) - 31 + optionOffsetX, yoffset, 0, 0, 63, 40); selectedX += Mouse.getDX(); selectedY += Mouse.getDY(); int limit = 80; - if(selectedX > limit) - selectedX = limit; - if(selectedX < -limit) - selectedX = -limit; + if(selectedX > limit + optionOffsetX) + selectedX = limit + optionOffsetX; + if(selectedX < -limit + optionOffsetX) + selectedX = -limit + optionOffsetX; if(selectedY > limit) selectedY = limit; @@ -286,7 +277,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if(selectedX < 0) selected += 3; mc.renderEngine.bindTexture(wheelparts[selected]); - drawTexturedModalRect((width/2) - 31,yoffset, 0, 0, 85, 55); + drawTexturedModalRect((width/2) - 31 + optionOffsetX,yoffset, 0, 0, 85, 55); for(int slot:dialog.options.keySet()){ DialogOption option = dialog.options.get(slot); if(option == null || option.optionType == EnumOptionType.Disabled) @@ -296,27 +287,27 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose color = 0x838FD8; //drawString(fontRenderer, option.title, width/2 -50 ,yoffset+ 162 + slot * 13 , color); if(slot == 0) - drawString(fontRendererObj, option.title, width/2 + 13,yoffset - 6 , color); + drawString(fontRendererObj, option.title, width/2 + 13 + optionOffsetX,yoffset - 6 , color); if(slot == 1) - drawString(fontRendererObj, option.title, width/2 + 33,yoffset + 12 , color); + drawString(fontRendererObj, option.title, width/2 + 33 + optionOffsetX,yoffset + 12 , color); if(slot == 2) - drawString(fontRendererObj, option.title, width/2 + 27,yoffset + 32 , color); + drawString(fontRendererObj, option.title, width/2 + 27 + optionOffsetX,yoffset + 32 , color); if(slot == 3) - drawString(fontRendererObj, option.title, width/2 - 13 - ClientProxy.Font.width(option.title),yoffset - 6 , color); + drawString(fontRendererObj, option.title, width/2 - 13 + optionOffsetX - ClientProxy.Font.width(option.title),yoffset - 6 , color); if(slot == 4) - drawString(fontRendererObj, option.title, width/2 - 33 - ClientProxy.Font.width(option.title),yoffset + 12 , color); + drawString(fontRendererObj, option.title, width/2 - 33 + optionOffsetX - ClientProxy.Font.width(option.title),yoffset + 12 , color); if(slot == 5) - drawString(fontRendererObj, option.title, width/2 - 27 - ClientProxy.Font.width(option.title),yoffset + 32 , color); + drawString(fontRendererObj, option.title, width/2 - 27 + optionOffsetX - ClientProxy.Font.width(option.title),yoffset + 32 , color); } mc.renderEngine.bindTexture(indicator); drawTexturedModalRect(width/2 + selectedX/4 - 2,yoffset + 16 - selectedY/6, 0, 0, 8, 8); } private void drawLinedOptions(int j){ - int offset = scaledResolution.getScaledHeight() - (options.size() + 2) * ClientProxy.Font.height(); + int offset = scaledResolution.getScaledHeight() - (options.size() + 2) * ClientProxy.Font.height() + optionOffsetY - options.size() * optionSpaceY; dialogTextBottom = offset - 100; if(j >= offset){ - int selected = options.size() - (j - offset) / ClientProxy.Font.height(); + int selected = options.size() - (j - offset + optionSpaceY) / (ClientProxy.Font.height() + optionSpaceY); if(selected < options.size()) this.selected = selected; } @@ -330,7 +321,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose for(int k = 0; k < options.size(); k++){ int id = options.get(options.size() - 1 - k); DialogOption option = dialog.options.get(id); - int y = scaledResolution.getScaledHeight() - (k + 2) * ClientProxy.Font.height(); + int y = scaledResolution.getScaledHeight() - (k + 2) * ClientProxy.Font.height() + optionOffsetY + (-1 - k) * optionSpaceY; if(selected == k){ drawString(fontRendererObj, ">", guiLeft - 60, y, 0xe0e0e0); } @@ -338,13 +329,23 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose } } - private void drawDialogString(String text, int left, int color, int count){ + private void drawDialogString(String text, int left, int color, int count, boolean mainDialogText){ int height = count - rowStart; int y = (height * ClientProxy.Font.height()) + dialogTextBottom + scrollY; if (y < dialogTextBottom - dialogHeight || y > dialogTextBottom + ClientProxy.Font.height() * 8) { return; } - drawString(fontRendererObj, text, guiLeft + left, y, color); + + int offsetX, offsetY; + if (mainDialogText) { + offsetX = textOffsetX; + offsetY = textOffsetY; + } else { + offsetX = titleOffsetX; + offsetY = titleOffsetY; + } + + drawString(fontRendererObj, text, guiLeft + left + offsetX, y + offsetY, color); } public void drawString(FontRenderer fontRendererIn, String text, int x, int y, int color){ From dccdb9636ce044c7de55d310afed19c994d7fb55 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Mon, 30 May 2022 23:56:31 -0500 Subject: [PATCH 13/40] More tweaks to dialogs, fixed option X spacing. --- .../npcs/client/gui/player/GuiDialogInteract.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index ddf374c00..f1be277e6 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -51,19 +51,17 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose private boolean showPreviousBlocks = true; - private int textOffsetX, textOffsetY; - private int titleOffsetX, titleOffsetY; - private int dialogWidth = 500; private int dialogHeight = 100; private int dialogTextBottom = 0; + private int textOffsetX, textOffsetY; + private int titleOffsetX, titleOffsetY; + private int optionSpaceX, optionSpaceY; private int optionOffsetX, optionOffsetY; - private int optionDefaultY = 175; private int scrollY; - private ResourceLocation wheel; private ResourceLocation[] wheelparts; private ResourceLocation indicator; @@ -312,7 +310,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose this.selected = selected; } if(selected >= options.size()) - selected = 0; + selected = options.size() - 1; if(selected < 0) selected = 0; @@ -325,7 +323,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if(selected == k){ drawString(fontRendererObj, ">", guiLeft - 60, y, 0xe0e0e0); } - drawString(fontRendererObj, NoppesStringUtils.formatText(option.title, player, npc), guiLeft - 30 + optionSpaceX * k, y, option.optionColor); + drawString(fontRendererObj, NoppesStringUtils.formatText(option.title, player, npc), guiLeft - 30 + optionSpaceX * (options.size() - 1 - k), y, option.optionColor); } } From 213d69f146eff237825e60c54a8f08c7cb05727d Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Tue, 31 May 2022 18:54:11 -0500 Subject: [PATCH 14/40] Function added NpcAPI: -Added stopServer() function. --- src/main/java/noppes/npcs/scripted/NpcAPI.java | 4 ++++ .../java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index 877dd19a0..5afa158e2 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -66,6 +66,10 @@ public class NpcAPI extends AbstractNpcAPI { worldCache.clear(); } + public void stopServer() { + CustomNpcs.getServer().stopServer(); + } + public IFactionHandler getFactions() { this.checkWorld(); return FactionController.getInstance(); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java b/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java index 939341e73..81d8ad3c3 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java @@ -43,6 +43,8 @@ public abstract class AbstractNpcAPI { public AbstractNpcAPI() { } + public abstract void stopServer(); + public abstract IFactionHandler getFactions(); public abstract IRecipeHandler getRecipes(); From 2c84a527bfea84832c1fa34c6fe7dafa649141b5 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Fri, 3 Jun 2022 14:02:48 -0500 Subject: [PATCH 15/40] Fixed dialog height --- .../noppes/npcs/client/gui/player/GuiDialogInteract.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index f1be277e6..813ec4b78 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -52,7 +52,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose private boolean showPreviousBlocks = true; private int dialogWidth = 500; - private int dialogHeight = 100; + private int dialogHeight = 200; private int dialogTextBottom = 0; private int textOffsetX, textOffsetY; @@ -477,9 +477,8 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose for(TextBlockClient block : lineBlocks){ rowTotal += block.lines.size() + 1; } - int max = dialogHeight / ClientProxy.Font.height(); - rowStart = rowTotal - max; + rowStart = rowTotal; if(rowStart < 0) rowStart = 0; } From c7b34dcf5404ffe9d0d7e97c1e1a5056f1f89e17 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Fri, 3 Jun 2022 15:33:20 -0500 Subject: [PATCH 16/40] More scrolling and dialog alignment fixes. --- .../client/gui/player/GuiDialogInteract.java | 56 +++++++++---------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index 813ec4b78..683994ed1 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -37,36 +37,35 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose private int selected = 0; private List lineBlocks = new ArrayList(); private List options = new ArrayList(); - private int rowStart = 0; - private int rowTotal = 0; + private int totalRows = 0; private ScaledResolution scaledResolution; - private int renderDialogType = 1; //0 - Instant (classic), 1 - Gradual private String gradualText = ""; private int currentBlock = 0; private int currentLine = 0; private int gradualTextTime = 0; private static int gradualTextSpeed = 10; - - private boolean showPreviousBlocks = true; - - private int dialogWidth = 500; - private int dialogHeight = 200; private int dialogTextBottom = 0; - private int textOffsetX, textOffsetY; - private int titleOffsetX, titleOffsetY; - - private int optionSpaceX, optionSpaceY; - private int optionOffsetX, optionOffsetY; - private int scrollY; private ResourceLocation wheel; private ResourceLocation[] wheelparts; private ResourceLocation indicator; private boolean isGrabbed = false; + + private int renderDialogType = 0; //0 - Instant (classic), 1 - Gradual + private boolean showPreviousBlocks = true; + + private int dialogWidth = 500; + private int dialogHeight = 200; + + private int textOffsetX, textOffsetY; + private int titleOffsetX, titleOffsetY; + + private int optionSpaceX, optionSpaceY; + private int optionOffsetX, optionOffsetY; public GuiDialogInteract(EntityNPCInterface npc, Dialog dialog){ super(npc); @@ -248,7 +247,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose private int selectedY = 0; private void drawWheel(){ int yoffset = scaledResolution.getScaledHeight() - 50 + optionOffsetY; - dialogTextBottom = yoffset - 100; + //dialogTextBottom = yoffset - 100; GL11.glColor4f(1, 1, 1, 1); mc.renderEngine.bindTexture(wheel); drawTexturedModalRect((width/2) - 31 + optionOffsetX, yoffset, 0, 0, 63, 40); @@ -303,7 +302,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose } private void drawLinedOptions(int j){ int offset = scaledResolution.getScaledHeight() - (options.size() + 2) * ClientProxy.Font.height() + optionOffsetY - options.size() * optionSpaceY; - dialogTextBottom = offset - 100; + //dialogTextBottom = offset - 100; if(j >= offset){ int selected = options.size() - (j - offset + optionSpaceY) / (ClientProxy.Font.height() + optionSpaceY); if(selected < options.size()) @@ -328,9 +327,10 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose } private void drawDialogString(String text, int left, int color, int count, boolean mainDialogText){ - int height = count - rowStart; - int y = (height * ClientProxy.Font.height()) + dialogTextBottom + scrollY; - if (y < dialogTextBottom - dialogHeight || y > dialogTextBottom + ClientProxy.Font.height() * 8) { + int height = count - totalRows; + int midScreen = scaledResolution.getScaledHeight() / 2; + int y = (height * ClientProxy.Font.height()) + midScreen + scrollY; + if (y < midScreen - dialogHeight || y > midScreen - ClientProxy.Font.height()) { return; } @@ -377,7 +377,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose gradualTextSpeed++; } - if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 201 && scrollY < rowStart * ClientProxy.Font.height()) {//Page up + if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 201 && scrollY < (totalRows - 2) * ClientProxy.Font.height()) {//Page up scrollY += ClientProxy.Font.height() * 2; } if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 209 && scrollY > 0) {//Page down @@ -462,25 +462,21 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose currentLine = 0; gradualTextTime = 0; - for(int slot:dialog.options.keySet()){ + for(int slot:dialog.options.keySet()){ DialogOption option = dialog.options.get(slot); if(option == null || option.optionType == EnumOptionType.Disabled) continue; options.add(slot); - } - calculateRowHeight(); + } + calculateRowHeight(); - grabMouse(dialog.showWheel); + grabMouse(dialog.showWheel); } private void calculateRowHeight(){ - rowTotal = 0; + totalRows = 0; for(TextBlockClient block : lineBlocks){ - rowTotal += block.lines.size() + 1; + totalRows += block.lines.size() + 1; } - - rowStart = rowTotal; - if(rowStart < 0) - rowStart = 0; } @Override From 3552b58e5c3e1430e9fe5a874eba986c90f05145 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Fri, 3 Jun 2022 15:38:52 -0500 Subject: [PATCH 17/40] You can no longer scroll up until no dialog lines are visible. --- .../java/noppes/npcs/client/gui/player/GuiDialogInteract.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index 683994ed1..db0b101af 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -377,7 +377,8 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose gradualTextSpeed++; } - if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 201 && scrollY < (totalRows - 2) * ClientProxy.Font.height()) {//Page up + int firstBlockSize = lineBlocks.size() > 0 ? lineBlocks.get(0).lines.size() + 1 : 0; + if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 201 && scrollY < (totalRows - firstBlockSize) * ClientProxy.Font.height()) {//Page up scrollY += ClientProxy.Font.height() * 2; } if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 209 && scrollY > 0) {//Page down From a1f4861d3388a0f201f7edd2ef3e537a989f0df2 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Fri, 3 Jun 2022 17:16:58 -0500 Subject: [PATCH 18/40] Added toggle for text sound --- .../client/gui/player/GuiDialogInteract.java | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index db0b101af..08958f858 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.OpenGlHelper; @@ -45,27 +46,34 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose private int currentBlock = 0; private int currentLine = 0; private int gradualTextTime = 0; - private static int gradualTextSpeed = 10; private int dialogTextBottom = 0; + private static int textSpeed = 10; + private static boolean textSoundEnabled = true; + private int scrollY; private ResourceLocation wheel; private ResourceLocation[] wheelparts; private ResourceLocation indicator; private boolean isGrabbed = false; + private int textSoundTime = 0; - private int renderDialogType = 0; //0 - Instant (classic), 1 - Gradual + + private int renderDialogType = 1; //0 - Instant (classic), 1 - Gradual private boolean showPreviousBlocks = true; private int dialogWidth = 500; - private int dialogHeight = 200; + private int dialogHeight = 400; private int textOffsetX, textOffsetY; private int titleOffsetX, titleOffsetY; private int optionSpaceX, optionSpaceY; private int optionOffsetX, optionOffsetY; + + private String textSound = "minecraft:random.wood_click"; + private float textPitch = 1.0F; public GuiDialogInteract(EntityNPCInterface npc, Dialog dialog){ super(npc); @@ -160,7 +168,8 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose GL11.glPushMatrix(); GL11.glTranslatef(0.0F, 0.5f, 100.065F); if (renderDialogType == 1) { - drawString(fontRendererObj, "Text Speed: " + gradualTextSpeed, 10, 10, 0xFFFFFF); + drawString(fontRendererObj, "Text Speed: " + textSpeed, 10, 10, 0xFFFFFF); + drawString(fontRendererObj, "Text Sound: " + (textSoundEnabled ? "On" : "Off"), 10, 20, 0xFFFFFF); } GL11.glPushMatrix(); @@ -205,12 +214,13 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if (currentLine < block.lines.size()) { IChatComponent line = block.lines.get(currentLine); try { - if (gradualTextSpeed > 10 || gradualTextTime%(11 - gradualTextSpeed) == 0) { - int addChar = gradualTextSpeed > 10 ? gradualTextSpeed - 9 : 1; + if (textSpeed > 10 || gradualTextTime%(11 - textSpeed) == 0) { + int addChar = textSpeed > 10 ? textSpeed - 9 : 1; gradualText += line.getFormattedText().substring(gradualText.length(), gradualText.length() + addChar); - if (gradualTextTime%3 == 0) { - NoppesUtil.clickSound(); + if (textSoundTime % 5 == 0) { + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation(textSound), textPitch)); } + textSoundTime++; } } catch (IndexOutOfBoundsException exception) { gradualText = line.getFormattedText(); @@ -247,7 +257,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose private int selectedY = 0; private void drawWheel(){ int yoffset = scaledResolution.getScaledHeight() - 50 + optionOffsetY; - //dialogTextBottom = yoffset - 100; + GL11.glColor4f(1, 1, 1, 1); mc.renderEngine.bindTexture(wheel); drawTexturedModalRect((width/2) - 31 + optionOffsetX, yoffset, 0, 0, 63, 40); @@ -302,7 +312,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose } private void drawLinedOptions(int j){ int offset = scaledResolution.getScaledHeight() - (options.size() + 2) * ClientProxy.Font.height() + optionOffsetY - options.size() * optionSpaceY; - //dialogTextBottom = offset - 100; + if(j >= offset){ int selected = options.size() - (j - offset + optionSpaceY) / (ClientProxy.Font.height() + optionSpaceY); if(selected < options.size()) @@ -328,7 +338,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose private void drawDialogString(String text, int left, int color, int count, boolean mainDialogText){ int height = count - totalRows; - int midScreen = scaledResolution.getScaledHeight() / 2; + int midScreen = (int) (scaledResolution.getScaledHeight() * 0.75F); int y = (height * ClientProxy.Font.height()) + midScreen + scrollY; if (y < midScreen - dialogHeight || y > midScreen - ClientProxy.Font.height()) { return; @@ -368,13 +378,17 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose } if(i == mc.gameSettings.keyBindForward.getKeyCode() || i == Keyboard.KEY_LEFT){ - gradualTextSpeed--; - if (gradualTextSpeed < 1) { - gradualTextSpeed = 1; + textSpeed--; + if (textSpeed < 1) { + textSpeed = 1; } } if(i == mc.gameSettings.keyBindBack.getKeyCode() || i == Keyboard.KEY_RIGHT){ - gradualTextSpeed++; + textSpeed++; + } + + if(i == mc.gameSettings.keyBindJump.getKeyCode() || i == Keyboard.KEY_SPACE){ + textSoundEnabled = !textSoundEnabled; } int firstBlockSize = lineBlocks.size() > 0 ? lineBlocks.get(0).lines.size() + 1 : 0; From e51d36e7a112443fb66c56ef2903538946ae5382 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Sun, 5 Jun 2022 23:28:33 -0500 Subject: [PATCH 19/40] Dialog text renders on top of options again. --- .../client/gui/player/GuiDialogInteract.java | 79 +++++++++++++++---- 1 file changed, 65 insertions(+), 14 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index 08958f858..29bac54f0 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -1,6 +1,7 @@ package noppes.npcs.client.gui.player; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import net.minecraft.client.Minecraft; @@ -46,7 +47,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose private int currentBlock = 0; private int currentLine = 0; private int gradualTextTime = 0; - private int dialogTextBottom = 0; + private int optionStart = 0; private static int textSpeed = 10; private static boolean textSoundEnabled = true; @@ -59,11 +60,14 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose private boolean isGrabbed = false; private int textSoundTime = 0; + /* * + * DIALOG VARIABLES * + * */ private int renderDialogType = 1; //0 - Instant (classic), 1 - Gradual private boolean showPreviousBlocks = true; - private int dialogWidth = 500; + private int dialogWidth = 300; private int dialogHeight = 400; private int textOffsetX, textOffsetY; @@ -74,6 +78,11 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose private String textSound = "minecraft:random.wood_click"; private float textPitch = 1.0F; + + private HashMap dialogImages = new HashMap<>(); + private GuiDialogImage textImage; + private GuiDialogImage optionImage; + private int selectedImageColor = 0xFFFF00; public GuiDialogInteract(EntityNPCInterface npc, Dialog dialog){ super(npc); @@ -81,6 +90,9 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose appendDialog(dialog); ySize = 238; + textImage = new GuiDialogImage(0, "customnpcs:textures/gui/extrasmallbg.png", 0,0, 176, 71); + optionImage = new GuiDialogImage(0, "customnpcs:textures/gui/info.png", 0,0, 256, 256); + wheel = this.getResource("wheel.png"); indicator = this.getResource("indicator.png"); wheelparts = new ResourceLocation[]{getResource("wheel1.png"),getResource("wheel2.png"),getResource("wheel3.png"), @@ -95,6 +107,8 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose calculateRowHeight(); this.scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); this.drawDefaultBackground = dialog.darkenScreen; + + optionStart = scaledResolution.getScaledHeight() - (options.size()) * (ClientProxy.Font.height() + optionSpaceY) - 20; } public void grabMouse(boolean grab){ @@ -172,8 +186,28 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose drawString(fontRendererObj, "Text Sound: " + (textSoundEnabled ? "On" : "Off"), 10, 20, 0xFFFFFF); } + for (GuiDialogImage image : dialogImages.values()) { + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); + GL11.glDisable(GL11.GL_ALPHA_TEST); + + image.onRender(mc); + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_ALPHA_TEST); + } + GL11.glPushMatrix(); GL11.glTranslatef(textOffsetX, 0.0F, 0.0F); + + if (textImage != null && !textImage.texture.isEmpty()) { + GL11.glPushMatrix(); + GL11.glTranslatef(guiLeft + textOffsetX, optionStart + textOffsetY - textImage.height * textImage.scale, 0.0F); + textImage.onRender(mc); + GL11.glPopMatrix(); + } + if (renderDialogType == 0) { int count = 0; for (TextBlockClient block : lineBlocks) { @@ -256,7 +290,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose private int selectedX = 0; private int selectedY = 0; private void drawWheel(){ - int yoffset = scaledResolution.getScaledHeight() - 50 + optionOffsetY; + int yoffset = optionStart; GL11.glColor4f(1, 1, 1, 1); mc.renderEngine.bindTexture(wheel); @@ -311,10 +345,10 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose drawTexturedModalRect(width/2 + selectedX/4 - 2,yoffset + 16 - selectedY/6, 0, 0, 8, 8); } private void drawLinedOptions(int j){ - int offset = scaledResolution.getScaledHeight() - (options.size() + 2) * ClientProxy.Font.height() + optionOffsetY - options.size() * optionSpaceY; + int offset = optionStart; if(j >= offset){ - int selected = options.size() - (j - offset + optionSpaceY) / (ClientProxy.Font.height() + optionSpaceY); + int selected = (j - offset - ClientProxy.Font.height() - optionOffsetY) / (ClientProxy.Font.height() + optionSpaceY); if(selected < options.size()) this.selected = selected; } @@ -326,21 +360,38 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose drawHorizontalLine(guiLeft - 60, guiLeft + xSize + 120, offset, 0xFFFFFFFF); for(int k = 0; k < options.size(); k++){ - int id = options.get(options.size() - 1 - k); + GL11.glPushMatrix(); + int id = options.get(k); DialogOption option = dialog.options.get(id); - int y = scaledResolution.getScaledHeight() - (k + 2) * ClientProxy.Font.height() + optionOffsetY + (-1 - k) * optionSpaceY; + int y = offset + (k + 1) * ClientProxy.Font.height(); + offset += optionSpaceY; + if(selected == k){ drawString(fontRendererObj, ">", guiLeft - 60, y, 0xe0e0e0); } - drawString(fontRendererObj, NoppesStringUtils.formatText(option.title, player, npc), guiLeft - 30 + optionSpaceX * (options.size() - 1 - k), y, option.optionColor); - } + if (optionImage != null && !optionImage.texture.equals("")) { + int originalColor = optionImage.color; + if(selected == k){ + optionImage.color = selectedImageColor; + } + GL11.glPushMatrix(); + GL11.glTranslatef(guiLeft - 30 + optionSpaceX * k, y, 0.0F); + optionImage.onRender(mc); + optionImage.color = originalColor; + GL11.glPopMatrix(); + } + + drawString(fontRendererObj, NoppesStringUtils.formatText(option.title, player, npc), guiLeft - 30 + optionSpaceX * k, y, option.optionColor); + GL11.glPopMatrix(); + } } private void drawDialogString(String text, int left, int color, int count, boolean mainDialogText){ - int height = count - totalRows; - int midScreen = (int) (scaledResolution.getScaledHeight() * 0.75F); - int y = (height * ClientProxy.Font.height()) + midScreen + scrollY; - if (y < midScreen - dialogHeight || y > midScreen - ClientProxy.Font.height()) { + int lineOffset = (currentBlock < lineBlocks.size() ? lineBlocks.get(currentBlock).lines.size() : lineBlocks.get(lineBlocks.size()-1).lines.size()) - currentLine; + int height = count - totalRows + lineOffset; + int screenPos = optionStart; + int y = (height * ClientProxy.Font.height()) + screenPos + scrollY; + if (y < screenPos - dialogHeight || y > screenPos - ClientProxy.Font.height()) { return; } @@ -422,7 +473,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if(dialog.showWheel) optionId = selected; else if(!options.isEmpty()) - optionId = options.get(options.size() - 1 - selected); + optionId = options.get(selected); NoppesUtilPlayer.sendData(EnumPlayerPacket.Dialog, dialog.id, optionId); if(dialog == null || !dialog.hasOtherOptions() || options.isEmpty()){ closed(); From 671899f21524f0fdde83cf988a1dd365d1fb2d0b Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Mon, 6 Jun 2022 03:06:09 -0500 Subject: [PATCH 20/40] Added curly bracket pauses to gradual dialog text. --- .../client/gui/player/GuiDialogImage.java | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 src/main/java/noppes/npcs/client/gui/player/GuiDialogImage.java diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogImage.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogImage.java new file mode 100644 index 000000000..4ac3b5360 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogImage.java @@ -0,0 +1,124 @@ +package noppes.npcs.client.gui.player; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.ITextureObject; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.ImageDownloadAlt; +import noppes.npcs.client.renderer.ImageBufferDownloadAlt; +import noppes.npcs.scripted.gui.ScriptGuiTexturedRect; +import noppes.npcs.scripted.interfaces.gui.ICustomGuiComponent; +import org.lwjgl.opengl.GL11; + +public class GuiDialogImage extends Gui { + GuiDialogInteract parent; + String texture; + ResourceLocation location; + int id; + int x; + int y; + int width; + int height; + int textureX; + int textureY; + float scale; + + int color; + float alpha; + float rotation; + + public GuiDialogImage(int id, String texture, int x, int y, int width, int height) { + this(id, texture, x, y, width, height, 0, 0); + } + + public GuiDialogImage(int id, String texture, int x, int y, int width, int height, int textureX, int textureY) { + this.color = 0xFFFFFF; + this.alpha = 1.0F; + this.scale = 1.0F; + this.id = id; + this.texture = texture; + this.location = new ResourceLocation(texture); + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.textureX = textureX; + this.textureY = textureY; + + if(texture.startsWith("https://")){ + TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); + ITextureObject object = new ImageDownloadAlt(null, texture, new ResourceLocation("customnpcs:textures/gui/invisible.png"), new ImageBufferDownloadAlt(true,false)); + texturemanager.loadTexture(this.location, object); + } + } + + public void setParent(GuiDialogInteract parent) { + this.parent = parent; + } + + public int getID() { + return this.id; + } + + public void onRender(Minecraft mc) { + try { + mc.getTextureManager().bindTexture(this.location); + } catch (Exception ignored) { return; } + + GL11.glPushMatrix(); + float red = (color >> 16 & 255) / 255f; + float green = (color >> 8 & 255) / 255f; + float blue = (color & 255) / 255f; + GL11.glColor4f(red,green,blue,this.alpha); + + GL11.glRotatef(this.rotation,0.0F,0.0F,1.0F); + GL11.glScalef(this.scale, this.scale, this.scale); + + int p_73729_1_ = (int) (this.x/(this.scale)); + int p_73729_2_ = (int) (this.y/(this.scale)); + int p_73729_3_ = this.textureX; + int p_73729_4_ = this.textureY; + int p_73729_5_ = (int)(this.width); + int p_73729_6_ = (int)(this.height); + + float f = 0.00390625F; + float f1 = 0.00390625F; + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.setColorOpaque_F(1, 1, 1); + tessellator.setColorRGBA_F(red, green, blue, alpha); + tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + p_73729_6_), (double)this.zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1)); + tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + p_73729_6_), (double)this.zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1)); + tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + 0), (double)this.zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + 0) * f1)); + tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + 0), (double)this.zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + 0) * f1)); + tessellator.draw(); + GL11.glPopMatrix(); + } + + public ICustomGuiComponent toComponent() { + ScriptGuiTexturedRect component = new ScriptGuiTexturedRect(this.id, this.location.toString(), this.x, this.y, this.width, this.height, this.textureX, this.textureY); + component.setScale(this.scale); + component.setColor(color); + component.setAlpha(alpha); + component.setRotation(rotation); + return component; + } + + public static GuiDialogImage fromComponent(ScriptGuiTexturedRect component) { + GuiDialogImage rect; + if (component.getTextureX() >= 0 && component.getTextureY() >= 0) { + rect = new GuiDialogImage(component.getID(), component.getTexture(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight(), component.getTextureX(), component.getTextureY()); + } else { + rect = new GuiDialogImage(component.getID(), component.getTexture(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight()); + } + + rect.scale = component.getScale(); + rect.color = component.getColor(); + rect.alpha = component.getAlpha(); + rect.rotation = component.getRotation(); + + return rect; + } +} From b70b51fab1926c66424318debdb86f359987424c Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Mon, 6 Jun 2022 03:08:04 -0500 Subject: [PATCH 21/40] Added curly bracket pauses to gradual dialog text. --- .../client/gui/player/GuiDialogInteract.java | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index 29bac54f0..5b16bc514 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -59,6 +59,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose private boolean isGrabbed = false; private int textSoundTime = 0; + private int textPauseTime = 0; /* * * DIALOG VARIABLES * @@ -90,7 +91,8 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose appendDialog(dialog); ySize = 238; - textImage = new GuiDialogImage(0, "customnpcs:textures/gui/extrasmallbg.png", 0,0, 176, 71); + //textImage = new GuiDialogImage(0, "customnpcs:textures/gui/largebg.png", 0,0, 176, 71); + //textImage.scale = 2; optionImage = new GuiDialogImage(0, "customnpcs:textures/gui/info.png", 0,0, 256, 256); wheel = this.getResource("wheel.png"); @@ -248,9 +250,44 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if (currentLine < block.lines.size()) { IChatComponent line = block.lines.get(currentLine); try { - if (textSpeed > 10 || gradualTextTime%(11 - textSpeed) == 0) { + if (textPauseTime > 0) { + textPauseTime--; + } else if (textSpeed > 10 || gradualTextTime%(11 - textSpeed) == 0) { int addChar = textSpeed > 10 ? textSpeed - 9 : 1; - gradualText += line.getFormattedText().substring(gradualText.length(), gradualText.length() + addChar); + String addText = line.getFormattedText().substring(gradualText.length(), gradualText.length() + addChar); + + if (addText.matches("^(\\{(\\d*)})(.*)")) { + StringBuilder numStr = new StringBuilder(); + int numLength; + for (numLength = 1; numLength < addText.length(); numLength++) { + if (addText.charAt(numLength) == '}') + break; + + numStr.append(addText.charAt(numLength)); + } + textPauseTime = Integer.parseInt(numStr.toString()); + addText = line.getFormattedText().substring(gradualText.length(), gradualText.length() + numLength + 1); + } else if (addText.matches("(.+)\\{(\\d*)(.*)")) { + StringBuilder str = new StringBuilder(); + for (char c : addText.toCharArray()) { + if (c == '{') + break; + str.append(c); + } + + addText = str.toString(); + } else if (addText.matches("(\\{(\\d*))$") || addText.equals("{")) { + do { + if (addText.length() == gradualText.length() + addText.length() + 1) + break; + + addText += line.getFormattedText().substring(gradualText.length() + addText.length(), gradualText.length() + addText.length() + 1); + } while (addText.matches("(.*)(\\{(\\d*))$")); + + textPauseTime = Integer.parseInt(addText.replace("{","").replace("}","")); + } + + gradualText += addText; if (textSoundTime % 5 == 0) { Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation(textSound), textPitch)); } @@ -404,6 +441,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose offsetY = titleOffsetY; } + text = text.replaceAll("\\{(\\d*)}",""); drawString(fontRendererObj, text, guiLeft + left + offsetX, y + offsetY, color); } From 50471dbfacd4e03cafd8349243e8d74a35681d62 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Mon, 6 Jun 2022 14:17:39 -0500 Subject: [PATCH 22/40] Added curly bracket pauses to instant dialog text. --- .../client/gui/player/GuiDialogInteract.java | 77 +++++++++++++++---- 1 file changed, 64 insertions(+), 13 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index 5b16bc514..df5c95e16 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -49,6 +49,10 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose private int gradualTextTime = 0; private int optionStart = 0; + private int instantBlockPos = 0; + private int instantLinePos = 0; + private int prevPausePos = -1; + private static int textSpeed = 10; private static boolean textSoundEnabled = true; @@ -65,7 +69,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose * DIALOG VARIABLES * * */ - private int renderDialogType = 1; //0 - Instant (classic), 1 - Gradual + private boolean renderGradual = false; private boolean showPreviousBlocks = true; private int dialogWidth = 300; @@ -183,7 +187,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose GL11.glPushMatrix(); GL11.glTranslatef(0.0F, 0.5f, 100.065F); - if (renderDialogType == 1) { + if (renderGradual) { drawString(fontRendererObj, "Text Speed: " + textSpeed, 10, 10, 0xFFFFFF); drawString(fontRendererObj, "Text Sound: " + (textSoundEnabled ? "On" : "Off"), 10, 20, 0xFFFFFF); } @@ -210,14 +214,57 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose GL11.glPopMatrix(); } - if (renderDialogType == 0) { + if (!renderGradual) { int count = 0; - for (TextBlockClient block : lineBlocks) { + blockLoop: + for (int b = 0; b < lineBlocks.size(); b++) { + TextBlockClient block = lineBlocks.get(b); + int size = ClientProxy.Font.width(block.getName() + " "); drawDialogString(block.getName() + " ", -4 - size, block.color, count, false); - for (IChatComponent line : block.lines) { - drawDialogString(line.getFormattedText(), 0, block.color, count, true); + for (int l = 0; l < block.lines.size(); l++) { + IChatComponent line = block.lines.get(l); + String drawText = line.getFormattedText(); + + if (b >= instantBlockPos && l >= instantLinePos) { + if (drawText.matches("(.*)(\\{(\\d+)})(.*)")) { + if (textPauseTime > 0) { + drawText = drawText.substring(0, prevPausePos); + drawDialogString(drawText, 0, block.color, count, true); + textPauseTime--; + break blockLoop; + } + + String strInt = ""; + for (int c = 0; c < drawText.length(); c++) { + if (drawText.substring(c).matches("^(\\{(\\d+)})(.*)") && c > prevPausePos) { + prevPausePos = c; + strInt += drawText.charAt(++c); + } else if (c > prevPausePos && !strInt.isEmpty()) { + if (drawText.charAt(c) == '}') + break; + + strInt += drawText.charAt(c); + } + } + + if (!strInt.isEmpty()) { + drawText = drawText.substring(0, prevPausePos); + + drawDialogString(drawText, 0, block.color, count, true); + + instantBlockPos = b; + instantLinePos = l; + textPauseTime = Integer.parseInt(strInt); + break blockLoop; + } + } else { + prevPausePos = -1; + } + } + + drawDialogString(drawText, 0, block.color, count, true); count++; } count++; @@ -256,7 +303,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose int addChar = textSpeed > 10 ? textSpeed - 9 : 1; String addText = line.getFormattedText().substring(gradualText.length(), gradualText.length() + addChar); - if (addText.matches("^(\\{(\\d*)})(.*)")) { + if (addText.matches("^(\\{(\\d+)})(.*)")) { StringBuilder numStr = new StringBuilder(); int numLength; for (numLength = 1; numLength < addText.length(); numLength++) { @@ -267,7 +314,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose } textPauseTime = Integer.parseInt(numStr.toString()); addText = line.getFormattedText().substring(gradualText.length(), gradualText.length() + numLength + 1); - } else if (addText.matches("(.+)\\{(\\d*)(.*)")) { + } else if (addText.matches("(.+)\\{(\\d+)(.*)")) { StringBuilder str = new StringBuilder(); for (char c : addText.toCharArray()) { if (c == '{') @@ -276,13 +323,13 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose } addText = str.toString(); - } else if (addText.matches("(\\{(\\d*))$") || addText.equals("{")) { + } else if (addText.matches("(\\{(\\d+))$") || addText.equals("{")) { do { if (addText.length() == gradualText.length() + addText.length() + 1) break; addText += line.getFormattedText().substring(gradualText.length() + addText.length(), gradualText.length() + addText.length() + 1); - } while (addText.matches("(.*)(\\{(\\d*))$")); + } while (addText.matches("(.*)(\\{(\\d+))$")); textPauseTime = Integer.parseInt(addText.replace("{","").replace("}","")); } @@ -424,7 +471,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose } private void drawDialogString(String text, int left, int color, int count, boolean mainDialogText){ - int lineOffset = (currentBlock < lineBlocks.size() ? lineBlocks.get(currentBlock).lines.size() : lineBlocks.get(lineBlocks.size()-1).lines.size()) - currentLine; + int lineOffset = renderGradual ? (currentBlock < lineBlocks.size() ? lineBlocks.get(currentBlock).lines.size() : lineBlocks.get(lineBlocks.size()-1).lines.size()) - currentLine : 0; int height = count - totalRows + lineOffset; int screenPos = optionStart; int y = (height * ClientProxy.Font.height()) + screenPos + scrollY; @@ -441,7 +488,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose offsetY = titleOffsetY; } - text = text.replaceAll("\\{(\\d*)}",""); + text = text.replaceAll("\\{(\\d+)}",""); drawString(fontRendererObj, text, guiLeft + left + offsetX, y + offsetY, color); } @@ -533,8 +580,12 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose currentBlock = lineBlocks.size()-1; currentLine = 0; gradualTextTime = 0; + + instantBlockPos = lineBlocks.size()-1; + instantLinePos = 0; calculateRowHeight(); - + textPauseTime = 0; + NoppesUtil.clickSound(); } From f3177f6fd9bff44630231dcf87b6cae9fa627bcf Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Wed, 8 Jun 2022 13:46:41 -0500 Subject: [PATCH 23/40] Fixed ImageDownloadAlt console spam. --- src/main/java/noppes/npcs/client/ImageDownloadAlt.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/noppes/npcs/client/ImageDownloadAlt.java b/src/main/java/noppes/npcs/client/ImageDownloadAlt.java index 88338c744..470a13647 100644 --- a/src/main/java/noppes/npcs/client/ImageDownloadAlt.java +++ b/src/main/java/noppes/npcs/client/ImageDownloadAlt.java @@ -4,6 +4,7 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.net.HttpURLConnection; +import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.atomic.AtomicInteger; @@ -160,6 +161,8 @@ public class ImageDownloadAlt extends SimpleTexture ImageDownloadAlt.this.setBufferedImage(bufferedimage); } + catch (MalformedURLException ignored) { + } catch (Exception exception) { ImageDownloadAlt.logger.error("Couldn\'t download http texture", exception); From deffb781675618e2611fb36d69f40793f39c3430 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Wed, 8 Jun 2022 16:51:28 -0500 Subject: [PATCH 24/40] Fixed render spam on overlays when checking for armor rendering. --- src/main/java/noppes/npcs/client/ClientEventHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/client/ClientEventHandler.java b/src/main/java/noppes/npcs/client/ClientEventHandler.java index 42ba6e216..c9112d4e3 100644 --- a/src/main/java/noppes/npcs/client/ClientEventHandler.java +++ b/src/main/java/noppes/npcs/client/ClientEventHandler.java @@ -44,7 +44,7 @@ public class ClientEventHandler { @SubscribeEvent public void cancelSpecials(RenderPlayerEvent.SetArmorModel event) { - if (event.renderer instanceof RenderCNPCPlayer && event.stack.getItem() instanceof ItemArmor) + if (event.renderer instanceof RenderCNPCPlayer && event.stack != null && event.stack.getItem() instanceof ItemArmor) event.setCanceled(true); } From 60794592d18a347909f5c1ba69ada636c1d9ada6 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Thu, 9 Jun 2022 02:03:14 -0500 Subject: [PATCH 25/40] Completely remade visual dialog options, added images and many other attributes to dialogs. --- .../npcs/client/gui/SubGuiNpcDialogExtra.java | 18 - .../client/gui/SubGuiNpcVisualOptions.java | 434 ++++++++++++++++++ .../components/CustomOverlayTexturedRect.java | 2 +- .../gui/global/GuiNPCManageDialogs.java | 27 +- .../client/gui/player/GuiDialogImage.java | 94 ++-- .../client/gui/player/GuiDialogInteract.java | 107 +++-- .../noppes/npcs/controllers/data/Dialog.java | 83 ++++ .../npcs/controllers/data/DialogImage.java | 65 +++ .../assets/customnpcs/lang/en_US.lang | 32 ++ 9 files changed, 739 insertions(+), 123 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/SubGuiNpcVisualOptions.java create mode 100644 src/main/java/noppes/npcs/controllers/data/DialogImage.java diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogExtra.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogExtra.java index 5fc09c88c..39e55df76 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogExtra.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogExtra.java @@ -39,19 +39,10 @@ public class SubGuiNpcDialogExtra extends SubGuiInterface implements ISubGuiList addButton(new GuiNpcButton(10, guiLeft + 120, y += 22, 50, 20, "selectServer.edit")); addLabel(new GuiNpcLabel(10, "advMode.command", guiLeft + 4, y + 5)); - - addButton(new GuiNpcButtonYesNo(11, guiLeft + 120, y += 22, dialog.hideNPC)); - addLabel(new GuiNpcLabel(11, "dialog.hideNPC", guiLeft + 4, y + 5)); - - addButton(new GuiNpcButtonYesNo(12, guiLeft + 120, y += 22, dialog.showWheel)); - addLabel(new GuiNpcLabel(12, "dialog.showWheel", guiLeft + 4, y + 5)); addButton(new GuiNpcButtonYesNo(15, guiLeft + 120, y += 22, dialog.disableEsc)); addLabel(new GuiNpcLabel(15, "dialog.disableEsc", guiLeft + 4, y + 5)); - addButton(new GuiNpcButtonYesNo(16, guiLeft + 120, y += 22, dialog.darkenScreen)); - addLabel(new GuiNpcLabel(16, "Darken Screen", guiLeft + 4, y + 5)); - this.addButton(new GuiNpcButton(66, guiLeft + 82, guiTop + 192,98, 20, "gui.done")); } @@ -63,18 +54,9 @@ public class SubGuiNpcDialogExtra extends SubGuiInterface implements ISubGuiList if(button.id == 10){ setSubGui(new SubGuiNpcCommand(dialog.command)); } - if(button.id == 11){ - dialog.hideNPC = button.getValue() == 1; - } - if(button.id == 12){ - dialog.showWheel = button.getValue() == 1; - } if(button.id == 15){ dialog.disableEsc = button.getValue() == 1; } - if(button.id == 16){ - dialog.darkenScreen = button.getValue() == 1; - } if(button.id == 13){ setSubGui(new SubGuiMailmanSendSetup(dialog.mail, getParent())); } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcVisualOptions.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcVisualOptions.java new file mode 100644 index 000000000..61d79ad58 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcVisualOptions.java @@ -0,0 +1,434 @@ +package noppes.npcs.client.gui; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.client.Client; +import noppes.npcs.client.NoppesUtil; +import noppes.npcs.client.gui.global.GuiNPCManageDialogs; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.controllers.data.Dialog; +import noppes.npcs.controllers.data.DialogImage; + +import java.util.ArrayList; +import java.util.Collections; + +public class SubGuiNpcVisualOptions extends SubGuiInterface implements ISubGuiListener, ITextfieldListener, ICustomScrollListener { + private final Dialog dialog; + public GuiScreen parent2; + + private GuiMenuTopButton[] topButtons; + private int activeMenu = 1; + + private GuiCustomScroll imageScroll; + private int selected = -1; + private int lastColorClicked = -1; + + public SubGuiNpcVisualOptions(Dialog dialog, GuiScreen parent) { + this.parent2 = parent; + this.dialog = dialog; + setBackground("menubg.png"); + xSize = 256; + ySize = 216; + closeOnEsc = true; + } + + public void initGui() + { + super.initGui(); + int y = guiTop - 10; + + GuiMenuTopButton close = new GuiMenuTopButton(0,guiLeft + xSize - 22, guiTop - 17, "X"); + GuiMenuTopButton general = new GuiMenuTopButton(1, guiLeft + 4, guiTop - 17, "General"); + GuiMenuTopButton spacing = new GuiMenuTopButton(2, general.xPosition + general.getWidth(), guiTop - 17, "Spacing"); + GuiMenuTopButton images = new GuiMenuTopButton(3, spacing.xPosition + spacing.getWidth(), guiTop - 17, "Images"); + topButtons = new GuiMenuTopButton[]{general,images,spacing,close}; + for(GuiMenuTopButton button : topButtons) + button.active = button.id == activeMenu; + + if (activeMenu == 1) { + addButton(new GuiNpcButtonYesNo(10, guiLeft + 120, y += 22, dialog.hideNPC)); + addLabel(new GuiNpcLabel(10, "dialog.hideNPC", guiLeft + 4, y + 5)); + + addButton(new GuiNpcButtonYesNo(11, guiLeft + 120, y += 22, dialog.showWheel)); + addLabel(new GuiNpcLabel(11, "dialog.showWheel", guiLeft + 4, y + 5)); + + addButton(new GuiNpcButtonYesNo(12, guiLeft + 120, y += 22, dialog.darkenScreen)); + addLabel(new GuiNpcLabel(12, "dialog.darkenScreen", guiLeft + 4, y + 5)); + + addButton(new GuiNpcButton(13, guiLeft + 120, y += 22, 50, 20, new String[]{"dialog.instant", "dialog.gradual"}, dialog.renderGradual ? 1 : 0)); + addLabel(new GuiNpcLabel(13, "dialog.renderType", guiLeft + 4, y + 5)); + + addButton(new GuiNpcButton(14, guiLeft + 120, y += 22, 50, 20, new String[]{"display.show", "display.hide"}, dialog.showPreviousBlocks ? 1 : 0)); + addLabel(new GuiNpcLabel(14, "dialog.previousBlocks", guiLeft + 4, y + 5)); + + if (dialog.renderGradual) { + addTextField(new GuiNpcTextField(15, this, guiLeft + 80, y += 22, 165, 20, dialog.textSound)); + addLabel(new GuiNpcLabel(15, "dialog.textSound", guiLeft + 4, y + 5)); + + addTextField(new GuiNpcTextField(16, this, guiLeft + 125, y += 22, 40, 20, String.valueOf(dialog.textPitch))); + addLabel(new GuiNpcLabel(16, "dialog.textPitch", guiLeft + 4, y + 5)); + getTextField(16).floatsOnly = true; + } + } else if (activeMenu == 2) { + addTextField(new GuiNpcTextField(10, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.textWidth))); + addTextField(new GuiNpcTextField(11, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.textHeight))); + addLabel(new GuiNpcLabel(12, "gui.widthHeight", guiLeft + 4, y + 5)); + + addTextField(new GuiNpcTextField(12, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.textOffsetX))); + addTextField(new GuiNpcTextField(13, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.textOffsetY))); + addLabel(new GuiNpcLabel(15, "dialog.textOffset", guiLeft + 4, y + 5)); + + addTextField(new GuiNpcTextField(14, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.titleOffsetX))); + addTextField(new GuiNpcTextField(15, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.titleOffsetY))); + addLabel(new GuiNpcLabel(18, "dialog.titleOffset", guiLeft + 4, y + 5)); + + addTextField(new GuiNpcTextField(16, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.optionOffsetX))); + addTextField(new GuiNpcTextField(17, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.optionOffsetY))); + addLabel(new GuiNpcLabel(21, "dialog.optionOffset", guiLeft + 4, y + 5)); + + addTextField(new GuiNpcTextField(18, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.optionSpaceX))); + addTextField(new GuiNpcTextField(19, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.optionSpaceY))); + addLabel(new GuiNpcLabel(24, "dialog.optionSpacing", guiLeft + 4, y + 5)); + + for (int i = 10; i < 20; i++) { + GuiNpcTextField textField = this.getTextField(i); + textField.integersOnly = true; + } + } else if (activeMenu == 3) { + if (imageScroll == null) { + imageScroll = new GuiCustomScroll(this, 0, false); + imageScroll.guiLeft = guiLeft + xSize; + imageScroll.guiTop = guiTop + 25; + imageScroll.setSize(50, this.ySize - 25); + } + + updateScrollData(); + + this.addButton(new GuiNpcButton(1, guiLeft + xSize + 2, guiTop + 5, 20, 20, "+")); + if (getSelectedImage() != null) { + DialogImage dialogImage = getSelectedImage(); + this.addButton(new GuiNpcButton(2, guiLeft + xSize + 24, guiTop + 5, 20, 20, "-")); + + addTextField(new GuiNpcTextField(10, this, guiLeft + 17, y += 25, 30, 20, String.valueOf(dialogImage.id))); + addTextField(new GuiNpcTextField(11, this, guiLeft + 92, y, 150, 20, dialogImage.texture)); + addLabel(new GuiNpcLabel(10, "gui.id", guiLeft + 4, y + 5)); + addLabel(new GuiNpcLabel(11, "display.texture", guiLeft + 50, y + 5)); + getTextField(10).integersOnly = true; + + addTextField(new GuiNpcTextField(12, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialogImage.x))); + addTextField(new GuiNpcTextField(13, this, guiLeft + 165, y, 40, 20, String.valueOf(dialogImage.y))); + addLabel(new GuiNpcLabel(12, "gui.position", guiLeft + 4, y + 5)); + getTextField(12).integersOnly = true; + getTextField(13).integersOnly = true; + + addTextField(new GuiNpcTextField(14, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialogImage.width))); + addTextField(new GuiNpcTextField(15, this, guiLeft + 165, y, 40, 20, String.valueOf(dialogImage.height))); + addLabel(new GuiNpcLabel(13, "gui.widthHeight", guiLeft + 4, y + 5)); + getTextField(14).integersOnly = true; + getTextField(15).integersOnly = true; + + addTextField(new GuiNpcTextField(16, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialogImage.textureX))); + addTextField(new GuiNpcTextField(17, this, guiLeft + 165, y, 40, 20, String.valueOf(dialogImage.textureY))); + addLabel(new GuiNpcLabel(14, "dialog.textureOffset", guiLeft + 4, y + 5)); + getTextField(16).integersOnly = true; + getTextField(17).integersOnly = true; + + String color = Integer.toHexString(dialogImage.color); + while(color.length() < 6) + color = 0 + color; + addButton(new GuiNpcButton(18, guiLeft + 35, y += 25, 60, 20, color)); + addLabel(new GuiNpcLabel(15, "gui.color", guiLeft + 4, y + 5)); + getButton(18).setTextColor(dialogImage.color); + + String selectedColor = Integer.toHexString(dialogImage.selectedColor); + while(selectedColor.length() < 6) + selectedColor = 0 + selectedColor; + addButton(new GuiNpcButton(19, guiLeft + 180, y, 60, 20, selectedColor)); + addLabel(new GuiNpcLabel(16, "dialog.selectedColor", guiLeft + 100, y + 5)); + getButton(19).setTextColor(dialogImage.selectedColor); + + addTextField(new GuiNpcTextField(20, this, guiLeft + 35, y += 25, 60, 20, String.valueOf(dialogImage.scale))); + addTextField(new GuiNpcTextField(21, this, guiLeft + 180, y, 60, 20, String.valueOf(dialogImage.alpha))); + addLabel(new GuiNpcLabel(17, "model.scale", guiLeft + 4, y + 5)); + addLabel(new GuiNpcLabel(18, "display.alpha", guiLeft + 100, y + 5)); + getTextField(20).floatsOnly = true; + getTextField(21).floatsOnly = true; + + addTextField(new GuiNpcTextField(22, this, guiLeft + 47, y += 25, 60, 20, String.valueOf(dialogImage.rotation))); + addLabel(new GuiNpcLabel(19, "movement.rotation", guiLeft + 4, y + 5)); + getTextField(22).floatsOnly = true; + + addButton(new GuiNpcButton(23, guiLeft + 180, y, 60, 20, new String[]{"gui.default","gui.text","gui.option"}, dialogImage.imageType)); + addLabel(new GuiNpcLabel(20, "dialog.imageType", guiLeft + 115, y + 5)); + + if (dialogImage.imageType == 0) { + addButton(new GuiNpcButton(24, guiLeft + 180, y += 25, 60, 20, + new String[]{"display.topLeft", "display.topCenter", "display.topRight", + "display.left", "display.center", "display.right", + "display.botLeft", "display.botCenter", "display.botRight"}, + dialogImage.alignment)); + addLabel(new GuiNpcLabel(21, "display.alignment", guiLeft + 115, y + 5)); + } + } + } + } + + public void updateScrollData() { + ArrayList ids = new ArrayList<>(dialog.dialogImages.keySet()); + Collections.sort(ids); + ArrayList strings = new ArrayList<>(); + for (int i : ids) { + strings.add(String.valueOf(i)); + } + imageScroll.setList(strings); + addScroll(imageScroll); + } + + public void mouseClicked(int i, int j, int k) { + super.mouseClicked(i,j,k); + if (k == 0) { + Minecraft mc = Minecraft.getMinecraft(); + for (GuiMenuTopButton button : topButtons) { + if (button.mousePressed(mc, i, j)) { + topButtonPressed(button); + } + } + } + } + + private void topButtonPressed(GuiMenuTopButton button) { + Minecraft mc = Minecraft.getMinecraft(); + NoppesUtil.clickSound(); + + int id = button.id; + if(id == 0){ + close(); + if(parent2 != null) + NoppesUtil.openGUI(player, parent2); + return; + } + save(); + + activeMenu = id; + initGui(); + } + + @Override + protected void actionPerformed(GuiButton guibutton){ + GuiNpcButton button = (GuiNpcButton) guibutton; + + if (activeMenu == 1) { + if (button.id == 10) { + dialog.hideNPC = button.getValue() == 1; + } + if (button.id == 11) { + dialog.showWheel = button.getValue() == 1; + } + if (button.id == 12) { + dialog.darkenScreen = button.getValue() == 1; + } + if (button.id == 13) { + dialog.renderGradual = button.getValue() == 1; + } + if (button.id == 14) { + dialog.showPreviousBlocks = button.getValue() == 1; + } + } + + if (activeMenu == 3) { + if (button.id == 1) { + int addId = 0; + if (selected != -1 && imageScroll.getSelected() != null) { + DialogImage selectedImage = dialog.dialogImages.get(Integer.valueOf(imageScroll.getSelected())); + ArrayList keys = new ArrayList<>(dialog.dialogImages.keySet()); + int keyIndex = keys.indexOf(selectedImage.id); + do { + addId = keys.get(keyIndex) + 1; + keyIndex++; + } while (dialog.dialogImages.containsKey(addId)); + } else if (dialog.dialogImages.size() > 0) { + addId = (Integer) dialog.dialogImages.keySet().toArray()[dialog.dialogImages.size() - 1] + 1; + } + + dialog.dialogImages.put(addId, new DialogImage(addId)); + updateScrollData(); + selected = imageScroll.getList().indexOf(String.valueOf(addId)); + } + if (button.id == 2) { + if (imageScroll.getSelected() != null) { + dialog.dialogImages.remove(Integer.valueOf(imageScroll.getSelected())); + selected--; + } + } + if (button.id == 18) { + if (getSelectedImage() != null) { + DialogImage dialogImage = getSelectedImage(); + setSubGui(new SubGuiColorSelector(dialogImage.color)); + lastColorClicked = 0; + } + } + if (button.id == 19) { + if (getSelectedImage() != null) { + DialogImage dialogImage = getSelectedImage(); + setSubGui(new SubGuiColorSelector(dialogImage.selectedColor)); + lastColorClicked = 1; + } + } + if (button.id == 23) { + if (getSelectedImage() != null) { + DialogImage dialogImage = getSelectedImage(); + dialogImage.imageType = button.getValue(); + } + } + if (button.id == 24) { + if (getSelectedImage() != null) { + DialogImage dialogImage = getSelectedImage(); + dialogImage.alignment = button.getValue(); + } + } + } + + initGui(); + } + + @Override + public void drawScreen(int i, int j, float f){ + super.drawScreen(i,j,f); + for(GuiMenuTopButton button: topButtons) + button.drawButton(mc, i, j); + } + + + @Override + public void subGuiClosed(SubGuiInterface subgui){ + if (getSelectedImage() != null) { + DialogImage dialogImage = getSelectedImage(); + if (lastColorClicked == 0) { + dialogImage.color = ((SubGuiColorSelector) subgui).color; + } else if (lastColorClicked == 1) { + dialogImage.selectedColor = ((SubGuiColorSelector) subgui).color; + } + initGui(); + } + save(); + } + + public void save() { + GuiNpcTextField.unfocus(); + if(dialog.id >= 0) + Client.sendData(EnumPacketServer.DialogSave, ((GuiNPCManageDialogs)parent2).category.id, dialog.writeToNBT(new NBTTagCompound())); + } + + private DialogImage getSelectedImage() { + if (selected > -1) { + return dialog.dialogImages.get((dialog.dialogImages.keySet().toArray(new Integer[0]))[selected]); + } else { + return null; + } + } + + @Override + public void unFocused(GuiNpcTextField textfield) { + if (activeMenu == 1) { + if (textfield.id == 15) { + dialog.textSound = textfield.getText(); + } + if (textfield.id == 16) { + dialog.textPitch = textfield.getFloat(); + } + } + + if (activeMenu == 2) { + int i = textfield.getInteger(); + + if (textfield.id == 10) { + dialog.textWidth = i; + } + if (textfield.id == 11) { + dialog.textHeight = i; + } + + if (textfield.id == 12) { + dialog.textOffsetX = i; + } + if (textfield.id == 13) { + dialog.textOffsetY = i; + } + + if (textfield.id == 14) { + dialog.titleOffsetX = i; + } + if (textfield.id == 15) { + dialog.titleOffsetY = i; + } + + if (textfield.id == 14) { + dialog.optionOffsetX = i; + } + if (textfield.id == 15) { + dialog.optionOffsetY = i; + } + + if (textfield.id == 14) { + dialog.optionSpaceX = i; + } + if (textfield.id == 15) { + dialog.optionSpaceY = i; + } + } + + if (activeMenu == 3) { + DialogImage dialogImage = getSelectedImage(); + if (dialogImage == null) { + return; + } + + if (textfield.id == 10) { + dialogImage.id = textfield.getInteger(); + } + if (textfield.id == 11) { + dialogImage.texture = textfield.getText(); + } + if (textfield.id == 12) { + dialogImage.x = textfield.getInteger(); + } + if (textfield.id == 13) { + dialogImage.y = textfield.getInteger(); + } + if (textfield.id == 14) { + dialogImage.width = textfield.getInteger(); + } + if (textfield.id == 15) { + dialogImage.height = textfield.getInteger(); + } + if (textfield.id == 16) { + dialogImage.textureX = textfield.getInteger(); + } + if (textfield.id == 17) { + dialogImage.textureY = textfield.getInteger(); + } + if (textfield.id == 20) { + dialogImage.scale = textfield.getFloat(); + } + if (textfield.id == 21) { + dialogImage.alpha = textfield.getFloat(); + } + if (textfield.id == 22) { + dialogImage.rotation = textfield.getFloat(); + } + } + + save(); + } + + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { + if(guiCustomScroll.id == 0 && imageScroll != null) { + selected = guiCustomScroll.selected; + initGui(); + } + } +} diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java index b1402308f..2525b1d42 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java @@ -71,7 +71,7 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent float green = (color >> 8 & 255) / 255f; float blue = (color & 255) / 255f; - GL11.glTranslatef(this.alignment%3*((float)(OverlayCustom.scaledWidth)/2), (float) (Math.floor((float)(alignment/3))*((float)(OverlayCustom.scaledHeight)/2)),0.0F);//alignment%3 * width/2 Math.floor(alignment/3) * height/2 + GL11.glTranslatef(this.alignment%3*((float)(OverlayCustom.scaledWidth)/2), (float) (Math.floor((float)(alignment/3))*((float)(OverlayCustom.scaledHeight)/2)),0.0F); GL11.glScalef(this.scale, this.scale, this.scale); diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java index 77d9025b8..ff3455fd8 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java @@ -7,12 +7,7 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.Client; import noppes.npcs.client.NoppesUtil; -import noppes.npcs.client.gui.GuiNpcSoundSelection; -import noppes.npcs.client.gui.SubGuiNpcAvailability; -import noppes.npcs.client.gui.SubGuiNpcDialogExtra; -import noppes.npcs.client.gui.SubGuiNpcDialogOptions; -import noppes.npcs.client.gui.SubGuiNpcFactionOptions; -import noppes.npcs.client.gui.SubGuiNpcTextArea; +import noppes.npcs.client.gui.*; import noppes.npcs.client.gui.util.GuiCustomScroll; import noppes.npcs.client.gui.util.ICustomScrollListener; import noppes.npcs.client.gui.util.GuiNPCInterface2; @@ -35,7 +30,7 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData private GuiCustomScroll scroll; private HashMap data = new HashMap(); private Dialog dialog = new Dialog(); - private DialogCategory category = new DialogCategory(); + public DialogCategory category = new DialogCategory(); private boolean categorySelection = true; private GuiNpcSoundSelection gui; @@ -88,14 +83,17 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData addLabel(new GuiNpcLabel(6, "dialog.options", guiLeft + 4, guiTop + 93)); addButton(new GuiNpcButton(6, guiLeft + 120, guiTop + 89, 50, 20, "selectServer.edit")); - addButton(new GuiNpcButton(7, guiLeft + 4, guiTop + 114, 144, 20, "availability.selectquest")); - addButton(new GuiNpcButton(8, guiLeft + 150, guiTop + 114, 20, 20, "X")); + addLabel(new GuiNpcLabel(11, "dialog.visualOption", guiLeft + 4, guiTop + 115)); + addButton(new GuiNpcButton(11, guiLeft + 120, guiTop + 110, 50, 20, "selectServer.edit")); - addLabel(new GuiNpcLabel(9, "gui.selectSound", guiLeft + 4, guiTop + 138)); - addTextField(new GuiNpcTextField(2, this, fontRendererObj, guiLeft + 4, guiTop + 148, 144, 20, dialog.sound)); - addButton(new GuiNpcButton(9, guiLeft + 150, guiTop + 148, 60, 20, "mco.template.button.select")); + addButton(new GuiNpcButton(7, guiLeft + 4, guiTop + 134, 144, 20, "availability.selectquest")); + addButton(new GuiNpcButton(8, guiLeft + 150, guiTop + 134, 20, 20, "X")); - addButton(new GuiNpcButton(10, guiLeft + 4, guiTop + 172, 120, 20, "gui.showmore")); + addLabel(new GuiNpcLabel(9, "gui.selectSound", guiLeft + 4, guiTop + 158)); + addTextField(new GuiNpcTextField(2, this, fontRendererObj, guiLeft + 4, guiTop + 168, 144, 20, dialog.sound)); + addButton(new GuiNpcButton(9, guiLeft + 150, guiTop + 168, 60, 20, "mco.template.button.select")); + + addButton(new GuiNpcButton(10, guiLeft + 4, guiTop + 192, 120, 20, "gui.showmore")); } private void categoryGuiInit() { @@ -183,6 +181,9 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData if(id == 10){ setSubGui(new SubGuiNpcDialogExtra(dialog, this)); } + if(id == 11){ + setSubGui(new SubGuiNpcVisualOptions(dialog, this)); + } } @Override diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogImage.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogImage.java index 4ac3b5360..f001c5139 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogImage.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogImage.java @@ -7,45 +7,53 @@ import net.minecraft.client.renderer.texture.ITextureObject; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.util.ResourceLocation; import noppes.npcs.client.ImageDownloadAlt; +import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.renderer.ImageBufferDownloadAlt; -import noppes.npcs.scripted.gui.ScriptGuiTexturedRect; -import noppes.npcs.scripted.interfaces.gui.ICustomGuiComponent; +import noppes.npcs.controllers.data.DialogImage; import org.lwjgl.opengl.GL11; public class GuiDialogImage extends Gui { GuiDialogInteract parent; - String texture; ResourceLocation location; - int id; - int x; - int y; - int width; - int height; - int textureX; - int textureY; - float scale; - int color; - float alpha; - float rotation; + public int id; + public String texture; + public int x; + public int y; + public int width; + public int height; + public int textureX; + public int textureY; + public float scale; - public GuiDialogImage(int id, String texture, int x, int y, int width, int height) { - this(id, texture, x, y, width, height, 0, 0); - } + public int color; + public int selectedColor; + public float alpha; + public float rotation; - public GuiDialogImage(int id, String texture, int x, int y, int width, int height, int textureX, int textureY) { - this.color = 0xFFFFFF; - this.alpha = 1.0F; - this.scale = 1.0F; - this.id = id; - this.texture = texture; - this.location = new ResourceLocation(texture); - this.x = x; - this.y = y; - this.width = width; - this.height = height; - this.textureX = textureX; - this.textureY = textureY; + public int imageType = 0; //0 - Default, 1 - Text, 2 - Option + public int alignment = 0; + + public GuiDialogImage(DialogImage dialogImage) { + this.location = new ResourceLocation(dialogImage.texture); + + this.id = dialogImage.id; + this.texture = dialogImage.texture; + this.x = dialogImage.x; + this.y = dialogImage.y; + this.width = dialogImage.width; + this.height = dialogImage.height; + this.textureX = dialogImage.textureX; + this.textureY = dialogImage.textureY; + this.scale = dialogImage.scale; + + this.color = dialogImage.color; + this.selectedColor = dialogImage.selectedColor; + this.rotation = dialogImage.rotation; + this.alpha = dialogImage.alpha; + + this.imageType = dialogImage.imageType; + this.alignment = dialogImage.alignment; if(texture.startsWith("https://")){ TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); @@ -73,6 +81,7 @@ public class GuiDialogImage extends Gui { float blue = (color & 255) / 255f; GL11.glColor4f(red,green,blue,this.alpha); + GL11.glTranslatef(this.alignment%3*((float)(OverlayCustom.scaledWidth)/2), (float) (Math.floor((float)(alignment/3))*((float)(OverlayCustom.scaledHeight)/2)),0.0F); GL11.glRotatef(this.rotation,0.0F,0.0F,1.0F); GL11.glScalef(this.scale, this.scale, this.scale); @@ -96,29 +105,4 @@ public class GuiDialogImage extends Gui { tessellator.draw(); GL11.glPopMatrix(); } - - public ICustomGuiComponent toComponent() { - ScriptGuiTexturedRect component = new ScriptGuiTexturedRect(this.id, this.location.toString(), this.x, this.y, this.width, this.height, this.textureX, this.textureY); - component.setScale(this.scale); - component.setColor(color); - component.setAlpha(alpha); - component.setRotation(rotation); - return component; - } - - public static GuiDialogImage fromComponent(ScriptGuiTexturedRect component) { - GuiDialogImage rect; - if (component.getTextureX() >= 0 && component.getTextureY() >= 0) { - rect = new GuiDialogImage(component.getID(), component.getTexture(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight(), component.getTextureX(), component.getTextureY()); - } else { - rect = new GuiDialogImage(component.getID(), component.getTexture(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight()); - } - - rect.scale = component.getScale(); - rect.color = component.getColor(); - rect.alpha = component.getAlpha(); - rect.rotation = component.getRotation(); - - return rect; - } } diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index df5c95e16..1d960ceea 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -25,6 +25,7 @@ import noppes.npcs.client.gui.util.IGuiClose; import noppes.npcs.constants.EnumOptionType; import noppes.npcs.constants.EnumPlayerPacket; import noppes.npcs.controllers.data.Dialog; +import noppes.npcs.controllers.data.DialogImage; import noppes.npcs.controllers.data.DialogOption; import noppes.npcs.entity.EntityNPCInterface; @@ -69,25 +70,22 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose * DIALOG VARIABLES * * */ - private boolean renderGradual = false; - private boolean showPreviousBlocks = true; + private final boolean renderGradual; + private final boolean showPreviousBlocks; - private int dialogWidth = 300; - private int dialogHeight = 400; + private final String textSound; + private final float textPitch; - private int textOffsetX, textOffsetY; - private int titleOffsetX, titleOffsetY; + private final int textWidth; + private final int textHeight; - private int optionSpaceX, optionSpaceY; - private int optionOffsetX, optionOffsetY; + private final int textOffsetX, textOffsetY; + private final int titleOffsetX, titleOffsetY; - private String textSound = "minecraft:random.wood_click"; - private float textPitch = 1.0F; + private final int optionSpaceX, optionSpaceY; + private final int optionOffsetX, optionOffsetY; - private HashMap dialogImages = new HashMap<>(); - private GuiDialogImage textImage; - private GuiDialogImage optionImage; - private int selectedImageColor = 0xFFFF00; + private final ArrayList dialogImages = new ArrayList<>(); public GuiDialogInteract(EntityNPCInterface npc, Dialog dialog){ super(npc); @@ -95,9 +93,24 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose appendDialog(dialog); ySize = 238; - //textImage = new GuiDialogImage(0, "customnpcs:textures/gui/largebg.png", 0,0, 176, 71); - //textImage.scale = 2; - optionImage = new GuiDialogImage(0, "customnpcs:textures/gui/info.png", 0,0, 256, 256); + this.renderGradual = dialog.renderGradual; + this.showPreviousBlocks = dialog.showPreviousBlocks; + this.textSound = dialog.textSound; + this.textPitch = dialog.textPitch; + this.textWidth = dialog.textWidth; + this.textHeight = dialog.textHeight; + this.textOffsetX = dialog.textOffsetX; + this.textOffsetY = dialog.textOffsetY; + this.titleOffsetX = dialog.titleOffsetX; + this.titleOffsetY = dialog.titleOffsetY; + this.optionSpaceX = dialog.optionSpaceX; + this.optionSpaceY = dialog.optionSpaceY; + this.optionOffsetX = dialog.optionOffsetX; + this.optionOffsetY = dialog.optionOffsetY; + + for (DialogImage dialogImage : dialog.dialogImages.values()) { + dialogImages.add(new GuiDialogImage(dialogImage)); + } wheel = this.getResource("wheel.png"); indicator = this.getResource("indicator.png"); @@ -192,7 +205,10 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose drawString(fontRendererObj, "Text Sound: " + (textSoundEnabled ? "On" : "Off"), 10, 20, 0xFFFFFF); } - for (GuiDialogImage image : dialogImages.values()) { + for (GuiDialogImage image : dialogImages) { + if (image.imageType != 0) + continue; + GL11.glEnable(GL11.GL_BLEND); OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); GL11.glDisable(GL11.GL_ALPHA_TEST); @@ -207,12 +223,23 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose GL11.glPushMatrix(); GL11.glTranslatef(textOffsetX, 0.0F, 0.0F); - if (textImage != null && !textImage.texture.isEmpty()) { - GL11.glPushMatrix(); - GL11.glTranslatef(guiLeft + textOffsetX, optionStart + textOffsetY - textImage.height * textImage.scale, 0.0F); - textImage.onRender(mc); - GL11.glPopMatrix(); + GL11.glPushMatrix(); + for (GuiDialogImage image : dialogImages) { + if (image.imageType != 1) + continue; + + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); + GL11.glDisable(GL11.GL_ALPHA_TEST); + + GL11.glTranslatef(guiLeft + textOffsetX, optionStart + textOffsetY - image.height * image.scale, 0.0F); + image.onRender(mc); + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_ALPHA_TEST); } + GL11.glPopMatrix(); if (!renderGradual) { int count = 0; @@ -453,17 +480,25 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if(selected == k){ drawString(fontRendererObj, ">", guiLeft - 60, y, 0xe0e0e0); } - if (optionImage != null && !optionImage.texture.equals("")) { - int originalColor = optionImage.color; - if(selected == k){ - optionImage.color = selectedImageColor; - } - GL11.glPushMatrix(); - GL11.glTranslatef(guiLeft - 30 + optionSpaceX * k, y, 0.0F); - optionImage.onRender(mc); - optionImage.color = originalColor; - GL11.glPopMatrix(); + + GL11.glPushMatrix(); + for (GuiDialogImage image : dialogImages) { + if (image.imageType != 2) + continue; + + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); + GL11.glDisable(GL11.GL_ALPHA_TEST); + + GL11.glTranslatef(guiLeft - 30 + optionSpaceX * k, y, 0.0F); + image.color = selected == k ? image.selectedColor : image.color; + image.onRender(mc); + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_ALPHA_TEST); } + GL11.glPopMatrix(); drawString(fontRendererObj, NoppesStringUtils.formatText(option.title, player, npc), guiLeft - 30 + optionSpaceX * k, y, option.optionColor); GL11.glPopMatrix(); @@ -475,7 +510,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose int height = count - totalRows + lineOffset; int screenPos = optionStart; int y = (height * ClientProxy.Font.height()) + screenPos + scrollY; - if (y < screenPos - dialogHeight || y > screenPos - ClientProxy.Font.height()) { + if (y < screenPos - textHeight || y > screenPos - ClientProxy.Font.height()) { return; } @@ -575,7 +610,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if (!showPreviousBlocks) { lineBlocks.clear(); } - lineBlocks.add(new TextBlockClient(player.getDisplayName(), option.title, dialogWidth, option.optionColor, player, npc)); + lineBlocks.add(new TextBlockClient(player.getDisplayName(), option.title, textWidth, option.optionColor, player, npc)); gradualText = ""; currentBlock = lineBlocks.size()-1; currentLine = 0; @@ -611,7 +646,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if (!showPreviousBlocks) { lineBlocks.clear(); } - lineBlocks.add(new TextBlockClient(npc, dialog.text, dialogWidth, 0xe0e0e0, player, npc)); + lineBlocks.add(new TextBlockClient(npc, dialog.text, textWidth, 0xe0e0e0, player, npc)); gradualText = ""; currentBlock = lineBlocks.size()-1; currentLine = 0; diff --git a/src/main/java/noppes/npcs/controllers/data/Dialog.java b/src/main/java/noppes/npcs/controllers/data/Dialog.java index 76ef188c1..4373f1ccb 100644 --- a/src/main/java/noppes/npcs/controllers/data/Dialog.java +++ b/src/main/java/noppes/npcs/controllers/data/Dialog.java @@ -33,6 +33,28 @@ public class Dialog implements ICompatibilty, IDialog { public boolean showWheel = false; public boolean disableEsc = false; public boolean darkenScreen = true; + + + /** + * Add these variables to NBT reads & writes + */ + + public boolean renderGradual = false; + public boolean showPreviousBlocks = true; + + public String textSound = "minecraft:random.wood_click"; + public float textPitch = 1.0F; + + public int textWidth = 300; + public int textHeight = 400; + + public int textOffsetX, textOffsetY; + public int titleOffsetX, titleOffsetY; + + public int optionSpaceX, optionSpaceY; + public int optionOffsetX, optionOffsetY; + + public HashMap dialogImages = new HashMap<>(); public boolean hasDialogs(EntityPlayer player) { for(DialogOption option: options.values()) @@ -82,6 +104,44 @@ public class Dialog implements ICompatibilty, IDialog { } this.options = newoptions; + NBTTagList images = compound.getTagList("Images", 10); + HashMap newImages = new HashMap<>(); + for(int i = 0; i < images.tagCount(); i++){ + NBTTagCompound imageCompound = images.getCompoundTagAt(i); + int id = imageCompound.getInteger("ID"); + DialogImage image = new DialogImage(id); + image.readNBT(imageCompound); + newImages.put(id, image); + } + this.dialogImages = newImages; + + renderGradual = compound.getBoolean("RenderGradual"); + showPreviousBlocks = compound.getBoolean("PreviousBlocks"); + textSound = compound.getString("TextSound"); + textPitch = compound.getFloat("TextPitch"); + textWidth = compound.getInteger("TextWidth"); + textHeight = compound.getInteger("TextHeight"); + textOffsetX = compound.getInteger("TextOffsetX"); + textOffsetY = compound.getInteger("TextOffsetY"); + titleOffsetX = compound.getInteger("TitleOffsetX"); + titleOffsetY = compound.getInteger("TitleOffsetY"); + optionOffsetX = compound.getInteger("OptionOffsetX"); + optionOffsetY = compound.getInteger("OptionOffsetY"); + optionSpaceX = compound.getInteger("OptionSpaceX"); + optionSpaceY = compound.getInteger("OptionSpaceY"); + + if (!compound.hasKey("PreviousBlocks")) + showPreviousBlocks = true; + if (!compound.hasKey("TextSound")) + textSound = "minecraft:random.wood_click"; + if (!compound.hasKey("TextPitch")) + textPitch = 1.0F; + if (!compound.hasKey("TextWidth")) + textWidth = 300; + if (!compound.hasKey("TextHeight")) + textWidth = 400; + + availability.readFromNBT(compound); factionOptions.readFromNBT(compound); } @@ -119,6 +179,29 @@ public class Dialog implements ICompatibilty, IDialog { availability.writeToNBT(compound); factionOptions.writeToNBT(compound); compound.setInteger("ModRev", version); + + compound.setBoolean("RenderGradual", renderGradual); + compound.setBoolean("PreviousBlocks", showPreviousBlocks); + compound.setString("TextSound", textSound); + compound.setFloat("TextPitch", textPitch); + compound.setInteger("TextWidth", textWidth); + compound.setInteger("TextHeight", textHeight); + compound.setInteger("TextOffsetX", textOffsetX); + compound.setInteger("TextOffsetY", textOffsetY); + compound.setInteger("TitleOffsetX", titleOffsetX); + compound.setInteger("TitleOffsetY", titleOffsetY); + compound.setInteger("OptionOffsetX", optionOffsetX); + compound.setInteger("OptionOffsetY", optionOffsetY); + compound.setInteger("OptionSpaceX", optionSpaceX); + compound.setInteger("OptionSpaceY", optionSpaceY); + + NBTTagList images = new NBTTagList(); + for (DialogImage dialogImage : dialogImages.values()) { + NBTTagCompound imageCompound = dialogImage.writeToNBT(new NBTTagCompound()); + images.appendTag(imageCompound); + } + compound.setTag("Images",images); + return compound; } diff --git a/src/main/java/noppes/npcs/controllers/data/DialogImage.java b/src/main/java/noppes/npcs/controllers/data/DialogImage.java new file mode 100644 index 000000000..e02957fda --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/data/DialogImage.java @@ -0,0 +1,65 @@ +package noppes.npcs.controllers.data; + +import net.minecraft.nbt.NBTTagCompound; + +public class DialogImage { + public int id; + public String texture = ""; + public int x = 0; + public int y = 0; + public int width = 0; + public int height = 0; + public int textureX = 0; + public int textureY = 0; + public float scale = 1.0F; + + public int color = 0xFFFFFF; + public int selectedColor = 0xFFFFFF; + public float alpha = 1.0F; + public float rotation = 0; + + public int imageType = 1; //0 - Default, 1 - Text, 2 - Option + public int alignment = 0; + + public DialogImage(int id) { + this.id = id; + } + + public NBTTagCompound writeToNBT(NBTTagCompound compound) { + compound.setInteger("ID", id); + compound.setString("Texture", texture); + compound.setInteger("PosX", x); + compound.setInteger("PosY", y); + compound.setInteger("Width", width); + compound.setInteger("Height", height); + compound.setInteger("TextureX", textureX); + compound.setInteger("TextureY", textureY); + compound.setFloat("Scale", scale); + compound.setInteger("Color", color); + compound.setInteger("SelectedColor", selectedColor); + compound.setFloat("Alpha", alpha); + compound.setFloat("Rotation", rotation); + compound.setInteger("ImageType", imageType); + compound.setInteger("Alignment", alignment); + + return compound; + } + + public void readNBT(NBTTagCompound compound) { + id = compound.getInteger("ID"); + texture = compound.getString("Texture"); + x = compound.getInteger("PosX"); + y = compound.getInteger("PosY"); + width = compound.getInteger("Width"); + height = compound.getInteger("Height"); + textureX = compound.getInteger("TextureX"); + textureY = compound.getInteger("TextureY"); + scale = compound.getFloat("Scale"); + color = compound.getInteger("Color"); + selectedColor = compound.getInteger("SelectedColor"); + alpha = compound.getFloat("Alpha"); + rotation = compound.getFloat("Rotation"); + imageType = compound.getInteger("ImageType"); + alignment = compound.getInteger("Alignment"); + } +} diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 2891b0adc..aa52c7982 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -116,6 +116,12 @@ gui.update=Update gui.editor=Editor gui.playernearby=Player nearby gui.forum=Forum +gui.id=ID +gui.widthHeight=Width & Height +gui.position=Position +gui.option=Option +gui.text=Text +gui.default=Default remote.title=Nearby NPCs remote.reset=Reset @@ -175,6 +181,17 @@ display.bossbar=BossBar display.squareTexture=Square Texture display.url=Url display.urlSix=Url64 +display.alpha=Alpha +display.alignment=Alignment +display.topLeft=Top Left +display.topCenter=Top Center +display.topRight=Top Right +display.left=Left +display.center=Center +display.right=Right +display.botLeft=Bottom Left +display.botCenter=Bottom Center +display.botRight=Bottom Right inv.minExp=Min Exp inv.maxExp=Max Exp @@ -416,6 +433,21 @@ dialog.commandoptionplayer=Use "@dp" to target the player using this dialog.hideNPC=Hide NPC dialog.showWheel=Show Dialog Wheel dialog.disableEsc=Disable Esc +dialog.visualOption=Visual Options +dialog.darkenScreen=Darken Screen +dialog.renderType=Render Type +dialog.instant=Instant +dialog.gradual=Gradual +dialog.previousBlocks=Previous Text Blocks +dialog.textOffset=Text Offset +dialog.titleOffset=Title Offset +dialog.optionOffset=Option Offset +dialog.optionSpacing=Option Spacing +dialog.textSound=Text Sound +dialog.textPitch=Text Pitch +dialog.textureOffset=Texture Offset +dialog.selectedColor=Selected Color +dialog.imageType=Image Type quest.quest=Quest quest.quests=Quests From 799d54a4dcdf60e040052ef5b34e9e59bcbbd15d Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Thu, 9 Jun 2022 02:16:25 -0500 Subject: [PATCH 26/40] Fixed a couple of client-side dialog data errors. --- .../noppes/npcs/client/gui/player/GuiDialogInteract.java | 6 +++--- src/main/java/noppes/npcs/controllers/data/Dialog.java | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index 1d960ceea..5d28bed15 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -90,9 +90,6 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose public GuiDialogInteract(EntityNPCInterface npc, Dialog dialog){ super(npc); this.dialog = dialog; - appendDialog(dialog); - ySize = 238; - this.renderGradual = dialog.renderGradual; this.showPreviousBlocks = dialog.showPreviousBlocks; this.textSound = dialog.textSound; @@ -108,6 +105,9 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose this.optionOffsetX = dialog.optionOffsetX; this.optionOffsetY = dialog.optionOffsetY; + appendDialog(dialog); + ySize = 238; + for (DialogImage dialogImage : dialog.dialogImages.values()) { dialogImages.add(new GuiDialogImage(dialogImage)); } diff --git a/src/main/java/noppes/npcs/controllers/data/Dialog.java b/src/main/java/noppes/npcs/controllers/data/Dialog.java index 4373f1ccb..51375ed9a 100644 --- a/src/main/java/noppes/npcs/controllers/data/Dialog.java +++ b/src/main/java/noppes/npcs/controllers/data/Dialog.java @@ -139,8 +139,7 @@ public class Dialog implements ICompatibilty, IDialog { if (!compound.hasKey("TextWidth")) textWidth = 300; if (!compound.hasKey("TextHeight")) - textWidth = 400; - + textHeight = 400; availability.readFromNBT(compound); factionOptions.readFromNBT(compound); From c99a4f8439494c067e9b6dcfbb6446211adcd6e2 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Thu, 9 Jun 2022 02:30:01 -0500 Subject: [PATCH 27/40] Server-side dialog data fixes. --- ...ptions.java => SubGuiNpcDialogVisual.java} | 4 ++-- .../gui/global/GuiNPCManageDialogs.java | 2 +- .../noppes/npcs/controllers/data/Dialog.java | 20 ++++++++++++++----- 3 files changed, 18 insertions(+), 8 deletions(-) rename src/main/java/noppes/npcs/client/gui/{SubGuiNpcVisualOptions.java => SubGuiNpcDialogVisual.java} (98%) diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcVisualOptions.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java similarity index 98% rename from src/main/java/noppes/npcs/client/gui/SubGuiNpcVisualOptions.java rename to src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java index 61d79ad58..3cd041fc1 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcVisualOptions.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java @@ -15,7 +15,7 @@ import noppes.npcs.controllers.data.DialogImage; import java.util.ArrayList; import java.util.Collections; -public class SubGuiNpcVisualOptions extends SubGuiInterface implements ISubGuiListener, ITextfieldListener, ICustomScrollListener { +public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiListener, ITextfieldListener, ICustomScrollListener { private final Dialog dialog; public GuiScreen parent2; @@ -26,7 +26,7 @@ public class SubGuiNpcVisualOptions extends SubGuiInterface implements ISubGuiLi private int selected = -1; private int lastColorClicked = -1; - public SubGuiNpcVisualOptions(Dialog dialog, GuiScreen parent) { + public SubGuiNpcDialogVisual(Dialog dialog, GuiScreen parent) { this.parent2 = parent; this.dialog = dialog; setBackground("menubg.png"); diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java index ff3455fd8..5252bc50a 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java @@ -182,7 +182,7 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData setSubGui(new SubGuiNpcDialogExtra(dialog, this)); } if(id == 11){ - setSubGui(new SubGuiNpcVisualOptions(dialog, this)); + setSubGui(new SubGuiNpcDialogVisual(dialog, this)); } } diff --git a/src/main/java/noppes/npcs/controllers/data/Dialog.java b/src/main/java/noppes/npcs/controllers/data/Dialog.java index 51375ed9a..438250582 100644 --- a/src/main/java/noppes/npcs/controllers/data/Dialog.java +++ b/src/main/java/noppes/npcs/controllers/data/Dialog.java @@ -34,11 +34,6 @@ public class Dialog implements ICompatibilty, IDialog { public boolean disableEsc = false; public boolean darkenScreen = true; - - /** - * Add these variables to NBT reads & writes - */ - public boolean renderGradual = false; public boolean showPreviousBlocks = true; @@ -229,6 +224,21 @@ public class Dialog implements ICompatibilty, IDialog { dialog.showWheel = showWheel; dialog.disableEsc = disableEsc; dialog.darkenScreen = darkenScreen; + dialog.renderGradual = renderGradual; + dialog.showPreviousBlocks = showPreviousBlocks; + dialog.textSound = textSound; + dialog.textPitch = textPitch; + dialog.textWidth = textWidth; + dialog.textHeight = textHeight; + dialog.textOffsetX = textOffsetX; + dialog.textOffsetY = textOffsetY; + dialog.titleOffsetX = titleOffsetX; + dialog.titleOffsetY = titleOffsetY; + dialog.optionOffsetX = optionOffsetX; + dialog.optionOffsetY = optionOffsetY; + dialog.optionSpaceX = optionSpaceX; + dialog.optionSpaceY = optionSpaceY; + dialog.dialogImages = dialogImages; for(int slot : options.keySet()){ DialogOption option = options.get(slot); From 84b77440230f6113417ad06fb9e5895a605dcee5 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Thu, 9 Jun 2022 03:41:27 -0500 Subject: [PATCH 28/40] Dialog GUI fixes. --- .../client/gui/SubGuiNpcDialogVisual.java | 50 ++++-- .../client/gui/player/GuiDialogInteract.java | 157 +++++++----------- 2 files changed, 100 insertions(+), 107 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java index 3cd041fc1..62db61c21 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java @@ -61,7 +61,7 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis addButton(new GuiNpcButton(13, guiLeft + 120, y += 22, 50, 20, new String[]{"dialog.instant", "dialog.gradual"}, dialog.renderGradual ? 1 : 0)); addLabel(new GuiNpcLabel(13, "dialog.renderType", guiLeft + 4, y + 5)); - addButton(new GuiNpcButton(14, guiLeft + 120, y += 22, 50, 20, new String[]{"display.show", "display.hide"}, dialog.showPreviousBlocks ? 1 : 0)); + addButton(new GuiNpcButton(14, guiLeft + 120, y += 22, 50, 20, new String[]{"display.hide", "display.show"}, dialog.showPreviousBlocks ? 1 : 0)); addLabel(new GuiNpcLabel(14, "dialog.previousBlocks", guiLeft + 4, y + 5)); if (dialog.renderGradual) { @@ -76,22 +76,42 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis addTextField(new GuiNpcTextField(10, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.textWidth))); addTextField(new GuiNpcTextField(11, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.textHeight))); addLabel(new GuiNpcLabel(12, "gui.widthHeight", guiLeft + 4, y + 5)); + getTextField(10).integersOnly = true; + getTextField(10).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(11).integersOnly = true; + getTextField(11).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); addTextField(new GuiNpcTextField(12, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.textOffsetX))); addTextField(new GuiNpcTextField(13, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.textOffsetY))); addLabel(new GuiNpcLabel(15, "dialog.textOffset", guiLeft + 4, y + 5)); + getTextField(12).integersOnly = true; + getTextField(12).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(13).integersOnly = true; + getTextField(13).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); addTextField(new GuiNpcTextField(14, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.titleOffsetX))); addTextField(new GuiNpcTextField(15, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.titleOffsetY))); addLabel(new GuiNpcLabel(18, "dialog.titleOffset", guiLeft + 4, y + 5)); + getTextField(14).integersOnly = true; + getTextField(14).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(15).integersOnly = true; + getTextField(15).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); addTextField(new GuiNpcTextField(16, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.optionOffsetX))); addTextField(new GuiNpcTextField(17, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.optionOffsetY))); addLabel(new GuiNpcLabel(21, "dialog.optionOffset", guiLeft + 4, y + 5)); + getTextField(16).integersOnly = true; + getTextField(16).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(17).integersOnly = true; + getTextField(17).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); addTextField(new GuiNpcTextField(18, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.optionSpaceX))); addTextField(new GuiNpcTextField(19, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.optionSpaceY))); addLabel(new GuiNpcLabel(24, "dialog.optionSpacing", guiLeft + 4, y + 5)); + getTextField(18).integersOnly = true; + getTextField(18).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(19).integersOnly = true; + getTextField(19).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); for (int i = 10; i < 20; i++) { GuiNpcTextField textField = this.getTextField(i); @@ -122,19 +142,25 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis addTextField(new GuiNpcTextField(13, this, guiLeft + 165, y, 40, 20, String.valueOf(dialogImage.y))); addLabel(new GuiNpcLabel(12, "gui.position", guiLeft + 4, y + 5)); getTextField(12).integersOnly = true; + getTextField(12).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); getTextField(13).integersOnly = true; + getTextField(13).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); addTextField(new GuiNpcTextField(14, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialogImage.width))); addTextField(new GuiNpcTextField(15, this, guiLeft + 165, y, 40, 20, String.valueOf(dialogImage.height))); addLabel(new GuiNpcLabel(13, "gui.widthHeight", guiLeft + 4, y + 5)); getTextField(14).integersOnly = true; + getTextField(14).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); getTextField(15).integersOnly = true; + getTextField(15).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); addTextField(new GuiNpcTextField(16, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialogImage.textureX))); addTextField(new GuiNpcTextField(17, this, guiLeft + 165, y, 40, 20, String.valueOf(dialogImage.textureY))); addLabel(new GuiNpcLabel(14, "dialog.textureOffset", guiLeft + 4, y + 5)); getTextField(16).integersOnly = true; + getTextField(16).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); getTextField(17).integersOnly = true; + getTextField(17).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); String color = Integer.toHexString(dialogImage.color); while(color.length() < 6) @@ -143,12 +169,14 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis addLabel(new GuiNpcLabel(15, "gui.color", guiLeft + 4, y + 5)); getButton(18).setTextColor(dialogImage.color); - String selectedColor = Integer.toHexString(dialogImage.selectedColor); - while(selectedColor.length() < 6) - selectedColor = 0 + selectedColor; - addButton(new GuiNpcButton(19, guiLeft + 180, y, 60, 20, selectedColor)); - addLabel(new GuiNpcLabel(16, "dialog.selectedColor", guiLeft + 100, y + 5)); - getButton(19).setTextColor(dialogImage.selectedColor); + if (dialogImage.imageType == 2) { + String selectedColor = Integer.toHexString(dialogImage.selectedColor); + while (selectedColor.length() < 6) + selectedColor = 0 + selectedColor; + addButton(new GuiNpcButton(19, guiLeft + 180, y, 60, 20, selectedColor)); + addLabel(new GuiNpcLabel(16, "dialog.selectedColor", guiLeft + 100, y + 5)); + getButton(19).setTextColor(dialogImage.selectedColor); + } addTextField(new GuiNpcTextField(20, this, guiLeft + 35, y += 25, 60, 20, String.valueOf(dialogImage.scale))); addTextField(new GuiNpcTextField(21, this, guiLeft + 180, y, 60, 20, String.valueOf(dialogImage.alpha))); @@ -365,17 +393,17 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis dialog.titleOffsetY = i; } - if (textfield.id == 14) { + if (textfield.id == 16) { dialog.optionOffsetX = i; } - if (textfield.id == 15) { + if (textfield.id == 17) { dialog.optionOffsetY = i; } - if (textfield.id == 14) { + if (textfield.id == 18) { dialog.optionSpaceX = i; } - if (textfield.id == 15) { + if (textfield.id == 19) { dialog.optionSpaceY = i; } } diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index 5d28bed15..8a68dc873 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -61,63 +61,24 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose private ResourceLocation wheel; private ResourceLocation[] wheelparts; private ResourceLocation indicator; - + private boolean isGrabbed = false; private int textSoundTime = 0; private int textPauseTime = 0; - /* * - * DIALOG VARIABLES * - * */ - - private final boolean renderGradual; - private final boolean showPreviousBlocks; - - private final String textSound; - private final float textPitch; - - private final int textWidth; - private final int textHeight; - - private final int textOffsetX, textOffsetY; - private final int titleOffsetX, titleOffsetY; - - private final int optionSpaceX, optionSpaceY; - private final int optionOffsetX, optionOffsetY; - - private final ArrayList dialogImages = new ArrayList<>(); - public GuiDialogInteract(EntityNPCInterface npc, Dialog dialog){ super(npc); this.dialog = dialog; - this.renderGradual = dialog.renderGradual; - this.showPreviousBlocks = dialog.showPreviousBlocks; - this.textSound = dialog.textSound; - this.textPitch = dialog.textPitch; - this.textWidth = dialog.textWidth; - this.textHeight = dialog.textHeight; - this.textOffsetX = dialog.textOffsetX; - this.textOffsetY = dialog.textOffsetY; - this.titleOffsetX = dialog.titleOffsetX; - this.titleOffsetY = dialog.titleOffsetY; - this.optionSpaceX = dialog.optionSpaceX; - this.optionSpaceY = dialog.optionSpaceY; - this.optionOffsetX = dialog.optionOffsetX; - this.optionOffsetY = dialog.optionOffsetY; appendDialog(dialog); ySize = 238; - for (DialogImage dialogImage : dialog.dialogImages.values()) { - dialogImages.add(new GuiDialogImage(dialogImage)); - } - wheel = this.getResource("wheel.png"); indicator = this.getResource("indicator.png"); wheelparts = new ResourceLocation[]{getResource("wheel1.png"),getResource("wheel2.png"),getResource("wheel3.png"), getResource("wheel4.png"),getResource("wheel5.png"),getResource("wheel6.png")}; } - + public void initGui(){ super.initGui(); isGrabbed = false; @@ -127,9 +88,9 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose this.scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); this.drawDefaultBackground = dialog.darkenScreen; - optionStart = scaledResolution.getScaledHeight() - (options.size()) * (ClientProxy.Font.height() + optionSpaceY) - 20; + optionStart = scaledResolution.getScaledHeight() - (options.size()) * (ClientProxy.Font.height() + dialog.optionSpaceY) - 20; } - + public void grabMouse(boolean grab){ if(grab && !isGrabbed){ Minecraft.getMinecraft().mouseHelper.grabMouseCursor(); @@ -140,10 +101,10 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose isGrabbed = false; } } - + public void drawScreen(int i, int j, float f){ GL11.glColor4f(1, 1, 1, 1); - + if(!dialog.hideNPC){ float l = (guiLeft - 70); float i1 = (guiTop + ySize); @@ -174,7 +135,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose npc.prevRotationYawHead = npc.rotationYawHead = npc.rotationYaw; GL11.glTranslatef(0.0F, npc.yOffset, 0.0F); RenderManager.instance.playerViewY = 180F; - + try{ RenderManager.instance.renderEntityWithPosYaw(npc, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F); } @@ -200,12 +161,14 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose GL11.glPushMatrix(); GL11.glTranslatef(0.0F, 0.5f, 100.065F); - if (renderGradual) { + if (dialog.renderGradual) { drawString(fontRendererObj, "Text Speed: " + textSpeed, 10, 10, 0xFFFFFF); drawString(fontRendererObj, "Text Sound: " + (textSoundEnabled ? "On" : "Off"), 10, 20, 0xFFFFFF); } - for (GuiDialogImage image : dialogImages) { + for (DialogImage dialogImage : dialog.dialogImages.values()) { + GuiDialogImage image = new GuiDialogImage(dialogImage); + if (image.imageType != 0) continue; @@ -221,10 +184,9 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose } GL11.glPushMatrix(); - GL11.glTranslatef(textOffsetX, 0.0F, 0.0F); + for (DialogImage dialogImage : dialog.dialogImages.values()) { + GuiDialogImage image = new GuiDialogImage(dialogImage); - GL11.glPushMatrix(); - for (GuiDialogImage image : dialogImages) { if (image.imageType != 1) continue; @@ -232,7 +194,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); GL11.glDisable(GL11.GL_ALPHA_TEST); - GL11.glTranslatef(guiLeft + textOffsetX, optionStart + textOffsetY - image.height * image.scale, 0.0F); + GL11.glTranslatef(guiLeft + dialog.textOffsetX, optionStart + dialog.textOffsetY - image.height * image.scale, 0.0F); image.onRender(mc); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); @@ -241,7 +203,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose } GL11.glPopMatrix(); - if (!renderGradual) { + if (!dialog.renderGradual) { int count = 0; blockLoop: for (int b = 0; b < lineBlocks.size(); b++) { @@ -363,7 +325,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose gradualText += addText; if (textSoundTime % 5 == 0) { - Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation(textSound), textPitch)); + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation(dialog.textSound), dialog.textPitch)); } textSoundTime++; } @@ -388,33 +350,34 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose GL11.glPopMatrix(); GL11.glPushMatrix(); - if(!options.isEmpty()){ - if(!dialog.showWheel) + if (!options.isEmpty()) { + if (!dialog.showWheel) { + GL11.glTranslatef(dialog.optionOffsetX, dialog.optionOffsetY, 0); drawLinedOptions(j); - else + } else { drawWheel(); + } } GL11.glPopMatrix(); - GL11.glPopMatrix(); } private int selectedX = 0; private int selectedY = 0; private void drawWheel(){ - int yoffset = optionStart; + int yoffset = optionStart + dialog.optionOffsetY; GL11.glColor4f(1, 1, 1, 1); mc.renderEngine.bindTexture(wheel); - drawTexturedModalRect((width/2) - 31 + optionOffsetX, yoffset, 0, 0, 63, 40); - - selectedX += Mouse.getDX(); + drawTexturedModalRect((width/2) - 31 + dialog.optionOffsetX, yoffset, 0, 0, 63, 40); + + selectedX += Mouse.getDX(); selectedY += Mouse.getDY(); int limit = 80; - if(selectedX > limit + optionOffsetX) - selectedX = limit + optionOffsetX; - if(selectedX < -limit + optionOffsetX) - selectedX = -limit + optionOffsetX; - + if(selectedX > limit) + selectedX = limit; + if(selectedX < -limit) + selectedX = -limit; + if(selectedY > limit) selectedY = limit; if(selectedY < -limit) @@ -425,41 +388,41 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose selected++; if(selectedY > 54) selected--; - + if(selectedX < 0) selected += 3; mc.renderEngine.bindTexture(wheelparts[selected]); - drawTexturedModalRect((width/2) - 31 + optionOffsetX,yoffset, 0, 0, 85, 55); + drawTexturedModalRect((width/2) - 31 + dialog.optionOffsetX,yoffset, 0, 0, 85, 55); for(int slot:dialog.options.keySet()){ DialogOption option = dialog.options.get(slot); if(option == null || option.optionType == EnumOptionType.Disabled) continue; - int color = option.optionColor; + int color = option.optionColor; if(slot == (selected)) color = 0x838FD8; //drawString(fontRenderer, option.title, width/2 -50 ,yoffset+ 162 + slot * 13 , color); if(slot == 0) - drawString(fontRendererObj, option.title, width/2 + 13 + optionOffsetX,yoffset - 6 , color); + drawString(fontRendererObj, option.title, width/2 + 13 + dialog.optionOffsetX,yoffset - 6 , color); if(slot == 1) - drawString(fontRendererObj, option.title, width/2 + 33 + optionOffsetX,yoffset + 12 , color); + drawString(fontRendererObj, option.title, width/2 + 33 + dialog.optionOffsetX,yoffset + 12 , color); if(slot == 2) - drawString(fontRendererObj, option.title, width/2 + 27 + optionOffsetX,yoffset + 32 , color); + drawString(fontRendererObj, option.title, width/2 + 27 + dialog.optionOffsetX,yoffset + 32 , color); if(slot == 3) - drawString(fontRendererObj, option.title, width/2 - 13 + optionOffsetX - ClientProxy.Font.width(option.title),yoffset - 6 , color); + drawString(fontRendererObj, option.title, width/2 - 13 + dialog.optionOffsetX - ClientProxy.Font.width(option.title),yoffset - 6 , color); if(slot == 4) - drawString(fontRendererObj, option.title, width/2 - 33 + optionOffsetX - ClientProxy.Font.width(option.title),yoffset + 12 , color); + drawString(fontRendererObj, option.title, width/2 - 33 + dialog.optionOffsetX - ClientProxy.Font.width(option.title),yoffset + 12 , color); if(slot == 5) - drawString(fontRendererObj, option.title, width/2 - 27 + optionOffsetX - ClientProxy.Font.width(option.title),yoffset + 32 , color); - + drawString(fontRendererObj, option.title, width/2 - 27 + dialog.optionOffsetX - ClientProxy.Font.width(option.title),yoffset + 32 , color); + } mc.renderEngine.bindTexture(indicator); - drawTexturedModalRect(width/2 + selectedX/4 - 2,yoffset + 16 - selectedY/6, 0, 0, 8, 8); + drawTexturedModalRect(width/2 + selectedX/4 - 2 + dialog.optionOffsetX,yoffset + 16 - selectedY/6, 0, 0, 8, 8); } private void drawLinedOptions(int j){ int offset = optionStart; if(j >= offset){ - int selected = (j - offset - ClientProxy.Font.height() - optionOffsetY) / (ClientProxy.Font.height() + optionSpaceY); + int selected = (j - offset - ClientProxy.Font.height() - dialog.optionOffsetY) / (ClientProxy.Font.height() + dialog.optionSpaceY); if(selected < options.size()) this.selected = selected; } @@ -475,14 +438,16 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose int id = options.get(k); DialogOption option = dialog.options.get(id); int y = offset + (k + 1) * ClientProxy.Font.height(); - offset += optionSpaceY; + offset += dialog.optionSpaceY; if(selected == k){ drawString(fontRendererObj, ">", guiLeft - 60, y, 0xe0e0e0); } GL11.glPushMatrix(); - for (GuiDialogImage image : dialogImages) { + for (DialogImage dialogImage : dialog.dialogImages.values()) { + GuiDialogImage image = new GuiDialogImage(dialogImage); + if (image.imageType != 2) continue; @@ -490,7 +455,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); GL11.glDisable(GL11.GL_ALPHA_TEST); - GL11.glTranslatef(guiLeft - 30 + optionSpaceX * k, y, 0.0F); + GL11.glTranslatef(guiLeft - 30 + dialog.optionSpaceX * k, y, 0.0F); image.color = selected == k ? image.selectedColor : image.color; image.onRender(mc); @@ -500,27 +465,27 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose } GL11.glPopMatrix(); - drawString(fontRendererObj, NoppesStringUtils.formatText(option.title, player, npc), guiLeft - 30 + optionSpaceX * k, y, option.optionColor); + drawString(fontRendererObj, NoppesStringUtils.formatText(option.title, player, npc), guiLeft - 30 + dialog.optionSpaceX * k, y, option.optionColor); GL11.glPopMatrix(); } } private void drawDialogString(String text, int left, int color, int count, boolean mainDialogText){ - int lineOffset = renderGradual ? (currentBlock < lineBlocks.size() ? lineBlocks.get(currentBlock).lines.size() : lineBlocks.get(lineBlocks.size()-1).lines.size()) - currentLine : 0; + int lineOffset = dialog.renderGradual ? (currentBlock < lineBlocks.size() ? lineBlocks.get(currentBlock).lines.size() : lineBlocks.get(lineBlocks.size()-1).lines.size()) - currentLine : 0; int height = count - totalRows + lineOffset; int screenPos = optionStart; int y = (height * ClientProxy.Font.height()) + screenPos + scrollY; - if (y < screenPos - textHeight || y > screenPos - ClientProxy.Font.height()) { + if (y < screenPos - dialog.textHeight || y > screenPos - ClientProxy.Font.height()) { return; } int offsetX, offsetY; if (mainDialogText) { - offsetX = textOffsetX; - offsetY = textOffsetY; + offsetX = dialog.textOffsetX; + offsetY = dialog.textOffsetY; } else { - offsetX = titleOffsetX; - offsetY = titleOffsetY; + offsetX = dialog.titleOffsetX; + offsetY = dialog.titleOffsetY; } text = text.replaceAll("\\{(\\d+)}",""); @@ -607,10 +572,10 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose return; } - if (!showPreviousBlocks) { + if (!dialog.showPreviousBlocks) { lineBlocks.clear(); } - lineBlocks.add(new TextBlockClient(player.getDisplayName(), option.title, textWidth, option.optionColor, player, npc)); + lineBlocks.add(new TextBlockClient(player.getDisplayName(), option.title, dialog.textWidth, option.optionColor, player, npc)); gradualText = ""; currentBlock = lineBlocks.size()-1; currentLine = 0; @@ -622,15 +587,15 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose textPauseTime = 0; NoppesUtil.clickSound(); - + } private void closed(){ grabMouse(false); NoppesUtilPlayer.sendData(EnumPlayerPacket.CheckQuestCompletion); } - + public void save() { - + } public void appendDialog(Dialog dialog) { @@ -643,10 +608,10 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose MusicController.Instance.playSound(dialog.sound, (float)npc.posX, (float)npc.posY, (float)npc.posZ); } - if (!showPreviousBlocks) { + if (!dialog.showPreviousBlocks) { lineBlocks.clear(); } - lineBlocks.add(new TextBlockClient(npc, dialog.text, textWidth, 0xe0e0e0, player, npc)); + lineBlocks.add(new TextBlockClient(npc, dialog.text, dialog.textWidth, 0xe0e0e0, player, npc)); gradualText = ""; currentBlock = lineBlocks.size()-1; currentLine = 0; From 76106b1ea65fe70b4a3414c9973a4466dfd9fba7 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Thu, 9 Jun 2022 03:51:27 -0500 Subject: [PATCH 29/40] Added dialog option to show line above options. --- .../java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java | 6 ++++++ .../noppes/npcs/client/gui/player/GuiDialogInteract.java | 4 +++- src/main/java/noppes/npcs/controllers/data/Dialog.java | 6 ++++++ src/main/resources/assets/customnpcs/lang/en_US.lang | 1 + 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java index 62db61c21..7c2cacdb6 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java @@ -72,6 +72,9 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis addLabel(new GuiNpcLabel(16, "dialog.textPitch", guiLeft + 4, y + 5)); getTextField(16).floatsOnly = true; } + + addButton(new GuiNpcButton(17, guiLeft + 120, y += 22, 50, 20, new String[]{"display.hide", "display.show"}, dialog.showOptionLine ? 1 : 0)); + addLabel(new GuiNpcLabel(17, "dialog.optionLine", guiLeft + 4, y + 5)); } else if (activeMenu == 2) { addTextField(new GuiNpcTextField(10, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.textWidth))); addTextField(new GuiNpcTextField(11, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.textHeight))); @@ -264,6 +267,9 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis if (button.id == 14) { dialog.showPreviousBlocks = button.getValue() == 1; } + if (button.id == 17) { + dialog.showOptionLine = button.getValue() == 1; + } } if (activeMenu == 3) { diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index 8a68dc873..b85638f51 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -431,7 +431,9 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if(selected < 0) selected = 0; - drawHorizontalLine(guiLeft - 60, guiLeft + xSize + 120, offset, 0xFFFFFFFF); + if (dialog.showOptionLine) { + drawHorizontalLine(guiLeft - 60, guiLeft + xSize + 120, offset, 0xFFFFFFFF); + } for(int k = 0; k < options.size(); k++){ GL11.glPushMatrix(); diff --git a/src/main/java/noppes/npcs/controllers/data/Dialog.java b/src/main/java/noppes/npcs/controllers/data/Dialog.java index 438250582..ae753f1c2 100644 --- a/src/main/java/noppes/npcs/controllers/data/Dialog.java +++ b/src/main/java/noppes/npcs/controllers/data/Dialog.java @@ -33,6 +33,7 @@ public class Dialog implements ICompatibilty, IDialog { public boolean showWheel = false; public boolean disableEsc = false; public boolean darkenScreen = true; + public boolean showOptionLine = true; public boolean renderGradual = false; public boolean showPreviousBlocks = true; @@ -112,6 +113,7 @@ public class Dialog implements ICompatibilty, IDialog { renderGradual = compound.getBoolean("RenderGradual"); showPreviousBlocks = compound.getBoolean("PreviousBlocks"); + showOptionLine = compound.getBoolean("ShowOptionLine"); textSound = compound.getString("TextSound"); textPitch = compound.getFloat("TextPitch"); textWidth = compound.getInteger("TextWidth"); @@ -135,6 +137,8 @@ public class Dialog implements ICompatibilty, IDialog { textWidth = 300; if (!compound.hasKey("TextHeight")) textHeight = 400; + if (!compound.hasKey("ShowOptionLine")) + showOptionLine = true; availability.readFromNBT(compound); factionOptions.readFromNBT(compound); @@ -176,6 +180,7 @@ public class Dialog implements ICompatibilty, IDialog { compound.setBoolean("RenderGradual", renderGradual); compound.setBoolean("PreviousBlocks", showPreviousBlocks); + compound.setBoolean("ShowOptionLine", showOptionLine); compound.setString("TextSound", textSound); compound.setFloat("TextPitch", textPitch); compound.setInteger("TextWidth", textWidth); @@ -226,6 +231,7 @@ public class Dialog implements ICompatibilty, IDialog { dialog.darkenScreen = darkenScreen; dialog.renderGradual = renderGradual; dialog.showPreviousBlocks = showPreviousBlocks; + dialog.showOptionLine = showOptionLine; dialog.textSound = textSound; dialog.textPitch = textPitch; dialog.textWidth = textWidth; diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index aa52c7982..4913898ab 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -448,6 +448,7 @@ dialog.textPitch=Text Pitch dialog.textureOffset=Texture Offset dialog.selectedColor=Selected Color dialog.imageType=Image Type +dialog.optionLine=Option Line quest.quest=Quest quest.quests=Quests From 4fe61a904fa85afe51d035cdcbbfe203570cc836 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Thu, 9 Jun 2022 18:07:51 -0500 Subject: [PATCH 30/40] More dialog GUI data fixes and visual tweaks. --- .../client/gui/SubGuiNpcDialogVisual.java | 134 ++++++++++-------- .../client/gui/player/GuiDialogImage.java | 1 - .../client/gui/player/GuiDialogInteract.java | 2 + .../assets/customnpcs/lang/en_US.lang | 5 +- 4 files changed, 83 insertions(+), 59 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java index 7c2cacdb6..0e4d940c6 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java @@ -3,6 +3,7 @@ package noppes.npcs.client.gui; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.Client; import noppes.npcs.client.NoppesUtil; @@ -26,6 +27,9 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis private int selected = -1; private int lastColorClicked = -1; + private long lastClickedTime = 0; + private int changedId = -1; + public SubGuiNpcDialogVisual(Dialog dialog, GuiScreen parent) { this.parent2 = parent; this.dialog = dialog; @@ -45,8 +49,10 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis GuiMenuTopButton spacing = new GuiMenuTopButton(2, general.xPosition + general.getWidth(), guiTop - 17, "Spacing"); GuiMenuTopButton images = new GuiMenuTopButton(3, spacing.xPosition + spacing.getWidth(), guiTop - 17, "Images"); topButtons = new GuiMenuTopButton[]{general,images,spacing,close}; - for(GuiMenuTopButton button : topButtons) + for(GuiMenuTopButton button : topButtons) { button.active = button.id == activeMenu; + addButton(button); + } if (activeMenu == 1) { addButton(new GuiNpcButtonYesNo(10, guiLeft + 120, y += 22, dialog.hideNPC)); @@ -64,17 +70,19 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis addButton(new GuiNpcButton(14, guiLeft + 120, y += 22, 50, 20, new String[]{"display.hide", "display.show"}, dialog.showPreviousBlocks ? 1 : 0)); addLabel(new GuiNpcLabel(14, "dialog.previousBlocks", guiLeft + 4, y + 5)); - if (dialog.renderGradual) { - addTextField(new GuiNpcTextField(15, this, guiLeft + 80, y += 22, 165, 20, dialog.textSound)); - addLabel(new GuiNpcLabel(15, "dialog.textSound", guiLeft + 4, y + 5)); + addButton(new GuiNpcButton(15, guiLeft + 120, y += 22, 50, 20, new String[]{"display.hide", "display.show"}, dialog.showOptionLine ? 1 : 0)); + addLabel(new GuiNpcLabel(15, "dialog.optionLine", guiLeft + 4, y + 5)); - addTextField(new GuiNpcTextField(16, this, guiLeft + 125, y += 22, 40, 20, String.valueOf(dialog.textPitch))); - addLabel(new GuiNpcLabel(16, "dialog.textPitch", guiLeft + 4, y + 5)); - getTextField(16).floatsOnly = true; - } + addTextField(new GuiNpcTextField(16, this, guiLeft + 80, y += 22, 165, 20, dialog.textSound)); + addLabel(new GuiNpcLabel(16, "dialog.textSound", guiLeft + 4, y + 5)); + getTextField(16).setVisible(dialog.renderGradual); + getLabel(16).enabled = dialog.renderGradual; - addButton(new GuiNpcButton(17, guiLeft + 120, y += 22, 50, 20, new String[]{"display.hide", "display.show"}, dialog.showOptionLine ? 1 : 0)); - addLabel(new GuiNpcLabel(17, "dialog.optionLine", guiLeft + 4, y + 5)); + addTextField(new GuiNpcTextField(17, this, guiLeft + 125, y += 22, 40, 20, String.valueOf(dialog.textPitch))); + addLabel(new GuiNpcLabel(17, "dialog.textPitch", guiLeft + 4, y + 5)); + getTextField(17).floatsOnly = true; + getTextField(17).setVisible(dialog.renderGradual); + getLabel(17).enabled = dialog.renderGradual; } else if (activeMenu == 2) { addTextField(new GuiNpcTextField(10, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.textWidth))); addTextField(new GuiNpcTextField(11, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.textHeight))); @@ -123,17 +131,17 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis } else if (activeMenu == 3) { if (imageScroll == null) { imageScroll = new GuiCustomScroll(this, 0, false); - imageScroll.guiLeft = guiLeft + xSize; - imageScroll.guiTop = guiTop + 25; - imageScroll.setSize(50, this.ySize - 25); } + imageScroll.guiLeft = guiLeft + xSize; + imageScroll.guiTop = guiTop + 25; + imageScroll.setSize(50, this.ySize - 25); updateScrollData(); - this.addButton(new GuiNpcButton(1, guiLeft + xSize + 2, guiTop + 5, 20, 20, "+")); + addButton(new GuiNpcButton(1, guiLeft + xSize + 2, guiTop + 5, 20, 20, "+")); if (getSelectedImage() != null) { DialogImage dialogImage = getSelectedImage(); - this.addButton(new GuiNpcButton(2, guiLeft + xSize + 24, guiTop + 5, 20, 20, "-")); + addButton(new GuiNpcButton(2, guiLeft + xSize + 24, guiTop + 5, 20, 20, "-")); addTextField(new GuiNpcTextField(10, this, guiLeft + 17, y += 25, 30, 20, String.valueOf(dialogImage.id))); addTextField(new GuiNpcTextField(11, this, guiLeft + 92, y, 150, 20, dialogImage.texture)); @@ -172,37 +180,38 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis addLabel(new GuiNpcLabel(15, "gui.color", guiLeft + 4, y + 5)); getButton(18).setTextColor(dialogImage.color); - if (dialogImage.imageType == 2) { - String selectedColor = Integer.toHexString(dialogImage.selectedColor); - while (selectedColor.length() < 6) - selectedColor = 0 + selectedColor; - addButton(new GuiNpcButton(19, guiLeft + 180, y, 60, 20, selectedColor)); - addLabel(new GuiNpcLabel(16, "dialog.selectedColor", guiLeft + 100, y + 5)); - getButton(19).setTextColor(dialogImage.selectedColor); - } + String selectedColor = Integer.toHexString(dialogImage.selectedColor); + while (selectedColor.length() < 6) + selectedColor = 0 + selectedColor; + addButton(new GuiNpcButton(19, guiLeft + 180, y, 60, 20, selectedColor)); + addLabel(new GuiNpcLabel(16, "dialog.selectedColor", guiLeft + 100, y + 5)); + getButton(19).setTextColor(dialogImage.selectedColor); + getButton(19).setEnabled(dialogImage.imageType == 2); + getButton(19).setVisible(dialogImage.imageType == 2); + getLabel(16).enabled = dialogImage.imageType == 2; - addTextField(new GuiNpcTextField(20, this, guiLeft + 35, y += 25, 60, 20, String.valueOf(dialogImage.scale))); - addTextField(new GuiNpcTextField(21, this, guiLeft + 180, y, 60, 20, String.valueOf(dialogImage.alpha))); + addTextField(new GuiNpcTextField(20, this, guiLeft + 33, y += 25, 30, 20, String.valueOf(dialogImage.scale))); + addTextField(new GuiNpcTextField(21, this, guiLeft + 102, y, 30, 20, String.valueOf(dialogImage.alpha))); + addTextField(new GuiNpcTextField(22, this, guiLeft + 183, y, 45, 20, String.valueOf(dialogImage.rotation))); addLabel(new GuiNpcLabel(17, "model.scale", guiLeft + 4, y + 5)); - addLabel(new GuiNpcLabel(18, "display.alpha", guiLeft + 100, y + 5)); + addLabel(new GuiNpcLabel(18, "display.alpha", guiLeft + 72, y + 5)); + addLabel(new GuiNpcLabel(19, "movement.rotation", guiLeft + 140, y + 5)); getTextField(20).floatsOnly = true; getTextField(21).floatsOnly = true; - - addTextField(new GuiNpcTextField(22, this, guiLeft + 47, y += 25, 60, 20, String.valueOf(dialogImage.rotation))); - addLabel(new GuiNpcLabel(19, "movement.rotation", guiLeft + 4, y + 5)); getTextField(22).floatsOnly = true; - addButton(new GuiNpcButton(23, guiLeft + 180, y, 60, 20, new String[]{"gui.default","gui.text","gui.option"}, dialogImage.imageType)); - addLabel(new GuiNpcLabel(20, "dialog.imageType", guiLeft + 115, y + 5)); + addButton(new GuiNpcButton(23, guiLeft + 35, y += 25, 60, 20, new String[]{"gui.screen", "gui.text", "gui.option"}, dialogImage.imageType)); + addLabel(new GuiNpcLabel(20, "gui.type", guiLeft + 4, y + 5)); - if (dialogImage.imageType == 0) { - addButton(new GuiNpcButton(24, guiLeft + 180, y += 25, 60, 20, - new String[]{"display.topLeft", "display.topCenter", "display.topRight", - "display.left", "display.center", "display.right", - "display.botLeft", "display.botCenter", "display.botRight"}, - dialogImage.alignment)); - addLabel(new GuiNpcLabel(21, "display.alignment", guiLeft + 115, y + 5)); - } + addButton(new GuiNpcButton(24, guiLeft + 160, y, 60, 20, + new String[]{"display.topLeft", "display.topCenter", "display.topRight", + "display.left", "display.center", "display.right", + "display.botLeft", "display.botCenter", "display.botRight"}, + dialogImage.alignment)); + addLabel(new GuiNpcLabel(21, "display.alignment", guiLeft + 110, y + 5)); + getButton(24).setEnabled(dialogImage.imageType == 0); + getButton(24).setVisible(dialogImage.imageType == 0); + getLabel(21).enabled = dialogImage.imageType == 0; } } } @@ -214,24 +223,18 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis for (int i : ids) { strings.add(String.valueOf(i)); } - imageScroll.setList(strings); + imageScroll.setUnsortedList(strings); + + if (changedId != -1) { + selected = imageScroll.getList().indexOf(String.valueOf(changedId)); + imageScroll.setSelected(String.valueOf(changedId)); + changedId = -1; + } + addScroll(imageScroll); } - public void mouseClicked(int i, int j, int k) { - super.mouseClicked(i,j,k); - if (k == 0) { - Minecraft mc = Minecraft.getMinecraft(); - for (GuiMenuTopButton button : topButtons) { - if (button.mousePressed(mc, i, j)) { - topButtonPressed(button); - } - } - } - } - private void topButtonPressed(GuiMenuTopButton button) { - Minecraft mc = Minecraft.getMinecraft(); NoppesUtil.clickSound(); int id = button.id; @@ -251,6 +254,10 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis protected void actionPerformed(GuiButton guibutton){ GuiNpcButton button = (GuiNpcButton) guibutton; + if (guibutton instanceof GuiMenuTopButton) { + topButtonPressed((GuiMenuTopButton) guibutton); + } + if (activeMenu == 1) { if (button.id == 10) { dialog.hideNPC = button.getValue() == 1; @@ -267,7 +274,7 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis if (button.id == 14) { dialog.showPreviousBlocks = button.getValue() == 1; } - if (button.id == 17) { + if (button.id == 15) { dialog.showOptionLine = button.getValue() == 1; } } @@ -315,6 +322,10 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis if (getSelectedImage() != null) { DialogImage dialogImage = getSelectedImage(); dialogImage.imageType = button.getValue(); + + if (dialogImage.imageType == 2) { + lastClickedTime++; + } } } if (button.id == 24) { @@ -367,10 +378,10 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis @Override public void unFocused(GuiNpcTextField textfield) { if (activeMenu == 1) { - if (textfield.id == 15) { + if (textfield.id == 16) { dialog.textSound = textfield.getText(); } - if (textfield.id == 16) { + if (textfield.id == 17) { dialog.textPitch = textfield.getFloat(); } } @@ -421,7 +432,18 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis } if (textfield.id == 10) { + if (imageScroll.getList().contains(String.valueOf(textfield.getInteger()))) { + textfield.setText(String.valueOf(dialogImage.id)); + return; + } + + dialog.dialogImages.remove(dialogImage.id); dialogImage.id = textfield.getInteger(); + dialog.dialogImages.put(dialogImage.id, dialogImage); + + changedId = dialogImage.id; + updateScrollData(); + initGui(); } if (textfield.id == 11) { dialogImage.texture = textfield.getText(); diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogImage.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogImage.java index f001c5139..f4de00036 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogImage.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogImage.java @@ -81,7 +81,6 @@ public class GuiDialogImage extends Gui { float blue = (color & 255) / 255f; GL11.glColor4f(red,green,blue,this.alpha); - GL11.glTranslatef(this.alignment%3*((float)(OverlayCustom.scaledWidth)/2), (float) (Math.floor((float)(alignment/3))*((float)(OverlayCustom.scaledHeight)/2)),0.0F); GL11.glRotatef(this.rotation,0.0F,0.0F,1.0F); GL11.glScalef(this.scale, this.scale, this.scale); diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index b85638f51..14ead84cb 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -20,6 +20,7 @@ import noppes.npcs.client.ClientProxy; import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.TextBlockClient; import noppes.npcs.client.controllers.MusicController; +import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.IGuiClose; import noppes.npcs.constants.EnumOptionType; @@ -176,6 +177,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); GL11.glDisable(GL11.GL_ALPHA_TEST); + GL11.glTranslatef(image.alignment%3*((float)(scaledResolution.getScaledWidth())/2), (float) (Math.floor((float)(image.alignment/3))*((float)(scaledResolution.getScaledHeight())/2)),0.0F); image.onRender(mc); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 4913898ab..20f0946c9 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -119,9 +119,11 @@ gui.forum=Forum gui.id=ID gui.widthHeight=Width & Height gui.position=Position -gui.option=Option +gui.screen=Screen gui.text=Text +gui.option=Option gui.default=Default +gui.type=Type remote.title=Nearby NPCs remote.reset=Reset @@ -447,7 +449,6 @@ dialog.textSound=Text Sound dialog.textPitch=Text Pitch dialog.textureOffset=Texture Offset dialog.selectedColor=Selected Color -dialog.imageType=Image Type dialog.optionLine=Option Line quest.quest=Quest From ff8fc68e88052039ddb844c4d4af224f0b786048 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Fri, 10 Jun 2022 01:38:01 -0500 Subject: [PATCH 31/40] Implemented dialog and text colors. --- .../noppes/npcs/client/TextBlockClient.java | 4 +- .../client/gui/SubGuiNpcDialogVisual.java | 123 ++++++++++++------ .../client/gui/player/GuiDialogInteract.java | 16 +-- .../npcs/client/gui/util/GuiNpcTextField.java | 4 + .../noppes/npcs/controllers/data/Dialog.java | 29 ++++- .../assets/customnpcs/lang/en_US.lang | 3 + 6 files changed, 132 insertions(+), 47 deletions(-) diff --git a/src/main/java/noppes/npcs/client/TextBlockClient.java b/src/main/java/noppes/npcs/client/TextBlockClient.java index b5f476bcc..68c40cf92 100644 --- a/src/main/java/noppes/npcs/client/TextBlockClient.java +++ b/src/main/java/noppes/npcs/client/TextBlockClient.java @@ -13,12 +13,14 @@ import noppes.npcs.entity.EntityNPCInterface; public class TextBlockClient extends TextBlock{ private ChatStyle style; public int color = 0xe0e0e0; + public int titleColor = 0xe0e0e0; private String name; private ICommandSender sender; - public TextBlockClient(ICommandSender sender, String text, int lineWidth, int color, Object... obs) { + public TextBlockClient(ICommandSender sender, String text, int lineWidth, int color, int titleColor, Object... obs) { this(text, lineWidth, false, obs); this.color = color; + this.titleColor = titleColor; this.sender = sender; } public TextBlockClient(String name, String text, int lineWidth, int color, Object... obs) { diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java index 0e4d940c6..0f514285a 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java @@ -26,8 +26,6 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis private GuiCustomScroll imageScroll; private int selected = -1; private int lastColorClicked = -1; - - private long lastClickedTime = 0; private int changedId = -1; public SubGuiNpcDialogVisual(Dialog dialog, GuiScreen parent) { @@ -73,16 +71,32 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis addButton(new GuiNpcButton(15, guiLeft + 120, y += 22, 50, 20, new String[]{"display.hide", "display.show"}, dialog.showOptionLine ? 1 : 0)); addLabel(new GuiNpcLabel(15, "dialog.optionLine", guiLeft + 4, y + 5)); - addTextField(new GuiNpcTextField(16, this, guiLeft + 80, y += 22, 165, 20, dialog.textSound)); - addLabel(new GuiNpcLabel(16, "dialog.textSound", guiLeft + 4, y + 5)); - getTextField(16).setVisible(dialog.renderGradual); - getLabel(16).enabled = dialog.renderGradual; + String color = Integer.toHexString(dialog.color); + while (color.length() < 6) { + color = 0 + color; + } + addButton(new GuiNpcButton(16, guiLeft + 35, y += 25, 60, 20, color)); + addLabel(new GuiNpcLabel(16, "gui.color", guiLeft + 4, y + 5)); + getButton(16).setTextColor(dialog.color); - addTextField(new GuiNpcTextField(17, this, guiLeft + 125, y += 22, 40, 20, String.valueOf(dialog.textPitch))); - addLabel(new GuiNpcLabel(17, "dialog.textPitch", guiLeft + 4, y + 5)); - getTextField(17).floatsOnly = true; - getTextField(17).setVisible(dialog.renderGradual); - getLabel(17).enabled = dialog.renderGradual; + color = Integer.toHexString(dialog.titleColor); + while (color.length() < 6) { + color = 0 + color; + } + addButton(new GuiNpcButton(17, guiLeft + 180, y, 60, 20, color)); + addLabel(new GuiNpcLabel(17, "dialog.titleColor", guiLeft + 100, y + 5)); + getButton(17).setTextColor(dialog.titleColor); + + addTextField(new GuiNpcTextField(18, this, guiLeft + 80, y += 22, 165, 20, dialog.textSound)); + addLabel(new GuiNpcLabel(18, "dialog.textSound", guiLeft + 4, y + 5)); + getTextField(18).setVisible(dialog.renderGradual); + getLabel(18).enabled = dialog.renderGradual; + + addTextField(new GuiNpcTextField(19, this, guiLeft + 125, y += 22, 40, 20, String.valueOf(dialog.textPitch))); + addLabel(new GuiNpcLabel(19, "dialog.textPitch", guiLeft + 4, y + 5)); + getTextField(19).floatsOnly = true; + getTextField(19).setVisible(dialog.renderGradual); + getLabel(19).enabled = dialog.renderGradual; } else if (activeMenu == 2) { addTextField(new GuiNpcTextField(10, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.textWidth))); addTextField(new GuiNpcTextField(11, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.textHeight))); @@ -124,10 +138,23 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis getTextField(19).integersOnly = true; getTextField(19).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); - for (int i = 10; i < 20; i++) { - GuiNpcTextField textField = this.getTextField(i); - textField.integersOnly = true; - } + addTextField(new GuiNpcTextField(20, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.npcOffsetX))); + addTextField(new GuiNpcTextField(21, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.npcOffsetY))); + addLabel(new GuiNpcLabel(25, "dialog.npcOffset", guiLeft + 4, y + 5)); + getTextField(20).integersOnly = true; + getTextField(20).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(20).setVisible(!dialog.hideNPC); + getTextField(21).integersOnly = true; + getTextField(21).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(21).setVisible(!dialog.hideNPC); + getLabel(25).enabled = !dialog.hideNPC; + + addTextField(new GuiNpcTextField(22, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.npcScale))); + addLabel(new GuiNpcLabel(26, "dialog.npcScale", guiLeft + 4, y + 5)); + getTextField(22).floatsOnly = true; + getTextField(22).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0); + getTextField(22).setVisible(!dialog.hideNPC); + getLabel(26).enabled = !dialog.hideNPC; } else if (activeMenu == 3) { if (imageScroll == null) { imageScroll = new GuiCustomScroll(this, 0, false); @@ -277,6 +304,14 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis if (button.id == 15) { dialog.showOptionLine = button.getValue() == 1; } + if (button.id == 16) { + setSubGui(new SubGuiColorSelector(dialog.color)); + lastColorClicked = 0; + } + if (button.id == 17) { + setSubGui(new SubGuiColorSelector(dialog.titleColor)); + lastColorClicked = 1; + } } if (activeMenu == 3) { @@ -322,10 +357,6 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis if (getSelectedImage() != null) { DialogImage dialogImage = getSelectedImage(); dialogImage.imageType = button.getValue(); - - if (dialogImage.imageType == 2) { - lastClickedTime++; - } } } if (button.id == 24) { @@ -349,15 +380,25 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis @Override public void subGuiClosed(SubGuiInterface subgui){ - if (getSelectedImage() != null) { - DialogImage dialogImage = getSelectedImage(); + if (activeMenu == 1) { if (lastColorClicked == 0) { - dialogImage.color = ((SubGuiColorSelector) subgui).color; + dialog.color = ((SubGuiColorSelector) subgui).color; } else if (lastColorClicked == 1) { - dialogImage.selectedColor = ((SubGuiColorSelector) subgui).color; + dialog.titleColor = ((SubGuiColorSelector) subgui).color; } initGui(); } + if (activeMenu == 3) { + if (getSelectedImage() != null) { + DialogImage dialogImage = getSelectedImage(); + if (lastColorClicked == 0) { + dialogImage.color = ((SubGuiColorSelector) subgui).color; + } else if (lastColorClicked == 1) { + dialogImage.selectedColor = ((SubGuiColorSelector) subgui).color; + } + initGui(); + } + } save(); } @@ -378,50 +419,58 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis @Override public void unFocused(GuiNpcTextField textfield) { if (activeMenu == 1) { - if (textfield.id == 16) { + if (textfield.id == 18) { dialog.textSound = textfield.getText(); } - if (textfield.id == 17) { + if (textfield.id == 19) { dialog.textPitch = textfield.getFloat(); } } if (activeMenu == 2) { - int i = textfield.getInteger(); - if (textfield.id == 10) { - dialog.textWidth = i; + dialog.textWidth = textfield.getInteger(); } if (textfield.id == 11) { - dialog.textHeight = i; + dialog.textHeight = textfield.getInteger(); } if (textfield.id == 12) { - dialog.textOffsetX = i; + dialog.textOffsetX = textfield.getInteger(); } if (textfield.id == 13) { - dialog.textOffsetY = i; + dialog.textOffsetY = textfield.getInteger(); } if (textfield.id == 14) { - dialog.titleOffsetX = i; + dialog.titleOffsetX = textfield.getInteger(); } if (textfield.id == 15) { - dialog.titleOffsetY = i; + dialog.titleOffsetY = textfield.getInteger(); } if (textfield.id == 16) { - dialog.optionOffsetX = i; + dialog.optionOffsetX = textfield.getInteger(); } if (textfield.id == 17) { - dialog.optionOffsetY = i; + dialog.optionOffsetY = textfield.getInteger(); } if (textfield.id == 18) { - dialog.optionSpaceX = i; + dialog.optionSpaceX = textfield.getInteger(); } if (textfield.id == 19) { - dialog.optionSpaceY = i; + dialog.optionSpaceY = textfield.getInteger(); + } + + if (textfield.id == 20) { + dialog.npcOffsetX = textfield.getInteger(); + } + if (textfield.id == 21) { + dialog.npcOffsetY = textfield.getInteger(); + } + if (textfield.id == 22) { + dialog.npcScale = textfield.getFloat(); } } diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index 14ead84cb..8eaf66eb9 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -111,7 +111,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose float i1 = (guiTop + ySize); GL11.glEnable(GL11.GL_COLOR_MATERIAL); GL11.glPushMatrix(); - GL11.glTranslatef(l, i1, 50F); + GL11.glTranslatef(l + dialog.npcOffsetX, i1 + dialog.npcOffsetY, 50F); float zoomed = npc.height; if(npc.width * 2 > zoomed) zoomed = npc.width * 2; @@ -138,10 +138,10 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose RenderManager.instance.playerViewY = 180F; try{ + GL11.glScalef(dialog.npcScale,dialog.npcScale,dialog.npcScale); RenderManager.instance.renderEntityWithPosYaw(npc, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F); - } - catch(Exception e){ - } + } catch(Exception ignored){} + npc.ai.orientation = rotation; npc.renderYawOffset = f2; npc.rotationYaw = f3; @@ -212,7 +212,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose TextBlockClient block = lineBlocks.get(b); int size = ClientProxy.Font.width(block.getName() + " "); - drawDialogString(block.getName() + " ", -4 - size, block.color, count, false); + drawDialogString(block.getName() + " ", -4 - size, block.titleColor, count, false); for (int l = 0; l < block.lines.size(); l++) { IChatComponent line = block.lines.get(l); @@ -265,7 +265,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose for (int pastBlock = 0; pastBlock < currentBlock; pastBlock++) { TextBlockClient block = lineBlocks.get(pastBlock); int size = ClientProxy.Font.width(block.getName() + " "); - drawDialogString(block.getName() + " ", -4 - size, block.color, count, false); + drawDialogString(block.getName() + " ", -4 - size, block.titleColor, count, false); for (IChatComponent line : block.lines) { drawDialogString(line.getFormattedText(), 0, block.color, count, true); @@ -277,7 +277,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if (currentBlock < lineBlocks.size()) { TextBlockClient block = lineBlocks.get(currentBlock); int size = ClientProxy.Font.width(block.getName() + " "); - drawDialogString(block.getName() + " ", -4 - size, block.color, count, false); + drawDialogString(block.getName() + " ", -4 - size, block.titleColor, count, false); for (int pastLine = 0; pastLine < currentLine; pastLine++) { IChatComponent line = block.lines.get(pastLine); @@ -615,7 +615,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if (!dialog.showPreviousBlocks) { lineBlocks.clear(); } - lineBlocks.add(new TextBlockClient(npc, dialog.text, dialog.textWidth, 0xe0e0e0, player, npc)); + lineBlocks.add(new TextBlockClient(npc, dialog.text, dialog.textWidth, dialog.color, dialog.titleColor, player, npc)); gradualText = ""; currentBlock = lineBlocks.size()-1; currentLine = 0; diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java b/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java index 6060d5cea..a45c5d062 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java @@ -43,6 +43,10 @@ public class GuiNpcTextField extends GuiTextField{ private boolean charAllowed(char c, int i){ if(!integersOnly || Character.isDigit(c)) return true; + + if(integersOnly && getText().isEmpty() && c == '-') + return true; + for(int j : allowedSpecialChars) if(j == i) return true; diff --git a/src/main/java/noppes/npcs/controllers/data/Dialog.java b/src/main/java/noppes/npcs/controllers/data/Dialog.java index ae753f1c2..5eea59e46 100644 --- a/src/main/java/noppes/npcs/controllers/data/Dialog.java +++ b/src/main/java/noppes/npcs/controllers/data/Dialog.java @@ -28,7 +28,10 @@ public class Dialog implements ICompatibilty, IDialog { public String sound; public String command = ""; public PlayerMail mail = new PlayerMail(); - + + public int color = 0xe0e0e0; + public int titleColor = 0xe0e0e0; + public boolean hideNPC = false; public boolean showWheel = false; public boolean disableEsc = false; @@ -50,6 +53,9 @@ public class Dialog implements ICompatibilty, IDialog { public int optionSpaceX, optionSpaceY; public int optionOffsetX, optionOffsetY; + public float npcScale = 1.0F; + public int npcOffsetX, npcOffsetY; + public HashMap dialogImages = new HashMap<>(); public boolean hasDialogs(EntityPlayer player) { @@ -111,6 +117,8 @@ public class Dialog implements ICompatibilty, IDialog { } this.dialogImages = newImages; + color = compound.getInteger("Color"); + titleColor = compound.getInteger("TitleColor"); renderGradual = compound.getBoolean("RenderGradual"); showPreviousBlocks = compound.getBoolean("PreviousBlocks"); showOptionLine = compound.getBoolean("ShowOptionLine"); @@ -126,6 +134,9 @@ public class Dialog implements ICompatibilty, IDialog { optionOffsetY = compound.getInteger("OptionOffsetY"); optionSpaceX = compound.getInteger("OptionSpaceX"); optionSpaceY = compound.getInteger("OptionSpaceY"); + npcScale = compound.getFloat("NPCScale"); + npcOffsetX = compound.getInteger("NPCOffsetX"); + npcOffsetY = compound.getInteger("NPCOffsetY"); if (!compound.hasKey("PreviousBlocks")) showPreviousBlocks = true; @@ -139,6 +150,12 @@ public class Dialog implements ICompatibilty, IDialog { textHeight = 400; if (!compound.hasKey("ShowOptionLine")) showOptionLine = true; + if (!compound.hasKey("NPCScale")) + npcScale = 1.0F; + if (!compound.hasKey("Color")) + color = 0xe0e0e0; + if (!compound.hasKey("TitleColor")) + titleColor = 0xe0e0e0; availability.readFromNBT(compound); factionOptions.readFromNBT(compound); @@ -178,6 +195,8 @@ public class Dialog implements ICompatibilty, IDialog { factionOptions.writeToNBT(compound); compound.setInteger("ModRev", version); + compound.setInteger("Color", color); + compound.setInteger("TitleColor", titleColor); compound.setBoolean("RenderGradual", renderGradual); compound.setBoolean("PreviousBlocks", showPreviousBlocks); compound.setBoolean("ShowOptionLine", showOptionLine); @@ -193,6 +212,9 @@ public class Dialog implements ICompatibilty, IDialog { compound.setInteger("OptionOffsetY", optionOffsetY); compound.setInteger("OptionSpaceX", optionSpaceX); compound.setInteger("OptionSpaceY", optionSpaceY); + compound.setFloat("NPCScale", npcScale); + compound.setInteger("NPCOffsetX", npcOffsetX); + compound.setInteger("NPCOffsetY", npcOffsetY); NBTTagList images = new NBTTagList(); for (DialogImage dialogImage : dialogImages.values()) { @@ -225,6 +247,8 @@ public class Dialog implements ICompatibilty, IDialog { dialog.sound = sound; dialog.mail = mail; dialog.command = command; + dialog.color = color; + dialog.titleColor = titleColor; dialog.hideNPC = hideNPC; dialog.showWheel = showWheel; dialog.disableEsc = disableEsc; @@ -244,6 +268,9 @@ public class Dialog implements ICompatibilty, IDialog { dialog.optionOffsetY = optionOffsetY; dialog.optionSpaceX = optionSpaceX; dialog.optionSpaceY = optionSpaceY; + dialog.npcScale = npcScale; + dialog.npcOffsetX = npcOffsetX; + dialog.npcOffsetY = npcOffsetY; dialog.dialogImages = dialogImages; for(int slot : options.keySet()){ diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 20f0946c9..4875768c4 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -450,6 +450,9 @@ dialog.textPitch=Text Pitch dialog.textureOffset=Texture Offset dialog.selectedColor=Selected Color dialog.optionLine=Option Line +dialog.npcScale=NPC Scale +dialog.npcOffset=NPC Offset +dialog.titleColor=Title Color quest.quest=Quest quest.quests=Quests From 486e37cd7fc9ac9e9029558fbadc24aafcb11668 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Fri, 10 Jun 2022 04:47:28 -0500 Subject: [PATCH 32/40] Implemented title positions for dialogs. --- .../noppes/npcs/client/TextBlockClient.java | 12 ++- .../client/gui/SubGuiNpcDialogVisual.java | 97 ++++++++++--------- .../client/gui/player/GuiDialogInteract.java | 48 +++++---- .../noppes/npcs/controllers/data/Dialog.java | 4 + .../assets/customnpcs/lang/en_US.lang | 3 +- 5 files changed, 95 insertions(+), 69 deletions(-) diff --git a/src/main/java/noppes/npcs/client/TextBlockClient.java b/src/main/java/noppes/npcs/client/TextBlockClient.java index 68c40cf92..0ff3a81e9 100644 --- a/src/main/java/noppes/npcs/client/TextBlockClient.java +++ b/src/main/java/noppes/npcs/client/TextBlockClient.java @@ -8,21 +8,25 @@ import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatStyle; import noppes.npcs.NoppesStringUtils; import noppes.npcs.TextBlock; +import noppes.npcs.controllers.data.Dialog; import noppes.npcs.entity.EntityNPCInterface; public class TextBlockClient extends TextBlock{ private ChatStyle style; public int color = 0xe0e0e0; public int titleColor = 0xe0e0e0; + public int titlePos = 0; private String name; private ICommandSender sender; - public TextBlockClient(ICommandSender sender, String text, int lineWidth, int color, int titleColor, Object... obs) { - this(text, lineWidth, false, obs); - this.color = color; - this.titleColor = titleColor; + public TextBlockClient(ICommandSender sender, Dialog dialog, Object... obs) { + this(dialog.text, dialog.textWidth, false, obs); + this.color = dialog.color; + this.titleColor = dialog.titleColor; + this.titlePos = dialog.titlePos; this.sender = sender; } + public TextBlockClient(String name, String text, int lineWidth, int color, Object... obs) { this(text, lineWidth, false, obs); this.color = color; diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java index 0f514285a..78be626bf 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java @@ -1,9 +1,7 @@ package noppes.npcs.client.gui; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.ScaledResolution; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.Client; import noppes.npcs.client.NoppesUtil; @@ -83,7 +81,7 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis while (color.length() < 6) { color = 0 + color; } - addButton(new GuiNpcButton(17, guiLeft + 180, y, 60, 20, color)); + addButton(new GuiNpcButton(17, guiLeft + 157, y, 60, 20, color)); addLabel(new GuiNpcLabel(17, "dialog.titleColor", guiLeft + 100, y + 5)); getButton(17).setTextColor(dialog.titleColor); @@ -98,62 +96,65 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis getTextField(19).setVisible(dialog.renderGradual); getLabel(19).enabled = dialog.renderGradual; } else if (activeMenu == 2) { - addTextField(new GuiNpcTextField(10, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.textWidth))); - addTextField(new GuiNpcTextField(11, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.textHeight))); + addButton(new GuiNpcButton(10, guiLeft + 70, y += 22, 50, 20, new String[]{"gui.text", "gui.option", "display.fixed"}, dialog.titlePos)); + addLabel(new GuiNpcLabel(10, "dialog.titlePos", guiLeft + 4, y + 5)); + + addTextField(new GuiNpcTextField(11, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.textWidth))); + addTextField(new GuiNpcTextField(12, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.textHeight))); addLabel(new GuiNpcLabel(12, "gui.widthHeight", guiLeft + 4, y + 5)); - getTextField(10).integersOnly = true; - getTextField(10).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); getTextField(11).integersOnly = true; getTextField(11).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); - - addTextField(new GuiNpcTextField(12, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.textOffsetX))); - addTextField(new GuiNpcTextField(13, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.textOffsetY))); - addLabel(new GuiNpcLabel(15, "dialog.textOffset", guiLeft + 4, y + 5)); getTextField(12).integersOnly = true; getTextField(12).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + + addTextField(new GuiNpcTextField(13, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.textOffsetX))); + addTextField(new GuiNpcTextField(14, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.textOffsetY))); + addLabel(new GuiNpcLabel(15, "dialog.textOffset", guiLeft + 4, y + 5)); getTextField(13).integersOnly = true; getTextField(13).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); - - addTextField(new GuiNpcTextField(14, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.titleOffsetX))); - addTextField(new GuiNpcTextField(15, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.titleOffsetY))); - addLabel(new GuiNpcLabel(18, "dialog.titleOffset", guiLeft + 4, y + 5)); getTextField(14).integersOnly = true; getTextField(14).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + + addTextField(new GuiNpcTextField(15, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.titleOffsetX))); + addTextField(new GuiNpcTextField(16, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.titleOffsetY))); + addLabel(new GuiNpcLabel(18, "dialog.titleOffset", guiLeft + 4, y + 5)); getTextField(15).integersOnly = true; getTextField(15).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); - - addTextField(new GuiNpcTextField(16, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.optionOffsetX))); - addTextField(new GuiNpcTextField(17, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.optionOffsetY))); - addLabel(new GuiNpcLabel(21, "dialog.optionOffset", guiLeft + 4, y + 5)); getTextField(16).integersOnly = true; getTextField(16).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + + addTextField(new GuiNpcTextField(17, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.optionOffsetX))); + addTextField(new GuiNpcTextField(18, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.optionOffsetY))); + addLabel(new GuiNpcLabel(21, "dialog.optionOffset", guiLeft + 4, y + 5)); getTextField(17).integersOnly = true; getTextField(17).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); - - addTextField(new GuiNpcTextField(18, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.optionSpaceX))); - addTextField(new GuiNpcTextField(19, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.optionSpaceY))); - addLabel(new GuiNpcLabel(24, "dialog.optionSpacing", guiLeft + 4, y + 5)); getTextField(18).integersOnly = true; getTextField(18).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + + addTextField(new GuiNpcTextField(19, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.optionSpaceX))); + addTextField(new GuiNpcTextField(20, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.optionSpaceY))); + addLabel(new GuiNpcLabel(24, "dialog.optionSpacing", guiLeft + 4, y + 5)); getTextField(19).integersOnly = true; getTextField(19).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); - - addTextField(new GuiNpcTextField(20, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.npcOffsetX))); - addTextField(new GuiNpcTextField(21, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.npcOffsetY))); - addLabel(new GuiNpcLabel(25, "dialog.npcOffset", guiLeft + 4, y + 5)); getTextField(20).integersOnly = true; getTextField(20).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); - getTextField(20).setVisible(!dialog.hideNPC); + + addTextField(new GuiNpcTextField(21, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.npcOffsetX))); + addTextField(new GuiNpcTextField(22, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.npcOffsetY))); + addLabel(new GuiNpcLabel(25, "dialog.npcOffset", guiLeft + 4, y + 5)); getTextField(21).integersOnly = true; getTextField(21).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); getTextField(21).setVisible(!dialog.hideNPC); + getTextField(22).integersOnly = true; + getTextField(22).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(22).setVisible(!dialog.hideNPC); getLabel(25).enabled = !dialog.hideNPC; - addTextField(new GuiNpcTextField(22, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.npcScale))); + addTextField(new GuiNpcTextField(23, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.npcScale))); addLabel(new GuiNpcLabel(26, "dialog.npcScale", guiLeft + 4, y + 5)); - getTextField(22).floatsOnly = true; - getTextField(22).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0); - getTextField(22).setVisible(!dialog.hideNPC); + getTextField(23).floatsOnly = true; + getTextField(23).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0); + getTextField(23).setVisible(!dialog.hideNPC); getLabel(26).enabled = !dialog.hideNPC; } else if (activeMenu == 3) { if (imageScroll == null) { @@ -314,6 +315,12 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis } } + if (activeMenu == 2) { + if (button.id == 10) { + dialog.titlePos = button.getValue(); + } + } + if (activeMenu == 3) { if (button.id == 1) { int addId = 0; @@ -428,48 +435,48 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis } if (activeMenu == 2) { - if (textfield.id == 10) { + if (textfield.id == 11) { dialog.textWidth = textfield.getInteger(); } - if (textfield.id == 11) { + if (textfield.id == 12) { dialog.textHeight = textfield.getInteger(); } - if (textfield.id == 12) { + if (textfield.id == 13) { dialog.textOffsetX = textfield.getInteger(); } - if (textfield.id == 13) { + if (textfield.id == 14) { dialog.textOffsetY = textfield.getInteger(); } - if (textfield.id == 14) { + if (textfield.id == 15) { dialog.titleOffsetX = textfield.getInteger(); } - if (textfield.id == 15) { + if (textfield.id == 16) { dialog.titleOffsetY = textfield.getInteger(); } - if (textfield.id == 16) { + if (textfield.id == 17) { dialog.optionOffsetX = textfield.getInteger(); } - if (textfield.id == 17) { + if (textfield.id == 18) { dialog.optionOffsetY = textfield.getInteger(); } - if (textfield.id == 18) { + if (textfield.id == 19) { dialog.optionSpaceX = textfield.getInteger(); } - if (textfield.id == 19) { + if (textfield.id == 20) { dialog.optionSpaceY = textfield.getInteger(); } - if (textfield.id == 20) { + if (textfield.id == 21) { dialog.npcOffsetX = textfield.getInteger(); } - if (textfield.id == 21) { + if (textfield.id == 22) { dialog.npcOffsetY = textfield.getInteger(); } - if (textfield.id == 22) { + if (textfield.id == 23) { dialog.npcScale = textfield.getFloat(); } } diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index 8eaf66eb9..47490533e 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -1,7 +1,6 @@ package noppes.npcs.client.gui.player; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import net.minecraft.client.Minecraft; @@ -20,7 +19,6 @@ import noppes.npcs.client.ClientProxy; import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.TextBlockClient; import noppes.npcs.client.controllers.MusicController; -import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.IGuiClose; import noppes.npcs.constants.EnumOptionType; @@ -212,7 +210,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose TextBlockClient block = lineBlocks.get(b); int size = ClientProxy.Font.width(block.getName() + " "); - drawDialogString(block.getName() + " ", -4 - size, block.titleColor, count, false); + drawDialogString(block.getName() + " ", -4 - size, count, false, block); for (int l = 0; l < block.lines.size(); l++) { IChatComponent line = block.lines.get(l); @@ -222,7 +220,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if (drawText.matches("(.*)(\\{(\\d+)})(.*)")) { if (textPauseTime > 0) { drawText = drawText.substring(0, prevPausePos); - drawDialogString(drawText, 0, block.color, count, true); + drawDialogString(drawText, 0, count, true, block); textPauseTime--; break blockLoop; } @@ -243,7 +241,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if (!strInt.isEmpty()) { drawText = drawText.substring(0, prevPausePos); - drawDialogString(drawText, 0, block.color, count, true); + drawDialogString(drawText, 0, count, true, block); instantBlockPos = b; instantLinePos = l; @@ -255,7 +253,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose } } - drawDialogString(drawText, 0, block.color, count, true); + drawDialogString(drawText, 0, count, true, block); count++; } count++; @@ -265,10 +263,10 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose for (int pastBlock = 0; pastBlock < currentBlock; pastBlock++) { TextBlockClient block = lineBlocks.get(pastBlock); int size = ClientProxy.Font.width(block.getName() + " "); - drawDialogString(block.getName() + " ", -4 - size, block.titleColor, count, false); + drawDialogString(block.getName() + " ", -4 - size, count, false, block); for (IChatComponent line : block.lines) { - drawDialogString(line.getFormattedText(), 0, block.color, count, true); + drawDialogString(line.getFormattedText(), 0, count, true, block); count++; } count++; @@ -277,11 +275,11 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if (currentBlock < lineBlocks.size()) { TextBlockClient block = lineBlocks.get(currentBlock); int size = ClientProxy.Font.width(block.getName() + " "); - drawDialogString(block.getName() + " ", -4 - size, block.titleColor, count, false); + drawDialogString(block.getName() + " ", -4 - size, count, false, block); for (int pastLine = 0; pastLine < currentLine; pastLine++) { IChatComponent line = block.lines.get(pastLine); - drawDialogString(line.getFormattedText(), 0, block.color, count, true); + drawDialogString(line.getFormattedText(), 0, count, true, block); count++; } @@ -335,7 +333,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose gradualText = line.getFormattedText(); } - drawDialogString(gradualText, 0, block.color, count, true); + drawDialogString(gradualText, 0, count, true, block); if (gradualText.length() == line.getFormattedText().length()) { gradualText = ""; @@ -474,26 +472,39 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose } } - private void drawDialogString(String text, int left, int color, int count, boolean mainDialogText){ + private void drawDialogString(String text, int left, int count, boolean mainDialogText, TextBlockClient block){ int lineOffset = dialog.renderGradual ? (currentBlock < lineBlocks.size() ? lineBlocks.get(currentBlock).lines.size() : lineBlocks.get(lineBlocks.size()-1).lines.size()) - currentLine : 0; int height = count - totalRows + lineOffset; int screenPos = optionStart; int y = (height * ClientProxy.Font.height()) + screenPos + scrollY; - if (y < screenPos - dialog.textHeight || y > screenPos - ClientProxy.Font.height()) { - return; + + if (block.titlePos == 0 || mainDialogText) { + if (y < screenPos - dialog.textHeight || y > screenPos - ClientProxy.Font.height()) { + return; + } } - int offsetX, offsetY; + int offsetX, offsetY, color; if (mainDialogText) { offsetX = dialog.textOffsetX; offsetY = dialog.textOffsetY; + color = block.color; } else { offsetX = dialog.titleOffsetX; offsetY = dialog.titleOffsetY; + color = block.titleColor; + + if (block.titlePos == 1 && block.equals(lineBlocks.get(currentBlock < lineBlocks.size() ? currentBlock : currentBlock - 1))) { + y = screenPos - ClientProxy.Font.height() - 5; + } } text = text.replaceAll("\\{(\\d+)}",""); - drawString(fontRendererObj, text, guiLeft + left + offsetX, y + offsetY, color); + if (!mainDialogText && block.titlePos == 2 && block.equals(lineBlocks.get(currentBlock < lineBlocks.size() ? currentBlock : currentBlock - 1))) { + drawString(fontRendererObj, text, offsetX, offsetY, color); + } else { + drawString(fontRendererObj, text, guiLeft + left + offsetX, y + offsetY, color); + } } public void drawString(FontRenderer fontRendererIn, String text, int x, int y, int color){ @@ -531,8 +542,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose textSoundEnabled = !textSoundEnabled; } - int firstBlockSize = lineBlocks.size() > 0 ? lineBlocks.get(0).lines.size() + 1 : 0; - if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 201 && scrollY < (totalRows - firstBlockSize) * ClientProxy.Font.height()) {//Page up + if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 201 && scrollY < (totalRows - 2) * ClientProxy.Font.height()) {//Page up scrollY += ClientProxy.Font.height() * 2; } if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 209 && scrollY > 0) {//Page down @@ -615,7 +625,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if (!dialog.showPreviousBlocks) { lineBlocks.clear(); } - lineBlocks.add(new TextBlockClient(npc, dialog.text, dialog.textWidth, dialog.color, dialog.titleColor, player, npc)); + lineBlocks.add(new TextBlockClient(npc, dialog, player, npc)); gradualText = ""; currentBlock = lineBlocks.size()-1; currentLine = 0; diff --git a/src/main/java/noppes/npcs/controllers/data/Dialog.java b/src/main/java/noppes/npcs/controllers/data/Dialog.java index 5eea59e46..5bc716d90 100644 --- a/src/main/java/noppes/npcs/controllers/data/Dialog.java +++ b/src/main/java/noppes/npcs/controllers/data/Dialog.java @@ -47,6 +47,7 @@ public class Dialog implements ICompatibilty, IDialog { public int textWidth = 300; public int textHeight = 400; + public int titlePos; public int textOffsetX, textOffsetY; public int titleOffsetX, titleOffsetY; @@ -128,6 +129,7 @@ public class Dialog implements ICompatibilty, IDialog { textHeight = compound.getInteger("TextHeight"); textOffsetX = compound.getInteger("TextOffsetX"); textOffsetY = compound.getInteger("TextOffsetY"); + titlePos = compound.getInteger("TitlePos"); titleOffsetX = compound.getInteger("TitleOffsetX"); titleOffsetY = compound.getInteger("TitleOffsetY"); optionOffsetX = compound.getInteger("OptionOffsetX"); @@ -206,6 +208,7 @@ public class Dialog implements ICompatibilty, IDialog { compound.setInteger("TextHeight", textHeight); compound.setInteger("TextOffsetX", textOffsetX); compound.setInteger("TextOffsetY", textOffsetY); + compound.setInteger("TitlePos", titlePos); compound.setInteger("TitleOffsetX", titleOffsetX); compound.setInteger("TitleOffsetY", titleOffsetY); compound.setInteger("OptionOffsetX", optionOffsetX); @@ -262,6 +265,7 @@ public class Dialog implements ICompatibilty, IDialog { dialog.textHeight = textHeight; dialog.textOffsetX = textOffsetX; dialog.textOffsetY = textOffsetY; + dialog.titlePos = titlePos; dialog.titleOffsetX = titleOffsetX; dialog.titleOffsetY = titleOffsetY; dialog.optionOffsetX = optionOffsetX; diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 4875768c4..046dc8f76 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -120,7 +120,6 @@ gui.id=ID gui.widthHeight=Width & Height gui.position=Position gui.screen=Screen -gui.text=Text gui.option=Option gui.default=Default gui.type=Type @@ -194,6 +193,7 @@ display.right=Right display.botLeft=Bottom Left display.botCenter=Bottom Center display.botRight=Bottom Right +display.fixed=Fixed inv.minExp=Min Exp inv.maxExp=Max Exp @@ -453,6 +453,7 @@ dialog.optionLine=Option Line dialog.npcScale=NPC Scale dialog.npcOffset=NPC Offset dialog.titleColor=Title Color +dialog.titlePos=Title Position quest.quest=Quest quest.quests=Quests From 8f16e6b20fd9493853d68f9076baaebc2f4ecb52 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Fri, 10 Jun 2022 17:25:58 -0500 Subject: [PATCH 33/40] Added IDialogImage, a scripted object which is used by IDialog. Used to add dialog images. IDialog: -Added several new functions for dialogs' new visual attributes, as well as a way to add, get, create, remove, and clear dialog images. Global NPC events: -Added fields and variables from the old ScriptEvent events, in preparation to replace the old events with NpcEvent instances on local NPC scripts. -Fixed issue where some event hooks would run on remote worlds. Global NPC killed event: -Added droppedItems and expDropped fields. IWorld and NpcAPI: -Now always uses a non-remove WorldServer object to create ScriptWorld objects and add them to the world cache. --- src/main/java/noppes/npcs/DataInventory.java | 111 +++++++----- src/main/java/noppes/npcs/EventHooks.java | 3 +- .../java/noppes/npcs/NoppesUtilPlayer.java | 23 +-- .../java/noppes/npcs/NoppesUtilServer.java | 9 +- .../client/gui/SubGuiNpcDialogVisual.java | 4 +- .../client/gui/player/GuiDialogInteract.java | 13 +- .../npcs/controllers/data/DataScript.java | 2 +- .../noppes/npcs/controllers/data/Dialog.java | 160 +++++++++++++++++- .../npcs/controllers/data/DialogImage.java | 139 ++++++++++++++- .../npcs/entity/EntityNPCInterface.java | 104 +++++++----- .../java/noppes/npcs/scripted/NpcAPI.java | 8 +- .../noppes/npcs/scripted/ScriptWorld.java | 11 +- .../npcs/scripted/entity/ScriptEntity.java | 5 +- .../noppes/npcs/scripted/event/NpcEvent.java | 154 ++++++++++++++++- .../scripted/interfaces/AbstractNpcAPI.java | 2 +- .../scripted/interfaces/entity/IEntity.java | 3 +- .../interfaces/handler/data/IDialog.java | 87 +++++++++- 17 files changed, 710 insertions(+), 128 deletions(-) diff --git a/src/main/java/noppes/npcs/DataInventory.java b/src/main/java/noppes/npcs/DataInventory.java index 924ebd969..9d2ff9c8e 100644 --- a/src/main/java/noppes/npcs/DataInventory.java +++ b/src/main/java/noppes/npcs/DataInventory.java @@ -93,7 +93,9 @@ public class DataInventory implements IInventory{ weapons.put(2, item); } - public void dropStuff(Entity entity, DamageSource damagesource) { + public ArrayList getDroppedItems(DamageSource damagesource) { + ArrayList drops = new ArrayList<>(); + ArrayList list = new ArrayList(); for (int i : items.keySet()) { ItemStack item = items.get(i); @@ -109,53 +111,76 @@ public class DataInventory implements IInventory{ list.add(e); } } - + for (EntityItem e : list) { + drops.add(e.getEntityItem()); + } + int enchant = 0; - if (damagesource.getEntity() instanceof EntityPlayer){ - enchant = EnchantmentHelper.getLootingModifier((EntityLivingBase)damagesource.getEntity()); - } - - if (!net.minecraftforge.common.ForgeHooks.onLivingDrops(npc, damagesource, list, enchant, true, 0)){ - for (EntityItem item : list){ - if(lootMode == 1 && entity instanceof EntityPlayer){ - EntityPlayer player = (EntityPlayer)entity; - item.delayBeforeCanPickup = 2; - npc.worldObj.spawnEntityInWorld(item); - ItemStack stack = item.getEntityItem(); - int i = stack.stackSize; + if (damagesource.getEntity() instanceof EntityPlayer){ + enchant = EnchantmentHelper.getLootingModifier((EntityLivingBase)damagesource.getEntity()); + } - if (player.inventory.addItemStackToInventory(stack)) { - npc.worldObj.playSoundAtEntity(item, - "random.pop", - 0.2F, - ((npc.getRNG().nextFloat() - npc.getRNG().nextFloat()) * 0.7F + 1.0F) * 2.0F); - player.onItemPickup(item, i); + if (!net.minecraftforge.common.ForgeHooks.onLivingDrops(npc, damagesource, list, enchant, true, 0)){ + return drops; + } else { + return new ArrayList<>(); + } + } - if (stack.stackSize <= 0) { - item.setDead(); - } - } - } - else - npc.worldObj.spawnEntityInWorld(item); - } - } - - int var1 = minExp; + public int getDroppedXp() { + int droppedXp = minExp; if (maxExp - minExp > 0) - var1 += npc.worldObj.rand.nextInt(maxExp - minExp); + droppedXp += npc.worldObj.rand.nextInt(maxExp - minExp); - while (var1 > 0){ - int var2 = EntityXPOrb.getXPSplit(var1); - var1 -= var2; - if(lootMode == 1 && entity instanceof EntityPlayer){ - npc.worldObj.spawnEntityInWorld(new EntityXPOrb(entity.worldObj, entity.posX, entity.posY, entity.posZ, var2)); - } - else{ - npc.worldObj.spawnEntityInWorld(new EntityXPOrb(npc.worldObj, npc.posX, npc.posY, npc.posZ, var2)); - } - } - + return droppedXp; + } + + public void dropXp(Entity entity, int droppedXp) { + while (droppedXp > 0){ + int var2 = EntityXPOrb.getXPSplit(droppedXp); + droppedXp -= var2; + if(lootMode == 1 && entity instanceof EntityPlayer){ + npc.worldObj.spawnEntityInWorld(new EntityXPOrb(entity.worldObj, entity.posX, entity.posY, entity.posZ, var2)); + } + else{ + npc.worldObj.spawnEntityInWorld(new EntityXPOrb(npc.worldObj, npc.posX, npc.posY, npc.posZ, var2)); + } + } + } + + public void dropItems(Entity entity, ArrayList itemList) { + ArrayList list = new ArrayList(); + for (ItemStack item : itemList) { + if(item == null) + continue; + EntityItem e = getEntityItem(item.copy()); + if(e != null) + list.add(e); + } + + for (EntityItem item : list){ + if(lootMode == 1 && entity instanceof EntityPlayer){ + EntityPlayer player = (EntityPlayer)entity; + item.delayBeforeCanPickup = 2; + npc.worldObj.spawnEntityInWorld(item); + ItemStack stack = item.getEntityItem(); + int i = stack.stackSize; + + if (player.inventory.addItemStackToInventory(stack)) { + npc.worldObj.playSoundAtEntity(item, + "random.pop", + 0.2F, + ((npc.getRNG().nextFloat() - npc.getRNG().nextFloat()) * 0.7F + 1.0F) * 2.0F); + player.onItemPickup(item, i); + + if (stack.stackSize <= 0) { + item.setDead(); + } + } + } + else + npc.worldObj.spawnEntityInWorld(item); + } } public EntityItem getEntityItem(ItemStack itemstack) { diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 4da9356f7..564196051 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -236,11 +236,10 @@ public class EventHooks { return result; } - public static boolean onNPCKilled(EntityNPCInterface npc, DamageSource damagesource, Entity entity, ScriptEventKilled killedEvent){ + public static boolean onNPCKilled(EntityNPCInterface npc, NpcEvent.DiedEvent event, ScriptEventKilled killedEvent){ if(npc == null || npc.wrappedNPC == null) return false; - NpcEvent.DiedEvent event = new NpcEvent.DiedEvent(npc.wrappedNPC,damagesource,entity); ScriptController.Instance.npcScripts.callScript(EnumScriptType.KILLED, event); boolean result = npc.script.callScript(EnumScriptType.KILLED, "event", killedEvent); NpcAPI.EVENT_BUS.post(event); diff --git a/src/main/java/noppes/npcs/NoppesUtilPlayer.java b/src/main/java/noppes/npcs/NoppesUtilPlayer.java index 8357d655a..200240b78 100644 --- a/src/main/java/noppes/npcs/NoppesUtilPlayer.java +++ b/src/main/java/noppes/npcs/NoppesUtilPlayer.java @@ -259,18 +259,19 @@ public class NoppesUtilPlayer { Dialog dialog = DialogController.instance.dialogs.get(dialogId); if(dialog == null) return; - - EventHooks.onDialogOption(new DialogEvent.DialogOption((IPlayer) NpcAPI.Instance().getIEntity(player), dialog)); - EventHooks.onNPCDialogClosed(npc,player,dialogId,optionId+1,dialog); - - if(!dialog.hasDialogs(player) && !dialog.hasOtherOptions()) { - EventHooks.onDialogClosed(new DialogEvent.DialogClosed((IPlayer) NpcAPI.Instance().getIEntity(player), dialog)); - return; - } DialogOption option = dialog.options.get(optionId); - if(option == null || option.optionType == EnumOptionType.DialogOption && (!option.isAvailable(player) || !option.hasDialog()) || option.optionType == EnumOptionType.Disabled || option.optionType == EnumOptionType.QuitOption) { - EventHooks.onDialogClosed(new DialogEvent.DialogClosed((IPlayer) NpcAPI.Instance().getIEntity(player), dialog)); - return; + if (!npc.isRemote()) { + EventHooks.onDialogOption(new DialogEvent.DialogOption((IPlayer) NpcAPI.Instance().getIEntity(player), dialog)); + EventHooks.onNPCDialogClosed(npc, player, dialogId, optionId + 1, dialog); + + if (!dialog.hasDialogs(player) && !dialog.hasOtherOptions()) { + EventHooks.onDialogClosed(new DialogEvent.DialogClosed((IPlayer) NpcAPI.Instance().getIEntity(player), dialog)); + return; + } + if (option == null || option.optionType == EnumOptionType.DialogOption && (!option.isAvailable(player) || !option.hasDialog()) || option.optionType == EnumOptionType.Disabled || option.optionType == EnumOptionType.QuitOption) { + EventHooks.onDialogClosed(new DialogEvent.DialogClosed((IPlayer) NpcAPI.Instance().getIEntity(player), dialog)); + return; + } } if(option.optionType == EnumOptionType.RoleOption){ if(npc.roleInterface != null) diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index c56bff429..363d31516 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -181,7 +181,9 @@ public class NoppesUtilServer { public static void openDialog(EntityPlayer player, EntityNPCInterface npc, Dialog dia, int optionId){ Dialog dialog = dia.copy(player); - EventHooks.onDialogOpen(new DialogEvent.DialogOpen((IPlayer) NpcAPI.Instance().getIEntity(player), dialog)); + if (!npc.isRemote()) { + EventHooks.onDialogOpen(new DialogEvent.DialogOpen((IPlayer) NpcAPI.Instance().getIEntity(player), dialog)); + } if(npc instanceof EntityDialogNpc){ dialog.hideNPC = true; @@ -201,7 +203,10 @@ public class NoppesUtilServer { if(!data.dialogsRead.contains(dialog.id)) data.dialogsRead.add(dialog.id); setEditingNpc(player, npc); - EventHooks.onNPCDialog(npc, player, dialog.id, optionId, dialog); + + if (!npc.isRemote()) { + EventHooks.onNPCDialog(npc, player, dialog.id, optionId, dialog); + } } public static void runCommand(EntityPlayer player, String name, String command){ runCommand(player, name, command, player); diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java index 78be626bf..c44832313 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java @@ -325,7 +325,7 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis if (button.id == 1) { int addId = 0; if (selected != -1 && imageScroll.getSelected() != null) { - DialogImage selectedImage = dialog.dialogImages.get(Integer.valueOf(imageScroll.getSelected())); + DialogImage selectedImage = (DialogImage) dialog.dialogImages.get(Integer.valueOf(imageScroll.getSelected())); ArrayList keys = new ArrayList<>(dialog.dialogImages.keySet()); int keyIndex = keys.indexOf(selectedImage.id); do { @@ -417,7 +417,7 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis private DialogImage getSelectedImage() { if (selected > -1) { - return dialog.dialogImages.get((dialog.dialogImages.keySet().toArray(new Integer[0]))[selected]); + return (DialogImage) dialog.dialogImages.get((dialog.dialogImages.keySet().toArray(new Integer[0]))[selected]); } else { return null; } diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index 47490533e..0ac6df680 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -28,6 +28,7 @@ import noppes.npcs.controllers.data.DialogImage; import noppes.npcs.controllers.data.DialogOption; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.scripted.interfaces.handler.data.IDialogImage; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; @@ -165,8 +166,8 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose drawString(fontRendererObj, "Text Sound: " + (textSoundEnabled ? "On" : "Off"), 10, 20, 0xFFFFFF); } - for (DialogImage dialogImage : dialog.dialogImages.values()) { - GuiDialogImage image = new GuiDialogImage(dialogImage); + for (IDialogImage dialogImage : dialog.dialogImages.values()) { + GuiDialogImage image = new GuiDialogImage((DialogImage) dialogImage); if (image.imageType != 0) continue; @@ -184,8 +185,8 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose } GL11.glPushMatrix(); - for (DialogImage dialogImage : dialog.dialogImages.values()) { - GuiDialogImage image = new GuiDialogImage(dialogImage); + for (IDialogImage dialogImage : dialog.dialogImages.values()) { + GuiDialogImage image = new GuiDialogImage((DialogImage) dialogImage); if (image.imageType != 1) continue; @@ -447,8 +448,8 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose } GL11.glPushMatrix(); - for (DialogImage dialogImage : dialog.dialogImages.values()) { - GuiDialogImage image = new GuiDialogImage(dialogImage); + for (IDialogImage dialogImage : dialog.dialogImages.values()) { + GuiDialogImage image = new GuiDialogImage((DialogImage) dialogImage); if (image.imageType != 2) continue; diff --git a/src/main/java/noppes/npcs/controllers/data/DataScript.java b/src/main/java/noppes/npcs/controllers/data/DataScript.java index 1fdaee109..a300229cf 100644 --- a/src/main/java/noppes/npcs/controllers/data/DataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/DataScript.java @@ -116,7 +116,7 @@ public class DataScript implements IScriptHandler { } if(!isEnabled()) return false; - if(!hasInited){ + if(!hasInited && !npc.isRemote()){ hasInited = true; EventHooks.onNPCInit(this.npc); callScript(EnumScriptType.INIT); diff --git a/src/main/java/noppes/npcs/controllers/data/Dialog.java b/src/main/java/noppes/npcs/controllers/data/Dialog.java index 5bc716d90..01cfa4ece 100644 --- a/src/main/java/noppes/npcs/controllers/data/Dialog.java +++ b/src/main/java/noppes/npcs/controllers/data/Dialog.java @@ -57,7 +57,7 @@ public class Dialog implements ICompatibilty, IDialog { public float npcScale = 1.0F; public int npcOffsetX, npcOffsetY; - public HashMap dialogImages = new HashMap<>(); + public HashMap dialogImages = new HashMap<>(); public boolean hasDialogs(EntityPlayer player) { for(DialogOption option: options.values()) @@ -108,7 +108,7 @@ public class Dialog implements ICompatibilty, IDialog { this.options = newoptions; NBTTagList images = compound.getTagList("Images", 10); - HashMap newImages = new HashMap<>(); + HashMap newImages = new HashMap<>(); for(int i = 0; i < images.tagCount(); i++){ NBTTagCompound imageCompound = images.getCompoundTagAt(i); int id = imageCompound.getInteger("ID"); @@ -220,8 +220,8 @@ public class Dialog implements ICompatibilty, IDialog { compound.setInteger("NPCOffsetY", npcOffsetY); NBTTagList images = new NBTTagList(); - for (DialogImage dialogImage : dialogImages.values()) { - NBTTagCompound imageCompound = dialogImage.writeToNBT(new NBTTagCompound()); + for (IDialogImage dialogImage : dialogImages.values()) { + NBTTagCompound imageCompound = ((DialogImage) dialogImage).writeToNBT(new NBTTagCompound()); images.appendTag(imageCompound); } compound.setTag("Images",images); @@ -398,4 +398,156 @@ public class Dialog implements ICompatibilty, IDialog { public String getSound() { return this.sound; } + + public void setColor(int color) { + this.color = color; + } + public int getColor() { + return this.color; + } + + public void setTitleColor(int titleColor) { + this.titleColor = titleColor; + } + public int getTitleColor() { + return titleColor; + } + + public void renderGradual(boolean gradual) { + this.renderGradual = gradual; + } + public boolean renderGradual() { + return renderGradual; + } + + public void showPreviousBlocks(boolean show) { + this.showPreviousBlocks = show; + } + public boolean showPreviousBlocks() { + return showPreviousBlocks; + } + + public void showOptionLine(boolean show) { + this.showOptionLine = show; + } + public boolean showOptionLine() { + return showOptionLine; + } + + public void setTextSound(String textSound) { + this.textSound = textSound; + } + public String getTextSound() { + return textSound; + } + + public void setTextPitch(float textPitch) { + this.textPitch = textPitch; + } + public float getTextPitch() { + return textPitch; + } + + public void setTitlePos(int pos) { + this.titlePos = pos; + } + public int getTitlePos() { + return this.titlePos; + } + + public void setNPCScale(float scale) { + this.npcScale = scale; + } + public float getNpcScale() { + return npcScale; + } + + public void setNpcOffset(int offsetX, int offsetY) { + this.npcOffsetX = offsetX; + this.npcOffsetY = offsetY; + } + public int getNpcOffsetX() { + return npcOffsetX; + } + public int getNpcOffsetY() { + return npcOffsetY; + } + + public void textWidthHeight(int textWidth, int textHeight) { + this.textWidth = textWidth; + this.textHeight = textHeight; + } + public int getTextWidth() { + return textWidth; + } + public int setTextHeight() { + return textHeight; + } + + public void setTextOffset(int offsetX, int offsetY) { + this.textOffsetX = offsetX; + this.textOffsetY = offsetY; + } + public int getTextOffsetX() { + return textOffsetX; + } + public int getTextOffsetY() { + return textOffsetY; + } + + public void setTitleOffset(int offsetX, int offsetY) { + this.titleOffsetX = offsetX; + this.titleOffsetY = offsetY; + } + public int getTitleOffsetX() { + return titleOffsetX; + } + public int getTitleOffsetY() { + return titleOffsetY; + } + + public void setOptionOffset(int offsetX, int offsetY) { + this.optionOffsetX = offsetX; + this.optionOffsetY = offsetY; + } + public int getOptionOffsetX() { + return optionOffsetX; + } + public int getOptionOffsetY() { + return optionOffsetY; + } + + public void setOptionSpacing(int spaceX, int spaceY) { + this.optionSpaceX = spaceX; + this.optionSpaceY = spaceY; + } + public int getOptionSpaceX() { + return optionSpaceX; + } + public int getOptionSpaceY() { + return optionSpaceY; + } + + public void addImage(int id, IDialogImage image) { + ((DialogImage) image).id = id; + dialogImages.put(id, image); + } + public IDialogImage getImage(int id) { + return dialogImages.get(id); + } + public IDialogImage createImage() { + return new DialogImage(); + } + public IDialogImage[] getImages() { + return (new ArrayList<>(dialogImages.values())).toArray(new IDialogImage[0]); + } + public boolean hasImage(int id) { + return dialogImages.containsKey(id); + } + public void removeImage(int id) { + dialogImages.remove(id); + } + public void clearImages() { + dialogImages.clear(); + } } diff --git a/src/main/java/noppes/npcs/controllers/data/DialogImage.java b/src/main/java/noppes/npcs/controllers/data/DialogImage.java index e02957fda..068836a8c 100644 --- a/src/main/java/noppes/npcs/controllers/data/DialogImage.java +++ b/src/main/java/noppes/npcs/controllers/data/DialogImage.java @@ -1,8 +1,9 @@ package noppes.npcs.controllers.data; import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.scripted.interfaces.handler.data.IDialogImage; -public class DialogImage { +public class DialogImage implements IDialogImage { public int id; public String texture = ""; public int x = 0; @@ -21,6 +22,9 @@ public class DialogImage { public int imageType = 1; //0 - Default, 1 - Text, 2 - Option public int alignment = 0; + public DialogImage() { + } + public DialogImage(int id) { this.id = id; } @@ -62,4 +66,137 @@ public class DialogImage { imageType = compound.getInteger("ImageType"); alignment = compound.getInteger("Alignment"); } + + @Override + public int getId() { + return id; + } + + @Override + public void setTexture(String texture) { + this.texture = texture; + } + + @Override + public String getTexture() { + return texture; + } + + @Override + public void setPosition(int x, int y) { + this.x = x; + this.y = y; + } + + @Override + public int getX() { + return x; + } + + @Override + public int getY() { + return y; + } + + @Override + public void setWidthHeight(int width, int height) { + this.width = width; + this.height = height; + } + + @Override + public int getWidth() { + return width; + } + + @Override + public int getHeight() { + return height; + } + + @Override + public void setTextureOffset(int offsetX, int offsetY) { + this.textureX = offsetX; + this.textureY = offsetY; + } + + @Override + public int getTextureX() { + return textureX; + } + + @Override + public int getTextureY() { + return textureY; + } + + @Override + public void setColor(int color) { + this.color = color; + } + + @Override + public int getColor() { + return color; + } + + @Override + public void setSelectedColor(int color) { + this.selectedColor = color; + } + + @Override + public int getSelectedColor() { + return selectedColor; + } + + @Override + public void setScale(float scale) { + this.scale = scale; + } + + @Override + public float getScale() { + return scale; + } + + @Override + public void setAlpha(float alpha) { + this.alpha = alpha; + } + + @Override + public float getAlpha() { + return alpha; + } + + @Override + public void setRotation(float rotation) { + this.rotation = rotation; + } + + @Override + public float getRotation() { + return rotation; + } + + @Override + public void setImageType(int imageType) { + this.imageType = imageType; + } + + @Override + public int getImageType() { + return imageType; + } + + @Override + public void setAlignment(int alignment) { + this.alignment = alignment; + } + + @Override + public int getAlignment() { + return alignment; + } } diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index b637b4f17..ba0a1a3b9 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -75,11 +75,9 @@ import noppes.npcs.roles.RoleCompanion; import noppes.npcs.roles.RoleFollower; import noppes.npcs.roles.RoleInterface; import noppes.npcs.scripted.entity.ScriptNpc; -import noppes.npcs.scripted.event.ScriptEventAttack; -import noppes.npcs.scripted.event.ScriptEventDamaged; -import noppes.npcs.scripted.event.ScriptEventKilled; -import noppes.npcs.scripted.event.ScriptEventTarget; +import noppes.npcs.scripted.event.*; import noppes.npcs.scripted.interfaces.entity.ICustomNpc; +import noppes.npcs.scripted.interfaces.item.IItemStack; import noppes.npcs.util.GameProfileAlt; import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData; @@ -211,10 +209,12 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti @Override public void onUpdate(){ super.onUpdate(); - if(this.ticksExisted % 10 == 0) { - EventHooks.onNPCUpdate(this); + if (!isRemote()) { + if (this.ticksExisted % 10 == 0) { + EventHooks.onNPCUpdate(this); + } + this.timers.update(); } - this.timers.update(); } public void setWorld(World world){ @@ -234,7 +234,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti if (stats.attackSpeed < 10){ par1Entity.hurtResistantTime = 0; } - if(par1Entity instanceof EntityLivingBase){ + if(par1Entity instanceof EntityLivingBase && !isRemote()){ ScriptEventAttack event = new ScriptEventAttack(f, (EntityLivingBase)par1Entity, false); if(EventHooks.onNPCMeleeAttack(this, f, (EntityLivingBase)par1Entity)) return false; @@ -542,20 +542,22 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti public void setAttackTarget(EntityLivingBase entity){ if(entity instanceof EntityPlayer && ((EntityPlayer)entity).capabilities.disableDamage || entity != null && entity == getOwner()) return; - if(getAttackTarget() != entity && entity != null){ - ScriptEventTarget event = new ScriptEventTarget(entity); - if(EventHooks.onNPCTarget(this,entity)) - return; - - if(event.getTarget() == null) - entity = null; - else - entity = event.getTarget().getMCEntity(); - } - if (entity != null && entity != this && ai.onAttack != 3 && !isAttacking() && !isRemote()){ - Line line = advanced.getAttackLine(); - if(line != null) - saySurrounding(line.formatTarget(entity)); + if (!isRemote()) { + if (getAttackTarget() != entity && entity != null) { + ScriptEventTarget event = new ScriptEventTarget(entity); + if (EventHooks.onNPCTarget(this, entity)) + return; + + if (event.getTarget() == null) + entity = null; + else + entity = event.getTarget().getMCEntity(); + } + if (entity != null && entity != this && ai.onAttack != 3 && !isAttacking()) { + Line line = advanced.getAttackLine(); + if (line != null) + saySurrounding(line.formatTarget(entity)); + } } super.setAttackTarget(entity); @@ -568,16 +570,16 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti updateTasks(); return; } - ScriptEventAttack event = new ScriptEventAttack(stats.pDamage, entity, true); - if(EventHooks.onNPCRangedAttack(this, f, (EntityLivingBase)entity)) - return; - for(int i = 0; i < this.stats.shotCount; i++) - { - EntityProjectile projectile = shoot(entity, stats.accuracy, proj, f == 1); - projectile.damage = event.getDamage(); + if (!isRemote()) { + ScriptEventAttack event = new ScriptEventAttack(stats.pDamage, entity, true); + if (EventHooks.onNPCRangedAttack(this, f, (EntityLivingBase) entity)) + return; + for (int i = 0; i < this.stats.shotCount; i++) { + EntityProjectile projectile = shoot(entity, stats.accuracy, proj, f == 1); + projectile.damage = event.getDamage(); + } + this.playSound(this.stats.fireSound, 2.0F, 1.0f); } - this.playSound(this.stats.fireSound, 2.0F, 1.0f); - } public EntityProjectile shoot(EntityLivingBase entity, int accuracy, ItemStack proj, boolean indirect){ @@ -1052,7 +1054,9 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti if(jobInterface != null) jobInterface.reset(); - EventHooks.onNPCInit(this); + if (!isRemote()) { + EventHooks.onNPCInit(this); + } } public void onCollide() { @@ -1072,12 +1076,14 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti if(list == null) return; - for (int i = 0; i < list.size(); ++i){ - Entity entity = (Entity)list.get(i); - if (entity.isEntityAlive()) { - EventHooks.onNPCCollide(this,entity); + if (!isRemote()) { + for (int i = 0; i < list.size(); ++i) { + Entity entity = (Entity) list.get(i); + if (entity.isEntityAlive()) { + EventHooks.onNPCCollide(this, entity); + } } - } + } } @@ -1202,12 +1208,26 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti else if ((entity instanceof EntityThrowable)) attackingEntity = ((EntityThrowable) entity).getThrower(); - ScriptEventKilled result = new ScriptEventKilled(attackingEntity, damagesource); - if(EventHooks.onNPCKilled(this,damagesource,attackingEntity,result)) - return; + + int droppedXp = inventory.getDroppedXp(); + ArrayList droppedItems = inventory.getDroppedItems(damagesource); + if(!isRemote()){ - if(this.recentlyHit > 0) - inventory.dropStuff(entity, damagesource); + ScriptEventKilled result = new ScriptEventKilled(attackingEntity, damagesource); + NpcEvent.DiedEvent event = new NpcEvent.DiedEvent(this.wrappedNPC,damagesource,entity,droppedItems, droppedXp); + if(EventHooks.onNPCKilled(this, event, result)) + return; + + droppedItems.clear(); + for (IItemStack iItemStack : event.droppedItems) { + droppedItems.add(iItemStack.getMCItemStack()); + } + droppedXp = event.expDropped; + + if(this.recentlyHit > 0) { + inventory.dropItems(entity, droppedItems); + inventory.dropXp(entity, droppedXp); + } Line line = advanced.getKilledLine(); if(line != null) saySurrounding(line.formatTarget(attackingEntity)); diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index 5afa158e2..cbf368d20 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -207,13 +207,13 @@ public class NpcAPI extends AbstractNpcAPI { return getIItemStack(new ItemStack(item, size, damage)); } - public IWorld getIWorld(WorldServer world) { - ScriptWorld w = (ScriptWorld)worldCache.get(world.provider.dimensionId); + public IWorld getIWorld(World world) { + ScriptWorld w = worldCache.get(world.provider.dimensionId); if (w != null) { - w.world = world; + w.world.provider.dimensionId = world.provider.dimensionId; return w; } else { - worldCache.put(world.provider.dimensionId, w = ScriptWorld.createNew(world)); + worldCache.put(world.provider.dimensionId, w = ScriptWorld.createNew(world.provider.dimensionId)); return w; } } diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index 9c01455ee..77eb0cc8b 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -21,6 +21,7 @@ import net.minecraft.tileentity.TileEntitySign; import net.minecraft.util.Vec3; import net.minecraft.util.math.BlockPos; import net.minecraft.world.WorldServer; +import noppes.npcs.CustomNpcs; import noppes.npcs.NoppesUtilServer; import noppes.npcs.blocks.tiles.TileBigSign; import noppes.npcs.controllers.ScriptController; @@ -41,7 +42,15 @@ public class ScriptWorld implements IWorld { this.world = world; } - public static ScriptWorld createNew(WorldServer world) { + public static ScriptWorld createNew(int dimensionId) { + WorldServer[] worlds = CustomNpcs.getServer().worldServers; + + WorldServer world = worlds[0]; + for (WorldServer w : worlds) { + if (w.provider.dimensionId == dimensionId) { + world = w; + } + } return new ScriptWorld(world); } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java index 4bdbe7951..72e94f68c 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java @@ -29,6 +29,7 @@ import noppes.npcs.scripted.ScriptBlockPos; import noppes.npcs.scripted.ScriptWorld; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.interfaces.IParticle; +import noppes.npcs.scripted.interfaces.IWorld; import noppes.npcs.scripted.interfaces.entity.IEntity; import noppes.npcs.scripted.interfaces.INbt; import noppes.npcs.scripted.interfaces.IPos; @@ -755,7 +756,7 @@ public class ScriptEntity implements IEntity { } } - public ScriptWorld getWorld() { - return (ScriptWorld) NpcAPI.Instance().getIWorld((WorldServer) entity.worldObj); + public IWorld getWorld() { + return NpcAPI.Instance().getIWorld(entity.worldObj); } } \ No newline at end of file diff --git a/src/main/java/noppes/npcs/scripted/event/NpcEvent.java b/src/main/java/noppes/npcs/scripted/event/NpcEvent.java index e1a5c69f0..56f4ecff1 100644 --- a/src/main/java/noppes/npcs/scripted/event/NpcEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/NpcEvent.java @@ -9,6 +9,7 @@ import cpw.mods.fml.common.eventhandler.Cancelable; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; import noppes.npcs.controllers.data.Dialog; import noppes.npcs.scripted.interfaces.*; @@ -19,6 +20,8 @@ import noppes.npcs.scripted.interfaces.entity.IPlayer; import noppes.npcs.scripted.interfaces.item.IItemStack; import noppes.npcs.scripted.NpcAPI; +import java.util.ArrayList; + public class NpcEvent extends CustomNPCsEvent { public final ICustomNpc npc; @@ -33,6 +36,10 @@ public class NpcEvent extends CustomNPCsEvent { super(npc); this.id = id; } + + public int getId(){ + return id; + } } public static class CollideEvent extends NpcEvent { @@ -49,13 +56,49 @@ public class NpcEvent extends CustomNPCsEvent { public final IDamageSource damageSource; public final IEntity source; public float damage; - public boolean clearTarget = false; + private boolean clearTarget = false; + + public boolean clear = false; + public final DamageSource damagesource; public DamagedEvent(ICustomNpc npc, Entity source, float damage, DamageSource damagesource) { super(npc); this.source = NpcAPI.Instance().getIEntity(source); this.damage = damage; this.damageSource = NpcAPI.Instance().getIDamageSource(damagesource); + + //Old CNPC Script compatibility + this.damagesource = damagesource; + } + + /** + * @return The source of the damage + */ + public IEntity getSource(){ + return source; + } + + /** + * @return Returns the damage value + */ + public float getDamage(){ + return damage; + } + + /** + * @param damage The new damage value + */ + public void setDamage(float damage){ + this.damage = damage; + } + + public void setClearTarget(boolean bo){ + this.clearTarget = bo; + this.clear = bo; + } + + public boolean getClearTarget(){ + return clearTarget && clear; } public String getType(){ @@ -103,13 +146,33 @@ public class NpcEvent extends CustomNPCsEvent { public IItemStack[] droppedItems; public int expDropped; - public DiedEvent(ICustomNpc npc, DamageSource damagesource, Entity entity) { + public DiedEvent(ICustomNpc npc, DamageSource damagesource, Entity entity, ArrayList droppedItems, int expDropped) { super(npc); this.damageSource = NpcAPI.Instance().getIDamageSource(damagesource); this.type = damagesource.damageType; this.source = NpcAPI.Instance().getIEntity(entity); + + ArrayList iItemStacks = new ArrayList<>(); + for (ItemStack itemStack : droppedItems) { + IItemStack iItemStack = NpcAPI.Instance().getIItemStack(itemStack); + iItemStacks.add(iItemStack); + } + this.droppedItems = iItemStacks.toArray(new IItemStack[0]); + this.expDropped = expDropped; } + /** + * @return The source of the damage + */ + public IEntity getSource(){ + return source; + } + + public IDamageSource getDamageSource() { return damageSource; } + + /** + * @return Returns the damage type + */ public String getType(){ return damageSource.getMCDamageSource().damageType; } @@ -129,14 +192,43 @@ public class NpcEvent extends CustomNPCsEvent { public final IPlayer player; public final int id; public final int optionId; - public final Dialog dialog; + public final Dialog dialogObj; + + public final int dialog; + public final int option; public DialogEvent(ICustomNpc npc, EntityPlayer player, int id, int optionId, Dialog dialog) { super(npc); this.player = (IPlayer)NpcAPI.Instance().getIEntity(player); this.id = id; this.optionId = optionId; - this.dialog = dialog; + this.dialogObj = dialog; + + this.dialog = id; + this.option = optionId; + } + + public IPlayer getPlayer() { + return player; + } + + public Dialog getDialog() { + return dialogObj; + } + + public int getDialogId() { + return dialog; + } + + public int getOptionId() { + return option; + } + + /** + * @deprecated + */ + public boolean isClosing(){ + return true; } } @@ -173,6 +265,17 @@ public class NpcEvent extends CustomNPCsEvent { super(npc); this.entity = (IEntityLivingBase) NpcAPI.Instance().getIEntity(entity); } + + /** + * @return The target source + */ + public IEntityLivingBase getTarget(){ + return entity; + } + + public void setTarget(IEntityLivingBase entity){ + this.entity = entity; + } } public static class UpdateEvent extends NpcEvent { @@ -186,4 +289,47 @@ public class NpcEvent extends CustomNPCsEvent { super(npc); } } + + public static class AttackEvent extends NpcEvent{ + private float damage; + private IEntityLivingBase target; + private boolean isRanged; + + public AttackEvent(ICustomNpc npc, float damage, EntityLivingBase target, boolean isRanged){ + super(npc); + this.damage = damage; + this.isRanged = isRanged; + this.target = (IEntityLivingBase) NpcAPI.Instance().getIEntity(target); + } + + /** + * @return The source of the damage + * @deprecated + */ + public IEntityLivingBase getTarget(){ + return target; + } + + + /** + * @return Returns the damage value + */ + public float getDamage(){ + return damage; + } + + /** + * @param damage The new damage value + */ + public void setDamage(float damage){ + this.damage = damage; + } + + /** + * @return Returns the damage type + */ + public boolean isRange(){ + return isRanged; + } + } } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java b/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java index 81d8ad3c3..2a169f994 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java @@ -77,7 +77,7 @@ public abstract class AbstractNpcAPI { public abstract IItemStack getIItemStack(ItemStack var1); - public abstract IWorld getIWorld(WorldServer var1); + public abstract IWorld getIWorld(World var1); public abstract IWorld getIWorld(int var1); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntity.java b/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntity.java index 0c266d515..2d35aaf9c 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntity.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntity.java @@ -10,6 +10,7 @@ import noppes.npcs.scripted.ScriptWorld; import noppes.npcs.scripted.interfaces.INbt; import noppes.npcs.scripted.interfaces.IParticle; import noppes.npcs.scripted.interfaces.IPos; +import noppes.npcs.scripted.interfaces.IWorld; import noppes.npcs.scripted.interfaces.item.IItemStack; public interface IEntity { @@ -342,5 +343,5 @@ public interface IEntity { void storeAsClone(int tab, String name); - ScriptWorld getWorld(); + IWorld getWorld(); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IDialog.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IDialog.java index e7e5bb6cc..21f8cf9e5 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IDialog.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IDialog.java @@ -4,7 +4,6 @@ // package noppes.npcs.scripted.interfaces.handler.data; - import java.util.List; public interface IDialog { @@ -50,4 +49,90 @@ public interface IDialog { String getSound(); void save(); + + void setColor(int color); + + int getColor(); + + void setTitleColor(int titleColor); + + int getTitleColor(); + + void renderGradual(boolean gradual); + + boolean renderGradual(); + + void showPreviousBlocks(boolean show); + + boolean showPreviousBlocks(); + + void showOptionLine(boolean show); + + boolean showOptionLine(); + + void setTextSound(String textSound); + + String getTextSound(); + + void setTextPitch(float textPitch); + + float getTextPitch(); + + void setTitlePos(int pos); + + int getTitlePos(); + + void setNPCScale(float scale); + + float getNpcScale(); + + void setNpcOffset(int offsetX, int offsetY); + + int getNpcOffsetX(); + + int getNpcOffsetY(); + + void textWidthHeight(int textWidth, int textHeight); + + int getTextWidth(); + + int setTextHeight(); + + void setTextOffset(int offsetX, int offsetY); + + int getTextOffsetX(); + + int getTextOffsetY(); + + void setTitleOffset(int offsetX, int offsetY); + + int getTitleOffsetX(); + + int getTitleOffsetY(); + + void setOptionOffset(int offsetX, int offsetY); + + int getOptionOffsetX(); + + int getOptionOffsetY(); + + void setOptionSpacing(int spaceX, int spaceY); + + int getOptionSpaceX(); + + int getOptionSpaceY(); + + void addImage(int id, IDialogImage image); + + IDialogImage getImage(int id); + + IDialogImage createImage(); + + IDialogImage[] getImages(); + + boolean hasImage(int id); + + void removeImage(int id); + + void clearImages(); } From 9c29aabea8a52c6324a00624009d2ef68a06ad5d Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Fri, 10 Jun 2022 18:32:42 -0500 Subject: [PATCH 34/40] Merged local and global NPC events, deleting old unused event classes. --- src/main/java/noppes/npcs/EventHooks.java | 60 +++----- .../npcs/controllers/data/DataScript.java | 22 +-- .../npcs/entity/EntityNPCInterface.java | 23 ++- .../noppes/npcs/scripted/event/NpcEvent.java | 136 ++++++++++++------ .../npcs/scripted/event/ScriptEvent.java | 22 --- .../scripted/event/ScriptEventAttack.java | 48 ------- .../scripted/event/ScriptEventDamaged.java | 56 -------- .../scripted/event/ScriptEventDialog.java | 43 ------ .../scripted/event/ScriptEventKilled.java | 33 ----- .../scripted/event/ScriptEventTarget.java | 26 ---- .../npcs/scripted/event/ScriptEventTimer.java | 13 -- 11 files changed, 132 insertions(+), 350 deletions(-) delete mode 100644 src/main/java/noppes/npcs/scripted/event/ScriptEvent.java delete mode 100644 src/main/java/noppes/npcs/scripted/event/ScriptEventAttack.java delete mode 100644 src/main/java/noppes/npcs/scripted/event/ScriptEventDamaged.java delete mode 100644 src/main/java/noppes/npcs/scripted/event/ScriptEventDialog.java delete mode 100644 src/main/java/noppes/npcs/scripted/event/ScriptEventKilled.java delete mode 100644 src/main/java/noppes/npcs/scripted/event/ScriptEventTarget.java delete mode 100644 src/main/java/noppes/npcs/scripted/event/ScriptEventTimer.java diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 564196051..3a2b2d5dc 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -121,7 +121,7 @@ public class EventHooks { noppes.npcs.scripted.event.NpcEvent.InitEvent event = new noppes.npcs.scripted.event.NpcEvent.InitEvent(npc.wrappedNPC); ScriptController.Instance.npcScripts.callScript(EnumScriptType.INIT, event); - npc.script.callScript(EnumScriptType.INIT); + npc.script.callScript(EnumScriptType.INIT, event); NpcAPI.EVENT_BUS.post(event); } @@ -131,7 +131,7 @@ public class EventHooks { noppes.npcs.scripted.event.NpcEvent.UpdateEvent event = new noppes.npcs.scripted.event.NpcEvent.UpdateEvent(npc.wrappedNPC); ScriptController.Instance.npcScripts.callScript(EnumScriptType.TICK, event); - npc.script.callScript(EnumScriptType.TICK); + npc.script.callScript(EnumScriptType.TICK, event); NpcAPI.EVENT_BUS.post(event); } @@ -141,9 +141,7 @@ public class EventHooks { NpcEvent.DialogEvent event = new NpcEvent.DialogEvent(npc.wrappedNPC, player, dialogId, optionId, dialog); ScriptController.Instance.npcScripts.callScript(EnumScriptType.DIALOG, event); - - ScriptEventDialog npcEvent = new ScriptEventDialog(player,dialogId,optionId,dialog); - npc.script.callScript(EnumScriptType.DIALOG, "event", npcEvent, "player", npcEvent.getPlayer(), "dialog", npcEvent.getDialogId(), "option", npcEvent.getOptionId(), "dialogObj", npcEvent.getDialog()); + npc.script.callScript(EnumScriptType.DIALOG, event, "player", event.getPlayer(), "dialog", event.getDialogId(), "option", event.getOptionId(), "dialogObj", event.getDialog()); NpcAPI.EVENT_BUS.post(event); } @@ -154,9 +152,7 @@ public class EventHooks { NpcEvent.DialogClosedEvent event = new NpcEvent.DialogClosedEvent(npc.wrappedNPC, player, dialogId, optionId, dialog); ScriptController.Instance.npcScripts.callScript(EnumScriptType.DIALOG_CLOSE, event); - - ScriptEventDialog npcEvent = new ScriptEventDialog(player,dialogId,optionId,dialog); - npc.script.callScript(EnumScriptType.DIALOG_CLOSE, "event", npcEvent, "player", npcEvent.getPlayer(), "dialog", npcEvent.getDialogId(), "option", npcEvent.getOptionId(), "dialogObj", npcEvent.getDialog()); + npc.script.callScript(EnumScriptType.DIALOG_CLOSE, event, "player", event.getPlayer(), "dialog", event.getDialogId(), "option", event.getOptionId(), "dialogObj", event.getDialog()); NpcAPI.EVENT_BUS.post(event); } @@ -167,31 +163,27 @@ public class EventHooks { NpcEvent.InteractEvent event = new NpcEvent.InteractEvent(npc.wrappedNPC,player); ScriptController.Instance.npcScripts.callScript(EnumScriptType.INTERACT, event); - boolean result = npc.script.callScript(EnumScriptType.INTERACT, "player", player); + boolean result = npc.script.callScript(EnumScriptType.INTERACT, event, "player", player); NpcAPI.EVENT_BUS.post(event); return result; } - public static boolean onNPCMeleeAttack(EntityNPCInterface npc, float damage, EntityLivingBase target){ + public static boolean onNPCMeleeAttack(EntityNPCInterface npc, NpcEvent.MeleeAttackEvent event){ if(npc == null || npc.wrappedNPC == null) return false; - NpcEvent.MeleeAttackEvent event = new NpcEvent.MeleeAttackEvent(npc.wrappedNPC,damage,target); ScriptController.Instance.npcScripts.callScript(EnumScriptType.ATTACK_MELEE, event); - boolean result = npc.script.callScript(EnumScriptType.ATTACK, "event", new ScriptEventAttack(damage,target,false), "target", target); - NpcAPI.EVENT_BUS.post(event); - return result; + npc.script.callScript(EnumScriptType.ATTACK, event, "target", event.target); + return NpcAPI.EVENT_BUS.post(event); } - public static boolean onNPCRangedAttack(EntityNPCInterface npc, float damage, EntityLivingBase target){ + public static boolean onNPCRangedAttack(EntityNPCInterface npc, NpcEvent.RangedLaunchedEvent event){ if(npc == null || npc.wrappedNPC == null) return false; - NpcEvent.RangedLaunchedEvent event = new NpcEvent.RangedLaunchedEvent(npc.wrappedNPC,damage,target); ScriptController.Instance.npcScripts.callScript(EnumScriptType.RANGED_LAUNCHED, event); - boolean result = npc.script.callScript(EnumScriptType.ATTACK, "event", new ScriptEventAttack(damage,target,true), "target", target); - NpcAPI.EVENT_BUS.post(event); - return result; + npc.script.callScript(EnumScriptType.ATTACK, event, "target", event.target); + return NpcAPI.EVENT_BUS.post(event); } public static void onNPCKilledEntity(EntityNPCInterface npc, EntityLivingBase entity){ @@ -200,19 +192,17 @@ public class EventHooks { NpcEvent.KilledEntityEvent event = new NpcEvent.KilledEntityEvent(npc.wrappedNPC,entity); ScriptController.Instance.npcScripts.callScript(EnumScriptType.KILLS, event); - npc.script.callScript(EnumScriptType.KILLS, "target", entity); + npc.script.callScript(EnumScriptType.KILLS, event, "target", entity); NpcAPI.EVENT_BUS.post(event); } - public static boolean onNPCTarget(EntityNPCInterface npc, EntityLivingBase target){ + public static boolean onNPCTarget(EntityNPCInterface npc, NpcEvent.TargetEvent event){ if(npc == null || npc.wrappedNPC == null) return false; - NpcEvent.TargetEvent event = new NpcEvent.TargetEvent(npc.wrappedNPC,target); ScriptController.Instance.npcScripts.callScript(EnumScriptType.TARGET, event); - boolean result = npc.script.callScript(EnumScriptType.TARGET, "event", new ScriptEventTarget(target)); - NpcAPI.EVENT_BUS.post(event); - return result; + npc.script.callScript(EnumScriptType.TARGET, event); + return NpcAPI.EVENT_BUS.post(event); } public static void onNPCCollide(EntityNPCInterface npc, Entity entity){ @@ -221,29 +211,26 @@ public class EventHooks { NpcEvent.CollideEvent event = new NpcEvent.CollideEvent(npc.wrappedNPC,entity); ScriptController.Instance.npcScripts.callScript(EnumScriptType.COLLIDE, event); - npc.script.callScript(EnumScriptType.COLLIDE, "entity", entity); + npc.script.callScript(EnumScriptType.COLLIDE, event, "entity", entity); NpcAPI.EVENT_BUS.post(event); } - public static boolean onNPCDamaged(EntityNPCInterface npc, Entity source, float damage, DamageSource damagesource, ScriptEventDamaged damagedEvent){ + public static boolean onNPCDamaged(EntityNPCInterface npc, NpcEvent.DamagedEvent event){ if(npc == null || npc.wrappedNPC == null) return false; - NpcEvent.DamagedEvent event = new NpcEvent.DamagedEvent(npc.wrappedNPC,source,damage,damagesource); ScriptController.Instance.npcScripts.callScript(EnumScriptType.DAMAGED, event); - boolean result = npc.script.callScript(EnumScriptType.DAMAGED, "event", damagedEvent); - NpcAPI.EVENT_BUS.post(event); - return result; + npc.script.callScript(EnumScriptType.DAMAGED, event); + return NpcAPI.EVENT_BUS.post(event); } - public static boolean onNPCKilled(EntityNPCInterface npc, NpcEvent.DiedEvent event, ScriptEventKilled killedEvent){ + public static boolean onNPCKilled(EntityNPCInterface npc, NpcEvent.DiedEvent event){ if(npc == null || npc.wrappedNPC == null) return false; ScriptController.Instance.npcScripts.callScript(EnumScriptType.KILLED, event); - boolean result = npc.script.callScript(EnumScriptType.KILLED, "event", killedEvent); - NpcAPI.EVENT_BUS.post(event); - return result; + npc.script.callScript(EnumScriptType.KILLED, event); + return NpcAPI.EVENT_BUS.post(event); } public static void onNPCTimer(EntityNPCInterface npc, int id) { @@ -251,8 +238,7 @@ public class EventHooks { return; NpcEvent.TimerEvent event = new NpcEvent.TimerEvent(npc.wrappedNPC, id); - ScriptEventTimer scriptEvent = new ScriptEventTimer(id); - npc.script.callScript(EnumScriptType.TIMER, "event", scriptEvent); + npc.script.callScript(EnumScriptType.TIMER, event); ScriptController.Instance.npcScripts.callScript(EnumScriptType.TIMER, event); NpcAPI.EVENT_BUS.post(event); } diff --git a/src/main/java/noppes/npcs/controllers/data/DataScript.java b/src/main/java/noppes/npcs/controllers/data/DataScript.java index a300229cf..6e2998e67 100644 --- a/src/main/java/noppes/npcs/controllers/data/DataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/DataScript.java @@ -17,7 +17,6 @@ import noppes.npcs.controllers.IScriptHandler; import noppes.npcs.controllers.ScriptController; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.entity.ScriptNpc; -import noppes.npcs.scripted.event.ScriptEvent; import noppes.npcs.scripted.ScriptWorld; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.constants.JobType; @@ -105,7 +104,7 @@ public class DataScript implements IScriptHandler { return list; } - public boolean callScript(EnumScriptType type, Object... obs){ + public boolean callScript(EnumScriptType type, Event event, Object... obs){ if(aiNeedsUpdate){ npc.updateAI = true; aiNeedsUpdate = false; @@ -116,10 +115,9 @@ public class DataScript implements IScriptHandler { } if(!isEnabled()) return false; - if(!hasInited && !npc.isRemote()){ + if(!hasInited && !npc.isRemote() && type != EnumScriptType.INIT){ hasInited = true; EventHooks.onNPCInit(this.npc); - callScript(EnumScriptType.INIT); } ScriptContainer script = scripts.get(type.ordinal()); if(script == null || script.errored || !script.hasCode()) @@ -134,16 +132,14 @@ public class DataScript implements IScriptHandler { script.engine.put(obs[i].toString(), ob); } - return callScript(script); + return callScript(script, event); } - private boolean callScript(ScriptContainer script){ + private boolean callScript(ScriptContainer script, Event event){ ScriptEngine engine = script.engine; engine.put("npc", dummyNpc); engine.put("world", dummyWorld); - ScriptEvent result = (ScriptEvent) engine.get("event"); - if(result == null) - engine.put("event", result = new ScriptEvent()); + engine.put("event", event); engine.put("API", new NpcAPI()); engine.put("EntityType", entities); engine.put("RoleType", roles); @@ -158,17 +154,13 @@ public class DataScript implements IScriptHandler { npc.updateAI = true; aiNeedsUpdate = false; } - return result.isCancelled(); + return event.isCanceled(); } public boolean isEnabled(){ return enabled && ScriptController.HasStart && !npc.worldObj.isRemote && !scripts.isEmpty(); } - public void callScript(EnumScriptType var1, Event var2, Object... obs) { - - } - public Map getConsoleText() { Map map = new TreeMap(); int tab = 0; @@ -200,7 +192,7 @@ public class DataScript implements IScriptHandler { @Override public void callScript(EnumScriptType var1, Event var2) { - + callScript(var1, var2, "$$IGNORED$$", null); } public boolean isClient() { diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index ba0a1a3b9..839c0871c 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -235,8 +235,8 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti par1Entity.hurtResistantTime = 0; } if(par1Entity instanceof EntityLivingBase && !isRemote()){ - ScriptEventAttack event = new ScriptEventAttack(f, (EntityLivingBase)par1Entity, false); - if(EventHooks.onNPCMeleeAttack(this, f, (EntityLivingBase)par1Entity)) + NpcEvent.MeleeAttackEvent event = new NpcEvent.MeleeAttackEvent(wrappedNPC, f, (EntityLivingBase)par1Entity); + if(EventHooks.onNPCMeleeAttack(this, event)) return false; f = event.getDamage(); } @@ -493,10 +493,10 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti } else if (attackingEntity instanceof EntityPlayer && faction.isFriendlyToPlayer((EntityPlayer) attackingEntity)) return false; - ScriptEventDamaged result = new ScriptEventDamaged(i, attackingEntity, damagesource); - if(EventHooks.onNPCDamaged(this, attackingEntity, i, damagesource, result) || isKilled()) + NpcEvent.DamagedEvent event = new NpcEvent.DamagedEvent(this.wrappedNPC, attackingEntity, i, damagesource); + if(EventHooks.onNPCDamaged(this, event) || isKilled()) return false; - i = result.getDamage(); + i = event.getDamage(); if(isKilled()) return false; @@ -526,7 +526,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti return super.attackEntityFrom(damagesource, i); } finally{ - if(result.getClearTarget()){ + if(event.getClearTarget()){ setAttackTarget(null); setRevengeTarget(null); } @@ -544,8 +544,8 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti return; if (!isRemote()) { if (getAttackTarget() != entity && entity != null) { - ScriptEventTarget event = new ScriptEventTarget(entity); - if (EventHooks.onNPCTarget(this, entity)) + NpcEvent.TargetEvent event = new NpcEvent.TargetEvent(wrappedNPC,entity); + if (EventHooks.onNPCTarget(this, event)) return; if (event.getTarget() == null) @@ -571,8 +571,8 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti return; } if (!isRemote()) { - ScriptEventAttack event = new ScriptEventAttack(stats.pDamage, entity, true); - if (EventHooks.onNPCRangedAttack(this, f, (EntityLivingBase) entity)) + NpcEvent.RangedLaunchedEvent event = new NpcEvent.RangedLaunchedEvent(wrappedNPC,stats.pDamage,entity); + if (EventHooks.onNPCRangedAttack(this, event)) return; for (int i = 0; i < this.stats.shotCount; i++) { EntityProjectile projectile = shoot(entity, stats.accuracy, proj, f == 1); @@ -1213,9 +1213,8 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti ArrayList droppedItems = inventory.getDroppedItems(damagesource); if(!isRemote()){ - ScriptEventKilled result = new ScriptEventKilled(attackingEntity, damagesource); NpcEvent.DiedEvent event = new NpcEvent.DiedEvent(this.wrappedNPC,damagesource,entity,droppedItems, droppedXp); - if(EventHooks.onNPCKilled(this, event, result)) + if(EventHooks.onNPCKilled(this, event)) return; droppedItems.clear(); diff --git a/src/main/java/noppes/npcs/scripted/event/NpcEvent.java b/src/main/java/noppes/npcs/scripted/event/NpcEvent.java index 56f4ecff1..c0320096e 100644 --- a/src/main/java/noppes/npcs/scripted/event/NpcEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/NpcEvent.java @@ -116,6 +116,36 @@ public class NpcEvent extends CustomNPCsEvent { this.target = (IEntityLivingBase)NpcAPI.Instance().getIEntity(target); this.damage = damage; } + + /** + * @return The source of the damage + * @deprecated + */ + public IEntityLivingBase getTarget(){ + return target; + } + + + /** + * @return Returns the damage value + */ + public float getDamage(){ + return damage; + } + + /** + * @param damage The new damage value + */ + public void setDamage(float damage){ + this.damage = damage; + } + + /** + * @return Returns the damage type + */ + public boolean isRange(){ + return true; + } } @Cancelable @@ -128,6 +158,36 @@ public class NpcEvent extends CustomNPCsEvent { this.target = (IEntityLivingBase)NpcAPI.Instance().getIEntity(target); this.damage = damage; } + + /** + * @return The source of the damage + * @deprecated + */ + public IEntityLivingBase getTarget(){ + return target; + } + + + /** + * @return Returns the damage value + */ + public float getDamage(){ + return damage; + } + + /** + * @param damage The new damage value + */ + public void setDamage(float damage){ + this.damage = damage; + } + + /** + * @return Returns the damage type + */ + public boolean isRange(){ + return false; + } } public static class KilledEntityEvent extends NpcEvent { @@ -236,14 +296,43 @@ public class NpcEvent extends CustomNPCsEvent { public final IPlayer player; public final int id; public final int optionId; - public final Dialog dialog; + public final Dialog dialogObj; + + public final int dialog; + public final int option; public DialogClosedEvent(ICustomNpc npc, EntityPlayer player, int id, int optionId, Dialog dialog) { super(npc); this.player = (IPlayer)NpcAPI.Instance().getIEntity(player); this.id = id; this.optionId = optionId; - this.dialog = dialog; + this.dialogObj = dialog; + + this.dialog = id; + this.option = optionId; + } + + public IPlayer getPlayer() { + return player; + } + + public Dialog getDialog() { + return dialogObj; + } + + public int getDialogId() { + return option; + } + + public int getOptionId() { + return option; + } + + /** + * @deprecated + */ + public boolean isClosing(){ + return true; } } @@ -289,47 +378,4 @@ public class NpcEvent extends CustomNPCsEvent { super(npc); } } - - public static class AttackEvent extends NpcEvent{ - private float damage; - private IEntityLivingBase target; - private boolean isRanged; - - public AttackEvent(ICustomNpc npc, float damage, EntityLivingBase target, boolean isRanged){ - super(npc); - this.damage = damage; - this.isRanged = isRanged; - this.target = (IEntityLivingBase) NpcAPI.Instance().getIEntity(target); - } - - /** - * @return The source of the damage - * @deprecated - */ - public IEntityLivingBase getTarget(){ - return target; - } - - - /** - * @return Returns the damage value - */ - public float getDamage(){ - return damage; - } - - /** - * @param damage The new damage value - */ - public void setDamage(float damage){ - this.damage = damage; - } - - /** - * @return Returns the damage type - */ - public boolean isRange(){ - return isRanged; - } - } } diff --git a/src/main/java/noppes/npcs/scripted/event/ScriptEvent.java b/src/main/java/noppes/npcs/scripted/event/ScriptEvent.java deleted file mode 100644 index 12a951ca2..000000000 --- a/src/main/java/noppes/npcs/scripted/event/ScriptEvent.java +++ /dev/null @@ -1,22 +0,0 @@ -package noppes.npcs.scripted.event; - -public -class ScriptEvent{ - private boolean isCancelled = false; - - public void setCancelled(boolean bo){ - isCancelled = bo; - } - - public boolean isCancelled(){ - return isCancelled; - } - - public void setCanceled(boolean bo){ - isCancelled = bo; - } - - public boolean isCanceled(){ - return isCancelled; - } -} diff --git a/src/main/java/noppes/npcs/scripted/event/ScriptEventAttack.java b/src/main/java/noppes/npcs/scripted/event/ScriptEventAttack.java deleted file mode 100644 index 0b8403c3f..000000000 --- a/src/main/java/noppes/npcs/scripted/event/ScriptEventAttack.java +++ /dev/null @@ -1,48 +0,0 @@ -package noppes.npcs.scripted.event; - -import net.minecraft.entity.EntityLivingBase; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; - -public class ScriptEventAttack extends ScriptEvent{ - - private float damage; - private IEntityLivingBase target; - private boolean isRanged; - - public ScriptEventAttack(float damage, EntityLivingBase target, boolean isRanged){ - this.damage = damage; - this.isRanged = isRanged; - this.target = (IEntityLivingBase) NpcAPI.Instance().getIEntity(target); - } - - /** - * @return The source of the damage - * @deprecated - */ - public IEntityLivingBase getTarget(){ - return target; - } - - - /** - * @return Returns the damage value - */ - public float getDamage(){ - return damage; - } - - /** - * @param damage The new damage value - */ - public void setDamage(float damage){ - this.damage = damage; - } - - /** - * @return Returns the damage type - */ - public boolean isRange(){ - return isRanged; - } -} diff --git a/src/main/java/noppes/npcs/scripted/event/ScriptEventDamaged.java b/src/main/java/noppes/npcs/scripted/event/ScriptEventDamaged.java deleted file mode 100644 index f4511a400..000000000 --- a/src/main/java/noppes/npcs/scripted/event/ScriptEventDamaged.java +++ /dev/null @@ -1,56 +0,0 @@ -package noppes.npcs.scripted.event; - -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.util.DamageSource; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; - -public class ScriptEventDamaged extends ScriptEvent{ - - private float damage; - private boolean clear = false; - private IEntityLivingBase source; - private DamageSource damagesource; - - public ScriptEventDamaged(float damage, EntityLivingBase attackingEntity, DamageSource damagesource){ - this.damage = damage; - this.damagesource = damagesource; - this.source = (IEntityLivingBase) NpcAPI.Instance().getIEntity(attackingEntity); - } - - /** - * @return The source of the damage - */ - public IEntityLivingBase getSource(){ - return source; - } - - public void setClearTarget(boolean bo){ - this.clear = bo; - } - - public boolean getClearTarget(){ - return clear; - } - - /** - * @return Returns the damage value - */ - public float getDamage(){ - return damage; - } - - /** - * @param damage The new damage value - */ - public void setDamage(float damage){ - this.damage = damage; - } - - /** - * @return Returns the damage type - */ - public String getType(){ - return damagesource.damageType; - } -} diff --git a/src/main/java/noppes/npcs/scripted/event/ScriptEventDialog.java b/src/main/java/noppes/npcs/scripted/event/ScriptEventDialog.java deleted file mode 100644 index f546ce429..000000000 --- a/src/main/java/noppes/npcs/scripted/event/ScriptEventDialog.java +++ /dev/null @@ -1,43 +0,0 @@ -package noppes.npcs.scripted.event; - -import net.minecraft.entity.player.EntityPlayer; -import noppes.npcs.controllers.data.Dialog; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.interfaces.entity.IPlayer; - -public class ScriptEventDialog extends ScriptEvent{ - public IPlayer player; - public int dialog; - public int option; - public Dialog dialogObj; - - public ScriptEventDialog(EntityPlayer player, int dialog, int option, Dialog dialogObj){ - this.player = (IPlayer) NpcAPI.Instance().getIEntity(player); - this.dialog = dialog; - this.option = option; - this.dialogObj = dialogObj; - } - - public IPlayer getPlayer() { - return player; - } - - public Dialog getDialog() { - return dialogObj; - } - - public int getDialogId() { - return dialog; - } - - public int getOptionId() { - return option; - } - - /** - * @deprecated - */ - public boolean isClosing(){ - return true; - } -} diff --git a/src/main/java/noppes/npcs/scripted/event/ScriptEventKilled.java b/src/main/java/noppes/npcs/scripted/event/ScriptEventKilled.java deleted file mode 100644 index 8362598a7..000000000 --- a/src/main/java/noppes/npcs/scripted/event/ScriptEventKilled.java +++ /dev/null @@ -1,33 +0,0 @@ -package noppes.npcs.scripted.event; - -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.util.DamageSource; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.interfaces.IDamageSource; -import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; - -public class ScriptEventKilled extends ScriptEvent{ - private IEntityLivingBase source; - private DamageSource damagesource; - - public ScriptEventKilled(EntityLivingBase target, DamageSource damagesource){ - this.damagesource = damagesource; - this.source = (IEntityLivingBase) NpcAPI.Instance().getIEntity(target); - } - - /** - * @return The source of the damage - */ - public IEntityLivingBase getSource(){ - return source; - } - - public IDamageSource getDamageSource() { return NpcAPI.Instance().getIDamageSource(damagesource); } - - /** - * @return Returns the damage type - */ - public String getType(){ - return damagesource.damageType; - } -} diff --git a/src/main/java/noppes/npcs/scripted/event/ScriptEventTarget.java b/src/main/java/noppes/npcs/scripted/event/ScriptEventTarget.java deleted file mode 100644 index 10d2effc1..000000000 --- a/src/main/java/noppes/npcs/scripted/event/ScriptEventTarget.java +++ /dev/null @@ -1,26 +0,0 @@ -package noppes.npcs.scripted.event; - -import net.minecraft.entity.EntityLivingBase; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; - -public class ScriptEventTarget extends ScriptEvent { - - private IEntityLivingBase target; - - public ScriptEventTarget(EntityLivingBase target){ - if(target != null) - this.target = (IEntityLivingBase) NpcAPI.Instance().getIEntity(target); - } - - /** - * @return The source of the damage - */ - public IEntityLivingBase getTarget(){ - return target; - } - - public void setTarget(IEntityLivingBase target){ - this.target = target; - } -} diff --git a/src/main/java/noppes/npcs/scripted/event/ScriptEventTimer.java b/src/main/java/noppes/npcs/scripted/event/ScriptEventTimer.java deleted file mode 100644 index 0fdc3584b..000000000 --- a/src/main/java/noppes/npcs/scripted/event/ScriptEventTimer.java +++ /dev/null @@ -1,13 +0,0 @@ -package noppes.npcs.scripted.event; - -public class ScriptEventTimer extends ScriptEvent { - private int id; - - public ScriptEventTimer(int id){ - this.id = id; - } - - public int getId(){ - return id; - } -} From 587f63396fe647c6df4357993a843f4135e9d3c6 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Fri, 10 Jun 2022 18:46:24 -0500 Subject: [PATCH 35/40] Dialog Image interface added. --- .../interfaces/handler/data/IDialogImage.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/handler/data/IDialogImage.java diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IDialogImage.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IDialogImage.java new file mode 100644 index 000000000..af6bdb1bb --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IDialogImage.java @@ -0,0 +1,41 @@ +package noppes.npcs.scripted.interfaces.handler.data; + +public interface IDialogImage { + int getId(); + + void setTexture(String texture); + String getTexture(); + + void setPosition(int x, int y); + int getX(); + int getY(); + + void setWidthHeight(int width, int height); + int getWidth(); + int getHeight(); + + void setTextureOffset(int offsetX, int offsetY); + int getTextureX(); + int getTextureY(); + + void setColor(int color); + int getColor(); + + void setSelectedColor(int color); + int getSelectedColor(); + + void setScale(float scale); + float getScale(); + + void setAlpha(float alpha); + float getAlpha(); + + void setRotation(float rotation); + float getRotation(); + + void setImageType(int imageType); + int getImageType(); + + void setAlignment(int alignment); + int getAlignment(); +} From 63a1525ee2947d4c8b56b2a27e2e71069f9536b3 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Sun, 12 Jun 2022 01:26:23 -0500 Subject: [PATCH 36/40] API Changes: -Implemented interfaces for all jobs & roles. ScriptPlayer: -Added getData() function, which returns player data objects. IPlayerData: New class that holds all player data for modification. -Holds dialog, bank, quest, transport, faction, item giver, and mail data. -Also holds companion data, with functions has/set/getCompanion, and a getCompanionID function to differentiate companions. --- src/main/java/noppes/npcs/CustomNpcs.java | 1 + src/main/java/noppes/npcs/DataAdvanced.java | 22 +++- .../java/noppes/npcs/PacketHandlerServer.java | 2 +- .../controllers/GlobalDataController.java | 23 +++- .../npcs/controllers/TransportController.java | 60 ++++++++- .../npcs/controllers/data/PlayerBankData.java | 8 +- .../npcs/controllers/data/PlayerData.java | 64 ++++++++-- .../controllers/data/PlayerDialogData.java | 21 +++- .../controllers/data/PlayerFactionData.java | 29 ++++- .../controllers/data/PlayerItemGiverData.java | 39 +++++- .../npcs/controllers/data/PlayerMail.java | 104 ++++++++++++++- .../npcs/controllers/data/PlayerMailData.java | 65 +++++++++- .../controllers/data/PlayerQuestData.java | 85 ++++++++++++- .../controllers/data/PlayerTransportData.java | 42 ++++++- .../controllers/data/TransportCategory.java | 57 ++++++++- .../controllers/data/TransportLocation.java | 54 +++++++- .../npcs/entity/EntityNPCInterface.java | 14 ++- .../java/noppes/npcs/roles/JobItemGiver.java | 13 +- .../java/noppes/npcs/scripted/NpcAPI.java | 17 +++ .../noppes/npcs/scripted/ScriptWorld.java | 14 ++- .../npcs/scripted/entity/ScriptPlayer.java | 5 +- .../scripted/interfaces/AbstractNpcAPI.java | 8 ++ .../npcs/scripted/interfaces/IWorld.java | 2 + .../scripted/interfaces/entity/IPlayer.java | 3 + .../interfaces/handler/IPlayerBankData.java | 4 + .../interfaces/handler/IPlayerData.java | 29 +++++ .../interfaces/handler/IPlayerDialogData.java | 10 ++ .../handler/IPlayerFactionData.java | 10 ++ .../handler/IPlayerItemGiverData.java | 14 +++ .../interfaces/handler/IPlayerMailData.java | 22 ++++ .../interfaces/handler/IPlayerQuestData.java | 24 ++++ .../handler/IPlayerTransportData.java | 18 +++ .../interfaces/handler/ITransportHandler.java | 14 +++ .../interfaces/handler/data/IPlayerMail.java | 32 +++++ .../handler/data/ITransportCategory.java | 16 +++ .../handler/data/ITransportLocation.java | 28 +++++ .../npcs/scripted/interfaces/jobs/IJob.java | 13 ++ .../scripted/interfaces/jobs/IJobBard.java | 8 ++ .../interfaces/jobs/IJobConversation.java | 5 + .../interfaces/jobs/IJobFollower.java | 14 +++ .../scripted/interfaces/jobs/IJobGuard.java | 4 + .../scripted/interfaces/jobs/IJobHealer.java | 8 ++ .../interfaces/jobs/IJobItemGiver.java | 34 +++++ .../scripted/interfaces/jobs/IJobPuppet.java | 20 +++ .../scripted/interfaces/jobs/IJobSpawner.java | 10 ++ .../npcs/scripted/interfaces/roles/IRole.java | 6 + .../scripted/interfaces/roles/IRoleBank.java | 5 + .../interfaces/roles/IRoleFollower.java | 64 ++++++++++ .../interfaces/roles/IRoleMailman.java | 5 + .../interfaces/roles/IRoleTrader.java | 119 ++++++++++++++++++ .../interfaces/roles/IRoleTransporter.java | 5 + .../npcs/scripted/roles/ScriptJobBard.java | 3 +- .../scripted/roles/ScriptJobConversation.java | 3 +- .../scripted/roles/ScriptJobFollower.java | 5 +- .../npcs/scripted/roles/ScriptJobGuard.java | 3 +- .../npcs/scripted/roles/ScriptJobHealer.java | 3 +- .../scripted/roles/ScriptJobInterface.java | 24 +++- .../scripted/roles/ScriptJobItemGiver.java | 98 ++++++++++++++- .../npcs/scripted/roles/ScriptJobPuppet.java | 5 +- .../npcs/scripted/roles/ScriptJobSpawner.java | 3 +- .../npcs/scripted/roles/ScriptRoleBank.java | 3 +- .../scripted/roles/ScriptRoleFollower.java | 57 ++------- .../scripted/roles/ScriptRoleInterface.java | 8 +- .../scripted/roles/ScriptRoleMailman.java | 3 +- .../npcs/scripted/roles/ScriptRoleTrader.java | 111 +++------------- .../scripted/roles/ScriptRoleTransporter.java | 3 +- 66 files changed, 1418 insertions(+), 207 deletions(-) create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerBankData.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerData.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerDialogData.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerFactionData.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerItemGiverData.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerMailData.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerQuestData.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerTransportData.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/handler/ITransportHandler.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/handler/data/IPlayerMail.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/handler/data/ITransportCategory.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/handler/data/ITransportLocation.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/jobs/IJob.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobBard.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobConversation.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobFollower.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobGuard.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobHealer.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobItemGiver.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobPuppet.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobSpawner.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/roles/IRole.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleBank.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleFollower.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleMailman.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleTrader.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleTransporter.java diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index 450bb5fd6..05d439dd8 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -296,6 +296,7 @@ public class CustomNpcs { @EventHandler public void stopped(FMLServerStoppedEvent event){ ServerCloneController.Instance = null; + GlobalDataController.instance.saveData(); } @EventHandler diff --git a/src/main/java/noppes/npcs/DataAdvanced.java b/src/main/java/noppes/npcs/DataAdvanced.java index 67200a374..c8864dee1 100644 --- a/src/main/java/noppes/npcs/DataAdvanced.java +++ b/src/main/java/noppes/npcs/DataAdvanced.java @@ -6,6 +6,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import noppes.npcs.constants.EnumJobType; import noppes.npcs.constants.EnumRoleType; +import noppes.npcs.controllers.GlobalDataController; import noppes.npcs.controllers.data.DialogOption; import noppes.npcs.controllers.data.FactionOptions; import noppes.npcs.controllers.data.Line; @@ -195,8 +196,25 @@ public class DataAdvanced { npc.jobInterface = new JobHealer(npc); else if (job == EnumJobType.Guard && !(npc.jobInterface instanceof JobGuard)) npc.jobInterface = new JobGuard(npc); - else if (job == EnumJobType.ItemGiver && !(npc.jobInterface instanceof JobItemGiver)) - npc.jobInterface = new JobItemGiver(npc); + else if (job == EnumJobType.ItemGiver && !(npc.jobInterface instanceof JobItemGiver)) { + if (!npc.isRemote()) { + if (npc.itemGiverId > 0 && GlobalDataController.instance.itemGivers.containsKey(npc.itemGiverId)) { + GlobalDataController.instance.itemGivers.get(npc.itemGiverId).npc = npc; + npc.jobInterface = GlobalDataController.instance.itemGivers.get(npc.itemGiverId); + } else { + npc.jobInterface = new JobItemGiver(npc); + if (npc.itemGiverId == -1) { + ((JobItemGiver) npc.jobInterface).itemGiverId = GlobalDataController.instance.incrementItemGiverId(); + } else { + ((JobItemGiver) npc.jobInterface).itemGiverId = npc.itemGiverId; + } + GlobalDataController.instance.itemGivers.put(((JobItemGiver) npc.jobInterface).itemGiverId, (JobItemGiver) npc.jobInterface); + npc.itemGiverId = ((JobItemGiver) npc.jobInterface).itemGiverId; + } + } else { + npc.jobInterface = new JobItemGiver(npc); + } + } else if (job == EnumJobType.Follower && !(npc.jobInterface instanceof JobFollower)) npc.jobInterface = new JobFollower(npc); else if (job == EnumJobType.Spawner && !(npc.jobInterface instanceof JobSpawner)) diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 71bfdab6d..5d776b7f4 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -629,7 +629,7 @@ public class PacketHandlerServer{ } else if(type == EnumPacketServer.TransportSave){ int cat = buffer.readInt(); - TransportLocation location = TransportController.getInstance().saveLocation(cat,Server.readNBT(buffer),player, npc); + TransportLocation location = TransportController.getInstance().saveLocation(cat,Server.readNBT(buffer), npc); if(location != null){ if(npc.advanced.role != EnumRoleType.Transporter) return; diff --git a/src/main/java/noppes/npcs/controllers/GlobalDataController.java b/src/main/java/noppes/npcs/controllers/GlobalDataController.java index 3c91876c3..d02912009 100644 --- a/src/main/java/noppes/npcs/controllers/GlobalDataController.java +++ b/src/main/java/noppes/npcs/controllers/GlobalDataController.java @@ -3,15 +3,19 @@ package noppes.npcs.controllers; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.util.HashMap; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import noppes.npcs.CustomNpcs; +import noppes.npcs.roles.JobItemGiver; public class GlobalDataController { public static GlobalDataController instance; private int itemGiverId = 0; + public HashMap itemGivers = new HashMap<>(); public GlobalDataController(){ instance = this; @@ -37,9 +41,17 @@ public class GlobalDataController { } } } - private void loadData(File file) throws Exception{ + private void loadData(File file) throws Exception { NBTTagCompound nbttagcompound1 = CompressedStreamTools.readCompressed(new FileInputStream(file)); itemGiverId = nbttagcompound1.getInteger("itemGiverId"); + + NBTTagList jobList = nbttagcompound1.getTagList("ItemGivers", 10); + for (int i = 0; i < jobList.tagCount(); i++) { + NBTTagCompound compound = jobList.getCompoundTagAt(i); + JobItemGiver jobItemGiver = new JobItemGiver(); + jobItemGiver.readFromNBT(compound); + itemGivers.put(jobItemGiver.itemGiverId, jobItemGiver); + } } public void saveData(){ try { @@ -47,6 +59,14 @@ public class GlobalDataController { NBTTagCompound nbttagcompound = new NBTTagCompound(); nbttagcompound.setInteger("itemGiverId", itemGiverId); + + NBTTagList jobList = new NBTTagList(); + for (JobItemGiver jobItemGiver : itemGivers.values()) { + NBTTagCompound compound = new NBTTagCompound(); + jobItemGiver.writeToNBT(compound); + jobList.appendTag(compound); + } + nbttagcompound.setTag("ItemGivers", jobList); File file = new File(saveDir, "global.dat_new"); File file1 = new File(saveDir, "global.dat_old"); @@ -72,7 +92,6 @@ public class GlobalDataController { } public int incrementItemGiverId(){ itemGiverId++; - saveData(); return itemGiverId; } } diff --git a/src/main/java/noppes/npcs/controllers/TransportController.java b/src/main/java/noppes/npcs/controllers/TransportController.java index b84371c4b..2679269c3 100644 --- a/src/main/java/noppes/npcs/controllers/TransportController.java +++ b/src/main/java/noppes/npcs/controllers/TransportController.java @@ -4,7 +4,10 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import java.util.Map; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.CompressedStreamTools; @@ -17,8 +20,11 @@ import noppes.npcs.controllers.data.TransportCategory; import noppes.npcs.controllers.data.TransportLocation; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleTransporter; +import noppes.npcs.scripted.interfaces.handler.ITransportHandler; +import noppes.npcs.scripted.interfaces.handler.data.ITransportCategory; +import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation; -public class TransportController { +public class TransportController implements ITransportHandler { private HashMap locations = new HashMap(); public HashMap categories = new HashMap(); @@ -131,7 +137,7 @@ public class TransportController { return null; } - private int getUniqueIdLocation() { + public int getUniqueIdLocation() { if(lastUsedID == 0){ for(int catid : locations.keySet()) if(catid > lastUsedID) @@ -219,7 +225,27 @@ public class TransportController { public static TransportController getInstance(){ return instance; } - public TransportLocation saveLocation(int categoryId, NBTTagCompound compound, EntityPlayerMP player, EntityNPCInterface npc){ + + public TransportLocation saveLocation(int categoryId, TransportLocation location){ + TransportCategory category = categories.get(categoryId); + if(category == null) + return null; + location.category = category; + if(location.id < 0 || !locations.get(location.id).name.equals(location.name)){ + while(containsLocationName(location.name)) + location.name += "_"; + } + if(location.id < 0) + location.id = getUniqueIdLocation(); + + category.locations.put(location.id, location); + locations.put(location.id, location); + saveCategories(); + + return location; + } + + public TransportLocation saveLocation(int categoryId, NBTTagCompound compound, EntityNPCInterface npc){ TransportCategory category = categories.get(categoryId); if(category == null || npc.advanced.role != EnumRoleType.Transporter) return null; @@ -243,4 +269,32 @@ public class TransportController { return location; } + public ITransportCategory[] categories() { + return (new ArrayList<>(categories.values())).toArray(new ITransportCategory[0]); + } + + public void createCategory(String title) { + this.saveCategory(title, -1); + } + + public ITransportCategory getCategory(String title) { + TransportCategory category = null; + for (TransportCategory c : categories.values()) { + if (c.title.equals(title)) { + category = c; + break; + } + } + + return category; + } + + public void removeCategory(String title) { + for (Map.Entry entry : categories.entrySet()) { + if (entry.getValue().title.equals(title)) { + categories.remove(entry.getKey()); + break; + } + } + } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerBankData.java b/src/main/java/noppes/npcs/controllers/data/PlayerBankData.java index df1d40afd..ae9e47178 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerBankData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerBankData.java @@ -5,11 +5,15 @@ import java.util.HashMap; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import noppes.npcs.controllers.BankController; +import noppes.npcs.scripted.interfaces.handler.IPlayerBankData; -public class PlayerBankData{ +public class PlayerBankData implements IPlayerBankData { + private final PlayerData parent; public HashMap banks; - public PlayerBankData(){ + + public PlayerBankData(PlayerData parent){ banks = new HashMap(); + this.parent = parent; } public void loadNBTData(NBTTagCompound compound) { diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerData.java b/src/main/java/noppes/npcs/controllers/data/PlayerData.java index 77f779db9..6fa62f017 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerData.java @@ -15,19 +15,23 @@ import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.entity.data.DataSkinOverlays; import noppes.npcs.entity.data.DataTimers; import noppes.npcs.roles.RoleCompanion; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.interfaces.entity.ICustomNpc; +import noppes.npcs.scripted.interfaces.handler.*; import noppes.npcs.util.NBTJsonUtil; import java.io.File; import java.io.FileInputStream; -public class PlayerData implements IExtendedEntityProperties{ - public PlayerDialogData dialogData = new PlayerDialogData(); - public PlayerBankData bankData = new PlayerBankData(); - public PlayerQuestData questData = new PlayerQuestData(); - public PlayerTransportData transportData = new PlayerTransportData(); - public PlayerFactionData factionData = new PlayerFactionData(); - public PlayerItemGiverData itemgiverData = new PlayerItemGiverData(); - public PlayerMailData mailData = new PlayerMailData(); +public class PlayerData implements IExtendedEntityProperties, IPlayerData { + public PlayerDialogData dialogData = new PlayerDialogData(this); + public PlayerBankData bankData = new PlayerBankData(this); + public PlayerQuestData questData = new PlayerQuestData(this); + public PlayerTransportData transportData = new PlayerTransportData(this); + public PlayerFactionData factionData = new PlayerFactionData(this); + public PlayerItemGiverData itemgiverData = new PlayerItemGiverData(this); + public PlayerMailData mailData = new PlayerMailData(this); + public DataTimers timers = new DataTimers(this); public DataSkinOverlays skinOverlays = new DataSkinOverlays(this); @@ -245,4 +249,48 @@ public class PlayerData implements IExtendedEntityProperties{ return data; } } + + public void setCompanion(ICustomNpc npc) { + this.setCompanion((EntityNPCInterface) npc.getMCEntity()); + } + + public ICustomNpc getCompanion() { + return (ICustomNpc) NpcAPI.Instance().getIEntity(activeCompanion); + } + + public int getCompanionID() { + return companionID; + } + + public IPlayerDialogData getDialogData() { + return dialogData; + } + + public IPlayerBankData getBankData() { + return bankData; + } + + public IPlayerQuestData getQuestData() { + return questData; + } + + public IPlayerTransportData getTransportData() { + return transportData; + } + + public IPlayerFactionData getFactionData() { + return factionData; + } + + public IPlayerItemGiverData getItemGiverData() { + return itemgiverData; + } + + public IPlayerMailData getMailData() { + return mailData; + } + + public void save() { + PlayerDataController.instance.savePlayerData(this); + } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerDialogData.java b/src/main/java/noppes/npcs/controllers/data/PlayerDialogData.java index 93b879f46..265b036d4 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerDialogData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerDialogData.java @@ -4,9 +4,15 @@ import java.util.HashSet; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import noppes.npcs.scripted.interfaces.handler.IPlayerDialogData; -public class PlayerDialogData{ +public class PlayerDialogData implements IPlayerDialogData { + private final PlayerData parent; public HashSet dialogsRead = new HashSet(); + + public PlayerDialogData(PlayerData parent) { + this.parent = parent; + } public void loadNBTData(NBTTagCompound compound) { HashSet dialogsRead = new HashSet(); @@ -35,5 +41,16 @@ public class PlayerDialogData{ compound.setTag("DialogData", list); } - + + public boolean hasReadDialog(int id) { + return dialogsRead.contains(id); + } + + public void readDialog(int id) { + dialogsRead.add(id); + } + + public void unreadDialog(int id) { + dialogsRead.remove(id); + } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerFactionData.java b/src/main/java/noppes/npcs/controllers/data/PlayerFactionData.java index e19290fe9..365c30c58 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerFactionData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerFactionData.java @@ -11,10 +11,20 @@ import noppes.npcs.controllers.FactionController; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.event.FactionEvent; import noppes.npcs.scripted.interfaces.entity.IPlayer; +import noppes.npcs.scripted.interfaces.handler.IPlayerFactionData; -public class PlayerFactionData { +public class PlayerFactionData implements IPlayerFactionData { + private final PlayerData parent; public HashMap factionData = new HashMap(); - + + public PlayerFactionData() { + parent = null; + } + + public PlayerFactionData(PlayerData parent) { + this.parent = parent; + } + public void loadNBTData(NBTTagCompound compound) { HashMap factionData = new HashMap(); if(compound == null) @@ -79,4 +89,19 @@ public class PlayerFactionData { return compound; } + public int getPoints(int id) { + return this.getFactionPoints(id); + } + + public void addPoints(int id, int points) { + if (parent != null) { + this.increasePoints(id, points, parent.player); + } + } + + public void setPoints(int id, int points) { + if (parent != null) { + increasePoints(id, points-getFactionPoints(id), parent.player); + } + } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerItemGiverData.java b/src/main/java/noppes/npcs/controllers/data/PlayerItemGiverData.java index 88bdb52f0..d54e54f20 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerItemGiverData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerItemGiverData.java @@ -1,15 +1,25 @@ package noppes.npcs.controllers.data; +import java.util.ArrayList; import java.util.HashMap; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.NBTTags; +import noppes.npcs.controllers.GlobalDataController; import noppes.npcs.roles.JobItemGiver; +import noppes.npcs.scripted.interfaces.handler.IPlayerItemGiverData; +import noppes.npcs.scripted.interfaces.jobs.IJobItemGiver; +import noppes.npcs.scripted.roles.ScriptJobItemGiver; -public class PlayerItemGiverData{ +public class PlayerItemGiverData implements IPlayerItemGiverData { + private final PlayerData parent; private HashMap itemgivers = new HashMap(); private HashMap chained = new HashMap(); - + + public PlayerItemGiverData(PlayerData parent) { + this.parent = parent; + } + public void loadNBTData(NBTTagCompound compound) { chained = NBTTags.getIntegerIntegerMap(compound.getTagList("ItemGiverChained", 10)); itemgivers = NBTTags.getIntegerLongMap(compound.getTagList("ItemGiversList", 10)); @@ -37,4 +47,29 @@ public class PlayerItemGiverData{ public void setItemIndex(JobItemGiver jobItemGiver, int i) { chained.put(jobItemGiver.itemGiverId, i); } + + public long getTime(IJobItemGiver jobItemGiver){ + return itemgivers.get(((JobItemGiver) jobItemGiver.getJobInterface()).itemGiverId); + } + + public void setTime(IJobItemGiver jobItemGiver, long day) { + itemgivers.put(((JobItemGiver) jobItemGiver.getJobInterface()).itemGiverId, day); + } + + public boolean hasInteractedBefore(IJobItemGiver jobItemGiver) { + return itemgivers.containsKey(((JobItemGiver) jobItemGiver.getJobInterface()).itemGiverId); + } + + public IJobItemGiver[] getItemGivers() { + ArrayList list = new ArrayList<>(); + for (JobItemGiver jobItemGiver : GlobalDataController.instance.itemGivers.values()) { + if (jobItemGiver.npc != null) { + list.add(new ScriptJobItemGiver(jobItemGiver.npc)); + } else { + list.add(new ScriptJobItemGiver(jobItemGiver)); + } + } + + return list.toArray(new IJobItemGiver[0]); + } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerMail.java b/src/main/java/noppes/npcs/controllers/data/PlayerMail.java index 35677adcd..01af6d63c 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerMail.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerMail.java @@ -5,10 +5,17 @@ import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; import noppes.npcs.NoppesUtilServer; import noppes.npcs.controllers.QuestController; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.interfaces.handler.data.IPlayerMail; +import noppes.npcs.scripted.interfaces.handler.data.IQuest; +import noppes.npcs.scripted.interfaces.item.IItemStack; -public class PlayerMail implements IInventory{ +import java.util.ArrayList; + +public class PlayerMail implements IInventory, IPlayerMail { public String subject = ""; public String sender = ""; public NBTTagCompound message = new NBTTagCompound(); @@ -202,4 +209,99 @@ public class PlayerMail implements IInventory{ mail.readNBT(writeNBT()); return mail; } + + public void setPageText(String[] pages) { + NBTTagList bookPages = new NBTTagList(); + for (String text : pages) { + bookPages.appendTag(new NBTTagString(text)); + } + + message.setTag("pages", bookPages); + } + + public String[] getPageText() { + NBTTagList bookPages = new NBTTagList(); + + if(message.hasKey("pages")) + bookPages = message.getTagList("pages", 8); + + if (bookPages != null) + { + bookPages = (NBTTagList)bookPages.copy(); + ArrayList pageStrings = new ArrayList<>(); + + for (int i = 0; i < bookPages.tagCount(); i++) { + pageStrings.add(bookPages.getStringTagAt(i)); + } + + return pageStrings.toArray(new String[0]); + } else { + return new String[]{""}; + } + } + + public int getPageCount() { + NBTTagList bookPages = new NBTTagList(); + + if(message.hasKey("pages")) + bookPages = message.getTagList("pages", 8); + + int bookTotalPages = 0; + if (bookPages != null) + { + bookPages = (NBTTagList)bookPages.copy(); + bookTotalPages = bookPages.tagCount(); + + if (bookTotalPages < 1) + { + bookTotalPages = 1; + } + + return bookTotalPages; + } + + return 0; + } + + public void setSender(String sender) { + this.sender = sender; + } + + public String getSender() { + return sender; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public String getSubject() { + return subject; + } + + public long getTimePast() { + return timePast; + } + + public long getTimeSent() { + return time; + } + + public IItemStack[] getItems() { + ArrayList list = new ArrayList<>(); + for (ItemStack itemStack : items) { + list.add(NpcAPI.Instance().getIItemStack(itemStack)); + } + + return list.toArray(new IItemStack[0]); + } + + public void setItems(IItemStack[] items) { + ArrayList list = new ArrayList<>(); + for (IItemStack itemStack : items) { + list.add(itemStack.getMCItemStack()); + } + + this.items = list.toArray(new ItemStack[0]); + } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerMailData.java b/src/main/java/noppes/npcs/controllers/data/PlayerMailData.java index e6e9dee62..58432a98b 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerMailData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerMailData.java @@ -4,10 +4,21 @@ import java.util.ArrayList; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import noppes.npcs.scripted.interfaces.handler.IPlayerMailData; +import noppes.npcs.scripted.interfaces.handler.data.IPlayerMail; -public class PlayerMailData{ +public class PlayerMailData implements IPlayerMailData { + private final PlayerData parent; public ArrayList playermail = new ArrayList(); + public PlayerMailData() { + this.parent = null; + } + + public PlayerMailData(PlayerData parent) { + this.parent = parent; + } + public void loadNBTData(NBTTagCompound compound) { ArrayList newmail = new ArrayList(); NBTTagList list = compound.getTagList("MailData", 10); @@ -39,4 +50,56 @@ public class PlayerMailData{ return true; return false; } + + public void addMail(IPlayerMail mail) { + playermail.add((PlayerMail) mail); + } + + public void removeMail(IPlayerMail mail) { + playermail.remove((PlayerMail) mail); + } + + public boolean hasMail(IPlayerMail mail) { + return playermail.contains((PlayerMail) mail); + } + + public IPlayerMail[] getAllMail() { + return playermail.toArray(new IPlayerMail[0]); + } + + public IPlayerMail[] getUnreadMail() { + ArrayList mails = new ArrayList<>(); + + for (PlayerMail mail : playermail) { + if (!mail.beenRead) { + mails.add(mail); + } + } + + return mails.toArray(new IPlayerMail[0]); + } + + public IPlayerMail[] getReadMail() { + ArrayList mails = new ArrayList<>(); + + for (PlayerMail mail : playermail) { + if (mail.beenRead) { + mails.add(mail); + } + } + + return mails.toArray(new IPlayerMail[0]); + } + + public IPlayerMail[] getMailFrom(String sender) { + ArrayList mails = new ArrayList<>(); + + for (PlayerMail mail : playermail) { + if (mail.sender.equals(sender)) { + mails.add(mail); + } + } + + return mails.toArray(new IPlayerMail[0]); + } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java b/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java index 06e73e83f..505241f06 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java @@ -1,6 +1,8 @@ package noppes.npcs.controllers.data; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -16,14 +18,20 @@ import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.controllers.QuestController; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.quests.QuestInterface; +import noppes.npcs.scripted.interfaces.handler.IPlayerQuestData; import noppes.npcs.scripted.interfaces.handler.data.IQuest; -public class PlayerQuestData { +public class PlayerQuestData implements IPlayerQuestData { + private final PlayerData parent; public IQuest trackedQuest = null; public HashMap activeQuests = new HashMap(); public HashMap finishedQuests = new HashMap(); - + + public PlayerQuestData(PlayerData parent) { + this.parent = parent; + } + public void loadNBTData(NBTTagCompound mainCompound) { if(mainCompound == null) return; @@ -129,5 +137,76 @@ public class PlayerQuestData { return bo; } - + + public IQuest getTrackedQuest() { + return trackedQuest; + } + + public void startQuest(int id) { + Quest quest = QuestController.instance.quests.get(id); + if (quest == null) + return; + if(activeQuests.containsKey(id)) + return; + QuestData questdata = new QuestData(quest); + activeQuests.put(id, questdata); + Server.sendData((EntityPlayerMP)parent.player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title); + Server.sendData((EntityPlayerMP)parent.player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title); + } + + public void finishQuest(int id) { + Quest quest = QuestController.instance.quests.get(id); + if (quest == null) + return; + finishedQuests.put(id, System.currentTimeMillis()); + } + + public void stopQuest(int id) { + Quest quest = QuestController.instance.quests.get(id); + if (quest == null) + return; + activeQuests.remove(id); + } + + public void removeQuest(int id) { + Quest quest = QuestController.instance.quests.get(id); + if (quest == null) + return; + activeQuests.remove(id); + finishedQuests.remove(id); + } + + public boolean hasFinishedQuest(int id){ + return finishedQuests.containsKey(id); + } + + public boolean hasActiveQuest(int id){ + return activeQuests.containsKey(id); + } + + public IQuest[] getActiveQuests() { + List quests = new ArrayList<>(); + + for (int id : activeQuests.keySet()) { + IQuest quest = (IQuest) QuestController.instance.quests.get(id); + if (quest != null) { + quests.add(quest); + } + } + + return (IQuest[])quests.toArray(new IQuest[0]); + } + + public IQuest[] getFinishedQuests() { + List quests = new ArrayList<>(); + + for (int id : finishedQuests.keySet()) { + IQuest quest = (IQuest) QuestController.instance.quests.get(id); + if (quest != null) { + quests.add(quest); + } + } + + return (IQuest[])quests.toArray(new IQuest[0]); + } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerTransportData.java b/src/main/java/noppes/npcs/controllers/data/PlayerTransportData.java index 945243474..50f7b8dc8 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerTransportData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerTransportData.java @@ -1,13 +1,22 @@ package noppes.npcs.controllers.data; +import java.util.ArrayList; import java.util.HashSet; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import noppes.npcs.controllers.TransportController; +import noppes.npcs.scripted.interfaces.handler.IPlayerTransportData; +import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation; -public class PlayerTransportData{ +public class PlayerTransportData implements IPlayerTransportData { + private final PlayerData parent; public HashSet transports = new HashSet(); + public PlayerTransportData(PlayerData parent) { + this.parent = parent; + } + public void loadNBTData(NBTTagCompound compound) { HashSet dialogsRead = new HashSet(); if(compound == null) @@ -35,5 +44,34 @@ public class PlayerTransportData{ compound.setTag("TransportData", list); } - + + public boolean hasTransport(int id) { + return transports.contains(id); + } + + public void addTransport(int id) { + transports.add(id); + } + + public void addTransport(ITransportLocation location) { + transports.add(location.getId()); + } + + public ITransportLocation getTransport(int id) { + return TransportController.getInstance().getTransport(id); + } + + public ITransportLocation[] getTransports() { + ArrayList list = new ArrayList<>(); + for (int id : transports) { + ITransportLocation location = TransportController.getInstance().getTransport(id); + list.add(location); + } + + return list.toArray(new ITransportLocation[0]); + } + + public void removeTransport(int id) { + transports.remove(id); + } } diff --git a/src/main/java/noppes/npcs/controllers/data/TransportCategory.java b/src/main/java/noppes/npcs/controllers/data/TransportCategory.java index fdfa21f86..99b6f3acb 100644 --- a/src/main/java/noppes/npcs/controllers/data/TransportCategory.java +++ b/src/main/java/noppes/npcs/controllers/data/TransportCategory.java @@ -1,18 +1,24 @@ package noppes.npcs.controllers.data; import java.util.HashMap; +import java.util.Map; import java.util.Vector; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import noppes.npcs.controllers.TransportController; +import noppes.npcs.scripted.interfaces.handler.data.ITransportCategory; +import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation; -public class TransportCategory { +public class TransportCategory implements ITransportCategory { public int id = -1; public String title = ""; public HashMap locations; + public TransportCategory(){ locations = new HashMap(); } + public Vector getDefaultLocations() { Vector list = new Vector(); for(TransportLocation loc : locations.values()) @@ -47,4 +53,53 @@ public class TransportCategory { } compound.setTag("CategoryLocations", locs); } + + public int getId() { + return id; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + public void addLocation(String name) { + int id = TransportController.getInstance().getUniqueIdLocation(); + TransportLocation location = new TransportLocation(); + location.id = id; + location.name = name; + location.category = this; + + TransportController.getInstance().setLocation(location); + } + + public ITransportLocation getLocation(String name) { + TransportLocation location = null; + for (TransportLocation l : locations.values()) { + if (l.getName().equals(name)) { + location = l; + break; + } + } + + return location; + } + + public void removeLocation(String name) { + int id = -1; + for (Map.Entry entry : locations.entrySet()) { + if (entry.getValue().getName().equals(name)) { + id = entry.getKey();; + locations.remove(entry.getKey()); + break; + } + } + + if (id >= 0) { + TransportController.getInstance().removeLocation(id); + } + } } diff --git a/src/main/java/noppes/npcs/controllers/data/TransportLocation.java b/src/main/java/noppes/npcs/controllers/data/TransportLocation.java index fc1dcb620..9d3256d38 100644 --- a/src/main/java/noppes/npcs/controllers/data/TransportLocation.java +++ b/src/main/java/noppes/npcs/controllers/data/TransportLocation.java @@ -1,8 +1,10 @@ package noppes.npcs.controllers.data; import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.controllers.TransportController; +import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation; -public class TransportLocation { +public class TransportLocation implements ITransportLocation { public int id = -1; public String name = "default name"; public double posX; @@ -41,4 +43,54 @@ public class TransportLocation { public boolean isDefault() { return type == 1; } + + public int getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setDimension(int dimension) { + this.dimension = dimension; + } + + public int getDimension() { + return dimension; + } + + public void setType(int type) { + this.type = type; + } + + public int getType() { + return type; + } + + public void setPosition(int x, int y, int z) { + this.posX = x; + this.posY = y; + this.posZ = z; + } + + public double getX() { + return posX; + } + + public double getY() { + return posY; + } + + public double getZ() { + return posZ; + } + + public void save() { + TransportController.getInstance().saveLocation(this.category.id, this); + } } diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 839c0871c..4ab7d2ce5 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -62,18 +62,14 @@ import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.constants.EnumPotionType; import noppes.npcs.constants.EnumRoleType; import noppes.npcs.constants.EnumStandingType; +import noppes.npcs.controllers.GlobalDataController; import noppes.npcs.controllers.data.*; import noppes.npcs.controllers.FactionController; import noppes.npcs.controllers.LinkedNpcController; import noppes.npcs.controllers.LinkedNpcController.LinkedData; import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.entity.data.DataTimers; -import noppes.npcs.roles.JobBard; -import noppes.npcs.roles.JobFollower; -import noppes.npcs.roles.JobInterface; -import noppes.npcs.roles.RoleCompanion; -import noppes.npcs.roles.RoleFollower; -import noppes.npcs.roles.RoleInterface; +import noppes.npcs.roles.*; import noppes.npcs.scripted.entity.ScriptNpc; import noppes.npcs.scripted.event.*; import noppes.npcs.scripted.interfaces.entity.ICustomNpc; @@ -111,6 +107,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti public long totalTicksAlive = 0; private int taskCount = 1; public int lastInteract = 0; + public int itemGiverId = 0; public Faction faction; //should only be used server side @@ -936,6 +933,11 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti ai.readToNBT(compound); script.readFromNBT(compound); timers.readFromNBT(compound); + if (compound.hasKey("ItemGiverId")) { + itemGiverId = compound.getInteger("ItemGiverId"); + } else { + itemGiverId = -1; + } advanced.readToNBT(compound); if (advanced.role != EnumRoleType.None && roleInterface != null) roleInterface.readFromNBT(compound); diff --git a/src/main/java/noppes/npcs/roles/JobItemGiver.java b/src/main/java/noppes/npcs/roles/JobItemGiver.java index 80c3319fb..6a696f3ca 100644 --- a/src/main/java/noppes/npcs/roles/JobItemGiver.java +++ b/src/main/java/noppes/npcs/roles/JobItemGiver.java @@ -35,6 +35,11 @@ public class JobItemGiver extends JobInterface{ private List toCheck; public Availability availability = new Availability(); + public JobItemGiver() { + super(null); + inventory = new NpcMiscInventory(9); + } + public JobItemGiver(EntityNPCInterface npc) { super(npc); inventory = new NpcMiscInventory(9); @@ -61,10 +66,6 @@ public class JobItemGiver extends JobInterface{ cooldown = nbttagcompound.getInteger("igCooldown"); lines = NBTTags.getStringList(nbttagcompound.getTagList("igLines", 10)); inventory.setFromNBT(nbttagcompound.getCompoundTag("igJobInventory")); - - if(itemGiverId == 0 && GlobalDataController.instance != null) - itemGiverId = GlobalDataController.instance.incrementItemGiverId(); - availability.readFromNBT(nbttagcompound.getCompoundTag("igAvailability")); } @@ -92,7 +93,7 @@ public class JobItemGiver extends JobInterface{ return map; } - private boolean giveItems(EntityPlayer player){ + public boolean giveItems(EntityPlayer player){ PlayerItemGiverData data = PlayerDataController.instance.getPlayerData(player).itemgiverData; if(!canPlayerInteract(data)){ return false; @@ -162,7 +163,7 @@ public class JobItemGiver extends JobInterface{ private int getDay(){ return (int) (npc.worldObj.getTotalWorldTime() / 24000L); } - private boolean canPlayerInteract(PlayerItemGiverData data) { + public boolean canPlayerInteract(PlayerItemGiverData data) { if(inventory.items.isEmpty()) return false; if(isOnTimer()){ diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index cbf368d20..d83a615e6 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -6,6 +6,7 @@ package noppes.npcs.scripted; import java.io.File; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -93,6 +94,10 @@ public class NpcAPI extends AbstractNpcAPI { return ServerCloneController.Instance; } + public ITransportHandler getLocations() { + return TransportController.getInstance(); + } + public IEntity getIEntity(Entity entity) { if(entity == null) return null; @@ -121,6 +126,18 @@ public class NpcAPI extends AbstractNpcAPI { } } + public IEntity[] getLoadedEntities() { + ArrayList list = new ArrayList<>(); + + for (IWorld world : worldCache.values()) { + for (Object obj : world.getMCWorld().loadedEntityList) { + list.add(NpcAPI.Instance().getIEntity((Entity) obj)); + } + } + + return list.toArray(new IEntity[0]); + } + public IBlock getIBlock(World world, BlockPos pos) { return new ScriptBlock(world, world.getBlock(pos.getX(),pos.getY(),pos.getZ()), pos); } diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index 77eb0cc8b..e377e486a 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -1,9 +1,6 @@ package noppes.npcs.scripted; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; import net.minecraft.block.Block; import net.minecraft.entity.Entity; @@ -181,6 +178,15 @@ public class ScriptWorld implements IWorld { return world.countEntities(entity.getMCEntity().getClass()); } + public IEntity[] getLoadedEntities() { + ArrayList list = new ArrayList<>(); + for (Object obj : world.loadedEntityList) { + list.add(NpcAPI.Instance().getIEntity((Entity) obj)); + } + + return list.toArray(new IEntity[0]); + } + public void setTileEntity(int x, int y, int z, ITileEntity tileEntity){ world.setTileEntity(x,y,z,tileEntity.getMCTileEntity()); } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index b812d8e70..d723f4bfb 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -44,6 +44,7 @@ import noppes.npcs.scripted.ScriptPixelmonPlayerData; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.gui.ScriptGui; import noppes.npcs.scripted.interfaces.IParticle; +import noppes.npcs.scripted.interfaces.handler.IPlayerData; import noppes.npcs.scripted.interfaces.handler.data.IQuest; import noppes.npcs.scripted.interfaces.IBlock; import noppes.npcs.scripted.interfaces.IContainer; @@ -557,7 +558,7 @@ public class ScriptPlayer extends ScriptLivingBase return player.isBlocking(); } - private PlayerData getData() { + public PlayerData getData() { if (this.data == null) { this.data = PlayerDataController.instance.getPlayerData(player); } @@ -566,7 +567,7 @@ public class ScriptPlayer extends ScriptLivingBase } public IQuest[] getActiveQuests() { - PlayerQuestData data = this.getData().questData; + PlayerQuestData data = (PlayerQuestData) this.getData().getQuestData(); List quests = new ArrayList(); Iterator var3 = data.activeQuests.keySet().iterator(); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java b/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java index 2a169f994..b6aa3afcd 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java @@ -55,6 +55,8 @@ public abstract class AbstractNpcAPI { public abstract ICloneHandler getClones(); + public abstract ITransportHandler getLocations(); + public abstract ICustomNpc createNPC(World var1); /** @@ -65,6 +67,8 @@ public abstract class AbstractNpcAPI { public abstract IEntity getIEntity(Entity var1); + public abstract IEntity[] getLoadedEntities(); + public abstract IBlock getIBlock(World var1, BlockPos var2); public abstract IBlock getIBlock(World world, Block block, BlockPos pos); @@ -85,6 +89,8 @@ public abstract class AbstractNpcAPI { public abstract IDamageSource getIDamageSource(DamageSource var1); + public abstract IDamageSource getIDamageSource(IEntity entity); + public abstract EventBus events(); public abstract File getGlobalDir(); @@ -137,6 +143,8 @@ public abstract class AbstractNpcAPI { public abstract INbt getINbt(NBTTagCompound nbtTagCompound); + public abstract INbt stringToNbt(String str); + public abstract IPlayer[] getAllServerPlayers(); public abstract IItemStack createItem(String id, int damage, int size); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java index 78585deca..275d51e0f 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java @@ -98,6 +98,8 @@ public interface IWorld { */ int countEntities(IEntity entity); + IEntity[] getLoadedEntities(); + /** * Sets the block's tile entity at the given position. */ 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 2dbd2c72b..e6cb61dd3 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/entity/IPlayer.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/entity/IPlayer.java @@ -5,6 +5,7 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.util.EnumChatFormatting; import noppes.npcs.scripted.entity.ScriptDBCPlayer; import noppes.npcs.scripted.interfaces.handler.IOverlayHandler; +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; @@ -228,6 +229,8 @@ public interface IPlayer extends IEntityLivingBase boolean blocking(); + public IPlayerData getData(); + IQuest[] getActiveQuests(); IContainer getOpenContainer(); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerBankData.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerBankData.java new file mode 100644 index 000000000..5303af7c3 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerBankData.java @@ -0,0 +1,4 @@ +package noppes.npcs.scripted.interfaces.handler; + +public interface IPlayerBankData { +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerData.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerData.java new file mode 100644 index 000000000..2a0a2b048 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerData.java @@ -0,0 +1,29 @@ +package noppes.npcs.scripted.interfaces.handler; +import noppes.npcs.scripted.interfaces.entity.ICustomNpc; + +public interface IPlayerData { + + void setCompanion(ICustomNpc npc); + + ICustomNpc getCompanion(); + + boolean hasCompanion(); + + int getCompanionID(); + + IPlayerDialogData getDialogData(); + + IPlayerBankData getBankData(); + + IPlayerQuestData getQuestData(); + + IPlayerTransportData getTransportData(); + + IPlayerFactionData getFactionData(); + + IPlayerItemGiverData getItemGiverData(); + + IPlayerMailData getMailData(); + + void save(); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerDialogData.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerDialogData.java new file mode 100644 index 000000000..b816dd68b --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerDialogData.java @@ -0,0 +1,10 @@ +package noppes.npcs.scripted.interfaces.handler; + +public interface IPlayerDialogData { + + boolean hasReadDialog(int id); + + void readDialog(int id); + + void unreadDialog(int id); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerFactionData.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerFactionData.java new file mode 100644 index 000000000..f6eba6b97 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerFactionData.java @@ -0,0 +1,10 @@ +package noppes.npcs.scripted.interfaces.handler; + +public interface IPlayerFactionData { + + int getPoints(int id); + + void addPoints(int id, int points); + + void setPoints(int id, int points); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerItemGiverData.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerItemGiverData.java new file mode 100644 index 000000000..dd319ae82 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerItemGiverData.java @@ -0,0 +1,14 @@ +package noppes.npcs.scripted.interfaces.handler; + +import noppes.npcs.scripted.interfaces.jobs.IJobItemGiver; + +public interface IPlayerItemGiverData { + + long getTime(IJobItemGiver jobItemGiver); + + void setTime(IJobItemGiver jobItemGiver, long day); + + boolean hasInteractedBefore(IJobItemGiver jobItemGiver); + + IJobItemGiver[] getItemGivers(); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerMailData.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerMailData.java new file mode 100644 index 000000000..aff72aa04 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerMailData.java @@ -0,0 +1,22 @@ +package noppes.npcs.scripted.interfaces.handler; + +import noppes.npcs.scripted.interfaces.handler.data.IPlayerMail; + +public interface IPlayerMailData { + + boolean hasMail(); + + void addMail(IPlayerMail mail); + + void removeMail(IPlayerMail mail); + + boolean hasMail(IPlayerMail mail); + + IPlayerMail[] getAllMail(); + + IPlayerMail[] getUnreadMail(); + + IPlayerMail[] getReadMail(); + + IPlayerMail[] getMailFrom(String sender); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerQuestData.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerQuestData.java new file mode 100644 index 000000000..ce3bc3f04 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerQuestData.java @@ -0,0 +1,24 @@ +package noppes.npcs.scripted.interfaces.handler; + +import noppes.npcs.scripted.interfaces.handler.data.IQuest; + +public interface IPlayerQuestData { + + IQuest getTrackedQuest(); + + void startQuest(int id); + + void finishQuest(int id); + + void stopQuest(int id); + + void removeQuest(int id); + + boolean hasFinishedQuest(int id); + + public boolean hasActiveQuest(int id); + + IQuest[] getActiveQuests(); + + IQuest[] getFinishedQuests(); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerTransportData.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerTransportData.java new file mode 100644 index 000000000..86e529758 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerTransportData.java @@ -0,0 +1,18 @@ +package noppes.npcs.scripted.interfaces.handler; + +import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation; + +public interface IPlayerTransportData { + + boolean hasTransport(int id); + + void addTransport(int id); + + void addTransport(ITransportLocation location); + + ITransportLocation getTransport(int id); + + ITransportLocation[] getTransports(); + + void removeTransport(int id); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/ITransportHandler.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/ITransportHandler.java new file mode 100644 index 000000000..cb16d0967 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/ITransportHandler.java @@ -0,0 +1,14 @@ +package noppes.npcs.scripted.interfaces.handler; + +import noppes.npcs.scripted.interfaces.handler.data.ITransportCategory; + +public interface ITransportHandler { + + ITransportCategory[] categories(); + + void createCategory(String title); + + ITransportCategory getCategory(String title); + + void removeCategory(String title); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IPlayerMail.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IPlayerMail.java new file mode 100644 index 000000000..4ade6a2e6 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IPlayerMail.java @@ -0,0 +1,32 @@ +package noppes.npcs.scripted.interfaces.handler.data; + +import noppes.npcs.scripted.interfaces.item.IItemStack; + +public interface IPlayerMail { + + void setPageText(String[] pages); + + String[] getPageText(); + + int getPageCount(); + + void setSender(String sender); + + String getSender(); + + void setSubject(String subject); + + String getSubject(); + + long getTimePast(); + + long getTimeSent(); + + boolean hasQuest(); + + IQuest getQuest(); + + IItemStack[] getItems(); + + void setItems(IItemStack[] items); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/data/ITransportCategory.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/ITransportCategory.java new file mode 100644 index 000000000..be97d683d --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/ITransportCategory.java @@ -0,0 +1,16 @@ +package noppes.npcs.scripted.interfaces.handler.data; + +public interface ITransportCategory { + + int getId(); + + void setTitle(String title); + + String getTitle(); + + void addLocation(String name); + + ITransportLocation getLocation(String name); + + void removeLocation(String name); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/data/ITransportLocation.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/ITransportLocation.java new file mode 100644 index 000000000..6978ae0b9 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/ITransportLocation.java @@ -0,0 +1,28 @@ +package noppes.npcs.scripted.interfaces.handler.data; + +public interface ITransportLocation { + + int getId(); + + void setName(String name); + + String getName(); + + void setDimension(int dimension); + + int getDimension(); + + void setType(int type); + + int getType(); + + void setPosition(int x, int y, int z); + + double getX(); + + double getY(); + + double getZ(); + + void save(); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJob.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJob.java new file mode 100644 index 000000000..41c82e852 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJob.java @@ -0,0 +1,13 @@ +package noppes.npcs.scripted.interfaces.jobs; + +import noppes.npcs.roles.JobInterface; +import noppes.npcs.scripted.interfaces.entity.ICustomNpc; + +public interface IJob { + + int getType(); + + JobInterface getJobInterface(); + + ICustomNpc getNpc(); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobBard.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobBard.java new file mode 100644 index 000000000..a9416d60e --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobBard.java @@ -0,0 +1,8 @@ +package noppes.npcs.scripted.interfaces.jobs; + +public interface IJobBard extends IJob { + + String getSong(); + + void setSong(String song); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobConversation.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobConversation.java new file mode 100644 index 000000000..e302430ec --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobConversation.java @@ -0,0 +1,5 @@ +package noppes.npcs.scripted.interfaces.jobs; + +public interface IJobConversation extends IJob { + +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobFollower.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobFollower.java new file mode 100644 index 000000000..963d1b66a --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobFollower.java @@ -0,0 +1,14 @@ +package noppes.npcs.scripted.interfaces.jobs; + +import noppes.npcs.scripted.interfaces.entity.ICustomNpc; + +public interface IJobFollower extends IJob { + + String getFollowingName(); + + void setFollowingName(String name); + + ICustomNpc getFollowingNpc(); + + boolean isFollowing(); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobGuard.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobGuard.java new file mode 100644 index 000000000..16710a8a7 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobGuard.java @@ -0,0 +1,4 @@ +package noppes.npcs.scripted.interfaces.jobs; + +public interface IJobGuard extends IJob { +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobHealer.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobHealer.java new file mode 100644 index 000000000..4cc335383 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobHealer.java @@ -0,0 +1,8 @@ +package noppes.npcs.scripted.interfaces.jobs; + +import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; + +public interface IJobHealer extends IJob { + + void heal(IEntityLivingBase entity, float amount); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobItemGiver.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobItemGiver.java new file mode 100644 index 000000000..c09e2ff8a --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobItemGiver.java @@ -0,0 +1,34 @@ +package noppes.npcs.scripted.interfaces.jobs; + +import noppes.npcs.scripted.interfaces.entity.IPlayer; +import noppes.npcs.scripted.interfaces.handler.data.IAvailability; +import noppes.npcs.scripted.interfaces.item.IItemStack; + +public interface IJobItemGiver extends IJob { + + void setCooldown(int cooldown); + + void setCooldownType(int type); + + int getCooldownType(); + + void setGivingMethod(int method); + + int getGivingMethod(); + + void setLines(String[] lines); + + String[] getLines(); + + void setAvailability(IAvailability availability); + + IAvailability getAvailability(); + + void setItem(int slot, IItemStack item); + + IItemStack[] getItems(); + + boolean giveItems(IPlayer player); + + boolean canPlayerInteract(IPlayer player); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobPuppet.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobPuppet.java new file mode 100644 index 000000000..b96d125e2 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobPuppet.java @@ -0,0 +1,20 @@ +package noppes.npcs.scripted.interfaces.jobs; + +public interface IJobPuppet extends IJob { + + int getRotationX(int part); + + int getRotationY(int part); + + int getRotationZ(int part); + + void setRotationX(int part, int rotation); + + void setRotationY(int part, int rotation); + + void setRotationZ(int part, int rotation); + + boolean isEnabled(int part); + + void setEnabled(int part, boolean bo); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobSpawner.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobSpawner.java new file mode 100644 index 000000000..b9ff96ac5 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobSpawner.java @@ -0,0 +1,10 @@ +package noppes.npcs.scripted.interfaces.jobs; + +import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; + +public interface IJobSpawner extends IJob { + + IEntityLivingBase spawnEntity(int number); + + void removeAllSpawned(); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/roles/IRole.java b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRole.java new file mode 100644 index 000000000..f309d7bd0 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRole.java @@ -0,0 +1,6 @@ +package noppes.npcs.scripted.interfaces.roles; + +public interface IRole { + + int getType(); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleBank.java b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleBank.java new file mode 100644 index 000000000..1f8d209dc --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleBank.java @@ -0,0 +1,5 @@ +package noppes.npcs.scripted.interfaces.roles; + +public interface IRoleBank extends IRole { + +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleFollower.java b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleFollower.java new file mode 100644 index 000000000..66c125572 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleFollower.java @@ -0,0 +1,64 @@ +package noppes.npcs.scripted.interfaces.roles; + +import noppes.npcs.scripted.interfaces.entity.IPlayer; + +public interface IRoleFollower extends IRole { + + /** + * @since 1.7.10c + * @param player Player who is set as the owner. If null given everything resets + */ + void setOwner(IPlayer player); + + /** + * @since 1.7.10c + * @return Returns the followers owner. Returns null if he has no owner or the owner is offline + */ + IPlayer getOwner(); + + /** + * @since 1.7.10c + * @return Returns whether or not the follower has an owner + */ + boolean hasOwner(); + + boolean isFollowing(); + + void setIsFollowing(boolean following); + + /** + * @since 1.7.10c + * @return Returns days left + */ + int getDaysLeft(); + + /** + * @since 1.7.10c + * @param days The days you want to add to the days remaining + */ + void addDaysLeft(int days); + + /** + * @since 1.7.10c + * @return Returns whether or not the follower is set to infinite days + */ + boolean getInfiniteDays(); + + /** + * @since 1.7.10c + * @param infinite Sets whether the days hired are infinite + */ + void setInfiniteDays(boolean infinite); + + /** + * @since 1.7.10c + * @return Return whether the gui is disabled + */ + boolean getGuiDisabled(); + + /** + * @since 1.7.10c + * @param disabled Set the gui to be disabled or not + */ + void setGuiDisabled(boolean disabled); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleMailman.java b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleMailman.java new file mode 100644 index 000000000..3813b031e --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleMailman.java @@ -0,0 +1,5 @@ +package noppes.npcs.scripted.interfaces.roles; + +public interface IRoleMailman extends IRole { + +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleTrader.java b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleTrader.java new file mode 100644 index 000000000..ed469568b --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleTrader.java @@ -0,0 +1,119 @@ +package noppes.npcs.scripted.interfaces.roles; + +import noppes.npcs.scripted.interfaces.entity.IPlayer; +import noppes.npcs.scripted.interfaces.item.IItemStack; + +public interface IRoleTrader extends IRole { + + /** + * @param slot Slot number 0-17 + * @param currency Currency item + * @param currency2 Currency item number two + * @param sold Item to be sold by this npc + */ + void setSellOption(int slot, IItemStack currency, IItemStack currency2, IItemStack sold); + + /** + * @param slot Slot number 0-17 + * @param currency Currency item + * @param sold Item to be sold by this npc + */ + void setSellOption(int slot, IItemStack currency, IItemStack sold); + + /** + * @param slot + * @return The item being sold in this slot. + */ + IItemStack getSellOption(int slot); + + /** + * @param slot + * @return a ScriptItemStack array of size 2 which contains the currency of this trade + */ + IItemStack[] getCurrency(int slot); + + /** + * @param slot Slot number 0-17 + */ + void removeSellOption(int slot); + + /** + * @param name The trader Linked Market name + */ + void setMarket(String name); + + /** + * @return Get the currently set Linked Market name + */ + String getMarket(); + + /** + * @param slot + * @return the number of times an item has been sold on that slot + */ + int getPurchaseNum(int slot); + + /** + * @param slot + * @param player + * @return the number of times this player has purchased from this trader + */ + int getPurchaseNum(int slot, IPlayer player); + + /** + * Sets the purchase count of all slots to 0 + */ + void resetPurchaseNum(); + + /** + * sets the purchase num for that slot to 0 + * @param slot + */ + void resetPurchaseNum(int slot); + + /** + * sets the purchase num for that slot and player to 0 + * @param slot + * @param player + */ + void resetPurchaseNum(int slot, IPlayer player); + + /** + * @param slot + * @return if this slot is enabled + */ + boolean isSlotEnabled(int slot); + + /** + * @param slot + * @param player + * @return if this slot is enabled for this player + */ + boolean isSlotEnabled(int slot, IPlayer player); + + /** + * prevent an item from being sold on that slot + * @param slot + */ + void disableSlot(int slot); + + /** + * disables the slot for this player + * @param slot + * @param player + */ + void disableSlot(int slot, IPlayer player); + + /** + * allow an item to be sold on that slot + * @param slot + */ + void enableSlot(int slot); + + /** + * enables the slot for this player + * @param slot + * @param player + */ + void enableSlot(int slot, IPlayer player); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleTransporter.java b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleTransporter.java new file mode 100644 index 000000000..b5c9b8f4c --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleTransporter.java @@ -0,0 +1,5 @@ +package noppes.npcs.scripted.interfaces.roles; + +public interface IRoleTransporter extends IRole { + +} diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobBard.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobBard.java index 306a652cc..fe5811930 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobBard.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobBard.java @@ -3,8 +3,9 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobBard; import noppes.npcs.scripted.constants.JobType; +import noppes.npcs.scripted.interfaces.jobs.IJobBard; -public class ScriptJobBard extends ScriptJobInterface{ +public class ScriptJobBard extends ScriptJobInterface implements IJobBard { private JobBard job; public ScriptJobBard(EntityNPCInterface npc){ super(npc); diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobConversation.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobConversation.java index 5f92c6d92..ea8071202 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobConversation.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobConversation.java @@ -3,8 +3,9 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobConversation; import noppes.npcs.scripted.constants.JobType; +import noppes.npcs.scripted.interfaces.jobs.IJobConversation; -public class ScriptJobConversation extends ScriptJobInterface{ +public class ScriptJobConversation extends ScriptJobInterface implements IJobConversation { private JobConversation job; public ScriptJobConversation(EntityNPCInterface npc){ super(npc); diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobFollower.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobFollower.java index ddbce4dd0..c34c18ef4 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobFollower.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobFollower.java @@ -4,8 +4,9 @@ import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobFollower; import noppes.npcs.scripted.constants.JobType; import noppes.npcs.scripted.interfaces.entity.ICustomNpc; +import noppes.npcs.scripted.interfaces.jobs.IJobFollower; -public class ScriptJobFollower extends ScriptJobInterface{ +public class ScriptJobFollower extends ScriptJobInterface implements IJobFollower { private JobFollower job; public ScriptJobFollower(EntityNPCInterface npc){ super(npc); @@ -20,7 +21,7 @@ public class ScriptJobFollower extends ScriptJobInterface{ job.name = name; } - public ICustomNpc getFollowingNpc(){ + public ICustomNpc getFollowingNpc() { if(!isFollowing()) return null; return job.following.script.dummyNpc; diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobGuard.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobGuard.java index 1543cd0a6..e16340f30 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobGuard.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobGuard.java @@ -3,8 +3,9 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobGuard; import noppes.npcs.scripted.constants.JobType; +import noppes.npcs.scripted.interfaces.jobs.IJobGuard; -public class ScriptJobGuard extends ScriptJobInterface{ +public class ScriptJobGuard extends ScriptJobInterface implements IJobGuard { private JobGuard job; public ScriptJobGuard(EntityNPCInterface npc){ super(npc); diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java index eec32c14c..85578453b 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java @@ -4,8 +4,9 @@ import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobHealer; import noppes.npcs.scripted.constants.JobType; import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; +import noppes.npcs.scripted.interfaces.jobs.IJobHealer; -public class ScriptJobHealer extends ScriptJobInterface{ +public class ScriptJobHealer extends ScriptJobInterface implements IJobHealer { private JobHealer job; public ScriptJobHealer(EntityNPCInterface npc){ super(npc); diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobInterface.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobInterface.java index d3887629c..b68789540 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobInterface.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobInterface.java @@ -1,13 +1,24 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.roles.JobInterface; +import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.constants.JobType; +import noppes.npcs.scripted.interfaces.entity.ICustomNpc; +import noppes.npcs.scripted.interfaces.jobs.IJob; -public class ScriptJobInterface { - protected EntityNPCInterface npc; +public class ScriptJobInterface implements IJob { + public final EntityNPCInterface npc; + public final JobInterface jobInterface; + + public ScriptJobInterface(JobInterface jobInterface) { + this.npc = null; + this.jobInterface = jobInterface; + } public ScriptJobInterface(EntityNPCInterface npc){ this.npc = npc; + this.jobInterface = npc.jobInterface; } /** * @see noppes.npcs.scripted.constants.JobType @@ -16,4 +27,13 @@ public class ScriptJobInterface { public int getType(){ return JobType.UNKNOWN; } + + public JobInterface getJobInterface() { + return jobInterface; + } + + public ICustomNpc getNpc() { + return (ICustomNpc) NpcAPI.Instance().getIEntity(npc); + } + } diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobItemGiver.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobItemGiver.java index 046f89dac..b32841b93 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobItemGiver.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobItemGiver.java @@ -1,11 +1,29 @@ package noppes.npcs.scripted.roles; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import noppes.npcs.controllers.data.Availability; +import noppes.npcs.controllers.data.PlayerItemGiverData; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobItemGiver; +import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.constants.JobType; +import noppes.npcs.scripted.interfaces.entity.IPlayer; +import noppes.npcs.scripted.interfaces.handler.data.IAvailability; +import noppes.npcs.scripted.interfaces.item.IItemStack; +import noppes.npcs.scripted.interfaces.jobs.IJobItemGiver; -public class ScriptJobItemGiver extends ScriptJobInterface{ +import java.util.ArrayList; +import java.util.Arrays; + +public class ScriptJobItemGiver extends ScriptJobInterface implements IJobItemGiver { private JobItemGiver job; + + public ScriptJobItemGiver(JobItemGiver job) { + super(job); + this.job = job; + } + public ScriptJobItemGiver(EntityNPCInterface npc){ super(npc); this.job = (JobItemGiver) npc.jobInterface; @@ -15,5 +33,81 @@ public class ScriptJobItemGiver extends ScriptJobInterface{ public int getType(){ return JobType.ITEMGIVER; } - + + public void setCooldown(int cooldown) { + if (cooldown < 0) + cooldown = 0; + + job.cooldown = cooldown; + } + + public void setCooldownType(int type) { + if (type < 0) { + type = 0; + } else if (type > 2) { + type = 2; + } + job.cooldownType = type; + } + + public int getCooldownType() { + return job.cooldownType; + } + + public void setGivingMethod(int method) { + if (method < 0) { + method = 0; + } else if (method > 4) { + method = 4; + } + job.givingMethod = method; + } + + public int getGivingMethod() { + return job.givingMethod; + } + + public void setLines(String[] lines) { + job.lines = new ArrayList<>(Arrays.asList(lines)); + } + + public String[] getLines() { + return job.lines.toArray(new String[0]); + } + + public void setAvailability(IAvailability availability) { + job.availability = (Availability) availability; + } + + public IAvailability getAvailability() { + return job.availability; + } + + public void setItem(int slot, IItemStack item) { + if (slot < 0) { + slot = 0; + } else if (slot > 8) { + slot = 8; + } + + job.inventory.items.put(slot, item.getMCItemStack()); + } + + public IItemStack[] getItems() { + ArrayList items = new ArrayList<>(); + + for (int i = 0; i < job.inventory.getSizeInventory(); i++) { + items.add(NpcAPI.Instance().getIItemStack(job.inventory.getStackInSlot(i))); + } + + return items.toArray(new IItemStack[0]); + } + + public boolean giveItems(IPlayer player) { + return job.giveItems((EntityPlayer) player.getMCEntity()); + } + + public boolean canPlayerInteract(IPlayer player) { + return job.canPlayerInteract((PlayerItemGiverData) player.getData().getItemGiverData()); + } } diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobPuppet.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobPuppet.java index 20b12965f..fa59f48da 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobPuppet.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobPuppet.java @@ -3,8 +3,9 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobPuppet; import noppes.npcs.scripted.constants.JobType; +import noppes.npcs.scripted.interfaces.jobs.IJobPuppet; -public class ScriptJobPuppet extends ScriptJobInterface{ +public class ScriptJobPuppet extends ScriptJobInterface implements IJobPuppet { private JobPuppet job; public ScriptJobPuppet(EntityNPCInterface npc){ super(npc); @@ -100,7 +101,7 @@ public class ScriptJobPuppet extends ScriptJobInterface{ /** * @since 1.7.10c - * @param type Body part (0:head, 1:body, 2:leftarm, 3:rightarm, 4:leftleg, 5:rightleg) + * @param part Body part (0:head, 1:body, 2:leftarm, 3:rightarm, 4:leftleg, 5:rightleg) * @param rotation Rotation the of the body part */ public void setRotationY(int part, int rotation){ diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobSpawner.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobSpawner.java index 64bc609f4..c44f03aad 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobSpawner.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobSpawner.java @@ -8,8 +8,9 @@ import noppes.npcs.roles.JobSpawner; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.constants.JobType; import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; +import noppes.npcs.scripted.interfaces.jobs.IJobSpawner; -public class ScriptJobSpawner extends ScriptJobInterface{ +public class ScriptJobSpawner extends ScriptJobInterface implements IJobSpawner { private JobSpawner job; public ScriptJobSpawner(EntityNPCInterface npc){ super(npc); diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleBank.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleBank.java index 222ddcc9e..2c5d48e23 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleBank.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleBank.java @@ -2,8 +2,9 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.constants.RoleType; +import noppes.npcs.scripted.interfaces.roles.IRoleBank; -public class ScriptRoleBank extends ScriptRoleInterface{ +public class ScriptRoleBank extends ScriptRoleInterface implements IRoleBank { public ScriptRoleBank(EntityNPCInterface npc) { super(npc); diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java index 4667c0d18..f6c7850a6 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java @@ -6,18 +6,15 @@ import noppes.npcs.roles.RoleFollower; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.constants.RoleType; import noppes.npcs.scripted.interfaces.entity.IPlayer; +import noppes.npcs.scripted.interfaces.roles.IRoleFollower; -public class ScriptRoleFollower extends ScriptRoleInterface{ +public class ScriptRoleFollower extends ScriptRoleInterface implements IRoleFollower { private RoleFollower role; public ScriptRoleFollower(EntityNPCInterface npc) { super(npc); role = (RoleFollower) npc.roleInterface; } - - /** - * @since 1.7.10c - * @param player Player who is set as the owner. If null given everything resets - */ + public void setOwner(IPlayer player){ if(player == null || player.getMCEntity() == null){ role.setOwner(null); @@ -26,22 +23,14 @@ public class ScriptRoleFollower extends ScriptRoleInterface{ EntityPlayer mcplayer = (EntityPlayer) player.getMCEntity(); role.setOwner(mcplayer); } - - /** - * @since 1.7.10c - * @return Returns the followers owner. Returns null if he has no owner or the owner is offline - */ + public IPlayer getOwner(){ if(role.owner == null) return null; return (IPlayer) NpcAPI.Instance().getIEntity(role.owner); } - - /** - * @since 1.7.10c - * @return Returns whether or not the follower has an owner - */ + public boolean hasOwner(){ return role.owner != null; } @@ -53,51 +42,27 @@ public class ScriptRoleFollower extends ScriptRoleInterface{ public void setIsFollowing(boolean following) { if (role.owner != null && role.getDaysLeft() > 0) role.isFollowing = following; } - - /** - * @since 1.7.10c - * @return Returns days left - */ + public int getDaysLeft(){ return role.getDaysLeft(); } - - /** - * @since 1.7.10c - * @param days The days you want to add to the days remaining - */ + public void addDaysLeft(int days){ role.addDays(days); } - - /** - * @since 1.7.10c - * @return Returns whether or not the follower is set to infinite days - */ + public boolean getInfiniteDays(){ return role.infiniteDays; } - - /** - * @since 1.7.10c - * @param infinite Sets whether the days hired are infinite - */ + public void setInfiniteDays(boolean infinite){ role.infiniteDays = infinite; } - - /** - * @since 1.7.10c - * @return Return whether the gui is disabled - */ + public boolean getGuiDisabled(){ return role.disableGui; } - - /** - * @since 1.7.10c - * @param disabled Set the gui to be disabled or not - */ + public void setGuiDisabled(boolean disabled){ role.disableGui = disabled; } diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleInterface.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleInterface.java index 338306819..eef73dd82 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleInterface.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleInterface.java @@ -1,13 +1,17 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.roles.RoleInterface; import noppes.npcs.scripted.constants.RoleType; +import noppes.npcs.scripted.interfaces.roles.IRole; -public class ScriptRoleInterface { - protected EntityNPCInterface npc; +public class ScriptRoleInterface implements IRole { + public final EntityNPCInterface npc; + public final RoleInterface role; public ScriptRoleInterface(EntityNPCInterface npc){ this.npc = npc; + this.role = npc.roleInterface; } /** diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleMailman.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleMailman.java index dd461bf92..907f6e3ce 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleMailman.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleMailman.java @@ -2,8 +2,9 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.constants.RoleType; +import noppes.npcs.scripted.interfaces.roles.IRoleMailman; -public class ScriptRoleMailman extends ScriptRoleInterface{ +public class ScriptRoleMailman extends ScriptRoleInterface implements IRoleMailman { public ScriptRoleMailman(EntityNPCInterface npc) { super(npc); diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java index 6d36f0d0d..8aa4f13dc 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java @@ -8,20 +8,15 @@ import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.interfaces.item.IItemStack; import noppes.npcs.scripted.constants.RoleType; import noppes.npcs.scripted.interfaces.entity.IPlayer; +import noppes.npcs.scripted.interfaces.roles.IRoleTrader; -public class ScriptRoleTrader extends ScriptRoleInterface{ +public class ScriptRoleTrader extends ScriptRoleInterface implements IRoleTrader { private RoleTrader role; public ScriptRoleTrader(EntityNPCInterface npc) { super(npc); role = (RoleTrader) npc.roleInterface; } - - /** - * @param slot Slot number 0-17 - * @param currency Currency item - * @param currency2 Currency item number two - * @param sold Item to be sold by this npc - */ + public void setSellOption(int slot, IItemStack currency, IItemStack currency2, IItemStack sold){ if(sold == null || slot >= 18 || slot < 0) return; @@ -40,29 +35,16 @@ public class ScriptRoleTrader extends ScriptRoleInterface{ role.inventorySold.items.put(slot, sold.getMCItemStack()); } - /** - * @param slot Slot number 0-17 - * @param currency Currency item - * @param sold Item to be sold by this npc - */ public void setSellOption(int slot, IItemStack currency, IItemStack sold){ setSellOption(slot, currency, null, sold); } - - /** - * @param slot - * @return The item being sold in this slot. - */ + public IItemStack getSellOption(int slot) { if (slot >= 18 || slot < 0) return null; if (role.inventorySold.items.get(slot) == null) return null; return NpcAPI.Instance().getIItemStack(role.inventoryCurrency.items.get(slot)); } - - /** - * @param slot - * @return a ScriptItemStack array of size 2 which contains the currency of this trade - */ + public IItemStack[] getCurrency(int slot) { if (slot >= 18 || slot < 0) return null; IItemStack[] currency = new IItemStack[2]; @@ -75,127 +57,72 @@ public class ScriptRoleTrader extends ScriptRoleInterface{ return currency; } - /** - * @param slot Slot number 0-17 - */ + public void removeSellOption(int slot){ if(slot >= 18 || slot < 0) return; role.inventoryCurrency.items.remove(slot); role.inventoryCurrency.items.remove(slot + 18); role.inventorySold.items.remove(slot); } - /** - * @param name The trader Linked Market name - */ + public void setMarket(String name){ role.marketName = name; Market.load(role, name); } - - /** - * @return Get the currently set Linked Market name - */ + public String getMarket(){ return role.marketName; } - - /** - * @param slot - * @return the number of times an item has been sold on that slot - */ + public int getPurchaseNum(int slot) { if(slot >= 18 || slot < 0) return -1; return role.purchases[slot]; } - - /** - * @param slot - * @param player - * @return the number of times this player has purchased from this trader - */ + public int getPurchaseNum(int slot, IPlayer player) { if(slot >= 18 || slot < 0) return -1; return role.getArrayByName(player.getDisplayName(), role.playerPurchases)[slot]; } - - /** - * Sets the purchase count of all slots to 0 - */ + public void resetPurchaseNum() { for (int i = 0; i < role.purchases.length; ++i) role.purchases[i] = 0; } - - /** - * sets the purchase num for that slot to 0 - * @param slot - */ + public void resetPurchaseNum(int slot) { if(slot >= 18 || slot < 0) return; role.purchases[slot] = 0; } - - /** - * sets the purchase num for that slot and player to 0 - * @param slot - * @param player - */ + public void resetPurchaseNum(int slot, IPlayer player) { if(slot >= 18 || slot < 0) return; role.getArrayByName(player.getDisplayName(), role.playerPurchases)[slot] = 0; } - - /** - * @param slot - * @return if this slot is enabled - */ + public boolean isSlotEnabled(int slot) { if(slot >= 18 || slot < 0) return false; return role.disableSlot[slot] > 0; } - - /** - * @param slot - * @param player - * @return if this slot is enabled for this player - */ + public boolean isSlotEnabled(int slot, IPlayer player) { if(slot >= 18 || slot < 0) return false; return role.isSlotEnabled(slot, (EntityPlayer)player.getMCEntity()); } - - /** - * prevent an item from being sold on that slot - * @param slot - */ + public void disableSlot(int slot) { if(slot >= 18 || slot < 0) return; role.disableSlot[slot] = 1; } - - /** - * disables the slot for this player - * @param slot - * @param player - */ + public void disableSlot(int slot, IPlayer player) { if(slot >= 18 || slot < 0) return; role.getArrayByName(player.getDisplayName(), role.playerDisableSlot)[slot] = 1; } - - /** - * allow an item to be sold on that slot - * @param slot - */ + public void enableSlot(int slot) { if(slot >= 18 || slot < 0) return; role.disableSlot[slot] = 0; } - - /** - * enables the slot for this player - * @param slot - * @param player - */ + public void enableSlot(int slot, IPlayer player) { if(slot >= 18 || slot < 0) return; role.getArrayByName(player.getDisplayName(), role.playerDisableSlot)[slot] = 0; diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTransporter.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTransporter.java index 50e9b63cd..3fbe5560b 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTransporter.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTransporter.java @@ -2,8 +2,9 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.constants.RoleType; +import noppes.npcs.scripted.interfaces.roles.IRoleTransporter; -public class ScriptRoleTransporter extends ScriptRoleInterface{ +public class ScriptRoleTransporter extends ScriptRoleInterface implements IRoleTransporter { public ScriptRoleTransporter(EntityNPCInterface npc) { super(npc); From b70d0ba08f18ab22b56a0194f5f397523ae82e99 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Sun, 12 Jun 2022 01:52:57 -0500 Subject: [PATCH 37/40] Fixed NPC textures being adjusted if an NPC has an entity model different from the default CNPC model. --- .../npcs/client/renderer/RenderNPCInterface.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java index 22a6a2eeb..47caf4f90 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java @@ -313,11 +313,16 @@ public class RenderNPCInterface extends RenderLiving{ EntityNPCInterface npc = (EntityNPCInterface) entity; if (npc.textureLocation == null) { if (npc.display.skinType == 0) { - if (!(npc.display.texture).equals("")) { - //npc.textureLocation = new ResourceLocation(npc.display.texture); - try { - npc.textureLocation = adjustLocalTexture(npc, new ResourceLocation(npc.display.texture)); - } catch (IOException ignored) {} + if (npc instanceof EntityCustomNpc && ((EntityCustomNpc) npc).modelData.entityClass == null) { + if (!(npc.display.texture).equals("")) { + //npc.textureLocation = new ResourceLocation(npc.display.texture); + try { + npc.textureLocation = adjustLocalTexture(npc, new ResourceLocation(npc.display.texture)); + } catch (IOException ignored) { + } + } + } else { + npc.textureLocation = new ResourceLocation(npc.display.texture); } } else if(LastTextureTick < 5) { //fixes request flood somewhat return AbstractClientPlayer.locationStevePng; From f52721dc8f1dbf980ae837b9dd4315e7ed371cac Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Sun, 12 Jun 2022 02:52:11 -0500 Subject: [PATCH 38/40] Small fix for NPC textures not appearing for different NpcGolem, NpcDragon, NpcSlime, & NpcPony types. --- .../client/gui/model/GuiEntitySelection.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/model/GuiEntitySelection.java b/src/main/java/noppes/npcs/client/gui/model/GuiEntitySelection.java index 0e124d88e..6029fe636 100644 --- a/src/main/java/noppes/npcs/client/gui/model/GuiEntitySelection.java +++ b/src/main/java/noppes/npcs/client/gui/model/GuiEntitySelection.java @@ -16,7 +16,7 @@ import noppes.npcs.client.EntityUtil; import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.GuiNPCStringSlot; import noppes.npcs.client.gui.util.GuiNpcButton; -import noppes.npcs.entity.EntityCustomNpc; +import noppes.npcs.entity.*; import org.lwjgl.opengl.GL11; @@ -115,13 +115,29 @@ public class GuiEntitySelection extends GuiNPCInterface super.drawScreen(i, j, f); } public void elementClicked(){ + if (playerdata.getEntityClass().equals(parent.data.get(slot.selected))) { + return; + } + try{ playerdata.setEntityClass(parent.data.get(slot.selected)); EntityLivingBase entity = playerdata.getEntity(npc); if(entity != null){ npc.display.modelType = 0; - RendererLivingEntity render = (RendererLivingEntity) RenderManager.instance.getEntityRenderObject(entity); - npc.display.texture = NPCRendererHelper.getTexture(render,entity); + if (entity instanceof EntityNpcCrystal) { + npc.display.texture = "customnpcs:textures/entity/crystal/EnderCrystal.png"; + } else if (entity instanceof EntityNPCGolem) { + npc.display.texture = "customnpcs:textures/entity/golem/Iron Golem.png"; + } else if (entity instanceof EntityNpcPony) { + npc.display.texture = "customnpcs:textures/entity/ponies/MineLP Derpy Hooves.png"; + } else if (entity instanceof EntityNpcSlime) { + npc.display.texture = "customnpcs:textures/entity/slime/Slime.png"; + } else if (entity instanceof EntityNpcDragon) { + npc.display.texture = "customnpcs:textures/entity/dragon/BlackDragon.png"; + } else { + RendererLivingEntity render = (RendererLivingEntity) RenderManager.instance.getEntityRenderObject(entity); + npc.display.texture = NPCRendererHelper.getTexture(render, entity); + } } else{ npc.display.texture = "customnpcs:textures/entity/humanmale/Steve.png"; @@ -130,8 +146,7 @@ public class GuiEntitySelection extends GuiNPCInterface npc.display.skinOverlayData.overlayList.remove(0); npc.textureLocation = null; npc.updateHitbox(); - } - catch(Exception ex){ + } catch(Exception ex) { npc.display.texture = "customnpcs:textures/entity/humanmale/Steve.png"; } } From 9a76c9a68dfcfbf9b0055cc4482b260602c4c7bc Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Sun, 12 Jun 2022 03:20:27 -0500 Subject: [PATCH 39/40] The glow texture selection GUI now correctly starts the player out at the "customnpcs:textures/overlays/" directory. --- .../java/noppes/npcs/client/gui/GuiNpcTextureOverlays.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcTextureOverlays.java b/src/main/java/noppes/npcs/client/gui/GuiNpcTextureOverlays.java index e6e4c9fd6..98ffa8dc6 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcTextureOverlays.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcTextureOverlays.java @@ -11,8 +11,7 @@ import org.lwjgl.opengl.GL11; public class GuiNpcTextureOverlays extends GuiNpcSelectionInterface{ public GuiNpcTextureOverlays(EntityNPCInterface npc,GuiScreen parent){ - //super(npc, parent, npc.display.glowTexture.isEmpty()?"customnpcs:textures/overlays/":npc.display.glowTexture); - super(npc, parent, npc.display.skinOverlayData.overlayList.containsKey(0) ? npc.display.skinOverlayData.overlayList.get(0).getTexture() : ""); + super(npc, parent, npc.display.skinOverlayData.overlayList.containsKey(0) ? !npc.display.skinOverlayData.overlayList.get(0).getTexture().isEmpty() ? npc.display.skinOverlayData.overlayList.get(0).getTexture() : "customnpcs:textures/overlays/" : "customnpcs:textures/overlays/"); title = "Select Overlay"; this.parent = parent; } From 8b77597e27ff545090d09dfcb82afe4402e17724 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Sun, 12 Jun 2022 03:38:20 -0500 Subject: [PATCH 40/40] Overlays don't render over special DBC model parts like antennae & tails. --- src/main/java/noppes/npcs/client/ClientEventHandler.java | 2 +- .../java/noppes/npcs/client/renderer/RenderCNPCPlayer.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/noppes/npcs/client/ClientEventHandler.java b/src/main/java/noppes/npcs/client/ClientEventHandler.java index c9112d4e3..520598787 100644 --- a/src/main/java/noppes/npcs/client/ClientEventHandler.java +++ b/src/main/java/noppes/npcs/client/ClientEventHandler.java @@ -37,7 +37,7 @@ public class ClientEventHandler { } @SubscribeEvent - public void cancelSpecials(RenderPlayerEvent.Specials.Pre event) { + public void cancelSpecials(RenderPlayerEvent.Specials event) { if (event.renderer instanceof RenderCNPCPlayer) event.setCanceled(true); } diff --git a/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java b/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java index 0821d0415..86046afec 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java @@ -632,7 +632,7 @@ public class RenderCNPCPlayer extends RenderPlayer { int j = 5095183; h1 = 1.0F; ////renderPlayerJBRA.getMethod("glColor3f",int.class).invoke(null,bodycm); - ModelBipedDBC.getMethod("renderHairs",float.class,String.class).invoke(modelMain,0.0625F,"N"); + //ModelBipedDBC.getMethod("renderHairs",float.class,String.class).invoke(modelMain,0.0625F,"N"); ////renderPlayerJBRA.getMethod("glColor3f",int.class).invoke(null,bodycm); ModelBipedDBC.getMethod("renderBody",float.class).invoke(modelMain,0.0625F); @@ -664,7 +664,7 @@ public class RenderCNPCPlayer extends RenderPlayer { short TransFrHrn = ((short[]) JRMCoreH.getField("TransFrHrn").get(null))[st]; - ModelBipedDBC.getMethod("renderHairs",float.class,String.class).invoke(modelMain,0.0625F,(ts == 4 ? "n" : "") + "FR" + TransFrHrn); + //ModelBipedDBC.getMethod("renderHairs",float.class,String.class).invoke(modelMain,0.0625F,(ts == 4 ? "n" : "") + "FR" + TransFrHrn); //renderPlayerJBRA.getMethod("glColor3f",int.class).invoke(null,bodyc1); //ModelBipedDBC.getMethod("renderHairs",float.class,String.class).invoke(modelMain,0.0625F,(ts == 4 ? "n" : "") + "FR" + TransFrHrn); @@ -788,7 +788,7 @@ public class RenderCNPCPlayer extends RenderPlayer { } //renderPlayerJBRA.getMethod("glColor3f",int.class).invoke(null,maxBody); - ModelBipedDBC.getMethod("renderHairs",float.class,String.class).invoke(modelMain,0.0625F,ts != 0 && ts != -1 ? (ts == 1 ? "SJT2" : "") : "SJT1"); + //ModelBipedDBC.getMethod("renderHairs",float.class,String.class).invoke(modelMain,0.0625F,ts != 0 && ts != -1 ? (ts == 1 ? "SJT2" : "") : "SJT1"); } h1 = 1.0F;