From 1044269f5ea96332c5ad63ce67d616131555e4f2 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Sun, 18 Feb 2024 01:30:34 -0600 Subject: [PATCH 01/41] Added current quest info to the party menu. --- .../java/noppes/npcs/PacketHandlerServer.java | 15 +- .../client/gui/player/inventory/GuiParty.java | 130 ++++++++++++++---- .../noppes/npcs/controllers/data/Party.java | 21 ++- 3 files changed, 137 insertions(+), 29 deletions(-) diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index d524ce7e5..d0fa28435 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -260,7 +260,20 @@ public class PacketHandlerServer{ if (playerData.partyUUID != null) { Party party = PartyController.Instance().getParty(playerData.partyUUID); - Server.sendData(player, EnumPacketClient.GUI_DATA, party.writeToNBT()); + NBTTagCompound compound = party.writeToNBT(); + if (party.getQuest() != null) { + Quest quest = (Quest) party.getQuest(); + Vector vector = quest.questInterface.getQuestLogStatus(player); + NBTTagList list = new NBTTagList(); + for (String s : vector) { + list.appendTag(new NBTTagString(s)); + } + compound.setTag("QuestProgress", list); + if(quest.completion == EnumQuestCompletion.Npc && quest.questInterface.isCompleted(playerData)) { + compound.setString("QuestCompleteWith", quest.completerNpc); + } + } + Server.sendData(player, EnumPacketClient.GUI_DATA, compound); } else { sendInviteData(player); } diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java index 7091dfb02..96c2daf23 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java @@ -12,22 +12,21 @@ import net.minecraft.util.StatCollector; import noppes.npcs.client.Client; import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.client.CustomNpcResourceListener; +import noppes.npcs.client.TextBlockClient; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.controllers.data.Party; +import noppes.npcs.controllers.data.Quest; import org.lwjgl.opengl.GL11; import tconstruct.client.tabs.InventoryTabCustomNpc; import tconstruct.client.tabs.TabRegistry; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.UUID; +import java.util.*; public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, ITopButtonListener,ICustomScrollListener, IGuiData, GuiYesNoCallback { private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/standardbg.png"); private final EntityPlayer player; - private Minecraft mc = Minecraft.getMinecraft(); + private final Minecraft mc = Minecraft.getMinecraft(); private boolean receivedData; private long renderTicks; @@ -40,6 +39,10 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT private final HashMap invites = new HashMap<>(); + private boolean showQuestText; + private final Vector questLogStatus = new Vector<>(); + private String questCompleteWith; + public GuiParty(EntityPlayer player) { super(); this.player = player; @@ -73,25 +76,25 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT //party invites list // GuiCustomScroll inviteScroll = new GuiCustomScroll(this, 210, false); - inviteScroll.setSize(150, 160); + inviteScroll.setSize(135, 165); inviteScroll.guiLeft = guiLeft + 5; inviteScroll.guiTop = guiTop + 5; inviteScroll.setList(new ArrayList<>(this.invites.keySet())); this.addScroll(inviteScroll); - GuiNpcButton acceptButton = new GuiNpcButton(215, guiLeft + 15, guiTop + ySize - 12, "party.accept"); - acceptButton.width = 60; + GuiNpcButton acceptButton = new GuiNpcButton(215, guiLeft + 5, guiTop + ySize - 8, "party.accept"); + acceptButton.width = 65; this.addButton(acceptButton); - GuiNpcButton ignoreButton = new GuiNpcButton(220, guiLeft + 80, guiTop + ySize - 12, "party.ignore"); - ignoreButton.width = 60; + GuiNpcButton ignoreButton = new GuiNpcButton(220, guiLeft + 75, guiTop + ySize - 8, "party.ignore"); + ignoreButton.width = 65; this.addButton(ignoreButton); } else { // //party player list // GuiCustomScroll playerScroll = new GuiCustomScroll(this, 300, false); - playerScroll.setSize(150, 160); + playerScroll.setSize(135, this.isLeader ? 145 : 165); playerScroll.guiLeft = guiLeft + 5; playerScroll.guiTop = guiTop + 5; @@ -108,18 +111,25 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT playerScroll.setList(arrayList); this.addScroll(playerScroll); + if (party.getIsLocked()) { + addButton(new GuiButtonNextPage(400, guiLeft + 144, guiTop + 176, false)); + getButton(400).visible = this.showQuestText; + addButton(new GuiButtonNextPage(401, guiLeft + 286, guiTop + 176, true)); + getButton(401).visible = !getButton(400).visible; + } + if (this.isLeader) { if (!party.getIsLocked()) { //set leader button // - GuiNpcButton leaderButton = new GuiNpcButton(305, guiLeft + 5, guiTop + ySize - 12, "party.makeLeader"); - leaderButton.width = 70; + GuiNpcButton leaderButton = new GuiNpcButton(305, guiLeft + 5, guiTop + ySize - 8 - 21, "party.makeLeader"); + leaderButton.width = 65; this.addButton(leaderButton); //kick player button // - GuiNpcButton kickButton = new GuiNpcButton(310, guiLeft + 85, guiTop + ySize - 12, "party.kick"); - kickButton.width = 70; + GuiNpcButton kickButton = new GuiNpcButton(310, guiLeft + 75, guiTop + ySize - 8 - 21, "party.kick"); + kickButton.width = 65; this.addButton(kickButton); //send invite button (opens subgui) @@ -133,25 +143,25 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT //toggle friendly fire // - GuiNpcButton friendlyFireButton = new GuiNpcButton(320, guiLeft + xSize / 2 + 95, guiTop + ySize / 2, new String[]{"gui.on", "gui.off"}, party.friendlyFire() ? 0 : 1); + GuiNpcLabel friendlyFireLabel = new GuiNpcLabel(321, StatCollector.translateToLocal("party.friendlyFire") + ":", guiLeft + xSize / 2 + 20, guiTop + ySize / 2 + 5); + if (party.getIsLocked()) { + friendlyFireLabel.x = guiLeft + 5; + friendlyFireLabel.y = guiTop + ySize - 8 - 15; + } + this.addLabel(friendlyFireLabel); + GuiNpcButton friendlyFireButton = new GuiNpcButton(320, friendlyFireLabel.x + 70, friendlyFireLabel.y - 6, new String[]{"gui.on", "gui.off"}, party.friendlyFire() ? 0 : 1); friendlyFireButton.width = 40; this.addButton(friendlyFireButton); - GuiNpcLabel friendlyFireLabel = new GuiNpcLabel(321, StatCollector.translateToLocal("party.friendlyFire") + ":", guiLeft + xSize / 2 + 20, guiTop + ySize / 2 + 5); - this.addLabel(friendlyFireLabel); //disband party // - GuiNpcButton disbandButton = new GuiNpcButton(335, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 70, "party.disbandParty"); - disbandButton.width = party.getIsLocked() ? 150 : 100; - if (party.getIsLocked()) { - disbandButton.xPosition = guiLeft + 5; - disbandButton.yPosition = guiTop + ySize - 12; - } + GuiNpcButton disbandButton = new GuiNpcButton(335, guiLeft + 5, guiTop + ySize - 9, "party.disbandParty"); + disbandButton.width = 135; this.addButton(disbandButton); } else { //leave party // - GuiNpcButton leaveButton = new GuiNpcButton(335, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 70, "party.leaveParty"); + GuiNpcButton leaveButton = new GuiNpcButton(335, guiLeft + 5, guiTop + ySize - 9, "party.leaveParty"); leaveButton.width = 100; this.addButton(leaveButton); } @@ -239,6 +249,12 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT displayGuiScreen(yesnoLeave); } break; + case 400: + this.showQuestText = false; + break; + case 401: + this.showQuestText = true; + break; } initGui(); if (guibutton.id == 100 && activeTab != 0) { @@ -272,6 +288,59 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT periods += "."; } fontRendererObj.drawString(StatCollector.translateToLocal("gui.loading") + periods,guiLeft + xSize/2,guiTop + 80, CustomNpcResourceListener.DefaultTextColor); + return; + } + + if (ClientCacheHandler.party != null && ClientCacheHandler.party.getQuest() != null) { + Quest quest = (Quest) ClientCacheHandler.party.getQuest(); + if (showQuestText) { + drawQuestText(quest); + String title = StatCollector.translateToLocal("quest.objectives"); + fontRendererObj.drawString(title, guiLeft + 168, guiTop + 179, CustomNpcResourceListener.DefaultTextColor); + } else { + drawProgress(); + String title = StatCollector.translateToLocal("gui.text"); + fontRendererObj.drawString(title, guiLeft + 284 - fontRendererObj.getStringWidth(title), guiTop + 179, CustomNpcResourceListener.DefaultTextColor); + } + + GL11.glPushMatrix(); + GL11.glTranslatef(guiLeft + 148, guiTop, 0); + GL11.glScalef(1.24f, 1.24f, 1.24f); + fontRendererObj.drawString(quest.getName(), (130 - fontRendererObj.getStringWidth(quest.getName())) / 2, 4, CustomNpcResourceListener.DefaultTextColor); + GL11.glPopMatrix(); + drawHorizontalLine(guiLeft + 142, guiLeft + 312, guiTop + 17, +0xFF000000 + CustomNpcResourceListener.DefaultTextColor); + } + } + + private void drawQuestText(Quest quest){ + TextBlockClient block = new TextBlockClient(quest.getLogText(), 174, true, player); + for(int i = 0; i < block.lines.size(); i++){ + String text = block.lines.get(i).getFormattedText(); + fontRendererObj.drawString(text, guiLeft + 142, guiTop + 20 + (i * fontRendererObj.FONT_HEIGHT), CustomNpcResourceListener.DefaultTextColor); + } + } + + private void drawProgress() { + String complete = this.questCompleteWith; + if(complete != null && !complete.isEmpty()) + fontRendererObj.drawString(StatCollector.translateToLocalFormatted("quest.completewith", complete), guiLeft + 144, guiTop + 105, CustomNpcResourceListener.DefaultTextColor); + + int yoffset = guiTop + 22; + for(String process : this.questLogStatus){ + int index = process.lastIndexOf(":"); + if(index > 0){ + String name = process.substring(0, index); + String trans = StatCollector.translateToLocal(name); + if(!trans.equals(name)) + name = trans; + trans = StatCollector.translateToLocal("entity." + name + ".name"); + if(!trans.equals("entity." + name + ".name")){ + name = trans; + } + process = name + process.substring(index); + } + fontRendererObj.drawString("- " + process, guiLeft + 144, yoffset , CustomNpcResourceListener.DefaultTextColor); + yoffset += 10; } } @@ -304,6 +373,17 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT ClientCacheHandler.party = new Party(uuid); Party party = ClientCacheHandler.party; party.readFromNBT(compound); + this.questLogStatus.clear(); + this.questCompleteWith = ""; + if (compound.hasKey("QuestProgress")) { + NBTTagList tagList = compound.getTagList("QuestProgress", 8); + for (int i = 0; i < tagList.tagCount(); i++) { + this.questLogStatus.add(tagList.getStringTagAt(i)); + } + } + if (compound.hasKey("QuestCompleteWith")) { + this.questCompleteWith = compound.getString("QuestCompleteWith"); + } this.isLeader = ClientCacheHandler.party.getPartyLeaderName().equals(this.player.getCommandSenderName()); } else if (compound.hasKey("Disband")) { this.isLeader = false; diff --git a/src/main/java/noppes/npcs/controllers/data/Party.java b/src/main/java/noppes/npcs/controllers/data/Party.java index 531f9f8fd..cdb83b07d 100644 --- a/src/main/java/noppes/npcs/controllers/data/Party.java +++ b/src/main/java/noppes/npcs/controllers/data/Party.java @@ -38,6 +38,7 @@ public class Party { //Client-sided private String partyLeaderName; + private Quest quest; public Party() { this.partyUUID = UUID.randomUUID(); @@ -68,7 +69,11 @@ public class Party { } public IQuest getQuest() { - return QuestController.Instance.get(this.currentQuestID); + if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { + return QuestController.Instance.get(this.currentQuestID); + } else { + return this.quest; + } } public int getCurrentQuestID() { @@ -295,11 +300,16 @@ public class Party { public void readFromNBT(NBTTagCompound compound) { this.partyLeaderName = compound.getString("PartyLeader"); - this.currentQuestID = compound.getInteger("PartyQuestID"); this.currentQuestName = compound.getString("PartyQuestName"); this.friendlyFire = compound.getBoolean("FriendlyFire"); this.partyLocked = compound.getBoolean("PartyLocked"); + this.currentQuestID = compound.getInteger("PartyQuestID"); + if (compound.hasKey("QuestNBT")) { + this.quest = new Quest(); + this.quest.readNBT(compound.getCompoundTag("QuestNBT")); + } + NBTTagList list = compound.getTagList("PartyMembers", 10); for (int i = 0; i < list.tagCount(); i++) { NBTTagCompound tagCompound = list.getCompoundTagAt(i); @@ -314,11 +324,16 @@ public class Party { NBTTagCompound compound = new NBTTagCompound(); compound.setString("PartyUUID", this.partyUUID.toString()); - compound.setInteger("PartyQuestID", this.currentQuestID); compound.setString("PartyQuestName", this.currentQuestName); compound.setBoolean("FriendlyFire", this.friendlyFire); compound.setBoolean("PartyLocked", this.partyLocked); + compound.setInteger("PartyQuestID", this.currentQuestID); + if (this.getQuest() != null) { + Quest quest = (Quest) this.getQuest(); + compound.setTag("QuestNBT", quest.writeToNBT(new NBTTagCompound())); + } + NBTTagList list = new NBTTagList(); for (UUID uuid : this.partyOrder) { NBTTagCompound uuidCompound = new NBTTagCompound(); From f84b16b29a2ce653b454bae0b3213fe41be30ba8 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Sun, 18 Feb 2024 03:02:02 -0600 Subject: [PATCH 02/41] Implemented party quest dropping in the party GUI. Made party button always visible in the quest log if a quest can be partied with. Added drawTextBlock() function to GuiNPCInterface. --- .../client/gui/player/inventory/GuiParty.java | 77 ++++++++++--------- .../gui/player/inventory/GuiQuestLog.java | 18 +++-- .../npcs/client/gui/util/GuiNPCInterface.java | 11 +++ .../assets/customnpcs/lang/en_US.lang | 5 +- 4 files changed, 63 insertions(+), 48 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java index 96c2daf23..7c05dfff5 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java @@ -65,14 +65,10 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT // //create party button // - GuiNpcButton createPartyButton = new GuiNpcButton(200, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 20, "party.createParty"); + GuiNpcButton createPartyButton = new GuiNpcButton(200, guiLeft + xSize/2 + 40, guiTop + ySize/2 + 20, "party.createParty"); createPartyButton.width = 100; this.addButton(createPartyButton); - this.addLabel(new GuiNpcLabel(201, "party.partyInfo1", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 30)); - this.addLabel(new GuiNpcLabel(202, "party.partyInfo2", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 20)); - this.addLabel(new GuiNpcLabel(203, "party.partyInfo3", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 10)); - //party invites list // GuiCustomScroll inviteScroll = new GuiCustomScroll(this, 210, false); @@ -112,12 +108,36 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT this.addScroll(playerScroll); if (party.getIsLocked()) { - addButton(new GuiButtonNextPage(400, guiLeft + 144, guiTop + 176, false)); - getButton(400).visible = this.showQuestText; - addButton(new GuiButtonNextPage(401, guiLeft + 286, guiTop + 176, true)); - getButton(401).visible = !getButton(400).visible; + int arrowButtonsY = guiTop + ySize - 8 - 20; + + addButton(new GuiButtonNextPage(400, guiLeft + 144, arrowButtonsY, false)); + addLabel(new GuiNpcLabel(401, "quest.objectives", guiLeft + 168, getButton(400).yPosition + 3)); + getButton(400).visible = getLabel(401).enabled = this.showQuestText; + + addButton(new GuiButtonNextPage(405, guiLeft + 286, arrowButtonsY, true)); + String textString = StatCollector.translateToLocal("gui.text"); + addLabel(new GuiNpcLabel(406, textString, + guiLeft + 284 - fontRendererObj.getStringWidth(textString), getButton(405).yPosition + 3)); + getButton(405).visible = getLabel(406).enabled = !getButton(400).visible; + + GuiNpcButton disbandButton = new GuiNpcButton(410, guiLeft + 164, arrowButtonsY + 19, "party.dropQuest"); + disbandButton.width = 135; + this.addButton(disbandButton); } + //toggle friendly fire + // + GuiNpcLabel friendlyFireLabel = new GuiNpcLabel(321, StatCollector.translateToLocal("party.friendlyFire") + ":", + guiLeft + xSize / 2 + 10, guiTop + ySize / 2 + 5); + if (party.getIsLocked()) { + friendlyFireLabel.x = guiLeft + 5; + friendlyFireLabel.y = guiTop + ySize - 8 - 15; + } + this.addLabel(friendlyFireLabel); + GuiNpcButton friendlyFireButton = new GuiNpcButton(320, friendlyFireLabel.x + 70, friendlyFireLabel.y - 6, new String[]{"gui.on", "gui.off"}, party.friendlyFire() ? 0 : 1); + friendlyFireButton.width = 40; + this.addButton(friendlyFireButton); + if (this.isLeader) { if (!party.getIsLocked()) { //set leader button @@ -134,25 +154,13 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT //send invite button (opens subgui) // - GuiNpcTextField playerTextField = new GuiNpcTextField(325, this, guiLeft + xSize / 2 + 20, guiTop + ySize / 2 + 40, 100, 20, ""); + GuiNpcTextField playerTextField = new GuiNpcTextField(325, this, friendlyFireLabel.x, guiTop + ySize / 2 + 25, 100, 20, ""); this.addTextField(playerTextField); - GuiNpcButton inviteButton = new GuiNpcButton(330, guiLeft + xSize / 2 + 125, guiTop + ySize / 2 + 40, "party.invite"); + GuiNpcButton inviteButton = new GuiNpcButton(330, playerTextField.xPosition + 105, playerTextField.yPosition, "party.invite"); inviteButton.width = 50; this.addButton(inviteButton); } - //toggle friendly fire - // - GuiNpcLabel friendlyFireLabel = new GuiNpcLabel(321, StatCollector.translateToLocal("party.friendlyFire") + ":", guiLeft + xSize / 2 + 20, guiTop + ySize / 2 + 5); - if (party.getIsLocked()) { - friendlyFireLabel.x = guiLeft + 5; - friendlyFireLabel.y = guiTop + ySize - 8 - 15; - } - this.addLabel(friendlyFireLabel); - GuiNpcButton friendlyFireButton = new GuiNpcButton(320, friendlyFireLabel.x + 70, friendlyFireLabel.y - 6, new String[]{"gui.on", "gui.off"}, party.friendlyFire() ? 0 : 1); - friendlyFireButton.width = 40; - this.addButton(friendlyFireButton); - //disband party // GuiNpcButton disbandButton = new GuiNpcButton(335, guiLeft + 5, guiTop + ySize - 9, "party.disbandParty"); @@ -252,9 +260,12 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT case 400: this.showQuestText = false; break; - case 401: + case 405: this.showQuestText = true; break; + case 410: + Client.sendData(EnumPacketServer.SetPartyQuest, "", ""); + break; } initGui(); if (guibutton.id == 100 && activeTab != 0) { @@ -291,16 +302,14 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT return; } - if (ClientCacheHandler.party != null && ClientCacheHandler.party.getQuest() != null) { + if (ClientCacheHandler.party == null) { + drawTextBlock("party.messageNoParty", guiLeft + 155, guiTop + ySize/2 - 20, 160); + } else if (ClientCacheHandler.party.getQuest() != null) { Quest quest = (Quest) ClientCacheHandler.party.getQuest(); if (showQuestText) { - drawQuestText(quest); - String title = StatCollector.translateToLocal("quest.objectives"); - fontRendererObj.drawString(title, guiLeft + 168, guiTop + 179, CustomNpcResourceListener.DefaultTextColor); + drawTextBlock(quest.getLogText(), guiLeft + 142, guiTop + 20, 174); } else { drawProgress(); - String title = StatCollector.translateToLocal("gui.text"); - fontRendererObj.drawString(title, guiLeft + 284 - fontRendererObj.getStringWidth(title), guiTop + 179, CustomNpcResourceListener.DefaultTextColor); } GL11.glPushMatrix(); @@ -312,14 +321,6 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT } } - private void drawQuestText(Quest quest){ - TextBlockClient block = new TextBlockClient(quest.getLogText(), 174, true, player); - for(int i = 0; i < block.lines.size(); i++){ - String text = block.lines.get(i).getFormattedText(); - fontRendererObj.drawString(text, guiLeft + 142, guiTop + 20 + (i * fontRendererObj.FONT_HEIGHT), CustomNpcResourceListener.DefaultTextColor); - } - } - private void drawProgress() { String complete = this.questCompleteWith; if(complete != null && !complete.isEmpty()) diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiQuestLog.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiQuestLog.java index 96e083339..5968cc332 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiQuestLog.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiQuestLog.java @@ -87,15 +87,16 @@ public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener, addButton(new GuiButtonNextPage(1, guiLeft + 286, guiTop + 176, true)); addButton(new GuiButtonNextPage(2, guiLeft + 144, guiTop + 176, false)); - if (ClientCacheHandler.party != null && data.hasSelectedQuest() - && data.partyAbleQuests.contains(data.selectedCategory + ":" + data.selectedQuest) - && ClientCacheHandler.party.getPartyLeaderName().equals(this.player.getCommandSenderName())) { - String questName = ClientCacheHandler.party.getCurrentQuestName(); + if (data.partyAbleQuests.contains(data.selectedCategory + ":" + data.selectedQuest)) { + String questName = ClientCacheHandler.party != null ? ClientCacheHandler.party.getCurrentQuestName() : null; GuiNpcButton partyButton = new GuiNpcButton(3, guiLeft + 150, guiTop + 151, 50, 20, new String[]{"party.party", "party.partying"}, Objects.equals(questName, data.selectedQuest) ? 1 : 0); - if (Objects.equals(questName, data.selectedQuest)) { + addButton(partyButton); + + partyButton.enabled = ClientCacheHandler.party != null && data.hasSelectedQuest() + && ClientCacheHandler.party.getPartyLeaderName().equals(this.player.getCommandSenderName()); + if (partyButton.enabled && Objects.equals(questName, data.selectedQuest)) { partyButton.packedFGColour = 0x32CD32; } - addButton(partyButton); } GuiNpcButton trackingButton = new GuiNpcButton(4, guiLeft + 260, guiTop + 151, 50, 20, new String[]{"quest.track", "quest.tracking"}, data.trackedQuestKey.equals(data.selectedCategory + ":" + data.selectedQuest) ? 1 : 0); @@ -111,6 +112,9 @@ public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener, getButton(2).visible = !questDetails && data.hasSelectedQuest(); getButton(4).visible = !data.selectedQuest.isEmpty() && getButton(1).visible; getButton(5).visible = getButton(4).visible; + if (getButton(3) != null) { + getButton(3).visible = getButton(4).visible; + } } @Override protected void actionPerformed(GuiButton guibutton){ @@ -317,5 +321,5 @@ public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener, Client.sendData(EnumPacketServer.QuestLogToServer, compound, this.data.trackedQuestKey); } } - + } diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java index 5df690a6e..2f15eca88 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java @@ -9,6 +9,9 @@ import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; +import noppes.npcs.client.CustomNpcResourceListener; +import noppes.npcs.client.TextBlockClient; import noppes.npcs.entity.EntityNPCInterface; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; @@ -269,6 +272,14 @@ public abstract class GuiNPCInterface extends GuiScreen GL11.glPopMatrix(); } + protected void drawTextBlock(String text, int x, int y, int lineWidth) { + TextBlockClient block = new TextBlockClient(StatCollector.translateToLocal(text), lineWidth, true, player); + for(int line = 0; line < block.lines.size(); line++){ + String lineText = block.lines.get(line).getFormattedText(); + fontRendererObj.drawString(lineText, x, y + (line * fontRendererObj.FONT_HEIGHT), CustomNpcResourceListener.DefaultTextColor); + } + } + public FontRenderer getFontRenderer() { return this.fontRendererObj; } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 65c68a44f..4338c92f1 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -138,6 +138,7 @@ party.completeFor=Complete For party.createParty=Create Party party.disbandParty=Disband Party party.disbandConfirm=Are you sure you want to disband the party? +party.dropQuest=Drop Quest party.friendlyFire=Friendly Fire party.ignore=Ignore party.invite=Invite @@ -154,9 +155,7 @@ party.maxPartySize=Max Party Size party.options=Party Options party.party=Party party.partying=Partying! -party.partyInfo1=You're not in a party! -party.partyInfo2=Either wait for an invite -party.partyInfo3=or create one. +party.messageNoParty=You're not in a party! Either wait for an invite or create one. party.partyRequirements=Party Requirements party.partyRewards=Party Rewards From 7edfc8f473c670c652bdee453d3f059a7c211cce Mon Sep 17 00:00:00 2001 From: Goodbird Date: Sun, 18 Feb 2024 18:09:29 +0300 Subject: [PATCH 03/41] Copied doRender code from RenderLiving and RenderLivingEntity for the next changes --- .../client/renderer/RenderNPCInterface.java | 240 +++++++++++++++++- 1 file changed, 239 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java index 5dc55057a..267adceca 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java @@ -18,7 +18,10 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.boss.BossStatus; +import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.event.RenderLivingEvent; +import net.minecraftforge.common.MinecraftForge; import noppes.npcs.api.ISkinOverlay; import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.client.ImageDownloadAlt; @@ -29,6 +32,7 @@ import noppes.npcs.controllers.data.SkinOverlay; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; @@ -213,9 +217,243 @@ public class RenderNPCInterface extends RenderLiving{ } staticRenderManager = this.renderManager; - super.doRender(entityliving, d, d1, d2, f, f1); + + doRenderLiving(entityliving, d, d1, d2, f, f1); } + public void doRenderLiving(EntityLiving p_76986_1_, double p_76986_2_, double p_76986_4_, double p_76986_6_, float p_76986_8_, float p_76986_9_) + { + if (MinecraftForge.EVENT_BUS.post(new RenderLivingEvent.Pre(p_76986_1_, this, p_76986_2_, p_76986_4_, p_76986_6_))) return; + GL11.glPushMatrix(); + GL11.glDisable(GL11.GL_CULL_FACE); + this.mainModel.onGround = this.renderSwingProgress(p_76986_1_, p_76986_9_); + + if (this.renderPassModel != null) + { + this.renderPassModel.onGround = this.mainModel.onGround; + } + + this.mainModel.isRiding = p_76986_1_.isRiding(); + + if (this.renderPassModel != null) + { + this.renderPassModel.isRiding = this.mainModel.isRiding; + } + + this.mainModel.isChild = p_76986_1_.isChild(); + + if (this.renderPassModel != null) + { + this.renderPassModel.isChild = this.mainModel.isChild; + } + + try + { + float f2 = this.interpolateRotation(p_76986_1_.prevRenderYawOffset, p_76986_1_.renderYawOffset, p_76986_9_); + float f3 = this.interpolateRotation(p_76986_1_.prevRotationYawHead, p_76986_1_.rotationYawHead, p_76986_9_); + float f4; + + if (p_76986_1_.isRiding() && p_76986_1_.ridingEntity instanceof EntityLivingBase) + { + EntityLivingBase entitylivingbase1 = (EntityLivingBase)p_76986_1_.ridingEntity; + f2 = this.interpolateRotation(entitylivingbase1.prevRenderYawOffset, entitylivingbase1.renderYawOffset, p_76986_9_); + f4 = MathHelper.wrapAngleTo180_float(f3 - f2); + + if (f4 < -85.0F) + { + f4 = -85.0F; + } + + if (f4 >= 85.0F) + { + f4 = 85.0F; + } + + f2 = f3 - f4; + + if (f4 * f4 > 2500.0F) + { + f2 += f4 * 0.2F; + } + } + + float f13 = p_76986_1_.prevRotationPitch + (p_76986_1_.rotationPitch - p_76986_1_.prevRotationPitch) * p_76986_9_; + this.renderLivingAt(p_76986_1_, p_76986_2_, p_76986_4_, p_76986_6_); + f4 = this.handleRotationFloat(p_76986_1_, p_76986_9_); + this.rotateCorpse(p_76986_1_, f4, f2, p_76986_9_); + float f5 = 0.0625F; + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + GL11.glScalef(-1.0F, -1.0F, 1.0F); + this.preRenderCallback(p_76986_1_, p_76986_9_); + GL11.glTranslatef(0.0F, -24.0F * f5 - 0.0078125F, 0.0F); + float f6 = p_76986_1_.prevLimbSwingAmount + (p_76986_1_.limbSwingAmount - p_76986_1_.prevLimbSwingAmount) * p_76986_9_; + float f7 = p_76986_1_.limbSwing - p_76986_1_.limbSwingAmount * (1.0F - p_76986_9_); + + if (p_76986_1_.isChild()) + { + f7 *= 3.0F; + } + + if (f6 > 1.0F) + { + f6 = 1.0F; + } + + GL11.glEnable(GL11.GL_ALPHA_TEST); + this.mainModel.setLivingAnimations(p_76986_1_, f7, f6, p_76986_9_); + this.renderModel(p_76986_1_, f7, f6, f4, f3 - f2, f13, f5); + int j; + float f8; + float f9; + float f10; + + for (int i = 0; i < 4; ++i) + { + j = this.shouldRenderPass(p_76986_1_, i, p_76986_9_); + + if (j > 0) + { + this.renderPassModel.setLivingAnimations(p_76986_1_, f7, f6, p_76986_9_); + this.renderPassModel.render(p_76986_1_, f7, f6, f4, f3 - f2, f13, f5); + + if ((j & 240) == 16) + { + this.func_82408_c(p_76986_1_, i, p_76986_9_); + this.renderPassModel.render(p_76986_1_, f7, f6, f4, f3 - f2, f13, f5); + } + + if ((j & 15) == 15) + { + f8 = (float)p_76986_1_.ticksExisted + p_76986_9_; + this.bindTexture(new ResourceLocation("textures/misc/enchanted_item_glint.png")); + GL11.glEnable(GL11.GL_BLEND); + f9 = 0.5F; + GL11.glColor4f(f9, f9, f9, 1.0F); + GL11.glDepthFunc(GL11.GL_EQUAL); + GL11.glDepthMask(false); + + for (int k = 0; k < 2; ++k) + { + GL11.glDisable(GL11.GL_LIGHTING); + f10 = 0.76F; + GL11.glColor4f(0.5F * f10, 0.25F * f10, 0.8F * f10, 1.0F); + GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glLoadIdentity(); + float f11 = f8 * (0.001F + (float)k * 0.003F) * 20.0F; + float f12 = 0.33333334F; + GL11.glScalef(f12, f12, f12); + GL11.glRotatef(30.0F - (float)k * 60.0F, 0.0F, 0.0F, 1.0F); + GL11.glTranslatef(0.0F, f11, 0.0F); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + this.renderPassModel.render(p_76986_1_, f7, f6, f4, f3 - f2, f13, f5); + } + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glDepthMask(true); + GL11.glLoadIdentity(); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_BLEND); + GL11.glDepthFunc(GL11.GL_LEQUAL); + } + + GL11.glDisable(GL11.GL_BLEND); + GL11.glEnable(GL11.GL_ALPHA_TEST); + } + } + + GL11.glDepthMask(true); + this.renderEquippedItems(p_76986_1_, p_76986_9_); + float f14 = p_76986_1_.getBrightness(p_76986_9_); + j = this.getColorMultiplier(p_76986_1_, f14, p_76986_9_); + OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit); + GL11.glDisable(GL11.GL_TEXTURE_2D); + OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); + + if ((j >> 24 & 255) > 0 || p_76986_1_.hurtTime > 0 || p_76986_1_.deathTime > 0) + { + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glDisable(GL11.GL_ALPHA_TEST); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glDepthFunc(GL11.GL_EQUAL); + + if (p_76986_1_.hurtTime > 0 || p_76986_1_.deathTime > 0) + { + GL11.glColor4f(f14, 0.0F, 0.0F, 0.4F); + this.mainModel.render(p_76986_1_, f7, f6, f4, f3 - f2, f13, f5); + + for (int l = 0; l < 4; ++l) + { + if (this.inheritRenderPass(p_76986_1_, l, p_76986_9_) >= 0) + { + GL11.glColor4f(f14, 0.0F, 0.0F, 0.4F); + this.renderPassModel.render(p_76986_1_, f7, f6, f4, f3 - f2, f13, f5); + } + } + } + + if ((j >> 24 & 255) > 0) + { + f8 = (float)(j >> 16 & 255) / 255.0F; + f9 = (float)(j >> 8 & 255) / 255.0F; + float f15 = (float)(j & 255) / 255.0F; + f10 = (float)(j >> 24 & 255) / 255.0F; + GL11.glColor4f(f8, f9, f15, f10); + this.mainModel.render(p_76986_1_, f7, f6, f4, f3 - f2, f13, f5); + + for (int i1 = 0; i1 < 4; ++i1) + { + if (this.inheritRenderPass(p_76986_1_, i1, p_76986_9_) >= 0) + { + GL11.glColor4f(f8, f9, f15, f10); + this.renderPassModel.render(p_76986_1_, f7, f6, f4, f3 - f2, f13, f5); + } + } + } + + GL11.glDepthFunc(GL11.GL_LEQUAL); + GL11.glDisable(GL11.GL_BLEND); + GL11.glEnable(GL11.GL_ALPHA_TEST); + GL11.glEnable(GL11.GL_TEXTURE_2D); + } + + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + } + catch (Exception exception) + { + + } + + OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit); + GL11.glEnable(GL11.GL_TEXTURE_2D); + OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); + GL11.glEnable(GL11.GL_CULL_FACE); + GL11.glPopMatrix(); + this.passSpecialRender(p_76986_1_, p_76986_2_, p_76986_4_, p_76986_6_); + MinecraftForge.EVENT_BUS.post(new RenderLivingEvent.Post(p_76986_1_, this, p_76986_2_, p_76986_4_, p_76986_6_)); + this.func_110827_b(p_76986_1_, p_76986_2_, p_76986_4_, p_76986_6_, p_76986_8_, p_76986_9_); + } + + private float interpolateRotation(float p_77034_1_, float p_77034_2_, float p_77034_3_) + { + float f3; + + for (f3 = p_77034_2_ - p_77034_1_; f3 < -180.0F; f3 += 360.0F) + { + ; + } + + while (f3 >= 180.0F) + { + f3 -= 360.0F; + } + + return p_77034_1_ + p_77034_3_ * f3; + } + protected void renderModel(EntityLivingBase entityliving, float par2, float par3, float par4, float par5, float par6, float par7) { EntityNPCInterface npc = (EntityNPCInterface) entityliving; if(GeckoAddonClient.Instance.isGeckoModel(mainModel)){ From b0c299ebb2835cfba6282a85bee72e4db6141fcf Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 19 Feb 2024 01:39:59 -0500 Subject: [PATCH 04/41] Update .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 5e80e0ae5..23d9047f1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /.idea/ /.vscode/ /run/ +/out/ /build/ /eclipse/ .classpath @@ -36,3 +37,5 @@ addon.local.gradle.kts addon.late.local.gradle addon.late.local.gradle.kts layout.json +out +run From 8e0e56dbfd526d81030b416e6a9f476ec7f7c440 Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 19 Feb 2024 01:42:31 -0500 Subject: [PATCH 05/41] Better Inventory Handling --- .../player/inventory/GuiCNPCInventory.java | 5 +--- .../gui/player/inventory/GuiFaction.java | 30 +++++++++---------- .../client/gui/player/inventory/GuiParty.java | 5 ++-- .../gui/player/inventory/GuiQuestLog.java | 5 ++-- .../client/tabs/InventoryTabCustomNpc.java | 8 ++++- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiCNPCInventory.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiCNPCInventory.java index 71d505d51..d47d69780 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiCNPCInventory.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiCNPCInventory.java @@ -26,9 +26,6 @@ public class GuiCNPCInventory extends GuiNPCInterface { super.initGui(); guiTop +=10; - TabRegistry.addTabsToList(buttonList); - TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabCustomNpc.class); - GuiMenuSideButton questsButton = new GuiMenuSideButton(100, guiLeft + xSize + 37, this.guiTop + 3, 22, 22, ""); questsButton.rightSided = true; questsButton.active = activeTab == 0; @@ -40,7 +37,7 @@ public class GuiCNPCInventory extends GuiNPCInterface { partyButton.active = activeTab == 1; partyButton.renderStack = new ItemStack(CustomItems.bag); addButton(partyButton); - + if(ConfigClient.enableFactionTab){ GuiMenuSideButton factionButton = new GuiMenuSideButton(102, guiLeft + xSize + 37, this.guiTop + 3 + 21*2, 22, 22, ""); factionButton.rightSided = true; diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiFaction.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiFaction.java index 9fe7bf8a3..7c84a4747 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiFaction.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiFaction.java @@ -22,7 +22,7 @@ import java.util.ArrayList; public class GuiFaction extends GuiCNPCInventory implements IGuiData{ private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/standardbg.png"); - + private ArrayList playerFactions = new ArrayList(); private Minecraft mc = Minecraft.getMinecraft(); @@ -46,8 +46,8 @@ public class GuiFaction extends GuiCNPCInventory implements IGuiData{ public void initGui() { super.initGui(); - TabRegistry.addTabsToList(buttonList); - TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabCustomNpc.class); + TabRegistry.addTabsToList(buttonList); + TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabCustomNpc.class); this.buttonList.add(buttonNextPage = new GuiButtonNextPage(1, (guiLeft + (xSize + 35) / 2) + 25, guiTop + 170, true)); this.buttonList.add(buttonPreviousPage = new GuiButtonNextPage(2, (guiLeft + (xSize + 35) / 2) - 40, guiTop + 170, false)); @@ -62,16 +62,16 @@ public class GuiFaction extends GuiCNPCInventory implements IGuiData{ mc.renderEngine.bindTexture(resource); drawTexturedModalRect(guiLeft, guiTop, 0, 0, 252, 195); drawTexturedModalRect(guiLeft + 252, guiTop, 188, 0, 67, 195); - + if(playerFactions.isEmpty()){ String noFaction = StatCollector.translateToLocal("faction.nostanding"); fontRendererObj.drawString(noFaction,guiLeft + (xSize - fontRendererObj.getStringWidth(noFaction)) / 2,guiTop + 80, CustomNpcResourceListener.DefaultTextColor); } else renderScreen(); - + super.drawScreen(i, j, f); - + } private void renderScreen(){ @@ -131,21 +131,21 @@ public class GuiFaction extends GuiCNPCInventory implements IGuiData{ fontRendererObj.drawString(s, guiLeft + (xSize + 45 - fontRendererObj.getStringWidth(s)) / 2, guiTop + 175, CustomNpcResourceListener.DefaultTextColor); } } - + @Override protected void actionPerformed(GuiButton guibutton){ if (guibutton.id >= 100) { if (guibutton.id == 100 && activeTab != 0) { activeTab = 0; - mc.displayGuiScreen(new GuiQuestLog(mc.thePlayer)); + mc.displayGuiScreen(new GuiQuestLog(mc.thePlayer)); } if (guibutton.id == 101 && activeTab != 1) { activeTab = 1; - mc.displayGuiScreen(new GuiParty(mc.thePlayer)); + mc.displayGuiScreen(new GuiParty(mc.thePlayer)); } if (guibutton.id == 102 && activeTab != 2) { activeTab = 2; - mc.displayGuiScreen(new GuiFaction()); + mc.displayGuiScreen(new GuiFaction()); } } @@ -166,9 +166,9 @@ public class GuiFaction extends GuiCNPCInventory implements IGuiData{ } protected void drawGuiContainerBackgroundLayer(float f, int i, int j) { - + } - + @Override public void keyTyped(char c, int i) { @@ -199,13 +199,13 @@ public class GuiFaction extends GuiCNPCInventory implements IGuiData{ faction.defaultPoints = points; } } - + pages = (playerFactions.size() - 1) / 10 ; pages++; - + page = 1; updateButtons(); } -} \ No newline at end of file +} diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java index 7c05dfff5..23793250a 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiParty.java @@ -55,11 +55,12 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT public void initGui(){ super.initGui(); - this.selectedInvite = this.selectedPlayer = null; - Party party = ClientCacheHandler.party; TabRegistry.addTabsToList(buttonList); TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabCustomNpc.class); + this.selectedInvite = this.selectedPlayer = null; + Party party = ClientCacheHandler.party; + if (receivedData) { if (party == null) { // diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiQuestLog.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiQuestLog.java index 5968cc332..cd2a60f86 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiQuestLog.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiQuestLog.java @@ -53,8 +53,9 @@ public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener, public void initGui(){ super.initGui(); sideButtons.clear(); - TabRegistry.addTabsToList(buttonList); - TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabCustomNpc.class); + + TabRegistry.addTabsToList(buttonList); + TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabCustomNpc.class); noQuests = false; diff --git a/src/main/java/tconstruct/client/tabs/InventoryTabCustomNpc.java b/src/main/java/tconstruct/client/tabs/InventoryTabCustomNpc.java index 9a7f128b2..bdc1df795 100644 --- a/src/main/java/tconstruct/client/tabs/InventoryTabCustomNpc.java +++ b/src/main/java/tconstruct/client/tabs/InventoryTabCustomNpc.java @@ -4,6 +4,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import noppes.npcs.CustomItems; +import noppes.npcs.client.gui.player.inventory.GuiCNPCInventory; import noppes.npcs.client.gui.player.inventory.GuiQuestLog; public class InventoryTabCustomNpc extends AbstractTab { @@ -16,6 +17,8 @@ public class InventoryTabCustomNpc extends AbstractTab { @Override public void onTabClicked() { + + Thread t = new Thread(){ @Override public void run(){ @@ -25,6 +28,9 @@ public class InventoryTabCustomNpc extends AbstractTab { e.printStackTrace(); } Minecraft mc = Minecraft.getMinecraft(); + if(mc.currentScreen instanceof GuiCNPCInventory) + return; + mc.displayGuiScreen(new GuiQuestLog(mc.thePlayer)); } }; @@ -35,4 +41,4 @@ public class InventoryTabCustomNpc extends AbstractTab { public boolean shouldAddToList() { return true; } -} \ No newline at end of file +} From 4a7315ac8cc7225a51415db6924eb166e7abf860 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Mon, 19 Feb 2024 20:37:18 +0300 Subject: [PATCH 06/41] Added a custom tint data class --- .../npcs/controllers/data/CustomTintData.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/main/java/noppes/npcs/controllers/data/CustomTintData.java diff --git a/src/main/java/noppes/npcs/controllers/data/CustomTintData.java b/src/main/java/noppes/npcs/controllers/data/CustomTintData.java new file mode 100644 index 000000000..c19c425ac --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/data/CustomTintData.java @@ -0,0 +1,83 @@ +package noppes.npcs.controllers.data; + +import net.minecraft.nbt.NBTTagCompound; + +public class CustomTintData { + private boolean enableCustomTint = false; + private boolean enableHurtTint = true; + private boolean enableNpcTint = false; + private int colorHurtTint = 0xff0000; + private int colorNpcTint = 0x000000; + private int colorNpcTintAlpha = 40; + + public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) { + nbttagcompound.setBoolean("EnableCustomTint", enableCustomTint); + if(enableCustomTint) { + nbttagcompound.setBoolean("EnableHurtTint", enableHurtTint); + nbttagcompound.setBoolean("EnableNpcTint", enableNpcTint); + nbttagcompound.setInteger("ColorHurtTint", colorHurtTint); + nbttagcompound.setInteger("ColorNpcTint", colorNpcTint); + nbttagcompound.setInteger("ColorNpcTintAlpha", colorNpcTintAlpha); + } + return nbttagcompound; + } + + public void readFromNBT(NBTTagCompound nbttagcompound) { + enableCustomTint = nbttagcompound.getBoolean("EnableCustomTint"); + if(enableCustomTint) { + enableHurtTint = nbttagcompound.getBoolean("EnableHurtTint"); + enableNpcTint = nbttagcompound.getBoolean("EnableNpcTint"); + colorHurtTint = nbttagcompound.getInteger("ColorHurtTint"); + colorNpcTint = nbttagcompound.getInteger("ColorNpcTint"); + colorNpcTintAlpha = nbttagcompound.getInteger("ColorNpcTintAlpha"); + } + } + + public boolean isEnableHurtTint() { + return enableHurtTint; + } + + public void setEnableHurtTint(boolean enableHurtTint) { + this.enableHurtTint = enableHurtTint; + } + + public int getColorHurtTint() { + return colorHurtTint; + } + + public void setColorHurtTint(int colorHurtTint) { + this.colorHurtTint = colorHurtTint; + } + + public int getColorNpcTint() { + return colorNpcTint; + } + + public void setColorNpcTint(int colorNpcTint) { + this.colorNpcTint = colorNpcTint; + } + + public boolean isEnableCustomTint() { + return enableCustomTint; + } + + public void setEnableCustomTint(boolean enableCustomTint) { + this.enableCustomTint = enableCustomTint; + } + + public boolean isEnableNpcTint() { + return enableNpcTint; + } + + public void setEnableNpcTint(boolean enableNpcTint) { + this.enableNpcTint = enableNpcTint; + } + + public int getColorNpcTintAlpha() { + return colorNpcTintAlpha; + } + + public void setColorNpcTintAlpha(int colorNpcTintAlpha) { + this.colorNpcTintAlpha = colorNpcTintAlpha; + } +} From a86ab2b84db7f05d3d6268e7b7cb91c0b4e81436 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Mon, 19 Feb 2024 20:37:38 +0300 Subject: [PATCH 07/41] Linked the custom tint data class to the DataDisplay --- src/main/java/noppes/npcs/DataDisplay.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/noppes/npcs/DataDisplay.java b/src/main/java/noppes/npcs/DataDisplay.java index ca5b640dd..2c977d3f4 100644 --- a/src/main/java/noppes/npcs/DataDisplay.java +++ b/src/main/java/noppes/npcs/DataDisplay.java @@ -11,6 +11,7 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.util.StringUtils; import noppes.npcs.config.ConfigMain; import noppes.npcs.controllers.data.AnimationData; +import noppes.npcs.controllers.data.CustomTintData; import noppes.npcs.controllers.data.SkinOverlay; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.entity.data.DataSkinOverlays; @@ -61,12 +62,15 @@ public class DataDisplay { //0 - Yes, 1 - No, 2 - Only NPCs, 3 - Only Players, 4 - NPCs and Players public int collidesWith = 1; + public CustomTintData customTintData; + public DataDisplay(EntityNPCInterface npc){ this.npc = npc; markovGeneratorId = new Random().nextInt(CustomNpcs.MARKOV_GENERATOR.length-1); skinOverlayData = new DataSkinOverlays(npc); name = getRandomName(); animationData = new AnimationData(this); + customTintData = new CustomTintData(); } public String getRandomName() { @@ -89,6 +93,8 @@ public class DataDisplay { nbttagcompound = animationData.writeToNBT(nbttagcompound); + nbttagcompound = customTintData.writeToNBT(nbttagcompound); + if (this.playerProfile != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); @@ -166,6 +172,8 @@ public class DataDisplay { animationData.readFromNBT(nbttagcompound); + customTintData.readFromNBT(nbttagcompound); + modelSize = ValueUtil.clamp(nbttagcompound.getInteger("Size"), 1, Integer.MAX_VALUE); if(modelSize > ConfigMain.NpcSizeLimit) modelSize = ConfigMain.NpcSizeLimit; From 6dcbee69cd3cbda8405f1f5e89f8450365a990fa Mon Sep 17 00:00:00 2001 From: Goodbird Date: Mon, 19 Feb 2024 20:38:05 +0300 Subject: [PATCH 08/41] Implemented tint rendering --- .../npcs/client/model/part/ModelLegs.java | 5 ++- .../npcs/client/model/part/ModelTail.java | 5 ++- .../client/model/util/ModelPartInterface.java | 5 ++- .../client/renderer/RenderNPCInterface.java | 33 +++++++++++++++---- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/main/java/noppes/npcs/client/model/part/ModelLegs.java b/src/main/java/noppes/npcs/client/model/part/ModelLegs.java index 8d1ad6ab0..cc959b665 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelLegs.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelLegs.java @@ -11,6 +11,7 @@ import noppes.npcs.client.model.part.legs.ModelMermaidLegs2; import noppes.npcs.client.model.part.legs.ModelNagaLegs; import noppes.npcs.client.model.util.ModelScaleRenderer; import noppes.npcs.constants.EnumAnimation; +import noppes.npcs.controllers.data.CustomTintData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.data.ModelPartData; import org.lwjgl.opengl.GL11; @@ -386,7 +387,9 @@ public class ModelLegs extends ModelScaleRenderer{ y *= 2f; } } - boolean bo = entity.hurtTime <= 0 && entity.deathTime <= 0 && !base.isArmor; + CustomTintData customTintData = entity.display.customTintData; + boolean bo = entity.hurtTime <= 0 && entity.deathTime <= 0 && !base.isArmor && + !(customTintData.isEnableCustomTint() && customTintData.isEnableNpcTint()); if(bo){ float red = (entity.modelData.legParts.color >> 16 & 255) / 255f; float green = (entity.modelData.legParts.color >> 8 & 255) / 255f; diff --git a/src/main/java/noppes/npcs/client/model/part/ModelTail.java b/src/main/java/noppes/npcs/client/model/part/ModelTail.java index 1cd310381..7541a7168 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelTail.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelTail.java @@ -10,6 +10,7 @@ import noppes.npcs.client.model.ModelMPM; import noppes.npcs.client.model.part.tails.*; import noppes.npcs.client.model.util.ModelScaleRenderer; import noppes.npcs.constants.EnumAnimation; +import noppes.npcs.controllers.data.CustomTintData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.data.ModelPartData; import org.lwjgl.opengl.GL11; @@ -150,7 +151,9 @@ public class ModelTail extends ModelScaleRenderer { base.currentlyPlayerTexture = true; } } - boolean bo = entity.hurtTime <= 0 && entity.deathTime <= 0; + CustomTintData customTintData = entity.display.customTintData; + boolean bo = entity.hurtTime <= 0 && entity.deathTime <= 0 && !base.isArmor && + !(customTintData.isEnableCustomTint() && customTintData.isEnableNpcTint()); if(bo){ float red = (color >> 16 & 255) / 255f; float green = (color >> 8 & 255) / 255f; diff --git a/src/main/java/noppes/npcs/client/model/util/ModelPartInterface.java b/src/main/java/noppes/npcs/client/model/util/ModelPartInterface.java index d8c9384ca..25d9d70e6 100644 --- a/src/main/java/noppes/npcs/client/model/util/ModelPartInterface.java +++ b/src/main/java/noppes/npcs/client/model/util/ModelPartInterface.java @@ -6,6 +6,7 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.ResourceLocation; import noppes.npcs.client.ClientProxy; import noppes.npcs.client.model.ModelMPM; +import noppes.npcs.controllers.data.CustomTintData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.data.ModelData; import noppes.npcs.entity.data.ModelPartData; @@ -59,7 +60,9 @@ public abstract class ModelPartInterface extends ModelRenderer { base.currentlyPlayerTexture = true; } } - boolean bo = entity.hurtTime <= 0 && entity.deathTime <= 0 && !base.isArmor; + CustomTintData customTintData = entity.display.customTintData; + boolean bo = entity.hurtTime <= 0 && entity.deathTime <= 0 && !base.isArmor && + !(customTintData.isEnableCustomTint() && customTintData.isEnableNpcTint()); if(bo){ float red = (color >> 16 & 255) / 255f; float green = (color >> 8 & 255) / 255f; diff --git a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java index 267adceca..c98a5e73a 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java @@ -28,6 +28,7 @@ import noppes.npcs.client.ImageDownloadAlt; import noppes.npcs.client.model.ModelMPM; import noppes.npcs.constants.EnumAnimation; import noppes.npcs.constants.EnumStandingType; +import noppes.npcs.controllers.data.CustomTintData; import noppes.npcs.controllers.data.SkinOverlay; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -218,10 +219,10 @@ public class RenderNPCInterface extends RenderLiving{ staticRenderManager = this.renderManager; - doRenderLiving(entityliving, d, d1, d2, f, f1); + doRenderLiving(npc, d, d1, d2, f, f1); } - public void doRenderLiving(EntityLiving p_76986_1_, double p_76986_2_, double p_76986_4_, double p_76986_6_, float p_76986_8_, float p_76986_9_) + public void doRenderLiving(EntityNPCInterface p_76986_1_, double p_76986_2_, double p_76986_4_, double p_76986_6_, float p_76986_8_, float p_76986_9_) { if (MinecraftForge.EVENT_BUS.post(new RenderLivingEvent.Pre(p_76986_1_, this, p_76986_2_, p_76986_4_, p_76986_6_))) return; GL11.glPushMatrix(); @@ -371,8 +372,8 @@ public class RenderNPCInterface extends RenderLiving{ OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit); GL11.glDisable(GL11.GL_TEXTURE_2D); OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); - - if ((j >> 24 & 255) > 0 || p_76986_1_.hurtTime > 0 || p_76986_1_.deathTime > 0) + CustomTintData customTintData = p_76986_1_.display.customTintData; + if ((j >> 24 & 255) > 0 || p_76986_1_.hurtTime > 0 || p_76986_1_.deathTime > 0 || (customTintData.isEnableCustomTint() && customTintData.isEnableNpcTint())) { GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glDisable(GL11.GL_ALPHA_TEST); @@ -380,16 +381,26 @@ public class RenderNPCInterface extends RenderLiving{ GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glDepthFunc(GL11.GL_EQUAL); - if (p_76986_1_.hurtTime > 0 || p_76986_1_.deathTime > 0) + if ((p_76986_1_.hurtTime > 0 || p_76986_1_.deathTime > 0) && (!customTintData.isEnableCustomTint() || customTintData.isEnableHurtTint())) { - GL11.glColor4f(f14, 0.0F, 0.0F, 0.4F); + float r, g, b; + if(customTintData.isEnableCustomTint()) { + r = (float) (customTintData.getColorHurtTint() >> 16 & 255) / 255.0F * f14; + g = (float) (customTintData.getColorHurtTint() >> 8 & 255) / 255.0F * f14; + b = (float) (customTintData.getColorHurtTint() & 255) / 255.0F * f14; + }else{ + r=f14; + g=0; + b=0; + } + GL11.glColor4f(r,g,b, 0.4F); this.mainModel.render(p_76986_1_, f7, f6, f4, f3 - f2, f13, f5); for (int l = 0; l < 4; ++l) { if (this.inheritRenderPass(p_76986_1_, l, p_76986_9_) >= 0) { - GL11.glColor4f(f14, 0.0F, 0.0F, 0.4F); + GL11.glColor4f(r,g,b, 0.4F); this.renderPassModel.render(p_76986_1_, f7, f6, f4, f3 - f2, f13, f5); } } @@ -454,6 +465,14 @@ public class RenderNPCInterface extends RenderLiving{ return p_77034_1_ + p_77034_3_ * f3; } + protected int getColorMultiplier(EntityLivingBase p_77030_1_, float p_77030_2_, float p_77030_3_) + { + EntityNPCInterface npc = (EntityNPCInterface) p_77030_1_; + CustomTintData tintData = npc.display.customTintData; + int alpha = (int) (0xff*((double)tintData.getColorNpcTintAlpha()/100d)) << 24; + return (tintData.isEnableCustomTint() && tintData.isEnableNpcTint())?tintData.getColorNpcTint()+alpha:0; + } + protected void renderModel(EntityLivingBase entityliving, float par2, float par3, float par4, float par5, float par6, float par7) { EntityNPCInterface npc = (EntityNPCInterface) entityliving; if(GeckoAddonClient.Instance.isGeckoModel(mainModel)){ From d10bb18ea4fc56d6e5f878532d5612af51d457e0 Mon Sep 17 00:00:00 2001 From: Goodbird Date: Mon, 19 Feb 2024 20:38:41 +0300 Subject: [PATCH 09/41] Added and linked npc tint sub gui --- .../noppes/npcs/client/gui/SubGuiNpcTint.java | 105 ++++++++++++++++++ .../client/gui/mainmenu/GuiNpcDisplay.java | 9 +- 2 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/SubGuiNpcTint.java diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcTint.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcTint.java new file mode 100644 index 000000000..54b72821e --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcTint.java @@ -0,0 +1,105 @@ +package noppes.npcs.client.gui; + +import net.minecraft.client.gui.GuiButton; +import noppes.npcs.DataStats; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.controllers.data.CustomTintData; +import noppes.npcs.controllers.data.DialogImage; + +public class SubGuiNpcTint extends SubGuiInterface implements ISubGuiListener, ITextfieldListener { + private CustomTintData tintData; + private int lastColorClicked = -1; + + public SubGuiNpcTint(CustomTintData tintData) { + this.tintData = tintData; + setBackground("menubg.png"); + xSize = 256; + ySize = 216; + closeOnEsc = true; + } + + @Override + public void initGui() { + super.initGui(); + int y = 30; + addLabel(new GuiNpcLabel(0, "Enable Custom Tint", guiLeft + 5, guiTop + y + 5)); + addButton(new GuiNpcButtonYesNo(0, guiLeft + 122, guiTop + y, 56, 20, tintData.isEnableCustomTint())); + y+=22; + if (tintData.isEnableCustomTint()) { + addLabel(new GuiNpcLabel(1, "Enable Npc Tint", guiLeft + 5, guiTop + y + 5)); + addButton(new GuiNpcButtonYesNo(1, guiLeft + 122, guiTop + y, 56, 20, tintData.isEnableNpcTint())); + y+=22; + if(tintData.isEnableNpcTint()) { + String color = Integer.toHexString(tintData.getColorNpcTint()); + while (color.length() < 6) color = 0 + color; + addLabel(new GuiNpcLabel(2, "Npc Tint", guiLeft + 4, guiTop + y + 5)); + addButton(new GuiNpcButton(2, guiLeft + 122, guiTop + y, 60, 20, color)); + getButton(2).setTextColor(tintData.getColorNpcTint()); + y+=22; + addLabel(new GuiNpcLabel(3,"Npc Tint Alpha", guiLeft + 5, guiTop + y + 5)); + addTextField(new GuiNpcTextField(3,this, fontRendererObj, guiLeft + 122, guiTop + y, 60, 20, tintData.getColorNpcTintAlpha() + "")); + getTextField(3).integersOnly = true; + getTextField(3).setMinMaxDefault(1, 100, 40); + y+=22; + } + addLabel(new GuiNpcLabel(4, "Enable Hurt Tint", guiLeft + 5, guiTop + y + 5)); + addButton(new GuiNpcButtonYesNo(4, guiLeft + 122, guiTop + y, 56, 20, tintData.isEnableHurtTint())); + y+=22; + if (tintData.isEnableHurtTint()) { + String color2 = Integer.toHexString(tintData.getColorHurtTint()); + while (color2.length() < 6) color2 = 0 + color2; + addLabel(new GuiNpcLabel(5, "Hurt Tint", guiLeft + 4, guiTop + y + 5)); + addButton(new GuiNpcButton(5, guiLeft + 122, guiTop + y, 60, 20, color2)); + getButton(5).setTextColor(tintData.getColorHurtTint()); + } + } + addButton(new GuiNpcButton(66, guiLeft + 82, guiTop + 190, 98, 20, "gui.done")); + } + + @Override + protected void actionPerformed(GuiButton guibutton) { + int id = guibutton.id; + GuiNpcButton button = (GuiNpcButton) guibutton; + if (id == 0) { + tintData.setEnableCustomTint(((GuiNpcButtonYesNo) button).getBoolean()); + initGui(); + } + if (id == 1) { + tintData.setEnableNpcTint(((GuiNpcButtonYesNo) button).getBoolean()); + initGui(); + } + if (id == 4) { + tintData.setEnableHurtTint(((GuiNpcButtonYesNo) button).getBoolean()); + initGui(); + } + if (button.id == 2) { + setSubGui(new SubGuiColorSelector(tintData.getColorNpcTint())); + lastColorClicked = 0; + } + if (button.id == 5) { + setSubGui(new SubGuiColorSelector(tintData.getColorHurtTint())); + lastColorClicked = 1; + } + if (id == 66) { + close(); + } + } + + @Override + public void subGuiClosed(SubGuiInterface subgui) { + if (lastColorClicked == 0) { + tintData.setColorNpcTint(((SubGuiColorSelector) subgui).color); + } else if (lastColorClicked == 1) { + tintData.setColorHurtTint(((SubGuiColorSelector) subgui).color); + } + initGui(); + save(); + } + + @Override + public void unFocused(GuiNpcTextField textfield) { + if(textfield.id==3){ + tintData.setColorNpcTintAlpha(textfield.getInteger()); + } + } +} 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 42de415d7..13a1a68e5 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java @@ -7,10 +7,7 @@ import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.DataDisplay; import noppes.npcs.client.Client; import noppes.npcs.client.NoppesUtil; -import noppes.npcs.client.gui.GuiNPCTextures; -import noppes.npcs.client.gui.GuiNpcTextureCloaks; -import noppes.npcs.client.gui.GuiNpcTextureOverlays; -import noppes.npcs.client.gui.SubGuiNpcName; +import noppes.npcs.client.gui.*; import noppes.npcs.client.gui.model.GuiCreationScreen; import noppes.npcs.client.gui.util.*; import noppes.npcs.config.ConfigMain; @@ -46,6 +43,7 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene y+=23; addLabel(new GuiNpcLabel(11,"gui.title", guiLeft + 5, y + 5)); addTextField(new GuiNpcTextField(11,this, fontRendererObj, guiLeft + 50, y, 206, 20, display.title)); + this.addButton(new GuiNpcButton(13, guiLeft + 259, y , 80, 20, "Tint settings")); y+=23; addLabel(new GuiNpcLabel(1,"display.model", guiLeft + 5, y + 5)); @@ -185,6 +183,9 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene npc.display.skinOverlayData.overlayList.get(0).setBlend(button.getValue() == 0); initGui(); } + else if (button.id == 13){ + setSubGui(new SubGuiNpcTint(display.customTintData)); + } else if(button.id == 14){ String name = display.getRandomName(); display.setName(name); From 60079b66bcf495de20a0ca7295e36a888348dc85 Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 19 Feb 2024 19:14:51 -0500 Subject: [PATCH 10/41] A Ton of New Permissions!!!! --- .../noppes/npcs/CustomNpcsPermissions.java | 56 ++++++++++--- .../java/noppes/npcs/NoppesUtilServer.java | 64 +++++++------- .../java/noppes/npcs/PacketHandlerServer.java | 9 +- .../java/noppes/npcs/ServerEventsHandler.java | 6 +- .../java/noppes/npcs/blocks/BlockBigSign.java | 26 +++--- .../java/noppes/npcs/blocks/BlockBook.java | 10 +-- .../noppes/npcs/blocks/BlockNpcRedstone.java | 16 ++-- .../noppes/npcs/blocks/BlockTombstone.java | 34 ++++---- .../noppes/npcs/blocks/BlockWaypoint.java | 8 +- .../java/noppes/npcs/client/ClientProxy.java | 3 + .../npcs/client/PacketHandlerClient.java | 6 ++ .../npcs/client/gui/GuiNpcRemoteEditor.java | 16 ++-- .../gui/global/GuiNpcManagePlayerData.java | 2 +- .../java/noppes/npcs/config/ConfigScript.java | 9 +- .../noppes/npcs/constants/EnumGuiType.java | 1 + .../npcs/constants/EnumPacketClient.java | 5 +- .../npcs/constants/EnumPacketServer.java | 84 +++++++++++-------- .../java/noppes/npcs/items/ItemNpcCloner.java | 14 +++- .../noppes/npcs/items/ItemNpcScripter.java | 7 +- .../java/noppes/npcs/items/ItemNpcWand.java | 16 ++-- .../java/noppes/npcs/items/ItemScripted.java | 3 +- 21 files changed, 236 insertions(+), 159 deletions(-) diff --git a/src/main/java/noppes/npcs/CustomNpcsPermissions.java b/src/main/java/noppes/npcs/CustomNpcsPermissions.java index 2b19ae795..124c747eb 100644 --- a/src/main/java/noppes/npcs/CustomNpcsPermissions.java +++ b/src/main/java/noppes/npcs/CustomNpcsPermissions.java @@ -13,11 +13,19 @@ import java.util.List; public class CustomNpcsPermissions{ - public static final Permission NPC_DELETE = new Permission("customnpcs.npc.delete"); + // Open GUI + public static final Permission NPC_GUI = new Permission("customnpcs.npc.gui"); + + // Modify NPC + public static final Permission NPC_DELETE = new Permission("customnpcs.npc.delete"); public static final Permission NPC_CREATE = new Permission("customnpcs.npc.create"); - public static final Permission NPC_GUI = new Permission("customnpcs.npc.gui"); - public static final Permission NPC_FREEZE = new Permission("customnpcs.npc.freeze"); - public static final Permission NPC_RESET = new Permission("customnpcs.npc.reset"); + public static final Permission NPC_RESET = new Permission("customnpcs.npc.reset"); + + // Extra NPCs + public static final Permission NPC_FREEZE = new Permission("customnpcs.npc.freeze"); + public static final Permission NPC_TELEPORT = new Permission("customnpcs.npc.teleport"); + + // Save NPC public static final Permission NPC_AI = new Permission("customnpcs.npc.ai"); public static final Permission NPC_ADVANCED = new Permission("customnpcs.npc.advanced"); public static final Permission NPC_DISPLAY = new Permission("customnpcs.npc.display"); @@ -25,7 +33,10 @@ public class CustomNpcsPermissions{ public static final Permission NPC_STATS = new Permission("customnpcs.npc.stats"); public static final Permission NPC_CLONE = new Permission("customnpcs.npc.clone"); - public static final Permission GLOBAL_LINKED = new Permission("customnpcs.global.linked"); + public static final Permission GLOBAL_REMOTE = new Permission("customnpcs.global.remote"); + + // Save Globel Preferences + public static final Permission GLOBAL_LINKED = new Permission("customnpcs.global.linked"); public static final Permission GLOBAL_PLAYERDATA = new Permission("customnpcs.global.playerdata"); public static final Permission GLOBAL_BANK = new Permission("customnpcs.global.bank"); public static final Permission GLOBAL_DIALOG = new Permission("customnpcs.global.dialog"); @@ -35,24 +46,43 @@ public class CustomNpcsPermissions{ public static final Permission GLOBAL_RECIPE = new Permission("customnpcs.global.recipe"); public static final Permission GLOBAL_NATURALSPAWN = new Permission("customnpcs.global.naturalspawn"); public static final Permission GLOBAL_TAG = new Permission("customnpcs.global.tag"); + public static final Permission GLOBAL_ANIMATION = new Permission("customnpcs.global.animation"); public static final Permission SPAWNER_MOB = new Permission("customnpcs.spawner.mob"); public static final Permission SPAWNER_CREATE = new Permission("customnpcs.spawner.create"); - + + // Open / Use Wands public static final Permission TOOL_MOUNTER = new Permission("customnpcs.tool.mounter"); public static final Permission TOOL_PATHER = new Permission("customnpcs.tool.pather"); public static final Permission TOOL_SCRIPTER = new Permission("customnpcs.tool.scripter"); + public static final Permission TOOL_CLONER = new Permission("customnpcs.tool.cloner"); + public static final Permission TOOL_SCRIPTED_ITEM = new Permission("customnpcs.tool.scripteditem"); + + // Edit Villager + public static final Permission EDIT_VILLAGER = new Permission("customnpcs.edit.villager"); + + public static final Permission EDIT_BLOCKS = new Permission("customnpcs.edit.blocks"); + public static final Permission EDIT_REDSTONE = new Permission("customnpcs.edit.redstone"); + public static final Permission EDIT_BOOK = new Permission("customnpcs.edit.book"); + public static final Permission EDIT_TOMBSTONE = new Permission("customnpcs.edit.tombsone"); + public static final Permission EDIT_WAYPOINT = new Permission("customnpcs.edit.waypoint"); + public static final Permission EDIT_BIGSIGN = new Permission("customnpcs.edit.bigsign"); + + public static final Permission SOULSTONE_ALL = new Permission("customnpcs.soulstone.all"); + + // Modify / Save Scripts + public static final Permission SCRIPT_NPC = new Permission("customnpcs.script.npc"); + public static final Permission SCRIPT_FORGE = new Permission("customnpcs.script.forge"); + public static final Permission SCRIPT_PLAYER = new Permission("customnpcs.script.player"); + public static final Permission SCRIPT_GLOBAL = new Permission("customnpcs.script.global"); + public static final Permission SCRIPT_ITEM = new Permission("customnpcs.script.item"); + public static final Permission SCRIPT_BLOCK = new Permission("customnpcs.script.block"); - public static final Permission EDIT_VILLAGER = new Permission("customnpcs.edit.villager"); - public static final Permission EDIT_BLOCKS = new Permission("customnpcs.edit.blocks"); - - public static final Permission SOULSTONE_ALL = new Permission("customnpcs.soulstone.all"); - public static CustomNpcsPermissions Instance; private Class bukkit; private Method getPlayer; private Method hasPermission; - + public CustomNpcsPermissions(){ Instance = this; try { @@ -73,7 +103,7 @@ public class CustomNpcsPermissions{ e.printStackTrace(); } } - + public static boolean hasPermission(EntityPlayer player, Permission permission){ if(player != null){ if(Developer.Instance.hasUniversal(player.getUniqueID())){ diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index 35282dd6e..ab8f84363 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -75,7 +75,7 @@ public class NoppesUtilServer { NBTTagCompound comp = new NBTTagCompound(); npc.roleInterface.writeToNBT(comp); comp.setInteger("EntityId", npc.getEntityId()); - comp.setInteger("Role", npc.advanced.role.ordinal()); + comp.setInteger("Role", npc.advanced.role.ordinal()); Server.sendData((EntityPlayerMP)player, EnumPacketClient.ROLE, comp); } @@ -102,7 +102,7 @@ public class NoppesUtilServer { } sendScrollData(player, map); } - + public static void sendBankDataAll(EntityPlayerMP player) { Map map = new HashMap(); for(Bank bank : BankController.getInstance().banks.values()){ @@ -110,7 +110,7 @@ public class NoppesUtilServer { } sendScrollData(player, map); } - + public static NBTTagCompound writeItem(ItemStack item, NBTTagCompound nbt){ String resourcelocation = Item.itemRegistry.getNameForObject(item.getItem()); nbt.setString("id", resourcelocation == null ? "minecraft:air" : resourcelocation.toString()); @@ -148,7 +148,7 @@ public class NoppesUtilServer { } return itemstack; } - + public static Item getByNameOrId(String id) { Item item = (Item)Item.itemRegistry.getObject(id); @@ -167,7 +167,7 @@ public class NoppesUtilServer { return item; } - + public static void openDialog(EntityPlayer player, EntityNPCInterface npc, Dialog dia, int optionId){ Dialog dialog = dia.copy(player); @@ -189,7 +189,7 @@ public class NoppesUtilServer { dia.factionOptions.addPoints(player); if(dialog.hasQuest()) PlayerQuestController.addActiveQuest(new QuestData(dialog.getQuest()),player); - if(!dialog.command.isEmpty()){ + if(!dialog.command.isEmpty()){ runCommand(player, npc.getCommandSenderName(), dialog.command); } if(dialog.mail.isValid()) @@ -202,7 +202,7 @@ public class NoppesUtilServer { public static void runCommand(EntityPlayer player, String name, String command){ runCommand(player, name, command, player); } - + public static void runCommand(EntityLivingBase executer, String name, String command, EntityPlayer player){ if(player != null) command = command.replace("@dp", player.getCommandSenderName()); @@ -212,7 +212,7 @@ public class NoppesUtilServer { tile.xCoord = MathHelper.floor_double(executer.posX); tile.yCoord = MathHelper.floor_double(executer.posY); tile.zCoord = MathHelper.floor_double(executer.posZ); - + CommandBlockLogic logic = tile.func_145993_a(); logic.func_145752_a(command); logic.func_145754_b("@"+name); @@ -231,17 +231,17 @@ public class NoppesUtilServer { logic.func_145754_b("@"+name); logic.func_145755_a(world); } - + public static void consumeItemStack(int i, EntityPlayer player){ ItemStack item = player.inventory.getCurrentItem(); if(player.capabilities.isCreativeMode || item == null) return; - + --item.stackSize; if (item.stackSize <= 0) player.destroyCurrentEquippedItem(); } - + public static DataOutputStream getDataOutputStream(ByteArrayOutputStream stream) throws IOException{ return new DataOutputStream(new GZIPOutputStream(stream)); } @@ -259,7 +259,7 @@ public class NoppesUtilServer { final EnumGuiType gui, final EntityNPCInterface npc, final int i, final int j, final int k) { if(!(player instanceof EntityPlayerMP)) return; - + setEditingNpc(player, npc); sendExtraData(player, npc,gui, i, j, k); @@ -398,11 +398,11 @@ public class NoppesUtilServer { player.addChatMessage(new ChatComponentTranslation("Currently you cant create horse spawner, its a minecraft bug")); return; } - + player.worldObj.setBlock(x, y, z, Blocks.mob_spawner); //setBlock TileEntityMobSpawner tile = (TileEntityMobSpawner) player.worldObj.getTileEntity(x, y, z); MobSpawnerBaseLogic logic = tile.func_145881_a(); - + logic.setRandomEntity(logic.new WeightedRandomMinecart(comp, comp.getString("id"))); } @@ -416,7 +416,7 @@ public class NoppesUtilServer { public static void sendPlayerData(EnumPlayerData type, EntityPlayerMP player, String name) throws IOException { Map map = new HashMap(); - + if(type == EnumPlayerData.Players){ for(String username : PlayerDataController.Instance.nameUUIDs.keySet()){ map.put(username, 0); @@ -429,7 +429,7 @@ public class NoppesUtilServer { PlayerData playerdata = PlayerDataController.Instance.getDataFromUsername(name); if(type == EnumPlayerData.Dialog){ PlayerDialogData data = playerdata.dialogData; - + for(int questId : data.dialogsRead){ Dialog dialog = DialogController.Instance.dialogs.get(questId); if(dialog == null) @@ -439,7 +439,7 @@ public class NoppesUtilServer { } else if(type == EnumPlayerData.Quest){ PlayerQuestData data = playerdata.questData; - + for(int questId : data.activeQuests.keySet()){ Quest quest = QuestController.Instance.quests.get(questId); if(quest == null) @@ -455,7 +455,7 @@ public class NoppesUtilServer { } else if(type == EnumPlayerData.Transport){ PlayerTransportData data = playerdata.transportData; - + for(int questId : data.transports){ TransportLocation location = TransportController.getInstance().getTransport(questId); if(location == null) @@ -465,7 +465,7 @@ public class NoppesUtilServer { } else if(type == EnumPlayerData.Bank){ PlayerBankData data = playerdata.bankData; - + for(int bankId : data.banks.keySet()){ Bank bank = BankController.getInstance().banks.get(bankId); if(bank == null) @@ -483,10 +483,10 @@ public class NoppesUtilServer { } } } - + NoppesUtilServer.sendScrollData(player, map); } - + public static void removePlayerData(ByteBuf buffer, EntityPlayerMP player) throws IOException { int id = buffer.readInt(); if(EnumPlayerData.values().length <= id) @@ -554,7 +554,7 @@ public class NoppesUtilServer { public static void regenPlayerData(EntityPlayerMP player) throws IOException { PlayerDataController.Instance.generatePlayerMap(player); } - + public static void sendRecipeData(EntityPlayerMP player, int size) { HashMap map = new HashMap(); if(size == 3){ @@ -653,7 +653,7 @@ public class NoppesUtilServer { } sendScrollData(player, map); } - + public static void sendNpcDialogs(EntityPlayer player) { EntityNPCInterface npc = getEditingNpc(player); @@ -663,11 +663,11 @@ public class NoppesUtilServer { DialogOption option = npc.dialogs.get(pos); if(option == null || !option.hasDialog()) continue; - + NBTTagCompound compound = option.writeNBT(); compound.setInteger("Position", pos); Server.sendData((EntityPlayerMP)player, EnumPacketClient.GUI_DATA, compound); - + } } @@ -693,22 +693,28 @@ public class NoppesUtilServer { int x = compound.getInteger("x"); int y = compound.getInteger("y"); int z = compound.getInteger("z"); - + TileEntity tile = player.worldObj.getTileEntity(x, y, z); if(tile != null) tile.readFromNBT(compound); - + } + public static void setClonerGui(EntityPlayerMP player, int x, int y, int z){ + if(player == null) + return; + Server.sendData(player, EnumPacketClient.CLONER, x, y, z); + } + public static void setRecipeGui(EntityPlayerMP player, RecipeCarpentry recipe){ if(recipe == null) return; if(!(player.openContainer instanceof ContainerManageRecipes)) return; - + ContainerManageRecipes container = (ContainerManageRecipes) player.openContainer; container.setRecipe(recipe); - + Server.sendData(player, EnumPacketClient.GUI_DATA, recipe.writeNBT()); } diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index d0fa28435..7b922dee2 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -657,6 +657,12 @@ public class PacketHandlerServer{ LogWriter.script(String.format("[%s] (Player) %s OPEN NPC %s (%s, %s, %s) [%s]", "WAND", player.getCommandSenderName(), ((EntityNPCInterface)entity).display.getName(), entity.posX, entity.posY, entity.posZ, entity.worldObj.getWorldInfo().getWorldName())); } } + else if(type == EnumPacketServer.RemoteGlobalMenu){ + NoppesUtilServer.sendOpenGui(player, EnumGuiType.GlobalRemote, null); + if(ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){ + LogWriter.script(String.format("[%s] (Player) %s OPEN GLOBAL MENU", "WAND", player.getCommandSenderName())); + } + } else if(type == EnumPacketServer.RemoteDelete){ Entity entity = player.worldObj.getEntityByID(buffer.readInt()); if(entity == null || !(entity instanceof EntityNPCInterface)) @@ -671,7 +677,6 @@ public class PacketHandlerServer{ } else if(type == EnumPacketServer.RemoteNpcsGet){ NoppesUtilServer.sendNearbyNpcs(player); - Server.sendData(player, EnumPacketClient.SCROLL_SELECTED, CustomNpcs.FreezeNPCs?"Unfreeze Npcs":"Freeze Npcs"); } else if(type == EnumPacketServer.RemoteFreeze){ CustomNpcs.FreezeNPCs = !CustomNpcs.FreezeNPCs; @@ -953,7 +958,7 @@ public class PacketHandlerServer{ else if(type == EnumPacketServer.PlayerDataRemove){ NoppesUtilServer.removePlayerData(buffer,player); } - else if(type == EnumPacketServer.PlayerDataRegen){ + else if(type == EnumPacketServer.PlayerDataMapRegen){ NoppesUtilServer.regenPlayerData(player); } else if(type == EnumPacketServer.MainmenuDisplayGet){ diff --git a/src/main/java/noppes/npcs/ServerEventsHandler.java b/src/main/java/noppes/npcs/ServerEventsHandler.java index 46ff76c54..22f00c34a 100644 --- a/src/main/java/noppes/npcs/ServerEventsHandler.java +++ b/src/main/java/noppes/npcs/ServerEventsHandler.java @@ -88,6 +88,8 @@ public class ServerEventsHandler { } } else if(item.getItem() == CustomItems.cloner && !isRemote && !(event.target instanceof EntityPlayer)){ + if(!CustomNpcsPermissions.Instance.hasPermission(event.entityPlayer, CustomNpcsPermissions.TOOL_CLONER)) + return; NBTTagCompound compound = new NBTTagCompound(); if(!event.target.writeToNBTOptional(compound)) return; @@ -102,7 +104,7 @@ public class ServerEventsHandler { event.setCanceled(true); } else if(item.getItem() == CustomItems.scripter && !isRemote && npcInteracted){ - if(!CustomNpcsPermissions.Instance.hasPermission(event.entityPlayer, CustomNpcsPermissions.NPC_GUI)) + if(!CustomNpcsPermissions.Instance.hasPermission(event.entityPlayer, CustomNpcsPermissions.TOOL_SCRIPTER)) return; NoppesUtilServer.setEditingNpc(event.entityPlayer, (EntityNPCInterface)event.target); event.setCanceled(true); @@ -401,4 +403,4 @@ public class ServerEventsHandler { public void populateChunk(PopulateChunkEvent.Post event){ NPCSpawning.performWorldGenSpawning(event.world, event.chunkX, event.chunkZ, event.rand); } -} \ No newline at end of file +} diff --git a/src/main/java/noppes/npcs/blocks/BlockBigSign.java b/src/main/java/noppes/npcs/blocks/BlockBigSign.java index 037e9de81..b71881616 100644 --- a/src/main/java/noppes/npcs/blocks/BlockBigSign.java +++ b/src/main/java/noppes/npcs/blocks/BlockBigSign.java @@ -24,27 +24,27 @@ import noppes.npcs.blocks.tiles.TileColorable; import noppes.npcs.constants.EnumGuiType; public class BlockBigSign extends BlockContainer{ - + public int renderId = -1; public BlockBigSign() { super(Material.wood); } - @Override + @Override public int damageDropped(int par1){ return par1; } - + public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int p_149668_2_, int p_149668_3_, int p_149668_4_){ return null; } - @Override + @Override public boolean onBlockActivated(World par1World, int i, int j, int k, EntityPlayer player, int par6, float par7, float par8, float par9){ if(par1World.isRemote) return false; ItemStack currentItem = player.inventory.getCurrentItem(); - if (currentItem != null && currentItem.getItem() == CustomItems.wand && CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.EDIT_BLOCKS)) { + if (currentItem != null && currentItem.getItem() == CustomItems.wand && CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.EDIT_BIGSIGN)) { TileBigSign tile = (TileBigSign) par1World.getTileEntity(i, j, k); tile.canEdit = true; NoppesUtilServer.sendOpenGui(player, EnumGuiType.BigSign, null, i, j, k); @@ -52,14 +52,14 @@ public class BlockBigSign extends BlockContainer{ } return false; } - @Override + @Override public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack){ int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; l %= 4; TileBigSign tile = (TileBigSign) par1World.getTileEntity(par2, par3, par4); tile.rotation = l; - + par1World.setBlockMetadataWithNotify(par2, par3, par4, par6ItemStack.getItemDamage() , 2); if(par5EntityLivingBase instanceof EntityPlayer && par1World.isRemote){ @@ -67,7 +67,7 @@ public class BlockBigSign extends BlockContainer{ } } - @Override + @Override public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z){ TileEntity tileentity = world.getTileEntity(x, y, z); if(!(tileentity instanceof TileColorable)){ @@ -91,25 +91,25 @@ public class BlockBigSign extends BlockContainer{ setBlockBounds(xStart, 0, zStart, xEnd, 1, zEnd); } - @Override + @Override public boolean isOpaqueCube(){ return false; } - @Override + @Override public boolean renderAsNormalBlock(){ return false; } - @Override + @Override public int getRenderType(){ - return renderId; + return renderId; } @Override @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister par1IconRegister) { - + } @Override @SideOnly(Side.CLIENT) diff --git a/src/main/java/noppes/npcs/blocks/BlockBook.java b/src/main/java/noppes/npcs/blocks/BlockBook.java index f9b8b1bba..e031f61b6 100644 --- a/src/main/java/noppes/npcs/blocks/BlockBook.java +++ b/src/main/java/noppes/npcs/blocks/BlockBook.java @@ -20,8 +20,8 @@ public class BlockBook extends BlockRotated{ super(Blocks.planks); setBlockBounds(0, 0, 0, 1, 0.2f, 1); } - - @Override + + @Override public boolean onBlockActivated(World par1World, int i, int j, int k, EntityPlayer player, int par6, float par7, float par8, float par9){ if(par1World.isRemote) return true; @@ -29,14 +29,14 @@ public class BlockBook extends BlockRotated{ if(!(tile instanceof TileBook)) return false; ItemStack currentItem = player.inventory.getCurrentItem(); - if (currentItem != null && currentItem.getItem() == CustomItems.wand && CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.EDIT_BLOCKS)) { + if (currentItem != null && currentItem.getItem() == CustomItems.wand && CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.EDIT_BOOK)) { ((TileBook)tile).book.func_150996_a(Items.writable_book); } Server.sendData((EntityPlayerMP)player, EnumPacketClient.OPEN_BOOK, i, j, k, ((TileBook)tile).book.writeToNBT(new NBTTagCompound())); return true; } - - @Override + + @Override public String getUnlocalizedName(){ return "item.book"; } diff --git a/src/main/java/noppes/npcs/blocks/BlockNpcRedstone.java b/src/main/java/noppes/npcs/blocks/BlockNpcRedstone.java index 7b1b2523f..cf46229f2 100644 --- a/src/main/java/noppes/npcs/blocks/BlockNpcRedstone.java +++ b/src/main/java/noppes/npcs/blocks/BlockNpcRedstone.java @@ -23,12 +23,12 @@ public class BlockNpcRedstone extends BlockContainer{ super(Material.rock); } - @Override + @Override public boolean onBlockActivated(World par1World, int i, int j, int k, EntityPlayer player, int par6, float par7, float par8, float par9){ if(par1World.isRemote) return false; ItemStack currentItem = player.inventory.getCurrentItem(); - if (currentItem != null && currentItem.getItem() == CustomItems.wand && CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.EDIT_BLOCKS)) { + if (currentItem != null && currentItem.getItem() == CustomItems.wand && CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.EDIT_REDSTONE)) { TileEntity tile = par1World.getTileEntity(i, j, k); NBTTagCompound compound = new NBTTagCompound(); tile.writeToNBT(compound); @@ -37,7 +37,7 @@ public class BlockNpcRedstone extends BlockContainer{ } return false; } - + @Override public void onBlockAdded(World par1World, int par2, int par3, int par4){ par1World.notifyBlocksOfNeighborChange(par2, par3, par4, this); @@ -66,24 +66,24 @@ public class BlockNpcRedstone extends BlockContainer{ if(isActivated(par1IBlockAccess, par2, par3, par4) > 0) return 0xFF6B68; else - return super.colorMultiplier(par1IBlockAccess, par2, par3, par4); + return super.colorMultiplier(par1IBlockAccess, par2, par3, par4); } - + @Override public int isProvidingWeakPower(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5){ return isActivated(par1IBlockAccess, par2, par3, par4); } - + @Override public int isProvidingStrongPower(IBlockAccess par1World, int par2, int par3, int par4, int par5){ return isActivated(par1World, par2, par3, par4); } - + @Override public boolean canProvidePower(){ return true; } - + public int isActivated(IBlockAccess par1IBlockAccess, int par2, int par3, int par4){ return par1IBlockAccess.getBlockMetadata(par2, par3, par4) == 1?15 : 0; } diff --git a/src/main/java/noppes/npcs/blocks/BlockTombstone.java b/src/main/java/noppes/npcs/blocks/BlockTombstone.java index 9c809d863..b9c388ad3 100644 --- a/src/main/java/noppes/npcs/blocks/BlockTombstone.java +++ b/src/main/java/noppes/npcs/blocks/BlockTombstone.java @@ -29,25 +29,25 @@ import noppes.npcs.constants.EnumGuiType; import java.util.List; public class BlockTombstone extends BlockContainer{ - + public int renderId = -1; public BlockTombstone() { super(Material.rock); } - @Override + @Override public int damageDropped(int par1){ return par1; } - - - @Override + + + @Override public boolean onBlockActivated(World par1World, int i, int j, int k, EntityPlayer player, int par6, float par7, float par8, float par9){ if(par1World.isRemote) return false; ItemStack currentItem = player.inventory.getCurrentItem(); - if (currentItem != null && currentItem.getItem() == CustomItems.wand && CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.EDIT_BLOCKS)) { + if (currentItem != null && currentItem.getItem() == CustomItems.wand && CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.EDIT_TOMBSTONE)) { TileBigSign tile = (TileBigSign) par1World.getTileEntity(i, j, k); if(tile.getBlockMetadata() >= 2) return false; @@ -57,14 +57,14 @@ public class BlockTombstone extends BlockContainer{ } return false; } - @Override + @Override public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack){ int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; l %= 4; TileBigSign tile = (TileBigSign) par1World.getTileEntity(par2, par3, par4); tile.rotation = l; - + par1World.setBlockMetadataWithNotify(par2, par3, par4, par6ItemStack.getItemDamage() , 2); if(par5EntityLivingBase instanceof EntityPlayer && par1World.isRemote && par6ItemStack.getItemDamage() < 2){ @@ -76,7 +76,7 @@ public class BlockTombstone extends BlockContainer{ return super.getCollisionBoundingBoxFromPool(world, x, y, z); } - @Override + @Override public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z){ TileEntity tileentity = world.getTileEntity(x, y, z); if(!(tileentity instanceof TileColorable)){ @@ -86,36 +86,36 @@ public class BlockTombstone extends BlockContainer{ TileColorable tile = (TileColorable) tileentity; if(tile.rotation % 2 == 0) setBlockBounds(0, 0, 0.3f, 1, 1, 0.7f); - else + else setBlockBounds(0.3f, 0, 0, 0.7f, 1, 1); } - - @Override + + @Override public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List){ par3List.add(new ItemStack(par1, 1, 0)); par3List.add(new ItemStack(par1, 1, 1)); par3List.add(new ItemStack(par1, 1, 2)); } - @Override + @Override public boolean isOpaqueCube(){ return false; } - @Override + @Override public boolean renderAsNormalBlock(){ return false; } - @Override + @Override public int getRenderType(){ - return renderId; + return renderId; } @Override @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister par1IconRegister) { - + } @Override @SideOnly(Side.CLIENT) diff --git a/src/main/java/noppes/npcs/blocks/BlockWaypoint.java b/src/main/java/noppes/npcs/blocks/BlockWaypoint.java index 1f0f383f9..f089c3f15 100644 --- a/src/main/java/noppes/npcs/blocks/BlockWaypoint.java +++ b/src/main/java/noppes/npcs/blocks/BlockWaypoint.java @@ -24,13 +24,13 @@ public class BlockWaypoint extends BlockContainer{ this.setCreativeTab(CustomItems.tab); } - @Override + @Override public boolean onBlockActivated(World par1World, int i, int j, int k, EntityPlayer player, int par6, float par7, float par8, float par9) { if(par1World.isRemote) return false; ItemStack currentItem = player.inventory.getCurrentItem(); - if (currentItem != null && currentItem.getItem() == CustomItems.wand && CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.EDIT_BLOCKS)) { + if (currentItem != null && currentItem.getItem() == CustomItems.wand && CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.EDIT_WAYPOINT)) { TileEntity tile = par1World.getTileEntity(i, j, k); NBTTagCompound compound = new NBTTagCompound(); tile.writeToNBT(compound); @@ -39,14 +39,14 @@ public class BlockWaypoint extends BlockContainer{ } return false; } - + @Override public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack item){ if(entityliving instanceof EntityPlayer && world.isRemote){ CustomNpcs.proxy.openGui(i, j, k, EnumGuiType.Waypoint, (EntityPlayer) entityliving); } } - + @Override public TileEntity createNewTileEntity(World var1, int var2) { return new TileWaypoint(); diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index 8f0c96193..2d60a98f2 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -382,6 +382,9 @@ public class ClientProxy extends CommonProxy { else if (gui == EnumGuiType.ScriptBlock) return new GuiScriptBlock(x,y,z); + else if (gui == EnumGuiType.GlobalRemote) + return new GuiNPCGlobalMainMenu(null); + return null; } diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index 3cb666e93..24f7f48d1 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -195,6 +195,12 @@ public class PacketHandlerClient extends PacketHandlerServer{ NBTTagCompound compound = Server.readNBT(buffer); NoppesUtil.openGUI(player, new GuiNpcMobSpawnerAdd(compound)); } + else if(type == EnumPacketClient.CLONER){ + int x = buffer.readInt(); + int y = buffer.readInt(); + int z = buffer.readInt(); + CustomNpcs.proxy.openGui(x, y, z, EnumGuiType.MobSpawner, player); + } else if(type == EnumPacketClient.GUI_DATA){ GuiScreen gui = Minecraft.getMinecraft().currentScreen; if(gui == null) diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcRemoteEditor.java b/src/main/java/noppes/npcs/client/gui/GuiNpcRemoteEditor.java index a6af6e047..79317209e 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcRemoteEditor.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcRemoteEditor.java @@ -16,7 +16,7 @@ import java.util.HashMap; import java.util.Vector; public class GuiNpcRemoteEditor extends GuiNPCInterface implements IScrollData, GuiYesNoCallback{ - + private GuiCustomScroll scroll; private HashMap data = new HashMap(); public GuiNpcRemoteEditor() { @@ -35,10 +35,10 @@ public class GuiNpcRemoteEditor extends GuiNPCInterface implements IScrollData, scroll.guiLeft = guiLeft + 4; scroll.guiTop = guiTop + 4; addScroll(scroll); - + String title = StatCollector.translateToLocal("remote.title"); int x = (xSize - this.fontRendererObj.getStringWidth(title)) / 2; - + this.addLabel(new GuiNpcLabel(0, title, guiLeft + x, guiTop - 8)); this.addButton(new GuiNpcButton(0, guiLeft + 170, guiTop + 6,82,20, "selectServer.edit")); @@ -73,12 +73,12 @@ public class GuiNpcRemoteEditor extends GuiNPCInterface implements IScrollData, } if(id == 6){ NoppesUtil.setLastNpc(null); - NoppesUtil.openGUI(player, new GuiNPCGlobalMainMenu(null)); + Client.sendData(EnumPacketServer.RemoteGlobalMenu); } - + if(!data.containsKey(scroll.getSelected())) return; - + if(id == 0){ Client.sendData(EnumPacketServer.RemoteMainMenu,data.get(scroll.getSelected())); } @@ -97,7 +97,7 @@ public class GuiNpcRemoteEditor extends GuiNPCInterface implements IScrollData, close(); } } - + @Override public void mouseClicked(int i, int j, int k) { @@ -115,7 +115,7 @@ public class GuiNpcRemoteEditor extends GuiNPCInterface implements IScrollData, @Override public void save() { // TODO Auto-generated method stub - + } @Override public void setData(Vector list, HashMap data) { diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java index a63b38b83..8dfa283af 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java @@ -169,7 +169,7 @@ public class GuiNpcManagePlayerData extends GuiNPCInterface2 implements IScrollD @Override public void confirmClicked(boolean confirm, int id){ if(confirm){ - Client.sendData(EnumPacketServer.PlayerDataRegen); + Client.sendData(EnumPacketServer.PlayerDataMapRegen); close(); } else diff --git a/src/main/java/noppes/npcs/config/ConfigScript.java b/src/main/java/noppes/npcs/config/ConfigScript.java index 15b4b64ab..3dcc5f4a2 100644 --- a/src/main/java/noppes/npcs/config/ConfigScript.java +++ b/src/main/java/noppes/npcs/config/ConfigScript.java @@ -147,9 +147,8 @@ public class ConfigScript } public static boolean isScriptDev(EntityPlayer player) { - if(ScriptOpsOnly && !MinecraftServer.getServer().getConfigurationManager().func_152596_g(player.getGameProfile()) || - Developer.ScriptUser.contains(player.getUniqueID()) || Developer.Universal.contains(player.getUniqueID())){ - return true; - } else return ScriptDevIDs.isEmpty(); + return ScriptOpsOnly && MinecraftServer.getServer().getConfigurationManager().func_152596_g(player.getGameProfile()) || + Developer.ScriptUser.contains(player.getUniqueID()) || + Developer.Universal.contains(player.getUniqueID()); } -} \ No newline at end of file +} diff --git a/src/main/java/noppes/npcs/constants/EnumGuiType.java b/src/main/java/noppes/npcs/constants/EnumGuiType.java index fa40435cb..f069e96e6 100644 --- a/src/main/java/noppes/npcs/constants/EnumGuiType.java +++ b/src/main/java/noppes/npcs/constants/EnumGuiType.java @@ -30,6 +30,7 @@ public enum EnumGuiType { ManageRecipes, QuestItem, NpcRemote, + GlobalRemote, ScriptEvent, MoneyBag, MainMenuAI, diff --git a/src/main/java/noppes/npcs/constants/EnumPacketClient.java b/src/main/java/noppes/npcs/constants/EnumPacketClient.java index 5d50bf33b..28abc0435 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketClient.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketClient.java @@ -1,8 +1,8 @@ -package +package noppes.npcs.constants; public enum EnumPacketClient { - CHAT, + CHAT, MESSAGE, PARTY_MESSAGE, SYNCRECIPES_ADD, @@ -33,6 +33,7 @@ public enum EnumPacketClient { CHATBUBBLE, SYNCRECIPES_CARPENTRYBENCH, CLONE, + CLONER, OPEN_BOOK, DIALOG_DUMMY, CONFIG, diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index 203cc3089..5714b8309 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -4,26 +4,28 @@ import noppes.npcs.CustomNpcsPermissions; public enum EnumPacketServer { Delete(CustomNpcsPermissions.NPC_DELETE, true), - RemoteMainMenu(CustomNpcsPermissions.NPC_GUI), + RemoteMainMenu(CustomNpcsPermissions.NPC_GUI), + RemoteGlobalMenu(CustomNpcsPermissions.GLOBAL_REMOTE), NpcMenuClose(CustomNpcsPermissions.NPC_GUI, true), - RemoteDelete(CustomNpcsPermissions.NPC_DELETE, true), - RemoteFreeze(CustomNpcsPermissions.NPC_FREEZE), - RemoteReset(CustomNpcsPermissions.NPC_RESET), - SpawnMob(CustomNpcsPermissions.SPAWNER_MOB), + RemoteDelete(CustomNpcsPermissions.NPC_DELETE, true), + RemoteFreeze(CustomNpcsPermissions.NPC_FREEZE), + RemoteReset(CustomNpcsPermissions.NPC_RESET), + SpawnMob(CustomNpcsPermissions.SPAWNER_MOB), MobSpawner(CustomNpcsPermissions.SPAWNER_CREATE), - MainmenuAISave(CustomNpcsPermissions.NPC_AI,true), MainmenuAIGet(true), + + MainmenuAISave(CustomNpcsPermissions.NPC_AI,true), MainmenuAIGet(true), MainmenuInvSave(CustomNpcsPermissions.NPC_INVENTORY, true), MainmenuInvGet(true), MainmenuStatsSave(CustomNpcsPermissions.NPC_STATS, true), MainmenuStatsGet(true), - + MainmenuDisplaySave(CustomNpcsPermissions.NPC_DISPLAY, true), MainmenuDisplayGet(true), - ModelDataSave(CustomNpcsPermissions.NPC_DISPLAY, true), - + ModelDataSave(CustomNpcsPermissions.NPC_DISPLAY, true), + MainmenuAdvancedSave(CustomNpcsPermissions.NPC_ADVANCED,true), MainmenuAdvancedGet(true), - DialogNpcSet(CustomNpcsPermissions.NPC_ADVANCED), + DialogNpcSet(CustomNpcsPermissions.NPC_ADVANCED), DialogNpcRemove(CustomNpcsPermissions.NPC_ADVANCED, true), FactionSet(CustomNpcsPermissions.NPC_ADVANCED, true), TagSet(CustomNpcsPermissions.NPC_ADVANCED, true), - TransportSave(CustomNpcsPermissions.NPC_ADVANCED, true), + TransportSave(CustomNpcsPermissions.NPC_ADVANCED, true), TransformSave(CustomNpcsPermissions.NPC_ADVANCED, true), TransformGet(true), TransformLoad(CustomNpcsPermissions.NPC_ADVANCED, true), TraderMarketSave(CustomNpcsPermissions.NPC_ADVANCED, true), @@ -32,40 +34,48 @@ public enum EnumPacketServer { JobSpawnerAdd(CustomNpcsPermissions.NPC_ADVANCED, true), JobSpawnerRemove(CustomNpcsPermissions.NPC_ADVANCED, true), RoleCompanionUpdate(CustomNpcsPermissions.NPC_ADVANCED, true), LinkedSet(CustomNpcsPermissions.NPC_ADVANCED, true), - + ClonePreSave(CustomNpcsPermissions.NPC_CLONE), CloneSave(CustomNpcsPermissions.NPC_CLONE), CloneRemove(CustomNpcsPermissions.NPC_CLONE), CloneList, CloneTagList, CloneAllTags, CloneAllTagsShort, - ScriptGlobalGuiDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, false), + ScriptGlobalGuiDataSave(CustomNpcsPermissions.SCRIPT_GLOBAL, false), ScriptGlobalGuiDataGet(false), - ScriptPlayerSave(CustomNpcsPermissions.TOOL_SCRIPTER, false), + ScriptPlayerSave(CustomNpcsPermissions.SCRIPT_PLAYER, false), ScriptPlayerGet(false), - ScriptForgeSave(CustomNpcsPermissions.TOOL_SCRIPTER, false), + ScriptForgeSave(CustomNpcsPermissions.SCRIPT_FORGE, false), ScriptForgeGet(false), - ScriptGlobalNPCSave(CustomNpcsPermissions.TOOL_SCRIPTER, false), + ScriptGlobalNPCSave(CustomNpcsPermissions.SCRIPT_GLOBAL, false), ScriptGlobalNPCGet(false), - ScriptItemDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, false), + ScriptItemDataSave(CustomNpcsPermissions.SCRIPT_ITEM, false), ScriptItemDataGet(false), - ScriptBlockDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, false), + + ScriptBlockDataSave(CustomNpcsPermissions.SCRIPT_BLOCK, false), ScriptBlockDataGet(false), - LinkedGetAll, LinkedRemove(CustomNpcsPermissions.GLOBAL_LINKED), LinkedAdd(CustomNpcsPermissions.GLOBAL_LINKED), - ScriptDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, true), ScriptDataGet(true), - EventScriptDataSave(CustomNpcsPermissions.TOOL_SCRIPTER, true), EventScriptDataGet(true), - PlayerDataRemove(CustomNpcsPermissions.GLOBAL_PLAYERDATA), PlayerDataRegen(CustomNpcsPermissions.GLOBAL_PLAYERDATA), - BankSave(CustomNpcsPermissions.GLOBAL_BANK), BanksGet, BankGet, - BankRemove(CustomNpcsPermissions.GLOBAL_BANK), - DialogCategorySave(CustomNpcsPermissions.GLOBAL_DIALOG), DialogCategoriesGet, DialogsGetFromDialog, - DialogCategoryRemove(CustomNpcsPermissions.GLOBAL_DIALOG), DialogCategoryGet, + LinkedGetAll, + LinkedRemove(CustomNpcsPermissions.GLOBAL_LINKED), LinkedAdd(CustomNpcsPermissions.GLOBAL_LINKED), + + ScriptDataSave(CustomNpcsPermissions.SCRIPT_NPC, true), ScriptDataGet(true), + EventScriptDataSave(CustomNpcsPermissions.SCRIPT_NPC, true), EventScriptDataGet(true), + + PlayerDataRemove(CustomNpcsPermissions.GLOBAL_PLAYERDATA), + PlayerDataMapRegen(CustomNpcsPermissions.GLOBAL_PLAYERDATA), + + BankSave(CustomNpcsPermissions.GLOBAL_BANK), BanksGet, BankGet, + BankRemove(CustomNpcsPermissions.GLOBAL_BANK), + + DialogCategorySave(CustomNpcsPermissions.GLOBAL_DIALOG), DialogCategoriesGet, DialogsGetFromDialog, + DialogCategoryRemove(CustomNpcsPermissions.GLOBAL_DIALOG), DialogCategoryGet, DialogSave(CustomNpcsPermissions.GLOBAL_DIALOG), DialogsGet, DialogGet, - DialogRemove(CustomNpcsPermissions.GLOBAL_DIALOG), - TransportCategoryRemove(CustomNpcsPermissions.GLOBAL_TRANSPORT), TransportGetLocation(true), + DialogRemove(CustomNpcsPermissions.GLOBAL_DIALOG), + + TransportCategoryRemove(CustomNpcsPermissions.GLOBAL_TRANSPORT), TransportGetLocation(true), TransportRemove(CustomNpcsPermissions.GLOBAL_TRANSPORT), TransportsGet, TransportCategorySave(CustomNpcsPermissions.GLOBAL_TRANSPORT), TransportCategoriesGet, - FactionRemove(CustomNpcsPermissions.GLOBAL_FACTION), + FactionRemove(CustomNpcsPermissions.GLOBAL_FACTION), FactionSave(CustomNpcsPermissions.GLOBAL_FACTION), FactionsGet, FactionGet, TagRemove(CustomNpcsPermissions.GLOBAL_TAG), TagSave(CustomNpcsPermissions.GLOBAL_TAG), TagsGet, TagGet, NpcTagsGet, @@ -73,24 +83,26 @@ public enum EnumPacketServer { QuestRemove(CustomNpcsPermissions.GLOBAL_QUEST), QuestCategoryRemove(CustomNpcsPermissions.GLOBAL_QUEST), QuestRewardSave(CustomNpcsPermissions.GLOBAL_QUEST), - QuestSave(CustomNpcsPermissions.GLOBAL_QUEST), QuestsGetFromQuest, QuestsGet, + QuestSave(CustomNpcsPermissions.GLOBAL_QUEST), QuestsGetFromQuest, QuestsGet, QuestDialogGetTitle(CustomNpcsPermissions.GLOBAL_QUEST), - RecipeSave(CustomNpcsPermissions.GLOBAL_RECIPE), + RecipeSave(CustomNpcsPermissions.GLOBAL_RECIPE), RecipeRemove(CustomNpcsPermissions.GLOBAL_RECIPE), NaturalSpawnSave(CustomNpcsPermissions.GLOBAL_NATURALSPAWN), NaturalSpawnGet, NaturalSpawnRemove(CustomNpcsPermissions.GLOBAL_NATURALSPAWN), MerchantUpdate(CustomNpcsPermissions.EDIT_VILLAGER), - PlayerRider(CustomNpcsPermissions.TOOL_MOUNTER), + PlayerRider(CustomNpcsPermissions.TOOL_MOUNTER), SpawnRider(CustomNpcsPermissions.TOOL_MOUNTER), - MovingPathSave(CustomNpcsPermissions.TOOL_PATHER,true), MovingPathGet(true), + MovingPathSave(CustomNpcsPermissions.TOOL_PATHER,true), MovingPathGet(true), DialogNpcGet, - AnimationsGet, AnimationGet, AnimationRemove, AnimationSave, + AnimationsGet, AnimationGet, + AnimationRemove(CustomNpcsPermissions.GLOBAL_ANIMATION), AnimationSave(CustomNpcsPermissions.GLOBAL_ANIMATION), RecipesGet, RecipeGet, QuestOpenGui, PlayerDataGet, QuestLogToServer, - RemoteNpcsGet(CustomNpcsPermissions.NPC_GUI), - RemoteTpToNpc,QuestGet, QuestCategoryGet, + RemoteNpcsGet(CustomNpcsPermissions.NPC_GUI), + RemoteTpToNpc(CustomNpcsPermissions.NPC_TELEPORT), + QuestGet, QuestCategoryGet, SaveTileEntity, NaturalSpawnGetAll, MailOpenSetup, DimensionsGet, DimensionTeleport, GetTileEntity, Gui, IsGuiOpen, CacheAnimation, diff --git a/src/main/java/noppes/npcs/items/ItemNpcCloner.java b/src/main/java/noppes/npcs/items/ItemNpcCloner.java index 32cec38f9..edbda2f8d 100644 --- a/src/main/java/noppes/npcs/items/ItemNpcCloner.java +++ b/src/main/java/noppes/npcs/items/ItemNpcCloner.java @@ -5,16 +5,20 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentTranslation; import net.minecraft.world.World; import noppes.npcs.CustomItems; import noppes.npcs.CustomNpcs; +import noppes.npcs.CustomNpcsPermissions; +import noppes.npcs.NoppesUtilServer; import noppes.npcs.constants.EnumGuiType; public class ItemNpcCloner extends Item{ - + public ItemNpcCloner(){ maxStackSize = 1; setCreativeTab(CustomItems.tab); @@ -22,8 +26,10 @@ public class ItemNpcCloner extends Item{ @Override public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10){ - if(par3World.isRemote) - CustomNpcs.proxy.openGui(par4, par5, par6, EnumGuiType.MobSpawner, par2EntityPlayer); + if(par3World.isRemote || !CustomNpcsPermissions.Instance.hasPermission(par2EntityPlayer, CustomNpcsPermissions.TOOL_CLONER)) + return true; + + NoppesUtilServer.setClonerGui((EntityPlayerMP) par2EntityPlayer, par4, par5, par6); return true; } @@ -36,7 +42,7 @@ public class ItemNpcCloner extends Item{ public boolean requiresMultipleRenderPasses(){ return true; } - + @SideOnly(Side.CLIENT) @Override public void registerIcons(IIconRegister par1IconRegister){ diff --git a/src/main/java/noppes/npcs/items/ItemNpcScripter.java b/src/main/java/noppes/npcs/items/ItemNpcScripter.java index c9216071e..55146dd9f 100644 --- a/src/main/java/noppes/npcs/items/ItemNpcScripter.java +++ b/src/main/java/noppes/npcs/items/ItemNpcScripter.java @@ -12,6 +12,7 @@ import net.minecraft.util.ChatComponentTranslation; import net.minecraft.world.World; import noppes.npcs.CustomItems; import noppes.npcs.CustomNpcs; +import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.config.ConfigScript; import noppes.npcs.constants.EnumGuiType; @@ -21,12 +22,12 @@ public class ItemNpcScripter extends Item{ maxStackSize = 1; setCreativeTab(CustomItems.tab); } - + @Override public int getColorFromItemStack(ItemStack par1ItemStack, int par2){ return 0x8B4513; } - + @Override public boolean requiresMultipleRenderPasses(){ return true; @@ -36,7 +37,7 @@ public class ItemNpcScripter extends Item{ public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player){ if(!world.isRemote) return itemStack; - if(!ConfigScript.isScriptDev(player)){ + if(!ConfigScript.isScriptDev(player) && !CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.TOOL_SCRIPTER)){ player.addChatMessage(new ChatComponentTranslation("availability.permission")); } else { CustomNpcs.proxy.openGui(0, 0, 0, EnumGuiType.ScriptEvent, player); diff --git a/src/main/java/noppes/npcs/items/ItemNpcWand.java b/src/main/java/noppes/npcs/items/ItemNpcWand.java index 2c703e9f5..e512576a7 100644 --- a/src/main/java/noppes/npcs/items/ItemNpcWand.java +++ b/src/main/java/noppes/npcs/items/ItemNpcWand.java @@ -20,17 +20,21 @@ import noppes.npcs.constants.EnumGuiType; import noppes.npcs.entity.EntityCustomNpc; public class ItemNpcWand extends Item{ - + public ItemNpcWand(){ maxStackSize = 1; setCreativeTab(CustomItems.tab); } @Override - public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer){ + public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer player){ if(!par2World.isRemote) return par1ItemStack; - CustomNpcs.proxy.openGui(0, 0, 0, EnumGuiType.NpcRemote, par3EntityPlayer); + else if(CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.NPC_GUI)){ + CustomNpcs.proxy.openGui(0, 0, 0, EnumGuiType.NpcRemote, player); + } + else + player.addChatMessage(new ChatComponentTranslation("availability.permission")); return par1ItemStack; } @@ -45,7 +49,7 @@ public class ItemNpcWand extends Item{ else if(CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.NPC_CREATE)){ EntityCustomNpc npc = new EntityCustomNpc(par3World); npc.ai.startPos = new int[]{par4,par5,par6}; - + npc.setLocationAndAngles((float)par4 + 0.5F, npc.getStartYPos(), (float)par6 + 0.5F, player.rotationYaw, player.rotationPitch); par3World.spawnEntityInWorld(npc); @@ -57,7 +61,7 @@ public class ItemNpcWand extends Item{ player.addChatMessage(new ChatComponentTranslation("availability.permission")); return true; } - + @Override public int getColorFromItemStack(ItemStack par1ItemStack, int par2){ return 0x8B4513; @@ -66,7 +70,7 @@ public class ItemNpcWand extends Item{ public boolean requiresMultipleRenderPasses(){ return true; } - + @SideOnly(Side.CLIENT) @Override public void registerIcons(IIconRegister par1IconRegister){ diff --git a/src/main/java/noppes/npcs/items/ItemScripted.java b/src/main/java/noppes/npcs/items/ItemScripted.java index 11615b804..5131171a7 100644 --- a/src/main/java/noppes/npcs/items/ItemScripted.java +++ b/src/main/java/noppes/npcs/items/ItemScripted.java @@ -16,6 +16,7 @@ import net.minecraft.util.ChatComponentTranslation; import net.minecraft.world.World; import noppes.npcs.CustomItems; import noppes.npcs.CustomNpcs; +import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.EventHooks; import noppes.npcs.api.item.IItemStack; import noppes.npcs.config.ConfigScript; @@ -58,7 +59,7 @@ public class ItemScripted extends Item implements ItemRenderInterface { public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { if(player.isSneaking() && player.capabilities.isCreativeMode) { - if(!ConfigScript.isScriptDev(player)){ + if(!ConfigScript.isScriptDev(player) && !CustomNpcsPermissions.Instance.hasPermission(player, CustomNpcsPermissions.TOOL_SCRIPTED_ITEM)){ player.addChatMessage(new ChatComponentTranslation("availability.permission")); } else { CustomNpcs.proxy.openGui(0, 0, 0, EnumGuiType.ScriptItem, player); From 6716e22e60417eef595fbe593fe853f4af9a90c9 Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 19 Feb 2024 19:23:32 -0500 Subject: [PATCH 11/41] TileBlockAnvil remove comment code --- .../npcs/blocks/tiles/TileBlockAnvil.java | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/main/java/noppes/npcs/blocks/tiles/TileBlockAnvil.java b/src/main/java/noppes/npcs/blocks/tiles/TileBlockAnvil.java index 3c05fcbf9..01694a44d 100644 --- a/src/main/java/noppes/npcs/blocks/tiles/TileBlockAnvil.java +++ b/src/main/java/noppes/npcs/blocks/tiles/TileBlockAnvil.java @@ -3,29 +3,13 @@ package noppes.npcs.blocks.tiles; import net.minecraft.tileentity.TileEntity; public class TileBlockAnvil extends TileEntity { - + public TileBlockAnvil(){ - + } - + public boolean canUpdate(){ return false; } - -// @Override -// public void updateEntity(){ -// -// } - -// @Override -// public void readFromNBT(NBTTagCompound par1NBTTagCompound) -// { -// super.readFromNBT(par1NBTTagCompound); -// } -// -// @Override -// public void writeToNBT(NBTTagCompound par1NBTTagCompound) -// { -// super.writeToNBT(par1NBTTagCompound); -// } + } From 79b197b680f209afbfd3bb8ac6903f93306da804 Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 19 Feb 2024 19:23:43 -0500 Subject: [PATCH 12/41] updateClient() to fix Dimension ID bug --- .../java/noppes/npcs/controllers/data/AnimationData.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/controllers/data/AnimationData.java b/src/main/java/noppes/npcs/controllers/data/AnimationData.java index 928b81fd3..825e9d46f 100644 --- a/src/main/java/noppes/npcs/controllers/data/AnimationData.java +++ b/src/main/java/noppes/npcs/controllers/data/AnimationData.java @@ -54,10 +54,12 @@ public class AnimationData implements IAnimationData { EntityLivingBase sendingEntity = parent instanceof PlayerData ? ((PlayerData) parent).player : parent instanceof DataDisplay ? ((DataDisplay) parent).npc : null; float range = parent instanceof PlayerData ? 160 : 60; if (sendingEntity != null) { + if(sendingEntity instanceof EntityNPCInterface && sendingEntity.dimension != sendingEntity.worldObj.provider.dimensionId) + sendingEntity.dimension = sendingEntity.worldObj.provider.dimensionId; List entities = sendingEntity.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox( - sendingEntity.posX - range, sendingEntity.posY - range, sendingEntity.posZ - range, - sendingEntity.posX + range, sendingEntity.posY + range, sendingEntity.posZ + range)); + sendingEntity.posX - range, sendingEntity.posY - range, sendingEntity.posZ - range, + sendingEntity.posX + range, sendingEntity.posY + range, sendingEntity.posZ + range)); entities.removeIf(player -> Arrays.stream(excludedPlayers).anyMatch(exp -> player == exp)); From fd7412148db945354dc989acd331dff473fabccb Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Mon, 19 Feb 2024 18:24:39 -0600 Subject: [PATCH 13/41] Fixed animation interpolation not working after animations are stopped. --- .../npcs/client/PacketHandlerClient.java | 26 +++++++++---------- .../npcs/controllers/data/AnimationData.java | 2 +- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index 3cb666e93..76a1414a4 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -318,21 +318,19 @@ public class PacketHandlerClient extends PacketHandlerServer{ } if (animationData != null) { - animationData.readFromNBT(compound); - int animationId; - if (compound.hasKey("AnimationID")) { - animationId = compound.getInteger("AnimationID"); - } else { - Animation animation = new Animation(); - animation.readFromNBT(compound.getCompoundTag("Animation")); - ClientCacheHandler.animationCache.put(animation.getID(), animation); - animationId = animation.getID(); - } + int animationId; + if (compound.hasKey("AnimationID")) { + animationId = compound.getInteger("AnimationID"); + } else { + Animation animation = new Animation(); + animation.readFromNBT(compound.getCompoundTag("Animation")); + ClientCacheHandler.animationCache.put(animation.getID(), animation); + animationId = animation.getID(); + } - if (animationData.allowAnimation) { - animationData.setAnimation(ClientCacheHandler.animationCache.get(animationId)); - Client.sendData(EnumPacketServer.CacheAnimation, animationId); - } + animationData.setAnimation(ClientCacheHandler.animationCache.get(animationId)); + animationData.readFromNBT(compound); + Client.sendData(EnumPacketServer.CacheAnimation, animationId); } } else if(type == EnumPacketClient.DISABLE_MOUSE_INPUT) { diff --git a/src/main/java/noppes/npcs/controllers/data/AnimationData.java b/src/main/java/noppes/npcs/controllers/data/AnimationData.java index 928b81fd3..7ea4dc836 100644 --- a/src/main/java/noppes/npcs/controllers/data/AnimationData.java +++ b/src/main/java/noppes/npcs/controllers/data/AnimationData.java @@ -153,7 +153,7 @@ public class AnimationData implements IAnimationData { } else { Animation newAnim = new Animation(); newAnim.readFromNBT(((Animation) animation).writeToNBT()); - if (this.animation != null && newAnim.frames.size() > 0) { + if (this.isActive() && !newAnim.frames.isEmpty()) { Frame frame = (Frame) this.animation.currentFrame(); if (frame != null) { Frame firstFrame = newAnim.frames.get(0); From 75dc7ed95ca88008f2c232eef5239bfee45ab3ca Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 19 Feb 2024 19:47:13 -0500 Subject: [PATCH 14/41] Tool Teleport Permissions --- .../noppes/npcs/CustomNpcsPermissions.java | 1 + .../java/noppes/npcs/NoppesUtilServer.java | 6 ++ .../npcs/client/PacketHandlerClient.java | 3 + .../npcs/constants/EnumPacketClient.java | 1 + .../noppes/npcs/items/ItemTeleporter.java | 84 ++++--------------- 5 files changed, 27 insertions(+), 68 deletions(-) diff --git a/src/main/java/noppes/npcs/CustomNpcsPermissions.java b/src/main/java/noppes/npcs/CustomNpcsPermissions.java index 124c747eb..071e63a51 100644 --- a/src/main/java/noppes/npcs/CustomNpcsPermissions.java +++ b/src/main/java/noppes/npcs/CustomNpcsPermissions.java @@ -57,6 +57,7 @@ public class CustomNpcsPermissions{ public static final Permission TOOL_SCRIPTER = new Permission("customnpcs.tool.scripter"); public static final Permission TOOL_CLONER = new Permission("customnpcs.tool.cloner"); public static final Permission TOOL_SCRIPTED_ITEM = new Permission("customnpcs.tool.scripteditem"); + public static final Permission TOOL_TELEPORTER = new Permission("customnpcs.tool.teleporter"); // Edit Villager public static final Permission EDIT_VILLAGER = new Permission("customnpcs.edit.villager"); diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index ab8f84363..80ecfeb7f 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -706,6 +706,12 @@ public class NoppesUtilServer { Server.sendData(player, EnumPacketClient.CLONER, x, y, z); } + public static void setTeleporterGUI(EntityPlayerMP player){ + if(player == null) + return; + Server.sendData(player, EnumPacketClient.TELEPORTER); + } + public static void setRecipeGui(EntityPlayerMP player, RecipeCarpentry recipe){ if(recipe == null) return; diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index 24f7f48d1..cf3d45d00 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -200,6 +200,9 @@ public class PacketHandlerClient extends PacketHandlerServer{ int y = buffer.readInt(); int z = buffer.readInt(); CustomNpcs.proxy.openGui(x, y, z, EnumGuiType.MobSpawner, player); + } + else if(type == EnumPacketClient.TELEPORTER){ + CustomNpcs.proxy.openGui((EntityNPCInterface)null,EnumGuiType.NpcDimensions); } else if(type == EnumPacketClient.GUI_DATA){ GuiScreen gui = Minecraft.getMinecraft().currentScreen; diff --git a/src/main/java/noppes/npcs/constants/EnumPacketClient.java b/src/main/java/noppes/npcs/constants/EnumPacketClient.java index 28abc0435..e070ce5ca 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketClient.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketClient.java @@ -34,6 +34,7 @@ public enum EnumPacketClient { SYNCRECIPES_CARPENTRYBENCH, CLONE, CLONER, + TELEPORTER, OPEN_BOOK, DIALOG_DUMMY, CONFIG, diff --git a/src/main/java/noppes/npcs/items/ItemTeleporter.java b/src/main/java/noppes/npcs/items/ItemTeleporter.java index 510a310ab..ac30fc2b2 100644 --- a/src/main/java/noppes/npcs/items/ItemTeleporter.java +++ b/src/main/java/noppes/npcs/items/ItemTeleporter.java @@ -7,6 +7,7 @@ import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; @@ -18,6 +19,8 @@ import net.minecraft.util.Vec3; import net.minecraft.world.World; import noppes.npcs.CustomItems; import noppes.npcs.CustomNpcs; +import noppes.npcs.CustomNpcsPermissions; +import noppes.npcs.NoppesUtilServer; import noppes.npcs.constants.EnumGuiType; import noppes.npcs.entity.EntityNPCInterface; @@ -25,7 +28,7 @@ import java.util.List; public class ItemTeleporter extends Item{ - + public ItemTeleporter(){ maxStackSize = 1; setCreativeTab(CustomItems.tab); @@ -33,9 +36,10 @@ public class ItemTeleporter extends Item{ @Override public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer){ - if(!par2World.isRemote) - return par1ItemStack; - CustomNpcs.proxy.openGui((EntityNPCInterface)null,EnumGuiType.NpcDimensions); + if(par2World.isRemote || !CustomNpcsPermissions.Instance.hasPermission(par3EntityPlayer, CustomNpcsPermissions.TOOL_TELEPORTER)) + return par1ItemStack; + + NoppesUtilServer.setTeleporterGUI((EntityPlayerMP) par3EntityPlayer); return par1ItemStack; } @@ -61,7 +65,7 @@ public class ItemTeleporter extends Item{ MovingObjectPosition movingobjectposition = par3EntityPlayer.worldObj.rayTraceBlocks(vec3, vec31, true); if (movingobjectposition == null) return false; - + Vec3 vec32 = par3EntityPlayer.getLook(f); boolean flag = false; float f9 = 1.0F; @@ -82,88 +86,32 @@ public class ItemTeleporter extends Item{ if (flag) return false; - + if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK){ int i = movingobjectposition.blockX; int j = movingobjectposition.blockY; int k = movingobjectposition.blockZ; - + while(par3EntityPlayer.worldObj.getBlock(i, j, k) != Blocks.air){ j++; } par3EntityPlayer.setPositionAndUpdate(i + 0.5F, j + 1.0F, k + 0.5F); } - - + + return true; } -// protected static MovingObjectPosition rayTraceBlocks(EntityPlayer entityPlayer, int radius) { -// Vec3 vec3 = Vec3.createVectorHelper(entityPlayer.posX, entityPlayer.height * 0.8 + entityPlayer.boundingBox.minY, entityPlayer.posZ); -// Vec3 vec3a = entityPlayer.getLookVec(); -// Vec3 vec3b = vec3.addVector(vec3a.xCoord * radius, vec3a.yCoord * radius, vec3a.zCoord * radius); -// -// return entityPlayer.worldObj.func_147447_a(vec3, vec3b, false, false, true); -// } -// -// protected static MovingObjectPosition getPointingEntity(EntityPlayer entityPlayer, int radius) { -// MovingObjectPosition block = rayTraceBlocks(entityPlayer, radius); -// Vec3 vec3 = Vec3.createVectorHelper(entityPlayer.posX, entityPlayer.height * 0.8 + entityPlayer.boundingBox.minY, entityPlayer.posZ); -// -// Vec3 vec31 = entityPlayer.getLookVec(); -// Vec3 vec32 = vec3.addVector(vec31.xCoord * radius, vec31.yCoord * radius, vec31.zCoord * radius); -// Vec3 vec33 = null; -// List entities = entityPlayer.worldObj.getEntitiesWithinAABBExcludingEntity(entityPlayer, entityPlayer.boundingBox.addCoord(vec31.xCoord * radius, vec31.yCoord * radius, vec31.zCoord * radius).expand(1.0D, 1.0D, 1.0D)); -// Entity pointedEntity = null; -// double d = radius; -// -// for (Entity entity : entities) { -// if (entity.canBeCollidedWith()) { -// float f = entity.getCollisionBorderSize(); -// AxisAlignedBB axisalignedbb = entity.boundingBox.expand((double)f, (double)f, (double)f); -// MovingObjectPosition movingObjectPosition = axisalignedbb.calculateIntercept(vec3, vec32); -// -// if (axisalignedbb.isVecInside(vec3)) { -// if (0.0D < radius || radius == 0.0D) { -// pointedEntity = entity; -// vec33 = movingObjectPosition == null ? vec3 : movingObjectPosition.hitVec; -// d = 0.0D; -// } -// } else if (movingObjectPosition != null) { -// double d2 = vec3.distanceTo(movingObjectPosition.hitVec); -// -// if (d2 < radius || radius == 0.0D) { -// if (entity == entityPlayer.ridingEntity && !entity.canRiderInteract()) { -// if (radius == 0.0D) { -// pointedEntity = entity; -// vec33 = movingObjectPosition.hitVec; -// } -// } else { -// pointedEntity = entity; -// vec33 = movingObjectPosition.hitVec; -// d = d2; -// } -// } -// } -// } -// } -// -// if (pointedEntity != null && (d < radius)) { -// return new MovingObjectPosition(pointedEntity, vec33); -// } -// -// return null; -// } - + @Override public int getColorFromItemStack(ItemStack par1ItemStack, int par2){ return 0x8B4513; } - + @Override public boolean requiresMultipleRenderPasses(){ return true; } - + @SideOnly(Side.CLIENT) @Override public void registerIcons(IIconRegister par1IconRegister){ From 2cc5e31dc78c593d1760589739c38bef4fd730c1 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 20 Feb 2024 00:39:51 -0500 Subject: [PATCH 15/41] Fix Dimension ID handling --- .../java/noppes/npcs/controllers/data/AnimationData.java | 2 +- src/main/java/noppes/npcs/entity/EntityNPCInterface.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/controllers/data/AnimationData.java b/src/main/java/noppes/npcs/controllers/data/AnimationData.java index 825e9d46f..e67fa4e01 100644 --- a/src/main/java/noppes/npcs/controllers/data/AnimationData.java +++ b/src/main/java/noppes/npcs/controllers/data/AnimationData.java @@ -55,7 +55,7 @@ public class AnimationData implements IAnimationData { float range = parent instanceof PlayerData ? 160 : 60; if (sendingEntity != null) { if(sendingEntity instanceof EntityNPCInterface && sendingEntity.dimension != sendingEntity.worldObj.provider.dimensionId) - sendingEntity.dimension = sendingEntity.worldObj.provider.dimensionId; + ((EntityNPCInterface) sendingEntity).fixDimensionID(); List entities = sendingEntity.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox( sendingEntity.posX - range, sendingEntity.posY - range, sendingEntity.posZ - range, diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index db10cca8c..5a1d80909 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -390,10 +390,17 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti public void updateClient() { NBTTagCompound compound = writeSpawnData(); compound.setInteger("EntityId", getEntityId()); + fixDimensionID(); Server.sendAssociatedData(this, EnumPacketClient.UPDATE_NPC, compound); updateClient = false; } + public void fixDimensionID(){ + if(worldObj == null || worldObj.provider == null || this.dimension == worldObj.provider.dimensionId) + return; + this.dimension = worldObj.provider.dimensionId; + } + @Override public boolean interact(EntityPlayer player) { From e044889b333b65f936c05819f3a79bffff4ef4e0 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 20 Feb 2024 00:43:00 -0500 Subject: [PATCH 16/41] Should already be fixed | Fix Unneeded --- .../java/noppes/npcs/controllers/data/AnimationData.java | 3 --- src/main/java/noppes/npcs/entity/EntityNPCInterface.java | 8 -------- 2 files changed, 11 deletions(-) diff --git a/src/main/java/noppes/npcs/controllers/data/AnimationData.java b/src/main/java/noppes/npcs/controllers/data/AnimationData.java index 70b8417bc..458f1d815 100644 --- a/src/main/java/noppes/npcs/controllers/data/AnimationData.java +++ b/src/main/java/noppes/npcs/controllers/data/AnimationData.java @@ -54,9 +54,6 @@ public class AnimationData implements IAnimationData { EntityLivingBase sendingEntity = parent instanceof PlayerData ? ((PlayerData) parent).player : parent instanceof DataDisplay ? ((DataDisplay) parent).npc : null; float range = parent instanceof PlayerData ? 160 : 60; if (sendingEntity != null) { - if(sendingEntity instanceof EntityNPCInterface && sendingEntity.dimension != sendingEntity.worldObj.provider.dimensionId) - ((EntityNPCInterface) sendingEntity).fixDimensionID(); - List entities = sendingEntity.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox( sendingEntity.posX - range, sendingEntity.posY - range, sendingEntity.posZ - range, sendingEntity.posX + range, sendingEntity.posY + range, sendingEntity.posZ + range)); diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 5a1d80909..a8826ef3d 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -390,18 +390,10 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti public void updateClient() { NBTTagCompound compound = writeSpawnData(); compound.setInteger("EntityId", getEntityId()); - fixDimensionID(); Server.sendAssociatedData(this, EnumPacketClient.UPDATE_NPC, compound); updateClient = false; } - public void fixDimensionID(){ - if(worldObj == null || worldObj.provider == null || this.dimension == worldObj.provider.dimensionId) - return; - this.dimension = worldObj.provider.dimensionId; - } - - @Override public boolean interact(EntityPlayer player) { if(worldObj.isRemote) From 32aca444434416981b51c1b2e1f2da102eafa6a8 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 20 Feb 2024 00:50:07 -0500 Subject: [PATCH 17/41] Fix Spawn when Summoner Dies and not Respawnable --- .../java/noppes/npcs/roles/JobSpawner.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/roles/JobSpawner.java b/src/main/java/noppes/npcs/roles/JobSpawner.java index e5cc0ac92..e5aca69e1 100644 --- a/src/main/java/noppes/npcs/roles/JobSpawner.java +++ b/src/main/java/noppes/npcs/roles/JobSpawner.java @@ -321,9 +321,25 @@ public class JobSpawner extends JobInterface{ target = null; checkSpawns(); } - @Override + + @Override + public void delete() { + if(spawnType == 3 && npc.stats.spawnCycle == 3){ + spawnEntity(compound1); + spawnEntity(compound2); + spawnEntity(compound3); + spawnEntity(compound4); + spawnEntity(compound5); + spawnEntity(compound6); + number = 6; + } + reset(); + } + + + @Override public void killed() { - if(spawnType == 3){ + if(spawnType == 3 && npc.stats.spawnCycle != 3){ spawnEntity(compound1); spawnEntity(compound2); spawnEntity(compound3); From 69185de3f3174b6e9c5f5028526974c88806972d Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 20 Feb 2024 01:17:51 -0500 Subject: [PATCH 18/41] Fix Quest Type Dialog Selection --- .../client/gui/GuiNPCDialogSelection.java | 11 ++++----- .../gui/questtypes/GuiNpcQuestTypeDialog.java | 24 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/GuiNPCDialogSelection.java b/src/main/java/noppes/npcs/client/gui/GuiNPCDialogSelection.java index 790d0b535..ad743701b 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNPCDialogSelection.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNPCDialogSelection.java @@ -26,15 +26,15 @@ public class GuiNPCDialogSelection extends GuiNPCInterface implements IScrollDat title = "Select Dialog Category"; this.parent = parent; this.dialog = dialog; - - + + if(dialog >= 0){ Client.sendData(EnumPacketServer.DialogsGetFromDialog, dialog); selectCategory = false; title = "Select Dialog"; }else Client.sendData(EnumPacketServer.DialogCategoriesGet, dialog); - + if(parent instanceof GuiSelectionListener){ listener = (GuiSelectionListener) parent; } @@ -48,7 +48,6 @@ public class GuiNPCDialogSelection extends GuiNPCInterface implements IScrollDat slot = new GuiNPCStringSlot(list,this,false,18); slot.registerScrollButtons(4, 5); - this.addButton(new GuiNpcButton(2, width / 2 -100, height - 41,98, 20, "gui.back")); this.addButton(new GuiNpcButton(4, width / 2 + 2, height - 41,98, 20, "gui.select")); } @@ -92,7 +91,7 @@ public class GuiNPCDialogSelection extends GuiNPCInterface implements IScrollDat close(); NoppesUtil.openGUI(player, parent); } - + } public void save() { if(dialog >= 0){ @@ -113,7 +112,7 @@ public class GuiNPCDialogSelection extends GuiNPCInterface implements IScrollDat @Override public void setSelected(String selected) { - + } diff --git a/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeDialog.java b/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeDialog.java index e2001ef10..78e8f1406 100644 --- a/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeDialog.java +++ b/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeDialog.java @@ -20,25 +20,24 @@ import java.util.HashMap; public class GuiNpcQuestTypeDialog extends SubGuiInterface implements GuiSelectionListener, IGuiData { private GuiScreen parent; - private QuestDialog quest; - + private HashMap data = new HashMap(); public GuiNpcQuestTypeDialog(EntityNPCInterface npc, Quest q, GuiScreen parent) { this.npc = npc; this.parent = parent; title = "Quest Dialog Setup"; - + quest = (QuestDialog) q.questInterface; setBackground("menubg.png"); xSize = 256; ySize = 216; closeOnEsc = true; - Client.sendData(EnumPacketServer.QuestDialogGetTitle, - quest.dialogs.containsKey(0)?quest.dialogs.get(0):-1, - quest.dialogs.containsKey(1)?quest.dialogs.get(1):-1, + Client.sendData(EnumPacketServer.QuestDialogGetTitle, + quest.dialogs.containsKey(0)?quest.dialogs.get(0):-1, + quest.dialogs.containsKey(1)?quest.dialogs.get(1):-1, quest.dialogs.containsKey(2)?quest.dialogs.get(2):-1); } @@ -48,12 +47,12 @@ public class GuiNpcQuestTypeDialog extends SubGuiInterface implements GuiSelecti String title = "dialog.selectoption"; if(data.containsKey(i)) title = data.get(i); - this.addButton(new GuiNpcButton(i + 9, guiLeft + 10, 55 + i * 22, 20, 20, "X")); - this.addButton(new GuiNpcButton(i + 3, guiLeft + 34, 55 + i * 22, 210, 20, title)); + this.addButton(new GuiNpcButton(i + 9, guiLeft + 10, guiTop + 55 + i * 22, 20, 20, "X")); + this.addButton(new GuiNpcButton(i + 3, guiLeft + 34, guiTop + 55 + i * 22, 210, 20, title)); } this.addButton(new GuiNpcButton(0, guiLeft + 150, guiTop + 190, 98, 20, "gui.back")); - + } private int selectedSlot; @@ -67,9 +66,10 @@ public class GuiNpcQuestTypeDialog extends SubGuiInterface implements GuiSelecti int id = -1; if(quest.dialogs.containsKey(selectedSlot)) id = quest.dialogs.get(selectedSlot); - GuiNPCDialogSelection gui = new GuiNPCDialogSelection(npc, parent, id); - gui.listener = this; - NoppesUtil.openGUI(player, gui); + + GuiNPCDialogSelection gui = new GuiNPCDialogSelection(npc, getParent(), id); + gui.listener = this; + NoppesUtil.openGUI(player, gui); } if (button.id >= 9 && button.id < 15) { int slot = button.id - 9; From 3e487739403f8206fb31817e2507b7e478df50c2 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 20 Feb 2024 02:07:38 -0500 Subject: [PATCH 19/41] Convert Market to Dat File Command / Config Support Faster Loading Speeds for LARGE Markets --- src/main/java/foxz/utils/Market.java | 212 +++++++++++++++--- .../java/kamkeel/command/ConfigCommand.java | 63 +++++- .../java/noppes/npcs/PacketHandlerServer.java | 1 - .../java/noppes/npcs/config/ConfigMain.java | 9 +- .../controllers/PlayerDataController.java | 2 +- 5 files changed, 248 insertions(+), 39 deletions(-) diff --git a/src/main/java/foxz/utils/Market.java b/src/main/java/foxz/utils/Market.java index 737ab02fc..79e05ed1e 100644 --- a/src/main/java/foxz/utils/Market.java +++ b/src/main/java/foxz/utils/Market.java @@ -1,58 +1,214 @@ package foxz.utils; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ChatComponentText; import noppes.npcs.CustomNpcs; +import noppes.npcs.LogWriter; +import noppes.npcs.config.ConfigMain; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleTrader; import noppes.npcs.util.NBTJsonUtil; import java.io.File; +import java.io.FileOutputStream; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import static noppes.npcs.controllers.PlayerDataController.loadNBTData; public class Market { static public void save(RoleTrader r, String name) { - if(name.isEmpty()) - return; - File file = getFile(name + "_new"); - File file1 = getFile(name); + if(name.isEmpty()) + return; + File file = getFile(name + "_new"); + File file1 = getFile(name); try { - NBTJsonUtil.SaveFile(file, r.writeNBT(new NBTTagCompound())); - if(file1.exists()){ - file1.delete(); - } - file.renameTo(file1); - } catch (Exception e) { + if(ConfigMain.MarketDatFormat){ + CompressedStreamTools.writeCompressed(r.writeNBT(new NBTTagCompound()), new FileOutputStream(file)); + } else { + NBTJsonUtil.SaveFile(file, r.writeNBT(new NBTTagCompound())); + } + if(file1.exists()){ + file1.delete(); + } + file.renameTo(file1); + } catch (Exception e) { - } + } } static public void load(RoleTrader role, String name){ - if(role.npc.worldObj.isRemote) - return; - File file = getFile(name); - if(!file.exists()) - return; + if(role.npc.worldObj.isRemote) + return; + File file = getFile(name); + if(!file.exists()) + return; - try { - role.readNBT(NBTJsonUtil.LoadFile(file)); - } catch (Exception e) { - } + try { + if(ConfigMain.MarketDatFormat){ + NBTTagCompound compound = loadNBTData(file); + role.readNBT(compound); + } + else { + role.readNBT(NBTJsonUtil.LoadFile(file)); + } + } catch (Exception e) { + } } + + public static File getMarketDir(){ + try{ + File file = new File(CustomNpcs.getWorldSaveDirectory(),"markets"); + if(!file.exists()) + file.mkdir(); + return file; + } + catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public File getNewMarketDir(){ + try{ + File file = new File(CustomNpcs.getWorldSaveDirectory(),"markets_new"); + if(file.exists()){ + return null; + } + file.mkdir(); + return file; + } + catch (Exception e) { + e.printStackTrace(); + return null; + } + } + private static File getFile(String name){ - File dir = new File(CustomNpcs.getWorldSaveDirectory(), "markets"); - if(!dir.exists()) - dir.mkdir(); - return new File(dir, name.toLowerCase() + ".json"); + String filename = name.toLowerCase(); + if(ConfigMain.MarketDatFormat){ + filename += ".dat"; + } else { + filename += ".json"; + } + + return new File(getMarketDir(), filename); } static public void setMarket(EntityNPCInterface npc, String marketName) { - if(marketName.isEmpty()) - return; - if(!getFile(marketName).exists()) - Market.save((RoleTrader) npc.roleInterface, marketName); + if(marketName.isEmpty()) + return; + if(!getFile(marketName).exists()) + Market.save((RoleTrader) npc.roleInterface, marketName); Market.load((RoleTrader) npc.roleInterface, marketName); } + + + public void convertMarketFiles(final EntityPlayerMP sender, final boolean type){ + ExecutorService executor = Executors.newSingleThreadExecutor(); + executor.execute(() -> { + String fileType; + if(type){ + fileType = ".dat"; + } + else { + fileType = ".json"; + } + + if(sender != null){ + LogWriter.info("Market Conversion queued by " + sender.getCommandSenderName()); + sender.addChatMessage(new ChatComponentText("Market Conversion to " + fileType + " format")); + } + + File dir = getMarketDir(); + LogWriter.info("Converting Market to " + fileType + " format"); + File[] files = dir.listFiles(); // Get an array of all files in the directory + if(files != null){ + int length = files.length; + if(length != 0){ + if(length > 100){ + LogWriter.info("Found " + length + " Market files... This may take a few minutes"); + } + int tenPercent = (int) ((double) length * 0.1); + int progress = 0; + File saveDir = getNewMarketDir(); + if(saveDir == null){ + if(sender != null){ + sender.addChatMessage(new ChatComponentText("markets_new folder already exists please delete it or rename it")); + } + LogWriter.error("markets_new folder already exists please delete it or rename it"); + return; + } + // Load the files in parallel using a stream + for(int i = 0; i < length; i++){ + File file = files[i]; + if(file.isDirectory() || (!file.getName().endsWith(".json") && !file.getName().endsWith(".dat"))) + continue; + try { + String filename = "error"; + boolean valid = false; + NBTTagCompound compound = new NBTTagCompound(); + if(type){ + if(file.getName().endsWith(".json")){ + compound = NBTJsonUtil.LoadFile(file); + if(compound.hasKey("PlayerName")) { + filename = file.getName().substring(0, file.getName().length() - 5); + valid = true; + } + } + } else { + if(file.getName().endsWith(".dat")){ + compound = loadNBTData(file); + if(compound.hasKey("PlayerName")){ + filename = file.getName().substring(0, file.getName().length() - 4); + valid = true; + } + } + } + if(valid){ + try { + File newFile = new File(saveDir, filename + "_new" + fileType); + File oldFile = new File(saveDir, filename + fileType); + if(type){ + CompressedStreamTools.writeCompressed(compound, new FileOutputStream(newFile)); + } else { + NBTJsonUtil.SaveFile(newFile, compound); + } + if(oldFile.exists()){ + oldFile.delete(); + } + newFile.renameTo(oldFile); + } catch (Exception e) { + LogWriter.except(e); + } + } + } catch (Exception e) { + LogWriter.error("Error loading: " + file.getAbsolutePath(), e); + } + if(tenPercent != 0 ){ + if(progress != 100){ + if (i % tenPercent == 0) { + progress += 10; + LogWriter.info("Converting Market: Progress: " + progress + "%"); + } + } + } + } + } + } + if(sender != null){ + sender.addChatMessage(new ChatComponentText("Market Conversion complete")); + } + LogWriter.info("Market Converted - Please rename the markets_new folder to markets and restart"); + }); + + executor.shutdown(); + } + } diff --git a/src/main/java/kamkeel/command/ConfigCommand.java b/src/main/java/kamkeel/command/ConfigCommand.java index b8d239904..5375afa9b 100644 --- a/src/main/java/kamkeel/command/ConfigCommand.java +++ b/src/main/java/kamkeel/command/ConfigCommand.java @@ -30,7 +30,7 @@ public class ConfigCommand extends CommandKamkeelBase { public String getDescription() { return "Some config things you can set"; } - + @SubCommand( desc = "Disable/Enable the natural leaves decay", usage = "[true/false]", @@ -56,7 +56,7 @@ public class ConfigCommand extends CommandKamkeelBase { sendResult(sender, "LeavesDecay is now \u00A7c" + ConfigMain.LeavesDecayEnabled); } } - + @SubCommand( desc = "Disable/Enable the vines growing", usage = "[true/false]", @@ -82,7 +82,7 @@ public class ConfigCommand extends CommandKamkeelBase { sendResult(sender, "VineGrowth is now \u00A7c" + ConfigMain.VineGrowthEnabled); } } - + @SubCommand( desc = "Disable/Enable the ice melting", usage = "[true/false]", @@ -127,7 +127,7 @@ public class ConfigCommand extends CommandKamkeelBase { sendResult(sender, "GunsEnabled is now \u00A7c" + ConfigMain.GunsEnabled); } } - + @SubCommand( desc = "Freezes/Unfreezes npcs", usage = "[true/false]", @@ -142,7 +142,7 @@ public class ConfigCommand extends CommandKamkeelBase { sendResult(sender, "FrozenNPCs is now \u00A7c" + CustomNpcs.FreezeNPCs); } } - + @SubCommand( desc = "Set number of active chunkloaders", usage = "", @@ -220,7 +220,54 @@ public class ConfigCommand extends CommandKamkeelBase { PlayerDataController.Instance.convertPlayerFiles(send, convertToDat); } } - + + @SubCommand( + desc = "Generate Market to JSON/DAT", + usage = "[fileType] [convert]", + permission = 4 + ) + public void market(ICommandSender sender, String[] args) throws CommandException{ + String fileType; + if(ConfigMain.MarketDatFormat){ + fileType = "DAT"; + } + else { + fileType = "JSON"; + } + if(args.length == 0){ + sendResult(sender, "Market Filetype: \u00A7c" + fileType); + } + else if(args.length == 1){ + sendResult(sender, "Please write the word 'convert' at the end to confirm. \u00A7c convert"); + } + else{ + if(args.length != 2){ + sendError(sender, "Two many arguments"); + return; + } + String formatType = args[0].toLowerCase(); + if(!formatType.equals("dat") && !formatType.equals("json")){ + sendError(sender, "Invalid Format Type - Please use dat or json"); + return; + } + + String convert = args[1].toLowerCase(); + if(!convert.equals("convert")){ + sendError(sender, "Please enter the word 'convert' at the end"); + return; + } + + boolean convertToDat = formatType.equals("dat"); + EntityPlayerMP send = null; + if(sender instanceof EntityPlayerMP){ + send = (EntityPlayerMP) sender; + } + + sendResult(sender, "Started Conversion Process for Market"); + PlayerDataController.Instance.convertPlayerFiles(send, convertToDat); + } + } + @SubCommand( desc = "Get/Set font", usage = "[type] [size]", @@ -236,7 +283,7 @@ public class ConfigCommand extends CommandKamkeelBase { args = Arrays.copyOfRange(args, 0, args.length - 1); } catch(Exception e){ - + } } String font = ""; @@ -245,6 +292,6 @@ public class ConfigCommand extends CommandKamkeelBase { } Server.sendData((EntityPlayerMP)sender, EnumPacketClient.CONFIG, 0, font.trim(), size); } - + } diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 7b922dee2..fad1036f8 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -1100,7 +1100,6 @@ public class PacketHandlerServer{ Market.setMarket(npc, market); else Market.save((RoleTrader)npc.roleInterface, market); - //NoppesUtilServer.sendRoleData(player, npc); } } else if(type == EnumPacketServer.AnimationsGet){ diff --git a/src/main/java/noppes/npcs/config/ConfigMain.java b/src/main/java/noppes/npcs/config/ConfigMain.java index fc6efcf8d..f7e10f428 100644 --- a/src/main/java/noppes/npcs/config/ConfigMain.java +++ b/src/main/java/noppes/npcs/config/ConfigMain.java @@ -63,6 +63,10 @@ public class ConfigMain public static Property DatFormatProperty; public static boolean DatFormat = false; + public static Property MarketDatFormatProperty; + public static boolean MarketDatFormat = false; + + public static Property DefaultMaxPartySizetProperty; public static int DefaultMaxPartySize = 4; @@ -152,6 +156,9 @@ public class ConfigMain DatFormatProperty = config.get(GENERAL, "Dat Format for PlayerData", false, "You need to use '/kamkeel config playerdata' to convert existing playerdata to new format."); DatFormat = DatFormatProperty.getBoolean(false); + MarketDatFormatProperty = config.get(GENERAL, "Dat Format for Market", false, "You need to use '/kamkeel config market' to convert existing market to new format."); + MarketDatFormat = MarketDatFormatProperty.getBoolean(false); + DefaultMaxPartySizetProperty = config.get(GENERAL, "Default Max Party Size", 4, "When creating a new Quest sets the default max party size"); DefaultMaxPartySize = DefaultMaxPartySizetProperty.getInt(4); @@ -280,4 +287,4 @@ public class ConfigMain } } } -} \ No newline at end of file +} diff --git a/src/main/java/noppes/npcs/controllers/PlayerDataController.java b/src/main/java/noppes/npcs/controllers/PlayerDataController.java index b3a0f3a7f..aaac92b25 100644 --- a/src/main/java/noppes/npcs/controllers/PlayerDataController.java +++ b/src/main/java/noppes/npcs/controllers/PlayerDataController.java @@ -242,7 +242,7 @@ public class PlayerDataController { return new NBTTagCompound(); } - public NBTTagCompound loadNBTData(File file){ + public static NBTTagCompound loadNBTData(File file){ try { return CompressedStreamTools.readCompressed(new FileInputStream(file)); } catch (Exception e) { From 444703b3f2b5fe212f60d04c5dbafe94c827f3b1 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 20 Feb 2024 02:08:46 -0500 Subject: [PATCH 20/41] Fix Market Config Command --- src/main/java/foxz/utils/Market.java | 4 ++-- src/main/java/kamkeel/command/ConfigCommand.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/foxz/utils/Market.java b/src/main/java/foxz/utils/Market.java index 79e05ed1e..60b345eb9 100644 --- a/src/main/java/foxz/utils/Market.java +++ b/src/main/java/foxz/utils/Market.java @@ -74,7 +74,7 @@ public class Market { } } - public File getNewMarketDir(){ + public static File getNewMarketDir(){ try{ File file = new File(CustomNpcs.getWorldSaveDirectory(),"markets_new"); if(file.exists()){ @@ -110,7 +110,7 @@ public class Market { } - public void convertMarketFiles(final EntityPlayerMP sender, final boolean type){ + public static void convertMarketFiles(final EntityPlayerMP sender, final boolean type){ ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(() -> { String fileType; diff --git a/src/main/java/kamkeel/command/ConfigCommand.java b/src/main/java/kamkeel/command/ConfigCommand.java index 5375afa9b..4be014417 100644 --- a/src/main/java/kamkeel/command/ConfigCommand.java +++ b/src/main/java/kamkeel/command/ConfigCommand.java @@ -1,5 +1,6 @@ package kamkeel.command; +import foxz.utils.Market; import net.minecraft.block.Block; import net.minecraft.block.BlockIce; import net.minecraft.block.BlockLeavesBase; @@ -264,7 +265,7 @@ public class ConfigCommand extends CommandKamkeelBase { } sendResult(sender, "Started Conversion Process for Market"); - PlayerDataController.Instance.convertPlayerFiles(send, convertToDat); + Market.convertMarketFiles(send, convertToDat); } } From 4f69da059414d508781194dc1045ba676eff59ae Mon Sep 17 00:00:00 2001 From: luisc Date: Tue, 20 Feb 2024 16:24:06 -0600 Subject: [PATCH 21/41] Fixed null pointer exception crash when clicking around top tabs in creative. --- .../client/tabs/InventoryTabVanilla.java | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/main/java/tconstruct/client/tabs/InventoryTabVanilla.java b/src/main/java/tconstruct/client/tabs/InventoryTabVanilla.java index d5c52e8c5..8378c936c 100644 --- a/src/main/java/tconstruct/client/tabs/InventoryTabVanilla.java +++ b/src/main/java/tconstruct/client/tabs/InventoryTabVanilla.java @@ -10,22 +10,11 @@ public class InventoryTabVanilla extends AbstractTab { @Override public void onTabClicked() { - Thread t = new Thread(){ - @Override - public void run(){ - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - TabRegistry.openInventoryGui(); - } - }; - t.start(); + TabRegistry.openInventoryGui(); } @Override public boolean shouldAddToList() { return true; } -} \ No newline at end of file +} From 3507cb85c5960682ce522dc9a2637ccf77e2fff7 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 20 Feb 2024 20:29:49 -0500 Subject: [PATCH 22/41] Multithread Market Saving + Record History for Markets --- src/main/java/foxz/utils/Market.java | 72 +++++++++++++++---- .../java/noppes/npcs/PacketHandlerServer.java | 2 + .../client/gui/roles/GuiNpcTraderSetup.java | 22 +++--- .../controllers/PlayerDataController.java | 23 ++---- .../npcs/controllers/data/PlayerData.java | 2 +- .../java/noppes/npcs/roles/RoleTrader.java | 49 +++++++------ .../npcs/scripted/roles/ScriptRoleTrader.java | 6 +- .../java/noppes/npcs/util/CacheHashMap.java | 29 +++++++- .../noppes/npcs/util/CustomNPCsThreader.java | 3 +- .../noppes/npcs/util/MarketCachedObject.java | 15 ++++ .../java/noppes/npcs/util/NBTJsonUtil.java | 18 +++-- src/main/resources/META-INF/customnpcs_at.cfg | 4 ++ .../assets/customnpcs/lang/en_US.lang | 1 + 13 files changed, 172 insertions(+), 74 deletions(-) create mode 100644 src/main/java/noppes/npcs/util/MarketCachedObject.java diff --git a/src/main/java/foxz/utils/Market.java b/src/main/java/foxz/utils/Market.java index 60b345eb9..461cc9a1c 100644 --- a/src/main/java/foxz/utils/Market.java +++ b/src/main/java/foxz/utils/Market.java @@ -9,6 +9,8 @@ import noppes.npcs.LogWriter; import noppes.npcs.config.ConfigMain; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleTrader; +import noppes.npcs.util.CacheHashMap; +import noppes.npcs.util.MarketCachedObject; import noppes.npcs.util.NBTJsonUtil; import java.io.File; @@ -16,28 +18,68 @@ import java.io.FileOutputStream; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import static noppes.npcs.controllers.PlayerDataController.loadNBTData; +import static noppes.npcs.util.CustomNPCsThreader.customNPCThread; public class Market { - static public void save(RoleTrader r, String name) { + private static final CacheHashMap marketCache = new CacheHashMap<>(5 * 60 * 1000, 1 * 60 * 1000); + + public static void save(RoleTrader r, String name) { if(name.isEmpty()) return; + + NBTTagCompound roleCompound = r.writeNBT(new NBTTagCompound()); + roleCompound.setString("SaveName", name); + putMarketCache(name, roleCompound); + if(r.recordHistory) + return; + + saveFile(roleCompound); + } + + public static void saveFile(NBTTagCompound compound) { + String name = compound.getString("SaveName"); File file = getFile(name + "_new"); File file1 = getFile(name); + customNPCThread.execute(() -> { + try { + if(ConfigMain.MarketDatFormat){ + CompressedStreamTools.writeCompressed(compound, new FileOutputStream(file)); + } else { + NBTJsonUtil.SaveFile(file, compound); + } + if(file1.exists()){ + file1.delete(); + } + file.renameTo(file1); + } catch (Exception e) { - try { - if(ConfigMain.MarketDatFormat){ - CompressedStreamTools.writeCompressed(r.writeNBT(new NBTTagCompound()), new FileOutputStream(file)); - } else { - NBTJsonUtil.SaveFile(file, r.writeNBT(new NBTTagCompound())); } - if(file1.exists()){ - file1.delete(); - } - file.renameTo(file1); - } catch (Exception e) { + }); + } + public static void getMarket(RoleTrader role, String name){ + NBTTagCompound data = getMarketCache(name); + if(data != null){ + role.readNBT(data); + return; + } + + load(role, name); + } + + public static NBTTagCompound getMarketCache(final String name) { + synchronized (marketCache) { + if (!marketCache.containsKey(name)) { + return null; + } + return marketCache.get(name).getObject(); + } + } + + public static void putMarketCache(final String name, final NBTTagCompound role) { + synchronized (marketCache) { + marketCache.put(name, new MarketCachedObject(role)); } } @@ -51,7 +93,7 @@ public class Market { try { if(ConfigMain.MarketDatFormat){ - NBTTagCompound compound = loadNBTData(file); + NBTTagCompound compound = NBTJsonUtil.loadNBTData(file); role.readNBT(compound); } else { @@ -106,7 +148,7 @@ public class Market { if(!getFile(marketName).exists()) Market.save((RoleTrader) npc.roleInterface, marketName); - Market.load((RoleTrader) npc.roleInterface, marketName); + Market.getMarket((RoleTrader) npc.roleInterface, marketName); } @@ -164,7 +206,7 @@ public class Market { } } else { if(file.getName().endsWith(".dat")){ - compound = loadNBTData(file); + compound = NBTJsonUtil.loadNBTData(file); if(compound.hasKey("PlayerName")){ filename = file.getName().substring(0, file.getName().length() - 4); valid = true; diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index fad1036f8..937a42f7a 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -1094,6 +1094,8 @@ public class PacketHandlerServer{ } else if(type == EnumPacketServer.TraderMarketSave){ String market = Server.readString(buffer); + if(market == null) + return; boolean bo = buffer.readBoolean(); if(npc.roleInterface instanceof RoleTrader){ if(bo) diff --git a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcTraderSetup.java b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcTraderSetup.java index 812a7721f..067699b70 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcTraderSetup.java +++ b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcTraderSetup.java @@ -14,17 +14,17 @@ import noppes.npcs.roles.RoleTrader; import org.lwjgl.opengl.GL11; public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITextfieldListener{ - + private final ResourceLocation slot = new ResourceLocation("customnpcs","textures/gui/slot.png"); private RoleTrader role; - + public GuiNpcTraderSetup(EntityNPCInterface npc, ContainerNPCTraderSetup container){ super(npc, container); ySize = 220; menuYOffset = 10; role = container.role; } - + @Override public void initGui(){ super.initGui(); @@ -35,9 +35,12 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex addLabel(new GuiNpcLabel(1, "gui.ignoreDamage", guiLeft + 260, guiTop + 29)); addButton(new GuiNpcButtonYesNo(1, guiLeft + 340, guiTop + 24, role.ignoreDamage)); - + addLabel(new GuiNpcLabel(2, "gui.ignoreNBT", guiLeft + 260, guiTop + 51)); addButton(new GuiNpcButtonYesNo(2, guiLeft + 340, guiTop + 46, role.ignoreNBT)); + + addLabel(new GuiNpcLabel(3, "gui.recordHistory", guiLeft + 260, guiTop + 73)); + addButton(new GuiNpcButtonYesNo(3, guiLeft + 340, guiTop + 68, role.recordHistory)); } @Override @@ -55,6 +58,9 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex if(guibutton.id == 2){ role.ignoreNBT = ((GuiNpcButtonYesNo)guibutton).getBoolean(); } + if(guibutton.id == 3){ + role.recordHistory = ((GuiNpcButtonYesNo)guibutton).getBoolean(); + } } @Override @@ -69,20 +75,20 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex GL11.glColor4f(1, 1, 1, 1); drawTexturedModalRect(x - 1, y, 0, 0, 18, 18); drawTexturedModalRect(x + 17, y, 0, 0, 18, 18); - + fontRendererObj.drawString("=", x + 36, y + 5, CustomNpcResourceListener.DefaultTextColor); mc.renderEngine.bindTexture(this.slot); GL11.glColor4f(1, 1, 1, 1); drawTexturedModalRect(x + 42, y, 0, 0, 18, 18); } } - + @Override public void save() { Client.sendData(EnumPacketServer.TraderMarketSave, role.marketName, false); Client.sendData(EnumPacketServer.RoleSave, role.writeToNBT(new NBTTagCompound())); } - + @Override public void unFocused(GuiNpcTextField guiNpcTextField) { String name = guiNpcTextField.getText(); @@ -90,6 +96,6 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex role.marketName = name; Client.sendData(EnumPacketServer.TraderMarketSave, role.marketName, true); } - + } } diff --git a/src/main/java/noppes/npcs/controllers/PlayerDataController.java b/src/main/java/noppes/npcs/controllers/PlayerDataController.java index aaac92b25..05708cdd5 100644 --- a/src/main/java/noppes/npcs/controllers/PlayerDataController.java +++ b/src/main/java/noppes/npcs/controllers/PlayerDataController.java @@ -28,7 +28,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.zip.GZIPInputStream; -import static noppes.npcs.util.CustomNPCsThreader.playerDataThread; +import static noppes.npcs.util.CustomNPCsThreader.customNPCThread; public class PlayerDataController { public static PlayerDataController Instance; @@ -66,7 +66,7 @@ public class PlayerDataController { } } if(file.getName().endsWith(".dat")){ - NBTTagCompound compound = loadNBTData(file); + NBTTagCompound compound = NBTJsonUtil.loadNBTData(file); if(compound.hasKey("PlayerName")){ map.put(compound.getString("PlayerName"), file.getName().substring(0, file.getName().length() - 4)); } @@ -128,7 +128,7 @@ public class PlayerDataController { } public synchronized void savePlayerDataMap(){ - playerDataThread.execute(() -> { + customNPCThread.execute(() -> { try { File saveDir = CustomNpcs.getWorldSaveDirectory(); File file = new File(saveDir, "playerdatamap.dat_new"); @@ -230,7 +230,7 @@ public class PlayerDataController { File file = new File(saveDir, filename); if(file.exists()){ if(ConfigMain.DatFormat){ - return loadNBTData(file); + return NBTJsonUtil.loadNBTData(file); } else { return NBTJsonUtil.LoadFile(file); } @@ -242,16 +242,7 @@ public class PlayerDataController { return new NBTTagCompound(); } - public static NBTTagCompound loadNBTData(File file){ - try { - return CompressedStreamTools.readCompressed(new FileInputStream(file)); - } catch (Exception e) { - LogWriter.error("Error loading: " + file.getName(), e); - } - return new NBTTagCompound(); - } - - public void putPlayerDataCache(final String uuid, final PlayerData playerCompound) { + public void putPlayerDataCache(final String uuid, final PlayerData playerCompound) { synchronized (playerDataCache) { playerDataCache.put(uuid, new CacheHashMap.CachedObject<>(playerCompound)); } @@ -453,7 +444,7 @@ public class PlayerDataController { } } if(file.getName().endsWith(".dat")){ - NBTTagCompound compound = loadNBTData(file); + NBTTagCompound compound = NBTJsonUtil.loadNBTData(file); if(compound.hasKey("PlayerName")){ map.put(compound.getString("PlayerName"), file.getName().substring(0, file.getName().length() - 4)); } @@ -536,7 +527,7 @@ public class PlayerDataController { } } else { if(file.getName().endsWith(".dat")){ - compound = loadNBTData(file); + compound = NBTJsonUtil.loadNBTData(file); if(compound.hasKey("PlayerName")){ filename = file.getName().substring(0, file.getName().length() - 4); valid = true; diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerData.java b/src/main/java/noppes/npcs/controllers/data/PlayerData.java index 593bd89be..4b12a1507 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerData.java @@ -277,7 +277,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData { } PlayerDataController.Instance.putPlayerMap(playername, uuid); PlayerDataController.Instance.putPlayerDataCache(uuid, this); - CustomNPCsThreader.playerDataThread.execute(() -> { + CustomNPCsThreader.customNPCThread.execute(() -> { try { File saveDir = PlayerDataController.Instance.getSaveDir(); File file = new File(saveDir, filename + "_new"); diff --git a/src/main/java/noppes/npcs/roles/RoleTrader.java b/src/main/java/noppes/npcs/roles/RoleTrader.java index f6406a6e8..fa5ae40bc 100644 --- a/src/main/java/noppes/npcs/roles/RoleTrader.java +++ b/src/main/java/noppes/npcs/roles/RoleTrader.java @@ -15,7 +15,7 @@ import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; -public class RoleTrader extends RoleInterface{ +public class RoleTrader extends RoleInterface { public String marketName = ""; public NpcMiscInventory inventoryCurrency; @@ -23,14 +23,13 @@ public class RoleTrader extends RoleInterface{ public boolean ignoreDamage = false; public boolean ignoreNBT = false; - - public boolean toSave = false; - + public boolean recordHistory = false; + public int[] purchases; public int[] disableSlot; public HashMap playerPurchases; public HashMap playerDisableSlot; - + public RoleTrader(EntityNPCInterface npc) { super(npc); inventoryCurrency = new NpcMiscInventory(36); @@ -45,10 +44,6 @@ public class RoleTrader extends RoleInterface{ public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) { nbttagcompound.setString("TraderMarket", marketName); writeNBT(nbttagcompound); - if (toSave && !npc.isRemote()) { - Market.save(this, marketName); - } - toSave = false; return nbttagcompound; } @@ -57,10 +52,13 @@ public class RoleTrader extends RoleInterface{ nbttagcompound.setTag("TraderSold", inventorySold.getToNBT()); nbttagcompound.setBoolean("TraderIgnoreDamage", ignoreDamage); nbttagcompound.setBoolean("TraderIgnoreNBT", ignoreNBT); - nbttagcompound.setIntArray("Purchases", purchases); + nbttagcompound.setBoolean("RecordHistory", recordHistory); nbttagcompound.setIntArray("DisableSlot", disableSlot); - nbttagcompound.setTag("PlayerPurchases", NBTTags.nbtStringIntegerArrayMap(playerPurchases)); nbttagcompound.setTag("PlayerDisableSlot", NBTTags.nbtStringIntegerArrayMap(playerDisableSlot)); + if(recordHistory){ + nbttagcompound.setIntArray("Purchases", purchases); + nbttagcompound.setTag("PlayerPurchases", NBTTags.nbtStringIntegerArrayMap(playerPurchases)); + } return nbttagcompound; } @@ -68,12 +66,11 @@ public class RoleTrader extends RoleInterface{ public void readFromNBT(NBTTagCompound nbttagcompound) { marketName = nbttagcompound.getString("TraderMarket"); readNBT(nbttagcompound); - + try { - Market.load(this, marketName); + Market.getMarket(this, marketName); } catch (Exception ex) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); - } } @@ -82,25 +79,28 @@ public class RoleTrader extends RoleInterface{ inventorySold.setFromNBT(nbttagcompound.getCompoundTag("TraderSold")); ignoreDamage = nbttagcompound.getBoolean("TraderIgnoreDamage"); ignoreNBT = nbttagcompound.getBoolean("TraderIgnoreNBT"); - purchases = nbttagcompound.getIntArray("Purchases"); + recordHistory = nbttagcompound.getBoolean("RecordHistory"); + disableSlot = nbttagcompound.getIntArray("DisableSlot"); + playerDisableSlot = NBTTags.getStringIntegerArrayMap(nbttagcompound.getTagList("PlayerDisableSlot", 10), 18); + if(recordHistory){ + purchases = nbttagcompound.getIntArray("Purchases"); + playerPurchases = NBTTags.getStringIntegerArrayMap(nbttagcompound.getTagList("PlayerPurchases", 10), 18); + } if (purchases == null || purchases.length != 18) { purchases = new int[18]; for (int i = 0; i < purchases.length; ++i) purchases[i] = 0; } - disableSlot = nbttagcompound.getIntArray("DisableSlot"); if (disableSlot == null || disableSlot.length != 18) { disableSlot = new int[18]; for (int i = 0; i < disableSlot.length; ++i) disableSlot[i] = 0; } - playerPurchases = NBTTags.getStringIntegerArrayMap(nbttagcompound.getTagList("PlayerPurchases", 10), 18); - playerDisableSlot = NBTTags.getStringIntegerArrayMap(nbttagcompound.getTagList("PlayerDisableSlot", 10), 18); } - + @Override public void interact(EntityPlayer player) { npc.say(player, npc.advanced.getInteractLine()); try { - Market.load(this, marketName); + Market.getMarket(this, marketName); } catch (Exception ex) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); } @@ -117,19 +117,22 @@ public class RoleTrader extends RoleInterface{ } return false; } - + public void addPurchase(int slot, String playerName) { if(slot >= 18 || slot < 0) return; ++purchases[slot]; ++getArrayByName(playerName, playerPurchases)[slot]; + + if(recordHistory) + Market.save(this, marketName); } - + public boolean isSlotEnabled(int slot, String playerName) { if(slot >= 18 || slot < 0) return false; if (disableSlot[slot] > 0) return false; return getArrayByName(playerName, playerDisableSlot)[slot] <= 0; } - + public int[] getArrayByName(String name, HashMap map) { map.computeIfAbsent(name, k -> new int[18]); return map.get(name); diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java index 1100a6c71..5fcc54821 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java @@ -30,7 +30,7 @@ public class ScriptRoleTrader extends ScriptRoleInterface implements IRoleTrader role.inventoryCurrency.items.put(slot + 18, currency2.getMCItemStack()); else role.inventoryCurrency.items.remove(slot + 18); - + role.inventorySold.items.put(slot, sold.getMCItemStack()); } @@ -55,7 +55,7 @@ public class ScriptRoleTrader extends ScriptRoleInterface implements IRoleTrader } return currency; } - + public void removeSellOption(int slot){ if(slot >= 18 || slot < 0) return; @@ -66,7 +66,7 @@ public class ScriptRoleTrader extends ScriptRoleInterface implements IRoleTrader public void setMarket(String name){ role.marketName = name; - Market.load(role, name); + Market.getMarket(role, name); } public String getMarket(){ diff --git a/src/main/java/noppes/npcs/util/CacheHashMap.java b/src/main/java/noppes/npcs/util/CacheHashMap.java index 200630327..12e682b61 100644 --- a/src/main/java/noppes/npcs/util/CacheHashMap.java +++ b/src/main/java/noppes/npcs/util/CacheHashMap.java @@ -6,11 +6,17 @@ import java.util.Map; public class CacheHashMap> extends HashMap { private final long maxCacheTime; + private long saveInterval; public CacheHashMap(long maxCacheTime) { this.maxCacheTime = maxCacheTime; } + public CacheHashMap(long maxCacheTime, long saveInterval) { + this.maxCacheTime = maxCacheTime; + this.saveInterval = saveInterval; + } + @Override public V get(Object key) { V object = super.get(key); @@ -19,9 +25,16 @@ public class CacheHashMap> extends Has Iterator> iterator = this.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = iterator.next(); - long timeDiff = entry.getValue().timeSinceAccessed(); - if (timeDiff > this.maxCacheTime) { + long lifeTimeDiff = entry.getValue().timeSinceAccessed(); + if (lifeTimeDiff > this.maxCacheTime) { + entry.getValue().save(); iterator.remove(); + } else if (this.saveInterval > 0) { + long saveTimeDiff = entry.getValue().timeSinceSaved(); + if (saveTimeDiff > this.saveInterval) { + entry.getValue().save(); + entry.getValue().updateSaveTime(); + } } } @@ -29,22 +42,34 @@ public class CacheHashMap> extends Has } public static class CachedObject { + private long timeSaved; private long lastTimeAccessed; private final T object; public CachedObject(T object) { this.object = object; this.lastTimeAccessed = System.currentTimeMillis(); + this.timeSaved = System.currentTimeMillis(); } public long timeSinceAccessed() { return System.currentTimeMillis() - this.lastTimeAccessed; } + public long timeSinceSaved() { + return System.currentTimeMillis() - this.timeSaved; + } + public void updateTimeAccessed() { this.lastTimeAccessed = System.currentTimeMillis(); } + public void updateSaveTime() { + this.timeSaved = System.currentTimeMillis(); + } + + public void save(){} + public T getObject() { return this.object; } diff --git a/src/main/java/noppes/npcs/util/CustomNPCsThreader.java b/src/main/java/noppes/npcs/util/CustomNPCsThreader.java index 8522fdf55..cdc040112 100644 --- a/src/main/java/noppes/npcs/util/CustomNPCsThreader.java +++ b/src/main/java/noppes/npcs/util/CustomNPCsThreader.java @@ -2,7 +2,8 @@ package noppes.npcs.util; import java.util.concurrent.Executor; import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; public class CustomNPCsThreader { - public static final Executor playerDataThread = Executors.newSingleThreadExecutor(); + public static final Executor customNPCThread = Executors.newSingleThreadExecutor(); } diff --git a/src/main/java/noppes/npcs/util/MarketCachedObject.java b/src/main/java/noppes/npcs/util/MarketCachedObject.java new file mode 100644 index 000000000..1a6aebfbe --- /dev/null +++ b/src/main/java/noppes/npcs/util/MarketCachedObject.java @@ -0,0 +1,15 @@ +package noppes.npcs.util; + +import foxz.utils.Market; +import net.minecraft.nbt.NBTTagCompound; + +public class MarketCachedObject extends CacheHashMap.CachedObject { + public MarketCachedObject(NBTTagCompound object) { + super(object); + } + + @Override + public void save() { + Market.saveFile(getObject()); + } +} diff --git a/src/main/java/noppes/npcs/util/NBTJsonUtil.java b/src/main/java/noppes/npcs/util/NBTJsonUtil.java index 21104a103..ae8cbc7c2 100644 --- a/src/main/java/noppes/npcs/util/NBTJsonUtil.java +++ b/src/main/java/noppes/npcs/util/NBTJsonUtil.java @@ -3,12 +3,10 @@ package noppes.npcs.util; import com.google.common.io.Files; import cpw.mods.fml.common.ObfuscationReflectionHelper; import net.minecraft.nbt.*; +import noppes.npcs.LogWriter; import org.apache.commons.io.Charsets; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; +import java.io.*; import java.util.ArrayList; import java.util.List; @@ -211,7 +209,17 @@ public class NBTJsonUtil { } return json; } - static class JsonLine{ + + public static NBTTagCompound loadNBTData(File file){ + try { + return CompressedStreamTools.readCompressed(new FileInputStream(file)); + } catch (Exception e) { + LogWriter.error("Error loading: " + file.getName(), e); + } + return new NBTTagCompound(); + } + + static class JsonLine{ private String line; public JsonLine(String line){ this.line = line; diff --git a/src/main/resources/META-INF/customnpcs_at.cfg b/src/main/resources/META-INF/customnpcs_at.cfg index 56f161026..990efc151 100644 --- a/src/main/resources/META-INF/customnpcs_at.cfg +++ b/src/main/resources/META-INF/customnpcs_at.cfg @@ -17,3 +17,7 @@ public net.minecraft.client.renderer.ItemRenderer field_78453_b # itemToRender public net.minecraft.client.renderer.entity.RenderPlayer func_77043_a(Lnet/minecraft/entity/EntityLivingBase;FFF)V # rotateCorpse #EntityLivingBase public net.minecraft.entity.EntityLivingBase func_82166_i()I # getArmSwingAnimationEnd +# Minecraft +public net.minecraft.client.Minecraft field_147126_aw # mcMusicTicker +# MusicTicker +public net.minecraft.client.audio.MusicTicker field_147676_d # timeUntilNextMusic diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 4338c92f1..f929b3bdb 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -87,6 +87,7 @@ gui.untilclose=UntilClose gui.whenavailable=OnTheMove gui.ignoreDamage=Ignore damage gui.ignoreNBT=Ignore NBT +gui.recordHistory=Record History gui.minrange=MinimumRange gui.engagedistance=EngageDistance gui.orbitdistance=OrbitDistance From 6f5fd25a240e1cbb6beeff612076ca276baf091a Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 20 Feb 2024 20:30:18 -0500 Subject: [PATCH 23/41] Prevent Music Overlapping Memory Leak --- .../client/controllers/MusicController.java | 17 ++++------ src/main/java/noppes/npcs/roles/JobBard.java | 33 ++++++++++--------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/main/java/noppes/npcs/client/controllers/MusicController.java b/src/main/java/noppes/npcs/client/controllers/MusicController.java index 51e80971c..c3b7f146c 100644 --- a/src/main/java/noppes/npcs/client/controllers/MusicController.java +++ b/src/main/java/noppes/npcs/client/controllers/MusicController.java @@ -1,28 +1,25 @@ package noppes.npcs.client.controllers; import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.ISound; import net.minecraft.client.audio.PositionedSoundRecord; +import net.minecraft.client.audio.SoundCategory; import net.minecraft.client.audio.SoundHandler; import net.minecraft.entity.Entity; import net.minecraft.util.ResourceLocation; public class MusicController { - //public TreeSet sounds = new TreeSet(); - //public TreeSet music = new TreeSet(); - + public static MusicController Instance; public PositionedSoundRecord playing; public ResourceLocation playingResource; public Entity playingEntity; - //private SoundPoolEntry musicPool; - public MusicController(){ Instance = this; } - public void stopMusic(){ SoundHandler handler = Minecraft.getMinecraft().getSoundHandler(); if(playing != null) @@ -32,9 +29,9 @@ public class MusicController { playingEntity = null; playing = null; } - + public void playStreaming(String music, Entity entity){ - if(isPlaying(music)){ + if(isPlaying(music)){ return; } stopMusic(); @@ -57,7 +54,7 @@ public class MusicController { playing = PositionedSoundRecord.func_147673_a(playingResource); handler.playSound(playing); } - + public boolean isPlaying(String music) { ResourceLocation resource = new ResourceLocation(music); @@ -66,7 +63,7 @@ public class MusicController { } return Minecraft.getMinecraft().getSoundHandler().isSoundPlaying(playing); } - + public void playSound(String music, float x, float y, float z) { Minecraft.getMinecraft().theWorld.playSound(x, y, z, music, 1, 1, false); } diff --git a/src/main/java/noppes/npcs/roles/JobBard.java b/src/main/java/noppes/npcs/roles/JobBard.java index 7d2c6054c..d18aa0bf1 100644 --- a/src/main/java/noppes/npcs/roles/JobBard.java +++ b/src/main/java/noppes/npcs/roles/JobBard.java @@ -1,5 +1,6 @@ package noppes.npcs.roles; +import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -14,12 +15,12 @@ import java.util.List; public class JobBard extends JobInterface{ public int minRange = 2; public int maxRange = 64; - + public boolean isStreamer = true; public boolean hasOffRange = true; public String song = ""; - + private EnumBardInstrument instrument = EnumBardInstrument.Banjo; public JobBard(EntityNPCInterface npc) { @@ -38,7 +39,7 @@ public class JobBard extends JobInterface{ nbttagcompound.setInteger("BardInstrument", instrument.ordinal()); nbttagcompound.setBoolean("BardStreamer", isStreamer); nbttagcompound.setBoolean("BardHasOff", hasOffRange); - + return nbttagcompound; } @@ -51,7 +52,7 @@ public class JobBard extends JobInterface{ isStreamer = nbttagcompound.getBoolean("BardStreamer"); hasOffRange = nbttagcompound.getBoolean("BardHasOff"); } - + public void setInstrument(int i) { if(CustomItems.banjo == null) return; @@ -87,16 +88,11 @@ public class JobBard extends JobInterface{ public EnumBardInstrument getInstrument(){ return instrument; } - private long ticks = 0; public void onLivingUpdate() { - if(!npc.isRemote()) + if(!npc.isRemote() || song.isEmpty()) return; - ticks++; - if(ticks % 10 != 0 ) - return; - if(song.isEmpty()) - return; - if(!MusicController.Instance.isPlaying(song)){ + + if(!MusicController.Instance.isPlaying(song)){ List list = npc.worldObj.getEntitiesWithinAABB(EntityPlayer.class, npc.boundingBox.expand(minRange, minRange/2, minRange)); if(!list.contains(CustomNpcs.proxy.getPlayer())) return; @@ -104,18 +100,23 @@ public class JobBard extends JobInterface{ MusicController.Instance.playStreaming(song, npc); else MusicController.Instance.playMusic(song, npc); - }else if(MusicController.Instance.playingEntity != npc){ + } + else if(MusicController.Instance.playingEntity != npc){ EntityPlayer player = CustomNpcs.proxy.getPlayer(); if(npc.getDistanceSqToEntity(player) < MusicController.Instance.playingEntity.getDistanceSqToEntity(player)){ MusicController.Instance.playingEntity = npc; } - - }else if(hasOffRange){ + + } + else if(hasOffRange){ List list = npc.worldObj.getEntitiesWithinAABB(EntityPlayer.class, npc.boundingBox.expand(maxRange, maxRange/2, maxRange)); if(!list.contains(CustomNpcs.proxy.getPlayer())) MusicController.Instance.stopMusic(); } - + + if(MusicController.Instance.isPlaying(song)) { + Minecraft.getMinecraft().mcMusicTicker.field_147676_d = 12000; + } } @Override From 4a58702d1659bcbcb34c542ee1912e747356c89a Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 20 Feb 2024 21:08:48 -0500 Subject: [PATCH 24/41] Implement IVillager Scripting (removed duplicate entity variable) --- src/api | 2 +- .../java/noppes/npcs/scripted/NpcAPI.java | 3 + .../npcs/scripted/constants/EntityType.java | 2 + .../npcs/scripted/entity/ScriptLiving.java | 10 ++- .../scripted/entity/ScriptLivingBase.java | 2 - .../npcs/scripted/entity/ScriptPixelmon.java | 63 +++++++++++-------- .../npcs/scripted/entity/ScriptVillager.java | 41 ++++++++++++ 7 files changed, 88 insertions(+), 35 deletions(-) create mode 100644 src/main/java/noppes/npcs/scripted/entity/ScriptVillager.java diff --git a/src/api b/src/api index a520cc647..d497bb704 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit a520cc647078e32ba2659e6400d86e95e62036dd +Subproject commit d497bb7045d9bcd1f40e24de8c2fd7ec98cd84ec diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index 968e68543..4fe5f5150 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -13,6 +13,7 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.passive.EntityAnimal; import net.minecraft.entity.passive.EntityTameable; +import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Items; import net.minecraft.inventory.Container; @@ -200,6 +201,8 @@ public class NpcAPI extends AbstractNpcAPI { data = new ScriptEntityData(new ScriptAnimal<>((EntityAnimal) entity)); else if(entity instanceof EntityMob) data = new ScriptEntityData(new ScriptMonster<>((EntityMob) entity)); + else if(entity instanceof EntityVillager) + data = new ScriptEntityData(new ScriptVillager<>((EntityVillager) entity)); else if(entity instanceof EntityLiving) data = new ScriptEntityData(new ScriptLiving<>((EntityLiving) entity)); else if(entity instanceof EntityLivingBase) diff --git a/src/main/java/noppes/npcs/scripted/constants/EntityType.java b/src/main/java/noppes/npcs/scripted/constants/EntityType.java index 4bd9cdfd5..76c21de71 100644 --- a/src/main/java/noppes/npcs/scripted/constants/EntityType.java +++ b/src/main/java/noppes/npcs/scripted/constants/EntityType.java @@ -9,4 +9,6 @@ public class EntityType { public static final int LIVING = 5; public static final int ITEM = 6; public static final int PROJECTILE = 7; + public static final int PIXELMON = 8; + public static final int VILLAGER = 9; } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptLiving.java b/src/main/java/noppes/npcs/scripted/entity/ScriptLiving.java index cb198413a..828803ed0 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptLiving.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptLiving.java @@ -8,10 +8,8 @@ import noppes.npcs.scripted.NpcAPI; public class ScriptLiving extends ScriptLivingBase implements IEntityLiving { - private T entity; public ScriptLiving(T entity) { super(entity); - this.entity = entity; } @Override @@ -33,7 +31,7 @@ public class ScriptLiving extends ScriptLivingBase im IEntityLivingBase base = (IEntityLivingBase) NpcAPI.Instance().getIEntity(entity.getAttackTarget()); return (base != null)? base: super.getAttackTarget(); } - + /** * Start path finding toward this target * @param x Destination x position @@ -44,21 +42,21 @@ public class ScriptLiving extends ScriptLivingBase im public void navigateTo(double x, double y, double z, double speed){ entity.getNavigator().tryMoveToXYZ(x, y, z, speed); } - + /** * Stop navigating wherever this npc was walking to */ public void clearNavigation(){ entity.getNavigator().clearPathEntity(); } - + /** * @return Whether or not this entity is navigating somewhere */ public boolean isNavigating(){ return !entity.getNavigator().noPath(); } - + @Override public boolean canSeeEntity(IEntity entity){ return this.entity.getEntitySenses().canSee(entity.getMCEntity()); diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java index 2c45b58eb..33e38d308 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java @@ -20,11 +20,9 @@ import java.util.ArrayList; import java.util.Collections; public class ScriptLivingBase extends ScriptEntity implements IEntityLivingBase { - protected T entity; public ScriptLivingBase(T entity){ super(entity); - this.entity = entity; } /** diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPixelmon.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPixelmon.java index 7bc01d080..702b9ad45 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPixelmon.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPixelmon.java @@ -4,6 +4,7 @@ import net.minecraft.entity.passive.EntityTameable; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.api.entity.IPixelmon; import noppes.npcs.compat.PixelmonHelper; +import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.util.ValueUtil; public class ScriptPixelmon extends ScriptAnimal implements IPixelmon { @@ -19,25 +20,25 @@ public class ScriptPixelmon extends ScriptAnimal im this(pixelmon); this.compound = compound; } - + public boolean getIsShiny(){ return compound.getBoolean("IsShiny"); } - + public void setIsShiny(boolean bo){ compound.setBoolean("IsShiny", bo); pixelmon.readEntityFromNBT(compound); } - + public int getLevel(){ return compound.getInteger("Level"); } - + public void setLevel(int level){ compound.setInteger("Level", level); pixelmon.readEntityFromNBT(compound); } - + /** * @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed */ @@ -54,11 +55,11 @@ public class ScriptPixelmon extends ScriptAnimal im return compound.getInteger("IVSpDef"); if(type == 5) return compound.getInteger("IVSpeed"); - + return -1; } - + /** * @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed */ @@ -77,7 +78,7 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setInteger("IVSpeed", value); pixelmon.readEntityFromNBT(compound); } - + /** * @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed */ @@ -94,11 +95,11 @@ public class ScriptPixelmon extends ScriptAnimal im return compound.getInteger("EVSpecialDefence"); if(type == 5) return compound.getInteger("EVSpeed"); - + return -1; } - + /** * @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed */ @@ -117,7 +118,7 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setInteger("EVSpeed", value); pixelmon.readEntityFromNBT(compound); } - + /** * @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed */ @@ -134,11 +135,11 @@ public class ScriptPixelmon extends ScriptAnimal im return compound.getInteger("StatsSpecialDefence"); if(type == 5) return compound.getInteger("StatsSpeed"); - + return -1; } - + /** * @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed */ @@ -157,14 +158,14 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setInteger("StatsSpeed", value); pixelmon.readEntityFromNBT(compound); } - + /** * @return type 0:Pygmy, 1:Runt, 2:Small, 3:Normal, 4:Huge, 5:Giant, 6:Enormous, 7:Ginormous, 8:Microscopic */ public int getSize(){ return compound.getShort("Growth"); } - + /** * @param type 0:Pygmy, 1:Runt, 2:Small, 3:Normal, 4:Huge, 5:Giant, 6:Enormous, 7:Ginormous, 8:Microscopic */ @@ -172,14 +173,14 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setShort("Growth", (short) type); pixelmon.readEntityFromNBT(compound); } - + /** * @return 0-255 */ public int getHapiness(){ return compound.getInteger("Friendship"); } - + /** * @param value 0-255 */ @@ -188,14 +189,14 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setInteger("Friendship", value); pixelmon.readEntityFromNBT(compound); } - + /** * @return 0:Hardy, 1:Serious, 2:Docile, 3:Bashful, 4:Quirky, 5:Lonely, 6:Brave, 7:Adamant, 8:Naughty, 9:Bold, 10:Relaxed, 11:Impish, 12:Lax, 13:Timid, 14:Hasty, 15:Jolly, 16:Naive, 17:Modest, 18:Mild, 19:Quiet, 20:Rash, 21:Calm, 22:Gentle, 23:Sassy, 24:Careful */ public int getNature(){ return compound.getShort("Nature"); } - + /** * @param type 0:Hardy, 1:Serious, 2:Docile, 3:Bashful, 4:Quirky, 5:Lonely, 6:Brave, 7:Adamant, 8:Naughty, 9:Bold, 10:Relaxed, 11:Impish, 12:Lax, 13:Timid, 14:Hasty, 15:Jolly, 16:Naive, 17:Modest, 18:Mild, 19:Quiet, 20:Rash, 21:Calm, 22:Gentle, 23:Sassy, 24:Careful */ @@ -203,7 +204,7 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setShort("Nature", (short) type); pixelmon.readEntityFromNBT(compound); } - + /** * @return -1:Uncaught, 0:Pokeball, 1:GreatBall, 2:UltraBall, 3:MasterBall, 4:LevelBall, 5:MoonBall, 6:FriendBall, 7:LoveBall, 8:SafariBall, 9:HeavyBall, 10:FastBall, 11:RepeatBall, 12:TimerBall, 13:NestBall, 14:NetBall, 15:DiveBall, 16:LuxuryBall, 17:HealBall, 18:DuskBall, 19:PremierBall, 20:SportBall, 21:QuickBall, 22:ParkBall, 23:LureBall, 24:CherishBall, 25:GSBall */ @@ -220,26 +221,26 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setInteger("CaughtBall", type); pixelmon.readEntityFromNBT(compound); } - + public String getNickname(){ return compound.getString("Nickname"); } - + public boolean hasNickname(){ return !getNickname().isEmpty(); } - + public void setNickname(String name){ compound.setString("Nickname", name); pixelmon.readEntityFromNBT(compound); } - + public String getMove(int slot){ if(!compound.hasKey("PixelmonMoveID" + slot)) return null; return PixelmonHelper.getAttackName(compound.getInteger("PixelmonMoveID" + slot)); } - + public void setMove(int slot, String move){ slot = ValueUtil.clamp(slot, 0, 3); int id = PixelmonHelper.getAttackID(move); @@ -257,7 +258,17 @@ public class ScriptPixelmon extends ScriptAnimal im size++; } compound.setInteger("PixelmonNumberMoves", size); - + pixelmon.readEntityFromNBT(compound); } + + @Override + public int getType(){ + return EntityType.PIXELMON; + } + + @Override + public boolean typeOf(int type){ + return type == EntityType.PIXELMON || super.typeOf(type); + } } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptVillager.java b/src/main/java/noppes/npcs/scripted/entity/ScriptVillager.java new file mode 100644 index 000000000..cc3804651 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptVillager.java @@ -0,0 +1,41 @@ +package noppes.npcs.scripted.entity; + +import net.minecraft.entity.passive.EntityVillager; +import noppes.npcs.api.entity.IEntityLivingBase; +import noppes.npcs.api.entity.IVillager; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.constants.EntityType; + +public class ScriptVillager extends ScriptLiving implements IVillager { + + public ScriptVillager(T entity) { + super(entity); + } + + @Override + public int getProfession() { + return entity.getProfession(); + } + + @Override + public boolean getIsTrading() { + return entity.isTrading(); + } + + @Override + public IEntityLivingBase getCustomer() + { + return (IEntityLivingBase) NpcAPI.Instance().getPlayer(entity.getCustomer().getCommandSenderName()); + } + + @Override + public int getType(){ + return EntityType.VILLAGER; + } + + @Override + public boolean typeOf(int type){ + return type == EntityType.VILLAGER || super.typeOf(type); + } + +} From 7f2a375323a1498281a9930128daa5c9d9b3917c Mon Sep 17 00:00:00 2001 From: Kam Date: Wed, 21 Feb 2024 00:31:17 -0500 Subject: [PATCH 25/41] RightClick Event for Scripted Items --- src/api | 2 +- src/main/java/noppes/npcs/EventHooks.java | 5 +++ .../noppes/npcs/ScriptItemEventHandler.java | 43 +++++++++++++++++++ .../npcs/client/gui/script/GuiScriptItem.java | 3 +- .../noppes/npcs/constants/EnumScriptType.java | 3 +- .../controllers/PlayerDataController.java | 17 +++++--- .../npcs/controllers/data/PlayerData.java | 1 + .../controllers/data/PlayerDataScript.java | 7 +-- .../noppes/npcs/scripted/event/ItemEvent.java | 34 +++++++++++++++ 9 files changed, 101 insertions(+), 14 deletions(-) diff --git a/src/api b/src/api index d497bb704..806bcf4c9 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit d497bb7045d9bcd1f40e24de8c2fd7ec98cd84ec +Subproject commit 806bcf4c914cf4aa68cb68e8d910dee54f32a647 diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 33f9c3971..7353af13c 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -85,6 +85,11 @@ public class EventHooks { return NpcAPI.EVENT_BUS.post(event); } + public static boolean onScriptItemRightClick(IItemCustom handler, noppes.npcs.scripted.event.ItemEvent.RightClickEvent event) { + ((ScriptCustomItem) handler).callScript(EnumScriptType.RIGHT_CLICK, event); + return NpcAPI.EVENT_BUS.post(event); + } + public static boolean onScriptItemAttack(IItemCustom handler, noppes.npcs.scripted.event.ItemEvent.AttackEvent event) { ((ScriptCustomItem) handler).callScript(EnumScriptType.ATTACK, event); return NpcAPI.EVENT_BUS.post(event); diff --git a/src/main/java/noppes/npcs/ScriptItemEventHandler.java b/src/main/java/noppes/npcs/ScriptItemEventHandler.java index c2014b23a..2d7b3cafc 100644 --- a/src/main/java/noppes/npcs/ScriptItemEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptItemEventHandler.java @@ -10,10 +10,15 @@ import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.entity.item.ItemTossEvent; import net.minecraftforge.event.entity.living.LivingEvent; import net.minecraftforge.event.entity.player.EntityInteractEvent; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerUseItemEvent; +import noppes.npcs.api.IWorld; import noppes.npcs.api.entity.IPlayer; import noppes.npcs.api.item.IItemCustom; import noppes.npcs.api.item.IItemStack; +import noppes.npcs.controllers.PlayerDataController; +import noppes.npcs.controllers.data.PlayerData; +import noppes.npcs.controllers.data.PlayerDataScript; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.items.ItemScripted; import noppes.npcs.scripted.NpcAPI; @@ -103,6 +108,44 @@ public class ScriptItemEventHandler { IItemCustom isw = ItemScripted.GetWrapper(event.entityPlayer.getHeldItem()); ItemEvent.InteractEvent eve = new ItemEvent.InteractEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 2, NpcAPI.Instance().getIEntity(event.target)); event.setCanceled(EventHooks.onScriptItemInteract(isw, eve)); + + ItemEvent.RightClickEvent rightClickEvent = new ItemEvent.RightClickEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 1, NpcAPI.Instance().getIEntity(event.target)); + event.setCanceled(EventHooks.onScriptItemRightClick(isw, rightClickEvent)); + } + } catch(Exception e) {} + } + } + + @SubscribeEvent + public void invoke(PlayerInteractEvent event) { + if(event.entityPlayer == null || event.entityPlayer.worldObj == null || event.action == null) + return; + + if(event.entityPlayer.worldObj.isRemote && event.entityPlayer.worldObj instanceof WorldServer) + return; + + if(event.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR){ + PlayerDataScript handler = PlayerDataController.Instance.getPlayerData(event.entityPlayer).scriptData; + if(handler.hadInteract) { + handler.hadInteract = false; + return; + } + try { + if (event.entityPlayer.getHeldItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) { + IItemCustom isw = ItemScripted.GetWrapper(event.entityPlayer.getHeldItem()); + ItemEvent.RightClickEvent eve = new ItemEvent.RightClickEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 0, null); + event.setCanceled(EventHooks.onScriptItemRightClick(isw, eve)); + } + } catch(Exception e) {} + } + else if(event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK){ + PlayerDataScript handler = PlayerDataController.Instance.getPlayerData(event.entityPlayer).scriptData; + handler.hadInteract = true; + try { + if (event.entityPlayer.getHeldItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) { + IItemCustom isw = ItemScripted.GetWrapper(event.entityPlayer.getHeldItem()); + ItemEvent.RightClickEvent eve = new ItemEvent.RightClickEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 2, NpcAPI.Instance().getIBlock((IWorld) NpcAPI.Instance().getIWorld(event.world), event.x, event.y, event.z)); + event.setCanceled(EventHooks.onScriptItemRightClick(isw, eve)); } } catch(Exception e) {} } diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptItem.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptItem.java index ef5f41c01..395497a77 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptItem.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptItem.java @@ -17,6 +17,7 @@ public class GuiScriptItem extends GuiScriptInterface { hookList.add("pickedUp"); hookList.add("spawn"); hookList.add("interact"); + hookList.add("rightClick"); hookList.add("attack"); hookList.add("startItem"); hookList.add("usingItem"); @@ -37,4 +38,4 @@ public class GuiScriptItem extends GuiScriptInterface { super.save(); Client.sendData(EnumPacketServer.ScriptItemDataSave, new Object[]{this.item.getMCNbt()}); } -} \ No newline at end of file +} diff --git a/src/main/java/noppes/npcs/constants/EnumScriptType.java b/src/main/java/noppes/npcs/constants/EnumScriptType.java index cdaf3db88..aec0854a3 100644 --- a/src/main/java/noppes/npcs/constants/EnumScriptType.java +++ b/src/main/java/noppes/npcs/constants/EnumScriptType.java @@ -20,6 +20,7 @@ public enum EnumScriptType { ATTACKED("attacked"), ATTACK_MELEE("meleeAttack"), ATTACK_SWING("meleeSwing"), + RIGHT_CLICK("rightClick"), ROLE("role"), RANGED_CHARGE("rangedCharge"), RANGED_LAUNCHED("rangedLaunched"), @@ -101,4 +102,4 @@ public enum EnumScriptType { private EnumScriptType(String function) { this.function = function; } -} \ No newline at end of file +} diff --git a/src/main/java/noppes/npcs/controllers/PlayerDataController.java b/src/main/java/noppes/npcs/controllers/PlayerDataController.java index 05708cdd5..ecf682fbb 100644 --- a/src/main/java/noppes/npcs/controllers/PlayerDataController.java +++ b/src/main/java/noppes/npcs/controllers/PlayerDataController.java @@ -12,10 +12,7 @@ import net.minecraft.util.ChatComponentText; import noppes.npcs.CustomNpcs; import noppes.npcs.LogWriter; import noppes.npcs.config.ConfigMain; -import noppes.npcs.controllers.data.Bank; -import noppes.npcs.controllers.data.PlayerBankData; -import noppes.npcs.controllers.data.PlayerData; -import noppes.npcs.controllers.data.PlayerMail; +import noppes.npcs.controllers.data.*; import noppes.npcs.util.CacheHashMap; import noppes.npcs.util.NBTJsonUtil; @@ -292,7 +289,10 @@ public class PlayerDataController { public PlayerData getPlayerData(EntityPlayer player){ PlayerData data = getPlayerDataCache(player.getUniqueID().toString()); if(data != null){ - data.player = player; + if(data.player == null){ + data.player = player; + data.scriptData = new PlayerDataScript(player); + } return data; } @@ -300,9 +300,14 @@ public class PlayerDataController { if(data == null){ player.registerExtendedProperties("CustomNpcsData", data = new PlayerData()); data.player = player; + data.scriptData = new PlayerDataScript(player); data.load(); } - data.player = player; + + if(data.player == null){ + data.player = player; + data.scriptData = new PlayerDataScript(player); + } return data; } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerData.java b/src/main/java/noppes/npcs/controllers/data/PlayerData.java index 4b12a1507..f700ed183 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerData.java @@ -41,6 +41,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData { public PlayerItemGiverData itemgiverData = new PlayerItemGiverData(this); public PlayerMailData mailData = new PlayerMailData(this); public AnimationData animationData = new AnimationData(this); + public PlayerDataScript scriptData; public DataTimers timers = new DataTimers(this); public DataSkinOverlays skinOverlays = new DataSkinOverlays(this); diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java index 3981be87a..f51b68748 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java @@ -1,7 +1,3 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// package noppes.npcs.controllers.data; import com.google.common.base.Preconditions; @@ -30,6 +26,7 @@ public class PlayerDataScript implements INpcScriptHandler { private IPlayer playerAPI; private long lastPlayerUpdate = 0L; public long lastInited = -1L; + public boolean hadInteract = true; public boolean enabled = false; public PlayerDataScript(EntityPlayer player) { @@ -320,4 +317,4 @@ public class PlayerDataScript implements INpcScriptHandler { public static PlayerDataScript.ToStringHelper toStringHelper(Object self) { return new PlayerDataScript.ToStringHelper(self.getClass().getSimpleName()); } -} \ No newline at end of file +} diff --git a/src/main/java/noppes/npcs/scripted/event/ItemEvent.java b/src/main/java/noppes/npcs/scripted/event/ItemEvent.java index c5196c78c..99e959814 100644 --- a/src/main/java/noppes/npcs/scripted/event/ItemEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/ItemEvent.java @@ -138,6 +138,40 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent { } } + @Cancelable + public static class RightClickEvent extends ItemEvent implements IItemEvent.RightClickEvent { + + /** + * 0:air, 1:entity, 2:block + */ + public final int type; + public final Object target; + public final IPlayer player; + + public RightClickEvent(IItemCustom item, IPlayer player, int type, Object target) { + super(item); + this.type = type; + this.target = target; + this.player = player; + } + + public String getHookName() { + return EnumScriptType.INTERACT.function; + } + + public int getType() { + return type; + } + + public Object getTarget() { + return target; + } + + public IPlayer getPlayer() { + return player; + } + } + @Cancelable public static class AttackEvent extends ItemEvent implements IItemEvent.AttackEvent { public final int type;//1: Hit, 2: Whiff From 8ec795c98a490605c019270220a8531397135d1c Mon Sep 17 00:00:00 2001 From: Kam Date: Wed, 21 Feb 2024 03:02:39 -0500 Subject: [PATCH 26/41] MarkData to NPCs [1.12 Backport] --- src/api | 2 +- .../java/noppes/npcs/NoppesUtilServer.java | 14 ++ .../java/noppes/npcs/PacketHandlerPlayer.java | 28 +++- .../java/noppes/npcs/PacketHandlerServer.java | 5 + .../java/noppes/npcs/ServerEventsHandler.java | 11 ++ .../npcs/client/ClientEventHandler.java | 14 ++ .../npcs/client/PacketHandlerClient.java | 9 ++ .../npcs/client/gui/advanced/GuiNPCMarks.java | 84 ++++++++++ .../client/gui/mainmenu/GuiNpcAdvanced.java | 18 ++- .../client/model/util/Model2DRenderer.java | 77 +++++++++ .../npcs/client/renderer/MarkRenderer.java | 59 +++++++ .../npcs/constants/EnumPacketClient.java | 3 +- .../npcs/constants/EnumPacketServer.java | 2 +- .../npcs/constants/EnumPlayerPacket.java | 6 +- .../java/noppes/npcs/constants/MarkType.java | 11 ++ .../npcs/controllers/data/MarkData.java | 147 ++++++++++++++++++ .../customnpcs/textures/marks/cross.png | Bin 0 -> 841 bytes .../customnpcs/textures/marks/exclamation.png | Bin 0 -> 946 bytes .../customnpcs/textures/marks/pointer.png | Bin 0 -> 670 bytes .../customnpcs/textures/marks/question.png | Bin 0 -> 640 bytes .../customnpcs/textures/marks/skull.png | Bin 0 -> 889 bytes .../assets/customnpcs/textures/marks/star.png | Bin 0 -> 1483 bytes 22 files changed, 473 insertions(+), 17 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/advanced/GuiNPCMarks.java create mode 100644 src/main/java/noppes/npcs/client/renderer/MarkRenderer.java create mode 100644 src/main/java/noppes/npcs/constants/MarkType.java create mode 100644 src/main/java/noppes/npcs/controllers/data/MarkData.java create mode 100644 src/main/resources/assets/customnpcs/textures/marks/cross.png create mode 100644 src/main/resources/assets/customnpcs/textures/marks/exclamation.png create mode 100644 src/main/resources/assets/customnpcs/textures/marks/pointer.png create mode 100644 src/main/resources/assets/customnpcs/textures/marks/question.png create mode 100644 src/main/resources/assets/customnpcs/textures/marks/skull.png create mode 100644 src/main/resources/assets/customnpcs/textures/marks/star.png diff --git a/src/api b/src/api index 806bcf4c9..c570d20fc 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit 806bcf4c914cf4aa68cb68e8d910dee54f32a647 +Subproject commit c570d20fc88a4e7fad399866802be6c795d5ff23 diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index 80ecfeb7f..06745b2b6 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -23,6 +23,7 @@ import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.world.World; +import net.minecraft.world.WorldServer; import noppes.npcs.api.entity.IPlayer; import noppes.npcs.config.ConfigMain; import noppes.npcs.constants.EnumGuiType; @@ -40,6 +41,7 @@ import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.ScriptSound; import noppes.npcs.scripted.event.DialogEvent; +import javax.annotation.Nullable; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.File; @@ -862,6 +864,18 @@ public class NoppesUtilServer { return null; } + public static Entity getEntityFromUUID(World world, UUID uuid) { + for (Object obj : world.loadedEntityList) { + if (obj instanceof Entity) { + Entity entity = (Entity) obj; + if (entity.getUniqueID().equals(uuid)) { + return entity; + } + } + } + return null; + } + static public EntityPlayer getPlayerByName(String playername){ return MinecraftServer.getServer().getConfigurationManager().func_152612_a(playername); } diff --git a/src/main/java/noppes/npcs/PacketHandlerPlayer.java b/src/main/java/noppes/npcs/PacketHandlerPlayer.java index 40924001f..db61d455d 100644 --- a/src/main/java/noppes/npcs/PacketHandlerPlayer.java +++ b/src/main/java/noppes/npcs/PacketHandlerPlayer.java @@ -3,6 +3,9 @@ package noppes.npcs; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent; import io.netty.buffer.ByteBuf; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Items; import net.minecraft.item.ItemEditableBook; @@ -25,9 +28,10 @@ import noppes.npcs.roles.RoleCompanion; import java.io.IOException; import java.util.Iterator; +import java.util.UUID; public class PacketHandlerPlayer{ - + @SubscribeEvent public void onServerPacket(ServerCustomPacketEvent event) { EntityPlayerMP player = ((NetHandlerPlayServer)event.handler).playerEntity; @@ -40,7 +44,17 @@ public class PacketHandlerPlayer{ } private void player(ByteBuf buffer, EntityPlayerMP player, EnumPlayerPacket type) throws IOException { - if(type == EnumPlayerPacket.CompanionTalentExp){ + if(type == EnumPlayerPacket.MarkData){ + String uuid = Server.readString(buffer); + if(uuid == null) + return; + + Entity entity = NoppesUtilServer.getEntityFromUUID(player.worldObj, UUID.fromString(uuid)); + if(!(entity instanceof EntityNPCInterface)) + return; + MarkData data = MarkData.get((EntityNPCInterface) entity); + } + else if(type == EnumPlayerPacket.CompanionTalentExp){ EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player); if(npc == null || npc.advanced.role != EnumRoleType.Companion || player != npc.getOwner()) return; @@ -202,7 +216,7 @@ public class PacketHandlerPlayer{ long time = buffer.readLong(); String username = Server.readString(buffer); PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData; - + Iterator it = data.playermail.iterator(); while(it.hasNext()){ PlayerMail mail = it.next(); @@ -220,7 +234,7 @@ public class PacketHandlerPlayer{ NoppesUtilServer.sendGuiError(player, 0); return; } - + PlayerMail mail = new PlayerMail(); //String s = player.func_145748_c_().getFormattedText(); String s = player.getDisplayName(); @@ -235,7 +249,7 @@ public class PacketHandlerPlayer{ return; } PlayerDataController.Instance.addPlayerMessage(username, mail); - + NBTTagCompound comp = new NBTTagCompound(); comp.setString("username", username); NoppesUtilServer.sendGuiClose(player, 1,comp); @@ -245,7 +259,7 @@ public class PacketHandlerPlayer{ String username = Server.readString(buffer); player.closeContainer(); PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData; - + Iterator it = data.playermail.iterator(); while(it.hasNext()){ PlayerMail mail = it.next(); @@ -260,7 +274,7 @@ public class PacketHandlerPlayer{ long time = buffer.readLong(); String username = Server.readString(buffer); PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData; - + Iterator it = data.playermail.iterator(); while(it.hasNext()){ PlayerMail mail = it.next(); diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 937a42f7a..5df65423f 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -1000,6 +1000,11 @@ public class PacketHandlerServer{ npc.updateAI = true; npc.updateClient = true; } + else if(type == EnumPacketServer.MainmenuAdvancedMarkData){ + MarkData data = MarkData.get(npc); + data.setNBT(Server.readNBT(buffer)); + data.syncClients(); + } else if(type == EnumPacketServer.JobSave){ NBTTagCompound original = npc.jobInterface.writeToNBT(new NBTTagCompound()); NBTTagCompound compound = Server.readNBT(buffer); diff --git a/src/main/java/noppes/npcs/ServerEventsHandler.java b/src/main/java/noppes/npcs/ServerEventsHandler.java index 22f00c34a..f46d562ef 100644 --- a/src/main/java/noppes/npcs/ServerEventsHandler.java +++ b/src/main/java/noppes/npcs/ServerEventsHandler.java @@ -403,4 +403,15 @@ public class ServerEventsHandler { public void populateChunk(PopulateChunkEvent.Post event){ NPCSpawning.performWorldGenSpawning(event.world, event.chunkX, event.chunkZ, event.rand); } + + @SubscribeEvent + public void playerTracking(PlayerEvent.StartTracking event){ + if(!(event.target instanceof EntityNPCInterface) || event.target.worldObj.isRemote) + return; + + MarkData data = MarkData.get((EntityNPCInterface) event.target); + if(data.marks.isEmpty()) + return; + Server.sendData((EntityPlayerMP)event.entityPlayer, EnumPacketClient.MARK_DATA, event.target.getEntityId(), data.getNBT()); + } } diff --git a/src/main/java/noppes/npcs/client/ClientEventHandler.java b/src/main/java/noppes/npcs/client/ClientEventHandler.java index c30f02180..ab42f1f97 100644 --- a/src/main/java/noppes/npcs/client/ClientEventHandler.java +++ b/src/main/java/noppes/npcs/client/ClientEventHandler.java @@ -15,11 +15,14 @@ import net.minecraftforge.client.event.RenderLivingEvent; import net.minecraftforge.client.event.RenderPlayerEvent; import net.minecraftforge.event.entity.living.LivingEvent; import noppes.npcs.client.gui.customoverlay.OverlayCustom; +import noppes.npcs.client.renderer.MarkRenderer; import noppes.npcs.client.renderer.RenderCNPCPlayer; import noppes.npcs.constants.EnumAnimationPart; +import noppes.npcs.constants.MarkType; import noppes.npcs.controllers.data.Animation; import noppes.npcs.controllers.data.AnimationData; import noppes.npcs.controllers.data.FramePart; +import noppes.npcs.controllers.data.MarkData; import noppes.npcs.entity.EntityNPCInterface; import java.lang.reflect.Field; @@ -93,6 +96,16 @@ public class ClientEventHandler { AnimationData data = null; if (event.entity instanceof EntityNPCInterface) { data = ClientEventHandler.renderingNpc.display.animationData; + + MarkData markData = MarkData.get((EntityNPCInterface) event.entity); + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + for(MarkData.Mark m : markData.marks){ + if(m.getType() != MarkType.NONE && m.availability.isAvailable(player)){ + MarkRenderer.render(event.entity, event.x, event.y, event.z, m); + break; + } + } + } else if (event.entity instanceof EntityPlayer) { if (ClientCacheHandler.playerAnimations.containsKey(event.entity.getUniqueID())) { data = ClientCacheHandler.playerAnimations.get(event.entity.getUniqueID()); @@ -118,6 +131,7 @@ public class ClientEventHandler { animation.increaseTime(); } } + ClientEventHandler.renderingNpc = null; } diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index 36938f5da..609e9d7b4 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -8,6 +8,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.achievement.GuiAchievement; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; @@ -35,6 +36,7 @@ import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.controllers.RecipeController; import noppes.npcs.controllers.data.Animation; import noppes.npcs.controllers.data.AnimationData; +import noppes.npcs.controllers.data.MarkData; import noppes.npcs.controllers.data.RecipeCarpentry; import noppes.npcs.entity.EntityDialogNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -103,6 +105,13 @@ public class PacketHandlerClient extends PacketHandlerServer{ RecipeController.Instance.anvilRecipes = RecipeController.syncRecipes; RecipeController.syncRecipes = new HashMap(); } + else if(type == EnumPacketClient.MARK_DATA){ + Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(buffer.readInt()); + if(!(entity instanceof EntityNPCInterface)) + return; + MarkData data = MarkData.get((EntityNPCInterface) entity); + data.setNBT(Server.readNBT(buffer)); + } else if(type == EnumPacketClient.DIALOG){ Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(buffer.readInt()); if(entity == null || !(entity instanceof EntityNPCInterface)) diff --git a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCMarks.java b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCMarks.java new file mode 100644 index 000000000..1be2ab503 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCMarks.java @@ -0,0 +1,84 @@ +package noppes.npcs.client.gui.advanced; + +import net.minecraft.client.gui.GuiButton; +import noppes.npcs.client.Client; +import noppes.npcs.client.gui.SubGuiColorSelector; +import noppes.npcs.client.gui.SubGuiNpcAvailability; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.constants.MarkType; +import noppes.npcs.controllers.data.MarkData; +import noppes.npcs.entity.EntityNPCInterface; + +public class GuiNPCMarks extends GuiNPCInterface2 implements ISubGuiListener { + private final String[] marks = new String[]{"gui.none", "mark.question", "mark.exclamation", "mark.pointer", "mark.skull", "mark.cross", "mark.star"}; + private MarkData data; + private MarkData.Mark selectedMark; + + public GuiNPCMarks(EntityNPCInterface npc){ + super(npc); + this.data = MarkData.get(npc); + } + + @Override + public void initGui(){ + super.initGui(); + int y = guiTop + 14; + for(int i = 0; i < data.marks.size(); i++){ + MarkData.Mark mark = data.marks.get(i); + this.addButton(new GuiButtonBiDirectional(1 + i * 10, guiLeft + 6, y, 120, 20, marks, mark.type)); + + String color = Integer.toHexString(mark.color); + while(color.length() < 6) + color = "0" + color; + addButton(new GuiNpcButton(2 + i * 10, guiLeft + 128, y, 60, 20, color)); + getButton(2 + i * 10).setTextColor(mark.color); + + this.addButton(new GuiNpcButton(3 + i * 10, guiLeft + 190, y, 120, 20, "availability.options")); + this.addButton(new GuiNpcButton(4 + i * 10, guiLeft + 312, y, 40, 20, "X")); + y += 22; + } + + if(data.marks.size() < 9){ + this.addButton(new GuiNpcButton(101 , guiLeft + 6, y + 2, 60, 20, "gui.add")); + } + } + + @Override + public void buttonEvent(GuiButton button){ + if(button.id < 90){ + selectedMark = data.marks.get(button.id / 10); + if(button.id % 10 == 1){ + selectedMark.type = ((GuiNpcButton)button).getValue(); + } + if(button.id % 10 == 2){ + this.setSubGui(new SubGuiColorSelector(selectedMark.color)); + } + if(button.id % 10 == 3){ + setSubGui(new SubGuiNpcAvailability(selectedMark.availability)); + } + if(button.id % 10 == 4){ + data.marks.remove(selectedMark); + initGui(); + } + } + if(button.id == 101){ + data.addMark(MarkType.NONE); + initGui(); + } + } + + @Override + public void subGuiClosed(SubGuiInterface subgui) { + if(subgui instanceof SubGuiColorSelector){ + selectedMark.color = ((SubGuiColorSelector)subgui).color; + initGui(); + } + } + + @Override + public void save() { + Client.sendData(EnumPacketServer.MainmenuAdvancedMarkData, data.getNBT()); + } + +} diff --git a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAdvanced.java b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAdvanced.java index 84ce86992..51ff99278 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAdvanced.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAdvanced.java @@ -45,7 +45,9 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData this.addButton(new GuiNpcButton(12, guiLeft + 85, y += gap, 214, 20, "advanced.night")); this.addButton(new GuiNpcButton(13, guiLeft + 85, y += gap, 214, 20, "global.linked")); this.addButton(new GuiNpcButton(14, guiLeft + 85, y += gap, 214, 20, "menu.tags")); - + + // FIX THIS KAM + this.addButton(new GuiNpcButton(15, guiLeft + 208, y, 190, 20, "advanced.marks")); } @Override @@ -68,7 +70,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData if(button.id == 5){ hasChanges = true; npc.advanced.setJob(button.getValue()); - + getButton(4).setEnabled(npc.advanced.job != EnumJobType.None && npc.advanced.job != EnumJobType.ChunkLoader); } if(button.id == 9){ @@ -99,6 +101,10 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData save(); NoppesUtil.openGUI(player, new GuiNPCTagSetup(npc)); } + if(button.id == 15){ + save(); + NoppesUtil.openGUI(player, new GuiNPCMarks(npc)); + } } @Override @@ -106,7 +112,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData if(compound.hasKey("RoleData")){ if(npc.roleInterface != null) npc.roleInterface.readFromNBT(compound); - + if(npc.advanced.role == EnumRoleType.Trader) NoppesUtil.requestOpenGUI(EnumGuiType.SetupTrader); else if(npc.advanced.role == EnumRoleType.Follower) @@ -121,7 +127,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData else if(compound.hasKey("JobData")){ if(npc.jobInterface != null) npc.jobInterface.readFromNBT(compound); - + if(npc.advanced.job == EnumJobType.Bard) NoppesUtil.openGUI(player, new GuiNpcBard(npc)); else if(npc.advanced.job == EnumJobType.Healer) @@ -142,7 +148,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData initGui(); } } - + @Override public void save() { if(hasChanges){ @@ -150,6 +156,6 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData hasChanges = false; } } - + } diff --git a/src/main/java/noppes/npcs/client/model/util/Model2DRenderer.java b/src/main/java/noppes/npcs/client/model/util/Model2DRenderer.java index 0cb4d163e..7dfa4b4dc 100644 --- a/src/main/java/noppes/npcs/client/model/util/Model2DRenderer.java +++ b/src/main/java/noppes/npcs/client/model/util/Model2DRenderer.java @@ -88,4 +88,81 @@ public class Model2DRenderer extends ModelRenderer { GL11.glEndList(); this.compiledModel = true; } + + public static void renderItemIn2D(float p_78439_1_, float p_78439_2_, float p_78439_3_, float p_78439_4_, int p_78439_5_, int p_78439_6_, float p_78439_7_) { + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, 1.0F); + tessellator.addVertexWithUV(0.0D, 0.0D, 0.0D, p_78439_1_, p_78439_4_); + tessellator.addVertexWithUV(1.0D, 0.0D, 0.0D, p_78439_3_, p_78439_4_); + tessellator.addVertexWithUV(1.0D, 1.0D, 0.0D, p_78439_3_, p_78439_2_); + tessellator.addVertexWithUV(0.0D, 1.0D, 0.0D, p_78439_1_, p_78439_2_); + tessellator.draw(); + + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, -1.0F); + tessellator.addVertexWithUV(0.0D, 1.0D, 0.0F - p_78439_7_, p_78439_1_, p_78439_2_); + tessellator.addVertexWithUV(1.0D, 1.0D, 0.0F - p_78439_7_, p_78439_3_, p_78439_2_); + tessellator.addVertexWithUV(1.0D, 0.0D, 0.0F - p_78439_7_, p_78439_3_, p_78439_4_); + tessellator.addVertexWithUV(0.0D, 0.0D, 0.0F - p_78439_7_, p_78439_1_, p_78439_4_); + tessellator.draw(); + + float f5 = 0.5F * (p_78439_1_ - p_78439_3_) / (float) p_78439_5_; + float f6 = 0.5F * (p_78439_4_ - p_78439_2_) / (float) p_78439_6_; + + tessellator.startDrawingQuads(); + tessellator.setNormal(-1.0F, 0.0F, 0.0F); + + for (int k = 0; k < p_78439_5_; ++k) { + float f7 = (float) k / (float) p_78439_5_; + float f8 = p_78439_1_ + (p_78439_3_ - p_78439_1_) * f7 - f5; + tessellator.addVertexWithUV(f7, 0.0D, 0.0F - p_78439_7_, f8, p_78439_4_); + tessellator.addVertexWithUV(f7, 0.0D, 0.0D, f8, p_78439_4_); + tessellator.addVertexWithUV(f7, 1.0D, 0.0D, f8, p_78439_2_); + tessellator.addVertexWithUV(f7, 1.0D, 0.0F - p_78439_7_, f8, p_78439_2_); + } + + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(1.0F, 0.0F, 0.0F); + + for (int k = 0; k < p_78439_5_; ++k) { + float f7 = (float) k / (float) p_78439_5_; + float f8 = p_78439_1_ + (p_78439_3_ - p_78439_1_) * f7 - f5; + float f9 = f7 + 1.0F / (float) p_78439_5_; + tessellator.addVertexWithUV(f9, 1.0D, 0.0F - p_78439_7_, f8, p_78439_2_); + tessellator.addVertexWithUV(f9, 1.0D, 0.0D, f8, p_78439_2_); + tessellator.addVertexWithUV(f9, 0.0D, 0.0D, f8, p_78439_4_); + tessellator.addVertexWithUV(f9, 0.0D, 0.0F - p_78439_7_, f8, p_78439_4_); + } + + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 1.0F, 0.0F); + + for (int k = 0; k < p_78439_6_; ++k) { + float f7 = (float) k / (float) p_78439_6_; + float f8 = p_78439_4_ + (p_78439_2_ - p_78439_4_) * f7 - f6; + float f9 = f7 + 1.0F / (float) p_78439_6_; + tessellator.addVertexWithUV(0.0D, f9, 0.0D, p_78439_1_, f8); + tessellator.addVertexWithUV(1.0D, f9, 0.0D, p_78439_3_, f8); + tessellator.addVertexWithUV(1.0D, f9, 0.0F - p_78439_7_, p_78439_3_, f8); + tessellator.addVertexWithUV(0.0D, f9, 0.0F - p_78439_7_, p_78439_1_, f8); + } + + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, -1.0F, 0.0F); + + for (int k = 0; k < p_78439_6_; ++k) { + float f7 = (float) k / (float) p_78439_6_; + float f8 = p_78439_4_ + (p_78439_2_ - p_78439_4_) * f7 - f6; + tessellator.addVertexWithUV(1.0D, f7, 0.0D, p_78439_3_, f8); + tessellator.addVertexWithUV(0.0D, f7, 0.0D, p_78439_1_, f8); + tessellator.addVertexWithUV(0.0D, f7, 0.0F - p_78439_7_, p_78439_1_, f8); + tessellator.addVertexWithUV(1.0D, f7, 0.0F - p_78439_7_, p_78439_3_, f8); + } + + tessellator.draw(); + } } diff --git a/src/main/java/noppes/npcs/client/renderer/MarkRenderer.java b/src/main/java/noppes/npcs/client/renderer/MarkRenderer.java new file mode 100644 index 000000000..50c5db0f3 --- /dev/null +++ b/src/main/java/noppes/npcs/client/renderer/MarkRenderer.java @@ -0,0 +1,59 @@ +package noppes.npcs.client.renderer; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GLAllocation; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.model.util.Model2DRenderer; +import noppes.npcs.constants.MarkType; +import noppes.npcs.controllers.data.MarkData; +import org.lwjgl.opengl.GL11; + +public class MarkRenderer { + public static ResourceLocation markExclamation = new ResourceLocation("customnpcs", "textures/marks/exclamation.png"); + public static ResourceLocation markQuestion = new ResourceLocation("customnpcs", "textures/marks/question.png"); + public static ResourceLocation markPointer = new ResourceLocation("customnpcs", "textures/marks/pointer.png"); + public static ResourceLocation markCross = new ResourceLocation("customnpcs", "textures/marks/cross.png"); + public static ResourceLocation markSkull = new ResourceLocation("customnpcs", "textures/marks/skull.png"); + public static ResourceLocation markStar = new ResourceLocation("customnpcs", "textures/marks/star.png"); + + public static int displayList = -1; + + public static void render(EntityLivingBase entity, double x, double y, double z, MarkData.Mark mark){ + GL11.glPushMatrix(); + int color = mark.color; + float red = (float)(color >> 16 & 255) / 255.0F; + float blue = (float)(color >> 8 & 255) / 255.0F; + float green = (float)(color & 255) / 255.0F; + GL11.glColor4f(red, blue, green, 1); + GL11.glTranslatef((float) x, (float) (y + entity.height + 0.6), (float) z); + GL11.glRotatef(-entity.rotationYawHead, 0, 1, 0); + + if(mark.type == MarkType.EXCLAMATION) + Minecraft.getMinecraft().getTextureManager().bindTexture(markExclamation); + else if(mark.type == MarkType.QUESTION) + Minecraft.getMinecraft().getTextureManager().bindTexture(markQuestion); + else if(mark.type == MarkType.POINTER) + Minecraft.getMinecraft().getTextureManager().bindTexture(markPointer); + else if(mark.type == MarkType.CROSS) + Minecraft.getMinecraft().getTextureManager().bindTexture(markCross); + else if(mark.type == MarkType.SKULL) + Minecraft.getMinecraft().getTextureManager().bindTexture(markSkull); + else if(mark.type == MarkType.STAR) + Minecraft.getMinecraft().getTextureManager().bindTexture(markStar); + + if(displayList >= 0){ + GL11.glCallList(displayList); + } + else{ + displayList = GLAllocation.generateDisplayLists(1); + GL11.glNewList(displayList, GL11.GL_COMPILE); + GL11.glTranslatef((float) -0.5, 0, 0); + Model2DRenderer.renderItemIn2D(0f, 0f, 1f, 1f, 32, 32, 0.0625F); + GL11.glEndList(); + } + + GL11.glPopMatrix(); + } +} diff --git a/src/main/java/noppes/npcs/constants/EnumPacketClient.java b/src/main/java/noppes/npcs/constants/EnumPacketClient.java index e070ce5ca..ff865baa0 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketClient.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketClient.java @@ -53,5 +53,6 @@ public enum EnumPacketClient { PAUSE_SOUNDS, CONTINUE_SOUNDS, STOP_SOUNDS, - SYNC_WEAPON + SYNC_WEAPON, + MARK_DATA } diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index 5714b8309..d13ee51a6 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -20,7 +20,7 @@ public enum EnumPacketServer { MainmenuDisplaySave(CustomNpcsPermissions.NPC_DISPLAY, true), MainmenuDisplayGet(true), ModelDataSave(CustomNpcsPermissions.NPC_DISPLAY, true), - MainmenuAdvancedSave(CustomNpcsPermissions.NPC_ADVANCED,true), MainmenuAdvancedGet(true), + MainmenuAdvancedSave(CustomNpcsPermissions.NPC_ADVANCED,true), MainmenuAdvancedGet(true), MainmenuAdvancedMarkData(CustomNpcsPermissions.NPC_ADVANCED,true), DialogNpcSet(CustomNpcsPermissions.NPC_ADVANCED), DialogNpcRemove(CustomNpcsPermissions.NPC_ADVANCED, true), FactionSet(CustomNpcsPermissions.NPC_ADVANCED, true), diff --git a/src/main/java/noppes/npcs/constants/EnumPlayerPacket.java b/src/main/java/noppes/npcs/constants/EnumPlayerPacket.java index 765cb7e92..e89854166 100644 --- a/src/main/java/noppes/npcs/constants/EnumPlayerPacket.java +++ b/src/main/java/noppes/npcs/constants/EnumPlayerPacket.java @@ -1,5 +1,9 @@ package noppes.npcs.constants; public enum EnumPlayerPacket { - FollowerHire,FollowerExtend,Trader, FollowerState, Transport, BankUnlock, BankUpgrade, Dialog, QuestLog, CheckQuestCompletion, BankSlotOpen, FactionsGet, MailGet, MailDelete, MailSend, MailRead, MailboxOpenMail, SignSave, SaveBook, CompanionOpenInv, RoleGet, KeyPressed, MouseClicked, CompanionTalentExp, ScreenSize + FollowerHire,FollowerExtend,Trader, FollowerState, Transport, BankUnlock, BankUpgrade, + Dialog, QuestLog, CheckQuestCompletion, BankSlotOpen, FactionsGet, + MailGet, MailDelete, MailSend, MailRead, MailboxOpenMail, + SignSave, SaveBook, CompanionOpenInv, RoleGet, KeyPressed, + MouseClicked, CompanionTalentExp, ScreenSize, MarkData } diff --git a/src/main/java/noppes/npcs/constants/MarkType.java b/src/main/java/noppes/npcs/constants/MarkType.java new file mode 100644 index 000000000..9beb217ec --- /dev/null +++ b/src/main/java/noppes/npcs/constants/MarkType.java @@ -0,0 +1,11 @@ +package noppes.npcs.constants; + +public class MarkType { + public static final int NONE = 0; + public static final int QUESTION = 1; + public static final int EXCLAMATION = 2; + public static final int POINTER = 3; + public static final int SKULL = 4; + public static final int CROSS = 5; + public static final int STAR = 6; +} diff --git a/src/main/java/noppes/npcs/controllers/data/MarkData.java b/src/main/java/noppes/npcs/controllers/data/MarkData.java new file mode 100644 index 000000000..2cd4edfc6 --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/data/MarkData.java @@ -0,0 +1,147 @@ +package noppes.npcs.controllers.data; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; +import net.minecraftforge.common.IExtendedEntityProperties; +import noppes.npcs.Server; +import noppes.npcs.api.entity.data.IMark; +import noppes.npcs.api.handler.data.IAvailability; +import noppes.npcs.constants.EnumPacketClient; +import noppes.npcs.constants.MarkType; +import noppes.npcs.entity.EntityNPCInterface; + +import java.util.ArrayList; +import java.util.List; + +public class MarkData implements IExtendedEntityProperties { + + private static final String CNPCMARK = "cnpcmark"; + private EntityLivingBase entity; + + public List marks = new ArrayList(); + + public void setNBT(NBTTagCompound compound){ + List marks = new ArrayList(); + NBTTagList list = compound.getTagList("marks", 10); + for(int i = 0; i < list.tagCount(); i++){ + NBTTagCompound c = list.getCompoundTagAt(i); + Mark m = new Mark(); + m.type = c.getInteger("type"); + m.color = c.getInteger("color"); + m.availability.readFromNBT(c.getCompoundTag("availability")); + marks.add(m); + } + this.marks = marks; + } + + public NBTTagCompound getNBT() { + NBTTagCompound compound = new NBTTagCompound(); + NBTTagList list = new NBTTagList(); + for(Mark m : marks){ + NBTTagCompound c = new NBTTagCompound(); + c.setInteger("type", m.type); + c.setInteger("color", m.color); + c.setTag("availability", m.availability.writeToNBT(new NBTTagCompound())); + list.appendTag(c); + } + compound.setTag("marks", list); + return compound; + } + + public static boolean has(EntityLivingBase entity) { + return entity.getExtendedProperties(CNPCMARK) != null; + } + + public static MarkData get(EntityNPCInterface npc){ + if(!MarkData.has(npc)){ + npc.registerExtendedProperties(CNPCMARK, new MarkData()); + } + + MarkData data = (MarkData) npc.getExtendedProperties(CNPCMARK); + if(data.entity == null){ + data.entity = npc; + data.setNBT(npc.getEntityData().getCompoundTag(CNPCMARK)); + } + return data; + } + + public IMark addMark(int type) { + Mark m = new Mark(); + m.type = type; + marks.add(m); + if (!entity.worldObj.isRemote) + syncClients(); + return m; + } + + public IMark addMark(int type, int color) { + Mark m = new Mark(); + m.type = type; + m.color = color; + marks.add(m); + if (!entity.worldObj.isRemote) + syncClients(); + return m; + } + + @Override + public void saveNBTData(NBTTagCompound compound) { + if (!(this.entity instanceof EntityNPCInterface)) { + return; + } + this.entity.getEntityData().setTag(CNPCMARK, this.getNBT()); + } + + @Override + public void loadNBTData(NBTTagCompound compound) {} + + @Override + public void init(Entity entity, World world) {} + + public void syncClients() { + Server.sendToAll(EnumPacketClient.MARK_DATA, entity.getEntityId(), getNBT()); + } + + public class Mark implements IMark { + public int type = MarkType.NONE; + public Availability availability = new Availability(); + public int color = 0xFFED51; + + @Override + public IAvailability getAvailability() { + return availability; + } + + @Override + public int getColor() { + return color; + } + + @Override + public void setColor(int color) { + this.color = color; + } + + @Override + public int getType() { + return type; + } + + @Override + public void setType(int type) { + this.type = type; + } + + @Override + public void update() { + MarkData.this.syncClients(); + } + } +} diff --git a/src/main/resources/assets/customnpcs/textures/marks/cross.png b/src/main/resources/assets/customnpcs/textures/marks/cross.png new file mode 100644 index 0000000000000000000000000000000000000000..1aac9f6cf3ff6d411e24e0aea9a8f6f3a1f214bb GIT binary patch literal 841 zcmV-P1GfB$P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02y>eSaefwW^{L9 za%BK;VQFr3E^cLXAT%y8E-^DS16z6k00Oy5L_t(oN4=I?j@m#FMOn*iAzPR&WDD6s zwvctr_aGtu2Z4Bqr^Q1I0-`v5%3V&mAI3ycu5_iD?yjoSW!&ywS(d$izn}A$#MnP| z7Ql^vIG3rpXG{*KkJKDa0=Thv3G)i)yV{4Vk`NJq`@c~f+4*PeLZypF5kv!^T9cLy z>S7-jX*!)YAZh?6=ks}aI2`yhDI3^kzdX|EbSh`F84&NfRsfjXZnx!Pv0zf1lLQ6Q zWY{l@G#-z|lgUK#yUhwj4RAaj1wsLq%O%61yYxlL0GQtcA%j7!1CpYTzsYuF{p|dcCee9?1fq&u7~GHOy<>3V=y^y?)_- zZdb3PxNG^3R8H%M0GQ-J6h$G=6^Ekjn4PokcDog+T%kJwU;y+D!R%7SZWX{6r}Zyk zj+8qCP>947z}jlWt~Z;F7|8qm-ucvgrUQjk3zT_H0m%OHtvdl!DPxUBBXLftT%jKV zRH~ZZU9v4V(}rd#a+S1g_XZ~1uY2wr{vZ*&IbXgrsBIGx?C=@Tl?N4 zn*=k)eF6vzl9R?+fJp3IpKV)lHFI2SEC8otPA=v(3&7E|_CWJXX542C#v&Tmw1xk*?`#VgTn8O&;zPILy@mz${Pz z{UzJ^XG|=Q1Bg^{906ci>GZd|R}<{98FWQhbW?9;ba!ELWdLwtX>N2bZe?^J zG%heMF*7s+TY3Nh120KLK~z{rm6qF1BS8#A^Z&mYq=ayjcmYCSwvRWbsWFq4cBH~? z-^%XpnXvo%`r0kavitu2E}YNjxke_i5s$oFE){E>bwJwD(+A$)-*=y%pQTSD29U&% zB%$_>Brrbx02{<iC@NB$V+mnmhJ1N>8S28tE97%H91yE}Lk^Hf4tIG5m~aagczu1X$w7Z?08lf@gnm&* zI!-5K6v)>|{d(5bz{o3o_-oD4Sce)&YUhC3#WePdCVB!Squ@|~9>{3|AC2;b8|ESh zy@pNVDjXSVnx4KfI9eQ11=y3tkv;53A#HV`G_sa!|R!Z z5}{iQNsPWa+jN>NASTd+tt0Sxett$&9(Bn<@4EnxjjR?)WS~jz0ASMoxcv$9vktH^ zP=5%(*rhtiOS;v-)mDB9$YUoQr~~_^5orSy02z}P(T8sUghSnYqil+u&fS~}#1v3s zvkCo3cjNj4RQDmL$De0TKDoV)auRB|h4iC8Jw44g!1K?^atLi{=UaikGG-Dal3GLp z*8V1p-KY=HEkf4#+!ZBuu$s)XCLs%|3v7_G10$#YAMkZGKV^qJ$Wm@4WI>Z4NBSnv z#I>23mmpVP9+B%(EH1V>&k2=$cxa^CsYeZgoqV>RwcAhZ{Na#PnYx`@Oh1>8{|(VC zh|IXGm!KJ9W>;H57S)fW8P^m@J*DwTIUFQoCW%hqO$8)c$XLL~D51RrvK$1g8c-4G z?6yqKuOWIiC$QN((jjx$3bH7AzmVB|+HGL?S35wQu{jKNtmPWHDtzl0`VNo`X~H<` zAtfPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02y>eSaefwW^{L9 za%BK;VQFr3E^cLXAT%y8E-^DS16z6k00It4L_t(oN5z%Ns=`1JMf3mPx;trOHJ6I-3wOX}<%jHrk>0vYDMCT@p9(;$ z)v{&OCZiZ3z-DD*aScIa8IurWTvMxF5&-p50t!G50fIPhG#V)Z!jbaAA(wz2Y`5DM zMmsdqX0vIbh}7$KJ7@E9o!+bOs`0h}tAGH@PhrjxsMTsFprt05-g8eZkgZ)vfMXm_5ImJu=yPF}Va{2m=Jz z-g`c#uz=b@C<1IsjtNIXvwzh0n70H#@4h~<><`Wn`icO=5_N2bZe?^J zG%heMF*7s+TY3Nh0sTotK~z{rrIrbD!!Qg3`~RQj_(JR&ir_*ps3=p-Y{Ubk4%?mn z?E7A_ZQI56SwSqt6R+2+%|q~0u`gcfSNc#Bo2@jUjgzDvGgMb5ctxvx(xbQbr#}@r z%=w&18%p}61!;r({l0_8;}K`-S7|?NPMb-MfxbW+hd<05z6tiIXg?HTR+}PlyWNiI zIu2d8-Ztpkvmbz;7#tOt?;b;6JndT%gH@5o{pxx0RIf3$PeZ9TK#=dx_;BB2<)s6f zgMCS);`Gmjo__Yd&o%=}fyQCG?;EK4IMne_L*p6H5%|yNvwdnHZD6(UX{;6~tii0d z=iS!W;1G?`#+A|6cf$4beXeLfGf|bpCkOBd`X8e+2Rqfd2J;#Cgg5Qa{V?-?NJMK= z{E}D&i(&)7H-P5V!cGjbI5lAm*N$5NeKX68D(z>sP-?6%q|c7#iRQ~fMGGtaw{fs- a+s`js4|g2{xj!5L0000Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02y>eSaefwW^{L9 za%BK;VQFr3E^cLXAT%y8E-^DS16z6k00QYrL_t(oN4=JdQYtYFhJ6O#|EX}0o623m z8^Xv{p{HMF)06GC2N6C0%s*_CZ1T6;rd(WJUj7=LbHac5l1@tvw9NUf-TGp?^(CE9 z1AdCR{7IvIHar!n9F@1!3aEe2XPf+}JbL!`y$r*%q;uW~)^?IS8 zemkD^7PPS`62ofHClCPXFOdBa$5#ZvdcE$Tz8I;`q7W!R#MRZ6Q1f|IY9$3g6`(iS zcfd8R0z8s+M1V4O7Cqr)=muox7dc9KZLN|3r8=zuPC~JR1N1hu;40=MfLK7PM#&gE zHBr$Y)GjFgHOr+G36nV84`&H@dwcUgf?$)8hiybD0RnCW-)l P00000NkvXXu0mjf^=5t8 literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/customnpcs/textures/marks/star.png b/src/main/resources/assets/customnpcs/textures/marks/star.png new file mode 100644 index 0000000000000000000000000000000000000000..87280663044204d694751724e994431831622d68 GIT binary patch literal 1483 zcmV;+1vL7JP)N2bZe?^J zG%heMF*7s+TY3Nh1xQImK~z{reb!fVR7ng4;2~%5kcwyjLf!~3y!ux`k)gmOgUOhj zF_>U5#`Ml7d~RK4w^mhhCrRf>>b~PaU)HW&J6OMd{p#w^nyy*1W_9Op`S$Hw`~CZO zJ9zNm(7JECZr!@U#*G_mFVbHp_J7KT4IAo^gLy=71f4y5_N@K-^{Xu{Ewy*=-nE=> z+O(;&jr5a3jQ&e<5LSRW#@LuZhYuef%6w&IrICe&g?8xBp~-$={z;@SY*LBN9^3J9 z5e5m8Ir;SIQ~Ub$Yn7jV|NgzbdiAR1oTvn!4rC<#O8h0`h6E{lDJ5rm?AWo%A3uJy z_wV1g<>lp4>n~rvs6yR^`1IRA#xY8gb+Y6X1!zB2pdUVbXfB_=Yk>-=h_!J%%aF+a zIH{752*W;!zPRncW&HBx%j*BnpFi9D{Cu_G&6_uERG}fiBt!ykoq3WgN#>*v8WITx zNS4o^Kd%-L75Mn^V|)Dgaq}`>zkXdWBI0iK<45}Ur4GZ^0nKxYIDhftMSJ`9ZGkAc zXNZ8zt)D!3Qs<*rG8v!$lOmOpq#S*w**kjl=un9PBLU3iiy)CRBvjP=JBBkXg%|`Z~HRo+hIF0E!=A^Qyi@pC#6U=C&K%bo&AVLc*NL z9ywV%^MT4Injf)et&OlkqN=V>*tp?91eApg>>&U^uw?7JPk@AgHQNy2Yo0GBKXDPD z1w6`VUa1K7fQ&>yj@AJuf>LKRplp&kF;7)U+7g?=<;$1bty{O6kzToSrQNx6r{c6PS$6C7zTz$kD4 ztR*F;c;fR3ZbxAI_U(i7=g${Q8JJVxXU?1{=d)+e76?F@B^v>e@kE`ej5DKi1Ss;s ziw<_~+&S2`ZCj1Q;jl&|fMX4m+I#TeK?QM}fhoVh=1LC~nTHP_79nK#n2!TbOiYy4 zAE5j9?;mX4y0u8`*|Vp{v_<(+Tc6lS$oC-=9{=MLcl2DDtAB_7^%JVi49{V2W-qQ zpWg*4Yl=XUh<{?(Pb>tiJ2n;$Cwx<03jikwRbKN7OhV?v zu;gq%?QmY@T9tfc@)4Svni?hsJ8_H>pkgLIJA1*ZKe7Wz^$h`g49!C%5(0i3WS`*d lLVzEYWe5b=_{VlQ_y-=&TIVj!C_DfF002ovPDHLkV1mBm!D0Xa literal 0 HcmV?d00001 From f27c548dff3f653c9d963258baf3b1cba49b0dae Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Sat, 24 Feb 2024 16:52:28 -0600 Subject: [PATCH 27/41] Fixed head interpolating incorrectly when going into an animation. --- .../java/noppes/npcs/mixin/MixinModelRenderer.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java index 5a3becff4..53fb3f200 100644 --- a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java +++ b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java @@ -232,14 +232,16 @@ public abstract class MixinModelRenderer { part.prevRotations[2] = part.prevRotations[2] * (1.0F - speed) + (this.rotateAngleZ * speed); } - if (animDataActive || (partType != EnumAnimationPart.HEAD - && ClientEventHandler.renderingPlayer.getAge() - animData.finishedTime < 20)) { + if (animDataActive || + ClientEventHandler.renderingPlayer.getAge() - animData.finishedTime < 20) { this.rotationPointX = originalPart.pivot[0] + part.prevPivots[0]; this.rotationPointY = originalPart.pivot[1] + part.prevPivots[1]; this.rotationPointZ = originalPart.pivot[2] + part.prevPivots[2]; - this.rotateAngleX = part.prevRotations[0]; - this.rotateAngleY = part.prevRotations[1]; - this.rotateAngleZ = part.prevRotations[2]; + if (animDataActive || partType != EnumAnimationPart.HEAD) { + this.rotateAngleX = part.prevRotations[0]; + this.rotateAngleY = part.prevRotations[1]; + this.rotateAngleZ = part.prevRotations[2]; + } } } else { this.rotateAngleZ += part.prevRotations[2]; From 4ab8fd761adcfe43a17e9b90f14be10ca4a95e7c Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Sun, 25 Feb 2024 23:48:23 -0600 Subject: [PATCH 28/41] Undid huge refactor of the render() function in the ModelRenderer mixin, messed with third person item rendering while animating. --- .../noppes/npcs/mixin/MixinModelRenderer.java | 182 +++++++++--------- 1 file changed, 88 insertions(+), 94 deletions(-) diff --git a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java index 53fb3f200..cc3984779 100644 --- a/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java +++ b/src/main/java/noppes/npcs/mixin/MixinModelRenderer.java @@ -5,10 +5,10 @@ import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelBiped; import net.minecraft.client.model.ModelRenderer; +import noppes.npcs.controllers.data.AnimationData; import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.client.ClientEventHandler; import noppes.npcs.constants.EnumAnimationPart; -import noppes.npcs.controllers.data.AnimationData; import noppes.npcs.controllers.data.Frame; import noppes.npcs.controllers.data.FramePart; import org.lwjgl.opengl.GL11; @@ -81,7 +81,86 @@ public abstract class MixinModelRenderer { float prevAngleY = this.rotateAngleY; float prevAngleZ = this.rotateAngleZ; - this.setAnimationValues(p_78785_1_); + FramePart currentPart = null; + if (ClientEventHandler.renderingNpc != null && ClientEventHandler.renderingNpc.display.animationData.isActive()) { + AnimationData animData = ClientEventHandler.renderingNpc.display.animationData; + EnumAnimationPart partType = this.getPartType((ModelRenderer) (Object) this); + + if (partType != null && animData != null) { + Frame frame = (Frame) animData.animation.currentFrame(); + if (frame.frameParts.containsKey(partType)) { + currentPart = frame.frameParts.get(partType); + currentPart.interpolateOffset(); + currentPart.interpolateAngles(); + this.rotationPointX += currentPart.prevPivots[0]; + this.rotationPointY += currentPart.prevPivots[1]; + this.rotationPointZ += currentPart.prevPivots[2]; + this.rotateAngleX = currentPart.prevRotations[0]; + this.rotateAngleY = currentPart.prevRotations[1]; + this.rotateAngleZ = currentPart.prevRotations[2]; + } + } + } + + if (ClientEventHandler.renderingPlayer != null) { + ClientEventHandler.playerModel = ((ModelRenderer) (Object) this).baseModel; + } + if (ClientEventHandler.renderingPlayer != null && ClientCacheHandler.playerAnimations.containsKey(ClientEventHandler.renderingPlayer.getUniqueID())) { + ClientEventHandler.playerModel = ((ModelRenderer) (Object) this).baseModel; + AnimationData animData = ClientCacheHandler.playerAnimations.get(ClientEventHandler.renderingPlayer.getUniqueID()); + + EnumAnimationPart mainPartType = this.getPlayerPartType((ModelRenderer) (Object) this); + EnumAnimationPart partType = mainPartType != null ? mainPartType : this.pivotEqualPart((ModelRenderer) (Object) this); + if (partType != null && animData != null && animData.animation != null) { + boolean animDataActive = animData.isActive(); + + if (!ClientEventHandler.originalValues.containsKey((ModelRenderer) (Object) this)) { + FramePart part = new FramePart(); + part.pivot = new float[]{prevPointX, prevPointY, prevPointZ}; + part.rotation = new float[]{prevAngleX, prevAngleY, prevAngleZ}; + ClientEventHandler.originalValues.put((ModelRenderer) (Object) this, part); + } + + FramePart originalPart = ClientEventHandler.originalValues.get((ModelRenderer) (Object) this); + Frame frame = (Frame) animData.animation.currentFrame(); + if (!animDataActive && animData.finishedFrame >= 0 && animData.finishedFrame < animData.animation.frames.size()) { + frame = animData.animation.frames.get(animData.finishedFrame); + } + + if (frame != null && frame.frameParts.containsKey(partType)) { + FramePart part = frame.frameParts.get(partType); + if (partType == mainPartType) { + if (animDataActive) { + part.interpolateAngles(); + part.interpolateOffset(); + } else { + float speed = 0.4F; + part.prevPivots[0] = part.prevPivots[0] * (1.0F - speed); + part.prevPivots[1] = part.prevPivots[1] * (1.0F - speed); + part.prevPivots[2] = part.prevPivots[2] * (1.0F - speed); + part.prevRotations[0] = part.prevRotations[0] * (1.0F - speed) + (this.rotateAngleX * speed); + part.prevRotations[1] = part.prevRotations[1] * (1.0F - speed) + (this.rotateAngleY * speed); + part.prevRotations[2] = part.prevRotations[2] * (1.0F - speed) + (this.rotateAngleZ * speed); + } + + if (animDataActive || + ClientEventHandler.renderingPlayer.getAge() - animData.finishedTime < 20) { + this.rotationPointX = originalPart.pivot[0] + part.prevPivots[0]; + this.rotationPointY = originalPart.pivot[1] + part.prevPivots[1]; + this.rotationPointZ = originalPart.pivot[2] + part.prevPivots[2]; + if (animDataActive || partType != EnumAnimationPart.HEAD) { + this.rotateAngleX = part.prevRotations[0]; + this.rotateAngleY = part.prevRotations[1]; + this.rotateAngleZ = part.prevRotations[2]; + } + } + } else { + currentPart = part; + this.rotateAngleZ += part.prevRotations[2]; + } + } + } + } GL11.glTranslatef(this.offsetX, this.offsetY, this.offsetZ); int i; @@ -154,98 +233,13 @@ public abstract class MixinModelRenderer { GL11.glPopMatrix(); } - this.rotationPointX = prevPointX; - this.rotationPointY = prevPointY; - this.rotationPointZ = prevPointZ; - this.rotateAngleX = prevAngleX; - this.rotateAngleY = prevAngleY; - this.rotateAngleZ = prevAngleZ; - } - } - } - - private void setAnimationValues(float p_78785_1_) { - float prevPointX = this.rotationPointX; - float prevPointY = this.rotationPointY; - float prevPointZ = this.rotationPointZ; - float prevAngleX = this.rotateAngleX; - float prevAngleY = this.rotateAngleY; - float prevAngleZ = this.rotateAngleZ; - - if (ClientEventHandler.renderingNpc != null && ClientEventHandler.renderingNpc.display.animationData.isActive()) { - AnimationData animData = ClientEventHandler.renderingNpc.display.animationData; - EnumAnimationPart partType = this.getPartType((ModelRenderer) (Object) this); - - if (partType != null && animData != null) { - Frame frame = (Frame) animData.animation.currentFrame(); - if (frame.frameParts.containsKey(partType)) { - FramePart currentPart = frame.frameParts.get(partType); - currentPart.interpolateOffset(); - currentPart.interpolateAngles(); - - this.rotationPointX += currentPart.prevPivots[0]; - this.rotationPointY += currentPart.prevPivots[1]; - this.rotationPointZ += currentPart.prevPivots[2]; - this.rotateAngleX = currentPart.prevRotations[0]; - this.rotateAngleY = currentPart.prevRotations[1]; - this.rotateAngleZ = currentPart.prevRotations[2]; - } - } - } - - if (ClientEventHandler.renderingPlayer != null && ClientCacheHandler.playerAnimations.containsKey(ClientEventHandler.renderingPlayer.getUniqueID())) { - ClientEventHandler.playerModel = ((ModelRenderer) (Object) this).baseModel; - AnimationData animData = ClientCacheHandler.playerAnimations.get(ClientEventHandler.renderingPlayer.getUniqueID()); - - EnumAnimationPart mainPartType = this.getPlayerPartType((ModelRenderer) (Object) this); - EnumAnimationPart partType = mainPartType != null ? mainPartType : this.pivotEqualPart((ModelRenderer) (Object) this); - - if (partType != null && animData != null && animData.animation != null) { - boolean animDataActive = animData.isActive(); - - if (!ClientEventHandler.originalValues.containsKey((ModelRenderer) (Object) this)) { - FramePart part = new FramePart(); - part.pivot = new float[]{prevPointX, prevPointY, prevPointZ}; - part.rotation = new float[]{prevAngleX, prevAngleY, prevAngleZ}; - ClientEventHandler.originalValues.put((ModelRenderer) (Object) this, part); - } - - FramePart originalPart = ClientEventHandler.originalValues.get((ModelRenderer) (Object) this); - Frame frame = (Frame) animData.animation.currentFrame(); - if (!animDataActive && animData.finishedFrame >= 0 && animData.finishedFrame < animData.animation.frames.size()) { - frame = animData.animation.frames.get(animData.finishedFrame); - } - - if (frame != null && frame.frameParts.containsKey(partType)) { - FramePart part = frame.frameParts.get(partType); - if (partType == mainPartType) { - if (animDataActive) { - part.interpolateAngles(); - part.interpolateOffset(); - } else { - float speed = 0.4F; - part.prevPivots[0] = part.prevPivots[0] * (1.0F - speed); - part.prevPivots[1] = part.prevPivots[1] * (1.0F - speed); - part.prevPivots[2] = part.prevPivots[2] * (1.0F - speed); - part.prevRotations[0] = part.prevRotations[0] * (1.0F - speed) + (this.rotateAngleX * speed); - part.prevRotations[1] = part.prevRotations[1] * (1.0F - speed) + (this.rotateAngleY * speed); - part.prevRotations[2] = part.prevRotations[2] * (1.0F - speed) + (this.rotateAngleZ * speed); - } - - if (animDataActive || - ClientEventHandler.renderingPlayer.getAge() - animData.finishedTime < 20) { - this.rotationPointX = originalPart.pivot[0] + part.prevPivots[0]; - this.rotationPointY = originalPart.pivot[1] + part.prevPivots[1]; - this.rotationPointZ = originalPart.pivot[2] + part.prevPivots[2]; - if (animDataActive || partType != EnumAnimationPart.HEAD) { - this.rotateAngleX = part.prevRotations[0]; - this.rotateAngleY = part.prevRotations[1]; - this.rotateAngleZ = part.prevRotations[2]; - } - } - } else { - this.rotateAngleZ += part.prevRotations[2]; - } + if (currentPart != null) { + this.rotationPointX = prevPointX; + this.rotationPointY = prevPointY; + this.rotationPointZ = prevPointZ; + this.rotateAngleX = prevAngleX; + this.rotateAngleY = prevAngleY; + this.rotateAngleZ = prevAngleZ; } } } From d7f4de989a695d9111091ff846be66791bbe2158 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 26 Feb 2024 16:55:42 -0600 Subject: [PATCH 29/41] Fixed incorrect angles rendering with full model angles in animations on players. --- src/main/java/noppes/npcs/mixin/MixinRenderPlayer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/mixin/MixinRenderPlayer.java b/src/main/java/noppes/npcs/mixin/MixinRenderPlayer.java index bd011e296..440743817 100644 --- a/src/main/java/noppes/npcs/mixin/MixinRenderPlayer.java +++ b/src/main/java/noppes/npcs/mixin/MixinRenderPlayer.java @@ -32,8 +32,8 @@ public abstract class MixinRenderPlayer { part.interpolateAngles(); float pi = 180 / (float) Math.PI; GL11.glTranslatef(part.prevPivots[0], part.prevPivots[1], part.prevPivots[2]); - GL11.glRotatef(part.prevRotations[0] * pi, 1, 0, 0); - GL11.glRotatef(part.prevRotations[1] * pi, 0, 1, 0); + GL11.glRotatef(-part.prevRotations[0] * pi, 1, 0, 0); + GL11.glRotatef(-part.prevRotations[1] * pi, 0, 1, 0); GL11.glRotatef(part.prevRotations[2] * pi, 0, 0, 1); } } From fd3a9cc4bc1348a2e47ff546414179c72260f476 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 26 Feb 2024 17:33:16 -0600 Subject: [PATCH 30/41] Changed player animation mixin to mixin setLivingAnimations() in the model base class instead. Makes animations be one-to-one between players and NPCs. --- .../npcs/mixin/CustomNPCsMixinPlugin.java | 2 +- ...nRenderPlayer.java => MixinModelBase.java} | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) rename src/main/java/noppes/npcs/mixin/{MixinRenderPlayer.java => MixinModelBase.java} (66%) diff --git a/src/main/java/noppes/npcs/mixin/CustomNPCsMixinPlugin.java b/src/main/java/noppes/npcs/mixin/CustomNPCsMixinPlugin.java index 04d31fac2..77554d921 100644 --- a/src/main/java/noppes/npcs/mixin/CustomNPCsMixinPlugin.java +++ b/src/main/java/noppes/npcs/mixin/CustomNPCsMixinPlugin.java @@ -49,7 +49,7 @@ public class CustomNPCsMixinPlugin implements IMixinConfigPlugin { } if (ConfigMixin.AnimationMixin) { mixins.add("MixinModelRenderer"); - mixins.add("MixinRenderPlayer"); + mixins.add("MixinModelBase"); } if (ConfigMixin.FirstPersonAnimationMixin) { mixins.add("MixinItemRenderer"); diff --git a/src/main/java/noppes/npcs/mixin/MixinRenderPlayer.java b/src/main/java/noppes/npcs/mixin/MixinModelBase.java similarity index 66% rename from src/main/java/noppes/npcs/mixin/MixinRenderPlayer.java rename to src/main/java/noppes/npcs/mixin/MixinModelBase.java index 440743817..6d8dda17c 100644 --- a/src/main/java/noppes/npcs/mixin/MixinRenderPlayer.java +++ b/src/main/java/noppes/npcs/mixin/MixinModelBase.java @@ -2,8 +2,8 @@ package noppes.npcs.mixin; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.client.entity.AbstractClientPlayer; -import net.minecraft.client.renderer.entity.RenderPlayer; +import net.minecraft.client.model.ModelBase; +import net.minecraft.entity.EntityLivingBase; import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.constants.EnumAnimationPart; import noppes.npcs.controllers.data.AnimationData; @@ -15,15 +15,15 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(value = RenderPlayer.class) -public abstract class MixinRenderPlayer { +@Mixin(value = ModelBase.class) +public abstract class MixinModelBase { @SideOnly(Side.CLIENT) - @Inject(method = "rotateCorpse*", at = @At(value = "TAIL")) - protected void modelDataRotations(AbstractClientPlayer p_77043_1_, float p_77043_2_, float p_77043_3_, float p_77043_4_, CallbackInfo callbackInfo) + @Inject(method = "setLivingAnimations", at = @At(value = "TAIL")) + public void setLivingAnimations(EntityLivingBase p_78086_1_, float p_78086_2_, float p_78086_3_, float p_78086_4_, CallbackInfo callbackInfo) { - if (ClientCacheHandler.playerAnimations.containsKey(p_77043_1_.getUniqueID())) { - AnimationData animData = ClientCacheHandler.playerAnimations.get(p_77043_1_.getUniqueID()); + if (ClientCacheHandler.playerAnimations.containsKey(p_78086_1_.getUniqueID())) { + AnimationData animData = ClientCacheHandler.playerAnimations.get(p_78086_1_.getUniqueID()); if (animData != null && animData.isActive()) { Frame frame = (Frame) animData.animation.currentFrame(); if (frame.frameParts.containsKey(EnumAnimationPart.FULL_MODEL)) { @@ -32,8 +32,8 @@ public abstract class MixinRenderPlayer { part.interpolateAngles(); float pi = 180 / (float) Math.PI; GL11.glTranslatef(part.prevPivots[0], part.prevPivots[1], part.prevPivots[2]); - GL11.glRotatef(-part.prevRotations[0] * pi, 1, 0, 0); - GL11.glRotatef(-part.prevRotations[1] * pi, 0, 1, 0); + GL11.glRotatef(part.prevRotations[0] * pi, 1, 0, 0); + GL11.glRotatef(part.prevRotations[1] * pi, 0, 1, 0); GL11.glRotatef(part.prevRotations[2] * pi, 0, 0, 1); } } From c24a900f18fd3d322bf592074f1fce0a3fb016b4 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Tue, 27 Feb 2024 02:17:21 -0600 Subject: [PATCH 31/41] Fixed first person animations not rendering correctly when rotating the model about the Y axis --- src/main/java/noppes/npcs/mixin/MixinItemRenderer.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/mixin/MixinItemRenderer.java b/src/main/java/noppes/npcs/mixin/MixinItemRenderer.java index 7cb4d7b84..3e33eb7e3 100644 --- a/src/main/java/noppes/npcs/mixin/MixinItemRenderer.java +++ b/src/main/java/noppes/npcs/mixin/MixinItemRenderer.java @@ -122,8 +122,16 @@ public abstract class MixinItemRenderer { float f4 = entityplayersp.prevRenderArmYaw + (entityplayersp.renderArmYaw - entityplayersp.prevRenderArmYaw) * partialRenderTick; GL11.glRotatef((entityclientplayermp.rotationPitch - f3) * 0.1F, 1.0F, 0.0F, 0.0F); GL11.glRotatef((entityclientplayermp.rotationYaw - f4) * 0.1F, 0.0F, 1.0F, 0.0F); - ItemStack itemstack = itemRenderer.itemToRender; + if (animData != null && animData.isActive()) { + if (frame.frameParts.containsKey(EnumAnimationPart.FULL_MODEL)) { + FramePart part = frame.frameParts.get(EnumAnimationPart.FULL_MODEL); + float pi = 180 / (float) Math.PI; + GL11.glRotatef(-part.prevRotations[1] * pi, 0, 1, 0); + } + } + + ItemStack itemstack = itemRenderer.itemToRender; int i = Minecraft.getMinecraft().theWorld.getLightBrightnessForSkyBlocks(MathHelper.floor_double(entityclientplayermp.posX), MathHelper.floor_double(entityclientplayermp.posY), MathHelper.floor_double(entityclientplayermp.posZ), 0); int j = i % 65536; int k = i / 65536; From df88e5b4f9f0a42e4ddcebd3863c194b58647383 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Tue, 27 Feb 2024 21:18:53 -0600 Subject: [PATCH 32/41] Implemented banned classes config for Nashorn scripts. --- .../java/noppes/npcs/config/ConfigScript.java | 15 +++++++++++++ .../npcs/controllers/ScriptController.java | 21 +++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/config/ConfigScript.java b/src/main/java/noppes/npcs/config/ConfigScript.java index 3dcc5f4a2..655a55635 100644 --- a/src/main/java/noppes/npcs/config/ConfigScript.java +++ b/src/main/java/noppes/npcs/config/ConfigScript.java @@ -11,6 +11,8 @@ import noppes.npcs.config.legacy.LegacyConfig; import org.apache.logging.log4j.Level; import java.io.File; +import java.util.Arrays; +import java.util.HashSet; import java.util.UUID; public class ConfigScript @@ -50,6 +52,9 @@ public class ConfigScript public static Property ScriptDevIDsProperty; public static String ScriptDevIDs = ""; + public static Property BannedClassesProperty; + public final static HashSet BannedClasses = new HashSet<>(); + public static void init(File configFile) { config = new Configuration(configFile); @@ -133,6 +138,16 @@ public class ConfigScript } } catch (Exception ignored) {} + BannedClassesProperty = config.get(CUSTOMIZATION, "Banned Classes", "java.net.URL,java.net.URI", + "Comma separated list of classes that cannot be used in scripts through Java.for().\n" + + "Classes must be fully written out with library names preceding them.\n" + + "This is a feature ONLY AVAILABLE ON NASHORN."); + String bannedClassesString = BannedClassesProperty.getString(); + + try { + BannedClasses.clear(); + BannedClasses.addAll(Arrays.asList(bannedClassesString.split(","))); + } catch (Exception ignored) {} } catch (Exception e) { diff --git a/src/main/java/noppes/npcs/controllers/ScriptController.java b/src/main/java/noppes/npcs/controllers/ScriptController.java index bcd1c66d2..ddd75ab9a 100644 --- a/src/main/java/noppes/npcs/controllers/ScriptController.java +++ b/src/main/java/noppes/npcs/controllers/ScriptController.java @@ -1,6 +1,8 @@ package noppes.npcs.controllers; import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import jdk.nashorn.api.scripting.ClassFilter; +import jdk.nashorn.api.scripting.NashornScriptEngineFactory; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -248,7 +250,22 @@ public class ScriptController { private static final List nashornNames = immutableList("nashorn", "Nashorn", "js", "JS", "JavaScript", "javascript", "ECMAScript", "ecmascript"); public ScriptEngine getEngineByName(String language) { if (nashornNames.contains(language) && this.nashornFactory != null) { - ScriptEngine scriptEngine = this.nashornFactory.getScriptEngine(); + ScriptEngine scriptEngine; + + try { + ClassFilter filter = s -> { + for (String className : ConfigScript.BannedClasses) { + if (s.compareTo(className) == 0) { + return false; + } + } + return true; + }; + NashornScriptEngineFactory nashornScriptEngineFactory = (NashornScriptEngineFactory) this.nashornFactory; + scriptEngine = nashornScriptEngineFactory.getScriptEngine(filter); + } catch (Exception e) { + scriptEngine = this.nashornFactory.getScriptEngine(); + } scriptEngine.setBindings(this.manager.getBindings(), ScriptContext.GLOBAL_SCOPE); return scriptEngine; } @@ -300,4 +317,4 @@ public class ScriptController { shouldSave = false; } -} \ No newline at end of file +} From 27359a429d0c4ce12bc632c460fc4ab8e31625ab Mon Sep 17 00:00:00 2001 From: Kam Date: Wed, 28 Feb 2024 20:58:00 -0500 Subject: [PATCH 33/41] Beta 5 Gradle --- build.gradle | 2 +- .../noppes/npcs/ScriptItemEventHandler.java | 54 +++++++++++-------- .../controllers/PlayerDataController.java | 3 -- .../npcs/controllers/data/PlayerData.java | 4 +- .../controllers/data/PlayerDataScript.java | 1 - 5 files changed, 34 insertions(+), 30 deletions(-) diff --git a/build.gradle b/build.gradle index 0495effa2..de188833f 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id 'idea' } -version = "1.9-beta6" +version = "1.9-beta5" group= "kamkeel.customnpc-plus" archivesBaseName = "CustomNPC-Plus" diff --git a/src/main/java/noppes/npcs/ScriptItemEventHandler.java b/src/main/java/noppes/npcs/ScriptItemEventHandler.java index 2d7b3cafc..63cae0ee3 100644 --- a/src/main/java/noppes/npcs/ScriptItemEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptItemEventHandler.java @@ -124,30 +124,38 @@ public class ScriptItemEventHandler { if(event.entityPlayer.worldObj.isRemote && event.entityPlayer.worldObj instanceof WorldServer) return; - if(event.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR){ - PlayerDataScript handler = PlayerDataController.Instance.getPlayerData(event.entityPlayer).scriptData; - if(handler.hadInteract) { - handler.hadInteract = false; - return; + if (PlayerDataController.Instance != null) { + if(event.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR){ + PlayerData handler = PlayerDataController.Instance.getPlayerData(event.entityPlayer); + if(handler == null) + return; + + if(handler.hadInteract) { + handler.hadInteract = false; + return; + } + try { + if (event.entityPlayer.getHeldItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) { + IItemCustom isw = ItemScripted.GetWrapper(event.entityPlayer.getHeldItem()); + ItemEvent.RightClickEvent eve = new ItemEvent.RightClickEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 0, null); + event.setCanceled(EventHooks.onScriptItemRightClick(isw, eve)); + } + } catch(Exception e) {} + } + else if(event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK){ + PlayerData handler = PlayerDataController.Instance.getPlayerData(event.entityPlayer); + if(handler == null) + return; + + handler.hadInteract = true; + try { + if (event.entityPlayer.getHeldItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) { + IItemCustom isw = ItemScripted.GetWrapper(event.entityPlayer.getHeldItem()); + ItemEvent.RightClickEvent eve = new ItemEvent.RightClickEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 2, NpcAPI.Instance().getIBlock((IWorld) NpcAPI.Instance().getIWorld(event.world), event.x, event.y, event.z)); + event.setCanceled(EventHooks.onScriptItemRightClick(isw, eve)); + } + } catch(Exception e) {} } - try { - if (event.entityPlayer.getHeldItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) { - IItemCustom isw = ItemScripted.GetWrapper(event.entityPlayer.getHeldItem()); - ItemEvent.RightClickEvent eve = new ItemEvent.RightClickEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 0, null); - event.setCanceled(EventHooks.onScriptItemRightClick(isw, eve)); - } - } catch(Exception e) {} - } - else if(event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK){ - PlayerDataScript handler = PlayerDataController.Instance.getPlayerData(event.entityPlayer).scriptData; - handler.hadInteract = true; - try { - if (event.entityPlayer.getHeldItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) { - IItemCustom isw = ItemScripted.GetWrapper(event.entityPlayer.getHeldItem()); - ItemEvent.RightClickEvent eve = new ItemEvent.RightClickEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 2, NpcAPI.Instance().getIBlock((IWorld) NpcAPI.Instance().getIWorld(event.world), event.x, event.y, event.z)); - event.setCanceled(EventHooks.onScriptItemRightClick(isw, eve)); - } - } catch(Exception e) {} } } diff --git a/src/main/java/noppes/npcs/controllers/PlayerDataController.java b/src/main/java/noppes/npcs/controllers/PlayerDataController.java index ecf682fbb..f6ba49118 100644 --- a/src/main/java/noppes/npcs/controllers/PlayerDataController.java +++ b/src/main/java/noppes/npcs/controllers/PlayerDataController.java @@ -291,7 +291,6 @@ public class PlayerDataController { if(data != null){ if(data.player == null){ data.player = player; - data.scriptData = new PlayerDataScript(player); } return data; } @@ -300,13 +299,11 @@ public class PlayerDataController { if(data == null){ player.registerExtendedProperties("CustomNpcsData", data = new PlayerData()); data.player = player; - data.scriptData = new PlayerDataScript(player); data.load(); } if(data.player == null){ data.player = player; - data.scriptData = new PlayerDataScript(player); } return data; } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerData.java b/src/main/java/noppes/npcs/controllers/data/PlayerData.java index f700ed183..6990cc219 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerData.java @@ -41,7 +41,6 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData { public PlayerItemGiverData itemgiverData = new PlayerItemGiverData(this); public PlayerMailData mailData = new PlayerMailData(this); public AnimationData animationData = new AnimationData(this); - public PlayerDataScript scriptData; public DataTimers timers = new DataTimers(this); public DataSkinOverlays skinOverlays = new DataSkinOverlays(this); @@ -61,8 +60,9 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData { public int companionID = 0; public boolean isGUIOpen = false; + public boolean hadInteract = true; - public ScreenSize screenSize = new ScreenSize(-1,-1); + public ScreenSize screenSize = new ScreenSize(-1,-1); public void onLogin() { diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java index f51b68748..85096dfe0 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java @@ -26,7 +26,6 @@ public class PlayerDataScript implements INpcScriptHandler { private IPlayer playerAPI; private long lastPlayerUpdate = 0L; public long lastInited = -1L; - public boolean hadInteract = true; public boolean enabled = false; public PlayerDataScript(EntityPlayer player) { From c2e4213df5112240512220e6984a063dfb742305 Mon Sep 17 00:00:00 2001 From: Kam Date: Wed, 28 Feb 2024 23:47:24 -0500 Subject: [PATCH 34/41] Better Client Skin Loading for Cached Skins --- .../npcs/client/ClientCacheHandler.java | 6 +++ .../npcs/client/renderer/ImageData.java | 2 +- .../client/renderer/RenderNPCInterface.java | 37 ++++++++++--------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/main/java/noppes/npcs/client/ClientCacheHandler.java b/src/main/java/noppes/npcs/client/ClientCacheHandler.java index 3e81bc125..dd55f7b5b 100644 --- a/src/main/java/noppes/npcs/client/ClientCacheHandler.java +++ b/src/main/java/noppes/npcs/client/ClientCacheHandler.java @@ -43,6 +43,12 @@ public class ClientCacheHandler { } } + public static boolean isCachedNPC(ResourceLocation resource) { + synchronized (imageDataCache) { + return imageDataCache.containsKey(resource.getResourcePath()); + } + } + public static void clearCache() { ClientCacheHandler.imageDataCache.clear(); ClientCacheHandler.animationCache.clear(); diff --git a/src/main/java/noppes/npcs/client/renderer/ImageData.java b/src/main/java/noppes/npcs/client/renderer/ImageData.java index db80df47b..5ca7cf33c 100644 --- a/src/main/java/noppes/npcs/client/renderer/ImageData.java +++ b/src/main/java/noppes/npcs/client/renderer/ImageData.java @@ -83,7 +83,7 @@ public class ImageData { } } - private ResourceLocation getLocation() { + public ResourceLocation getLocation() { return this.isUrl && this.imageDownloadAlt.getBufferedImage() == null ? null : this.location; } diff --git a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java index 5dc55057a..b611c9d5f 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java @@ -320,8 +320,6 @@ public class RenderNPCInterface extends RenderLiving{ } else { npc.textureLocation = new ResourceLocation(npc.display.texture); } - } else if(LastTextureTick < 5) { //fixes request flood somewhat - return AbstractClientPlayer.locationStevePng; } else if(npc.display.skinType == 1 && npc.display.playerProfile != null) { Minecraft minecraft = Minecraft.getMinecraft(); Map map = minecraft.func_152342_ad().func_152788_a(npc.display.playerProfile); @@ -330,22 +328,25 @@ public class RenderNPCInterface extends RenderLiving{ } LastTextureTick = 0; } else if (npc.display.skinType == 2 || npc.display.skinType == 3) { - try { - MessageDigest digest = MessageDigest.getInstance("MD5"); - byte[] hash = digest.digest(npc.display.url.getBytes("UTF-8")); - StringBuilder sb = new StringBuilder(2*hash.length); - for (byte b : hash) { - sb.append(String.format("%02x", b&0xff)); - } - if (npc.display.skinType == 2) { - npc.textureLocation = new ResourceLocation("skins/" + sb.toString()); - ClientCacheHandler.getNPCTexture(npc.display.url, false, npc.textureLocation); - } else { - npc.textureLocation = new ResourceLocation("skins64/" + sb.toString()); - ClientCacheHandler.getNPCTexture(npc.display.url, true, npc.textureLocation); - } - LastTextureTick = 0; - } catch(Exception ignored){} + ResourceLocation location = new ResourceLocation("skins/" + (npc.display.modelType + npc.display.url).hashCode()); + // If URL Empty Steve + if(npc.display.url.isEmpty()){ return AbstractClientPlayer.locationStevePng; } + // If URL Cached then grab it + else if(ClientCacheHandler.isCachedNPC(location)){ + try { + npc.textureLocation = ClientCacheHandler.getNPCTexture(npc.display.url, npc.display.modelType > 0, location).getLocation(); + } catch(Exception ignored){} + } + // For New URL Requests do not spam it + else if(LastTextureTick < 5) { //fixes request flood somewhat + return AbstractClientPlayer.locationStevePng; + } + else { + try { + npc.textureLocation = ClientCacheHandler.getNPCTexture(npc.display.url, npc.display.modelType > 0, location).getLocation(); + LastTextureTick = 0; + } catch(Exception ignored){} + } } else { return AbstractClientPlayer.locationStevePng; } From c692f86ff14e85ae4a07ca9039c681fe1d6590ec Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 29 Feb 2024 00:55:13 -0500 Subject: [PATCH 35/41] Add Lang to Marks --- src/main/resources/assets/customnpcs/lang/en_US.lang | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index f929b3bdb..f8ee18cda 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -1167,5 +1167,11 @@ markov.gender.name=Gender markov.gender.either=Either markov.gender.female=Female markov.gender.male=Male - markov.generate=Generate + +mark.question=Question +mark.exclamation=Exclamation +mark.pointer=Pointer +mark.skull=Skull +mark.cross=Cross +mark.star=Star From d76416593f91c390c472b9bfc49142a1bad2fbd6 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 29 Feb 2024 00:57:49 -0500 Subject: [PATCH 36/41] Better Imgur Handling --- .../noppes/npcs/client/ImageDownloadAlt.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/client/ImageDownloadAlt.java b/src/main/java/noppes/npcs/client/ImageDownloadAlt.java index 8d8a510b2..2274682e8 100644 --- a/src/main/java/noppes/npcs/client/ImageDownloadAlt.java +++ b/src/main/java/noppes/npcs/client/ImageDownloadAlt.java @@ -124,13 +124,21 @@ public class ImageDownloadAlt extends SimpleTexture try { - connection = (HttpURLConnection)(new URL(ImageDownloadAlt.this.imageUrl)).openConnection(Minecraft.getMinecraft().getProxy()); + URL url = new URL(ImageDownloadAlt.this.imageUrl); + connection = (HttpURLConnection)(url).openConnection(Minecraft.getMinecraft().getProxy()); connection.setDoInput(true); connection.setDoOutput(false); connection.setRequestProperty("Content-Type", "image/png"); connection.setRequestProperty("Expect", "100-continue"); //connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:19.0) Gecko/20100101 Firefox/19.0"); - connection.setRequestProperty("User-Agent", "Mozilla/5.0"); + + // Set user agent + if (isImgurLink(url)) { + connection.setRequestProperty("User-Agent", "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)"); + } + else { + connection.setRequestProperty("User-Agent", "Mozilla/5.0"); + } connection.connect(); if (connection.getResponseCode() / 100 != 2) @@ -175,4 +183,9 @@ public class ImageDownloadAlt extends SimpleTexture this.imageThread.setDaemon(true); this.imageThread.start(); } + + // Check if the URL is an Imgur link + private static boolean isImgurLink(URL url) { + return url.getHost().endsWith("imgur.com"); + } } From ed09a3ad33bd7c58f3f1f9817984cb50454abcd8 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 29 Feb 2024 20:23:42 -0500 Subject: [PATCH 37/41] EnableBannedClasses Config Option --- .../java/noppes/npcs/config/ConfigScript.java | 16 +++++++---- .../npcs/controllers/ScriptController.java | 27 ++++++++++--------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/main/java/noppes/npcs/config/ConfigScript.java b/src/main/java/noppes/npcs/config/ConfigScript.java index 655a55635..32af30968 100644 --- a/src/main/java/noppes/npcs/config/ConfigScript.java +++ b/src/main/java/noppes/npcs/config/ConfigScript.java @@ -52,6 +52,9 @@ public class ConfigScript public static Property ScriptDevIDsProperty; public static String ScriptDevIDs = ""; + public static Property EnableBannedClassesProperty; + public static boolean EnableBannedClasses = false; + public static Property BannedClassesProperty; public final static HashSet BannedClasses = new HashSet<>(); @@ -100,6 +103,14 @@ public class ConfigScript "If left empty and ScriptsOpsOnly is false, anyone can see and edit scripts with a scripter."); ScriptDevIDs = ScriptDevIDsProperty.getString(); + EnableBannedClassesProperty = config.get(CUSTOMIZATION, "Enable Banned Classes", false, "Enables the Banned Classes Functionality"); + EnableBannedClasses = EnableBannedClassesProperty.getBoolean(false); + + BannedClassesProperty = config.get(CUSTOMIZATION, "Banned Classes", "java.net.URL,java.net.URI", + "Comma separated list of classes that cannot be used in scripts through Java.for().\n" + + "Classes must be fully written out with library names preceding them.\n" + + "This is a feature ONLY AVAILABLE ON NASHORN."); + // Convert to Legacy if(CustomNpcs.legacyExist){ ScriptingEnabled = LegacyConfig.ScriptingEnabled; @@ -138,12 +149,7 @@ public class ConfigScript } } catch (Exception ignored) {} - BannedClassesProperty = config.get(CUSTOMIZATION, "Banned Classes", "java.net.URL,java.net.URI", - "Comma separated list of classes that cannot be used in scripts through Java.for().\n" + - "Classes must be fully written out with library names preceding them.\n" + - "This is a feature ONLY AVAILABLE ON NASHORN."); String bannedClassesString = BannedClassesProperty.getString(); - try { BannedClasses.clear(); BannedClasses.addAll(Arrays.asList(bannedClassesString.split(","))); diff --git a/src/main/java/noppes/npcs/controllers/ScriptController.java b/src/main/java/noppes/npcs/controllers/ScriptController.java index ddd75ab9a..2ff38be7b 100644 --- a/src/main/java/noppes/npcs/controllers/ScriptController.java +++ b/src/main/java/noppes/npcs/controllers/ScriptController.java @@ -251,19 +251,22 @@ public class ScriptController { public ScriptEngine getEngineByName(String language) { if (nashornNames.contains(language) && this.nashornFactory != null) { ScriptEngine scriptEngine; - - try { - ClassFilter filter = s -> { - for (String className : ConfigScript.BannedClasses) { - if (s.compareTo(className) == 0) { - return false; + if(ConfigScript.EnableBannedClasses){ + try { + ClassFilter filter = s -> { + for (String className : ConfigScript.BannedClasses) { + if (s.compareTo(className) == 0) { + return false; + } } - } - return true; - }; - NashornScriptEngineFactory nashornScriptEngineFactory = (NashornScriptEngineFactory) this.nashornFactory; - scriptEngine = nashornScriptEngineFactory.getScriptEngine(filter); - } catch (Exception e) { + return true; + }; + NashornScriptEngineFactory nashornScriptEngineFactory = (NashornScriptEngineFactory) this.nashornFactory; + scriptEngine = nashornScriptEngineFactory.getScriptEngine(filter); + } catch (Exception e) { + scriptEngine = this.nashornFactory.getScriptEngine(); + } + } else { scriptEngine = this.nashornFactory.getScriptEngine(); } scriptEngine.setBindings(this.manager.getBindings(), ScriptContext.GLOBAL_SCOPE); From 702785476e6e2a14aed7952947fa9b4aeccf6aff Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 29 Feb 2024 20:33:29 -0500 Subject: [PATCH 38/41] Better Advanced GUI Organization --- .../client/gui/mainmenu/GuiNpcAdvanced.java | 20 +++++++++---------- .../assets/customnpcs/lang/en_US.lang | 1 + 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAdvanced.java b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAdvanced.java index 51ff99278..d05e8a0a5 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAdvanced.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAdvanced.java @@ -28,25 +28,25 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData public void initGui(){ super.initGui(); int y = guiTop + 10; - int gap = 21; this.addButton(new GuiNpcButton(3, guiLeft + 85 + 160, y, 52, 20, "selectServer.edit")); this.addButton(new GuiNpcButton(8, guiLeft + 85, y,155,20, new String[]{"role.none","role.trader","role.follower","role.bank","role.transporter", "role.mailman", NoppesStringUtils.translate("role.companion", "(WIP)")},npc.advanced.role.ordinal())); getButton(3).setEnabled(npc.advanced.role != EnumRoleType.None && npc.advanced.role != EnumRoleType.Postman); - this.addButton(new GuiNpcButton(4, guiLeft + 85 + 160, y += gap, 52, 20, "selectServer.edit")); + this.addButton(new GuiNpcButton(4, guiLeft + 85 + 160, y += 22, 52, 20, "selectServer.edit")); this.addButton(new GuiNpcButton(5, guiLeft + 85, y,155,20, new String[]{"job.none","job.bard","job.healer","job.guard","job.itemgiver","role.follower", "job.spawner", "job.conversation", "job.chunkloader"},npc.advanced.job.ordinal())); getButton(4).setEnabled(npc.advanced.job != EnumJobType.None && npc.advanced.job != EnumJobType.ChunkLoader); - this.addButton(new GuiNpcButton(7, guiLeft + 85, y += gap, 214, 20, "advanced.lines")); - this.addButton(new GuiNpcButton(9, guiLeft + 85, y += gap, 214, 20, "menu.factions")); - this.addButton(new GuiNpcButton(10, guiLeft + 85, y += gap, 214, 20, "dialog.dialogs")); - this.addButton(new GuiNpcButton(11, guiLeft + 85, y += gap, 214, 20, "advanced.sounds")); - this.addButton(new GuiNpcButton(12, guiLeft + 85, y += gap, 214, 20, "advanced.night")); - this.addButton(new GuiNpcButton(13, guiLeft + 85, y += gap, 214, 20, "global.linked")); - this.addButton(new GuiNpcButton(14, guiLeft + 85, y += gap, 214, 20, "menu.tags")); + this.addButton(new GuiNpcButton(7, guiLeft + 15, y += 22, 190, 20, "advanced.lines")); + this.addButton(new GuiNpcButton(9, guiLeft + 208, y, 190, 20, "menu.factions")); - // FIX THIS KAM + this.addButton(new GuiNpcButton(10, guiLeft + 15, y += 22, 190, 20, "dialog.dialogs")); + this.addButton(new GuiNpcButton(11, guiLeft + 208, y, 190, 20, "advanced.sounds")); + + this.addButton(new GuiNpcButton(12, guiLeft + 15, y += 22, 190, 20, "advanced.night")); + this.addButton(new GuiNpcButton(13, guiLeft + 208, y, 190, 20, "global.linked")); + + this.addButton(new GuiNpcButton(14, guiLeft + 15, y += 22, 190, 20, "menu.tags")); this.addButton(new GuiNpcButton(15, guiLeft + 208, y, 190, 20, "advanced.marks")); } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index f8ee18cda..733af8f63 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -421,6 +421,7 @@ advanced.editingmode=EditingMode advanced.loadday=Load Day advanced.loadnight=Load Night advanced.haspitch=Has Pitch +advanced.marks=Marks faction.hostiles=Hostile Factions faction.unfriendly=Unfriendly From 0def6eafb731499110ad14ef9370e4fcf342a8e1 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 29 Feb 2024 20:34:49 -0500 Subject: [PATCH 39/41] PRE: Hoverable Button --- .../npcs/client/gui/util/GuiNPCInterface.java | 4 + .../npcs/client/gui/util/GuiNpcButton.java | 115 ++++++++++++++++++ 2 files changed, 119 insertions(+) diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java index 2f15eca88..b14814ff0 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java @@ -253,6 +253,10 @@ public abstract class GuiNPCInterface extends GuiScreen if(scroll.hoverableText){ scroll.drawHover(i, j, f, hasSubGui()?0:this.mouseWheel); } + for(GuiNpcButton button : buttons.values()) + if(!button.hoverableText.isEmpty()){ + button.drawHover(i, j, hasSubGui()); + } if(subgui != null) subgui.drawScreen(i,j,f); } diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNpcButton.java b/src/main/java/noppes/npcs/client/gui/util/GuiNpcButton.java index 5e1c12201..4eedca8b1 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNpcButton.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNpcButton.java @@ -1,16 +1,26 @@ package noppes.npcs.client.gui.util; +import kamkeel.util.TextSplitter; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.RenderHelper; import net.minecraft.util.StatCollector; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; public class GuiNpcButton extends GuiButton{ protected String[] display; private int displayValue = 0; public int id; + public String hoverableText = ""; + public int oldHover; + public int hoverCount = 0; public GuiNpcButton(int i, int j, int k, String s) { super(i, j, k, StatCollector.translateToLocal(s)); @@ -48,6 +58,9 @@ public class GuiNpcButton extends GuiButton{ public void setDisplayText(String text){ this.displayString = StatCollector.translateToLocal(text); } + public void setHoverText(String text){ + this.hoverableText = StatCollector.translateToLocal(text); + } public int getValue(){ return displayValue; } @@ -85,4 +98,106 @@ public class GuiNpcButton extends GuiButton{ public int getWidth() { return width; } + + public void drawHover(int i, int j, boolean hasSubGui) { + if (hasSubGui || !visible || hoverableText.isEmpty()) + return; + + int hoverState = this.getHoverState(this.field_146123_n); + if (oldHover != hoverState) { + oldHover = hoverState; + hoverCount = 0; + } else { + if (hoverCount < 110) + hoverCount++; + } + + if (hoverState == 2 && hoverCount > 100) { + GL11.glPushMatrix(); + Minecraft mc = Minecraft.getMinecraft(); + String displayString = StatCollector.translateToLocal(hoverableText); + GL11.glColor4f(1, 1, 1, 1); + List lines = TextSplitter.splitText(displayString, 30); + drawHoveringText(lines, i, j, mc); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glPopMatrix(); + } + } + + protected void drawHoveringText(List textLines, int x, int y, Minecraft mc) { + if (mc.fontRenderer == null || textLines.isEmpty()) + return; + + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + RenderHelper.disableStandardItemLighting(); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_DEPTH_TEST); + + int maxWidth = 0; + Iterator iterator = textLines.iterator(); + while (iterator.hasNext()) { + String s = (String) iterator.next(); + int lineWidth = mc.fontRenderer.getStringWidth(s); + if (lineWidth > maxWidth) { + maxWidth = lineWidth; + } + } + + int j2 = x + 12; + int k2 = y - 12; + int maxHeight = 8; + + if (textLines.size() > 1) { + maxHeight += 2 + (textLines.size() - 1) * 10; + } + + // Calculate the maximum x-coordinate to ensure the tooltip stays within the game window + int gameWidth = mc.displayWidth; + int maxTooltipX = gameWidth - maxWidth - 4; // Subtract the tooltip width + + // Adjust tooltip position if it goes off the screen to the right + if (j2 > maxTooltipX) { + int diff = j2 - maxTooltipX; + j2 -= diff; // Shift tooltip to the left + GL11.glTranslatef(-300, 0, 0); // Apply translation + } + + if (k2 + maxHeight + 6 > mc.displayHeight) { + k2 = mc.displayHeight - maxHeight - 6; + } + + // Draw the tooltip + this.zLevel = 300.0F; + int j1 = -267386864; + // Draw the gradient background + // (Ensure to adjust the coordinates according to the translation) + this.drawGradientRect(j2 - 3, k2 - 4, j2 + maxWidth + 3, k2 - 3, j1, j1); + this.drawGradientRect(j2 - 3, k2 + maxHeight + 3, j2 + maxWidth + 3, k2 + maxHeight + 4, j1, j1); + this.drawGradientRect(j2 - 3, k2 - 3, j2 + maxWidth + 3, k2 + maxHeight + 3, j1, j1); + this.drawGradientRect(j2 - 4, k2 - 3, j2 - 3, k2 + maxHeight + 3, j1, j1); + this.drawGradientRect(j2 + maxWidth + 3, k2 - 3, j2 + maxWidth + 4, k2 + maxHeight + 3, j1, j1); + int k1 = 1347420415; + int l1 = (k1 & 16711422) >> 1 | k1 & -16777216; + this.drawGradientRect(j2 - 3, k2 - 3 + 1, j2 - 3 + 1, k2 + maxHeight + 3 - 1, k1, l1); + this.drawGradientRect(j2 + maxWidth + 2, k2 - 3 + 1, j2 + maxWidth + 3, k2 + maxHeight + 3 - 1, k1, l1); + this.drawGradientRect(j2 - 3, k2 - 3, j2 + maxWidth + 3, k2 - 3 + 1, k1, k1); + this.drawGradientRect(j2 - 3, k2 + maxHeight + 2, j2 + maxWidth + 3, k2 + maxHeight + 3, l1, l1); + + // Draw the text lines + for (int i2 = 0; i2 < textLines.size(); ++i2) { + String s1 = (String) textLines.get(i2); + mc.fontRenderer.drawStringWithShadow(s1, j2, k2, -1); + if (i2 == 0) { + k2 += 2; + } + k2 += 10; + } + + this.zLevel = 0.0F; + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_DEPTH_TEST); + RenderHelper.enableStandardItemLighting(); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + } + } From d75a054118c61f56401333702df69c05fe65c2d2 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 29 Feb 2024 20:58:23 -0500 Subject: [PATCH 40/41] Add Lang for Custom Tint --- .../java/noppes/npcs/client/gui/SubGuiNpcTint.java | 12 ++++++------ src/main/resources/assets/customnpcs/lang/en_US.lang | 7 +++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcTint.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcTint.java index 54b72821e..f39e37678 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcTint.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcTint.java @@ -22,33 +22,33 @@ public class SubGuiNpcTint extends SubGuiInterface implements ISubGuiListener, I public void initGui() { super.initGui(); int y = 30; - addLabel(new GuiNpcLabel(0, "Enable Custom Tint", guiLeft + 5, guiTop + y + 5)); + addLabel(new GuiNpcLabel(0, "tint.enablecustom", guiLeft + 5, guiTop + y + 5)); addButton(new GuiNpcButtonYesNo(0, guiLeft + 122, guiTop + y, 56, 20, tintData.isEnableCustomTint())); y+=22; if (tintData.isEnableCustomTint()) { - addLabel(new GuiNpcLabel(1, "Enable Npc Tint", guiLeft + 5, guiTop + y + 5)); + addLabel(new GuiNpcLabel(1, "tint.enablenpc", guiLeft + 5, guiTop + y + 5)); addButton(new GuiNpcButtonYesNo(1, guiLeft + 122, guiTop + y, 56, 20, tintData.isEnableNpcTint())); y+=22; if(tintData.isEnableNpcTint()) { String color = Integer.toHexString(tintData.getColorNpcTint()); while (color.length() < 6) color = 0 + color; - addLabel(new GuiNpcLabel(2, "Npc Tint", guiLeft + 4, guiTop + y + 5)); + addLabel(new GuiNpcLabel(2, "tint.tint", guiLeft + 4, guiTop + y + 5)); addButton(new GuiNpcButton(2, guiLeft + 122, guiTop + y, 60, 20, color)); getButton(2).setTextColor(tintData.getColorNpcTint()); y+=22; - addLabel(new GuiNpcLabel(3,"Npc Tint Alpha", guiLeft + 5, guiTop + y + 5)); + addLabel(new GuiNpcLabel(3,"tint.alpha", guiLeft + 5, guiTop + y + 5)); addTextField(new GuiNpcTextField(3,this, fontRendererObj, guiLeft + 122, guiTop + y, 60, 20, tintData.getColorNpcTintAlpha() + "")); getTextField(3).integersOnly = true; getTextField(3).setMinMaxDefault(1, 100, 40); y+=22; } - addLabel(new GuiNpcLabel(4, "Enable Hurt Tint", guiLeft + 5, guiTop + y + 5)); + addLabel(new GuiNpcLabel(4, "tint.enablehurt", guiLeft + 5, guiTop + y + 5)); addButton(new GuiNpcButtonYesNo(4, guiLeft + 122, guiTop + y, 56, 20, tintData.isEnableHurtTint())); y+=22; if (tintData.isEnableHurtTint()) { String color2 = Integer.toHexString(tintData.getColorHurtTint()); while (color2.length() < 6) color2 = 0 + color2; - addLabel(new GuiNpcLabel(5, "Hurt Tint", guiLeft + 4, guiTop + y + 5)); + addLabel(new GuiNpcLabel(5, "tint.hurt", guiLeft + 4, guiTop + y + 5)); addButton(new GuiNpcButton(5, guiLeft + 122, guiTop + y, 60, 20, color2)); getButton(5).setTextColor(tintData.getColorHurtTint()); } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 733af8f63..4ff9d4b68 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -1176,3 +1176,10 @@ mark.pointer=Pointer mark.skull=Skull mark.cross=Cross mark.star=Star + +tint.enablecustom=Enable Custom Tint +tint.enablenpc=Enable NPC Tint +tint.enablehurt=Enable Hurt Tint +tint.tint=Tint +tint.alpha=Alpha +tint.hurt=Hurt Tint From ea0b8ec5a4139b5b442ea5c16dbbd5a9fd23c5c8 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 29 Feb 2024 22:06:21 -0500 Subject: [PATCH 41/41] Tint Code Refactoring and some cleanup wo the lang file --- .../noppes/npcs/client/gui/SubGuiNpcTint.java | 44 +++++----- .../client/gui/mainmenu/GuiNpcDisplay.java | 7 +- .../npcs/client/model/part/ModelLegs.java | 2 +- .../npcs/client/model/part/ModelTail.java | 2 +- .../client/model/util/ModelPartInterface.java | 2 +- .../client/renderer/RenderNPCInterface.java | 16 ++-- .../npcs/controllers/data/CustomTintData.java | 88 +++++++++---------- .../assets/customnpcs/lang/en_US.lang | 8 +- 8 files changed, 85 insertions(+), 84 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcTint.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcTint.java index f39e37678..13064c47b 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcTint.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcTint.java @@ -1,10 +1,8 @@ package noppes.npcs.client.gui; import net.minecraft.client.gui.GuiButton; -import noppes.npcs.DataStats; import noppes.npcs.client.gui.util.*; import noppes.npcs.controllers.data.CustomTintData; -import noppes.npcs.controllers.data.DialogImage; public class SubGuiNpcTint extends SubGuiInterface implements ISubGuiListener, ITextfieldListener { private CustomTintData tintData; @@ -22,35 +20,35 @@ public class SubGuiNpcTint extends SubGuiInterface implements ISubGuiListener, I public void initGui() { super.initGui(); int y = 30; - addLabel(new GuiNpcLabel(0, "tint.enablecustom", guiLeft + 5, guiTop + y + 5)); - addButton(new GuiNpcButtonYesNo(0, guiLeft + 122, guiTop + y, 56, 20, tintData.isEnableCustomTint())); + addLabel(new GuiNpcLabel(0, "tint.enable", guiLeft + 5, guiTop + y + 5)); + addButton(new GuiNpcButtonYesNo(0, guiLeft + 122, guiTop + y, 56, 20, tintData.isTintEnabled())); y+=22; - if (tintData.isEnableCustomTint()) { - addLabel(new GuiNpcLabel(1, "tint.enablenpc", guiLeft + 5, guiTop + y + 5)); - addButton(new GuiNpcButtonYesNo(1, guiLeft + 122, guiTop + y, 56, 20, tintData.isEnableNpcTint())); + if (tintData.isTintEnabled()) { + addLabel(new GuiNpcLabel(1, "tint.enablegeneral", guiLeft + 5, guiTop + y + 5)); + addButton(new GuiNpcButtonYesNo(1, guiLeft + 122, guiTop + y, 56, 20, tintData.isGeneralTintEnabled())); y+=22; - if(tintData.isEnableNpcTint()) { - String color = Integer.toHexString(tintData.getColorNpcTint()); + if(tintData.isGeneralTintEnabled()) { + String color = Integer.toHexString(tintData.getGeneralTint()); while (color.length() < 6) color = 0 + color; addLabel(new GuiNpcLabel(2, "tint.tint", guiLeft + 4, guiTop + y + 5)); addButton(new GuiNpcButton(2, guiLeft + 122, guiTop + y, 60, 20, color)); - getButton(2).setTextColor(tintData.getColorNpcTint()); + getButton(2).setTextColor(tintData.getGeneralTint()); y+=22; addLabel(new GuiNpcLabel(3,"tint.alpha", guiLeft + 5, guiTop + y + 5)); - addTextField(new GuiNpcTextField(3,this, fontRendererObj, guiLeft + 122, guiTop + y, 60, 20, tintData.getColorNpcTintAlpha() + "")); + addTextField(new GuiNpcTextField(3,this, fontRendererObj, guiLeft + 122, guiTop + y, 60, 20, tintData.getGeneralAlpha() + "")); getTextField(3).integersOnly = true; getTextField(3).setMinMaxDefault(1, 100, 40); y+=22; } addLabel(new GuiNpcLabel(4, "tint.enablehurt", guiLeft + 5, guiTop + y + 5)); - addButton(new GuiNpcButtonYesNo(4, guiLeft + 122, guiTop + y, 56, 20, tintData.isEnableHurtTint())); + addButton(new GuiNpcButtonYesNo(4, guiLeft + 122, guiTop + y, 56, 20, tintData.isHurtTintEnabled())); y+=22; - if (tintData.isEnableHurtTint()) { - String color2 = Integer.toHexString(tintData.getColorHurtTint()); + if (tintData.isHurtTintEnabled()) { + String color2 = Integer.toHexString(tintData.getHurtTint()); while (color2.length() < 6) color2 = 0 + color2; addLabel(new GuiNpcLabel(5, "tint.hurt", guiLeft + 4, guiTop + y + 5)); addButton(new GuiNpcButton(5, guiLeft + 122, guiTop + y, 60, 20, color2)); - getButton(5).setTextColor(tintData.getColorHurtTint()); + getButton(5).setTextColor(tintData.getHurtTint()); } } addButton(new GuiNpcButton(66, guiLeft + 82, guiTop + 190, 98, 20, "gui.done")); @@ -61,23 +59,23 @@ public class SubGuiNpcTint extends SubGuiInterface implements ISubGuiListener, I int id = guibutton.id; GuiNpcButton button = (GuiNpcButton) guibutton; if (id == 0) { - tintData.setEnableCustomTint(((GuiNpcButtonYesNo) button).getBoolean()); + tintData.setTintEnabled(((GuiNpcButtonYesNo) button).getBoolean()); initGui(); } if (id == 1) { - tintData.setEnableNpcTint(((GuiNpcButtonYesNo) button).getBoolean()); + tintData.setGeneralTintEnabled(((GuiNpcButtonYesNo) button).getBoolean()); initGui(); } if (id == 4) { - tintData.setEnableHurtTint(((GuiNpcButtonYesNo) button).getBoolean()); + tintData.setHurtTintEnabled(((GuiNpcButtonYesNo) button).getBoolean()); initGui(); } if (button.id == 2) { - setSubGui(new SubGuiColorSelector(tintData.getColorNpcTint())); + setSubGui(new SubGuiColorSelector(tintData.getGeneralTint())); lastColorClicked = 0; } if (button.id == 5) { - setSubGui(new SubGuiColorSelector(tintData.getColorHurtTint())); + setSubGui(new SubGuiColorSelector(tintData.getHurtTint())); lastColorClicked = 1; } if (id == 66) { @@ -88,9 +86,9 @@ public class SubGuiNpcTint extends SubGuiInterface implements ISubGuiListener, I @Override public void subGuiClosed(SubGuiInterface subgui) { if (lastColorClicked == 0) { - tintData.setColorNpcTint(((SubGuiColorSelector) subgui).color); + tintData.setGeneralTint(((SubGuiColorSelector) subgui).color); } else if (lastColorClicked == 1) { - tintData.setColorHurtTint(((SubGuiColorSelector) subgui).color); + tintData.setHurtTint(((SubGuiColorSelector) subgui).color); } initGui(); save(); @@ -99,7 +97,7 @@ public class SubGuiNpcTint extends SubGuiInterface implements ISubGuiListener, I @Override public void unFocused(GuiNpcTextField textfield) { if(textfield.id==3){ - tintData.setColorNpcTintAlpha(textfield.getInteger()); + tintData.setGeneralAlpha(textfield.getInteger()); } } } 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 13a1a68e5..2b266184f 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java @@ -43,7 +43,6 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene y+=23; addLabel(new GuiNpcLabel(11,"gui.title", guiLeft + 5, y + 5)); addTextField(new GuiNpcTextField(11,this, fontRendererObj, guiLeft + 50, y, 206, 20, display.title)); - this.addButton(new GuiNpcButton(13, guiLeft + 259, y , 80, 20, "Tint settings")); y+=23; addLabel(new GuiNpcLabel(1,"display.model", guiLeft + 5, y + 5)); @@ -82,16 +81,18 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene addLabel(new GuiNpcLabel(5,"display.livingAnimation", guiLeft + 5, y + 5)); this.addButton(new GuiNpcButton(5, guiLeft + 120, y, 50, 20, new String[]{"gui.yes","gui.no"}, display.disableLivingAnimation?1:0)); - addLabel(new GuiNpcLabel(6,"Collides With Entities", guiLeft + 185, y + 5)); + addLabel(new GuiNpcLabel(6,"display.collides", guiLeft + 185, y + 5)); this.addButton(new GuiNpcButton(6, guiLeft + 300, y, 100, 20, new String[]{"gui.yes","gui.no","Only CNPCs","Only Players","CNPCs & Players"}, display.collidesWith)); y+=23; addLabel(new GuiNpcLabel(7,"display.visible", guiLeft + 5, y + 5)); this.addButton(new GuiNpcButton(7, guiLeft + 120, y, 50, 20, new String[]{"gui.yes","gui.no","gui.partly"}, display.visible)); + this.addButton(new GuiNpcButton(13, guiLeft + 185, y , 100, 20, "display.tintsettings")); + y+=23; addLabel(new GuiNpcLabel(10,"display.bossbar", guiLeft + 5, y + 5)); - this.addButton(new GuiNpcButton(10, guiLeft + 120, y, 110, 20, new String[]{"display.hide","display.show","display.showAttacking"}, display.showBossBar)); + this.addButton(new GuiNpcButton(10, guiLeft + 60, y, 110, 20, new String[]{"display.hide","display.show","display.showAttacking"}, display.showBossBar)); GeckoAddonClient.Instance.geckoNpcDisplayInitGui(this); } diff --git a/src/main/java/noppes/npcs/client/model/part/ModelLegs.java b/src/main/java/noppes/npcs/client/model/part/ModelLegs.java index cc959b665..9807c9e11 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelLegs.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelLegs.java @@ -389,7 +389,7 @@ public class ModelLegs extends ModelScaleRenderer{ } CustomTintData customTintData = entity.display.customTintData; boolean bo = entity.hurtTime <= 0 && entity.deathTime <= 0 && !base.isArmor && - !(customTintData.isEnableCustomTint() && customTintData.isEnableNpcTint()); + !(customTintData.isTintEnabled() && customTintData.isGeneralTintEnabled()); if(bo){ float red = (entity.modelData.legParts.color >> 16 & 255) / 255f; float green = (entity.modelData.legParts.color >> 8 & 255) / 255f; diff --git a/src/main/java/noppes/npcs/client/model/part/ModelTail.java b/src/main/java/noppes/npcs/client/model/part/ModelTail.java index 7541a7168..ede9ddc2e 100644 --- a/src/main/java/noppes/npcs/client/model/part/ModelTail.java +++ b/src/main/java/noppes/npcs/client/model/part/ModelTail.java @@ -153,7 +153,7 @@ public class ModelTail extends ModelScaleRenderer { } CustomTintData customTintData = entity.display.customTintData; boolean bo = entity.hurtTime <= 0 && entity.deathTime <= 0 && !base.isArmor && - !(customTintData.isEnableCustomTint() && customTintData.isEnableNpcTint()); + !(customTintData.isTintEnabled() && customTintData.isGeneralTintEnabled()); if(bo){ float red = (color >> 16 & 255) / 255f; float green = (color >> 8 & 255) / 255f; diff --git a/src/main/java/noppes/npcs/client/model/util/ModelPartInterface.java b/src/main/java/noppes/npcs/client/model/util/ModelPartInterface.java index 25d9d70e6..8c02f6af3 100644 --- a/src/main/java/noppes/npcs/client/model/util/ModelPartInterface.java +++ b/src/main/java/noppes/npcs/client/model/util/ModelPartInterface.java @@ -62,7 +62,7 @@ public abstract class ModelPartInterface extends ModelRenderer { } CustomTintData customTintData = entity.display.customTintData; boolean bo = entity.hurtTime <= 0 && entity.deathTime <= 0 && !base.isArmor && - !(customTintData.isEnableCustomTint() && customTintData.isEnableNpcTint()); + !(customTintData.isTintEnabled() && customTintData.isGeneralTintEnabled()); if(bo){ float red = (color >> 16 & 255) / 255f; float green = (color >> 8 & 255) / 255f; diff --git a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java index 01eeffc30..a2d32d85a 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java @@ -373,7 +373,7 @@ public class RenderNPCInterface extends RenderLiving{ GL11.glDisable(GL11.GL_TEXTURE_2D); OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); CustomTintData customTintData = p_76986_1_.display.customTintData; - if ((j >> 24 & 255) > 0 || p_76986_1_.hurtTime > 0 || p_76986_1_.deathTime > 0 || (customTintData.isEnableCustomTint() && customTintData.isEnableNpcTint())) + if ((j >> 24 & 255) > 0 || p_76986_1_.hurtTime > 0 || p_76986_1_.deathTime > 0 || (customTintData.isTintEnabled() && customTintData.isGeneralTintEnabled())) { GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glDisable(GL11.GL_ALPHA_TEST); @@ -381,13 +381,13 @@ public class RenderNPCInterface extends RenderLiving{ GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glDepthFunc(GL11.GL_EQUAL); - if ((p_76986_1_.hurtTime > 0 || p_76986_1_.deathTime > 0) && (!customTintData.isEnableCustomTint() || customTintData.isEnableHurtTint())) + if ((p_76986_1_.hurtTime > 0 || p_76986_1_.deathTime > 0) && (!customTintData.isTintEnabled() || customTintData.isHurtTintEnabled())) { float r, g, b; - if(customTintData.isEnableCustomTint()) { - r = (float) (customTintData.getColorHurtTint() >> 16 & 255) / 255.0F * f14; - g = (float) (customTintData.getColorHurtTint() >> 8 & 255) / 255.0F * f14; - b = (float) (customTintData.getColorHurtTint() & 255) / 255.0F * f14; + if(customTintData.isTintEnabled()) { + r = (float) (customTintData.getHurtTint() >> 16 & 255) / 255.0F * f14; + g = (float) (customTintData.getHurtTint() >> 8 & 255) / 255.0F * f14; + b = (float) (customTintData.getHurtTint() & 255) / 255.0F * f14; }else{ r=f14; g=0; @@ -469,8 +469,8 @@ public class RenderNPCInterface extends RenderLiving{ { EntityNPCInterface npc = (EntityNPCInterface) p_77030_1_; CustomTintData tintData = npc.display.customTintData; - int alpha = (int) (0xff*((double)tintData.getColorNpcTintAlpha()/100d)) << 24; - return (tintData.isEnableCustomTint() && tintData.isEnableNpcTint())?tintData.getColorNpcTint()+alpha:0; + int alpha = (int) (0xff*((double)tintData.getGeneralAlpha()/100d)) << 24; + return (tintData.isTintEnabled() && tintData.isGeneralTintEnabled())?tintData.getGeneralTint()+alpha:0; } protected void renderModel(EntityLivingBase entityliving, float par2, float par3, float par4, float par5, float par6, float par7) { diff --git a/src/main/java/noppes/npcs/controllers/data/CustomTintData.java b/src/main/java/noppes/npcs/controllers/data/CustomTintData.java index c19c425ac..f1013d55e 100644 --- a/src/main/java/noppes/npcs/controllers/data/CustomTintData.java +++ b/src/main/java/noppes/npcs/controllers/data/CustomTintData.java @@ -3,81 +3,81 @@ package noppes.npcs.controllers.data; import net.minecraft.nbt.NBTTagCompound; public class CustomTintData { - private boolean enableCustomTint = false; - private boolean enableHurtTint = true; - private boolean enableNpcTint = false; - private int colorHurtTint = 0xff0000; - private int colorNpcTint = 0x000000; - private int colorNpcTintAlpha = 40; + private boolean tintEnabled = false; + private boolean hurtTintEnabled = true; + private boolean generalTintEnabled = false; + private int hurtTint = 0xff0000; + private int generalTint = 0x000000; + private int generalAlpha = 40; public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) { - nbttagcompound.setBoolean("EnableCustomTint", enableCustomTint); - if(enableCustomTint) { - nbttagcompound.setBoolean("EnableHurtTint", enableHurtTint); - nbttagcompound.setBoolean("EnableNpcTint", enableNpcTint); - nbttagcompound.setInteger("ColorHurtTint", colorHurtTint); - nbttagcompound.setInteger("ColorNpcTint", colorNpcTint); - nbttagcompound.setInteger("ColorNpcTintAlpha", colorNpcTintAlpha); + nbttagcompound.setBoolean("TintEnabled", tintEnabled); + if(tintEnabled) { + nbttagcompound.setBoolean("HurtTintEnabled", hurtTintEnabled); + nbttagcompound.setBoolean("GeneralTintEnabled", generalTintEnabled); + nbttagcompound.setInteger("HurtTint", hurtTint); + nbttagcompound.setInteger("GeneralTint", generalTint); + nbttagcompound.setInteger("GeneralAlpha", generalAlpha); } return nbttagcompound; } public void readFromNBT(NBTTagCompound nbttagcompound) { - enableCustomTint = nbttagcompound.getBoolean("EnableCustomTint"); - if(enableCustomTint) { - enableHurtTint = nbttagcompound.getBoolean("EnableHurtTint"); - enableNpcTint = nbttagcompound.getBoolean("EnableNpcTint"); - colorHurtTint = nbttagcompound.getInteger("ColorHurtTint"); - colorNpcTint = nbttagcompound.getInteger("ColorNpcTint"); - colorNpcTintAlpha = nbttagcompound.getInteger("ColorNpcTintAlpha"); + tintEnabled = nbttagcompound.getBoolean("TintEnabled"); + if(tintEnabled) { + hurtTintEnabled = nbttagcompound.getBoolean("HurtTintEnabled"); + generalTintEnabled = nbttagcompound.getBoolean("GeneralTintEnabled"); + hurtTint = nbttagcompound.getInteger("HurtTint"); + generalTint = nbttagcompound.getInteger("GeneralTint"); + generalAlpha = nbttagcompound.getInteger("GeneralAlpha"); } } - public boolean isEnableHurtTint() { - return enableHurtTint; + public boolean isHurtTintEnabled() { + return hurtTintEnabled; } - public void setEnableHurtTint(boolean enableHurtTint) { - this.enableHurtTint = enableHurtTint; + public void setHurtTintEnabled(boolean hurtTintEnabled) { + this.hurtTintEnabled = hurtTintEnabled; } - public int getColorHurtTint() { - return colorHurtTint; + public int getHurtTint() { + return hurtTint; } - public void setColorHurtTint(int colorHurtTint) { - this.colorHurtTint = colorHurtTint; + public void setHurtTint(int colorHurtTint) { + this.hurtTint = colorHurtTint; } - public int getColorNpcTint() { - return colorNpcTint; + public int getGeneralTint() { + return generalTint; } - public void setColorNpcTint(int colorNpcTint) { - this.colorNpcTint = colorNpcTint; + public void setGeneralTint(int generalTint) { + this.generalTint = generalTint; } - public boolean isEnableCustomTint() { - return enableCustomTint; + public boolean isTintEnabled() { + return tintEnabled; } - public void setEnableCustomTint(boolean enableCustomTint) { - this.enableCustomTint = enableCustomTint; + public void setTintEnabled(boolean tintEnabled) { + this.tintEnabled = tintEnabled; } - public boolean isEnableNpcTint() { - return enableNpcTint; + public boolean isGeneralTintEnabled() { + return generalTintEnabled; } - public void setEnableNpcTint(boolean enableNpcTint) { - this.enableNpcTint = enableNpcTint; + public void setGeneralTintEnabled(boolean generalTintEnabled) { + this.generalTintEnabled = generalTintEnabled; } - public int getColorNpcTintAlpha() { - return colorNpcTintAlpha; + public int getGeneralAlpha() { + return generalAlpha; } - public void setColorNpcTintAlpha(int colorNpcTintAlpha) { - this.colorNpcTintAlpha = colorNpcTintAlpha; + public void setGeneralAlpha(int generalAlpha) { + this.generalAlpha = generalAlpha; } } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 4ff9d4b68..2d4b3f8e7 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -223,6 +223,7 @@ display.overlay=Overlay display.player=Player display.selectTexture=Select Texture display.livingAnimation=Has a living animation +display.collides=Collides With Entities display.visible=Visible display.bossbar=BossBar display.squareTexture=Square Texture @@ -244,6 +245,7 @@ display.top=Top display.fixed=Fixed display.glow=Glow display.solid=Solid +display.tintsettings=Tint Settings inv.minExp=Min Exp inv.maxExp=Max Exp @@ -1177,9 +1179,9 @@ mark.skull=Skull mark.cross=Cross mark.star=Star -tint.enablecustom=Enable Custom Tint -tint.enablenpc=Enable NPC Tint +tint.enable=Enable Custom Tint +tint.enablegeneral=Enable General Tint tint.enablehurt=Enable Hurt Tint -tint.tint=Tint +tint.tint=General Tint tint.alpha=Alpha tint.hurt=Hurt Tint