From eb899061bf64375c1ff502480ca0e5c662714302 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 18 Feb 2025 16:11:58 -0500 Subject: [PATCH 01/59] Better Chat Color Utility Handling for Commands --- .../npcs/command/AnimationCommand.java | 3 + .../kamkeel/npcs/command/CloneCommand.java | 2 + .../kamkeel/npcs/command/CommandCommand.java | 3 + .../npcs/command/CommandKamkeelBase.java | 12 -- .../kamkeel/npcs/command/ConfigCommand.java | 3 + .../npcs/command/DialogCategoryCommand.java | 3 + .../kamkeel/npcs/command/DialogCommand.java | 3 + .../kamkeel/npcs/command/EffectCommand.java | 5 +- .../kamkeel/npcs/command/FactionCommand.java | 3 + .../kamkeel/npcs/command/HelpCommand.java | 3 + .../java/kamkeel/npcs/command/NpcCommand.java | 3 + .../kamkeel/npcs/command/OverlayCommand.java | 3 + .../npcs/command/QuestCategoryCommand.java | 3 + .../kamkeel/npcs/command/QuestCommand.java | 3 + .../kamkeel/npcs/command/ScriptCommand.java | 3 + .../kamkeel/npcs/command/SlayCommand.java | 2 + .../command/profile/CommandHelpProfile.java | 3 + .../command/profile/CommandProfileAdmin.java | 2 + .../command/profile/CommandProfileBase.java | 19 +-- .../command/profile/CommandProfileChange.java | 3 + .../command/profile/CommandProfileList.java | 3 + .../command/profile/CommandProfileRemove.java | 3 + .../command/profile/CommandProfileRename.java | 3 + .../java/kamkeel/npcs/util/ColorUtil.java | 135 ++++++++++++++++++ 24 files changed, 202 insertions(+), 26 deletions(-) diff --git a/src/main/java/kamkeel/npcs/command/AnimationCommand.java b/src/main/java/kamkeel/npcs/command/AnimationCommand.java index 05e5e517f..e8388e802 100644 --- a/src/main/java/kamkeel/npcs/command/AnimationCommand.java +++ b/src/main/java/kamkeel/npcs/command/AnimationCommand.java @@ -9,6 +9,9 @@ import noppes.npcs.controllers.data.PlayerData; import java.util.List; +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendResult; + public class AnimationCommand extends CommandKamkeelBase { @Override diff --git a/src/main/java/kamkeel/npcs/command/CloneCommand.java b/src/main/java/kamkeel/npcs/command/CloneCommand.java index b62308d30..3ce2f02b8 100644 --- a/src/main/java/kamkeel/npcs/command/CloneCommand.java +++ b/src/main/java/kamkeel/npcs/command/CloneCommand.java @@ -17,6 +17,8 @@ import noppes.npcs.entity.EntityNPCInterface; import java.util.List; +import static kamkeel.npcs.util.ColorUtil.*; + public class CloneCommand extends CommandKamkeelBase { @Override diff --git a/src/main/java/kamkeel/npcs/command/CommandCommand.java b/src/main/java/kamkeel/npcs/command/CommandCommand.java index facac35f1..edc20b84d 100644 --- a/src/main/java/kamkeel/npcs/command/CommandCommand.java +++ b/src/main/java/kamkeel/npcs/command/CommandCommand.java @@ -10,6 +10,9 @@ import noppes.npcs.api.IWorld; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.event.CustomNPCsEvent; +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendMessage; + public class CommandCommand extends CommandKamkeelBase { @Override diff --git a/src/main/java/kamkeel/npcs/command/CommandKamkeelBase.java b/src/main/java/kamkeel/npcs/command/CommandKamkeelBase.java index cf87c5d36..e594603f9 100644 --- a/src/main/java/kamkeel/npcs/command/CommandKamkeelBase.java +++ b/src/main/java/kamkeel/npcs/command/CommandKamkeelBase.java @@ -55,18 +55,6 @@ public abstract class CommandKamkeelBase extends CommandBase{ return !subcommands.isEmpty(); } - protected static void sendMessage(ICommandSender sender, String message, Object... obs) { - sender.addChatMessage(new ChatComponentTranslation(message, obs)); - } - - protected static void sendResult(ICommandSender sender, String message, Object... obs) { - sender.addChatMessage(new ChatComponentTranslation("\u00A76[\u00A7eCNPC+\u00A76]\u00A77 " + message, obs)); - } - - protected static void sendError(ICommandSender sender, String message, Object... obs) { - sender.addChatMessage(new ChatComponentTranslation("\u00A76[\u00A7eCNPC+\u00A76]\u00A74 Error:\u00A7c " + message, obs)); - } - @Retention(value = RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface SubCommand { diff --git a/src/main/java/kamkeel/npcs/command/ConfigCommand.java b/src/main/java/kamkeel/npcs/command/ConfigCommand.java index f31a1dc18..b432df26e 100644 --- a/src/main/java/kamkeel/npcs/command/ConfigCommand.java +++ b/src/main/java/kamkeel/npcs/command/ConfigCommand.java @@ -20,6 +20,9 @@ import noppes.npcs.controllers.PlayerDataController; import java.util.Arrays; import java.util.Set; +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendResult; + public class ConfigCommand extends CommandKamkeelBase { diff --git a/src/main/java/kamkeel/npcs/command/DialogCategoryCommand.java b/src/main/java/kamkeel/npcs/command/DialogCategoryCommand.java index d149a15b7..cf1424386 100644 --- a/src/main/java/kamkeel/npcs/command/DialogCategoryCommand.java +++ b/src/main/java/kamkeel/npcs/command/DialogCategoryCommand.java @@ -11,6 +11,9 @@ import noppes.npcs.controllers.data.PlayerData; import java.util.Collection; import java.util.List; +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendResult; + public class DialogCategoryCommand extends CommandKamkeelBase { @Override diff --git a/src/main/java/kamkeel/npcs/command/DialogCommand.java b/src/main/java/kamkeel/npcs/command/DialogCommand.java index 4ad1e7e22..d3953bad3 100644 --- a/src/main/java/kamkeel/npcs/command/DialogCommand.java +++ b/src/main/java/kamkeel/npcs/command/DialogCommand.java @@ -20,6 +20,9 @@ import noppes.npcs.entity.EntityDialogNpc; import java.util.Collection; import java.util.List; +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendResult; + public class DialogCommand extends CommandKamkeelBase { @Override diff --git a/src/main/java/kamkeel/npcs/command/EffectCommand.java b/src/main/java/kamkeel/npcs/command/EffectCommand.java index b82f1a5c0..5c128a821 100644 --- a/src/main/java/kamkeel/npcs/command/EffectCommand.java +++ b/src/main/java/kamkeel/npcs/command/EffectCommand.java @@ -13,6 +13,9 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendResult; + public class EffectCommand extends CommandKamkeelBase { @Override @@ -26,7 +29,7 @@ public class EffectCommand extends CommandKamkeelBase { } @SubCommand(desc = "Lists all Effects") - public void infoAll(ICommandSender sender, String[] args) throws CommandException { + public void list(ICommandSender sender, String[] args) throws CommandException { CustomEffectController controller = CustomEffectController.getInstance(); if (controller.indexMapper.isEmpty()) { sendError(sender, "No effects found."); diff --git a/src/main/java/kamkeel/npcs/command/FactionCommand.java b/src/main/java/kamkeel/npcs/command/FactionCommand.java index f5de2f3b5..32bea0d2d 100644 --- a/src/main/java/kamkeel/npcs/command/FactionCommand.java +++ b/src/main/java/kamkeel/npcs/command/FactionCommand.java @@ -11,6 +11,9 @@ import noppes.npcs.controllers.data.PlayerFactionData; import java.util.Arrays; import java.util.List; +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendResult; + public class FactionCommand extends CommandKamkeelBase { public Faction selectedFaction; diff --git a/src/main/java/kamkeel/npcs/command/HelpCommand.java b/src/main/java/kamkeel/npcs/command/HelpCommand.java index f5e0828da..18423a975 100644 --- a/src/main/java/kamkeel/npcs/command/HelpCommand.java +++ b/src/main/java/kamkeel/npcs/command/HelpCommand.java @@ -7,6 +7,9 @@ import net.minecraft.util.ChatComponentTranslation; import java.lang.reflect.Method; import java.util.Map.Entry; +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendMessage; + public class HelpCommand extends CommandKamkeelBase{ private CommandKamkeel parent; diff --git a/src/main/java/kamkeel/npcs/command/NpcCommand.java b/src/main/java/kamkeel/npcs/command/NpcCommand.java index fe775928c..4e5745906 100644 --- a/src/main/java/kamkeel/npcs/command/NpcCommand.java +++ b/src/main/java/kamkeel/npcs/command/NpcCommand.java @@ -22,6 +22,9 @@ import org.apache.commons.lang3.ArrayUtils; import java.util.Arrays; import java.util.List; +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendResult; + public class NpcCommand extends CommandKamkeelBase { public EntityNPCInterface selectedNpc; diff --git a/src/main/java/kamkeel/npcs/command/OverlayCommand.java b/src/main/java/kamkeel/npcs/command/OverlayCommand.java index e740bc5e0..95e098f7c 100644 --- a/src/main/java/kamkeel/npcs/command/OverlayCommand.java +++ b/src/main/java/kamkeel/npcs/command/OverlayCommand.java @@ -9,6 +9,9 @@ import noppes.npcs.controllers.data.SkinOverlay; import java.util.List; +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendResult; + public class OverlayCommand extends CommandKamkeelBase { @Override diff --git a/src/main/java/kamkeel/npcs/command/QuestCategoryCommand.java b/src/main/java/kamkeel/npcs/command/QuestCategoryCommand.java index 9e3e238fd..d29ded081 100644 --- a/src/main/java/kamkeel/npcs/command/QuestCategoryCommand.java +++ b/src/main/java/kamkeel/npcs/command/QuestCategoryCommand.java @@ -16,6 +16,9 @@ import noppes.npcs.controllers.data.QuestData; import java.util.Collection; import java.util.List; +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendResult; + public class QuestCategoryCommand extends CommandKamkeelBase { @Override diff --git a/src/main/java/kamkeel/npcs/command/QuestCommand.java b/src/main/java/kamkeel/npcs/command/QuestCommand.java index 7ac9b1fcd..127fb1726 100644 --- a/src/main/java/kamkeel/npcs/command/QuestCommand.java +++ b/src/main/java/kamkeel/npcs/command/QuestCommand.java @@ -21,6 +21,9 @@ import noppes.npcs.util.ValueUtil; import java.util.Collection; import java.util.List; +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendResult; + public class QuestCommand extends CommandKamkeelBase { @Override diff --git a/src/main/java/kamkeel/npcs/command/ScriptCommand.java b/src/main/java/kamkeel/npcs/command/ScriptCommand.java index bf62cc3fb..f314d2e42 100644 --- a/src/main/java/kamkeel/npcs/command/ScriptCommand.java +++ b/src/main/java/kamkeel/npcs/command/ScriptCommand.java @@ -3,6 +3,9 @@ package kamkeel.npcs.command; import net.minecraft.command.ICommandSender; import noppes.npcs.controllers.ScriptController; +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendResult; + public class ScriptCommand extends CommandKamkeelBase { diff --git a/src/main/java/kamkeel/npcs/command/SlayCommand.java b/src/main/java/kamkeel/npcs/command/SlayCommand.java index 60af6d6cf..82400b148 100644 --- a/src/main/java/kamkeel/npcs/command/SlayCommand.java +++ b/src/main/java/kamkeel/npcs/command/SlayCommand.java @@ -20,6 +20,8 @@ import noppes.npcs.entity.EntityNPCInterface; import java.util.*; +import static kamkeel.npcs.util.ColorUtil.sendResult; + public class SlayCommand extends CommandKamkeelBase { public Map> SlayMap = new LinkedHashMap>(); diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandHelpProfile.java b/src/main/java/kamkeel/npcs/command/profile/CommandHelpProfile.java index 672e7886c..effecd494 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandHelpProfile.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandHelpProfile.java @@ -7,6 +7,9 @@ import net.minecraft.util.ChatComponentTranslation; import java.lang.reflect.Method; import java.util.Map.Entry; +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendMessage; + public class CommandHelpProfile extends CommandProfileBase { private CommandProfile parent; diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java index 4b1c2429d..13b4a13c5 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java @@ -12,6 +12,8 @@ import net.minecraft.nbt.NBTTagCompound; import java.util.Map; import java.util.UUID; +import static kamkeel.npcs.util.ColorUtil.*; + public class CommandProfileAdmin extends CommandProfileBase { @Override diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileBase.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileBase.java index 18c06ad4f..7cdf0b5c3 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileBase.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileBase.java @@ -4,7 +4,10 @@ import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.ChatStyle; +import net.minecraft.util.EnumChatFormatting; import noppes.npcs.CustomNpcsPermissions; import java.lang.annotation.ElementType; @@ -16,6 +19,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public abstract class CommandProfileBase extends CommandBase{ public Map subcommands = new HashMap(); @@ -55,19 +60,7 @@ public abstract class CommandProfileBase extends CommandBase{ return !subcommands.isEmpty(); } - protected static void sendMessage(ICommandSender sender, String message, Object... obs) { - sender.addChatMessage(new ChatComponentTranslation(message, obs)); - } - - protected static void sendResult(ICommandSender sender, String message, Object... obs) { - sender.addChatMessage(new ChatComponentTranslation("\u00A76[\u00A7eCNPC+\u00A76]\u00A77 " + message, obs)); - } - - protected static void sendError(ICommandSender sender, String message, Object... obs) { - sender.addChatMessage(new ChatComponentTranslation("\u00A76[\u00A7eCNPC+\u00A76]\u00A74 Error:\u00A7c " + message, obs)); - } - - @Retention(value = RetentionPolicy.RUNTIME) + @Retention(value = RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface SubCommand { diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java index bbce07b84..d58660714 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java @@ -6,6 +6,9 @@ import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendResult; + public class CommandProfileChange extends CommandProfileBase { @Override diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java index 3ba49fc9a..97b6bbded 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java @@ -9,6 +9,9 @@ import net.minecraft.entity.player.EntityPlayer; import java.util.Map; +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendMessage; + public class CommandProfileList extends CommandProfileBase { @Override diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java index 9af22fca5..1d8b53413 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java @@ -6,6 +6,9 @@ import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendResult; + public class CommandProfileRemove extends CommandProfileBase { @Override diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java index 53c092b45..4155427c1 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java @@ -7,6 +7,9 @@ import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendResult; + public class CommandProfileRename extends CommandProfileBase { @Override diff --git a/src/main/java/kamkeel/npcs/util/ColorUtil.java b/src/main/java/kamkeel/npcs/util/ColorUtil.java index 2fd9997f0..b31ba2dfd 100644 --- a/src/main/java/kamkeel/npcs/util/ColorUtil.java +++ b/src/main/java/kamkeel/npcs/util/ColorUtil.java @@ -1,5 +1,11 @@ package kamkeel.npcs.util; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ChatStyle; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IChatComponent; + public class ColorUtil { @@ -28,4 +34,133 @@ public class ColorUtil { float b = (hex & 0xFF) / 255.0F; return new float[]{r, g, b}; } + + + /** + * Helper method that retrieves the EnumChatFormatting associated with a given formatting code character. + * + * @param c The formatting code character (e.g., '6' or 'l'). + * @return The matching EnumChatFormatting, or null if not found. + */ + public static EnumChatFormatting getFormattingByChar(char c) { + for (EnumChatFormatting format : EnumChatFormatting.values()) { + if (format.getFormattingCode() == c) { + return format; + } + } + return null; + } + + /** + * Assembles a composite IChatComponent from a raw text string with formatting codes (using §). + * Each time the formatting changes, a new component is created and appended as a sibling. + * + * @param text The raw text with formatting codes. + * @return A composite IChatComponent reflecting the formatting changes. + */ + public static IChatComponent assembleComponent(String text) { + // Final composite component + ChatComponentText composite = new ChatComponentText(""); + // Accumulates text until a formatting code change + ChatComponentText current = new ChatComponentText(""); + // Start with a fresh ChatStyle + ChatStyle currentStyle = new ChatStyle(); + + int i = 0; + while (i < text.length()) { + char c = text.charAt(i); + if (c == '\u00A7' && i + 1 < text.length()) { + // When a formatting code is encountered, first add any accumulated text as a sibling. + if (current.getUnformattedText().length() > 0) { + current.setChatStyle(currentStyle.createDeepCopy()); + composite.appendSibling(current); + current = new ChatComponentText(""); + } + char code = text.charAt(i + 1); + EnumChatFormatting formatting = getFormattingByChar(code); + if (formatting != null) { + // If it’s a color code (0-9, a-f), then it resets previous formatting. + if ("0123456789abcdef".indexOf(Character.toLowerCase(code)) >= 0) { + currentStyle = new ChatStyle().setColor(formatting); + } else { + // For modifiers (BOLD, ITALIC, etc.) + if (formatting == EnumChatFormatting.RESET) { + currentStyle = new ChatStyle(); + } else { + switch (formatting) { + case BOLD: + currentStyle = currentStyle.setBold(Boolean.TRUE); + break; + case ITALIC: + currentStyle = currentStyle.setItalic(Boolean.TRUE); + break; + case UNDERLINE: + currentStyle = currentStyle.setUnderlined(Boolean.TRUE); + break; + case STRIKETHROUGH: + currentStyle = currentStyle.setStrikethrough(Boolean.TRUE); + break; + case OBFUSCATED: + currentStyle = currentStyle.setObfuscated(Boolean.TRUE); + break; + default: + break; + } + } + } + } + i += 2; // Skip the § and the code character. + } else { + // Accumulate normal characters. + current.appendText(String.valueOf(c)); + i++; + } + } + // Append any trailing text. + if (current.getUnformattedText().length() > 0) { + current.setChatStyle(currentStyle.createDeepCopy()); + composite.appendSibling(current); + } + return composite; + } + + private static String LABEL = "\u00A7e[CNPC+] "; + + /** + * Assembles a composite chat component from a raw text string with formatting codes, + * and immediately sends it to the specified ICommandSender. + * + * @param sender The ICommandSender to send the message to. + * @param text The raw text (with § codes) to be assembled and sent. + */ + public static void sendMessage(ICommandSender sender, String text) { + text = "\u00A77" + text; + IChatComponent component = assembleComponent(text); + sender.addChatMessage(component); + } + + public static void sendMessage(ICommandSender sender, String format, Object... obs) { + sendMessage(sender, String.format(format, obs)); + } + + public static void sendResult(ICommandSender sender, String text) { + text = LABEL + "\u00A7a" + text; + IChatComponent component = assembleComponent(text); + sender.addChatMessage(component); + } + + public static void sendResult(ICommandSender sender, String format, Object... obs) { + sendResult(sender, String.format(format, obs)); + } + + public static void sendError(ICommandSender sender, String text) { + text = LABEL + "\u00A7c" + text; + IChatComponent component = assembleComponent(text); + sender.addChatMessage(component); + } + + public static void sendError(ICommandSender sender, String format, Object... obs) { + sendError(sender, String.format(format, obs)); + } + } From a728ff13c1cbe33c6b207974286bcc6213a9e4d6 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 18 Feb 2025 16:16:06 -0500 Subject: [PATCH 02/59] Better Label + Error Message --- src/main/java/kamkeel/npcs/util/ColorUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/kamkeel/npcs/util/ColorUtil.java b/src/main/java/kamkeel/npcs/util/ColorUtil.java index b31ba2dfd..1c72fc103 100644 --- a/src/main/java/kamkeel/npcs/util/ColorUtil.java +++ b/src/main/java/kamkeel/npcs/util/ColorUtil.java @@ -124,7 +124,7 @@ public class ColorUtil { return composite; } - private static String LABEL = "\u00A7e[CNPC+] "; + private static String LABEL = "\u00A76[\u00A7eCNPC+\u00A76] "; /** * Assembles a composite chat component from a raw text string with formatting codes, @@ -154,7 +154,7 @@ public class ColorUtil { } public static void sendError(ICommandSender sender, String text) { - text = LABEL + "\u00A7c" + text; + text = LABEL + "\u00A74Error: \u00A7c" + text; IChatComponent component = assembleComponent(text); sender.addChatMessage(component); } From 753a2a192786ea05621034d4e24c1f32c7b9fd1a Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 18 Feb 2025 16:23:03 -0500 Subject: [PATCH 03/59] Update ChatAlertPacket.java --- .../network/packets/data/ChatAlertPacket.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/kamkeel/npcs/network/packets/data/ChatAlertPacket.java b/src/main/java/kamkeel/npcs/network/packets/data/ChatAlertPacket.java index b57661e90..67574442a 100644 --- a/src/main/java/kamkeel/npcs/network/packets/data/ChatAlertPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/data/ChatAlertPacket.java @@ -8,12 +8,17 @@ import kamkeel.npcs.network.PacketChannel; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumDataPacket; import kamkeel.npcs.util.ByteBufUtils; +import kamkeel.npcs.util.ColorUtil; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.IChatComponent; +import net.minecraft.util.StatCollector; import noppes.npcs.config.ConfigClient; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; public final class ChatAlertPacket extends AbstractPacket { public static final String packetName = "Data|ChatAlert"; @@ -53,11 +58,20 @@ public final class ChatAlertPacket extends AbstractPacket { if (!ConfigClient.ChatAlerts) return; - StringBuilder message = new StringBuilder(); - String str; - while ((str = ByteBufUtils.readString(in)) != null && !str.isEmpty()) { - message.append(str); + // Read all objects (sent as strings) from the buffer. + List parts = new ArrayList<>(); + String part; + while ((part = ByteBufUtils.readString(in)) != null && !part.isEmpty()) { + parts.add(part); } - player.addChatMessage(new ChatComponentTranslation(message.toString())); + + StringBuilder finalMessage = new StringBuilder(); + for (String s : parts) { + finalMessage.append(StatCollector.translateToLocal(s)); + } + + String text = finalMessage.toString(); + IChatComponent comp = ColorUtil.assembleComponent(text); + player.addChatMessage(comp); } } From 64bb024e61a0976aa99dd2c332035268b6b9d115 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 18 Feb 2025 18:48:56 -0500 Subject: [PATCH 04/59] Change Inventory Tab Handling --- build.gradle | 2 +- .../kamkeel/npcs/addon/client/DBCClient.java | 3 - .../network/packets/data/ChatAlertPacket.java | 2 +- .../noppes/npcs/client/ClientTickHandler.java | 19 +----- .../player/inventory/GuiCNPCInventory.java | 59 +++++++----------- .../gui/player/inventory/GuiFaction.java | 2 +- .../client/gui/player/inventory/GuiParty.java | 2 +- .../gui/player/inventory/GuiQuestLog.java | 2 +- .../gui/player/inventory/GuiSettings.java | 2 +- .../client/tabs/InventoryTabCustomNpc.java | 41 ++++++------ .../assets/customnpcs/textures/gui/icons.png | Bin 10888 -> 4653 bytes 11 files changed, 51 insertions(+), 83 deletions(-) diff --git a/build.gradle b/build.gradle index c13a3e25d..478bd6638 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id 'idea' } -version = "1.9.4-beta2.9" +version = "1.9.4-beta3.1" group= "kamkeel.customnpc-plus" archivesBaseName = "CustomNPC-Plus" diff --git a/src/main/java/kamkeel/npcs/addon/client/DBCClient.java b/src/main/java/kamkeel/npcs/addon/client/DBCClient.java index 5fdc75d7e..7dd94ef6a 100644 --- a/src/main/java/kamkeel/npcs/addon/client/DBCClient.java +++ b/src/main/java/kamkeel/npcs/addon/client/DBCClient.java @@ -34,7 +34,4 @@ public class DBCClient { public GuiNPCInterface2 manageCustomForms(EntityNPCInterface npcInterface){ return null; } // Manage Custom Forms public GuiNPCInterface2 manageCustomAuras(EntityNPCInterface npcInterface){ return null; } - - // Inventory GUI - public GuiCNPCInventory inventoryGUI(){ return null; } } diff --git a/src/main/java/kamkeel/npcs/network/packets/data/ChatAlertPacket.java b/src/main/java/kamkeel/npcs/network/packets/data/ChatAlertPacket.java index 67574442a..fd47a6287 100644 --- a/src/main/java/kamkeel/npcs/network/packets/data/ChatAlertPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/data/ChatAlertPacket.java @@ -64,7 +64,7 @@ public final class ChatAlertPacket extends AbstractPacket { while ((part = ByteBufUtils.readString(in)) != null && !part.isEmpty()) { parts.add(part); } - + StringBuilder finalMessage = new StringBuilder(); for (String s : parts) { finalMessage.append(StatCollector.translateToLocal(s)); diff --git a/src/main/java/noppes/npcs/client/ClientTickHandler.java b/src/main/java/noppes/npcs/client/ClientTickHandler.java index 038ea5177..7c9e627e6 100644 --- a/src/main/java/noppes/npcs/client/ClientTickHandler.java +++ b/src/main/java/noppes/npcs/client/ClientTickHandler.java @@ -23,6 +23,7 @@ import noppes.npcs.client.renderer.RenderNPCInterface; import noppes.npcs.constants.EnumPlayerPacket; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; +import tconstruct.client.tabs.InventoryTabCustomNpc; import static noppes.npcs.client.ClientEventHandler.renderCNPCPlayer; @@ -94,23 +95,7 @@ public class ClientTickHandler{ if(ClientProxy.NPCButton.isPressed()){ Minecraft mc = Minecraft.getMinecraft(); if(mc.currentScreen == null){ - switch (GuiCNPCInventory.activeTab){ - case 0: - NoppesUtil.openGUI(mc.thePlayer, new GuiQuestLog()); - break; - case 1: - NoppesUtil.openGUI(mc.thePlayer, new GuiParty()); - break; - case 2: - NoppesUtil.openGUI(mc.thePlayer, new GuiFaction()); - break; - case 3: - NoppesUtil.openGUI(mc.thePlayer, new GuiSettings()); - break; - case 4: - NoppesUtil.openGUI(mc.thePlayer, DBCClient.Instance.inventoryGUI()); - break; - } + InventoryTabCustomNpc.tabHelper(); } else if(mc.currentScreen instanceof GuiCNPCInventory) mc.setIngameFocus(); 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 3ab43c14e..2509837a8 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 @@ -15,7 +15,7 @@ import tconstruct.client.tabs.TabRegistry; public class GuiCNPCInventory extends GuiNPCInterface { public static final ResourceLocation specialIcons = new ResourceLocation("customnpcs","textures/gui/icons.png"); - public static int activeTab = 0; + public static int activeTab = -100; protected Minecraft mc = Minecraft.getMinecraft(); public GuiCNPCInventory() { @@ -34,54 +34,43 @@ public class GuiCNPCInventory extends GuiNPCInterface { int y = 3; - GuiMenuSideButton questsButton = new GuiMenuSideButton(100, guiLeft + xSize + 37, this.guiTop + y, 22, 22, ""); + GuiMenuSideButton questsButton = new GuiMenuSideButton(-100, guiLeft + xSize + 37, this.guiTop + y, 22, 22, ""); questsButton.rightSided = true; - questsButton.active = activeTab == 0; + questsButton.active = activeTab == -100; questsButton.renderIconPosX = 32; questsButton.renderResource = specialIcons; addButton(questsButton); y += 21; - GuiMenuSideButton partyButton = new GuiMenuSideButton(101, guiLeft + xSize + 37, this.guiTop + y, 22, 22, ""); + GuiMenuSideButton partyButton = new GuiMenuSideButton(-101, guiLeft + xSize + 37, this.guiTop + y, 22, 22, ""); partyButton.rightSided = true; - partyButton.active = activeTab == 1; + partyButton.active = activeTab == -101; partyButton.renderResource = specialIcons; addButton(partyButton); if(ConfigClient.enableFactionTab){ y += 21; - GuiMenuSideButton factionButton = new GuiMenuSideButton(102, guiLeft + xSize + 37, this.guiTop + y, 22, 22, ""); + GuiMenuSideButton factionButton = new GuiMenuSideButton(-102, guiLeft + xSize + 37, this.guiTop + y, 22, 22, ""); factionButton.rightSided = true; - factionButton.active = activeTab == 2; + factionButton.active = activeTab == -102; factionButton.renderIconPosX = 48; factionButton.renderResource = specialIcons; addButton(factionButton); } - - if(Loader.isModLoaded("npcdbc")){ - y += 21; - GuiMenuSideButton dbcButton = new GuiMenuSideButton(104, guiLeft + xSize + 37, this.guiTop + y, 22, 22, ""); - dbcButton.rightSided = true; - dbcButton.active = activeTab == 4; - dbcButton.renderIconPosX = 64; - dbcButton.renderResource = specialIcons; - addButton(dbcButton); - } - if(ConfigMain.EnableProfiles){ y += 21; - GuiMenuSideButton profileButton = new GuiMenuSideButton(105, guiLeft + xSize + 37, this.guiTop + y, 22, 22, ""); + GuiMenuSideButton profileButton = new GuiMenuSideButton(-104, guiLeft + xSize + 37, this.guiTop + y, 22, 22, ""); profileButton.rightSided = true; - profileButton.active = activeTab == 5; + profileButton.active = activeTab == -104; profileButton.renderIconPosX = 80; profileButton.renderResource = specialIcons; addButton(profileButton); } y += 21; - GuiMenuSideButton clientButton = new GuiMenuSideButton(103, guiLeft + xSize + 37, this.guiTop + y, 22, 22, ""); + GuiMenuSideButton clientButton = new GuiMenuSideButton(-103, guiLeft + xSize + 37, this.guiTop + y, 22, 22, ""); clientButton.rightSided = true; - clientButton.active = activeTab == 3; + clientButton.active = activeTab == -103; clientButton.renderIconPosX = 16; clientButton.renderResource = specialIcons; addButton(clientButton); @@ -89,29 +78,25 @@ public class GuiCNPCInventory extends GuiNPCInterface { @Override protected void actionPerformed(GuiButton guibutton){ - if (guibutton.id >= 100) { - if (guibutton.id == 100 && activeTab != 0) { - activeTab = 0; + if (guibutton.id <= -100) { + if (guibutton.id == -100 && activeTab != 0) { + activeTab = -100; mc.displayGuiScreen(new GuiQuestLog()); } - if (guibutton.id == 101 && activeTab != 1) { - activeTab = 1; + if (guibutton.id == -101 && activeTab != 1) { + activeTab = -101; mc.displayGuiScreen(new GuiParty()); } - if (guibutton.id == 102 && activeTab != 2) { - activeTab = 2; + if (guibutton.id == -102 && activeTab != 2) { + activeTab = -102; mc.displayGuiScreen(new GuiFaction()); } - if (guibutton.id == 103 && activeTab != 3) { - activeTab = 3; + if (guibutton.id == -103 && activeTab != 3) { + activeTab = -103; mc.displayGuiScreen(new GuiSettings()); } - if (guibutton.id == 104 && activeTab != 4) { - activeTab = 4; - mc.displayGuiScreen(DBCClient.Instance.inventoryGUI()); - } - if (guibutton.id == 105 && activeTab != 5) { - activeTab = 5; + if (guibutton.id == -104 && activeTab != 4) { + activeTab = -104; mc.displayGuiScreen(new GuiProfiles()); } } 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 9e7b39cf6..ff7dcbb7a 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 @@ -133,7 +133,7 @@ public class GuiFaction extends GuiCNPCInventory implements IGuiData { if(guibutton instanceof AbstractTab) return; - if (guibutton.id >= 100 && guibutton.id <= 105) { + if (guibutton.id <= -100) { super.actionPerformed(guibutton); return; } 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 07af473b1..a6c1a4dc6 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 @@ -226,7 +226,7 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener,ICu return; Party party = ClientCacheHandler.party; - if (guibutton.id >= 100 && guibutton.id <= 105) { + if (guibutton.id <= -100) { super.actionPerformed(guibutton); return; } 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 1ab495627..6091ce220 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 @@ -171,7 +171,7 @@ public class GuiQuestLog extends GuiCNPCInventory implements ICustomScrollListen if(guibutton instanceof AbstractTab) return; - if (guibutton.id >= 100 && guibutton.id <= 105) { + if (guibutton.id <= -100) { super.actionPerformed(guibutton); return; } diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java index f85d95c00..e702e59cb 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java @@ -122,7 +122,7 @@ public class GuiSettings extends GuiCNPCInventory implements ITextfieldListener, if(btn instanceof AbstractTab) return; - if (btn.id >= 100 && btn.id <= 105) { + if (btn.id <= -100) { super.actionPerformed(btn); return; } diff --git a/src/main/java/tconstruct/client/tabs/InventoryTabCustomNpc.java b/src/main/java/tconstruct/client/tabs/InventoryTabCustomNpc.java index 888bc77f1..39f9f1761 100644 --- a/src/main/java/tconstruct/client/tabs/InventoryTabCustomNpc.java +++ b/src/main/java/tconstruct/client/tabs/InventoryTabCustomNpc.java @@ -17,8 +17,6 @@ public class InventoryTabCustomNpc extends AbstractTab { @Override public void onTabClicked() { - - Thread t = new Thread(){ @Override public void run(){ @@ -27,24 +25,7 @@ public class InventoryTabCustomNpc extends AbstractTab { } catch (InterruptedException e) { e.printStackTrace(); } - Minecraft mc = Minecraft.getMinecraft(); - switch (GuiCNPCInventory.activeTab){ - case 0: - mc.displayGuiScreen(new GuiQuestLog()); - break; - case 1: - mc.displayGuiScreen(new GuiParty()); - break; - case 2: - mc.displayGuiScreen(new GuiFaction()); - break; - case 3: - mc.displayGuiScreen(new GuiSettings()); - break; - case 4: - mc.displayGuiScreen(DBCClient.Instance.inventoryGUI()); - break; - } + tabHelper(); } }; t.start(); @@ -54,4 +35,24 @@ public class InventoryTabCustomNpc extends AbstractTab { public boolean shouldAddToList() { return true; } + + public static void tabHelper(){ + Minecraft mc = Minecraft.getMinecraft(); + int tab = GuiCNPCInventory.activeTab; + if(tab == -100){ + mc.displayGuiScreen(new GuiQuestLog()); + } + if(tab == -101){ + mc.displayGuiScreen(new GuiParty()); + } + if(tab == -102){ + mc.displayGuiScreen(new GuiFaction()); + } + if(tab == -103){ + mc.displayGuiScreen(new GuiSettings()); + } + if(tab == -104){ + // Profile Tab + } + } } diff --git a/src/main/resources/assets/customnpcs/textures/gui/icons.png b/src/main/resources/assets/customnpcs/textures/gui/icons.png index a0bd71c262c6ba8c9057a4cbd66f83c9bec698dc..bcfb3ba65e65c136dd12360329e2cb7c6466f3b9 100644 GIT binary patch literal 4653 zcmeH~c{J4R`^WFkEE>x&)(2&cM%mY_na18TAqhoxqGX8}ON=$LrGyY#@E|6sWFJdZ z9?CpthYUU! zoC^Sewz4#}0|45aLI4HdGnXDa+5hc@+F9U1-Qa=cJqK~&_{rk{)Ms96QzP1POc9dIN*-*DGexOUFaUb-i2pvG(U(Jnc?7 zn3-BtVX;LbBK3>xTQh9kqx!mK&TKZDPNNwI-XPP; z5?h58DH0JT3S-PMrlzJ>u3RCJNLg7~gx3f2mtw*{{{3Kci{;{bCOOQ``t)8(|Lp>o z{ao>T0dWRfo(%|WW zHJ>#Nse!?)Ry)*f7gH_6oEi9iTZNuR4vr|^pKYzW`}Wi#>G9dFAWS9+Z_?e}eV>0^ z@};5Ld$`PB4=M4xnCuXGqM~D6*4Ajbn#`PnjF-5v_?}>}Zk#*y#{yqpUkgIEK5L#q zd`v@y0hd)6>U#Ik()f5m#iyb7^yl|i#>h6oFnGSP5RgNi>=8&amCH$ewJl7!qv&Y- z15y*n%Hn_EFaB!!y)7R|jboW#$H|#@>1WEzra5_E(I}zs#PWLt1m~h%o45c+4kR%JP>80UnlNY zlQQ)*9b0@9kSkm?E$dYErCd)=06Tpe1)Mvx zZ+8Wyn#!itB_*=ivH>^qjREx+EJ@=8HMx(kR;?s9AUPXa3gy?)-xF$Bx_v7aORRg3 z;$zFgh&J-kZ+^DT?5CLBhDnP*wSq9{iANwcCBP1tn&=z`4`hmjz|hT;TqM8Ohmbg} zT}=(1Aw9P$`y=vE?3BRitBH3XUcW2-e-@?fJQ`*wuUcT!_s7J$?=o|HG z^Ktn|rgP&=HqdLQ(l~d|2)a~B!X{i)jE#(p1}Yk)$9XVnzC6PPn_+?L61Tu7>&nQ_ zl1Z9E@y{FAMoWXHw}vmo#oB;2?%npkVwo^fz;3uoY3ZPEJe=tI|>}tbYSb=jj`FN)&ur zOH0&m4onX&Gz^~wIo+$@ey;lWa;3YS1=O`BJ+JV<7k(w^GC@7)6iZ}_0CJpo93%uP z$;K+V{R=kj?itrM?-G~7a=iWy?H)oGiTl33dVuvN6x_kz?-JEae>E{b)?i*Ar30x# zsG$eBb{ZU)7+(N29&7C!drm=B`3@U4!5&k6{sN zL0l#^OYvcJ{WX%9G#qbk|D{V)&5aXxnCo@_oW3^D=|0N%5_qE-JeeF6O+uvJg?X=BQENo?ZWj2NzFcab&{avs=f4+m4a7`Hc zQhxl<$R)KXD)t`({k4S^mnVPq4h~vBlw_WKEKpjU@k%i8vBt8XWrKa8ow9hQ!0T94 zY1EluujuW$-WMp6SuiZMCq$>1N5DxzwHA*AuuBUnB#UfG-cH@Fk;OSWcI}jbLth@7KZ6qZ8Yvw)u7swKQMxP?XDIX_p-7b=O zvAIt0#BB&n?jOjUUgVJCiJrmgLQ3&z)Ey_?-TsI?cf{k`Iu3{#6+`PQZ8xrx#5jGw z*1K0EF7iKRv=$Zi;AlDh(?j z8LxFvzubz9E|as`5vQ-I^2KdNMh7)EG3YXK_|UO!vl#_|NPB6l$YhXJ?#!{^h-XJ> z#wZLij8;iIY9mdB#`Sf_qY{#Fx`cWey7Plipp2I&X8Y>LY;5yvok2MKBaDzRNR2p8 z#@HW81pre>I5anf<%E$&N%d`R?A^VbMzl25@30~pnx=oA2Apz4?0cCfwyp`c`Mkl#%EzPC>hOX8Co&Z!TP;Ot&c7auPY{h~VPU*qT*c zbfZI!l8T6voWmc&Tntn6?vW8{xh-WA29}cKZs*Ez%IAjr#!tJk>)VE=0(FkQh~#35 z0ZlMH*&1nBgm=VGA&oBG50OO`_PGHyXst( zay^pJpK)riCn8I^o}sTrd3KD1VWD2l>l?5Ln zWlwab&jQNU?OGh`7-`T)W*=$HSPi`xI?f#ibXUV$p3`)*p1(wifqU`JR=4D;UTWi& z`l~-&%ri?}(8%lZEttJk#0dI*6?G_~?aSmJzI-IoO$uJD0+4q<*`h`O0a(u&0t|bu zKk>pl7-LO#e8&@zxf(VNT@YSUH(LfSKvJaPK;z5LKk^nw*Kk--TpDxV!ssEl+U7x-03!Pq z)mSN!voKi|-g*pFgP#x+ZS^5Ze0(OzfcM#}yoFIE%d3S+lNT)y!-d~XCj8zJ_Oa-f zA8lC73{ckB!%IyVlaq?aj#_`+rw`~yFh`_Z(NpohqS=8naTwEJ+VxOyKo*GZn~%2D zm7;JIv%YDKkYad|pW@*Z*`@Ip=c~>ZKsUecq8%|l5sC^YG>n#mgwi2kKD0ClbIBQ( z8%)`~DuZ!ao9x7KP+x(syNMQGAPUnBFWH*3NgdyQBA=j4i!KY$DZ0+d54<-W@vVH% zP7XhIawzv~66U2E4iO4Hk5X4nSOGy1jcFh}-Haay(0xrt#MjwsB1FwU&&y#(sz4b} zYt*l=bgFz0pOC9WbZNw--*wPa`tD0*q}6AOGU23tQnhmx(YSLqq}s3W(domq4XO5+ zv`VV{+ev+)WBhuIc9&x!ET$N@3;J?kU`fnng0ym^gg2SjRZ>#2tG}MvRs&OEiM$t_ zT|Q9lQ1f9AwIjbp!5oi$NwvGR4z)4|EGWo1_Bx)`^JX?%rOb4LfP|hnw)aFtDi1|3 z-+O5B%Nou$*~uS8Zdq{QE?h!<2({(d1m@=SCKN3%IIRcD$VkF713ueY>L5^{t0R1M z>sJ~l5uaf!tC+4!n)67NLhX|mSPZ{N zh$>2#yqOn>U}j=^W3PFhXhzV<$cl=T$}*Jo$>h%`NQ191hSG!3>pLL6--Bo>x!bKE zrh457A&@eQl-_al{OiR3g+<=~KYIGlw*Q5b|D6!#h2@PgG8@+xyA!=!I=^3~*>ZV< z`khuzE#Z+hVrU-v<{FbT*0$aC{Z&4UZb55*63r+F3ZQM93rDMy?#A3}A8UcB{llGI z{KPT;_XX+%uf^e}iS#@K4Mi!qSEQbCx9MHxd@J#B$FHo~C+gdqQ^o2AN1e4)#YqvZ zq8k4~wN6xVl%9*i&-S5b>1Gd|ipd{8aGQY+jGn;xf5_0teEOM0U%kZk10T@ZI)^~5 zZtcOI03qRGn+FWmfQ`i`lrI0y-+BMS+PwhX;|e$FRk2y0tg=-YPc=*b2wJFUV$ z{@u@VltI+?y0U=uv^&>cGdM0lpRV@*_~Lxfw{PFHzQ(`1IQOJtLl3(0b6uH5eIa$@ z@A_?9BLn^i4x*%ysT_% zT+HW_`-E#8>XjOOLxAn>q|L_U)xJRcn)5KzF;yG~W#Y?1c9M2BuH4sy!>O(mWDS1| zdM;7v!2v*gY_=3Q5V^qTY6SAmR5=AE|Er6wHcJ$sP|5x`*Ec?LStrh5bRXn8nl#!m zVwotv#>v`i`?kuOmn(sc{X>01;yE`>N}RrGoJEkRgQ+wX|Fdo-pA^3B&uvcfDmoLZ zjthpp*S@aYomwf8va4?4IJDZ2+1vjLNcLnD+wsDh5<}WXLvQWUY@3%HKgyGT# z`U$rY9$r81F~vS;-xF9$3d09muxvXNbcr^GY=zWoCF%Qx7UN3TFNZq7E;3J#x8JOy SQf=?s4y??qP3!RP3I7EXbbpZm literal 10888 zcmeHtcT^KW`|c+6UZq3ms3<6?AT@MCFCqw1l_Ju6Cx9S`^d`LtA|RkhF9}_G2c<@e z^xh%BUB2IU&;9S7bN|14&SZD9+04v4Gw<`h&odEP8cJluOvC^HkRg=ibpQYYUP1su zeDL(rrO4{$&Q(WA7APBFSpxue03k2)%qwGS*4K;ns7ZSFgg5pbPdYP#E8skpgeJl8VK(S zJ7vv3zu-JCj&iQybl4kB14=KwE_1H2>&TkEp2UgLI#@@C5&);}ZTIoKpbUapMaY<1 zms_2MRtsdzX)o+gS<;bc85Vn^+7N{67y=d|^P&spzOYu_H@n|n+V@3U$mW?3s{_uF z*~vO|elYq5BM4w@UnLr775ciw4Td`ap#Z=dhNh=WN;NgIpbfL+Btkq*+z*!L?C$hY z=S!T3;NM1|6It%iscy%^Jza&T?4JPW5aiNZYA2#Y49l5s7u(4+>F74;^AWj;i1=Pg9ffl>yDU)*IO7I5k#qAa zR&jdO*HUf8Ea%nNLm2}vp&Kjmi)#ytmX|f0m%DFVr2(_c3>$SJcBZ>EL~xeN<*sv? zk|$2`De}A7((^&Z#exvP$~Eza@rxICHd$HgTNWKjch93rA~5tyfdC;1@%~rhp~Op^ zmh3oR;_>lYHiGYYIX)`7=3IV%`P$O5)rJ(_y`>vO;{imYQ%c@hm8RX%CwV-pMGYO+ zI*TBCjJwqv$K2X-M=jO6*iMhK^AMEKE#kkEYXtLmrpY7obGXDR@QSKzYl5 z#R3@Bz`&a6`;`W};KYe2Z#ga@-~2eE`>Ur%-Y^Z1PSb0^SaHDU-Yj4_w;LCKXPRp)_{>SVS*$w`y_Ev3vu5zyJt|9Y-IiA zJUHmMC@=f9Va|}RVg@|}ChvYeA^~zrOP{%v;mYrxxF0VR&(FLY3_LC?#1bIqk~L;2 z@}$m7jOl3>^-xHY7dtGmS=Fp%v8Jf^_D04_V;Wt z%ibcL^nLY@>CkrdmQOia0DKwVl~w;Hhd1~ddqzHcgg^+J3#FRX)a2@pHwYfOAKQvu z9(pljO_lds=ITu0k4VOPO@2<3r5#_xyG*-%BZ_&^I^M7JOwr1GLC0M#=8y2%#eJ!W z9kV~28aB8r(U+dXvTc5K0zH)3ZdZLWzwdf7bZVyYh4S4S`UqXM=kws4x&~r1B=EYs zb+wF*b6NhXx3r9;JwC~=*k$kOQGuZCrI8{&&mu6JORw#ujSD1987Ywy+YayW@E}gy z1aY)wkrCR-jxdH?C$?jpC0-=quh=oapGK~acFeg$P=(B=00L>*T$aOI_uvkoaSuS4;ufu&`CiqKGkq;>SuQxsM= zSLP$M$oMEdJ+W&&A9dh|)Ybkj>ik13fQ^n3@@3$`aoq-g;7wmnQ)PJWTv zLkRb8%6RmnlD_4&&>eN0hS}(!k0Ko|=3h9f^7V*pD;T}y|0nI9{-d!=T^N3<^tR;h zd}}NB%UYzx5piH(QOehl`AHWONx7lvNiVKBLfW6dA^k zP_t?oFm`~Wi0<6H9rB5&wraR0y2)Q8?I}@sm;wTr(>PtTEg8?GXFrD&m++hItUmY@ z98xeaVB+S{BZoYWCYO7WDq%c1J8a4gLdeGlobGMZ;9@1n5x?bCdw322Ik~w+;L3I| z71oi?t~^`Sc?cj6YOhWa2LP~c4sTk{D#XW$-n+_mJB_Hj4sJkaOWjwut*QCD`De(X$m=Tm>a7*+VH&gs-Omu3b7U*?Vt>qJp-nh8%%Cx(yn|9<2Rw?`U%jL&c% zAaRwl+it! zY3AjJ*Hhe(J&_OL;Z863pv_=?^@%Ozp8Q9u-s%ce*w)GWM7N2|QagfAR8=4IE8XQ_ z5%*Bjxz=UuigInRx7MfMKREE$fc_PhijB9{AOK#j7I&yO5q>QUmG70mO_OUE!`2QZ-L)+YcB_tD6AWjQ&4~h z#AaocF)#U)*U=)(u>2aOfE|6y{w}a>aNI^R=7N$R|6Xm@iUKb2 z4B`Uh^!2uJu@7K?mhLDKXtEz=FCyBmgA1uw@0)@qhp%7s{J0sH(T`GYHOE{BK~A(S z&Ro=^d9I=j(}cd(%ytuO?^q-x?`Hcy7)a7rRgI)xwP^AZsJ4IeX80Svg@pxaN--6!7-0xZT z2<{3e&yYuHCn^TMgWpD)>K^tSq@DW!Xw-aQ%;+HYe5UFJ0^mFyuNkEl8D;r;7lShO zc{9|NufR>{p2VJo1DBQkraD5opM9r&Bydm>77)H~(G?|rjNSfhev~2q)ouMwMk%o1 z+KIMm3a>zz7mr+X4jldDd?*B&%vU`Bb=SY3g*({TPak%vfJyJy{v_&5J?HZ_eZT(m z=hU0{qG7gdW?@T*51NAMLicNXh$wr19sZ>ng|B#rC>)bbn+^b?y81XduqYe^{L?G8 zki4)+uFFNGeg@!lWF9tI_XnK*(8T1sN*{B1Lk7wO3W#n-0?1)G>iD6a{)EhOl5N)a z3zne4_W2{a0TGM&APrz&^5o}W{@&T}=;>Ca*d+w8^sbGrGu~X)ro99X? z{AOKmChkRrR;W7^3FUmkO}*k{=i9%fNuW|C7{ZiO+@!4FWC!TT=lc17fyvr6FIKrD&l8ZLVp*cWLPu z@;5c*`rfU_FWZ@8=F2ZCC+DQP3j{3>Ob1_%d@gM2zZ+)2 zj5o0=O_`k_SiX(SKRvy!*b-$MP=x@GQg*tk{wnPzynhb;EpRKlDO}{L&3{+Ac4Tjc zh}lKRp zwnc47+aUL}`#F-x3JKD+(7}Qx2Ril2=yKlk40oCc7RetEX*p|Qwh&dJ4 zSsAnl-YuweT`AT_G=nar+4sN`mHr-y1nj1d>3L4SO)!C7!3D-9CtF_=-}3ZU^f>11 z@~4&*J-E(td)o8jt#Kggz{G2KBW*|R_y>Y{6g z?uzl9F&*C9i{|SR1OTDYu2;PY-2$k}@fdx79)vk5kdc}3aqCM703-+9^6pJ=x@shQ zVk8b=bRU`brSESwlt;#i%Yp&D-Of1b&zDLNJ(xi-;U%-qm`@-vt|BBP)%Q6*n%EJi z{3d~q^d}H&A`U=nLuhG#$*@BMWz86Di_;*9X3J?jqCabJ!BH&ar@(;NjD za(A&|`S_~!YytI}9Kamphfs|E*;uNnk+`pxMtM8M={v{1^lXPBW@wJO&p18^CJ|rU zSeVzy^8Pp(!}WF;15;Vfyl5@Zm3C~&3(^*S`{gCRBfn!i);*zO7eo;Ws-SL^J>=h+ zZzk^C@AJF=tgUfk9p|N-7q|hqVpztx0yX7wv)FD&eGd&EB@NADJI@7y~Jw zvP<#42ujzkRL>nm7OJlE@+Vd}<2~VG6yV3g`HTQ{`^-_(5i+8?``*4Q$uhx$#;LFj zf3Ug2pZ&DyS%dzS0CkX;K=Sx@hh)sXuI%hUygxO~Aw+T7pD3xqVKd&S6X`b9SBG>T z{*xYkqLiYm&By5oJW$$03z>$PCSHNTq|Wo_g@uw|1zeB9o1qWYYC-FDr>n>wLb$mZ z_I7cED_r{T+{6lwrofz!e{L~F4q^?*>ABWW*x1v*1}9xoW@?0EE!h^^iZc|Ba$7J@ zC}34sxNx*mW3e4i+NY-8k=w-MwV9#~mR{~77N}+;(N&rQI~81pz#_w5AaD&fb7 zh=(^3i;7BG#QHjMfxjTNjA9rbnCumf?QCx9K?D7q7zR9RQId_qafI#K(x?Sow%Wfw zz;-%uQos6X%W-CXcAGKv?@z3j2BJemMI!RG>~k01P#@L+>vh}R2>T}vnvU8kf#0!z z=&QNr;v+LJ#FPF7O^yZaG}^HfVV(M^u?r{BL_TjFvmfR8;|Bmkv$LVcLDJ{lx)2AE z0i!J3-s?BI&3*;s1|@n%QctVwjTyS4LY!wr<>lp9HT3Wf#dmPQ*x6?QIrsK34R7P> z_j{rs^G}ovVZURQc}~UY(zUg#DIhfkII%IO^vpq9f?Em--cQ*sENMaPf9TN()2{Mv z&AByj&KNNAHM@qLLzx^KOlQBV8GzFC7LYKW3CBT+hky$bfA*TSWIJql^^`e=f?Q5c zjz&dAMO#PbLs%GZVp7sw)4T&s+(0n-%u>Nhy z=o3GM=d{Z+@G0Ci-E(&SRcHI;>Y#pOHXu6ck9OGQ^E%VJf{&Tj(es}9e{O<@&nCxi z&Rn+jL3n#{J=NQ*?x(ZW=x|ND%HfyIFl7FwKI{xOpgPQrugNrc3(a^7;<<>hp=@3P4I@fB3r0;%R=Zrr%6hFu5WVZW42AC;a zO8oQ(pV_n-$h`@N9%C~3ZhehF)0dSUb)7j5DlPs|=~Iqw*>2*&*;tMr^Cl0P`zTxR zO;Cb|Pjq-501gP6`N&JBb9@BYUTNQ^yC3`voUbiuxOv0?va_%f3<+ixDsD{YHYPti zS@NE4+@$^~Jy}e77lX97P+wQc4nFWqWO{e? zO*o#jEz`4v<8Dx`jS>(0#BxE;r9_^X)*y|6beBJ0p4jQN&plb!pN?}VQ}0rNi^cnO z8VAtEd=2O@4fJvE_#le7{s!NSl3zGYUbqnLkBPg`1*$tdc_n*lfOYG~>z6JUA!-4A znh+C?JVj-1?1&Q|=~uqPq7?{$zP^&8h2K7AjqSQDZ(^#oO|FKapK@eqC0znbf1851 zwO;7OMA!OTsU{);sn1aFBQCP)7F^I;!236Svnau5)dJJLi+@vAoFoVA>dBq6< zTr6zt#5R;EwP}*%Vvn|AzJ#Ub^(mdNYBGdLW>qArMeVp5jlc z$PIztI&^xbxXuo<`w{E9D+0y>upU;)ONx~OjGA$j>aO(BCS6;bx29^ICOVy)Qj$X} z0gxYxv|MN~;H7S@ql4WgfPI7@J$%#SFH1J8|5jxxEmtA-MS6uu(i+mu-=yO*~*HvE+JrW+T-?lU{CHJ3F1?#i{#ztz=+g4y1Qcw${7IzVM;>J%|;8=e@Umr z7?s!IIc`sd8adYC#b8~?vb+|EB=&nv&B5nhhr>#H?KGMgebo6a@WCq}(oI_KieSfV zt;P|boez?5XY9KR`|t5_8F%+kA!4oPyf8v?S~@7w0k6XCpW8>W$WB(0{9*4xM$k37 zoL$#>G;|-6qvvv2E+I~0%gO2U zs(r1jB(kdH+SAk5#|&qeb`)BR@b@ZM=N65PjE>G;1&l3T5Wsx244dx}ASF0=w~ZQ{ z+FH*T9Em*|;YYvgWOtKmB(Z7SIis{-8WQsUK<8P4e>4uVYc9b1;u2o(c?*g0`|N45 zok6P@IV}aq;DRh64qVHC(!>_8OnM};m1|$Xk1POW0!OFs`4o4!dVaxGkeByrv_dwV zVT0?1wfs)TyoUfpbrhg3%D#--BOj?r23RepJL3eg`R(phpnQrPBI*>uLY)ZzPv z1l)VQ_fA*+kB)HseDlf3)CFiXXR7!^?;BMsyRHnlGh^4^0^y^`qkj<5e*i%7jfvz; z0_eK%)ZlbXsbWh0A|opvYmppdz)AG+8Ut_&<;6Z5$$JKX6!B>+?@$K|RJT;dn-soQ zDm;E^d_IXj^F9M}~(J z)~xKOgT#~iphNO}d5o^Vuzshi!t}Sa$v)q|3T+$wjtM}Wap1Kl3P(;!q7(j&a0kXb65b}0iFQ0khi6twFyJ$}M4F_)hSxo|T1 zFk+4Ar8JY%E%CWqp+E36D(_>W3_k$(J=Bk^6X^WDEu(x)-z2V-b7&Jc8OU(-j^kmv zmZSJl-8FKN6BaFnTsw6#eb^Zt+2&ea-+U#jKbkX+!|n-y83ml^wAiO{oDvsql49vX z<`zfVF616TejBplGBJzZQ7IN}esSr0;2{n)n>H@q%=nnVL$2(97xeZuOgF;~av`&? zG2PegDbVK_felqJ$pwMU?`(U^TX)A0n6uDful74c_gFqtz%y}isjxoNk(kL$x=lr} zGyAi;)RY^7-ZWquTOha;Xtoj%lvBZuk+Baue8N$iFJi8|BLM{onvC*88n(>bx)Dvi z4k9q5d`u68ynK(%Fy$*M0a86YjEox=PvY=wf>DjNu&+2P;VJYdT<+0VXA9fVfu}i5 zvkte}F1rmaHNr%V4V*;m_WHLVP*YRCRQ)+f0YmG(IC$LKt`{_8 zOs(cmj;wT*+=scHcX-@0>9T>tr@E)#Eh=NrTy~ z9qIFB8w8dDfP0oa8476)b_-1YvPG&(X48mr{)K|6yTUtkcYWK=^4M*&it%K2+F_2g ztghVAaT!FnYotR$lHy06Lfkw(|F(Av;Q;S0jXsTu6i~>R%REqXZv@%#_8)PC0Wv!o zkeXJJ^W$FDT8*6TeVK51cG2uRo=2ix0%J0QFQZ!o!>`|ie1;13ZX!U}*aW9;YtNz% z5+4YHu~A3=%2D1lZ4NX*>{%&x#lC9?Jbf|Ks@}$9es(EiI;mU95AiPH<+Cb|P0R zSW46yQ#bSCP569EK9hgGcM<@qFGG^HS##P#oRGr-|G)8fCLY|?L%Qz1%J4g4cH0bk zZOrkIXhdNK_*q^_e_U*(2DZd|^d2P- z%8T@ub@!hQ?nH3fpVXxX>6;|bv{E|!FbkhI*Al~Ks0LPHSdIyXMA97GQscSIRifR9 z0sum?1U|IiVTg3DBgWAAsuTDW--OzpZcNAC#Be(^^a9ILp28r-1F~8CBD1R{Z`#2G zUo}o-slJJ+TzHnt%PE@Wbf85rIjVQ;5uU{M+luV@qtwq=`$tFeDZ#vuqL`~i-q7`C zc#JY`3xa0GgP|B~oz zxiAz&7-u7F&L5ANszDFkbHs^r9Cl8s-MwdIvguPkc<^eZJnmphBzZ;Xf`+mER-BvI z2mtgD2%%<9P5s^EC9kwrPmisU9k174PcTF0tToKW{Et!E$IUh+$JJUT-2YTU;+|F_QmYuKVQ#jN?b!=_y z=UUU7`ACqcpr#D6uc>LV{njGqIM8wM<;UacB>EEypF@I-us!+mz|r!@7X&#?goU=u zN6JCva=~mTnr@7)Ujcc79M`k*GU%96U{w|ei0%d~Pcvh3=5SHHR7PK*PBnp^<$G1c z3~v9eR9g>_Tbn)6YnzT6NvF``KgrT1&;&KvXggAQ@H-Q{JnD*dHY|oEu`y-U<9cgZ zwTd+mr=0cPY0?w_u~)bM_$(&(Z~*`@%gtVZ_RA}hhQwyPW1OL7WmmV%Mou|mjWi^Z zkP90H3E_pT{6KvvprN0t_Y*@Xzuc9Z`3xPJ%Nd#Oefh@fl8Dte78HB4j!pMX^4{*C z-bceN`vQ^r7xZ~-IPdY+To%9uY1!zyds6MTaFE>;smX?g%^o)kE~6};7rq8vc4}}4 zkMovy{zJI%M|@CTrd4ZciN7Oi;L&~JmhyA|+>z}p{=+bErCQAfk#%rJ zK-V#_iK}_l*F5kPvYJU8%AhUvo#yh)z;z5&i$&GM?G`R5e(dzfx`{`O#StXdDDj}yy!Jno-h)7+mC*`9x@}6Dk6_qRz6MGe zv?)>Gx$ZxuYGca4aF=C0DQNS!TBfVNiSfDX;Z!zL>gD?xX!i%1a=J%4JK3u`dtQhK zo)Kv8rW#QGOB5d|EO?>y{CV+VR^)Ujj>}MZZq*I@)91mgw$*@)HB$7r*3d&2H3#OY zwwJtxMvqlp;~qsxf$wq;JJ2n4Mcae&FV9N!R+oD%lzp{*Zdu%4=PSHL8|8eAOCL_uzk8wh`1>!=l+!bvy1{q%)9ceOTGb~Bkall zN1oJArit6Zf)5$gK)nz^j=NIxP+`?~!nioNpoNV7rTF1t=6wYLINM90teI+cnA=bV zOQm?1Px!<#^Ud(nj9L44O_gL%-crbtXEnduNnG97_)!iFY(L2Zf4JtI3m`!q6aq*l zyfv>pM(=l6UQ>k&7^S#hc>hOzvXutdrL0LyeFZq*m@u5nikX!kzVDw3`MvLm-4VK{>ZN#v|m~|CS5o&R>+QaI1Xhi1U&zrUEG0V1(&a1OTPW?jyBAErYyx z?Wt#Y4NXx95!mS)l*d!6W@WAOI~iJyuxC} zUdkw1R}n1|v>;^{b8xJXG%k43nw;yy@G(JC@ZB61?#>v9>ecAa-taqk1irJ2S=VYD zAg(&+?!Uh+xUJ-PCWLr~J7Tlh>2KZA#>i%-I@W9u!KNn#G)WS8al;^hg&ar} zfqbW&uj&I&1b)D-a`6v)koY9uy5FKS!C5|+LU;u_!2T74YUKkkT#L^ZJMA@!zRf=; zUUh37BPeP3+Q!C47K9fGJeBc(MDc;LKV5#(w@?5eXJsz#ZE)g#BlE0aG#`3$t?1W* z>dvdQTxMZi-M#YzBW-OHa<~R@hoxSv)Evf@(Xna*?cjKDWGSytTR@T1xJ(F+r}=MD z|MxNy&mC>R&N4+*d)(7l%)oaTm?!2^)_Sk!l?;-#;Zg1g-`D(KIOeG}iH#KcotCNnXh zwU?F4$^A4DH#3~E`{AcJmXMOSmp4tPqFLf-=qdKGWX>%!-o~L+he)pP1w6!BKf*`b zMF;<33BB11b#n;wnAx zKiA6WiDc#!O+k_cG&KM!7xxp>fyjOpJTPm4Ke{Eqt4T=e`erop-^X!7ocxCXNI6pP z0-&6W1nV0axz{5GLM17U3TVpT_j35tw%5>a-q5KFV>(;E>VUO9tI@CRV;ssSb9%~H zOLAV*Ye?2R%AU)r{Ez_0i92Wy#sZgDq>WcGOvKO!nNH4?5(RixLdM(tId6nVo>M)D zpuS|WHZ+faHfIt?i$Iz^6v#m$kj-5$7VMYetuNC;J2f5!ng!u!Sf zctc@`WStA;b>;D*r0e8WO%0jY_Mo}Uc_FwZ5#(=*%F48|dJ%w*ZTlt_ncrg`BEX3o zO0dFpW!7S9YzzU-!>e2LX+09m5rHKQ^ya1lu#`hD7XohAQ4tR6Mm7`q5&w&m(ECl} zEEJ2m!!Vmk_?nnJS^hyJ71{T`I%;rp;mc}ml!I4x*y{e#HALG Date: Tue, 18 Feb 2025 18:56:15 -0500 Subject: [PATCH 05/59] Fix Profile Tab Bugging out --- build.gradle | 2 +- .../client/gui/player/inventory/GuiCNPCInventory.java | 10 +++++----- .../npcs/client/gui/player/inventory/GuiProfiles.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 478bd6638..b4b886938 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id 'idea' } -version = "1.9.4-beta3.1" +version = "1.9.4-beta3.2" group= "kamkeel.customnpc-plus" archivesBaseName = "CustomNPC-Plus" 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 2509837a8..d2d3e3a01 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 @@ -79,23 +79,23 @@ public class GuiCNPCInventory extends GuiNPCInterface { @Override protected void actionPerformed(GuiButton guibutton){ if (guibutton.id <= -100) { - if (guibutton.id == -100 && activeTab != 0) { + if (guibutton.id == -100 && activeTab != -100) { activeTab = -100; mc.displayGuiScreen(new GuiQuestLog()); } - if (guibutton.id == -101 && activeTab != 1) { + if (guibutton.id == -101 && activeTab != -101) { activeTab = -101; mc.displayGuiScreen(new GuiParty()); } - if (guibutton.id == -102 && activeTab != 2) { + if (guibutton.id == -102 && activeTab != -102) { activeTab = -102; mc.displayGuiScreen(new GuiFaction()); } - if (guibutton.id == -103 && activeTab != 3) { + if (guibutton.id == -103 && activeTab != -103) { activeTab = -103; mc.displayGuiScreen(new GuiSettings()); } - if (guibutton.id == -104 && activeTab != 4) { + if (guibutton.id == -104 && activeTab != -104) { activeTab = -104; mc.displayGuiScreen(new GuiProfiles()); } diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java index 053deddac..5b08d8877 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java @@ -133,7 +133,7 @@ public class GuiProfiles extends GuiCNPCInventory implements IGuiData { if(guibutton instanceof AbstractTab) return; - if (guibutton.id >= 100 && guibutton.id <= 105) { + if (guibutton.id <= -100) { super.actionPerformed(guibutton); return; } From f5a2ce27ffaf96ad32603aef83c182e83055f7d8 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 18 Feb 2025 20:05:55 -0500 Subject: [PATCH 06/59] Profile Operations in Order --- .../npcs/controllers/ProfileController.java | 29 +++++++++++++++---- .../npcs/controllers/data/CNPCData.java | 13 +++++++-- .../npcs/controllers/data/IProfileData.java | 23 +++++++++++---- .../controllers/data/ProfileOperation.java | 4 ++- 4 files changed, 56 insertions(+), 13 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index 96ee90145..f9367dfac 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -22,8 +22,7 @@ import java.io.InputStreamReader; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; -import java.util.HashMap; -import java.util.UUID; +import java.util.*; public class ProfileController { @@ -234,6 +233,19 @@ public class ProfileController { LogWriter.error("Profile is locked; cannot clone slot."); return ProfileOperation.LOCKED; } + + // Run verification checks on all IProfileData in priority order. + if(profile.player != null) { + List dataList = new ArrayList<>(profileTypes.values()); + dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority)); + for(IProfileData pd : dataList) { + if(!pd.verifySwitch(profile.player)) { + LogWriter.error("Verification check failed for profile type: " + pd.getTagName()); + return ProfileOperation.VERIFICATION_FAILED; + } + } + } + if(!profile.slots.containsKey(sourceSlotId)) { LogWriter.error("Source slot " + sourceSlotId + " does not exist."); return ProfileOperation.ERROR; @@ -442,14 +454,16 @@ public class ProfileController { dataCompound = new NBTTagCompound(); slot.setCompound(dataCompound); } - for(IProfileData profileData : profileTypes.values()){ + + List dataList = new ArrayList<>(profileTypes.values()); + dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority)); + for(IProfileData profileData : dataList){ NBTTagCompound cloned = (NBTTagCompound) profileData.getCurrentNBT(player).copy(); dataCompound.setTag(profileData.getTagName(), cloned); } slot.setCompound(dataCompound); } - // TODO: public static void loadSlotData(EntityPlayer player) { if(player == null || !activeProfiles.containsKey(player.getUniqueID())) return; @@ -462,7 +476,9 @@ public class ProfileController { NBTTagCompound slotCompound = (NBTTagCompound) profile.slots.get(profile.currentID).getCompound().copy(); // For each registered profile data type, load its saved compound onto the player. - for(IProfileData profileData : profileTypes.values()){ + List dataList = new ArrayList<>(profileTypes.values()); + dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority)); + for(IProfileData profileData : dataList){ NBTTagCompound data; if(slotCompound.hasKey(profileData.getTagName())) data = slotCompound.getCompoundTag(profileData.getTagName()); @@ -470,6 +486,9 @@ public class ProfileController { data = new NBTTagCompound(); profileData.setNBT(player, data); + } + + for(IProfileData profileData : dataList){ profileData.save(player); } } diff --git a/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java b/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java index d4e61530f..8662e0b84 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java +++ b/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java @@ -33,10 +33,19 @@ public class CNPCData implements IProfileData { PlayerData newData = new PlayerData(); newData.player = player; customNPCData.setNBT((NBTTagCompound) newData.getNBT().copy()); - } - else { + } else { customNPCData.setNBT(replace); } customNPCData.updateClient = true; } + + @Override + public int getSwitchPriority() { + return 0; + } + + @Override + public boolean verifySwitch(EntityPlayer player) { + return true; + } } diff --git a/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java b/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java index a68abc597..853ddf1e0 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java +++ b/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java @@ -6,24 +6,37 @@ import net.minecraft.nbt.NBTTagCompound; public interface IProfileData { /** - * Do not use the tag: - Name, lastLoaded, ID + * Do not use the tags: Name, lastLoaded, ID. * - * @return The Save Tag utilized in the Profile + * @return The save tag utilized in the Profile. */ public String getTagName(); /** - * @return NBTTagCompound of their Current Data for a given Entity Player + * @return NBTTagCompound of the current data for a given EntityPlayer. */ public NBTTagCompound getCurrentNBT(EntityPlayer player); /** - * Called immediately after setNBT() Replaces existing NBT + * Called immediately after setNBT() to replace existing NBT. */ public void save(EntityPlayer player); /** - * Replaces their Current Data operation when changing Profiles + * Replaces the current data operation when changing profiles. */ public void setNBT(EntityPlayer player, NBTTagCompound replace); + + /** + * Returns the priority for this ProfileData's verification check. + * Lower numbers run first. + */ + public int getSwitchPriority(); + + /** + * Called before a profile switch occurs. + * @param player The player switching profiles. + * @return true if allowed, false if not. + */ + public boolean verifySwitch(EntityPlayer player); } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ProfileOperation.java b/src/main/java/kamkeel/npcs/controllers/data/ProfileOperation.java index 62ec9508a..f3d6d1179 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ProfileOperation.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ProfileOperation.java @@ -4,5 +4,7 @@ public enum ProfileOperation { SUCCESS, ERROR, LOCKED, - PLAYER_NOT_FOUND + PLAYER_NOT_FOUND, + VERIFICATION_FAILED } + From 36181d5165dd4371798369f8e2184201c455f26d Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 18 Feb 2025 20:08:26 -0500 Subject: [PATCH 07/59] Better --- .../npcs/controllers/ProfileController.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index f9367dfac..0c5f74427 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -294,8 +294,23 @@ public class ProfileController { LogWriter.error("Profile is locked; cannot change slot."); return ProfileOperation.LOCKED; } - if(profile.player != null) + + // Run verification checks from all registered IProfileData in order of priority. + if(profile.player != null) { + List dataList = new ArrayList<>(profileTypes.values()); + dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority));; + for(IProfileData pd : dataList) { + if(!pd.verifySwitch(profile.player)) { + LogWriter.error("Verification check failed for profile type: " + pd.getTagName()); + return ProfileOperation.VERIFICATION_FAILED; + } + } + } + + if(profile.player != null) { saveSlotData(profile.player); + } + // If the new slot doesn't exist, create it. if(!profile.slots.containsKey(newSlotId)) { Slot newSlot = new Slot(newSlotId, "Slot " + newSlotId); @@ -304,10 +319,11 @@ public class ProfileController { } profile.currentID = newSlotId; - if(profile.player != null) + if(profile.player != null) { loadSlotData(profile.player); + } - // Update PlayerData so that PlayerData.get(player).profileSlot matches Profile.currentID + // Update PlayerData so that PlayerData.get(player).profileSlot matches Profile.currentID. if(profile.player != null) { PlayerData pdata = PlayerData.get(profile.player); pdata.profileSlot = newSlotId; From e8f657f7e685d9aa6e1d3bb75295e01bdca4575f Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 18 Feb 2025 22:22:40 -0500 Subject: [PATCH 08/59] More Profile Handling + Login Packet --- build.gradle | 2 +- .../npcs/command/profile/CommandProfile.java | 3 +- .../command/profile/CommandProfileAdmin.java | 202 ++++++++---------- .../command/profile/CommandProfileChange.java | 23 +- .../command/profile/CommandProfileList.java | 13 +- .../command/profile/CommandProfileRemove.java | 9 +- .../command/profile/CommandProfileRename.java | 39 ++-- .../npcs/controllers/ProfileController.java | 149 +++++++++---- .../npcs/controllers/SyncController.java | 5 + .../npcs/controllers/data/Profile.java | 11 +- .../controllers/data/ProfileOperation.java | 2 + .../kamkeel/npcs/network/PacketHandler.java | 1 + .../network/packets/data/LoginPacket.java | 19 +- src/main/java/noppes/npcs/CustomNpcs.java | 3 +- .../npcs/client/ClientCacheHandler.java | 4 + .../player/inventory/GuiCNPCInventory.java | 20 +- .../java/noppes/npcs/config/ConfigMain.java | 12 +- 17 files changed, 294 insertions(+), 223 deletions(-) diff --git a/build.gradle b/build.gradle index b4b886938..97f204521 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id 'idea' } -version = "1.9.4-beta3.2" +version = "1.9.4-beta3.3" group= "kamkeel.customnpc-plus" archivesBaseName = "CustomNPC-Plus" diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfile.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfile.java index 035fecb1a..70607f4f2 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfile.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfile.java @@ -99,7 +99,8 @@ public class CommandProfile extends CommandBase { if(args.length <= useArgs.length + 2) { if(args.length - 3 >= 0){ String usage = useArgs[args.length - 3]; - if(usage.equals("") || usage.equals("[player]")) { + if(usage.equals("") || usage.equals("[player]") || usage.equals("") + || usage.equals("") || usage.equals("")) { return CommandBase.getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames()); } } diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java index 13b4a13c5..7f768d480 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java @@ -4,14 +4,13 @@ import kamkeel.npcs.controllers.ProfileController; import kamkeel.npcs.controllers.data.Profile; import kamkeel.npcs.controllers.data.ProfileOperation; import kamkeel.npcs.controllers.data.Slot; +import noppes.npcs.LogWriter; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; -import noppes.npcs.LogWriter; -import net.minecraft.nbt.NBTTagCompound; +import java.io.File; import java.util.Map; import java.util.UUID; - import static kamkeel.npcs.util.ColorUtil.*; public class CommandProfileAdmin extends CommandProfileBase { @@ -23,7 +22,7 @@ public class CommandProfileAdmin extends CommandProfileBase { @Override public String getDescription() { - return "Admin profile management: clone, remove, change, and list a player's slots."; + return "Admin profile management: clone, remove, change, list, rename, and rollback profiles."; } @Override @@ -36,7 +35,7 @@ public class CommandProfileAdmin extends CommandProfileBase { usage = " [temp]" ) public void clone(ICommandSender sender, String[] args) throws CommandException { - if (args.length < 4) { + if(args.length < 4) { sendError(sender, "Usage: /profile admin clone [temp]"); return; } @@ -47,55 +46,31 @@ public class CommandProfileAdmin extends CommandProfileBase { sourceSlot = Integer.parseInt(args[2]); destinationSlot = Integer.parseInt(args[3]); } catch (NumberFormatException ex) { - sendError(sender, "Source and destination slot IDs must be numbers."); + sendError(sender, "Slot IDs must be numbers."); return; } boolean temporary = (args.length >= 5 && args[4].equalsIgnoreCase("temp")); - - Profile sourceProfile = ProfileController.getProfile(sourcePlayer); - if (sourceProfile == null) { - sendError(sender, "Source profile not found for player: " + sourcePlayer); - return; - } - Profile destProfile = ProfileController.getProfile(destinationPlayer); - if (destProfile == null) { - sendError(sender, "Destination profile not found for player: " + destinationPlayer); - return; - } - if (destProfile.locked) { - sendError(sender, "Destination profile is locked. Please try again later."); - return; - } - if (!sourceProfile.slots.containsKey(sourceSlot)) { - sendError(sender, "Source slot " + sourceSlot + " does not exist for player: " + sourcePlayer); - return; - } - if (destinationSlot == destProfile.currentID) { - sendError(sender, "Cannot clone into the destination's active slot."); - return; - } - try { - Slot sourceSlotObj = sourceProfile.slots.get(sourceSlot); - if (sourceSlotObj == null) { - sendError(sender, "Source slot is invalid."); - return; - } - NBTTagCompound clonedData = (NBTTagCompound) sourceSlotObj.getCompound().copy(); - Slot clonedSlot = new Slot(destinationSlot, "Admin Cloned Slot " + destinationSlot, clonedData, System.currentTimeMillis(), temporary); - destProfile.slots.put(destinationSlot, clonedSlot); - - if (destProfile.player != null) { - ProfileController.save(destProfile.player, destProfile); - } else { - UUID destUUID = ProfileController.getUUIDFromUsername(destinationPlayer); - if (destUUID != null) - ProfileController.saveOffline(destProfile, destUUID); - } - sendResult(sender, "Successfully cloned slot %d from %s to slot %d for %s%s.", - sourceSlot, sourcePlayer, destinationSlot, destinationPlayer, (temporary ? " (temporary)" : "")); - } catch (Exception e) { - LogWriter.error("Error cloning slot", e); - sendError(sender, "An error occurred while cloning slot."); + ProfileOperation result = ProfileController.cloneSlot(sourcePlayer, sourceSlot, destinationSlot, temporary); + switch(result) { + case SUCCESS: + sendResult(sender, "Successfully cloned slot %d from %s to slot %d for %s.", sourceSlot, sourcePlayer, destinationSlot, destinationPlayer); + break; + case NEW_SLOT_CREATED: + sendResult(sender, "Successfully cloned slot %d from %s to NEW slot %d for %s.", sourceSlot, sourcePlayer, destinationSlot, destinationPlayer); + break; + case LOCKED: + sendError(sender, "Profile is locked. Please try again later."); + break; + case VERIFICATION_FAILED: + sendError(sender, "Profile verification failed. Change not permitted."); + break; + case PLAYER_NOT_FOUND: + sendError(sender, "Player profile not found."); + break; + case ERROR: + default: + sendError(sender, "Error cloning slot."); + break; } } @@ -104,7 +79,7 @@ public class CommandProfileAdmin extends CommandProfileBase { usage = " " ) public void remove(ICommandSender sender, String[] args) throws CommandException { - if (args.length < 2) { + if(args.length < 2) { sendError(sender, "Usage: /profile admin remove "); return; } @@ -112,29 +87,21 @@ public class CommandProfileAdmin extends CommandProfileBase { int slotId; try { slotId = Integer.parseInt(args[1]); - } catch (NumberFormatException ex) { + } catch(NumberFormatException ex) { sendError(sender, "Slot ID must be a number."); return; } - Profile targetProfile = ProfileController.getProfile(targetPlayer); - if (targetProfile == null) { - sendError(sender, "Profile not found for player: " + targetPlayer); - return; - } - if (targetProfile.locked) { - sendError(sender, "Profile for " + targetPlayer + " is locked. Please try again later."); - return; - } ProfileOperation result = ProfileController.removeSlot(targetPlayer, slotId); - switch (result) { + switch(result) { case SUCCESS: sendResult(sender, "Successfully removed slot %d from %s.", slotId, targetPlayer); break; case LOCKED: - sendError(sender, "Profile for " + targetPlayer + " is locked."); + sendError(sender, "Profile for %s is locked. Please try again later.", targetPlayer); break; default: sendError(sender, "Error removing slot %d from %s.", slotId, targetPlayer); + break; } } @@ -143,7 +110,7 @@ public class CommandProfileAdmin extends CommandProfileBase { usage = " " ) public void change(ICommandSender sender, String[] args) throws CommandException { - if (args.length < 2) { + if(args.length < 2) { sendError(sender, "Usage: /profile admin change "); return; } @@ -151,29 +118,29 @@ public class CommandProfileAdmin extends CommandProfileBase { int newSlotId; try { newSlotId = Integer.parseInt(args[1]); - } catch (NumberFormatException ex) { + } catch(NumberFormatException ex) { sendError(sender, "Slot ID must be a number."); return; } - Profile targetProfile = ProfileController.getProfile(targetPlayer); - if (targetProfile == null) { - sendError(sender, "Profile not found for player: " + targetPlayer); - return; - } - if (targetProfile.locked) { - sendError(sender, "Profile for " + targetPlayer + " is locked. Please try again later."); - return; - } ProfileOperation result = ProfileController.changeSlot(targetPlayer, newSlotId); - switch (result) { + switch(result) { case SUCCESS: sendResult(sender, "Successfully changed %s's active slot to %d.", targetPlayer, newSlotId); break; + case NEW_SLOT_CREATED: + sendResult(sender, "Switched %s to NEW slot %d (new profile created).", targetPlayer, newSlotId); + break; + case ALREADY_ACTIVE: + sendError(sender, "Slot %d is already active for %s.", newSlotId, targetPlayer); + break; case LOCKED: - sendError(sender, "Profile for " + targetPlayer + " is locked."); + sendError(sender, "Profile for %s is locked. Please try again later.", targetPlayer); + break; + case VERIFICATION_FAILED: + sendError(sender, "Profile verification failed for %s.", targetPlayer); break; default: - sendError(sender, "Error changing active slot for " + targetPlayer); + sendError(sender, "Error changing active slot for %s.", targetPlayer); } } @@ -182,21 +149,21 @@ public class CommandProfileAdmin extends CommandProfileBase { usage = "" ) public void list(ICommandSender sender, String[] args) throws CommandException { - if (args.length < 1) { + if(args.length < 1) { sendError(sender, "Usage: /profile admin list "); return; } String targetPlayer = args[0]; - Profile targetProfile = ProfileController.getProfile(targetPlayer); - if (targetProfile == null) { + Profile profile = ProfileController.getProfile(targetPlayer); + if(profile == null) { sendError(sender, "Profile not found for player: " + targetPlayer); return; } - sendMessage(sender, "Profile Slots for " + targetPlayer + ":"); - for (Map.Entry entry : targetProfile.slots.entrySet()) { + sendMessage(sender, "Profile Slots for %s:", targetPlayer); + for(Map.Entry entry : profile.slots.entrySet()) { int id = entry.getKey(); String name = entry.getValue().getName(); - String prefix = (id == targetProfile.currentID) ? "* " : "- "; + String prefix = (id == profile.currentID) ? "* " : "- "; sendMessage(sender, prefix + "Slot " + id + ": " + name); } } @@ -206,7 +173,7 @@ public class CommandProfileAdmin extends CommandProfileBase { usage = " " ) public void rename(ICommandSender sender, String[] args) throws CommandException { - if (args.length < 3) { + if(args.length < 3) { sendError(sender, "Usage: /profile admin rename "); return; } @@ -214,50 +181,69 @@ public class CommandProfileAdmin extends CommandProfileBase { int slotId; try { slotId = Integer.parseInt(args[1]); - } catch (NumberFormatException ex) { + } catch(NumberFormatException ex) { sendError(sender, "Slot ID must be a number."); return; } - // Combine remaining arguments for the new name. StringBuilder sb = new StringBuilder(); - for (int i = 2; i < args.length; i++) { - if (i > 2) sb.append(" "); + for(int i = 2; i < args.length; i++){ + if(i > 2) sb.append(" "); sb.append(args[i]); } String newName = sb.toString().trim(); - // Cap name at 20 characters. - if (newName.length() > 20) { + if(newName.length() > 20) { newName = newName.substring(0, 20); } - // Validate that name contains only letters and spaces. - if (!newName.matches("[A-Za-z ]+")) { + if(!newName.matches("[A-Za-z ]+")){ sendError(sender, "Invalid name. Only alphabetic characters and spaces are allowed."); return; } - Profile targetProfile = ProfileController.getProfile(targetPlayer); - if (targetProfile == null) { + Profile profile = ProfileController.getProfile(targetPlayer); + if(profile == null) { sendError(sender, "Profile not found for player: " + targetPlayer); return; } - if (targetProfile.locked) { - sendError(sender, "Profile for " + targetPlayer + " is locked. Please try again later."); + if(profile.locked) { + sendError(sender, "Profile for %s is locked. Please try again later.", targetPlayer); return; } - if (!targetProfile.slots.containsKey(slotId)) { - sendError(sender, "Slot " + slotId + " not found in " + targetPlayer + "'s profile."); + if(!profile.slots.containsKey(slotId)) { + sendError(sender, "Slot %d not found in %s's profile.", slotId, targetPlayer); return; } - // Rename the slot. - Slot targetSlot = targetProfile.slots.get(slotId); - targetSlot.setName(newName); - // Save the updated profile. - if (targetProfile.player != null) { - ProfileController.save(targetProfile.player, targetProfile); + profile.slots.get(slotId).setName(newName); + if(profile.player != null) { + ProfileController.save(profile.player, profile); } else { UUID uuid = ProfileController.getUUIDFromUsername(targetPlayer); - if (uuid != null) - ProfileController.saveOffline(targetProfile, uuid); + if(uuid != null) + ProfileController.saveOffline(profile, uuid); + } + sendResult(sender, "Successfully renamed slot %d for %s to '%s'.", slotId, targetPlayer, newName); + } + + @SubCommand( + desc = "Rollback a player's profile to one of their backups.", + usage = " " + ) + public void rollback(ICommandSender sender, String[] args) throws CommandException { + if(args.length < 2) { + sendError(sender, "Usage: /profile admin rollback "); + return; + } + String targetPlayer = args[0]; + String backupFileName = args[1]; + File backupDir = new File(ProfileController.getBackupDir(), ProfileController.getProfile(targetPlayer).player.getUniqueID().toString()); + File backupFile = new File(backupDir, backupFileName); + if(!backupFile.exists()){ + sendError(sender, "Backup file %s not found for player %s.", backupFileName, targetPlayer); + return; + } + boolean success = ProfileController.rollbackProfile(targetPlayer, backupFile); + if(success) { + sendResult(sender, "Successfully rolled back %s's profile to backup %s.", targetPlayer, backupFileName); + } else { + sendError(sender, "Failed to rollback %s's profile.", targetPlayer); } - sendResult(sender, "Successfully renamed slot %s for %s to '%s'.", slotId, targetPlayer, newName); } } diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java index d58660714..8f8c46fbc 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java @@ -5,7 +5,6 @@ import kamkeel.npcs.controllers.data.ProfileOperation; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; - import static kamkeel.npcs.util.ColorUtil.sendError; import static kamkeel.npcs.util.ColorUtil.sendResult; @@ -33,35 +32,41 @@ public class CommandProfileChange extends CommandProfileBase { @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (!(sender instanceof EntityPlayer)) { + if(!(sender instanceof EntityPlayer)) { sendError(sender, "This command can only be used by a player."); return; } - if (args.length < 1) { + if(args.length < 1) { sendError(sender, "Usage: " + getUsage()); return; } int slotId; try { slotId = Integer.parseInt(args[0]); - } catch (NumberFormatException ex) { + } catch(NumberFormatException ex) { sendError(sender, "Slot ID must be a number: " + args[0]); return; } - EntityPlayer player = (EntityPlayer) sender; + EntityPlayer player = (EntityPlayer)sender; ProfileOperation result = ProfileController.changeSlot(player, slotId); switch(result) { case SUCCESS: - sendResult(sender, "Successfully changed profile slot to %s.", slotId); + sendResult(sender, "Successfully changed profile slot to %d.", slotId); + break; + case NEW_SLOT_CREATED: + sendResult(sender, "Switched to new slot %d (new profile created).", slotId); + break; + case ALREADY_ACTIVE: + sendError(sender, "Slot %d is already active.", slotId); break; case LOCKED: sendError(sender, "Profile is locked. Please try again later."); break; - case ERROR: - sendError(sender, "Error occurred while changing your profile slot."); + case VERIFICATION_FAILED: + sendError(sender, "Profile verification failed. Change not permitted."); break; default: - sendError(sender, "Operation could not be completed."); + sendError(sender, "Error occurred while changing your profile slot."); } } } diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java index 97b6bbded..07d03fc90 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java @@ -6,9 +6,7 @@ import kamkeel.npcs.controllers.data.Slot; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; - import java.util.Map; - import static kamkeel.npcs.util.ColorUtil.sendError; import static kamkeel.npcs.util.ColorUtil.sendMessage; @@ -31,18 +29,21 @@ public class CommandProfileList extends CommandProfileBase { @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (!(sender instanceof EntityPlayer)) { + if(!(sender instanceof EntityPlayer)) { sendError(sender, "This command can only be used by a player."); return; } - EntityPlayer player = (EntityPlayer) sender; + EntityPlayer player = (EntityPlayer)sender; Profile profile = ProfileController.getProfile(player); - if (profile == null) { + if(profile == null) { sendError(sender, "Profile not found."); return; } + if(profile.slots.isEmpty()){ + sendMessage(sender, "No slots found. Using default slot 0."); + } sendMessage(sender, "Your Profile Slots:"); - for (Map.Entry entry : profile.slots.entrySet()) { + for(Map.Entry entry : profile.slots.entrySet()) { int id = entry.getKey(); String name = entry.getValue().getName(); String prefix = (id == profile.currentID) ? "* " : "- "; diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java index 1d8b53413..81d7e6a4b 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java @@ -5,7 +5,6 @@ import kamkeel.npcs.controllers.data.ProfileOperation; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; - import static kamkeel.npcs.util.ColorUtil.sendError; import static kamkeel.npcs.util.ColorUtil.sendResult; @@ -33,22 +32,22 @@ public class CommandProfileRemove extends CommandProfileBase { @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (!(sender instanceof EntityPlayer)) { + if(!(sender instanceof EntityPlayer)) { sendError(sender, "This command can only be used by a player."); return; } - if (args.length < 1) { + if(args.length < 1) { sendError(sender, "Usage: " + getUsage()); return; } int slotId; try { slotId = Integer.parseInt(args[0]); - } catch (NumberFormatException ex) { + } catch(NumberFormatException ex) { sendError(sender, "Slot ID must be a number: " + args[0]); return; } - EntityPlayer player = (EntityPlayer) sender; + EntityPlayer player = (EntityPlayer)sender; ProfileOperation result = ProfileController.removeSlot(player, slotId); switch(result) { case SUCCESS: diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java index 4155427c1..dbb116d87 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java @@ -1,12 +1,10 @@ package kamkeel.npcs.command.profile; import kamkeel.npcs.controllers.ProfileController; -import kamkeel.npcs.controllers.data.Profile; -import kamkeel.npcs.controllers.data.Slot; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; - +import java.util.UUID; import static kamkeel.npcs.util.ColorUtil.sendError; import static kamkeel.npcs.util.ColorUtil.sendResult; @@ -29,52 +27,45 @@ public class CommandProfileRename extends CommandProfileBase { @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (!(sender instanceof EntityPlayer)) { + if(!(sender instanceof EntityPlayer)) { sendError(sender, "This command can only be used by a player."); return; } - if (args.length < 2) { + if(args.length < 2) { sendError(sender, "Usage: " + getUsage()); return; } int slotId; try { slotId = Integer.parseInt(args[0]); - } catch (NumberFormatException e) { + } catch(NumberFormatException ex) { sendError(sender, "Slot ID must be a number."); return; } - // Combine remaining arguments into one name string. StringBuilder sb = new StringBuilder(); - for (int i = 1; i < args.length; i++) { - if (i > 1) sb.append(" "); + for(int i = 1; i < args.length; i++){ + if(i > 1) sb.append(" "); sb.append(args[i]); } String newName = sb.toString().trim(); - // Cap at 20 characters. - if (newName.length() > 20) { + if(newName.length() > 20) { newName = newName.substring(0, 20); } - // Validate that the new name contains only letters and spaces. - if (!newName.matches("[A-Za-z ]+")) { + if(!newName.matches("[A-Za-z ]+")){ sendError(sender, "Invalid name. Only alphabetic characters and spaces are allowed."); return; } - - EntityPlayer player = (EntityPlayer) sender; - Profile profile = ProfileController.getProfile(player); - if (profile == null) { + EntityPlayer player = (EntityPlayer)sender; + if(ProfileController.getProfile(player) == null) { sendError(sender, "Profile not found."); return; } - if (!profile.slots.containsKey(slotId)) { - sendError(sender, "Slot " + slotId + " not found in your profile."); + if(!ProfileController.getProfile(player).slots.containsKey(slotId)) { + sendError(sender, "Slot %d not found in your profile.", slotId); return; } - Slot slot = profile.slots.get(slotId); - slot.setName(newName); - // Save the profile after renaming. - ProfileController.save(player, profile); - sendResult(sender, "Successfully renamed slot %s to '%s'.", slotId, newName); + ProfileController.getProfile(player).slots.get(slotId).setName(newName); + ProfileController.save(player, ProfileController.getProfile(player)); + sendResult(sender, "Successfully renamed slot %d to '%s'.", slotId, newName); } } diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index 0c5f74427..d8a316ba3 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -1,8 +1,8 @@ package kamkeel.npcs.controllers; import kamkeel.npcs.controllers.data.IProfileData; -import kamkeel.npcs.controllers.data.ProfileOperation; import kamkeel.npcs.controllers.data.Profile; +import kamkeel.npcs.controllers.data.ProfileOperation; import kamkeel.npcs.controllers.data.Slot; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -11,17 +11,15 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.MinecraftServer; import noppes.npcs.CustomNpcs; import noppes.npcs.LogWriter; +import noppes.npcs.config.ConfigMain; import noppes.npcs.controllers.data.PlayerData; import noppes.npcs.util.CustomNPCsThreader; import noppes.npcs.util.NBTJsonUtil; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStreamReader; -import java.io.IOException; +import java.io.*; import java.net.HttpURLConnection; import java.net.URL; +import java.text.SimpleDateFormat; import java.util.*; public class ProfileController { @@ -36,7 +34,6 @@ public class ProfileController { } // ---------- Registration & I/O ---------- - public static boolean registerProfileType(IProfileData type){ if(profileTypes.containsKey(type.getTagName())) return false; @@ -56,7 +53,18 @@ public class ProfileController { } } - // Login for online players + // Returns the backup folder for profiles. + public static File getBackupDir() { + File base = getProfileDir(); + File backup = new File(base, "backup"); + if(!backup.exists()){ + backup.mkdir(); + } + return backup; + } + + // Login for online players. + // If no slots exist, create default slot 0 and save the player's current IProfileData into it. public static synchronized void login(EntityPlayer player){ if(player == null) return; @@ -67,6 +75,15 @@ public class ProfileController { } else { NBTTagCompound compound = load(player); profile = new Profile(player, compound); + // If no slots exist, create default slot 0. + if(profile.slots.isEmpty()){ + Slot defaultSlot = new Slot(0, "Default Slot"); + defaultSlot.setCompound(new NBTTagCompound()); + profile.slots.put(0, defaultSlot); + profile.currentID = 0; + saveSlotData(player); + save(player, profile); + } activeProfiles.put(player.getUniqueID(), profile); } } @@ -99,7 +116,7 @@ public class ProfileController { return new NBTTagCompound(); } - // Offline save (synchronous) when no EntityPlayer is available + // Offline save (synchronous) when no EntityPlayer is available. public static synchronized void saveOffline(Profile profile, UUID uuid) { final NBTTagCompound compound = profile.writeToNBT(); final String filename = uuid.toString() + ".dat"; @@ -112,12 +129,14 @@ public class ProfileController { fileOld.delete(); } fileNew.renameTo(fileOld); + // Also backup if allowed. + backupProfile(uuid, compound); } catch (Exception e) { LogWriter.except(e); } } - // Save for online players (asynchronous) + // Save for online players (asynchronous). public static synchronized void save(EntityPlayer player, Profile profile) { profile.locked = true; CustomNPCsThreader.customNPCThread.execute(() -> { @@ -132,6 +151,10 @@ public class ProfileController { fileOld.delete(); } fileNew.renameTo(fileOld); + // Backup if enabled. + if(ConfigMain.AllowProfileBackups) { + backupProfile(player.getUniqueID(), compound); + } } catch (Exception e) { LogWriter.except(e); } finally { @@ -140,7 +163,67 @@ public class ProfileController { }); } - // Logout removes an active profile + // Backup the profile by saving a copy to profiles/backup//.dat. + private static void backupProfile(UUID uuid, NBTTagCompound compound) { + try { + File backupDir = new File(getBackupDir(), uuid.toString()); + if(!backupDir.exists()){ + backupDir.mkdirs(); + } + String dateStr = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); + File backupFile = new File(backupDir, dateStr + ".dat"); + CompressedStreamTools.writeCompressed(compound, new FileOutputStream(backupFile)); + // Now enforce backup amount limit. + File[] backups = backupDir.listFiles((dir, name) -> name.endsWith(".dat")); + if(backups != null && backups.length > ConfigMain.ProfileBackupAmount) { + // Sort backups by last modified ascending (oldest first) + Arrays.sort(backups, Comparator.comparingLong(File::lastModified)); + for(int i = 0; i < backups.length - ConfigMain.ProfileBackupAmount; i++){ + backups[i].delete(); + } + } + } catch(Exception e) { + LogWriter.except(e); + } + } + + // Rollback a player's profile from a backup file. + // Returns true if successful. + public static boolean rollbackProfile(String username, File backupFile) { + UUID uuid = getUUIDFromUsername(username); + if(uuid == null) return false; + try (FileInputStream fis = new FileInputStream(backupFile)) { + NBTTagCompound compound = CompressedStreamTools.readCompressed(fis); + // Overwrite the main profile file. + File saveDir = getProfileDir(); + File mainFile = new File(saveDir, uuid.toString() + ".dat"); + File fileNew = new File(saveDir, uuid.toString() + "_new"); + CompressedStreamTools.writeCompressed(compound, new FileOutputStream(fileNew)); + if(mainFile.exists()){ + mainFile.delete(); + } + fileNew.renameTo(mainFile); + + // Update the in-memory profile. + EntityPlayerMP player = getPlayer(username); + Profile newProfile; + if(player != null) { + newProfile = new Profile(player, compound); + activeProfiles.put(uuid, newProfile); + // Load the rolled-back data into the player's IProfileData. + loadSlotData(player); + } else { + newProfile = new Profile(null, compound); + activeProfiles.put(uuid, newProfile); + } + return true; + } catch(Exception e) { + LogWriter.except(e); + return false; + } + } + + // Logout removes an active profile. public static synchronized void logout(EntityPlayer player) { if(player != null) { activeProfiles.remove(player.getUniqueID()); @@ -148,8 +231,6 @@ public class ProfileController { } // ---------- Profile Retrieval Helpers ---------- - - // Get profile via EntityPlayer (online) public static Profile getProfile(EntityPlayer player) { if(player == null) return null; if(!activeProfiles.containsKey(player.getUniqueID())) @@ -157,7 +238,6 @@ public class ProfileController { return activeProfiles.get(player.getUniqueID()); } - // Get profile via UUID (may be offline) public static Profile getProfile(UUID uuid) { if(activeProfiles.containsKey(uuid)) return activeProfiles.get(uuid); @@ -165,7 +245,6 @@ public class ProfileController { return new Profile(null, compound); } - // Get profile via username (tries online first, then offline via Mojang API) public static Profile getProfile(String username) { EntityPlayer player = getPlayer(username); if(player != null) { @@ -178,7 +257,6 @@ public class ProfileController { } // ---------- Mojang API UUID Lookup ---------- - public static UUID getUUIDFromUsername(String username) { try { URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + username); @@ -214,7 +292,6 @@ public class ProfileController { } // ---------- Internal Slot Operation Helpers ---------- - // Returns the next available temporary (negative) slot id (starting at -1) private static int getNextAvailableTempSlot(Profile profile) { int id = -1; @@ -225,15 +302,12 @@ public class ProfileController { } // Clone a slot within a Profile. - // sourceSlotId is the slot to copy. - // destinationSlotId is the target id for non-temporary clones. // If temporary==true, destinationSlotId is computed automatically. private static ProfileOperation cloneSlotInternal(Profile profile, int sourceSlotId, int destinationSlotId, boolean temporary) { if(profile.locked) { LogWriter.error("Profile is locked; cannot clone slot."); return ProfileOperation.LOCKED; } - // Run verification checks on all IProfileData in priority order. if(profile.player != null) { List dataList = new ArrayList<>(profileTypes.values()); @@ -245,7 +319,6 @@ public class ProfileController { } } } - if(!profile.slots.containsKey(sourceSlotId)) { LogWriter.error("Source slot " + sourceSlotId + " does not exist."); return ProfileOperation.ERROR; @@ -288,17 +361,22 @@ public class ProfileController { } // Change the active slot in a Profile. + // If the new slot doesn't exist, it is created and NEW_SLOT_CREATED is returned. // Saves current slot data before switching. private static ProfileOperation changeSlotInternal(Profile profile, int newSlotId) { if(profile.locked) { LogWriter.error("Profile is locked; cannot change slot."); return ProfileOperation.LOCKED; } - - // Run verification checks from all registered IProfileData in order of priority. + // Disallow switching to the same active slot. + if(profile.currentID == newSlotId) { + LogWriter.error("Slot " + newSlotId + " is already active."); + return ProfileOperation.ALREADY_ACTIVE; + } + // Run verification checks from all IProfileData in order of priority. if(profile.player != null) { List dataList = new ArrayList<>(profileTypes.values()); - dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority));; + dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority)); for(IProfileData pd : dataList) { if(!pd.verifySwitch(profile.player)) { LogWriter.error("Verification check failed for profile type: " + pd.getTagName()); @@ -306,34 +384,31 @@ public class ProfileController { } } } - if(profile.player != null) { saveSlotData(profile.player); } - + boolean createdNewSlot = false; // If the new slot doesn't exist, create it. if(!profile.slots.containsKey(newSlotId)) { Slot newSlot = new Slot(newSlotId, "Slot " + newSlotId); newSlot.setCompound(new NBTTagCompound()); profile.slots.put(newSlotId, newSlot); + createdNewSlot = true; } - profile.currentID = newSlotId; if(profile.player != null) { loadSlotData(profile.player); } - // Update PlayerData so that PlayerData.get(player).profileSlot matches Profile.currentID. if(profile.player != null) { PlayerData pdata = PlayerData.get(profile.player); pdata.profileSlot = newSlotId; pdata.save(); } - return ProfileOperation.SUCCESS; + return createdNewSlot ? ProfileOperation.NEW_SLOT_CREATED : ProfileOperation.SUCCESS; } // ---------- Public Operations (Overloaded for EntityPlayer, UUID, or username) ---------- - // ----- Clone Slot ----- public static ProfileOperation cloneSlot(EntityPlayer player, int sourceSlotId, int destinationSlotId, boolean temporary) { Profile profile = getProfile(player); @@ -417,7 +492,7 @@ public class ProfileController { Profile profile = getProfile(player); if(profile == null) return ProfileOperation.PLAYER_NOT_FOUND; ProfileOperation result = changeSlotInternal(profile, newSlotId); - if(result == ProfileOperation.SUCCESS && player != null) + if((result == ProfileOperation.SUCCESS || result == ProfileOperation.NEW_SLOT_CREATED) && player != null) save(player, profile); return result; } @@ -426,7 +501,7 @@ public class ProfileController { Profile profile = getProfile(uuid); if(profile == null) return ProfileOperation.PLAYER_NOT_FOUND; ProfileOperation result = changeSlotInternal(profile, newSlotId); - if(result == ProfileOperation.SUCCESS) { + if(result == ProfileOperation.SUCCESS || result == ProfileOperation.NEW_SLOT_CREATED) { if(profile.player != null) save(profile.player, profile); else @@ -439,7 +514,7 @@ public class ProfileController { Profile profile = getProfile(username); if(profile == null) return ProfileOperation.PLAYER_NOT_FOUND; ProfileOperation result = changeSlotInternal(profile, newSlotId); - if(result == ProfileOperation.SUCCESS) { + if(result == ProfileOperation.SUCCESS || result == ProfileOperation.NEW_SLOT_CREATED) { if(profile.player != null) save(profile.player, profile); else { @@ -470,7 +545,6 @@ public class ProfileController { dataCompound = new NBTTagCompound(); slot.setCompound(dataCompound); } - List dataList = new ArrayList<>(profileTypes.values()); dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority)); for(IProfileData profileData : dataList){ @@ -483,15 +557,10 @@ public class ProfileController { public static void loadSlotData(EntityPlayer player) { if(player == null || !activeProfiles.containsKey(player.getUniqueID())) return; - Profile profile = activeProfiles.get(player.getUniqueID()); if(profile.slots.isEmpty() || !profile.slots.containsKey(profile.currentID)) return; - - // Get a copy of the active slot's NBT compound. NBTTagCompound slotCompound = (NBTTagCompound) profile.slots.get(profile.currentID).getCompound().copy(); - - // For each registered profile data type, load its saved compound onto the player. List dataList = new ArrayList<>(profileTypes.values()); dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority)); for(IProfileData profileData : dataList){ @@ -500,10 +569,8 @@ public class ProfileController { data = slotCompound.getCompoundTag(profileData.getTagName()); else data = new NBTTagCompound(); - profileData.setNBT(player, data); } - for(IProfileData profileData : dataList){ profileData.save(player); } diff --git a/src/main/java/kamkeel/npcs/controllers/SyncController.java b/src/main/java/kamkeel/npcs/controllers/SyncController.java index 1b936cd9b..a591a899b 100644 --- a/src/main/java/kamkeel/npcs/controllers/SyncController.java +++ b/src/main/java/kamkeel/npcs/controllers/SyncController.java @@ -4,6 +4,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import kamkeel.npcs.addon.DBCAddon; import kamkeel.npcs.network.PacketHandler; +import kamkeel.npcs.network.packets.data.LoginPacket; import kamkeel.npcs.network.packets.data.large.SyncEffectPacket; import kamkeel.npcs.network.packets.data.large.SyncPacket; import kamkeel.npcs.network.enums.EnumSyncAction; @@ -23,6 +24,10 @@ import java.util.concurrent.ConcurrentHashMap; public class SyncController { public static void syncPlayer(EntityPlayerMP player){ + + // Login Packet + PacketHandler.Instance.sendToPlayer(new LoginPacket(), player); + // 1) Factions PacketHandler.Instance.sendToPlayer(new SyncPacket( EnumSyncType.FACTION, diff --git a/src/main/java/kamkeel/npcs/controllers/data/Profile.java b/src/main/java/kamkeel/npcs/controllers/data/Profile.java index 502bea91a..3a1baac89 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/Profile.java +++ b/src/main/java/kamkeel/npcs/controllers/data/Profile.java @@ -11,9 +11,9 @@ public class Profile { public EntityPlayer player; public int currentID; public HashMap slots = new HashMap<>(); - public boolean locked = false; // Prevent modifications while saving + public boolean locked = false; - public Profile(EntityPlayer player, NBTTagCompound compound){ + public Profile(EntityPlayer player, NBTTagCompound compound) { this.player = player; if(compound.hasKey("CurrentID")){ this.currentID = compound.getInteger("CurrentID"); @@ -21,9 +21,9 @@ public class Profile { this.currentID = 0; } - if (compound.hasKey("Slots")) { + if(compound.hasKey("Slots")) { NBTTagCompound slotsCompound = compound.getCompoundTag("Slots"); - for (String key : (Set) slotsCompound.func_150296_c()) { + for(String key : (Set) slotsCompound.func_150296_c()){ int slotID = Integer.parseInt(key); NBTTagCompound slotNBT = slotsCompound.getCompoundTag(key); Slot slot = Slot.fromNBT(slotID, slotNBT); @@ -34,7 +34,6 @@ public class Profile { public NBTTagCompound writeToNBT() { NBTTagCompound fullCompound = new NBTTagCompound(); - if(this.player != null) fullCompound.setString("Name", player.getCommandSenderName()); fullCompound.setInteger("CurrentID", currentID); @@ -44,7 +43,7 @@ public class Profile { for (HashMap.Entry entry : slots.entrySet()) { Slot slot = entry.getValue(); if(slot.isTemporary()) - continue; // Do not save temporary slots + continue; int id = entry.getKey(); slot.setId(id); NBTTagCompound slotTag = slot.toNBT(); diff --git a/src/main/java/kamkeel/npcs/controllers/data/ProfileOperation.java b/src/main/java/kamkeel/npcs/controllers/data/ProfileOperation.java index f3d6d1179..3e6e81b90 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ProfileOperation.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ProfileOperation.java @@ -5,6 +5,8 @@ public enum ProfileOperation { ERROR, LOCKED, PLAYER_NOT_FOUND, + NEW_SLOT_CREATED, + ALREADY_ACTIVE, VERIFICATION_FAILED } diff --git a/src/main/java/kamkeel/npcs/network/PacketHandler.java b/src/main/java/kamkeel/npcs/network/PacketHandler.java index 67003b53b..d8ca8da65 100644 --- a/src/main/java/kamkeel/npcs/network/PacketHandler.java +++ b/src/main/java/kamkeel/npcs/network/PacketHandler.java @@ -338,6 +338,7 @@ public class PacketHandler { public void registerDataPackets(){ // Data Packets + DATA_PACKET.registerPacket(new LoginPacket()); DATA_PACKET.registerPacket(new AchievementPacket()); DATA_PACKET.registerPacket(new ChatAlertPacket()); DATA_PACKET.registerPacket(new ChatBubblePacket()); diff --git a/src/main/java/kamkeel/npcs/network/packets/data/LoginPacket.java b/src/main/java/kamkeel/npcs/network/packets/data/LoginPacket.java index 385b8fda4..022f4bc5e 100644 --- a/src/main/java/kamkeel/npcs/network/packets/data/LoginPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/data/LoginPacket.java @@ -1,21 +1,21 @@ package kamkeel.npcs.network.packets.data; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; import kamkeel.npcs.network.AbstractPacket; import kamkeel.npcs.network.PacketChannel; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumDataPacket; -import kamkeel.npcs.util.ByteBufUtils; import net.minecraft.entity.player.EntityPlayer; +import noppes.npcs.client.ClientCacheHandler; +import noppes.npcs.config.ConfigMain; import java.io.IOException; public final class LoginPacket extends AbstractPacket { public static final String packetName = "CNPC+|Login"; - - public LoginPacket() { - } - + public LoginPacket() {} @Override public Enum getType() { @@ -29,13 +29,14 @@ public final class LoginPacket extends AbstractPacket { @Override public void sendData(ByteBuf out) throws IOException { -// ByteBufUtils.writeUTF8String(out, this.data.player.getCommandSenderName()); -// ByteBufUtils.writeNBT(out,this.data.saveFromNBT(new NBTTagCompound())); + out.writeBoolean(ConfigMain.PartiesEnabled); + out.writeBoolean(ConfigMain.ProfilesEnabled); } + @SideOnly(Side.CLIENT) @Override public void receiveData(ByteBuf in, EntityPlayer player) throws IOException { - String playerName = ByteBufUtils.readUTF8String(in); - + ClientCacheHandler.allowParties = in.readBoolean(); + ClientCacheHandler.allowProfiles = in.readBoolean(); } } diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index 69463d914..699117a03 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -267,7 +267,8 @@ public class CustomNpcs { public void serverstart(FMLServerStartingEvent event) { event.registerServerCommand(new CommandNoppes()); event.registerServerCommand(new CommandKamkeel()); - event.registerServerCommand(new CommandProfile()); + if(ConfigMain.ProfilesEnabled) + event.registerServerCommand(new CommandProfile()); } private void registerNpc(Class cl, String name) { diff --git a/src/main/java/noppes/npcs/client/ClientCacheHandler.java b/src/main/java/noppes/npcs/client/ClientCacheHandler.java index 0661b7505..a51986c5d 100644 --- a/src/main/java/noppes/npcs/client/ClientCacheHandler.java +++ b/src/main/java/noppes/npcs/client/ClientCacheHandler.java @@ -23,6 +23,10 @@ public class ClientCacheHandler { public static Party party; + public static boolean allowProfiles = true; + public static boolean allowParties = true; + + public static ImageData getImageData(String directory) { synchronized (imageDataCache) { if (!imageDataCache.containsKey(directory)) { 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 d2d3e3a01..68395a52f 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 @@ -1,10 +1,9 @@ package noppes.npcs.client.gui.player.inventory; -import cpw.mods.fml.common.Loader; -import kamkeel.npcs.addon.client.DBCClient; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.client.gui.util.GuiMenuSideButton; import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.config.ConfigClient; @@ -41,13 +40,14 @@ public class GuiCNPCInventory extends GuiNPCInterface { questsButton.renderResource = specialIcons; addButton(questsButton); - y += 21; - GuiMenuSideButton partyButton = new GuiMenuSideButton(-101, guiLeft + xSize + 37, this.guiTop + y, 22, 22, ""); - partyButton.rightSided = true; - partyButton.active = activeTab == -101; - partyButton.renderResource = specialIcons; - addButton(partyButton); - + if(ClientCacheHandler.allowParties){ + y += 21; + GuiMenuSideButton partyButton = new GuiMenuSideButton(-101, guiLeft + xSize + 37, this.guiTop + y, 22, 22, ""); + partyButton.rightSided = true; + partyButton.active = activeTab == -101; + partyButton.renderResource = specialIcons; + addButton(partyButton); + } if(ConfigClient.enableFactionTab){ y += 21; GuiMenuSideButton factionButton = new GuiMenuSideButton(-102, guiLeft + xSize + 37, this.guiTop + y, 22, 22, ""); @@ -57,7 +57,7 @@ public class GuiCNPCInventory extends GuiNPCInterface { factionButton.renderResource = specialIcons; addButton(factionButton); } - if(ConfigMain.EnableProfiles){ + if(ClientCacheHandler.allowProfiles){ y += 21; GuiMenuSideButton profileButton = new GuiMenuSideButton(-104, guiLeft + xSize + 37, this.guiTop + y, 22, 22, ""); profileButton.rightSided = true; diff --git a/src/main/java/noppes/npcs/config/ConfigMain.java b/src/main/java/noppes/npcs/config/ConfigMain.java index e3437c610..8f0846b60 100644 --- a/src/main/java/noppes/npcs/config/ConfigMain.java +++ b/src/main/java/noppes/npcs/config/ConfigMain.java @@ -80,7 +80,13 @@ public class ConfigMain public static Property DefaultMaxPartySizeProperty; public static int DefaultMaxPartySize = 4; - public static boolean EnableProfiles = true; + /** + * Profile Properties + **/ + public static boolean ProfilesEnabled = true; + public static boolean AllowProfileBackups = true; + public static int ProfileBackupAmount = 5; + /** * General NPC Properties @@ -220,7 +226,9 @@ public class ConfigMain TrackedQuestUpdateFrequency = TrackedQuestUpdateFrequencyProperty.getInt(5); // PROFILES - EnableProfiles = config.get(PROFILES, "Enable Profiles", true, "Allow the use of character Profiles").getBoolean(true); + ProfilesEnabled = config.get(PROFILES, "Enable Profiles", true, "Allow the use of character Profiles").getBoolean(true); + AllowProfileBackups = config.get(PROFILES, "Enable Profile Backups", true, "Will create backups of profile changes").getBoolean(true); + ProfileBackupAmount = config.get(PROFILES, "Number of Backups", 5, "How many backups per player to save").getInt(5); // Convert to Legacy if(CustomNpcs.legacyExist){ From 5a38f9057f1c52e3fed26ffa56d30cd85c29d79e Mon Sep 17 00:00:00 2001 From: Kam Date: Wed, 19 Feb 2025 00:21:40 -0500 Subject: [PATCH 09/59] Profile + Effect Loading --- .../command/profile/CommandProfileAdmin.java | 2 +- .../npcs/controllers/ProfileController.java | 34 ++ .../npcs/controllers/data/CNPCData.java | 20 +- .../npcs/controllers/data/IProfileData.java | 11 +- .../kamkeel/npcs/network/PacketHandler.java | 4 + .../npcs/network/enums/EnumRequestPacket.java | 2 +- .../request/profile/ProfileGetPacket.java | 51 +++ .../gui/player/inventory/GuiProfiles.java | 359 +++++++++++------- .../npcs/controllers/data/PlayerData.java | 10 +- 9 files changed, 354 insertions(+), 139 deletions(-) create mode 100644 src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java index 7f768d480..255a48fac 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java @@ -232,7 +232,7 @@ public class CommandProfileAdmin extends CommandProfileBase { return; } String targetPlayer = args[0]; - String backupFileName = args[1]; + String backupFileName = args[1] += ".dat"; File backupDir = new File(ProfileController.getBackupDir(), ProfileController.getProfile(targetPlayer).player.getUniqueID().toString()); File backupFile = new File(backupDir, backupFileName); if(!backupFile.exists()){ diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index d8a316ba3..cdad4795d 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -576,6 +576,40 @@ public class ProfileController { } } + public static List getProfileInfo(EntityPlayer player, int slotId) { + List infoList = new ArrayList<>(); + Profile profile = getProfile(player); + if (profile == null) + return infoList; + + List dataList = new ArrayList<>(profileTypes.values()); + dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority)); + + if (slotId == profile.currentID) { + // Use current data (not stored slot data) for active slot. + for (IProfileData pd : dataList) { + NBTTagCompound currentNBT = pd.getCurrentNBT(player); + List subInfo = pd.getInfo(player, currentNBT); + infoList.addAll(subInfo); + } + } else { + // Use stored data from the specified slot. + if (!profile.slots.containsKey(slotId)) + return infoList; + NBTTagCompound slotCompound = profile.slots.get(slotId).getCompound(); + for (IProfileData pd : dataList) { + if (slotCompound.hasKey(pd.getTagName())) { + NBTTagCompound sub = slotCompound.getCompoundTag(pd.getTagName()); + List subInfo = pd.getInfo(player, sub); + infoList.addAll(subInfo); + } + } + } + return infoList; + } + + + public static EntityPlayerMP getPlayer(String username){ return MinecraftServer.getServer().getConfigurationManager().func_152612_a(username); } diff --git a/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java b/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java index 8662e0b84..60bf83cee 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java +++ b/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java @@ -5,6 +5,8 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.controllers.data.PlayerData; +import java.util.ArrayList; +import java.util.List; public class CNPCData implements IProfileData { @@ -33,7 +35,8 @@ public class CNPCData implements IProfileData { PlayerData newData = new PlayerData(); newData.player = player; customNPCData.setNBT((NBTTagCompound) newData.getNBT().copy()); - } else { + } + else { customNPCData.setNBT(replace); } customNPCData.updateClient = true; @@ -48,4 +51,19 @@ public class CNPCData implements IProfileData { public boolean verifySwitch(EntityPlayer player) { return true; } + + @Override + public List getInfo(EntityPlayer player, NBTTagCompound compound) { + PlayerData playerData = new PlayerData(); + playerData.player = player; + playerData.setNBT(compound); + + List info = new ArrayList<>(); + + info.add("QuestsFinished" + "###" + playerData.questData.finishedQuests.size()); + info.add("QuestsActive" + "###" + playerData.questData.activeQuests.size()); + info.add("DialogsRead" + "###" + playerData.dialogData.dialogsRead.size()); + + return info; + } } diff --git a/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java b/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java index 853ddf1e0..00dc63929 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java +++ b/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java @@ -2,12 +2,12 @@ package kamkeel.npcs.controllers.data; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; +import java.util.List; public interface IProfileData { /** * Do not use the tags: Name, lastLoaded, ID. - * * @return The save tag utilized in the Profile. */ public String getTagName(); @@ -39,4 +39,13 @@ public interface IProfileData { * @return true if allowed, false if not. */ public boolean verifySwitch(EntityPlayer player); + + /** + * NEW: Builds and returns a list of informational strings about this profile data, + * based on the provided NBTTagCompound from the slot. + * @param player The player in question. + * @param compound The NBT data from the slot under this profile data's tag. + * @return A list of strings with information (could be empty). + */ + public List getInfo(EntityPlayer player, NBTTagCompound compound); } diff --git a/src/main/java/kamkeel/npcs/network/PacketHandler.java b/src/main/java/kamkeel/npcs/network/PacketHandler.java index d8ca8da65..c9c0dd5c2 100644 --- a/src/main/java/kamkeel/npcs/network/PacketHandler.java +++ b/src/main/java/kamkeel/npcs/network/PacketHandler.java @@ -56,6 +56,7 @@ import kamkeel.npcs.network.packets.request.pather.MovingPathSavePacket; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetPacket; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataMapRegenPacket; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataRemovePacket; +import kamkeel.npcs.network.packets.request.profile.ProfileGetPacket; import kamkeel.npcs.network.packets.request.quest.*; import kamkeel.npcs.network.packets.request.recipe.RecipeGetPacket; import kamkeel.npcs.network.packets.request.recipe.RecipeRemovePacket; @@ -323,6 +324,9 @@ public class PacketHandler { REQUEST_PACKET.registerPacket(new EffectSavePacket()); REQUEST_PACKET.registerPacket(new EffectRemovePacket()); + // Profile Packets + REQUEST_PACKET.registerPacket(new ProfileGetPacket()); + // Other Packets REQUEST_PACKET.registerPacket(new IsGuiOpenInform()); REQUEST_PACKET.registerPacket(new GuiRequestPacket()); diff --git a/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java b/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java index b68446eac..92d90a328 100644 --- a/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java +++ b/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java @@ -185,5 +185,5 @@ public enum EnumRequestPacket { EffectSave, ColorSet, - ColorBrush + ProfileGet, ProfileGetAll, ColorBrush } diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java new file mode 100644 index 000000000..feac5f37c --- /dev/null +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java @@ -0,0 +1,51 @@ +package kamkeel.npcs.network.packets.request.profile; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import io.netty.buffer.ByteBuf; +import kamkeel.npcs.controllers.ProfileController; +import kamkeel.npcs.controllers.data.Profile; +import kamkeel.npcs.network.*; +import kamkeel.npcs.network.enums.EnumItemPacketType; +import kamkeel.npcs.network.enums.EnumRequestPacket; +import kamkeel.npcs.network.packets.data.large.GuiDataPacket; +import kamkeel.npcs.util.ByteBufUtils; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.controllers.LinkedItemController; +import noppes.npcs.controllers.LinkedNpcController; +import noppes.npcs.controllers.data.LinkedItem; + +import java.io.IOException; + +public final class ProfileGetPacket extends AbstractPacket { + public static String packetName = "Request|ProfileGet"; + + public ProfileGetPacket() {} + + @Override + public Enum getType() { + return EnumRequestPacket.ProfileGet; + } + + @Override + public PacketChannel getChannel() { + return PacketHandler.REQUEST_PACKET; + } + + @SideOnly(Side.CLIENT) + @Override + public void sendData(ByteBuf out) throws IOException {} + + @Override + public void receiveData(ByteBuf in, EntityPlayer player) throws IOException { + if (!(player instanceof EntityPlayerMP)) + return; + + Profile profile = ProfileController.getProfile(player); + NBTTagCompound compound = profile.writeToNBT(); + compound.setBoolean("PROFILE", true); + GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java index 5b08d8877..dfebad2b7 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java @@ -1,35 +1,45 @@ package noppes.npcs.client.gui.player.inventory; +import kamkeel.npcs.controllers.data.Profile; +import kamkeel.npcs.controllers.data.Slot; import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.player.CheckPlayerValue; +import kamkeel.npcs.network.packets.request.linked.LinkedGetPacket; +import kamkeel.npcs.network.packets.request.linked.LinkedItemRemovePacket; +import kamkeel.npcs.network.packets.request.linked.LinkedNPCAddPacket; +import kamkeel.npcs.network.packets.request.linked.LinkedNPCRemovePacket; +import kamkeel.npcs.network.packets.request.profile.ProfileGetPacket; import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.client.CustomNpcResourceListener; -import noppes.npcs.client.gui.util.GuiButtonNextPage; -import noppes.npcs.client.gui.util.IGuiData; +import noppes.npcs.client.NoppesUtil; +import noppes.npcs.client.gui.SubGuiEditText; +import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPlayerPacket; import noppes.npcs.controllers.data.Faction; +import noppes.npcs.controllers.data.LinkedItem; import noppes.npcs.controllers.data.PlayerFactionData; import org.lwjgl.opengl.GL11; import tconstruct.client.tabs.AbstractTab; import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Vector; -public class GuiProfiles extends GuiCNPCInventory implements IGuiData { +public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, ICustomScrollListener, IGuiData, GuiYesNoCallback { private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/standardbg.png"); - - private ArrayList playerFactions = new ArrayList(); - - private int page = 0; - private int pages = 1; - - private GuiButtonNextPage buttonNextPage; - private GuiButtonNextPage buttonPreviousPage; + private GuiCustomScroll scroll; + public HashMap data = new HashMap<>(); + private String selected = null; + private Profile profile; + private Slot slot; public GuiProfiles() { super(); @@ -37,7 +47,7 @@ public class GuiProfiles extends GuiCNPCInventory implements IGuiData { ySize = 180; this.drawDefaultBackground = false; title = ""; - PacketClient.sendClient(new CheckPlayerValue(CheckPlayerValue.Type.Faction)); + PacketClient.sendClient(new ProfileGetPacket()); } @Override @@ -45,91 +55,24 @@ public class GuiProfiles extends GuiCNPCInventory implements IGuiData { { super.initGui(); - 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)); - updateButtons(); - } + int y = guiTop + 8; + this.addButton(new GuiNpcButton(1,guiLeft + 368, y += 40, 45, 20, "gui.add")); + this.addButton(new GuiNpcButton(2,guiLeft + 368, y += 22, 45, 20, "gui.remove")); + this.addButton(new GuiNpcButton(3,guiLeft + 368, y += 22, 45, 20, "gui.rename")); + this.addButton(new GuiNpcButton(4,guiLeft + 368, y += 22, 45, 20, "gui.change")); - @Override - public void drawScreen(int i, int j, float f) - { - drawDefaultBackground(); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - 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(){ - int size = 10; - if(playerFactions.size() % 10 != 0 && page == pages) - size = playerFactions.size() % 10; - - int hLine = 5; - if(size < 5){ - hLine = size; - } - - int count = -1; - for(int id = 0 ; id < size; id++){ - count++; - - Faction faction = playerFactions.get((page - 1) * 10 + id); - String name = faction.name; - String points = " : " + faction.defaultPoints; - - String standing = StatCollector.translateToLocal("faction.friendly"); - int color = 0x00FF00; - if(faction.defaultPoints < faction.neutralPoints){ - standing = StatCollector.translateToLocal("faction.unfriendly"); - color = 0xFF0000; - points += "/" + faction.neutralPoints; - } - else if(faction.defaultPoints < faction.friendlyPoints){ - standing = StatCollector.translateToLocal("faction.neutral"); - color = 0xF2FF00; - points += "/" + faction.friendlyPoints; - } - else{ - points += "/-"; - } - - drawVerticalLine(guiLeft + (xSize + 45) / 2, (guiTop + ySize - 15), guiTop + 13, 0xFF000000 + CustomNpcResourceListener.DefaultTextColor); - if(count < 5){ - drawHorizontalLine(guiLeft + 2, guiLeft + xSize + 35, guiTop + 14 + count * 30, 0xFF000000 + CustomNpcResourceListener.DefaultTextColor); - fontRendererObj.drawString(name, guiLeft + (xSize + 45 - fontRendererObj.getStringWidth(name)) / 4, guiTop + 19 + count * 30, faction.color); - - fontRendererObj.drawString(standing, (guiLeft + (xSize + 45) / 4) - fontRendererObj.getStringWidth(standing), guiTop + 33 + count * 30, color); - fontRendererObj.drawString(points, (guiLeft + (xSize + 45) / 4), guiTop + 33 + count * 30, CustomNpcResourceListener.DefaultTextColor); - } - else { - fontRendererObj.drawString(name, guiLeft + 3*(xSize + 45 - fontRendererObj.getStringWidth(name)) / 4, guiTop + 19 + (count - 5) * 30, faction.color); - - fontRendererObj.drawString(standing, (guiLeft + 3*(xSize + 45) / 4) - fontRendererObj.getStringWidth(standing) - 10, guiTop + 33 + (count - 5) * 30, color); - fontRendererObj.drawString(points, (guiLeft + 3*(xSize + 45) / 4) - 10, guiTop + 33 + (count - 5) * 30, CustomNpcResourceListener.DefaultTextColor); - } - - drawHorizontalLine(guiLeft + 2, guiLeft + xSize + 35, guiTop + 14 + hLine * 30, 0xFF000000 + CustomNpcResourceListener.DefaultTextColor); - } - - if(pages > 1){ - String s = page +"/" + pages; - fontRendererObj.drawString(s, guiLeft + (xSize + 45 - fontRendererObj.getStringWidth(s)) / 2, guiTop + 175, CustomNpcResourceListener.DefaultTextColor); + if(scroll == null){ + scroll = new GuiCustomScroll(this,0,0); + scroll.setSize(143, 185); } + scroll.guiLeft = guiLeft + 220; + scroll.guiTop = guiTop + 4; + scroll.setList(new ArrayList(this.data.keySet())); + this.addScroll(scroll); } @Override - protected void actionPerformed(GuiButton guibutton){ + protected void actionPerformed(GuiButton guibutton){ if(guibutton instanceof AbstractTab) return; @@ -137,63 +80,211 @@ public class GuiProfiles extends GuiCNPCInventory implements IGuiData { super.actionPerformed(guibutton); return; } - if(!(guibutton instanceof GuiButtonNextPage)) - return; - int id = guibutton.id; - if(id == 1){ - page++; - } - if(id == 2){ - page--; - } - updateButtons(); } - private void updateButtons(){ - buttonNextPage.setVisible(page < pages); - buttonPreviousPage.setVisible(page > 1); - } - protected void drawGuiContainerBackgroundLayer(float f, int i, int j) - { + @Override + public void drawScreen(int i, int j, float f) + { + super.drawScreen(i, j, f); + if(hasSubGui()) + return; + } + + @Override + public void drawBackground() { + super.drawBackground(); + renderScreen(); + } + + private void renderScreen() { + // Draw the common background bars + drawGradientRect(guiLeft + 5, guiTop + 4, guiLeft + 218, guiTop + 24, 0xC0101010, 0xC0101010); + drawHorizontalLine(guiLeft + 5, guiLeft + 218, guiTop + 25, 0xFF000000 + CustomNpcResourceListener.DefaultTextColor); + drawGradientRect(guiLeft + 5, guiTop + 27, guiLeft + 218, guiTop + ySize + 9, 0xA0101010, 0xA0101010); + + if (this.profile != null) { + // Top bar: display NPC display name (centered) +// String topBarText = npc.display.getName(); +// int textWidth = getStringWidthWithoutColor(topBarText); +// int centerX = guiLeft + 5 + ((218 - 10 - textWidth) / 2); +// fontRendererObj.drawString(topBarText, centerX, guiTop + 10, npc.getFaction().color, true); +// +// // Lower section: display NPC properties as label and value pairs +// int y = guiTop + 30; +// int xLabel = guiLeft + 8; +// int xValue = guiLeft + 120; +// int valueColor = 0xFFFFFF; +// String label, value; +// +// // Health +// label = StatCollector.translateToLocal("stats.health") + ": "; +// value = String.valueOf(npc.stats.maxHealth); +// fontRendererObj.drawString(label, xLabel, y, 0x29d6b9, false); +// fontRendererObj.drawString(value, xValue, y, valueColor, false); +// y += 15; +// +// // Damage (using getAttackStrength) +// label = StatCollector.translateToLocal("stats.meleestrength") + ": "; +// value = String.valueOf(npc.stats.getAttackStrength()); +// fontRendererObj.drawString(label, xLabel, y, 0xff5714, false); +// fontRendererObj.drawString(value, xValue, y, valueColor, false); +// y += 15; +// +// // Attack Speed +// label = StatCollector.translateToLocal("stats.meleespeed") + ": "; +// value = String.valueOf(npc.stats.attackSpeed); +// fontRendererObj.drawString(label, xLabel, y, 0xf7ca28, false); +// fontRendererObj.drawString(value, xValue, y, valueColor, false); +// y += 15; +// +// // AI Type (npc.ai.onAttack: 0 = fight, 1 = panic, 2 = retreat, 3 = nothing) +// label = StatCollector.translateToLocal("menu.ai") + ": "; +// int onAttack = npc.ais.onAttack; +// switch (onAttack) { +// case 0: +// value = StatCollector.translateToLocal("gui.retaliate"); +// break; +// case 1: +// value = StatCollector.translateToLocal("gui.panic"); +// break; +// case 2: +// value = StatCollector.translateToLocal("gui.retreat"); +// break; +// case 3: +// default: +// value = StatCollector.translateToLocal("gui.nothing"); +// break; +// } +// fontRendererObj.drawString(label, xLabel, y, 0xce75fa, false); +// fontRendererObj.drawString(value, xValue, y, valueColor, false); +// y += 15; +// +// // Walk Speed +// label = StatCollector.translateToLocal("stats.speed") + ": "; +// value = String.valueOf(npc.ais.getWalkingSpeed()); +// fontRendererObj.drawString(label, xLabel, y, 0xffae0d, false); +// fontRendererObj.drawString(value, xValue, y, valueColor, false); +// y += 15; +// +// // Movement Type (0 = Ground, 1 = Flying) +// label = StatCollector.translateToLocal("movement.type") + ": "; +// int movementType = npc.ais.movementType; +// if (movementType == 0) { +// value = StatCollector.translateToLocal("movement.ground"); +// } else { +// value = StatCollector.translateToLocal("movement.flying"); +// } +// fontRendererObj.drawString(label, xLabel, y, 0x7cff54, false); +// fontRendererObj.drawString(value, xValue, y, valueColor, false); +// y += 15; + } } @Override public void keyTyped(char c, int i) { - if (i == 1 || isInventoryKey(i)) + if (i == 1 || (!hasSubGui() && isInventoryKey(i))) { close(); } } @Override - public void save() { - } - @Override - public void setGuiData(NBTTagCompound compound) { - playerFactions = new ArrayList(); + public void save() {} - NBTTagList list = compound.getTagList("FactionList", 10); - for(int i = 0; i < list.tagCount(); i++){ - Faction faction = new Faction(); - faction.readNBT(list.getCompoundTagAt(i)); - playerFactions.add(faction); - } - PlayerFactionData data = new PlayerFactionData(); - data.loadNBTData(compound); - for(int id : data.factionData.keySet()){ - int points = data.factionData.get(id); - for(Faction faction : playerFactions){ - if(faction.id == id) - faction.defaultPoints = points; - } - } + @Override + public void confirmClicked(boolean result, int id) { + NoppesUtil.openGUI(player, this); + if (!result) + return; + if (id == 1) { + if (data.containsKey(scroll.getSelected())) { - pages = (playerFactions.size() - 1) / 10 ; - pages++; + // DELETE PROFILE + // PacketClient.sendClient(new LinkedNPCRemovePacket(scroll.getSelected())); - page = 1; + initGui(); + } + } + if(id == 1){ + if (data.containsKey(scroll.getSelected())) { - updateButtons(); - } + // RENAME PROFILE + // PacketClient.sendClient(new LinkedItemRemovePacket(data.get(scroll.getSelected()))); + + initGui(); + } + } + if(id == 1){ + // CREATE PROFILE + // PacketClient.sendClient(new LinkedItemRemovePacket(data.get(scroll.getSelected()))); + + initGui(); + } + if(id == 1){ + // CHANGE PROFILE + // PacketClient.sendClient(new LinkedItemRemovePacket(data.get(scroll.getSelected()))); + + initGui(); + } + } + + public int getStringWidthWithoutColor(String text) { + int width = 0; + for (int i = 0; i < text.length(); i++) { + char c = text.charAt(i); + + if (c == '§') { + if (i < text.length() - 1) { + i += 1; + } + } else { + // If not a color code, calculate the width + width += fontRendererObj.getCharWidth(c); + } + } + return width; + } + + @Override + public void subGuiClosed(SubGuiInterface subgui) { + if(subgui instanceof SubGuiEditText){ + if(!((SubGuiEditText)subgui).cancelled){ + PacketClient.sendClient(new LinkedNPCAddPacket(((SubGuiEditText)subgui).text)); + } + } + } + + public boolean isMouseOverRenderer(int x, int y) { + return x >= guiLeft + 10 && x <= guiLeft + 10 + 200 && y >= guiTop + 6 && y <= guiTop + 6 + 204; + } + + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { + if (guiCustomScroll.id == 0) { + selected = scroll.getSelected(); + if (selected != null && !selected.isEmpty()){ + // LOAD SLOT INFORMATION + + } + } + } + + @Override + public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {} + + public void setGuiData(NBTTagCompound compound) { + this.profile = null; + if(compound.hasKey("PROFILE")){ + // Load Profile + this.profile = new Profile(mc.thePlayer, compound); + this.data = new HashMap<>(); + for(Slot slot1 : profile.slots.values()){ + this.data.put(slot1.getName(), slot1.getId()); + } + } else if(compound.hasKey("PROFILE_INFO")){ + + } + initGui(); + } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerData.java b/src/main/java/noppes/npcs/controllers/data/PlayerData.java index 4f8731c96..d53ff7c1c 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerData.java @@ -17,6 +17,7 @@ import noppes.npcs.api.entity.ICustomNpc; import noppes.npcs.api.handler.*; import noppes.npcs.config.ConfigMain; import noppes.npcs.constants.EnumRoleType; +import noppes.npcs.controllers.CustomEffectController; import noppes.npcs.controllers.PartyController; import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.entity.EntityCustomNpc; @@ -71,7 +72,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData { public int profileSlot = 0; public void onLogin() { - //Continue playing animation for self when re-logging + // Continue playing animation for self when re-logging AnimationData animationData = this.animationData; if (animationData != null && animationData.isClientAnimating()) { Animation currentAnimation = animationData.currentClientAnimation; @@ -79,6 +80,13 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData { animationData.viewAnimation(currentAnimation, animationData, compound, animationData.isClientAnimating(), currentAnimation.currentFrame, currentAnimation.currentFrameTime); } + + CustomEffectController controller = CustomEffectController.getInstance(); + UUID playerID = player.getPersistentID(); + // Only add if there are saved effects and none are registered yet. + if (!controller.playerEffects.containsKey(playerID)) { + controller.playerEffects.put(playerID, effectData.getEffects()); + } } public void onLogout() { From cd123979279b87762c39b5279d55d770552f5534 Mon Sep 17 00:00:00 2001 From: Kam Date: Wed, 19 Feb 2025 05:43:28 -0500 Subject: [PATCH 10/59] Profile GUI and Effect Bar --- .../kamkeel/npcs/command/CommandKamkeel.java | 2 +- .../npcs/controllers/ProfileController.java | 14 +- .../npcs/controllers/data/CNPCData.java | 12 +- .../npcs/controllers/data/IProfileData.java | 4 +- .../npcs/controllers/data/InfoEntry.java | 50 +++ .../kamkeel/npcs/network/PacketHandler.java | 2 + .../npcs/network/enums/EnumRequestPacket.java | 2 +- .../request/profile/ProfileGetInfoPacket.java | 97 +++++ .../player/inventory/GuiCNPCInventory.java | 66 +++- .../gui/player/inventory/GuiProfiles.java | 365 ++++++++++++------ .../npcs/client/gui/util/GuiEffectBar.java | 195 ++++++++++ .../npcs/controllers/data/CustomEffect.java | 1 - .../client/tabs/InventoryTabCustomNpc.java | 2 +- .../assets/customnpcs/lang/en_US.lang | 4 + 14 files changed, 671 insertions(+), 145 deletions(-) create mode 100644 src/main/java/kamkeel/npcs/controllers/data/InfoEntry.java create mode 100644 src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java create mode 100644 src/main/java/noppes/npcs/client/gui/util/GuiEffectBar.java diff --git a/src/main/java/kamkeel/npcs/command/CommandKamkeel.java b/src/main/java/kamkeel/npcs/command/CommandKamkeel.java index 85adfce4c..59920807e 100644 --- a/src/main/java/kamkeel/npcs/command/CommandKamkeel.java +++ b/src/main/java/kamkeel/npcs/command/CommandKamkeel.java @@ -47,7 +47,7 @@ public class CommandKamkeel extends CommandBase{ @Override public String getCommandName() { - return "kamkeel/npcs"; + return "kamkeel"; } @Override diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index cdad4795d..71c2d9f5e 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -1,9 +1,6 @@ package kamkeel.npcs.controllers; -import kamkeel.npcs.controllers.data.IProfileData; -import kamkeel.npcs.controllers.data.Profile; -import kamkeel.npcs.controllers.data.ProfileOperation; -import kamkeel.npcs.controllers.data.Slot; +import kamkeel.npcs.controllers.data.*; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.CompressedStreamTools; @@ -552,6 +549,7 @@ public class ProfileController { dataCompound.setTag(profileData.getTagName(), cloned); } slot.setCompound(dataCompound); + slot.setLastLoaded(System.currentTimeMillis()); } public static void loadSlotData(EntityPlayer player) { @@ -576,8 +574,8 @@ public class ProfileController { } } - public static List getProfileInfo(EntityPlayer player, int slotId) { - List infoList = new ArrayList<>(); + public static List getProfileInfo(EntityPlayer player, int slotId) { + List infoList = new ArrayList<>(); Profile profile = getProfile(player); if (profile == null) return infoList; @@ -589,7 +587,7 @@ public class ProfileController { // Use current data (not stored slot data) for active slot. for (IProfileData pd : dataList) { NBTTagCompound currentNBT = pd.getCurrentNBT(player); - List subInfo = pd.getInfo(player, currentNBT); + List subInfo = pd.getInfo(player, currentNBT); infoList.addAll(subInfo); } } else { @@ -600,7 +598,7 @@ public class ProfileController { for (IProfileData pd : dataList) { if (slotCompound.hasKey(pd.getTagName())) { NBTTagCompound sub = slotCompound.getCompoundTag(pd.getTagName()); - List subInfo = pd.getInfo(player, sub); + List subInfo = pd.getInfo(player, sub); infoList.addAll(subInfo); } } diff --git a/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java b/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java index 60bf83cee..6a60ade72 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java +++ b/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java @@ -53,17 +53,15 @@ public class CNPCData implements IProfileData { } @Override - public List getInfo(EntityPlayer player, NBTTagCompound compound) { + public List getInfo(EntityPlayer player, NBTTagCompound compound) { PlayerData playerData = new PlayerData(); playerData.player = player; playerData.setNBT(compound); - List info = new ArrayList<>(); - - info.add("QuestsFinished" + "###" + playerData.questData.finishedQuests.size()); - info.add("QuestsActive" + "###" + playerData.questData.activeQuests.size()); - info.add("DialogsRead" + "###" + playerData.dialogData.dialogsRead.size()); - + List info = new ArrayList<>(); + info.add(new InfoEntry("profile.info.quest.finished", 0x60fa57, playerData.questData.finishedQuests.size(), 0xFFFFFF)); + info.add(new InfoEntry("profile.info.quest.active", 0xf75336, playerData.questData.activeQuests.size(), 0xFFFFFF)); + info.add(new InfoEntry("profile.info.dialog.read", 0x47acf5, playerData.dialogData.dialogsRead.size(), 0xFFFFFF)); return info; } } diff --git a/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java b/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java index 00dc63929..2b5e308b5 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java +++ b/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java @@ -45,7 +45,7 @@ public interface IProfileData { * based on the provided NBTTagCompound from the slot. * @param player The player in question. * @param compound The NBT data from the slot under this profile data's tag. - * @return A list of strings with information (could be empty). + * @return A list of InfoEntry with information */ - public List getInfo(EntityPlayer player, NBTTagCompound compound); + public List getInfo(EntityPlayer player, NBTTagCompound compound); } diff --git a/src/main/java/kamkeel/npcs/controllers/data/InfoEntry.java b/src/main/java/kamkeel/npcs/controllers/data/InfoEntry.java new file mode 100644 index 000000000..7a8f29991 --- /dev/null +++ b/src/main/java/kamkeel/npcs/controllers/data/InfoEntry.java @@ -0,0 +1,50 @@ +package kamkeel.npcs.controllers.data; + +import net.minecraft.nbt.NBTTagCompound; + +public class InfoEntry { + private String label; + private String result; + private int labelColor; + private int resultColor; + + public InfoEntry() {} + + public InfoEntry(String label, int labelColor, String result, int resultColor) { + this.label = label; + this.result = result; + this.labelColor = labelColor; + this.resultColor = resultColor; + } + + public InfoEntry(String label, int labelColor, int result, int resultColor) { + this(label, labelColor, String.valueOf(result), resultColor); + } + + public InfoEntry(String label, String result) { + this(label, 0xFFFFFF, result, 0xFFFFFF); + } + + public NBTTagCompound writeToNBT() { + NBTTagCompound tag = new NBTTagCompound(); + tag.setString("Label", label); + tag.setInteger("LabelColor", labelColor); + tag.setString("Result", result); + tag.setInteger("ResultColor", resultColor); + return tag; + } + + public static InfoEntry readFromNBT(NBTTagCompound tag) { + return new InfoEntry( + tag.getString("Label"), + tag.getInteger("LabelColor"), + tag.getString("Result"), + tag.getInteger("ResultColor") + ); + } + + public String getLabel() { return label; } + public String getResult() { return result; } + public int getLabelColor() { return labelColor; } + public int getResultColor() { return resultColor; } +} diff --git a/src/main/java/kamkeel/npcs/network/PacketHandler.java b/src/main/java/kamkeel/npcs/network/PacketHandler.java index c9c0dd5c2..de5799d2b 100644 --- a/src/main/java/kamkeel/npcs/network/PacketHandler.java +++ b/src/main/java/kamkeel/npcs/network/PacketHandler.java @@ -56,6 +56,7 @@ import kamkeel.npcs.network.packets.request.pather.MovingPathSavePacket; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetPacket; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataMapRegenPacket; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataRemovePacket; +import kamkeel.npcs.network.packets.request.profile.ProfileGetInfoPacket; import kamkeel.npcs.network.packets.request.profile.ProfileGetPacket; import kamkeel.npcs.network.packets.request.quest.*; import kamkeel.npcs.network.packets.request.recipe.RecipeGetPacket; @@ -326,6 +327,7 @@ public class PacketHandler { // Profile Packets REQUEST_PACKET.registerPacket(new ProfileGetPacket()); + REQUEST_PACKET.registerPacket(new ProfileGetInfoPacket()); // Other Packets REQUEST_PACKET.registerPacket(new IsGuiOpenInform()); diff --git a/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java b/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java index 92d90a328..49e0b57b5 100644 --- a/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java +++ b/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java @@ -185,5 +185,5 @@ public enum EnumRequestPacket { EffectSave, ColorSet, - ProfileGet, ProfileGetAll, ColorBrush + ProfileGet, ProfileGetAll, ProfileGetInfo, ColorBrush } diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java new file mode 100644 index 000000000..5d853db50 --- /dev/null +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java @@ -0,0 +1,97 @@ +package kamkeel.npcs.network.packets.request.profile; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import io.netty.buffer.ByteBuf; +import kamkeel.npcs.controllers.ProfileController; +import kamkeel.npcs.controllers.data.InfoEntry; +import kamkeel.npcs.controllers.data.Profile; +import kamkeel.npcs.controllers.data.Slot; +import kamkeel.npcs.network.AbstractPacket; +import kamkeel.npcs.network.PacketChannel; +import kamkeel.npcs.network.PacketHandler; +import kamkeel.npcs.network.enums.EnumRequestPacket; +import kamkeel.npcs.network.packets.data.large.GuiDataPacket; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraftforge.common.util.Constants; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public final class ProfileGetInfoPacket extends AbstractPacket { + public static String packetName = "Request|ProfileGetInfo"; + + public ProfileGetInfoPacket() {} + + @Override + public Enum getType() { + return EnumRequestPacket.ProfileGetInfo; + } + + @Override + public PacketChannel getChannel() { + return PacketHandler.REQUEST_PACKET; + } + + @SideOnly(Side.CLIENT) + @Override + public void sendData(ByteBuf out) throws IOException {} + + @Override + public void receiveData(ByteBuf in, EntityPlayer player) throws IOException { + if (!(player instanceof EntityPlayerMP)) + return; + + NBTTagCompound compound = new NBTTagCompound(); + compound.setBoolean("PROFILE_INFO", true); + NBTTagList slotList = new NBTTagList(); + Profile profile = ProfileController.getProfile(player); + if(profile != null){ + for(Slot slot : profile.slots.values()){ + NBTTagCompound slotCompound = new NBTTagCompound(); + NBTTagList infoList = new NBTTagList(); + slotCompound.setInteger("ID", slot.getId()); + List profileInfo = ProfileController.getProfileInfo(player, slot.getId()); + for(InfoEntry infoEntry : profileInfo){ + infoList.appendTag(infoEntry.writeToNBT()); + } + slotCompound.setTag("INFO", infoList); + slotList.appendTag(slotCompound); + } + compound.setTag("SLOTS", slotList); + } + GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound); + } + + public static HashMap> readSlotsFromNBT(NBTTagCompound compound) { + HashMap> slotInfoMap = new HashMap<>(); + + if (!compound.getBoolean("PROFILE_INFO")) return slotInfoMap; + + NBTTagList slotList = compound.getTagList("SLOTS", Constants.NBT.TAG_COMPOUND); + + for (int i = 0; i < slotList.tagCount(); i++) { + NBTTagCompound slotCompound = slotList.getCompoundTagAt(i); + + int slotId = slotCompound.getInteger("ID"); + NBTTagList infoList = slotCompound.getTagList("INFO", Constants.NBT.TAG_COMPOUND); + + List infoEntries = new ArrayList<>(); + for (int j = 0; j < infoList.tagCount(); j++) { + NBTTagCompound infoTag = infoList.getCompoundTagAt(j); + infoEntries.add(InfoEntry.readFromNBT(infoTag)); // Convert back to InfoEntry + } + + slotInfoMap.put(slotId, infoEntries); + } + + return slotInfoMap; + } + +} 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 68395a52f..ee607398b 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 @@ -4,10 +4,15 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.util.ResourceLocation; import noppes.npcs.client.ClientCacheHandler; +import noppes.npcs.client.gui.util.GuiEffectBar; import noppes.npcs.client.gui.util.GuiMenuSideButton; import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.config.ConfigClient; -import noppes.npcs.config.ConfigMain; +import noppes.npcs.controllers.CustomEffectController; +import noppes.npcs.controllers.data.CustomEffect; +import noppes.npcs.controllers.data.PlayerData; +import noppes.npcs.controllers.data.PlayerEffect; +import org.lwjgl.input.Mouse; import tconstruct.client.tabs.InventoryTabCustomNpc; import tconstruct.client.tabs.TabRegistry; @@ -16,6 +21,7 @@ public class GuiCNPCInventory extends GuiNPCInterface { public static int activeTab = -100; protected Minecraft mc = Minecraft.getMinecraft(); + private GuiEffectBar effectBar; public GuiCNPCInventory() { super(); @@ -38,7 +44,7 @@ public class GuiCNPCInventory extends GuiNPCInterface { questsButton.active = activeTab == -100; questsButton.renderIconPosX = 32; questsButton.renderResource = specialIcons; - addButton(questsButton); + addSideButton(questsButton); if(ClientCacheHandler.allowParties){ y += 21; @@ -46,7 +52,7 @@ public class GuiCNPCInventory extends GuiNPCInterface { partyButton.rightSided = true; partyButton.active = activeTab == -101; partyButton.renderResource = specialIcons; - addButton(partyButton); + addSideButton(partyButton); } if(ConfigClient.enableFactionTab){ y += 21; @@ -55,16 +61,16 @@ public class GuiCNPCInventory extends GuiNPCInterface { factionButton.active = activeTab == -102; factionButton.renderIconPosX = 48; factionButton.renderResource = specialIcons; - addButton(factionButton); + addSideButton(factionButton); } if(ClientCacheHandler.allowProfiles){ y += 21; GuiMenuSideButton profileButton = new GuiMenuSideButton(-104, guiLeft + xSize + 37, this.guiTop + y, 22, 22, ""); profileButton.rightSided = true; profileButton.active = activeTab == -104; - profileButton.renderIconPosX = 80; + profileButton.renderIconPosX = 64; profileButton.renderResource = specialIcons; - addButton(profileButton); + addSideButton(profileButton); } y += 21; @@ -73,9 +79,55 @@ public class GuiCNPCInventory extends GuiNPCInterface { clientButton.active = activeTab == -103; clientButton.renderIconPosX = 16; clientButton.renderResource = specialIcons; - addButton(clientButton); + addSideButton(clientButton); + + int effectBarX = guiLeft + xSize + 65; + int effectBarY = guiTop + 10; + int effectBarWidth = 24; + int effectBarHeight = ySize; + effectBar = new GuiEffectBar(effectBarX, effectBarY, effectBarWidth, effectBarHeight); } + private void updateEffectBar() { + if (effectBar != null) { + effectBar.entries.clear(); + PlayerData data = PlayerData.get(mc.thePlayer); + if (data != null && data.effectData != null) { + for (PlayerEffect pe : data.effectData.getEffects().values()) { + CustomEffect effect = CustomEffectController.getInstance().get(pe.id, pe.index); + if (effect != null) { + effectBar.entries.add(new GuiEffectBar.EffectEntry(effect, pe)); + } + } + } + } + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + updateEffectBar(); + super.drawScreen(mouseX, mouseY, partialTicks); + if (effectBar != null) { + effectBar.drawScreen(mouseX, mouseY, partialTicks); + } + } + + @Override + public void handleMouseInput() { + super.handleMouseInput(); + int delta = Mouse.getDWheel(); + if (delta != 0 && effectBar != null) { + int mouseX = Mouse.getX() * width / mc.displayWidth; + int mouseY = height - Mouse.getY() * height / mc.displayHeight - 1; + // Only scroll the effect bar if the mouse is over its area. + if (mouseX >= effectBar.x && mouseX < effectBar.x + effectBar.width && + mouseY >= effectBar.y && mouseY < effectBar.y + effectBar.height) { + effectBar.mouseScrolled(delta > 0 ? 1 : -1); + } + } + } + + @Override protected void actionPerformed(GuiButton guibutton){ if (guibutton.id <= -100) { diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java index dfebad2b7..9c9f00140 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java @@ -1,36 +1,32 @@ package noppes.npcs.client.gui.player.inventory; +import kamkeel.npcs.controllers.data.InfoEntry; import kamkeel.npcs.controllers.data.Profile; import kamkeel.npcs.controllers.data.Slot; import kamkeel.npcs.network.PacketClient; -import kamkeel.npcs.network.packets.player.CheckPlayerValue; -import kamkeel.npcs.network.packets.request.linked.LinkedGetPacket; -import kamkeel.npcs.network.packets.request.linked.LinkedItemRemovePacket; import kamkeel.npcs.network.packets.request.linked.LinkedNPCAddPacket; -import kamkeel.npcs.network.packets.request.linked.LinkedNPCRemovePacket; +import kamkeel.npcs.network.packets.request.profile.ProfileGetInfoPacket; import kamkeel.npcs.network.packets.request.profile.ProfileGetPacket; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiYesNoCallback; +import net.minecraft.client.gui.ScaledResolution; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; -import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.client.CustomNpcResourceListener; import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.SubGuiEditText; import noppes.npcs.client.gui.util.*; -import noppes.npcs.constants.EnumPlayerPacket; -import noppes.npcs.controllers.data.Faction; -import noppes.npcs.controllers.data.LinkedItem; -import noppes.npcs.controllers.data.PlayerFactionData; +import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import tconstruct.client.tabs.AbstractTab; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.List; -import java.util.Vector; public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, ICustomScrollListener, IGuiData, GuiYesNoCallback { @@ -40,14 +36,23 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC private String selected = null; private Profile profile; private Slot slot; + private HashMap> slotInfoMap = new HashMap<>(); + private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("MM/dd/yyyy HH:mm"); - public GuiProfiles() { + private int scrollY = 0; // Vertical scrolling position + private int maxScrollY = 0; // Maximum scroll limit + + private boolean draggingScrollbar = false; // Track if user is dragging the scrollbar + private int lastMouseY = 0; // Last recorded mouse Y position when dragging + + public GuiProfiles() { super(); xSize = 280; ySize = 180; this.drawDefaultBackground = false; title = ""; PacketClient.sendClient(new ProfileGetPacket()); + PacketClient.sendClient(new ProfileGetInfoPacket()); } @Override @@ -55,17 +60,17 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC { super.initGui(); - int y = guiTop + 8; - this.addButton(new GuiNpcButton(1,guiLeft + 368, y += 40, 45, 20, "gui.add")); - this.addButton(new GuiNpcButton(2,guiLeft + 368, y += 22, 45, 20, "gui.remove")); - this.addButton(new GuiNpcButton(3,guiLeft + 368, y += 22, 45, 20, "gui.rename")); - this.addButton(new GuiNpcButton(4,guiLeft + 368, y += 22, 45, 20, "gui.change")); + int y = guiTop + 4; + this.addButton(new GuiNpcButton(1,guiLeft + 4, y += 144, 60, 20, "gui.change")); + this.addButton(new GuiNpcButton(2,guiLeft + 4 + 63, y, 60, 20, "gui.rename")); + this.addButton(new GuiNpcButton(3,guiLeft + 4 + 63, y += 22, 60, 20, "gui.remove")); + this.addButton(new GuiNpcButton(4,guiLeft + 4, y, 60, 20, "gui.create")); if(scroll == null){ scroll = new GuiCustomScroll(this,0,0); - scroll.setSize(143, 185); + scroll.setSize(123, 141); } - scroll.guiLeft = guiLeft + 220; + scroll.guiLeft = guiLeft + 4; scroll.guiTop = guiTop + 4; scroll.setList(new ArrayList(this.data.keySet())); this.addScroll(scroll); @@ -82,102 +87,162 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC } } - @Override - public void drawScreen(int i, int j, float f) - { - super.drawScreen(i, j, f); - if(hasSubGui()) - return; - } - @Override - public void drawBackground() { - super.drawBackground(); - renderScreen(); + public void drawScreen(int mouseX, int mouseY, float f) { + drawDefaultBackground(); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + mc.renderEngine.bindTexture(resource); + drawTexturedModalRect(guiLeft, guiTop, 0, 0, 252, 195); + drawTexturedModalRect(guiLeft + 252, guiTop, 188, 0, 67, 195); + + super.drawScreen(mouseX, mouseY, f); + if (hasSubGui()) return; + + renderScrollableScreen(mouseX, mouseY); } - private void renderScreen() { - // Draw the common background bars - drawGradientRect(guiLeft + 5, guiTop + 4, guiLeft + 218, guiTop + 24, 0xC0101010, 0xC0101010); - drawHorizontalLine(guiLeft + 5, guiLeft + 218, guiTop + 25, 0xFF000000 + CustomNpcResourceListener.DefaultTextColor); - drawGradientRect(guiLeft + 5, guiTop + 27, guiLeft + 218, guiTop + ySize + 9, 0xA0101010, 0xA0101010); + /** + * Renders the scrollable area inside the background box. + */ + private void renderScrollableScreen(int mouseX, int mouseY) { + drawGradientRect(guiLeft + 133, guiTop + 4, guiLeft + xSize + 33, guiTop + 24, 0xC0101010, 0xC0101010); + drawHorizontalLine(guiLeft + 133, guiLeft + xSize + 33, guiTop + 25, 0xFF000000 + CustomNpcResourceListener.DefaultTextColor); + drawGradientRect(guiLeft + 133, guiTop + 27, guiLeft + xSize + 33, guiTop + ySize + 9, 0xA0101010, 0xA0101010); - if (this.profile != null) { - // Top bar: display NPC display name (centered) -// String topBarText = npc.display.getName(); -// int textWidth = getStringWidthWithoutColor(topBarText); -// int centerX = guiLeft + 5 + ((218 - 10 - textWidth) / 2); -// fontRendererObj.drawString(topBarText, centerX, guiTop + 10, npc.getFaction().color, true); -// -// // Lower section: display NPC properties as label and value pairs -// int y = guiTop + 30; -// int xLabel = guiLeft + 8; -// int xValue = guiLeft + 120; -// int valueColor = 0xFFFFFF; -// String label, value; -// -// // Health -// label = StatCollector.translateToLocal("stats.health") + ": "; -// value = String.valueOf(npc.stats.maxHealth); -// fontRendererObj.drawString(label, xLabel, y, 0x29d6b9, false); -// fontRendererObj.drawString(value, xValue, y, valueColor, false); -// y += 15; -// -// // Damage (using getAttackStrength) -// label = StatCollector.translateToLocal("stats.meleestrength") + ": "; -// value = String.valueOf(npc.stats.getAttackStrength()); -// fontRendererObj.drawString(label, xLabel, y, 0xff5714, false); -// fontRendererObj.drawString(value, xValue, y, valueColor, false); -// y += 15; -// -// // Attack Speed -// label = StatCollector.translateToLocal("stats.meleespeed") + ": "; -// value = String.valueOf(npc.stats.attackSpeed); -// fontRendererObj.drawString(label, xLabel, y, 0xf7ca28, false); -// fontRendererObj.drawString(value, xValue, y, valueColor, false); -// y += 15; -// -// // AI Type (npc.ai.onAttack: 0 = fight, 1 = panic, 2 = retreat, 3 = nothing) -// label = StatCollector.translateToLocal("menu.ai") + ": "; -// int onAttack = npc.ais.onAttack; -// switch (onAttack) { -// case 0: -// value = StatCollector.translateToLocal("gui.retaliate"); -// break; -// case 1: -// value = StatCollector.translateToLocal("gui.panic"); -// break; -// case 2: -// value = StatCollector.translateToLocal("gui.retreat"); -// break; -// case 3: -// default: -// value = StatCollector.translateToLocal("gui.nothing"); -// break; -// } -// fontRendererObj.drawString(label, xLabel, y, 0xce75fa, false); -// fontRendererObj.drawString(value, xValue, y, valueColor, false); -// y += 15; -// -// // Walk Speed -// label = StatCollector.translateToLocal("stats.speed") + ": "; -// value = String.valueOf(npc.ais.getWalkingSpeed()); -// fontRendererObj.drawString(label, xLabel, y, 0xffae0d, false); -// fontRendererObj.drawString(value, xValue, y, valueColor, false); -// y += 15; -// -// // Movement Type (0 = Ground, 1 = Flying) -// label = StatCollector.translateToLocal("movement.type") + ": "; -// int movementType = npc.ais.movementType; -// if (movementType == 0) { -// value = StatCollector.translateToLocal("movement.ground"); -// } else { -// value = StatCollector.translateToLocal("movement.flying"); -// } -// fontRendererObj.drawString(label, xLabel, y, 0x7cff54, false); -// fontRendererObj.drawString(value, xValue, y, valueColor, false); -// y += 15; + if (this.profile != null && slot != null) { + + String topBarText = slot.getName(); + int textWidth = fontRendererObj.getStringWidth(topBarText); + int barCenterX = guiLeft + 133 + ((xSize + 33 - 133) / 2); + int textX = barCenterX - (textWidth / 2); + fontRendererObj.drawString(topBarText, textX, guiTop + 10, 0xFFFFFF, true); + + GL11.glEnable(GL11.GL_SCISSOR_TEST); + ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + int scaleFactor = sr.getScaleFactor(); + + // Define the SCISSOR RECTANGLE to restrict drawing to only within the background box + int scissorX = (guiLeft + 133) * scaleFactor; + int scissorY = (sr.getScaledHeight() - (guiTop + ySize + 6)) * scaleFactor; + int scissorW = (xSize + 33 - 133) * scaleFactor; + int scissorH = (ySize + 4 - 27) * scaleFactor; // The height from 27 to ySize+9 + GL11.glScissor(scissorX, scissorY, scissorW, scissorH); + + GL11.glPushMatrix(); + GL11.glTranslatef(0, -scrollY, 0); // Apply Scroll to Info + + int spacing = 14; + int y = guiTop + 30; + int xLabel = guiLeft + 136; + int boxRightX = guiLeft + xSize + 30; + + String label, result; + int labelColor, resultColor, resultWidth, resultX; + + label = StatCollector.translateToLocal("profile.lastLoaded"); + result = String.valueOf(DATE_FORMAT.format(new Date(slot.getLastLoaded()))); + labelColor = 0xff9c2b; + resultColor = 0xffdb59; + fontRendererObj.drawString(label, xLabel, y, labelColor, false); + resultWidth = fontRendererObj.getStringWidth(result); + resultX = boxRightX - resultWidth - 5; + fontRendererObj.drawString(result, resultX, y, resultColor, false); + y += spacing; + + if(slot.isTemporary()){ + label = StatCollector.translateToLocal("profile.temporary"); + result = (String.valueOf(slot.isTemporary())).toUpperCase(); + labelColor = 0xfc60dd; + resultColor = 0x35fc81; + fontRendererObj.drawString(label, xLabel, y, labelColor, false); + resultWidth = fontRendererObj.getStringWidth(result); + resultX = boxRightX - resultWidth - 5; + fontRendererObj.drawString(result, resultX, y, resultColor, false); + y += spacing; + } + + if (slotInfoMap.containsKey(slot.getId())) { + List infoEntries = slotInfoMap.get(slot.getId()); + for (InfoEntry entry : infoEntries) { + label = StatCollector.translateToLocal(entry.getLabel()); + result = StatCollector.translateToLocal(entry.getResult()); + labelColor = entry.getLabelColor(); + resultColor = entry.getResultColor(); + + // Draw Label + fontRendererObj.drawString(label, xLabel, y, labelColor, false); + + // Calculate Result X Position (Right-Aligned) + resultWidth = fontRendererObj.getStringWidth(result); + resultX = boxRightX - resultWidth - 5; + + // Draw Result at Right-Aligned Position + fontRendererObj.drawString(result, resultX, y, resultColor, false); + + // Move to next line + y += spacing; + } + } + + maxScrollY = Math.max(0, y - (guiTop + ySize - 35)); } + + GL11.glPopMatrix(); + GL11.glDisable(GL11.GL_SCISSOR_TEST); + + // Draw scrollbar only if needed + if (maxScrollY > 0) { + drawScrollbar(); + } + } + + /** + * Handles mouse scroll input **only inside the background box**. + */ + @Override + public void handleMouseInput() { + super.handleMouseInput(); + if(isMouseOverScrollBox(mouseX, mouseY)){ + int delta = Mouse.getEventDWheel(); + if (delta != 0) { + scrollY -= delta / 7; + if (scrollY < 0) scrollY = 0; + if (scrollY > maxScrollY) scrollY = maxScrollY; + } + } + + if (draggingScrollbar) { + if (Mouse.isButtonDown(0)) { + int mouseDiff = mouseY - lastMouseY; + scrollY += (mouseDiff * maxScrollY) / (ySize - 70); + scrollY = Math.max(0, Math.min(scrollY, maxScrollY)); + lastMouseY = mouseY; + } else { + draggingScrollbar = false; + } + } + } + + /** + * Draws the vertical scrollbar (only if needed). + */ + private void drawScrollbar() { + int scrollbarX = guiLeft + xSize + 30; + int scrollbarY = guiTop + 27; + int scrollbarHeight = ySize - 18; + int thumbHeight = Math.max(10, (scrollbarHeight * scrollbarHeight) / (maxScrollY + scrollbarHeight)); + int thumbY = scrollbarY + ((scrollY * (scrollbarHeight - thumbHeight)) / maxScrollY); + + drawRect(scrollbarX, scrollbarY, scrollbarX + 5, scrollbarY + scrollbarHeight, 0xFF333333); + drawRect(scrollbarX, thumbY, scrollbarX + 5, thumbY + thumbHeight, 0xFFAAAAAA); + } + + /** + * Checks if the mouse is inside the background box for scrolling. + */ + private boolean isMouseOverScrollBox(int mouseX, int mouseY) { + return (mouseX >= guiLeft + 133 && mouseX <= guiLeft + xSize + 33 && + mouseY >= guiTop + 27 && mouseY <= guiTop + ySize + 9); } @Override @@ -239,7 +304,7 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC } } else { // If not a color code, calculate the width - width += fontRendererObj.getCharWidth(c); + width += Minecraft.getMinecraft().fontRenderer.getCharWidth(c); } } return width; @@ -261,10 +326,15 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC @Override public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { if (guiCustomScroll.id == 0) { + slot = null; selected = scroll.getSelected(); - if (selected != null && !selected.isEmpty()){ - // LOAD SLOT INFORMATION - + if (profile != null && selected != null && !selected.isEmpty()){ + for(Slot checkSlot : profile.slots.values()){ + if(checkSlot.getId() == data.get(selected)){ + slot = checkSlot; + break; + } + } } } } @@ -273,18 +343,79 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {} public void setGuiData(NBTTagCompound compound) { - this.profile = null; if(compound.hasKey("PROFILE")){ // Load Profile this.profile = new Profile(mc.thePlayer, compound); this.data = new HashMap<>(); + String colorCode = "\u00A7e"; for(Slot slot1 : profile.slots.values()){ - this.data.put(slot1.getName(), slot1.getId()); + String name = slot1.getId() + " - " + slot1.getName(); + if(profile.currentID == slot1.getId()) + name = colorCode + name; + this.data.put(name, slot1.getId()); } } else if(compound.hasKey("PROFILE_INFO")){ - + slotInfoMap = ProfileGetInfoPacket.readSlotsFromNBT(compound); } initGui(); } + /** + * Handles mouse clicks for the scrollbar. + */ + @Override + public void mouseClicked(int mouseX, int mouseY, int button) { + super.mouseClicked(mouseX, mouseY, button); + + if (button == 0) { // Left mouse button + if (isMouseOverScrollbar(mouseX, mouseY)) { + int scrollbarY = guiTop + 27; + int scrollbarHeight = ySize - 35; + int thumbHeight = Math.max(10, (scrollbarHeight * scrollbarHeight) / (maxScrollY + scrollbarHeight)); + int thumbY = scrollbarY + ((scrollY * (scrollbarHeight - thumbHeight)) / maxScrollY); + + // If clicking on scrollbar thumb, start dragging + if (mouseY >= thumbY && mouseY <= thumbY + thumbHeight) { + draggingScrollbar = true; + lastMouseY = mouseY; + } else { + // Click anywhere on scrollbar background to jump position + scrollY = ((mouseY - scrollbarY) * maxScrollY) / scrollbarHeight; + scrollY = Math.max(0, Math.min(scrollY, maxScrollY)); + } + } + } + } + + /** + * Handles mouse dragging while clicking. + */ + @Override + protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + if (draggingScrollbar) { + int mouseDiff = mouseY - lastMouseY; + scrollY += (mouseDiff * maxScrollY) / (ySize - 70); + scrollY = Math.max(0, Math.min(scrollY, maxScrollY)); + lastMouseY = mouseY; + } + } + + /** + * Handles mouse release. + */ + @Override + protected void mouseMovedOrUp(int mouseX, int mouseY, int state) { + super.mouseMovedOrUp(mouseX, mouseY, state); + if (state == 0) { + draggingScrollbar = false; + } + } + + private boolean isMouseOverScrollbar(int mouseX, int mouseY) { + int scrollbarX = guiLeft + xSize + 30; + int scrollbarY = guiTop + 27; + int scrollbarHeight = ySize - 35; + return (mouseX >= scrollbarX && mouseX <= scrollbarX + 5 && + mouseY >= scrollbarY && mouseY <= scrollbarY + scrollbarHeight); + } } diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiEffectBar.java b/src/main/java/noppes/npcs/client/gui/util/GuiEffectBar.java new file mode 100644 index 000000000..262ff9d0a --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/util/GuiEffectBar.java @@ -0,0 +1,195 @@ +package noppes.npcs.client.gui.util; + +import java.util.ArrayList; +import java.util.List; +import noppes.npcs.client.ClientCacheHandler; +import noppes.npcs.client.renderer.ImageData; +import noppes.npcs.controllers.data.CustomEffect; +import noppes.npcs.controllers.data.PlayerEffect; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; +import org.lwjgl.opengl.GL11; + +public class GuiEffectBar extends GuiScreen { + public int x, y, width, height; + public int scrollY = 0; // Tracks vertical scrolling + public int entryHeight = 20; // Height for each effect slot + public List entries = new ArrayList<>(); + public FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer; + + public GuiEffectBar(int x, int y, int width, int height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + @Override + public void initGui() { + this.fontRenderer = Minecraft.getMinecraft().fontRenderer; + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + // Draw background of effect bar + drawRect(x, y, x + width, y + height, 0x90000000); + + int totalHeight = entries.size() * (entryHeight + 2); // +2 for padding + if (scrollY < 0) scrollY = 0; + if (scrollY > totalHeight - height) scrollY = Math.max(totalHeight - height, 0); + + // Enable scissoring for vertical clipping + GL11.glEnable(GL11.GL_SCISSOR_TEST); + Minecraft minecraft = Minecraft.getMinecraft(); + ScaledResolution sr = new ScaledResolution(minecraft, minecraft.displayWidth, minecraft.displayHeight); + int scaleFactor = sr.getScaleFactor(); + int scissorX = x * scaleFactor; + int scissorY = (sr.getScaledHeight() - (y + height)) * scaleFactor; + int scissorW = width * scaleFactor; + int scissorH = height * scaleFactor; + GL11.glScissor(scissorX, scissorY, scissorW, scissorH); + + int iconRenderSize = 16; + int padding = 1; + + int startIndex = scrollY / (entryHeight + padding); + int endIndex = Math.min(entries.size(), startIndex + height / (entryHeight + padding) + 1); + + List hoveredTooltip = null; + int tooltipX = 0, tooltipY = 0; + CustomEffect toolTipEffect = null; + + for (int i = startIndex; i < endIndex; i++) { + int drawY = y + (i - startIndex) * (entryHeight + padding) - (scrollY % (entryHeight + padding)); + EffectEntry entry = entries.get(i); + ImageData imageData = ClientCacheHandler.getImageData(entry.effect.getIcon()); + + if (imageData != null && imageData.imageLoaded()) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + imageData.bindTexture(); + int iconU = entry.effect.iconX; + int iconV = entry.effect.iconY; + int iconWidth = entry.effect.getWidth(); + int iconHeight = entry.effect.getHeight(); + int texWidth = imageData.getTotalWidth(); + + func_152125_a(x + 2, drawY + 2, iconU, iconV, iconWidth, iconHeight, iconRenderSize, iconRenderSize, texWidth, texWidth); + } + + // If mouse hovers over this effect, save tooltip info + if (mouseX >= x && mouseX < x + width && + mouseY >= drawY && mouseY < drawY + entryHeight) { + int seconds = entry.playerEffect.duration; + hoveredTooltip = new ArrayList<>(); + hoveredTooltip.add(entry.effect.getMenuName()); + hoveredTooltip.add("Time: " + seconds + "s"); + + tooltipX = mouseX; + tooltipY = mouseY; + toolTipEffect = entry.effect; + } + } + + // Disable scissoring for tooltip rendering + GL11.glDisable(GL11.GL_SCISSOR_TEST); + + // Draw vertical scrollbar + if (totalHeight > height) { + int scrollBarWidth = 4; + int scrollBarX = x + width - scrollBarWidth - 2 + 10 ; + drawRect(scrollBarX, y, scrollBarX + scrollBarWidth, y + height, 0xFF333333); + int thumbHeight = Math.max(20, height * height / totalHeight); + int thumbY = y + (scrollY * (height - thumbHeight)) / (totalHeight - height); + drawRect(scrollBarX, thumbY, scrollBarX + scrollBarWidth, thumbY + thumbHeight, 0xFFAAAAAA); + } + + super.drawScreen(mouseX, mouseY, partialTicks); + + // Draw tooltip after all icons + if (hoveredTooltip != null && fontRenderer != null && toolTipEffect != null) { + drawCustomHoveringText(hoveredTooltip, tooltipX, tooltipY, fontRenderer, toolTipEffect); + } + } + + /** + * Adjusted scrolling to move up and down instead of left and right. + */ + public void mouseScrolled(int delta) { + int totalHeight = entries.size() * entryHeight; + scrollY -= delta * 10; // Adjust scroll speed as needed. + if (scrollY < 0) scrollY = 0; + if (scrollY > totalHeight - height) scrollY = Math.max(totalHeight - height, 0); + } + + /** + * Custom tooltip with enlarged effect icon. + */ + public void drawCustomHoveringText(List textLines, int x, int y, FontRenderer font, CustomEffect hoveredEffect) { + if (textLines == null || textLines.isEmpty()) return; + + int maxWidth = 0; + for (String s : textLines) { + int lineWidth = font.getStringWidth(s); + if (lineWidth > maxWidth) { + maxWidth = lineWidth; + } + } + + int iconSize = 32; + + int tooltipHeight = 8 + iconSize + 8; // Reserve space for enlarged icon + if (textLines.size() > 1) { + tooltipHeight += 2 + (textLines.size() - 1) * 10; + } + + int screenWidth = Minecraft.getMinecraft().currentScreen.width; + int screenHeight = Minecraft.getMinecraft().currentScreen.height; + + int tooltipX = x + 12; + int tooltipY = y - 12; + if (tooltipX + maxWidth > screenWidth) { + tooltipX = x - 28 - maxWidth; + } + if (tooltipY + tooltipHeight + 6 > screenHeight) { + tooltipY = screenHeight - tooltipHeight - 6; + } + + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glPushMatrix(); + this.zLevel = 1000.0F; + + // Draw tooltip background + drawRect(tooltipX - 3, tooltipY - 4, tooltipX + maxWidth + 3, tooltipY + tooltipHeight, 0xF0100010); + + // Draw text + int textY = tooltipY; + for (String s : textLines) { + font.drawStringWithShadow(s, tooltipX, textY, 0xFFFFFF); + textY += 10; + } + + // Draw enlarged icon + ImageData imageData = ClientCacheHandler.getImageData(hoveredEffect.getIcon()); + if (imageData != null && imageData.imageLoaded()) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + imageData.bindTexture(); + func_152125_a(tooltipX + (maxWidth - iconSize) / 2, textY + 4, hoveredEffect.iconX, hoveredEffect.iconY, hoveredEffect.getWidth(), hoveredEffect.getHeight(), iconSize, iconSize, imageData.getTotalWidth(), imageData.getTotalWidth()); + } + + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glPopMatrix(); + GL11.glPopAttrib(); + } + + public static class EffectEntry { + public CustomEffect effect; + public PlayerEffect playerEffect; + public EffectEntry(CustomEffect effect, PlayerEffect playerEffect) { + this.effect = effect; + this.playerEffect = playerEffect; + } + } +} diff --git a/src/main/java/noppes/npcs/controllers/data/CustomEffect.java b/src/main/java/noppes/npcs/controllers/data/CustomEffect.java index 03520eee8..75591a8c5 100644 --- a/src/main/java/noppes/npcs/controllers/data/CustomEffect.java +++ b/src/main/java/noppes/npcs/controllers/data/CustomEffect.java @@ -22,7 +22,6 @@ public class CustomEffect implements ICustomEffect { public int everyXTick = 20; public String icon = ""; - // CustomNpcPlusDBC.ID + ":textures/gui/icons.png"; public int iconX = 0, iconY = 0; /** diff --git a/src/main/java/tconstruct/client/tabs/InventoryTabCustomNpc.java b/src/main/java/tconstruct/client/tabs/InventoryTabCustomNpc.java index 39f9f1761..9b845c5f5 100644 --- a/src/main/java/tconstruct/client/tabs/InventoryTabCustomNpc.java +++ b/src/main/java/tconstruct/client/tabs/InventoryTabCustomNpc.java @@ -52,7 +52,7 @@ public class InventoryTabCustomNpc extends AbstractTab { mc.displayGuiScreen(new GuiSettings()); } if(tab == -104){ - // Profile Tab + mc.displayGuiScreen(new GuiProfiles()); } } } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index b7723ab04..95a469c4f 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -1303,3 +1303,7 @@ effect.editor.xPos=X Pos effect.editor.yPos=Y Pos effect.editor.lossOnDeath=Loss on Death +profile.lastLoaded=Last Loaded +profile.info.quest.active=Quests Active +profile.info.quest.finished=Quests Finished +profile.info.dialog.read=Dialogs Read From d62b02410e19b307d14e21772c6cab032d16f8b8 Mon Sep 17 00:00:00 2001 From: Kam Date: Wed, 19 Feb 2025 16:27:27 -0500 Subject: [PATCH 11/59] Profile Operations + Packets for GUI Handling --- .../npcs/command/profile/CommandProfile.java | 3 +- .../command/profile/CommandProfileAdmin.java | 36 +++++ .../command/profile/CommandProfileCreate.java | 64 +++++++++ .../npcs/controllers/ProfileController.java | 125 ++++++++++++++---- .../controllers/data/ProfileOperation.java | 3 +- .../kamkeel/npcs/network/PacketHandler.java | 7 +- .../npcs/network/enums/EnumRequestPacket.java | 3 +- .../request/profile/ProfileChangePacket.java | 62 +++++++++ .../request/profile/ProfileCreatePacket.java | 57 ++++++++ .../request/profile/ProfileGetInfoPacket.java | 7 +- .../request/profile/ProfileGetPacket.java | 4 + .../request/profile/ProfileRemovePacket.java | 64 +++++++++ .../request/profile/ProfileRenamePacket.java | 77 +++++++++++ .../noppes/npcs/CustomNpcsPermissions.java | 8 ++ .../gui/player/inventory/GuiProfiles.java | 101 +++++++------- .../assets/customnpcs/lang/en_US.lang | 7 + 16 files changed, 542 insertions(+), 86 deletions(-) create mode 100644 src/main/java/kamkeel/npcs/command/profile/CommandProfileCreate.java create mode 100644 src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileChangePacket.java create mode 100644 src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java create mode 100644 src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java create mode 100644 src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfile.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfile.java index 70607f4f2..ed3133eaf 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfile.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfile.java @@ -23,6 +23,7 @@ public class CommandProfile extends CommandBase { public CommandProfile(){ registerCommand(help); registerCommand(new CommandProfileChange()); + registerCommand(new CommandProfileCreate()); registerCommand(new CommandProfileRemove()); registerCommand(new CommandProfileAdmin()); registerCommand(new CommandProfileList()); @@ -116,7 +117,7 @@ public class CommandProfile extends CommandBase { @Override public int getRequiredPermissionLevel(){ - return 0; + return 4; } public static String getCommandPermission(String command){ diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java index 255a48fac..c2c710a08 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java @@ -105,6 +105,7 @@ public class CommandProfileAdmin extends CommandProfileBase { } } + // Existing change subcommand update: @SubCommand( desc = "Change a specified player's active slot.", usage = " " @@ -144,6 +145,41 @@ public class CommandProfileAdmin extends CommandProfileBase { } } + // New admin create subcommand: + @SubCommand( + desc = "Create a new slot for a specified player's profile.", + usage = "" + ) + public void create(ICommandSender sender, String[] args) throws CommandException { + if(args.length < 1) { + sendError(sender, "Usage: /profile admin create "); + return; + } + String targetPlayer = args[0]; + Profile profile = ProfileController.getProfile(targetPlayer); + if(profile == null) { + sendError(sender, "Profile not found for player: " + targetPlayer); + return; + } + ProfileOperation result = ProfileController.createSlotInternal(profile); + switch(result) { + case NEW_SLOT_CREATED: + sendResult(sender, "New slot created successfully for %s.", targetPlayer); + break; + case MAX_SLOTS: + sendError(sender, "Player %s has reached maximum allowed slots.", targetPlayer); + break; + case LOCKED: + sendError(sender, "Profile for %s is locked. Please try again later.", targetPlayer); + break; + case VERIFICATION_FAILED: + sendError(sender, "Profile verification failed for %s.", targetPlayer); + break; + default: + sendError(sender, "Error creating new slot for %s.", targetPlayer); + } + } + @SubCommand( desc = "List all slots (IDs and names) for a specified player's profile.", usage = "" diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileCreate.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileCreate.java new file mode 100644 index 000000000..b8610f33c --- /dev/null +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileCreate.java @@ -0,0 +1,64 @@ +package kamkeel.npcs.command.profile; + +import kamkeel.npcs.controllers.ProfileController; +import kamkeel.npcs.controllers.data.Profile; +import kamkeel.npcs.controllers.data.ProfileOperation; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendResult; + +public class CommandProfileCreate extends CommandProfileBase { + + @Override + public String getCommandName() { + return "create"; + } + + @Override + public String getDescription() { + return "Create a new profile slot."; + } + + @Override + public String getUsage() { + return ""; + } + + @Override + public boolean runSubCommands() { + return false; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) throws CommandException { + if(!(sender instanceof EntityPlayer)) { + sendError(sender, "This command can only be used by a player."); + return; + } + EntityPlayer player = (EntityPlayer)sender; + Profile profile = ProfileController.getProfile(player); + if(profile == null) { + sendError(sender, "Profile not found."); + return; + } + ProfileOperation result = ProfileController.createSlotInternal(profile); + switch(result) { + case NEW_SLOT_CREATED: + sendResult(sender, "New profile slot created successfully."); + break; + case MAX_SLOTS: + sendError(sender, "You have reached the maximum allowed slots."); + break; + case LOCKED: + sendError(sender, "Profile is locked. Please try again later."); + break; + case VERIFICATION_FAILED: + sendError(sender, "Profile verification failed. Creation not permitted."); + break; + default: + sendError(sender, "Error occurred while creating a new profile slot."); + } + } +} diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index 71c2d9f5e..be8ce4912 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -1,12 +1,14 @@ package kamkeel.npcs.controllers; import kamkeel.npcs.controllers.data.*; +import kamkeel.npcs.network.packets.data.ChatAlertPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.MinecraftServer; import noppes.npcs.CustomNpcs; +import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.LogWriter; import noppes.npcs.config.ConfigMain; import noppes.npcs.controllers.data.PlayerData; @@ -357,52 +359,78 @@ public class ProfileController { return ProfileOperation.SUCCESS; } - // Change the active slot in a Profile. - // If the new slot doesn't exist, it is created and NEW_SLOT_CREATED is returned. - // Saves current slot data before switching. - private static ProfileOperation changeSlotInternal(Profile profile, int newSlotId) { - if(profile.locked) { - LogWriter.error("Profile is locked; cannot change slot."); + public static ProfileOperation createSlotInternal(Profile profile) { + if (profile.locked) { + LogWriter.error("Profile is locked; cannot create slot."); return ProfileOperation.LOCKED; } - // Disallow switching to the same active slot. - if(profile.currentID == newSlotId) { - LogWriter.error("Slot " + newSlotId + " is already active."); - return ProfileOperation.ALREADY_ACTIVE; + int newSlotId = 0; + while (profile.slots.containsKey(newSlotId)) { + newSlotId++; + } + + // Check if the player is allowed to create a new slot. + if (!allowSlotPermission(profile.player)) { + LogWriter.error("Player has reached maximum allowed slots."); + return ProfileOperation.MAX_SLOTS; } // Run verification checks from all IProfileData in order of priority. - if(profile.player != null) { + if (profile.player != null) { List dataList = new ArrayList<>(profileTypes.values()); dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority)); - for(IProfileData pd : dataList) { - if(!pd.verifySwitch(profile.player)) { + for (IProfileData pd : dataList) { + if (!pd.verifySwitch(profile.player)) { LogWriter.error("Verification check failed for profile type: " + pd.getTagName()); return ProfileOperation.VERIFICATION_FAILED; } } } - if(profile.player != null) { + // Create and add the new slot. + Slot newSlot = new Slot(newSlotId, "Slot " + newSlotId); + newSlot.setCompound(new NBTTagCompound()); + profile.slots.put(newSlotId, newSlot); + return ProfileOperation.NEW_SLOT_CREATED; + } + + // Change the active slot in a profile without automatically creating a new one. + // If the target slot does not exist, the operation fails. + private static ProfileOperation changeSlotInternal(Profile profile, int newSlotId) { + if (profile.locked) { + LogWriter.error("Profile is locked; cannot change slot."); + return ProfileOperation.LOCKED; + } + if (profile.currentID == newSlotId) { + LogWriter.error("Slot " + newSlotId + " is already active."); + return ProfileOperation.ALREADY_ACTIVE; + } + if (!profile.slots.containsKey(newSlotId)) { + LogWriter.error("Slot " + newSlotId + " does not exist."); + return ProfileOperation.ERROR; + } + // Run verification checks on all IProfileData in priority order. + if (profile.player != null) { + List dataList = new ArrayList<>(profileTypes.values()); + dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority)); + for (IProfileData pd : dataList) { + if (!pd.verifySwitch(profile.player)) { + LogWriter.error("Verification check failed for profile type: " + pd.getTagName()); + return ProfileOperation.VERIFICATION_FAILED; + } + } + } + if (profile.player != null) { saveSlotData(profile.player); } - boolean createdNewSlot = false; - // If the new slot doesn't exist, create it. - if(!profile.slots.containsKey(newSlotId)) { - Slot newSlot = new Slot(newSlotId, "Slot " + newSlotId); - newSlot.setCompound(new NBTTagCompound()); - profile.slots.put(newSlotId, newSlot); - createdNewSlot = true; - } profile.currentID = newSlotId; - if(profile.player != null) { + if (profile.player != null) { loadSlotData(profile.player); } - // Update PlayerData so that PlayerData.get(player).profileSlot matches Profile.currentID. - if(profile.player != null) { + if (profile.player != null) { PlayerData pdata = PlayerData.get(profile.player); pdata.profileSlot = newSlotId; pdata.save(); } - return createdNewSlot ? ProfileOperation.NEW_SLOT_CREATED : ProfileOperation.SUCCESS; + return ProfileOperation.SUCCESS; } // ---------- Public Operations (Overloaded for EntityPlayer, UUID, or username) ---------- @@ -607,6 +635,51 @@ public class ProfileController { } + public static boolean allowSlotPermission(EntityPlayer player) { + Profile profile = ProfileController.getProfile(player); + int currentSlots = profile.slots.size(); + + // Unlimited slots if the player has the wildcard permission. + if (CustomNpcsPermissions.hasCustomPermission(player, "customnpcs.profile.max.*")) { + return true; + } + + int highestAllowed = 0; + for (int i = 1; i <= 50; i++) { + String perm = "customnpcs.profile.max." + i; + if (CustomNpcsPermissions.hasCustomPermission(player, perm)) { + highestAllowed = i; + } + } + + if (highestAllowed == 0) { + highestAllowed = 1; + } + + return currentSlots < highestAllowed; + } + + public void sendChatAlert(ProfileOperation operation, EntityPlayerMP player){ + switch (operation){ + case SUCCESS: + ChatAlertPacket.sendChatAlert(player, "quest.newquest", ": ", ""); + break; + case ERROR: + break; + case LOCKED: + break; + case PLAYER_NOT_FOUND: + break; + case NEW_SLOT_CREATED: + break; + case ALREADY_ACTIVE: + break; + case VERIFICATION_FAILED: + break; + case MAX_SLOTS: + break; + } + } public static EntityPlayerMP getPlayer(String username){ return MinecraftServer.getServer().getConfigurationManager().func_152612_a(username); diff --git a/src/main/java/kamkeel/npcs/controllers/data/ProfileOperation.java b/src/main/java/kamkeel/npcs/controllers/data/ProfileOperation.java index 3e6e81b90..59dc7e2ef 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ProfileOperation.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ProfileOperation.java @@ -7,6 +7,7 @@ public enum ProfileOperation { PLAYER_NOT_FOUND, NEW_SLOT_CREATED, ALREADY_ACTIVE, - VERIFICATION_FAILED + VERIFICATION_FAILED, + MAX_SLOTS } diff --git a/src/main/java/kamkeel/npcs/network/PacketHandler.java b/src/main/java/kamkeel/npcs/network/PacketHandler.java index de5799d2b..91b24a22b 100644 --- a/src/main/java/kamkeel/npcs/network/PacketHandler.java +++ b/src/main/java/kamkeel/npcs/network/PacketHandler.java @@ -56,8 +56,7 @@ import kamkeel.npcs.network.packets.request.pather.MovingPathSavePacket; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetPacket; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataMapRegenPacket; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataRemovePacket; -import kamkeel.npcs.network.packets.request.profile.ProfileGetInfoPacket; -import kamkeel.npcs.network.packets.request.profile.ProfileGetPacket; +import kamkeel.npcs.network.packets.request.profile.*; import kamkeel.npcs.network.packets.request.quest.*; import kamkeel.npcs.network.packets.request.recipe.RecipeGetPacket; import kamkeel.npcs.network.packets.request.recipe.RecipeRemovePacket; @@ -328,6 +327,10 @@ public class PacketHandler { // Profile Packets REQUEST_PACKET.registerPacket(new ProfileGetPacket()); REQUEST_PACKET.registerPacket(new ProfileGetInfoPacket()); + REQUEST_PACKET.registerPacket(new ProfileCreatePacket()); + REQUEST_PACKET.registerPacket(new ProfileRenamePacket()); + REQUEST_PACKET.registerPacket(new ProfileRenamePacket()); + REQUEST_PACKET.registerPacket(new ProfileChangePacket()); // Other Packets REQUEST_PACKET.registerPacket(new IsGuiOpenInform()); diff --git a/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java b/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java index 49e0b57b5..febd0386b 100644 --- a/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java +++ b/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java @@ -185,5 +185,6 @@ public enum EnumRequestPacket { EffectSave, ColorSet, - ProfileGet, ProfileGetAll, ProfileGetInfo, ColorBrush + ColorBrush, + ProfileGet, ProfileGetAll, ProfileGetInfo, ProfileCreate, ProfileRemove, ProfileRename, ProfileChange, } diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileChangePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileChangePacket.java new file mode 100644 index 000000000..4b6579bd5 --- /dev/null +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileChangePacket.java @@ -0,0 +1,62 @@ +package kamkeel.npcs.network.packets.request.profile; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import io.netty.buffer.ByteBuf; +import kamkeel.npcs.controllers.ProfileController; +import kamkeel.npcs.controllers.data.ProfileOperation; +import kamkeel.npcs.network.AbstractPacket; +import kamkeel.npcs.network.PacketChannel; +import kamkeel.npcs.network.PacketHandler; +import kamkeel.npcs.network.enums.EnumRequestPacket; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import noppes.npcs.CustomNpcsPermissions; + +import java.io.IOException; + +public final class ProfileChangePacket extends AbstractPacket { + public static String packetName = "Request|ProfileChange"; + + private int slotID; + + public ProfileChangePacket() {} + + public ProfileChangePacket(int slotID) { + this.slotID = slotID; + } + + @Override + public Enum getType() { + return EnumRequestPacket.ProfileChange; + } + + @Override + public PacketChannel getChannel() { + return PacketHandler.REQUEST_PACKET; + } + + @Override + public CustomNpcsPermissions.Permission getPermission() { + return CustomNpcsPermissions.PROFILE_CHANGE; + } + + @SideOnly(Side.CLIENT) + @Override + public void sendData(ByteBuf out) throws IOException { + out.writeInt(this.slotID); + } + + @Override + public void receiveData(ByteBuf in, EntityPlayer player) throws IOException { + if (!(player instanceof EntityPlayerMP)) + return; + + int slot = in.readInt(); + ProfileOperation operation = ProfileController.changeSlot(player, slot); + // TODO: Check Operation and Send Message + + ProfileGetPacket.sendProfileNBT(player); + ProfileGetInfoPacket.sendProfileInfo(player); + } +} diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java new file mode 100644 index 000000000..102bb026d --- /dev/null +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java @@ -0,0 +1,57 @@ +package kamkeel.npcs.network.packets.request.profile; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import io.netty.buffer.ByteBuf; +import kamkeel.npcs.controllers.ProfileController; +import kamkeel.npcs.controllers.data.Profile; +import kamkeel.npcs.controllers.data.ProfileOperation; +import kamkeel.npcs.network.AbstractPacket; +import kamkeel.npcs.network.PacketChannel; +import kamkeel.npcs.network.PacketHandler; +import kamkeel.npcs.network.enums.EnumRequestPacket; +import kamkeel.npcs.network.packets.data.large.GuiDataPacket; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.CustomNpcsPermissions; + +import java.io.IOException; + +public final class ProfileCreatePacket extends AbstractPacket { + public static String packetName = "Request|ProfileCreate"; + + public ProfileCreatePacket() {} + + @Override + public Enum getType() { + return EnumRequestPacket.ProfileCreate; + } + + @Override + public PacketChannel getChannel() { + return PacketHandler.REQUEST_PACKET; + } + + @Override + public CustomNpcsPermissions.Permission getPermission() { + return CustomNpcsPermissions.PROFILE_CREATE; + } + + @SideOnly(Side.CLIENT) + @Override + public void sendData(ByteBuf out) throws IOException {} + + @Override + public void receiveData(ByteBuf in, EntityPlayer player) throws IOException { + if (!(player instanceof EntityPlayerMP)) + return; + + Profile profile = ProfileController.getProfile(player); + ProfileOperation operation = ProfileController.createSlotInternal(profile); + // TODO: Check Operation and Send Message + + ProfileGetPacket.sendProfileNBT(player); + ProfileGetInfoPacket.sendProfileInfo(player); + } +} diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java index 5d853db50..50ce09dd3 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java @@ -22,7 +22,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Map; public final class ProfileGetInfoPacket extends AbstractPacket { public static String packetName = "Request|ProfileGetInfo"; @@ -48,6 +47,10 @@ public final class ProfileGetInfoPacket extends AbstractPacket { if (!(player instanceof EntityPlayerMP)) return; + sendProfileInfo(player); + } + + public static void sendProfileInfo(EntityPlayer player){ NBTTagCompound compound = new NBTTagCompound(); compound.setBoolean("PROFILE_INFO", true); NBTTagList slotList = new NBTTagList(); @@ -69,7 +72,7 @@ public final class ProfileGetInfoPacket extends AbstractPacket { GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound); } - public static HashMap> readSlotsFromNBT(NBTTagCompound compound) { + public static HashMap> readProfileInfo(NBTTagCompound compound) { HashMap> slotInfoMap = new HashMap<>(); if (!compound.getBoolean("PROFILE_INFO")) return slotInfoMap; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java index feac5f37c..e86204acf 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java @@ -43,6 +43,10 @@ public final class ProfileGetPacket extends AbstractPacket { if (!(player instanceof EntityPlayerMP)) return; + sendProfileNBT(player); + } + + public static void sendProfileNBT(EntityPlayer player){ Profile profile = ProfileController.getProfile(player); NBTTagCompound compound = profile.writeToNBT(); compound.setBoolean("PROFILE", true); diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java new file mode 100644 index 000000000..ed98fae19 --- /dev/null +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java @@ -0,0 +1,64 @@ +package kamkeel.npcs.network.packets.request.profile; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import io.netty.buffer.ByteBuf; +import kamkeel.npcs.controllers.ProfileController; +import kamkeel.npcs.controllers.data.Profile; +import kamkeel.npcs.controllers.data.ProfileOperation; +import kamkeel.npcs.network.AbstractPacket; +import kamkeel.npcs.network.PacketChannel; +import kamkeel.npcs.network.PacketHandler; +import kamkeel.npcs.network.enums.EnumRequestPacket; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import noppes.npcs.CustomNpcsPermissions; + +import java.io.IOException; + +public final class ProfileRemovePacket extends AbstractPacket { + public static String packetName = "Request|ProfileRemove"; + + private int slotID; + + public ProfileRemovePacket() {} + + public ProfileRemovePacket(int slotID) { + this.slotID = slotID; + } + + @Override + public Enum getType() { + return EnumRequestPacket.ProfileRemove; + } + + @Override + public PacketChannel getChannel() { + return PacketHandler.REQUEST_PACKET; + } + + @Override + public CustomNpcsPermissions.Permission getPermission() { + return CustomNpcsPermissions.PROFILE_DELETE; + } + + @SideOnly(Side.CLIENT) + @Override + public void sendData(ByteBuf out) throws IOException { + out.writeInt(this.slotID); + } + + @Override + public void receiveData(ByteBuf in, EntityPlayer player) throws IOException { + if (!(player instanceof EntityPlayerMP)) + return; + + int slot = in.readInt(); + ProfileOperation operation = ProfileController.removeSlot(player, slot); + // TODO: Check Operation and Send Message + + + ProfileGetPacket.sendProfileNBT(player); + ProfileGetInfoPacket.sendProfileInfo(player); + } +} diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java new file mode 100644 index 000000000..c1496caf5 --- /dev/null +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java @@ -0,0 +1,77 @@ +package kamkeel.npcs.network.packets.request.profile; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import io.netty.buffer.ByteBuf; +import kamkeel.npcs.controllers.ProfileController; +import kamkeel.npcs.controllers.data.Profile; +import kamkeel.npcs.controllers.data.ProfileOperation; +import kamkeel.npcs.network.AbstractPacket; +import kamkeel.npcs.network.PacketChannel; +import kamkeel.npcs.network.PacketHandler; +import kamkeel.npcs.network.enums.EnumRequestPacket; +import kamkeel.npcs.util.ByteBufUtils; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import noppes.npcs.CustomNpcsPermissions; + +import java.io.IOException; + +import static kamkeel.npcs.util.ColorUtil.sendError; + +public final class ProfileRenamePacket extends AbstractPacket { + public static String packetName = "Request|ProfileRename"; + + private int slotID; + private String name; + + public ProfileRenamePacket() {} + + public ProfileRenamePacket(int slotID, String name) { + this.slotID = slotID; + this.name = name; + } + + @Override + public Enum getType() { + return EnumRequestPacket.ProfileRename; + } + + @Override + public PacketChannel getChannel() { + return PacketHandler.REQUEST_PACKET; + } + + @Override + public CustomNpcsPermissions.Permission getPermission() { + return CustomNpcsPermissions.PROFILE_RENAME; + } + + @SideOnly(Side.CLIENT) + @Override + public void sendData(ByteBuf out) throws IOException { + out.writeInt(this.slotID); + ByteBufUtils.writeString(out, this.name); + } + + @Override + public void receiveData(ByteBuf in, EntityPlayer player) throws IOException { + if (!(player instanceof EntityPlayerMP)) + return; + + int slot = in.readInt(); + String newName = ByteBufUtils.readString(in); + + Profile profile = ProfileController.getProfile(player); + if(!profile.slots.containsKey(slot)) { + // TODO: Check Operation and Send Message + return; + } + + ProfileController.getProfile(player).slots.get(slot).setName(newName); + ProfileController.save(player, ProfileController.getProfile(player)); + + ProfileGetPacket.sendProfileNBT(player); + ProfileGetInfoPacket.sendProfileInfo(player); + } +} diff --git a/src/main/java/noppes/npcs/CustomNpcsPermissions.java b/src/main/java/noppes/npcs/CustomNpcsPermissions.java index f494ddb9a..35aa84c0e 100644 --- a/src/main/java/noppes/npcs/CustomNpcsPermissions.java +++ b/src/main/java/noppes/npcs/CustomNpcsPermissions.java @@ -88,6 +88,14 @@ public class CustomNpcsPermissions{ public static final Permission SCRIPT_ITEM = new Permission("customnpcs.script.item"); public static final Permission SCRIPT_BLOCK = new Permission("customnpcs.script.block"); + // Profiles + public static final Permission PROFILE_ADMIN = new Permission("customnpcs.profile.admin"); + public static final Permission PROFILE_CREATE = new Permission("customnpcs.profile.create"); + public static final Permission PROFILE_DELETE = new Permission("customnpcs.profile.delete"); + public static final Permission PROFILE_RENAME = new Permission("customnpcs.profile.rename"); + public static final Permission PROFILE_CHANGE = new Permission("customnpcs.profile.change"); + public static final Permission PROFILE_MAX = new Permission("customnpcs.profile.max.*"); + public static CustomNpcsPermissions Instance; private Class bukkit; private Method getPlayer; diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java index 9c9f00140..d8219546e 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java @@ -4,11 +4,11 @@ import kamkeel.npcs.controllers.data.InfoEntry; import kamkeel.npcs.controllers.data.Profile; import kamkeel.npcs.controllers.data.Slot; import kamkeel.npcs.network.PacketClient; -import kamkeel.npcs.network.packets.request.linked.LinkedNPCAddPacket; -import kamkeel.npcs.network.packets.request.profile.ProfileGetInfoPacket; -import kamkeel.npcs.network.packets.request.profile.ProfileGetPacket; +import kamkeel.npcs.network.packets.request.linked.LinkedItemRemovePacket; +import kamkeel.npcs.network.packets.request.profile.*; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.nbt.NBTTagCompound; @@ -34,6 +34,7 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC private GuiCustomScroll scroll; public HashMap data = new HashMap<>(); private String selected = null; + private String rename; private Profile profile; private Slot slot; private HashMap> slotInfoMap = new HashMap<>(); @@ -85,6 +86,26 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC super.actionPerformed(guibutton); return; } + + if(guibutton.id == 4){ + GuiYesNo guiyesno = new GuiYesNo(this, StatCollector.translateToLocal("profile.create.message"), StatCollector.translateToLocal("gui.sure"), 104); + displayGuiScreen(guiyesno); + } + + if(this.slot == null) + return; + + if(guibutton.id == 1){ + GuiYesNo guiyesno = new GuiYesNo(this, slot.getName(), StatCollector.translateToLocal("profile.change.message"), 101); + displayGuiScreen(guiyesno); + } + if(guibutton.id == 2){ + setSubGui(new SubGuiEditText(slot.getName())); + } + if(guibutton.id == 3){ + GuiYesNo guiyesno = new GuiYesNo(this, slot.getName(), StatCollector.translateToLocal("gui.delete"), 103); + displayGuiScreen(guiyesno); + } } @Override @@ -261,68 +282,38 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC NoppesUtil.openGUI(player, this); if (!result) return; - if (id == 1) { - if (data.containsKey(scroll.getSelected())) { - - // DELETE PROFILE - // PacketClient.sendClient(new LinkedNPCRemovePacket(scroll.getSelected())); - - initGui(); - } + if (id == 104) { + // Create Slot + PacketClient.sendClient(new ProfileCreatePacket()); } - if(id == 1){ - if (data.containsKey(scroll.getSelected())) { + if(slot == null) + return; - // RENAME PROFILE - // PacketClient.sendClient(new LinkedItemRemovePacket(data.get(scroll.getSelected()))); - - initGui(); - } + if(id == 101){ + // Change Slot + PacketClient.sendClient(new ProfileChangePacket(slot.getId())); } - if(id == 1){ - // CREATE PROFILE - // PacketClient.sendClient(new LinkedItemRemovePacket(data.get(scroll.getSelected()))); - - initGui(); + if(id == 102 && rename != null && !rename.equalsIgnoreCase(slot.getName())){ + // Rename Slot + PacketClient.sendClient(new ProfileRenamePacket(slot.getId(), rename)); } - if(id == 1){ - // CHANGE PROFILE - // PacketClient.sendClient(new LinkedItemRemovePacket(data.get(scroll.getSelected()))); - - initGui(); + if(id == 103){ + // Delete Slot + PacketClient.sendClient(new ProfileRemovePacket(slot.getId())); } } - public int getStringWidthWithoutColor(String text) { - int width = 0; - for (int i = 0; i < text.length(); i++) { - char c = text.charAt(i); - - if (c == '§') { - if (i < text.length() - 1) { - i += 1; - } - } else { - // If not a color code, calculate the width - width += Minecraft.getMinecraft().fontRenderer.getCharWidth(c); - } - } - return width; - } - @Override public void subGuiClosed(SubGuiInterface subgui) { if(subgui instanceof SubGuiEditText){ if(!((SubGuiEditText)subgui).cancelled){ - PacketClient.sendClient(new LinkedNPCAddPacket(((SubGuiEditText)subgui).text)); + rename = ((SubGuiEditText)subgui).text; + GuiYesNo guiyesno = new GuiYesNo(this, rename, StatCollector.translateToLocal("profile.rename.message"), 102); + displayGuiScreen(guiyesno); } } } - public boolean isMouseOverRenderer(int x, int y) { - return x >= guiLeft + 10 && x <= guiLeft + 10 + 200 && y >= guiTop + 6 && y <= guiTop + 6 + 204; - } - @Override public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { if (guiCustomScroll.id == 0) { @@ -343,19 +334,23 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {} public void setGuiData(NBTTagCompound compound) { + this.slot = null; if(compound.hasKey("PROFILE")){ // Load Profile this.profile = new Profile(mc.thePlayer, compound); this.data = new HashMap<>(); - String colorCode = "\u00A7e"; + String currentSlot = "\u00A7e"; + String otherSlot = "\u00A7f"; for(Slot slot1 : profile.slots.values()){ String name = slot1.getId() + " - " + slot1.getName(); if(profile.currentID == slot1.getId()) - name = colorCode + name; + name = currentSlot + name; + else + name = otherSlot + name; this.data.put(name, slot1.getId()); } } else if(compound.hasKey("PROFILE_INFO")){ - slotInfoMap = ProfileGetInfoPacket.readSlotsFromNBT(compound); + slotInfoMap = ProfileGetInfoPacket.readProfileInfo(compound); } initGui(); } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 95a469c4f..2e827cb94 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -148,6 +148,9 @@ gui.sure=Are you sure? gui.available=Requirements Met gui.items=Items gui.npcs=NPCs +gui.change=Change +gui.create=Create +gui.rename=Rename party.accept=Accept party.allowParty=Allow Partying @@ -1307,3 +1310,7 @@ profile.lastLoaded=Last Loaded profile.info.quest.active=Quests Active profile.info.quest.finished=Quests Finished profile.info.dialog.read=Dialogs Read +profile.change.message=Do you want to change? +profile.create.message=Creating a new profile will change you to it. +profile.rename.message=Do you want to rename your slot? +profile.operation.error=There was an error in your request From 3ce72039788c583ca8548f63d9fd8a841e00f230 Mon Sep 17 00:00:00 2001 From: Kam Date: Wed, 19 Feb 2025 16:31:36 -0500 Subject: [PATCH 12/59] Fixes --- .../npcs/client/gui/player/inventory/GuiProfiles.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java index d8219546e..7ec782a8c 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java @@ -68,7 +68,7 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC this.addButton(new GuiNpcButton(4,guiLeft + 4, y, 60, 20, "gui.create")); if(scroll == null){ - scroll = new GuiCustomScroll(this,0,0); + scroll = new GuiCustomScroll(this,0); scroll.setSize(123, 141); } scroll.guiLeft = guiLeft + 4; @@ -269,6 +269,7 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC @Override public void keyTyped(char c, int i) { + super.keyTyped(c, i); if (i == 1 || (!hasSubGui() && isInventoryKey(i))) { close(); @@ -352,6 +353,9 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC } else if(compound.hasKey("PROFILE_INFO")){ slotInfoMap = ProfileGetInfoPacket.readProfileInfo(compound); } + if(scroll != null){ + scroll.setSelected(""); + } initGui(); } From db330d00383924e8dbf0e2eb06699cdcab453a6b Mon Sep 17 00:00:00 2001 From: Kam Date: Wed, 19 Feb 2025 17:14:11 -0500 Subject: [PATCH 13/59] Remap Keybind to N by Default, L is used by DBC --- build.gradle | 2 +- src/main/java/kamkeel/npcs/network/PacketHandler.java | 2 +- src/main/java/noppes/npcs/client/ClientProxy.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 97f204521..2d866a64f 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id 'idea' } -version = "1.9.4-beta3.3" +version = "1.9.4-beta3.5" group= "kamkeel.customnpc-plus" archivesBaseName = "CustomNPC-Plus" diff --git a/src/main/java/kamkeel/npcs/network/PacketHandler.java b/src/main/java/kamkeel/npcs/network/PacketHandler.java index 91b24a22b..8b115635c 100644 --- a/src/main/java/kamkeel/npcs/network/PacketHandler.java +++ b/src/main/java/kamkeel/npcs/network/PacketHandler.java @@ -328,7 +328,7 @@ public class PacketHandler { REQUEST_PACKET.registerPacket(new ProfileGetPacket()); REQUEST_PACKET.registerPacket(new ProfileGetInfoPacket()); REQUEST_PACKET.registerPacket(new ProfileCreatePacket()); - REQUEST_PACKET.registerPacket(new ProfileRenamePacket()); + REQUEST_PACKET.registerPacket(new ProfileRemovePacket()); REQUEST_PACKET.registerPacket(new ProfileRenamePacket()); REQUEST_PACKET.registerPacket(new ProfileChangePacket()); diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index 1e8b73d6b..75e0a3e12 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -146,7 +146,7 @@ public class ClientProxy extends CommonProxy { } Minecraft mc = Minecraft.getMinecraft(); - NPCButton = new KeyBinding("NPC Inventory", Keyboard.KEY_L, "key.categories.customnpc"); + NPCButton = new KeyBinding("NPC Inventory", Keyboard.KEY_N, "key.categories.customnpc"); ClientRegistry.registerKeyBinding(NPCButton); mc.gameSettings.loadOptions(); From cf6e6dd65545008c8444c204b2355b2bed12add6 Mon Sep 17 00:00:00 2001 From: Kam Date: Wed, 19 Feb 2025 18:15:05 -0500 Subject: [PATCH 14/59] Implement Profile Regions --- .../command/profile/CommandHelpProfile.java | 124 ++++++----- .../npcs/command/profile/CommandProfile.java | 1 + .../command/profile/CommandProfileAdmin.java | 108 ++++----- .../command/profile/CommandProfileChange.java | 30 +-- .../command/profile/CommandProfileCreate.java | 33 +-- .../command/profile/CommandProfileRegion.java | 160 ++++++++++++++ .../command/profile/CommandProfileRemove.java | 24 +- .../npcs/controllers/ProfileController.java | 207 ++++++++++-------- .../npcs/controllers/data/CNPCData.java | 9 +- .../data/EnumProfileOperation.java | 7 + .../npcs/controllers/data/IProfileData.java | 2 +- .../controllers/data/ProfileOperation.java | 38 +++- .../noppes/npcs/CustomNpcsPermissions.java | 1 + .../java/noppes/npcs/config/ConfigMain.java | 25 +++ 14 files changed, 486 insertions(+), 283 deletions(-) create mode 100644 src/main/java/kamkeel/npcs/command/profile/CommandProfileRegion.java create mode 100644 src/main/java/kamkeel/npcs/controllers/data/EnumProfileOperation.java diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandHelpProfile.java b/src/main/java/kamkeel/npcs/command/profile/CommandHelpProfile.java index effecd494..987f4a1b2 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandHelpProfile.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandHelpProfile.java @@ -2,72 +2,90 @@ package kamkeel.npcs.command.profile; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ChatComponentTranslation; - import java.lang.reflect.Method; import java.util.Map.Entry; - import static kamkeel.npcs.util.ColorUtil.sendError; import static kamkeel.npcs.util.ColorUtil.sendMessage; +import noppes.npcs.CustomNpcsPermissions; public class CommandHelpProfile extends CommandProfileBase { - private CommandProfile parent; + private CommandProfile parent; - public CommandHelpProfile(CommandProfile parent){ - this.parent = parent; - } + public CommandHelpProfile(CommandProfile parent){ + this.parent = parent; + } - @Override - public String getCommandName() { - return "help"; - } + @Override + public String getCommandName() { + return "help"; + } - @Override - public String getDescription() { - return "help [command]"; - } + @Override + public String getDescription() { + return "help [command]"; + } - - @Override - public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if(args.length == 0){ - sendMessage(sender, "\u00A78------ \u00A7aProfile Commands \u00A78------"); - for(Entry entry : parent.map.entrySet()){ - sendMessage(sender, "\u00A77> " + "\u00A7e" + entry.getKey() + "\u00A78: \u00A77" + entry.getValue().getCommandUsage(sender)); - } - return; - } + @Override + public void processCommand(ICommandSender sender, String[] args) throws CommandException { + if(args.length == 0){ + sendMessage(sender, "\u00A78------ \u00A7aProfile Commands \u00A78------"); + for(Entry entry : parent.map.entrySet()){ + sendMessage(sender, "\u00A77> " + "\u00A7e" + entry.getKey() + "\u00A78: \u00A77" + + entry.getValue().getCommandUsage(sender)); + } + return; + } CommandProfileBase command = parent.getCommand(args); - if(command == null){ - sendError(sender, "Unknown command " + args[0]); - return; - } + if(command == null){ + sendError(sender, "Unknown command " + args[0]); + return; + } - if(command.subcommands.isEmpty()){ - sender.addChatMessage(new ChatComponentTranslation(command.getCommandUsage(sender))); - return; - } + if(command.subcommands.isEmpty()){ + sender.addChatMessage(new ChatComponentTranslation(command.getCommandUsage(sender))); + return; + } - Method m = null; - if(args.length > 1){ - m = command.subcommands.get(args[1].toLowerCase()); - } - if(m == null){ - sendMessage(sender, "\u00A78------ \u00A7a" + command.getCommandName().toUpperCase() + " SubCommands \u00A78------"); - sendMessage(sender, "\u00A77Usage: \u00A76" + command.getUsage()); - for(Entry entry : command.subcommands.entrySet()){ - sender.addChatMessage(new ChatComponentTranslation("\u00A77> " + "\u00A7e" + entry.getKey() + "\u00A78: \u00A77" + entry.getValue().getAnnotation(SubCommand.class).desc())); - } - sender.addChatMessage(new ChatComponentTranslation("\u00A78Permission:\u00A77 " + CommandProfile.getCommandPermission(command.getCommandName()))); - } - else{ - sendMessage(sender, "\u00A78------ \u00A7b" + command.getCommandName().toUpperCase() + "." + args[1].toUpperCase() + " Command \u00A78------"); - SubCommand sc = m.getAnnotation(SubCommand.class); - sender.addChatMessage(new ChatComponentTranslation("\u00A77" + sc.desc())); - if(!sc.usage().isEmpty()) - sender.addChatMessage(new ChatComponentTranslation("\u00A77Usage: \u00A76" + sc.usage())); - sender.addChatMessage(new ChatComponentTranslation("\u00A78Permission:\u00A77 " + getSubCommandPermission(args[1]))); - } - } + Method m = null; + if(args.length > 1){ + m = command.subcommands.get(args[1].toLowerCase()); + } + if(m == null){ + sendMessage(sender, "\u00A78------ \u00A7a" + command.getCommandName().toUpperCase() + + " SubCommands \u00A78------"); + sendMessage(sender, "\u00A77Usage: \u00A76" + command.getUsage()); + for(Entry entry : command.subcommands.entrySet()){ + SubCommand sc = entry.getValue().getAnnotation(SubCommand.class); + // For players, only list subcommands if they have permission; for console, show all. + if(!(sender instanceof EntityPlayer) || command.canSendCommand(sender, sc, entry.getKey())){ + sender.addChatMessage(new ChatComponentTranslation("\u00A77> " + + "\u00A7e" + entry.getKey() + + "\u00A78: \u00A77" + sc.desc())); + } + } + // Show permission node only if sender is console or has permission. + if(!(sender instanceof EntityPlayer) || + CustomNpcsPermissions.hasPermission((EntityPlayer)sender, CustomNpcsPermissions.PROFILE_ADMIN)){ + sender.addChatMessage(new ChatComponentTranslation("\u00A78Permission:\u00A77 " + + CommandProfile.getCommandPermission(command.getCommandName()))); + } + } + else{ + sendMessage(sender, "\u00A78------ \u00A7b" + command.getCommandName().toUpperCase() + + "." + args[1].toUpperCase() + " Command \u00A78------"); + SubCommand sc = m.getAnnotation(SubCommand.class); + sender.addChatMessage(new ChatComponentTranslation("\u00A77" + sc.desc())); + if(!sc.usage().isEmpty()){ + sender.addChatMessage(new ChatComponentTranslation("\u00A77Usage: \u00A76" + sc.usage())); + } + if(!(sender instanceof EntityPlayer) || + CustomNpcsPermissions.hasPermission((EntityPlayer)sender, CustomNpcsPermissions.PROFILE_ADMIN)){ + sender.addChatMessage(new ChatComponentTranslation("\u00A78Permission:\u00A77 " + + getSubCommandPermission(args[1]))); + } + } + } } diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfile.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfile.java index ed3133eaf..4987f1bbf 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfile.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfile.java @@ -26,6 +26,7 @@ public class CommandProfile extends CommandBase { registerCommand(new CommandProfileCreate()); registerCommand(new CommandProfileRemove()); registerCommand(new CommandProfileAdmin()); + registerCommand(new CommandProfileRegion()); registerCommand(new CommandProfileList()); registerCommand(new CommandProfileRename()); } diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java index c2c710a08..44acdcfbd 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java @@ -3,11 +3,11 @@ package kamkeel.npcs.command.profile; import kamkeel.npcs.controllers.ProfileController; import kamkeel.npcs.controllers.data.Profile; import kamkeel.npcs.controllers.data.ProfileOperation; +import kamkeel.npcs.controllers.data.EnumProfileOperation; import kamkeel.npcs.controllers.data.Slot; import noppes.npcs.LogWriter; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; - import java.io.File; import java.util.Map; import java.util.UUID; @@ -51,26 +51,15 @@ public class CommandProfileAdmin extends CommandProfileBase { } boolean temporary = (args.length >= 5 && args[4].equalsIgnoreCase("temp")); ProfileOperation result = ProfileController.cloneSlot(sourcePlayer, sourceSlot, destinationSlot, temporary); - switch(result) { - case SUCCESS: - sendResult(sender, "Successfully cloned slot %d from %s to slot %d for %s.", sourceSlot, sourcePlayer, destinationSlot, destinationPlayer); - break; - case NEW_SLOT_CREATED: - sendResult(sender, "Successfully cloned slot %d from %s to NEW slot %d for %s.", sourceSlot, sourcePlayer, destinationSlot, destinationPlayer); - break; - case LOCKED: - sendError(sender, "Profile is locked. Please try again later."); - break; - case VERIFICATION_FAILED: - sendError(sender, "Profile verification failed. Change not permitted."); - break; - case PLAYER_NOT_FOUND: - sendError(sender, "Player profile not found."); - break; - case ERROR: - default: - sendError(sender, "Error cloning slot."); - break; + if(result.getResult() == EnumProfileOperation.SUCCESS) { + sendResult(sender, "Successfully cloned slot %d from %s to slot %d for %s.", sourceSlot, sourcePlayer, destinationSlot, destinationPlayer); + } else if(result.getResult() == EnumProfileOperation.LOCKED) { + // Detail message for admins – note: using result.getMessage() for further details. + sendError(sender, "Clone failed for %s: Profile is locked. Details: %s", sourcePlayer, result.getMessage()); + } else if(result.getResult() == EnumProfileOperation.ERROR) { + sendError(sender, "Error cloning slot for %s: %s", sourcePlayer, result.getMessage()); + } else { + sendError(sender, "Unexpected error cloning slot: %s", result.getMessage()); } } @@ -92,20 +81,17 @@ public class CommandProfileAdmin extends CommandProfileBase { return; } ProfileOperation result = ProfileController.removeSlot(targetPlayer, slotId); - switch(result) { - case SUCCESS: - sendResult(sender, "Successfully removed slot %d from %s.", slotId, targetPlayer); - break; - case LOCKED: - sendError(sender, "Profile for %s is locked. Please try again later.", targetPlayer); - break; - default: - sendError(sender, "Error removing slot %d from %s.", slotId, targetPlayer); - break; + if(result.getResult() == EnumProfileOperation.SUCCESS) { + sendResult(sender, "Successfully removed slot %d from %s.", slotId, targetPlayer); + } else if(result.getResult() == EnumProfileOperation.LOCKED) { + sendError(sender, "Remove failed for %s: Profile is locked. Details: %s", targetPlayer, result.getMessage()); + } else if(result.getResult() == EnumProfileOperation.ERROR) { + sendError(sender, "Error removing slot %d from %s: %s", slotId, targetPlayer, result.getMessage()); + } else { + sendError(sender, "Unexpected error during removal: %s", result.getMessage()); } } - // Existing change subcommand update: @SubCommand( desc = "Change a specified player's active slot.", usage = " " @@ -124,28 +110,17 @@ public class CommandProfileAdmin extends CommandProfileBase { return; } ProfileOperation result = ProfileController.changeSlot(targetPlayer, newSlotId); - switch(result) { - case SUCCESS: - sendResult(sender, "Successfully changed %s's active slot to %d.", targetPlayer, newSlotId); - break; - case NEW_SLOT_CREATED: - sendResult(sender, "Switched %s to NEW slot %d (new profile created).", targetPlayer, newSlotId); - break; - case ALREADY_ACTIVE: - sendError(sender, "Slot %d is already active for %s.", newSlotId, targetPlayer); - break; - case LOCKED: - sendError(sender, "Profile for %s is locked. Please try again later.", targetPlayer); - break; - case VERIFICATION_FAILED: - sendError(sender, "Profile verification failed for %s.", targetPlayer); - break; - default: - sendError(sender, "Error changing active slot for %s.", targetPlayer); + if(result.getResult() == EnumProfileOperation.SUCCESS) { + sendResult(sender, "Successfully changed %s's active slot to %d.", targetPlayer, newSlotId); + } else if(result.getResult() == EnumProfileOperation.LOCKED) { + sendError(sender, "Change failed for %s: Profile is locked. Details: %s", targetPlayer, result.getMessage()); + } else if(result.getResult() == EnumProfileOperation.ERROR) { + sendError(sender, "Error changing active slot for %s: %s", targetPlayer, result.getMessage()); + } else { + sendError(sender, "Unexpected error during change: %s", result.getMessage()); } } - // New admin create subcommand: @SubCommand( desc = "Create a new slot for a specified player's profile.", usage = "" @@ -158,25 +133,18 @@ public class CommandProfileAdmin extends CommandProfileBase { String targetPlayer = args[0]; Profile profile = ProfileController.getProfile(targetPlayer); if(profile == null) { - sendError(sender, "Profile not found for player: " + targetPlayer); + sendError(sender, "Profile not found for player: %s", targetPlayer); return; } ProfileOperation result = ProfileController.createSlotInternal(profile); - switch(result) { - case NEW_SLOT_CREATED: - sendResult(sender, "New slot created successfully for %s.", targetPlayer); - break; - case MAX_SLOTS: - sendError(sender, "Player %s has reached maximum allowed slots.", targetPlayer); - break; - case LOCKED: - sendError(sender, "Profile for %s is locked. Please try again later.", targetPlayer); - break; - case VERIFICATION_FAILED: - sendError(sender, "Profile verification failed for %s.", targetPlayer); - break; - default: - sendError(sender, "Error creating new slot for %s.", targetPlayer); + if(result.getResult() == EnumProfileOperation.SUCCESS) { + sendResult(sender, "New slot created successfully for %s.", targetPlayer); + } else if(result.getResult() == EnumProfileOperation.LOCKED) { + sendError(sender, "Create failed for %s: Profile is locked. Details: %s", targetPlayer, result.getMessage()); + } else if(result.getResult() == EnumProfileOperation.ERROR) { + sendError(sender, "Error creating new slot for %s: %s", targetPlayer, result.getMessage()); + } else { + sendError(sender, "Unexpected error during slot creation: %s", result.getMessage()); } } @@ -192,7 +160,7 @@ public class CommandProfileAdmin extends CommandProfileBase { String targetPlayer = args[0]; Profile profile = ProfileController.getProfile(targetPlayer); if(profile == null) { - sendError(sender, "Profile not found for player: " + targetPlayer); + sendError(sender, "Profile not found for player: %s", targetPlayer); return; } sendMessage(sender, "Profile Slots for %s:", targetPlayer); @@ -236,7 +204,7 @@ public class CommandProfileAdmin extends CommandProfileBase { } Profile profile = ProfileController.getProfile(targetPlayer); if(profile == null) { - sendError(sender, "Profile not found for player: " + targetPlayer); + sendError(sender, "Profile not found for player: %s", targetPlayer); return; } if(profile.locked) { @@ -268,7 +236,7 @@ public class CommandProfileAdmin extends CommandProfileBase { return; } String targetPlayer = args[0]; - String backupFileName = args[1] += ".dat"; + String backupFileName = args[1] + ".dat"; File backupDir = new File(ProfileController.getBackupDir(), ProfileController.getProfile(targetPlayer).player.getUniqueID().toString()); File backupFile = new File(backupDir, backupFileName); if(!backupFile.exists()){ diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java index 8f8c46fbc..c0a0c9706 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java @@ -2,11 +2,11 @@ package kamkeel.npcs.command.profile; import kamkeel.npcs.controllers.ProfileController; import kamkeel.npcs.controllers.data.ProfileOperation; +import kamkeel.npcs.controllers.data.EnumProfileOperation; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; -import static kamkeel.npcs.util.ColorUtil.sendError; -import static kamkeel.npcs.util.ColorUtil.sendResult; +import static kamkeel.npcs.util.ColorUtil.*; public class CommandProfileChange extends CommandProfileBase { @@ -49,24 +49,14 @@ public class CommandProfileChange extends CommandProfileBase { } EntityPlayer player = (EntityPlayer)sender; ProfileOperation result = ProfileController.changeSlot(player, slotId); - switch(result) { - case SUCCESS: - sendResult(sender, "Successfully changed profile slot to %d.", slotId); - break; - case NEW_SLOT_CREATED: - sendResult(sender, "Switched to new slot %d (new profile created).", slotId); - break; - case ALREADY_ACTIVE: - sendError(sender, "Slot %d is already active.", slotId); - break; - case LOCKED: - sendError(sender, "Profile is locked. Please try again later."); - break; - case VERIFICATION_FAILED: - sendError(sender, "Profile verification failed. Change not permitted."); - break; - default: - sendError(sender, "Error occurred while changing your profile slot."); + if(result.getResult() == EnumProfileOperation.SUCCESS) { + sendResult(sender, "Successfully changed profile slot to %d.", slotId); + } else if(result.getResult() == EnumProfileOperation.LOCKED) { + sendError(sender, "Profile is locked. Details: %s", result.getMessage()); + } else if(result.getResult() == EnumProfileOperation.ERROR) { + sendError(sender, "Error changing your profile slot: %s", result.getMessage()); + } else { + sendError(sender, "Unexpected error: %s", result.getMessage()); } } } diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileCreate.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileCreate.java index b8610f33c..1ca777382 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileCreate.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileCreate.java @@ -1,13 +1,12 @@ package kamkeel.npcs.command.profile; import kamkeel.npcs.controllers.ProfileController; -import kamkeel.npcs.controllers.data.Profile; import kamkeel.npcs.controllers.data.ProfileOperation; +import kamkeel.npcs.controllers.data.EnumProfileOperation; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; -import static kamkeel.npcs.util.ColorUtil.sendError; -import static kamkeel.npcs.util.ColorUtil.sendResult; +import static kamkeel.npcs.util.ColorUtil.*; public class CommandProfileCreate extends CommandProfileBase { @@ -38,27 +37,19 @@ public class CommandProfileCreate extends CommandProfileBase { return; } EntityPlayer player = (EntityPlayer)sender; - Profile profile = ProfileController.getProfile(player); - if(profile == null) { + if(ProfileController.getProfile(player) == null) { sendError(sender, "Profile not found."); return; } - ProfileOperation result = ProfileController.createSlotInternal(profile); - switch(result) { - case NEW_SLOT_CREATED: - sendResult(sender, "New profile slot created successfully."); - break; - case MAX_SLOTS: - sendError(sender, "You have reached the maximum allowed slots."); - break; - case LOCKED: - sendError(sender, "Profile is locked. Please try again later."); - break; - case VERIFICATION_FAILED: - sendError(sender, "Profile verification failed. Creation not permitted."); - break; - default: - sendError(sender, "Error occurred while creating a new profile slot."); + ProfileOperation result = ProfileController.createSlotInternal(ProfileController.getProfile(player)); + if(result.getResult() == EnumProfileOperation.SUCCESS) { + sendResult(sender, "New profile slot created successfully."); + } else if(result.getResult() == EnumProfileOperation.LOCKED) { + sendError(sender, "Profile is locked. Details: %s", result.getMessage()); + } else if(result.getResult() == EnumProfileOperation.ERROR) { + sendError(sender, "Error creating new profile slot: %s", result.getMessage()); + } else { + sendError(sender, "Unexpected error: %s", result.getMessage()); } } } diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRegion.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRegion.java new file mode 100644 index 000000000..91071f132 --- /dev/null +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRegion.java @@ -0,0 +1,160 @@ +package kamkeel.npcs.command.profile; + +import noppes.npcs.config.ConfigMain; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommandSender; +import java.util.ArrayList; +import java.util.List; + +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendMessage; +import static kamkeel.npcs.util.ColorUtil.sendResult; + +public class CommandProfileRegion extends CommandProfileBase { + + @Override + public String getCommandName() { + return "region"; + } + + @Override + public String getDescription() { + return "Manage profile region switching and restricted regions"; + } + + @Override + public String getUsage() { + return ""; + } + + @SubCommand( + desc = "Enable region-based profile switching", + usage = "" + ) + public void enable(ICommandSender sender, String[] args) throws CommandException { + ConfigMain.RegionProfileSwitching = true; + ConfigMain.RegionProfileSwitchingProperty.set(true); + if(ConfigMain.config.hasChanged()){ + ConfigMain.config.save(); + } + sendResult(sender, "Profile region switching enabled."); + } + + @SubCommand( + desc = "Disable region-based profile switching", + usage = "" + ) + public void disable(ICommandSender sender, String[] args) throws CommandException { + ConfigMain.RegionProfileSwitching = false; + ConfigMain.RegionProfileSwitchingProperty.set(false); + if(ConfigMain.config.hasChanged()){ + ConfigMain.config.save(); + } + sendResult(sender, "Profile region switching disabled."); + } + + @SubCommand( + desc = "Add a new region. Format: DIM, X1, Y1, Z1, X2, Y2, Z2", + usage = " " + ) + public void add(ICommandSender sender, String[] args) throws CommandException { + if(args.length < 1){ + sendError(sender, "Usage: /profile region add "); + return; + } + // Combine args in case the region data was split by spaces + String regionStr = String.join(" ", args).trim(); + String[] parts = regionStr.split(","); + if(parts.length != 7){ + sendError(sender, "Invalid region format. Must contain 7 integers separated by commas."); + return; + } + List regionList = new ArrayList<>(); + try { + for(String part : parts){ + regionList.add(Integer.parseInt(part.trim())); + } + } catch(NumberFormatException e){ + sendError(sender, "Invalid number format in region data."); + return; + } + ConfigMain.RestrictedProfileRegions.add(regionList); + // Update config property value + List regionStrings = new ArrayList<>(); + for(List region : ConfigMain.RestrictedProfileRegions) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < region.size(); i++) { + if(i > 0) sb.append(", "); + sb.append(region.get(i)); + } + regionStrings.add(sb.toString()); + } + ConfigMain.RestrictedProfileRegionsProperty.set(regionStrings.toArray(new String[0])); + if(ConfigMain.config.hasChanged()){ + ConfigMain.config.save(); + } + sendResult(sender, "Region added successfully."); + } + + @SubCommand( + desc = "Remove a region by its index (1-based).", + usage = "" + ) + public void remove(ICommandSender sender, String[] args) throws CommandException { + if(args.length < 1){ + sendError(sender, "Usage: /profile region remove "); + return; + } + int index; + try { + index = Integer.parseInt(args[0]); + } catch(NumberFormatException e){ + sendError(sender, "Index must be a number."); + return; + } + index = index - 1; // Convert to 0-based index + if(index < 0 || index >= ConfigMain.RestrictedProfileRegions.size()){ + sendError(sender, "Invalid index. Must be between 1 and " + ConfigMain.RestrictedProfileRegions.size()); + return; + } + ConfigMain.RestrictedProfileRegions.remove(index); + // Update config property value + List regionStrings = new ArrayList<>(); + for(List region : ConfigMain.RestrictedProfileRegions) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < region.size(); i++) { + if(i > 0) sb.append(", "); + sb.append(region.get(i)); + } + regionStrings.add(sb.toString()); + } + ConfigMain.RestrictedProfileRegionsProperty.set(regionStrings.toArray(new String[0])); + if(ConfigMain.config.hasChanged()){ + ConfigMain.config.save(); + } + sendResult(sender, "Region removed successfully."); + } + + @SubCommand( + desc = "List all restricted profile regions.", + usage = "" + ) + public void list(ICommandSender sender, String[] args) throws CommandException { + if(ConfigMain.RestrictedProfileRegions.isEmpty()){ + sendMessage(sender, "No restricted profile regions configured."); + return; + } + sendMessage(sender, "Restricted Profile Regions:"); + int i = 1; + for(List region : ConfigMain.RestrictedProfileRegions) { + StringBuilder sb = new StringBuilder(); + sb.append(i).append(": "); + for (int j = 0; j < region.size(); j++) { + if(j > 0) sb.append(", "); + sb.append(region.get(j)); + } + sendMessage(sender, sb.toString()); + i++; + } + } +} diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java index 81d7e6a4b..b5cc04556 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java @@ -2,11 +2,11 @@ package kamkeel.npcs.command.profile; import kamkeel.npcs.controllers.ProfileController; import kamkeel.npcs.controllers.data.ProfileOperation; +import kamkeel.npcs.controllers.data.EnumProfileOperation; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; -import static kamkeel.npcs.util.ColorUtil.sendError; -import static kamkeel.npcs.util.ColorUtil.sendResult; +import static kamkeel.npcs.util.ColorUtil.*; public class CommandProfileRemove extends CommandProfileBase { @@ -49,18 +49,14 @@ public class CommandProfileRemove extends CommandProfileBase { } EntityPlayer player = (EntityPlayer)sender; ProfileOperation result = ProfileController.removeSlot(player, slotId); - switch(result) { - case SUCCESS: - sendResult(sender, "Successfully removed slot %d from your profile.", slotId); - break; - case LOCKED: - sendError(sender, "Profile is locked. Please try again later."); - break; - case ERROR: - sendError(sender, "Error removing slot. Ensure the slot exists and is not your active slot."); - break; - default: - sendError(sender, "Operation could not be completed."); + if(result.getResult() == EnumProfileOperation.SUCCESS) { + sendResult(sender, "Successfully removed slot %d from your profile.", slotId); + } else if(result.getResult() == EnumProfileOperation.LOCKED) { + sendError(sender, "Profile is locked. Details: %s", result.getMessage()); + } else if(result.getResult() == EnumProfileOperation.ERROR) { + sendError(sender, "Error removing slot: %s", result.getMessage()); + } else { + sendError(sender, "Unexpected error: %s", result.getMessage()); } } } diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index be8ce4912..769cdb237 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -21,8 +21,41 @@ import java.net.URL; import java.text.SimpleDateFormat; import java.util.*; +import static noppes.npcs.CustomNpcsPermissions.PROFILE_REGION_BYPASS; +import static noppes.npcs.CustomNpcsPermissions.hasPermission; + public class ProfileController { + // ------------------- Message Constants ------------------- + // General messages + private static final String MSG_PLAYER_NOT_FOUND = "Player not found."; + + // Clone Slot messages + private static final String MSG_PROFILE_LOCKED_CLONE = "Profile is locked; cannot clone slot."; + private static final String MSG_SOURCE_SLOT_NOT_EXIST = "Source slot does not exist."; + private static final String MSG_CANNOT_CLONE_CURRENT = "Cannot clone to the current active slot."; + private static final String MSG_INVALID_DEST_SLOT = "Invalid destination slot id."; + private static final String MSG_CLONE_SUCCESS = "Slot cloned successfully."; + + // Remove Slot messages + private static final String MSG_PROFILE_LOCKED_REMOVE = "Profile is locked; cannot remove slot."; + private static final String MSG_CANNOT_REMOVE_ACTIVE = "Cannot remove the currently active slot."; + private static final String MSG_SLOT_NOT_EXIST = "Slot does not exist."; + private static final String MSG_REMOVE_SUCCESS = "Slot removed successfully."; + + // Create Slot messages + private static final String MSG_PROFILE_LOCKED_CREATE = "Profile is locked; cannot create slot."; + private static final String MSG_MAX_SLOTS_REACHED = "Maximum allowed slots reached."; + private static final String MSG_NEW_SLOT_CREATED = "New slot created successfully."; + + // Change Slot messages + private static final String MSG_PROFILE_LOCKED_CHANGE = "Profile is locked; cannot change slot."; + private static final String MSG_SLOT_ALREADY_ACTIVE = "Slot is already active."; + private static final String MSG_REGION_NOT_ALLOWED = "Profile switching not allowed from your current location."; + private static final String MSG_CHANGE_SUCCESS = "Slot changed successfully."; + + // ------------------- End Constants ------------------- + public static HashMap profileTypes; public static HashMap activeProfiles; public static String profile_directory = "profiles"; @@ -175,7 +208,6 @@ public class ProfileController { // Now enforce backup amount limit. File[] backups = backupDir.listFiles((dir, name) -> name.endsWith(".dat")); if(backups != null && backups.length > ConfigMain.ProfileBackupAmount) { - // Sort backups by last modified ascending (oldest first) Arrays.sort(backups, Comparator.comparingLong(File::lastModified)); for(int i = 0; i < backups.length - ConfigMain.ProfileBackupAmount; i++){ backups[i].delete(); @@ -291,7 +323,6 @@ public class ProfileController { } // ---------- Internal Slot Operation Helpers ---------- - // Returns the next available temporary (negative) slot id (starting at -1) private static int getNextAvailableTempSlot(Profile profile) { int id = -1; while(profile.slots.containsKey(id)) { @@ -301,120 +332,127 @@ public class ProfileController { } // Clone a slot within a Profile. - // If temporary==true, destinationSlotId is computed automatically. private static ProfileOperation cloneSlotInternal(Profile profile, int sourceSlotId, int destinationSlotId, boolean temporary) { if(profile.locked) { - LogWriter.error("Profile is locked; cannot clone slot."); - return ProfileOperation.LOCKED; + return ProfileOperation.locked(MSG_PROFILE_LOCKED_CLONE); } - // Run verification checks on all IProfileData in priority order. if(profile.player != null) { List dataList = new ArrayList<>(profileTypes.values()); dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority)); for(IProfileData pd : dataList) { - if(!pd.verifySwitch(profile.player)) { - LogWriter.error("Verification check failed for profile type: " + pd.getTagName()); - return ProfileOperation.VERIFICATION_FAILED; + if (pd.verifySwitch(profile.player).getResult() != EnumProfileOperation.SUCCESS) { + return pd.verifySwitch(profile.player); } } } if(!profile.slots.containsKey(sourceSlotId)) { - LogWriter.error("Source slot " + sourceSlotId + " does not exist."); - return ProfileOperation.ERROR; + return ProfileOperation.error(MSG_SOURCE_SLOT_NOT_EXIST); } if(destinationSlotId == profile.currentID) { - LogWriter.error("Cannot clone to the current active slot (" + profile.currentID + ")."); - return ProfileOperation.ERROR; + return ProfileOperation.error(MSG_CANNOT_CLONE_CURRENT); } if(temporary) { destinationSlotId = getNextAvailableTempSlot(profile); } else { if(destinationSlotId <= 0) { - LogWriter.error("Invalid destination slot id for a non-temporary clone."); - return ProfileOperation.ERROR; + return ProfileOperation.error(MSG_INVALID_DEST_SLOT); } } Slot sourceSlot = profile.slots.get(sourceSlotId); NBTTagCompound clonedData = (NBTTagCompound) sourceSlot.getCompound().copy(); Slot clonedSlot = new Slot(destinationSlotId, "Cloned Slot " + destinationSlotId, clonedData, System.currentTimeMillis(), temporary); profile.slots.put(destinationSlotId, clonedSlot); - return ProfileOperation.SUCCESS; + return ProfileOperation.success(MSG_CLONE_SUCCESS); } // Remove a slot from a Profile. private static ProfileOperation removeSlotInternal(Profile profile, int slotId) { if(profile.locked) { - LogWriter.error("Profile is locked; cannot remove slot."); - return ProfileOperation.LOCKED; + return ProfileOperation.locked(MSG_PROFILE_LOCKED_REMOVE); } if(slotId == profile.currentID) { - LogWriter.error("Cannot remove the currently active slot (" + profile.currentID + ")."); - return ProfileOperation.ERROR; + return ProfileOperation.error(MSG_CANNOT_REMOVE_ACTIVE); } if(!profile.slots.containsKey(slotId)) { - LogWriter.error("Slot " + slotId + " does not exist."); - return ProfileOperation.ERROR; + return ProfileOperation.error(MSG_SLOT_NOT_EXIST); } profile.slots.remove(slotId); - return ProfileOperation.SUCCESS; + return ProfileOperation.success(MSG_REMOVE_SUCCESS); } public static ProfileOperation createSlotInternal(Profile profile) { if (profile.locked) { - LogWriter.error("Profile is locked; cannot create slot."); - return ProfileOperation.LOCKED; + return ProfileOperation.locked(MSG_PROFILE_LOCKED_CREATE); } int newSlotId = 0; while (profile.slots.containsKey(newSlotId)) { newSlotId++; } - - // Check if the player is allowed to create a new slot. if (!allowSlotPermission(profile.player)) { - LogWriter.error("Player has reached maximum allowed slots."); - return ProfileOperation.MAX_SLOTS; + return ProfileOperation.error(MSG_MAX_SLOTS_REACHED); } - // Run verification checks from all IProfileData in order of priority. if (profile.player != null) { List dataList = new ArrayList<>(profileTypes.values()); dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority)); for (IProfileData pd : dataList) { - if (!pd.verifySwitch(profile.player)) { - LogWriter.error("Verification check failed for profile type: " + pd.getTagName()); - return ProfileOperation.VERIFICATION_FAILED; + if (pd.verifySwitch(profile.player).getResult() != EnumProfileOperation.SUCCESS) { + return pd.verifySwitch(profile.player); } } } - // Create and add the new slot. Slot newSlot = new Slot(newSlotId, "Slot " + newSlotId); newSlot.setCompound(new NBTTagCompound()); profile.slots.put(newSlotId, newSlot); - return ProfileOperation.NEW_SLOT_CREATED; + return ProfileOperation.success(MSG_NEW_SLOT_CREATED); } - // Change the active slot in a profile without automatically creating a new one. - // If the target slot does not exist, the operation fails. private static ProfileOperation changeSlotInternal(Profile profile, int newSlotId) { if (profile.locked) { - LogWriter.error("Profile is locked; cannot change slot."); - return ProfileOperation.LOCKED; + return ProfileOperation.locked(MSG_PROFILE_LOCKED_CHANGE); } if (profile.currentID == newSlotId) { - LogWriter.error("Slot " + newSlotId + " is already active."); - return ProfileOperation.ALREADY_ACTIVE; + return ProfileOperation.error(MSG_SLOT_ALREADY_ACTIVE); } if (!profile.slots.containsKey(newSlotId)) { - LogWriter.error("Slot " + newSlotId + " does not exist."); - return ProfileOperation.ERROR; + return ProfileOperation.error(MSG_SLOT_NOT_EXIST); + } + // Region-based check: if enabled, ensure the player is within an allowed region. + if (ConfigMain.RegionProfileSwitching && profile.player != null) { + boolean allowed = hasPermission(profile.player, PROFILE_REGION_BYPASS); + if(!allowed){ + int playerDim = profile.player.dimension; + int playerX = (int) profile.player.posX; + int playerY = (int) profile.player.posY; + int playerZ = (int) profile.player.posZ; + for (List region : ConfigMain.RestrictedProfileRegions) { + if(region.size() == 7) { + int dim = region.get(0); + int x1 = Math.min(region.get(1), region.get(4)); + int y1 = Math.min(region.get(2), region.get(5)); + int z1 = Math.min(region.get(3), region.get(6)); + int x2 = Math.max(region.get(1), region.get(4)); + int y2 = Math.max(region.get(2), region.get(5)); + int z2 = Math.max(region.get(3), region.get(6)); + if(playerDim == dim && + playerX >= x1 && playerX <= x2 && + playerY >= y1 && playerY <= y2 && + playerZ >= z1 && playerZ <= z2) { + allowed = true; + break; + } + } + } + } + if (!allowed) { + return ProfileOperation.error(MSG_REGION_NOT_ALLOWED); + } } - // Run verification checks on all IProfileData in priority order. if (profile.player != null) { List dataList = new ArrayList<>(profileTypes.values()); dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority)); for (IProfileData pd : dataList) { - if (!pd.verifySwitch(profile.player)) { - LogWriter.error("Verification check failed for profile type: " + pd.getTagName()); - return ProfileOperation.VERIFICATION_FAILED; + if (pd.verifySwitch(profile.player).getResult() != EnumProfileOperation.SUCCESS) { + return pd.verifySwitch(profile.player); } } } @@ -424,31 +462,32 @@ public class ProfileController { profile.currentID = newSlotId; if (profile.player != null) { loadSlotData(profile.player); - } - if (profile.player != null) { PlayerData pdata = PlayerData.get(profile.player); pdata.profileSlot = newSlotId; pdata.save(); } - return ProfileOperation.SUCCESS; + return ProfileOperation.success(MSG_CHANGE_SUCCESS); } // ---------- Public Operations (Overloaded for EntityPlayer, UUID, or username) ---------- // ----- Clone Slot ----- public static ProfileOperation cloneSlot(EntityPlayer player, int sourceSlotId, int destinationSlotId, boolean temporary) { Profile profile = getProfile(player); - if(profile == null) return ProfileOperation.PLAYER_NOT_FOUND; + if(profile == null) + return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); ProfileOperation result = cloneSlotInternal(profile, sourceSlotId, destinationSlotId, temporary); - if(result == ProfileOperation.SUCCESS && player != null) + if(result.getResult() == EnumProfileOperation.SUCCESS && player != null) { save(player, profile); + } return result; } public static ProfileOperation cloneSlot(UUID uuid, int sourceSlotId, int destinationSlotId, boolean temporary) { Profile profile = getProfile(uuid); - if(profile == null) return ProfileOperation.PLAYER_NOT_FOUND; + if(profile == null) + return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); ProfileOperation result = cloneSlotInternal(profile, sourceSlotId, destinationSlotId, temporary); - if(result == ProfileOperation.SUCCESS) { + if(result.getResult() == EnumProfileOperation.SUCCESS) { if(profile.player != null) save(profile.player, profile); else @@ -459,9 +498,10 @@ public class ProfileController { public static ProfileOperation cloneSlot(String username, int sourceSlotId, int destinationSlotId, boolean temporary) { Profile profile = getProfile(username); - if(profile == null) return ProfileOperation.PLAYER_NOT_FOUND; + if(profile == null) + return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); ProfileOperation result = cloneSlotInternal(profile, sourceSlotId, destinationSlotId, temporary); - if(result == ProfileOperation.SUCCESS) { + if(result.getResult() == EnumProfileOperation.SUCCESS) { if(profile.player != null) save(profile.player, profile); else { @@ -476,18 +516,21 @@ public class ProfileController { // ----- Remove Slot ----- public static ProfileOperation removeSlot(EntityPlayer player, int slotId) { Profile profile = getProfile(player); - if(profile == null) return ProfileOperation.PLAYER_NOT_FOUND; + if(profile == null) + return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); ProfileOperation result = removeSlotInternal(profile, slotId); - if(result == ProfileOperation.SUCCESS && player != null) + if(result.getResult() == EnumProfileOperation.SUCCESS && player != null) { save(player, profile); + } return result; } public static ProfileOperation removeSlot(UUID uuid, int slotId) { Profile profile = getProfile(uuid); - if(profile == null) return ProfileOperation.PLAYER_NOT_FOUND; + if(profile == null) + return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); ProfileOperation result = removeSlotInternal(profile, slotId); - if(result == ProfileOperation.SUCCESS) { + if(result.getResult() == EnumProfileOperation.SUCCESS) { if(profile.player != null) save(profile.player, profile); else @@ -498,9 +541,10 @@ public class ProfileController { public static ProfileOperation removeSlot(String username, int slotId) { Profile profile = getProfile(username); - if(profile == null) return ProfileOperation.PLAYER_NOT_FOUND; + if(profile == null) + return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); ProfileOperation result = removeSlotInternal(profile, slotId); - if(result == ProfileOperation.SUCCESS) { + if(result.getResult() == EnumProfileOperation.SUCCESS) { if(profile.player != null) save(profile.player, profile); else { @@ -515,18 +559,20 @@ public class ProfileController { // ----- Change Slot ----- public static ProfileOperation changeSlot(EntityPlayer player, int newSlotId) { Profile profile = getProfile(player); - if(profile == null) return ProfileOperation.PLAYER_NOT_FOUND; + if(profile == null) + return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); ProfileOperation result = changeSlotInternal(profile, newSlotId); - if((result == ProfileOperation.SUCCESS || result == ProfileOperation.NEW_SLOT_CREATED) && player != null) + if(result.getResult() == EnumProfileOperation.SUCCESS && player != null) save(player, profile); return result; } public static ProfileOperation changeSlot(UUID uuid, int newSlotId) { Profile profile = getProfile(uuid); - if(profile == null) return ProfileOperation.PLAYER_NOT_FOUND; + if(profile == null) + return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); ProfileOperation result = changeSlotInternal(profile, newSlotId); - if(result == ProfileOperation.SUCCESS || result == ProfileOperation.NEW_SLOT_CREATED) { + if(result.getResult() == EnumProfileOperation.SUCCESS) { if(profile.player != null) save(profile.player, profile); else @@ -537,9 +583,10 @@ public class ProfileController { public static ProfileOperation changeSlot(String username, int newSlotId) { Profile profile = getProfile(username); - if(profile == null) return ProfileOperation.PLAYER_NOT_FOUND; + if(profile == null) + return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); ProfileOperation result = changeSlotInternal(profile, newSlotId); - if(result == ProfileOperation.SUCCESS || result == ProfileOperation.NEW_SLOT_CREATED) { + if(result.getResult() == EnumProfileOperation.SUCCESS) { if(profile.player != null) save(profile.player, profile); else { @@ -557,7 +604,6 @@ public class ProfileController { return; Profile profile = activeProfiles.get(player.getUniqueID()); if(profile.locked) { - LogWriter.error("Profile is locked; cannot save slot data."); return; } NBTTagCompound dataCompound; @@ -634,7 +680,6 @@ public class ProfileController { return infoList; } - public static boolean allowSlotPermission(EntityPlayer player) { Profile profile = ProfileController.getProfile(player); int currentSlots = profile.slots.size(); @@ -659,28 +704,6 @@ public class ProfileController { return currentSlots < highestAllowed; } - public void sendChatAlert(ProfileOperation operation, EntityPlayerMP player){ - switch (operation){ - case SUCCESS: - ChatAlertPacket.sendChatAlert(player, "quest.newquest", ": ", ""); - break; - case ERROR: - break; - case LOCKED: - break; - case PLAYER_NOT_FOUND: - break; - case NEW_SLOT_CREATED: - break; - case ALREADY_ACTIVE: - break; - case VERIFICATION_FAILED: - break; - case MAX_SLOTS: - break; - } - } - public static EntityPlayerMP getPlayer(String username){ return MinecraftServer.getServer().getConfigurationManager().func_152612_a(username); } diff --git a/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java b/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java index 6a60ade72..c40c43ca4 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java +++ b/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java @@ -4,6 +4,7 @@ import kamkeel.npcs.controllers.SyncController; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.controllers.PartyController; import noppes.npcs.controllers.data.PlayerData; import java.util.ArrayList; import java.util.List; @@ -48,8 +49,12 @@ public class CNPCData implements IProfileData { } @Override - public boolean verifySwitch(EntityPlayer player) { - return true; + public ProfileOperation verifySwitch(EntityPlayer player) { + PlayerData playerData = PlayerData.get(player); + if(playerData.partyUUID != null) + return ProfileOperation.error("Cannot switch while in Party"); + + return ProfileOperation.success(""); } @Override diff --git a/src/main/java/kamkeel/npcs/controllers/data/EnumProfileOperation.java b/src/main/java/kamkeel/npcs/controllers/data/EnumProfileOperation.java new file mode 100644 index 000000000..b4c10d3ec --- /dev/null +++ b/src/main/java/kamkeel/npcs/controllers/data/EnumProfileOperation.java @@ -0,0 +1,7 @@ +package kamkeel.npcs.controllers.data; + +public enum EnumProfileOperation { + SUCCESS, + ERROR, + LOCKED +} diff --git a/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java b/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java index 2b5e308b5..846d93acc 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java +++ b/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java @@ -38,7 +38,7 @@ public interface IProfileData { * @param player The player switching profiles. * @return true if allowed, false if not. */ - public boolean verifySwitch(EntityPlayer player); + public ProfileOperation verifySwitch(EntityPlayer player); /** * NEW: Builds and returns a list of informational strings about this profile data, diff --git a/src/main/java/kamkeel/npcs/controllers/data/ProfileOperation.java b/src/main/java/kamkeel/npcs/controllers/data/ProfileOperation.java index 59dc7e2ef..7c3844794 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ProfileOperation.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ProfileOperation.java @@ -1,13 +1,31 @@ package kamkeel.npcs.controllers.data; -public enum ProfileOperation { - SUCCESS, - ERROR, - LOCKED, - PLAYER_NOT_FOUND, - NEW_SLOT_CREATED, - ALREADY_ACTIVE, - VERIFICATION_FAILED, - MAX_SLOTS -} +public class ProfileOperation { + private final EnumProfileOperation result; + private final String message; + public ProfileOperation(EnumProfileOperation result, String message) { + this.result = result; + this.message = message; + } + + public EnumProfileOperation getResult() { + return result; + } + + public String getMessage() { + return message; + } + + public static ProfileOperation success(String message) { + return new ProfileOperation(EnumProfileOperation.SUCCESS, message); + } + + public static ProfileOperation error(String message) { + return new ProfileOperation(EnumProfileOperation.ERROR, message); + } + + public static ProfileOperation locked(String message) { + return new ProfileOperation(EnumProfileOperation.LOCKED, message); + } +} diff --git a/src/main/java/noppes/npcs/CustomNpcsPermissions.java b/src/main/java/noppes/npcs/CustomNpcsPermissions.java index 35aa84c0e..71419fada 100644 --- a/src/main/java/noppes/npcs/CustomNpcsPermissions.java +++ b/src/main/java/noppes/npcs/CustomNpcsPermissions.java @@ -94,6 +94,7 @@ public class CustomNpcsPermissions{ public static final Permission PROFILE_DELETE = new Permission("customnpcs.profile.delete"); public static final Permission PROFILE_RENAME = new Permission("customnpcs.profile.rename"); public static final Permission PROFILE_CHANGE = new Permission("customnpcs.profile.change"); + public static final Permission PROFILE_REGION_BYPASS = new Permission("customnpcs.profile.region-bypass"); public static final Permission PROFILE_MAX = new Permission("customnpcs.profile.max.*"); public static CustomNpcsPermissions Instance; diff --git a/src/main/java/noppes/npcs/config/ConfigMain.java b/src/main/java/noppes/npcs/config/ConfigMain.java index 8f0846b60..7732dd7c5 100644 --- a/src/main/java/noppes/npcs/config/ConfigMain.java +++ b/src/main/java/noppes/npcs/config/ConfigMain.java @@ -8,6 +8,8 @@ import noppes.npcs.config.legacy.LegacyConfig; import org.apache.logging.log4j.Level; import java.io.File; +import java.util.ArrayList; +import java.util.List; public class ConfigMain { @@ -87,6 +89,11 @@ public class ConfigMain public static boolean AllowProfileBackups = true; public static int ProfileBackupAmount = 5; + public static Property RegionProfileSwitchingProperty; + public static boolean RegionProfileSwitching = false; + + public static Property RestrictedProfileRegionsProperty; + public static List> RestrictedProfileRegions = new ArrayList<>(); /** * General NPC Properties @@ -230,6 +237,24 @@ public class ConfigMain AllowProfileBackups = config.get(PROFILES, "Enable Profile Backups", true, "Will create backups of profile changes").getBoolean(true); ProfileBackupAmount = config.get(PROFILES, "Number of Backups", 5, "How many backups per player to save").getInt(5); + RegionProfileSwitchingProperty = config.get(PROFILES, "Region Profile Switching", false, "If true, only allows profile switching in certain regions."); + RegionProfileSwitching = RegionProfileSwitchingProperty.getBoolean(false); + + RestrictedProfileRegionsProperty = config.get(PROFILES, "Restricted Profile Regions", new String[]{ + "0, 100, 64, 100, 200, 80, 200", + "1, 50, 60, 50, 150, 75, 150" + }, "List of restricted regions where profile switching is enabled. Format: DIM, X1, Y1, Z1, X2, Y2, Z2"); + + RestrictedProfileRegions.clear(); + for (String region : RestrictedProfileRegionsProperty.getStringList()) { + String[] parts = region.split(", "); + List regionList = new ArrayList<>(); + for (String part : parts) { + regionList.add(Integer.parseInt(part)); + } + RestrictedProfileRegions.add(regionList); + } + // Convert to Legacy if(CustomNpcs.legacyExist){ EnableUpdateChecker = LegacyConfig.EnableUpdateChecker; From 98e886703c9fcf52f71bb20ba04b9ccff5c6d424 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 20 Feb 2025 00:31:52 -0500 Subject: [PATCH 15/59] Push a TERRIBLY INCOMPLETE CODE!!! :DDDDD --- .../kamkeel/npcs/network/PacketHandler.java | 14 +- .../npcs/network/enums/EnumDataPacket.java | 1 + .../npcs/network/enums/EnumRequestPacket.java | 2 +- .../playerdata/PlayerDataGetPacket.java | 2 +- .../java/kamkeel/npcs/util/ByteBufUtils.java | 2 +- .../npcs/client/gui/SubGuiPlayerData.java | 928 ++++++++++++++++++ .../client/gui/global/GuiNPCManageLinked.java | 2 - .../client/gui/global/GuiNPCManageMagic.java | 2 +- .../gui/global/GuiNpcManagePlayerData.java | 248 ++--- .../gui/player/inventory/GuiProfiles.java | 2 +- .../npcs/client/gui/test/IPlayerDataInfo.java | 11 + .../client/gui/test/NoppesUtilClientNew.java | 74 ++ .../client/gui/test/NoppesUtilServerNew.java | 155 +++ .../gui/test/PlayerDataGetPacketNew.java | 47 + .../gui/test/PlayerDataRemovePacketNew.java | 56 ++ .../gui/test/PlayerDataSendPacketNew.java | 101 ++ .../npcs/client/gui/test/PlayerDataTab.java | 9 + .../client/gui/test/SubGuiPlayerDataNew.java | 864 ++++++++++++++++ .../npcs/client/gui/util/GuiCustomScroll.java | 2 +- .../npcs/client/gui/util/GuiNPCInterface.java | 18 + 20 files changed, 2392 insertions(+), 148 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java create mode 100644 src/main/java/noppes/npcs/client/gui/test/IPlayerDataInfo.java create mode 100644 src/main/java/noppes/npcs/client/gui/test/NoppesUtilClientNew.java create mode 100644 src/main/java/noppes/npcs/client/gui/test/NoppesUtilServerNew.java create mode 100644 src/main/java/noppes/npcs/client/gui/test/PlayerDataGetPacketNew.java create mode 100644 src/main/java/noppes/npcs/client/gui/test/PlayerDataRemovePacketNew.java create mode 100644 src/main/java/noppes/npcs/client/gui/test/PlayerDataSendPacketNew.java create mode 100644 src/main/java/noppes/npcs/client/gui/test/PlayerDataTab.java create mode 100644 src/main/java/noppes/npcs/client/gui/test/SubGuiPlayerDataNew.java diff --git a/src/main/java/kamkeel/npcs/network/PacketHandler.java b/src/main/java/kamkeel/npcs/network/PacketHandler.java index 8b115635c..10a5fd259 100644 --- a/src/main/java/kamkeel/npcs/network/PacketHandler.java +++ b/src/main/java/kamkeel/npcs/network/PacketHandler.java @@ -82,6 +82,9 @@ import noppes.npcs.CustomNpcs; import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.LogWriter; import noppes.npcs.NoppesUtilServer; +import noppes.npcs.client.gui.test.PlayerDataGetPacketNew; +import noppes.npcs.client.gui.test.PlayerDataRemovePacketNew; +import noppes.npcs.client.gui.test.PlayerDataSendPacketNew; import noppes.npcs.config.ConfigMain; import noppes.npcs.entity.EntityNPCInterface; @@ -225,8 +228,14 @@ public class PacketHandler { REQUEST_PACKET.registerPacket(new TagRemovePacket()); // PlayerData Packets + + REQUEST_PACKET.registerPacket(new PlayerDataGetPacket()); - REQUEST_PACKET.registerPacket(new PlayerDataRemovePacket()); +// REQUEST_PACKET.registerPacket(new PlayerDataRemovePacket()); + + REQUEST_PACKET.registerPacket(new PlayerDataGetPacketNew()); + REQUEST_PACKET.registerPacket(new PlayerDataRemovePacketNew()); + REQUEST_PACKET.registerPacket(new PlayerDataMapRegenPacket()); // Main Menu Packets @@ -346,6 +355,9 @@ public class PacketHandler { } public void registerDataPackets(){ + + DATA_PACKET.registerPacket(new PlayerDataSendPacketNew()); + // Data Packets DATA_PACKET.registerPacket(new LoginPacket()); DATA_PACKET.registerPacket(new AchievementPacket()); diff --git a/src/main/java/kamkeel/npcs/network/enums/EnumDataPacket.java b/src/main/java/kamkeel/npcs/network/enums/EnumDataPacket.java index afde0e87e..874677af9 100644 --- a/src/main/java/kamkeel/npcs/network/enums/EnumDataPacket.java +++ b/src/main/java/kamkeel/npcs/network/enums/EnumDataPacket.java @@ -38,6 +38,7 @@ public enum EnumDataPacket { GUI_TELEPORTER, GUI_BOOK, GUI_DATA, + PLAYER_DATA, GUI_ERROR, GUI_CLOSE, ISGUIOPEN, diff --git a/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java b/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java index febd0386b..3036d9a88 100644 --- a/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java +++ b/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java @@ -186,5 +186,5 @@ public enum EnumRequestPacket { ColorSet, ColorBrush, - ProfileGet, ProfileGetAll, ProfileGetInfo, ProfileCreate, ProfileRemove, ProfileRename, ProfileChange, + ProfileGet, ProfileGetAll, ProfileGetInfo, ProfileCreate, ProfileRemove, ProfileRename, ProfileChange, PlayerDataGetOld, } diff --git a/src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataGetPacket.java index 557698999..9f4ea14f6 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataGetPacket.java @@ -32,7 +32,7 @@ public final class PlayerDataGetPacket extends AbstractPacket { @Override public Enum getType() { - return EnumRequestPacket.PlayerDataGet; + return EnumRequestPacket.PlayerDataGetOld; } @Override diff --git a/src/main/java/kamkeel/npcs/util/ByteBufUtils.java b/src/main/java/kamkeel/npcs/util/ByteBufUtils.java index f470e17c0..225327935 100644 --- a/src/main/java/kamkeel/npcs/util/ByteBufUtils.java +++ b/src/main/java/kamkeel/npcs/util/ByteBufUtils.java @@ -102,7 +102,7 @@ public class ByteBufUtils extends cpw.mods.fml.common.network.ByteBufUtils { int length = buffer.readInt(); byte[] bytes = new byte[length]; buffer.readBytes(bytes); - return CompressedStreamTools.func_152457_a(bytes, new NBTSizeTracker(15728640L)); + return CompressedStreamTools.func_152457_a(bytes, new NBTSizeTracker(31457280L)); } public static void writeString(ByteBuf buffer, String s){ diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java b/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java new file mode 100644 index 000000000..f4db0f16d --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java @@ -0,0 +1,928 @@ +package noppes.npcs.client.gui; + +import kamkeel.npcs.network.PacketClient; +import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetPacket; +import kamkeel.npcs.network.packets.request.playerdata.PlayerDataRemovePacket; +import net.minecraft.client.gui.GuiYesNo; +import net.minecraft.client.gui.GuiYesNoCallback; +import noppes.npcs.client.NoppesUtil; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.constants.EnumPlayerData; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.util.StatCollector; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Vector; + +public class SubGuiPlayerData extends SubGuiInterface implements GuiYesNoCallback, ICustomScrollListener, IScrollData { + + private String playerName; + private int currentTab = 10; // 10: Quests, 11: Dialog, 12: Transport, 13: Bank, 14: Faction. + private int viewMode = 0; // 0: Categorical, 1: Compact. + private int lastDataType = 0; + + // ----- Quest Tab (10) ----- + private GuiCustomScroll questCatScroll, questFinishedScroll, questActiveScroll; + private String questCatSearch = "", questFinishedSearch = "", questActiveSearch = ""; + // Maps for category display (questCatData) and for quest entries: + private HashMap questCatData = new HashMap<>(); + private HashMap questFinishedData = new HashMap<>(); + private HashMap questActiveData = new HashMap<>(); + // New: maps storing the extracted category for each quest entry (keyed by the displayed quest title) + private HashMap questFinishedCategory = new HashMap<>(); + private HashMap questActiveCategory = new HashMap<>(); + private String selectedQuestCategory = ""; + + // ----- Dialog Tab (11) ----- + private GuiCustomScroll dialogCatScroll, dialogReadScroll; + private String dialogCatSearch = "", dialogReadSearch = ""; + private HashMap dialogCatData = new HashMap<>(); + private HashMap dialogReadData = new HashMap<>(); + // For dialog entries, we split off the category from the key ("Category: Title") + private HashMap dialogCategory = new HashMap<>(); + private GuiCustomScroll dialogCompactScroll; + private String dialogCompactSearch = ""; + private HashMap dialogCompactData = new HashMap<>(); + private String selectedDialogCategory = ""; + + // ----- Transport Tab (12) ----- + private GuiCustomScroll transCatScroll, transLocScroll; + private String transCatSearch = "", transLocSearch = ""; + private HashMap transCatData = new HashMap<>(); + private HashMap transLocData = new HashMap<>(); + // For transport locations, also store their category: + private HashMap transLocationCategory = new HashMap<>(); + private GuiCustomScroll transCompactScroll; + private String transCompactSearch = ""; + private HashMap transCompactData = new HashMap<>(); + private String selectedTransCategory = ""; + + // ----- Bank & Faction Tabs (13 & 14) ----- + private GuiCustomScroll singleScroll; + private String singleSearch = ""; + private HashMap singleData = new HashMap<>(); + + // ----- Divider/resizing variables ----- +// We use margins so that scrolls have room on the right for buttons. + private final int leftMargin = guiLeft + 4; + private final int rightMargin = guiLeft + xSize - 80; // leave 80px for the buttons on the right + private int dividerOffset1 = 120; + private int dividerOffset2 = 240; + private final int dividerWidth = 5; + private final int minScrollWidth = 50; + private int draggingDivider = 0; + private int initialDragX = 0; + private boolean isResizing = false; + + public SubGuiPlayerData(String playerName) { + this.playerName = playerName; + xSize = 420; + ySize = 216; + setBackground("menubg.png"); + lastDataType = 11; + PacketClient.sendClient(new PlayerDataGetPacket(EnumPlayerData.Quest, playerName)); + closeOnEsc = true; + } + + @Override + public void initGui() { + super.initGui(); + // --- Top Buttons --- + GuiMenuTopButton close = new GuiMenuTopButton(-5, guiLeft + xSize - 22, guiTop - 10, "X"); + GuiMenuTopButton quests = new GuiMenuTopButton(10, guiLeft + 4, guiTop - 10, StatCollector.translateToLocal("tab.quests")); + GuiMenuTopButton dialog = new GuiMenuTopButton(11, quests.xPosition + quests.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.dialog")); + GuiMenuTopButton transport = new GuiMenuTopButton(12, dialog.xPosition + dialog.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.transport")); + GuiMenuTopButton bank = new GuiMenuTopButton(13, transport.xPosition + transport.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.bank")); + GuiMenuTopButton faction = new GuiMenuTopButton(14, bank.xPosition + bank.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.faction")); + + quests.active = (currentTab == 10); + dialog.active = (currentTab == 11); + transport.active = (currentTab == 12); + bank.active = (currentTab == 13); + faction.active = (currentTab == 14); + close.active = false; + + addTopButton(close); + addTopButton(quests); + addTopButton(dialog); + addTopButton(transport); + addTopButton(bank); + addTopButton(faction); + + if (currentTab == 10 || currentTab == 11 || currentTab == 12) { + addButton(new GuiNpcButton(20, guiLeft + xSize - 80, guiTop - 10, 75, 20, + viewMode == 0 ? StatCollector.translateToLocal("view.categorical") : StatCollector.translateToLocal("view.compact"))); + } + + guiTop += 7; + + if (currentTab == 10) + lastDataType = 11; + else if (currentTab == 11) + lastDataType = (viewMode == 0) ? 21 : 22; + else if (currentTab == 12) + lastDataType = (viewMode == 0) ? 31 : 32; + else if (currentTab == 13 || currentTab == 14) + lastDataType = 40; + + switch (currentTab) { + case 10: + initQuestTab(); + break; + case 11: + initDialogTab(); + break; + case 12: + initTransportTab(); + break; + case 13: + case 14: + initSingleScroll(); + break; + } + + addButton(new GuiNpcButton(30, guiLeft + xSize - 80, guiTop + ySize - 30, 75, 20, StatCollector.translateToLocal("button.delete"))); + } + + private void initQuestTab() { + int regionLeft = leftMargin; + int regionRight = rightMargin; + int dividerX1 = regionLeft + dividerOffset1; + int dividerX2 = regionLeft + dividerOffset2; + + if (viewMode == 0) { + if (questCatScroll == null) { + questCatScroll = new GuiCustomScroll(this, 0, 0); + } + questCatScroll.guiLeft = regionLeft; + questCatScroll.guiTop = guiTop + 30; + questCatScroll.setSize(dividerX1 - regionLeft, 150); + addScroll(questCatScroll); + addLabel(new GuiNpcLabel(1000, "Categories", regionLeft, guiTop + 15, 0xFFFFFF)); + + if (questFinishedScroll == null) { + questFinishedScroll = new GuiCustomScroll(this, 1, 0); + } + questFinishedScroll.guiLeft = dividerX1 + dividerWidth; + questFinishedScroll.guiTop = guiTop + 30; + questFinishedScroll.setSize(dividerX2 - dividerX1 - dividerWidth, 150); + addScroll(questFinishedScroll); + addLabel(new GuiNpcLabel(1001, "Finished", dividerX1 + dividerWidth, guiTop + 15, 0xFFFFFF)); + + if (questActiveScroll == null) { + questActiveScroll = new GuiCustomScroll(this, 2, 0); + } + questActiveScroll.guiLeft = dividerX2 + dividerWidth; + questActiveScroll.guiTop = guiTop + 30; + questActiveScroll.setSize(regionRight - dividerX2 - dividerWidth, 150); + addScroll(questActiveScroll); + addLabel(new GuiNpcLabel(1002, "Active", dividerX2 + dividerWidth, guiTop + 15, 0xFFFFFF)); + + // When a category is selected, filter using our extra maps. + if (!selectedQuestCategory.isEmpty()) { + questFinishedScroll.setList(filterQuestsByCategory(questFinishedData, questFinishedCategory, selectedQuestCategory)); + questActiveScroll.setList(filterQuestsByCategory(questActiveData, questActiveCategory, selectedQuestCategory)); + } else { + questFinishedScroll.setList(getSearchList(questFinishedData, questFinishedSearch)); + questActiveScroll.setList(getSearchList(questActiveData, questActiveSearch)); + } + } else { + if (questFinishedScroll == null) { + questFinishedScroll = new GuiCustomScroll(this, 1, 0); + } + questFinishedScroll.guiLeft = regionLeft; + questFinishedScroll.guiTop = guiTop + 30; + questFinishedScroll.setSize((regionRight - regionLeft) / 2, 150); + addScroll(questFinishedScroll); + addLabel(new GuiNpcLabel(1003, "Finished", regionLeft, guiTop + 15, 0xFFFFFF)); + + if (questActiveScroll == null) { + questActiveScroll = new GuiCustomScroll(this, 2, 0); + } + questActiveScroll.guiLeft = regionLeft + (regionRight - regionLeft) / 2; + questActiveScroll.guiTop = guiTop + 30; + questActiveScroll.setSize((regionRight - regionLeft) / 2, 150); + addScroll(questActiveScroll); + addLabel(new GuiNpcLabel(1004, "Active", questActiveScroll.guiLeft, guiTop + 15, 0xFFFFFF)); + } + if (viewMode == 0) { + addTextField(new GuiNpcTextField(55, this, fontRendererObj, regionLeft, guiTop + 30 + 153, dividerX1 - regionLeft, 20, questCatSearch)); + addTextField(new GuiNpcTextField(56, this, fontRendererObj, dividerX1 + dividerWidth, guiTop + 30 + 153, dividerX2 - dividerX1 - dividerWidth, 20, questFinishedSearch)); + addTextField(new GuiNpcTextField(57, this, fontRendererObj, dividerX2 + dividerWidth, guiTop + 30 + 153, regionRight - dividerX2 - dividerWidth, 20, questActiveSearch)); + } else { + addTextField(new GuiNpcTextField(55, this, fontRendererObj, regionLeft, guiTop + 30 + 153, (regionRight - regionLeft) / 2, 20, questFinishedSearch)); + addTextField(new GuiNpcTextField(56, this, fontRendererObj, questActiveScroll.guiLeft, guiTop + 30 + 153, (regionRight - regionLeft) / 2, 20, questActiveSearch)); + } + } + + private void initDialogTab() { + int regionLeft = leftMargin; + int regionRight = rightMargin; + int dividerX = regionLeft + dividerOffset1; + + if (viewMode == 0) { + if (dialogCatScroll == null) { + dialogCatScroll = new GuiCustomScroll(this, 0, 0); + } + dialogCatScroll.guiLeft = regionLeft; + dialogCatScroll.guiTop = guiTop + 30; + dialogCatScroll.setSize(dividerX - regionLeft, 150); + addScroll(dialogCatScroll); + addLabel(new GuiNpcLabel(2000, "Categories", regionLeft, guiTop + 15, 0xFFFFFF)); + + if (dialogReadScroll == null) { + dialogReadScroll = new GuiCustomScroll(this, 1, 0); + } + dialogReadScroll.guiLeft = dividerX + dividerWidth; + dialogReadScroll.guiTop = guiTop + 30; + dialogReadScroll.setSize(regionRight - dividerX - dividerWidth, 150); + addScroll(dialogReadScroll); + addLabel(new GuiNpcLabel(2001, "Read", dividerX + dividerWidth, guiTop + 15, 0xFFFFFF)); + + if (!selectedDialogCategory.isEmpty()) { + dialogReadScroll.setList(filterDialogsByCategory(dialogReadData, dialogCategory, selectedDialogCategory)); + } else { + dialogReadScroll.setList(getSearchList(dialogReadData, dialogReadSearch)); + } + } else { + if (dialogCompactScroll == null) { + dialogCompactScroll = new GuiCustomScroll(this, 5, 0); + } + dialogCompactScroll.guiLeft = regionLeft; + dialogCompactScroll.guiTop = guiTop + 30; + dialogCompactScroll.setSize(regionRight - regionLeft, 150); + addScroll(dialogCompactScroll); + addLabel(new GuiNpcLabel(2002, "All", regionLeft, guiTop + 15, 0xFFFFFF)); + dialogCompactScroll.setList(getSearchList(dialogCompactData, dialogCompactSearch)); + addTextField(new GuiNpcTextField(55, this, fontRendererObj, regionLeft, guiTop + 30 + 153, regionRight - regionLeft, 20, dialogCompactSearch)); + } + if (viewMode == 0) { + addTextField(new GuiNpcTextField(55, this, fontRendererObj, regionLeft, guiTop + 30 + 153, dividerX - regionLeft, 20, dialogCatSearch)); + addTextField(new GuiNpcTextField(56, this, fontRendererObj, dividerX + dividerWidth, guiTop + 30 + 153, regionRight - dividerX - dividerWidth, 20, dialogReadSearch)); + } + } + + private void initTransportTab() { + int regionLeft = leftMargin; + int regionRight = rightMargin; + int dividerX = regionLeft + dividerOffset1; + + if (viewMode == 0) { + if (transCatScroll == null) { + transCatScroll = new GuiCustomScroll(this, 3, 0); + } + transCatScroll.guiLeft = regionLeft; + transCatScroll.guiTop = guiTop + 30; + transCatScroll.setSize(dividerX - regionLeft, 150); + addScroll(transCatScroll); + addLabel(new GuiNpcLabel(3000, "Categories", regionLeft, guiTop + 15, 0xFFFFFF)); + + if (transLocScroll == null) { + transLocScroll = new GuiCustomScroll(this, 4, 0); + } + transLocScroll.guiLeft = dividerX + dividerWidth; + transLocScroll.guiTop = guiTop + 30; + transLocScroll.setSize(regionRight - dividerX - dividerWidth, 150); + addScroll(transLocScroll); + addLabel(new GuiNpcLabel(3001, "Locations", dividerX + dividerWidth, guiTop + 15, 0xFFFFFF)); + + if (!selectedTransCategory.isEmpty()) { + transLocScroll.setList(filterTransportsByCategory(transLocData, transLocationCategory, selectedTransCategory)); + } else { + transLocScroll.setList(getSearchList(transLocData, transLocSearch)); + } + } else { + if (transCompactScroll == null) { + transCompactScroll = new GuiCustomScroll(this, 5, 0); + } + transCompactScroll.guiLeft = regionLeft; + transCompactScroll.guiTop = guiTop + 30; + transCompactScroll.setSize(regionRight - regionLeft, 150); + addScroll(transCompactScroll); + addLabel(new GuiNpcLabel(3002, "All", regionLeft, guiTop + 15, 0xFFFFFF)); + transCompactScroll.setList(getSearchList(transCompactData, transCompactSearch)); + addTextField(new GuiNpcTextField(60, this, fontRendererObj, regionLeft, guiTop + 30 + 153, regionRight - regionLeft, 20, transCompactSearch)); + } + if (viewMode == 0) { + addTextField(new GuiNpcTextField(60, this, fontRendererObj, regionLeft, guiTop + 30 + 153, dividerX - regionLeft, 20, transCatSearch)); + addTextField(new GuiNpcTextField(61, this, fontRendererObj, dividerX + dividerWidth, guiTop + 30 + 153, regionRight - dividerX - dividerWidth, 20, transLocSearch)); + } + } + + private void initSingleScroll() { + int regionLeft = leftMargin; + int regionRight = rightMargin; + if (singleScroll == null) { + singleScroll = new GuiCustomScroll(this, 6, 0); + } + singleScroll.guiLeft = regionLeft; + singleScroll.guiTop = guiTop + 30; + singleScroll.setSize(regionRight - regionLeft, 150); + addScroll(singleScroll); + addLabel(new GuiNpcLabel(4000, "Data", regionLeft, guiTop + 15, 0xFFFFFF)); + addTextField(new GuiNpcTextField(70, this, fontRendererObj, regionLeft, guiTop + 30 + 153, regionRight - regionLeft, 20, singleSearch)); + } + + @Override + public void actionPerformed(GuiButton button) { + int id = button.id; + if (id >= 10 && id <= 14) { + currentTab = id; + clearData(); + selectedQuestCategory = ""; + selectedDialogCategory = ""; + selectedTransCategory = ""; + switch (currentTab) { + case 10: + PacketClient.sendClient(new PlayerDataGetPacket(EnumPlayerData.Quest, playerName)); + break; + case 11: + PacketClient.sendClient(new PlayerDataGetPacket(EnumPlayerData.Dialog, playerName)); + break; + case 12: + PacketClient.sendClient(new PlayerDataGetPacket(EnumPlayerData.Transport, playerName)); + break; + case 13: + PacketClient.sendClient(new PlayerDataGetPacket(EnumPlayerData.Bank, playerName)); + break; + case 14: + PacketClient.sendClient(new PlayerDataGetPacket(EnumPlayerData.Factions, playerName)); + break; + } + initGui(); + return; + } + if (id == 20) { + viewMode = (viewMode == 0) ? 1 : 0; + initGui(); + return; + } + if (id == 30) { + displayGuiScreen(new GuiYesNo(this, StatCollector.translateToLocal("gui.deleteconfirm"), "", 100 + currentTab)); + return; + } + } + + private void clearData() { + questCatData.clear(); + questFinishedData.clear(); + questActiveData.clear(); + questFinishedCategory.clear(); + questActiveCategory.clear(); + dialogCatData.clear(); + dialogReadData.clear(); + dialogCompactData.clear(); + dialogCategory.clear(); + transCatData.clear(); + transLocData.clear(); + transLocationCategory.clear(); + transCompactData.clear(); + singleData.clear(); + } + + @Override + public void keyTyped(char c, int i) { + super.keyTyped(c, i); + if (currentTab == 10) { + if (getTextField(55) != null && getTextField(55).isFocused()) { + String newSearch = getTextField(55).getText().toLowerCase(); + if (!questCatSearch.equals(newSearch)) { + questCatSearch = newSearch; + if (questCatScroll != null) + questCatScroll.setList(getSearchList(questCatData, questCatSearch)); + } + } + if (getTextField(56) != null && getTextField(56).isFocused()) { + String newSearch = getTextField(56).getText().toLowerCase(); + if (!questFinishedSearch.equals(newSearch)) { + questFinishedSearch = newSearch; + if (questFinishedScroll != null) + questFinishedScroll.setList(getSearchList(questFinishedData, questFinishedSearch)); + } + } + if (getTextField(57) != null && getTextField(57).isFocused()) { + String newSearch = getTextField(57).getText().toLowerCase(); + if (!questActiveSearch.equals(newSearch)) { + questActiveSearch = newSearch; + if (questActiveScroll != null) + questActiveScroll.setList(getSearchList(questActiveData, questActiveSearch)); + } + } + } + if (currentTab == 11) { + if (viewMode == 0) { + if (getTextField(55) != null && getTextField(55).isFocused()) { + String newSearch = getTextField(55).getText().toLowerCase(); + if (!dialogCatSearch.equals(newSearch)) { + dialogCatSearch = newSearch; + if (dialogCatScroll != null) + dialogCatScroll.setList(getSearchList(dialogCatData, dialogCatSearch)); + } + } + if (getTextField(56) != null && getTextField(56).isFocused()) { + String newSearch = getTextField(56).getText().toLowerCase(); + if (!dialogReadSearch.equals(newSearch)) { + dialogReadSearch = newSearch; + if (dialogReadScroll != null) + dialogReadScroll.setList(getSearchList(dialogReadData, dialogReadSearch)); + } + } + } else { + if (getTextField(55) != null && getTextField(55).isFocused()) { + String newSearch = getTextField(55).getText().toLowerCase(); + if (!dialogCompactSearch.equals(newSearch)) { + dialogCompactSearch = newSearch; + if (dialogCompactScroll != null) + dialogCompactScroll.setList(getSearchList(dialogCompactData, dialogCompactSearch)); + } + } + } + } + if (currentTab == 12) { + if (viewMode == 0) { + if (getTextField(60) != null && getTextField(60).isFocused()) { + String newSearch = getTextField(60).getText().toLowerCase(); + if (!transCatSearch.equals(newSearch)) { + transCatSearch = newSearch; + if (transCatScroll != null) + transCatScroll.setList(getSearchList(transCatData, transCatSearch)); + } + } + if (getTextField(61) != null && getTextField(61).isFocused()) { + String newSearch = getTextField(61).getText().toLowerCase(); + if (!transLocSearch.equals(newSearch)) { + transLocSearch = newSearch; + if (transLocScroll != null) + transLocScroll.setList(getSearchList(transLocData, transLocSearch)); + } + } + } else { + if (getTextField(60) != null && getTextField(60).isFocused()) { + String newSearch = getTextField(60).getText().toLowerCase(); + if (!transCompactSearch.equals(newSearch)) { + transCompactSearch = newSearch; + if (transCompactScroll != null) + transCompactScroll.setList(getSearchList(transCompactData, transCompactSearch)); + } + } + } + } + if (currentTab == 13 || currentTab == 14) { + if (getTextField(70) != null && getTextField(70).isFocused()) { + String newSearch = getTextField(70).getText().toLowerCase(); + if (!singleSearch.equals(newSearch)) { + singleSearch = newSearch; + if (singleScroll != null) + singleScroll.setList(getSearchList(singleData, singleSearch)); + } + } + } + } + + @Override + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + if ((currentTab == 10 || currentTab == 11 || currentTab == 12) && viewMode == 0) { + int regionLeft = leftMargin; + if (currentTab == 10) { + int dividerX1 = regionLeft + dividerOffset1; + int dividerX2 = regionLeft + dividerOffset2; + int regionTop = guiTop + 30; + int regionHeight = 150; + int dividerLineHeight = 20; + int dividerLineYOffset = (regionHeight - dividerLineHeight) / 2; + if (mouseX >= dividerX1 && mouseX <= dividerX1 + dividerWidth && + mouseY >= regionTop + dividerLineYOffset && mouseY <= regionTop + dividerLineYOffset + dividerLineHeight) { + isResizing = true; + draggingDivider = 1; + initialDragX = mouseX; + return; + } + if (mouseX >= dividerX2 && mouseX <= dividerX2 + dividerWidth && + mouseY >= regionTop + dividerLineYOffset && mouseY <= regionTop + dividerLineYOffset + dividerLineHeight) { + isResizing = true; + draggingDivider = 2; + initialDragX = mouseX; + return; + } + } else { + int dividerX = regionLeft + dividerOffset1; + int regionTop = guiTop + 30; + int regionHeight = 150; + int dividerLineHeight = 20; + int dividerLineYOffset = (regionHeight - dividerLineHeight) / 2; + if (mouseX >= dividerX && mouseX <= dividerX + dividerWidth && + mouseY >= regionTop + dividerLineYOffset && mouseY <= regionTop + dividerLineYOffset + dividerLineHeight) { + isResizing = true; + draggingDivider = 1; + initialDragX = mouseX; + return; + } + } + } + super.mouseClicked(mouseX, mouseY, mouseButton); + } + + @Override + public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + if (isResizing) { + int dx = mouseX - initialDragX; + initialDragX = mouseX; + if (currentTab == 10) { + if (draggingDivider == 1) { + dividerOffset1 += dx; + int regionLeft = leftMargin; + if (dividerOffset1 < minScrollWidth) + dividerOffset1 = minScrollWidth; + if (dividerOffset1 > dividerOffset2 - dividerWidth - minScrollWidth) + dividerOffset1 = dividerOffset2 - dividerWidth - minScrollWidth; + } + if (draggingDivider == 2) { + dividerOffset2 += dx; + int regionLeft = leftMargin; + int regionRight = rightMargin; + if (dividerOffset2 < dividerOffset1 + dividerWidth + minScrollWidth) + dividerOffset2 = dividerOffset1 + dividerWidth + minScrollWidth; + if (dividerOffset2 > (regionRight - regionLeft) - minScrollWidth) + dividerOffset2 = (regionRight - regionLeft) - minScrollWidth; + } + int regionLeft = leftMargin; + int regionRight = rightMargin; + int dividerX1 = regionLeft + dividerOffset1; + int dividerX2 = regionLeft + dividerOffset2; + if (questCatScroll != null) + questCatScroll.setSize(dividerX1 - regionLeft, 150); + if (questFinishedScroll != null) { + questFinishedScroll.guiLeft = dividerX1 + dividerWidth; + questFinishedScroll.setSize(dividerX2 - dividerX1 - dividerWidth, 150); + } + if (questActiveScroll != null) { + questActiveScroll.guiLeft = dividerX2 + dividerWidth; + questActiveScroll.setSize(regionRight - dividerX2 - dividerWidth, 150); + } + if (getTextField(55) != null) + getTextField(55).width = dividerX1 - regionLeft; + if (getTextField(56) != null) + getTextField(56).width = dividerX2 - dividerX1 - dividerWidth; + if (getTextField(57) != null) + getTextField(57).width = regionRight - dividerX2 - dividerWidth; + } else if ((currentTab == 11 || currentTab == 12) && viewMode == 0) { + int regionLeft = leftMargin; + int regionRight = rightMargin; + dividerOffset1 += dx; + if (dividerOffset1 < minScrollWidth) + dividerOffset1 = minScrollWidth; + if (dividerOffset1 > (regionRight - regionLeft) - dividerWidth - minScrollWidth) + dividerOffset1 = (regionRight - regionLeft) - dividerWidth - minScrollWidth; + int dividerX = regionLeft + dividerOffset1; + if (currentTab == 11) { + if (dialogCatScroll != null) + dialogCatScroll.setSize(dividerX - regionLeft, 150); + if (dialogReadScroll != null) { + dialogReadScroll.guiLeft = dividerX + dividerWidth; + dialogReadScroll.setSize(regionRight - dividerX - dividerWidth, 150); + } + if (getTextField(55) != null) + getTextField(55).width = dividerX - regionLeft; + if (getTextField(56) != null) + getTextField(56).width = regionRight - dividerX - dividerWidth; + } else { + if (transCatScroll != null) + transCatScroll.setSize(dividerX - regionLeft, 150); + if (transLocScroll != null) { + transLocScroll.guiLeft = dividerX + dividerWidth; + transLocScroll.setSize(regionRight - dividerX - dividerWidth, 150); + } + if (getTextField(60) != null) + getTextField(60).width = dividerX - regionLeft; + if (getTextField(61) != null) + getTextField(61).width = regionRight - dividerX - dividerWidth; + } + } + return; + } + super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); + } + + @Override + protected void mouseMovedOrUp(int mouseX, int mouseY, int state) { + if (isResizing) { + isResizing = false; + draggingDivider = 0; + return; + } + super.mouseMovedOrUp(mouseX, mouseY, state); + } + + @Override + public void confirmClicked(boolean confirm, int id) { + if (confirm && id == 100 + currentTab) { + int removeId = -1; + String selected = null; + switch (currentTab) { + case 10: + if (questFinishedScroll != null && questFinishedScroll.getSelected() != null) { + selected = questFinishedScroll.getSelected(); + removeId = questFinishedData.get(selected); + } else if (questActiveScroll != null && questActiveScroll.getSelected() != null) { + selected = questActiveScroll.getSelected(); + removeId = questActiveData.get(selected); + } + if (removeId != -1) + PacketClient.sendClient(new PlayerDataRemovePacket(EnumPlayerData.Quest, playerName, removeId)); + break; + case 11: + if (viewMode == 0) { + if (dialogReadScroll != null && dialogReadScroll.getSelected() != null) { + selected = dialogReadScroll.getSelected(); + removeId = dialogReadData.get(selected); + } + } else { + if (dialogCompactScroll != null && dialogCompactScroll.getSelected() != null) { + selected = dialogCompactScroll.getSelected(); + removeId = dialogCompactData.get(selected); + } + } + if (removeId != -1) + PacketClient.sendClient(new PlayerDataRemovePacket(EnumPlayerData.Dialog, playerName, removeId)); + break; + case 12: + if (viewMode == 0) { + if (transLocScroll != null && transLocScroll.getSelected() != null) { + selected = transLocScroll.getSelected(); + removeId = transLocData.get(selected); + } + } else { + if (transCompactScroll != null && transCompactScroll.getSelected() != null) { + selected = transCompactScroll.getSelected(); + removeId = transCompactData.get(selected); + } + } + if (removeId != -1) + PacketClient.sendClient(new PlayerDataRemovePacket(EnumPlayerData.Transport, playerName, removeId)); + break; + case 13: + case 14: + if (singleScroll != null && singleScroll.getSelected() != null) { + selected = singleScroll.getSelected(); + removeId = singleData.get(selected); + } + if (removeId != -1) { + EnumPlayerData type = (currentTab == 13) ? EnumPlayerData.Bank : EnumPlayerData.Factions; + PacketClient.sendClient(new PlayerDataRemovePacket(type, playerName, removeId)); + } + break; + default: + break; + } + } + NoppesUtil.openGUI(mc.thePlayer, this); + } + + // In setData, for quests we now extract category and remove the suffix from the displayed quest title. + public void setData(Vector list, HashMap data, int dataType) { + lastDataType = dataType; + if (currentTab == 10 && viewMode == 0 && (dataType == 11 || dataType == 12)) { + if (dataType == 11) { + questFinishedData.clear(); + questFinishedCategory.clear(); + for (String key : data.keySet()) { + int colon = key.indexOf(":"); + int paren = key.lastIndexOf("("); + if (colon != -1 && paren != -1) { + String category = key.substring(0, colon).trim(); + String questName = key.substring(colon + 1, paren).trim(); + questFinishedData.put(questName, data.get(key)); + questFinishedCategory.put(questName, category); + if (!questCatData.containsKey(category)) + questCatData.put(category, -1); + } else { + questFinishedData.put(key, data.get(key)); + } + } + if (questFinishedScroll != null) + questFinishedScroll.setList(getSearchList(questFinishedData, questFinishedSearch)); + } else if (dataType == 12) { + questActiveData.clear(); + questActiveCategory.clear(); + for (String key : data.keySet()) { + int colon = key.indexOf(":"); + int paren = key.lastIndexOf("("); + if (colon != -1 && paren != -1) { + String category = key.substring(0, colon).trim(); + String questName = key.substring(colon + 1, paren).trim(); + questActiveData.put(questName, data.get(key)); + questActiveCategory.put(questName, category); + if (!questCatData.containsKey(category)) + questCatData.put(category, -1); + } else { + questActiveData.put(key, data.get(key)); + } + } + if (questActiveScroll != null) + questActiveScroll.setList(getSearchList(questActiveData, questActiveSearch)); + } + if (questCatScroll != null) + questCatScroll.setList(new ArrayList<>(questCatData.keySet())); + return; + } + switch (dataType) { + case 10: + questCatData.clear(); + questCatData.putAll(data); + if (questCatScroll != null) + questCatScroll.setList(getSearchList(questCatData, questCatSearch)); + break; + case 20: + dialogCatData.clear(); + dialogCatData.putAll(data); + // For dialogs, split key into category and title: + dialogCategory.clear(); + HashMap temp = new HashMap<>(); + for (String key : data.keySet()) { + int colon = key.indexOf(":"); + if (colon != -1) { + String cat = key.substring(0, colon).trim(); + String title = key.substring(colon + 1).trim(); + temp.put(title, data.get(key)); + dialogCategory.put(title, cat); + if (!dialogCatData.containsKey(cat)) + dialogCatData.put(cat, -1); + } else { + temp.put(key, data.get(key)); + } + } + dialogCatData.putAll(temp); + if (dialogCatScroll != null) + dialogCatScroll.setList(getSearchList(dialogCatData, dialogCatSearch)); + break; + case 21: + dialogReadData.clear(); + dialogReadData.putAll(data); + if (dialogReadScroll != null) + dialogReadScroll.setList(getSearchList(dialogReadData, dialogReadSearch)); + break; + case 22: + dialogCompactData.clear(); + dialogCompactData.putAll(data); + if (dialogCompactScroll != null) + dialogCompactScroll.setList(getSearchList(dialogCompactData, dialogCompactSearch)); + break; + case 30: + transCatData.clear(); + transCatData.putAll(data); + if (transCatScroll != null) + transCatScroll.setList(getSearchList(transCatData, transCatSearch)); + break; + case 31: + transLocData.clear(); + transLocData.putAll(data); + // For transports, split key into category and location name: + transLocationCategory.clear(); + HashMap temp2 = new HashMap<>(); + for (String key : data.keySet()) { + int colon = key.indexOf(":"); + if (colon != -1) { + String cat = key.substring(0, colon).trim(); + String loc = key.substring(colon + 1).trim(); + temp2.put(loc, data.get(key)); + transLocationCategory.put(loc, cat); + if (!transCatData.containsKey(cat)) + transCatData.put(cat, -1); + } else { + temp2.put(key, data.get(key)); + } + } + transLocData.putAll(temp2); + if (transLocScroll != null) + transLocScroll.setList(getSearchList(transLocData, transLocSearch)); + break; + case 32: + transCompactData.clear(); + transCompactData.putAll(data); + if (transCompactScroll != null) + transCompactScroll.setList(getSearchList(transCompactData, transCompactSearch)); + break; + case 40: + singleData.clear(); + singleData.putAll(data); + if (singleScroll != null) + singleScroll.setList(getSearchList(singleData, singleSearch)); + break; + default: + break; + } + } + + @Override + public void setData(Vector list, HashMap data) { + setData(list, data, lastDataType); + } + + @Override + public void setSelected(String selected) { + // Handled in customScrollClicked. + } + + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) { + if (currentTab == 10) { + if (scroll.id == 0) { + selectedQuestCategory = scroll.getSelected(); + questFinishedScroll.setList(filterQuestsByCategory(questFinishedData, questFinishedCategory, selectedQuestCategory)); + questActiveScroll.setList(filterQuestsByCategory(questActiveData, questActiveCategory, selectedQuestCategory)); + } else if (scroll.id == 1) { + lastDataType = 11; + if (questActiveScroll != null) + questActiveScroll.setSelected(null); + } else if (scroll.id == 2) { + lastDataType = 12; + if (questFinishedScroll != null) + questFinishedScroll.setSelected(null); + } + } else if (currentTab == 11) { + if (viewMode == 0) { + if (scroll.id == 0) { + selectedDialogCategory = scroll.getSelected(); + dialogReadScroll.setList(filterDialogsByCategory(dialogReadData, dialogCategory, selectedDialogCategory)); + } else if (scroll.id == 1) { + lastDataType = 21; + if (dialogCatScroll != null) + dialogCatScroll.setSelected(null); + } + } else { + lastDataType = 22; + } + } else if (currentTab == 12) { + if (viewMode == 0) { + if (scroll.id == 3) { + selectedTransCategory = scroll.getSelected(); + transLocScroll.setList(filterTransportsByCategory(transLocData, transLocationCategory, selectedTransCategory)); + } else if (scroll.id == 4) { + lastDataType = 31; + if (transCatScroll != null) + transCatScroll.setSelected(null); + } + } else { + lastDataType = 32; + } + } else if (currentTab == 13 || currentTab == 14) { + lastDataType = 40; + } + } + + @Override + public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) { + // Optional double-click behavior. + } + + private List getSearchList(HashMap dataMap, String searchTerm) { + if (searchTerm.isEmpty()) + return new ArrayList<>(dataMap.keySet()); + List list = new ArrayList<>(); + for (String key : dataMap.keySet()) { + if (key.toLowerCase().contains(searchTerm)) + list.add(key); + } + return list; + } + + private List filterQuestsByCategory(HashMap questMap, HashMap catMap, String category) { + List filtered = new ArrayList<>(); + for (String title : questMap.keySet()) { + if (catMap.containsKey(title) && catMap.get(title).equalsIgnoreCase(category)) + filtered.add(title); + } + return filtered; + } + + private List filterDialogsByCategory(HashMap dialogMap, HashMap catMap, String category) { + List filtered = new ArrayList<>(); + for (String title : dialogMap.keySet()) { + if (catMap.containsKey(title) && catMap.get(title).equalsIgnoreCase(category)) + filtered.add(title); + } + return filtered; + } + + private List filterTransportsByCategory(HashMap transMap, HashMap catMap, String category) { + List filtered = new ArrayList<>(); + for (String name : transMap.keySet()) { + if (catMap.containsKey(name) && catMap.get(name).equalsIgnoreCase(category)) + filtered.add(name); + } + return filtered; + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + drawDefaultBackground(); + super.drawScreen(mouseX, mouseY, partialTicks); + } + + @Override + public void close() { + super.close(); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageLinked.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageLinked.java index 4c37aa728..9677742f7 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageLinked.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageLinked.java @@ -26,9 +26,7 @@ import noppes.npcs.client.gui.item.SubGuiLinkedItem; import noppes.npcs.client.gui.util.*; import noppes.npcs.client.renderer.ImageData; -import noppes.npcs.controllers.data.CustomEffect; import noppes.npcs.controllers.data.LinkedItem; -import noppes.npcs.controllers.data.Quest; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; import org.lwjgl.input.Mouse; diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageMagic.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageMagic.java index b5ccdc8e6..e1b35b31e 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageMagic.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageMagic.java @@ -26,7 +26,7 @@ public class GuiNPCManageMagic extends GuiNPCInterface2 { } @Override - protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { if (magicMap != null) { magicMap.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); } 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 4b505c9d3..6b9b02e6f 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java @@ -4,13 +4,14 @@ import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetPacket; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataMapRegenPacket; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataRemovePacket; -import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; - +import noppes.npcs.client.gui.SubGuiPlayerData; +import noppes.npcs.client.gui.test.SubGuiPlayerDataNew; import noppes.npcs.client.gui.util.*; - import noppes.npcs.constants.EnumPlayerData; +import net.minecraft.util.StatCollector; +import net.minecraft.client.gui.GuiButton; import noppes.npcs.entity.EntityNPCInterface; import java.util.ArrayList; @@ -18,167 +19,136 @@ import java.util.HashMap; import java.util.List; import java.util.Vector; -public class GuiNpcManagePlayerData extends GuiNPCInterface2 implements IScrollData,ICustomScrollListener,GuiYesNoCallback -{ - private GuiCustomScroll scroll; - private String selectedPlayer = null; - private String selected = null; - private HashMap data = new HashMap(); - private EnumPlayerData selection = EnumPlayerData.Players; - private String search = ""; +public class GuiNpcManagePlayerData extends GuiNPCInterface2 implements GuiYesNoCallback, IScrollData, ICustomScrollListener, ISubGuiListener { - public GuiNpcManagePlayerData(EntityNPCInterface npc) - { - super(npc); - PacketClient.sendClient(new PlayerDataGetPacket(selection, "")); + private GuiCustomScroll playerScroll; + private String selectedPlayer = null; + private HashMap playerData = new HashMap<>(); + private String search = ""; + + public GuiNpcManagePlayerData(EntityNPCInterface npcInterface) { + super(npcInterface); + // Request the complete list of players. + PacketClient.sendClient(new PlayerDataGetPacket(EnumPlayerData.Players, "")); } - public void initGui() - { + @Override + public void initGui() { super.initGui(); - scroll = new GuiCustomScroll(this,0, 0); - scroll.setSize(303, 175); - scroll.guiLeft = guiLeft + 4; - scroll.guiTop = guiTop + 16; - addScroll(scroll); + if (playerScroll == null) { + playerScroll = new GuiCustomScroll(this, 0, 0); + } + playerScroll.guiLeft = guiLeft + 4; + playerScroll.guiTop = guiTop + 16; + playerScroll.setSize(303, 175); + addScroll(playerScroll); - addLabel(new GuiNpcLabel(0,"All Players", guiLeft + 10, guiTop + 6)); + addLabel(new GuiNpcLabel(0, StatCollector.translateToLocal("All Players"), guiLeft + 10, guiTop + 6)); - this.addButton(new GuiNpcButton(0, guiLeft + 313, guiTop + 10,98, 20, "selectWorld.deleteButton")); - this.addButton(new GuiNpcButton(1, guiLeft + 313, guiTop + 32,98, 20, "Players")); - this.addButton(new GuiNpcButton(2, guiLeft + 313, guiTop + 54,98, 20, "Quest Data")); - this.addButton(new GuiNpcButton(3, guiLeft + 313, guiTop + 76,98, 20, "Dialog Data")); - this.addButton(new GuiNpcButton(4, guiLeft + 313, guiTop + 98,98, 20, "Transport Data")); - this.addButton(new GuiNpcButton(5, guiLeft + 313, guiTop + 120,98, 20, "Bank Data")); - this.addButton(new GuiNpcButton(6, guiLeft + 313, guiTop + 142,98, 20, "Faction Data")); + addButton(new GuiNpcButton(0, guiLeft + 313, guiTop + 10, 98, 20, StatCollector.translateToLocal("button.delete"))); + addButton(new GuiNpcButton(1, guiLeft + 313, guiTop + 32, 98, 20, StatCollector.translateToLocal("button.view"))); + addButton(new GuiNpcButton(2, guiLeft + 313, guiTop + 54, 98, 20, StatCollector.translateToLocal("button.regenPlayerMap"))); - this.addButton(new GuiNpcButton(7, guiLeft + 313, guiTop + 193,98, 20, "Regen PlayerMap")); + addTextField(new GuiNpcTextField(0, this, fontRendererObj, guiLeft + 4, guiTop + 193, 303, 20, search)); - addTextField(new GuiNpcTextField(0, this, fontRendererObj, guiLeft + 4, guiTop + 193, 303, 20, search)); - getTextField(0).enabled = selection == EnumPlayerData.Players; - - initButtons(); + playerScroll.setList(getSearchList()); } - public void initButtons(){ - getButton(1).setEnabled(selection != EnumPlayerData.Players); - getButton(2).setEnabled(selection != EnumPlayerData.Quest); - getButton(3).setEnabled(selection != EnumPlayerData.Dialog); - getButton(4).setEnabled(selection != EnumPlayerData.Transport); - getButton(5).setEnabled(selection != EnumPlayerData.Bank); - getButton(6).setEnabled(selection != EnumPlayerData.Factions); - - if(selection == EnumPlayerData.Players) - getLabel(0).label = "All Players"; - else - getLabel(0).label = "Selected player: " + selectedPlayer; - } - public void drawScreen(int i, int j, float f) - { + @Override + public void drawScreen(int i, int j, float f) { super.drawScreen(i, j, f); - scroll.drawScreen(i, j, f); + playerScroll.drawScreen(i, j, f); } - public void mouseClicked(int i, int j, int k) - { - super.mouseClicked(i, j, k); - if(k == 0 && scroll != null) - scroll.mouseClicked(i, j, k); + @Override + public void mouseClicked(int i, int j, int k) {; + super.mouseClicked(i, j, k); + if (k == 0 && playerScroll != null) + playerScroll.mouseClicked(i, j, k); } - public void keyTyped(char c, int i) - { - super.keyTyped(c, i); + @Override + public void save() {} - if(search.equals(getTextField(0).getText())) - return; - search = getTextField(0).getText().toLowerCase(); - scroll.setList(getSearchList()); - } - private List getSearchList(){ - if(search.isEmpty()) - return new ArrayList(this.data.keySet()); - List list = new ArrayList(); - for(String name : data.keySet()){ - if(name.toLowerCase().contains(search)) - list.add(name); - } - return list; + @Override + public void keyTyped(char c, int i) { + super.keyTyped(c, i); + String newText = getTextField(0).getText(); + if (!search.equals(newText)) { + search = newText.toLowerCase(); + playerScroll.setList(getSearchList()); + } } - protected void actionPerformed(GuiButton guibutton) - { - int id = guibutton.id; - if(id < 7){ - GuiNpcTextField tf = getTextField(0); - if(tf != null){ - tf.setText(""); - } - search = ""; - if(id == 0) - { - if(selected != null){ - if(selection == EnumPlayerData.Players) - PacketClient.sendClient(new PlayerDataRemovePacket(selection, selectedPlayer, selected)); - else - PacketClient.sendClient(new PlayerDataRemovePacket(selection, selectedPlayer, data.get(selected))); - data.clear(); - } - selected = null; - } - if(id >= 1 && id <= 6) - { - if(selectedPlayer == null && id != 1) - return; - selection = EnumPlayerData.values()[id - 1]; - initButtons(); - scroll.clear(); - data.clear(); - - PacketClient.sendClient(new PlayerDataGetPacket(selection, selectedPlayer)); - selected = null; - } - } - if(id == 7){ - displayGuiScreen(new GuiYesNo(this, "Warning", "Do not operate on PlayerData as its regenerating", 1)); - } + private List getSearchList() { + if (search.isEmpty()) + return new ArrayList<>(playerData.keySet()); + List list = new ArrayList<>(); + for (String name : playerData.keySet()) { + if (name.toLowerCase().contains(search)) + list.add(name); + } + return list; } - @Override - public void save() { - } + @Override + public void actionPerformed(GuiButton button) { + int id = button.id; + if (id == 0) { + if (selectedPlayer != null) { + displayGuiScreen(new GuiYesNo(this, selectedPlayer, StatCollector.translateToLocal("gui.deleteconfirm"), 0)); + } + } + if (id == 1) { + if (selectedPlayer != null) { + setSubGui(new SubGuiPlayerDataNew(selectedPlayer)); + } + } + if (id == 2) { + displayGuiScreen(new GuiYesNo(this, StatCollector.translateToLocal("gui.warning"), StatCollector.translateToLocal("gui.regenconfirm"), 1)); + } + } - @Override - public void setData(Vector list, HashMap data) { - this.data.putAll(data); + @Override + public void confirmClicked(boolean confirm, int id) { + if (confirm) { + if (id == 0) { + PacketClient.sendClient(new PlayerDataRemovePacket(EnumPlayerData.Players, selectedPlayer, null)); + playerData.remove(selectedPlayer); + selectedPlayer = null; + playerScroll.setList(getSearchList()); + } + if (id == 1) { + PacketClient.sendClient(new PlayerDataMapRegenPacket()); + close(); + } + } else { + displayGuiScreen(this); + } + } - scroll.setList(getSearchList()); + // IScrollData interface. + @Override + public void setData(Vector list, HashMap data) { + playerData.clear(); + playerData.putAll(data); + playerScroll.setList(getSearchList()); + } - if(selection == EnumPlayerData.Players && selectedPlayer != null){ - scroll.setSelected(selectedPlayer); - selected = selectedPlayer; - } - } + // ICustomScrollListener interface. + @Override + public void setSelected(String selected) { + selectedPlayer = selected; + } - @Override - public void setSelected(String selected) { - } + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) { + selectedPlayer = scroll.getSelected(); + } - @Override - public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { - selected = guiCustomScroll.getSelected(); - if(selection == EnumPlayerData.Players) - selectedPlayer = selected; - } + @Override + public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {} - @Override - public void confirmClicked(boolean confirm, int id){ - if(confirm){ - PacketClient.sendClient(new PlayerDataMapRegenPacket()); - close(); - } - else - displayGuiScreen(this); - } + public void subGuiClosed(SubGuiInterface subgui) {} } diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java index 7ec782a8c..0d467129d 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java @@ -390,7 +390,7 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC * Handles mouse dragging while clicking. */ @Override - protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { if (draggingScrollbar) { int mouseDiff = mouseY - lastMouseY; scrollY += (mouseDiff * maxScrollY) / (ySize - 70); diff --git a/src/main/java/noppes/npcs/client/gui/test/IPlayerDataInfo.java b/src/main/java/noppes/npcs/client/gui/test/IPlayerDataInfo.java new file mode 100644 index 000000000..3aef92ad8 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/test/IPlayerDataInfo.java @@ -0,0 +1,11 @@ +package noppes.npcs.client.gui.test; + +import java.util.Map; + +public interface IPlayerDataInfo { + void setQuestData(Map questCategories, Map questActive, Map questFinished); + void setDialogData(Map dialogCategories, Map dialogRead); + void setTransportData(Map transportCategories, Map transportLocations); + void setBankData(Map bankData); + void setFactionData(Map factionData); +} diff --git a/src/main/java/noppes/npcs/client/gui/test/NoppesUtilClientNew.java b/src/main/java/noppes/npcs/client/gui/test/NoppesUtilClientNew.java new file mode 100644 index 000000000..ecb62dc6f --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/test/NoppesUtilClientNew.java @@ -0,0 +1,74 @@ +package noppes.npcs.client.gui.test; + +import io.netty.buffer.ByteBuf; +import kamkeel.npcs.util.ByteBufUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.entity.player.EntityPlayer; +import noppes.npcs.client.gui.util.GuiContainerNPCInterface; +import noppes.npcs.client.gui.util.GuiNPCInterface; +import noppes.npcs.client.gui.util.IScrollData; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Vector; + +public class NoppesUtilClientNew { + + /** + * Handles the incoming large packet with full player data. + * The packet writes: + * - player name (String) + * - questCategories, questActive, questFinished (maps) + * - dialogCategories, dialogRead (maps) + * - transportCategories, transportLocations (maps) + * - bankData, factionData (maps) + * + * The existing PlayerDataController functions are used on the server side; + * here we simply update the active SubGuiPlayerDataNew if present. + */ + public static void handlePlayerData(ByteBuf data, EntityPlayer player) throws IOException { + String playerName = ByteBufUtils.readString(data); + Map questCategories = readMap(data); + Map questActive = readMap(data); + Map questFinished = readMap(data); + Map dialogCategories = readMap(data); + Map dialogRead = readMap(data); + Map transportCategories = readMap(data); + Map transportLocations = readMap(data); + Map bankData = readMap(data); + Map factionData = readMap(data); + + + GuiScreen gui = Minecraft.getMinecraft().currentScreen; + if(gui == null) + return; + if(gui instanceof GuiNPCInterface && ((GuiNPCInterface)gui).hasSubGui()){ + gui = (GuiScreen) ((GuiNPCInterface)gui).getSubGui(); + } + + if(gui instanceof GuiContainerNPCInterface && ((GuiContainerNPCInterface)gui).hasSubGui()){ + gui = (GuiScreen) ((GuiContainerNPCInterface)gui).getSubGui(); + } + if (gui instanceof IPlayerDataInfo) { + IPlayerDataInfo info = (IPlayerDataInfo) gui; + info.setQuestData(questCategories, questActive, questFinished); + info.setDialogData(dialogCategories, dialogRead); + info.setTransportData(transportCategories, transportLocations); + info.setBankData(bankData); + info.setFactionData(factionData); + } + } + + private static Map readMap(ByteBuf data) { + int size = data.readInt(); + Map map = new HashMap<>(); + for (int i = 0; i < size; i++) { + String key = ByteBufUtils.readString(data); + int value = data.readInt(); + map.put(key, value); + } + return map; + } +} diff --git a/src/main/java/noppes/npcs/client/gui/test/NoppesUtilServerNew.java b/src/main/java/noppes/npcs/client/gui/test/NoppesUtilServerNew.java new file mode 100644 index 000000000..4fc9d15d5 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/test/NoppesUtilServerNew.java @@ -0,0 +1,155 @@ +package noppes.npcs.client.gui.test; + +import kamkeel.npcs.controllers.SyncController; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.server.MinecraftServer; +import kamkeel.npcs.network.PacketHandler; +import noppes.npcs.controllers.*; +import noppes.npcs.controllers.data.*; +import noppes.npcs.config.ConfigMain; +import net.minecraft.nbt.NBTTagCompound; +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +public class NoppesUtilServerNew { + + /** + * Retrieves the player's data from the existing PlayerDataController and sends + * a large packet to the client containing all the maps, including categories. + */ + public static void sendPlayerData(String playerName, EntityPlayerMP player) { + PlayerData playerdata; + EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(playerName); + if(pl == null) + playerdata = PlayerDataController.Instance.getDataFromUsername(playerName); + else + playerdata = PlayerDataController.Instance.getPlayerData(pl); + + // Assemble quest maps: + Map questActiveMap = new HashMap<>(); + Map questFinishedMap = new HashMap<>(); + Map questCategoriesMap = new HashMap<>(); + QuestController qc = QuestController.Instance; + PlayerQuestData qData = playerdata.questData; + for (Integer questId : qData.activeQuests.keySet()) { + if(!qc.quests.containsKey(questId)) + continue; + Quest quest = qc.quests.get(questId); + questActiveMap.put(quest.category.title + ": " + quest.title, questId); + if (!questCategoriesMap.containsKey(quest.category.title)) + questCategoriesMap.put(quest.category.title, quest.category.id); + } + for (Integer questId : qData.finishedQuests.keySet()) { + if(!qc.quests.containsKey(questId)) + continue; + Quest quest = qc.quests.get(questId); + questFinishedMap.put(quest.category.title + ": " + quest.title, questId); + if (!questCategoriesMap.containsKey(quest.category.title)) + questCategoriesMap.put(quest.category.title, quest.category.id); + } + + // Assemble dialog maps: + Map dialogReadMap = new HashMap<>(); + Map dialogCategoriesMap = new HashMap<>(); + PlayerDialogData dData = playerdata.dialogData; + for (Integer dialogId : dData.dialogsRead) { + if(!DialogController.Instance.dialogs.containsKey(dialogId)) + continue; + Dialog dialog = DialogController.Instance.dialogs.get(dialogId); + dialogReadMap.put(dialog.category.title + ": " + dialog.title, dialogId); + if (!dialogCategoriesMap.containsKey(dialog.category.title)) + dialogCategoriesMap.put(dialog.category.title, dialog.category.id); + } + + // Assemble transport maps: + Map transportLocationsMap = new HashMap<>(); + Map transportCategoriesMap = new HashMap<>(); + PlayerTransportData tData = playerdata.transportData; + TransportController tc = TransportController.getInstance(); + for (Integer id : tData.transports) { + TransportLocation location = tc.getTransport(id); + if(location == null) + continue; + transportLocationsMap.put(location.category.title + ": " + location.name, id); + if (!transportCategoriesMap.containsKey(location.category.title)) + transportCategoriesMap.put(location.category.title, location.category.id); + } + + // Assemble bank map: + Map bankMap = new HashMap<>(); + PlayerBankData bData = playerdata.bankData; + BankController bc = BankController.getInstance(); + for (Integer bankId : bData.banks.keySet()) { + if(!bc.banks.containsKey(bankId)) + continue; + Bank bank = bc.banks.get(bankId); + bankMap.put(bank.name, bankId); + } + + // Assemble faction map: + Map factionMap = new HashMap<>(); + PlayerFactionData fData = playerdata.factionData; + FactionController fc = FactionController.getInstance(); + for (Integer factionId : fData.factionData.keySet()) { + if(!fc.factions.containsKey(factionId)) + continue; + Faction faction = fc.factions.get(factionId); + factionMap.put(faction.name + "(" + fData.getFactionPoints(factionId) + ")", factionId); + } + + // Send the full packet with categories, active/finished data, dialogs, transports, banks, and factions. + PlayerDataSendPacketNew packet = new PlayerDataSendPacketNew(playerName, + questCategoriesMap, questActiveMap, questFinishedMap, + dialogCategoriesMap, dialogReadMap, + transportCategoriesMap, transportLocationsMap, + bankMap, factionMap); + PacketHandler.Instance.sendToPlayer(packet, player); + } + + /** + * Removes a specific data entry from the player's data. + * + * The tabType parameter is used as follows: + * 0: Quest – remove from both activeQuests and finishedQuests. + * 1: Dialog – remove from dialogsRead. + * 2: Transport – remove from transports. + * 3: Bank – remove from banks. + * 4: Factions – remove from factionData. + * + * The selectedKey is expected to be the string representation of the entry's ID. + */ + public static void removePlayerData(String playerName, int tabType, int value, EntityPlayerMP player) { + EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(playerName); + PlayerData playerdata; + if(pl == null) + playerdata = PlayerDataController.Instance.getDataFromUsername(playerName); + else + playerdata = PlayerDataController.Instance.getPlayerData(pl); + + if(tabType == 0) { // Quest removal + playerdata.questData.activeQuests.remove(value); + playerdata.questData.finishedQuests.remove(value); + } + if(tabType == 1) { // Dialog removal + playerdata.dialogData.dialogsRead.remove(value); + } + if(tabType == 2) { // Transport removal + playerdata.transportData.transports.remove(value); + } + if(tabType == 3) { // Bank removal + playerdata.bankData.banks.remove(value); + } + if(tabType == 4) { // Faction removal + playerdata.factionData.factionData.remove(value); + } + playerdata.save(); + + if(pl != null) { + SyncController.syncPlayer((EntityPlayerMP) pl); + } + // Resend the updated data to the client. + sendPlayerData(playerName, player); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/test/PlayerDataGetPacketNew.java b/src/main/java/noppes/npcs/client/gui/test/PlayerDataGetPacketNew.java new file mode 100644 index 000000000..fe12b0333 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/test/PlayerDataGetPacketNew.java @@ -0,0 +1,47 @@ +package noppes.npcs.client.gui.test; + +import io.netty.buffer.ByteBuf; +import kamkeel.npcs.network.AbstractPacket; +import kamkeel.npcs.network.PacketChannel; +import kamkeel.npcs.network.PacketHandler; +import kamkeel.npcs.network.enums.EnumRequestPacket; +import kamkeel.npcs.util.ByteBufUtils; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; + +import java.io.IOException; + +public final class PlayerDataGetPacketNew extends AbstractPacket { + public static final String packetName = "Request|PlayerDataGetNew"; + private String playerName; + + public PlayerDataGetPacketNew() {} + + public PlayerDataGetPacketNew(String playerName) { + this.playerName = playerName; + } + + @Override + public Enum getType() { + return EnumRequestPacket.PlayerDataGet; + } + + @Override + public PacketChannel getChannel() { + return PacketHandler.REQUEST_PACKET; + } + + @Override + public void sendData(ByteBuf out) throws IOException { + ByteBufUtils.writeString(out, playerName); + } + + @Override + public void receiveData(ByteBuf in, EntityPlayer player) throws IOException { + if (!(player instanceof EntityPlayerMP)) + return; + + String playerName = ByteBufUtils.readString(in); + NoppesUtilServerNew.sendPlayerData(playerName, (EntityPlayerMP) player); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/test/PlayerDataRemovePacketNew.java b/src/main/java/noppes/npcs/client/gui/test/PlayerDataRemovePacketNew.java new file mode 100644 index 000000000..ea5133271 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/test/PlayerDataRemovePacketNew.java @@ -0,0 +1,56 @@ +package noppes.npcs.client.gui.test; + +import io.netty.buffer.ByteBuf; +import kamkeel.npcs.network.AbstractPacket; +import kamkeel.npcs.network.PacketChannel; +import kamkeel.npcs.network.PacketHandler; +import kamkeel.npcs.network.enums.EnumRequestPacket; +import kamkeel.npcs.util.ByteBufUtils; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import noppes.npcs.constants.EnumPlayerData; + +import java.io.IOException; + +public final class PlayerDataRemovePacketNew extends AbstractPacket { + public static final String packetName = "Request|PlayerDataRemoveNew"; + + private String playerName; + private EnumPlayerData tabType; + private int value; + + public PlayerDataRemovePacketNew() {} + + public PlayerDataRemovePacketNew(String playerName, EnumPlayerData tabType, int selectedKey) { + this.playerName = playerName; + this.tabType = tabType; + this.value = selectedKey; + } + + @Override + public Enum getType() { + return EnumRequestPacket.PlayerDataRemove; + } + + @Override + public PacketChannel getChannel() { + return PacketHandler.REQUEST_PACKET; + } + + @Override + public void sendData(ByteBuf out) throws IOException { + ByteBufUtils.writeString(out, playerName); + out.writeInt(tabType.ordinal()); + out.writeInt(this.value); + } + + @Override + public void receiveData(ByteBuf in, EntityPlayer player) throws IOException { + if (!(player instanceof EntityPlayerMP)) + return; + String playerName = ByteBufUtils.readString(in); + int tabType = in.readInt(); + int value = in.readInt(); + NoppesUtilServerNew.removePlayerData(playerName, tabType, value, (EntityPlayerMP) player); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/test/PlayerDataSendPacketNew.java b/src/main/java/noppes/npcs/client/gui/test/PlayerDataSendPacketNew.java new file mode 100644 index 000000000..2352fd063 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/test/PlayerDataSendPacketNew.java @@ -0,0 +1,101 @@ +package noppes.npcs.client.gui.test; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import kamkeel.npcs.network.LargeAbstractPacket; +import kamkeel.npcs.network.PacketChannel; +import kamkeel.npcs.network.PacketHandler; +import kamkeel.npcs.network.enums.EnumDataPacket; +import kamkeel.npcs.util.ByteBufUtils; +import net.minecraft.entity.player.EntityPlayer; +import java.io.IOException; +import java.util.Map; + +public final class PlayerDataSendPacketNew extends LargeAbstractPacket { + public static final String packetName = "Large|PlayerDataSendNew"; + + private String playerName; + private Map questCategories; + private Map questActive; + private Map questFinished; + + private Map dialogCategories; + private Map dialogRead; + + private Map transportCategories; + private Map transportLocations; + + private Map bankData; + private Map factionData; + + public PlayerDataSendPacketNew() {} + + public PlayerDataSendPacketNew(String playerName, + Map questCategories, Map questActive, Map questFinished, + Map dialogCategories, Map dialogRead, + Map transportCategories, Map transportLocations, + Map bankData, Map factionData) { + this.playerName = playerName; + this.questCategories = questCategories; + this.questActive = questActive; + this.questFinished = questFinished; + this.dialogCategories = dialogCategories; + this.dialogRead = dialogRead; + this.transportCategories = transportCategories; + this.transportLocations = transportLocations; + this.bankData = bankData; + this.factionData = factionData; + } + + @Override + public Enum getType() { + return EnumDataPacket.PLAYER_DATA; + } + + @Override + public PacketChannel getChannel() { + return PacketHandler.DATA_PACKET; + } + + @Override + protected byte[] getData() throws IOException { + ByteBuf buffer = Unpooled.buffer(); + // Write player name: + ByteBufUtils.writeString(buffer, playerName); + // Write quest data maps: + writeMap(buffer, questCategories); + writeMap(buffer, questActive); + writeMap(buffer, questFinished); + // Write dialog data maps: + writeMap(buffer, dialogCategories); + writeMap(buffer, dialogRead); + // Write transport data maps: + writeMap(buffer, transportCategories); + writeMap(buffer, transportLocations); + // Write bank data map: + writeMap(buffer, bankData); + // Write faction data map: + writeMap(buffer, factionData); + + byte[] bytes = new byte[buffer.readableBytes()]; + buffer.readBytes(bytes); + return bytes; + } + + private void writeMap(ByteBuf buffer, Map map) { + if (map != null) { + buffer.writeInt(map.size()); + for (Map.Entry entry : map.entrySet()) { + ByteBufUtils.writeString(buffer, entry.getKey()); + buffer.writeInt(entry.getValue()); + } + } else { + buffer.writeInt(0); + } + } + + @Override + protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException { + NoppesUtilClientNew.handlePlayerData(data, player); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/test/PlayerDataTab.java b/src/main/java/noppes/npcs/client/gui/test/PlayerDataTab.java new file mode 100644 index 000000000..713836dd3 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/test/PlayerDataTab.java @@ -0,0 +1,9 @@ +package noppes.npcs.client.gui.test; + +public enum PlayerDataTab { + QUEST, + DIALOG, + TRANSPORT, + BANK, + FACTION; +} diff --git a/src/main/java/noppes/npcs/client/gui/test/SubGuiPlayerDataNew.java b/src/main/java/noppes/npcs/client/gui/test/SubGuiPlayerDataNew.java new file mode 100644 index 000000000..bd382d07f --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/test/SubGuiPlayerDataNew.java @@ -0,0 +1,864 @@ +package noppes.npcs.client.gui.test; + +import kamkeel.npcs.network.PacketClient; +import noppes.npcs.client.CustomNpcResourceListener; +import noppes.npcs.client.gui.util.*; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.util.StatCollector; +import noppes.npcs.constants.EnumPlayerData; +import org.lwjgl.input.Mouse; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class SubGuiPlayerDataNew extends SubGuiInterface implements IPlayerDataInfo, ICustomScrollListener { + + // Tabs: 10 = Quest, 11 = Dialog, 12 = Transport, 13 = Bank, 14 = Faction. + private int currentTab = 10; + // View mode: 0 = Categorical (3 or 2 scrolls), 1 = Compact (2 or 1 scroll). + private int viewMode = 0; + + // Quest Tab components: + protected GuiCustomScroll questCatScroll, questActiveScroll, questFinishedScroll; + private String questCatSearch = "", questActiveSearch = "", questFinishedSearch = ""; + private HashMap questCatData = new HashMap<>(); + private HashMap questActiveData = new HashMap<>(); + private HashMap questFinishedData = new HashMap<>(); + private String selectedQuestCategory = ""; + + // Dialog Tab components: + protected GuiCustomScroll dialogCatScroll, dialogReadScroll, dialogCompactScroll; + private String dialogCatSearch = "", dialogReadSearch = "", dialogCompactSearch = ""; + private HashMap dialogCatData = new HashMap<>(); + private HashMap dialogReadData = new HashMap<>(); + private String selectedDialogCategory = ""; + + // Transport Tab components: + protected GuiCustomScroll transCatScroll, transLocScroll, transCompactScroll; + private String transCatSearch = "", transLocSearch = "", transCompactSearch = ""; + private HashMap transCatData = new HashMap<>(); + private HashMap transLocData = new HashMap<>(); + private String selectedTransCategory = ""; + + // Bank and Faction tabs – separate data and one scroll: + protected GuiCustomScroll singleScroll; + private String singleSearch = ""; + private HashMap bankData = new HashMap<>(); + private HashMap factionData = new HashMap<>(); + + // Divider/resizing variables for categorical mode. + // For Quest tab: in categorical mode we use 2 dividers (3 scrolls) + // In compact mode for Quests we use one divider between the two scrolls. + private int dividerOffset1 = 0; // In categorical: width of left scroll; in compact for quests: width of left scroll. + private int dividerOffset2 = 0; // Only for Quest categorical mode. + private final int dividerWidth = 5; + private final int minScrollWidth = 50; + private boolean isResizing = false; + private int resizingDivider = 0; + private int initialDragX = 0; + + // Layout constants. + private final int leftPadding = 6; + private final int rightPadding = 6; + private final int scrollTopOffset = 30; + private final int verticalGapAboveTF = 3; + private final int textFieldHeight = 20; + private final int verticalGapBelowTF = 3; + + // The player name for which we are displaying data. + private String playerName; + + public SubGuiPlayerDataNew(String playerName) { + this.playerName = playerName; + xSize = 420; + ySize = 215; + setBackground("menubg.png"); + closeOnEsc = true; + PacketClient.sendClient(new PlayerDataGetPacketNew(playerName)); + } + + @Override + public void handleMouseInput() { + super.handleMouseInput(); + } + + @Override + public void initGui() { + super.initGui(); + // Top tab buttons: + GuiMenuTopButton btnQuest = new GuiMenuTopButton(10, guiLeft + 4, guiTop - 10, StatCollector.translateToLocal("tab.quests")); + GuiMenuTopButton btnDialog = new GuiMenuTopButton(11, btnQuest.xPosition + btnQuest.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.dialog")); + GuiMenuTopButton btnTransport = new GuiMenuTopButton(12, btnDialog.xPosition + btnDialog.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.transport")); + GuiMenuTopButton btnBank = new GuiMenuTopButton(13, btnTransport.xPosition + btnTransport.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.bank")); + GuiMenuTopButton btnFaction = new GuiMenuTopButton(14, btnBank.xPosition + btnBank.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.faction")); + GuiMenuTopButton close = new GuiMenuTopButton(-5, guiLeft + xSize - 22, guiTop - 10, "X"); + + btnQuest.active = (currentTab == 10); + btnDialog.active = (currentTab == 11); + btnTransport.active = (currentTab == 12); + btnBank.active = (currentTab == 13); + btnFaction.active = (currentTab == 14); + addTopButton(btnQuest); + addTopButton(btnDialog); + addTopButton(btnTransport); + addTopButton(btnBank); + addTopButton(btnFaction); + addTopButton(close); + + // Mode toggle button (50px wide) + if (currentTab == 10 || currentTab == 11 || currentTab == 12) { + String modeText = viewMode == 0 ? StatCollector.translateToLocal("view.categorical") : StatCollector.translateToLocal("view.compact"); + addButton(new GuiNpcButton(20, guiLeft + xSize - 60, guiTop + 10, 50, 20, modeText)); + } + + guiTop += 7; + + + // Initialize components for the current tab: + switch (currentTab) { + case 10: initQuestTab(); break; + case 11: initDialogTab(); break; + case 12: initTransportTab(); break; + case 13: + case 14: initSingleTab(); break; + } + // Delete button (50px wide) + addButton(new GuiNpcButton(30, guiLeft + xSize - 60, guiTop + ySize - 30, 50, 20, StatCollector.translateToLocal("button.delete"))); + } + + private int getScrollHeight() { + return ySize - (scrollTopOffset + verticalGapAboveTF + textFieldHeight + verticalGapBelowTF); + } + + private int getTextFieldY() { + return guiTop + scrollTopOffset + getScrollHeight() + verticalGapAboveTF; + } + + // Init Quest Tab. + private void initQuestTab() { + int regionLeft = guiLeft + leftPadding; + int regionRight = guiLeft + xSize - rightPadding; + int availableWidth = regionRight - regionLeft; + int scrollHeight = getScrollHeight(); + + if (viewMode == 0) { // Categorical: 3 scrolls. + if (!isResizing) { + dividerOffset1 = (availableWidth - 2 * dividerWidth) / 3; + dividerOffset2 = dividerOffset1 + dividerWidth + (availableWidth - 2 * dividerWidth) / 3; + } + if (questCatScroll == null) questCatScroll = new GuiCustomScroll(this, 0, 0); + questCatScroll.guiLeft = regionLeft; + questCatScroll.guiTop = guiTop + scrollTopOffset; + questCatScroll.setSize(dividerOffset1, scrollHeight); + questCatScroll.setList(new ArrayList<>(questCatData.keySet())); + questCatScroll.selected = -1; + questCatSearch = ""; + addScroll(questCatScroll); + addLabel(new GuiNpcLabel(1000, "Categories", regionLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); + + if (questFinishedScroll == null) questFinishedScroll = new GuiCustomScroll(this, 1, 0); + questFinishedScroll.guiLeft = regionLeft + dividerOffset1 + dividerWidth; + questFinishedScroll.guiTop = guiTop + scrollTopOffset; + questFinishedScroll.setSize(dividerOffset2 - dividerOffset1 - dividerWidth, scrollHeight); + questFinishedScroll.setList(new ArrayList<>()); + questFinishedScroll.selected = -1; + questFinishedSearch = ""; + addScroll(questFinishedScroll); + addLabel(new GuiNpcLabel(1001, "Finished", regionLeft + dividerOffset1 + dividerWidth, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); + + if (questActiveScroll == null) + questActiveScroll = new GuiCustomScroll(this, 2, 0); + + questActiveScroll.guiLeft = regionLeft + dividerOffset2 + dividerWidth; + questActiveScroll.guiTop = guiTop + scrollTopOffset; + questActiveScroll.setSize(regionRight - (regionLeft + dividerOffset2 + dividerWidth), scrollHeight); + questActiveScroll.setList(new ArrayList<>()); + questActiveScroll.selected = -1; + questActiveSearch = ""; + addScroll(questActiveScroll); + addLabel(new GuiNpcLabel(1002, "Active", regionLeft + dividerOffset2 + dividerWidth, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); + + addTextField(new GuiNpcTextField(55, this, fontRendererObj, regionLeft, getTextFieldY(), dividerOffset1, textFieldHeight, questCatSearch)); + addTextField(new GuiNpcTextField(56, this, fontRendererObj, regionLeft + dividerOffset1 + dividerWidth, getTextFieldY(), dividerOffset2 - dividerOffset1 - dividerWidth, textFieldHeight, questFinishedSearch)); + addTextField(new GuiNpcTextField(57, this, fontRendererObj, regionLeft + dividerOffset2 + dividerWidth, getTextFieldY(), regionRight - (regionLeft + dividerOffset2 + dividerWidth), textFieldHeight, questActiveSearch)); + } else { // Compact: 2 scrolls with resizable divider. + // Default divider for compact mode. + if (!isResizing) { + dividerOffset1 = (availableWidth - dividerWidth) / 2; + } + if (questFinishedScroll == null) questFinishedScroll = new GuiCustomScroll(this, 1, 0); + questFinishedScroll.guiLeft = regionLeft; + questFinishedScroll.guiTop = guiTop + scrollTopOffset; + questFinishedScroll.setSize(dividerOffset1, scrollHeight); + questFinishedScroll.setList(new ArrayList<>(questFinishedData.keySet())); + questFinishedSearch = ""; + addScroll(questFinishedScroll); + addLabel(new GuiNpcLabel(1003, "Finished", regionLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); + + if (questActiveScroll == null) questActiveScroll = new GuiCustomScroll(this, 2, 0); + questActiveScroll.guiLeft = regionLeft + dividerOffset1 + dividerWidth; + questActiveScroll.guiTop = guiTop + scrollTopOffset; + questActiveScroll.setSize(availableWidth - dividerOffset1 - dividerWidth, scrollHeight); + questActiveScroll.setList(new ArrayList<>(questActiveData.keySet())); + questActiveSearch = ""; + addScroll(questActiveScroll); + addLabel(new GuiNpcLabel(1004, "Active", regionLeft + dividerOffset1 + dividerWidth, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); + + addTextField(new GuiNpcTextField(55, this, fontRendererObj, regionLeft, getTextFieldY(), dividerOffset1, textFieldHeight, questFinishedSearch)); + addTextField(new GuiNpcTextField(56, this, fontRendererObj, regionLeft + dividerOffset1 + dividerWidth, getTextFieldY(), availableWidth - dividerOffset1 - dividerWidth, textFieldHeight, questActiveSearch)); + } + } + + private void initDialogTab() { + int regionLeft = guiLeft + leftPadding; + int regionRight = guiLeft + xSize - rightPadding; + int availableWidth = regionRight - regionLeft; + int scrollHeight = getScrollHeight(); + if (viewMode == 0) { // Categorical: 2 scrolls. + if (!isResizing) { + dividerOffset1 = (availableWidth - dividerWidth) / 2; + } + if (dialogCatScroll == null) dialogCatScroll = new GuiCustomScroll(this, 0, 0); + dialogCatScroll.guiLeft = regionLeft; + dialogCatScroll.guiTop = guiTop + scrollTopOffset; + dialogCatScroll.setSize(dividerOffset1, scrollHeight); + dialogCatScroll.setList(new ArrayList<>(dialogCatData.keySet())); + addScroll(dialogCatScroll); + addLabel(new GuiNpcLabel(2000, "Categories", regionLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); + + if (dialogReadScroll == null) dialogReadScroll = new GuiCustomScroll(this, 1, 0); + dialogReadScroll.guiLeft = regionLeft + dividerOffset1 + dividerWidth; + dialogReadScroll.guiTop = guiTop + scrollTopOffset; + dialogReadScroll.setSize(availableWidth - dividerOffset1 - dividerWidth, scrollHeight); + dialogReadScroll.setList(new ArrayList<>(dialogReadData.keySet())); + addScroll(dialogReadScroll); + addLabel(new GuiNpcLabel(2001, "Read", regionLeft + dividerOffset1 + dividerWidth, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); + + addTextField(new GuiNpcTextField(55, this, fontRendererObj, regionLeft, getTextFieldY(), dividerOffset1, textFieldHeight, dialogCatSearch)); + addTextField(new GuiNpcTextField(56, this, fontRendererObj, regionLeft + dividerOffset1 + dividerWidth, getTextFieldY(), availableWidth - dividerOffset1 - dividerWidth, textFieldHeight, dialogReadSearch)); + } else { // Compact: 1 scroll – no divider. + if (dialogCompactScroll == null) dialogCompactScroll = new GuiCustomScroll(this, 5, 0); + dialogCompactScroll.guiLeft = regionLeft; + dialogCompactScroll.guiTop = guiTop + scrollTopOffset; + dialogCompactScroll.setSize(availableWidth, scrollHeight); + dialogCompactScroll.setList(new ArrayList<>(dialogReadData.keySet())); + addScroll(dialogCompactScroll); + addLabel(new GuiNpcLabel(2002, "All", regionLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); + addTextField(new GuiNpcTextField(55, this, fontRendererObj, regionLeft, getTextFieldY(), availableWidth, textFieldHeight, dialogCompactSearch)); + } + } + + private void initTransportTab() { + int regionLeft = guiLeft + leftPadding; + int regionRight = guiLeft + xSize - rightPadding; + int availableWidth = regionRight - regionLeft; + int scrollHeight = getScrollHeight(); + if (viewMode == 0) { // Categorical: 2 scrolls. + if (!isResizing) { + dividerOffset1 = (availableWidth - dividerWidth) / 2; + } + if (transCatScroll == null) transCatScroll = new GuiCustomScroll(this, 3, 0); + transCatScroll.guiLeft = regionLeft; + transCatScroll.guiTop = guiTop + scrollTopOffset; + transCatScroll.setSize(dividerOffset1, scrollHeight); + transCatScroll.setList(new ArrayList<>(transCatData.keySet())); + addScroll(transCatScroll); + addLabel(new GuiNpcLabel(3000, "Categories", regionLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); + + if (transLocScroll == null) transLocScroll = new GuiCustomScroll(this, 4, 0); + transLocScroll.guiLeft = regionLeft + dividerOffset1 + dividerWidth; + transLocScroll.guiTop = guiTop + scrollTopOffset; + transLocScroll.setSize(availableWidth - dividerOffset1 - dividerWidth, scrollHeight); + transLocScroll.setList(new ArrayList<>(transLocData.keySet())); + addScroll(transLocScroll); + addLabel(new GuiNpcLabel(3001, "Locations", regionLeft + dividerOffset1 + dividerWidth, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); + + addTextField(new GuiNpcTextField(60, this, fontRendererObj, regionLeft, getTextFieldY(), dividerOffset1, textFieldHeight, transCatSearch)); + addTextField(new GuiNpcTextField(61, this, fontRendererObj, regionLeft + dividerOffset1 + dividerWidth, getTextFieldY(), availableWidth - dividerOffset1 - dividerWidth, textFieldHeight, transLocSearch)); + } else { // Compact: 1 scroll – no divider. + if (transCompactScroll == null) transCompactScroll = new GuiCustomScroll(this, 5, 0); + transCompactScroll.guiLeft = regionLeft; + transCompactScroll.guiTop = guiTop + scrollTopOffset; + transCompactScroll.setSize(availableWidth, scrollHeight); + transCompactScroll.setList(new ArrayList<>(transLocData.keySet())); + addScroll(transCompactScroll); + addLabel(new GuiNpcLabel(3002, "All", regionLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); + addTextField(new GuiNpcTextField(60, this, fontRendererObj, regionLeft, getTextFieldY(), availableWidth, textFieldHeight, transCompactSearch)); + } + } + + private void initSingleTab() { + int regionLeft = guiLeft + leftPadding; + int regionRight = guiLeft + xSize - rightPadding; + int availableWidth = regionRight - regionLeft; + int scrollHeight = getScrollHeight(); + if (singleScroll == null) singleScroll = new GuiCustomScroll(this, 0, 0); + singleScroll.guiLeft = regionLeft; + singleScroll.guiTop = guiTop + scrollTopOffset; + if (currentTab == 13) { + singleScroll.setSize(availableWidth, scrollHeight); + singleScroll.setList(new ArrayList<>(bankData.keySet())); + addLabel(new GuiNpcLabel(4000, "Bank", regionLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); + } else { + singleScroll.setSize(availableWidth, scrollHeight); + singleScroll.setList(new ArrayList<>(factionData.keySet())); + addLabel(new GuiNpcLabel(4000, "Faction", regionLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); + } + addScroll(singleScroll); + addTextField(new GuiNpcTextField(70, this, fontRendererObj, regionLeft, getTextFieldY(), availableWidth, textFieldHeight, singleSearch)); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + super.drawScreen(mouseX, mouseY, partialTicks); + int scrollHeight = getScrollHeight(); + int regionLeft = guiLeft + leftPadding; + int regionRight = guiLeft + xSize - rightPadding; + int availableWidth = regionRight - regionLeft; + // In compact mode for Quests (2-scroll) draw divider. + if (currentTab == 10 && viewMode != 0 && !hasSubGui()) { + int dividerX = regionLeft + dividerOffset1; + drawRect(dividerX, guiTop + scrollTopOffset, dividerX + dividerWidth, guiTop + scrollTopOffset + scrollHeight, 0xFF707070); + } + // In categorical mode, draw dividers. + if (currentTab == 10 && viewMode == 0 && !hasSubGui()) { + int dividerX1 = regionLeft + dividerOffset1; + int dividerX2 = regionLeft + dividerOffset2; + drawRect(dividerX1, guiTop + scrollTopOffset, dividerX1 + dividerWidth, guiTop + scrollTopOffset + scrollHeight, 0xFF707070); + drawRect(dividerX2, guiTop + scrollTopOffset, dividerX2 + dividerWidth, guiTop + scrollTopOffset + scrollHeight, 0xFF707070); + } else if ((currentTab == 11 || currentTab == 12) && viewMode == 0 && !hasSubGui()) { + int dividerX = regionLeft + dividerOffset1; + drawRect(dividerX, guiTop + scrollTopOffset, dividerX + dividerWidth, guiTop + scrollTopOffset + scrollHeight, 0xFF707070); + } + // Do not draw any divider for compact mode in Dialog/Transport. + } + + @Override + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + int hitMargin = 3; + int regionTop = guiTop + scrollTopOffset; + int regionBottom = regionTop + getScrollHeight(); + int regionLeft = guiLeft + leftPadding; + int availableWidth = (guiLeft + xSize - rightPadding) - regionLeft; + if (!hasSubGui() && mouseY >= regionTop && mouseY <= regionBottom) { + if (viewMode == 0) { + if (currentTab == 10) { // Categorical: 3 scrolls. + int dividerX1 = regionLeft + dividerOffset1; + int dividerX2 = regionLeft + dividerOffset2; + if (mouseX >= dividerX1 - hitMargin && mouseX <= dividerX1 + dividerWidth + hitMargin) { + isResizing = true; + resizingDivider = 1; + initialDragX = mouseX; + return; + } else if (mouseX >= dividerX2 - hitMargin && mouseX <= dividerX2 + dividerWidth + hitMargin) { + isResizing = true; + resizingDivider = 2; + initialDragX = mouseX; + return; + } + } else if (currentTab == 11 || currentTab == 12) { // Categorical for Dialog/Transport. + int dividerX = regionLeft + dividerOffset1; + if (mouseX >= dividerX - hitMargin && mouseX <= dividerX + dividerWidth + hitMargin) { + isResizing = true; + resizingDivider = 1; + initialDragX = mouseX; + return; + } + } + } else { // Compact mode. + if (currentTab == 10) { // Compact mode for Quests (2 scrolls) + // Use dividerOffset1 as the divider between the two scrolls. + int defaultWidth = (availableWidth - dividerWidth) / 2; + if (!isResizing) dividerOffset1 = defaultWidth; + int dividerX = regionLeft + dividerOffset1; + if (mouseX >= dividerX - hitMargin && mouseX <= dividerX + dividerWidth + hitMargin) { + isResizing = true; + resizingDivider = 1; + initialDragX = mouseX; + return; + } + } + // For Dialog/Transport compact, there's no divider. + } + } + super.mouseClicked(mouseX, mouseY, mouseButton); + } + + @Override + public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + int regionLeft = guiLeft + leftPadding; + int regionRight = guiLeft + xSize - rightPadding; + int availableWidth = regionRight - regionLeft; + if (isResizing) { + int dx = mouseX - initialDragX; + initialDragX = mouseX; + // For Quest tab: + if (currentTab == 10) { + if (viewMode == 0) { // Categorical (3 scrolls) + if (resizingDivider == 1) { + dividerOffset1 += dx; + int maxOffset = dividerOffset2 - dividerWidth - minScrollWidth; + if (dividerOffset1 < minScrollWidth) dividerOffset1 = minScrollWidth; + if (dividerOffset1 > maxOffset) dividerOffset1 = maxOffset; + questCatScroll.setSize(dividerOffset1, getScrollHeight()); + questFinishedScroll.guiLeft = regionLeft + dividerOffset1 + dividerWidth; + questFinishedScroll.setSize(dividerOffset2 - dividerOffset1 - dividerWidth, getScrollHeight()); + questActiveScroll.guiLeft = regionLeft + dividerOffset2 + dividerWidth; + questActiveScroll.setSize(availableWidth - (dividerOffset2 + dividerWidth), getScrollHeight()); + // Update textfields and labels. + GuiNpcTextField tf55 = getTextField(55); + if(tf55 != null) { tf55.xPosition = regionLeft; tf55.width = dividerOffset1; } + GuiNpcTextField tf56 = getTextField(56); + if(tf56 != null) { tf56.xPosition = regionLeft + dividerOffset1 + dividerWidth; tf56.width = dividerOffset2 - dividerOffset1 - dividerWidth; } + GuiNpcTextField tf57 = getTextField(57); + if(tf57 != null) { tf57.xPosition = regionLeft + dividerOffset2 + dividerWidth; tf57.width = availableWidth - (dividerOffset2 + dividerWidth); } + GuiNpcLabel lbl1000 = getLabel(1000); + if(lbl1000 != null) { lbl1000.x = regionLeft; } + GuiNpcLabel lbl1001 = getLabel(1001); + if(lbl1001 != null) { lbl1001.x = regionLeft + dividerOffset1 + dividerWidth; } + GuiNpcLabel lbl1002 = getLabel(1002); + if(lbl1002 != null) { lbl1002.x = regionLeft + dividerOffset2 + dividerWidth; } + } else if (resizingDivider == 2) { + dividerOffset2 += dx; + int minOffset = dividerOffset1 + dividerWidth + minScrollWidth; + int maxOffset = availableWidth - minScrollWidth; + if (dividerOffset2 < minOffset) dividerOffset2 = minOffset; + if (dividerOffset2 > maxOffset) dividerOffset2 = maxOffset; + questFinishedScroll.setSize(dividerOffset2 - dividerOffset1 - dividerWidth, getScrollHeight()); + questActiveScroll.guiLeft = regionLeft + dividerOffset2 + dividerWidth; + questActiveScroll.setSize(availableWidth - (dividerOffset2 + dividerWidth), getScrollHeight()); + GuiNpcTextField tf56 = getTextField(56); + if(tf56 != null) { tf56.xPosition = regionLeft + dividerOffset1 + dividerWidth; tf56.width = dividerOffset2 - dividerOffset1 - dividerWidth; } + GuiNpcTextField tf57 = getTextField(57); + if(tf57 != null) { tf57.xPosition = regionLeft + dividerOffset2 + dividerWidth; tf57.width = availableWidth - (dividerOffset2 + dividerWidth); } + GuiNpcLabel lbl1001 = getLabel(1001); + if(lbl1001 != null) { lbl1001.x = regionLeft + dividerOffset1 + dividerWidth; } + GuiNpcLabel lbl1002 = getLabel(1002); + if(lbl1002 != null) { lbl1002.x = regionLeft + dividerOffset2 + dividerWidth; } + } + } else { // Compact mode for Quests (2 scrolls) + if (resizingDivider == 1) { + dividerOffset1 += dx; + if (dividerOffset1 < minScrollWidth) dividerOffset1 = minScrollWidth; + if (dividerOffset1 > availableWidth - dividerWidth - minScrollWidth) + dividerOffset1 = availableWidth - dividerWidth - minScrollWidth; + questFinishedScroll.setSize(dividerOffset1, getScrollHeight()); + questActiveScroll.guiLeft = regionLeft + dividerOffset1 + dividerWidth; + questActiveScroll.setSize(availableWidth - dividerOffset1 - dividerWidth, getScrollHeight()); + // Update textfields and labels. + GuiNpcTextField tf55 = getTextField(55); + if(tf55 != null) { tf55.xPosition = regionLeft; tf55.width = dividerOffset1; } + GuiNpcTextField tf56 = getTextField(56); + if(tf56 != null) { tf56.xPosition = regionLeft + dividerOffset1 + dividerWidth; tf56.width = availableWidth - dividerOffset1 - dividerWidth; } + GuiNpcLabel lbl1003 = getLabel(1003); + if(lbl1003 != null) { lbl1003.x = regionLeft; } + GuiNpcLabel lbl1004 = getLabel(1004); + if(lbl1004 != null) { lbl1004.x = regionLeft + dividerOffset1 + dividerWidth; } + } + } + } + return; + } + super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); + } + + @Override + protected void mouseMovedOrUp(int mouseX, int mouseY, int state) { + if (isResizing) { + isResizing = false; + resizingDivider = 0; + return; + } + super.mouseMovedOrUp(mouseX, mouseY, state); + } + + @Override + public void keyTyped(char c, int i) { + super.keyTyped(c, i); + GuiNpcTextField tf; + if (currentTab == 10) { + if (viewMode == 0) { + tf = getTextField(55); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!questCatSearch.equals(newText)) { + questCatSearch = newText; + if (questCatScroll != null) { + if (selectedQuestCategory.isEmpty()) + questCatScroll.setList(new ArrayList<>()); + else + questCatScroll.setList(filterList(questCatData, questCatSearch)); + } + } + } + tf = getTextField(56); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!questFinishedSearch.equals(newText)) { + questFinishedSearch = newText; + if (questFinishedScroll != null) + questFinishedScroll.setList( + selectedQuestCategory.isEmpty() ? + new ArrayList<>() : + filterAndTrimListByCategory(questFinishedData, selectedQuestCategory, questFinishedSearch) + ); + } + } + tf = getTextField(57); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!questActiveSearch.equals(newText)) { + questActiveSearch = newText; + if (questActiveScroll != null) + questActiveScroll.setList( + selectedQuestCategory.isEmpty() ? + new ArrayList<>() : + filterAndTrimListByCategory(questActiveData, selectedQuestCategory, questActiveSearch) + ); + } + } + } else { + tf = getTextField(55); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!questFinishedSearch.equals(newText)) { + questFinishedSearch = newText; + if (questFinishedScroll != null) + questFinishedScroll.setList(filterList(questFinishedData, questFinishedSearch)); + } + } + tf = getTextField(56); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!questActiveSearch.equals(newText)) { + questActiveSearch = newText; + if (questActiveScroll != null) + questActiveScroll.setList(filterList(questActiveData, questActiveSearch)); + } + } + } + } else if (currentTab == 11) { + if (viewMode == 0) { + tf = getTextField(55); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!dialogCatSearch.equals(newText)) { + dialogCatSearch = newText; + if (dialogCatScroll != null) + dialogCatScroll.setList(selectedDialogCategory.isEmpty() ? + new ArrayList<>() : + filterList(dialogCatData, dialogCatSearch)); + } + } + tf = getTextField(56); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!dialogReadSearch.equals(newText)) { + dialogReadSearch = newText; + if (dialogReadScroll != null) + dialogReadScroll.setList( + selectedDialogCategory.isEmpty() ? + new ArrayList<>() : + filterAndTrimListByCategory(dialogReadData, selectedDialogCategory, dialogReadSearch) + ); + } + } + } else { + tf = getTextField(55); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!dialogCompactSearch.equals(newText)) { + dialogCompactSearch = newText; + if (dialogCompactScroll != null) + dialogCompactScroll.setList(filterList(dialogReadData, dialogCompactSearch)); + } + } + } + } else if (currentTab == 12) { + if (viewMode == 0) { + tf = getTextField(60); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!transCatSearch.equals(newText)) { + transCatSearch = newText; + if (transCatScroll != null) + transCatScroll.setList(selectedTransCategory.isEmpty() ? + new ArrayList<>() : + filterList(transCatData, transCatSearch)); + } + } + tf = getTextField(61); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!transLocSearch.equals(newText)) { + transLocSearch = newText; + if (transLocScroll != null) + transLocScroll.setList( + selectedTransCategory.isEmpty() ? + new ArrayList<>() : + filterAndTrimListByCategory(transLocData, selectedTransCategory, transLocSearch) + ); + } + } + } else { + tf = getTextField(60); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!transCompactSearch.equals(newText)) { + transCompactSearch = newText; + if (transCompactScroll != null) + transCompactScroll.setList(filterList(transLocData, transCompactSearch)); + } + } + } + } else if (currentTab == 13 || currentTab == 14) { + tf = getTextField(70); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!singleSearch.equals(newText)) { + singleSearch = newText; + if (singleScroll != null) + singleScroll.setList(filterList(currentTab == 13 ? bankData : factionData, singleSearch)); + } + } + } + } + + private List filterList(HashMap data, String search) { + List list = new ArrayList<>(); + for (String key : data.keySet()) { + if (key.toLowerCase().contains(search)) { + list.add(key); + } + } + return list; + } + + private List filterAndTrimListByCategory(HashMap data, String category, String search) { + List list = new ArrayList<>(); + String prefix = category + ":"; + for (String key : data.keySet()) { + if (key.startsWith(prefix)) { + String trimmed = key.substring(prefix.length()).trim(); + if (trimmed.toLowerCase().contains(search)) { + list.add(trimmed); + } + } + } + return list; + } + + @Override + public void actionPerformed(GuiButton button) { + if(button.id == -5){ + close(); + return; + } + if (button.id >= 10 && button.id <= 14) { + currentTab = button.id; + initGui(); + return; + } + if (button.id == 20) { + viewMode = (viewMode == 0) ? 1 : 0; + initGui(); + } else if (button.id == 30) { + Integer selectedID = null; + EnumPlayerData tabType = null; + if (currentTab == 10) { + if(viewMode == 0){ + if(questCatScroll.getSelected() == null) + return; + if (questActiveScroll.getSelected() != null) { + selectedID = questActiveData.get(questCatScroll.getSelected() + ": " + questActiveScroll.getSelected()); + if(selectedID != null){ + questActiveScroll.list.remove(questActiveScroll.selected); + questActiveData.remove(questCatScroll.getSelected() + ": " + questActiveScroll.getSelected()); + } + tabType = EnumPlayerData.Quest; + } else if (questFinishedScroll.getSelected() != null) { + selectedID = questFinishedData.get(questCatScroll.getSelected() + ": " + questFinishedScroll.getSelected()); + if(selectedID != null){ + questFinishedScroll.list.remove(questFinishedScroll.selected); + questFinishedData.remove(questCatScroll.getSelected() + ": " + questFinishedScroll.getSelected()); + } + tabType = EnumPlayerData.Quest; + } + } else { + if (questActiveScroll.getSelected() != null) { + selectedID = questActiveData.get(questActiveScroll.getSelected()); + if(selectedID != null){ + questActiveScroll.list.remove(questActiveScroll.selected); + questActiveData.remove(questActiveScroll.getSelected()); + } + tabType = EnumPlayerData.Quest; + } else if (questFinishedScroll.getSelected() != null) { + selectedID = questFinishedData.get(questFinishedScroll.getSelected()); + if(selectedID != null){ + questFinishedScroll.list.remove(questFinishedScroll.selected); + questFinishedData.remove(questFinishedScroll.getSelected()); + } + tabType = EnumPlayerData.Quest; + } + } + } else if (currentTab == 11) { + if (viewMode == 0) { + if (dialogReadScroll.getSelected() != null && dialogCatScroll.getSelected() != null) { + selectedID = dialogReadData.get(dialogCatScroll.getSelected() + ": " + dialogReadScroll.getSelected()); + if(selectedID != null){ + dialogReadScroll.list.remove(dialogReadScroll.selected); + dialogReadData.remove(dialogCatScroll.getSelected() + ": " + dialogReadScroll.getSelected()); + } + tabType = EnumPlayerData.Dialog; + } + } else { + if (dialogCompactScroll.getSelected() != null) { + selectedID = dialogReadData.get(dialogCompactScroll.getSelected()); + if(selectedID != null){ + dialogCompactScroll.list.remove(dialogCompactScroll.selected); + dialogReadData.remove(dialogCompactScroll.getSelected()); + } + tabType = EnumPlayerData.Dialog; + } + } + } else if (currentTab == 12) { + if (viewMode == 0) { + if (transLocScroll.getSelected() != null && transCatScroll.getSelected() != null) { + selectedID = transLocData.get(transCatScroll.getSelected() + ": " + transLocScroll.getSelected()); + if(selectedID != null){ + transLocScroll.list.remove(transLocScroll.selected); + transLocData.remove(transCatScroll.getSelected() + ": " + transLocScroll.getSelected()); + } + tabType = EnumPlayerData.Transport; + } + } else { + if (transCompactScroll.getSelected() != null) { + selectedID = transLocData.get(transCompactScroll.getSelected()); + if(selectedID != null){ + transCompactScroll.list.remove(transCompactScroll.selected); + transLocData.remove(transCompactScroll.getSelected()); + } + tabType = EnumPlayerData.Transport; + } + } + } else if (currentTab == 13) { + if (singleScroll.getSelected() != null) { + selectedID = bankData.get(singleScroll.getSelected()); + if(selectedID != null){ + singleScroll.list.remove(singleScroll.selected); + bankData.remove(singleScroll.getSelected()); + } + tabType = EnumPlayerData.Bank; + } + } else if (currentTab == 14) { + if (singleScroll.getSelected() != null) { + selectedID = factionData.get(singleScroll.getSelected()); + if(selectedID != null){ + singleScroll.list.remove(singleScroll.selected); + bankData.remove(singleScroll.getSelected()); + } + tabType = EnumPlayerData.Factions; + } + } + if (selectedID != null) { + PacketClient.sendClient(new PlayerDataRemovePacketNew(playerName, tabType, selectedID)); + } + } + } + + @Override + public void setQuestData(Map questCategories, Map questActive, Map questFinished) { + this.questCatData = new HashMap<>(questCategories); + this.questActiveData = new HashMap<>(questActive); + this.questFinishedData = new HashMap<>(questFinished); + if (questCatScroll != null) { + questCatScroll.setList(new ArrayList<>(questCatData.keySet())); + } + } + + @Override + public void setDialogData(Map dialogCategories, Map dialogRead) { + this.dialogCatData = new HashMap<>(dialogCategories); + this.dialogReadData = new HashMap<>(dialogRead); + if (dialogCatScroll != null) { + dialogCatScroll.setList(new ArrayList<>(dialogCatData.keySet())); + } + if (dialogReadScroll != null) { + dialogReadScroll.setList(new ArrayList<>(dialogReadData.keySet())); + } + if (dialogCompactScroll != null) { + List merged = new ArrayList<>(dialogReadData.keySet()); + dialogCompactScroll.setList(merged); + } + } + + @Override + public void setTransportData(Map transportCategories, Map transportLocations) { + this.transCatData = new HashMap<>(transportCategories); + this.transLocData = new HashMap<>(transportLocations); + if (transCatScroll != null) { + transCatScroll.setList(new ArrayList<>(transCatData.keySet())); + } + if (transLocScroll != null) { + transLocScroll.setList(new ArrayList<>(transLocData.keySet())); + } + if (transCompactScroll != null) { + List merged = new ArrayList<>(transLocData.keySet()); + transCompactScroll.setList(merged); + } + } + + @Override + public void setBankData(Map bankData) { + this.bankData = new HashMap<>(bankData); + if (singleScroll != null && currentTab == 13) { + singleScroll.setList(new ArrayList<>(this.bankData.keySet())); + } + } + + @Override + public void setFactionData(Map factionData) { + this.factionData = new HashMap<>(factionData); + if (singleScroll != null && currentTab == 14) { + singleScroll.setList(new ArrayList<>(this.factionData.keySet())); + } + } + + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { + if (guiCustomScroll == questCatScroll) { + selectedQuestCategory = questCatScroll.getSelected(); + questFinishedScroll.resetScroll(); + questActiveScroll.resetScroll(); + if (!selectedQuestCategory.isEmpty()) { + questFinishedScroll.setList(filterAndTrimListByCategory(questFinishedData, selectedQuestCategory, questFinishedSearch)); + questActiveScroll.setList(filterAndTrimListByCategory(questActiveData, selectedQuestCategory, questActiveSearch)); + } else { + questFinishedScroll.setList(new ArrayList<>()); + questActiveScroll.setList(new ArrayList<>()); + } + } else if (guiCustomScroll == dialogCatScroll) { + selectedDialogCategory = dialogCatScroll.getSelected(); + dialogReadScroll.resetScroll(); + if (!selectedDialogCategory.isEmpty()) { + dialogReadScroll.setList(filterAndTrimListByCategory(dialogReadData, selectedDialogCategory, dialogReadSearch)); + } else { + dialogReadScroll.setList(new ArrayList<>()); + } + } else if (guiCustomScroll == transCatScroll) { + selectedTransCategory = transCatScroll.getSelected(); + transLocScroll.resetScroll(); + if (!selectedTransCategory.isEmpty()) { + transLocScroll.setList(filterAndTrimListByCategory(transLocData, selectedTransCategory, transLocSearch)); + } else { + transLocScroll.setList(new ArrayList<>()); + } + } else if (guiCustomScroll == questActiveScroll) { + questFinishedScroll.selected = -1; + } else if (guiCustomScroll == questFinishedScroll) { + questActiveScroll.selected = -1; + } + } +} diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java index 68f5e6de7..4e466040d 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java @@ -15,7 +15,7 @@ import static noppes.npcs.client.gui.util.GuiNPCInterface.resizingActive; public class GuiCustomScroll extends GuiScreen { public static final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/misc.png"); - protected List list; + public List list; public final HashMap colors = new HashMap<>(); public int id; 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 7ffbc3b34..d605aaa76 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java @@ -162,6 +162,24 @@ public abstract class GuiNPCInterface extends GuiScreen { } } + @Override + public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + if (subgui != null) { + subgui.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); + return; + } + super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); + } + + @Override + protected void mouseMovedOrUp(int mouseX, int mouseY, int state) { + if (subgui != null) { + subgui.mouseMovedOrUp(mouseX, mouseY, state); + return; + } + super.mouseMovedOrUp(mouseX, mouseY, state); + } + public void mouseEvent(int i, int j, int k){} @Override From e15e72d478dd1f5c8fe52f6f587ed99a7c1d39f4 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 20 Feb 2025 00:41:45 -0500 Subject: [PATCH 16/59] =?UTF-8?q?Full=20Refactor=20and=20Now=20it=20looks?= =?UTF-8?q?=20better=20=F0=9F=92=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kamkeel/npcs/network/PacketHandler.java | 22 +- .../npcs/network/enums/EnumRequestPacket.java | 13 +- .../packets/data/PlayerDataInfoPacket.java} | 20 +- .../playerdata/PlayerDataGetInfoPacket.java} | 13 +- ...ket.java => PlayerDataGetNamesPacket.java} | 8 +- .../PlayerDataRemoveInfoPacket.java} | 11 +- .../java/noppes/npcs/NoppesUtilServer.java | 139 ++ .../java/noppes/npcs/client/NoppesUtil.java | 58 + .../npcs/client/gui/SubGuiPlayerData.java | 1565 +++++++++-------- .../gui/global/GuiNpcManagePlayerData.java | 7 +- .../client/gui/test/NoppesUtilClientNew.java | 74 - .../client/gui/test/NoppesUtilServerNew.java | 155 -- .../npcs/client/gui/test/PlayerDataTab.java | 9 - .../client/gui/test/SubGuiPlayerDataNew.java | 864 --------- .../gui/{test => util}/IPlayerDataInfo.java | 2 +- 15 files changed, 1073 insertions(+), 1887 deletions(-) rename src/main/java/{noppes/npcs/client/gui/test/PlayerDataSendPacketNew.java => kamkeel/npcs/network/packets/data/PlayerDataInfoPacket.java} (79%) rename src/main/java/{noppes/npcs/client/gui/test/PlayerDataGetPacketNew.java => kamkeel/npcs/network/packets/request/playerdata/PlayerDataGetInfoPacket.java} (73%) rename src/main/java/kamkeel/npcs/network/packets/request/playerdata/{PlayerDataGetPacket.java => PlayerDataGetNamesPacket.java} (88%) rename src/main/java/{noppes/npcs/client/gui/test/PlayerDataRemovePacketNew.java => kamkeel/npcs/network/packets/request/playerdata/PlayerDataRemoveInfoPacket.java} (77%) delete mode 100644 src/main/java/noppes/npcs/client/gui/test/NoppesUtilClientNew.java delete mode 100644 src/main/java/noppes/npcs/client/gui/test/NoppesUtilServerNew.java delete mode 100644 src/main/java/noppes/npcs/client/gui/test/PlayerDataTab.java delete mode 100644 src/main/java/noppes/npcs/client/gui/test/SubGuiPlayerDataNew.java rename src/main/java/noppes/npcs/client/gui/{test => util}/IPlayerDataInfo.java (93%) diff --git a/src/main/java/kamkeel/npcs/network/PacketHandler.java b/src/main/java/kamkeel/npcs/network/PacketHandler.java index 10a5fd259..b1ba1f217 100644 --- a/src/main/java/kamkeel/npcs/network/PacketHandler.java +++ b/src/main/java/kamkeel/npcs/network/PacketHandler.java @@ -53,7 +53,7 @@ import kamkeel.npcs.network.packets.request.npc.*; import kamkeel.npcs.network.packets.request.party.*; import kamkeel.npcs.network.packets.request.pather.MovingPathGetPacket; import kamkeel.npcs.network.packets.request.pather.MovingPathSavePacket; -import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetPacket; +import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetNamesPacket; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataMapRegenPacket; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataRemovePacket; import kamkeel.npcs.network.packets.request.profile.*; @@ -82,9 +82,9 @@ import noppes.npcs.CustomNpcs; import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.LogWriter; import noppes.npcs.NoppesUtilServer; -import noppes.npcs.client.gui.test.PlayerDataGetPacketNew; -import noppes.npcs.client.gui.test.PlayerDataRemovePacketNew; -import noppes.npcs.client.gui.test.PlayerDataSendPacketNew; +import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetInfoPacket; +import kamkeel.npcs.network.packets.request.playerdata.PlayerDataRemoveInfoPacket; +import kamkeel.npcs.network.packets.data.PlayerDataInfoPacket; import noppes.npcs.config.ConfigMain; import noppes.npcs.entity.EntityNPCInterface; @@ -230,12 +230,10 @@ public class PacketHandler { // PlayerData Packets - REQUEST_PACKET.registerPacket(new PlayerDataGetPacket()); -// REQUEST_PACKET.registerPacket(new PlayerDataRemovePacket()); - - REQUEST_PACKET.registerPacket(new PlayerDataGetPacketNew()); - REQUEST_PACKET.registerPacket(new PlayerDataRemovePacketNew()); - + REQUEST_PACKET.registerPacket(new PlayerDataGetNamesPacket()); + REQUEST_PACKET.registerPacket(new PlayerDataRemovePacket()); + REQUEST_PACKET.registerPacket(new PlayerDataGetInfoPacket()); + REQUEST_PACKET.registerPacket(new PlayerDataRemoveInfoPacket()); REQUEST_PACKET.registerPacket(new PlayerDataMapRegenPacket()); // Main Menu Packets @@ -355,9 +353,6 @@ public class PacketHandler { } public void registerDataPackets(){ - - DATA_PACKET.registerPacket(new PlayerDataSendPacketNew()); - // Data Packets DATA_PACKET.registerPacket(new LoginPacket()); DATA_PACKET.registerPacket(new AchievementPacket()); @@ -375,6 +370,7 @@ public class PacketHandler { DATA_PACKET.registerPacket(new SwingPlayerArmPacket()); DATA_PACKET.registerPacket(new UpdateAnimationsPacket()); DATA_PACKET.registerPacket(new VillagerListPacket()); + DATA_PACKET.registerPacket(new PlayerDataInfoPacket()); // Data | GUI Packets DATA_PACKET.registerPacket(new GuiClosePacket()); diff --git a/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java b/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java index 3036d9a88..9f7278368 100644 --- a/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java +++ b/src/main/java/kamkeel/npcs/network/enums/EnumRequestPacket.java @@ -136,7 +136,9 @@ public enum EnumRequestPacket { QuestCategoryGet, - PlayerDataGet, + PlayerDataInfo, + PlayerDataGetNames, + PlayerDataDelete, PlayerDataRemove, PlayerDataMapRegen, @@ -186,5 +188,12 @@ public enum EnumRequestPacket { ColorSet, ColorBrush, - ProfileGet, ProfileGetAll, ProfileGetInfo, ProfileCreate, ProfileRemove, ProfileRename, ProfileChange, PlayerDataGetOld, + + ProfileGet, + ProfileGetAll, + ProfileGetInfo, + ProfileCreate, + ProfileRemove, + ProfileRename, + ProfileChange } diff --git a/src/main/java/noppes/npcs/client/gui/test/PlayerDataSendPacketNew.java b/src/main/java/kamkeel/npcs/network/packets/data/PlayerDataInfoPacket.java similarity index 79% rename from src/main/java/noppes/npcs/client/gui/test/PlayerDataSendPacketNew.java rename to src/main/java/kamkeel/npcs/network/packets/data/PlayerDataInfoPacket.java index 2352fd063..ca639fb21 100644 --- a/src/main/java/noppes/npcs/client/gui/test/PlayerDataSendPacketNew.java +++ b/src/main/java/kamkeel/npcs/network/packets/data/PlayerDataInfoPacket.java @@ -1,4 +1,4 @@ -package noppes.npcs.client.gui.test; +package kamkeel.npcs.network.packets.data; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -8,10 +8,12 @@ import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumDataPacket; import kamkeel.npcs.util.ByteBufUtils; import net.minecraft.entity.player.EntityPlayer; +import noppes.npcs.client.NoppesUtil; + import java.io.IOException; import java.util.Map; -public final class PlayerDataSendPacketNew extends LargeAbstractPacket { +public final class PlayerDataInfoPacket extends LargeAbstractPacket { public static final String packetName = "Large|PlayerDataSendNew"; private String playerName; @@ -28,13 +30,13 @@ public final class PlayerDataSendPacketNew extends LargeAbstractPacket { private Map bankData; private Map factionData; - public PlayerDataSendPacketNew() {} + public PlayerDataInfoPacket() {} - public PlayerDataSendPacketNew(String playerName, - Map questCategories, Map questActive, Map questFinished, - Map dialogCategories, Map dialogRead, - Map transportCategories, Map transportLocations, - Map bankData, Map factionData) { + public PlayerDataInfoPacket(String playerName, + Map questCategories, Map questActive, Map questFinished, + Map dialogCategories, Map dialogRead, + Map transportCategories, Map transportLocations, + Map bankData, Map factionData) { this.playerName = playerName; this.questCategories = questCategories; this.questActive = questActive; @@ -96,6 +98,6 @@ public final class PlayerDataSendPacketNew extends LargeAbstractPacket { @Override protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException { - NoppesUtilClientNew.handlePlayerData(data, player); + NoppesUtil.handlePlayerData(data, player); } } diff --git a/src/main/java/noppes/npcs/client/gui/test/PlayerDataGetPacketNew.java b/src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataGetInfoPacket.java similarity index 73% rename from src/main/java/noppes/npcs/client/gui/test/PlayerDataGetPacketNew.java rename to src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataGetInfoPacket.java index fe12b0333..f4037e2c7 100644 --- a/src/main/java/noppes/npcs/client/gui/test/PlayerDataGetPacketNew.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataGetInfoPacket.java @@ -1,4 +1,4 @@ -package noppes.npcs.client.gui.test; +package kamkeel.npcs.network.packets.request.playerdata; import io.netty.buffer.ByteBuf; import kamkeel.npcs.network.AbstractPacket; @@ -8,22 +8,23 @@ import kamkeel.npcs.network.enums.EnumRequestPacket; import kamkeel.npcs.util.ByteBufUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; +import noppes.npcs.NoppesUtilServer; import java.io.IOException; -public final class PlayerDataGetPacketNew extends AbstractPacket { +public final class PlayerDataGetInfoPacket extends AbstractPacket { public static final String packetName = "Request|PlayerDataGetNew"; private String playerName; - public PlayerDataGetPacketNew() {} + public PlayerDataGetInfoPacket() {} - public PlayerDataGetPacketNew(String playerName) { + public PlayerDataGetInfoPacket(String playerName) { this.playerName = playerName; } @Override public Enum getType() { - return EnumRequestPacket.PlayerDataGet; + return EnumRequestPacket.PlayerDataInfo; } @Override @@ -42,6 +43,6 @@ public final class PlayerDataGetPacketNew extends AbstractPacket { return; String playerName = ByteBufUtils.readString(in); - NoppesUtilServerNew.sendPlayerData(playerName, (EntityPlayerMP) player); + NoppesUtilServer.sendPlayerDataInfo(playerName, (EntityPlayerMP) player); } } diff --git a/src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataGetNamesPacket.java similarity index 88% rename from src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataGetPacket.java rename to src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataGetNamesPacket.java index 9f4ea14f6..7bc09452e 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataGetNamesPacket.java @@ -17,22 +17,22 @@ import noppes.npcs.constants.EnumPlayerData; import java.io.IOException; -public final class PlayerDataGetPacket extends AbstractPacket { +public final class PlayerDataGetNamesPacket extends AbstractPacket { public static String packetName = "Request|PlayerDataGet"; private EnumPlayerData playerData; private String name; - public PlayerDataGetPacket() {} + public PlayerDataGetNamesPacket() {} - public PlayerDataGetPacket(EnumPlayerData playerData, String name) { + public PlayerDataGetNamesPacket(EnumPlayerData playerData, String name) { this.playerData = playerData; this.name = name; } @Override public Enum getType() { - return EnumRequestPacket.PlayerDataGetOld; + return EnumRequestPacket.PlayerDataGetNames; } @Override diff --git a/src/main/java/noppes/npcs/client/gui/test/PlayerDataRemovePacketNew.java b/src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataRemoveInfoPacket.java similarity index 77% rename from src/main/java/noppes/npcs/client/gui/test/PlayerDataRemovePacketNew.java rename to src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataRemoveInfoPacket.java index ea5133271..38d4dab7a 100644 --- a/src/main/java/noppes/npcs/client/gui/test/PlayerDataRemovePacketNew.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataRemoveInfoPacket.java @@ -1,4 +1,4 @@ -package noppes.npcs.client.gui.test; +package kamkeel.npcs.network.packets.request.playerdata; import io.netty.buffer.ByteBuf; import kamkeel.npcs.network.AbstractPacket; @@ -8,20 +8,21 @@ import kamkeel.npcs.network.enums.EnumRequestPacket; import kamkeel.npcs.util.ByteBufUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; +import noppes.npcs.NoppesUtilServer; import noppes.npcs.constants.EnumPlayerData; import java.io.IOException; -public final class PlayerDataRemovePacketNew extends AbstractPacket { +public final class PlayerDataRemoveInfoPacket extends AbstractPacket { public static final String packetName = "Request|PlayerDataRemoveNew"; private String playerName; private EnumPlayerData tabType; private int value; - public PlayerDataRemovePacketNew() {} + public PlayerDataRemoveInfoPacket() {} - public PlayerDataRemovePacketNew(String playerName, EnumPlayerData tabType, int selectedKey) { + public PlayerDataRemoveInfoPacket(String playerName, EnumPlayerData tabType, int selectedKey) { this.playerName = playerName; this.tabType = tabType; this.value = selectedKey; @@ -51,6 +52,6 @@ public final class PlayerDataRemovePacketNew extends AbstractPacket { String playerName = ByteBufUtils.readString(in); int tabType = in.readInt(); int value = in.readInt(); - NoppesUtilServerNew.removePlayerData(playerName, tabType, value, (EntityPlayerMP) player); + NoppesUtilServer.removePlayerDataInfo(playerName, tabType, value, (EntityPlayerMP) player); } } diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index cbda4ae2d..0d11add1b 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -3,6 +3,7 @@ package noppes.npcs; import io.netty.buffer.ByteBuf; import kamkeel.npcs.controllers.SyncController; import kamkeel.npcs.network.PacketHandler; +import kamkeel.npcs.network.packets.data.PlayerDataInfoPacket; import kamkeel.npcs.network.packets.data.gui.GuiClosePacket; import kamkeel.npcs.network.packets.data.gui.GuiErrorPacket; import kamkeel.npcs.network.packets.data.gui.GuiOpenPacket; @@ -975,4 +976,142 @@ public class NoppesUtilServer { sb.append(seconds).append(" second").append(seconds == 1 ? "" : "s"); return sb.toString(); } + + /** + * Retrieves the player's data from the existing PlayerDataController and sends + * a large packet to the client containing all the maps, including categories. + */ + public static void sendPlayerDataInfo(String playerName, EntityPlayerMP player) { + PlayerData playerdata; + EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(playerName); + if(pl == null) + playerdata = PlayerDataController.Instance.getDataFromUsername(playerName); + else + playerdata = PlayerDataController.Instance.getPlayerData(pl); + + // Assemble quest maps: + Map questActiveMap = new HashMap<>(); + Map questFinishedMap = new HashMap<>(); + Map questCategoriesMap = new HashMap<>(); + QuestController qc = QuestController.Instance; + PlayerQuestData qData = playerdata.questData; + for (Integer questId : qData.activeQuests.keySet()) { + if(!qc.quests.containsKey(questId)) + continue; + Quest quest = qc.quests.get(questId); + questActiveMap.put(quest.category.title + ": " + quest.title, questId); + if (!questCategoriesMap.containsKey(quest.category.title)) + questCategoriesMap.put(quest.category.title, quest.category.id); + } + for (Integer questId : qData.finishedQuests.keySet()) { + if(!qc.quests.containsKey(questId)) + continue; + Quest quest = qc.quests.get(questId); + questFinishedMap.put(quest.category.title + ": " + quest.title, questId); + if (!questCategoriesMap.containsKey(quest.category.title)) + questCategoriesMap.put(quest.category.title, quest.category.id); + } + + // Assemble dialog maps: + Map dialogReadMap = new HashMap<>(); + Map dialogCategoriesMap = new HashMap<>(); + PlayerDialogData dData = playerdata.dialogData; + for (Integer dialogId : dData.dialogsRead) { + if(!DialogController.Instance.dialogs.containsKey(dialogId)) + continue; + Dialog dialog = DialogController.Instance.dialogs.get(dialogId); + dialogReadMap.put(dialog.category.title + ": " + dialog.title, dialogId); + if (!dialogCategoriesMap.containsKey(dialog.category.title)) + dialogCategoriesMap.put(dialog.category.title, dialog.category.id); + } + + // Assemble transport maps: + Map transportLocationsMap = new HashMap<>(); + Map transportCategoriesMap = new HashMap<>(); + PlayerTransportData tData = playerdata.transportData; + TransportController tc = TransportController.getInstance(); + for (Integer id : tData.transports) { + TransportLocation location = tc.getTransport(id); + if(location == null) + continue; + transportLocationsMap.put(location.category.title + ": " + location.name, id); + if (!transportCategoriesMap.containsKey(location.category.title)) + transportCategoriesMap.put(location.category.title, location.category.id); + } + + // Assemble bank map: + Map bankMap = new HashMap<>(); + PlayerBankData bData = playerdata.bankData; + BankController bc = BankController.getInstance(); + for (Integer bankId : bData.banks.keySet()) { + if(!bc.banks.containsKey(bankId)) + continue; + Bank bank = bc.banks.get(bankId); + bankMap.put(bank.name, bankId); + } + + // Assemble faction map: + Map factionMap = new HashMap<>(); + PlayerFactionData fData = playerdata.factionData; + FactionController fc = FactionController.getInstance(); + for (Integer factionId : fData.factionData.keySet()) { + if(!fc.factions.containsKey(factionId)) + continue; + Faction faction = fc.factions.get(factionId); + factionMap.put(faction.name + "(" + fData.getFactionPoints(factionId) + ")", factionId); + } + + // Send the full packet with categories, active/finished data, dialogs, transports, banks, and factions. + PlayerDataInfoPacket packet = new PlayerDataInfoPacket(playerName, + questCategoriesMap, questActiveMap, questFinishedMap, + dialogCategoriesMap, dialogReadMap, + transportCategoriesMap, transportLocationsMap, + bankMap, factionMap); + PacketHandler.Instance.sendToPlayer(packet, player); + } + + /** + * Removes a specific data entry from the player's data. + * + * The tabType parameter is used as follows: + * 0: Quest – remove from both activeQuests and finishedQuests. + * 1: Dialog – remove from dialogsRead. + * 2: Transport – remove from transports. + * 3: Bank – remove from banks. + * 4: Factions – remove from factionData. + * + * The selectedKey is expected to be the string representation of the entry's ID. + */ + public static void removePlayerDataInfo(String playerName, int tabType, int value, EntityPlayerMP player) { + EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(playerName); + PlayerData playerdata; + if(pl == null) + playerdata = PlayerDataController.Instance.getDataFromUsername(playerName); + else + playerdata = PlayerDataController.Instance.getPlayerData(pl); + + if(tabType == 0) { // Quest removal + playerdata.questData.activeQuests.remove(value); + playerdata.questData.finishedQuests.remove(value); + } + if(tabType == 1) { // Dialog removal + playerdata.dialogData.dialogsRead.remove(value); + } + if(tabType == 2) { // Transport removal + playerdata.transportData.transports.remove(value); + } + if(tabType == 3) { // Bank removal + playerdata.bankData.banks.remove(value); + } + if(tabType == 4) { // Faction removal + playerdata.factionData.factionData.remove(value); + } + playerdata.save(); + + if(pl != null) { + SyncController.syncPlayer((EntityPlayerMP) pl); + } + // Resend the updated data to the client. + sendPlayerDataInfo(playerName, player); + } } diff --git a/src/main/java/noppes/npcs/client/NoppesUtil.java b/src/main/java/noppes/npcs/client/NoppesUtil.java index 2de2178d7..cc07e9d47 100644 --- a/src/main/java/noppes/npcs/client/NoppesUtil.java +++ b/src/main/java/noppes/npcs/client/NoppesUtil.java @@ -17,6 +17,7 @@ import net.minecraft.util.Util; import noppes.npcs.CustomNpcs; import noppes.npcs.client.gui.player.GuiDialogInteract; import noppes.npcs.client.gui.player.GuiQuestCompletion; +import noppes.npcs.client.gui.util.IPlayerDataInfo; import noppes.npcs.client.gui.util.GuiContainerNPCInterface; import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.IScrollData; @@ -32,6 +33,7 @@ import java.io.File; import java.io.IOException; import java.net.URI; import java.util.HashMap; +import java.util.Map; import java.util.Vector; public class NoppesUtil { @@ -258,4 +260,60 @@ public class NoppesUtil { public static void isGUIOpen(boolean isGUIOpen) { PacketClient.sendClient(new IsGuiOpenInform(isGUIOpen)); } + + /** + * Handles the incoming large packet with full player data. + * The packet writes: + * - player name (String) + * - questCategories, questActive, questFinished (maps) + * - dialogCategories, dialogRead (maps) + * - transportCategories, transportLocations (maps) + * - bankData, factionData (maps) + * + * The existing PlayerDataController functions are used on the server side; + * here we simply update the active SubGuiPlayerDataNew if present. + */ + public static void handlePlayerData(ByteBuf data, EntityPlayer player) throws IOException { + String playerName = ByteBufUtils.readString(data); + Map questCategories = readMap(data); + Map questActive = readMap(data); + Map questFinished = readMap(data); + Map dialogCategories = readMap(data); + Map dialogRead = readMap(data); + Map transportCategories = readMap(data); + Map transportLocations = readMap(data); + Map bankData = readMap(data); + Map factionData = readMap(data); + + + GuiScreen gui = Minecraft.getMinecraft().currentScreen; + if(gui == null) + return; + if(gui instanceof GuiNPCInterface && ((GuiNPCInterface)gui).hasSubGui()){ + gui = (GuiScreen) ((GuiNPCInterface)gui).getSubGui(); + } + + if(gui instanceof GuiContainerNPCInterface && ((GuiContainerNPCInterface)gui).hasSubGui()){ + gui = (GuiScreen) ((GuiContainerNPCInterface)gui).getSubGui(); + } + if (gui instanceof IPlayerDataInfo) { + IPlayerDataInfo info = (IPlayerDataInfo) gui; + info.setQuestData(questCategories, questActive, questFinished); + info.setDialogData(dialogCategories, dialogRead); + info.setTransportData(transportCategories, transportLocations); + info.setBankData(bankData); + info.setFactionData(factionData); + } + } + + private static Map readMap(ByteBuf data) { + int size = data.readInt(); + Map map = new HashMap<>(); + for (int i = 0; i < size; i++) { + String key = ByteBufUtils.readString(data); + int value = data.readInt(); + map.put(key, value); + } + return map; + } } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java b/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java index f4db0f16d..12e50d7d6 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java @@ -1,11 +1,10 @@ package noppes.npcs.client.gui; import kamkeel.npcs.network.PacketClient; -import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetPacket; -import kamkeel.npcs.network.packets.request.playerdata.PlayerDataRemovePacket; -import net.minecraft.client.gui.GuiYesNo; -import net.minecraft.client.gui.GuiYesNoCallback; -import noppes.npcs.client.NoppesUtil; +import noppes.npcs.client.CustomNpcResourceListener; +import noppes.npcs.client.gui.util.IPlayerDataInfo; +import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetInfoPacket; +import kamkeel.npcs.network.packets.request.playerdata.PlayerDataRemoveInfoPacket; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPlayerData; import net.minecraft.client.gui.GuiButton; @@ -14,119 +13,177 @@ import net.minecraft.util.StatCollector; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Vector; +import java.util.Map; -public class SubGuiPlayerData extends SubGuiInterface implements GuiYesNoCallback, ICustomScrollListener, IScrollData { +public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo, ICustomScrollListener { - private String playerName; - private int currentTab = 10; // 10: Quests, 11: Dialog, 12: Transport, 13: Bank, 14: Faction. - private int viewMode = 0; // 0: Categorical, 1: Compact. - private int lastDataType = 0; + //////////////////////////////////////////////////////////////////////////////// + // Fields + //////////////////////////////////////////////////////////////////////////////// - // ----- Quest Tab (10) ----- - private GuiCustomScroll questCatScroll, questFinishedScroll, questActiveScroll; - private String questCatSearch = "", questFinishedSearch = "", questActiveSearch = ""; - // Maps for category display (questCatData) and for quest entries: + // Current tab (10=Quest, 11=Dialog, 12=Transport, 13=Bank, 14=Faction) + private int currentTab = 10; + // View mode: 0 = Categorical (3 or 2 scrolls), 1 = Compact (2 or 1 scroll) + private int viewMode = 0; + + // ----- Quest Tab Components ----- + protected GuiCustomScroll questCatScroll, questActiveScroll, questFinishedScroll; + private String questCatSearch = "", questActiveSearch = "", questFinishedSearch = ""; private HashMap questCatData = new HashMap<>(); - private HashMap questFinishedData = new HashMap<>(); private HashMap questActiveData = new HashMap<>(); - // New: maps storing the extracted category for each quest entry (keyed by the displayed quest title) - private HashMap questFinishedCategory = new HashMap<>(); - private HashMap questActiveCategory = new HashMap<>(); + private HashMap questFinishedData = new HashMap<>(); private String selectedQuestCategory = ""; - // ----- Dialog Tab (11) ----- - private GuiCustomScroll dialogCatScroll, dialogReadScroll; - private String dialogCatSearch = "", dialogReadSearch = ""; + // ----- Dialog Tab Components ----- + protected GuiCustomScroll dialogCatScroll, dialogReadScroll, dialogCompactScroll; + private String dialogCatSearch = "", dialogReadSearch = "", dialogCompactSearch = ""; private HashMap dialogCatData = new HashMap<>(); private HashMap dialogReadData = new HashMap<>(); - // For dialog entries, we split off the category from the key ("Category: Title") - private HashMap dialogCategory = new HashMap<>(); - private GuiCustomScroll dialogCompactScroll; - private String dialogCompactSearch = ""; - private HashMap dialogCompactData = new HashMap<>(); private String selectedDialogCategory = ""; - // ----- Transport Tab (12) ----- - private GuiCustomScroll transCatScroll, transLocScroll; - private String transCatSearch = "", transLocSearch = ""; + // ----- Transport Tab Components ----- + protected GuiCustomScroll transCatScroll, transLocScroll, transCompactScroll; + private String transCatSearch = "", transLocSearch = "", transCompactSearch = ""; private HashMap transCatData = new HashMap<>(); private HashMap transLocData = new HashMap<>(); - // For transport locations, also store their category: - private HashMap transLocationCategory = new HashMap<>(); - private GuiCustomScroll transCompactScroll; - private String transCompactSearch = ""; - private HashMap transCompactData = new HashMap<>(); private String selectedTransCategory = ""; - // ----- Bank & Faction Tabs (13 & 14) ----- - private GuiCustomScroll singleScroll; + // ----- Bank and Faction (Single Scroll) ----- + protected GuiCustomScroll singleScroll; private String singleSearch = ""; - private HashMap singleData = new HashMap<>(); + private HashMap bankData = new HashMap<>(); + private HashMap factionData = new HashMap<>(); - // ----- Divider/resizing variables ----- -// We use margins so that scrolls have room on the right for buttons. - private final int leftMargin = guiLeft + 4; - private final int rightMargin = guiLeft + xSize - 80; // leave 80px for the buttons on the right - private int dividerOffset1 = 120; - private int dividerOffset2 = 240; + // ----- Divider & Resizing Variables ----- + // In categorical mode for Quest: two dividers (3 scrolls). + // In compact mode for Quest: one divider between two scrolls. + private int dividerOffset1 = 0; // In categorical: width of left scroll; in compact for quests: width of left scroll. + private int dividerOffset2 = 0; // Only used for Quest categorical mode. private final int dividerWidth = 5; private final int minScrollWidth = 50; - private int draggingDivider = 0; - private int initialDragX = 0; private boolean isResizing = false; + private int resizingDivider = 0; + private int initialDragX = 0; + // ----- Layout Constants ----- + private final int leftPadding = 6; + private final int rightPadding = 6; + private final int scrollTopOffset = 30; + private final int verticalGapAboveTF = 3; + private final int textFieldHeight = 20; + private final int verticalGapBelowTF = 3; + + // ----- Other ----- + private String playerName; + + //////////////////////////////////////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////////////////////////////////////// public SubGuiPlayerData(String playerName) { this.playerName = playerName; xSize = 420; - ySize = 216; + ySize = 215; setBackground("menubg.png"); - lastDataType = 11; - PacketClient.sendClient(new PlayerDataGetPacket(EnumPlayerData.Quest, playerName)); closeOnEsc = true; + PacketClient.sendClient(new PlayerDataGetInfoPacket(playerName)); } + //////////////////////////////////////////////////////////////////////////////// + // Layout Helpers + //////////////////////////////////////////////////////////////////////////////// + + private int getPaddedLeft() { + return guiLeft + leftPadding; + } + + private int getPaddedRight() { + return guiLeft + xSize - rightPadding; + } + + private int getAvailableWidth() { + return getPaddedRight() - getPaddedLeft(); + } + + // Height available for scroll windows. + private int getScrollHeight() { + return ySize - (scrollTopOffset + verticalGapAboveTF + textFieldHeight + verticalGapBelowTF); + } + + // Y coordinate for textfields. + private int getTextFieldY() { + return guiTop + scrollTopOffset + getScrollHeight() + verticalGapAboveTF; + } + + //////////////////////////////////////////////////////////////////////////////// + // Component Setup Helpers + //////////////////////////////////////////////////////////////////////////////// + + // Create top buttons. + private void setupTopButtons() { + GuiMenuTopButton btnQuest = new GuiMenuTopButton(10, guiLeft + 4, guiTop - 10, StatCollector.translateToLocal("tab.quests")); + GuiMenuTopButton btnDialog = new GuiMenuTopButton(11, btnQuest.xPosition + btnQuest.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.dialog")); + GuiMenuTopButton btnTransport = new GuiMenuTopButton(12, btnDialog.xPosition + btnDialog.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.transport")); + GuiMenuTopButton btnBank = new GuiMenuTopButton(13, btnTransport.xPosition + btnTransport.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.bank")); + GuiMenuTopButton btnFaction = new GuiMenuTopButton(14, btnBank.xPosition + btnBank.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.faction")); + // Close button. + GuiMenuTopButton close = new GuiMenuTopButton(-5, guiLeft + xSize - 22, guiTop - 10, "X"); + + btnQuest.active = (currentTab == 10); + btnDialog.active = (currentTab == 11); + btnTransport.active = (currentTab == 12); + btnBank.active = (currentTab == 13); + btnFaction.active = (currentTab == 14); + + addTopButton(btnQuest); + addTopButton(btnDialog); + addTopButton(btnTransport); + addTopButton(btnBank); + addTopButton(btnFaction); + addTopButton(close); + } + + // Helper to ensure scroll exists. + private GuiCustomScroll ensureScroll(GuiCustomScroll scroll, int id) { + if (scroll == null) { + scroll = new GuiCustomScroll(this, id, 0); + } + return scroll; + } + + // Helper to update a text field's position and width. + private void updateComponentPosition(int fieldId, int newX, int newWidth) { + GuiNpcTextField tf = getTextField(fieldId); + if (tf != null) { + tf.xPosition = newX; + tf.width = newWidth; + } + } + + // Helper to update a label's x position. + private void updateLabelPosition(int labelId, int newX) { + GuiNpcLabel lbl = getLabel(labelId); + if (lbl != null) { + lbl.x = newX; + } + } + + //////////////////////////////////////////////////////////////////////////////// + // initGui() & Tab Initialization + //////////////////////////////////////////////////////////////////////////////// + @Override public void initGui() { super.initGui(); - // --- Top Buttons --- - GuiMenuTopButton close = new GuiMenuTopButton(-5, guiLeft + xSize - 22, guiTop - 10, "X"); - GuiMenuTopButton quests = new GuiMenuTopButton(10, guiLeft + 4, guiTop - 10, StatCollector.translateToLocal("tab.quests")); - GuiMenuTopButton dialog = new GuiMenuTopButton(11, quests.xPosition + quests.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.dialog")); - GuiMenuTopButton transport = new GuiMenuTopButton(12, dialog.xPosition + dialog.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.transport")); - GuiMenuTopButton bank = new GuiMenuTopButton(13, transport.xPosition + transport.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.bank")); - GuiMenuTopButton faction = new GuiMenuTopButton(14, bank.xPosition + bank.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.faction")); - - quests.active = (currentTab == 10); - dialog.active = (currentTab == 11); - transport.active = (currentTab == 12); - bank.active = (currentTab == 13); - faction.active = (currentTab == 14); - close.active = false; - - addTopButton(close); - addTopButton(quests); - addTopButton(dialog); - addTopButton(transport); - addTopButton(bank); - addTopButton(faction); + setupTopButtons(); + // Mode toggle button (50px wide) if (currentTab == 10 || currentTab == 11 || currentTab == 12) { - addButton(new GuiNpcButton(20, guiLeft + xSize - 80, guiTop - 10, 75, 20, - viewMode == 0 ? StatCollector.translateToLocal("view.categorical") : StatCollector.translateToLocal("view.compact"))); + String modeText = viewMode == 0 ? StatCollector.translateToLocal("view.categorical") : StatCollector.translateToLocal("view.compact"); + addButton(new GuiNpcButton(20, guiLeft + xSize - 60, guiTop + 10, 50, 20, modeText)); } guiTop += 7; - - if (currentTab == 10) - lastDataType = 11; - else if (currentTab == 11) - lastDataType = (viewMode == 0) ? 21 : 22; - else if (currentTab == 12) - lastDataType = (viewMode == 0) ? 31 : 32; - else if (currentTab == 13 || currentTab == 14) - lastDataType = 40; - + // Initialize components based on current tab. switch (currentTab) { case 10: initQuestTab(); @@ -139,386 +196,268 @@ public class SubGuiPlayerData extends SubGuiInterface implements GuiYesNoCallbac break; case 13: case 14: - initSingleScroll(); + initSingleTab(); break; } - - addButton(new GuiNpcButton(30, guiLeft + xSize - 80, guiTop + ySize - 30, 75, 20, StatCollector.translateToLocal("button.delete"))); + // Delete button. + addButton(new GuiNpcButton(30, guiLeft + xSize - 60, guiTop + ySize - 30, 50, 20, StatCollector.translateToLocal("button.delete"))); } + // ----- Quest Tab Initialization ----- private void initQuestTab() { - int regionLeft = leftMargin; - int regionRight = rightMargin; - int dividerX1 = regionLeft + dividerOffset1; - int dividerX2 = regionLeft + dividerOffset2; + int paddedLeft = getPaddedLeft(); + int paddedRight = getPaddedRight(); + int availableWidth = getAvailableWidth(); + int scrollHeight = getScrollHeight(); - if (viewMode == 0) { - if (questCatScroll == null) { - questCatScroll = new GuiCustomScroll(this, 0, 0); + if (viewMode == 0) { // Categorical: 3 scrolls. + if (!isResizing) { + dividerOffset1 = (availableWidth - 2 * dividerWidth) / 3; + dividerOffset2 = dividerOffset1 + dividerWidth + (availableWidth - 2 * dividerWidth) / 3; } - questCatScroll.guiLeft = regionLeft; - questCatScroll.guiTop = guiTop + 30; - questCatScroll.setSize(dividerX1 - regionLeft, 150); + // Quest Category Scroll. + questCatScroll = ensureScroll(questCatScroll, 0); + questCatScroll.guiLeft = paddedLeft; + questCatScroll.guiTop = guiTop + scrollTopOffset; + questCatScroll.setSize(dividerOffset1, scrollHeight); + questCatScroll.setList(new ArrayList<>(questCatData.keySet())); + questCatScroll.selected = -1; + questCatSearch = ""; addScroll(questCatScroll); - addLabel(new GuiNpcLabel(1000, "Categories", regionLeft, guiTop + 15, 0xFFFFFF)); + addLabel(new GuiNpcLabel(1000, "Categories", paddedLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - if (questFinishedScroll == null) { - questFinishedScroll = new GuiCustomScroll(this, 1, 0); - } - questFinishedScroll.guiLeft = dividerX1 + dividerWidth; - questFinishedScroll.guiTop = guiTop + 30; - questFinishedScroll.setSize(dividerX2 - dividerX1 - dividerWidth, 150); + // Quest Finished Scroll. + questFinishedScroll = ensureScroll(questFinishedScroll, 1); + questFinishedScroll.guiLeft = paddedLeft + dividerOffset1 + dividerWidth; + questFinishedScroll.guiTop = guiTop + scrollTopOffset; + questFinishedScroll.setSize(dividerOffset2 - dividerOffset1 - dividerWidth, scrollHeight); + questFinishedScroll.setList(new ArrayList<>()); + questFinishedScroll.selected = -1; + questFinishedSearch = ""; addScroll(questFinishedScroll); - addLabel(new GuiNpcLabel(1001, "Finished", dividerX1 + dividerWidth, guiTop + 15, 0xFFFFFF)); + addLabel(new GuiNpcLabel(1001, "Finished", paddedLeft + dividerOffset1 + dividerWidth, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - if (questActiveScroll == null) { - questActiveScroll = new GuiCustomScroll(this, 2, 0); - } - questActiveScroll.guiLeft = dividerX2 + dividerWidth; - questActiveScroll.guiTop = guiTop + 30; - questActiveScroll.setSize(regionRight - dividerX2 - dividerWidth, 150); + // Quest Active Scroll. + questActiveScroll = ensureScroll(questActiveScroll, 2); + questActiveScroll.guiLeft = paddedLeft + dividerOffset2 + dividerWidth; + questActiveScroll.guiTop = guiTop + scrollTopOffset; + questActiveScroll.setSize(paddedRight - (paddedLeft + dividerOffset2 + dividerWidth), scrollHeight); + questActiveScroll.setList(new ArrayList<>()); + questActiveScroll.selected = -1; + questActiveSearch = ""; addScroll(questActiveScroll); - addLabel(new GuiNpcLabel(1002, "Active", dividerX2 + dividerWidth, guiTop + 15, 0xFFFFFF)); + addLabel(new GuiNpcLabel(1002, "Active", paddedLeft + dividerOffset2 + dividerWidth, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - // When a category is selected, filter using our extra maps. - if (!selectedQuestCategory.isEmpty()) { - questFinishedScroll.setList(filterQuestsByCategory(questFinishedData, questFinishedCategory, selectedQuestCategory)); - questActiveScroll.setList(filterQuestsByCategory(questActiveData, questActiveCategory, selectedQuestCategory)); - } else { - questFinishedScroll.setList(getSearchList(questFinishedData, questFinishedSearch)); - questActiveScroll.setList(getSearchList(questActiveData, questActiveSearch)); + // Text Fields. + addTextField(new GuiNpcTextField(55, this, fontRendererObj, paddedLeft, getTextFieldY(), dividerOffset1, textFieldHeight, questCatSearch)); + addTextField(new GuiNpcTextField(56, this, fontRendererObj, paddedLeft + dividerOffset1 + dividerWidth, getTextFieldY(), dividerOffset2 - dividerOffset1 - dividerWidth, textFieldHeight, questFinishedSearch)); + addTextField(new GuiNpcTextField(57, this, fontRendererObj, paddedLeft + dividerOffset2 + dividerWidth, getTextFieldY(), paddedRight - (paddedLeft + dividerOffset2 + dividerWidth), textFieldHeight, questActiveSearch)); + } else { // Compact: 2 scrolls with resizable divider. + if (!isResizing) { + dividerOffset1 = (availableWidth - dividerWidth) / 2; } - } else { - if (questFinishedScroll == null) { - questFinishedScroll = new GuiCustomScroll(this, 1, 0); - } - questFinishedScroll.guiLeft = regionLeft; - questFinishedScroll.guiTop = guiTop + 30; - questFinishedScroll.setSize((regionRight - regionLeft) / 2, 150); + questFinishedScroll = ensureScroll(questFinishedScroll, 1); + questFinishedScroll.guiLeft = paddedLeft; + questFinishedScroll.guiTop = guiTop + scrollTopOffset; + questFinishedScroll.setSize(dividerOffset1, scrollHeight); + questFinishedScroll.setList(new ArrayList<>(questFinishedData.keySet())); + questFinishedSearch = ""; addScroll(questFinishedScroll); - addLabel(new GuiNpcLabel(1003, "Finished", regionLeft, guiTop + 15, 0xFFFFFF)); + addLabel(new GuiNpcLabel(1003, "Finished", paddedLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - if (questActiveScroll == null) { - questActiveScroll = new GuiCustomScroll(this, 2, 0); - } - questActiveScroll.guiLeft = regionLeft + (regionRight - regionLeft) / 2; - questActiveScroll.guiTop = guiTop + 30; - questActiveScroll.setSize((regionRight - regionLeft) / 2, 150); + questActiveScroll = ensureScroll(questActiveScroll, 2); + questActiveScroll.guiLeft = paddedLeft + dividerOffset1 + dividerWidth; + questActiveScroll.guiTop = guiTop + scrollTopOffset; + questActiveScroll.setSize(availableWidth - dividerOffset1 - dividerWidth, scrollHeight); + questActiveScroll.setList(new ArrayList<>(questActiveData.keySet())); + questActiveSearch = ""; addScroll(questActiveScroll); - addLabel(new GuiNpcLabel(1004, "Active", questActiveScroll.guiLeft, guiTop + 15, 0xFFFFFF)); - } - if (viewMode == 0) { - addTextField(new GuiNpcTextField(55, this, fontRendererObj, regionLeft, guiTop + 30 + 153, dividerX1 - regionLeft, 20, questCatSearch)); - addTextField(new GuiNpcTextField(56, this, fontRendererObj, dividerX1 + dividerWidth, guiTop + 30 + 153, dividerX2 - dividerX1 - dividerWidth, 20, questFinishedSearch)); - addTextField(new GuiNpcTextField(57, this, fontRendererObj, dividerX2 + dividerWidth, guiTop + 30 + 153, regionRight - dividerX2 - dividerWidth, 20, questActiveSearch)); - } else { - addTextField(new GuiNpcTextField(55, this, fontRendererObj, regionLeft, guiTop + 30 + 153, (regionRight - regionLeft) / 2, 20, questFinishedSearch)); - addTextField(new GuiNpcTextField(56, this, fontRendererObj, questActiveScroll.guiLeft, guiTop + 30 + 153, (regionRight - regionLeft) / 2, 20, questActiveSearch)); + addLabel(new GuiNpcLabel(1004, "Active", paddedLeft + dividerOffset1 + dividerWidth, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); + + addTextField(new GuiNpcTextField(55, this, fontRendererObj, paddedLeft, getTextFieldY(), dividerOffset1, textFieldHeight, questFinishedSearch)); + addTextField(new GuiNpcTextField(56, this, fontRendererObj, paddedLeft + dividerOffset1 + dividerWidth, getTextFieldY(), availableWidth - dividerOffset1 - dividerWidth, textFieldHeight, questActiveSearch)); } } + // ----- Dialog Tab Initialization ----- private void initDialogTab() { - int regionLeft = leftMargin; - int regionRight = rightMargin; - int dividerX = regionLeft + dividerOffset1; + int paddedLeft = getPaddedLeft(); + int availableWidth = getAvailableWidth(); + int scrollHeight = getScrollHeight(); - if (viewMode == 0) { - if (dialogCatScroll == null) { - dialogCatScroll = new GuiCustomScroll(this, 0, 0); + if (viewMode == 0) { // Categorical: 2 scrolls. + if (!isResizing) { + dividerOffset1 = (availableWidth - dividerWidth) / 2; } - dialogCatScroll.guiLeft = regionLeft; - dialogCatScroll.guiTop = guiTop + 30; - dialogCatScroll.setSize(dividerX - regionLeft, 150); + dialogCatScroll = ensureScroll(dialogCatScroll, 0); + dialogCatScroll.guiLeft = paddedLeft; + dialogCatScroll.guiTop = guiTop + scrollTopOffset; + dialogCatScroll.setSize(dividerOffset1, scrollHeight); + dialogCatScroll.setList(new ArrayList<>(dialogCatData.keySet())); addScroll(dialogCatScroll); - addLabel(new GuiNpcLabel(2000, "Categories", regionLeft, guiTop + 15, 0xFFFFFF)); + addLabel(new GuiNpcLabel(2000, "Categories", paddedLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - if (dialogReadScroll == null) { - dialogReadScroll = new GuiCustomScroll(this, 1, 0); - } - dialogReadScroll.guiLeft = dividerX + dividerWidth; - dialogReadScroll.guiTop = guiTop + 30; - dialogReadScroll.setSize(regionRight - dividerX - dividerWidth, 150); + dialogReadScroll = ensureScroll(dialogReadScroll, 1); + dialogReadScroll.guiLeft = paddedLeft + dividerOffset1 + dividerWidth; + dialogReadScroll.guiTop = guiTop + scrollTopOffset; + dialogReadScroll.setSize(availableWidth - dividerOffset1 - dividerWidth, scrollHeight); + dialogReadScroll.setList(new ArrayList<>(dialogReadData.keySet())); addScroll(dialogReadScroll); - addLabel(new GuiNpcLabel(2001, "Read", dividerX + dividerWidth, guiTop + 15, 0xFFFFFF)); + addLabel(new GuiNpcLabel(2001, "Read", paddedLeft + dividerOffset1 + dividerWidth, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - if (!selectedDialogCategory.isEmpty()) { - dialogReadScroll.setList(filterDialogsByCategory(dialogReadData, dialogCategory, selectedDialogCategory)); - } else { - dialogReadScroll.setList(getSearchList(dialogReadData, dialogReadSearch)); - } - } else { - if (dialogCompactScroll == null) { - dialogCompactScroll = new GuiCustomScroll(this, 5, 0); - } - dialogCompactScroll.guiLeft = regionLeft; - dialogCompactScroll.guiTop = guiTop + 30; - dialogCompactScroll.setSize(regionRight - regionLeft, 150); + addTextField(new GuiNpcTextField(55, this, fontRendererObj, paddedLeft, getTextFieldY(), dividerOffset1, textFieldHeight, dialogCatSearch)); + addTextField(new GuiNpcTextField(56, this, fontRendererObj, paddedLeft + dividerOffset1 + dividerWidth, getTextFieldY(), availableWidth - dividerOffset1 - dividerWidth, textFieldHeight, dialogReadSearch)); + } else { // Compact: 1 scroll (no divider). + dialogCompactScroll = ensureScroll(dialogCompactScroll, 5); + dialogCompactScroll.guiLeft = paddedLeft; + dialogCompactScroll.guiTop = guiTop + scrollTopOffset; + dialogCompactScroll.setSize(availableWidth, getScrollHeight()); + dialogCompactScroll.setList(new ArrayList<>(dialogReadData.keySet())); addScroll(dialogCompactScroll); - addLabel(new GuiNpcLabel(2002, "All", regionLeft, guiTop + 15, 0xFFFFFF)); - dialogCompactScroll.setList(getSearchList(dialogCompactData, dialogCompactSearch)); - addTextField(new GuiNpcTextField(55, this, fontRendererObj, regionLeft, guiTop + 30 + 153, regionRight - regionLeft, 20, dialogCompactSearch)); - } - if (viewMode == 0) { - addTextField(new GuiNpcTextField(55, this, fontRendererObj, regionLeft, guiTop + 30 + 153, dividerX - regionLeft, 20, dialogCatSearch)); - addTextField(new GuiNpcTextField(56, this, fontRendererObj, dividerX + dividerWidth, guiTop + 30 + 153, regionRight - dividerX - dividerWidth, 20, dialogReadSearch)); + addLabel(new GuiNpcLabel(2002, "All", paddedLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); + addTextField(new GuiNpcTextField(55, this, fontRendererObj, paddedLeft, getTextFieldY(), availableWidth, textFieldHeight, dialogCompactSearch)); } } + // ----- Transport Tab Initialization ----- private void initTransportTab() { - int regionLeft = leftMargin; - int regionRight = rightMargin; - int dividerX = regionLeft + dividerOffset1; + int paddedLeft = getPaddedLeft(); + int availableWidth = getAvailableWidth(); + int scrollHeight = getScrollHeight(); - if (viewMode == 0) { - if (transCatScroll == null) { - transCatScroll = new GuiCustomScroll(this, 3, 0); + if (viewMode == 0) { // Categorical: 2 scrolls. + if (!isResizing) { + dividerOffset1 = (availableWidth - dividerWidth) / 2; } - transCatScroll.guiLeft = regionLeft; - transCatScroll.guiTop = guiTop + 30; - transCatScroll.setSize(dividerX - regionLeft, 150); + transCatScroll = ensureScroll(transCatScroll, 3); + transCatScroll.guiLeft = paddedLeft; + transCatScroll.guiTop = guiTop + scrollTopOffset; + transCatScroll.setSize(dividerOffset1, scrollHeight); + transCatScroll.setList(new ArrayList<>(transCatData.keySet())); addScroll(transCatScroll); - addLabel(new GuiNpcLabel(3000, "Categories", regionLeft, guiTop + 15, 0xFFFFFF)); + addLabel(new GuiNpcLabel(3000, "Categories", paddedLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - if (transLocScroll == null) { - transLocScroll = new GuiCustomScroll(this, 4, 0); - } - transLocScroll.guiLeft = dividerX + dividerWidth; - transLocScroll.guiTop = guiTop + 30; - transLocScroll.setSize(regionRight - dividerX - dividerWidth, 150); + transLocScroll = ensureScroll(transLocScroll, 4); + transLocScroll.guiLeft = paddedLeft + dividerOffset1 + dividerWidth; + transLocScroll.guiTop = guiTop + scrollTopOffset; + transLocScroll.setSize(availableWidth - dividerOffset1 - dividerWidth, scrollHeight); + transLocScroll.setList(new ArrayList<>(transLocData.keySet())); addScroll(transLocScroll); - addLabel(new GuiNpcLabel(3001, "Locations", dividerX + dividerWidth, guiTop + 15, 0xFFFFFF)); + addLabel(new GuiNpcLabel(3001, "Locations", paddedLeft + dividerOffset1 + dividerWidth, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - if (!selectedTransCategory.isEmpty()) { - transLocScroll.setList(filterTransportsByCategory(transLocData, transLocationCategory, selectedTransCategory)); - } else { - transLocScroll.setList(getSearchList(transLocData, transLocSearch)); - } - } else { - if (transCompactScroll == null) { - transCompactScroll = new GuiCustomScroll(this, 5, 0); - } - transCompactScroll.guiLeft = regionLeft; - transCompactScroll.guiTop = guiTop + 30; - transCompactScroll.setSize(regionRight - regionLeft, 150); + addTextField(new GuiNpcTextField(60, this, fontRendererObj, paddedLeft, getTextFieldY(), dividerOffset1, textFieldHeight, transCatSearch)); + addTextField(new GuiNpcTextField(61, this, fontRendererObj, paddedLeft + dividerOffset1 + dividerWidth, getTextFieldY(), availableWidth - dividerOffset1 - dividerWidth, textFieldHeight, transLocSearch)); + } else { // Compact: 1 scroll (no divider). + transCompactScroll = ensureScroll(transCompactScroll, 5); + transCompactScroll.guiLeft = paddedLeft; + transCompactScroll.guiTop = guiTop + scrollTopOffset; + transCompactScroll.setSize(availableWidth, getScrollHeight()); + transCompactScroll.setList(new ArrayList<>(transLocData.keySet())); addScroll(transCompactScroll); - addLabel(new GuiNpcLabel(3002, "All", regionLeft, guiTop + 15, 0xFFFFFF)); - transCompactScroll.setList(getSearchList(transCompactData, transCompactSearch)); - addTextField(new GuiNpcTextField(60, this, fontRendererObj, regionLeft, guiTop + 30 + 153, regionRight - regionLeft, 20, transCompactSearch)); - } - if (viewMode == 0) { - addTextField(new GuiNpcTextField(60, this, fontRendererObj, regionLeft, guiTop + 30 + 153, dividerX - regionLeft, 20, transCatSearch)); - addTextField(new GuiNpcTextField(61, this, fontRendererObj, dividerX + dividerWidth, guiTop + 30 + 153, regionRight - dividerX - dividerWidth, 20, transLocSearch)); + addLabel(new GuiNpcLabel(3002, "All", paddedLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); + addTextField(new GuiNpcTextField(60, this, fontRendererObj, paddedLeft, getTextFieldY(), availableWidth, textFieldHeight, transCompactSearch)); } } - private void initSingleScroll() { - int regionLeft = leftMargin; - int regionRight = rightMargin; - if (singleScroll == null) { - singleScroll = new GuiCustomScroll(this, 6, 0); + // ----- Single Tab Initialization (Bank/Faction) ----- + private void initSingleTab() { + int paddedLeft = getPaddedLeft(); + int availableWidth = getAvailableWidth(); + int scrollHeight = getScrollHeight(); + singleScroll = ensureScroll(singleScroll, 0); + singleScroll.guiLeft = paddedLeft; + singleScroll.guiTop = guiTop + scrollTopOffset; + if (currentTab == 13) { + singleScroll.setSize(availableWidth, scrollHeight); + singleScroll.setList(new ArrayList<>(bankData.keySet())); + addLabel(new GuiNpcLabel(4000, "Bank", paddedLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); + } else { + singleScroll.setSize(availableWidth, scrollHeight); + singleScroll.setList(new ArrayList<>(factionData.keySet())); + addLabel(new GuiNpcLabel(4000, "Faction", paddedLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); } - singleScroll.guiLeft = regionLeft; - singleScroll.guiTop = guiTop + 30; - singleScroll.setSize(regionRight - regionLeft, 150); addScroll(singleScroll); - addLabel(new GuiNpcLabel(4000, "Data", regionLeft, guiTop + 15, 0xFFFFFF)); - addTextField(new GuiNpcTextField(70, this, fontRendererObj, regionLeft, guiTop + 30 + 153, regionRight - regionLeft, 20, singleSearch)); + addTextField(new GuiNpcTextField(70, this, fontRendererObj, paddedLeft, getTextFieldY(), availableWidth, textFieldHeight, singleSearch)); } + //////////////////////////////////////////////////////////////////////////////// + // Drawing Helpers + //////////////////////////////////////////////////////////////////////////////// + @Override - public void actionPerformed(GuiButton button) { - int id = button.id; - if (id >= 10 && id <= 14) { - currentTab = id; - clearData(); - selectedQuestCategory = ""; - selectedDialogCategory = ""; - selectedTransCategory = ""; - switch (currentTab) { - case 10: - PacketClient.sendClient(new PlayerDataGetPacket(EnumPlayerData.Quest, playerName)); - break; - case 11: - PacketClient.sendClient(new PlayerDataGetPacket(EnumPlayerData.Dialog, playerName)); - break; - case 12: - PacketClient.sendClient(new PlayerDataGetPacket(EnumPlayerData.Transport, playerName)); - break; - case 13: - PacketClient.sendClient(new PlayerDataGetPacket(EnumPlayerData.Bank, playerName)); - break; - case 14: - PacketClient.sendClient(new PlayerDataGetPacket(EnumPlayerData.Factions, playerName)); - break; - } - initGui(); - return; + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + super.drawScreen(mouseX, mouseY, partialTicks); + int scrollHeight = getScrollHeight(); + int paddedLeft = getPaddedLeft(); + int availableWidth = getAvailableWidth(); + + // In compact mode for Quests, draw divider between the two scrolls. + if (currentTab == 10 && viewMode != 0 && !hasSubGui()) { + int dividerX = paddedLeft + dividerOffset1; + drawRect(dividerX, guiTop + scrollTopOffset, dividerX + dividerWidth, guiTop + scrollTopOffset + scrollHeight, 0xFF707070); } - if (id == 20) { - viewMode = (viewMode == 0) ? 1 : 0; - initGui(); - return; - } - if (id == 30) { - displayGuiScreen(new GuiYesNo(this, StatCollector.translateToLocal("gui.deleteconfirm"), "", 100 + currentTab)); - return; + // In categorical mode for Quest, draw both dividers. + if (currentTab == 10 && viewMode == 0 && !hasSubGui()) { + int dividerX1 = paddedLeft + dividerOffset1; + int dividerX2 = paddedLeft + dividerOffset2; + drawRect(dividerX1, guiTop + scrollTopOffset, dividerX1 + dividerWidth, guiTop + scrollTopOffset + scrollHeight, 0xFF707070); + drawRect(dividerX2, guiTop + scrollTopOffset, dividerX2 + dividerWidth, guiTop + scrollTopOffset + scrollHeight, 0xFF707070); + } else if ((currentTab == 11 || currentTab == 12) && viewMode == 0 && !hasSubGui()) { + int dividerX = paddedLeft + dividerOffset1; + drawRect(dividerX, guiTop + scrollTopOffset, dividerX + dividerWidth, guiTop + scrollTopOffset + scrollHeight, 0xFF707070); } + // Compact mode for Dialog/Transport uses one scroll => no divider. } - private void clearData() { - questCatData.clear(); - questFinishedData.clear(); - questActiveData.clear(); - questFinishedCategory.clear(); - questActiveCategory.clear(); - dialogCatData.clear(); - dialogReadData.clear(); - dialogCompactData.clear(); - dialogCategory.clear(); - transCatData.clear(); - transLocData.clear(); - transLocationCategory.clear(); - transCompactData.clear(); - singleData.clear(); - } - - @Override - public void keyTyped(char c, int i) { - super.keyTyped(c, i); - if (currentTab == 10) { - if (getTextField(55) != null && getTextField(55).isFocused()) { - String newSearch = getTextField(55).getText().toLowerCase(); - if (!questCatSearch.equals(newSearch)) { - questCatSearch = newSearch; - if (questCatScroll != null) - questCatScroll.setList(getSearchList(questCatData, questCatSearch)); - } - } - if (getTextField(56) != null && getTextField(56).isFocused()) { - String newSearch = getTextField(56).getText().toLowerCase(); - if (!questFinishedSearch.equals(newSearch)) { - questFinishedSearch = newSearch; - if (questFinishedScroll != null) - questFinishedScroll.setList(getSearchList(questFinishedData, questFinishedSearch)); - } - } - if (getTextField(57) != null && getTextField(57).isFocused()) { - String newSearch = getTextField(57).getText().toLowerCase(); - if (!questActiveSearch.equals(newSearch)) { - questActiveSearch = newSearch; - if (questActiveScroll != null) - questActiveScroll.setList(getSearchList(questActiveData, questActiveSearch)); - } - } - } - if (currentTab == 11) { - if (viewMode == 0) { - if (getTextField(55) != null && getTextField(55).isFocused()) { - String newSearch = getTextField(55).getText().toLowerCase(); - if (!dialogCatSearch.equals(newSearch)) { - dialogCatSearch = newSearch; - if (dialogCatScroll != null) - dialogCatScroll.setList(getSearchList(dialogCatData, dialogCatSearch)); - } - } - if (getTextField(56) != null && getTextField(56).isFocused()) { - String newSearch = getTextField(56).getText().toLowerCase(); - if (!dialogReadSearch.equals(newSearch)) { - dialogReadSearch = newSearch; - if (dialogReadScroll != null) - dialogReadScroll.setList(getSearchList(dialogReadData, dialogReadSearch)); - } - } - } else { - if (getTextField(55) != null && getTextField(55).isFocused()) { - String newSearch = getTextField(55).getText().toLowerCase(); - if (!dialogCompactSearch.equals(newSearch)) { - dialogCompactSearch = newSearch; - if (dialogCompactScroll != null) - dialogCompactScroll.setList(getSearchList(dialogCompactData, dialogCompactSearch)); - } - } - } - } - if (currentTab == 12) { - if (viewMode == 0) { - if (getTextField(60) != null && getTextField(60).isFocused()) { - String newSearch = getTextField(60).getText().toLowerCase(); - if (!transCatSearch.equals(newSearch)) { - transCatSearch = newSearch; - if (transCatScroll != null) - transCatScroll.setList(getSearchList(transCatData, transCatSearch)); - } - } - if (getTextField(61) != null && getTextField(61).isFocused()) { - String newSearch = getTextField(61).getText().toLowerCase(); - if (!transLocSearch.equals(newSearch)) { - transLocSearch = newSearch; - if (transLocScroll != null) - transLocScroll.setList(getSearchList(transLocData, transLocSearch)); - } - } - } else { - if (getTextField(60) != null && getTextField(60).isFocused()) { - String newSearch = getTextField(60).getText().toLowerCase(); - if (!transCompactSearch.equals(newSearch)) { - transCompactSearch = newSearch; - if (transCompactScroll != null) - transCompactScroll.setList(getSearchList(transCompactData, transCompactSearch)); - } - } - } - } - if (currentTab == 13 || currentTab == 14) { - if (getTextField(70) != null && getTextField(70).isFocused()) { - String newSearch = getTextField(70).getText().toLowerCase(); - if (!singleSearch.equals(newSearch)) { - singleSearch = newSearch; - if (singleScroll != null) - singleScroll.setList(getSearchList(singleData, singleSearch)); - } - } - } - } + //////////////////////////////////////////////////////////////////////////////// + // Mouse & Resizing Handlers + //////////////////////////////////////////////////////////////////////////////// @Override public void mouseClicked(int mouseX, int mouseY, int mouseButton) { - if ((currentTab == 10 || currentTab == 11 || currentTab == 12) && viewMode == 0) { - int regionLeft = leftMargin; - if (currentTab == 10) { - int dividerX1 = regionLeft + dividerOffset1; - int dividerX2 = regionLeft + dividerOffset2; - int regionTop = guiTop + 30; - int regionHeight = 150; - int dividerLineHeight = 20; - int dividerLineYOffset = (regionHeight - dividerLineHeight) / 2; - if (mouseX >= dividerX1 && mouseX <= dividerX1 + dividerWidth && - mouseY >= regionTop + dividerLineYOffset && mouseY <= regionTop + dividerLineYOffset + dividerLineHeight) { - isResizing = true; - draggingDivider = 1; - initialDragX = mouseX; - return; + int hitMargin = 3; + int regionTop = guiTop + scrollTopOffset; + int regionBottom = regionTop + getScrollHeight(); + int paddedLeft = getPaddedLeft(); + int availableWidth = getAvailableWidth(); + if (!hasSubGui() && mouseY >= regionTop && mouseY <= regionBottom) { + if (viewMode == 0) { + if (currentTab == 10) { // Quest categorical: 3 scrolls. + int dividerX1 = paddedLeft + dividerOffset1; + int dividerX2 = paddedLeft + dividerOffset2; + if (mouseX >= dividerX1 - hitMargin && mouseX <= dividerX1 + dividerWidth + hitMargin) { + isResizing = true; + resizingDivider = 1; + initialDragX = mouseX; + return; + } else if (mouseX >= dividerX2 - hitMargin && mouseX <= dividerX2 + dividerWidth + hitMargin) { + isResizing = true; + resizingDivider = 2; + initialDragX = mouseX; + return; + } + } else if (currentTab == 11 || currentTab == 12) { + int dividerX = paddedLeft + dividerOffset1; + if (mouseX >= dividerX - hitMargin && mouseX <= dividerX + dividerWidth + hitMargin) { + isResizing = true; + resizingDivider = 1; + initialDragX = mouseX; + return; + } } - if (mouseX >= dividerX2 && mouseX <= dividerX2 + dividerWidth && - mouseY >= regionTop + dividerLineYOffset && mouseY <= regionTop + dividerLineYOffset + dividerLineHeight) { - isResizing = true; - draggingDivider = 2; - initialDragX = mouseX; - return; - } - } else { - int dividerX = regionLeft + dividerOffset1; - int regionTop = guiTop + 30; - int regionHeight = 150; - int dividerLineHeight = 20; - int dividerLineYOffset = (regionHeight - dividerLineHeight) / 2; - if (mouseX >= dividerX && mouseX <= dividerX + dividerWidth && - mouseY >= regionTop + dividerLineYOffset && mouseY <= regionTop + dividerLineYOffset + dividerLineHeight) { - isResizing = true; - draggingDivider = 1; - initialDragX = mouseX; - return; + } else { // Compact mode. + if (currentTab == 10) { // Quest compact: 2 scrolls. + int defaultWidth = (availableWidth - dividerWidth) / 2; + if (!isResizing) dividerOffset1 = defaultWidth; + int dividerX = paddedLeft + dividerOffset1; + if (mouseX >= dividerX - hitMargin && mouseX <= dividerX + dividerWidth + hitMargin) { + isResizing = true; + resizingDivider = 1; + initialDragX = mouseX; + return; + } } + // Dialog/Transport compact have only one scroll => no divider. } } super.mouseClicked(mouseX, mouseY, mouseButton); @@ -526,78 +465,76 @@ public class SubGuiPlayerData extends SubGuiInterface implements GuiYesNoCallbac @Override public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + int paddedLeft = getPaddedLeft(); + int paddedRight = getPaddedRight(); + int availableWidth = getAvailableWidth(); if (isResizing) { int dx = mouseX - initialDragX; initialDragX = mouseX; + // Handle Quest tab resizing. if (currentTab == 10) { - if (draggingDivider == 1) { - dividerOffset1 += dx; - int regionLeft = leftMargin; - if (dividerOffset1 < minScrollWidth) - dividerOffset1 = minScrollWidth; - if (dividerOffset1 > dividerOffset2 - dividerWidth - minScrollWidth) - dividerOffset1 = dividerOffset2 - dividerWidth - minScrollWidth; + if (viewMode == 0) { // Categorical (3 scrolls) + if (resizingDivider == 1) { + dividerOffset1 += dx; + int maxOffset = dividerOffset2 - dividerWidth - minScrollWidth; + dividerOffset1 = clamp(dividerOffset1, minScrollWidth, maxOffset); + questCatScroll.setSize(dividerOffset1, getScrollHeight()); + questFinishedScroll.guiLeft = paddedLeft + dividerOffset1 + dividerWidth; + questFinishedScroll.setSize(dividerOffset2 - dividerOffset1 - dividerWidth, getScrollHeight()); + questActiveScroll.guiLeft = paddedLeft + dividerOffset2 + dividerWidth; + questActiveScroll.setSize(availableWidth - (dividerOffset2 + dividerWidth), getScrollHeight()); + updateComponentPosition(55, paddedLeft, dividerOffset1); + updateComponentPosition(56, paddedLeft + dividerOffset1 + dividerWidth, dividerOffset2 - dividerOffset1 - dividerWidth); + updateComponentPosition(57, paddedLeft + dividerOffset2 + dividerWidth, availableWidth - (dividerOffset2 + dividerWidth)); + updateLabelPosition(1000, paddedLeft); + updateLabelPosition(1001, paddedLeft + dividerOffset1 + dividerWidth); + updateLabelPosition(1002, paddedLeft + dividerOffset2 + dividerWidth); + } else if (resizingDivider == 2) { + dividerOffset2 += dx; + int minOffset = dividerOffset1 + dividerWidth + minScrollWidth; + int maxOffset = availableWidth - minScrollWidth; + dividerOffset2 = clamp(dividerOffset2, minOffset, maxOffset); + questFinishedScroll.setSize(dividerOffset2 - dividerOffset1 - dividerWidth, getScrollHeight()); + questActiveScroll.guiLeft = paddedLeft + dividerOffset2 + dividerWidth; + questActiveScroll.setSize(availableWidth - (dividerOffset2 + dividerWidth), getScrollHeight()); + updateComponentPosition(56, paddedLeft + dividerOffset1 + dividerWidth, dividerOffset2 - dividerOffset1 - dividerWidth); + updateComponentPosition(57, paddedLeft + dividerOffset2 + dividerWidth, availableWidth - (dividerOffset2 + dividerWidth)); + updateLabelPosition(1001, paddedLeft + dividerOffset1 + dividerWidth); + updateLabelPosition(1002, paddedLeft + dividerOffset2 + dividerWidth); + } + } else { // Compact mode for Quests (2 scrolls) + if (resizingDivider == 1) { + dividerOffset1 += dx; + dividerOffset1 = clamp(dividerOffset1, minScrollWidth, availableWidth - dividerWidth - minScrollWidth); + questFinishedScroll.setSize(dividerOffset1, getScrollHeight()); + questActiveScroll.guiLeft = paddedLeft + dividerOffset1 + dividerWidth; + questActiveScroll.setSize(availableWidth - dividerOffset1 - dividerWidth, getScrollHeight()); + updateComponentPosition(55, paddedLeft, dividerOffset1); + updateComponentPosition(56, paddedLeft + dividerOffset1 + dividerWidth, availableWidth - dividerOffset1 - dividerWidth); + updateLabelPosition(1003, paddedLeft); + updateLabelPosition(1004, paddedLeft + dividerOffset1 + dividerWidth); + } } - if (draggingDivider == 2) { - dividerOffset2 += dx; - int regionLeft = leftMargin; - int regionRight = rightMargin; - if (dividerOffset2 < dividerOffset1 + dividerWidth + minScrollWidth) - dividerOffset2 = dividerOffset1 + dividerWidth + minScrollWidth; - if (dividerOffset2 > (regionRight - regionLeft) - minScrollWidth) - dividerOffset2 = (regionRight - regionLeft) - minScrollWidth; - } - int regionLeft = leftMargin; - int regionRight = rightMargin; - int dividerX1 = regionLeft + dividerOffset1; - int dividerX2 = regionLeft + dividerOffset2; - if (questCatScroll != null) - questCatScroll.setSize(dividerX1 - regionLeft, 150); - if (questFinishedScroll != null) { - questFinishedScroll.guiLeft = dividerX1 + dividerWidth; - questFinishedScroll.setSize(dividerX2 - dividerX1 - dividerWidth, 150); - } - if (questActiveScroll != null) { - questActiveScroll.guiLeft = dividerX2 + dividerWidth; - questActiveScroll.setSize(regionRight - dividerX2 - dividerWidth, 150); - } - if (getTextField(55) != null) - getTextField(55).width = dividerX1 - regionLeft; - if (getTextField(56) != null) - getTextField(56).width = dividerX2 - dividerX1 - dividerWidth; - if (getTextField(57) != null) - getTextField(57).width = regionRight - dividerX2 - dividerWidth; } else if ((currentTab == 11 || currentTab == 12) && viewMode == 0) { - int regionLeft = leftMargin; - int regionRight = rightMargin; + // For Dialog and Transport in categorical mode. dividerOffset1 += dx; - if (dividerOffset1 < minScrollWidth) - dividerOffset1 = minScrollWidth; - if (dividerOffset1 > (regionRight - regionLeft) - dividerWidth - minScrollWidth) - dividerOffset1 = (regionRight - regionLeft) - dividerWidth - minScrollWidth; - int dividerX = regionLeft + dividerOffset1; + dividerOffset1 = clamp(dividerOffset1, minScrollWidth, availableWidth - minScrollWidth); if (currentTab == 11) { - if (dialogCatScroll != null) - dialogCatScroll.setSize(dividerX - regionLeft, 150); - if (dialogReadScroll != null) { - dialogReadScroll.guiLeft = dividerX + dividerWidth; - dialogReadScroll.setSize(regionRight - dividerX - dividerWidth, 150); - } - if (getTextField(55) != null) - getTextField(55).width = dividerX - regionLeft; - if (getTextField(56) != null) - getTextField(56).width = regionRight - dividerX - dividerWidth; - } else { - if (transCatScroll != null) - transCatScroll.setSize(dividerX - regionLeft, 150); - if (transLocScroll != null) { - transLocScroll.guiLeft = dividerX + dividerWidth; - transLocScroll.setSize(regionRight - dividerX - dividerWidth, 150); - } - if (getTextField(60) != null) - getTextField(60).width = dividerX - regionLeft; - if (getTextField(61) != null) - getTextField(61).width = regionRight - dividerX - dividerWidth; + dialogCatScroll.setSize(dividerOffset1, getScrollHeight()); + dialogReadScroll.guiLeft = paddedLeft + dividerOffset1 + dividerWidth; + dialogReadScroll.setSize(availableWidth - dividerOffset1 - dividerWidth, getScrollHeight()); + updateComponentPosition(55, paddedLeft, dividerOffset1); + updateComponentPosition(56, paddedLeft + dividerOffset1 + dividerWidth, availableWidth - dividerOffset1 - dividerWidth); + updateLabelPosition(2000, paddedLeft); + updateLabelPosition(2001, paddedLeft + dividerOffset1 + dividerWidth); + } else if (currentTab == 12) { + transCatScroll.setSize(dividerOffset1, getScrollHeight()); + transLocScroll.guiLeft = paddedLeft + dividerOffset1 + dividerWidth; + transLocScroll.setSize(availableWidth - dividerOffset1 - dividerWidth, getScrollHeight()); + updateComponentPosition(60, paddedLeft, dividerOffset1); + updateComponentPosition(61, paddedLeft + dividerOffset1 + dividerWidth, availableWidth - dividerOffset1 - dividerWidth); + updateLabelPosition(3000, paddedLeft); + updateLabelPosition(3001, paddedLeft + dividerOffset1 + dividerWidth); } } return; @@ -609,320 +546,466 @@ public class SubGuiPlayerData extends SubGuiInterface implements GuiYesNoCallbac protected void mouseMovedOrUp(int mouseX, int mouseY, int state) { if (isResizing) { isResizing = false; - draggingDivider = 0; + resizingDivider = 0; return; } super.mouseMovedOrUp(mouseX, mouseY, state); } - @Override - public void confirmClicked(boolean confirm, int id) { - if (confirm && id == 100 + currentTab) { - int removeId = -1; - String selected = null; - switch (currentTab) { - case 10: - if (questFinishedScroll != null && questFinishedScroll.getSelected() != null) { - selected = questFinishedScroll.getSelected(); - removeId = questFinishedData.get(selected); - } else if (questActiveScroll != null && questActiveScroll.getSelected() != null) { - selected = questActiveScroll.getSelected(); - removeId = questActiveData.get(selected); - } - if (removeId != -1) - PacketClient.sendClient(new PlayerDataRemovePacket(EnumPlayerData.Quest, playerName, removeId)); - break; - case 11: - if (viewMode == 0) { - if (dialogReadScroll != null && dialogReadScroll.getSelected() != null) { - selected = dialogReadScroll.getSelected(); - removeId = dialogReadData.get(selected); - } - } else { - if (dialogCompactScroll != null && dialogCompactScroll.getSelected() != null) { - selected = dialogCompactScroll.getSelected(); - removeId = dialogCompactData.get(selected); - } - } - if (removeId != -1) - PacketClient.sendClient(new PlayerDataRemovePacket(EnumPlayerData.Dialog, playerName, removeId)); - break; - case 12: - if (viewMode == 0) { - if (transLocScroll != null && transLocScroll.getSelected() != null) { - selected = transLocScroll.getSelected(); - removeId = transLocData.get(selected); - } - } else { - if (transCompactScroll != null && transCompactScroll.getSelected() != null) { - selected = transCompactScroll.getSelected(); - removeId = transCompactData.get(selected); - } - } - if (removeId != -1) - PacketClient.sendClient(new PlayerDataRemovePacket(EnumPlayerData.Transport, playerName, removeId)); - break; - case 13: - case 14: - if (singleScroll != null && singleScroll.getSelected() != null) { - selected = singleScroll.getSelected(); - removeId = singleData.get(selected); - } - if (removeId != -1) { - EnumPlayerData type = (currentTab == 13) ? EnumPlayerData.Bank : EnumPlayerData.Factions; - PacketClient.sendClient(new PlayerDataRemovePacket(type, playerName, removeId)); - } - break; - default: - break; - } - } - NoppesUtil.openGUI(mc.thePlayer, this); + // Simple clamp helper. + private int clamp(int value, int min, int max) { + if (value < min) + return min; + if (value > max) + return max; + return value; } - // In setData, for quests we now extract category and remove the suffix from the displayed quest title. - public void setData(Vector list, HashMap data, int dataType) { - lastDataType = dataType; - if (currentTab == 10 && viewMode == 0 && (dataType == 11 || dataType == 12)) { - if (dataType == 11) { - questFinishedData.clear(); - questFinishedCategory.clear(); - for (String key : data.keySet()) { - int colon = key.indexOf(":"); - int paren = key.lastIndexOf("("); - if (colon != -1 && paren != -1) { - String category = key.substring(0, colon).trim(); - String questName = key.substring(colon + 1, paren).trim(); - questFinishedData.put(questName, data.get(key)); - questFinishedCategory.put(questName, category); - if (!questCatData.containsKey(category)) - questCatData.put(category, -1); - } else { - questFinishedData.put(key, data.get(key)); - } - } - if (questFinishedScroll != null) - questFinishedScroll.setList(getSearchList(questFinishedData, questFinishedSearch)); - } else if (dataType == 12) { - questActiveData.clear(); - questActiveCategory.clear(); - for (String key : data.keySet()) { - int colon = key.indexOf(":"); - int paren = key.lastIndexOf("("); - if (colon != -1 && paren != -1) { - String category = key.substring(0, colon).trim(); - String questName = key.substring(colon + 1, paren).trim(); - questActiveData.put(questName, data.get(key)); - questActiveCategory.put(questName, category); - if (!questCatData.containsKey(category)) - questCatData.put(category, -1); - } else { - questActiveData.put(key, data.get(key)); - } - } - if (questActiveScroll != null) - questActiveScroll.setList(getSearchList(questActiveData, questActiveSearch)); - } - if (questCatScroll != null) - questCatScroll.setList(new ArrayList<>(questCatData.keySet())); - return; - } - switch (dataType) { - case 10: - questCatData.clear(); - questCatData.putAll(data); - if (questCatScroll != null) - questCatScroll.setList(getSearchList(questCatData, questCatSearch)); - break; - case 20: - dialogCatData.clear(); - dialogCatData.putAll(data); - // For dialogs, split key into category and title: - dialogCategory.clear(); - HashMap temp = new HashMap<>(); - for (String key : data.keySet()) { - int colon = key.indexOf(":"); - if (colon != -1) { - String cat = key.substring(0, colon).trim(); - String title = key.substring(colon + 1).trim(); - temp.put(title, data.get(key)); - dialogCategory.put(title, cat); - if (!dialogCatData.containsKey(cat)) - dialogCatData.put(cat, -1); - } else { - temp.put(key, data.get(key)); - } - } - dialogCatData.putAll(temp); - if (dialogCatScroll != null) - dialogCatScroll.setList(getSearchList(dialogCatData, dialogCatSearch)); - break; - case 21: - dialogReadData.clear(); - dialogReadData.putAll(data); - if (dialogReadScroll != null) - dialogReadScroll.setList(getSearchList(dialogReadData, dialogReadSearch)); - break; - case 22: - dialogCompactData.clear(); - dialogCompactData.putAll(data); - if (dialogCompactScroll != null) - dialogCompactScroll.setList(getSearchList(dialogCompactData, dialogCompactSearch)); - break; - case 30: - transCatData.clear(); - transCatData.putAll(data); - if (transCatScroll != null) - transCatScroll.setList(getSearchList(transCatData, transCatSearch)); - break; - case 31: - transLocData.clear(); - transLocData.putAll(data); - // For transports, split key into category and location name: - transLocationCategory.clear(); - HashMap temp2 = new HashMap<>(); - for (String key : data.keySet()) { - int colon = key.indexOf(":"); - if (colon != -1) { - String cat = key.substring(0, colon).trim(); - String loc = key.substring(colon + 1).trim(); - temp2.put(loc, data.get(key)); - transLocationCategory.put(loc, cat); - if (!transCatData.containsKey(cat)) - transCatData.put(cat, -1); - } else { - temp2.put(key, data.get(key)); - } - } - transLocData.putAll(temp2); - if (transLocScroll != null) - transLocScroll.setList(getSearchList(transLocData, transLocSearch)); - break; - case 32: - transCompactData.clear(); - transCompactData.putAll(data); - if (transCompactScroll != null) - transCompactScroll.setList(getSearchList(transCompactData, transCompactSearch)); - break; - case 40: - singleData.clear(); - singleData.putAll(data); - if (singleScroll != null) - singleScroll.setList(getSearchList(singleData, singleSearch)); - break; - default: - break; - } - } + //////////////////////////////////////////////////////////////////////////////// + // Key & Search Field Handling + //////////////////////////////////////////////////////////////////////////////// @Override - public void setData(Vector list, HashMap data) { - setData(list, data, lastDataType); - } - - @Override - public void setSelected(String selected) { - // Handled in customScrollClicked. - } - - @Override - public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) { + public void keyTyped(char c, int i) { + super.keyTyped(c, i); if (currentTab == 10) { - if (scroll.id == 0) { - selectedQuestCategory = scroll.getSelected(); - questFinishedScroll.setList(filterQuestsByCategory(questFinishedData, questFinishedCategory, selectedQuestCategory)); - questActiveScroll.setList(filterQuestsByCategory(questActiveData, questActiveCategory, selectedQuestCategory)); - } else if (scroll.id == 1) { - lastDataType = 11; - if (questActiveScroll != null) - questActiveScroll.setSelected(null); - } else if (scroll.id == 2) { - lastDataType = 12; - if (questFinishedScroll != null) - questFinishedScroll.setSelected(null); + if (viewMode == 0) { + updateQuestSearchField(55, 56, 57); + } else { + updateQuestSearchFieldCompact(55, 56); } } else if (currentTab == 11) { if (viewMode == 0) { - if (scroll.id == 0) { - selectedDialogCategory = scroll.getSelected(); - dialogReadScroll.setList(filterDialogsByCategory(dialogReadData, dialogCategory, selectedDialogCategory)); - } else if (scroll.id == 1) { - lastDataType = 21; - if (dialogCatScroll != null) - dialogCatScroll.setSelected(null); - } + updateDialogSearchField(55, 56); } else { - lastDataType = 22; + updateDialogSearchFieldCompact(55); } } else if (currentTab == 12) { if (viewMode == 0) { - if (scroll.id == 3) { - selectedTransCategory = scroll.getSelected(); - transLocScroll.setList(filterTransportsByCategory(transLocData, transLocationCategory, selectedTransCategory)); - } else if (scroll.id == 4) { - lastDataType = 31; - if (transCatScroll != null) - transCatScroll.setSelected(null); - } + updateTransportSearchField(60, 61); } else { - lastDataType = 32; + updateTransportSearchFieldCompact(60); } } else if (currentTab == 13 || currentTab == 14) { - lastDataType = 40; + updateSingleSearchField(70); } } - @Override - public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) { - // Optional double-click behavior. + // Update quest search fields (categorical mode). + private void updateQuestSearchField(int catFieldId, int finishedFieldId, int activeFieldId) { + GuiNpcTextField tf = getTextField(catFieldId); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!questCatSearch.equals(newText)) { + questCatSearch = newText; + if (questCatScroll != null) { + if (selectedQuestCategory.isEmpty()) + questCatScroll.setList(new ArrayList<>()); + else + questCatScroll.setList(filterList(questCatData, questCatSearch)); + } + } + } + tf = getTextField(finishedFieldId); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!questFinishedSearch.equals(newText)) { + questFinishedSearch = newText; + if (questFinishedScroll != null) + questFinishedScroll.setList( + selectedQuestCategory.isEmpty() ? + new ArrayList<>() : + filterAndTrimListByCategory(questFinishedData, selectedQuestCategory, questFinishedSearch) + ); + } + } + tf = getTextField(activeFieldId); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!questActiveSearch.equals(newText)) { + questActiveSearch = newText; + if (questActiveScroll != null) + questActiveScroll.setList( + selectedQuestCategory.isEmpty() ? + new ArrayList<>() : + filterAndTrimListByCategory(questActiveData, selectedQuestCategory, questActiveSearch) + ); + } + } } - private List getSearchList(HashMap dataMap, String searchTerm) { - if (searchTerm.isEmpty()) - return new ArrayList<>(dataMap.keySet()); + // Update quest search fields in compact mode. + private void updateQuestSearchFieldCompact(int finishedFieldId, int activeFieldId) { + GuiNpcTextField tf = getTextField(finishedFieldId); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!questFinishedSearch.equals(newText)) { + questFinishedSearch = newText; + if (questFinishedScroll != null) + questFinishedScroll.setList(filterList(questFinishedData, questFinishedSearch)); + } + } + tf = getTextField(activeFieldId); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!questActiveSearch.equals(newText)) { + questActiveSearch = newText; + if (questActiveScroll != null) + questActiveScroll.setList(filterList(questActiveData, questActiveSearch)); + } + } + } + + // Update dialog search fields (categorical). + private void updateDialogSearchField(int catFieldId, int readFieldId) { + GuiNpcTextField tf = getTextField(catFieldId); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!dialogCatSearch.equals(newText)) { + dialogCatSearch = newText; + if (dialogCatScroll != null) + dialogCatScroll.setList( + selectedDialogCategory.isEmpty() ? + new ArrayList<>() : + filterList(dialogCatData, dialogCatSearch) + ); + } + } + tf = getTextField(readFieldId); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!dialogReadSearch.equals(newText)) { + dialogReadSearch = newText; + if (dialogReadScroll != null) + dialogReadScroll.setList( + selectedDialogCategory.isEmpty() ? + new ArrayList<>() : + filterAndTrimListByCategory(dialogReadData, selectedDialogCategory, dialogReadSearch) + ); + } + } + } + + // Update dialog search fields (compact). + private void updateDialogSearchFieldCompact(int fieldId) { + GuiNpcTextField tf = getTextField(fieldId); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!dialogCompactSearch.equals(newText)) { + dialogCompactSearch = newText; + if (dialogCompactScroll != null) + dialogCompactScroll.setList(filterList(dialogReadData, dialogCompactSearch)); + } + } + } + + // Update transport search fields (categorical). + private void updateTransportSearchField(int catFieldId, int locFieldId) { + GuiNpcTextField tf = getTextField(catFieldId); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!transCatSearch.equals(newText)) { + transCatSearch = newText; + if (transCatScroll != null) + transCatScroll.setList( + selectedTransCategory.isEmpty() ? + new ArrayList<>() : + filterList(transCatData, transCatSearch) + ); + } + } + tf = getTextField(locFieldId); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!transLocSearch.equals(newText)) { + transLocSearch = newText; + if (transLocScroll != null) + transLocScroll.setList( + selectedTransCategory.isEmpty() ? + new ArrayList<>() : + filterAndTrimListByCategory(transLocData, selectedTransCategory, transLocSearch) + ); + } + } + } + + // Update transport search fields (compact). + private void updateTransportSearchFieldCompact(int fieldId) { + GuiNpcTextField tf = getTextField(fieldId); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!transCompactSearch.equals(newText)) { + transCompactSearch = newText; + if (transCompactScroll != null) + transCompactScroll.setList(filterList(transLocData, transCompactSearch)); + } + } + } + + // Update search field for single scroll (Bank/Faction). + private void updateSingleSearchField(int fieldId) { + GuiNpcTextField tf = getTextField(fieldId); + if (tf != null && tf.isFocused()) { + String newText = tf.getText().toLowerCase(); + if (!singleSearch.equals(newText)) { + singleSearch = newText; + if (singleScroll != null) + singleScroll.setList(filterList(currentTab == 13 ? bankData : factionData, singleSearch)); + } + } + } + + // Standard filtering helpers. + private List filterList(HashMap data, String search) { List list = new ArrayList<>(); - for (String key : dataMap.keySet()) { - if (key.toLowerCase().contains(searchTerm)) + for (String key : data.keySet()) { + if (key.toLowerCase().contains(search)) { list.add(key); + } } return list; } - private List filterQuestsByCategory(HashMap questMap, HashMap catMap, String category) { - List filtered = new ArrayList<>(); - for (String title : questMap.keySet()) { - if (catMap.containsKey(title) && catMap.get(title).equalsIgnoreCase(category)) - filtered.add(title); + private List filterAndTrimListByCategory(HashMap data, String category, String search) { + List list = new ArrayList<>(); + String prefix = category + ":"; + for (String key : data.keySet()) { + if (key.startsWith(prefix)) { + String trimmed = key.substring(prefix.length()).trim(); + if (trimmed.toLowerCase().contains(search)) { + list.add(trimmed); + } + } } - return filtered; + return list; } - private List filterDialogsByCategory(HashMap dialogMap, HashMap catMap, String category) { - List filtered = new ArrayList<>(); - for (String title : dialogMap.keySet()) { - if (catMap.containsKey(title) && catMap.get(title).equalsIgnoreCase(category)) - filtered.add(title); + //////////////////////////////////////////////////////////////////////////////// + // Action Handling + //////////////////////////////////////////////////////////////////////////////// + + @Override + public void actionPerformed(GuiButton button) { + // Close if the "X" button was clicked. + if (button.id == -5) { + close(); + return; + } + // Tab switching. + if (button.id >= 10 && button.id <= 14) { + currentTab = button.id; + initGui(); // Reinitialize components using stored data. + return; + } + // Mode toggle. + if (button.id == 20) { + viewMode = (viewMode == 0) ? 1 : 0; + initGui(); + } + // Delete button. + else if (button.id == 30) { + Integer selectedID = null; + EnumPlayerData tabType = null; + if (currentTab == 10) { + if (viewMode == 0) { + if (questCatScroll.getSelected() == null) + return; + if (questActiveScroll.getSelected() != null) { + selectedID = questActiveData.get(questCatScroll.getSelected() + ": " + questActiveScroll.getSelected()); + if (selectedID != null) { + questActiveScroll.list.remove(questActiveScroll.selected); + questActiveData.remove(questCatScroll.getSelected() + ": " + questActiveScroll.getSelected()); + } + tabType = EnumPlayerData.Quest; + } else if (questFinishedScroll.getSelected() != null) { + selectedID = questFinishedData.get(questCatScroll.getSelected() + ": " + questFinishedScroll.getSelected()); + if (selectedID != null) { + questFinishedScroll.list.remove(questFinishedScroll.selected); + questFinishedData.remove(questCatScroll.getSelected() + ": " + questFinishedScroll.getSelected()); + } + tabType = EnumPlayerData.Quest; + } + } else { + if (questActiveScroll.getSelected() != null) { + selectedID = questActiveData.get(questActiveScroll.getSelected()); + if (selectedID != null) { + questActiveScroll.list.remove(questActiveScroll.selected); + questActiveData.remove(questActiveScroll.getSelected()); + } + tabType = EnumPlayerData.Quest; + } else if (questFinishedScroll.getSelected() != null) { + selectedID = questFinishedData.get(questFinishedScroll.getSelected()); + if (selectedID != null) { + questFinishedScroll.list.remove(questFinishedScroll.selected); + questFinishedData.remove(questFinishedScroll.getSelected()); + } + tabType = EnumPlayerData.Quest; + } + } + } else if (currentTab == 11) { + if (viewMode == 0) { + if (dialogReadScroll.getSelected() != null && dialogCatScroll.getSelected() != null) { + selectedID = dialogReadData.get(dialogCatScroll.getSelected() + ": " + dialogReadScroll.getSelected()); + if (selectedID != null) { + dialogReadScroll.list.remove(dialogReadScroll.selected); + dialogReadData.remove(dialogCatScroll.getSelected() + ": " + dialogReadScroll.getSelected()); + } + tabType = EnumPlayerData.Dialog; + } + } else { + if (dialogCompactScroll.getSelected() != null) { + selectedID = dialogReadData.get(dialogCompactScroll.getSelected()); + if (selectedID != null) { + dialogCompactScroll.list.remove(dialogCompactScroll.selected); + dialogReadData.remove(dialogCompactScroll.getSelected()); + } + tabType = EnumPlayerData.Dialog; + } + } + } else if (currentTab == 12) { + if (viewMode == 0) { + if (transLocScroll.getSelected() != null && transCatScroll.getSelected() != null) { + selectedID = transLocData.get(transCatScroll.getSelected() + ": " + transLocScroll.getSelected()); + if (selectedID != null) { + transLocScroll.list.remove(transLocScroll.selected); + transLocData.remove(transCatScroll.getSelected() + ": " + transLocScroll.getSelected()); + } + tabType = EnumPlayerData.Transport; + } + } else { + if (transCompactScroll.getSelected() != null) { + selectedID = transLocData.get(transCompactScroll.getSelected()); + if (selectedID != null) { + transCompactScroll.list.remove(transCompactScroll.selected); + transLocData.remove(transCompactScroll.getSelected()); + } + tabType = EnumPlayerData.Transport; + } + } + } else if (currentTab == 13) { + if (singleScroll.getSelected() != null) { + selectedID = bankData.get(singleScroll.getSelected()); + if (selectedID != null) { + singleScroll.list.remove(singleScroll.selected); + bankData.remove(singleScroll.getSelected()); + } + tabType = EnumPlayerData.Bank; + } + } else if (currentTab == 14) { + if (singleScroll.getSelected() != null) { + selectedID = factionData.get(singleScroll.getSelected()); + if (selectedID != null) { + singleScroll.list.remove(singleScroll.selected); + factionData.remove(singleScroll.getSelected()); + } + tabType = EnumPlayerData.Factions; + } + } + if (selectedID != null) { + PacketClient.sendClient(new PlayerDataRemoveInfoPacket(playerName, tabType, selectedID)); + } } - return filtered; } - private List filterTransportsByCategory(HashMap transMap, HashMap catMap, String category) { - List filtered = new ArrayList<>(); - for (String name : transMap.keySet()) { - if (catMap.containsKey(name) && catMap.get(name).equalsIgnoreCase(category)) - filtered.add(name); + //////////////////////////////////////////////////////////////////////////////// + // Data Setting Methods (IPlayerDataInfo) + //////////////////////////////////////////////////////////////////////////////// + + @Override + public void setQuestData(Map questCategories, Map questActive, Map questFinished) { + this.questCatData = new HashMap<>(questCategories); + this.questActiveData = new HashMap<>(questActive); + this.questFinishedData = new HashMap<>(questFinished); + if (questCatScroll != null) { + questCatScroll.setList(new ArrayList<>(questCatData.keySet())); } - return filtered; } @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - drawDefaultBackground(); - super.drawScreen(mouseX, mouseY, partialTicks); + public void setDialogData(Map dialogCategories, Map dialogRead) { + this.dialogCatData = new HashMap<>(dialogCategories); + this.dialogReadData = new HashMap<>(dialogRead); + if (dialogCatScroll != null) { + dialogCatScroll.setList(new ArrayList<>(dialogCatData.keySet())); + } + if (dialogReadScroll != null) { + dialogReadScroll.setList(new ArrayList<>(dialogReadData.keySet())); + } + if (dialogCompactScroll != null) { + List merged = new ArrayList<>(dialogReadData.keySet()); + dialogCompactScroll.setList(merged); + } } @Override - public void close() { - super.close(); + public void setTransportData(Map transportCategories, Map transportLocations) { + this.transCatData = new HashMap<>(transportCategories); + this.transLocData = new HashMap<>(transportLocations); + if (transCatScroll != null) { + transCatScroll.setList(new ArrayList<>(transCatData.keySet())); + } + if (transLocScroll != null) { + transLocScroll.setList(new ArrayList<>(transLocData.keySet())); + } + if (transCompactScroll != null) { + List merged = new ArrayList<>(transLocData.keySet()); + transCompactScroll.setList(merged); + } + } + + @Override + public void setBankData(Map bankData) { + this.bankData = new HashMap<>(bankData); + if (singleScroll != null && currentTab == 13) { + singleScroll.setList(new ArrayList<>(this.bankData.keySet())); + } + } + + @Override + public void setFactionData(Map factionData) { + this.factionData = new HashMap<>(factionData); + if (singleScroll != null && currentTab == 14) { + singleScroll.setList(new ArrayList<>(this.factionData.keySet())); + } + } + + //////////////////////////////////////////////////////////////////////////////// + // Custom Scroll Click Handling + //////////////////////////////////////////////////////////////////////////////// + + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { + if (guiCustomScroll == questCatScroll) { + selectedQuestCategory = questCatScroll.getSelected(); + questFinishedScroll.resetScroll(); + questActiveScroll.resetScroll(); + if (!selectedQuestCategory.isEmpty()) { + questFinishedScroll.setList(filterAndTrimListByCategory(questFinishedData, selectedQuestCategory, questFinishedSearch)); + questActiveScroll.setList(filterAndTrimListByCategory(questActiveData, selectedQuestCategory, questActiveSearch)); + } else { + questFinishedScroll.setList(new ArrayList<>()); + questActiveScroll.setList(new ArrayList<>()); + } + } else if (guiCustomScroll == dialogCatScroll) { + selectedDialogCategory = dialogCatScroll.getSelected(); + dialogReadScroll.resetScroll(); + if (!selectedDialogCategory.isEmpty()) { + dialogReadScroll.setList(filterAndTrimListByCategory(dialogReadData, selectedDialogCategory, dialogReadSearch)); + } else { + dialogReadScroll.setList(new ArrayList<>()); + } + } else if (guiCustomScroll == transCatScroll) { + selectedTransCategory = transCatScroll.getSelected(); + transLocScroll.resetScroll(); + if (!selectedTransCategory.isEmpty()) { + transLocScroll.setList(filterAndTrimListByCategory(transLocData, selectedTransCategory, transLocSearch)); + } else { + transLocScroll.setList(new ArrayList<>()); + } + } else if (guiCustomScroll == questActiveScroll) { + questFinishedScroll.selected = -1; + } else if (guiCustomScroll == questFinishedScroll) { + questActiveScroll.selected = -1; + } } } 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 6b9b02e6f..e3c5cc9d8 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java @@ -1,13 +1,12 @@ package noppes.npcs.client.gui.global; import kamkeel.npcs.network.PacketClient; -import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetPacket; +import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetNamesPacket; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataMapRegenPacket; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataRemovePacket; import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; import noppes.npcs.client.gui.SubGuiPlayerData; -import noppes.npcs.client.gui.test.SubGuiPlayerDataNew; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPlayerData; import net.minecraft.util.StatCollector; @@ -29,7 +28,7 @@ public class GuiNpcManagePlayerData extends GuiNPCInterface2 implements GuiYesNo public GuiNpcManagePlayerData(EntityNPCInterface npcInterface) { super(npcInterface); // Request the complete list of players. - PacketClient.sendClient(new PlayerDataGetPacket(EnumPlayerData.Players, "")); + PacketClient.sendClient(new PlayerDataGetNamesPacket(EnumPlayerData.Players, "")); } @Override @@ -101,7 +100,7 @@ public class GuiNpcManagePlayerData extends GuiNPCInterface2 implements GuiYesNo } if (id == 1) { if (selectedPlayer != null) { - setSubGui(new SubGuiPlayerDataNew(selectedPlayer)); + setSubGui(new SubGuiPlayerData(selectedPlayer)); } } if (id == 2) { diff --git a/src/main/java/noppes/npcs/client/gui/test/NoppesUtilClientNew.java b/src/main/java/noppes/npcs/client/gui/test/NoppesUtilClientNew.java deleted file mode 100644 index ecb62dc6f..000000000 --- a/src/main/java/noppes/npcs/client/gui/test/NoppesUtilClientNew.java +++ /dev/null @@ -1,74 +0,0 @@ -package noppes.npcs.client.gui.test; - -import io.netty.buffer.ByteBuf; -import kamkeel.npcs.util.ByteBufUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.entity.player.EntityPlayer; -import noppes.npcs.client.gui.util.GuiContainerNPCInterface; -import noppes.npcs.client.gui.util.GuiNPCInterface; -import noppes.npcs.client.gui.util.IScrollData; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Vector; - -public class NoppesUtilClientNew { - - /** - * Handles the incoming large packet with full player data. - * The packet writes: - * - player name (String) - * - questCategories, questActive, questFinished (maps) - * - dialogCategories, dialogRead (maps) - * - transportCategories, transportLocations (maps) - * - bankData, factionData (maps) - * - * The existing PlayerDataController functions are used on the server side; - * here we simply update the active SubGuiPlayerDataNew if present. - */ - public static void handlePlayerData(ByteBuf data, EntityPlayer player) throws IOException { - String playerName = ByteBufUtils.readString(data); - Map questCategories = readMap(data); - Map questActive = readMap(data); - Map questFinished = readMap(data); - Map dialogCategories = readMap(data); - Map dialogRead = readMap(data); - Map transportCategories = readMap(data); - Map transportLocations = readMap(data); - Map bankData = readMap(data); - Map factionData = readMap(data); - - - GuiScreen gui = Minecraft.getMinecraft().currentScreen; - if(gui == null) - return; - if(gui instanceof GuiNPCInterface && ((GuiNPCInterface)gui).hasSubGui()){ - gui = (GuiScreen) ((GuiNPCInterface)gui).getSubGui(); - } - - if(gui instanceof GuiContainerNPCInterface && ((GuiContainerNPCInterface)gui).hasSubGui()){ - gui = (GuiScreen) ((GuiContainerNPCInterface)gui).getSubGui(); - } - if (gui instanceof IPlayerDataInfo) { - IPlayerDataInfo info = (IPlayerDataInfo) gui; - info.setQuestData(questCategories, questActive, questFinished); - info.setDialogData(dialogCategories, dialogRead); - info.setTransportData(transportCategories, transportLocations); - info.setBankData(bankData); - info.setFactionData(factionData); - } - } - - private static Map readMap(ByteBuf data) { - int size = data.readInt(); - Map map = new HashMap<>(); - for (int i = 0; i < size; i++) { - String key = ByteBufUtils.readString(data); - int value = data.readInt(); - map.put(key, value); - } - return map; - } -} diff --git a/src/main/java/noppes/npcs/client/gui/test/NoppesUtilServerNew.java b/src/main/java/noppes/npcs/client/gui/test/NoppesUtilServerNew.java deleted file mode 100644 index 4fc9d15d5..000000000 --- a/src/main/java/noppes/npcs/client/gui/test/NoppesUtilServerNew.java +++ /dev/null @@ -1,155 +0,0 @@ -package noppes.npcs.client.gui.test; - -import kamkeel.npcs.controllers.SyncController; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.server.MinecraftServer; -import kamkeel.npcs.network.PacketHandler; -import noppes.npcs.controllers.*; -import noppes.npcs.controllers.data.*; -import noppes.npcs.config.ConfigMain; -import net.minecraft.nbt.NBTTagCompound; -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -public class NoppesUtilServerNew { - - /** - * Retrieves the player's data from the existing PlayerDataController and sends - * a large packet to the client containing all the maps, including categories. - */ - public static void sendPlayerData(String playerName, EntityPlayerMP player) { - PlayerData playerdata; - EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(playerName); - if(pl == null) - playerdata = PlayerDataController.Instance.getDataFromUsername(playerName); - else - playerdata = PlayerDataController.Instance.getPlayerData(pl); - - // Assemble quest maps: - Map questActiveMap = new HashMap<>(); - Map questFinishedMap = new HashMap<>(); - Map questCategoriesMap = new HashMap<>(); - QuestController qc = QuestController.Instance; - PlayerQuestData qData = playerdata.questData; - for (Integer questId : qData.activeQuests.keySet()) { - if(!qc.quests.containsKey(questId)) - continue; - Quest quest = qc.quests.get(questId); - questActiveMap.put(quest.category.title + ": " + quest.title, questId); - if (!questCategoriesMap.containsKey(quest.category.title)) - questCategoriesMap.put(quest.category.title, quest.category.id); - } - for (Integer questId : qData.finishedQuests.keySet()) { - if(!qc.quests.containsKey(questId)) - continue; - Quest quest = qc.quests.get(questId); - questFinishedMap.put(quest.category.title + ": " + quest.title, questId); - if (!questCategoriesMap.containsKey(quest.category.title)) - questCategoriesMap.put(quest.category.title, quest.category.id); - } - - // Assemble dialog maps: - Map dialogReadMap = new HashMap<>(); - Map dialogCategoriesMap = new HashMap<>(); - PlayerDialogData dData = playerdata.dialogData; - for (Integer dialogId : dData.dialogsRead) { - if(!DialogController.Instance.dialogs.containsKey(dialogId)) - continue; - Dialog dialog = DialogController.Instance.dialogs.get(dialogId); - dialogReadMap.put(dialog.category.title + ": " + dialog.title, dialogId); - if (!dialogCategoriesMap.containsKey(dialog.category.title)) - dialogCategoriesMap.put(dialog.category.title, dialog.category.id); - } - - // Assemble transport maps: - Map transportLocationsMap = new HashMap<>(); - Map transportCategoriesMap = new HashMap<>(); - PlayerTransportData tData = playerdata.transportData; - TransportController tc = TransportController.getInstance(); - for (Integer id : tData.transports) { - TransportLocation location = tc.getTransport(id); - if(location == null) - continue; - transportLocationsMap.put(location.category.title + ": " + location.name, id); - if (!transportCategoriesMap.containsKey(location.category.title)) - transportCategoriesMap.put(location.category.title, location.category.id); - } - - // Assemble bank map: - Map bankMap = new HashMap<>(); - PlayerBankData bData = playerdata.bankData; - BankController bc = BankController.getInstance(); - for (Integer bankId : bData.banks.keySet()) { - if(!bc.banks.containsKey(bankId)) - continue; - Bank bank = bc.banks.get(bankId); - bankMap.put(bank.name, bankId); - } - - // Assemble faction map: - Map factionMap = new HashMap<>(); - PlayerFactionData fData = playerdata.factionData; - FactionController fc = FactionController.getInstance(); - for (Integer factionId : fData.factionData.keySet()) { - if(!fc.factions.containsKey(factionId)) - continue; - Faction faction = fc.factions.get(factionId); - factionMap.put(faction.name + "(" + fData.getFactionPoints(factionId) + ")", factionId); - } - - // Send the full packet with categories, active/finished data, dialogs, transports, banks, and factions. - PlayerDataSendPacketNew packet = new PlayerDataSendPacketNew(playerName, - questCategoriesMap, questActiveMap, questFinishedMap, - dialogCategoriesMap, dialogReadMap, - transportCategoriesMap, transportLocationsMap, - bankMap, factionMap); - PacketHandler.Instance.sendToPlayer(packet, player); - } - - /** - * Removes a specific data entry from the player's data. - * - * The tabType parameter is used as follows: - * 0: Quest – remove from both activeQuests and finishedQuests. - * 1: Dialog – remove from dialogsRead. - * 2: Transport – remove from transports. - * 3: Bank – remove from banks. - * 4: Factions – remove from factionData. - * - * The selectedKey is expected to be the string representation of the entry's ID. - */ - public static void removePlayerData(String playerName, int tabType, int value, EntityPlayerMP player) { - EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(playerName); - PlayerData playerdata; - if(pl == null) - playerdata = PlayerDataController.Instance.getDataFromUsername(playerName); - else - playerdata = PlayerDataController.Instance.getPlayerData(pl); - - if(tabType == 0) { // Quest removal - playerdata.questData.activeQuests.remove(value); - playerdata.questData.finishedQuests.remove(value); - } - if(tabType == 1) { // Dialog removal - playerdata.dialogData.dialogsRead.remove(value); - } - if(tabType == 2) { // Transport removal - playerdata.transportData.transports.remove(value); - } - if(tabType == 3) { // Bank removal - playerdata.bankData.banks.remove(value); - } - if(tabType == 4) { // Faction removal - playerdata.factionData.factionData.remove(value); - } - playerdata.save(); - - if(pl != null) { - SyncController.syncPlayer((EntityPlayerMP) pl); - } - // Resend the updated data to the client. - sendPlayerData(playerName, player); - } -} diff --git a/src/main/java/noppes/npcs/client/gui/test/PlayerDataTab.java b/src/main/java/noppes/npcs/client/gui/test/PlayerDataTab.java deleted file mode 100644 index 713836dd3..000000000 --- a/src/main/java/noppes/npcs/client/gui/test/PlayerDataTab.java +++ /dev/null @@ -1,9 +0,0 @@ -package noppes.npcs.client.gui.test; - -public enum PlayerDataTab { - QUEST, - DIALOG, - TRANSPORT, - BANK, - FACTION; -} diff --git a/src/main/java/noppes/npcs/client/gui/test/SubGuiPlayerDataNew.java b/src/main/java/noppes/npcs/client/gui/test/SubGuiPlayerDataNew.java deleted file mode 100644 index bd382d07f..000000000 --- a/src/main/java/noppes/npcs/client/gui/test/SubGuiPlayerDataNew.java +++ /dev/null @@ -1,864 +0,0 @@ -package noppes.npcs.client.gui.test; - -import kamkeel.npcs.network.PacketClient; -import noppes.npcs.client.CustomNpcResourceListener; -import noppes.npcs.client.gui.util.*; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.util.StatCollector; -import noppes.npcs.constants.EnumPlayerData; -import org.lwjgl.input.Mouse; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class SubGuiPlayerDataNew extends SubGuiInterface implements IPlayerDataInfo, ICustomScrollListener { - - // Tabs: 10 = Quest, 11 = Dialog, 12 = Transport, 13 = Bank, 14 = Faction. - private int currentTab = 10; - // View mode: 0 = Categorical (3 or 2 scrolls), 1 = Compact (2 or 1 scroll). - private int viewMode = 0; - - // Quest Tab components: - protected GuiCustomScroll questCatScroll, questActiveScroll, questFinishedScroll; - private String questCatSearch = "", questActiveSearch = "", questFinishedSearch = ""; - private HashMap questCatData = new HashMap<>(); - private HashMap questActiveData = new HashMap<>(); - private HashMap questFinishedData = new HashMap<>(); - private String selectedQuestCategory = ""; - - // Dialog Tab components: - protected GuiCustomScroll dialogCatScroll, dialogReadScroll, dialogCompactScroll; - private String dialogCatSearch = "", dialogReadSearch = "", dialogCompactSearch = ""; - private HashMap dialogCatData = new HashMap<>(); - private HashMap dialogReadData = new HashMap<>(); - private String selectedDialogCategory = ""; - - // Transport Tab components: - protected GuiCustomScroll transCatScroll, transLocScroll, transCompactScroll; - private String transCatSearch = "", transLocSearch = "", transCompactSearch = ""; - private HashMap transCatData = new HashMap<>(); - private HashMap transLocData = new HashMap<>(); - private String selectedTransCategory = ""; - - // Bank and Faction tabs – separate data and one scroll: - protected GuiCustomScroll singleScroll; - private String singleSearch = ""; - private HashMap bankData = new HashMap<>(); - private HashMap factionData = new HashMap<>(); - - // Divider/resizing variables for categorical mode. - // For Quest tab: in categorical mode we use 2 dividers (3 scrolls) - // In compact mode for Quests we use one divider between the two scrolls. - private int dividerOffset1 = 0; // In categorical: width of left scroll; in compact for quests: width of left scroll. - private int dividerOffset2 = 0; // Only for Quest categorical mode. - private final int dividerWidth = 5; - private final int minScrollWidth = 50; - private boolean isResizing = false; - private int resizingDivider = 0; - private int initialDragX = 0; - - // Layout constants. - private final int leftPadding = 6; - private final int rightPadding = 6; - private final int scrollTopOffset = 30; - private final int verticalGapAboveTF = 3; - private final int textFieldHeight = 20; - private final int verticalGapBelowTF = 3; - - // The player name for which we are displaying data. - private String playerName; - - public SubGuiPlayerDataNew(String playerName) { - this.playerName = playerName; - xSize = 420; - ySize = 215; - setBackground("menubg.png"); - closeOnEsc = true; - PacketClient.sendClient(new PlayerDataGetPacketNew(playerName)); - } - - @Override - public void handleMouseInput() { - super.handleMouseInput(); - } - - @Override - public void initGui() { - super.initGui(); - // Top tab buttons: - GuiMenuTopButton btnQuest = new GuiMenuTopButton(10, guiLeft + 4, guiTop - 10, StatCollector.translateToLocal("tab.quests")); - GuiMenuTopButton btnDialog = new GuiMenuTopButton(11, btnQuest.xPosition + btnQuest.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.dialog")); - GuiMenuTopButton btnTransport = new GuiMenuTopButton(12, btnDialog.xPosition + btnDialog.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.transport")); - GuiMenuTopButton btnBank = new GuiMenuTopButton(13, btnTransport.xPosition + btnTransport.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.bank")); - GuiMenuTopButton btnFaction = new GuiMenuTopButton(14, btnBank.xPosition + btnBank.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.faction")); - GuiMenuTopButton close = new GuiMenuTopButton(-5, guiLeft + xSize - 22, guiTop - 10, "X"); - - btnQuest.active = (currentTab == 10); - btnDialog.active = (currentTab == 11); - btnTransport.active = (currentTab == 12); - btnBank.active = (currentTab == 13); - btnFaction.active = (currentTab == 14); - addTopButton(btnQuest); - addTopButton(btnDialog); - addTopButton(btnTransport); - addTopButton(btnBank); - addTopButton(btnFaction); - addTopButton(close); - - // Mode toggle button (50px wide) - if (currentTab == 10 || currentTab == 11 || currentTab == 12) { - String modeText = viewMode == 0 ? StatCollector.translateToLocal("view.categorical") : StatCollector.translateToLocal("view.compact"); - addButton(new GuiNpcButton(20, guiLeft + xSize - 60, guiTop + 10, 50, 20, modeText)); - } - - guiTop += 7; - - - // Initialize components for the current tab: - switch (currentTab) { - case 10: initQuestTab(); break; - case 11: initDialogTab(); break; - case 12: initTransportTab(); break; - case 13: - case 14: initSingleTab(); break; - } - // Delete button (50px wide) - addButton(new GuiNpcButton(30, guiLeft + xSize - 60, guiTop + ySize - 30, 50, 20, StatCollector.translateToLocal("button.delete"))); - } - - private int getScrollHeight() { - return ySize - (scrollTopOffset + verticalGapAboveTF + textFieldHeight + verticalGapBelowTF); - } - - private int getTextFieldY() { - return guiTop + scrollTopOffset + getScrollHeight() + verticalGapAboveTF; - } - - // Init Quest Tab. - private void initQuestTab() { - int regionLeft = guiLeft + leftPadding; - int regionRight = guiLeft + xSize - rightPadding; - int availableWidth = regionRight - regionLeft; - int scrollHeight = getScrollHeight(); - - if (viewMode == 0) { // Categorical: 3 scrolls. - if (!isResizing) { - dividerOffset1 = (availableWidth - 2 * dividerWidth) / 3; - dividerOffset2 = dividerOffset1 + dividerWidth + (availableWidth - 2 * dividerWidth) / 3; - } - if (questCatScroll == null) questCatScroll = new GuiCustomScroll(this, 0, 0); - questCatScroll.guiLeft = regionLeft; - questCatScroll.guiTop = guiTop + scrollTopOffset; - questCatScroll.setSize(dividerOffset1, scrollHeight); - questCatScroll.setList(new ArrayList<>(questCatData.keySet())); - questCatScroll.selected = -1; - questCatSearch = ""; - addScroll(questCatScroll); - addLabel(new GuiNpcLabel(1000, "Categories", regionLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - - if (questFinishedScroll == null) questFinishedScroll = new GuiCustomScroll(this, 1, 0); - questFinishedScroll.guiLeft = regionLeft + dividerOffset1 + dividerWidth; - questFinishedScroll.guiTop = guiTop + scrollTopOffset; - questFinishedScroll.setSize(dividerOffset2 - dividerOffset1 - dividerWidth, scrollHeight); - questFinishedScroll.setList(new ArrayList<>()); - questFinishedScroll.selected = -1; - questFinishedSearch = ""; - addScroll(questFinishedScroll); - addLabel(new GuiNpcLabel(1001, "Finished", regionLeft + dividerOffset1 + dividerWidth, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - - if (questActiveScroll == null) - questActiveScroll = new GuiCustomScroll(this, 2, 0); - - questActiveScroll.guiLeft = regionLeft + dividerOffset2 + dividerWidth; - questActiveScroll.guiTop = guiTop + scrollTopOffset; - questActiveScroll.setSize(regionRight - (regionLeft + dividerOffset2 + dividerWidth), scrollHeight); - questActiveScroll.setList(new ArrayList<>()); - questActiveScroll.selected = -1; - questActiveSearch = ""; - addScroll(questActiveScroll); - addLabel(new GuiNpcLabel(1002, "Active", regionLeft + dividerOffset2 + dividerWidth, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - - addTextField(new GuiNpcTextField(55, this, fontRendererObj, regionLeft, getTextFieldY(), dividerOffset1, textFieldHeight, questCatSearch)); - addTextField(new GuiNpcTextField(56, this, fontRendererObj, regionLeft + dividerOffset1 + dividerWidth, getTextFieldY(), dividerOffset2 - dividerOffset1 - dividerWidth, textFieldHeight, questFinishedSearch)); - addTextField(new GuiNpcTextField(57, this, fontRendererObj, regionLeft + dividerOffset2 + dividerWidth, getTextFieldY(), regionRight - (regionLeft + dividerOffset2 + dividerWidth), textFieldHeight, questActiveSearch)); - } else { // Compact: 2 scrolls with resizable divider. - // Default divider for compact mode. - if (!isResizing) { - dividerOffset1 = (availableWidth - dividerWidth) / 2; - } - if (questFinishedScroll == null) questFinishedScroll = new GuiCustomScroll(this, 1, 0); - questFinishedScroll.guiLeft = regionLeft; - questFinishedScroll.guiTop = guiTop + scrollTopOffset; - questFinishedScroll.setSize(dividerOffset1, scrollHeight); - questFinishedScroll.setList(new ArrayList<>(questFinishedData.keySet())); - questFinishedSearch = ""; - addScroll(questFinishedScroll); - addLabel(new GuiNpcLabel(1003, "Finished", regionLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - - if (questActiveScroll == null) questActiveScroll = new GuiCustomScroll(this, 2, 0); - questActiveScroll.guiLeft = regionLeft + dividerOffset1 + dividerWidth; - questActiveScroll.guiTop = guiTop + scrollTopOffset; - questActiveScroll.setSize(availableWidth - dividerOffset1 - dividerWidth, scrollHeight); - questActiveScroll.setList(new ArrayList<>(questActiveData.keySet())); - questActiveSearch = ""; - addScroll(questActiveScroll); - addLabel(new GuiNpcLabel(1004, "Active", regionLeft + dividerOffset1 + dividerWidth, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - - addTextField(new GuiNpcTextField(55, this, fontRendererObj, regionLeft, getTextFieldY(), dividerOffset1, textFieldHeight, questFinishedSearch)); - addTextField(new GuiNpcTextField(56, this, fontRendererObj, regionLeft + dividerOffset1 + dividerWidth, getTextFieldY(), availableWidth - dividerOffset1 - dividerWidth, textFieldHeight, questActiveSearch)); - } - } - - private void initDialogTab() { - int regionLeft = guiLeft + leftPadding; - int regionRight = guiLeft + xSize - rightPadding; - int availableWidth = regionRight - regionLeft; - int scrollHeight = getScrollHeight(); - if (viewMode == 0) { // Categorical: 2 scrolls. - if (!isResizing) { - dividerOffset1 = (availableWidth - dividerWidth) / 2; - } - if (dialogCatScroll == null) dialogCatScroll = new GuiCustomScroll(this, 0, 0); - dialogCatScroll.guiLeft = regionLeft; - dialogCatScroll.guiTop = guiTop + scrollTopOffset; - dialogCatScroll.setSize(dividerOffset1, scrollHeight); - dialogCatScroll.setList(new ArrayList<>(dialogCatData.keySet())); - addScroll(dialogCatScroll); - addLabel(new GuiNpcLabel(2000, "Categories", regionLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - - if (dialogReadScroll == null) dialogReadScroll = new GuiCustomScroll(this, 1, 0); - dialogReadScroll.guiLeft = regionLeft + dividerOffset1 + dividerWidth; - dialogReadScroll.guiTop = guiTop + scrollTopOffset; - dialogReadScroll.setSize(availableWidth - dividerOffset1 - dividerWidth, scrollHeight); - dialogReadScroll.setList(new ArrayList<>(dialogReadData.keySet())); - addScroll(dialogReadScroll); - addLabel(new GuiNpcLabel(2001, "Read", regionLeft + dividerOffset1 + dividerWidth, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - - addTextField(new GuiNpcTextField(55, this, fontRendererObj, regionLeft, getTextFieldY(), dividerOffset1, textFieldHeight, dialogCatSearch)); - addTextField(new GuiNpcTextField(56, this, fontRendererObj, regionLeft + dividerOffset1 + dividerWidth, getTextFieldY(), availableWidth - dividerOffset1 - dividerWidth, textFieldHeight, dialogReadSearch)); - } else { // Compact: 1 scroll – no divider. - if (dialogCompactScroll == null) dialogCompactScroll = new GuiCustomScroll(this, 5, 0); - dialogCompactScroll.guiLeft = regionLeft; - dialogCompactScroll.guiTop = guiTop + scrollTopOffset; - dialogCompactScroll.setSize(availableWidth, scrollHeight); - dialogCompactScroll.setList(new ArrayList<>(dialogReadData.keySet())); - addScroll(dialogCompactScroll); - addLabel(new GuiNpcLabel(2002, "All", regionLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - addTextField(new GuiNpcTextField(55, this, fontRendererObj, regionLeft, getTextFieldY(), availableWidth, textFieldHeight, dialogCompactSearch)); - } - } - - private void initTransportTab() { - int regionLeft = guiLeft + leftPadding; - int regionRight = guiLeft + xSize - rightPadding; - int availableWidth = regionRight - regionLeft; - int scrollHeight = getScrollHeight(); - if (viewMode == 0) { // Categorical: 2 scrolls. - if (!isResizing) { - dividerOffset1 = (availableWidth - dividerWidth) / 2; - } - if (transCatScroll == null) transCatScroll = new GuiCustomScroll(this, 3, 0); - transCatScroll.guiLeft = regionLeft; - transCatScroll.guiTop = guiTop + scrollTopOffset; - transCatScroll.setSize(dividerOffset1, scrollHeight); - transCatScroll.setList(new ArrayList<>(transCatData.keySet())); - addScroll(transCatScroll); - addLabel(new GuiNpcLabel(3000, "Categories", regionLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - - if (transLocScroll == null) transLocScroll = new GuiCustomScroll(this, 4, 0); - transLocScroll.guiLeft = regionLeft + dividerOffset1 + dividerWidth; - transLocScroll.guiTop = guiTop + scrollTopOffset; - transLocScroll.setSize(availableWidth - dividerOffset1 - dividerWidth, scrollHeight); - transLocScroll.setList(new ArrayList<>(transLocData.keySet())); - addScroll(transLocScroll); - addLabel(new GuiNpcLabel(3001, "Locations", regionLeft + dividerOffset1 + dividerWidth, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - - addTextField(new GuiNpcTextField(60, this, fontRendererObj, regionLeft, getTextFieldY(), dividerOffset1, textFieldHeight, transCatSearch)); - addTextField(new GuiNpcTextField(61, this, fontRendererObj, regionLeft + dividerOffset1 + dividerWidth, getTextFieldY(), availableWidth - dividerOffset1 - dividerWidth, textFieldHeight, transLocSearch)); - } else { // Compact: 1 scroll – no divider. - if (transCompactScroll == null) transCompactScroll = new GuiCustomScroll(this, 5, 0); - transCompactScroll.guiLeft = regionLeft; - transCompactScroll.guiTop = guiTop + scrollTopOffset; - transCompactScroll.setSize(availableWidth, scrollHeight); - transCompactScroll.setList(new ArrayList<>(transLocData.keySet())); - addScroll(transCompactScroll); - addLabel(new GuiNpcLabel(3002, "All", regionLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - addTextField(new GuiNpcTextField(60, this, fontRendererObj, regionLeft, getTextFieldY(), availableWidth, textFieldHeight, transCompactSearch)); - } - } - - private void initSingleTab() { - int regionLeft = guiLeft + leftPadding; - int regionRight = guiLeft + xSize - rightPadding; - int availableWidth = regionRight - regionLeft; - int scrollHeight = getScrollHeight(); - if (singleScroll == null) singleScroll = new GuiCustomScroll(this, 0, 0); - singleScroll.guiLeft = regionLeft; - singleScroll.guiTop = guiTop + scrollTopOffset; - if (currentTab == 13) { - singleScroll.setSize(availableWidth, scrollHeight); - singleScroll.setList(new ArrayList<>(bankData.keySet())); - addLabel(new GuiNpcLabel(4000, "Bank", regionLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - } else { - singleScroll.setSize(availableWidth, scrollHeight); - singleScroll.setList(new ArrayList<>(factionData.keySet())); - addLabel(new GuiNpcLabel(4000, "Faction", regionLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); - } - addScroll(singleScroll); - addTextField(new GuiNpcTextField(70, this, fontRendererObj, regionLeft, getTextFieldY(), availableWidth, textFieldHeight, singleSearch)); - } - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - super.drawScreen(mouseX, mouseY, partialTicks); - int scrollHeight = getScrollHeight(); - int regionLeft = guiLeft + leftPadding; - int regionRight = guiLeft + xSize - rightPadding; - int availableWidth = regionRight - regionLeft; - // In compact mode for Quests (2-scroll) draw divider. - if (currentTab == 10 && viewMode != 0 && !hasSubGui()) { - int dividerX = regionLeft + dividerOffset1; - drawRect(dividerX, guiTop + scrollTopOffset, dividerX + dividerWidth, guiTop + scrollTopOffset + scrollHeight, 0xFF707070); - } - // In categorical mode, draw dividers. - if (currentTab == 10 && viewMode == 0 && !hasSubGui()) { - int dividerX1 = regionLeft + dividerOffset1; - int dividerX2 = regionLeft + dividerOffset2; - drawRect(dividerX1, guiTop + scrollTopOffset, dividerX1 + dividerWidth, guiTop + scrollTopOffset + scrollHeight, 0xFF707070); - drawRect(dividerX2, guiTop + scrollTopOffset, dividerX2 + dividerWidth, guiTop + scrollTopOffset + scrollHeight, 0xFF707070); - } else if ((currentTab == 11 || currentTab == 12) && viewMode == 0 && !hasSubGui()) { - int dividerX = regionLeft + dividerOffset1; - drawRect(dividerX, guiTop + scrollTopOffset, dividerX + dividerWidth, guiTop + scrollTopOffset + scrollHeight, 0xFF707070); - } - // Do not draw any divider for compact mode in Dialog/Transport. - } - - @Override - public void mouseClicked(int mouseX, int mouseY, int mouseButton) { - int hitMargin = 3; - int regionTop = guiTop + scrollTopOffset; - int regionBottom = regionTop + getScrollHeight(); - int regionLeft = guiLeft + leftPadding; - int availableWidth = (guiLeft + xSize - rightPadding) - regionLeft; - if (!hasSubGui() && mouseY >= regionTop && mouseY <= regionBottom) { - if (viewMode == 0) { - if (currentTab == 10) { // Categorical: 3 scrolls. - int dividerX1 = regionLeft + dividerOffset1; - int dividerX2 = regionLeft + dividerOffset2; - if (mouseX >= dividerX1 - hitMargin && mouseX <= dividerX1 + dividerWidth + hitMargin) { - isResizing = true; - resizingDivider = 1; - initialDragX = mouseX; - return; - } else if (mouseX >= dividerX2 - hitMargin && mouseX <= dividerX2 + dividerWidth + hitMargin) { - isResizing = true; - resizingDivider = 2; - initialDragX = mouseX; - return; - } - } else if (currentTab == 11 || currentTab == 12) { // Categorical for Dialog/Transport. - int dividerX = regionLeft + dividerOffset1; - if (mouseX >= dividerX - hitMargin && mouseX <= dividerX + dividerWidth + hitMargin) { - isResizing = true; - resizingDivider = 1; - initialDragX = mouseX; - return; - } - } - } else { // Compact mode. - if (currentTab == 10) { // Compact mode for Quests (2 scrolls) - // Use dividerOffset1 as the divider between the two scrolls. - int defaultWidth = (availableWidth - dividerWidth) / 2; - if (!isResizing) dividerOffset1 = defaultWidth; - int dividerX = regionLeft + dividerOffset1; - if (mouseX >= dividerX - hitMargin && mouseX <= dividerX + dividerWidth + hitMargin) { - isResizing = true; - resizingDivider = 1; - initialDragX = mouseX; - return; - } - } - // For Dialog/Transport compact, there's no divider. - } - } - super.mouseClicked(mouseX, mouseY, mouseButton); - } - - @Override - public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { - int regionLeft = guiLeft + leftPadding; - int regionRight = guiLeft + xSize - rightPadding; - int availableWidth = regionRight - regionLeft; - if (isResizing) { - int dx = mouseX - initialDragX; - initialDragX = mouseX; - // For Quest tab: - if (currentTab == 10) { - if (viewMode == 0) { // Categorical (3 scrolls) - if (resizingDivider == 1) { - dividerOffset1 += dx; - int maxOffset = dividerOffset2 - dividerWidth - minScrollWidth; - if (dividerOffset1 < minScrollWidth) dividerOffset1 = minScrollWidth; - if (dividerOffset1 > maxOffset) dividerOffset1 = maxOffset; - questCatScroll.setSize(dividerOffset1, getScrollHeight()); - questFinishedScroll.guiLeft = regionLeft + dividerOffset1 + dividerWidth; - questFinishedScroll.setSize(dividerOffset2 - dividerOffset1 - dividerWidth, getScrollHeight()); - questActiveScroll.guiLeft = regionLeft + dividerOffset2 + dividerWidth; - questActiveScroll.setSize(availableWidth - (dividerOffset2 + dividerWidth), getScrollHeight()); - // Update textfields and labels. - GuiNpcTextField tf55 = getTextField(55); - if(tf55 != null) { tf55.xPosition = regionLeft; tf55.width = dividerOffset1; } - GuiNpcTextField tf56 = getTextField(56); - if(tf56 != null) { tf56.xPosition = regionLeft + dividerOffset1 + dividerWidth; tf56.width = dividerOffset2 - dividerOffset1 - dividerWidth; } - GuiNpcTextField tf57 = getTextField(57); - if(tf57 != null) { tf57.xPosition = regionLeft + dividerOffset2 + dividerWidth; tf57.width = availableWidth - (dividerOffset2 + dividerWidth); } - GuiNpcLabel lbl1000 = getLabel(1000); - if(lbl1000 != null) { lbl1000.x = regionLeft; } - GuiNpcLabel lbl1001 = getLabel(1001); - if(lbl1001 != null) { lbl1001.x = regionLeft + dividerOffset1 + dividerWidth; } - GuiNpcLabel lbl1002 = getLabel(1002); - if(lbl1002 != null) { lbl1002.x = regionLeft + dividerOffset2 + dividerWidth; } - } else if (resizingDivider == 2) { - dividerOffset2 += dx; - int minOffset = dividerOffset1 + dividerWidth + minScrollWidth; - int maxOffset = availableWidth - minScrollWidth; - if (dividerOffset2 < minOffset) dividerOffset2 = minOffset; - if (dividerOffset2 > maxOffset) dividerOffset2 = maxOffset; - questFinishedScroll.setSize(dividerOffset2 - dividerOffset1 - dividerWidth, getScrollHeight()); - questActiveScroll.guiLeft = regionLeft + dividerOffset2 + dividerWidth; - questActiveScroll.setSize(availableWidth - (dividerOffset2 + dividerWidth), getScrollHeight()); - GuiNpcTextField tf56 = getTextField(56); - if(tf56 != null) { tf56.xPosition = regionLeft + dividerOffset1 + dividerWidth; tf56.width = dividerOffset2 - dividerOffset1 - dividerWidth; } - GuiNpcTextField tf57 = getTextField(57); - if(tf57 != null) { tf57.xPosition = regionLeft + dividerOffset2 + dividerWidth; tf57.width = availableWidth - (dividerOffset2 + dividerWidth); } - GuiNpcLabel lbl1001 = getLabel(1001); - if(lbl1001 != null) { lbl1001.x = regionLeft + dividerOffset1 + dividerWidth; } - GuiNpcLabel lbl1002 = getLabel(1002); - if(lbl1002 != null) { lbl1002.x = regionLeft + dividerOffset2 + dividerWidth; } - } - } else { // Compact mode for Quests (2 scrolls) - if (resizingDivider == 1) { - dividerOffset1 += dx; - if (dividerOffset1 < minScrollWidth) dividerOffset1 = minScrollWidth; - if (dividerOffset1 > availableWidth - dividerWidth - minScrollWidth) - dividerOffset1 = availableWidth - dividerWidth - minScrollWidth; - questFinishedScroll.setSize(dividerOffset1, getScrollHeight()); - questActiveScroll.guiLeft = regionLeft + dividerOffset1 + dividerWidth; - questActiveScroll.setSize(availableWidth - dividerOffset1 - dividerWidth, getScrollHeight()); - // Update textfields and labels. - GuiNpcTextField tf55 = getTextField(55); - if(tf55 != null) { tf55.xPosition = regionLeft; tf55.width = dividerOffset1; } - GuiNpcTextField tf56 = getTextField(56); - if(tf56 != null) { tf56.xPosition = regionLeft + dividerOffset1 + dividerWidth; tf56.width = availableWidth - dividerOffset1 - dividerWidth; } - GuiNpcLabel lbl1003 = getLabel(1003); - if(lbl1003 != null) { lbl1003.x = regionLeft; } - GuiNpcLabel lbl1004 = getLabel(1004); - if(lbl1004 != null) { lbl1004.x = regionLeft + dividerOffset1 + dividerWidth; } - } - } - } - return; - } - super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); - } - - @Override - protected void mouseMovedOrUp(int mouseX, int mouseY, int state) { - if (isResizing) { - isResizing = false; - resizingDivider = 0; - return; - } - super.mouseMovedOrUp(mouseX, mouseY, state); - } - - @Override - public void keyTyped(char c, int i) { - super.keyTyped(c, i); - GuiNpcTextField tf; - if (currentTab == 10) { - if (viewMode == 0) { - tf = getTextField(55); - if (tf != null && tf.isFocused()) { - String newText = tf.getText().toLowerCase(); - if (!questCatSearch.equals(newText)) { - questCatSearch = newText; - if (questCatScroll != null) { - if (selectedQuestCategory.isEmpty()) - questCatScroll.setList(new ArrayList<>()); - else - questCatScroll.setList(filterList(questCatData, questCatSearch)); - } - } - } - tf = getTextField(56); - if (tf != null && tf.isFocused()) { - String newText = tf.getText().toLowerCase(); - if (!questFinishedSearch.equals(newText)) { - questFinishedSearch = newText; - if (questFinishedScroll != null) - questFinishedScroll.setList( - selectedQuestCategory.isEmpty() ? - new ArrayList<>() : - filterAndTrimListByCategory(questFinishedData, selectedQuestCategory, questFinishedSearch) - ); - } - } - tf = getTextField(57); - if (tf != null && tf.isFocused()) { - String newText = tf.getText().toLowerCase(); - if (!questActiveSearch.equals(newText)) { - questActiveSearch = newText; - if (questActiveScroll != null) - questActiveScroll.setList( - selectedQuestCategory.isEmpty() ? - new ArrayList<>() : - filterAndTrimListByCategory(questActiveData, selectedQuestCategory, questActiveSearch) - ); - } - } - } else { - tf = getTextField(55); - if (tf != null && tf.isFocused()) { - String newText = tf.getText().toLowerCase(); - if (!questFinishedSearch.equals(newText)) { - questFinishedSearch = newText; - if (questFinishedScroll != null) - questFinishedScroll.setList(filterList(questFinishedData, questFinishedSearch)); - } - } - tf = getTextField(56); - if (tf != null && tf.isFocused()) { - String newText = tf.getText().toLowerCase(); - if (!questActiveSearch.equals(newText)) { - questActiveSearch = newText; - if (questActiveScroll != null) - questActiveScroll.setList(filterList(questActiveData, questActiveSearch)); - } - } - } - } else if (currentTab == 11) { - if (viewMode == 0) { - tf = getTextField(55); - if (tf != null && tf.isFocused()) { - String newText = tf.getText().toLowerCase(); - if (!dialogCatSearch.equals(newText)) { - dialogCatSearch = newText; - if (dialogCatScroll != null) - dialogCatScroll.setList(selectedDialogCategory.isEmpty() ? - new ArrayList<>() : - filterList(dialogCatData, dialogCatSearch)); - } - } - tf = getTextField(56); - if (tf != null && tf.isFocused()) { - String newText = tf.getText().toLowerCase(); - if (!dialogReadSearch.equals(newText)) { - dialogReadSearch = newText; - if (dialogReadScroll != null) - dialogReadScroll.setList( - selectedDialogCategory.isEmpty() ? - new ArrayList<>() : - filterAndTrimListByCategory(dialogReadData, selectedDialogCategory, dialogReadSearch) - ); - } - } - } else { - tf = getTextField(55); - if (tf != null && tf.isFocused()) { - String newText = tf.getText().toLowerCase(); - if (!dialogCompactSearch.equals(newText)) { - dialogCompactSearch = newText; - if (dialogCompactScroll != null) - dialogCompactScroll.setList(filterList(dialogReadData, dialogCompactSearch)); - } - } - } - } else if (currentTab == 12) { - if (viewMode == 0) { - tf = getTextField(60); - if (tf != null && tf.isFocused()) { - String newText = tf.getText().toLowerCase(); - if (!transCatSearch.equals(newText)) { - transCatSearch = newText; - if (transCatScroll != null) - transCatScroll.setList(selectedTransCategory.isEmpty() ? - new ArrayList<>() : - filterList(transCatData, transCatSearch)); - } - } - tf = getTextField(61); - if (tf != null && tf.isFocused()) { - String newText = tf.getText().toLowerCase(); - if (!transLocSearch.equals(newText)) { - transLocSearch = newText; - if (transLocScroll != null) - transLocScroll.setList( - selectedTransCategory.isEmpty() ? - new ArrayList<>() : - filterAndTrimListByCategory(transLocData, selectedTransCategory, transLocSearch) - ); - } - } - } else { - tf = getTextField(60); - if (tf != null && tf.isFocused()) { - String newText = tf.getText().toLowerCase(); - if (!transCompactSearch.equals(newText)) { - transCompactSearch = newText; - if (transCompactScroll != null) - transCompactScroll.setList(filterList(transLocData, transCompactSearch)); - } - } - } - } else if (currentTab == 13 || currentTab == 14) { - tf = getTextField(70); - if (tf != null && tf.isFocused()) { - String newText = tf.getText().toLowerCase(); - if (!singleSearch.equals(newText)) { - singleSearch = newText; - if (singleScroll != null) - singleScroll.setList(filterList(currentTab == 13 ? bankData : factionData, singleSearch)); - } - } - } - } - - private List filterList(HashMap data, String search) { - List list = new ArrayList<>(); - for (String key : data.keySet()) { - if (key.toLowerCase().contains(search)) { - list.add(key); - } - } - return list; - } - - private List filterAndTrimListByCategory(HashMap data, String category, String search) { - List list = new ArrayList<>(); - String prefix = category + ":"; - for (String key : data.keySet()) { - if (key.startsWith(prefix)) { - String trimmed = key.substring(prefix.length()).trim(); - if (trimmed.toLowerCase().contains(search)) { - list.add(trimmed); - } - } - } - return list; - } - - @Override - public void actionPerformed(GuiButton button) { - if(button.id == -5){ - close(); - return; - } - if (button.id >= 10 && button.id <= 14) { - currentTab = button.id; - initGui(); - return; - } - if (button.id == 20) { - viewMode = (viewMode == 0) ? 1 : 0; - initGui(); - } else if (button.id == 30) { - Integer selectedID = null; - EnumPlayerData tabType = null; - if (currentTab == 10) { - if(viewMode == 0){ - if(questCatScroll.getSelected() == null) - return; - if (questActiveScroll.getSelected() != null) { - selectedID = questActiveData.get(questCatScroll.getSelected() + ": " + questActiveScroll.getSelected()); - if(selectedID != null){ - questActiveScroll.list.remove(questActiveScroll.selected); - questActiveData.remove(questCatScroll.getSelected() + ": " + questActiveScroll.getSelected()); - } - tabType = EnumPlayerData.Quest; - } else if (questFinishedScroll.getSelected() != null) { - selectedID = questFinishedData.get(questCatScroll.getSelected() + ": " + questFinishedScroll.getSelected()); - if(selectedID != null){ - questFinishedScroll.list.remove(questFinishedScroll.selected); - questFinishedData.remove(questCatScroll.getSelected() + ": " + questFinishedScroll.getSelected()); - } - tabType = EnumPlayerData.Quest; - } - } else { - if (questActiveScroll.getSelected() != null) { - selectedID = questActiveData.get(questActiveScroll.getSelected()); - if(selectedID != null){ - questActiveScroll.list.remove(questActiveScroll.selected); - questActiveData.remove(questActiveScroll.getSelected()); - } - tabType = EnumPlayerData.Quest; - } else if (questFinishedScroll.getSelected() != null) { - selectedID = questFinishedData.get(questFinishedScroll.getSelected()); - if(selectedID != null){ - questFinishedScroll.list.remove(questFinishedScroll.selected); - questFinishedData.remove(questFinishedScroll.getSelected()); - } - tabType = EnumPlayerData.Quest; - } - } - } else if (currentTab == 11) { - if (viewMode == 0) { - if (dialogReadScroll.getSelected() != null && dialogCatScroll.getSelected() != null) { - selectedID = dialogReadData.get(dialogCatScroll.getSelected() + ": " + dialogReadScroll.getSelected()); - if(selectedID != null){ - dialogReadScroll.list.remove(dialogReadScroll.selected); - dialogReadData.remove(dialogCatScroll.getSelected() + ": " + dialogReadScroll.getSelected()); - } - tabType = EnumPlayerData.Dialog; - } - } else { - if (dialogCompactScroll.getSelected() != null) { - selectedID = dialogReadData.get(dialogCompactScroll.getSelected()); - if(selectedID != null){ - dialogCompactScroll.list.remove(dialogCompactScroll.selected); - dialogReadData.remove(dialogCompactScroll.getSelected()); - } - tabType = EnumPlayerData.Dialog; - } - } - } else if (currentTab == 12) { - if (viewMode == 0) { - if (transLocScroll.getSelected() != null && transCatScroll.getSelected() != null) { - selectedID = transLocData.get(transCatScroll.getSelected() + ": " + transLocScroll.getSelected()); - if(selectedID != null){ - transLocScroll.list.remove(transLocScroll.selected); - transLocData.remove(transCatScroll.getSelected() + ": " + transLocScroll.getSelected()); - } - tabType = EnumPlayerData.Transport; - } - } else { - if (transCompactScroll.getSelected() != null) { - selectedID = transLocData.get(transCompactScroll.getSelected()); - if(selectedID != null){ - transCompactScroll.list.remove(transCompactScroll.selected); - transLocData.remove(transCompactScroll.getSelected()); - } - tabType = EnumPlayerData.Transport; - } - } - } else if (currentTab == 13) { - if (singleScroll.getSelected() != null) { - selectedID = bankData.get(singleScroll.getSelected()); - if(selectedID != null){ - singleScroll.list.remove(singleScroll.selected); - bankData.remove(singleScroll.getSelected()); - } - tabType = EnumPlayerData.Bank; - } - } else if (currentTab == 14) { - if (singleScroll.getSelected() != null) { - selectedID = factionData.get(singleScroll.getSelected()); - if(selectedID != null){ - singleScroll.list.remove(singleScroll.selected); - bankData.remove(singleScroll.getSelected()); - } - tabType = EnumPlayerData.Factions; - } - } - if (selectedID != null) { - PacketClient.sendClient(new PlayerDataRemovePacketNew(playerName, tabType, selectedID)); - } - } - } - - @Override - public void setQuestData(Map questCategories, Map questActive, Map questFinished) { - this.questCatData = new HashMap<>(questCategories); - this.questActiveData = new HashMap<>(questActive); - this.questFinishedData = new HashMap<>(questFinished); - if (questCatScroll != null) { - questCatScroll.setList(new ArrayList<>(questCatData.keySet())); - } - } - - @Override - public void setDialogData(Map dialogCategories, Map dialogRead) { - this.dialogCatData = new HashMap<>(dialogCategories); - this.dialogReadData = new HashMap<>(dialogRead); - if (dialogCatScroll != null) { - dialogCatScroll.setList(new ArrayList<>(dialogCatData.keySet())); - } - if (dialogReadScroll != null) { - dialogReadScroll.setList(new ArrayList<>(dialogReadData.keySet())); - } - if (dialogCompactScroll != null) { - List merged = new ArrayList<>(dialogReadData.keySet()); - dialogCompactScroll.setList(merged); - } - } - - @Override - public void setTransportData(Map transportCategories, Map transportLocations) { - this.transCatData = new HashMap<>(transportCategories); - this.transLocData = new HashMap<>(transportLocations); - if (transCatScroll != null) { - transCatScroll.setList(new ArrayList<>(transCatData.keySet())); - } - if (transLocScroll != null) { - transLocScroll.setList(new ArrayList<>(transLocData.keySet())); - } - if (transCompactScroll != null) { - List merged = new ArrayList<>(transLocData.keySet()); - transCompactScroll.setList(merged); - } - } - - @Override - public void setBankData(Map bankData) { - this.bankData = new HashMap<>(bankData); - if (singleScroll != null && currentTab == 13) { - singleScroll.setList(new ArrayList<>(this.bankData.keySet())); - } - } - - @Override - public void setFactionData(Map factionData) { - this.factionData = new HashMap<>(factionData); - if (singleScroll != null && currentTab == 14) { - singleScroll.setList(new ArrayList<>(this.factionData.keySet())); - } - } - - @Override - public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { - if (guiCustomScroll == questCatScroll) { - selectedQuestCategory = questCatScroll.getSelected(); - questFinishedScroll.resetScroll(); - questActiveScroll.resetScroll(); - if (!selectedQuestCategory.isEmpty()) { - questFinishedScroll.setList(filterAndTrimListByCategory(questFinishedData, selectedQuestCategory, questFinishedSearch)); - questActiveScroll.setList(filterAndTrimListByCategory(questActiveData, selectedQuestCategory, questActiveSearch)); - } else { - questFinishedScroll.setList(new ArrayList<>()); - questActiveScroll.setList(new ArrayList<>()); - } - } else if (guiCustomScroll == dialogCatScroll) { - selectedDialogCategory = dialogCatScroll.getSelected(); - dialogReadScroll.resetScroll(); - if (!selectedDialogCategory.isEmpty()) { - dialogReadScroll.setList(filterAndTrimListByCategory(dialogReadData, selectedDialogCategory, dialogReadSearch)); - } else { - dialogReadScroll.setList(new ArrayList<>()); - } - } else if (guiCustomScroll == transCatScroll) { - selectedTransCategory = transCatScroll.getSelected(); - transLocScroll.resetScroll(); - if (!selectedTransCategory.isEmpty()) { - transLocScroll.setList(filterAndTrimListByCategory(transLocData, selectedTransCategory, transLocSearch)); - } else { - transLocScroll.setList(new ArrayList<>()); - } - } else if (guiCustomScroll == questActiveScroll) { - questFinishedScroll.selected = -1; - } else if (guiCustomScroll == questFinishedScroll) { - questActiveScroll.selected = -1; - } - } -} diff --git a/src/main/java/noppes/npcs/client/gui/test/IPlayerDataInfo.java b/src/main/java/noppes/npcs/client/gui/util/IPlayerDataInfo.java similarity index 93% rename from src/main/java/noppes/npcs/client/gui/test/IPlayerDataInfo.java rename to src/main/java/noppes/npcs/client/gui/util/IPlayerDataInfo.java index 3aef92ad8..c41b9b626 100644 --- a/src/main/java/noppes/npcs/client/gui/test/IPlayerDataInfo.java +++ b/src/main/java/noppes/npcs/client/gui/util/IPlayerDataInfo.java @@ -1,4 +1,4 @@ -package noppes.npcs.client.gui.test; +package noppes.npcs.client.gui.util; import java.util.Map; From ea1f142571cb1d04699ed20e9f6b0311ea379c35 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 20 Feb 2025 00:49:31 -0500 Subject: [PATCH 17/59] Fix Packet + Compact Code --- .../PlayerDataRemoveInfoPacket.java | 2 +- .../npcs/client/gui/SubGuiPlayerData.java | 121 ++++++++---------- 2 files changed, 55 insertions(+), 68 deletions(-) diff --git a/src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataRemoveInfoPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataRemoveInfoPacket.java index 38d4dab7a..50ab6148e 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataRemoveInfoPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/playerdata/PlayerDataRemoveInfoPacket.java @@ -30,7 +30,7 @@ public final class PlayerDataRemoveInfoPacket extends AbstractPacket { @Override public Enum getType() { - return EnumRequestPacket.PlayerDataRemove; + return EnumRequestPacket.PlayerDataDelete; } @Override diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java b/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java index 12e50d7d6..38ac3c162 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java @@ -801,105 +801,71 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo if (button.id == 20) { viewMode = (viewMode == 0) ? 1 : 0; initGui(); + return; } // Delete button. - else if (button.id == 30) { + if (button.id == 30) { Integer selectedID = null; EnumPlayerData tabType = null; + // Quest tab if (currentTab == 10) { - if (viewMode == 0) { + if (viewMode == 0) { // Categorical mode if (questCatScroll.getSelected() == null) return; + // Use category + selection key. if (questActiveScroll.getSelected() != null) { - selectedID = questActiveData.get(questCatScroll.getSelected() + ": " + questActiveScroll.getSelected()); - if (selectedID != null) { - questActiveScroll.list.remove(questActiveScroll.selected); - questActiveData.remove(questCatScroll.getSelected() + ": " + questActiveScroll.getSelected()); - } - tabType = EnumPlayerData.Quest; + selectedID = removeSelection(questActiveScroll, questActiveData, questCatScroll.getSelected()); } else if (questFinishedScroll.getSelected() != null) { - selectedID = questFinishedData.get(questCatScroll.getSelected() + ": " + questFinishedScroll.getSelected()); - if (selectedID != null) { - questFinishedScroll.list.remove(questFinishedScroll.selected); - questFinishedData.remove(questCatScroll.getSelected() + ": " + questFinishedScroll.getSelected()); - } - tabType = EnumPlayerData.Quest; + selectedID = removeSelection(questFinishedScroll, questFinishedData, questCatScroll.getSelected()); } - } else { + } else { // Compact mode: key is just the selection. if (questActiveScroll.getSelected() != null) { - selectedID = questActiveData.get(questActiveScroll.getSelected()); - if (selectedID != null) { - questActiveScroll.list.remove(questActiveScroll.selected); - questActiveData.remove(questActiveScroll.getSelected()); - } - tabType = EnumPlayerData.Quest; + selectedID = removeSelection(questActiveScroll, questActiveData, null); } else if (questFinishedScroll.getSelected() != null) { - selectedID = questFinishedData.get(questFinishedScroll.getSelected()); - if (selectedID != null) { - questFinishedScroll.list.remove(questFinishedScroll.selected); - questFinishedData.remove(questFinishedScroll.getSelected()); - } - tabType = EnumPlayerData.Quest; + selectedID = removeSelection(questFinishedScroll, questFinishedData, null); } } - } else if (currentTab == 11) { + tabType = EnumPlayerData.Quest; + } + // Dialog tab + else if (currentTab == 11) { if (viewMode == 0) { if (dialogReadScroll.getSelected() != null && dialogCatScroll.getSelected() != null) { - selectedID = dialogReadData.get(dialogCatScroll.getSelected() + ": " + dialogReadScroll.getSelected()); - if (selectedID != null) { - dialogReadScroll.list.remove(dialogReadScroll.selected); - dialogReadData.remove(dialogCatScroll.getSelected() + ": " + dialogReadScroll.getSelected()); - } - tabType = EnumPlayerData.Dialog; + selectedID = removeSelection(dialogReadScroll, dialogReadData, dialogCatScroll.getSelected()); } } else { if (dialogCompactScroll.getSelected() != null) { - selectedID = dialogReadData.get(dialogCompactScroll.getSelected()); - if (selectedID != null) { - dialogCompactScroll.list.remove(dialogCompactScroll.selected); - dialogReadData.remove(dialogCompactScroll.getSelected()); - } - tabType = EnumPlayerData.Dialog; + selectedID = removeSelection(dialogCompactScroll, dialogReadData, null); } } - } else if (currentTab == 12) { + tabType = EnumPlayerData.Dialog; + } + // Transport tab + else if (currentTab == 12) { if (viewMode == 0) { if (transLocScroll.getSelected() != null && transCatScroll.getSelected() != null) { - selectedID = transLocData.get(transCatScroll.getSelected() + ": " + transLocScroll.getSelected()); - if (selectedID != null) { - transLocScroll.list.remove(transLocScroll.selected); - transLocData.remove(transCatScroll.getSelected() + ": " + transLocScroll.getSelected()); - } - tabType = EnumPlayerData.Transport; + selectedID = removeSelection(transLocScroll, transLocData, transCatScroll.getSelected()); } } else { if (transCompactScroll.getSelected() != null) { - selectedID = transLocData.get(transCompactScroll.getSelected()); - if (selectedID != null) { - transCompactScroll.list.remove(transCompactScroll.selected); - transLocData.remove(transCompactScroll.getSelected()); - } - tabType = EnumPlayerData.Transport; + selectedID = removeSelection(transCompactScroll, transLocData, null); } } - } else if (currentTab == 13) { + tabType = EnumPlayerData.Transport; + } + // Bank tab + else if (currentTab == 13) { if (singleScroll.getSelected() != null) { - selectedID = bankData.get(singleScroll.getSelected()); - if (selectedID != null) { - singleScroll.list.remove(singleScroll.selected); - bankData.remove(singleScroll.getSelected()); - } - tabType = EnumPlayerData.Bank; + selectedID = removeSelection(singleScroll, bankData, null); } - } else if (currentTab == 14) { + tabType = EnumPlayerData.Bank; + } + // Faction tab + else if (currentTab == 14) { if (singleScroll.getSelected() != null) { - selectedID = factionData.get(singleScroll.getSelected()); - if (selectedID != null) { - singleScroll.list.remove(singleScroll.selected); - factionData.remove(singleScroll.getSelected()); - } - tabType = EnumPlayerData.Factions; + selectedID = removeSelection(singleScroll, factionData, null); } + tabType = EnumPlayerData.Factions; } if (selectedID != null) { PacketClient.sendClient(new PlayerDataRemoveInfoPacket(playerName, tabType, selectedID)); @@ -907,6 +873,27 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo } } + /** + * Helper method that removes the selected entry from a scroll and its backing data. + * + * @param scroll The GuiCustomScroll in question. + * @param data The backing map holding keys and IDs. + * @param prefix If non-null and non-empty, the key is built as "prefix: " + scroll.getSelected(); otherwise, + * scroll.getSelected() is used. + * @return The ID of the removed item, or null if none was found. + */ + private Integer removeSelection(GuiCustomScroll scroll, Map data, String prefix) { + if (scroll.getSelected() == null) return null; + String key = (prefix == null || prefix.isEmpty()) ? scroll.getSelected() : prefix + ": " + scroll.getSelected(); + Integer id = data.get(key); + if (id != null) { + scroll.list.remove(scroll.selected); + scroll.selected = -1; + data.remove(key); + } + return id; + } + //////////////////////////////////////////////////////////////////////////////// // Data Setting Methods (IPlayerDataInfo) //////////////////////////////////////////////////////////////////////////////// From 478e16d27937e4120edd1139766fb73c7aeb2741 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 20 Feb 2025 01:02:27 -0500 Subject: [PATCH 18/59] fixxx --- .../java/noppes/npcs/NoppesUtilServer.java | 14 ++++---- .../npcs/client/gui/SubGuiPlayerData.java | 34 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index 0d11add1b..fcba2b7ff 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -1085,25 +1085,27 @@ public class NoppesUtilServer { public static void removePlayerDataInfo(String playerName, int tabType, int value, EntityPlayerMP player) { EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(playerName); PlayerData playerdata; + + EnumPlayerData enumPlayerData = EnumPlayerData.values()[tabType]; if(pl == null) playerdata = PlayerDataController.Instance.getDataFromUsername(playerName); else playerdata = PlayerDataController.Instance.getPlayerData(pl); - if(tabType == 0) { // Quest removal + if(enumPlayerData == EnumPlayerData.Quest) { // Quest removal playerdata.questData.activeQuests.remove(value); playerdata.questData.finishedQuests.remove(value); } - if(tabType == 1) { // Dialog removal + if(enumPlayerData == EnumPlayerData.Dialog){ // Dialog removal playerdata.dialogData.dialogsRead.remove(value); } - if(tabType == 2) { // Transport removal + if(enumPlayerData == EnumPlayerData.Transport) { // Transport removal playerdata.transportData.transports.remove(value); } - if(tabType == 3) { // Bank removal + if(enumPlayerData == EnumPlayerData.Bank) { // Bank removal playerdata.bankData.banks.remove(value); } - if(tabType == 4) { // Faction removal + if(enumPlayerData == EnumPlayerData.Factions) { // Faction removal playerdata.factionData.factionData.remove(value); } playerdata.save(); @@ -1111,7 +1113,5 @@ public class NoppesUtilServer { if(pl != null) { SyncController.syncPlayer((EntityPlayerMP) pl); } - // Resend the updated data to the client. - sendPlayerDataInfo(playerName, player); } } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java b/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java index 38ac3c162..7c3f87bba 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java @@ -9,6 +9,7 @@ import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPlayerData; import net.minecraft.client.gui.GuiButton; import net.minecraft.util.StatCollector; +import org.lwjgl.opengl.GL11; import java.util.ArrayList; import java.util.HashMap; @@ -293,6 +294,7 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo dialogCatScroll.guiLeft = paddedLeft; dialogCatScroll.guiTop = guiTop + scrollTopOffset; dialogCatScroll.setSize(dividerOffset1, scrollHeight); + dialogCatScroll.selected = -1; dialogCatScroll.setList(new ArrayList<>(dialogCatData.keySet())); addScroll(dialogCatScroll); addLabel(new GuiNpcLabel(2000, "Categories", paddedLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); @@ -301,7 +303,8 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo dialogReadScroll.guiLeft = paddedLeft + dividerOffset1 + dividerWidth; dialogReadScroll.guiTop = guiTop + scrollTopOffset; dialogReadScroll.setSize(availableWidth - dividerOffset1 - dividerWidth, scrollHeight); - dialogReadScroll.setList(new ArrayList<>(dialogReadData.keySet())); + dialogReadScroll.selected = -1; + dialogReadScroll.setList(new ArrayList<>()); addScroll(dialogReadScroll); addLabel(new GuiNpcLabel(2001, "Read", paddedLeft + dividerOffset1 + dividerWidth, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); @@ -313,6 +316,7 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo dialogCompactScroll.guiTop = guiTop + scrollTopOffset; dialogCompactScroll.setSize(availableWidth, getScrollHeight()); dialogCompactScroll.setList(new ArrayList<>(dialogReadData.keySet())); + dialogCompactScroll.selected = -1; addScroll(dialogCompactScroll); addLabel(new GuiNpcLabel(2002, "All", paddedLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); addTextField(new GuiNpcTextField(55, this, fontRendererObj, paddedLeft, getTextFieldY(), availableWidth, textFieldHeight, dialogCompactSearch)); @@ -333,6 +337,7 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo transCatScroll.guiLeft = paddedLeft; transCatScroll.guiTop = guiTop + scrollTopOffset; transCatScroll.setSize(dividerOffset1, scrollHeight); + transCatScroll.selected = -1; transCatScroll.setList(new ArrayList<>(transCatData.keySet())); addScroll(transCatScroll); addLabel(new GuiNpcLabel(3000, "Categories", paddedLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); @@ -341,7 +346,8 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo transLocScroll.guiLeft = paddedLeft + dividerOffset1 + dividerWidth; transLocScroll.guiTop = guiTop + scrollTopOffset; transLocScroll.setSize(availableWidth - dividerOffset1 - dividerWidth, scrollHeight); - transLocScroll.setList(new ArrayList<>(transLocData.keySet())); + transLocScroll.selected = -1; + transLocScroll.setList(new ArrayList<>()); addScroll(transLocScroll); addLabel(new GuiNpcLabel(3001, "Locations", paddedLeft + dividerOffset1 + dividerWidth, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); @@ -351,6 +357,7 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo transCompactScroll = ensureScroll(transCompactScroll, 5); transCompactScroll.guiLeft = paddedLeft; transCompactScroll.guiTop = guiTop + scrollTopOffset; + transCompactScroll.selected = -1; transCompactScroll.setSize(availableWidth, getScrollHeight()); transCompactScroll.setList(new ArrayList<>(transLocData.keySet())); addScroll(transCompactScroll); @@ -370,10 +377,12 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo if (currentTab == 13) { singleScroll.setSize(availableWidth, scrollHeight); singleScroll.setList(new ArrayList<>(bankData.keySet())); + singleScroll.selected = -1; addLabel(new GuiNpcLabel(4000, "Bank", paddedLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); } else { singleScroll.setSize(availableWidth, scrollHeight); singleScroll.setList(new ArrayList<>(factionData.keySet())); + singleScroll.selected = -1; addLabel(new GuiNpcLabel(4000, "Faction", paddedLeft, guiTop + 15, CustomNpcResourceListener.DefaultTextColor)); } addScroll(singleScroll); @@ -386,11 +395,12 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { - super.drawScreen(mouseX, mouseY, partialTicks); int scrollHeight = getScrollHeight(); int paddedLeft = getPaddedLeft(); int availableWidth = getAvailableWidth(); + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + GL11.glEnable(GL11.GL_DEPTH_TEST); // In compact mode for Quests, draw divider between the two scrolls. if (currentTab == 10 && viewMode != 0 && !hasSubGui()) { int dividerX = paddedLeft + dividerOffset1; @@ -406,6 +416,10 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo int dividerX = paddedLeft + dividerOffset1; drawRect(dividerX, guiTop + scrollTopOffset, dividerX + dividerWidth, guiTop + scrollTopOffset + scrollHeight, 0xFF707070); } + GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glPopAttrib(); + + super.drawScreen(mouseX, mouseY, partialTicks); // Compact mode for Dialog/Transport uses one scroll => no divider. } @@ -915,13 +929,6 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo if (dialogCatScroll != null) { dialogCatScroll.setList(new ArrayList<>(dialogCatData.keySet())); } - if (dialogReadScroll != null) { - dialogReadScroll.setList(new ArrayList<>(dialogReadData.keySet())); - } - if (dialogCompactScroll != null) { - List merged = new ArrayList<>(dialogReadData.keySet()); - dialogCompactScroll.setList(merged); - } } @Override @@ -931,13 +938,6 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo if (transCatScroll != null) { transCatScroll.setList(new ArrayList<>(transCatData.keySet())); } - if (transLocScroll != null) { - transLocScroll.setList(new ArrayList<>(transLocData.keySet())); - } - if (transCompactScroll != null) { - List merged = new ArrayList<>(transLocData.keySet()); - transCompactScroll.setList(merged); - } } @Override From 36183cd181386dd1e91983db1926695cd1d11835 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 20 Feb 2025 03:53:47 -0500 Subject: [PATCH 19/59] Completely Renovated PlayerData Menu + Toggle Button --- .../npcs/client/gui/SubGuiPlayerData.java | 27 ++- .../gui/global/GuiNpcManagePlayerData.java | 6 +- .../client/gui/util/GuiMenuTopButton.java | 7 +- .../npcs/client/gui/util/GuiToggleButton.java | 173 ++++++++++++++++++ .../assets/customnpcs/lang/en_US.lang | 2 + 5 files changed, 201 insertions(+), 14 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/util/GuiToggleButton.java diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java b/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java index 7c3f87bba..28a3d6d93 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java @@ -16,6 +16,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static noppes.npcs.client.gui.player.inventory.GuiCNPCInventory.specialIcons; + public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo, ICustomScrollListener { //////////////////////////////////////////////////////////////////////////////// @@ -121,11 +123,17 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo // Create top buttons. private void setupTopButtons() { - GuiMenuTopButton btnQuest = new GuiMenuTopButton(10, guiLeft + 4, guiTop - 10, StatCollector.translateToLocal("tab.quests")); - GuiMenuTopButton btnDialog = new GuiMenuTopButton(11, btnQuest.xPosition + btnQuest.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.dialog")); - GuiMenuTopButton btnTransport = new GuiMenuTopButton(12, btnDialog.xPosition + btnDialog.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.transport")); - GuiMenuTopButton btnBank = new GuiMenuTopButton(13, btnTransport.xPosition + btnTransport.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.bank")); - GuiMenuTopButton btnFaction = new GuiMenuTopButton(14, btnBank.xPosition + btnBank.getWidth(), guiTop - 10, StatCollector.translateToLocal("tab.faction")); + + GuiMenuTopButton playerTab = new GuiMenuTopButton(-10, guiLeft + 4, guiTop - 10, playerName); + playerTab.active = false; + playerTab.enabled = false; + playerTab.packedFGColour = CustomNpcResourceListener.DefaultTextColor; + + GuiMenuTopButton btnQuest = new GuiMenuTopButton(10, playerTab.xPosition + playerTab.getButtonWidth(), guiTop - 10, "quest.quests"); + GuiMenuTopButton btnDialog = new GuiMenuTopButton(11, btnQuest.xPosition + btnQuest.getWidth(), guiTop - 10, "dialog.dialogs"); + GuiMenuTopButton btnTransport = new GuiMenuTopButton(12, btnDialog.xPosition + btnDialog.getWidth(), guiTop - 10, "global.transport"); + GuiMenuTopButton btnBank = new GuiMenuTopButton(13, btnTransport.xPosition + btnTransport.getWidth(), guiTop - 10, "global.banks"); + GuiMenuTopButton btnFaction = new GuiMenuTopButton(14, btnBank.xPosition + btnBank.getWidth(), guiTop - 10, "menu.factions"); // Close button. GuiMenuTopButton close = new GuiMenuTopButton(-5, guiLeft + xSize - 22, guiTop - 10, "X"); @@ -135,6 +143,7 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo btnBank.active = (currentTab == 13); btnFaction.active = (currentTab == 14); + addTopButton(playerTab); addTopButton(btnQuest); addTopButton(btnDialog); addTopButton(btnTransport); @@ -177,10 +186,10 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo super.initGui(); setupTopButtons(); - // Mode toggle button (50px wide) if (currentTab == 10 || currentTab == 11 || currentTab == 12) { - String modeText = viewMode == 0 ? StatCollector.translateToLocal("view.categorical") : StatCollector.translateToLocal("view.compact"); - addButton(new GuiNpcButton(20, guiLeft + xSize - 60, guiTop + 10, 50, 20, modeText)); + addButton(new GuiToggleButton(20, guiLeft + xSize - 102, guiTop + 10, viewMode == 0)); + ((GuiToggleButton) getButton(20)).setTextureOff(specialIcons).setTextureOffPos( 16, 0); + ((GuiToggleButton) getButton(20)).setIconTexture(specialIcons).setIconPos( 16, 16, 16, 0 ); } guiTop += 7; @@ -201,7 +210,7 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo break; } // Delete button. - addButton(new GuiNpcButton(30, guiLeft + xSize - 60, guiTop + ySize - 30, 50, 20, StatCollector.translateToLocal("button.delete"))); + addButton(new GuiNpcButton(30, guiLeft + xSize - 60, guiTop + 10 - 7, 50, 20, "gui.remove")); } // ----- Quest Tab Initialization ----- 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 e3c5cc9d8..4e423ae3b 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java @@ -44,9 +44,9 @@ public class GuiNpcManagePlayerData extends GuiNPCInterface2 implements GuiYesNo addLabel(new GuiNpcLabel(0, StatCollector.translateToLocal("All Players"), guiLeft + 10, guiTop + 6)); - addButton(new GuiNpcButton(0, guiLeft + 313, guiTop + 10, 98, 20, StatCollector.translateToLocal("button.delete"))); - addButton(new GuiNpcButton(1, guiLeft + 313, guiTop + 32, 98, 20, StatCollector.translateToLocal("button.view"))); - addButton(new GuiNpcButton(2, guiLeft + 313, guiTop + 54, 98, 20, StatCollector.translateToLocal("button.regenPlayerMap"))); + addButton(new GuiNpcButton(0, guiLeft + 313, guiTop + 10, 98, 20, "gui.remove")); + addButton(new GuiNpcButton(1, guiLeft + 313, guiTop + 32, 98, 20, "gui.view")); + addButton(new GuiNpcButton(2, guiLeft + 313, guiTop + 54, 98, 20, "gui.playerMap")); addTextField(new GuiNpcTextField(0, this, fontRendererObj, guiLeft + 4, guiTop + 193, 303, 20, search)); diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiMenuTopButton.java b/src/main/java/noppes/npcs/client/gui/util/GuiMenuTopButton.java index 48ad1b389..33604c02c 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiMenuTopButton.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiMenuTopButton.java @@ -40,6 +40,9 @@ public class GuiMenuTopButton extends GuiNpcButton public int getHoverState(boolean flag) { byte byte0 = 1; + if(!enabled) + return byte0; + if (active) { byte0 = 0; @@ -57,7 +60,7 @@ public class GuiMenuTopButton extends GuiNpcButton if (!getVisible()) { return; - } + } GL11.glPushMatrix(); minecraft.renderEngine.bindTexture(resource); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); @@ -74,7 +77,7 @@ public class GuiMenuTopButton extends GuiNpcButton { drawCenteredString(fontrenderer, displayString, xPosition + getWidth() / 2, yPosition + (height - 8) / 2, 0xffffa0); } - else if (hover) + else if (hover && enabled) { drawCenteredString(fontrenderer, displayString, xPosition + getWidth() / 2, yPosition + (height - 8) / 2, 0xffffa0); } diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiToggleButton.java b/src/main/java/noppes/npcs/client/gui/util/GuiToggleButton.java new file mode 100644 index 000000000..14b5970b9 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/util/GuiToggleButton.java @@ -0,0 +1,173 @@ +package noppes.npcs.client.gui.util; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; + +public class GuiToggleButton extends GuiNpcButton { + + // Fixed dimensions: 40x20 (even if other values are passed) + private static final int FIXED_WIDTH = 40; + private static final int FIXED_HEIGHT = 20; + + private boolean toggled; + // Animation progress: 0.0 = OFF (knob left), 1.0 = ON (knob right) + private float animProgress; + + // Optional off icon (if not set, the super class icon is used) + private ResourceLocation textureOff = null; + private int textureOffPosX = 0; + private int textureOffPosY = 0; + // Off icon always 16x16 + private static final int ICON_SIZE = 16; + + /** + * Basic constructor. Uses the super class’s icon as the ON texture. + * Note: The button is fixed at 40×20. + */ + public GuiToggleButton(int id, int x, int y, boolean initialState) { + super(id, x, y, FIXED_WIDTH, FIXED_HEIGHT, ""); + this.toggled = initialState; + this.animProgress = initialState ? 1.0f : 0.0f; + } + + /** + * Constructor with both an ON and OFF icon. + * The ON icon is taken from the super class’s icon. + */ + public GuiToggleButton(int id, int x, int y, boolean initialState, + ResourceLocation textureOn, ResourceLocation textureOff) { + super(id, x, y, FIXED_WIDTH, FIXED_HEIGHT, ""); + this.setIconTexture(textureOn); + this.toggled = initialState; + this.animProgress = initialState ? 1.0f : 0.0f; + this.textureOff = textureOff; + } + + // Off icon setters + public GuiToggleButton setTextureOff(ResourceLocation texture) { + this.textureOff = texture; + return this; + } + + public GuiToggleButton setTextureOffPos(int posX, int posY) { + this.textureOffPosX = posX; + this.textureOffPosY = posY; + return this; + } + + @Override + public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) { + boolean pressed = super.mousePressed(mc, mouseX, mouseY); + if (pressed) { + toggled = !toggled; + } + return pressed; + } + + @Override + public void drawButton(Minecraft mc, int mouseX, int mouseY) { + if (!this.visible) + return; + + FontRenderer fontrenderer = mc.fontRenderer; + // Bind vanilla button texture. + mc.getTextureManager().bindTexture(buttonTextures); + GL11.glColor4f(1F, 1F, 1F, 1F); + + // Determine hover state (vanilla style) + this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && + mouseX < this.xPosition + FIXED_WIDTH && mouseY < this.yPosition + FIXED_HEIGHT; + int k = this.getHoverState(this.field_146123_n); + + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + // Update animation progress smoothly toward the target state. + float target = toggled ? 1.0f : 0.0f; + animProgress += (target - animProgress) * 0.2f; + if (Math.abs(target - animProgress) < 0.01f) + animProgress = target; + + // Draw the two halves using the vanilla button drawing code. + // Left half: + GL11.glColor4f(1F, 1F, 1F, 1F); + this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 20, FIXED_WIDTH / 2, FIXED_HEIGHT); + // Right half: + this.drawTexturedModalRect(this.xPosition + FIXED_WIDTH / 2, this.yPosition, 200 - FIXED_WIDTH / 2, 46 + k * 20, FIXED_WIDTH / 2, FIXED_HEIGHT); + + // Determine which half is the non-head (static background) area. + // When toggled ON, the knob (head) is on the right so non-head is the left half. + // When toggled OFF, the knob is on the left so non-head is the right half. + int nonHeadX, nonHeadWidth; + if (animProgress > 0.5f) { + // ON: knob on right, non-head = left half. + nonHeadX = this.xPosition; + nonHeadWidth = FIXED_WIDTH / 2; + } else { + // OFF: knob on left, non-head = right half. + nonHeadX = this.xPosition + FIXED_WIDTH / 2; + nonHeadWidth = FIXED_WIDTH / 2; + } + + // Tint the non-head area darker. + GL11.glColor4f(0.6f, 0.6f, 0.6f, 1.0F); + // Redraw that half to simulate a darker tone. + this.drawTexturedModalRect(nonHeadX, this.yPosition, 0, 46 + k * 20, nonHeadWidth, FIXED_HEIGHT); + + // Now draw the knob ("head") that slides. + // Knob width equals half of the button (20 pixels). + int knobWidth = FIXED_WIDTH / 2; + // The knob slides from xPosition (OFF) to xPosition + (FIXED_WIDTH - knobWidth) (ON). + int knobX = this.xPosition + (int)((FIXED_WIDTH - knobWidth) * animProgress); + int knobY = this.yPosition; + + // Draw the knob with no tint. + GL11.glColor4f(1F, 1F, 1F, 1F); + this.drawTexturedModalRect(knobX, knobY, 0, 46 + k * 20, knobWidth / 2, FIXED_HEIGHT); + this.drawTexturedModalRect(knobX + knobWidth / 2, knobY, 200 - knobWidth / 2, 46 + k * 20, knobWidth / 2, FIXED_HEIGHT); + + // Draw the icon on the knob (always 16×16, centered on the knob). + int iconX = knobX + (knobWidth - ICON_SIZE) / 2; + int iconY = knobY + (FIXED_HEIGHT - ICON_SIZE) / 2; + ResourceLocation iconTex; + int texX, texY; + // When ON, use the super class icon; when OFF, use textureOff if provided. + if (toggled) { + iconTex = this.iconTexture; + texX = this.iconPosX; + texY = this.iconPosY; + } else { + if (this.textureOff != null) { + iconTex = this.textureOff; + texX = this.textureOffPosX; + texY = this.textureOffPosY; + } else { + iconTex = this.iconTexture; + texX = this.iconPosX; + texY = this.iconPosY; + } + } + if (iconTex != null) { + mc.getTextureManager().bindTexture(iconTex); + GL11.glColor4f(1F, 1F, 1F, 1F); + this.drawTexturedModalRect(iconX, iconY, texX, texY, ICON_SIZE, ICON_SIZE); + } + + // Optionally, draw the centered display string (if needed). + int textColor = 14737632; + if (packedFGColour != 0) { + textColor = packedFGColour; + } else if (!this.enabled) { + textColor = 10526880; + } else if (this.field_146123_n) { + textColor = 16777120; + } + this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + FIXED_WIDTH / 2, + this.yPosition + (FIXED_HEIGHT - 8) / 2, textColor); + } +} diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 2e827cb94..5b5d71dc4 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -58,6 +58,7 @@ tile.npcScripted.name=Scripted Block gui.delete=Are you sure you want to delete this? gui.add=Add +gui.view=View gui.remove=Remove gui.save=Save gui.name=Name @@ -151,6 +152,7 @@ gui.npcs=NPCs gui.change=Change gui.create=Create gui.rename=Rename +gui.playerMap=Regen PlayerMap party.accept=Accept party.allowParty=Allow Partying From 3ee39e8b956d63117856293c992c933e2da8996a Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 20 Feb 2025 13:15:49 -0500 Subject: [PATCH 20/59] Add Pagging to Grabbable Middle Section --- .../npcs/client/gui/SubGuiPlayerData.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java b/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java index 28a3d6d93..44ec2c744 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java @@ -404,31 +404,38 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { + super.drawScreen(mouseX, mouseY, partialTicks); + } + + @Override + public void drawBackground() { + super.drawBackground(); + + int paddingTopBottom = 25; int scrollHeight = getScrollHeight(); int paddedLeft = getPaddedLeft(); int availableWidth = getAvailableWidth(); + int widthPadding = 1; GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); GL11.glEnable(GL11.GL_DEPTH_TEST); // In compact mode for Quests, draw divider between the two scrolls. if (currentTab == 10 && viewMode != 0 && !hasSubGui()) { int dividerX = paddedLeft + dividerOffset1; - drawRect(dividerX, guiTop + scrollTopOffset, dividerX + dividerWidth, guiTop + scrollTopOffset + scrollHeight, 0xFF707070); + drawRect(dividerX + widthPadding, guiTop + scrollTopOffset + paddingTopBottom, dividerX + dividerWidth - widthPadding, guiTop + scrollTopOffset + scrollHeight - paddingTopBottom, 0xFF707070); } // In categorical mode for Quest, draw both dividers. if (currentTab == 10 && viewMode == 0 && !hasSubGui()) { int dividerX1 = paddedLeft + dividerOffset1; int dividerX2 = paddedLeft + dividerOffset2; - drawRect(dividerX1, guiTop + scrollTopOffset, dividerX1 + dividerWidth, guiTop + scrollTopOffset + scrollHeight, 0xFF707070); - drawRect(dividerX2, guiTop + scrollTopOffset, dividerX2 + dividerWidth, guiTop + scrollTopOffset + scrollHeight, 0xFF707070); + drawRect(dividerX1 + widthPadding, guiTop + scrollTopOffset + paddingTopBottom, dividerX1 + dividerWidth - widthPadding, guiTop + scrollTopOffset + scrollHeight - paddingTopBottom, 0xFF707070); + drawRect(dividerX2 + widthPadding, guiTop + scrollTopOffset + paddingTopBottom, dividerX2 + dividerWidth - widthPadding, guiTop + scrollTopOffset + scrollHeight - paddingTopBottom, 0xFF707070); } else if ((currentTab == 11 || currentTab == 12) && viewMode == 0 && !hasSubGui()) { int dividerX = paddedLeft + dividerOffset1; - drawRect(dividerX, guiTop + scrollTopOffset, dividerX + dividerWidth, guiTop + scrollTopOffset + scrollHeight, 0xFF707070); + drawRect(dividerX + widthPadding, guiTop + scrollTopOffset + paddingTopBottom, dividerX + dividerWidth - widthPadding, guiTop + scrollTopOffset + scrollHeight - paddingTopBottom, 0xFF707070); } GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glPopAttrib(); - - super.drawScreen(mouseX, mouseY, partialTicks); // Compact mode for Dialog/Transport uses one scroll => no divider. } From 19a1b629c8bdfa808b801de512d4198ab22672df Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 20 Feb 2025 13:36:07 -0500 Subject: [PATCH 21/59] More Fixerinos --- .../npcs/controllers/ProfileController.java | 95 +++++++------------ .../npcs/client/gui/SubGuiPlayerData.java | 7 +- 2 files changed, 36 insertions(+), 66 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index 769cdb237..5ff9d1919 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -416,38 +416,39 @@ public class ProfileController { if (!profile.slots.containsKey(newSlotId)) { return ProfileOperation.error(MSG_SLOT_NOT_EXIST); } - // Region-based check: if enabled, ensure the player is within an allowed region. - if (ConfigMain.RegionProfileSwitching && profile.player != null) { - boolean allowed = hasPermission(profile.player, PROFILE_REGION_BYPASS); - if(!allowed){ - int playerDim = profile.player.dimension; - int playerX = (int) profile.player.posX; - int playerY = (int) profile.player.posY; - int playerZ = (int) profile.player.posZ; - for (List region : ConfigMain.RestrictedProfileRegions) { - if(region.size() == 7) { - int dim = region.get(0); - int x1 = Math.min(region.get(1), region.get(4)); - int y1 = Math.min(region.get(2), region.get(5)); - int z1 = Math.min(region.get(3), region.get(6)); - int x2 = Math.max(region.get(1), region.get(4)); - int y2 = Math.max(region.get(2), region.get(5)); - int z2 = Math.max(region.get(3), region.get(6)); - if(playerDim == dim && - playerX >= x1 && playerX <= x2 && - playerY >= y1 && playerY <= y2 && - playerZ >= z1 && playerZ <= z2) { - allowed = true; - break; + + if(profile.player != null){ + // Region-based check: if enabled, ensure the player is within an allowed region. + if (ConfigMain.RegionProfileSwitching) { + boolean allowed = hasPermission(profile.player, PROFILE_REGION_BYPASS); + if(!allowed){ + int playerDim = profile.player.dimension; + int playerX = (int) profile.player.posX; + int playerY = (int) profile.player.posY; + int playerZ = (int) profile.player.posZ; + for (List region : ConfigMain.RestrictedProfileRegions) { + if(region.size() == 7) { + int dim = region.get(0); + int x1 = Math.min(region.get(1), region.get(4)); + int y1 = Math.min(region.get(2), region.get(5)); + int z1 = Math.min(region.get(3), region.get(6)); + int x2 = Math.max(region.get(1), region.get(4)); + int y2 = Math.max(region.get(2), region.get(5)); + int z2 = Math.max(region.get(3), region.get(6)); + if(playerDim == dim && + playerX >= x1 && playerX <= x2 && + playerY >= y1 && playerY <= y2 && + playerZ >= z1 && playerZ <= z2) { + allowed = true; + break; + } } } } + if (!allowed) { + return ProfileOperation.error(MSG_REGION_NOT_ALLOWED); + } } - if (!allowed) { - return ProfileOperation.error(MSG_REGION_NOT_ALLOWED); - } - } - if (profile.player != null) { List dataList = new ArrayList<>(profileTypes.values()); dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority)); for (IProfileData pd : dataList) { @@ -455,17 +456,17 @@ public class ProfileController { return pd.verifySwitch(profile.player); } } - } - if (profile.player != null) { saveSlotData(profile.player); - } - profile.currentID = newSlotId; - if (profile.player != null) { + profile.currentID = newSlotId; + loadSlotData(profile.player); PlayerData pdata = PlayerData.get(profile.player); pdata.profileSlot = newSlotId; pdata.save(); + } else { + return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); } + return ProfileOperation.success(MSG_CHANGE_SUCCESS); } @@ -525,20 +526,6 @@ public class ProfileController { return result; } - public static ProfileOperation removeSlot(UUID uuid, int slotId) { - Profile profile = getProfile(uuid); - if(profile == null) - return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); - ProfileOperation result = removeSlotInternal(profile, slotId); - if(result.getResult() == EnumProfileOperation.SUCCESS) { - if(profile.player != null) - save(profile.player, profile); - else - saveOffline(profile, uuid); - } - return result; - } - public static ProfileOperation removeSlot(String username, int slotId) { Profile profile = getProfile(username); if(profile == null) @@ -567,20 +554,6 @@ public class ProfileController { return result; } - public static ProfileOperation changeSlot(UUID uuid, int newSlotId) { - Profile profile = getProfile(uuid); - if(profile == null) - return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); - ProfileOperation result = changeSlotInternal(profile, newSlotId); - if(result.getResult() == EnumProfileOperation.SUCCESS) { - if(profile.player != null) - save(profile.player, profile); - else - saveOffline(profile, uuid); - } - return result; - } - public static ProfileOperation changeSlot(String username, int newSlotId) { Profile profile = getProfile(username); if(profile == null) diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java b/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java index 44ec2c744..3e6431a53 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java @@ -124,10 +124,8 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo // Create top buttons. private void setupTopButtons() { + // Show General Display Information GuiMenuTopButton playerTab = new GuiMenuTopButton(-10, guiLeft + 4, guiTop - 10, playerName); - playerTab.active = false; - playerTab.enabled = false; - playerTab.packedFGColour = CustomNpcResourceListener.DefaultTextColor; GuiMenuTopButton btnQuest = new GuiMenuTopButton(10, playerTab.xPosition + playerTab.getButtonWidth(), guiTop - 10, "quest.quests"); GuiMenuTopButton btnDialog = new GuiMenuTopButton(11, btnQuest.xPosition + btnQuest.getWidth(), guiTop - 10, "dialog.dialogs"); @@ -137,6 +135,7 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo // Close button. GuiMenuTopButton close = new GuiMenuTopButton(-5, guiLeft + xSize - 22, guiTop - 10, "X"); + playerTab.active = (currentTab == -10); btnQuest.active = (currentTab == 10); btnDialog.active = (currentTab == 11); btnTransport.active = (currentTab == 12); @@ -414,7 +413,6 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo int paddingTopBottom = 25; int scrollHeight = getScrollHeight(); int paddedLeft = getPaddedLeft(); - int availableWidth = getAvailableWidth(); int widthPadding = 1; GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); @@ -436,7 +434,6 @@ public class SubGuiPlayerData extends SubGuiInterface implements IPlayerDataInfo } GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glPopAttrib(); - // Compact mode for Dialog/Transport uses one scroll => no divider. } //////////////////////////////////////////////////////////////////////////////// From cd3514aa731b0bb0c7db295e59a5d59eac910ecc Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 20 Feb 2025 13:48:40 -0500 Subject: [PATCH 22/59] Don't save current PlayerData if we're modifying it within a Profile --- .../npcs/controllers/ProfileController.java | 33 ++++++++++--------- .../npcs/controllers/data/PlayerData.java | 9 +++++ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index 5ff9d1919..d289c7f33 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -150,22 +150,25 @@ public class ProfileController { // Offline save (synchronous) when no EntityPlayer is available. public static synchronized void saveOffline(Profile profile, UUID uuid) { - final NBTTagCompound compound = profile.writeToNBT(); - final String filename = uuid.toString() + ".dat"; - try { - File saveDir = getProfileDir(); - File fileNew = new File(saveDir, filename + "_new"); - File fileOld = new File(saveDir, filename); - CompressedStreamTools.writeCompressed(compound, new FileOutputStream(fileNew)); - if(fileOld.exists()){ - fileOld.delete(); + profile.locked = true; + CustomNPCsThreader.customNPCThread.execute(() -> { + final NBTTagCompound compound = profile.writeToNBT(); + final String filename = uuid.toString() + ".dat"; + try { + File saveDir = getProfileDir(); + File fileNew = new File(saveDir, filename + "_new"); + File fileOld = new File(saveDir, filename); + CompressedStreamTools.writeCompressed(compound, new FileOutputStream(fileNew)); + if(fileOld.exists()){ + fileOld.delete(); + } + fileNew.renameTo(fileOld); + // Also backup if allowed. + backupProfile(uuid, compound); + } catch (Exception e) { + LogWriter.except(e); } - fileNew.renameTo(fileOld); - // Also backup if allowed. - backupProfile(uuid, compound); - } catch (Exception e) { - LogWriter.except(e); - } + }); } // Save for online players (asynchronous). diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerData.java b/src/main/java/noppes/npcs/controllers/data/PlayerData.java index d53ff7c1c..982e5b6f3 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerData.java @@ -1,6 +1,8 @@ package noppes.npcs.controllers.data; import kamkeel.npcs.addon.DBCAddon; +import kamkeel.npcs.controllers.ProfileController; +import kamkeel.npcs.controllers.data.Profile; import kamkeel.npcs.network.packets.data.AchievementPacket; import kamkeel.npcs.network.packets.data.ChatAlertPacket; import kamkeel.npcs.network.packets.request.party.PartyInvitePacket; @@ -373,6 +375,13 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData { } public synchronized void save() { + // Don't Save this is a Modification of a Profile's PlayerData + Profile profile = ProfileController.getProfile(UUID.fromString(uuid)); + if(profile != null && profile.currentID != this.profileSlot){ + ProfileController.saveOffline(profile, UUID.fromString(uuid)); + return; + } + final NBTTagCompound compound = getNBT(); final String filename; if(ConfigMain.DatFormat){ From 7820e37180dc73d97229a7c0c85d3a18f132a097 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 20 Feb 2025 21:39:02 -0500 Subject: [PATCH 23/59] Incomplete Push for Refactoring --- .../command/profile/CommandProfileAdmin.java | 24 +- .../command/profile/CommandProfileList.java | 7 +- .../command/profile/CommandProfileRename.java | 4 +- .../npcs/controllers/ProfileController.java | 388 +++++++++--------- .../npcs/controllers/data/CNPCData.java | 2 +- .../npcs/controllers/data/IProfile.java | 33 ++ .../controllers/data/IProfileController.java | 17 + .../kamkeel/npcs/controllers/data/ISlot.java | 63 +++ .../npcs/controllers/data/Profile.java | 98 +++-- .../kamkeel/npcs/controllers/data/Slot.java | 80 +++- .../request/profile/ProfileGetInfoPacket.java | 3 +- .../request/profile/ProfileRenamePacket.java | 4 +- .../gui/player/inventory/GuiProfiles.java | 9 +- .../npcs/controllers/data/PlayerData.java | 2 +- 14 files changed, 473 insertions(+), 261 deletions(-) create mode 100644 src/main/java/kamkeel/npcs/controllers/data/IProfile.java create mode 100644 src/main/java/kamkeel/npcs/controllers/data/IProfileController.java create mode 100644 src/main/java/kamkeel/npcs/controllers/data/ISlot.java diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java index 44acdcfbd..ec15c643d 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java @@ -1,10 +1,7 @@ package kamkeel.npcs.command.profile; import kamkeel.npcs.controllers.ProfileController; -import kamkeel.npcs.controllers.data.Profile; -import kamkeel.npcs.controllers.data.ProfileOperation; -import kamkeel.npcs.controllers.data.EnumProfileOperation; -import kamkeel.npcs.controllers.data.Slot; +import kamkeel.npcs.controllers.data.*; import noppes.npcs.LogWriter; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; @@ -164,10 +161,10 @@ public class CommandProfileAdmin extends CommandProfileBase { return; } sendMessage(sender, "Profile Slots for %s:", targetPlayer); - for(Map.Entry entry : profile.slots.entrySet()) { + for(Map.Entry entry : profile.getSlots().entrySet()) { int id = entry.getKey(); String name = entry.getValue().getName(); - String prefix = (id == profile.currentID) ? "* " : "- "; + String prefix = (id == profile.currentSlotId) ? "* " : "- "; sendMessage(sender, prefix + "Slot " + id + ": " + name); } } @@ -207,16 +204,16 @@ public class CommandProfileAdmin extends CommandProfileBase { sendError(sender, "Profile not found for player: %s", targetPlayer); return; } - if(profile.locked) { + if(profile.isLocked()) { sendError(sender, "Profile for %s is locked. Please try again later.", targetPlayer); return; } - if(!profile.slots.containsKey(slotId)) { + if(!profile.getSlots().containsKey(slotId)) { sendError(sender, "Slot %d not found in %s's profile.", slotId, targetPlayer); return; } - profile.slots.get(slotId).setName(newName); - if(profile.player != null) { + profile.getSlots().get(slotId).setName(newName); + if(profile.getPlayer() != null) { ProfileController.save(profile.player, profile); } else { UUID uuid = ProfileController.getUUIDFromUsername(targetPlayer); @@ -237,7 +234,12 @@ public class CommandProfileAdmin extends CommandProfileBase { } String targetPlayer = args[0]; String backupFileName = args[1] + ".dat"; - File backupDir = new File(ProfileController.getBackupDir(), ProfileController.getProfile(targetPlayer).player.getUniqueID().toString()); + + Profile profile = ProfileController.getProfile(targetPlayer); + if(profile == null || profile.player == null) + return; + + File backupDir = new File(ProfileController.getBackupDir(), profile.getPlayer().getUniqueID().toString()); File backupFile = new File(backupDir, backupFileName); if(!backupFile.exists()){ sendError(sender, "Backup file %s not found for player %s.", backupFileName, targetPlayer); diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java index 07d03fc90..8c387ae4d 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java @@ -1,6 +1,7 @@ package kamkeel.npcs.command.profile; import kamkeel.npcs.controllers.ProfileController; +import kamkeel.npcs.controllers.data.ISlot; import kamkeel.npcs.controllers.data.Profile; import kamkeel.npcs.controllers.data.Slot; import net.minecraft.command.CommandException; @@ -39,14 +40,14 @@ public class CommandProfileList extends CommandProfileBase { sendError(sender, "Profile not found."); return; } - if(profile.slots.isEmpty()){ + if(profile.getSlots().isEmpty()){ sendMessage(sender, "No slots found. Using default slot 0."); } sendMessage(sender, "Your Profile Slots:"); - for(Map.Entry entry : profile.slots.entrySet()) { + for(Map.Entry entry : profile.getSlots().entrySet()) { int id = entry.getKey(); String name = entry.getValue().getName(); - String prefix = (id == profile.currentID) ? "* " : "- "; + String prefix = (id == profile.currentSlotId) ? "* " : "- "; sendMessage(sender, prefix + "Slot " + id + ": " + name); } } diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java index dbb116d87..3800bb1e6 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java @@ -60,11 +60,11 @@ public class CommandProfileRename extends CommandProfileBase { sendError(sender, "Profile not found."); return; } - if(!ProfileController.getProfile(player).slots.containsKey(slotId)) { + if(!ProfileController.getProfile(player).getSlots().containsKey(slotId)) { sendError(sender, "Slot %d not found in your profile.", slotId); return; } - ProfileController.getProfile(player).slots.get(slotId).setName(newName); + ProfileController.getProfile(player).getSlots().get(slotId).setName(newName); ProfileController.save(player, ProfileController.getProfile(player)); sendResult(sender, "Successfully renamed slot %d to '%s'.", slotId, newName); } diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index d289c7f33..f5065e475 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -1,7 +1,6 @@ package kamkeel.npcs.controllers; import kamkeel.npcs.controllers.data.*; -import kamkeel.npcs.network.packets.data.ChatAlertPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.CompressedStreamTools; @@ -10,73 +9,65 @@ import net.minecraft.server.MinecraftServer; import noppes.npcs.CustomNpcs; import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.LogWriter; +import noppes.npcs.api.entity.IPlayer; +import noppes.npcs.api.handler.IPlayerData; import noppes.npcs.config.ConfigMain; +import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.controllers.data.PlayerData; import noppes.npcs.util.CustomNPCsThreader; import noppes.npcs.util.NBTJsonUtil; - import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.text.SimpleDateFormat; import java.util.*; - import static noppes.npcs.CustomNpcsPermissions.PROFILE_REGION_BYPASS; import static noppes.npcs.CustomNpcsPermissions.hasPermission; -public class ProfileController { +public class ProfileController implements IProfileController { - // ------------------- Message Constants ------------------- - // General messages + // Message constants private static final String MSG_PLAYER_NOT_FOUND = "Player not found."; - - // Clone Slot messages private static final String MSG_PROFILE_LOCKED_CLONE = "Profile is locked; cannot clone slot."; private static final String MSG_SOURCE_SLOT_NOT_EXIST = "Source slot does not exist."; private static final String MSG_CANNOT_CLONE_CURRENT = "Cannot clone to the current active slot."; private static final String MSG_INVALID_DEST_SLOT = "Invalid destination slot id."; private static final String MSG_CLONE_SUCCESS = "Slot cloned successfully."; - - // Remove Slot messages private static final String MSG_PROFILE_LOCKED_REMOVE = "Profile is locked; cannot remove slot."; private static final String MSG_CANNOT_REMOVE_ACTIVE = "Cannot remove the currently active slot."; private static final String MSG_SLOT_NOT_EXIST = "Slot does not exist."; private static final String MSG_REMOVE_SUCCESS = "Slot removed successfully."; - - // Create Slot messages private static final String MSG_PROFILE_LOCKED_CREATE = "Profile is locked; cannot create slot."; private static final String MSG_MAX_SLOTS_REACHED = "Maximum allowed slots reached."; private static final String MSG_NEW_SLOT_CREATED = "New slot created successfully."; - - // Change Slot messages private static final String MSG_PROFILE_LOCKED_CHANGE = "Profile is locked; cannot change slot."; private static final String MSG_SLOT_ALREADY_ACTIVE = "Slot is already active."; private static final String MSG_REGION_NOT_ALLOWED = "Profile switching not allowed from your current location."; private static final String MSG_CHANGE_SUCCESS = "Slot changed successfully."; - // ------------------- End Constants ------------------- - - public static HashMap profileTypes; - public static HashMap activeProfiles; + public static Map profileTypes = new HashMap<>(); + public static Map activeProfiles = new HashMap<>(); public static String profile_directory = "profiles"; - public ProfileController(){ + public static ProfileController Instance; + + public ProfileController() { + Instance = this; profileTypes = new HashMap<>(); activeProfiles = new HashMap<>(); } - // ---------- Registration & I/O ---------- - public static boolean registerProfileType(IProfileData type){ - if(profileTypes.containsKey(type.getTagName())) + public static boolean registerProfileType(IProfileData type) { + if (profileTypes.containsKey(type.getTagName())) return false; profileTypes.put(type.getTagName(), type); return true; } - public static File getProfileDir(){ + public static File getProfileDir() { try { File file = new File(CustomNpcs.getWorldSaveDirectory(), profile_directory); - if(!file.exists()) + if (!file.exists()) file.mkdir(); return file; } catch (Exception e) { @@ -85,34 +76,31 @@ public class ProfileController { } } - // Returns the backup folder for profiles. public static File getBackupDir() { File base = getProfileDir(); File backup = new File(base, "backup"); - if(!backup.exists()){ + if (!backup.exists()) { backup.mkdir(); } return backup; } - // Login for online players. - // If no slots exist, create default slot 0 and save the player's current IProfileData into it. - public static synchronized void login(EntityPlayer player){ - if(player == null) + public synchronized void login(EntityPlayer player) { + if (player == null) return; Profile profile; - if(activeProfiles.containsKey(player.getUniqueID())){ + if (activeProfiles.containsKey(player.getUniqueID())) { profile = activeProfiles.get(player.getUniqueID()); - profile.player = player; + // Update the player reference if needed. + profile = new Profile(player, profile.writeToNBT()); } else { NBTTagCompound compound = load(player); profile = new Profile(player, compound); - // If no slots exist, create default slot 0. - if(profile.slots.isEmpty()){ + if (profile.getSlots().isEmpty()) { Slot defaultSlot = new Slot(0, "Default Slot"); - defaultSlot.setCompound(new NBTTagCompound()); - profile.slots.put(0, defaultSlot); - profile.currentID = 0; + defaultSlot.setLastLoaded(System.currentTimeMillis()); + profile.getSlots().put(0, defaultSlot); + profile.currentSlotId = 0; saveSlotData(player); save(player, profile); } @@ -125,7 +113,7 @@ public class ProfileController { String filename = player.getUniqueID().toString() + ".dat"; try { File file = new File(saveDir, filename); - if(file.exists()){ + if (file.exists()) { return NBTJsonUtil.loadNBTData(file); } } catch (Exception e) { @@ -139,7 +127,7 @@ public class ProfileController { String filename = uuid.toString() + ".dat"; try { File file = new File(saveDir, filename); - if(file.exists()){ + if (file.exists()) { return NBTJsonUtil.loadNBTData(file); } } catch (Exception e) { @@ -148,9 +136,8 @@ public class ProfileController { return new NBTTagCompound(); } - // Offline save (synchronous) when no EntityPlayer is available. public static synchronized void saveOffline(Profile profile, UUID uuid) { - profile.locked = true; + profile.setLocked(true); CustomNPCsThreader.customNPCThread.execute(() -> { final NBTTagCompound compound = profile.writeToNBT(); final String filename = uuid.toString() + ".dat"; @@ -159,11 +146,10 @@ public class ProfileController { File fileNew = new File(saveDir, filename + "_new"); File fileOld = new File(saveDir, filename); CompressedStreamTools.writeCompressed(compound, new FileOutputStream(fileNew)); - if(fileOld.exists()){ + if (fileOld.exists()) { fileOld.delete(); } fileNew.renameTo(fileOld); - // Also backup if allowed. backupProfile(uuid, compound); } catch (Exception e) { LogWriter.except(e); @@ -171,9 +157,8 @@ public class ProfileController { }); } - // Save for online players (asynchronous). public static synchronized void save(EntityPlayer player, Profile profile) { - profile.locked = true; + profile.setLocked(true); CustomNPCsThreader.customNPCThread.execute(() -> { final NBTTagCompound compound = profile.writeToNBT(); final String filename = player.getUniqueID() + ".dat"; @@ -182,98 +167,89 @@ public class ProfileController { File fileNew = new File(saveDir, filename + "_new"); File fileOld = new File(saveDir, filename); CompressedStreamTools.writeCompressed(compound, new FileOutputStream(fileNew)); - if(fileOld.exists()){ + if (fileOld.exists()) { fileOld.delete(); } fileNew.renameTo(fileOld); - // Backup if enabled. - if(ConfigMain.AllowProfileBackups) { + if (ConfigMain.AllowProfileBackups) { backupProfile(player.getUniqueID(), compound); } } catch (Exception e) { LogWriter.except(e); } finally { - profile.locked = false; + profile.setLocked(false); } }); } - // Backup the profile by saving a copy to profiles/backup//.dat. private static void backupProfile(UUID uuid, NBTTagCompound compound) { try { File backupDir = new File(getBackupDir(), uuid.toString()); - if(!backupDir.exists()){ + if (!backupDir.exists()) { backupDir.mkdirs(); } String dateStr = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File backupFile = new File(backupDir, dateStr + ".dat"); CompressedStreamTools.writeCompressed(compound, new FileOutputStream(backupFile)); - // Now enforce backup amount limit. File[] backups = backupDir.listFiles((dir, name) -> name.endsWith(".dat")); - if(backups != null && backups.length > ConfigMain.ProfileBackupAmount) { + if (backups != null && backups.length > ConfigMain.ProfileBackupAmount) { Arrays.sort(backups, Comparator.comparingLong(File::lastModified)); - for(int i = 0; i < backups.length - ConfigMain.ProfileBackupAmount; i++){ + for (int i = 0; i < backups.length - ConfigMain.ProfileBackupAmount; i++) { backups[i].delete(); } } - } catch(Exception e) { + } catch (Exception e) { LogWriter.except(e); } } - // Rollback a player's profile from a backup file. - // Returns true if successful. public static boolean rollbackProfile(String username, File backupFile) { UUID uuid = getUUIDFromUsername(username); - if(uuid == null) return false; + if (uuid == null) + return false; try (FileInputStream fis = new FileInputStream(backupFile)) { NBTTagCompound compound = CompressedStreamTools.readCompressed(fis); - // Overwrite the main profile file. File saveDir = getProfileDir(); File mainFile = new File(saveDir, uuid.toString() + ".dat"); File fileNew = new File(saveDir, uuid.toString() + "_new"); CompressedStreamTools.writeCompressed(compound, new FileOutputStream(fileNew)); - if(mainFile.exists()){ + if (mainFile.exists()) { mainFile.delete(); } fileNew.renameTo(mainFile); - - // Update the in-memory profile. EntityPlayerMP player = getPlayer(username); Profile newProfile; - if(player != null) { + if (player != null) { newProfile = new Profile(player, compound); activeProfiles.put(uuid, newProfile); - // Load the rolled-back data into the player's IProfileData. loadSlotData(player); } else { newProfile = new Profile(null, compound); activeProfiles.put(uuid, newProfile); } return true; - } catch(Exception e) { + } catch (Exception e) { LogWriter.except(e); return false; } } - // Logout removes an active profile. public static synchronized void logout(EntityPlayer player) { - if(player != null) { + if (player != null) { activeProfiles.remove(player.getUniqueID()); } } - // ---------- Profile Retrieval Helpers ---------- public static Profile getProfile(EntityPlayer player) { - if(player == null) return null; - if(!activeProfiles.containsKey(player.getUniqueID())) + if (player == null) + return null; + if (!activeProfiles.containsKey(player.getUniqueID())) login(player); return activeProfiles.get(player.getUniqueID()); } public static Profile getProfile(UUID uuid) { - if(activeProfiles.containsKey(uuid)) + if (activeProfiles.containsKey(uuid)) return activeProfiles.get(uuid); NBTTagCompound compound = load(uuid); return new Profile(null, compound); @@ -281,16 +257,16 @@ public class ProfileController { public static Profile getProfile(String username) { EntityPlayer player = getPlayer(username); - if(player != null) { + if (player != null) { return getProfile(player); } else { UUID uuid = getUUIDFromUsername(username); - if(uuid == null) return null; + if (uuid == null) + return null; return getProfile(uuid); } } - // ---------- Mojang API UUID Lookup ---------- public static UUID getUUIDFromUsername(String username) { try { URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + username); @@ -301,13 +277,13 @@ public class ProfileController { BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); StringBuilder temp = new StringBuilder(); String line; - while((line = in.readLine()) != null){ + while ((line = in.readLine()) != null) { temp.append(line); } in.close(); con.disconnect(); String response = temp.toString(); - if(response.contains("\"id\"")) { + if (response.contains("\"id\"")) { int idIndex = response.indexOf("\"id\""); int colonIndex = response.indexOf(":", idIndex); int quoteStart = response.indexOf("\"", colonIndex); @@ -325,70 +301,70 @@ public class ProfileController { return null; } - // ---------- Internal Slot Operation Helpers ---------- private static int getNextAvailableTempSlot(Profile profile) { int id = -1; - while(profile.slots.containsKey(id)) { + while (profile.getSlots().containsKey(id)) { id--; } return id; } - // Clone a slot within a Profile. private static ProfileOperation cloneSlotInternal(Profile profile, int sourceSlotId, int destinationSlotId, boolean temporary) { - if(profile.locked) { + if (profile.isLocked()) { return ProfileOperation.locked(MSG_PROFILE_LOCKED_CLONE); } - if(profile.player != null) { + if (profile.player != null) { List dataList = new ArrayList<>(profileTypes.values()); dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority)); - for(IProfileData pd : dataList) { + for (IProfileData pd : dataList) { if (pd.verifySwitch(profile.player).getResult() != EnumProfileOperation.SUCCESS) { return pd.verifySwitch(profile.player); } } } - if(!profile.slots.containsKey(sourceSlotId)) { + if (!profile.getSlots().containsKey(sourceSlotId)) { return ProfileOperation.error(MSG_SOURCE_SLOT_NOT_EXIST); } - if(destinationSlotId == profile.currentID) { + if (destinationSlotId == profile.getCurrentSlotId()) { return ProfileOperation.error(MSG_CANNOT_CLONE_CURRENT); } - if(temporary) { + if (temporary) { destinationSlotId = getNextAvailableTempSlot(profile); } else { - if(destinationSlotId <= 0) { + if (destinationSlotId <= 0) { return ProfileOperation.error(MSG_INVALID_DEST_SLOT); } } - Slot sourceSlot = profile.slots.get(sourceSlotId); - NBTTagCompound clonedData = (NBTTagCompound) sourceSlot.getCompound().copy(); - Slot clonedSlot = new Slot(destinationSlotId, "Cloned Slot " + destinationSlotId, clonedData, System.currentTimeMillis(), temporary); - profile.slots.put(destinationSlotId, clonedSlot); + ISlot sourceSlot = profile.getSlots().get(sourceSlotId); + Map newComponents = new HashMap<>(); + for (String key : sourceSlot.getComponents().keySet()) { + newComponents.put(key, sourceSlot.getComponentData(key).copy()); + } + Slot clonedSlot = new Slot(destinationSlotId, "Cloned Slot " + destinationSlotId, System.currentTimeMillis(), temporary, newComponents); + profile.getSlots().put(destinationSlotId, clonedSlot); return ProfileOperation.success(MSG_CLONE_SUCCESS); } - // Remove a slot from a Profile. private static ProfileOperation removeSlotInternal(Profile profile, int slotId) { - if(profile.locked) { + if (profile.isLocked()) { return ProfileOperation.locked(MSG_PROFILE_LOCKED_REMOVE); } - if(slotId == profile.currentID) { + if (slotId == profile.getCurrentSlotId()) { return ProfileOperation.error(MSG_CANNOT_REMOVE_ACTIVE); } - if(!profile.slots.containsKey(slotId)) { + if (!profile.getSlots().containsKey(slotId)) { return ProfileOperation.error(MSG_SLOT_NOT_EXIST); } - profile.slots.remove(slotId); + profile.getSlots().remove(slotId); return ProfileOperation.success(MSG_REMOVE_SUCCESS); } public static ProfileOperation createSlotInternal(Profile profile) { - if (profile.locked) { + if (profile.isLocked()) { return ProfileOperation.locked(MSG_PROFILE_LOCKED_CREATE); } int newSlotId = 0; - while (profile.slots.containsKey(newSlotId)) { + while (profile.getSlots().containsKey(newSlotId)) { newSlotId++; } if (!allowSlotPermission(profile.player)) { @@ -404,33 +380,31 @@ public class ProfileController { } } Slot newSlot = new Slot(newSlotId, "Slot " + newSlotId); - newSlot.setCompound(new NBTTagCompound()); - profile.slots.put(newSlotId, newSlot); + newSlot.setLastLoaded(System.currentTimeMillis()); + profile.getSlots().put(newSlotId, newSlot); return ProfileOperation.success(MSG_NEW_SLOT_CREATED); } private static ProfileOperation changeSlotInternal(Profile profile, int newSlotId) { - if (profile.locked) { + if (profile.isLocked()) { return ProfileOperation.locked(MSG_PROFILE_LOCKED_CHANGE); } - if (profile.currentID == newSlotId) { + if (profile.getCurrentSlotId() == newSlotId) { return ProfileOperation.error(MSG_SLOT_ALREADY_ACTIVE); } - if (!profile.slots.containsKey(newSlotId)) { + if (!profile.getSlots().containsKey(newSlotId)) { return ProfileOperation.error(MSG_SLOT_NOT_EXIST); } - - if(profile.player != null){ - // Region-based check: if enabled, ensure the player is within an allowed region. + if (profile.player != null) { if (ConfigMain.RegionProfileSwitching) { boolean allowed = hasPermission(profile.player, PROFILE_REGION_BYPASS); - if(!allowed){ + if (!allowed) { int playerDim = profile.player.dimension; int playerX = (int) profile.player.posX; int playerY = (int) profile.player.posY; int playerZ = (int) profile.player.posZ; for (List region : ConfigMain.RestrictedProfileRegions) { - if(region.size() == 7) { + if (region.size() == 7) { int dim = region.get(0); int x1 = Math.min(region.get(1), region.get(4)); int y1 = Math.min(region.get(2), region.get(5)); @@ -438,7 +412,7 @@ public class ProfileController { int x2 = Math.max(region.get(1), region.get(4)); int y2 = Math.max(region.get(2), region.get(5)); int z2 = Math.max(region.get(3), region.get(6)); - if(playerDim == dim && + if (playerDim == dim && playerX >= x1 && playerX <= x2 && playerY >= y1 && playerY <= y2 && playerZ >= z1 && playerZ <= z2) { @@ -460,8 +434,7 @@ public class ProfileController { } } saveSlotData(profile.player); - profile.currentID = newSlotId; - + profile.currentSlotId = newSlotId; loadSlotData(profile.player); PlayerData pdata = PlayerData.get(profile.player); pdata.profileSlot = newSlotId; @@ -469,18 +442,15 @@ public class ProfileController { } else { return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); } - return ProfileOperation.success(MSG_CHANGE_SUCCESS); } - // ---------- Public Operations (Overloaded for EntityPlayer, UUID, or username) ---------- - // ----- Clone Slot ----- public static ProfileOperation cloneSlot(EntityPlayer player, int sourceSlotId, int destinationSlotId, boolean temporary) { Profile profile = getProfile(player); - if(profile == null) + if (profile == null) return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); ProfileOperation result = cloneSlotInternal(profile, sourceSlotId, destinationSlotId, temporary); - if(result.getResult() == EnumProfileOperation.SUCCESS && player != null) { + if (result.getResult() == EnumProfileOperation.SUCCESS && player != null) { save(player, profile); } return result; @@ -488,11 +458,11 @@ public class ProfileController { public static ProfileOperation cloneSlot(UUID uuid, int sourceSlotId, int destinationSlotId, boolean temporary) { Profile profile = getProfile(uuid); - if(profile == null) + if (profile == null) return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); ProfileOperation result = cloneSlotInternal(profile, sourceSlotId, destinationSlotId, temporary); - if(result.getResult() == EnumProfileOperation.SUCCESS) { - if(profile.player != null) + if (result.getResult() == EnumProfileOperation.SUCCESS) { + if (profile.player != null) save(profile.player, profile); else saveOffline(profile, uuid); @@ -502,28 +472,27 @@ public class ProfileController { public static ProfileOperation cloneSlot(String username, int sourceSlotId, int destinationSlotId, boolean temporary) { Profile profile = getProfile(username); - if(profile == null) + if (profile == null) return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); ProfileOperation result = cloneSlotInternal(profile, sourceSlotId, destinationSlotId, temporary); - if(result.getResult() == EnumProfileOperation.SUCCESS) { - if(profile.player != null) + if (result.getResult() == EnumProfileOperation.SUCCESS) { + if (profile.player != null) save(profile.player, profile); else { UUID uuid = getUUIDFromUsername(username); - if(uuid != null) + if (uuid != null) saveOffline(profile, uuid); } } return result; } - // ----- Remove Slot ----- public static ProfileOperation removeSlot(EntityPlayer player, int slotId) { Profile profile = getProfile(player); - if(profile == null) + if (profile == null) return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); ProfileOperation result = removeSlotInternal(profile, slotId); - if(result.getResult() == EnumProfileOperation.SUCCESS && player != null) { + if (result.getResult() == EnumProfileOperation.SUCCESS && player != null) { save(player, profile); } return result; @@ -531,95 +500,83 @@ public class ProfileController { public static ProfileOperation removeSlot(String username, int slotId) { Profile profile = getProfile(username); - if(profile == null) + if (profile == null) return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); ProfileOperation result = removeSlotInternal(profile, slotId); - if(result.getResult() == EnumProfileOperation.SUCCESS) { - if(profile.player != null) + if (result.getResult() == EnumProfileOperation.SUCCESS) { + if (profile.player != null) save(profile.player, profile); else { UUID uuid = getUUIDFromUsername(username); - if(uuid != null) + if (uuid != null) saveOffline(profile, uuid); } } return result; } - // ----- Change Slot ----- public static ProfileOperation changeSlot(EntityPlayer player, int newSlotId) { Profile profile = getProfile(player); - if(profile == null) + if (profile == null) return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); ProfileOperation result = changeSlotInternal(profile, newSlotId); - if(result.getResult() == EnumProfileOperation.SUCCESS && player != null) + if (result.getResult() == EnumProfileOperation.SUCCESS && player != null) save(player, profile); return result; } public static ProfileOperation changeSlot(String username, int newSlotId) { Profile profile = getProfile(username); - if(profile == null) + if (profile == null) return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); ProfileOperation result = changeSlotInternal(profile, newSlotId); - if(result.getResult() == EnumProfileOperation.SUCCESS) { - if(profile.player != null) + if (result.getResult() == EnumProfileOperation.SUCCESS) { + if (profile.player != null) save(profile.player, profile); else { UUID uuid = getUUIDFromUsername(username); - if(uuid != null) + if (uuid != null) saveOffline(profile, uuid); } } return result; } - // ---------- Saving current slot data (used before switching) ---------- - public static void saveSlotData(EntityPlayer player){ - if(player == null || !activeProfiles.containsKey(player.getUniqueID())) + public void saveSlotData(EntityPlayer player) { + if (player == null || !activeProfiles.containsKey(player.getUniqueID())) return; Profile profile = activeProfiles.get(player.getUniqueID()); - if(profile.locked) { + if (profile.isLocked()) { return; } - NBTTagCompound dataCompound; - Slot slot; - if(!profile.slots.isEmpty() && profile.slots.containsKey(profile.currentID)){ - slot = profile.slots.get(profile.currentID); - dataCompound = (NBTTagCompound) slot.getCompound().copy(); - } else { - slot = new Slot(profile.currentID, "Slot " + profile.currentID); - dataCompound = new NBTTagCompound(); - slot.setCompound(dataCompound); + ISlot slot = profile.getSlots().get(profile.getCurrentSlotId()); + if (slot == null) { + slot = new Slot(profile.getCurrentSlotId(), "Slot " + profile.getCurrentSlotId()); + profile.getSlots().put(profile.getCurrentSlotId(), slot); } - List dataList = new ArrayList<>(profileTypes.values()); - dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority)); - for(IProfileData profileData : dataList){ - NBTTagCompound cloned = (NBTTagCompound) profileData.getCurrentNBT(player).copy(); - dataCompound.setTag(profileData.getTagName(), cloned); + for (IProfileData profileData : profileTypes.values()) { + NBTTagCompound cloned = profileData.getCurrentNBT(player).copy(); + slot.setComponentData(profileData.getTagName(), cloned); } - slot.setCompound(dataCompound); slot.setLastLoaded(System.currentTimeMillis()); } public static void loadSlotData(EntityPlayer player) { - if(player == null || !activeProfiles.containsKey(player.getUniqueID())) + if (player == null || !activeProfiles.containsKey(player.getUniqueID())) return; Profile profile = activeProfiles.get(player.getUniqueID()); - if(profile.slots.isEmpty() || !profile.slots.containsKey(profile.currentID)) + ISlot slot = profile.getSlots().get(profile.getCurrentSlotId()); + if (slot == null) return; - NBTTagCompound slotCompound = (NBTTagCompound) profile.slots.get(profile.currentID).getCompound().copy(); - List dataList = new ArrayList<>(profileTypes.values()); - dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority)); - for(IProfileData profileData : dataList){ + for (IProfileData profileData : profileTypes.values()) { NBTTagCompound data; - if(slotCompound.hasKey(profileData.getTagName())) - data = slotCompound.getCompoundTag(profileData.getTagName()); + if (slot.getComponents().containsKey(profileData.getTagName())) + data = slot.getComponentData(profileData.getTagName()); else data = new NBTTagCompound(); profileData.setNBT(player, data); } - for(IProfileData profileData : dataList){ + for (IProfileData profileData : profileTypes.values()) { profileData.save(player); } } @@ -629,25 +586,19 @@ public class ProfileController { Profile profile = getProfile(player); if (profile == null) return infoList; - - List dataList = new ArrayList<>(profileTypes.values()); - dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority)); - - if (slotId == profile.currentID) { - // Use current data (not stored slot data) for active slot. - for (IProfileData pd : dataList) { + if (slotId == profile.getCurrentSlotId()) { + for (IProfileData pd : profileTypes.values()) { NBTTagCompound currentNBT = pd.getCurrentNBT(player); List subInfo = pd.getInfo(player, currentNBT); infoList.addAll(subInfo); } } else { - // Use stored data from the specified slot. - if (!profile.slots.containsKey(slotId)) + if (!profile.getSlots().containsKey(slotId)) return infoList; - NBTTagCompound slotCompound = profile.slots.get(slotId).getCompound(); - for (IProfileData pd : dataList) { - if (slotCompound.hasKey(pd.getTagName())) { - NBTTagCompound sub = slotCompound.getCompoundTag(pd.getTagName()); + ISlot slot = profile.getSlots().get(slotId); + for (IProfileData pd : profileTypes.values()) { + if (slot.getComponents().containsKey(pd.getTagName())) { + NBTTagCompound sub = slot.getComponentData(pd.getTagName()); List subInfo = pd.getInfo(player, sub); infoList.addAll(subInfo); } @@ -657,14 +608,11 @@ public class ProfileController { } public static boolean allowSlotPermission(EntityPlayer player) { - Profile profile = ProfileController.getProfile(player); - int currentSlots = profile.slots.size(); - - // Unlimited slots if the player has the wildcard permission. + Profile profile = getProfile(player); + int currentSlots = profile.getSlots().size(); if (CustomNpcsPermissions.hasCustomPermission(player, "customnpcs.profile.max.*")) { return true; } - int highestAllowed = 0; for (int i = 1; i <= 50; i++) { String perm = "customnpcs.profile.max." + i; @@ -672,15 +620,85 @@ public class ProfileController { highestAllowed = i; } } - if (highestAllowed == 0) { highestAllowed = 1; } - return currentSlots < highestAllowed; } - public static EntityPlayerMP getPlayer(String username){ + public static EntityPlayerMP getPlayer(String username) { return MinecraftServer.getServer().getConfigurationManager().func_152612_a(username); } + + @Override + public IProfile getProfile(IPlayer player) { + if(player == null || player.getMCEntity() == null) + return null; + return ProfileController.getProfile((EntityPlayer) player.getMCEntity()); + } + + @Override + public boolean changeSlot(IPlayer player, int slotID) { + if(player == null || player.getMCEntity() == null) + return false; + + EntityPlayer entityPlayer = (EntityPlayer) player.getMCEntity(); + ProfileOperation profileOperation = changeSlot(entityPlayer, slotID); + return profileOperation.getResult() == EnumProfileOperation.SUCCESS; + } + + @Override + public boolean hasSlot(IPlayer player, int slotID) { + if(player == null || player.getMCEntity() == null) + return false; + + EntityPlayer entityPlayer = (EntityPlayer) player.getMCEntity(); + Profile profile = getProfile(entityPlayer); + if(profile == null) + return false; + return profile.getSlots().containsKey(slotID); + } + + @Override + public boolean removeSlot(IPlayer player, int slotID) { + if(player == null || player.getMCEntity() == null) + return false; + + EntityPlayer entityPlayer = (EntityPlayer) player.getMCEntity(); + ProfileOperation profileOperation = removeSlot(entityPlayer, slotID); + return profileOperation.getResult() == EnumProfileOperation.SUCCESS; + } + + @Override + public IPlayerData getSlotPlayerData(IPlayer player, int slotID) { + PlayerData playerData; + if(player == null || player.getMCEntity() == null) + return null; + + EntityPlayer entityPlayer = (EntityPlayer) player.getMCEntity(); + Profile profile = getProfile(entityPlayer); + if(profile == null) + return null; + + if(profile.currentSlotId == slotID){ + playerData = PlayerData.get(entityPlayer); + } else { + Slot slot = (Slot) profile.getSlots().get(slotID); + if(slot == null) + return null; + + playerData = new PlayerData(); + playerData.player = entityPlayer; + playerData.setNBT(slot.getComponentData(new CNPCData().getTagName())); + } + return playerData; + } + + public void saveSlotData(IPlayer player) { + if(player == null || player.getMCEntity() == null) + return; + + EntityPlayer entityPlayer = (EntityPlayer) player.getMCEntity(); + saveSlotData(entityPlayer); + } } diff --git a/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java b/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java index c40c43ca4..0e65043b1 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java +++ b/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java @@ -13,7 +13,7 @@ public class CNPCData implements IProfileData { @Override public String getTagName() { - return "CustomNPC+"; + return "CNPC+"; } @Override diff --git a/src/main/java/kamkeel/npcs/controllers/data/IProfile.java b/src/main/java/kamkeel/npcs/controllers/data/IProfile.java new file mode 100644 index 000000000..a82c724bb --- /dev/null +++ b/src/main/java/kamkeel/npcs/controllers/data/IProfile.java @@ -0,0 +1,33 @@ +package kamkeel.npcs.controllers.data; + +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.api.entity.IPlayer; + +import java.util.Map; + +public interface IProfile { + + + /** + * @return the IPlayer attached to the Profile + */ + IPlayer getPlayer(); + + + /** + * @return The profiles current Slot ID + */ + int getCurrentSlotId(); + + + /** + * @return Map of all Slot IDs + */ + Map getSlots(); + + + /** + * @return FULL NBT of the Profile + */ + NBTTagCompound writeToNBT(); +} diff --git a/src/main/java/kamkeel/npcs/controllers/data/IProfileController.java b/src/main/java/kamkeel/npcs/controllers/data/IProfileController.java new file mode 100644 index 000000000..4d28291f9 --- /dev/null +++ b/src/main/java/kamkeel/npcs/controllers/data/IProfileController.java @@ -0,0 +1,17 @@ +package kamkeel.npcs.controllers.data; + +import noppes.npcs.api.entity.IPlayer; +import noppes.npcs.api.handler.IPlayerData; + +public interface IProfileController { + + IProfile getProfile(IPlayer player); + + boolean changeSlot(IPlayer player, int slotID); + + boolean hasSlot(IPlayer player, int slotID); + + boolean removeSlot(IPlayer player, int slotID); + + IPlayerData getSlotPlayerData(IPlayer player, int slotID); +} diff --git a/src/main/java/kamkeel/npcs/controllers/data/ISlot.java b/src/main/java/kamkeel/npcs/controllers/data/ISlot.java new file mode 100644 index 000000000..2c0601d58 --- /dev/null +++ b/src/main/java/kamkeel/npcs/controllers/data/ISlot.java @@ -0,0 +1,63 @@ +package kamkeel.npcs.controllers.data; + +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.api.handler.IPlayerData; +import noppes.npcs.controllers.data.PlayerData; + +import java.util.Map; + +public interface ISlot { + /** + * @return id of slot + */ + int getId(); + + /** + * @return Name of Slot + */ + String getName(); + + + /** + * @param name - New name of slot + */ + void setName(String name); + + /** + * @return Last time Slot was Saved + */ + long getLastLoaded(); + + /** + * @param time - Long time for when it was last saved + */ + void setLastLoaded(long time); + + /** + * @return if the slot is temporary + */ + boolean isTemporary(); + + /** + * @param temporary - Setting a slot to temporary won't save it to Profile + */ + void setTemporary(boolean temporary); + + /** + * @return A map of all the NBTs within a slot + */ + Map getComponents(); + + void setComponentData(String key, NBTTagCompound data); + + /** + * @param key - The KEY of the NBT for the Slot: [CNPC+, DBC... etc] + * @return NBT for that that key + */ + NBTTagCompound getComponentData(String key); + + /** + * @return The full NBT of the Slot + */ + NBTTagCompound toNBT(); +} diff --git a/src/main/java/kamkeel/npcs/controllers/data/Profile.java b/src/main/java/kamkeel/npcs/controllers/data/Profile.java index 3a1baac89..03f91ad0c 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/Profile.java +++ b/src/main/java/kamkeel/npcs/controllers/data/Profile.java @@ -2,55 +2,89 @@ package kamkeel.npcs.controllers.data; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.NoppesUtilServer; +import noppes.npcs.api.entity.IPlayer; import java.util.HashMap; +import java.util.Map; import java.util.Set; -public class Profile { - +public class Profile implements IProfile { public EntityPlayer player; - public int currentID; - public HashMap slots = new HashMap<>(); - public boolean locked = false; + public int currentSlotId; + private Map slots = new HashMap<>(); + private boolean locked = false; public Profile(EntityPlayer player, NBTTagCompound compound) { this.player = player; - if(compound.hasKey("CurrentID")){ - this.currentID = compound.getInteger("CurrentID"); + if(compound.hasKey("CurrentSlotId")){ + this.currentSlotId = compound.getInteger("CurrentSlotId"); } else { - this.currentID = 0; + this.currentSlotId = 0; } - if(compound.hasKey("Slots")) { + if(compound.hasKey("Slots")){ NBTTagCompound slotsCompound = compound.getCompoundTag("Slots"); - for(String key : (Set) slotsCompound.func_150296_c()){ - int slotID = Integer.parseInt(key); - NBTTagCompound slotNBT = slotsCompound.getCompoundTag(key); - Slot slot = Slot.fromNBT(slotID, slotNBT); - slots.put(slotID, slot); + Set keys = slotsCompound.func_150296_c(); + for(String key : keys) { + try { + int slotId = Integer.parseInt(key); + NBTTagCompound slotNBT = slotsCompound.getCompoundTag(key); + ISlot slot = Slot.fromNBT(slotId, slotNBT); + slots.put(slotId, slot); + } catch (NumberFormatException e) { + // Skip keys that are not valid slot IDs. + } } } } - public NBTTagCompound writeToNBT() { - NBTTagCompound fullCompound = new NBTTagCompound(); - if(this.player != null) - fullCompound.setString("Name", player.getCommandSenderName()); - fullCompound.setInteger("CurrentID", currentID); + public Profile(EntityPlayer player) { + this.player = player; + this.currentSlotId = 0; + // Create a default slot. + Slot defaultSlot = new Slot(0, "Default Slot"); + defaultSlot.setLastLoaded(System.currentTimeMillis()); + slots.put(0, defaultSlot); + } - if(!slots.isEmpty()){ - NBTTagCompound slotsCompound = new NBTTagCompound(); - for (HashMap.Entry entry : slots.entrySet()) { - Slot slot = entry.getValue(); - if(slot.isTemporary()) - continue; - int id = entry.getKey(); - slot.setId(id); - NBTTagCompound slotTag = slot.toNBT(); - slotsCompound.setTag(String.valueOf(id), slotTag); - } - fullCompound.setTag("Slots", slotsCompound); + @Override + public IPlayer getPlayer() { + return NoppesUtilServer.getIPlayer(player); + } + + @Override + public int getCurrentSlotId() { + return currentSlotId; + } + + @Override + public Map getSlots() { + return slots; + } + + public boolean isLocked() { + return locked; + } + + public void setLocked(boolean locked) { + this.locked = locked; + } + + @Override + public NBTTagCompound writeToNBT() { + NBTTagCompound compound = new NBTTagCompound(); + if(player != null) + compound.setString("Name", player.getCommandSenderName()); + compound.setInteger("CurrentSlotId", currentSlotId); + NBTTagCompound slotsCompound = new NBTTagCompound(); + for(Map.Entry entry : slots.entrySet()) { + // Save only non-temporary slots. + if(entry.getValue().isTemporary()) + continue; + slotsCompound.setTag(String.valueOf(entry.getKey()), entry.getValue().toNBT()); } - return fullCompound; + compound.setTag("Slots", slotsCompound); + return compound; } } diff --git a/src/main/java/kamkeel/npcs/controllers/data/Slot.java b/src/main/java/kamkeel/npcs/controllers/data/Slot.java index 9b3c5dd97..21e659dfd 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/Slot.java +++ b/src/main/java/kamkeel/npcs/controllers/data/Slot.java @@ -1,74 +1,116 @@ package kamkeel.npcs.controllers.data; +import kamkeel.npcs.controllers.data.ISlot; import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.api.handler.IPlayerData; +import noppes.npcs.controllers.data.PlayerData; -public class Slot { +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +public class Slot implements ISlot { private int id; private String name; private long lastLoaded; - private NBTTagCompound compound; - private boolean temporary = false; + private boolean temporary; + private Map components = new HashMap<>(); public Slot(int id, String name) { this.id = id; this.name = name; } - public Slot(int id, String name, NBTTagCompound compound, long last, boolean temporary) { + public Slot(int id, String name, long lastLoaded, boolean temporary, Map components) { this.id = id; this.name = name; - this.compound = compound; - this.lastLoaded = last; + this.lastLoaded = lastLoaded; this.temporary = temporary; + this.components = components; } - // Getters and setters + @Override public int getId() { return id; } + public void setId(int id) { this.id = id; } + + @Override public String getName() { return name; } + + @Override public void setName(String name) { this.name = name; } + + @Override public long getLastLoaded() { return lastLoaded; } - public void setLastLoaded(long lastLoaded) { - this.lastLoaded = lastLoaded; - } - public NBTTagCompound getCompound() { - return compound; - } - public void setCompound(NBTTagCompound compound) { - this.compound = compound; + + @Override + public void setLastLoaded(long time) { + this.lastLoaded = time; } + + @Override public boolean isTemporary() { return temporary; } + + @Override public void setTemporary(boolean temporary) { this.temporary = temporary; } + @Override + public Map getComponents() { + return components; + } + + @Override + public void setComponentData(String key, NBTTagCompound data) { + components.put(key, data); + } + + @Override + public NBTTagCompound getComponentData(String key) { + return components.get(key); + } + + @Override public NBTTagCompound toNBT() { NBTTagCompound slotNBT = new NBTTagCompound(); slotNBT.setString("Name", name); slotNBT.setLong("LastLoaded", lastLoaded); - slotNBT.setTag("Data", compound); slotNBT.setBoolean("Temporary", temporary); + NBTTagCompound compCompound = new NBTTagCompound(); + for (Map.Entry entry : components.entrySet()) { + compCompound.setTag(entry.getKey(), entry.getValue()); + } + slotNBT.setTag("Components", compCompound); return slotNBT; } public static Slot fromNBT(int id, NBTTagCompound slotNBT) { String name = slotNBT.getString("Name"); long lastLoaded = slotNBT.getLong("LastLoaded"); - NBTTagCompound compound = slotNBT.getCompoundTag("Data"); - boolean temporary = slotNBT.hasKey("Temporary") && slotNBT.getBoolean("Temporary"); - return new Slot(id, name, compound, lastLoaded, temporary); + boolean temporary = slotNBT.getBoolean("Temporary"); + Slot slot = new Slot(id, name); + slot.setLastLoaded(lastLoaded); + slot.setTemporary(temporary); + if (slotNBT.hasKey("Components")) { + NBTTagCompound compCompound = slotNBT.getCompoundTag("Components"); + Set keys = compCompound.func_150296_c(); + for (String key : keys) { + slot.setComponentData(key, compCompound.getCompoundTag(key)); + } + } + return slot; } } diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java index 50ce09dd3..1c9752f59 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java @@ -4,6 +4,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; import kamkeel.npcs.controllers.ProfileController; +import kamkeel.npcs.controllers.data.ISlot; import kamkeel.npcs.controllers.data.InfoEntry; import kamkeel.npcs.controllers.data.Profile; import kamkeel.npcs.controllers.data.Slot; @@ -56,7 +57,7 @@ public final class ProfileGetInfoPacket extends AbstractPacket { NBTTagList slotList = new NBTTagList(); Profile profile = ProfileController.getProfile(player); if(profile != null){ - for(Slot slot : profile.slots.values()){ + for(ISlot slot : profile.getSlots().values()){ NBTTagCompound slotCompound = new NBTTagCompound(); NBTTagList infoList = new NBTTagList(); slotCompound.setInteger("ID", slot.getId()); diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java index c1496caf5..b88dc6189 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java @@ -63,12 +63,12 @@ public final class ProfileRenamePacket extends AbstractPacket { String newName = ByteBufUtils.readString(in); Profile profile = ProfileController.getProfile(player); - if(!profile.slots.containsKey(slot)) { + if(!profile.getSlots().containsKey(slot)) { // TODO: Check Operation and Send Message return; } - ProfileController.getProfile(player).slots.get(slot).setName(newName); + ProfileController.getProfile(player).getSlots().get(slot).setName(newName); ProfileController.save(player, ProfileController.getProfile(player)); ProfileGetPacket.sendProfileNBT(player); diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java index 0d467129d..28ae83cfe 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java @@ -1,5 +1,6 @@ package noppes.npcs.client.gui.player.inventory; +import kamkeel.npcs.controllers.data.ISlot; import kamkeel.npcs.controllers.data.InfoEntry; import kamkeel.npcs.controllers.data.Profile; import kamkeel.npcs.controllers.data.Slot; @@ -321,9 +322,9 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC slot = null; selected = scroll.getSelected(); if (profile != null && selected != null && !selected.isEmpty()){ - for(Slot checkSlot : profile.slots.values()){ + for(ISlot checkSlot : profile.getSlots().values()){ if(checkSlot.getId() == data.get(selected)){ - slot = checkSlot; + slot = (Slot) checkSlot; break; } } @@ -342,9 +343,9 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC this.data = new HashMap<>(); String currentSlot = "\u00A7e"; String otherSlot = "\u00A7f"; - for(Slot slot1 : profile.slots.values()){ + for(ISlot slot1 : profile.getSlots().values()){ String name = slot1.getId() + " - " + slot1.getName(); - if(profile.currentID == slot1.getId()) + if(profile.currentSlotId == slot1.getId()) name = currentSlot + name; else name = otherSlot + name; diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerData.java b/src/main/java/noppes/npcs/controllers/data/PlayerData.java index 982e5b6f3..027d10a24 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerData.java @@ -377,7 +377,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData { public synchronized void save() { // Don't Save this is a Modification of a Profile's PlayerData Profile profile = ProfileController.getProfile(UUID.fromString(uuid)); - if(profile != null && profile.currentID != this.profileSlot){ + if(profile != null && profile.currentSlotId != this.profileSlot){ ProfileController.saveOffline(profile, UUID.fromString(uuid)); return; } From c3538836be6310796a6d3115675e0f0e58bef9dd Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 20 Feb 2025 21:40:39 -0500 Subject: [PATCH 24/59] Optimize Imports --- .../kamkeel/npcs/addon/client/DBCClient.java | 1 - .../npcs/command/CommandKamkeelBase.java | 1 - .../kamkeel/npcs/command/EffectCommand.java | 2 +- .../command/profile/CommandHelpProfile.java | 4 +++- .../command/profile/CommandProfileAdmin.java | 8 ++++++-- .../command/profile/CommandProfileBase.java | 6 ------ .../command/profile/CommandProfileChange.java | 6 ++++-- .../command/profile/CommandProfileCreate.java | 6 ++++-- .../command/profile/CommandProfileList.java | 3 ++- .../command/profile/CommandProfileRegion.java | 7 +++---- .../command/profile/CommandProfileRemove.java | 6 ++++-- .../command/profile/CommandProfileRename.java | 2 +- .../npcs/controllers/ProfileController.java | 3 ++- .../npcs/controllers/SyncController.java | 5 ++--- .../npcs/controllers/data/CNPCData.java | 2 +- .../npcs/controllers/data/IProfileData.java | 1 + .../kamkeel/npcs/controllers/data/ISlot.java | 2 -- .../kamkeel/npcs/controllers/data/Slot.java | 3 --- .../npcs/network/LargeAbstractPacket.java | 1 - .../kamkeel/npcs/network/PacketHandler.java | 7 +------ .../java/kamkeel/npcs/network/PacketUtil.java | 1 - .../network/packets/data/ChatAlertPacket.java | 1 - .../packets/data/large/SyncEffectPacket.java | 2 -- .../packets/player/DialogSelectPacket.java | 2 -- .../packets/player/SaveSignPacket.java | 1 - .../packets/request/TileEntityGetPacket.java | 4 ---- .../request/clone/CloneAllTagsPacket.java | 2 -- .../request/clone/CloneListPacket.java | 4 ---- .../request/clone/CloneTagListPacket.java | 5 ----- .../request/clone/MobSpawnerPacket.java | 6 ------ .../dialog/DialogCategoriesGetPacket.java | 3 --- .../request/dialog/DialogGetPacket.java | 1 - .../request/effects/EffectGetPacket.java | 1 - .../request/faction/FactionsGetPacket.java | 2 -- .../feather/DimensionTeleportPacket.java | 5 ----- .../packets/request/item/ColorSetPacket.java | 5 ++++- .../request/linked/LinkedItemBuildPacket.java | 7 ------- .../mainmenu/MainmenuDisplayGetPacket.java | 1 - .../mainmenu/MainmenuStatsGetPacket.java | 1 - .../request/profile/ProfileCreatePacket.java | 2 -- .../request/profile/ProfileGetInfoPacket.java | 1 - .../request/profile/ProfileGetPacket.java | 9 +++------ .../request/profile/ProfileRemovePacket.java | 1 - .../request/profile/ProfileRenamePacket.java | 3 --- .../quest/QuestCategoriesGetPacket.java | 2 -- .../packets/request/quest/QuestGetPacket.java | 2 -- .../request/quest/QuestRemovePacket.java | 2 -- .../request/quest/QuestsGetPacket.java | 1 - .../packets/request/role/RoleGetPacket.java | 1 - .../request/script/BlockScriptPacket.java | 3 --- .../request/script/ForgeScriptPacket.java | 1 - .../request/script/GlobalNPCScriptPacket.java | 1 - .../request/script/NPCScriptPacket.java | 2 -- .../request/script/PlayerScriptPacket.java | 4 ---- .../request/script/ScriptInfoPacket.java | 4 ---- .../script/item/ItemScriptErrorPacket.java | 3 --- .../request/script/item/ItemScriptPacket.java | 5 ++++- .../script/item/LinkedItemScriptPacket.java | 4 +++- .../packets/request/tags/TagGetPacket.java | 1 - .../packets/request/tags/TagSetPacket.java | 1 - .../transport/TransportSavePacket.java | 4 ---- .../java/kamkeel/npcs/util/ByteBufUtils.java | 2 -- src/main/java/noppes/npcs/EventHooks.java | 1 - .../java/noppes/npcs/NoppesUtilPlayer.java | 2 -- .../java/noppes/npcs/NoppesUtilServer.java | 8 ++++---- .../noppes/npcs/ScriptPlayerEventHandler.java | 1 - .../java/noppes/npcs/ServerEventsHandler.java | 7 ++++--- .../java/noppes/npcs/blocks/BlockLantern.java | 2 +- .../noppes/npcs/blocks/BlockPedestal.java | 2 +- .../java/noppes/npcs/blocks/BlockShelf.java | 2 +- .../noppes/npcs/blocks/BlockShortLamp.java | 1 - .../java/noppes/npcs/blocks/BlockSign.java | 2 +- .../java/noppes/npcs/blocks/BlockStool.java | 2 +- .../java/noppes/npcs/blocks/BlockTable.java | 2 -- .../noppes/npcs/blocks/BlockTallLamp.java | 1 - .../noppes/npcs/blocks/BlockTombstone.java | 2 +- .../noppes/npcs/blocks/BlockWallBanner.java | 1 - .../noppes/npcs/blocks/BlockWeaponRack.java | 2 +- .../npcs/blocks/tiles/TileColorable.java | 3 --- .../npcs/client/ClientCacheHandler.java | 5 ++++- .../npcs/client/ClientEventHandler.java | 7 +++---- .../java/noppes/npcs/client/ClientProxy.java | 3 +-- .../noppes/npcs/client/ClientTickHandler.java | 5 +---- .../java/noppes/npcs/client/NoppesUtil.java | 6 +----- .../controllers/ClientCloneController.java | 1 - .../npcs/client/fx/EntityBigSmokeFX.java | 4 +--- .../npcs/client/gui/GuiBorderBlock.java | 1 - .../noppes/npcs/client/gui/GuiMagicMap.java | 16 ++++++++-------- .../npcs/client/gui/GuiMerchantAdd.java | 2 -- .../client/gui/GuiNPCFactionSelection.java | 3 --- .../npcs/client/gui/GuiNPCLinesEdit.java | 2 -- .../gui/GuiNPCTransportCategoryEdit.java | 2 -- .../npcs/client/gui/GuiNpcDimension.java | 2 -- .../npcs/client/gui/GuiNpcMobSpawner.java | 2 -- .../npcs/client/gui/GuiNpcMobSpawnerAdd.java | 4 ---- .../client/gui/GuiNpcMobSpawnerMounter.java | 2 -- .../client/gui/GuiNpcMobSpawnerSelector.java | 2 -- .../noppes/npcs/client/gui/GuiNpcPather.java | 2 -- .../npcs/client/gui/GuiNpcRedstoneBlock.java | 1 - .../npcs/client/gui/GuiNpcRemoteEditor.java | 2 -- .../npcs/client/gui/GuiNpcWaypoint.java | 1 - .../noppes/npcs/client/gui/GuiScript.java | 3 --- .../npcs/client/gui/SubGuiClonerNPCTags.java | 2 +- .../client/gui/SubGuiMailmanSendSetup.java | 2 -- .../client/gui/SubGuiNpcAvailability.java | 2 -- .../gui/SubGuiNpcAvailabilityDialog.java | 2 -- .../gui/SubGuiNpcAvailabilityQuest.java | 2 -- .../npcs/client/gui/SubGuiNpcDialog.java | 2 -- .../client/gui/SubGuiNpcDialogOption.java | 2 -- .../client/gui/SubGuiNpcDialogVisual.java | 2 -- .../npcs/client/gui/SubGuiNpcDimensions.java | 2 -- .../client/gui/SubGuiNpcFactionOptions.java | 2 -- .../npcs/client/gui/SubGuiNpcQuest.java | 6 ++++-- .../npcs/client/gui/SubGuiPlayerData.java | 6 ++---- .../gui/advanced/GuiNPCAdvancedLinkedNpc.java | 2 -- .../gui/advanced/GuiNPCDialogNpcOptions.java | 2 -- .../gui/advanced/GuiNPCFactionSetup.java | 2 -- .../client/gui/advanced/GuiNPCLinesMenu.java | 2 -- .../npcs/client/gui/advanced/GuiNPCMarks.java | 3 --- .../client/gui/advanced/GuiNPCNightSetup.java | 2 -- .../client/gui/advanced/GuiNPCSoundsMenu.java | 2 -- .../client/gui/advanced/GuiNPCTagSetup.java | 2 +- .../npcs/client/gui/custom/GuiCustom.java | 2 -- .../client/gui/global/GuiNPCManageBanks.java | 2 -- .../gui/global/GuiNPCManageDialogs.java | 2 -- .../gui/global/GuiNPCManageFactions.java | 3 --- .../client/gui/global/GuiNPCManageLinked.java | 5 ----- .../client/gui/global/GuiNPCManageQuest.java | 2 -- .../client/gui/global/GuiNPCManageTags.java | 4 +--- .../gui/global/GuiNPCManageTransporters.java | 2 -- .../gui/global/GuiNpcManagePlayerData.java | 4 ++-- .../gui/global/GuiNpcManageRecipes.java | 2 -- .../gui/global/GuiNpcNaturalSpawns.java | 2 -- .../client/gui/item/SubGuiLinkedItem.java | 5 ----- .../gui/mainmenu/GuiNPCGlobalMainMenu.java | 7 +------ .../npcs/client/gui/mainmenu/GuiNPCInv.java | 2 -- .../npcs/client/gui/mainmenu/GuiNpcAI.java | 2 -- .../client/gui/mainmenu/GuiNpcAdvanced.java | 2 -- .../client/gui/mainmenu/GuiNpcDisplay.java | 2 -- .../npcs/client/gui/mainmenu/GuiNpcStats.java | 2 -- .../client/gui/model/GuiCreationScreen.java | 2 -- .../client/gui/player/GuiAnvilRecipes.java | 19 +++++++++---------- .../npcs/client/gui/player/GuiBigSign.java | 2 -- .../npcs/client/gui/player/GuiBook.java | 2 -- .../npcs/client/gui/player/GuiMailbox.java | 2 -- .../client/gui/player/GuiMailmanWrite.java | 2 -- .../client/gui/player/GuiNpcFollower.java | 2 -- .../client/gui/player/GuiNpcFollowerHire.java | 2 -- .../gui/player/GuiTransportSelection.java | 2 -- .../companion/GuiNpcCompanionStats.java | 2 -- .../companion/GuiNpcCompanionTalents.java | 2 -- .../gui/player/inventory/GuiFaction.java | 2 -- .../client/gui/player/inventory/GuiParty.java | 5 ----- .../gui/player/inventory/GuiProfiles.java | 2 -- .../gui/player/inventory/GuiQuestLog.java | 9 ++++----- .../gui/player/inventory/GuiSettings.java | 3 --- .../gui/questtypes/GuiNpcQuestTypeDialog.java | 2 -- .../gui/questtypes/GuiNpcQuestTypeKill.java | 1 - .../gui/questtypes/GuiNpcQuestTypeManual.java | 1 - .../client/gui/roles/GuiNpcBankSetup.java | 3 --- .../npcs/client/gui/roles/GuiNpcBard.java | 4 ---- .../client/gui/roles/GuiNpcCompanion.java | 2 -- .../client/gui/roles/GuiNpcConversation.java | 3 --- .../client/gui/roles/GuiNpcFollowerJob.java | 3 --- .../client/gui/roles/GuiNpcFollowerSetup.java | 2 -- .../npcs/client/gui/roles/GuiNpcGuard.java | 3 --- .../npcs/client/gui/roles/GuiNpcHealer.java | 3 --- .../client/gui/roles/GuiNpcItemGiver.java | 3 --- .../npcs/client/gui/roles/GuiNpcSpawner.java | 2 -- .../client/gui/roles/GuiNpcTraderSetup.java | 2 -- .../client/gui/roles/GuiNpcTransporter.java | 2 -- .../client/gui/script/GuiScriptAllNPCs.java | 2 -- .../client/gui/script/GuiScriptForge.java | 2 -- .../client/gui/script/GuiScriptGlobal.java | 2 -- .../npcs/client/gui/script/GuiScriptItem.java | 5 ----- .../client/gui/script/GuiScriptPlayers.java | 2 -- .../client/gui/select/GuiSoundSelection.java | 2 -- .../npcs/client/gui/util/GuiCustomScroll.java | 1 - .../npcs/client/gui/util/GuiDiagram.java | 8 +++++--- .../npcs/client/gui/util/GuiEffectBar.java | 13 +++++++------ .../client/gui/util/GuiNPCInterface2.java | 3 --- .../npcs/client/gui/util/GuiNpcMenu.java | 2 -- .../client/gui/util/GuiNpcSquareButton.java | 2 -- .../npcs/client/gui/util/GuiToggleButton.java | 1 - .../model/blocks/barrel/ModelBarrel.java | 1 - .../client/model/util/Model2DRenderer.java | 1 - .../client/renderer/RenderCNPCPlayer.java | 1 - .../renderer/blocks/BlockBeamRenderer.java | 2 +- .../blocks/BlockCarpentryBenchRenderer.java | 3 +-- .../renderer/blocks/BlockLanternRenderer.java | 2 +- .../blocks/BlockScriptedRenderer.java | 5 ++++- .../renderer/blocks/BlockShelfRenderer.java | 2 +- .../blocks/BlockWallBannerRenderer.java | 4 +++- .../renderer/items/ItemBannerRenderer.java | 1 - .../renderer/items/ItemCouchWoolRenderer.java | 4 ++-- .../renderer/items/ItemShortLampRenderer.java | 5 ----- .../renderer/items/ItemTallLampRenderer.java | 1 - .../renderer/items/NpcItemToolRenderer.java | 3 --- .../noppes/npcs/constants/EnumGuiType.java | 6 ------ .../npcs/containers/ContainerAnvilRepair.java | 7 +------ .../controllers/LinkedItemController.java | 4 +++- .../npcs/controllers/ScriptController.java | 6 ++++-- .../npcs/controllers/data/EffectScript.java | 2 -- .../controllers/data/LinkedItemScript.java | 3 --- .../npcs/controllers/data/PlayerEffect.java | 1 - .../controllers/data/PlayerEffectData.java | 1 + .../noppes/npcs/controllers/data/Quest.java | 12 +++++------- .../npcs/controllers/data/RecipeAnvil.java | 1 - .../java/noppes/npcs/quests/QuestManual.java | 1 - .../java/noppes/npcs/scripted/NpcAPI.java | 7 ++++--- .../noppes/npcs/scripted/ScriptWorld.java | 5 ----- .../npcs/scripted/entity/ScriptPlayer.java | 5 ++++- .../npcs/scripted/gui/ScriptGuiItemSlot.java | 3 --- .../npcs/scripted/item/ScriptItemStack.java | 2 -- .../client/tabs/InventoryTabCustomNpc.java | 1 - 215 files changed, 155 insertions(+), 497 deletions(-) diff --git a/src/main/java/kamkeel/npcs/addon/client/DBCClient.java b/src/main/java/kamkeel/npcs/addon/client/DBCClient.java index 7dd94ef6a..9f839936b 100644 --- a/src/main/java/kamkeel/npcs/addon/client/DBCClient.java +++ b/src/main/java/kamkeel/npcs/addon/client/DBCClient.java @@ -2,7 +2,6 @@ package kamkeel.npcs.addon.client; import net.minecraft.entity.EntityLivingBase; import noppes.npcs.client.gui.mainmenu.GuiNpcStats; -import noppes.npcs.client.gui.player.inventory.GuiCNPCInventory; import noppes.npcs.client.gui.util.GuiNPCInterface2; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.entity.EntityNPCInterface; diff --git a/src/main/java/kamkeel/npcs/command/CommandKamkeelBase.java b/src/main/java/kamkeel/npcs/command/CommandKamkeelBase.java index e594603f9..cc874f392 100644 --- a/src/main/java/kamkeel/npcs/command/CommandKamkeelBase.java +++ b/src/main/java/kamkeel/npcs/command/CommandKamkeelBase.java @@ -4,7 +4,6 @@ import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.ChatComponentTranslation; import noppes.npcs.CustomNpcsPermissions; import java.lang.annotation.ElementType; diff --git a/src/main/java/kamkeel/npcs/command/EffectCommand.java b/src/main/java/kamkeel/npcs/command/EffectCommand.java index 5c128a821..054795c44 100644 --- a/src/main/java/kamkeel/npcs/command/EffectCommand.java +++ b/src/main/java/kamkeel/npcs/command/EffectCommand.java @@ -2,8 +2,8 @@ package kamkeel.npcs.command; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; -import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.controllers.CustomEffectController; +import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.controllers.data.CustomEffect; import noppes.npcs.controllers.data.PlayerData; import noppes.npcs.scripted.event.PlayerEvent.EffectEvent.ExpirationType; diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandHelpProfile.java b/src/main/java/kamkeel/npcs/command/profile/CommandHelpProfile.java index 987f4a1b2..a03d30ea0 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandHelpProfile.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandHelpProfile.java @@ -4,11 +4,13 @@ import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ChatComponentTranslation; +import noppes.npcs.CustomNpcsPermissions; + import java.lang.reflect.Method; import java.util.Map.Entry; + import static kamkeel.npcs.util.ColorUtil.sendError; import static kamkeel.npcs.util.ColorUtil.sendMessage; -import noppes.npcs.CustomNpcsPermissions; public class CommandHelpProfile extends CommandProfileBase { private CommandProfile parent; diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java index ec15c643d..ed6001775 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java @@ -1,13 +1,17 @@ package kamkeel.npcs.command.profile; import kamkeel.npcs.controllers.ProfileController; -import kamkeel.npcs.controllers.data.*; -import noppes.npcs.LogWriter; +import kamkeel.npcs.controllers.data.EnumProfileOperation; +import kamkeel.npcs.controllers.data.ISlot; +import kamkeel.npcs.controllers.data.Profile; +import kamkeel.npcs.controllers.data.ProfileOperation; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; + import java.io.File; import java.util.Map; import java.util.UUID; + import static kamkeel.npcs.util.ColorUtil.*; public class CommandProfileAdmin extends CommandProfileBase { diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileBase.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileBase.java index 7cdf0b5c3..71f44a4be 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileBase.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileBase.java @@ -4,10 +4,6 @@ import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.ChatComponentTranslation; -import net.minecraft.util.ChatStyle; -import net.minecraft.util.EnumChatFormatting; import noppes.npcs.CustomNpcsPermissions; import java.lang.annotation.ElementType; @@ -19,8 +15,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public abstract class CommandProfileBase extends CommandBase{ public Map subcommands = new HashMap(); diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java index c0a0c9706..30f5ca0f9 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java @@ -1,12 +1,14 @@ package kamkeel.npcs.command.profile; import kamkeel.npcs.controllers.ProfileController; -import kamkeel.npcs.controllers.data.ProfileOperation; import kamkeel.npcs.controllers.data.EnumProfileOperation; +import kamkeel.npcs.controllers.data.ProfileOperation; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; -import static kamkeel.npcs.util.ColorUtil.*; + +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendResult; public class CommandProfileChange extends CommandProfileBase { diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileCreate.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileCreate.java index 1ca777382..70e6a179a 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileCreate.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileCreate.java @@ -1,12 +1,14 @@ package kamkeel.npcs.command.profile; import kamkeel.npcs.controllers.ProfileController; -import kamkeel.npcs.controllers.data.ProfileOperation; import kamkeel.npcs.controllers.data.EnumProfileOperation; +import kamkeel.npcs.controllers.data.ProfileOperation; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; -import static kamkeel.npcs.util.ColorUtil.*; + +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendResult; public class CommandProfileCreate extends CommandProfileBase { diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java index 8c387ae4d..0e0af6dee 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java @@ -3,11 +3,12 @@ package kamkeel.npcs.command.profile; import kamkeel.npcs.controllers.ProfileController; import kamkeel.npcs.controllers.data.ISlot; import kamkeel.npcs.controllers.data.Profile; -import kamkeel.npcs.controllers.data.Slot; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; + import java.util.Map; + import static kamkeel.npcs.util.ColorUtil.sendError; import static kamkeel.npcs.util.ColorUtil.sendMessage; diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRegion.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRegion.java index 91071f132..24b993d77 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRegion.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRegion.java @@ -1,14 +1,13 @@ package kamkeel.npcs.command.profile; -import noppes.npcs.config.ConfigMain; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; +import noppes.npcs.config.ConfigMain; + import java.util.ArrayList; import java.util.List; -import static kamkeel.npcs.util.ColorUtil.sendError; -import static kamkeel.npcs.util.ColorUtil.sendMessage; -import static kamkeel.npcs.util.ColorUtil.sendResult; +import static kamkeel.npcs.util.ColorUtil.*; public class CommandProfileRegion extends CommandProfileBase { diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java index b5cc04556..892c9e592 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java @@ -1,12 +1,14 @@ package kamkeel.npcs.command.profile; import kamkeel.npcs.controllers.ProfileController; -import kamkeel.npcs.controllers.data.ProfileOperation; import kamkeel.npcs.controllers.data.EnumProfileOperation; +import kamkeel.npcs.controllers.data.ProfileOperation; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; -import static kamkeel.npcs.util.ColorUtil.*; + +import static kamkeel.npcs.util.ColorUtil.sendError; +import static kamkeel.npcs.util.ColorUtil.sendResult; public class CommandProfileRemove extends CommandProfileBase { diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java index 3800bb1e6..f234c1110 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java @@ -4,7 +4,7 @@ import kamkeel.npcs.controllers.ProfileController; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; -import java.util.UUID; + import static kamkeel.npcs.util.ColorUtil.sendError; import static kamkeel.npcs.util.ColorUtil.sendResult; diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index f5065e475..9e3278c4d 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -12,15 +12,16 @@ import noppes.npcs.LogWriter; import noppes.npcs.api.entity.IPlayer; import noppes.npcs.api.handler.IPlayerData; import noppes.npcs.config.ConfigMain; -import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.controllers.data.PlayerData; import noppes.npcs.util.CustomNPCsThreader; import noppes.npcs.util.NBTJsonUtil; + import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.text.SimpleDateFormat; import java.util.*; + import static noppes.npcs.CustomNpcsPermissions.PROFILE_REGION_BYPASS; import static noppes.npcs.CustomNpcsPermissions.hasPermission; diff --git a/src/main/java/kamkeel/npcs/controllers/SyncController.java b/src/main/java/kamkeel/npcs/controllers/SyncController.java index a591a899b..153b79d76 100644 --- a/src/main/java/kamkeel/npcs/controllers/SyncController.java +++ b/src/main/java/kamkeel/npcs/controllers/SyncController.java @@ -4,11 +4,11 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import kamkeel.npcs.addon.DBCAddon; import kamkeel.npcs.network.PacketHandler; +import kamkeel.npcs.network.enums.EnumSyncAction; +import kamkeel.npcs.network.enums.EnumSyncType; import kamkeel.npcs.network.packets.data.LoginPacket; import kamkeel.npcs.network.packets.data.large.SyncEffectPacket; import kamkeel.npcs.network.packets.data.large.SyncPacket; -import kamkeel.npcs.network.enums.EnumSyncAction; -import kamkeel.npcs.network.enums.EnumSyncType; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; @@ -18,7 +18,6 @@ import noppes.npcs.controllers.*; import noppes.npcs.controllers.data.*; import java.util.HashMap; -import java.util.Map; import java.util.concurrent.ConcurrentHashMap; public class SyncController { diff --git a/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java b/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java index 0e65043b1..9da19b00f 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java +++ b/src/main/java/kamkeel/npcs/controllers/data/CNPCData.java @@ -4,8 +4,8 @@ import kamkeel.npcs.controllers.SyncController; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.controllers.PartyController; import noppes.npcs.controllers.data.PlayerData; + import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java b/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java index 846d93acc..b84af3d7d 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java +++ b/src/main/java/kamkeel/npcs/controllers/data/IProfileData.java @@ -2,6 +2,7 @@ package kamkeel.npcs.controllers.data; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; + import java.util.List; public interface IProfileData { diff --git a/src/main/java/kamkeel/npcs/controllers/data/ISlot.java b/src/main/java/kamkeel/npcs/controllers/data/ISlot.java index 2c0601d58..e41f2e60b 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ISlot.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ISlot.java @@ -1,8 +1,6 @@ package kamkeel.npcs.controllers.data; import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.api.handler.IPlayerData; -import noppes.npcs.controllers.data.PlayerData; import java.util.Map; diff --git a/src/main/java/kamkeel/npcs/controllers/data/Slot.java b/src/main/java/kamkeel/npcs/controllers/data/Slot.java index 21e659dfd..cfdc8fcbf 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/Slot.java +++ b/src/main/java/kamkeel/npcs/controllers/data/Slot.java @@ -1,9 +1,6 @@ package kamkeel.npcs.controllers.data; -import kamkeel.npcs.controllers.data.ISlot; import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.api.handler.IPlayerData; -import noppes.npcs.controllers.data.PlayerData; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/kamkeel/npcs/network/LargeAbstractPacket.java b/src/main/java/kamkeel/npcs/network/LargeAbstractPacket.java index 30941b233..c55e391f1 100644 --- a/src/main/java/kamkeel/npcs/network/LargeAbstractPacket.java +++ b/src/main/java/kamkeel/npcs/network/LargeAbstractPacket.java @@ -5,7 +5,6 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import net.minecraft.entity.player.EntityPlayer; import noppes.npcs.LogWriter; -import org.lwjgl.Sys; import java.io.IOException; import java.util.ArrayList; diff --git a/src/main/java/kamkeel/npcs/network/PacketHandler.java b/src/main/java/kamkeel/npcs/network/PacketHandler.java index b1ba1f217..52c73929c 100644 --- a/src/main/java/kamkeel/npcs/network/PacketHandler.java +++ b/src/main/java/kamkeel/npcs/network/PacketHandler.java @@ -53,9 +53,7 @@ import kamkeel.npcs.network.packets.request.npc.*; import kamkeel.npcs.network.packets.request.party.*; import kamkeel.npcs.network.packets.request.pather.MovingPathGetPacket; import kamkeel.npcs.network.packets.request.pather.MovingPathSavePacket; -import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetNamesPacket; -import kamkeel.npcs.network.packets.request.playerdata.PlayerDataMapRegenPacket; -import kamkeel.npcs.network.packets.request.playerdata.PlayerDataRemovePacket; +import kamkeel.npcs.network.packets.request.playerdata.*; import kamkeel.npcs.network.packets.request.profile.*; import kamkeel.npcs.network.packets.request.quest.*; import kamkeel.npcs.network.packets.request.recipe.RecipeGetPacket; @@ -82,9 +80,6 @@ import noppes.npcs.CustomNpcs; import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.LogWriter; import noppes.npcs.NoppesUtilServer; -import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetInfoPacket; -import kamkeel.npcs.network.packets.request.playerdata.PlayerDataRemoveInfoPacket; -import kamkeel.npcs.network.packets.data.PlayerDataInfoPacket; import noppes.npcs.config.ConfigMain; import noppes.npcs.entity.EntityNPCInterface; diff --git a/src/main/java/kamkeel/npcs/network/PacketUtil.java b/src/main/java/kamkeel/npcs/network/PacketUtil.java index 50967d743..684be11d6 100644 --- a/src/main/java/kamkeel/npcs/network/PacketUtil.java +++ b/src/main/java/kamkeel/npcs/network/PacketUtil.java @@ -17,7 +17,6 @@ import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.data.IScriptHandler; import java.io.IOException; -import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; diff --git a/src/main/java/kamkeel/npcs/network/packets/data/ChatAlertPacket.java b/src/main/java/kamkeel/npcs/network/packets/data/ChatAlertPacket.java index fd47a6287..b8c259796 100644 --- a/src/main/java/kamkeel/npcs/network/packets/data/ChatAlertPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/data/ChatAlertPacket.java @@ -11,7 +11,6 @@ import kamkeel.npcs.util.ByteBufUtils; import kamkeel.npcs.util.ColorUtil; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.IChatComponent; import net.minecraft.util.StatCollector; import noppes.npcs.config.ConfigClient; diff --git a/src/main/java/kamkeel/npcs/network/packets/data/large/SyncEffectPacket.java b/src/main/java/kamkeel/npcs/network/packets/data/large/SyncEffectPacket.java index 723df8658..2282be91b 100644 --- a/src/main/java/kamkeel/npcs/network/packets/data/large/SyncEffectPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/data/large/SyncEffectPacket.java @@ -9,8 +9,6 @@ import kamkeel.npcs.network.LargeAbstractPacket; import kamkeel.npcs.network.PacketChannel; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumDataPacket; -import kamkeel.npcs.network.enums.EnumSyncAction; -import kamkeel.npcs.network.enums.EnumSyncType; import kamkeel.npcs.util.ByteBufUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; diff --git a/src/main/java/kamkeel/npcs/network/packets/player/DialogSelectPacket.java b/src/main/java/kamkeel/npcs/network/packets/player/DialogSelectPacket.java index c87f7ae5d..8932b22a0 100644 --- a/src/main/java/kamkeel/npcs/network/packets/player/DialogSelectPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/player/DialogSelectPacket.java @@ -8,8 +8,6 @@ import kamkeel.npcs.network.enums.EnumPlayerPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import noppes.npcs.NoppesUtilPlayer; -import noppes.npcs.NoppesUtilServer; -import noppes.npcs.entity.EntityNPCInterface; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/player/SaveSignPacket.java b/src/main/java/kamkeel/npcs/network/packets/player/SaveSignPacket.java index b00ce42bc..e1c50257e 100644 --- a/src/main/java/kamkeel/npcs/network/packets/player/SaveSignPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/player/SaveSignPacket.java @@ -8,7 +8,6 @@ import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumPlayerPacket; import kamkeel.npcs.util.ByteBufUtils; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import noppes.npcs.blocks.tiles.TileBigSign; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/TileEntityGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/TileEntityGetPacket.java index 280dc89dc..0ef4419a1 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/TileEntityGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/TileEntityGetPacket.java @@ -10,16 +10,12 @@ import kamkeel.npcs.network.PacketUtil; import kamkeel.npcs.network.enums.EnumItemPacketType; import kamkeel.npcs.network.enums.EnumRequestPacket; import kamkeel.npcs.network.packets.data.large.GuiDataPacket; -import kamkeel.npcs.network.packets.data.large.ScrollDataPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.WorldProvider; -import net.minecraftforge.common.DimensionManager; import java.io.IOException; -import java.util.HashMap; public final class TileEntityGetPacket extends AbstractPacket { public static final String packetName = "Request|TileEntityGet"; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/clone/CloneAllTagsPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/clone/CloneAllTagsPacket.java index 6aafe22dc..c593e5097 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/clone/CloneAllTagsPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/clone/CloneAllTagsPacket.java @@ -14,10 +14,8 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import noppes.npcs.controllers.ServerTagMapController; import noppes.npcs.controllers.TagController; import noppes.npcs.controllers.data.Tag; -import noppes.npcs.controllers.data.TagMap; import java.io.IOException; import java.util.HashSet; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/clone/CloneListPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/clone/CloneListPacket.java index 004ae7937..68ba3faba 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/clone/CloneListPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/clone/CloneListPacket.java @@ -1,6 +1,5 @@ package kamkeel.npcs.network.packets.request.clone; -import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; @@ -17,9 +16,6 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagString; -import noppes.npcs.LogWriter; -import noppes.npcs.NoppesUtilServer; -import noppes.npcs.config.ConfigDebug; import noppes.npcs.controllers.ServerCloneController; import noppes.npcs.entity.EntityNPCInterface; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/clone/CloneTagListPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/clone/CloneTagListPacket.java index 312831112..a12a1fe0c 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/clone/CloneTagListPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/clone/CloneTagListPacket.java @@ -10,16 +10,11 @@ import kamkeel.npcs.network.PacketUtil; import kamkeel.npcs.network.enums.EnumItemPacketType; import kamkeel.npcs.network.enums.EnumRequestPacket; import kamkeel.npcs.network.packets.data.large.GuiDataPacket; -import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; -import noppes.npcs.controllers.ServerCloneController; import noppes.npcs.controllers.ServerTagMapController; import noppes.npcs.controllers.data.TagMap; -import noppes.npcs.entity.EntityNPCInterface; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/clone/MobSpawnerPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/clone/MobSpawnerPacket.java index 29ff58063..55720121c 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/clone/MobSpawnerPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/clone/MobSpawnerPacket.java @@ -1,6 +1,5 @@ package kamkeel.npcs.network.packets.request.clone; -import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; @@ -11,18 +10,13 @@ import kamkeel.npcs.network.PacketUtil; import kamkeel.npcs.network.enums.EnumItemPacketType; import kamkeel.npcs.network.enums.EnumRequestPacket; import kamkeel.npcs.util.ByteBufUtils; -import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ChatComponentText; import noppes.npcs.CustomNpcsPermissions; -import noppes.npcs.LogWriter; import noppes.npcs.NoppesUtilServer; -import noppes.npcs.config.ConfigDebug; import noppes.npcs.config.ConfigScript; import noppes.npcs.controllers.ServerCloneController; -import noppes.npcs.entity.EntityNPCInterface; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/dialog/DialogCategoriesGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/dialog/DialogCategoriesGetPacket.java index 1a264fd01..fb9ae8f84 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/dialog/DialogCategoriesGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/dialog/DialogCategoriesGetPacket.java @@ -9,13 +9,10 @@ import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.PacketUtil; import kamkeel.npcs.network.enums.EnumItemPacketType; import kamkeel.npcs.network.enums.EnumRequestPacket; -import kamkeel.npcs.network.packets.data.large.GuiDataPacket; import kamkeel.npcs.network.packets.data.large.ScrollDataPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.controllers.DialogController; -import noppes.npcs.controllers.data.DialogCategory; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/dialog/DialogGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/dialog/DialogGetPacket.java index dfe96e28c..f8787f435 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/dialog/DialogGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/dialog/DialogGetPacket.java @@ -10,7 +10,6 @@ import kamkeel.npcs.network.packets.data.large.GuiDataPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.NoppesUtilServer; import noppes.npcs.controllers.DialogController; import noppes.npcs.controllers.QuestController; import noppes.npcs.controllers.data.Dialog; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/effects/EffectGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/effects/EffectGetPacket.java index 140fc591b..0b9d8613e 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/effects/EffectGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/effects/EffectGetPacket.java @@ -15,7 +15,6 @@ import noppes.npcs.controllers.CustomEffectController; import noppes.npcs.controllers.data.CustomEffect; import java.io.IOException; -import java.util.HashMap; public final class EffectGetPacket extends AbstractPacket { public static final String packetName = "NPC|GetEffect"; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/faction/FactionsGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/faction/FactionsGetPacket.java index 36273b4d3..7f4d90b5e 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/faction/FactionsGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/faction/FactionsGetPacket.java @@ -12,8 +12,6 @@ import kamkeel.npcs.network.enums.EnumRequestPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import noppes.npcs.NoppesUtilServer; -import noppes.npcs.controllers.QuestController; -import noppes.npcs.controllers.data.QuestCategory; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/feather/DimensionTeleportPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/feather/DimensionTeleportPacket.java index 884552595..76215a38c 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/feather/DimensionTeleportPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/feather/DimensionTeleportPacket.java @@ -9,17 +9,12 @@ import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.PacketUtil; import kamkeel.npcs.network.enums.EnumItemPacketType; import kamkeel.npcs.network.enums.EnumRequestPacket; -import kamkeel.npcs.network.packets.data.large.GuiDataPacket; -import kamkeel.npcs.util.ByteBufUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.MinecraftServer; import net.minecraft.util.ChunkCoordinates; import net.minecraft.world.WorldServer; -import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.NoppesUtilPlayer; -import noppes.npcs.controllers.ServerCloneController; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/item/ColorSetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/item/ColorSetPacket.java index aafac6830..0d3529137 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/item/ColorSetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/item/ColorSetPacket.java @@ -3,7 +3,10 @@ package kamkeel.npcs.network.packets.request.item; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; -import kamkeel.npcs.network.*; +import kamkeel.npcs.network.AbstractPacket; +import kamkeel.npcs.network.PacketChannel; +import kamkeel.npcs.network.PacketHandler; +import kamkeel.npcs.network.PacketUtil; import kamkeel.npcs.network.enums.EnumItemPacketType; import kamkeel.npcs.network.enums.EnumRequestPacket; import net.minecraft.entity.player.EntityPlayer; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/linked/LinkedItemBuildPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/linked/LinkedItemBuildPacket.java index bb54cc529..b72ea1b0c 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/linked/LinkedItemBuildPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/linked/LinkedItemBuildPacket.java @@ -9,18 +9,11 @@ import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.PacketUtil; import kamkeel.npcs.network.enums.EnumItemPacketType; import kamkeel.npcs.network.enums.EnumRequestPacket; -import kamkeel.npcs.util.ByteBufUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.CustomItems; import noppes.npcs.CustomNpcsPermissions; -import noppes.npcs.NoppesUtilServer; import noppes.npcs.controllers.LinkedItemController; import noppes.npcs.controllers.data.LinkedItem; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.item.ScriptLinkedItem; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/mainmenu/MainmenuDisplayGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/mainmenu/MainmenuDisplayGetPacket.java index c286b37e2..c0e658dec 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/mainmenu/MainmenuDisplayGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/mainmenu/MainmenuDisplayGetPacket.java @@ -13,7 +13,6 @@ import kamkeel.npcs.network.packets.data.large.GuiDataPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.CustomNpcsPermissions; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/mainmenu/MainmenuStatsGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/mainmenu/MainmenuStatsGetPacket.java index 4b0ab51ed..1c0165164 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/mainmenu/MainmenuStatsGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/mainmenu/MainmenuStatsGetPacket.java @@ -13,7 +13,6 @@ import kamkeel.npcs.network.packets.data.large.GuiDataPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.CustomNpcsPermissions; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java index 102bb026d..611546e06 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java @@ -10,10 +10,8 @@ import kamkeel.npcs.network.AbstractPacket; import kamkeel.npcs.network.PacketChannel; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumRequestPacket; -import kamkeel.npcs.network.packets.data.large.GuiDataPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.CustomNpcsPermissions; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java index 1c9752f59..81808afe3 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java @@ -7,7 +7,6 @@ import kamkeel.npcs.controllers.ProfileController; import kamkeel.npcs.controllers.data.ISlot; import kamkeel.npcs.controllers.data.InfoEntry; import kamkeel.npcs.controllers.data.Profile; -import kamkeel.npcs.controllers.data.Slot; import kamkeel.npcs.network.AbstractPacket; import kamkeel.npcs.network.PacketChannel; import kamkeel.npcs.network.PacketHandler; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java index e86204acf..d03849b83 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java @@ -5,17 +5,14 @@ import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; import kamkeel.npcs.controllers.ProfileController; import kamkeel.npcs.controllers.data.Profile; -import kamkeel.npcs.network.*; -import kamkeel.npcs.network.enums.EnumItemPacketType; +import kamkeel.npcs.network.AbstractPacket; +import kamkeel.npcs.network.PacketChannel; +import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumRequestPacket; import kamkeel.npcs.network.packets.data.large.GuiDataPacket; -import kamkeel.npcs.util.ByteBufUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.controllers.LinkedItemController; -import noppes.npcs.controllers.LinkedNpcController; -import noppes.npcs.controllers.data.LinkedItem; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java index ed98fae19..d7ae74c8c 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java @@ -4,7 +4,6 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; import kamkeel.npcs.controllers.ProfileController; -import kamkeel.npcs.controllers.data.Profile; import kamkeel.npcs.controllers.data.ProfileOperation; import kamkeel.npcs.network.AbstractPacket; import kamkeel.npcs.network.PacketChannel; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java index b88dc6189..945726b49 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java @@ -5,7 +5,6 @@ import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; import kamkeel.npcs.controllers.ProfileController; import kamkeel.npcs.controllers.data.Profile; -import kamkeel.npcs.controllers.data.ProfileOperation; import kamkeel.npcs.network.AbstractPacket; import kamkeel.npcs.network.PacketChannel; import kamkeel.npcs.network.PacketHandler; @@ -17,8 +16,6 @@ import noppes.npcs.CustomNpcsPermissions; import java.io.IOException; -import static kamkeel.npcs.util.ColorUtil.sendError; - public final class ProfileRenamePacket extends AbstractPacket { public static String packetName = "Request|ProfileRename"; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/quest/QuestCategoriesGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/quest/QuestCategoriesGetPacket.java index 12ed56a54..c276bfb1f 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/quest/QuestCategoriesGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/quest/QuestCategoriesGetPacket.java @@ -9,11 +9,9 @@ import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.PacketUtil; import kamkeel.npcs.network.enums.EnumItemPacketType; import kamkeel.npcs.network.enums.EnumRequestPacket; -import kamkeel.npcs.network.packets.data.large.ScrollDataPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import noppes.npcs.NoppesUtilServer; -import noppes.npcs.controllers.DialogController; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/quest/QuestGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/quest/QuestGetPacket.java index e3f9119d4..bb236af33 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/quest/QuestGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/quest/QuestGetPacket.java @@ -10,9 +10,7 @@ import kamkeel.npcs.network.packets.data.large.GuiDataPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.controllers.DialogController; import noppes.npcs.controllers.QuestController; -import noppes.npcs.controllers.data.Dialog; import noppes.npcs.controllers.data.Quest; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/quest/QuestRemovePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/quest/QuestRemovePacket.java index 55ca84f39..199be0063 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/quest/QuestRemovePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/quest/QuestRemovePacket.java @@ -13,9 +13,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.NoppesUtilServer; -import noppes.npcs.controllers.DialogController; import noppes.npcs.controllers.QuestController; -import noppes.npcs.controllers.data.Dialog; import noppes.npcs.controllers.data.Quest; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/quest/QuestsGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/quest/QuestsGetPacket.java index 29fc59194..500be2d03 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/quest/QuestsGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/quest/QuestsGetPacket.java @@ -12,7 +12,6 @@ import kamkeel.npcs.network.enums.EnumRequestPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import noppes.npcs.NoppesUtilServer; -import noppes.npcs.controllers.DialogController; import noppes.npcs.controllers.QuestController; import noppes.npcs.controllers.data.QuestCategory; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/role/RoleGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/role/RoleGetPacket.java index 11f6e0037..c7bb7da2d 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/role/RoleGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/role/RoleGetPacket.java @@ -13,7 +13,6 @@ import kamkeel.npcs.network.packets.data.large.GuiDataPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.CustomNpcsPermissions; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/script/BlockScriptPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/script/BlockScriptPacket.java index 1b9fcb81d..e354a611c 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/script/BlockScriptPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/script/BlockScriptPacket.java @@ -18,9 +18,6 @@ import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.blocks.tiles.TileScripted; import noppes.npcs.config.ConfigScript; import noppes.npcs.controllers.ScriptController; -import noppes.npcs.controllers.data.PlayerDataScript; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.item.ScriptCustomItem; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/script/ForgeScriptPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/script/ForgeScriptPacket.java index 02ab27097..cb0fe7894 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/script/ForgeScriptPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/script/ForgeScriptPacket.java @@ -15,7 +15,6 @@ import noppes.npcs.config.ConfigScript; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.data.ForgeDataScript; import noppes.npcs.controllers.data.IScriptHandler; -import noppes.npcs.controllers.data.PlayerDataScript; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/script/GlobalNPCScriptPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/script/GlobalNPCScriptPacket.java index a34cbb1fa..70ecfecd4 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/script/GlobalNPCScriptPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/script/GlobalNPCScriptPacket.java @@ -13,7 +13,6 @@ import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.config.ConfigScript; import noppes.npcs.controllers.ScriptController; -import noppes.npcs.controllers.data.ForgeDataScript; import noppes.npcs.controllers.data.GlobalNPCDataScript; import noppes.npcs.controllers.data.IScriptHandler; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/script/NPCScriptPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/script/NPCScriptPacket.java index fc6073fbb..31eb1768e 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/script/NPCScriptPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/script/NPCScriptPacket.java @@ -17,8 +17,6 @@ import noppes.npcs.LogWriter; import noppes.npcs.config.ConfigDebug; import noppes.npcs.config.ConfigScript; import noppes.npcs.controllers.ScriptController; -import noppes.npcs.controllers.data.GlobalNPCDataScript; -import noppes.npcs.controllers.data.IScriptHandler; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/script/PlayerScriptPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/script/PlayerScriptPacket.java index ec57a2d25..eadaab2b1 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/script/PlayerScriptPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/script/PlayerScriptPacket.java @@ -1,6 +1,5 @@ package kamkeel.npcs.network.packets.request.script; -import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; @@ -12,11 +11,8 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.CustomNpcsPermissions; -import noppes.npcs.LogWriter; -import noppes.npcs.config.ConfigDebug; import noppes.npcs.config.ConfigScript; import noppes.npcs.controllers.ScriptController; -import noppes.npcs.controllers.data.DataScript; import noppes.npcs.controllers.data.IScriptHandler; import noppes.npcs.controllers.data.PlayerDataScript; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/script/ScriptInfoPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/script/ScriptInfoPacket.java index c4bfbfa8b..d97ee13b8 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/script/ScriptInfoPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/script/ScriptInfoPacket.java @@ -1,6 +1,5 @@ package kamkeel.npcs.network.packets.request.script; -import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; @@ -13,10 +12,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.CustomNpcsPermissions; -import noppes.npcs.LogWriter; -import noppes.npcs.config.ConfigDebug; import noppes.npcs.config.ConfigScript; -import noppes.npcs.controllers.ScriptController; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/script/item/ItemScriptErrorPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/script/item/ItemScriptErrorPacket.java index c40417a41..697e54f87 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/script/item/ItemScriptErrorPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/script/item/ItemScriptErrorPacket.java @@ -9,17 +9,14 @@ import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumRequestPacket; import kamkeel.npcs.network.packets.data.large.GuiDataPacket; -import kamkeel.npcs.util.ByteBufUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.NBTTags; import noppes.npcs.api.item.IItemStack; -import noppes.npcs.client.gui.script.GuiScriptItem; import noppes.npcs.config.ConfigScript; import noppes.npcs.controllers.ScriptContainer; -import noppes.npcs.controllers.ScriptController; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.item.ScriptCustomItem; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/script/item/ItemScriptPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/script/item/ItemScriptPacket.java index bc66d732f..aa60d90b1 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/script/item/ItemScriptPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/script/item/ItemScriptPacket.java @@ -3,7 +3,10 @@ package kamkeel.npcs.network.packets.request.script.item; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; -import kamkeel.npcs.network.*; +import kamkeel.npcs.network.AbstractPacket; +import kamkeel.npcs.network.PacketChannel; +import kamkeel.npcs.network.PacketClient; +import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumRequestPacket; import kamkeel.npcs.network.packets.data.large.GuiDataPacket; import kamkeel.npcs.util.ByteBufUtils; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/script/item/LinkedItemScriptPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/script/item/LinkedItemScriptPacket.java index b01f2adc5..98a1927f6 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/script/item/LinkedItemScriptPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/script/item/LinkedItemScriptPacket.java @@ -15,7 +15,9 @@ import noppes.npcs.LogWriter; import noppes.npcs.config.ConfigDebug; import noppes.npcs.config.ConfigScript; import noppes.npcs.controllers.LinkedItemController; -import noppes.npcs.controllers.data.*; +import noppes.npcs.controllers.data.IScriptHandler; +import noppes.npcs.controllers.data.LinkedItem; +import noppes.npcs.controllers.data.LinkedItemScript; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/tags/TagGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/tags/TagGetPacket.java index 74a2561dc..29bfce39c 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/tags/TagGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/tags/TagGetPacket.java @@ -13,7 +13,6 @@ import kamkeel.npcs.network.packets.data.large.GuiDataPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.NoppesUtilServer; import noppes.npcs.controllers.TagController; import noppes.npcs.controllers.data.Tag; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/tags/TagSetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/tags/TagSetPacket.java index e28190fa1..2c49aae9c 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/tags/TagSetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/tags/TagSetPacket.java @@ -16,7 +16,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.controllers.TagController; -import noppes.npcs.controllers.data.Tag; import noppes.npcs.entity.EntityNPCInterface; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/transport/TransportSavePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/transport/TransportSavePacket.java index 6fe84ed05..119145e72 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/transport/TransportSavePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/transport/TransportSavePacket.java @@ -9,18 +9,14 @@ import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.PacketUtil; import kamkeel.npcs.network.enums.EnumItemPacketType; import kamkeel.npcs.network.enums.EnumRequestPacket; -import kamkeel.npcs.network.packets.data.large.GuiDataPacket; import kamkeel.npcs.util.ByteBufUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.CustomNpcsPermissions; -import noppes.npcs.constants.EnumJobType; import noppes.npcs.constants.EnumRoleType; -import noppes.npcs.controllers.ServerCloneController; import noppes.npcs.controllers.TransportController; import noppes.npcs.controllers.data.TransportLocation; -import noppes.npcs.roles.JobSpawner; import noppes.npcs.roles.RoleTransporter; import java.io.IOException; diff --git a/src/main/java/kamkeel/npcs/util/ByteBufUtils.java b/src/main/java/kamkeel/npcs/util/ByteBufUtils.java index 225327935..86ad378d8 100644 --- a/src/main/java/kamkeel/npcs/util/ByteBufUtils.java +++ b/src/main/java/kamkeel/npcs/util/ByteBufUtils.java @@ -7,10 +7,8 @@ import net.minecraft.nbt.NBTSizeTracker; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.village.MerchantRecipeList; -import noppes.npcs.LogWriter; import java.io.IOException; -import java.util.Arrays; import java.util.List; import java.util.Map; diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 913a2a5a0..465fa1f47 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -17,7 +17,6 @@ import net.minecraftforge.event.world.WorldEvent; import noppes.npcs.api.IWorld; import noppes.npcs.api.entity.*; import noppes.npcs.api.event.IAnimationEvent; -import noppes.npcs.api.event.IItemEvent; import noppes.npcs.api.gui.ICustomGui; import noppes.npcs.api.gui.IItemSlot; import noppes.npcs.api.handler.data.IAnimation; diff --git a/src/main/java/noppes/npcs/NoppesUtilPlayer.java b/src/main/java/noppes/npcs/NoppesUtilPlayer.java index 2f364de8f..26b5f5f73 100644 --- a/src/main/java/noppes/npcs/NoppesUtilPlayer.java +++ b/src/main/java/noppes/npcs/NoppesUtilPlayer.java @@ -1,8 +1,6 @@ package noppes.npcs; -import cpw.mods.fml.common.network.internal.FMLProxyPacket; import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumSoundOperation; import kamkeel.npcs.network.packets.data.*; diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index fcba2b7ff..41ae71b34 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -3,20 +3,20 @@ package noppes.npcs; import io.netty.buffer.ByteBuf; import kamkeel.npcs.controllers.SyncController; import kamkeel.npcs.network.PacketHandler; +import kamkeel.npcs.network.packets.data.ParticlePacket; import kamkeel.npcs.network.packets.data.PlayerDataInfoPacket; import kamkeel.npcs.network.packets.data.gui.GuiClosePacket; import kamkeel.npcs.network.packets.data.gui.GuiErrorPacket; import kamkeel.npcs.network.packets.data.gui.GuiOpenPacket; +import kamkeel.npcs.network.packets.data.gui.GuiTeleporterPacket; import kamkeel.npcs.network.packets.data.large.GuiDataPacket; import kamkeel.npcs.network.packets.data.large.ScrollDataPacket; import kamkeel.npcs.network.packets.data.large.ScrollListPacket; -import kamkeel.npcs.network.packets.data.npc.DialogPacket; -import kamkeel.npcs.network.packets.data.ParticlePacket; -import kamkeel.npcs.network.packets.data.script.ScriptedParticlePacket; import kamkeel.npcs.network.packets.data.npc.DeleteNpcPacket; +import kamkeel.npcs.network.packets.data.npc.DialogPacket; import kamkeel.npcs.network.packets.data.npc.EditNpcPacket; import kamkeel.npcs.network.packets.data.npc.RolePacket; -import kamkeel.npcs.network.packets.data.gui.GuiTeleporterPacket; +import kamkeel.npcs.network.packets.data.script.ScriptedParticlePacket; import kamkeel.npcs.util.ByteBufUtils; import net.minecraft.command.server.CommandBlockLogic; import net.minecraft.entity.Entity; diff --git a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java index 0c4dab046..b2e7e984c 100644 --- a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java @@ -32,7 +32,6 @@ import noppes.npcs.controllers.data.*; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.quests.QuestItem; import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.item.ScriptCustomItem; import static noppes.npcs.config.ConfigMain.TrackedQuestUpdateFrequency; diff --git a/src/main/java/noppes/npcs/ServerEventsHandler.java b/src/main/java/noppes/npcs/ServerEventsHandler.java index 2e61e2624..ebccd424d 100644 --- a/src/main/java/noppes/npcs/ServerEventsHandler.java +++ b/src/main/java/noppes/npcs/ServerEventsHandler.java @@ -22,7 +22,6 @@ import net.minecraft.entity.passive.EntityVillager; 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.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.MinecraftServer; @@ -41,10 +40,12 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; import net.minecraftforge.event.terraingen.PopulateChunkEvent; import noppes.npcs.blocks.tiles.ITileIcon; -import noppes.npcs.blocks.tiles.TileBanner; import noppes.npcs.config.ConfigDebug; import noppes.npcs.config.ConfigMain; -import noppes.npcs.constants.*; +import noppes.npcs.constants.EnumGuiType; +import noppes.npcs.constants.EnumPartyObjectives; +import noppes.npcs.constants.EnumQuestType; +import noppes.npcs.constants.EnumRoleType; import noppes.npcs.controllers.PartyController; import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.controllers.ServerCloneController; diff --git a/src/main/java/noppes/npcs/blocks/BlockLantern.java b/src/main/java/noppes/npcs/blocks/BlockLantern.java index 6be362b7c..fa7db3c4f 100644 --- a/src/main/java/noppes/npcs/blocks/BlockLantern.java +++ b/src/main/java/noppes/npcs/blocks/BlockLantern.java @@ -10,8 +10,8 @@ import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import noppes.npcs.CustomItems; -import noppes.npcs.blocks.tiles.TileVariant; import noppes.npcs.blocks.tiles.TileLamp; +import noppes.npcs.blocks.tiles.TileVariant; public class BlockLantern extends BlockLightable{ diff --git a/src/main/java/noppes/npcs/blocks/BlockPedestal.java b/src/main/java/noppes/npcs/blocks/BlockPedestal.java index 03ba7bd1e..06b907a09 100644 --- a/src/main/java/noppes/npcs/blocks/BlockPedestal.java +++ b/src/main/java/noppes/npcs/blocks/BlockPedestal.java @@ -14,9 +14,9 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import noppes.npcs.blocks.tiles.TileVariant; import noppes.npcs.blocks.tiles.TileNpcContainer; import noppes.npcs.blocks.tiles.TilePedestal; +import noppes.npcs.blocks.tiles.TileVariant; import java.util.List; diff --git a/src/main/java/noppes/npcs/blocks/BlockShelf.java b/src/main/java/noppes/npcs/blocks/BlockShelf.java index ee0a8e4ca..1fda4c516 100644 --- a/src/main/java/noppes/npcs/blocks/BlockShelf.java +++ b/src/main/java/noppes/npcs/blocks/BlockShelf.java @@ -9,8 +9,8 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import noppes.npcs.blocks.tiles.TileVariant; import noppes.npcs.blocks.tiles.TileShelf; +import noppes.npcs.blocks.tiles.TileVariant; import java.util.List; diff --git a/src/main/java/noppes/npcs/blocks/BlockShortLamp.java b/src/main/java/noppes/npcs/blocks/BlockShortLamp.java index f1a483610..0e2a8480b 100644 --- a/src/main/java/noppes/npcs/blocks/BlockShortLamp.java +++ b/src/main/java/noppes/npcs/blocks/BlockShortLamp.java @@ -23,7 +23,6 @@ import net.minecraft.world.World; import noppes.npcs.NoppesUtilServer; import noppes.npcs.blocks.tiles.TileColorable; import noppes.npcs.blocks.tiles.TileShortLamp; -import noppes.npcs.blocks.tiles.TileTallLamp; import java.util.List; diff --git a/src/main/java/noppes/npcs/blocks/BlockSign.java b/src/main/java/noppes/npcs/blocks/BlockSign.java index 8d5af1e2d..2233f6bc1 100644 --- a/src/main/java/noppes/npcs/blocks/BlockSign.java +++ b/src/main/java/noppes/npcs/blocks/BlockSign.java @@ -12,8 +12,8 @@ import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import noppes.npcs.blocks.tiles.TileBanner; -import noppes.npcs.blocks.tiles.TileVariant; import noppes.npcs.blocks.tiles.TileSign; +import noppes.npcs.blocks.tiles.TileVariant; import java.util.List; diff --git a/src/main/java/noppes/npcs/blocks/BlockStool.java b/src/main/java/noppes/npcs/blocks/BlockStool.java index a5d426200..45314103f 100644 --- a/src/main/java/noppes/npcs/blocks/BlockStool.java +++ b/src/main/java/noppes/npcs/blocks/BlockStool.java @@ -16,8 +16,8 @@ import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.world.World; -import noppes.npcs.blocks.tiles.TileVariant; import noppes.npcs.blocks.tiles.TileStool; +import noppes.npcs.blocks.tiles.TileVariant; import java.util.List; diff --git a/src/main/java/noppes/npcs/blocks/BlockTable.java b/src/main/java/noppes/npcs/blocks/BlockTable.java index 2c49f08a5..1169bc49b 100644 --- a/src/main/java/noppes/npcs/blocks/BlockTable.java +++ b/src/main/java/noppes/npcs/blocks/BlockTable.java @@ -1,13 +1,11 @@ package noppes.npcs.blocks; -import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import noppes.npcs.blocks.tiles.TileTable; diff --git a/src/main/java/noppes/npcs/blocks/BlockTallLamp.java b/src/main/java/noppes/npcs/blocks/BlockTallLamp.java index 9c5badea1..96bb0314a 100644 --- a/src/main/java/noppes/npcs/blocks/BlockTallLamp.java +++ b/src/main/java/noppes/npcs/blocks/BlockTallLamp.java @@ -21,7 +21,6 @@ import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import noppes.npcs.NoppesUtilServer; -import noppes.npcs.blocks.tiles.TileBanner; import noppes.npcs.blocks.tiles.TileColorable; import noppes.npcs.blocks.tiles.TileTallLamp; diff --git a/src/main/java/noppes/npcs/blocks/BlockTombstone.java b/src/main/java/noppes/npcs/blocks/BlockTombstone.java index 58ef784c1..987761666 100644 --- a/src/main/java/noppes/npcs/blocks/BlockTombstone.java +++ b/src/main/java/noppes/npcs/blocks/BlockTombstone.java @@ -22,8 +22,8 @@ import noppes.npcs.CustomNpcs; import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.NoppesUtilServer; import noppes.npcs.blocks.tiles.TileBigSign; -import noppes.npcs.blocks.tiles.TileVariant; import noppes.npcs.blocks.tiles.TileTombstone; +import noppes.npcs.blocks.tiles.TileVariant; import noppes.npcs.constants.EnumGuiType; import java.util.List; diff --git a/src/main/java/noppes/npcs/blocks/BlockWallBanner.java b/src/main/java/noppes/npcs/blocks/BlockWallBanner.java index 165524e60..f219da7b2 100644 --- a/src/main/java/noppes/npcs/blocks/BlockWallBanner.java +++ b/src/main/java/noppes/npcs/blocks/BlockWallBanner.java @@ -18,7 +18,6 @@ import net.minecraft.util.*; import net.minecraft.world.World; import noppes.npcs.NoppesUtilServer; import noppes.npcs.blocks.tiles.TileColorable; -import noppes.npcs.blocks.tiles.TileCouchWool; import noppes.npcs.blocks.tiles.TileWallBanner; import java.util.List; diff --git a/src/main/java/noppes/npcs/blocks/BlockWeaponRack.java b/src/main/java/noppes/npcs/blocks/BlockWeaponRack.java index b18efc5a5..41554f83a 100644 --- a/src/main/java/noppes/npcs/blocks/BlockWeaponRack.java +++ b/src/main/java/noppes/npcs/blocks/BlockWeaponRack.java @@ -13,8 +13,8 @@ import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import noppes.npcs.blocks.tiles.TileVariant; import noppes.npcs.blocks.tiles.TileNpcContainer; +import noppes.npcs.blocks.tiles.TileVariant; import noppes.npcs.blocks.tiles.TileWeaponRack; import java.util.List; diff --git a/src/main/java/noppes/npcs/blocks/tiles/TileColorable.java b/src/main/java/noppes/npcs/blocks/tiles/TileColorable.java index 2f1d7f978..e85efd0b5 100644 --- a/src/main/java/noppes/npcs/blocks/tiles/TileColorable.java +++ b/src/main/java/noppes/npcs/blocks/tiles/TileColorable.java @@ -1,11 +1,8 @@ package noppes.npcs.blocks.tiles; -import net.minecraft.block.BlockColored; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.NoppesUtilServer; import noppes.npcs.items.ItemNpcTool; import static noppes.npcs.items.ItemNpcTool.BRUSH_COLOR_TAG; diff --git a/src/main/java/noppes/npcs/client/ClientCacheHandler.java b/src/main/java/noppes/npcs/client/ClientCacheHandler.java index a51986c5d..e4771c4e3 100644 --- a/src/main/java/noppes/npcs/client/ClientCacheHandler.java +++ b/src/main/java/noppes/npcs/client/ClientCacheHandler.java @@ -7,7 +7,10 @@ import noppes.npcs.client.gui.select.GuiSoundSelection; import noppes.npcs.client.gui.select.GuiTextureSelection; import noppes.npcs.client.renderer.ImageData; import noppes.npcs.config.ConfigClient; -import noppes.npcs.controllers.data.*; +import noppes.npcs.controllers.data.AnimationData; +import noppes.npcs.controllers.data.Party; +import noppes.npcs.controllers.data.PlayerData; +import noppes.npcs.controllers.data.SkinOverlay; import noppes.npcs.util.CacheHashMap; import java.util.HashMap; diff --git a/src/main/java/noppes/npcs/client/ClientEventHandler.java b/src/main/java/noppes/npcs/client/ClientEventHandler.java index 359745ac6..e142c5286 100644 --- a/src/main/java/noppes/npcs/client/ClientEventHandler.java +++ b/src/main/java/noppes/npcs/client/ClientEventHandler.java @@ -1,9 +1,7 @@ package noppes.npcs.client; -import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.EventPriority; import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.relauncher.Side; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.entity.EntityClientPlayerMP; @@ -17,13 +15,14 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.*; -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.*; +import noppes.npcs.controllers.data.FramePart; +import noppes.npcs.controllers.data.MarkData; +import noppes.npcs.controllers.data.PlayerData; import noppes.npcs.entity.EntityNPCInterface; import java.lang.reflect.Field; diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index 75e0a3e12..63bdaa45b 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -21,7 +21,6 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.item.Item; -import net.minecraft.item.ItemTool; import net.minecraft.stats.Achievement; import net.minecraft.util.ChatComponentText; import net.minecraft.util.ReportedException; @@ -69,8 +68,8 @@ import noppes.npcs.controllers.data.PlayerData; import noppes.npcs.entity.*; import noppes.npcs.entity.data.ModelData; import noppes.npcs.entity.data.ModelPartData; -import noppes.npcs.items.ItemNpcTool; import noppes.npcs.items.ItemLinked; +import noppes.npcs.items.ItemNpcTool; import noppes.npcs.items.ItemScripted; import org.lwjgl.input.Keyboard; import tconstruct.client.tabs.InventoryTabCustomNpc; diff --git a/src/main/java/noppes/npcs/client/ClientTickHandler.java b/src/main/java/noppes/npcs/client/ClientTickHandler.java index 7c9e627e6..33e979c89 100644 --- a/src/main/java/noppes/npcs/client/ClientTickHandler.java +++ b/src/main/java/noppes/npcs/client/ClientTickHandler.java @@ -5,7 +5,6 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.InputEvent; import cpw.mods.fml.common.gameevent.TickEvent; import cpw.mods.fml.common.gameevent.TickEvent.Phase; -import kamkeel.npcs.addon.client.DBCClient; import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.player.CheckPlayerValue; import kamkeel.npcs.network.packets.player.InputDevicePacket; @@ -15,12 +14,10 @@ import net.minecraft.entity.Entity; import net.minecraft.inventory.ContainerPlayer; import net.minecraft.world.World; import noppes.npcs.CustomNpcs; -import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.client.controllers.MusicController; import noppes.npcs.client.controllers.ScriptSoundController; -import noppes.npcs.client.gui.player.inventory.*; +import noppes.npcs.client.gui.player.inventory.GuiCNPCInventory; import noppes.npcs.client.renderer.RenderNPCInterface; -import noppes.npcs.constants.EnumPlayerPacket; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import tconstruct.client.tabs.InventoryTabCustomNpc; diff --git a/src/main/java/noppes/npcs/client/NoppesUtil.java b/src/main/java/noppes/npcs/client/NoppesUtil.java index cc07e9d47..4ac30d82c 100644 --- a/src/main/java/noppes/npcs/client/NoppesUtil.java +++ b/src/main/java/noppes/npcs/client/NoppesUtil.java @@ -17,11 +17,7 @@ import net.minecraft.util.Util; import noppes.npcs.CustomNpcs; import noppes.npcs.client.gui.player.GuiDialogInteract; import noppes.npcs.client.gui.player.GuiQuestCompletion; -import noppes.npcs.client.gui.util.IPlayerDataInfo; -import noppes.npcs.client.gui.util.GuiContainerNPCInterface; -import noppes.npcs.client.gui.util.GuiNPCInterface; -import noppes.npcs.client.gui.util.IScrollData; -import noppes.npcs.client.gui.util.IScrollGroup; +import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumGuiType; import noppes.npcs.controllers.data.Dialog; import noppes.npcs.controllers.data.Quest; diff --git a/src/main/java/noppes/npcs/client/controllers/ClientCloneController.java b/src/main/java/noppes/npcs/client/controllers/ClientCloneController.java index 505c02173..bfce34457 100644 --- a/src/main/java/noppes/npcs/client/controllers/ClientCloneController.java +++ b/src/main/java/noppes/npcs/client/controllers/ClientCloneController.java @@ -4,7 +4,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import noppes.npcs.CustomNpcs; import noppes.npcs.controllers.ServerCloneController; -import noppes.npcs.controllers.ServerTagMapController; import noppes.npcs.controllers.data.TagMap; import java.io.File; diff --git a/src/main/java/noppes/npcs/client/fx/EntityBigSmokeFX.java b/src/main/java/noppes/npcs/client/fx/EntityBigSmokeFX.java index c645c637e..18942eee7 100644 --- a/src/main/java/noppes/npcs/client/fx/EntityBigSmokeFX.java +++ b/src/main/java/noppes/npcs/client/fx/EntityBigSmokeFX.java @@ -1,7 +1,5 @@ package noppes.npcs.client.fx; -import org.lwjgl.opengl.GL11; - import cpw.mods.fml.common.eventhandler.Cancelable; import cpw.mods.fml.relauncher.Side; import net.minecraft.client.Minecraft; @@ -10,12 +8,12 @@ import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.entity.EntityLivingBase; -import net.minecraft.init.Blocks; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.EntityEvent.EntityConstructing; +import org.lwjgl.opengl.GL11; public class EntityBigSmokeFX extends EntityFX { diff --git a/src/main/java/noppes/npcs/client/gui/GuiBorderBlock.java b/src/main/java/noppes/npcs/client/gui/GuiBorderBlock.java index 290385537..d9c4d1717 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiBorderBlock.java +++ b/src/main/java/noppes/npcs/client/gui/GuiBorderBlock.java @@ -6,7 +6,6 @@ import kamkeel.npcs.network.packets.request.TileEntitySavePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.blocks.tiles.TileBorder; - import noppes.npcs.client.gui.util.*; public class GuiBorderBlock extends GuiNPCInterface implements IGuiData{ diff --git a/src/main/java/noppes/npcs/client/gui/GuiMagicMap.java b/src/main/java/noppes/npcs/client/gui/GuiMagicMap.java index d12695ada..34d5a3d21 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiMagicMap.java +++ b/src/main/java/noppes/npcs/client/gui/GuiMagicMap.java @@ -1,13 +1,5 @@ package noppes.npcs.client.gui; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import noppes.npcs.client.gui.util.GuiDiagram; -import noppes.npcs.client.gui.util.GuiNPCInterface; -import noppes.npcs.controllers.MagicController; -import noppes.npcs.controllers.data.Magic; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.renderer.RenderHelper; @@ -15,8 +7,16 @@ import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.gui.util.GuiDiagram; +import noppes.npcs.client.gui.util.GuiNPCInterface; +import noppes.npcs.controllers.MagicController; +import noppes.npcs.controllers.data.Magic; import org.lwjgl.opengl.GL11; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + public class GuiMagicMap extends GuiDiagram { private List magics; diff --git a/src/main/java/noppes/npcs/client/gui/GuiMerchantAdd.java b/src/main/java/noppes/npcs/client/gui/GuiMerchantAdd.java index 9979ecf1f..d39a6531a 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiMerchantAdd.java +++ b/src/main/java/noppes/npcs/client/gui/GuiMerchantAdd.java @@ -18,10 +18,8 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.village.MerchantRecipe; import net.minecraft.village.MerchantRecipeList; import noppes.npcs.ServerEventsHandler; - import noppes.npcs.client.CustomNpcResourceListener; import noppes.npcs.client.gui.util.GuiNpcButton; - import noppes.npcs.containers.ContainerMerchantAdd; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; diff --git a/src/main/java/noppes/npcs/client/gui/GuiNPCFactionSelection.java b/src/main/java/noppes/npcs/client/gui/GuiNPCFactionSelection.java index b3ba50227..01eef3728 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNPCFactionSelection.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNPCFactionSelection.java @@ -4,11 +4,8 @@ import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.request.faction.FactionsGetPacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; - import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.util.*; - -import noppes.npcs.controllers.data.Quest; import noppes.npcs.entity.EntityNPCInterface; import java.util.HashMap; diff --git a/src/main/java/noppes/npcs/client/gui/GuiNPCLinesEdit.java b/src/main/java/noppes/npcs/client/gui/GuiNPCLinesEdit.java index ea0bffc3e..d97a33a13 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNPCLinesEdit.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNPCLinesEdit.java @@ -5,10 +5,8 @@ import kamkeel.npcs.network.packets.request.mainmenu.MainmenuAdvancedGetPacket; import kamkeel.npcs.network.packets.request.mainmenu.MainmenuAdvancedSavePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.select.GuiSoundSelection; import noppes.npcs.client.gui.util.*; - import noppes.npcs.controllers.data.Line; import noppes.npcs.controllers.data.Lines; import noppes.npcs.entity.EntityNPCInterface; diff --git a/src/main/java/noppes/npcs/client/gui/GuiNPCTransportCategoryEdit.java b/src/main/java/noppes/npcs/client/gui/GuiNPCTransportCategoryEdit.java index c25e59dbf..129f4bd0b 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNPCTransportCategoryEdit.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNPCTransportCategoryEdit.java @@ -5,13 +5,11 @@ import kamkeel.npcs.network.packets.request.transport.TransportCategoriesGetPack import kamkeel.npcs.network.packets.request.transport.TransportCategorySavePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; - import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.GuiNpcTextField; - import noppes.npcs.entity.EntityNPCInterface; public class GuiNPCTransportCategoryEdit extends GuiNPCInterface diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcDimension.java b/src/main/java/noppes/npcs/client/gui/GuiNpcDimension.java index 2aa64b412..ce7b8d3e1 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcDimension.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcDimension.java @@ -6,11 +6,9 @@ import kamkeel.npcs.network.packets.request.feather.DimensionTeleportPacket; import kamkeel.npcs.network.packets.request.npc.RemoteDeletePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.util.StatCollector; - import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.util.*; - import java.util.HashMap; import java.util.Vector; diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java index b467640dc..8393eefa6 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawner.java @@ -11,11 +11,9 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.StatCollector; import net.minecraft.world.World; - import noppes.npcs.client.controllers.ClientCloneController; import noppes.npcs.client.controllers.ClientTagMapController; import noppes.npcs.client.gui.util.*; - import noppes.npcs.controllers.data.Tag; import noppes.npcs.controllers.data.TagMap; diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java index 4215e59d3..66ae14499 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java @@ -1,7 +1,6 @@ package noppes.npcs.client.gui; import kamkeel.npcs.network.PacketClient; -import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.packets.request.clone.CloneAllTagsShortPacket; import kamkeel.npcs.network.packets.request.clone.ClonePreSavePacket; import kamkeel.npcs.network.packets.request.clone.CloneSavePacket; @@ -14,11 +13,8 @@ import net.minecraft.entity.EntityList; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagString; - import noppes.npcs.client.controllers.ClientCloneController; import noppes.npcs.client.gui.util.*; - -import noppes.npcs.controllers.TagController; import noppes.npcs.controllers.data.Tag; import noppes.npcs.entity.EntityNPCInterface; diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerMounter.java b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerMounter.java index fff76deda..d1157b1cc 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerMounter.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerMounter.java @@ -12,11 +12,9 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagDouble; import net.minecraft.nbt.NBTTagList; import net.minecraft.world.World; - import noppes.npcs.client.controllers.ClientCloneController; import noppes.npcs.client.gui.util.*; - import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerSelector.java b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerSelector.java index 16d58c93d..cc9cff0c2 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerSelector.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerSelector.java @@ -6,11 +6,9 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagDouble; import net.minecraft.nbt.NBTTagList; - import noppes.npcs.client.controllers.ClientCloneController; import noppes.npcs.client.gui.util.*; - import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcPather.java b/src/main/java/noppes/npcs/client/gui/GuiNpcPather.java index 916748f08..7bb61e1c3 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcPather.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcPather.java @@ -7,12 +7,10 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.DataAI; import noppes.npcs.NBTTags; - import noppes.npcs.client.gui.util.GuiCustomScroll; import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.IGuiData; - import noppes.npcs.entity.EntityNPCInterface; import java.util.ArrayList; diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcRedstoneBlock.java b/src/main/java/noppes/npcs/client/gui/GuiNpcRedstoneBlock.java index 114af0fb6..9c81a1286 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcRedstoneBlock.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcRedstoneBlock.java @@ -6,7 +6,6 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.StatCollector; import noppes.npcs.blocks.tiles.TileRedstoneBlock; - import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcRemoteEditor.java b/src/main/java/noppes/npcs/client/gui/GuiNpcRemoteEditor.java index a35484e1b..ecf243d6d 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcRemoteEditor.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcRemoteEditor.java @@ -7,10 +7,8 @@ import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.entity.Entity; import net.minecraft.util.StatCollector; - import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.util.*; - import noppes.npcs.entity.EntityNPCInterface; import java.util.ArrayList; diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcWaypoint.java b/src/main/java/noppes/npcs/client/gui/GuiNpcWaypoint.java index c8fdc959d..c0afa6aaf 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcWaypoint.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcWaypoint.java @@ -5,7 +5,6 @@ import kamkeel.npcs.network.packets.request.TileEntitySavePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.blocks.tiles.TileWaypoint; - import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; diff --git a/src/main/java/noppes/npcs/client/gui/GuiScript.java b/src/main/java/noppes/npcs/client/gui/GuiScript.java index cd444d038..d5025d87b 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiScript.java +++ b/src/main/java/noppes/npcs/client/gui/GuiScript.java @@ -10,15 +10,12 @@ import net.minecraft.nbt.NBTTagList; import net.minecraft.server.MinecraftServer; import net.minecraft.util.StatCollector; import noppes.npcs.NoppesStringUtils; - import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.script.GuiNPCEventScripts; import noppes.npcs.client.gui.util.*; - import noppes.npcs.controllers.ScriptContainer; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.data.DataScript; -import noppes.npcs.controllers.data.Quest; import noppes.npcs.entity.EntityNPCInterface; import java.util.*; diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java b/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java index d8512eba9..22b0dfff1 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java @@ -1,9 +1,9 @@ package noppes.npcs.client.gui; import kamkeel.npcs.network.PacketClient; +import kamkeel.npcs.network.packets.request.tags.TagSetPacket; import kamkeel.npcs.network.packets.request.tags.TagsGetPacket; import kamkeel.npcs.network.packets.request.tags.TagsNpcGetPacket; -import kamkeel.npcs.network.packets.request.tags.TagSetPacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiMailmanSendSetup.java b/src/main/java/noppes/npcs/client/gui/SubGuiMailmanSendSetup.java index 0dadea474..2f0f5dfeb 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiMailmanSendSetup.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiMailmanSendSetup.java @@ -5,11 +5,9 @@ import kamkeel.npcs.network.packets.request.MailOpenSetupPacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.player.GuiMailmanWrite; import noppes.npcs.client.gui.select.GuiQuestSelection; import noppes.npcs.client.gui.util.*; - import noppes.npcs.containers.ContainerMail; import noppes.npcs.controllers.data.PlayerMail; diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailability.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailability.java index 6d4b5bc4a..2d59d80a8 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailability.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailability.java @@ -3,12 +3,10 @@ package noppes.npcs.client.gui; import kamkeel.npcs.network.packets.request.faction.FactionGetPacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumAvailabilityFactionType; import noppes.npcs.constants.EnumDayTime; - import noppes.npcs.controllers.data.Availability; import noppes.npcs.controllers.data.Faction; diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityDialog.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityDialog.java index 35ee2158f..c55f040c5 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityDialog.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityDialog.java @@ -3,11 +3,9 @@ package noppes.npcs.client.gui; import kamkeel.npcs.network.packets.request.dialog.DialogGetPacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.select.GuiDialogSelection; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumAvailabilityDialog; - import noppes.npcs.controllers.data.Availability; import noppes.npcs.controllers.data.Dialog; diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityQuest.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityQuest.java index c993936db..5d333ba3a 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityQuest.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityQuest.java @@ -3,11 +3,9 @@ package noppes.npcs.client.gui; import kamkeel.npcs.network.packets.request.quest.QuestGetPacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.select.GuiQuestSelection; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumAvailabilityQuest; - import noppes.npcs.controllers.data.Availability; import noppes.npcs.controllers.data.Quest; diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialog.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialog.java index 0e09356c3..f1efa4716 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialog.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialog.java @@ -4,7 +4,6 @@ import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.request.dialog.DialogSavePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.EntityUtil; import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.global.GuiNPCManageDialogs; @@ -12,7 +11,6 @@ import noppes.npcs.client.gui.player.GuiDialogInteract; import noppes.npcs.client.gui.select.GuiQuestSelection; import noppes.npcs.client.gui.select.GuiSoundSelection; import noppes.npcs.client.gui.util.*; - import noppes.npcs.controllers.data.Dialog; import noppes.npcs.controllers.data.PlayerMail; import noppes.npcs.entity.EntityDialogNpc; diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogOption.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogOption.java index f5565e43f..b47e71794 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogOption.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogOption.java @@ -3,11 +3,9 @@ package noppes.npcs.client.gui; import kamkeel.npcs.network.packets.request.dialog.DialogGetPacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.select.GuiDialogSelection; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumOptionType; - import noppes.npcs.controllers.data.Dialog; import noppes.npcs.controllers.data.DialogOption; diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java index bd7092d50..81da655e8 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java @@ -4,11 +4,9 @@ import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.request.dialog.DialogSavePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.util.*; import noppes.npcs.config.ConfigMain; - import noppes.npcs.controllers.data.Dialog; import noppes.npcs.controllers.data.DialogImage; diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDimensions.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDimensions.java index f90cc61b1..066a797f6 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDimensions.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDimensions.java @@ -3,9 +3,7 @@ package noppes.npcs.client.gui; import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.request.DimensionsGetPacket; import net.minecraft.client.gui.GuiButton; - import noppes.npcs.client.gui.util.*; - import noppes.npcs.controllers.data.SpawnData; import java.util.*; diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcFactionOptions.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcFactionOptions.java index d3cce58c2..7d1d2fdd9 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcFactionOptions.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcFactionOptions.java @@ -4,9 +4,7 @@ import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.request.faction.FactionsGetPacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.util.StatCollector; - import noppes.npcs.client.gui.util.*; - import noppes.npcs.controllers.data.FactionOptions; import java.util.HashMap; diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java index 8b1b70319..192dfc4ca 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java @@ -5,7 +5,6 @@ import kamkeel.npcs.network.packets.request.quest.QuestOpenGuiPacket; import kamkeel.npcs.network.packets.request.quest.QuestSavePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.global.GuiNPCManageQuest; import noppes.npcs.client.gui.questtypes.GuiNpcQuestTypeDialog; import noppes.npcs.client.gui.questtypes.GuiNpcQuestTypeKill; @@ -13,7 +12,10 @@ import noppes.npcs.client.gui.questtypes.GuiNpcQuestTypeLocation; import noppes.npcs.client.gui.questtypes.GuiNpcQuestTypeManual; import noppes.npcs.client.gui.select.GuiQuestSelection; import noppes.npcs.client.gui.util.*; -import noppes.npcs.constants.*; +import noppes.npcs.constants.EnumGuiType; +import noppes.npcs.constants.EnumQuestCompletion; +import noppes.npcs.constants.EnumQuestRepeat; +import noppes.npcs.constants.EnumQuestType; import noppes.npcs.controllers.data.PlayerMail; import noppes.npcs.controllers.data.Quest; diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java b/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java index 3e6431a53..571009469 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiPlayerData.java @@ -1,14 +1,12 @@ package noppes.npcs.client.gui; import kamkeel.npcs.network.PacketClient; -import noppes.npcs.client.CustomNpcResourceListener; -import noppes.npcs.client.gui.util.IPlayerDataInfo; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetInfoPacket; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataRemoveInfoPacket; +import net.minecraft.client.gui.GuiButton; +import noppes.npcs.client.CustomNpcResourceListener; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPlayerData; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.util.StatCollector; import org.lwjgl.opengl.GL11; import java.util.ArrayList; diff --git a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCAdvancedLinkedNpc.java b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCAdvancedLinkedNpc.java index 6c4c771ae..4d71c789b 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCAdvancedLinkedNpc.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCAdvancedLinkedNpc.java @@ -5,9 +5,7 @@ import kamkeel.npcs.network.packets.request.linked.LinkedGetAllPacket; import kamkeel.npcs.network.packets.request.linked.LinkedSetPacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; - import noppes.npcs.client.gui.util.*; - import noppes.npcs.entity.EntityNPCInterface; import java.util.ArrayList; diff --git a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCDialogNpcOptions.java b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCDialogNpcOptions.java index 88dd27c92..4db6170b1 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCDialogNpcOptions.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCDialogNpcOptions.java @@ -7,10 +7,8 @@ import kamkeel.npcs.network.packets.request.dialog.DialogNpcSetPacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.select.GuiDialogSelection; import noppes.npcs.client.gui.util.*; - import noppes.npcs.controllers.data.DialogOption; import noppes.npcs.entity.EntityNPCInterface; diff --git a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCFactionSetup.java b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCFactionSetup.java index e7aab677e..314e2cb92 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCFactionSetup.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCFactionSetup.java @@ -6,10 +6,8 @@ import kamkeel.npcs.network.packets.request.faction.FactionsGetPacket; import kamkeel.npcs.network.packets.request.mainmenu.MainmenuAdvancedSavePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.SubGuiNpcFactionOptions; import noppes.npcs.client.gui.util.*; - import noppes.npcs.entity.EntityNPCInterface; import java.util.HashMap; diff --git a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCLinesMenu.java b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCLinesMenu.java index 92d5c49dd..3a1b0a0e7 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCLinesMenu.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCLinesMenu.java @@ -4,14 +4,12 @@ import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.request.mainmenu.MainmenuAdvancedSavePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.GuiNPCLinesEdit; import noppes.npcs.client.gui.util.GuiNPCInterface2; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcButtonYesNo; import noppes.npcs.client.gui.util.GuiNpcLabel; - import noppes.npcs.entity.EntityNPCInterface; public class GuiNPCLinesMenu extends GuiNPCInterface2 { diff --git a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCMarks.java b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCMarks.java index bad32b76b..048af68c0 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCMarks.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCMarks.java @@ -1,14 +1,11 @@ package noppes.npcs.client.gui.advanced; import kamkeel.npcs.network.PacketClient; -import kamkeel.npcs.network.packets.request.mainmenu.MainmenuAdvancedGetPacket; import kamkeel.npcs.network.packets.request.mainmenu.MainmenuAdvancedMarkDataPacket; import net.minecraft.client.gui.GuiButton; - import noppes.npcs.client.gui.SubGuiColorSelector; import noppes.npcs.client.gui.SubGuiNpcAvailability; import noppes.npcs.client.gui.util.*; - import noppes.npcs.constants.MarkType; import noppes.npcs.controllers.data.MarkData; import noppes.npcs.entity.EntityNPCInterface; diff --git a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCNightSetup.java b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCNightSetup.java index cbe94b524..4ca3755b6 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCNightSetup.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCNightSetup.java @@ -6,12 +6,10 @@ import kamkeel.npcs.network.packets.request.transform.TransformLoadPacket; import kamkeel.npcs.network.packets.request.transform.TransformSavePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.util.GuiNPCInterface2; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.IGuiData; - import noppes.npcs.controllers.data.DataTransform; import noppes.npcs.entity.EntityNPCInterface; diff --git a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCSoundsMenu.java b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCSoundsMenu.java index efd0e5d0b..352b9044c 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCSoundsMenu.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCSoundsMenu.java @@ -4,10 +4,8 @@ import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.request.mainmenu.MainmenuAdvancedSavePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.select.GuiSoundSelection; import noppes.npcs.client.gui.util.*; - import noppes.npcs.entity.EntityNPCInterface; public class GuiNPCSoundsMenu extends GuiNPCInterface2 implements ITextfieldListener, ISubGuiListener diff --git a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCTagSetup.java b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCTagSetup.java index 54c5abecf..ad91240de 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCTagSetup.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCTagSetup.java @@ -1,9 +1,9 @@ package noppes.npcs.client.gui.advanced; import kamkeel.npcs.network.PacketClient; +import kamkeel.npcs.network.packets.request.tags.TagSetPacket; import kamkeel.npcs.network.packets.request.tags.TagsGetPacket; import kamkeel.npcs.network.packets.request.tags.TagsNpcGetPacket; -import kamkeel.npcs.network.packets.request.tags.TagSetPacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; diff --git a/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java b/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java index 6bf025ae3..dfa5b928d 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java +++ b/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java @@ -25,7 +25,6 @@ import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; import noppes.npcs.api.gui.ICustomGuiComponent; - import noppes.npcs.client.gui.custom.components.*; import noppes.npcs.client.gui.custom.interfaces.IClickListener; import noppes.npcs.client.gui.custom.interfaces.IDataHolder; @@ -33,7 +32,6 @@ import noppes.npcs.client.gui.custom.interfaces.IGuiComponent; import noppes.npcs.client.gui.util.GuiCustomScroll; import noppes.npcs.client.gui.util.ICustomScrollListener; import noppes.npcs.client.gui.util.IGuiData; - import noppes.npcs.containers.ContainerCustomGui; import noppes.npcs.scripted.gui.*; import org.lwjgl.input.Keyboard; diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageBanks.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageBanks.java index ec0f581b1..0b0b693f5 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageBanks.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageBanks.java @@ -7,10 +7,8 @@ import kamkeel.npcs.network.packets.request.bank.BankSavePacket; import kamkeel.npcs.network.packets.request.bank.BanksGetPacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.CustomNpcResourceListener; import noppes.npcs.client.gui.util.*; - import noppes.npcs.containers.ContainerManageBanks; import noppes.npcs.controllers.data.Bank; import noppes.npcs.entity.EntityNPCInterface; diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java index 0dafe3325..dc0e9bfbc 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java @@ -7,12 +7,10 @@ import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.StatCollector; - import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.SubGuiEditText; import noppes.npcs.client.gui.SubGuiNpcDialog; import noppes.npcs.client.gui.util.*; - import noppes.npcs.controllers.data.Dialog; import noppes.npcs.controllers.data.DialogCategory; import noppes.npcs.entity.EntityNPCInterface; diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageFactions.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageFactions.java index c2cc01330..427543a42 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageFactions.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageFactions.java @@ -10,14 +10,11 @@ import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.StatCollector; - import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.SubGuiColorSelector; import noppes.npcs.client.gui.SubGuiNpcFactionPoints; import noppes.npcs.client.gui.util.*; - import noppes.npcs.controllers.data.Faction; -import noppes.npcs.controllers.data.Quest; import noppes.npcs.entity.EntityNPCInterface; import java.util.*; diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageLinked.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageLinked.java index 9677742f7..4a11ef336 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageLinked.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageLinked.java @@ -1,13 +1,9 @@ package noppes.npcs.client.gui.global; import kamkeel.npcs.network.PacketClient; -import kamkeel.npcs.network.packets.request.effects.EffectRemovePacket; -import kamkeel.npcs.network.packets.request.effects.EffectSavePacket; import kamkeel.npcs.network.packets.request.linked.*; -import kamkeel.npcs.network.packets.request.quest.QuestSavePacket; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; - import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.client.renderer.OpenGlHelper; @@ -24,7 +20,6 @@ import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.SubGuiEditText; import noppes.npcs.client.gui.item.SubGuiLinkedItem; import noppes.npcs.client.gui.util.*; - import noppes.npcs.client.renderer.ImageData; import noppes.npcs.controllers.data.LinkedItem; import noppes.npcs.entity.EntityCustomNpc; diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageQuest.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageQuest.java index c31792185..d51341fb3 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageQuest.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageQuest.java @@ -8,12 +8,10 @@ import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.StatCollector; - import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.SubGuiEditText; import noppes.npcs.client.gui.SubGuiNpcQuest; import noppes.npcs.client.gui.util.*; - import noppes.npcs.controllers.data.Quest; import noppes.npcs.controllers.data.QuestCategory; import noppes.npcs.entity.EntityNPCInterface; diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageTags.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageTags.java index 1d9bc3e13..bd1d2a500 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageTags.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageTags.java @@ -2,15 +2,13 @@ package noppes.npcs.client.gui.global; import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.request.tags.TagGetPacket; -import kamkeel.npcs.network.packets.request.tags.TagsGetPacket; import kamkeel.npcs.network.packets.request.tags.TagRemovePacket; import kamkeel.npcs.network.packets.request.tags.TagSavePacket; +import kamkeel.npcs.network.packets.request.tags.TagsGetPacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.SubGuiColorSelector; import noppes.npcs.client.gui.util.*; - import noppes.npcs.controllers.data.Tag; import noppes.npcs.entity.EntityNPCInterface; diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageTransporters.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageTransporters.java index dfec90df5..198248660 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageTransporters.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageTransporters.java @@ -6,7 +6,6 @@ import kamkeel.npcs.network.packets.request.transport.TransportCategoryRemovePac import kamkeel.npcs.network.packets.request.transport.TransportRemovePacket; import kamkeel.npcs.network.packets.request.transport.TransportsGetPacket; import net.minecraft.client.gui.GuiButton; - import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.GuiNPCTransportCategoryEdit; import noppes.npcs.client.gui.mainmenu.GuiNPCGlobalMainMenu; @@ -14,7 +13,6 @@ import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.GuiNPCStringSlot; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.IScrollData; - import noppes.npcs.entity.EntityNPCInterface; import java.util.HashMap; 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 4e423ae3b..74dd37de2 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManagePlayerData.java @@ -4,13 +4,13 @@ import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetNamesPacket; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataMapRegenPacket; import kamkeel.npcs.network.packets.request.playerdata.PlayerDataRemovePacket; +import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; +import net.minecraft.util.StatCollector; import noppes.npcs.client.gui.SubGuiPlayerData; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPlayerData; -import net.minecraft.util.StatCollector; -import net.minecraft.client.gui.GuiButton; import noppes.npcs.entity.EntityNPCInterface; import java.util.ArrayList; diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java index 76dd1b840..54c048512 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNpcManageRecipes.java @@ -8,14 +8,12 @@ import kamkeel.npcs.network.packets.request.recipe.RecipesGetPacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; - import net.minecraft.util.StatCollector; import noppes.npcs.client.CustomNpcResourceListener; import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.SubGuiNpcAvailability; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumGuiType; - import noppes.npcs.containers.ContainerManageRecipes; import noppes.npcs.controllers.data.RecipeAnvil; import noppes.npcs.controllers.data.RecipeCarpentry; diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNpcNaturalSpawns.java b/src/main/java/noppes/npcs/client/gui/global/GuiNpcNaturalSpawns.java index bd3b4e9e5..e73b4cdf1 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNpcNaturalSpawns.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNpcNaturalSpawns.java @@ -8,13 +8,11 @@ import kamkeel.npcs.network.packets.request.naturalspawns.NaturalSpawnSavePacket import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.StatCollector; - import noppes.npcs.client.gui.GuiNpcMobSpawnerSelector; import noppes.npcs.client.gui.SubGuiNpcBiomes; import noppes.npcs.client.gui.SubGuiNpcDimensions; import noppes.npcs.client.gui.SubGuiSpawningOptions; import noppes.npcs.client.gui.util.*; - import noppes.npcs.controllers.data.SpawnData; import noppes.npcs.entity.EntityNPCInterface; diff --git a/src/main/java/noppes/npcs/client/gui/item/SubGuiLinkedItem.java b/src/main/java/noppes/npcs/client/gui/item/SubGuiLinkedItem.java index 77a2d35ee..92d4df551 100644 --- a/src/main/java/noppes/npcs/client/gui/item/SubGuiLinkedItem.java +++ b/src/main/java/noppes/npcs/client/gui/item/SubGuiLinkedItem.java @@ -2,25 +2,20 @@ package noppes.npcs.client.gui.item; import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.request.linked.LinkedItemSavePacket; -import kamkeel.npcs.network.packets.request.linked.LinkedNPCAddPacket; import kamkeel.npcs.util.ColorUtil; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.StatCollector; import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.client.CustomNpcResourceListener; -import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.SubGuiColorSelector; -import noppes.npcs.client.gui.SubGuiEditText; import noppes.npcs.client.gui.global.GuiNPCManageLinked; import noppes.npcs.client.gui.script.GuiScriptLinkedItem; import noppes.npcs.client.gui.util.*; import noppes.npcs.client.renderer.ImageData; import noppes.npcs.controllers.data.LinkedItem; -import noppes.npcs.util.ValueUtil; import org.lwjgl.opengl.GL11; public class SubGuiLinkedItem extends SubGuiInterface implements ITextfieldListener, GuiYesNoCallback, ISubGuiListener { diff --git a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCGlobalMainMenu.java b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCGlobalMainMenu.java index a70e427da..203b32c9f 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCGlobalMainMenu.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCGlobalMainMenu.java @@ -11,12 +11,7 @@ import noppes.npcs.client.gui.util.GuiNpcSquareButton; import noppes.npcs.constants.EnumGuiType; import noppes.npcs.entity.EntityNPCInterface; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.HashMap; +import java.util.*; import static noppes.npcs.client.gui.player.inventory.GuiCNPCInventory.specialIcons; diff --git a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCInv.java b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCInv.java index d4b033b4d..2d18c8769 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCInv.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCInv.java @@ -10,9 +10,7 @@ import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.inventory.Slot; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; - import noppes.npcs.client.gui.util.*; - import noppes.npcs.containers.ContainerNPCInv; import noppes.npcs.entity.EntityNPCInterface; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAI.java b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAI.java index dafe8f50d..683898be0 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAI.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAI.java @@ -6,12 +6,10 @@ import kamkeel.npcs.network.packets.request.mainmenu.MainmenuAISavePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.DataAI; - import noppes.npcs.client.gui.SubGuiNpcMovement; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumCombatPolicy; import noppes.npcs.constants.EnumNavType; - import noppes.npcs.entity.EntityNPCInterface; public class GuiNpcAI extends GuiNPCInterface2 implements ITextfieldListener, IGuiData{ 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 4a4eae046..fb722e1ce 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAdvanced.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAdvanced.java @@ -8,7 +8,6 @@ import kamkeel.npcs.network.packets.request.role.RoleGetPacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.NoppesStringUtils; - import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.advanced.*; import noppes.npcs.client.gui.roles.*; @@ -17,7 +16,6 @@ import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.IGuiData; import noppes.npcs.constants.EnumGuiType; import noppes.npcs.constants.EnumJobType; - import noppes.npcs.constants.EnumRoleType; import noppes.npcs.entity.EntityNPCInterface; 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 b035b84be..41394770c 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java @@ -9,14 +9,12 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import noppes.npcs.DataDisplay; - import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.*; import noppes.npcs.client.gui.model.GuiCreationScreen; import noppes.npcs.client.gui.select.GuiTextureSelection; import noppes.npcs.client.gui.util.*; import noppes.npcs.config.ConfigMain; - import noppes.npcs.controllers.data.SkinOverlay; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; diff --git a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcStats.java b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcStats.java index 8fc1d567c..7dc198388 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcStats.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcStats.java @@ -8,10 +8,8 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.EnumCreatureAttribute; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.DataStats; - import noppes.npcs.client.gui.*; import noppes.npcs.client.gui.util.*; - import noppes.npcs.entity.EntityNPCInterface; public class GuiNpcStats extends GuiNPCInterface2 implements ITextfieldListener, IGuiData{ diff --git a/src/main/java/noppes/npcs/client/gui/model/GuiCreationScreen.java b/src/main/java/noppes/npcs/client/gui/model/GuiCreationScreen.java index 590b8d4ea..68aff497e 100644 --- a/src/main/java/noppes/npcs/client/gui/model/GuiCreationScreen.java +++ b/src/main/java/noppes/npcs/client/gui/model/GuiCreationScreen.java @@ -16,10 +16,8 @@ import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagByte; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; - import noppes.npcs.client.gui.util.*; import noppes.npcs.compat.PixelmonHelper; - import noppes.npcs.entity.*; import java.lang.reflect.Method; diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiAnvilRecipes.java b/src/main/java/noppes/npcs/client/gui/player/GuiAnvilRecipes.java index cac06388a..c1c78865a 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiAnvilRecipes.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiAnvilRecipes.java @@ -2,25 +2,24 @@ package noppes.npcs.client.gui.player; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import net.minecraft.util.StatCollector; -import noppes.npcs.client.CustomNpcResourceListener; -import noppes.npcs.client.gui.util.*; -import noppes.npcs.controllers.RecipeController; -import noppes.npcs.controllers.data.RecipeAnvil; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.item.ItemStack; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; -import noppes.npcs.util.ValueUtil; +import net.minecraft.util.StatCollector; +import noppes.npcs.client.CustomNpcResourceListener; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.controllers.RecipeController; +import noppes.npcs.controllers.data.RecipeAnvil; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + @SideOnly(Side.CLIENT) public class GuiAnvilRecipes extends GuiNPCInterface { diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiBigSign.java b/src/main/java/noppes/npcs/client/gui/player/GuiBigSign.java index f9773d335..fb4554bed 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiBigSign.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiBigSign.java @@ -2,10 +2,8 @@ package noppes.npcs.client.gui.player; import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.player.SaveSignPacket; -import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.blocks.tiles.TileBigSign; import noppes.npcs.client.gui.SubGuiNpcTextArea; -import noppes.npcs.constants.EnumPlayerPacket; public class GuiBigSign extends SubGuiNpcTextArea{ public TileBigSign tile; diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiBook.java b/src/main/java/noppes/npcs/client/gui/player/GuiBook.java index bc609440e..730427a24 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiBook.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiBook.java @@ -17,8 +17,6 @@ import net.minecraft.nbt.NBTTagString; import net.minecraft.util.ChatAllowedCharacters; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; -import noppes.npcs.NoppesUtilPlayer; -import noppes.npcs.constants.EnumPlayerPacket; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.lwjgl.input.Keyboard; diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiMailbox.java b/src/main/java/noppes/npcs/client/gui/player/GuiMailbox.java index 70e2130f9..360d69c0c 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiMailbox.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiMailbox.java @@ -6,10 +6,8 @@ import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.StatCollector; -import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.util.*; -import noppes.npcs.constants.EnumPlayerPacket; import noppes.npcs.controllers.data.PlayerMail; import noppes.npcs.controllers.data.PlayerMailData; diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiMailmanWrite.java b/src/main/java/noppes/npcs/client/gui/player/GuiMailmanWrite.java index 32efa064c..3f2bf588b 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiMailmanWrite.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiMailmanWrite.java @@ -13,10 +13,8 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagString; import net.minecraft.util.*; -import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.util.*; -import noppes.npcs.constants.EnumPlayerPacket; import noppes.npcs.containers.ContainerMail; import noppes.npcs.controllers.data.PlayerMail; import org.lwjgl.input.Keyboard; diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiNpcFollower.java b/src/main/java/noppes/npcs/client/gui/player/GuiNpcFollower.java index 815ae9c9a..05d162aa0 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiNpcFollower.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiNpcFollower.java @@ -9,12 +9,10 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; -import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.client.CustomNpcResourceListener; import noppes.npcs.client.gui.util.GuiContainerNPCInterface; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.IGuiData; -import noppes.npcs.constants.EnumPlayerPacket; import noppes.npcs.containers.ContainerNPCFollower; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleFollower; diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiNpcFollowerHire.java b/src/main/java/noppes/npcs/client/gui/player/GuiNpcFollowerHire.java index 5dfc6008b..261e2d9bb 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiNpcFollowerHire.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiNpcFollowerHire.java @@ -7,11 +7,9 @@ import net.minecraft.client.renderer.RenderHelper; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; -import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.client.CustomNpcResourceListener; import noppes.npcs.client.gui.util.GuiContainerNPCInterface; import noppes.npcs.client.gui.util.GuiNpcButton; -import noppes.npcs.constants.EnumPlayerPacket; import noppes.npcs.containers.ContainerNPCFollowerHire; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleFollower; diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiTransportSelection.java b/src/main/java/noppes/npcs/client/gui/player/GuiTransportSelection.java index 601f01df5..df217675a 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiTransportSelection.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiTransportSelection.java @@ -5,9 +5,7 @@ import kamkeel.npcs.network.packets.player.TransportPacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; -import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.client.gui.util.*; -import noppes.npcs.constants.EnumPlayerPacket; import noppes.npcs.entity.EntityNPCInterface; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/noppes/npcs/client/gui/player/companion/GuiNpcCompanionStats.java b/src/main/java/noppes/npcs/client/gui/player/companion/GuiNpcCompanionStats.java index c95927985..11215c505 100644 --- a/src/main/java/noppes/npcs/client/gui/player/companion/GuiNpcCompanionStats.java +++ b/src/main/java/noppes/npcs/client/gui/player/companion/GuiNpcCompanionStats.java @@ -11,12 +11,10 @@ import net.minecraft.util.MathHelper; import noppes.npcs.CustomItems; import noppes.npcs.CustomNpcs; import noppes.npcs.NoppesStringUtils; -import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumCompanionJobs; import noppes.npcs.constants.EnumCompanionTalent; import noppes.npcs.constants.EnumGuiType; -import noppes.npcs.constants.EnumPlayerPacket; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleCompanion; diff --git a/src/main/java/noppes/npcs/client/gui/player/companion/GuiNpcCompanionTalents.java b/src/main/java/noppes/npcs/client/gui/player/companion/GuiNpcCompanionTalents.java index f9e1c8a9d..9478240f2 100644 --- a/src/main/java/noppes/npcs/client/gui/player/companion/GuiNpcCompanionTalents.java +++ b/src/main/java/noppes/npcs/client/gui/player/companion/GuiNpcCompanionTalents.java @@ -11,14 +11,12 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import noppes.npcs.CustomNpcs; import noppes.npcs.NoppesStringUtils; -import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.client.CustomNpcResourceListener; import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.constants.EnumCompanionTalent; import noppes.npcs.constants.EnumGuiType; -import noppes.npcs.constants.EnumPlayerPacket; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleCompanion; import org.lwjgl.input.Mouse; 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 ff7dcbb7a..f8a4969d6 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 @@ -7,11 +7,9 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; -import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.client.CustomNpcResourceListener; import noppes.npcs.client.gui.util.GuiButtonNextPage; import noppes.npcs.client.gui.util.IGuiData; -import noppes.npcs.constants.EnumPlayerPacket; import noppes.npcs.controllers.data.Faction; import noppes.npcs.controllers.data.PlayerFactionData; import org.lwjgl.opengl.GL11; 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 a6c1a4dc6..58348542a 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 @@ -1,7 +1,6 @@ package noppes.npcs.client.gui.player.inventory; import kamkeel.npcs.network.PacketClient; -import kamkeel.npcs.network.packets.data.large.PartyDataPacket; import kamkeel.npcs.network.packets.player.CheckPlayerValue; import kamkeel.npcs.network.packets.request.party.*; import net.minecraft.client.gui.GuiButton; @@ -12,14 +11,10 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; -import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.QuestLogData; - import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.client.CustomNpcResourceListener; import noppes.npcs.client.gui.util.*; - -import noppes.npcs.constants.EnumPlayerPacket; import noppes.npcs.controllers.data.Party; import noppes.npcs.controllers.data.Quest; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java index 28ae83cfe..fe3b884a5 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java @@ -5,9 +5,7 @@ import kamkeel.npcs.controllers.data.InfoEntry; import kamkeel.npcs.controllers.data.Profile; import kamkeel.npcs.controllers.data.Slot; import kamkeel.npcs.network.PacketClient; -import kamkeel.npcs.network.packets.request.linked.LinkedItemRemovePacket; import kamkeel.npcs.network.packets.request.profile.*; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; 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 6091ce220..55583f14e 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 @@ -2,7 +2,6 @@ package noppes.npcs.client.gui.player.inventory; import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.player.CheckPlayerValue; -import kamkeel.npcs.network.packets.request.party.PartyLogToServerPacket; import kamkeel.npcs.network.packets.request.party.PartySetQuestPacket; import kamkeel.npcs.network.packets.request.quest.QuestLogToServerPacket; import net.minecraft.client.gui.GuiButton; @@ -13,12 +12,12 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import noppes.npcs.NBTTags; -import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.QuestLogData; -import noppes.npcs.client.*; +import noppes.npcs.client.ClientCacheHandler; +import noppes.npcs.client.CustomNpcResourceListener; +import noppes.npcs.client.NoppesUtil; +import noppes.npcs.client.TextBlockClient; import noppes.npcs.client.gui.util.*; - -import noppes.npcs.constants.EnumPlayerPacket; import noppes.npcs.controllers.data.Party; import noppes.npcs.util.ValueUtil; import org.lwjgl.input.Mouse; diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java index e702e59cb..19aea1433 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java @@ -1,21 +1,18 @@ package noppes.npcs.client.gui.player.inventory; import kamkeel.npcs.network.PacketClient; -import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.packets.request.quest.QuestUntrackPacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; - import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.ITextfieldListener; import noppes.npcs.config.ConfigClient; - import org.lwjgl.opengl.GL11; import tconstruct.client.tabs.AbstractTab; 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 9458c5095..3aa5d0fea 100644 --- a/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeDialog.java +++ b/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeDialog.java @@ -5,13 +5,11 @@ import kamkeel.npcs.network.packets.request.quest.QuestDialogGetTitlePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.select.GuiDialogSelection; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiSelectionListener; import noppes.npcs.client.gui.util.IGuiData; import noppes.npcs.client.gui.util.SubGuiInterface; - import noppes.npcs.controllers.data.Quest; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.quests.QuestDialog; diff --git a/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeKill.java b/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeKill.java index 19ca84c53..c1e8381ad 100644 --- a/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeKill.java +++ b/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeKill.java @@ -12,7 +12,6 @@ import noppes.npcs.quests.QuestKill; import java.lang.reflect.Modifier; import java.util.ArrayList; -import java.util.HashMap; import java.util.Map; import java.util.TreeMap; diff --git a/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeManual.java b/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeManual.java index 19f2293bb..a05a38c72 100644 --- a/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeManual.java +++ b/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeManual.java @@ -7,7 +7,6 @@ import noppes.npcs.controllers.data.Quest; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.quests.QuestManual; -import java.util.HashMap; import java.util.TreeMap; public class GuiNpcQuestTypeManual extends SubGuiInterface implements ITextfieldListener diff --git a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBankSetup.java b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBankSetup.java index 615368344..1483c9aba 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBankSetup.java +++ b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBankSetup.java @@ -1,17 +1,14 @@ package noppes.npcs.client.gui.roles; import kamkeel.npcs.network.PacketClient; -import kamkeel.npcs.network.packets.request.bank.BankGetPacket; import kamkeel.npcs.network.packets.request.bank.BanksGetPacket; import kamkeel.npcs.network.packets.request.role.RoleSavePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.util.GuiCustomScroll; import noppes.npcs.client.gui.util.GuiNPCInterface2; import noppes.npcs.client.gui.util.ICustomScrollListener; import noppes.npcs.client.gui.util.IScrollData; - import noppes.npcs.controllers.data.Bank; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleBank; diff --git a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBard.java b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBard.java index 319d3bfcf..37317a08f 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBard.java +++ b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBard.java @@ -1,14 +1,10 @@ package noppes.npcs.client.gui.roles; -import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.request.jobs.JobSavePacket; import net.minecraft.client.gui.GuiButton; -import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.controllers.MusicController; import noppes.npcs.client.gui.select.GuiSoundSelection; import noppes.npcs.client.gui.util.*; - import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobBard; diff --git a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcCompanion.java b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcCompanion.java index 136dbdc77..f17b3052e 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcCompanion.java +++ b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcCompanion.java @@ -5,12 +5,10 @@ import kamkeel.npcs.network.packets.request.role.RoleCompanionUpdatePacket; import kamkeel.npcs.network.packets.request.role.RoleSavePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.player.companion.GuiNpcCompanionTalents.GuiTalent; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumCompanionStage; import noppes.npcs.constants.EnumCompanionTalent; - import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleCompanion; diff --git a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcConversation.java b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcConversation.java index 1ee14f2f4..1948c26b0 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcConversation.java +++ b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcConversation.java @@ -2,12 +2,9 @@ package noppes.npcs.client.gui.roles; import kamkeel.npcs.network.packets.request.jobs.JobSavePacket; import net.minecraft.client.gui.GuiButton; -import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.SubGuiNpcAvailability; import noppes.npcs.client.gui.select.GuiQuestSelection; import noppes.npcs.client.gui.util.*; - import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobConversation; import noppes.npcs.roles.JobConversation.ConversationLine; diff --git a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcFollowerJob.java b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcFollowerJob.java index 0223de066..a995ce380 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcFollowerJob.java +++ b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcFollowerJob.java @@ -1,10 +1,7 @@ package noppes.npcs.client.gui.roles; import kamkeel.npcs.network.packets.request.jobs.JobSavePacket; -import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.util.*; - import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobFollower; diff --git a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcFollowerSetup.java b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcFollowerSetup.java index bf40f5cf4..5664d3549 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcFollowerSetup.java +++ b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcFollowerSetup.java @@ -6,9 +6,7 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; - import noppes.npcs.client.gui.util.*; - import noppes.npcs.containers.ContainerNPCFollowerSetup; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleFollower; diff --git a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcGuard.java b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcGuard.java index bb2a2bdf9..0fa18d455 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcGuard.java +++ b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcGuard.java @@ -4,13 +4,10 @@ import kamkeel.npcs.network.packets.request.jobs.JobSavePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLivingBase; -import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.util.GuiCustomScroll; import noppes.npcs.client.gui.util.GuiNPCInterface2; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; - import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobGuard; diff --git a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcHealer.java b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcHealer.java index 25ac2077e..05c41b644 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcHealer.java +++ b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcHealer.java @@ -1,12 +1,9 @@ package noppes.npcs.client.gui.roles; import kamkeel.npcs.network.packets.request.jobs.JobSavePacket; -import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.util.GuiNPCInterface2; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.GuiNpcTextField; - import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobHealer; diff --git a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcItemGiver.java b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcItemGiver.java index 15cf67340..5b518dc2b 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcItemGiver.java +++ b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcItemGiver.java @@ -2,14 +2,11 @@ package noppes.npcs.client.gui.roles; import kamkeel.npcs.network.packets.request.jobs.JobSavePacket; import net.minecraft.client.gui.GuiButton; -import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.SubGuiNpcAvailability; import noppes.npcs.client.gui.util.GuiContainerNPCInterface2; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.GuiNpcTextField; - import noppes.npcs.containers.ContainerNpcItemGiver; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobItemGiver; diff --git a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcSpawner.java b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcSpawner.java index 1afbedf74..105a52be6 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcSpawner.java +++ b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcSpawner.java @@ -7,10 +7,8 @@ import kamkeel.npcs.network.packets.request.jobs.JobSpawnerRemovePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.StatCollector; - import noppes.npcs.client.gui.GuiNpcMobSpawnerSelector; import noppes.npcs.client.gui.util.*; - import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobSpawner; 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 389e52850..38e270d18 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcTraderSetup.java +++ b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcTraderSetup.java @@ -7,10 +7,8 @@ import kamkeel.npcs.network.packets.request.role.RoleSavePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; - import noppes.npcs.client.CustomNpcResourceListener; import noppes.npcs.client.gui.util.*; - import noppes.npcs.containers.ContainerNPCTraderSetup; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleTrader; diff --git a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcTransporter.java b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcTransporter.java index 6bf2c3f62..15da59255 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcTransporter.java +++ b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcTransporter.java @@ -6,9 +6,7 @@ import kamkeel.npcs.network.packets.request.transport.TransportGetLocationPacket import kamkeel.npcs.network.packets.request.transport.TransportSavePacket; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; - import noppes.npcs.client.gui.util.*; - import noppes.npcs.controllers.data.TransportLocation; import noppes.npcs.entity.EntityNPCInterface; diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptAllNPCs.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptAllNPCs.java index 908d1b75a..c4220720a 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptAllNPCs.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptAllNPCs.java @@ -3,8 +3,6 @@ package noppes.npcs.client.gui.script; import kamkeel.npcs.network.packets.request.script.GlobalNPCScriptPacket; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.NBTTags; - - import noppes.npcs.controllers.ScriptContainer; import noppes.npcs.controllers.data.GlobalNPCDataScript; diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptForge.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptForge.java index 7d0ec5aee..d26499219 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptForge.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptForge.java @@ -13,8 +13,6 @@ import net.minecraftforge.event.world.ChunkEvent; import net.minecraftforge.event.world.ChunkWatchEvent; import net.minecraftforge.event.world.WorldEvent; import noppes.npcs.NBTTags; - - import noppes.npcs.controllers.ScriptContainer; import noppes.npcs.controllers.data.ForgeDataScript; import org.apache.commons.lang3.StringUtils; diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java index 234c9b893..0683ef87c 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java @@ -5,11 +5,9 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; - import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.IGuiData; - import org.lwjgl.opengl.GL11; import java.util.HashMap; 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 6f7d9e1cd..2880df5d8 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptItem.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptItem.java @@ -1,16 +1,11 @@ package noppes.npcs.client.gui.script; -import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.packets.request.script.item.ItemScriptErrorPacket; import kamkeel.npcs.network.packets.request.script.item.ItemScriptPacket; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.CustomItems; - - import noppes.npcs.NBTTags; -import noppes.npcs.NoppesStringUtils; -import noppes.npcs.controllers.ScriptContainer; import noppes.npcs.scripted.item.ScriptCustomItem; import java.util.Date; diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java index 22973038d..153dea0c7 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptPlayers.java @@ -4,8 +4,6 @@ import kamkeel.npcs.network.packets.request.script.PlayerScriptPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.NBTTags; - - import noppes.npcs.controllers.ScriptContainer; import noppes.npcs.controllers.data.PlayerDataScript; diff --git a/src/main/java/noppes/npcs/client/gui/select/GuiSoundSelection.java b/src/main/java/noppes/npcs/client/gui/select/GuiSoundSelection.java index 97bb7af13..11573e2a4 100644 --- a/src/main/java/noppes/npcs/client/gui/select/GuiSoundSelection.java +++ b/src/main/java/noppes/npcs/client/gui/select/GuiSoundSelection.java @@ -7,10 +7,8 @@ import net.minecraft.client.audio.SoundHandler; import net.minecraft.client.audio.SoundRegistry; import net.minecraft.client.gui.GuiButton; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.StatCollector; import noppes.npcs.client.controllers.MusicController; import noppes.npcs.client.gui.util.*; -import noppes.npcs.entity.EntityNPCInterface; import java.util.ArrayList; import java.util.HashMap; diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java index 4e466040d..a98f2c329 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java @@ -4,7 +4,6 @@ import kamkeel.npcs.util.TextSplitter; import net.minecraft.client.gui.GuiScreen; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; -import noppes.npcs.client.gui.global.GuiNPCManageDialogs; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiDiagram.java b/src/main/java/noppes/npcs/client/gui/util/GuiDiagram.java index 8c8e839de..a831842e6 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiDiagram.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiDiagram.java @@ -1,8 +1,5 @@ package noppes.npcs.client.gui.util; -import java.awt.Point; -import java.util.*; - import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; @@ -10,6 +7,11 @@ import net.minecraft.client.gui.ScaledResolution; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; +import java.awt.*; +import java.util.List; +import java.util.Queue; +import java.util.*; + /** * Abstract GUI class for drawing diagrams with icons (nodes) and connections (arrows). * diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiEffectBar.java b/src/main/java/noppes/npcs/client/gui/util/GuiEffectBar.java index 262ff9d0a..96b78fc59 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiEffectBar.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiEffectBar.java @@ -1,17 +1,18 @@ package noppes.npcs.client.gui.util; -import java.util.ArrayList; -import java.util.List; -import noppes.npcs.client.ClientCacheHandler; -import noppes.npcs.client.renderer.ImageData; -import noppes.npcs.controllers.data.CustomEffect; -import noppes.npcs.controllers.data.PlayerEffect; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; +import noppes.npcs.client.ClientCacheHandler; +import noppes.npcs.client.renderer.ImageData; +import noppes.npcs.controllers.data.CustomEffect; +import noppes.npcs.controllers.data.PlayerEffect; import org.lwjgl.opengl.GL11; +import java.util.ArrayList; +import java.util.List; + public class GuiEffectBar extends GuiScreen { public int x, y, width, height; public int scrollY = 0; // Tracks vertical scrolling diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface2.java b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface2.java index a987fe826..da766c681 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface2.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface2.java @@ -1,12 +1,9 @@ package noppes.npcs.client.gui.util; -import net.minecraft.client.gui.FontRenderer; import net.minecraft.util.ResourceLocation; import noppes.npcs.entity.EntityNPCInterface; import org.lwjgl.opengl.GL11; -import java.util.List; - public abstract class GuiNPCInterface2 extends GuiNPCInterface { private ResourceLocation background = new ResourceLocation("customnpcs:textures/gui/menubg.png"); diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNpcMenu.java b/src/main/java/noppes/npcs/client/gui/util/GuiNpcMenu.java index 70492f9cb..10be5d5d8 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNpcMenu.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNpcMenu.java @@ -10,10 +10,8 @@ import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.util.StatCollector; import noppes.npcs.CustomNpcs; - import noppes.npcs.client.NoppesUtil; import noppes.npcs.constants.EnumGuiType; - import noppes.npcs.entity.EntityNPCInterface; import org.lwjgl.input.Keyboard; diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNpcSquareButton.java b/src/main/java/noppes/npcs/client/gui/util/GuiNpcSquareButton.java index 8132e2eaa..072f64c30 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNpcSquareButton.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNpcSquareButton.java @@ -5,8 +5,6 @@ import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.RenderHelper; import org.lwjgl.opengl.GL11; -import static noppes.npcs.client.gui.player.inventory.GuiCNPCInventory.specialIcons; - public class GuiNpcSquareButton extends GuiNpcButton { // Fixed height for the text button portion. diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiToggleButton.java b/src/main/java/noppes/npcs/client/gui/util/GuiToggleButton.java index 14b5970b9..c2e0506af 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiToggleButton.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiToggleButton.java @@ -2,7 +2,6 @@ package noppes.npcs.client.gui.util; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/noppes/npcs/client/model/blocks/barrel/ModelBarrel.java b/src/main/java/noppes/npcs/client/model/blocks/barrel/ModelBarrel.java index 6c1a2692f..c8506d465 100644 --- a/src/main/java/noppes/npcs/client/model/blocks/barrel/ModelBarrel.java +++ b/src/main/java/noppes/npcs/client/model/blocks/barrel/ModelBarrel.java @@ -3,7 +3,6 @@ package noppes.npcs.client.model.blocks.barrel; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelBox; import net.minecraft.client.model.ModelRenderer; -import net.minecraft.entity.Entity; public class ModelBarrel extends ModelBase { private final ModelRenderer Wall; 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 fdf31d224..62038fa9f 100644 --- a/src/main/java/noppes/npcs/client/model/util/Model2DRenderer.java +++ b/src/main/java/noppes/npcs/client/model/util/Model2DRenderer.java @@ -5,7 +5,6 @@ import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; import net.minecraft.client.renderer.GLAllocation; -import net.minecraft.client.renderer.ItemRenderer; import net.minecraft.client.renderer.Tessellator; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java b/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java index 82da923bb..9ccd98016 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java @@ -19,7 +19,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.MathHelper; import net.minecraftforge.client.event.RenderPlayerEvent; import noppes.npcs.client.ClientCacheHandler; -import noppes.npcs.client.model.ModelMPM; import noppes.npcs.controllers.data.SkinOverlay; import org.lwjgl.opengl.GL11; import org.lwjgl.util.glu.Project; diff --git a/src/main/java/noppes/npcs/client/renderer/blocks/BlockBeamRenderer.java b/src/main/java/noppes/npcs/client/renderer/blocks/BlockBeamRenderer.java index b734a48dd..60e9b5d3c 100644 --- a/src/main/java/noppes/npcs/client/renderer/blocks/BlockBeamRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/blocks/BlockBeamRenderer.java @@ -7,8 +7,8 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import noppes.npcs.CustomItems; import noppes.npcs.blocks.BlockRotated; -import noppes.npcs.blocks.tiles.TileVariant; import noppes.npcs.blocks.tiles.TileShelf; +import noppes.npcs.blocks.tiles.TileVariant; import noppes.npcs.client.model.blocks.ModelBeam; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; diff --git a/src/main/java/noppes/npcs/client/renderer/blocks/BlockCarpentryBenchRenderer.java b/src/main/java/noppes/npcs/client/renderer/blocks/BlockCarpentryBenchRenderer.java index 3b0c40a03..49c61c0b6 100644 --- a/src/main/java/noppes/npcs/client/renderer/blocks/BlockCarpentryBenchRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/blocks/BlockCarpentryBenchRenderer.java @@ -11,10 +11,9 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.world.IBlockAccess; import noppes.npcs.CustomItems; import noppes.npcs.blocks.BlockCarpentryBench; -import noppes.npcs.blocks.tiles.TileBlockAnvil; import noppes.npcs.client.model.blocks.ModelAnvil; -import noppes.npcs.client.model.blocks.legacy.ModelLegacyAnvil; import noppes.npcs.client.model.blocks.ModelCarpentryBench; +import noppes.npcs.client.model.blocks.legacy.ModelLegacyAnvil; import noppes.npcs.client.model.blocks.legacy.ModelLegacyCarpentryBench; import noppes.npcs.config.ConfigClient; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/noppes/npcs/client/renderer/blocks/BlockLanternRenderer.java b/src/main/java/noppes/npcs/client/renderer/blocks/BlockLanternRenderer.java index 842f71a1b..57e4da380 100644 --- a/src/main/java/noppes/npcs/client/renderer/blocks/BlockLanternRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/blocks/BlockLanternRenderer.java @@ -15,8 +15,8 @@ import noppes.npcs.blocks.tiles.TileLamp; import noppes.npcs.client.model.blocks.lantern.LanternCeiling; import noppes.npcs.client.model.blocks.lantern.LanternFloor; import noppes.npcs.client.model.blocks.lantern.LanternWall; -import noppes.npcs.client.model.blocks.legacy.ModelLegacyLantern; import noppes.npcs.client.model.blocks.legacy.ModelLegacyCeiling; +import noppes.npcs.client.model.blocks.legacy.ModelLegacyLantern; import noppes.npcs.client.model.blocks.legacy.ModelLegacyWall; import noppes.npcs.config.ConfigClient; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/noppes/npcs/client/renderer/blocks/BlockScriptedRenderer.java b/src/main/java/noppes/npcs/client/renderer/blocks/BlockScriptedRenderer.java index 4148da831..c6a48e3bc 100644 --- a/src/main/java/noppes/npcs/client/renderer/blocks/BlockScriptedRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/blocks/BlockScriptedRenderer.java @@ -4,7 +4,10 @@ import cpw.mods.fml.client.registry.RenderingRegistry; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemBlock; diff --git a/src/main/java/noppes/npcs/client/renderer/blocks/BlockShelfRenderer.java b/src/main/java/noppes/npcs/client/renderer/blocks/BlockShelfRenderer.java index 8e29769a6..ef4cd98db 100644 --- a/src/main/java/noppes/npcs/client/renderer/blocks/BlockShelfRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/blocks/BlockShelfRenderer.java @@ -7,8 +7,8 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import noppes.npcs.CustomItems; import noppes.npcs.blocks.BlockRotated; -import noppes.npcs.blocks.tiles.TileVariant; import noppes.npcs.blocks.tiles.TileShelf; +import noppes.npcs.blocks.tiles.TileVariant; import noppes.npcs.client.model.blocks.ModelShelf; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; diff --git a/src/main/java/noppes/npcs/client/renderer/blocks/BlockWallBannerRenderer.java b/src/main/java/noppes/npcs/client/renderer/blocks/BlockWallBannerRenderer.java index b578fb8b2..ec0db4379 100644 --- a/src/main/java/noppes/npcs/client/renderer/blocks/BlockWallBannerRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/blocks/BlockWallBannerRenderer.java @@ -9,7 +9,9 @@ import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.init.Blocks; -import net.minecraft.item.*; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; diff --git a/src/main/java/noppes/npcs/client/renderer/items/ItemBannerRenderer.java b/src/main/java/noppes/npcs/client/renderer/items/ItemBannerRenderer.java index dad55ad1f..c64393181 100644 --- a/src/main/java/noppes/npcs/client/renderer/items/ItemBannerRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/items/ItemBannerRenderer.java @@ -6,7 +6,6 @@ import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.item.ItemStack; import net.minecraftforge.client.IItemRenderer; import noppes.npcs.client.renderer.blocks.BlockBannerRenderer; -import noppes.npcs.client.renderer.blocks.BlockShortLampRenderer; import noppes.npcs.config.ConfigClient; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/noppes/npcs/client/renderer/items/ItemCouchWoolRenderer.java b/src/main/java/noppes/npcs/client/renderer/items/ItemCouchWoolRenderer.java index 928916bae..481dcc4ef 100644 --- a/src/main/java/noppes/npcs/client/renderer/items/ItemCouchWoolRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/items/ItemCouchWoolRenderer.java @@ -1,15 +1,15 @@ package noppes.npcs.client.renderer.items; +import kamkeel.npcs.util.ColorUtil; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.item.ItemStack; import net.minecraftforge.client.IItemRenderer; import noppes.npcs.client.renderer.blocks.BlockCouchWoolRenderer; import noppes.npcs.client.renderer.blocks.BlockRendererInterface; -import org.lwjgl.opengl.GL11; import noppes.npcs.client.renderer.blocks.BlockTallLampRenderer; import noppes.npcs.config.ConfigClient; -import kamkeel.npcs.util.ColorUtil; +import org.lwjgl.opengl.GL11; public class ItemCouchWoolRenderer implements IItemRenderer { diff --git a/src/main/java/noppes/npcs/client/renderer/items/ItemShortLampRenderer.java b/src/main/java/noppes/npcs/client/renderer/items/ItemShortLampRenderer.java index aaa98ab1c..b413c722f 100644 --- a/src/main/java/noppes/npcs/client/renderer/items/ItemShortLampRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/items/ItemShortLampRenderer.java @@ -1,14 +1,9 @@ package noppes.npcs.client.renderer.items; import kamkeel.npcs.util.ColorUtil; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.item.ItemStack; import net.minecraftforge.client.IItemRenderer; -import noppes.npcs.client.renderer.blocks.BlockRendererInterface; import noppes.npcs.client.renderer.blocks.BlockShortLampRenderer; -import noppes.npcs.client.renderer.blocks.BlockTallLampRenderer; -import noppes.npcs.config.ConfigClient; import org.lwjgl.opengl.GL11; public class ItemShortLampRenderer implements IItemRenderer { diff --git a/src/main/java/noppes/npcs/client/renderer/items/ItemTallLampRenderer.java b/src/main/java/noppes/npcs/client/renderer/items/ItemTallLampRenderer.java index 5ce2cfac1..2b891aa1a 100644 --- a/src/main/java/noppes/npcs/client/renderer/items/ItemTallLampRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/items/ItemTallLampRenderer.java @@ -5,7 +5,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.item.ItemStack; import net.minecraftforge.client.IItemRenderer; -import noppes.npcs.client.renderer.blocks.BlockCouchWoolRenderer; import noppes.npcs.client.renderer.blocks.BlockRendererInterface; import noppes.npcs.client.renderer.blocks.BlockTallLampRenderer; import noppes.npcs.config.ConfigClient; diff --git a/src/main/java/noppes/npcs/client/renderer/items/NpcItemToolRenderer.java b/src/main/java/noppes/npcs/client/renderer/items/NpcItemToolRenderer.java index 9b7a85885..2b79acdf9 100644 --- a/src/main/java/noppes/npcs/client/renderer/items/NpcItemToolRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/items/NpcItemToolRenderer.java @@ -10,12 +10,9 @@ import net.minecraft.util.IIcon; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.IItemRenderer; import noppes.npcs.items.ItemNpcTool; -import noppes.npcs.items.ItemRenderInterface; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; -import static noppes.npcs.items.ItemNpcTool.BRUSH_COLOR_TAG; - public class NpcItemToolRenderer implements IItemRenderer { // Textures for the assembled paintbrush parts: diff --git a/src/main/java/noppes/npcs/constants/EnumGuiType.java b/src/main/java/noppes/npcs/constants/EnumGuiType.java index 16927bacc..b95544a8a 100644 --- a/src/main/java/noppes/npcs/constants/EnumGuiType.java +++ b/src/main/java/noppes/npcs/constants/EnumGuiType.java @@ -1,11 +1,5 @@ package noppes.npcs.constants; -import noppes.npcs.quests.QuestItem; -import noppes.npcs.roles.companion.CompanionTrader; -import noppes.npcs.scripted.ScriptBlock; - -import javax.swing.border.Border; - public enum EnumGuiType { MainMenuDisplay, MainMenuInv, diff --git a/src/main/java/noppes/npcs/containers/ContainerAnvilRepair.java b/src/main/java/noppes/npcs/containers/ContainerAnvilRepair.java index 9230ed884..4b46ccdfa 100644 --- a/src/main/java/noppes/npcs/containers/ContainerAnvilRepair.java +++ b/src/main/java/noppes/npcs/containers/ContainerAnvilRepair.java @@ -3,12 +3,7 @@ package noppes.npcs.containers; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.inventory.InventoryCraftResult; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; +import net.minecraft.inventory.*; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import noppes.npcs.api.handler.data.IAnvilRecipe; diff --git a/src/main/java/noppes/npcs/controllers/LinkedItemController.java b/src/main/java/noppes/npcs/controllers/LinkedItemController.java index 93d1ebe42..117f497b5 100644 --- a/src/main/java/noppes/npcs/controllers/LinkedItemController.java +++ b/src/main/java/noppes/npcs/controllers/LinkedItemController.java @@ -7,7 +7,9 @@ import noppes.npcs.CustomNpcs; import noppes.npcs.LogWriter; import noppes.npcs.api.handler.data.ILinkedItem; import noppes.npcs.api.item.IItemStack; -import noppes.npcs.controllers.data.*; +import noppes.npcs.controllers.data.INpcScriptHandler; +import noppes.npcs.controllers.data.LinkedItem; +import noppes.npcs.controllers.data.LinkedItemScript; import noppes.npcs.util.NBTJsonUtil; import java.io.*; diff --git a/src/main/java/noppes/npcs/controllers/ScriptController.java b/src/main/java/noppes/npcs/controllers/ScriptController.java index 73b872e8f..4217f8668 100644 --- a/src/main/java/noppes/npcs/controllers/ScriptController.java +++ b/src/main/java/noppes/npcs/controllers/ScriptController.java @@ -4,7 +4,6 @@ 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.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagString; @@ -25,7 +24,10 @@ import javax.script.ScriptContext; import javax.script.ScriptEngine; import javax.script.ScriptEngineFactory; import javax.script.ScriptEngineManager; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; import java.util.*; import static noppes.npcs.util.CustomNPCsThreader.customNPCThread; diff --git a/src/main/java/noppes/npcs/controllers/data/EffectScript.java b/src/main/java/noppes/npcs/controllers/data/EffectScript.java index 16f8f1e63..f27232554 100644 --- a/src/main/java/noppes/npcs/controllers/data/EffectScript.java +++ b/src/main/java/noppes/npcs/controllers/data/EffectScript.java @@ -10,10 +10,8 @@ import noppes.npcs.config.ConfigScript; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.ScriptContainer; import noppes.npcs.controllers.ScriptController; -import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.event.PlayerEvent; -import javax.script.ScriptEngine; import java.io.IOException; import java.util.*; diff --git a/src/main/java/noppes/npcs/controllers/data/LinkedItemScript.java b/src/main/java/noppes/npcs/controllers/data/LinkedItemScript.java index 4c46a4e32..c88b880e2 100644 --- a/src/main/java/noppes/npcs/controllers/data/LinkedItemScript.java +++ b/src/main/java/noppes/npcs/controllers/data/LinkedItemScript.java @@ -10,10 +10,7 @@ import noppes.npcs.config.ConfigScript; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.ScriptContainer; import noppes.npcs.controllers.ScriptController; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.event.PlayerEvent; -import javax.script.ScriptEngine; import java.io.IOException; import java.util.*; diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerEffect.java b/src/main/java/noppes/npcs/controllers/data/PlayerEffect.java index 6a02b4e06..45aa535f3 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerEffect.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerEffect.java @@ -1,7 +1,6 @@ package noppes.npcs.controllers.data; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.api.entity.IPlayer; import noppes.npcs.api.handler.data.IPlayerEffect; import noppes.npcs.controllers.CustomEffectController; diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerEffectData.java b/src/main/java/noppes/npcs/controllers/data/PlayerEffectData.java index 2675cd74e..93f69483f 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerEffectData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerEffectData.java @@ -2,6 +2,7 @@ package noppes.npcs.controllers.data; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; + import java.util.HashSet; import java.util.Iterator; import java.util.Map; diff --git a/src/main/java/noppes/npcs/controllers/data/Quest.java b/src/main/java/noppes/npcs/controllers/data/Quest.java index 0643b20c9..4bd22e5ff 100644 --- a/src/main/java/noppes/npcs/controllers/data/Quest.java +++ b/src/main/java/noppes/npcs/controllers/data/Quest.java @@ -4,7 +4,10 @@ import kamkeel.npcs.network.packets.data.QuestCompletionPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.*; +import noppes.npcs.ICompatibilty; +import noppes.npcs.NoppesUtilPlayer; +import noppes.npcs.NpcMiscInventory; +import noppes.npcs.VersionCompatibility; import noppes.npcs.api.IContainer; import noppes.npcs.api.entity.IPlayer; import noppes.npcs.api.handler.data.*; @@ -13,14 +16,9 @@ import noppes.npcs.constants.EnumQuestRepeat; import noppes.npcs.constants.EnumQuestType; import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.controllers.QuestController; +import noppes.npcs.quests.*; import noppes.npcs.scripted.CustomNPCsException; import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.quests.QuestDialog; -import noppes.npcs.quests.QuestInterface; -import noppes.npcs.quests.QuestItem; -import noppes.npcs.quests.QuestKill; -import noppes.npcs.quests.QuestLocation; -import noppes.npcs.quests.QuestManual; public class Quest implements ICompatibilty, IQuest { public int version = VersionCompatibility.ModRev; diff --git a/src/main/java/noppes/npcs/controllers/data/RecipeAnvil.java b/src/main/java/noppes/npcs/controllers/data/RecipeAnvil.java index 02f7919a7..2b6291bd8 100644 --- a/src/main/java/noppes/npcs/controllers/data/RecipeAnvil.java +++ b/src/main/java/noppes/npcs/controllers/data/RecipeAnvil.java @@ -5,7 +5,6 @@ import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.NoppesUtilServer; import noppes.npcs.api.handler.data.IAnvilRecipe; -import noppes.npcs.controllers.data.Availability; public class RecipeAnvil implements IAnvilRecipe { public int id = -1; diff --git a/src/main/java/noppes/npcs/quests/QuestManual.java b/src/main/java/noppes/npcs/quests/QuestManual.java index 9beb70a66..2bac92bef 100644 --- a/src/main/java/noppes/npcs/quests/QuestManual.java +++ b/src/main/java/noppes/npcs/quests/QuestManual.java @@ -2,7 +2,6 @@ package noppes.npcs.quests; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.StatCollector; import noppes.npcs.NBTTags; import noppes.npcs.NoppesUtilServer; import noppes.npcs.api.handler.data.IQuestObjective; diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index e68dde801..bda38006c 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -1,7 +1,6 @@ package noppes.npcs.scripted; import cpw.mods.fml.common.eventhandler.EventBus; -import cpw.mods.fml.relauncher.Side; import foxz.command.ScriptedCommand; import net.minecraft.block.Block; import net.minecraft.command.CommandHandler; @@ -31,7 +30,6 @@ import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraft.world.biome.BiomeGenBase; import noppes.npcs.CustomNpcs; -import noppes.npcs.EventHooks; import noppes.npcs.NoppesUtilServer; import noppes.npcs.api.*; import noppes.npcs.api.entity.ICustomNpc; @@ -50,7 +48,10 @@ import noppes.npcs.config.ConfigScript; import noppes.npcs.constants.EnumAnimationPart; import noppes.npcs.containers.ContainerNpcInterface; import noppes.npcs.controllers.*; -import noppes.npcs.controllers.data.*; +import noppes.npcs.controllers.data.Animation; +import noppes.npcs.controllers.data.Frame; +import noppes.npcs.controllers.data.FramePart; +import noppes.npcs.controllers.data.SkinOverlay; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.entity.EntityProjectile; diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index d19a2d27d..9921cf226 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -7,15 +7,11 @@ import net.minecraft.entity.effect.EntityLightningBolt; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTBase.NBTPrimitive; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagString; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntitySign; import net.minecraft.util.*; -import net.minecraft.util.math.BlockPos; import net.minecraft.world.WorldServer; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.BlockSnapshot; @@ -30,7 +26,6 @@ import noppes.npcs.api.handler.data.ISound; import noppes.npcs.api.item.IItemStack; import noppes.npcs.api.scoreboard.IScoreboard; import noppes.npcs.blocks.tiles.TileBigSign; -import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.ServerCloneController; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.scoreboard.ScriptScoreboard; diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index 86485c5b6..0ce931c0e 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -18,7 +18,10 @@ import net.minecraft.util.ChatStyle; import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.WorldSettings; -import noppes.npcs.*; +import noppes.npcs.CustomNpcsPermissions; +import noppes.npcs.NoppesStringUtils; +import noppes.npcs.NoppesUtilPlayer; +import noppes.npcs.NoppesUtilServer; import noppes.npcs.api.*; import noppes.npcs.api.entity.IEntity; import noppes.npcs.api.entity.IPlayer; diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiItemSlot.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiItemSlot.java index b33e2f204..8e48a585b 100644 --- a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiItemSlot.java +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiItemSlot.java @@ -1,11 +1,8 @@ package noppes.npcs.scripted.gui; import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.api.gui.IItemSlot; import noppes.npcs.api.item.IItemStack; -import noppes.npcs.scripted.NpcAPI; public class ScriptGuiItemSlot extends ScriptGuiComponent implements IItemSlot { IItemStack stack; diff --git a/src/main/java/noppes/npcs/scripted/item/ScriptItemStack.java b/src/main/java/noppes/npcs/scripted/item/ScriptItemStack.java index 5b15da052..11920d809 100644 --- a/src/main/java/noppes/npcs/scripted/item/ScriptItemStack.java +++ b/src/main/java/noppes/npcs/scripted/item/ScriptItemStack.java @@ -16,8 +16,6 @@ import net.minecraftforge.common.IPlantable; import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.api.INbt; import noppes.npcs.api.item.IItemStack; -import noppes.npcs.controllers.LinkedItemController; -import noppes.npcs.controllers.data.LinkedItem; import noppes.npcs.items.ItemLinked; import noppes.npcs.items.ItemScripted; import noppes.npcs.scripted.CustomNPCsException; diff --git a/src/main/java/tconstruct/client/tabs/InventoryTabCustomNpc.java b/src/main/java/tconstruct/client/tabs/InventoryTabCustomNpc.java index 9b845c5f5..983c2d495 100644 --- a/src/main/java/tconstruct/client/tabs/InventoryTabCustomNpc.java +++ b/src/main/java/tconstruct/client/tabs/InventoryTabCustomNpc.java @@ -1,6 +1,5 @@ package tconstruct.client.tabs; -import kamkeel.npcs.addon.client.DBCClient; import net.minecraft.client.Minecraft; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; From 83c16ae419dea3eeb97f36c4973acef6a697a7c6 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 20 Feb 2025 21:44:15 -0500 Subject: [PATCH 25/59] Fine Tuning Profile Controller Instance --- .../command/profile/CommandProfileAdmin.java | 20 +++---- .../command/profile/CommandProfileChange.java | 2 +- .../command/profile/CommandProfileCreate.java | 4 +- .../command/profile/CommandProfileList.java | 2 +- .../command/profile/CommandProfileRemove.java | 2 +- .../command/profile/CommandProfileRename.java | 8 +-- .../npcs/controllers/ProfileController.java | 60 +++++++++---------- .../npcs/controllers/data/PlayerData.java | 4 +- 8 files changed, 51 insertions(+), 51 deletions(-) diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java index ed6001775..c66649112 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java @@ -51,7 +51,7 @@ public class CommandProfileAdmin extends CommandProfileBase { return; } boolean temporary = (args.length >= 5 && args[4].equalsIgnoreCase("temp")); - ProfileOperation result = ProfileController.cloneSlot(sourcePlayer, sourceSlot, destinationSlot, temporary); + ProfileOperation result = ProfileController.Instance.cloneSlot(sourcePlayer, sourceSlot, destinationSlot, temporary); if(result.getResult() == EnumProfileOperation.SUCCESS) { sendResult(sender, "Successfully cloned slot %d from %s to slot %d for %s.", sourceSlot, sourcePlayer, destinationSlot, destinationPlayer); } else if(result.getResult() == EnumProfileOperation.LOCKED) { @@ -81,7 +81,7 @@ public class CommandProfileAdmin extends CommandProfileBase { sendError(sender, "Slot ID must be a number."); return; } - ProfileOperation result = ProfileController.removeSlot(targetPlayer, slotId); + ProfileOperation result = ProfileController.Instance.removeSlot(targetPlayer, slotId); if(result.getResult() == EnumProfileOperation.SUCCESS) { sendResult(sender, "Successfully removed slot %d from %s.", slotId, targetPlayer); } else if(result.getResult() == EnumProfileOperation.LOCKED) { @@ -110,7 +110,7 @@ public class CommandProfileAdmin extends CommandProfileBase { sendError(sender, "Slot ID must be a number."); return; } - ProfileOperation result = ProfileController.changeSlot(targetPlayer, newSlotId); + ProfileOperation result = ProfileController.Instance.changeSlot(targetPlayer, newSlotId); if(result.getResult() == EnumProfileOperation.SUCCESS) { sendResult(sender, "Successfully changed %s's active slot to %d.", targetPlayer, newSlotId); } else if(result.getResult() == EnumProfileOperation.LOCKED) { @@ -132,12 +132,12 @@ public class CommandProfileAdmin extends CommandProfileBase { return; } String targetPlayer = args[0]; - Profile profile = ProfileController.getProfile(targetPlayer); + Profile profile = ProfileController.Instance.getProfile(targetPlayer); if(profile == null) { sendError(sender, "Profile not found for player: %s", targetPlayer); return; } - ProfileOperation result = ProfileController.createSlotInternal(profile); + ProfileOperation result = ProfileController.Instance.createSlotInternal(profile); if(result.getResult() == EnumProfileOperation.SUCCESS) { sendResult(sender, "New slot created successfully for %s.", targetPlayer); } else if(result.getResult() == EnumProfileOperation.LOCKED) { @@ -218,11 +218,11 @@ public class CommandProfileAdmin extends CommandProfileBase { } profile.getSlots().get(slotId).setName(newName); if(profile.getPlayer() != null) { - ProfileController.save(profile.player, profile); + ProfileController.Instance.save(profile.player, profile); } else { - UUID uuid = ProfileController.getUUIDFromUsername(targetPlayer); + UUID uuid = ProfileController.Instance.getUUIDFromUsername(targetPlayer); if(uuid != null) - ProfileController.saveOffline(profile, uuid); + ProfileController.Instance.saveOffline(profile, uuid); } sendResult(sender, "Successfully renamed slot %d for %s to '%s'.", slotId, targetPlayer, newName); } @@ -239,7 +239,7 @@ public class CommandProfileAdmin extends CommandProfileBase { String targetPlayer = args[0]; String backupFileName = args[1] + ".dat"; - Profile profile = ProfileController.getProfile(targetPlayer); + Profile profile = ProfileController.Instance.getProfile(targetPlayer); if(profile == null || profile.player == null) return; @@ -249,7 +249,7 @@ public class CommandProfileAdmin extends CommandProfileBase { sendError(sender, "Backup file %s not found for player %s.", backupFileName, targetPlayer); return; } - boolean success = ProfileController.rollbackProfile(targetPlayer, backupFile); + boolean success = ProfileController.Instance.rollbackProfile(targetPlayer, backupFile); if(success) { sendResult(sender, "Successfully rolled back %s's profile to backup %s.", targetPlayer, backupFileName); } else { diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java index 30f5ca0f9..b7373aa34 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileChange.java @@ -50,7 +50,7 @@ public class CommandProfileChange extends CommandProfileBase { return; } EntityPlayer player = (EntityPlayer)sender; - ProfileOperation result = ProfileController.changeSlot(player, slotId); + ProfileOperation result = ProfileController.Instance.changeSlot(player, slotId); if(result.getResult() == EnumProfileOperation.SUCCESS) { sendResult(sender, "Successfully changed profile slot to %d.", slotId); } else if(result.getResult() == EnumProfileOperation.LOCKED) { diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileCreate.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileCreate.java index 70e6a179a..6b06f266a 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileCreate.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileCreate.java @@ -39,11 +39,11 @@ public class CommandProfileCreate extends CommandProfileBase { return; } EntityPlayer player = (EntityPlayer)sender; - if(ProfileController.getProfile(player) == null) { + if(ProfileController.Instance.getProfile(player) == null) { sendError(sender, "Profile not found."); return; } - ProfileOperation result = ProfileController.createSlotInternal(ProfileController.getProfile(player)); + ProfileOperation result = ProfileController.Instance.createSlotInternal(ProfileController.Instance.getProfile(player)); if(result.getResult() == EnumProfileOperation.SUCCESS) { sendResult(sender, "New profile slot created successfully."); } else if(result.getResult() == EnumProfileOperation.LOCKED) { diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java index 0e0af6dee..7c15bc548 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java @@ -36,7 +36,7 @@ public class CommandProfileList extends CommandProfileBase { return; } EntityPlayer player = (EntityPlayer)sender; - Profile profile = ProfileController.getProfile(player); + Profile profile = ProfileController.Instance.getProfile(player); if(profile == null) { sendError(sender, "Profile not found."); return; diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java index 892c9e592..a80d76f8b 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRemove.java @@ -50,7 +50,7 @@ public class CommandProfileRemove extends CommandProfileBase { return; } EntityPlayer player = (EntityPlayer)sender; - ProfileOperation result = ProfileController.removeSlot(player, slotId); + ProfileOperation result = ProfileController.Instance.removeSlot(player, slotId); if(result.getResult() == EnumProfileOperation.SUCCESS) { sendResult(sender, "Successfully removed slot %d from your profile.", slotId); } else if(result.getResult() == EnumProfileOperation.LOCKED) { diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java index f234c1110..50108d7b1 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileRename.java @@ -56,16 +56,16 @@ public class CommandProfileRename extends CommandProfileBase { return; } EntityPlayer player = (EntityPlayer)sender; - if(ProfileController.getProfile(player) == null) { + if(ProfileController.Instance.getProfile(player) == null) { sendError(sender, "Profile not found."); return; } - if(!ProfileController.getProfile(player).getSlots().containsKey(slotId)) { + if(!ProfileController.Instance.getProfile(player).getSlots().containsKey(slotId)) { sendError(sender, "Slot %d not found in your profile.", slotId); return; } - ProfileController.getProfile(player).getSlots().get(slotId).setName(newName); - ProfileController.save(player, ProfileController.getProfile(player)); + ProfileController.Instance.getProfile(player).getSlots().get(slotId).setName(newName); + ProfileController.Instance.save(player, ProfileController.Instance.getProfile(player)); sendResult(sender, "Successfully renamed slot %d to '%s'.", slotId, newName); } } diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index 9e3278c4d..09526352e 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -109,7 +109,7 @@ public class ProfileController implements IProfileController { } } - public static synchronized NBTTagCompound load(EntityPlayer player) { + public synchronized NBTTagCompound load(EntityPlayer player) { File saveDir = getProfileDir(); String filename = player.getUniqueID().toString() + ".dat"; try { @@ -123,7 +123,7 @@ public class ProfileController implements IProfileController { return new NBTTagCompound(); } - public static synchronized NBTTagCompound load(UUID uuid) { + public synchronized NBTTagCompound load(UUID uuid) { File saveDir = getProfileDir(); String filename = uuid.toString() + ".dat"; try { @@ -137,7 +137,7 @@ public class ProfileController implements IProfileController { return new NBTTagCompound(); } - public static synchronized void saveOffline(Profile profile, UUID uuid) { + public synchronized void saveOffline(Profile profile, UUID uuid) { profile.setLocked(true); CustomNPCsThreader.customNPCThread.execute(() -> { final NBTTagCompound compound = profile.writeToNBT(); @@ -158,7 +158,7 @@ public class ProfileController implements IProfileController { }); } - public static synchronized void save(EntityPlayer player, Profile profile) { + public synchronized void save(EntityPlayer player, Profile profile) { profile.setLocked(true); CustomNPCsThreader.customNPCThread.execute(() -> { final NBTTagCompound compound = profile.writeToNBT(); @@ -183,7 +183,7 @@ public class ProfileController implements IProfileController { }); } - private static void backupProfile(UUID uuid, NBTTagCompound compound) { + private void backupProfile(UUID uuid, NBTTagCompound compound) { try { File backupDir = new File(getBackupDir(), uuid.toString()); if (!backupDir.exists()) { @@ -204,7 +204,7 @@ public class ProfileController implements IProfileController { } } - public static boolean rollbackProfile(String username, File backupFile) { + public boolean rollbackProfile(String username, File backupFile) { UUID uuid = getUUIDFromUsername(username); if (uuid == null) return false; @@ -235,13 +235,13 @@ public class ProfileController implements IProfileController { } } - public static synchronized void logout(EntityPlayer player) { + public synchronized void logout(EntityPlayer player) { if (player != null) { activeProfiles.remove(player.getUniqueID()); } } - public static Profile getProfile(EntityPlayer player) { + public Profile getProfile(EntityPlayer player) { if (player == null) return null; if (!activeProfiles.containsKey(player.getUniqueID())) @@ -249,14 +249,14 @@ public class ProfileController implements IProfileController { return activeProfiles.get(player.getUniqueID()); } - public static Profile getProfile(UUID uuid) { + public Profile getProfile(UUID uuid) { if (activeProfiles.containsKey(uuid)) return activeProfiles.get(uuid); NBTTagCompound compound = load(uuid); return new Profile(null, compound); } - public static Profile getProfile(String username) { + public Profile getProfile(String username) { EntityPlayer player = getPlayer(username); if (player != null) { return getProfile(player); @@ -268,7 +268,7 @@ public class ProfileController implements IProfileController { } } - public static UUID getUUIDFromUsername(String username) { + public UUID getUUIDFromUsername(String username) { try { URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + username); HttpURLConnection con = (HttpURLConnection) url.openConnection(); @@ -302,7 +302,7 @@ public class ProfileController implements IProfileController { return null; } - private static int getNextAvailableTempSlot(Profile profile) { + private int getNextAvailableTempSlot(Profile profile) { int id = -1; while (profile.getSlots().containsKey(id)) { id--; @@ -310,7 +310,7 @@ public class ProfileController implements IProfileController { return id; } - private static ProfileOperation cloneSlotInternal(Profile profile, int sourceSlotId, int destinationSlotId, boolean temporary) { + private ProfileOperation cloneSlotInternal(Profile profile, int sourceSlotId, int destinationSlotId, boolean temporary) { if (profile.isLocked()) { return ProfileOperation.locked(MSG_PROFILE_LOCKED_CLONE); } @@ -339,14 +339,14 @@ public class ProfileController implements IProfileController { ISlot sourceSlot = profile.getSlots().get(sourceSlotId); Map newComponents = new HashMap<>(); for (String key : sourceSlot.getComponents().keySet()) { - newComponents.put(key, sourceSlot.getComponentData(key).copy()); + newComponents.put(key, (NBTTagCompound) sourceSlot.getComponentData(key).copy()); } Slot clonedSlot = new Slot(destinationSlotId, "Cloned Slot " + destinationSlotId, System.currentTimeMillis(), temporary, newComponents); profile.getSlots().put(destinationSlotId, clonedSlot); return ProfileOperation.success(MSG_CLONE_SUCCESS); } - private static ProfileOperation removeSlotInternal(Profile profile, int slotId) { + private ProfileOperation removeSlotInternal(Profile profile, int slotId) { if (profile.isLocked()) { return ProfileOperation.locked(MSG_PROFILE_LOCKED_REMOVE); } @@ -360,7 +360,7 @@ public class ProfileController implements IProfileController { return ProfileOperation.success(MSG_REMOVE_SUCCESS); } - public static ProfileOperation createSlotInternal(Profile profile) { + public ProfileOperation createSlotInternal(Profile profile) { if (profile.isLocked()) { return ProfileOperation.locked(MSG_PROFILE_LOCKED_CREATE); } @@ -386,7 +386,7 @@ public class ProfileController implements IProfileController { return ProfileOperation.success(MSG_NEW_SLOT_CREATED); } - private static ProfileOperation changeSlotInternal(Profile profile, int newSlotId) { + private ProfileOperation changeSlotInternal(Profile profile, int newSlotId) { if (profile.isLocked()) { return ProfileOperation.locked(MSG_PROFILE_LOCKED_CHANGE); } @@ -446,7 +446,7 @@ public class ProfileController implements IProfileController { return ProfileOperation.success(MSG_CHANGE_SUCCESS); } - public static ProfileOperation cloneSlot(EntityPlayer player, int sourceSlotId, int destinationSlotId, boolean temporary) { + public ProfileOperation cloneSlot(EntityPlayer player, int sourceSlotId, int destinationSlotId, boolean temporary) { Profile profile = getProfile(player); if (profile == null) return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); @@ -457,7 +457,7 @@ public class ProfileController implements IProfileController { return result; } - public static ProfileOperation cloneSlot(UUID uuid, int sourceSlotId, int destinationSlotId, boolean temporary) { + public ProfileOperation cloneSlot(UUID uuid, int sourceSlotId, int destinationSlotId, boolean temporary) { Profile profile = getProfile(uuid); if (profile == null) return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); @@ -471,7 +471,7 @@ public class ProfileController implements IProfileController { return result; } - public static ProfileOperation cloneSlot(String username, int sourceSlotId, int destinationSlotId, boolean temporary) { + public ProfileOperation cloneSlot(String username, int sourceSlotId, int destinationSlotId, boolean temporary) { Profile profile = getProfile(username); if (profile == null) return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); @@ -488,7 +488,7 @@ public class ProfileController implements IProfileController { return result; } - public static ProfileOperation removeSlot(EntityPlayer player, int slotId) { + public ProfileOperation removeSlot(EntityPlayer player, int slotId) { Profile profile = getProfile(player); if (profile == null) return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); @@ -499,7 +499,7 @@ public class ProfileController implements IProfileController { return result; } - public static ProfileOperation removeSlot(String username, int slotId) { + public ProfileOperation removeSlot(String username, int slotId) { Profile profile = getProfile(username); if (profile == null) return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); @@ -516,7 +516,7 @@ public class ProfileController implements IProfileController { return result; } - public static ProfileOperation changeSlot(EntityPlayer player, int newSlotId) { + public ProfileOperation changeSlot(EntityPlayer player, int newSlotId) { Profile profile = getProfile(player); if (profile == null) return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); @@ -526,7 +526,7 @@ public class ProfileController implements IProfileController { return result; } - public static ProfileOperation changeSlot(String username, int newSlotId) { + public ProfileOperation changeSlot(String username, int newSlotId) { Profile profile = getProfile(username); if (profile == null) return ProfileOperation.error(MSG_PLAYER_NOT_FOUND); @@ -556,13 +556,13 @@ public class ProfileController implements IProfileController { profile.getSlots().put(profile.getCurrentSlotId(), slot); } for (IProfileData profileData : profileTypes.values()) { - NBTTagCompound cloned = profileData.getCurrentNBT(player).copy(); + NBTTagCompound cloned = (NBTTagCompound) profileData.getCurrentNBT(player).copy(); slot.setComponentData(profileData.getTagName(), cloned); } slot.setLastLoaded(System.currentTimeMillis()); } - public static void loadSlotData(EntityPlayer player) { + public void loadSlotData(EntityPlayer player) { if (player == null || !activeProfiles.containsKey(player.getUniqueID())) return; Profile profile = activeProfiles.get(player.getUniqueID()); @@ -582,7 +582,7 @@ public class ProfileController implements IProfileController { } } - public static List getProfileInfo(EntityPlayer player, int slotId) { + public List getProfileInfo(EntityPlayer player, int slotId) { List infoList = new ArrayList<>(); Profile profile = getProfile(player); if (profile == null) @@ -608,7 +608,7 @@ public class ProfileController implements IProfileController { return infoList; } - public static boolean allowSlotPermission(EntityPlayer player) { + public boolean allowSlotPermission(EntityPlayer player) { Profile profile = getProfile(player); int currentSlots = profile.getSlots().size(); if (CustomNpcsPermissions.hasCustomPermission(player, "customnpcs.profile.max.*")) { @@ -627,7 +627,7 @@ public class ProfileController implements IProfileController { return currentSlots < highestAllowed; } - public static EntityPlayerMP getPlayer(String username) { + public EntityPlayerMP getPlayer(String username) { return MinecraftServer.getServer().getConfigurationManager().func_152612_a(username); } @@ -635,7 +635,7 @@ public class ProfileController implements IProfileController { public IProfile getProfile(IPlayer player) { if(player == null || player.getMCEntity() == null) return null; - return ProfileController.getProfile((EntityPlayer) player.getMCEntity()); + return getProfile((EntityPlayer) player.getMCEntity()); } @Override diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerData.java b/src/main/java/noppes/npcs/controllers/data/PlayerData.java index 027d10a24..041b15c0c 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerData.java @@ -376,9 +376,9 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData { public synchronized void save() { // Don't Save this is a Modification of a Profile's PlayerData - Profile profile = ProfileController.getProfile(UUID.fromString(uuid)); + Profile profile = ProfileController.Instance.getProfile(UUID.fromString(uuid)); if(profile != null && profile.currentSlotId != this.profileSlot){ - ProfileController.saveOffline(profile, UUID.fromString(uuid)); + ProfileController.Instance.saveOffline(profile, UUID.fromString(uuid)); return; } From 2141c5c4ca7a8f2abd17a263346ffabaf5480586 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 20 Feb 2025 22:19:21 -0500 Subject: [PATCH 26/59] Custom Quest Cooldowns / Shared Profile Cooldowns + Profile Packet Fixes --- src/api | 2 +- .../command/profile/CommandProfileAdmin.java | 4 +- .../request/profile/ProfileChangePacket.java | 2 +- .../request/profile/ProfileCreatePacket.java | 4 +- .../request/profile/ProfileGetInfoPacket.java | 4 +- .../request/profile/ProfileGetPacket.java | 2 +- .../request/profile/ProfileRemovePacket.java | 2 +- .../request/profile/ProfileRenamePacket.java | 6 +- .../java/noppes/npcs/ServerTickHandler.java | 2 +- .../npcs/constants/EnumQuestRepeat.java | 2 +- .../noppes/npcs/controllers/data/Quest.java | 139 +++++++++++++++--- 11 files changed, 135 insertions(+), 34 deletions(-) diff --git a/src/api b/src/api index 0d9abd56f..7b9e091a3 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit 0d9abd56f6f1ab8bdc7d5ce844a668df86f20bf3 +Subproject commit 7b9e091a309eef2be8a202dd0abcc3eb017df27c diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java index c66649112..3affe65ad 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java @@ -159,7 +159,7 @@ public class CommandProfileAdmin extends CommandProfileBase { return; } String targetPlayer = args[0]; - Profile profile = ProfileController.getProfile(targetPlayer); + Profile profile = ProfileController.Instance.getProfile(targetPlayer); if(profile == null) { sendError(sender, "Profile not found for player: %s", targetPlayer); return; @@ -203,7 +203,7 @@ public class CommandProfileAdmin extends CommandProfileBase { sendError(sender, "Invalid name. Only alphabetic characters and spaces are allowed."); return; } - Profile profile = ProfileController.getProfile(targetPlayer); + Profile profile = ProfileController.Instance.getProfile(targetPlayer); if(profile == null) { sendError(sender, "Profile not found for player: %s", targetPlayer); return; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileChangePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileChangePacket.java index 4b6579bd5..c6f88fb77 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileChangePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileChangePacket.java @@ -53,7 +53,7 @@ public final class ProfileChangePacket extends AbstractPacket { return; int slot = in.readInt(); - ProfileOperation operation = ProfileController.changeSlot(player, slot); + ProfileOperation operation = ProfileController.Instance.changeSlot(player, slot); // TODO: Check Operation and Send Message ProfileGetPacket.sendProfileNBT(player); diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java index 611546e06..60560ec79 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java @@ -45,8 +45,8 @@ public final class ProfileCreatePacket extends AbstractPacket { if (!(player instanceof EntityPlayerMP)) return; - Profile profile = ProfileController.getProfile(player); - ProfileOperation operation = ProfileController.createSlotInternal(profile); + Profile profile = ProfileController.Instance.getProfile(player); + ProfileOperation operation = ProfileController.Instance.createSlotInternal(profile); // TODO: Check Operation and Send Message ProfileGetPacket.sendProfileNBT(player); diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java index 81808afe3..43b2885a6 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java @@ -54,13 +54,13 @@ public final class ProfileGetInfoPacket extends AbstractPacket { NBTTagCompound compound = new NBTTagCompound(); compound.setBoolean("PROFILE_INFO", true); NBTTagList slotList = new NBTTagList(); - Profile profile = ProfileController.getProfile(player); + Profile profile = ProfileController.Instance.getProfile(player); if(profile != null){ for(ISlot slot : profile.getSlots().values()){ NBTTagCompound slotCompound = new NBTTagCompound(); NBTTagList infoList = new NBTTagList(); slotCompound.setInteger("ID", slot.getId()); - List profileInfo = ProfileController.getProfileInfo(player, slot.getId()); + List profileInfo = ProfileController.Instance.getProfileInfo(player, slot.getId()); for(InfoEntry infoEntry : profileInfo){ infoList.appendTag(infoEntry.writeToNBT()); } diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java index d03849b83..a37572db5 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java @@ -44,7 +44,7 @@ public final class ProfileGetPacket extends AbstractPacket { } public static void sendProfileNBT(EntityPlayer player){ - Profile profile = ProfileController.getProfile(player); + Profile profile = ProfileController.Instance.getProfile(player); NBTTagCompound compound = profile.writeToNBT(); compound.setBoolean("PROFILE", true); GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound); diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java index d7ae74c8c..6f8ff983c 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java @@ -53,7 +53,7 @@ public final class ProfileRemovePacket extends AbstractPacket { return; int slot = in.readInt(); - ProfileOperation operation = ProfileController.removeSlot(player, slot); + ProfileOperation operation = ProfileController.Instance.removeSlot(player, slot); // TODO: Check Operation and Send Message diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java index 945726b49..7322517d4 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java @@ -59,14 +59,14 @@ public final class ProfileRenamePacket extends AbstractPacket { int slot = in.readInt(); String newName = ByteBufUtils.readString(in); - Profile profile = ProfileController.getProfile(player); + Profile profile = ProfileController.Instance.getProfile(player); if(!profile.getSlots().containsKey(slot)) { // TODO: Check Operation and Send Message return; } - ProfileController.getProfile(player).getSlots().get(slot).setName(newName); - ProfileController.save(player, ProfileController.getProfile(player)); + ProfileController.Instance.getProfile(player).getSlots().get(slot).setName(newName); + ProfileController.Instance.save(player, ProfileController.Instance.getProfile(player)); ProfileGetPacket.sendProfileNBT(player); ProfileGetInfoPacket.sendProfileInfo(player); diff --git a/src/main/java/noppes/npcs/ServerTickHandler.java b/src/main/java/noppes/npcs/ServerTickHandler.java index e793e8db0..95d1332ba 100644 --- a/src/main/java/noppes/npcs/ServerTickHandler.java +++ b/src/main/java/noppes/npcs/ServerTickHandler.java @@ -54,7 +54,7 @@ public class ServerTickHandler { SyncController.syncPlayer(player); SyncController.syncEffects(player); - ProfileController.login(player); + ProfileController.Instance.login(player); } @SubscribeEvent diff --git a/src/main/java/noppes/npcs/constants/EnumQuestRepeat.java b/src/main/java/noppes/npcs/constants/EnumQuestRepeat.java index 954e4acd8..7cb4ecac5 100644 --- a/src/main/java/noppes/npcs/constants/EnumQuestRepeat.java +++ b/src/main/java/noppes/npcs/constants/EnumQuestRepeat.java @@ -1,5 +1,5 @@ package noppes.npcs.constants; public enum EnumQuestRepeat { - NONE, REPEATABLE, MCDAILY, MCWEEKLY, RLDAILY, RLWEEKLY; + NONE, REPEATABLE, MCDAILY, MCWEEKLY, RLDAILY, RLWEEKLY, MCCUSTOM, RLCUSTOM; } diff --git a/src/main/java/noppes/npcs/controllers/data/Quest.java b/src/main/java/noppes/npcs/controllers/data/Quest.java index 4bd22e5ff..7b0dad77b 100644 --- a/src/main/java/noppes/npcs/controllers/data/Quest.java +++ b/src/main/java/noppes/npcs/controllers/data/Quest.java @@ -1,16 +1,20 @@ package noppes.npcs.controllers.data; +import kamkeel.npcs.controllers.ProfileController; +import kamkeel.npcs.controllers.data.ISlot; +import kamkeel.npcs.controllers.data.Profile; +import kamkeel.npcs.controllers.data.Slot; import kamkeel.npcs.network.packets.data.QuestCompletionPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.ICompatibilty; -import noppes.npcs.NoppesUtilPlayer; -import noppes.npcs.NpcMiscInventory; -import noppes.npcs.VersionCompatibility; +import noppes.npcs.*; import noppes.npcs.api.IContainer; import noppes.npcs.api.entity.IPlayer; +import noppes.npcs.api.handler.IPlayerData; +import noppes.npcs.api.handler.IPlayerQuestData; import noppes.npcs.api.handler.data.*; +import noppes.npcs.config.ConfigMain; import noppes.npcs.constants.EnumQuestCompletion; import noppes.npcs.constants.EnumQuestRepeat; import noppes.npcs.constants.EnumQuestType; @@ -38,6 +42,9 @@ public class Quest implements ICompatibilty, IQuest { public QuestInterface questInterface = new QuestItem(); + public boolean profileShared = false; + public long customCooldown = 0; + public int rewardExp = 0; public NpcMiscInventory rewardItems = new NpcMiscInventory(9); public boolean randomReward = false; @@ -72,6 +79,9 @@ public class Quest implements ICompatibilty, IQuest { completion = EnumQuestCompletion.values()[compound.getInteger("QuestCompletion")]; repeat = EnumQuestRepeat.values()[compound.getInteger("QuestRepeat")]; + customCooldown = compound.getLong("CustomCooldown"); + profileShared = compound.getBoolean("ProfileShared"); + questInterface.readEntityFromNBT(compound); factionOptions.readFromNBT(compound.getCompoundTag("QuestFactionPoints")); @@ -114,6 +124,8 @@ public class Quest implements ICompatibilty, IQuest { compound.setTag("Rewards", rewardItems.getToNBT()); compound.setString("QuestCommand", command); compound.setBoolean("RandomReward", randomReward); + compound.setBoolean("ProfileShared", profileShared); + compound.setLong("CustomCooldown", customCooldown); compound.setInteger("QuestCompletion", completion.ordinal()); compound.setInteger("QuestRepeat", repeat.ordinal()); @@ -153,23 +165,96 @@ public class Quest implements ICompatibilty, IQuest { return quest; } - public long getTimeUntilRepeat(EntityPlayer player) { - long questTime = PlayerDataController.Instance.getPlayerData(player).getQuestData().getLastCompletedTime(this.id); + public long getTimeUntilRepeat(EntityPlayer player) { + if(profileShared && ConfigMain.ProfilesEnabled){ + Profile profile = ProfileController.Instance.getProfile(player); + IPlayer iPlayer = NoppesUtilServer.getIPlayer(player); + long timeRemaining = 0L; + for(ISlot slot : profile.getSlots().values()){ + IPlayerData playerData = ProfileController.Instance.getSlotPlayerData(iPlayer, slot.getId()); + IPlayerQuestData iPlayerQuestData = playerData.getQuestData(); + timeRemaining = Math.max(timeRemaining, getTimeUntilRepeatQuestData(player, iPlayerQuestData)); + } + return timeRemaining; + } + IPlayerQuestData questData = PlayerDataController.Instance.getPlayerData(player).getQuestData(); + return getTimeUntilRepeatQuestData(player, questData); + } - switch (repeat) { - case MCDAILY: - return Math.max(0, (questTime + 24000 - player.worldObj.getTotalWorldTime()) * 50); - case MCWEEKLY: - return Math.max(0, (questTime + 168000 - player.worldObj.getTotalWorldTime()) * 50); - case RLDAILY: - return Math.max(0, questTime + 86400000 - System.currentTimeMillis()); - case RLWEEKLY: - return Math.max(0, questTime + 604800000 - System.currentTimeMillis()); - } - return 0L; - } + public long getTimeUntilRepeatQuestData(EntityPlayer player, IPlayerQuestData questData){ + long questTime = questData.getLastCompletedTime(this.id); - @Override + switch (repeat) { + case MCDAILY: { + long now = player.worldObj.getTotalWorldTime(); + long allowedTicks = 24000; + // If questTime is in the future and the excess is greater than allowed, reset it. + if (questTime > now && (questTime - now) > allowedTicks) { + questTime = now; + questData.setLastCompletedTime(this.id, questTime); + } + long remainingTicks = questTime + allowedTicks - now; + return Math.max(0, remainingTicks * 50); + } + case MCWEEKLY: { + long now = player.worldObj.getTotalWorldTime(); + long allowedTicks = 168000; + if (questTime > now && (questTime - now) > allowedTicks) { + questTime = now; + questData.setLastCompletedTime(this.id, questTime); + } + long remainingTicks = questTime + allowedTicks - now; + return Math.max(0, remainingTicks * 50); + } + case RLDAILY: { + long now = System.currentTimeMillis(); + long allowedMillis = 86400000; + if (questTime > now && (questTime - now) > allowedMillis) { + questTime = now; + questData.setLastCompletedTime(this.id, questTime); + } + long remainingMillis = questTime + allowedMillis - now; + return Math.max(0, remainingMillis); + } + case RLWEEKLY: { + long now = System.currentTimeMillis(); + long allowedMillis = 604800000; + if (questTime > now && (questTime - now) > allowedMillis) { + questTime = now; + questData.setLastCompletedTime(this.id, questTime); + } + long remainingMillis = questTime + allowedMillis - now; + return Math.max(0, remainingMillis); + } + case MCCUSTOM: { + // For MCCUSTOM, customCooldown is assumed to be defined in ticks. + long now = player.worldObj.getTotalWorldTime(); + long allowedTicks = this.customCooldown; + if (questTime > now && (questTime - now) > allowedTicks) { + questTime = now; + questData.setLastCompletedTime(this.id, questTime); + } + long remainingTicks = questTime + allowedTicks - now; + return Math.max(0, remainingTicks * 50); + } + case RLCUSTOM: { + // For RLCUSTOM, customCooldown is assumed to be in milliseconds. + long now = System.currentTimeMillis(); + long allowedMillis = this.customCooldown; + if (questTime > now && (questTime - now) > allowedMillis) { + questTime = now; + questData.setLastCompletedTime(this.id, questTime); + } + long remainingMillis = questTime + allowedMillis - now; + return Math.max(0, remainingMillis); + } + default: + return 0L; + } + } + + + @Override public int getVersion() { return version; } @@ -287,4 +372,20 @@ public class Quest implements ICompatibilty, IQuest { public IPartyOptions getPartyOptions() { return this.partyOptions; } + + public boolean isProfileShared() { + return this.profileShared; + } + + public void setProfileShared(boolean value) { + this.profileShared = value; + } + + public long getCustomCooldown() { + return this.customCooldown; + } + + public void setCustomCooldown(long newCooldown) { + this.customCooldown = newCooldown; + } } From 40154f9c53b7d58c91fb57c5f932c890af71a2ec Mon Sep 17 00:00:00 2001 From: Kam Date: Fri, 21 Feb 2025 06:19:24 -0500 Subject: [PATCH 27/59] Quest Profile Options --- src/api | 2 +- .../npcs/command/QuestCategoryCommand.java | 7 +- .../npcs/controllers/ProfileController.java | 109 +++++++++++++--- .../controllers/data/IProfileController.java | 2 + .../request/profile/ProfileCreatePacket.java | 2 - .../client/gui/SubGuiNpcProfileOptions.java | 65 ++++++++++ .../npcs/client/gui/SubGuiNpcQuest.java | 33 +++-- .../gui/util/SubGuiNpcCooldownPicker.java | 118 ++++++++++++++++++ .../npcs/constants/EnumProfileSync.java | 21 ++++ .../controllers/PlayerQuestController.java | 23 +++- .../npcs/controllers/data/ProfileOptions.java | 88 +++++++++++++ .../noppes/npcs/controllers/data/Quest.java | 20 +-- .../npcs/scripted/entity/ScriptPlayer.java | 8 +- .../assets/customnpcs/lang/en_US.lang | 16 ++- 14 files changed, 454 insertions(+), 60 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/SubGuiNpcProfileOptions.java create mode 100644 src/main/java/noppes/npcs/client/gui/util/SubGuiNpcCooldownPicker.java create mode 100644 src/main/java/noppes/npcs/constants/EnumProfileSync.java create mode 100644 src/main/java/noppes/npcs/controllers/data/ProfileOptions.java diff --git a/src/api b/src/api index 7b9e091a3..30ba1bafa 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit 7b9e091a309eef2be8a202dd0abcc3eb017df27c +Subproject commit 30ba1bafac147bc34cab98fadb38cff0dbab7b90 diff --git a/src/main/java/kamkeel/npcs/command/QuestCategoryCommand.java b/src/main/java/kamkeel/npcs/command/QuestCategoryCommand.java index d29ded081..7d57851ba 100644 --- a/src/main/java/kamkeel/npcs/command/QuestCategoryCommand.java +++ b/src/main/java/kamkeel/npcs/command/QuestCategoryCommand.java @@ -7,6 +7,7 @@ import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayerMP; import noppes.npcs.constants.EnumQuestRepeat; import noppes.npcs.controllers.PlayerDataController; +import noppes.npcs.controllers.PlayerQuestController; import noppes.npcs.controllers.QuestController; import noppes.npcs.controllers.data.PlayerData; import noppes.npcs.controllers.data.Quest; @@ -85,11 +86,9 @@ public class QuestCategoryCommand extends CommandKamkeelBase { int count = 0; for(PlayerData playerdata : data){ + count = 0; for(Quest quest : questCategory.quests.values()){ - if(playerdata.questData.activeQuests.containsKey(quest.id)){ - playerdata.questData.activeQuests.remove(quest.id); - } - + playerdata.questData.activeQuests.remove(quest.id); if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY) playerdata.questData.finishedQuests.put(quest.id, System.currentTimeMillis()); else diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index 09526352e..152b81222 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -11,8 +11,13 @@ import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.LogWriter; import noppes.npcs.api.entity.IPlayer; import noppes.npcs.api.handler.IPlayerData; +import noppes.npcs.api.handler.data.IQuest; import noppes.npcs.config.ConfigMain; +import noppes.npcs.constants.EnumProfileSync; +import noppes.npcs.controllers.QuestController; import noppes.npcs.controllers.data.PlayerData; +import noppes.npcs.controllers.data.PlayerQuestData; +import noppes.npcs.controllers.data.Quest; import noppes.npcs.util.CustomNPCsThreader; import noppes.npcs.util.NBTJsonUtil; @@ -92,8 +97,7 @@ public class ProfileController implements IProfileController { Profile profile; if (activeProfiles.containsKey(player.getUniqueID())) { profile = activeProfiles.get(player.getUniqueID()); - // Update the player reference if needed. - profile = new Profile(player, profile.writeToNBT()); + profile.player = player; } else { NBTTagCompound compound = load(player); profile = new Profile(player, compound); @@ -103,9 +107,10 @@ public class ProfileController implements IProfileController { profile.getSlots().put(0, defaultSlot); profile.currentSlotId = 0; saveSlotData(player); - save(player, profile); } + profile.player = player; activeProfiles.put(player.getUniqueID(), profile); + verifySlotQuests(profile.player); } } @@ -382,6 +387,9 @@ public class ProfileController implements IProfileController { } Slot newSlot = new Slot(newSlotId, "Slot " + newSlotId); newSlot.setLastLoaded(System.currentTimeMillis()); + if(profile.player != null) + verifySlotQuests(profile.player); + profile.getSlots().put(newSlotId, newSlot); return ProfileOperation.success(MSG_NEW_SLOT_CREATED); } @@ -680,21 +688,10 @@ public class ProfileController implements IProfileController { Profile profile = getProfile(entityPlayer); if(profile == null) return null; - - if(profile.currentSlotId == slotID){ - playerData = PlayerData.get(entityPlayer); - } else { - Slot slot = (Slot) profile.getSlots().get(slotID); - if(slot == null) - return null; - - playerData = new PlayerData(); - playerData.player = entityPlayer; - playerData.setNBT(slot.getComponentData(new CNPCData().getTagName())); - } - return playerData; + return getSlotPlayerData(entityPlayer, slotID); } + @Override public void saveSlotData(IPlayer player) { if(player == null || player.getMCEntity() == null) return; @@ -702,4 +699,84 @@ public class ProfileController implements IProfileController { EntityPlayer entityPlayer = (EntityPlayer) player.getMCEntity(); saveSlotData(entityPlayer); } + + public IPlayerData getSlotPlayerData(EntityPlayer player, int slotID) { + PlayerData playerData; + Profile profile = getProfile(player); + if(profile == null) + return null; + + if(profile.currentSlotId == slotID){ + playerData = PlayerData.get(player); + } else { + Slot slot = (Slot) profile.getSlots().get(slotID); + return getSlotPlayerData(player, slot); + } + return playerData; + } + + public PlayerData getSlotPlayerData(EntityPlayer player, Slot slot) { + if(slot == null) + return null; + + PlayerData playerData = new PlayerData(); + playerData.player = player; + playerData.setNBT(slot.getComponentData(new CNPCData().getTagName())); + return playerData; + } + + public void verifySlotQuests(EntityPlayer player) { + Profile profile = getProfile(player); + if(profile == null) + return; + + HashMap universalFinished = new HashMap<>(); + for(ISlot profileSlot : profile.getSlots().values()){ + IPlayerData playerData = getSlotPlayerData(player, profileSlot.getId()); + if(playerData != null){ + PlayerQuestData playerQuestData = (PlayerQuestData) playerData.getQuestData(); + for(int id : playerQuestData.finishedQuests.keySet()){ + IQuest quest = QuestController.Instance.get(id); + if(quest != null){ + Quest quest1 = (Quest) quest; + if(quest1.profileOptions.enableOptions && quest1.profileOptions.completeControl == EnumProfileSync.Shared){ + long complete = playerQuestData.finishedQuests.get(id); + if(universalFinished.containsKey(id)){ + complete = Math.max(universalFinished.get(id), complete); + } + universalFinished.put(id, complete); + } + } + } + } + } + for(ISlot profileSlot : profile.getSlots().values()){ + IPlayerData playerData = getSlotPlayerData(player, profileSlot.getId()); + if(playerData != null){ + PlayerQuestData playerQuestData = (PlayerQuestData) playerData.getQuestData(); + playerQuestData.finishedQuests.putAll(universalFinished); + } + } + ProfileController.Instance.save(player, profile); + } + + public void shareQuestCompletion(EntityPlayer player, int questId, long completeTime) { + Profile profile = getProfile(player); + if (profile == null) { + return; + } + for (ISlot slot : profile.getSlots().values()) { + IPlayerData playerData = getSlotPlayerData(player, slot.getId()); + if (playerData != null) { + PlayerQuestData questData = (PlayerQuestData) playerData.getQuestData(); + Long existing = questData.finishedQuests.get(questId); + // Only update if this completion time is newer. + if (existing == null || completeTime > existing) { + questData.finishedQuests.put(questId, completeTime); + } + } + } + // Optionally, immediately persist the updated profile. + save(player, profile); + } } diff --git a/src/main/java/kamkeel/npcs/controllers/data/IProfileController.java b/src/main/java/kamkeel/npcs/controllers/data/IProfileController.java index 4d28291f9..960662ff8 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/IProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/data/IProfileController.java @@ -14,4 +14,6 @@ public interface IProfileController { boolean removeSlot(IPlayer player, int slotID); IPlayerData getSlotPlayerData(IPlayer player, int slotID); + + void saveSlotData(IPlayer player); } diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java index 60560ec79..56023b5af 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java @@ -47,8 +47,6 @@ public final class ProfileCreatePacket extends AbstractPacket { Profile profile = ProfileController.Instance.getProfile(player); ProfileOperation operation = ProfileController.Instance.createSlotInternal(profile); - // TODO: Check Operation and Send Message - ProfileGetPacket.sendProfileNBT(player); ProfileGetInfoPacket.sendProfileInfo(player); } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcProfileOptions.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcProfileOptions.java new file mode 100644 index 000000000..5177eb95a --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcProfileOptions.java @@ -0,0 +1,65 @@ +package noppes.npcs.client.gui; + +import net.minecraft.client.gui.GuiButton; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.constants.EnumProfileSync; +import noppes.npcs.controllers.data.ProfileOptions; + +public class SubGuiNpcProfileOptions extends SubGuiInterface +{ + private final ProfileOptions options; + + public SubGuiNpcProfileOptions(ProfileOptions options) + { + this.options = options; + setBackground("menubg.png"); + xSize = 256; + ySize = 216; + closeOnEsc = true; + } + + public void initGui() + { + super.initGui(); + + int y = 0; + //Allow party - T/F button + addButton(new GuiNpcButton(0, guiLeft + 130, guiTop + 10 + y, 60, 20, + new String[]{"gui.no", "gui.yes"}, options.enableOptions ? 1 : 0)); + addLabel(new GuiNpcLabel(1, "party.allowParty", guiLeft + 10, guiTop + 17 + y)); + + if (options.enableOptions) { + y += 23; + addButton(new GuiNpcButton(5, guiLeft + 130, guiTop + 10 + y, 60, 20, + EnumProfileSync.values(), options.completeControl.ordinal())); + addLabel(new GuiNpcLabel(5, "party.partyRequirements", guiLeft + 10, guiTop + 17 + y)); + + y += 23; + addButton(new GuiNpcButton(18, guiLeft + 130, guiTop + 10 + y, 60, 20, + EnumProfileSync.values(), options.cooldownControl.ordinal())); + addLabel(new GuiNpcLabel(18, "quest.objectives", guiLeft + 10, guiTop + 17 + y)); + } + + addButton(new GuiNpcButton(66, guiLeft + 200, guiTop + 192, 50, 20, "gui.done")); + } + + protected void actionPerformed(GuiButton guibutton) + { + int id = guibutton.id; + switch (id) { + case 0: + options.enableOptions = !options.enableOptions; + break; + case 5: + options.completeControl = EnumProfileSync.valueOf(guibutton.displayString); + break; + case 18: + options.cooldownControl = EnumProfileSync.valueOf(guibutton.displayString); + break; + case 66: + close(); + break; + } + initGui(); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java index 192dfc4ca..bd8e559c8 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java @@ -69,7 +69,10 @@ public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener, addLabel(new GuiNpcLabel(17, "party.options", guiLeft + 180, guiTop + 135)); addButton(new GuiNpcButton(18, guiLeft + 303, guiTop + 130, 50, 20, "selectServer.edit")); - this.addButton(new GuiNpcButton(9, guiLeft + 7, guiTop + 102,90, 20, new String[]{"quest.npc","quest.instant"},quest.completion.ordinal())); + addLabel(new GuiNpcLabel(33, "quest.profile", guiLeft + 180, guiTop + 159)); + addButton(new GuiNpcButton(33, guiLeft + 303, guiTop + 154, 50, 20, "selectServer.edit")); + + this.addButton(new GuiNpcButton(9, guiLeft + 7, guiTop + 102,90, 20, new String[]{"quest.npc","quest.instant"},quest.completion.ordinal())); if(quest.completerNpc.isEmpty() && npc != null) quest.completerNpc = npc.display.name; this.addTextField(new GuiNpcTextField(2,this, this.fontRendererObj, guiLeft + 104, guiTop + 102, 154, 20, quest.completerNpc)); @@ -85,9 +88,12 @@ public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener, if(!quest.mail.subject.isEmpty()) getButton(13).setDisplayText(quest.mail.subject); - addLabel(new GuiNpcLabel(8, "quest.repeatable", guiLeft + 7, guiTop + 178 + 5)); - this.addButton(new GuiNpcButton(8, guiLeft + 100, guiTop + 178,70, 20, new String[]{"gui.no","gui.yes","quest.mcdaily","quest.mcweekly","quest.rldaily","quest.rlweekly"}, quest.repeat.ordinal())); - + addLabel(new GuiNpcLabel(8, "quest.repeatable", guiLeft + 7, guiTop + 178 + 5)); + this.addButton(new GuiNpcButton(8, guiLeft + 100, guiTop + 178, 70, 20, + new String[]{"gui.no", "gui.yes", "quest.mcdaily", "quest.mcweekly", "quest.rldaily", "quest.rlweekly", "quest.mccustom", "quest.rlcustom"}, quest.repeat.ordinal())); + if(quest.repeat == EnumQuestRepeat.MCCUSTOM || quest.repeat == EnumQuestRepeat.RLCUSTOM) { + addButton(new GuiNpcButton(19, guiLeft + 175, guiTop + 178, 90, 20, "Set Cooldown")); + } addButton(new GuiNpcButton(16, guiLeft + 303, guiTop + 192, 50, 20, "gui.done")); if(!quest.mail.subject.isEmpty()) @@ -134,6 +140,7 @@ public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener, if(button.id == 8) { quest.repeat = EnumQuestRepeat.values()[button.getValue()]; + initGui(); } if(button.id == 9) { @@ -161,14 +168,18 @@ public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener, } if(button.id == 15 && quest.id >= 0){ setSubGui(new GuiQuestSelection(quest.nextQuestid)); -// questSelection = new GuiNPCQuestSelection(npc, getParent(), quest.nextQuestid); -// questSelection.listener = this; -// NoppesUtil.openGUI(player, questSelection); } if(button.id == 18) { setSubGui(new SubGuiNpcPartyOptions(quest.partyOptions)); } + if(button.id == 19) { + boolean isMCCustom = (quest.repeat == EnumQuestRepeat.MCCUSTOM); + setSubGui(new SubGuiNpcCooldownPicker(isMCCustom, quest.customCooldown)); + } + if(button.id == 33){ + setSubGui(new SubGuiNpcProfileOptions(quest.profileOptions)); + } if(button.id == 16){ close(); } @@ -211,7 +222,13 @@ public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener, else if(subgui instanceof SubGuiNpcCommand){ SubGuiNpcCommand sub = (SubGuiNpcCommand) subgui; quest.command = sub.command; - } + initGui(); + + } else if(subgui instanceof SubGuiNpcCooldownPicker){ + SubGuiNpcCooldownPicker cooldownGui = (SubGuiNpcCooldownPicker) subgui; + quest.customCooldown = cooldownGui.cooldownValue; + initGui(); + } else { initGui(); } diff --git a/src/main/java/noppes/npcs/client/gui/util/SubGuiNpcCooldownPicker.java b/src/main/java/noppes/npcs/client/gui/util/SubGuiNpcCooldownPicker.java new file mode 100644 index 000000000..35df31263 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/util/SubGuiNpcCooldownPicker.java @@ -0,0 +1,118 @@ +package noppes.npcs.client.gui.util; + +import net.minecraft.client.gui.GuiButton; + +public class SubGuiNpcCooldownPicker extends SubGuiInterface implements ITextfieldListener { + + private final boolean isMCCustom; + public long cooldownValue; + + private GuiNpcTextField daysField; + private GuiNpcTextField hoursField; + private GuiNpcTextField minutesField; + private GuiNpcTextField secondsField; + + public SubGuiNpcCooldownPicker(boolean isMCCustom, long currentCooldown) { + this.isMCCustom = isMCCustom; + this.cooldownValue = currentCooldown; + setBackground("smallbg.png"); + xSize = 220; + ySize = 222; + closeOnEsc = true; + } + + @Override + public void initGui() { + super.initGui(); + + int days = 0, hours = 0, minutes = 0, seconds = 0; + if(isMCCustom) { + long currentMillis = cooldownValue * 50; + days = (int)(currentMillis / 86400000L); + long remainder = currentMillis % 86400000L; + hours = (int)(remainder / 3600000L); + remainder %= 3600000L; + minutes = (int)(remainder / 60000L); + remainder %= 60000L; + seconds = (int)(remainder / 1000L); + } else { + // For RL custom cooldown, currentCooldown is stored in milliseconds. + days = (int)(cooldownValue / 86400000L); + long remainder = cooldownValue % 86400000L; + hours = (int)(remainder / 3600000L); + remainder %= 3600000L; + minutes = (int)(remainder / 60000L); + remainder %= 60000L; + seconds = (int)(remainder / 1000L); + } + + int y = guiTop + 20; + addLabel(new GuiNpcLabel(1, "mailbox.days", guiLeft + 10, y)); + daysField = new GuiNpcTextField(1, this, fontRendererObj, guiLeft + xSize - 110, y - 5, 40, 20, "" + days); + daysField.setIntegersOnly(); + daysField.setMinMaxDefault(0, Integer.MAX_VALUE, 0); + addTextField(daysField); + + y += 30; + + addLabel(new GuiNpcLabel(2, "mailbox.hours", guiLeft + 10, y)); + hoursField = new GuiNpcTextField(2, this, fontRendererObj, guiLeft + xSize - 110, y - 5, 40, 20, "" + hours); + hoursField.setIntegersOnly(); + hoursField.setMinMaxDefault(0, 24, 0); + addTextField(hoursField); + + y += 30; + + addLabel(new GuiNpcLabel(3, "mailbox.minutes", guiLeft + 10, y)); + minutesField = new GuiNpcTextField(3, this, fontRendererObj, guiLeft + xSize - 110, y - 5, 40, 20, "" + minutes); + minutesField.setIntegersOnly(); + minutesField.setMinMaxDefault(0, 60, 0); + addTextField(minutesField); + + y += 30; + + addLabel(new GuiNpcLabel(4, "mailbox.seconds", guiLeft + 10, y)); + secondsField = new GuiNpcTextField(4, this, fontRendererObj, guiLeft + xSize - 110, y - 5, 40, 20, "" + seconds); + secondsField.setIntegersOnly(); + secondsField.setMinMaxDefault(0, 60, 0); + addTextField(secondsField); + + addButton(new GuiNpcButton(0, guiLeft + 10, guiTop + ySize - 30, 80, 20, "gui.done")); + } + + @Override + public void buttonEvent(GuiButton button) { + if(button.id == 0) { + close(); + } + } + + public void close(){ + int inputDays = parseInt(daysField.getText()); + int inputHours = parseInt(hoursField.getText()); + int inputMinutes = parseInt(minutesField.getText()); + int inputSeconds = parseInt(secondsField.getText()); + // Calculate total time in milliseconds. + long totalMillis = inputDays * 86400000L + inputHours * 3600000L + inputMinutes * 60000L + inputSeconds * 1000L; + if(isMCCustom) { + // Convert real milliseconds to ticks. + cooldownValue = totalMillis / 50; + } else { + cooldownValue = totalMillis; + } + super.close(); + } + + @Override + public void unFocused(GuiNpcTextField textField) { + // No immediate action needed on unfocus. + } + + private int parseInt(String text) { + try { + return Integer.parseInt(text); + } catch(Exception e) { + return 0; + } + } +} diff --git a/src/main/java/noppes/npcs/constants/EnumProfileSync.java b/src/main/java/noppes/npcs/constants/EnumProfileSync.java new file mode 100644 index 000000000..f20e3e208 --- /dev/null +++ b/src/main/java/noppes/npcs/constants/EnumProfileSync.java @@ -0,0 +1,21 @@ +package noppes.npcs.constants; + +import java.util.ArrayList; + +public enum EnumProfileSync { + Individual("profile.individual"), + Shared("profile.shared"); + + public final String name; + + EnumProfileSync(String name){ + this.name = name; + } + public static String[] names(){ + ArrayList list = new ArrayList(); + for(EnumProfileSync e : values()) + list.add(e.name); + + return list.toArray(new String[list.size()]); + } +} diff --git a/src/main/java/noppes/npcs/controllers/PlayerQuestController.java b/src/main/java/noppes/npcs/controllers/PlayerQuestController.java index 20d6236e3..c994aec34 100644 --- a/src/main/java/noppes/npcs/controllers/PlayerQuestController.java +++ b/src/main/java/noppes/npcs/controllers/PlayerQuestController.java @@ -1,5 +1,6 @@ package noppes.npcs.controllers; +import kamkeel.npcs.controllers.ProfileController; import kamkeel.npcs.network.packets.data.AchievementPacket; import kamkeel.npcs.network.packets.data.ChatAlertPacket; import net.minecraft.entity.player.EntityPlayer; @@ -8,6 +9,8 @@ import net.minecraft.util.ChatComponentTranslation; import noppes.npcs.EventHooks; import noppes.npcs.NoppesStringUtils; import noppes.npcs.NoppesUtilServer; +import noppes.npcs.config.ConfigMain; +import noppes.npcs.constants.EnumProfileSync; import noppes.npcs.constants.EnumQuestRepeat; import noppes.npcs.constants.EnumQuestType; import noppes.npcs.controllers.data.PlayerData; @@ -64,11 +67,7 @@ public class PlayerQuestController { PlayerQuestData data = playerdata.questData; QuestData questData = data.activeQuests.get(quest.id); data.activeQuests.remove(quest.id); - if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY) - data.finishedQuests.put(quest.id, System.currentTimeMillis()); - else - data.finishedQuests.put(quest.id,player.worldObj.getTotalWorldTime()); - + setQuestFinishedUtil(player, quest, data); if(quest.repeat != EnumQuestRepeat.NONE && quest.type == EnumQuestType.Dialog){ QuestDialog questdialog = (QuestDialog) quest.questInterface; for(int dialog : questdialog.dialogs.values()){ @@ -82,6 +81,20 @@ public class PlayerQuestController { playerdata.updateClient = true; } + public static void setQuestFinishedUtil(EntityPlayer player, Quest quest, PlayerQuestData questData){ + long completeTime; + if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY || quest.repeat == EnumQuestRepeat.RLCUSTOM){ + completeTime = System.currentTimeMillis(); + questData.finishedQuests.put(quest.id, completeTime); + } else { + completeTime = player.worldObj.getTotalWorldTime(); + questData.finishedQuests.put(quest.id, completeTime); + } + + if(ConfigMain.ProfilesEnabled && quest.profileOptions.enableOptions && quest.profileOptions.completeControl == EnumProfileSync.Shared) + ProfileController.Instance.shareQuestCompletion(player, quest.id, completeTime); + } + public static void setQuestPartyFinished(Quest quest, EntityPlayer player, QuestData questData ){ PlayerData playerdata = PlayerData.get(player); PlayerQuestData data = playerdata.questData; diff --git a/src/main/java/noppes/npcs/controllers/data/ProfileOptions.java b/src/main/java/noppes/npcs/controllers/data/ProfileOptions.java new file mode 100644 index 000000000..5605f1b63 --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/data/ProfileOptions.java @@ -0,0 +1,88 @@ +package noppes.npcs.controllers.data; + +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.api.handler.data.IProfileOptions; +import noppes.npcs.constants.EnumProfileSync; + +public class ProfileOptions implements IProfileOptions { + public boolean enableOptions = false; + + public EnumProfileSync cooldownControl = EnumProfileSync.Individual; + public EnumProfileSync completeControl = EnumProfileSync.Individual; + + public void readFromNBT(NBTTagCompound compound) + { + // Party Management + enableOptions = compound.getBoolean("EnableProfiles"); + if(enableOptions){ + cooldownControl = EnumProfileSync.values()[compound.getInteger("CooldownControl")]; + completeControl = EnumProfileSync.values()[compound.getInteger("CompleteControl")]; + } + else { + if(compound.hasKey("CooldownControl")){ + compound.removeTag("CooldownControl"); + } + if(compound.hasKey("CompleteControl")){ + compound.removeTag("CompleteControl"); + } + + cooldownControl = EnumProfileSync.Individual; + completeControl = EnumProfileSync.Individual; + } + } + public NBTTagCompound writeToNBT() + { + NBTTagCompound compound = new NBTTagCompound(); + compound.setBoolean("EnableProfiles", enableOptions); + if(enableOptions){ + compound.setInteger("CooldownControl", cooldownControl.ordinal()); + compound.setInteger("CompleteControl", completeControl.ordinal()); + } + else { + if(compound.hasKey("CooldownControl")){ + compound.removeTag("CooldownControl"); + } + if(compound.hasKey("CompleteControl")){ + compound.removeTag("CompleteControl"); + } + } + + return compound; + } + + @Override + public boolean hasProfileOptions() { + return enableOptions; + } + + @Override + public void setProfileOptions(boolean enable) { + this.enableOptions = enable; + } + + @Override + public void setCooldownControl(int profileType) { + if (profileType < 0 || profileType >= EnumProfileSync.values().length) { + return; + } + this.cooldownControl = EnumProfileSync.values()[profileType]; + } + + @Override + public int getCooldownControl(){ + return this.cooldownControl.ordinal(); + } + + @Override + public void setCompleteControl(int profileType) { + if (profileType < 0 || profileType >= EnumProfileSync.values().length) { + return; + } + this.completeControl = EnumProfileSync.values()[profileType]; + } + + @Override + public int getCompleteControl(){ + return this.completeControl.ordinal(); + } +} diff --git a/src/main/java/noppes/npcs/controllers/data/Quest.java b/src/main/java/noppes/npcs/controllers/data/Quest.java index 7b0dad77b..83205ca28 100644 --- a/src/main/java/noppes/npcs/controllers/data/Quest.java +++ b/src/main/java/noppes/npcs/controllers/data/Quest.java @@ -41,8 +41,6 @@ public class Quest implements ICompatibilty, IQuest { public String command = ""; public QuestInterface questInterface = new QuestItem(); - - public boolean profileShared = false; public long customCooldown = 0; public int rewardExp = 0; @@ -50,7 +48,7 @@ public class Quest implements ICompatibilty, IQuest { public boolean randomReward = false; public FactionOptions factionOptions = new FactionOptions(); public PartyOptions partyOptions = new PartyOptions(); - + public ProfileOptions profileOptions = new ProfileOptions(); public void readNBT(NBTTagCompound compound) { id = compound.getInteger("Id"); @@ -78,14 +76,12 @@ public class Quest implements ICompatibilty, IQuest { completion = EnumQuestCompletion.values()[compound.getInteger("QuestCompletion")]; repeat = EnumQuestRepeat.values()[compound.getInteger("QuestRepeat")]; - customCooldown = compound.getLong("CustomCooldown"); - profileShared = compound.getBoolean("ProfileShared"); - questInterface.readEntityFromNBT(compound); factionOptions.readFromNBT(compound.getCompoundTag("QuestFactionPoints")); partyOptions.readFromNBT(compound.getCompoundTag("PartyOptions")); + profileOptions.readFromNBT(compound.getCompoundTag("ProfileOptions")); mail.readNBT(compound.getCompoundTag("QuestMail")); } @@ -124,7 +120,6 @@ public class Quest implements ICompatibilty, IQuest { compound.setTag("Rewards", rewardItems.getToNBT()); compound.setString("QuestCommand", command); compound.setBoolean("RandomReward", randomReward); - compound.setBoolean("ProfileShared", profileShared); compound.setLong("CustomCooldown", customCooldown); compound.setInteger("QuestCompletion", completion.ordinal()); @@ -133,6 +128,7 @@ public class Quest implements ICompatibilty, IQuest { this.questInterface.writeEntityToNBT(compound); compound.setTag("QuestFactionPoints", factionOptions.writeToNBT(new NBTTagCompound())); compound.setTag("PartyOptions", partyOptions.writeToNBT()); + compound.setTag("ProfileOptions", profileOptions.writeToNBT()); compound.setTag("QuestMail", mail.writeNBT()); return compound; @@ -166,7 +162,7 @@ public class Quest implements ICompatibilty, IQuest { } public long getTimeUntilRepeat(EntityPlayer player) { - if(profileShared && ConfigMain.ProfilesEnabled){ + if(profileOptions.enableOptions && ConfigMain.ProfilesEnabled){ Profile profile = ProfileController.Instance.getProfile(player); IPlayer iPlayer = NoppesUtilServer.getIPlayer(player); long timeRemaining = 0L; @@ -373,12 +369,8 @@ public class Quest implements ICompatibilty, IQuest { return this.partyOptions; } - public boolean isProfileShared() { - return this.profileShared; - } - - public void setProfileShared(boolean value) { - this.profileShared = value; + public IProfileOptions getProfileOptions() { + return this.profileOptions; } public long getCustomCooldown() { diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index 0ce931c0e..485e9cc21 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -1,5 +1,6 @@ package noppes.npcs.scripted.entity; +import kamkeel.npcs.controllers.ProfileController; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.packets.data.AchievementPacket; import kamkeel.npcs.network.packets.data.ChatAlertPacket; @@ -34,7 +35,9 @@ import noppes.npcs.api.handler.data.ISound; import noppes.npcs.api.item.IItemStack; import noppes.npcs.api.overlay.ICustomOverlay; import noppes.npcs.compat.PixelmonHelper; +import noppes.npcs.config.ConfigMain; import noppes.npcs.config.ConfigScript; +import noppes.npcs.constants.EnumProfileSync; import noppes.npcs.constants.EnumQuestRepeat; import noppes.npcs.constants.EnumQuestType; import noppes.npcs.containers.ContainerCustomGui; @@ -284,10 +287,7 @@ public class ScriptPlayer extends ScriptLivingBase if (quest == null) return; PlayerData data = PlayerData.get(player); - if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY) - data.questData.finishedQuests.put(quest.id, System.currentTimeMillis()); - else - data.questData.finishedQuests.put(quest.id, player.worldObj.getTotalWorldTime()); + PlayerQuestController.setQuestFinishedUtil(player, quest, data.questData); data.updateClient = true; } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 5b5d71dc4..6997383b3 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -254,12 +254,13 @@ mailbox.name=Mailbox mailbox.sender=Sender mailbox.read=Read mailbox.timesend=%s ago -mailbox.day=day -mailbox.days=days -mailbox.hour=hour -mailbox.hours=hours -mailbox.minute=minute -mailbox.minutes=minutes +mailbox.day=Day +mailbox.days=Days +mailbox.hour=Hour +mailbox.hours=Hours +mailbox.minute=Minute +mailbox.minutes=Minutes +mailbox.seconds=Seconds mailbox.username=Username mailbox.subject=Subject mailbox.send=Send @@ -662,6 +663,9 @@ quest.mcdaily=MC Daily quest.mcweekly=MC Weekly quest.rldaily=RL Daily quest.rlweekly=RL Weekly +quest.rlcustom=RL Custom +quest.mccustom=MC Custom +quest.profile=Profile Options quest.instant=Instant Complete quest.npc=Complete by npc quest.next=Next Quest From 98605b727619a2fb1b06f0650919b428dda87ac0 Mon Sep 17 00:00:00 2001 From: Kam Date: Fri, 21 Feb 2025 07:05:56 -0500 Subject: [PATCH 28/59] moreee --- .../npcs/command/QuestCategoryCommand.java | 18 ++++++++++++++---- .../kamkeel/npcs/command/QuestCommand.java | 19 +++++++++++++------ .../npcs/controllers/ProfileController.java | 13 +++++-------- .../controllers/PlayerQuestController.java | 6 +----- .../controllers/data/PlayerQuestData.java | 8 ++------ 5 files changed, 35 insertions(+), 29 deletions(-) diff --git a/src/main/java/kamkeel/npcs/command/QuestCategoryCommand.java b/src/main/java/kamkeel/npcs/command/QuestCategoryCommand.java index 7d57851ba..eb673da35 100644 --- a/src/main/java/kamkeel/npcs/command/QuestCategoryCommand.java +++ b/src/main/java/kamkeel/npcs/command/QuestCategoryCommand.java @@ -1,10 +1,13 @@ package kamkeel.npcs.command; +import kamkeel.npcs.controllers.ProfileController; import kamkeel.npcs.network.packets.data.AchievementPacket; import kamkeel.npcs.network.packets.data.ChatAlertPacket; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayerMP; +import noppes.npcs.config.ConfigMain; +import noppes.npcs.constants.EnumProfileSync; import noppes.npcs.constants.EnumQuestRepeat; import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.controllers.PlayerQuestController; @@ -89,10 +92,17 @@ public class QuestCategoryCommand extends CommandKamkeelBase { count = 0; for(Quest quest : questCategory.quests.values()){ playerdata.questData.activeQuests.remove(quest.id); - if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY) - playerdata.questData.finishedQuests.put(quest.id, System.currentTimeMillis()); - else - playerdata.questData.finishedQuests.put(quest.id, sender.getEntityWorld().getTotalWorldTime()); + long completeTime; + if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY || quest.repeat == EnumQuestRepeat.RLCUSTOM){ + completeTime = System.currentTimeMillis(); + playerdata.questData.finishedQuests.put(quest.id, completeTime); + } else { + completeTime = sender.getEntityWorld().getTotalWorldTime(); + playerdata.questData.finishedQuests.put(quest.id, completeTime); + } + + if(ConfigMain.ProfilesEnabled && playerdata.player != null && quest.profileOptions.enableOptions && quest.profileOptions.completeControl == EnumProfileSync.Shared) + ProfileController.Instance.shareQuestCompletion(playerdata.player, quest.id, completeTime);; if(playerdata.player != null){ AchievementPacket.sendAchievement((EntityPlayerMP) playerdata.player, false, "quest.completed", quest.title); diff --git a/src/main/java/kamkeel/npcs/command/QuestCommand.java b/src/main/java/kamkeel/npcs/command/QuestCommand.java index 127fb1726..e1e0894d0 100644 --- a/src/main/java/kamkeel/npcs/command/QuestCommand.java +++ b/src/main/java/kamkeel/npcs/command/QuestCommand.java @@ -1,5 +1,6 @@ package kamkeel.npcs.command; +import kamkeel.npcs.controllers.ProfileController; import kamkeel.npcs.controllers.SyncController; import kamkeel.npcs.network.packets.data.AchievementPacket; import kamkeel.npcs.network.packets.data.ChatAlertPacket; @@ -8,6 +9,8 @@ import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import noppes.npcs.api.handler.data.IQuestObjective; +import noppes.npcs.config.ConfigMain; +import noppes.npcs.constants.EnumProfileSync; import noppes.npcs.constants.EnumQuestCompletion; import noppes.npcs.constants.EnumQuestRepeat; import noppes.npcs.controllers.PlayerDataController; @@ -103,14 +106,18 @@ public class QuestCommand extends CommandKamkeelBase { return; } for(PlayerData playerdata : data){ - if(playerdata.questData.activeQuests.containsKey(questid)){ - playerdata.questData.activeQuests.remove(questid); + playerdata.questData.activeQuests.remove(questid); + long completeTime; + if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY || quest.repeat == EnumQuestRepeat.RLCUSTOM){ + completeTime = System.currentTimeMillis(); + playerdata.questData.finishedQuests.put(quest.id, completeTime); + } else { + completeTime = sender.getEntityWorld().getTotalWorldTime(); + playerdata.questData.finishedQuests.put(quest.id, completeTime); } - if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY) - playerdata.questData.finishedQuests.put(quest.id, System.currentTimeMillis()); - else - playerdata.questData.finishedQuests.put(quest.id, sender.getEntityWorld().getTotalWorldTime()); + if(ConfigMain.ProfilesEnabled && playerdata.player != null && quest.profileOptions.enableOptions && quest.profileOptions.completeControl == EnumProfileSync.Shared) + ProfileController.Instance.shareQuestCompletion(playerdata.player, quest.id, completeTime); playerdata.save(); if(playerdata.player != null){ diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index 152b81222..80637fe15 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -9,6 +9,7 @@ import net.minecraft.server.MinecraftServer; import noppes.npcs.CustomNpcs; import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.LogWriter; +import noppes.npcs.NoppesUtilServer; import noppes.npcs.api.entity.IPlayer; import noppes.npcs.api.handler.IPlayerData; import noppes.npcs.api.handler.data.IQuest; @@ -111,6 +112,7 @@ public class ProfileController implements IProfileController { profile.player = player; activeProfiles.put(player.getUniqueID(), profile); verifySlotQuests(profile.player); + save(player, profile); } } @@ -223,7 +225,7 @@ public class ProfileController implements IProfileController { mainFile.delete(); } fileNew.renameTo(mainFile); - EntityPlayerMP player = getPlayer(username); + EntityPlayer player = NoppesUtilServer.getPlayerByName(username); Profile newProfile; if (player != null) { newProfile = new Profile(player, compound); @@ -262,7 +264,7 @@ public class ProfileController implements IProfileController { } public Profile getProfile(String username) { - EntityPlayer player = getPlayer(username); + EntityPlayer player = NoppesUtilServer.getPlayerByName(username); if (player != null) { return getProfile(player); } else { @@ -635,10 +637,6 @@ public class ProfileController implements IProfileController { return currentSlots < highestAllowed; } - public EntityPlayerMP getPlayer(String username) { - return MinecraftServer.getServer().getConfigurationManager().func_152612_a(username); - } - @Override public IProfile getProfile(IPlayer player) { if(player == null || player.getMCEntity() == null) @@ -757,7 +755,6 @@ public class ProfileController implements IProfileController { playerQuestData.finishedQuests.putAll(universalFinished); } } - ProfileController.Instance.save(player, profile); } public void shareQuestCompletion(EntityPlayer player, int questId, long completeTime) { @@ -774,9 +771,9 @@ public class ProfileController implements IProfileController { if (existing == null || completeTime > existing) { questData.finishedQuests.put(questId, completeTime); } + playerData.save(); } } - // Optionally, immediately persist the updated profile. save(player, profile); } } diff --git a/src/main/java/noppes/npcs/controllers/PlayerQuestController.java b/src/main/java/noppes/npcs/controllers/PlayerQuestController.java index c994aec34..f7d38a3b3 100644 --- a/src/main/java/noppes/npcs/controllers/PlayerQuestController.java +++ b/src/main/java/noppes/npcs/controllers/PlayerQuestController.java @@ -99,11 +99,7 @@ public class PlayerQuestController { PlayerData playerdata = PlayerData.get(player); PlayerQuestData data = playerdata.questData; data.activeQuests.remove(quest.id); - if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY) - data.finishedQuests.put(quest.id, System.currentTimeMillis()); - else - data.finishedQuests.put(quest.id,player.worldObj.getTotalWorldTime()); - + setQuestFinishedUtil(player, quest, data); if(quest.repeat != EnumQuestRepeat.NONE && quest.type == EnumQuestType.Dialog){ QuestDialog questdialog = (QuestDialog) quest.questInterface; for(int dialog : questdialog.dialogs.values()){ diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java b/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java index 134f80312..cb91cfc7a 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java @@ -18,6 +18,7 @@ import noppes.npcs.constants.EnumQuestRepeat; import noppes.npcs.constants.EnumQuestType; import noppes.npcs.controllers.PartyController; import noppes.npcs.controllers.PlayerDataController; +import noppes.npcs.controllers.PlayerQuestController; import noppes.npcs.controllers.QuestController; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.quests.QuestInterface; @@ -229,12 +230,7 @@ public class PlayerQuestData implements IPlayerQuestData { Quest quest = QuestController.Instance.quests.get(id); if (quest == null) return; - - if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY) - finishedQuests.put(quest.id, System.currentTimeMillis()); - else - finishedQuests.put(quest.id, parent.player.worldObj.getTotalWorldTime()); - + PlayerQuestController.setQuestFinished(quest, parent.player); parent.updateClient = true; } From 05487a06a214500a941f4fe5595eab24649ec569 Mon Sep 17 00:00:00 2001 From: Kam Date: Fri, 21 Feb 2025 16:40:44 -0500 Subject: [PATCH 29/59] Better Shared Quest Completion --- .../npcs/controllers/ProfileController.java | 48 +++++++++---------- .../npcs/controllers/QuestController.java | 11 +++++ 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index 80637fe15..3cfac441c 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -725,34 +725,35 @@ public class ProfileController implements IProfileController { public void verifySlotQuests(EntityPlayer player) { Profile profile = getProfile(player); - if(profile == null) + if (profile == null) { return; + } - HashMap universalFinished = new HashMap<>(); - for(ISlot profileSlot : profile.getSlots().values()){ - IPlayerData playerData = getSlotPlayerData(player, profileSlot.getId()); - if(playerData != null){ - PlayerQuestData playerQuestData = (PlayerQuestData) playerData.getQuestData(); - for(int id : playerQuestData.finishedQuests.keySet()){ - IQuest quest = QuestController.Instance.get(id); - if(quest != null){ - Quest quest1 = (Quest) quest; - if(quest1.profileOptions.enableOptions && quest1.profileOptions.completeControl == EnumProfileSync.Shared){ - long complete = playerQuestData.finishedQuests.get(id); - if(universalFinished.containsKey(id)){ - complete = Math.max(universalFinished.get(id), complete); - } - universalFinished.put(id, complete); - } - } + Map universalFinished = new HashMap<>(); + for (Integer questId : QuestController.Instance.sharedQuests.keySet()) { + long maxTime = 0; + for (ISlot slot : profile.getSlots().values()) { + IPlayerData data = getSlotPlayerData(player, slot.getId()); + if (data == null) { + continue; + } + PlayerQuestData questData = (PlayerQuestData) data.getQuestData(); + Long t = questData.finishedQuests.get(questId); + if (t != null && t > maxTime) { + maxTime = t; } } + if (maxTime > 0) { + universalFinished.put(questId, maxTime); + } } - for(ISlot profileSlot : profile.getSlots().values()){ - IPlayerData playerData = getSlotPlayerData(player, profileSlot.getId()); - if(playerData != null){ - PlayerQuestData playerQuestData = (PlayerQuestData) playerData.getQuestData(); - playerQuestData.finishedQuests.putAll(universalFinished); + + // Push the universal shared completion times into every slot. + for (ISlot slot : profile.getSlots().values()) { + IPlayerData data = getSlotPlayerData(player, slot.getId()); + if (data != null) { + PlayerQuestData questData = (PlayerQuestData) data.getQuestData(); + questData.finishedQuests.putAll(universalFinished); } } } @@ -767,7 +768,6 @@ public class ProfileController implements IProfileController { if (playerData != null) { PlayerQuestData questData = (PlayerQuestData) playerData.getQuestData(); Long existing = questData.finishedQuests.get(questId); - // Only update if this completion time is newer. if (existing == null || completeTime > existing) { questData.finishedQuests.put(questId, completeTime); } diff --git a/src/main/java/noppes/npcs/controllers/QuestController.java b/src/main/java/noppes/npcs/controllers/QuestController.java index 51051bcb4..3b5616e4d 100644 --- a/src/main/java/noppes/npcs/controllers/QuestController.java +++ b/src/main/java/noppes/npcs/controllers/QuestController.java @@ -11,6 +11,7 @@ import noppes.npcs.NoppesStringUtils; import noppes.npcs.api.handler.IQuestHandler; import noppes.npcs.api.handler.data.IQuest; import noppes.npcs.api.handler.data.IQuestCategory; +import noppes.npcs.constants.EnumProfileSync; import noppes.npcs.controllers.data.Quest; import noppes.npcs.controllers.data.QuestCategory; import noppes.npcs.util.NBTJsonUtil; @@ -23,6 +24,7 @@ public class QuestController implements IQuestHandler { public HashMap categoriesSync = new HashMap(); public HashMap categories = new HashMap(); public HashMap quests = new HashMap(); + public HashMap sharedQuests = new HashMap<>(); public static QuestController Instance = new QuestController();; @@ -75,6 +77,9 @@ public class QuestController implements IQuestHandler { } else{ quests.put(id, quest); + if(quest.profileOptions.enableOptions && quest.profileOptions.completeControl == EnumProfileSync.Shared){ + sharedQuests.put(id, quest); + } } } lastUsedCatID++; @@ -209,9 +214,15 @@ public class QuestController implements IQuestHandler { lastUsedQuestID++; quest.id = lastUsedQuestID; } + quests.put(quest.id, quest); category.quests.put(quest.id, quest); + sharedQuests.remove(quest.id); + if(quest.profileOptions.enableOptions && quest.profileOptions.completeControl == EnumProfileSync.Shared){ + sharedQuests.put(quest.id, quest); + } + File dir = new File(getDir(), category.title); if(!dir.exists()) dir.mkdirs(); From 9905aaaf0c1b911d7df009fb0952ce7882ba8fb2 Mon Sep 17 00:00:00 2001 From: Kam Date: Fri, 21 Feb 2025 16:42:09 -0500 Subject: [PATCH 30/59] Update Quest.java --- src/main/java/noppes/npcs/controllers/data/Quest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/controllers/data/Quest.java b/src/main/java/noppes/npcs/controllers/data/Quest.java index 83205ca28..2a8f5c462 100644 --- a/src/main/java/noppes/npcs/controllers/data/Quest.java +++ b/src/main/java/noppes/npcs/controllers/data/Quest.java @@ -15,6 +15,7 @@ import noppes.npcs.api.handler.IPlayerData; import noppes.npcs.api.handler.IPlayerQuestData; import noppes.npcs.api.handler.data.*; import noppes.npcs.config.ConfigMain; +import noppes.npcs.constants.EnumProfileSync; import noppes.npcs.constants.EnumQuestCompletion; import noppes.npcs.constants.EnumQuestRepeat; import noppes.npcs.constants.EnumQuestType; @@ -162,7 +163,7 @@ public class Quest implements ICompatibilty, IQuest { } public long getTimeUntilRepeat(EntityPlayer player) { - if(profileOptions.enableOptions && ConfigMain.ProfilesEnabled){ + if(ConfigMain.ProfilesEnabled && profileOptions.enableOptions && profileOptions.cooldownControl == EnumProfileSync.Shared){ Profile profile = ProfileController.Instance.getProfile(player); IPlayer iPlayer = NoppesUtilServer.getIPlayer(player); long timeRemaining = 0L; From 9f71370c1f6910a3619b41c0d404f19ee02cdeb1 Mon Sep 17 00:00:00 2001 From: Kam Date: Fri, 21 Feb 2025 16:44:40 -0500 Subject: [PATCH 31/59] Add Langs --- .../noppes/npcs/client/gui/SubGuiNpcProfileOptions.java | 6 +++--- src/main/java/noppes/npcs/constants/EnumProfileSync.java | 2 +- src/main/resources/assets/customnpcs/lang/en_US.lang | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcProfileOptions.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcProfileOptions.java index 5177eb95a..bc6376bd5 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcProfileOptions.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcProfileOptions.java @@ -26,18 +26,18 @@ public class SubGuiNpcProfileOptions extends SubGuiInterface //Allow party - T/F button addButton(new GuiNpcButton(0, guiLeft + 130, guiTop + 10 + y, 60, 20, new String[]{"gui.no", "gui.yes"}, options.enableOptions ? 1 : 0)); - addLabel(new GuiNpcLabel(1, "party.allowParty", guiLeft + 10, guiTop + 17 + y)); + addLabel(new GuiNpcLabel(1, "profile.enableOptions", guiLeft + 10, guiTop + 17 + y)); if (options.enableOptions) { y += 23; addButton(new GuiNpcButton(5, guiLeft + 130, guiTop + 10 + y, 60, 20, EnumProfileSync.values(), options.completeControl.ordinal())); - addLabel(new GuiNpcLabel(5, "party.partyRequirements", guiLeft + 10, guiTop + 17 + y)); + addLabel(new GuiNpcLabel(5, "profile.completion", guiLeft + 10, guiTop + 17 + y)); y += 23; addButton(new GuiNpcButton(18, guiLeft + 130, guiTop + 10 + y, 60, 20, EnumProfileSync.values(), options.cooldownControl.ordinal())); - addLabel(new GuiNpcLabel(18, "quest.objectives", guiLeft + 10, guiTop + 17 + y)); + addLabel(new GuiNpcLabel(18, "profile.cooldown", guiLeft + 10, guiTop + 17 + y)); } addButton(new GuiNpcButton(66, guiLeft + 200, guiTop + 192, 50, 20, "gui.done")); diff --git a/src/main/java/noppes/npcs/constants/EnumProfileSync.java b/src/main/java/noppes/npcs/constants/EnumProfileSync.java index f20e3e208..6702e08f7 100644 --- a/src/main/java/noppes/npcs/constants/EnumProfileSync.java +++ b/src/main/java/noppes/npcs/constants/EnumProfileSync.java @@ -4,7 +4,7 @@ import java.util.ArrayList; public enum EnumProfileSync { Individual("profile.individual"), - Shared("profile.shared"); + Shared("party.shared"); public final String name; diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 6997383b3..908d9f23c 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -1320,3 +1320,7 @@ profile.change.message=Do you want to change? profile.create.message=Creating a new profile will change you to it. profile.rename.message=Do you want to rename your slot? profile.operation.error=There was an error in your request +profile.enableOptions=Enable Options +profile.completion=Completion +profile.cooldown=Cooldown +profile.individual=Individual From ce1f652d5381e60d3a2b87090715bbb4bcc9d530 Mon Sep 17 00:00:00 2001 From: Kam Date: Fri, 21 Feb 2025 17:23:51 -0500 Subject: [PATCH 32/59] Fix Slot Creation Quest Syncing --- .../npcs/controllers/ProfileController.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index 3cfac441c..2f02a68a2 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -389,10 +389,11 @@ public class ProfileController implements IProfileController { } Slot newSlot = new Slot(newSlotId, "Slot " + newSlotId); newSlot.setLastLoaded(System.currentTimeMillis()); - if(profile.player != null) - verifySlotQuests(profile.player); - profile.getSlots().put(newSlotId, newSlot); + if(profile.player != null){ + verifySlotQuests(profile.player); + save(profile.player, profile); + } return ProfileOperation.success(MSG_NEW_SLOT_CREATED); } @@ -708,7 +709,7 @@ public class ProfileController implements IProfileController { playerData = PlayerData.get(player); } else { Slot slot = (Slot) profile.getSlots().get(slotID); - return getSlotPlayerData(player, slot); + playerData = getSlotPlayerData(player, slot); } return playerData; } @@ -719,7 +720,11 @@ public class ProfileController implements IProfileController { PlayerData playerData = new PlayerData(); playerData.player = player; - playerData.setNBT(slot.getComponentData(new CNPCData().getTagName())); + + NBTTagCompound compound = slot.getComponentData(new CNPCData().getTagName()); + if(compound == null) + compound = new NBTTagCompound(); + playerData.setNBT(compound); return playerData; } @@ -752,8 +757,10 @@ public class ProfileController implements IProfileController { for (ISlot slot : profile.getSlots().values()) { IPlayerData data = getSlotPlayerData(player, slot.getId()); if (data != null) { + PlayerData playerData = (PlayerData) data; PlayerQuestData questData = (PlayerQuestData) data.getQuestData(); questData.finishedQuests.putAll(universalFinished); + slot.setComponentData(new CNPCData().getTagName(), playerData.getNBT()); } } } From d7d968bf860391d9bd92fac07f082a720ecbd97a Mon Sep 17 00:00:00 2001 From: Kam Date: Fri, 21 Feb 2025 17:30:57 -0500 Subject: [PATCH 33/59] Scripting for Effects and Profiles --- src/api | 2 +- .../command/profile/CommandProfileAdmin.java | 2 +- .../command/profile/CommandProfileList.java | 2 +- .../npcs/controllers/ProfileController.java | 10 ++- .../npcs/controllers/data/IProfile.java | 33 ---------- .../controllers/data/IProfileController.java | 19 ------ .../kamkeel/npcs/controllers/data/ISlot.java | 61 ------------------- .../npcs/controllers/data/Profile.java | 2 + .../kamkeel/npcs/controllers/data/Slot.java | 1 + .../request/profile/ProfileGetInfoPacket.java | 2 +- .../gui/player/inventory/GuiProfiles.java | 2 +- .../noppes/npcs/controllers/data/Quest.java | 3 +- .../java/noppes/npcs/scripted/NpcAPI.java | 5 ++ 13 files changed, 18 insertions(+), 126 deletions(-) delete mode 100644 src/main/java/kamkeel/npcs/controllers/data/IProfile.java delete mode 100644 src/main/java/kamkeel/npcs/controllers/data/IProfileController.java delete mode 100644 src/main/java/kamkeel/npcs/controllers/data/ISlot.java diff --git a/src/api b/src/api index 30ba1bafa..dd3d8c552 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit 30ba1bafac147bc34cab98fadb38cff0dbab7b90 +Subproject commit dd3d8c552c515b48901f4c8d443b8c7cb85c0a20 diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java index 3affe65ad..4bc21da09 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java @@ -2,7 +2,7 @@ package kamkeel.npcs.command.profile; import kamkeel.npcs.controllers.ProfileController; import kamkeel.npcs.controllers.data.EnumProfileOperation; -import kamkeel.npcs.controllers.data.ISlot; +import noppes.npcs.api.handler.data.ISlot; import kamkeel.npcs.controllers.data.Profile; import kamkeel.npcs.controllers.data.ProfileOperation; import net.minecraft.command.CommandException; diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java index 7c15bc548..17e82fcce 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileList.java @@ -1,7 +1,7 @@ package kamkeel.npcs.command.profile; import kamkeel.npcs.controllers.ProfileController; -import kamkeel.npcs.controllers.data.ISlot; +import noppes.npcs.api.handler.data.ISlot; import kamkeel.npcs.controllers.data.Profile; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index 2f02a68a2..6c2808e1b 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -2,23 +2,21 @@ package kamkeel.npcs.controllers; import kamkeel.npcs.controllers.data.*; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.server.MinecraftServer; import noppes.npcs.CustomNpcs; import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.LogWriter; import noppes.npcs.NoppesUtilServer; import noppes.npcs.api.entity.IPlayer; import noppes.npcs.api.handler.IPlayerData; -import noppes.npcs.api.handler.data.IQuest; +import noppes.npcs.api.handler.data.IProfile; +import noppes.npcs.api.handler.IProfileHandler; +import noppes.npcs.api.handler.data.ISlot; import noppes.npcs.config.ConfigMain; -import noppes.npcs.constants.EnumProfileSync; import noppes.npcs.controllers.QuestController; import noppes.npcs.controllers.data.PlayerData; import noppes.npcs.controllers.data.PlayerQuestData; -import noppes.npcs.controllers.data.Quest; import noppes.npcs.util.CustomNPCsThreader; import noppes.npcs.util.NBTJsonUtil; @@ -31,7 +29,7 @@ import java.util.*; import static noppes.npcs.CustomNpcsPermissions.PROFILE_REGION_BYPASS; import static noppes.npcs.CustomNpcsPermissions.hasPermission; -public class ProfileController implements IProfileController { +public class ProfileController implements IProfileHandler { // Message constants private static final String MSG_PLAYER_NOT_FOUND = "Player not found."; diff --git a/src/main/java/kamkeel/npcs/controllers/data/IProfile.java b/src/main/java/kamkeel/npcs/controllers/data/IProfile.java deleted file mode 100644 index a82c724bb..000000000 --- a/src/main/java/kamkeel/npcs/controllers/data/IProfile.java +++ /dev/null @@ -1,33 +0,0 @@ -package kamkeel.npcs.controllers.data; - -import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.api.entity.IPlayer; - -import java.util.Map; - -public interface IProfile { - - - /** - * @return the IPlayer attached to the Profile - */ - IPlayer getPlayer(); - - - /** - * @return The profiles current Slot ID - */ - int getCurrentSlotId(); - - - /** - * @return Map of all Slot IDs - */ - Map getSlots(); - - - /** - * @return FULL NBT of the Profile - */ - NBTTagCompound writeToNBT(); -} diff --git a/src/main/java/kamkeel/npcs/controllers/data/IProfileController.java b/src/main/java/kamkeel/npcs/controllers/data/IProfileController.java deleted file mode 100644 index 960662ff8..000000000 --- a/src/main/java/kamkeel/npcs/controllers/data/IProfileController.java +++ /dev/null @@ -1,19 +0,0 @@ -package kamkeel.npcs.controllers.data; - -import noppes.npcs.api.entity.IPlayer; -import noppes.npcs.api.handler.IPlayerData; - -public interface IProfileController { - - IProfile getProfile(IPlayer player); - - boolean changeSlot(IPlayer player, int slotID); - - boolean hasSlot(IPlayer player, int slotID); - - boolean removeSlot(IPlayer player, int slotID); - - IPlayerData getSlotPlayerData(IPlayer player, int slotID); - - void saveSlotData(IPlayer player); -} diff --git a/src/main/java/kamkeel/npcs/controllers/data/ISlot.java b/src/main/java/kamkeel/npcs/controllers/data/ISlot.java deleted file mode 100644 index e41f2e60b..000000000 --- a/src/main/java/kamkeel/npcs/controllers/data/ISlot.java +++ /dev/null @@ -1,61 +0,0 @@ -package kamkeel.npcs.controllers.data; - -import net.minecraft.nbt.NBTTagCompound; - -import java.util.Map; - -public interface ISlot { - /** - * @return id of slot - */ - int getId(); - - /** - * @return Name of Slot - */ - String getName(); - - - /** - * @param name - New name of slot - */ - void setName(String name); - - /** - * @return Last time Slot was Saved - */ - long getLastLoaded(); - - /** - * @param time - Long time for when it was last saved - */ - void setLastLoaded(long time); - - /** - * @return if the slot is temporary - */ - boolean isTemporary(); - - /** - * @param temporary - Setting a slot to temporary won't save it to Profile - */ - void setTemporary(boolean temporary); - - /** - * @return A map of all the NBTs within a slot - */ - Map getComponents(); - - void setComponentData(String key, NBTTagCompound data); - - /** - * @param key - The KEY of the NBT for the Slot: [CNPC+, DBC... etc] - * @return NBT for that that key - */ - NBTTagCompound getComponentData(String key); - - /** - * @return The full NBT of the Slot - */ - NBTTagCompound toNBT(); -} diff --git a/src/main/java/kamkeel/npcs/controllers/data/Profile.java b/src/main/java/kamkeel/npcs/controllers/data/Profile.java index 03f91ad0c..d1be4fd40 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/Profile.java +++ b/src/main/java/kamkeel/npcs/controllers/data/Profile.java @@ -4,6 +4,8 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.NoppesUtilServer; import noppes.npcs.api.entity.IPlayer; +import noppes.npcs.api.handler.data.IProfile; +import noppes.npcs.api.handler.data.ISlot; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/kamkeel/npcs/controllers/data/Slot.java b/src/main/java/kamkeel/npcs/controllers/data/Slot.java index cfdc8fcbf..6c74b47c3 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/Slot.java +++ b/src/main/java/kamkeel/npcs/controllers/data/Slot.java @@ -1,6 +1,7 @@ package kamkeel.npcs.controllers.data; import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.api.handler.data.ISlot; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java index 43b2885a6..e83109ac3 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java @@ -4,7 +4,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; import kamkeel.npcs.controllers.ProfileController; -import kamkeel.npcs.controllers.data.ISlot; +import noppes.npcs.api.handler.data.ISlot; import kamkeel.npcs.controllers.data.InfoEntry; import kamkeel.npcs.controllers.data.Profile; import kamkeel.npcs.network.AbstractPacket; diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java index fe3b884a5..c4a805a68 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java @@ -1,6 +1,6 @@ package noppes.npcs.client.gui.player.inventory; -import kamkeel.npcs.controllers.data.ISlot; +import noppes.npcs.api.handler.data.ISlot; import kamkeel.npcs.controllers.data.InfoEntry; import kamkeel.npcs.controllers.data.Profile; import kamkeel.npcs.controllers.data.Slot; diff --git a/src/main/java/noppes/npcs/controllers/data/Quest.java b/src/main/java/noppes/npcs/controllers/data/Quest.java index 2a8f5c462..aab2d65b9 100644 --- a/src/main/java/noppes/npcs/controllers/data/Quest.java +++ b/src/main/java/noppes/npcs/controllers/data/Quest.java @@ -1,9 +1,8 @@ package noppes.npcs.controllers.data; import kamkeel.npcs.controllers.ProfileController; -import kamkeel.npcs.controllers.data.ISlot; +import noppes.npcs.api.handler.data.ISlot; import kamkeel.npcs.controllers.data.Profile; -import kamkeel.npcs.controllers.data.Slot; import kamkeel.npcs.network.packets.data.QuestCompletionPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index bda38006c..1b5df256e 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -2,6 +2,7 @@ package noppes.npcs.scripted; import cpw.mods.fml.common.eventhandler.EventBus; import foxz.command.ScriptedCommand; +import kamkeel.npcs.controllers.ProfileController; import net.minecraft.block.Block; import net.minecraft.command.CommandHandler; import net.minecraft.entity.Entity; @@ -241,6 +242,10 @@ public class NpcAPI extends AbstractNpcAPI { public INaturalSpawnsHandler getNaturalSpawns() { return SpawnController.Instance; } + public IProfileHandler getProfileHandler() { return ProfileController.Instance; } + + public ICustomEffectHandler getCustomEffectHandler() { return CustomEffectController.Instance; } + public ITransportHandler getLocations() { return TransportController.getInstance(); } From a37b32c1a506b03460e45e0b5ec14598cde1551c Mon Sep 17 00:00:00 2001 From: Kam Date: Fri, 21 Feb 2025 18:13:08 -0500 Subject: [PATCH 34/59] Effects Rendering Borders --- .../npcs/controllers/ProfileController.java | 3 +++ .../npcs/client/gui/SubGuiEffectGeneral.java | 8 ++++---- .../gui/global/GuiNPCManageEffects.java | 8 ++++---- .../gui/mainmenu/GuiNPCGlobalMainMenu.java | 2 +- .../player/inventory/GuiCNPCInventory.java | 4 ++-- .../gui/player/inventory/GuiSettings.java | 10 ++++++++++ .../npcs/client/gui/util/GuiEffectBar.java | 8 ++++++++ .../java/noppes/npcs/config/ConfigClient.java | 6 ++++++ .../assets/customnpcs/lang/en_US.lang | 1 + .../assets/customnpcs/textures/gui/icons.png | Bin 4653 -> 5191 bytes 10 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index 6c2808e1b..e7d14dbfd 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -91,6 +91,9 @@ public class ProfileController implements IProfileHandler { } public synchronized void login(EntityPlayer player) { + if(!ConfigMain.ProfilesEnabled) + return; + if (player == null) return; Profile profile; diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiEffectGeneral.java b/src/main/java/noppes/npcs/client/gui/SubGuiEffectGeneral.java index a5f8f0418..ea9152189 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiEffectGeneral.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiEffectGeneral.java @@ -16,6 +16,8 @@ import org.lwjgl.opengl.GL11; import java.util.ArrayList; import java.util.List; +import static noppes.npcs.client.gui.player.inventory.GuiCNPCInventory.specialIcons; + public class SubGuiEffectGeneral extends SubGuiInterface implements ITextfieldListener { private final GuiNPCManageEffects parent; public CustomEffect effect; @@ -128,10 +130,8 @@ public class SubGuiEffectGeneral extends SubGuiInterface implements ITextfieldLi func_152125_a(x, y, 0, 0, 1, 1, iconRenderSize, iconRenderSize, 1, 1); } GL11.glDisable(GL11.GL_DEPTH_TEST); - - // TODO: FIX TEXTURE - // textureManager.bindTexture(new ResourceLocation(CustomNpcPlusDBC.ID + ":textures/gui/icons.png")); - // func_152125_a(x, y, 0, 240, 16, 16, iconRenderSize, iconRenderSize, 256, 256); + textureManager.bindTexture(specialIcons); + func_152125_a(x, y, 0, 224, 16, 16, iconRenderSize, iconRenderSize, 256, 256); GL11.glEnable(GL11.GL_DEPTH_TEST); } }; diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageEffects.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageEffects.java index b227cc829..d0da71469 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageEffects.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageEffects.java @@ -28,6 +28,8 @@ import java.util.HashMap; import java.util.List; import java.util.Vector; +import static noppes.npcs.client.gui.player.inventory.GuiCNPCInventory.specialIcons; + public class GuiNPCManageEffects extends GuiNPCInterface2 implements ICustomScrollListener, IScrollData, IGuiData, ISubGuiListener, GuiYesNoCallback { public GuiCustomScroll scrollEffects; public HashMap data = new HashMap<>(); @@ -170,10 +172,8 @@ public class GuiNPCManageEffects extends GuiNPCInterface2 implements ICustomScro func_152125_a(x, y, 0, 0, 1, 1, iconRenderSize, iconRenderSize, 1, 1); } GL11.glDisable(GL11.GL_DEPTH_TEST); - - // TODO: Fix ICONS - // textureManager.bindTexture(new ResourceLocation(CustomNpcPlusDBC.ID + ":textures/gui/icons.png")); - // func_152125_a(x, y, 0, 240, 16, 16, iconRenderSize, iconRenderSize, 256, 256); + textureManager.bindTexture(specialIcons); + func_152125_a(x, y, 0, 224, 16, 16, iconRenderSize, iconRenderSize, 256, 256); GL11.glEnable(GL11.GL_DEPTH_TEST); x += iconRenderSize + 3; diff --git a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCGlobalMainMenu.java b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCGlobalMainMenu.java index 203b32c9f..a4b38906e 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCGlobalMainMenu.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCGlobalMainMenu.java @@ -83,7 +83,7 @@ public class GuiNPCGlobalMainMenu extends GuiNPCInterface2 { tagButton.setIconPos(24, 24, 192, 32).setIconTexture(specialIcons); registerButton(effectsButton = new GuiNpcSquareButton(19, 0, 0, 20, "global.customeffects", 0xFF333333)); - effectsButton.setIconPos(24, 24, 192, 32).setIconTexture(specialIcons); + effectsButton.setIconPos(24, 24, 24, 56).setIconTexture(specialIcons); // Layout composite buttons optimally. layoutButtons(); 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 ee607398b..7e5480712 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 @@ -83,7 +83,7 @@ public class GuiCNPCInventory extends GuiNPCInterface { int effectBarX = guiLeft + xSize + 65; int effectBarY = guiTop + 10; - int effectBarWidth = 24; + int effectBarWidth = 20; int effectBarHeight = ySize; effectBar = new GuiEffectBar(effectBarX, effectBarY, effectBarWidth, effectBarHeight); } @@ -107,7 +107,7 @@ public class GuiCNPCInventory extends GuiNPCInterface { public void drawScreen(int mouseX, int mouseY, float partialTicks) { updateEffectBar(); super.drawScreen(mouseX, mouseY, partialTicks); - if (effectBar != null) { + if (!ConfigClient.HideEffectsBar && effectBar != null && !effectBar.entries.isEmpty()) { effectBar.drawScreen(mouseX, mouseY, partialTicks); } } diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java index 19aea1433..44f2af54e 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java @@ -13,6 +13,7 @@ import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.GuiNpcTextField; import noppes.npcs.client.gui.util.ITextfieldListener; import noppes.npcs.config.ConfigClient; +import noppes.npcs.config.ConfigMain; import org.lwjgl.opengl.GL11; import tconstruct.client.tabs.AbstractTab; @@ -77,6 +78,9 @@ public class GuiSettings extends GuiCNPCInventory implements ITextfieldListener, y += 22; + this.addLabel(new GuiNpcLabel(8, "settings.effectsBar", guiLeft + 8, guiTop + 14 + y)); + this.addButton(new GuiNpcButton(8, guiLeft + 105, guiTop + 9 + y, 50, 20, new String[]{"gui.no", "gui.yes"}, ConfigClient.HideEffectsBar?1:0)); + y += 22; y += 22; @@ -154,6 +158,12 @@ public class GuiSettings extends GuiCNPCInventory implements ITextfieldListener, ConfigClient.BannerAlerts = button.getValue() == 1; ConfigClient.BannerAlertsProperty.set(ConfigClient.BannerAlerts); } + if(button.id == 8){ + ConfigClient.HideEffectsBar = button.getValue() == 1; + ConfigClient.HideEffectsBarProperty.set(ConfigClient.HideEffectsBar); + } + + ConfigClient.config.save(); } diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiEffectBar.java b/src/main/java/noppes/npcs/client/gui/util/GuiEffectBar.java index 96b78fc59..938265149 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiEffectBar.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiEffectBar.java @@ -4,6 +4,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.util.ResourceLocation; import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.client.renderer.ImageData; import noppes.npcs.controllers.data.CustomEffect; @@ -13,6 +14,8 @@ import org.lwjgl.opengl.GL11; import java.util.ArrayList; import java.util.List; +import static noppes.npcs.client.gui.player.inventory.GuiCNPCInventory.specialIcons; + public class GuiEffectBar extends GuiScreen { public int x, y, width, height; public int scrollY = 0; // Tracks vertical scrolling @@ -77,6 +80,11 @@ public class GuiEffectBar extends GuiScreen { int texWidth = imageData.getTotalWidth(); func_152125_a(x + 2, drawY + 2, iconU, iconV, iconWidth, iconHeight, iconRenderSize, iconRenderSize, texWidth, texWidth); + + GL11.glDisable(GL11.GL_DEPTH_TEST); + minecraft.getTextureManager().bindTexture(specialIcons); + func_152125_a(x + 2, drawY + 2, 0, 224, 16, 16, iconRenderSize, iconRenderSize, 256, 256); + GL11.glEnable(GL11.GL_DEPTH_TEST); } // If mouse hovers over this effect, save tooltip info diff --git a/src/main/java/noppes/npcs/config/ConfigClient.java b/src/main/java/noppes/npcs/config/ConfigClient.java index 459268552..d2d7d1a85 100644 --- a/src/main/java/noppes/npcs/config/ConfigClient.java +++ b/src/main/java/noppes/npcs/config/ConfigClient.java @@ -47,6 +47,9 @@ public class ConfigClient public static Property ChatBubblesFontTypeProperty; public static boolean ChatBubblesFontType = false; + public static Property HideEffectsBarProperty; + public static boolean HideEffectsBar = false; + /** * Questing Properties **/ @@ -127,6 +130,9 @@ public class ConfigClient ChatBubblesFontTypeProperty = config.get(VISUAL, "Chat Bubbles Font Type", false, "Enable the use of Custom Font for Chat Bubbles"); ChatBubblesFontType = ChatBubblesFontTypeProperty.getBoolean(false); + HideEffectsBarProperty = config.get(VISUAL, "Hide Effects Bar", false, "Hides CNPC+ Inventory Effects Bar"); + HideEffectsBar = HideEffectsBarProperty.getBoolean(false); + // Questing TrackingInfoAlignmentProperty = config.get(QUESTING, "Tracking Info Alignment", 3, "Client sided! Determines where tracking quest info shows up on the screen based on a number from 0 to 8. Default: 3"); TrackingInfoAlignment = TrackingInfoAlignmentProperty.getInt(3); diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 908d9f23c..c4f26dd2d 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -210,6 +210,7 @@ settings.dialogSound=Dialog Sound settings.dialogSpeed=Dialog Speed settings.chatAlerts=Chat Alerts settings.bannerAlerts=Banner Alerts +settings.effectsBar=Hide Effects Bar settings.alignmentX=Alignment X settings.alignmentY=Alignment Y settings.trackScale=Tracking Scale diff --git a/src/main/resources/assets/customnpcs/textures/gui/icons.png b/src/main/resources/assets/customnpcs/textures/gui/icons.png index bcfb3ba65e65c136dd12360329e2cb7c6466f3b9..49c1b77e922e80daced989d904c4eff3c02c3c60 100644 GIT binary patch delta 4652 zcmchbdo!Skl1mImE|m~Ms-X)>NaWgl2ceKlu8%IJ{DdMS zmqKPnZYAOu3FVfOyUAU{c;@$8&w8I{t#_^WulIfTT4$ZL_S$FfbN1S2?a$gJN-g*l z6X4`B}OWr<30#lyug~$SkYw=~Prm6cgLj zKloU3`*#gB5{VQL5J06;lai8-zEuPOyiM^c=WXd}1JJEBHY5TAb3HqVr@{JLx?BT5 zxZ$q_wfGgD2S7B?ie%yta%Sd!^2r@mRV_!PyWPdgPRge~^g8?&s4o5#gt zKz9~ZMw3&s+g@qkJ{){Ow@*t{QR+%JJ*|>E5(zSpok49l!g1)F<;u(YG|t4S zm%b+k%?GIHv$+5t%HJW(iTwVJO^z~i!-D{V+dV2IR zAN2c#bz+?pujHPt4yb(p!ssgQo4@GC5_+D-%*+gthQw4*eoy#?g?Xdy*Ev=X%nrsX z+Vc5VqFE#UuiOR(2IBdXs{-9FGbtNkvWjpg&-NfV^EfQL?o4Ud)J%}BDpl>|bBZrS zYaE$WA=!y<3qI991&Hg1bf5A(HjdbZ*V*`$mNSQDD%TH-KB_25s5)IO0QyrP`RBf- zdw2&h#B~X3q)k{FM75?eS$#*ulUtjKu%DuEWL3v=;`r&)6*JnB=(;i3Tt7Y%@^KT|(7EBKvV; zk!V!svflmhY(BDJ9qcQ~72ZxJB93N*^azuQ_MV-G4jp0#r0Me#N67@f!RHXG)A4-Z zGDw7yEher9so5eVsgYARkl6r39jqWhMCLudp+Z1I5394hf%0=-$0hvJcx8auvPBN~ z@G&L7Q=+>j7JC|{*H_KGcB;XEHO+U++7Y3tPVs_cel4C;ix412Cv-mN$$@P2uTS&O z>a{BaU$F0qviQB}505rXMMFCGl)xbFm>BT8rGlmElG0GDosX>$!$N;5LF`zsyCB3& z#|pguRhrt-VvzNIZiN#%xB2MQOUC-$mAyDUxZc>-kf$`<1246*$zECv;^ zgjpih+}HFK(Z)Hv)@Ng_r)2Z@B-0p2+=yc4Q@0uM%ZXP@Cy`=JA3d@>xC?8cklJZ0 zi6Q0THs6lZJ9G_yS85)($mzV~?hV%ujj52}OY4IPCx=^FTHxR*HEU*dgRI_JK%>+T z+0!&-bl}NmB0j=k7gi_+kR)H4nZ1m|-?3RYf&fECdg)GLQe#B|?!*l|A#teRZolu>TYGino8-fdd;mCsn7KjWhTON}JyeG%=GV}H8*ZbAOXAg-l@<%V)MsqC#51M8%UIW7l$?TwTlcX#Kg684YSq3-db=Gw|{J zJ&JY-BCEQC%AbnnVF1DE@uudS@P z;|IM_@G;13cYb#(GE?9Y<|3=RTRfdw+tqbKf=V(fxzy)#K$lrlqn}&8p^_7@va(WB zw>Id&G?yc8K#q=Xd$&hU$FUvD1@=BKHgt1?MKH!36 zkN-K^!k!=h^)Z*SK7jzZ&G|GvH+JbB%MmnTM@0=}ynIuIYK!S&Iw9w=2RB?cik_E_ zjh(#KE0O)QdCsOf{4xsRKff*O$gdDXk|X~W;3TnK;_L1b?{0^&xH{EM^1Vf#+Qbs zjLM9dri`B*+a;VNip7bDGd)-bY~t?SBi|b&EkAfj6(T~|K$0K~Z$~(v84N3{tgPf4 zWj#duBeUxiC$*uQ&a(b1vpNolOh_FHym9VY9&Ku2?WoFrEz$fBgI+2-g2J`gCv}jT zf8sxE2Q0I)|C zQ&VL>8RfqtRl#e4o2_vtk-;>n=Dfe^RrD*TOBqy&fqSb=SzLy58=AF!;nPJ(#naFD1035EB#+Ck>^C`u z9&Q4Y+-Qp|h_!mwROa=~wc&0KT{%i)A)IE57mvh>f}6c3O^Zd^ymK5!RMa0iM z2+Ixq;*|j!W#QYTSZAyA7PM_Q-%|sPGWNmK%u%-@NQ}*CA7XCID?g0N!e6_5k8^XO zjT6x4O#fEUeSJR<76X?nwIVCd2ca4*gft7j>6Qv)vriFE_!NZUAJ`PMG&eWX zr^-&RxhXg*LxQY?Tn*Gw9JfPr_4xgbjq!u=!J6sPFt~ByHk{Qbb|YobAk1Myhb`O9 zymXp&H4saE;F0<==jeX$ps*%7uw}ig@dXIH{_UFRn8rxvb+6RfX~y6{<-K-gG_AZm zpD*{0k6)3Q?H?7dR(>x{4bVMi zm=_6+!{gM|NTNl!fsy>>qE{#S2L?9syDOFe2;?#9Glo0d zMJP9k4@|Gw)>@~}HVoO~CWUokZb>nPsB3`^j^XJt^b(asStyW*=+z$f0S4`oOe}3< zhoOv*3g8ExL~XttTR^7e@l?_Y07kd*D;=AevCBqGn3O9J!5EBlH|tlo!>Pp%`8cOA9r{G!O|id$+h31-o5IqZ$!E5pn4(C3Y&cg z*G#GNqwR&_n;w{<*gg2HdqG>WKO>MxX{0TRAMN@SOE;Ssw8@Wf(;9@GT3e0@16iCW z_)DFT|Da(sAm1ZB`A+mjG&QS%eamn?&aU$Ph=RtpI|0@9MGlG4V`vtxJ5EGZMyh#4 zUYv>?Ez~oJOkjw8+4E6MjF2Rpl%qr0NiBEm*G^`Vt|Oh0X+aw zTN)f3I;Ysfv5985=Z@{<&WyjkU`7A?haDQ+2w8dvA{6r)jE30bpBcT9aIsBzzOLWk z>pdAEn|YtYtKKkDOD!yJDCQ|@&3J%{irQMvkIcL)4Yy#;OvX(X<3Fy@op(Sjb~F~P910NLV?L2(bfP> zjuVyhZa;3GwcJu3azse0(WEK|w~IoZ@f(_=oz4 z@Nn@0R&=Zh(I(z}wf>4)dSfH%JW(YY3@>^v71S_t?wxJ#v!~*5Olj6b_jKzY^COS0 zcH?7G?i1PSlw^-)#NVxrZo_1hl@)b(R>GkiNjVuw#C4!NN)KGGvfnGaLkPvvUunGR zVZ&cUQpvFVu8l>5R(NFMqI`kp&#s9b(6?XRo}d|C?J)DP=^IvvZQxtAeN@-Oh zAjLw}{tH-ggaEEk7K+0Rm)PyqZIhH+{NAVzv%L|P|7ssZczx$_-NmSf?PD*hZc_^h zLQg9zGY;k18$FlwQ~NQBMo>}ynEQpQ&tlgcTG!nbd7a3|XR?$3hmIN_#%|juWEai; zg6%%xGoo}xN3-8!MHM5&|XA@+Ea$lrXp!d`1E}ct0`zex|GI7WN)(AT!T@{S7aRNjn z;$UB7?0DicgcC|GOmcIgBC~mQo1>lhF4U`c*7AzvUDCVuTd%7Ce3bw1j$1>M$nqUJ zZ!QUqS^%5@BjhRYx->-Kjbf6PcPdl10=q|OqLqbzrkqbAV~4Thp?C}BPHZTqUV5sX zgXgpu`}WO=99&q>lUvqOxmZZpEMIRC;@&O1x(NR{JLMN>qHl*jKKx8x#KC5dbjtsZ{2tOAK?cJ$6kLL4`rUSvSJZ8~)&f zCqe-b?)d9KJwbn*20$eD5b;+>vfDyorqigkSkDj+86uu`r5Y84teAOY=uzdWU2{9V z;%k9vGPo}=KZH3gH?I3fu3aB%YKrh(-ALYb$!AGVzOO%{ z*#UFSmAKC=djdw@wpZ({=i`eKUT$eN+V<0$ol9k)e?<(``9yhbYi zd6yBlh06?COi*{K$yk3^s-rlirsyqWA@kD^hz`65^ZSfQPfrs{sWxMpO}@{EWNIXRU3uhQk0%y3U2APkrpT9XJd7r_w2w-|PrjYGjEBBovGK zEawXi6M}@2U?TykEbz;2unU&g4-aK_b2vuLW2dvpW`@tj735fUK;D%Nd0;8JCG+o{ z!$=8Y42X29IKLf*2Vcvy`M~ZEW}H|wFaT#DH>6Zb#?i|2IbQq#aqJidxU^+nYY$2$ zDy7s=6L>r&|ExRK$e#_J~yL6vg@{Wn(eOvl^ zLIcL`6^?sVqIgMxPGMLGr{gO$n7<3*S_HS~f5vhU6#uPot>WT--}0pf*8_R4KGzKzE7+^yxpkrX zNxJ&04Mz(_VrHM}JZ1(3iQlo1Oqf_s`S~o&eb$3tyKP{JI5F-A@4KQiHK~c;J(>Mc5K?W9TSXa-9USorR9eij~tW zv~qf9?C2h8m)35OXT!3+|N7f4lo1;LZDnC6_jxF|PPpAJrJve0GCfphT^nTxX~Pg^ z;7*Q%9^ZNPXTXe8wRMR-siv)Yorf6V4QY3Im#6M@SzJY1mN>p3k#ZbVA!j$YhNg${ zaIP`sBo^olYDuPhh0xDAz1q!iF2JP|*RXqJrs{VU?v)3oK9In)`^lE2=Q0~FQ+aX+ zV{WPe9Xegk`KQb&12F%FAHWYs#>PjDIoI5~W$bH>D2;xm8Q!K(@}V0J6^>uNm7Tbf z*7jWF@}5Lg36*A5bm!R~)d}&=*2YJTC$(ss>87jSCR=&Twn!94gF}Ps=yduwO-_Wc zkHcJAIaBpv!>Ii#z-#5T-t64~WIo4vtT-;eXS(>=y}>yx2$WdC9s72^!weYoHOV92 zpaLk3@*+4RKRqgkg%{50J%4_zv3}$_XQk%v=a>5GU0mj4+FGMYg}jDfNruwXtG%C{ zzRQB+eLin1{od`kIJhs7OABtOnK#9FXvhd#qVEw0!<;jT0cJ6r;JXbi;}Rek5v={< z9tC`GKb6RVd(ZpWdMs_-?V%gCZhUKE(OGNBs)+gV`NtM?uNz10O}0i!><`}=M0%5jd|7b`AI>k<#VuQw-tu+Fi-K~pAO>{%?P zIO_Lc@92%G?k50Oh4d*ej2b&5ow1 zipj<8+htOEh=wguKC~&bxTGxtuSG@&)i3X;Ncv2(EpPYNC^X z9ik+7HzjkVEp-ww)~{9Lxd$lyK8o8YLl!#NPocwta2POJ2yc4KGRk=T6eA68#km~1 zs$B8ZfS}P^`Sx6{Rq~8pZo6;( z{BNyc?{EG%%Nmrn0*sZF@M25$=&1UE{jlwqZ6;uGFK(~A8+I(tS1L1b0>%-8S(ih> zP9-3w(#RglqP&a(~j+MMa$R(r6o=kJ$yjY$e!yh8P@of?P9ojXAvWKqX$26%Cj88{WLk zFA7etIT4yg9vvCH?|i(}t6{q^(`~M7jYUcFWFwj%H6#}>O`DCV632~K# zh8{T4J0l`B2cqY0-L?5)i{x2u=DkC&+X&##oJYM4wdY#{*4B$~1BR6woYD!UrBMkS z|BvcLTQPr_DY<+5@EQJi#KckCsv!;Pp#8oI13sk{VZdnEDWVM>1&&P<^n zdUhSe^?H(ta$6m0(%P5JQDRAxXoXEDuRjm}Z=iJgUw8`s7ohsLxc{p#_#ce>|IGT| zr0~DgWqxCoGK++i%-Q<8zq-X_54CKxf9uLa zEZVT>52D$nKn=8P2;f;Y3LUsx^r0q%&fhTFE=nHqgJ0+ClDt0+HjJd^qF5M4{;iw3 zX*U{PrB64L@3;QQsD7Zku{KtyYr5ZMpSBDoqFGAsAAD=W6h;}lsx8w89;I5{buOg6 ze=BGOT5-l=r~alzbL;U(vOTr38+Uv_bMq7mv#|aX0L4i0=UO}wh&t6+LVPhi_nT;U zM#h8^B=)Xp;OXO&J|P3D_SFTxEl2kssZ-^pl=;QIS}w(yMs2KUiYbhH2>cujzltr6 zSNgqwaw_QS*RT7&#JxH<^`LCk7`m{$qRC}Gk-zd+E4Qyw1pkGFCUW<5H&VcTK2qfHkdCWY7(VOXpx$9z1pZF|-6T8(<&5MaMGYPULi zu_w^6>J)-Fq>blejC`KSq#9)6OMN~0oNJ0f#^C#)$Fk*~d;rA7X3B$|kuxH0<{qo0EZCfvCoGS;4j(1H+ z2`An48L){qY!f7PoT$JgEZ5BEQNlO;1g$CFH-C@S#Rnr^8(g7HZK*IIs=MnF%kDZ7I_(Bb(kF4%eKu^?d1V)qeMUAHePfq@PV?RekbZraf!gJ*(q zOy9{|f-tzEP`D*Ny}E%PrCL8d=f%YUuby98co0s&0GPyILwR~H-{MHWHMk`k$)r`n?W<0gzOGT+WBtF4Kyr%=LU<;jVEZl2VR<84Ns|SayY>71lkNE!p@_$b{ From 1c190fe5c4bdf65dad6db690c4670e651a216a37 Mon Sep 17 00:00:00 2001 From: Kam Date: Fri, 21 Feb 2025 19:37:57 -0500 Subject: [PATCH 35/59] Fix Some Rendering --- .../player/inventory/GuiCNPCInventory.java | 17 +++++++------- .../npcs/client/gui/util/GuiEffectBar.java | 23 +++++++++++++------ 2 files changed, 25 insertions(+), 15 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 7e5480712..4783e7cff 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 @@ -81,9 +81,9 @@ public class GuiCNPCInventory extends GuiNPCInterface { clientButton.renderResource = specialIcons; addSideButton(clientButton); - int effectBarX = guiLeft + xSize + 65; + int effectBarX = guiLeft - 40; int effectBarY = guiTop + 10; - int effectBarWidth = 20; + int effectBarWidth = 28; int effectBarHeight = ySize; effectBar = new GuiEffectBar(effectBarX, effectBarY, effectBarWidth, effectBarHeight); } @@ -108,23 +108,24 @@ public class GuiCNPCInventory extends GuiNPCInterface { updateEffectBar(); super.drawScreen(mouseX, mouseY, partialTicks); if (!ConfigClient.HideEffectsBar && effectBar != null && !effectBar.entries.isEmpty()) { - effectBar.drawScreen(mouseX, mouseY, partialTicks); + if(activeTab != -100) + effectBar.drawScreen(mouseX, mouseY, partialTicks); } } @Override public void handleMouseInput() { - super.handleMouseInput(); int delta = Mouse.getDWheel(); if (delta != 0 && effectBar != null) { - int mouseX = Mouse.getX() * width / mc.displayWidth; - int mouseY = height - Mouse.getY() * height / mc.displayHeight - 1; - // Only scroll the effect bar if the mouse is over its area. + int mouseX = Mouse.getX() * this.width / mc.displayWidth; + int mouseY = this.height - Mouse.getY() * this.height / mc.displayHeight - 1; if (mouseX >= effectBar.x && mouseX < effectBar.x + effectBar.width && mouseY >= effectBar.y && mouseY < effectBar.y + effectBar.height) { - effectBar.mouseScrolled(delta > 0 ? 1 : -1); + // Use delta/120 to convert the typical scroll wheel values to ±1 + effectBar.mouseScrolled(delta / 120); } } + super.handleMouseInput(); } diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiEffectBar.java b/src/main/java/noppes/npcs/client/gui/util/GuiEffectBar.java index 938265149..7aa4119a2 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiEffectBar.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiEffectBar.java @@ -4,6 +4,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.util.ResourceLocation; import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.client.renderer.ImageData; @@ -19,7 +20,7 @@ import static noppes.npcs.client.gui.player.inventory.GuiCNPCInventory.specialIc public class GuiEffectBar extends GuiScreen { public int x, y, width, height; public int scrollY = 0; // Tracks vertical scrolling - public int entryHeight = 20; // Height for each effect slot + public int entryHeight = 28; // Height for each effect slot public List entries = new ArrayList<>(); public FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer; @@ -55,8 +56,10 @@ public class GuiEffectBar extends GuiScreen { int scissorH = height * scaleFactor; GL11.glScissor(scissorX, scissorY, scissorW, scissorH); - int iconRenderSize = 16; + int iconRenderSize = 24; int padding = 1; + // Calculate vertical offset to center the icon in the slot + int iconYOffset = (entryHeight - iconRenderSize) / 2; int startIndex = scrollY / (entryHeight + padding); int endIndex = Math.min(entries.size(), startIndex + height / (entryHeight + padding) + 1); @@ -79,15 +82,16 @@ public class GuiEffectBar extends GuiScreen { int iconHeight = entry.effect.getHeight(); int texWidth = imageData.getTotalWidth(); - func_152125_a(x + 2, drawY + 2, iconU, iconV, iconWidth, iconHeight, iconRenderSize, iconRenderSize, texWidth, texWidth); + // Use iconYOffset to vertically center the icon + func_152125_a(x + 2, drawY + iconYOffset, iconU, iconV, iconWidth, iconHeight, iconRenderSize, iconRenderSize, texWidth, texWidth); GL11.glDisable(GL11.GL_DEPTH_TEST); - minecraft.getTextureManager().bindTexture(specialIcons); - func_152125_a(x + 2, drawY + 2, 0, 224, 16, 16, iconRenderSize, iconRenderSize, 256, 256); + Minecraft.getMinecraft().getTextureManager().bindTexture(specialIcons); + func_152125_a(x + 2, drawY + iconYOffset, 0, 224, 16, 16, iconRenderSize, iconRenderSize, 256, 256); GL11.glEnable(GL11.GL_DEPTH_TEST); } - // If mouse hovers over this effect, save tooltip info + // Mouse hover logic remains unchanged if (mouseX >= x && mouseX < x + width && mouseY >= drawY && mouseY < drawY + entryHeight) { int seconds = entry.playerEffect.duration; @@ -126,7 +130,8 @@ public class GuiEffectBar extends GuiScreen { * Adjusted scrolling to move up and down instead of left and right. */ public void mouseScrolled(int delta) { - int totalHeight = entries.size() * entryHeight; + int padding = 1; + int totalHeight = entries.size() * (entryHeight + padding); scrollY -= delta * 10; // Adjust scroll speed as needed. if (scrollY < 0) scrollY = 0; if (scrollY > totalHeight - height) scrollY = Math.max(totalHeight - height, 0); @@ -155,6 +160,7 @@ public class GuiEffectBar extends GuiScreen { int screenWidth = Minecraft.getMinecraft().currentScreen.width; int screenHeight = Minecraft.getMinecraft().currentScreen.height; + TextureManager textureManager = Minecraft.getMinecraft().getTextureManager(); int tooltipX = x + 12; int tooltipY = y - 12; @@ -188,7 +194,10 @@ public class GuiEffectBar extends GuiScreen { func_152125_a(tooltipX + (maxWidth - iconSize) / 2, textY + 4, hoveredEffect.iconX, hoveredEffect.iconY, hoveredEffect.getWidth(), hoveredEffect.getHeight(), iconSize, iconSize, imageData.getTotalWidth(), imageData.getTotalWidth()); } + textureManager.bindTexture(specialIcons); + func_152125_a(tooltipX + (maxWidth - iconSize) / 2, textY + 4, 0, 224, 16, 16, iconSize, iconSize, 256, 256); GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glPopMatrix(); GL11.glPopAttrib(); } From b98f024fbddd3abfe83ad4e4e1c44452d4a81336 Mon Sep 17 00:00:00 2001 From: Kam Date: Fri, 21 Feb 2025 20:00:55 -0500 Subject: [PATCH 36/59] Shrink Chair + Add Lang for Items --- .../npcs/client/renderer/blocks/BlockChairRenderer.java | 4 ++-- src/main/resources/assets/customnpcs/lang/en_US.lang | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/client/renderer/blocks/BlockChairRenderer.java b/src/main/java/noppes/npcs/client/renderer/blocks/BlockChairRenderer.java index bd915dfc9..b7dd1b738 100644 --- a/src/main/java/noppes/npcs/client/renderer/blocks/BlockChairRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/blocks/BlockChairRenderer.java @@ -42,8 +42,8 @@ public class BlockChairRenderer extends BlockRendererInterface{ GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); GL11.glDisable(GL12.GL_RESCALE_NORMAL); GL11.glPushMatrix(); - GL11.glTranslatef((float)var2 + 0.5f, (float)var4 + 1.65f, (float)var6 + 0.5f); - GL11.glScalef(1.2f, 1.1f, 1.2f); + GL11.glTranslatef((float)var2 + 0.5f, (float)var4 + 1.5f, (float)var6 + 0.5f); + // GL11.glScalef(1.2f, 1.1f, 1.2f); GL11.glRotatef(180, 0, 0, 1); GL11.glRotatef(90 * tile.rotation, 0, 1, 0); GL11.glColor3f(1, 1, 1); diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index c4f26dd2d..2e118025d 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -764,6 +764,10 @@ item.npcMounter.name=Mounter item.npcTeleporter.name=Teleporter item.npcScripter.name=Scripter item.scripted_item.name=Scripted Item +item.linked_item.name=Linked Item +item.npcTool.hammer.name=Npc Hammer +item.npcTool.paintbrush.name=Npc Brush + item.npcBanjo.name=Banjo item.npcViolin.name=Violin From faf335c8310fcef3b892defda174cf063ca1ae90 Mon Sep 17 00:00:00 2001 From: Kam Date: Fri, 21 Feb 2025 21:43:47 -0500 Subject: [PATCH 37/59] Working Tool Renderer --- .../java/noppes/npcs/client/ClientProxy.java | 2 +- .../renderer/items/NpcItemToolRenderer.java | 9 +- .../renderer/items/ToolItemRenderer.java | 550 ++++++++++++++++++ .../textures/items/npcBrushHair.png | Bin 0 -> 222 bytes .../textures/items/npcBrushHandle.png | Bin 0 -> 227 bytes .../textures/items/paintbrush_brush.png | Bin 184 -> 0 bytes .../textures/items/paintbrush_handle.png | Bin 180 -> 0 bytes 7 files changed, 555 insertions(+), 6 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/renderer/items/ToolItemRenderer.java create mode 100644 src/main/resources/assets/customnpcs/textures/items/npcBrushHair.png create mode 100644 src/main/resources/assets/customnpcs/textures/items/npcBrushHandle.png delete mode 100644 src/main/resources/assets/customnpcs/textures/items/paintbrush_brush.png delete mode 100644 src/main/resources/assets/customnpcs/textures/items/paintbrush_handle.png diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index 63bdaa45b..f62284c97 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -535,7 +535,7 @@ public class ClientProxy extends CommonProxy { if (item instanceof ItemScripted || item instanceof ItemLinked) { MinecraftForgeClient.registerItemRenderer(item, new CustomItemRenderer()); } else if (item instanceof ItemNpcTool) { - MinecraftForgeClient.registerItemRenderer(item, new NpcItemToolRenderer()); + MinecraftForgeClient.registerItemRenderer(item, new ToolItemRenderer()); }else { MinecraftForgeClient.registerItemRenderer(item, new NpcItemRenderer()); } diff --git a/src/main/java/noppes/npcs/client/renderer/items/NpcItemToolRenderer.java b/src/main/java/noppes/npcs/client/renderer/items/NpcItemToolRenderer.java index 2b79acdf9..7d6c8099b 100644 --- a/src/main/java/noppes/npcs/client/renderer/items/NpcItemToolRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/items/NpcItemToolRenderer.java @@ -16,19 +16,18 @@ import org.lwjgl.opengl.GL12; public class NpcItemToolRenderer implements IItemRenderer { // Textures for the assembled paintbrush parts: - private static final ResourceLocation PAINTBRUSH_HANDLE = new ResourceLocation("customnpcs", "textures/items/paintbrush_handle.png"); - private static final ResourceLocation PAINTBRUSH_BRUSH = new ResourceLocation("customnpcs", "textures/items/paintbrush_brush.png"); + private static final ResourceLocation PAINTBRUSH_HANDLE = new ResourceLocation("customnpcs", "textures/items/npcBrushHandle.png"); + private static final ResourceLocation PAINTBRUSH_BRUSH = new ResourceLocation("customnpcs", "textures/items/npcBrushHair.png"); private static final ResourceLocation ENCHANT = new ResourceLocation("textures/misc/enchanted_item_glint.png"); @Override public boolean handleRenderType(ItemStack item, ItemRenderType type) { - // Only handle equipped types (first person or third person equipped) - return type == ItemRenderType.EQUIPPED || type == ItemRenderType.EQUIPPED_FIRST_PERSON; + return type != ItemRenderType.FIRST_PERSON_MAP; } @Override public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { - return false; + return helper == ItemRendererHelper.ENTITY_ROTATION || helper == ItemRendererHelper.ENTITY_BOBBING; } @Override diff --git a/src/main/java/noppes/npcs/client/renderer/items/ToolItemRenderer.java b/src/main/java/noppes/npcs/client/renderer/items/ToolItemRenderer.java new file mode 100644 index 000000000..a015f840d --- /dev/null +++ b/src/main/java/noppes/npcs/client/renderer/items/ToolItemRenderer.java @@ -0,0 +1,550 @@ +package noppes.npcs.client.renderer.items; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.IItemRenderer; +import noppes.npcs.api.item.IItemCustomizable; +import noppes.npcs.api.item.IItemStack; +import noppes.npcs.client.ClientCacheHandler; +import noppes.npcs.client.renderer.ImageData; +import noppes.npcs.items.ItemCustomizable; +import noppes.npcs.items.ItemNpcTool; +import noppes.npcs.scripted.NpcAPI; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +import java.util.Random; + +import static net.minecraft.client.renderer.entity.RenderItem.renderInFrame; + +public class ToolItemRenderer implements IItemRenderer { + + private static final ResourceLocation RES_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png"); + private static final ResourceLocation PAINTBRUSH_HANDLE = new ResourceLocation("customnpcs", "textures/items/npcBrushHandle.png"); + private static final ResourceLocation PAINTBRUSH_BRUSH = new ResourceLocation("customnpcs", "textures/items/npcBrushHair.png"); + private final Random random = new Random(); + + private int item3dRenderTicks = 1; + + @Override + public boolean handleRenderType(ItemStack item, ItemRenderType type) { + return type != ItemRenderType.FIRST_PERSON_MAP; + } + + @Override + public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { + return helper == ItemRendererHelper.ENTITY_ROTATION || helper == ItemRendererHelper.ENTITY_BOBBING; + } + + @Override + public void renderItem(ItemRenderType type, ItemStack itemStack, Object... data) { + if (itemStack == null || !(itemStack.getItem() instanceof ItemNpcTool)) { + return; + } + + if (type == ItemRenderType.INVENTORY) { + GL11.glPushMatrix(); + renderInventoryCustomItem(itemStack); + GL11.glPopMatrix(); + return; + } + if (type == ItemRenderType.ENTITY) { + GL11.glPushMatrix(); + EntityItem entityItem = (EntityItem) data[1]; + if (!entityItem.ignoreFrustumCheck) { + entityItem.ignoreFrustumCheck = true; + + float entityXZSize = (float) Math.sqrt(Math.pow(1,2) + Math.pow(1,2)); + this.setEntitySize(entityItem, entityXZSize * 0.25F, 1 * 0.25F); + + double XSize = entityItem.boundingBox.maxX - entityItem.boundingBox.minX; + double YSize = entityItem.boundingBox.maxY - entityItem.boundingBox.minY; + double ZSize = entityItem.boundingBox.maxZ - entityItem.boundingBox.minZ; + entityItem.boundingBox.maxX = entityItem.boundingBox.minX + XSize * 1; + entityItem.boundingBox.maxY = entityItem.boundingBox.minY + YSize * 1; + entityItem.boundingBox.maxZ = entityItem.boundingBox.minZ + ZSize * 1; + } + + float entityRenderTicks = Minecraft.getMinecraft().timer.renderPartialTicks; + float bobbing = MathHelper.sin(((float)entityItem.age + entityRenderTicks) / 10.0F + entityItem.hoverStart) * 0.1F + 0.1F; + + GL11.glRotatef(1 * entityRenderTicks %360, 1, 0, 0); + GL11.glRotatef(1 * entityRenderTicks %360, 0, 1, 0); + GL11.glRotatef(1 * entityRenderTicks %360, 0, 0, 1); + + if (!renderInFrame) { + GL11.glTranslatef(0.0F, -bobbing, 0.0F); + } + + renderEntityCustomItem(itemStack, entityItem, PAINTBRUSH_HANDLE); + int color = ItemNpcTool.getColor(itemStack.getTagCompound()); + float red = ((color >> 16) & 0xFF) / 255.0F; + float green = ((color >> 8) & 0xFF) / 255.0F; + float blue = (color & 0xFF) / 255.0F; + GL11.glColor3f(red, green, blue); + renderEntityCustomItem(itemStack, entityItem, PAINTBRUSH_BRUSH); + + GL11.glPopMatrix(); + return; + } + GL11.glPushMatrix(); + + GL11.glTranslatef(0.9375F, 0.0625F, 0.0F); + GL11.glRotatef(-315.0F, 0.0F, 0.0F, 1.0F); + GL11.glTranslatef(0.135F * 1, 0.2F * 1, 0.07F * 1); + + GL11.glScalef(1, 1, 1); + GL11.glRotatef(-20.0F, 0.0F, 0.0F, 1.0F); + GL11.glRotatef(-50.0F, 0.0F, 1.0F, 0.0F); + GL11.glTranslatef(-0.09375F, 0.0625F, 0.0F); + + + EntityLivingBase entityLivingBase = (EntityLivingBase) data[1]; + + GL11.glPushMatrix(); + renderItem3d(entityLivingBase, itemStack, PAINTBRUSH_HANDLE); + GL11.glPopMatrix(); + + int color = ItemNpcTool.getColor(itemStack.getTagCompound()); + float red = ((color >> 16) & 0xFF) / 255.0F; + float green = ((color >> 8) & 0xFF) / 255.0F; + float blue = (color & 0xFF) / 255.0F; + GL11.glColor3f(red, green, blue); + + GL11.glPushMatrix(); + renderItem3d(entityLivingBase, itemStack, PAINTBRUSH_BRUSH); + GL11.glPopMatrix(); + + GL11.glPopMatrix(); + } + + private void setEntitySize(EntityItem entityItem, float p_70105_1_, float p_70105_2_) + { + float f2; + + if (p_70105_1_ != entityItem.width || p_70105_2_ != entityItem.height) + { + f2 = entityItem.width; + entityItem.width = p_70105_1_; + entityItem.height = p_70105_2_; + entityItem.boundingBox.maxX = entityItem.boundingBox.minX + (double)entityItem.width; + entityItem.boundingBox.maxZ = entityItem.boundingBox.minZ + (double)entityItem.width; + entityItem.boundingBox.maxY = entityItem.boundingBox.minY + (double)entityItem.height; + + if (entityItem.width > f2 && !entityItem.firstUpdate && !entityItem.worldObj.isRemote) + { + entityItem.moveEntity((double)(f2 - entityItem.width), 0.0D, (double)(f2 - entityItem.width)); + } + } + + f2 = p_70105_1_ % 2.0F; + + if ((double)f2 < 0.375D) + { + entityItem.myEntitySize = Entity.EnumEntitySize.SIZE_1; + } + else if ((double)f2 < 0.75D) + { + entityItem.myEntitySize = Entity.EnumEntitySize.SIZE_2; + } + else if ((double)f2 < 1.0D) + { + entityItem.myEntitySize = Entity.EnumEntitySize.SIZE_3; + } + else if ((double)f2 < 1.375D) + { + entityItem.myEntitySize = Entity.EnumEntitySize.SIZE_4; + } + else if ((double)f2 < 1.75D) + { + entityItem.myEntitySize = Entity.EnumEntitySize.SIZE_5; + } + else + { + entityItem.myEntitySize = Entity.EnumEntitySize.SIZE_6; + } + } + + public void renderEntityCustomItem(ItemStack itemStack, EntityItem entityItem, ResourceLocation location) { + int pass = 0; + + GL11.glPushMatrix(); + TextureManager textureManager = Minecraft.getMinecraft().getTextureManager(); + textureManager.bindTexture(location); + + if (renderInFrame) + { + GL11.glTranslatef(0.0F, -0.05F, 0.0F); + GL11.glScalef(1.025641F,1.025641F,1.025641F); + GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F); + } + + Tessellator tessellator = Tessellator.instance; + + float f14 = 0.0F; + float f15 = 1.0F; + float f4 = 0.0F; + float f5 = 1.0F; + float f6 = 1.0F; + float f7 = 0.5F; + float f8 = 0.25F; + float f10; + + if (RenderManager.instance.options.fancyGraphics) + { + GL11.glPushMatrix(); + + float f9 = 0.0625F; + f10 = 0.021875F; + int j = itemStack.stackSize; + byte b0; + + if (j < 2) + { + b0 = 1; + } + else if (j < 16) + { + b0 = 2; + } + else if (j < 32) + { + b0 = 3; + } + else + { + b0 = 4; + } + + GL11.glTranslatef(-f7, -f8, -((f9 + f10) * (float)b0 / 2.0F)); + + for (int k = 0; k < b0; ++k) + { + GL11.glTranslatef(0f, 0f, f9 + f10); + // TODO: May need to rebind here + ItemRenderer.renderItemIn2D(tessellator, 1.0F, 0.0F, 0.0F, 1.0F, 16, 16, f9); + if (itemStack.hasEffect(pass)) + { + GL11.glDepthFunc(GL11.GL_EQUAL); + GL11.glDisable(GL11.GL_LIGHTING); + RenderManager.instance.renderEngine.bindTexture(RES_ITEM_GLINT); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); + float f11 = 0.76F; + GL11.glColor4f(0.5F * f11, 0.25F * f11, 0.8F * f11, 1.0F); + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glPushMatrix(); + float f12 = 0.125F; + GL11.glScalef(f12, f12, f12); + float f13 = (float)(Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F; + GL11.glTranslatef(f13, 0.0F, 0.0F); + GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F); + ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 255, 255, f9); + GL11.glPopMatrix(); + GL11.glPushMatrix(); + GL11.glScalef(f12, f12, f12); + f13 = (float)(Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F; + GL11.glTranslatef(-f13, 0.0F, 0.0F); + GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F); + ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 255, 255, f9); + GL11.glPopMatrix(); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GL11.glDisable(GL11.GL_BLEND); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glDepthFunc(GL11.GL_LEQUAL); + } + } + + GL11.glPopMatrix(); + } + else + { + int j = itemStack.stackSize; + int b0; + + if (j < 2) + { + b0 = 1; + } + else if (j < 16) + { + b0 = 2; + } + else if (j < 32) + { + b0 = 3; + } + else + { + b0 = 4; + } + + for (int l = 0; l < b0; ++l) + { + GL11.glPushMatrix(); + + if (l > 0) + { + f10 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.3F; + float f16 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.3F; + float f17 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.3F; + GL11.glTranslatef(f10, f16, f17); + } + + if (!renderInFrame) + { + GL11.glRotatef(180.0F - RenderManager.instance.playerViewY, 0.0F, 1.0F, 0.0F); + } + + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 1.0F, 0.0F); + tessellator.addVertexWithUV((double)(0.0F - f7), (double)(0.0F - f8), 0.0D, (double)f14, (double)f5); + tessellator.addVertexWithUV((double)(f6 - f7), (double)(0.0F - f8), 0.0D, (double)f15, (double)f5); + tessellator.addVertexWithUV((double)(f6 - f7), (double)(1.0F - f8), 0.0D, (double)f15, (double)f4); + tessellator.addVertexWithUV((double)(0.0F - f7), (double)(1.0F - f8), 0.0D, (double)f14, (double)f4); + tessellator.draw(); + GL11.glPopMatrix(); + } + } + GL11.glPopMatrix(); + } + + public void renderInventoryCustomItem(ItemStack itemStack) { + GL11.glPushMatrix(); + TextureManager textureManager = Minecraft.getMinecraft().getTextureManager(); + + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_ALPHA_TEST); + + textureManager.bindTexture(PAINTBRUSH_HANDLE); + renderCustomItemSlot(0,0,16,16, 1.0f, 1.0f, 1.0f); + + int color = ItemNpcTool.getColor(itemStack.getTagCompound()); + float red = ((color >> 16) & 0xFF) / 255.0F; + float green = ((color >> 8) & 0xFF) / 255.0F; + float blue = (color & 0xFF) / 255.0F; + textureManager.bindTexture(PAINTBRUSH_BRUSH); + renderCustomItemSlot(0,0,16,16, red, green, blue); + + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_ALPHA_TEST); + + if (itemStack.hasEffect(0)) + { + renderEffect(Minecraft.getMinecraft().getTextureManager(), 0, 0); + } + + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glPopMatrix(); + } + + public void renderEffect(TextureManager manager, int x, int y) + { + GL11.glDepthFunc(GL11.GL_EQUAL); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDepthMask(false); + manager.bindTexture(RES_ITEM_GLINT); + GL11.glEnable(GL11.GL_ALPHA_TEST); + GL11.glEnable(GL11.GL_BLEND); + GL11.glColor4f(0.5F, 0.25F, 0.8F, 1.0F); + this.renderGlint(x - 2, y - 2, 20, 20); + GL11.glDepthMask(true); + GL11.glDisable(GL11.GL_BLEND); + GL11.glDisable(GL11.GL_ALPHA_TEST); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glDepthFunc(GL11.GL_LEQUAL); + } + + private void renderGlint(int p_77018_2_, int p_77018_3_, int p_77018_4_, int p_77018_5_) + { + for (int j1 = 0; j1 < 2; ++j1) + { + OpenGlHelper.glBlendFunc(772, 1, 0, 0); + float f = 0.00390625F; + float f1 = 0.00390625F; + float f2 = (float)(Minecraft.getSystemTime() % (long)(3000 + j1 * 1873)) / (3000.0F + (float)(j1 * 1873)) * 256.0F; + float f3 = 0.0F; + Tessellator tessellator = Tessellator.instance; + float f4 = 4.0F; + + if (j1 == 1) + { + f4 = -1.0F; + } + + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV((double)(p_77018_2_ + 0), (double)(p_77018_3_ + p_77018_5_), 0, (double)((f2 + (float)p_77018_5_ * f4) * f), (double)((f3 + (float)p_77018_5_) * f1)); + tessellator.addVertexWithUV((double)(p_77018_2_ + p_77018_4_), (double)(p_77018_3_ + p_77018_5_), 0, (double)((f2 + (float)p_77018_4_ + (float)p_77018_5_ * f4) * f), (double)((f3 + (float)p_77018_5_) * f1)); + tessellator.addVertexWithUV((double)(p_77018_2_ + p_77018_4_), (double)(p_77018_3_ + 0), 0, (double)((f2 + (float)p_77018_4_) * f), (double)((f3 + 0.0F) * f1)); + tessellator.addVertexWithUV((double)(p_77018_2_ + 0), (double)(p_77018_3_ + 0), 0, (double)((f2 + 0.0F) * f), (double)((f3 + 0.0F) * f1)); + tessellator.draw(); + } + } + + public void renderCustomItemSlot(int posX, int posY, int imageWidth, int imageHeight, float itemRed, float itemGreen, float itemBlue) { + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.setColorRGBA_F(itemRed, itemGreen, itemBlue, 1.0F); + tessellator.addVertexWithUV((double)(posX), (double)(posY + imageHeight), 0, 0, 1); + tessellator.addVertexWithUV((double)(posX + imageWidth), (double)(posY + imageHeight), 0, 1, 1); + tessellator.addVertexWithUV((double)(posX + imageWidth), (double)(posY), 0, 1, 0); + tessellator.addVertexWithUV((double)(posX), (double)(posY), 0, 0, 0); + tessellator.draw(); + } + + public void renderItem3d(EntityLivingBase entityLivingBase, ItemStack itemStack, ResourceLocation location) { + item3dRenderTicks++; + + Minecraft mc = Minecraft.getMinecraft(); + TextureManager texturemanager = mc.getTextureManager(); + int par3 = 0; + + texturemanager.bindTexture(location); + + Tessellator tessellator = Tessellator.instance; + IIcon icon = entityLivingBase.getItemIcon(itemStack, par3); + + if (icon == null) { + return; + } + + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + + float f4 = 0.0F; + float f5 = 0.3F; + GL11.glTranslatef(-f4, -f5, 0.0F); + GL11.glRotatef(50.0F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(335.0F, 0.0F, 0.0F, 1.0F); + GL11.glTranslatef(-0.9375F, -0.0625F, 0.0F); + + renderCustomItemIn2D(tessellator, 1.0F, 0.0F, 0.0F, 1.0F, 0.0625F); + + if (itemStack.hasEffect(par3)) { + GL11.glDepthFunc(GL11.GL_EQUAL); + GL11.glDisable(GL11.GL_LIGHTING); + texturemanager.bindTexture(RES_ITEM_GLINT); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); + float f7 = 0.76F; + GL11.glColor4f(0.5F * f7, 0.25F * f7, 0.8F * f7, 1.0F); + GL11.glMatrixMode(GL11.GL_TEXTURE); + GL11.glPushMatrix(); + float f8 = 0.125F; + GL11.glScalef(f8, f8, f8); + float f9 = (float) (Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F; + GL11.glTranslatef(f9, 0.0F, 0.0F); + GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F); + ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F); + GL11.glPopMatrix(); + GL11.glPushMatrix(); + GL11.glScalef(f8, f8, f8); + f9 = (float) (Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F; + GL11.glTranslatef(-f9, 0.0F, 0.0F); + GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F); + ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F); + GL11.glPopMatrix(); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GL11.glDisable(GL11.GL_BLEND); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glDepthFunc(GL11.GL_LEQUAL); + } + + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + } + + public static void renderCustomItemIn2D(Tessellator p_78439_0_, float p_78439_1_, float p_78439_2_, float p_78439_3_, float p_78439_4_, float p_78439_7_) + { + int width = 16; + int height = 16; + + p_78439_0_.startDrawingQuads(); + p_78439_0_.setNormal(0.0F, 0.0F, 1.0F); + p_78439_0_.addVertexWithUV(0.0D, 0.0D, 0.0D, (double)p_78439_1_, (double)p_78439_4_); + p_78439_0_.addVertexWithUV(1.0D, 0.0D, 0.0D, (double)p_78439_3_, (double)p_78439_4_); + p_78439_0_.addVertexWithUV(1.0D, 1.0D, 0.0D, (double)p_78439_3_, (double)p_78439_2_); + p_78439_0_.addVertexWithUV(0.0D, 1.0D, 0.0D, (double)p_78439_1_, (double)p_78439_2_); + p_78439_0_.draw(); + p_78439_0_.startDrawingQuads(); + p_78439_0_.setNormal(0.0F, 0.0F, -1.0F); + p_78439_0_.addVertexWithUV(0.0D, 1.0D, (double)(0.0F - p_78439_7_), (double)p_78439_1_, (double)p_78439_2_); + p_78439_0_.addVertexWithUV(1.0D, 1.0D, (double)(0.0F - p_78439_7_), (double)p_78439_3_, (double)p_78439_2_); + p_78439_0_.addVertexWithUV(1.0D, 0.0D, (double)(0.0F - p_78439_7_), (double)p_78439_3_, (double)p_78439_4_); + p_78439_0_.addVertexWithUV(0.0D, 0.0D, (double)(0.0F - p_78439_7_), (double)p_78439_1_, (double)p_78439_4_); + p_78439_0_.draw(); + float f5 = 0.5F * (p_78439_1_ - p_78439_3_) / (float)width; + float f6 = 0.5F * (p_78439_4_ - p_78439_2_) / (float)height; + p_78439_0_.startDrawingQuads(); + p_78439_0_.setNormal(-1.0F, 0.0F, 0.0F); + int k; + float f7; + float f8; + + for (k = 0; k < width; ++k) + { + f7 = (float)k / (float)width; + f8 = p_78439_1_ + (p_78439_3_ - p_78439_1_) * f7 - f5; + p_78439_0_.addVertexWithUV((double)f7, 0.0D, (double)(0.0F - p_78439_7_), (double)f8, (double)p_78439_4_); + p_78439_0_.addVertexWithUV((double)f7, 0.0D, 0.0D, (double)f8, (double)p_78439_4_); + p_78439_0_.addVertexWithUV((double)f7, 1.0D, 0.0D, (double)f8, (double)p_78439_2_); + p_78439_0_.addVertexWithUV((double)f7, 1.0D, (double)(0.0F - p_78439_7_), (double)f8, (double)p_78439_2_); + } + + p_78439_0_.draw(); + p_78439_0_.startDrawingQuads(); + p_78439_0_.setNormal(1.0F, 0.0F, 0.0F); + float f9; + + for (k = 0; k < width; ++k) + { + f7 = (float)k / (float)width; + f8 = p_78439_1_ + (p_78439_3_ - p_78439_1_) * f7 - f5; + f9 = f7 + 1.0F / (float)width; + p_78439_0_.addVertexWithUV((double)f9, 1.0D, (double)(0.0F - p_78439_7_), (double)f8, (double)p_78439_2_); + p_78439_0_.addVertexWithUV((double)f9, 1.0D, 0.0D, (double)f8, (double)p_78439_2_); + p_78439_0_.addVertexWithUV((double)f9, 0.0D, 0.0D, (double)f8, (double)p_78439_4_); + p_78439_0_.addVertexWithUV((double)f9, 0.0D, (double)(0.0F - p_78439_7_), (double)f8, (double)p_78439_4_); + } + + p_78439_0_.draw(); + p_78439_0_.startDrawingQuads(); + p_78439_0_.setNormal(0.0F, 1.0F, 0.0F); + + for (k = 0; k < height; ++k) + { + f7 = (float)k / (float)height; + f8 = p_78439_4_ + (p_78439_2_ - p_78439_4_) * f7 - f6; + f9 = f7 + 1.0F / (float)height; + p_78439_0_.addVertexWithUV(0.0D, (double)f9, 0.0D, (double)p_78439_1_, (double)f8); + p_78439_0_.addVertexWithUV(1.0D, (double)f9, 0.0D, (double)p_78439_3_, (double)f8); + p_78439_0_.addVertexWithUV(1.0D, (double)f9, (double)(0.0F - p_78439_7_), (double)p_78439_3_, (double)f8); + p_78439_0_.addVertexWithUV(0.0D, (double)f9, (double)(0.0F - p_78439_7_), (double)p_78439_1_, (double)f8); + } + + p_78439_0_.draw(); + p_78439_0_.startDrawingQuads(); + p_78439_0_.setNormal(0.0F, -1.0F, 0.0F); + + for (k = 0; k < height; ++k) + { + f7 = (float)k / (float)height; + f8 = p_78439_4_ + (p_78439_2_ - p_78439_4_) * f7 - f6; + p_78439_0_.addVertexWithUV(1.0D, (double)f7, 0.0D, (double)p_78439_3_, (double)f8); + p_78439_0_.addVertexWithUV(0.0D, (double)f7, 0.0D, (double)p_78439_1_, (double)f8); + p_78439_0_.addVertexWithUV(0.0D, (double)f7, (double)(0.0F - p_78439_7_), (double)p_78439_1_, (double)f8); + p_78439_0_.addVertexWithUV(1.0D, (double)f7, (double)(0.0F - p_78439_7_), (double)p_78439_3_, (double)f8); + } + + p_78439_0_.draw(); + } +} diff --git a/src/main/resources/assets/customnpcs/textures/items/npcBrushHair.png b/src/main/resources/assets/customnpcs/textures/items/npcBrushHair.png new file mode 100644 index 0000000000000000000000000000000000000000..f31bfc0f33f711e35363efa8ad835ed7e16b25fd GIT binary patch literal 222 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|>O5T>Lo9mV zUQpy~F%V$A!2d9eo9}F8RZCowc(myv_NH60+d6is`LdacuHcN=_xsUbAGRGcpK&QE z?K4p*nB{iFHu>M4uM;|UOgXYt<=;QEZP$z#N~He0YQOb(p5XuJw`-p0FWh2lfe5nzhX}-P;T0k}j5QD&_;K?A$ M)78&qol`;+0Hsq-aR2}S literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/customnpcs/textures/items/npcBrushHandle.png b/src/main/resources/assets/customnpcs/textures/items/npcBrushHandle.png new file mode 100644 index 0000000000000000000000000000000000000000..d15bd92c5e15a6916ac0ebcdd9c0cc6d58eeba55 GIT binary patch literal 227 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|nmt_{Lo9le z6C_v<%N{v;^zZ({$H(fsOx8zie6)Y%N=-j!iH)39vpWAxpZ*}_huVV!1%H2)wq0KC zpB&nLmBHWm;{U!jC!XKu_b2c8|4909uX}u9R$2lO99s7C-skr&nQn!Qo1QU?-xFFY zna8kmmZSs_XkO%DmnypR-}K3jlU?}?vuFA2&28Ge1?U{U)CkWsUtb0-Ae#e-LEuvG PWDw=)>gTe~DWM4f2JKeR literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/customnpcs/textures/items/paintbrush_brush.png b/src/main/resources/assets/customnpcs/textures/items/paintbrush_brush.png deleted file mode 100644 index 7e6bec2d87f24f59722a53dd5ba5db596fd493e1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 184 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucL0?Z7#}EtuWQl?U97_wE{yQ+F8W}J#PT^!% zkz`;#!S>LUVRo8CgXAHWXNinIOq7}Duqjvz%P+{4IKZ$;@rB;um#jGqv7a?0WEvV7 Z86<2a1Uz2-TLv_k!PC{xWt~$(69DXoG1veA diff --git a/src/main/resources/assets/customnpcs/textures/items/paintbrush_handle.png b/src/main/resources/assets/customnpcs/textures/items/paintbrush_handle.png deleted file mode 100644 index 1a60a0ad0cb7368bc02700d6b63060cab2bf2e28..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 180 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucK~GN?#}EtuWC_;8a)0KZ{2+ho2&cqC6E=ry zXJ+(8%Z70#nKm=Dsc6n}WN>9%Im@wu(@R)1;ReGEv68b#Zt<}zFrO%8Y;9;{WSDzW VGDT$fpB$i}44$rjF6*2UngAVRG;sg` From 5dfe061bad01dff0d133b0a4bee16c696d6eae0c Mon Sep 17 00:00:00 2001 From: Kam Date: Sat, 22 Feb 2025 01:21:35 -0500 Subject: [PATCH 38/59] Fix Tool Renderer --- .../java/noppes/npcs/client/ClientProxy.java | 4 +- ...mRenderer.java => ItemCustomRenderer.java} | 2 +- ...temRenderer.java => ItemToolRenderer.java} | 94 +++++------ .../renderer/items/NpcItemToolRenderer.java | 150 ------------------ 4 files changed, 47 insertions(+), 203 deletions(-) rename src/main/java/noppes/npcs/client/renderer/items/{CustomItemRenderer.java => ItemCustomRenderer.java} (99%) rename src/main/java/noppes/npcs/client/renderer/items/{ToolItemRenderer.java => ItemToolRenderer.java} (90%) delete mode 100644 src/main/java/noppes/npcs/client/renderer/items/NpcItemToolRenderer.java diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index f62284c97..eaafdf0f6 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -533,9 +533,9 @@ public class ClientProxy extends CommonProxy { @Override public void registerItem(Item item) { if (item instanceof ItemScripted || item instanceof ItemLinked) { - MinecraftForgeClient.registerItemRenderer(item, new CustomItemRenderer()); + MinecraftForgeClient.registerItemRenderer(item, new ItemCustomRenderer()); } else if (item instanceof ItemNpcTool) { - MinecraftForgeClient.registerItemRenderer(item, new ToolItemRenderer()); + MinecraftForgeClient.registerItemRenderer(item, new ItemToolRenderer()); }else { MinecraftForgeClient.registerItemRenderer(item, new NpcItemRenderer()); } diff --git a/src/main/java/noppes/npcs/client/renderer/items/CustomItemRenderer.java b/src/main/java/noppes/npcs/client/renderer/items/ItemCustomRenderer.java similarity index 99% rename from src/main/java/noppes/npcs/client/renderer/items/CustomItemRenderer.java rename to src/main/java/noppes/npcs/client/renderer/items/ItemCustomRenderer.java index 44465218b..9c16b4d4d 100644 --- a/src/main/java/noppes/npcs/client/renderer/items/CustomItemRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/items/ItemCustomRenderer.java @@ -27,7 +27,7 @@ import java.util.Random; import static net.minecraft.client.renderer.entity.RenderItem.renderInFrame; -public class CustomItemRenderer implements IItemRenderer { +public class ItemCustomRenderer implements IItemRenderer { private static final ResourceLocation RES_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png"); private static final ResourceLocation enchant = new ResourceLocation("textures/misc/enchanted_item_glint.png"); private final Random random = new Random(); diff --git a/src/main/java/noppes/npcs/client/renderer/items/ToolItemRenderer.java b/src/main/java/noppes/npcs/client/renderer/items/ItemToolRenderer.java similarity index 90% rename from src/main/java/noppes/npcs/client/renderer/items/ToolItemRenderer.java rename to src/main/java/noppes/npcs/client/renderer/items/ItemToolRenderer.java index a015f840d..6cf9aac84 100644 --- a/src/main/java/noppes/npcs/client/renderer/items/ToolItemRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/items/ItemToolRenderer.java @@ -11,16 +11,9 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; -import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.IItemRenderer; -import noppes.npcs.api.item.IItemCustomizable; -import noppes.npcs.api.item.IItemStack; -import noppes.npcs.client.ClientCacheHandler; -import noppes.npcs.client.renderer.ImageData; -import noppes.npcs.items.ItemCustomizable; import noppes.npcs.items.ItemNpcTool; -import noppes.npcs.scripted.NpcAPI; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; @@ -28,14 +21,16 @@ import java.util.Random; import static net.minecraft.client.renderer.entity.RenderItem.renderInFrame; -public class ToolItemRenderer implements IItemRenderer { +public class ItemToolRenderer implements IItemRenderer { private static final ResourceLocation RES_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png"); private static final ResourceLocation PAINTBRUSH_HANDLE = new ResourceLocation("customnpcs", "textures/items/npcBrushHandle.png"); private static final ResourceLocation PAINTBRUSH_BRUSH = new ResourceLocation("customnpcs", "textures/items/npcBrushHair.png"); + + private static final ResourceLocation HAMMER = new ResourceLocation("customnpcs", "textures/items/npcHammer.png"); + private final Random random = new Random(); - private int item3dRenderTicks = 1; @Override public boolean handleRenderType(ItemStack item, ItemRenderType type) { @@ -75,26 +70,17 @@ public class ToolItemRenderer implements IItemRenderer { entityItem.boundingBox.maxY = entityItem.boundingBox.minY + YSize * 1; entityItem.boundingBox.maxZ = entityItem.boundingBox.minZ + ZSize * 1; } - - float entityRenderTicks = Minecraft.getMinecraft().timer.renderPartialTicks; - float bobbing = MathHelper.sin(((float)entityItem.age + entityRenderTicks) / 10.0F + entityItem.hoverStart) * 0.1F + 0.1F; - - GL11.glRotatef(1 * entityRenderTicks %360, 1, 0, 0); - GL11.glRotatef(1 * entityRenderTicks %360, 0, 1, 0); - GL11.glRotatef(1 * entityRenderTicks %360, 0, 0, 1); - - if (!renderInFrame) { - GL11.glTranslatef(0.0F, -bobbing, 0.0F); + if(itemStack.getItemDamage() == 1){ + renderEntityCustomItem(itemStack, entityItem, PAINTBRUSH_HANDLE); + int color = ItemNpcTool.getColor(itemStack.getTagCompound()); + float red = ((color >> 16) & 0xFF) / 255.0F; + float green = ((color >> 8) & 0xFF) / 255.0F; + float blue = (color & 0xFF) / 255.0F; + GL11.glColor3f(red, green, blue); + renderEntityCustomItem(itemStack, entityItem, PAINTBRUSH_BRUSH); + } else { + renderEntityCustomItem(itemStack, entityItem, HAMMER); } - - renderEntityCustomItem(itemStack, entityItem, PAINTBRUSH_HANDLE); - int color = ItemNpcTool.getColor(itemStack.getTagCompound()); - float red = ((color >> 16) & 0xFF) / 255.0F; - float green = ((color >> 8) & 0xFF) / 255.0F; - float blue = (color & 0xFF) / 255.0F; - GL11.glColor3f(red, green, blue); - renderEntityCustomItem(itemStack, entityItem, PAINTBRUSH_BRUSH); - GL11.glPopMatrix(); return; } @@ -112,19 +98,25 @@ public class ToolItemRenderer implements IItemRenderer { EntityLivingBase entityLivingBase = (EntityLivingBase) data[1]; - GL11.glPushMatrix(); - renderItem3d(entityLivingBase, itemStack, PAINTBRUSH_HANDLE); - GL11.glPopMatrix(); + if(itemStack.getItemDamage() == 1){ + GL11.glPushMatrix(); + renderItem3d(entityLivingBase, itemStack, PAINTBRUSH_HANDLE); + GL11.glPopMatrix(); - int color = ItemNpcTool.getColor(itemStack.getTagCompound()); - float red = ((color >> 16) & 0xFF) / 255.0F; - float green = ((color >> 8) & 0xFF) / 255.0F; - float blue = (color & 0xFF) / 255.0F; - GL11.glColor3f(red, green, blue); + int color = ItemNpcTool.getColor(itemStack.getTagCompound()); + float red = ((color >> 16) & 0xFF) / 255.0F; + float green = ((color >> 8) & 0xFF) / 255.0F; + float blue = (color & 0xFF) / 255.0F; + GL11.glColor3f(red, green, blue); - GL11.glPushMatrix(); - renderItem3d(entityLivingBase, itemStack, PAINTBRUSH_BRUSH); - GL11.glPopMatrix(); + GL11.glPushMatrix(); + renderItem3d(entityLivingBase, itemStack, PAINTBRUSH_BRUSH); + GL11.glPopMatrix(); + } else { + GL11.glPushMatrix(); + renderItem3d(entityLivingBase, itemStack, HAMMER); + GL11.glPopMatrix(); + } GL11.glPopMatrix(); } @@ -232,7 +224,6 @@ public class ToolItemRenderer implements IItemRenderer { for (int k = 0; k < b0; ++k) { GL11.glTranslatef(0f, 0f, f9 + f10); - // TODO: May need to rebind here ItemRenderer.renderItemIn2D(tessellator, 1.0F, 0.0F, 0.0F, 1.0F, 16, 16, f9); if (itemStack.hasEffect(pass)) { @@ -327,15 +318,20 @@ public class ToolItemRenderer implements IItemRenderer { GL11.glDisable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_ALPHA_TEST); - textureManager.bindTexture(PAINTBRUSH_HANDLE); - renderCustomItemSlot(0,0,16,16, 1.0f, 1.0f, 1.0f); + if(itemStack.getItemDamage() == 1){ + textureManager.bindTexture(PAINTBRUSH_HANDLE); + renderCustomItemSlot(0,0,16,16, 1.0f, 1.0f, 1.0f); - int color = ItemNpcTool.getColor(itemStack.getTagCompound()); - float red = ((color >> 16) & 0xFF) / 255.0F; - float green = ((color >> 8) & 0xFF) / 255.0F; - float blue = (color & 0xFF) / 255.0F; - textureManager.bindTexture(PAINTBRUSH_BRUSH); - renderCustomItemSlot(0,0,16,16, red, green, blue); + int color = ItemNpcTool.getColor(itemStack.getTagCompound()); + float red = ((color >> 16) & 0xFF) / 255.0F; + float green = ((color >> 8) & 0xFF) / 255.0F; + float blue = (color & 0xFF) / 255.0F; + textureManager.bindTexture(PAINTBRUSH_BRUSH); + renderCustomItemSlot(0,0,16,16, red, green, blue); + } else { + textureManager.bindTexture(HAMMER); + renderCustomItemSlot(0,0,16,16, 1.0f, 1.0f, 1.0f); + } GL11.glEnable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_ALPHA_TEST); @@ -404,8 +400,6 @@ public class ToolItemRenderer implements IItemRenderer { } public void renderItem3d(EntityLivingBase entityLivingBase, ItemStack itemStack, ResourceLocation location) { - item3dRenderTicks++; - Minecraft mc = Minecraft.getMinecraft(); TextureManager texturemanager = mc.getTextureManager(); int par3 = 0; diff --git a/src/main/java/noppes/npcs/client/renderer/items/NpcItemToolRenderer.java b/src/main/java/noppes/npcs/client/renderer/items/NpcItemToolRenderer.java deleted file mode 100644 index 7d6c8099b..000000000 --- a/src/main/java/noppes/npcs/client/renderer/items/NpcItemToolRenderer.java +++ /dev/null @@ -1,150 +0,0 @@ -package noppes.npcs.client.renderer.items; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.ItemRenderer; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.texture.TextureManager; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.IItemRenderer; -import noppes.npcs.items.ItemNpcTool; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; - -public class NpcItemToolRenderer implements IItemRenderer { - - // Textures for the assembled paintbrush parts: - private static final ResourceLocation PAINTBRUSH_HANDLE = new ResourceLocation("customnpcs", "textures/items/npcBrushHandle.png"); - private static final ResourceLocation PAINTBRUSH_BRUSH = new ResourceLocation("customnpcs", "textures/items/npcBrushHair.png"); - private static final ResourceLocation ENCHANT = new ResourceLocation("textures/misc/enchanted_item_glint.png"); - - @Override - public boolean handleRenderType(ItemStack item, ItemRenderType type) { - return type != ItemRenderType.FIRST_PERSON_MAP; - } - - @Override - public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { - return helper == ItemRendererHelper.ENTITY_ROTATION || helper == ItemRendererHelper.ENTITY_BOBBING; - } - - @Override - public void renderItem(ItemRenderType type, ItemStack item, Object... data) { - // Ensure the item implements our render interface - if (!(item.getItem() instanceof ItemNpcTool)) - return; - - EntityLivingBase entity = (EntityLivingBase) data[1]; - - GL11.glPushMatrix(); - // For meta==1 (paintbrush) we want to assemble the texture from two parts - if (item.getItemDamage() == 1) { - renderPaintbrush(entity, item); - } else { - // For other tools, fall back on the normal special render routine. - renderItem3d(entity, item); - } - GL11.glPopMatrix(); - } - - /** - * Renders the paintbrush by drawing its handle first, then overlaying the brush part tinted - * by the NBT "BrushColor" value (an integer/hex value). - */ - private void renderPaintbrush(EntityLivingBase entity, ItemStack item) { - Minecraft mc = Minecraft.getMinecraft(); - TextureManager textureManager = mc.getTextureManager(); - Tessellator tessellator = Tessellator.instance; - int width = 16; - int height = 16; - float thickness = 0.0625F; - - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - - // Render the handle (untinted) - textureManager.bindTexture(PAINTBRUSH_HANDLE); - // Using full texture coordinates (0→1) in the same order as vanilla's renderItemIn2D: - ItemRenderer.renderItemIn2D(tessellator, 1.0F, 0.0F, 0.0F, 1.0F, width, height, thickness); - - // Get the NBT color (default is white if not present) - int color = ItemNpcTool.getColor(item.getTagCompound()); - float red = ((color >> 16) & 0xFF) / 255.0F; - float green = ((color >> 8) & 0xFF) / 255.0F; - float blue = (color & 0xFF) / 255.0F; - GL11.glColor3f(red, green, blue); - - // Render the brush (tinted by the color) - textureManager.bindTexture(PAINTBRUSH_BRUSH); - ItemRenderer.renderItemIn2D(tessellator, 1.0F, 0.0F, 0.0F, 1.0F, width, height, thickness); - - // Reset GL color to white so that subsequent rendering is not tinted - GL11.glColor3f(1.0F, 1.0F, 1.0F); - GL11.glDisable(GL12.GL_RESCALE_NORMAL); - - // If the item is enchanted, render the enchanted glint effect on top - if (item.hasEffect(0)) { - renderEnchantedEffect(tessellator, textureManager); - } - } - - /** - * Fallback 3D item renderer (for non-paintbrush items) - */ - private void renderItem3d(EntityLivingBase entity, ItemStack item) { - Minecraft mc = Minecraft.getMinecraft(); - TextureManager textureManager = mc.getTextureManager(); - Tessellator tessellator = Tessellator.instance; - textureManager.bindTexture(textureManager.getResourceLocation(item.getItemSpriteNumber())); - IIcon icon = entity.getItemIcon(item, 0); - if (icon == null) { - return; - } - float minU = icon.getMinU(); - float maxU = icon.getMaxU(); - float minV = icon.getMinV(); - float maxV = icon.getMaxV(); - int width = icon.getIconWidth(); - int height = icon.getIconHeight(); - - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - // Note: The order here mimics vanilla's 2D item rendering - ItemRenderer.renderItemIn2D(tessellator, maxU, minV, minU, maxV, width, height, 0.0625F); - GL11.glDisable(GL12.GL_RESCALE_NORMAL); - } - - /** - * Renders the enchanted glint overlay. - */ - private void renderEnchantedEffect(Tessellator tessellator, TextureManager textureManager) { - GL11.glDepthFunc(GL11.GL_EQUAL); - GL11.glDisable(GL11.GL_LIGHTING); - textureManager.bindTexture(ENCHANT); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); - float f7 = 0.76F; - GL11.glColor4f(0.5F * f7, 0.25F * f7, 0.8F * f7, 1.0F); - GL11.glMatrixMode(GL11.GL_TEXTURE); - GL11.glPushMatrix(); - float f8 = 0.125F; - GL11.glScalef(f8, f8, f8); - float f9 = (float) (Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F; - GL11.glTranslatef(f9, 0.0F, 0.0F); - GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F); - ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F); - GL11.glPopMatrix(); - GL11.glPushMatrix(); - GL11.glScalef(f8, f8, f8); - f9 = (float) (Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F; - GL11.glTranslatef(-f9, 0.0F, 0.0F); - GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F); - ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F); - GL11.glPopMatrix(); - GL11.glMatrixMode(GL11.GL_MODELVIEW); - GL11.glDisable(GL11.GL_BLEND); - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glDepthFunc(GL11.GL_LEQUAL); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - } -} From aeee864bf710df5cebb9cb2f77a11b2b6f745d57 Mon Sep 17 00:00:00 2001 From: Kam Date: Sat, 22 Feb 2025 05:09:22 -0500 Subject: [PATCH 39/59] Scripted & Linked Items now Rendering Images in Banners + Wall Banners --- .../renderer/blocks/BlockBannerRenderer.java | 41 ++++++++++++- .../blocks/BlockWallBannerRenderer.java | 57 ++++++++++++++++--- 2 files changed, 89 insertions(+), 9 deletions(-) diff --git a/src/main/java/noppes/npcs/client/renderer/blocks/BlockBannerRenderer.java b/src/main/java/noppes/npcs/client/renderer/blocks/BlockBannerRenderer.java index 56c7aec7c..b8e4beb58 100644 --- a/src/main/java/noppes/npcs/client/renderer/blocks/BlockBannerRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/blocks/BlockBannerRenderer.java @@ -6,6 +6,7 @@ import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.item.ItemStack; @@ -14,14 +15,19 @@ import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; import noppes.npcs.CustomItems; +import noppes.npcs.api.item.IItemCustomizable; +import noppes.npcs.api.item.IItemStack; import noppes.npcs.blocks.BlockBanner; import noppes.npcs.blocks.tiles.TileBanner; +import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.client.model.blocks.banner.ModelBannerFloor; import noppes.npcs.client.model.blocks.banner.ModelBannerFloorFlag; import noppes.npcs.client.model.blocks.legacy.ModelLegacyBanner; import noppes.npcs.client.model.blocks.legacy.ModelLegacyBannerFlag; +import noppes.npcs.client.renderer.ImageData; import noppes.npcs.config.ConfigClient; import noppes.npcs.constants.EnumBannerVariant; +import noppes.npcs.scripted.NpcAPI; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; @@ -129,11 +135,44 @@ public class BlockBannerRenderer extends BlockRendererInterface{ float f2 = 0.05f; Minecraft mc = Minecraft.getMinecraft(); GL11.glScalef(f2, f2, f2); - renderItemBanner(mc.renderEngine, iicon, -8, -8, false); + IItemStack iItemStack = NpcAPI.Instance().getIItemStack(iicon); + if (iItemStack instanceof IItemCustomizable) { + IItemCustomizable custom = (IItemCustomizable) iItemStack; + ImageData imageData = ClientCacheHandler.getImageData(custom.getTexture()); + if (imageData.imageLoaded()) { + imageData.bindTexture(); + int color = custom.getColor(); + float[] colors = ColorUtil.hexToRGB(color); + renderCustomItemInBanner(colors[0], colors[1], colors[2]); + GL11.glColor3f(1.0f, 1.0f, 1.0f); + } else { + renderItemBanner(mc.renderEngine, iicon, -8, -8, false); + } + } else { + renderItemBanner(mc.renderEngine, iicon, -8, -8, false); + } GL11.glDepthMask(true); GL11.glPopMatrix(); } + private void renderCustomItemInBanner(float red, float green, float blue) { + // Ensure lighting isn't interfering + GL11.glDisable(GL11.GL_LIGHTING); + // Force the texture to use the current color + GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE); + + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.setColorRGBA_F(red, green, blue, 1.0F); + tessellator.addVertexWithUV(-8, 8, 0, 0, 1); + tessellator.addVertexWithUV(8, 8, 0, 1, 1); + tessellator.addVertexWithUV(8, -8, 0, 1, 0); + tessellator.addVertexWithUV(-8, -8, 0, 0, 0); + tessellator.draw(); + + GL11.glEnable(GL11.GL_LIGHTING); + } + public void renderItemBanner(TextureManager txtMng, ItemStack item, int p_77015_4_, int p_77015_5_, boolean renderEffect) { Object object = item.getIconIndex(); diff --git a/src/main/java/noppes/npcs/client/renderer/blocks/BlockWallBannerRenderer.java b/src/main/java/noppes/npcs/client/renderer/blocks/BlockWallBannerRenderer.java index ec0db4379..945775a0f 100644 --- a/src/main/java/noppes/npcs/client/renderer/blocks/BlockWallBannerRenderer.java +++ b/src/main/java/noppes/npcs/client/renderer/blocks/BlockWallBannerRenderer.java @@ -6,6 +6,7 @@ import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.init.Blocks; @@ -17,13 +18,19 @@ import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; import noppes.npcs.CustomItems; +import noppes.npcs.api.item.IItemCustomizable; +import noppes.npcs.api.item.IItemStack; import noppes.npcs.blocks.BlockWallBanner; import noppes.npcs.blocks.tiles.TileWallBanner; +import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.client.model.blocks.banner.ModelBannerWall; import noppes.npcs.client.model.blocks.banner.ModelBannerWallFlag; import noppes.npcs.client.model.blocks.legacy.ModelLegacyWallBanner; import noppes.npcs.client.model.blocks.legacy.ModelLegacyWallBannerFlag; +import noppes.npcs.client.renderer.ImageData; import noppes.npcs.config.ConfigClient; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.item.ScriptItemStack; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; @@ -95,34 +102,68 @@ public class BlockWallBannerRenderer extends BlockRendererInterface{ } GL11.glPopAttrib(); } - public void doRender(double par2, double par4, double par6, int meta, ItemStack iicon, float rotate) - { + + public void doRender(double par2, double par4, double par6, int meta, ItemStack iicon, float rotate) { GL11.glPushMatrix(); bindTexture(TextureMap.locationItemsTexture); GL11.glTranslatef((float)par2 + 0.5f, (float)par4 + 0.2f, (float)par6 + 0.5f); GL11.glRotatef(180, 0, 0, 1); GL11.glRotatef(90 * meta, 0, 1, 0); - - if(ConfigClient.LegacyBanner){ + if (ConfigClient.LegacyBanner) { GL11.glTranslatef(0, 0, 0.26f); - } - else { + } else { GL11.glTranslatef(0, 0, 0.3f); GL11.glTranslatef(0, -0.6f, 0); // Translate to pivot point GL11.glRotatef((float) Math.toDegrees(rotate), 1, 0, 0); // Apply sway rotation GL11.glTranslatef(0, 0.6f, 0); // Translate to pivot point } - GL11.glDepthMask(false); float f2 = 0.05f; Minecraft mc = Minecraft.getMinecraft(); GL11.glScalef(f2, f2, f2); - renderItemBanner(mc.renderEngine, iicon, -8, -8, false); + + // Check if the item is customizable. + IItemStack iItemStack = NpcAPI.Instance().getIItemStack(iicon); + if (iItemStack instanceof IItemCustomizable) { + IItemCustomizable custom = (IItemCustomizable) iItemStack; + ImageData imageData = ClientCacheHandler.getImageData(custom.getTexture()); + if (imageData.imageLoaded()) { + imageData.bindTexture(); + int color = custom.getColor(); + float[] colors = ColorUtil.hexToRGB(color); + renderCustomItemInBanner(colors[0], colors[1], colors[2]); + GL11.glColor3f(1.0f, 1.0f, 1.0f); + } else { + renderItemBanner(mc.renderEngine, iicon, -8, -8, false); + } + } else { + renderItemBanner(mc.renderEngine, iicon, -8, -8, false); + } + GL11.glDepthMask(true); GL11.glPopMatrix(); } + private void renderCustomItemInBanner(float red, float green, float blue) { + // Ensure lighting isn't interfering + GL11.glDisable(GL11.GL_LIGHTING); + // Force the texture to use the current color + GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE); + + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.setColorRGBA_F(red, green, blue, 1.0F); + tessellator.addVertexWithUV(-8, 8, 0, 0, 1); + tessellator.addVertexWithUV(8, 8, 0, 1, 1); + tessellator.addVertexWithUV(8, -8, 0, 1, 0); + tessellator.addVertexWithUV(-8, -8, 0, 0, 0); + tessellator.draw(); + + GL11.glEnable(GL11.GL_LIGHTING); + } + + public void renderItemBanner(TextureManager txtMng, ItemStack item, int p_77015_4_, int p_77015_5_, boolean renderEffect) { Object object = item.getIconIndex(); From 294abe4d259803b00a8eb41cdd8e6fcd5156be31 Mon Sep 17 00:00:00 2001 From: Kam Date: Sat, 22 Feb 2025 22:29:27 -0500 Subject: [PATCH 40/59] Apply Configs to Packets --- .../packets/request/profile/ProfileChangePacket.java | 8 ++++++-- .../packets/request/profile/ProfileCreatePacket.java | 6 ++++++ .../packets/request/profile/ProfileGetInfoPacket.java | 4 ++++ .../packets/request/profile/ProfileGetPacket.java | 4 ++++ .../packets/request/profile/ProfileRemovePacket.java | 9 ++++++--- .../packets/request/profile/ProfileRenamePacket.java | 7 ++++++- 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileChangePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileChangePacket.java index c6f88fb77..19c62ffff 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileChangePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileChangePacket.java @@ -9,9 +9,11 @@ import kamkeel.npcs.network.AbstractPacket; import kamkeel.npcs.network.PacketChannel; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumRequestPacket; +import kamkeel.npcs.network.packets.data.ChatAlertPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import noppes.npcs.CustomNpcsPermissions; +import noppes.npcs.config.ConfigMain; import java.io.IOException; @@ -52,11 +54,13 @@ public final class ProfileChangePacket extends AbstractPacket { if (!(player instanceof EntityPlayerMP)) return; + if(!ConfigMain.ProfilesEnabled) + return; + int slot = in.readInt(); ProfileOperation operation = ProfileController.Instance.changeSlot(player, slot); - // TODO: Check Operation and Send Message - ProfileGetPacket.sendProfileNBT(player); ProfileGetInfoPacket.sendProfileInfo(player); + ChatAlertPacket.sendChatAlert((EntityPlayerMP) player, operation.getMessage()); } } diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java index 56023b5af..b8d50e6d4 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java @@ -10,9 +10,11 @@ import kamkeel.npcs.network.AbstractPacket; import kamkeel.npcs.network.PacketChannel; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumRequestPacket; +import kamkeel.npcs.network.packets.data.ChatAlertPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import noppes.npcs.CustomNpcsPermissions; +import noppes.npcs.config.ConfigMain; import java.io.IOException; @@ -45,9 +47,13 @@ public final class ProfileCreatePacket extends AbstractPacket { if (!(player instanceof EntityPlayerMP)) return; + if(!ConfigMain.ProfilesEnabled) + return; + Profile profile = ProfileController.Instance.getProfile(player); ProfileOperation operation = ProfileController.Instance.createSlotInternal(profile); ProfileGetPacket.sendProfileNBT(player); ProfileGetInfoPacket.sendProfileInfo(player); + ChatAlertPacket.sendChatAlert((EntityPlayerMP) player, operation.getMessage()); } } diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java index e83109ac3..50f9d8fe1 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java @@ -17,6 +17,7 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraftforge.common.util.Constants; +import noppes.npcs.config.ConfigMain; import java.io.IOException; import java.util.ArrayList; @@ -47,6 +48,9 @@ public final class ProfileGetInfoPacket extends AbstractPacket { if (!(player instanceof EntityPlayerMP)) return; + if(!ConfigMain.ProfilesEnabled) + return; + sendProfileInfo(player); } diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java index a37572db5..ffbdb4997 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java @@ -13,6 +13,7 @@ import kamkeel.npcs.network.packets.data.large.GuiDataPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.config.ConfigMain; import java.io.IOException; @@ -40,6 +41,9 @@ public final class ProfileGetPacket extends AbstractPacket { if (!(player instanceof EntityPlayerMP)) return; + if(!ConfigMain.ProfilesEnabled) + return; + sendProfileNBT(player); } diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java index 6f8ff983c..c762b435b 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java @@ -9,9 +9,11 @@ import kamkeel.npcs.network.AbstractPacket; import kamkeel.npcs.network.PacketChannel; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumRequestPacket; +import kamkeel.npcs.network.packets.data.ChatAlertPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import noppes.npcs.CustomNpcsPermissions; +import noppes.npcs.config.ConfigMain; import java.io.IOException; @@ -52,12 +54,13 @@ public final class ProfileRemovePacket extends AbstractPacket { if (!(player instanceof EntityPlayerMP)) return; + if(!ConfigMain.ProfilesEnabled) + return; + int slot = in.readInt(); ProfileOperation operation = ProfileController.Instance.removeSlot(player, slot); - // TODO: Check Operation and Send Message - - ProfileGetPacket.sendProfileNBT(player); ProfileGetInfoPacket.sendProfileInfo(player); + ChatAlertPacket.sendChatAlert((EntityPlayerMP) player, operation.getMessage()); } } diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java index 7322517d4..d692e1ed9 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java @@ -9,10 +9,12 @@ import kamkeel.npcs.network.AbstractPacket; import kamkeel.npcs.network.PacketChannel; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumRequestPacket; +import kamkeel.npcs.network.packets.data.ChatAlertPacket; import kamkeel.npcs.util.ByteBufUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import noppes.npcs.CustomNpcsPermissions; +import noppes.npcs.config.ConfigMain; import java.io.IOException; @@ -56,12 +58,15 @@ public final class ProfileRenamePacket extends AbstractPacket { if (!(player instanceof EntityPlayerMP)) return; + if(!ConfigMain.ProfilesEnabled) + return; + int slot = in.readInt(); String newName = ByteBufUtils.readString(in); Profile profile = ProfileController.Instance.getProfile(player); if(!profile.getSlots().containsKey(slot)) { - // TODO: Check Operation and Send Message + ChatAlertPacket.sendChatAlert((EntityPlayerMP) player, "No slot found"); return; } From c023071ff0a7fd052d245821e9a7a79a03acde33 Mon Sep 17 00:00:00 2001 From: Kam Date: Sat, 22 Feb 2025 23:58:56 -0500 Subject: [PATCH 41/59] Quest Tracking Changes --- .../data/OverlayQuestTrackingPacket.java | 2 +- .../npcs/client/ClientCacheHandler.java | 2 +- .../npcs/client/ClientEventHandler.java | 2 +- .../java/noppes/npcs/client/ClientProxy.java | 2 +- .../npcs/client/gui/OverlayQuestTracking.java | 703 ------------------ .../client/gui/hud/GuiOverlayQuestEditor.java | 199 +++++ .../client/gui/hud/OverlayQuestTracking.java | 191 +++++ .../gui/player/inventory/GuiSettings.java | 7 + .../java/noppes/npcs/config/ConfigClient.java | 28 + 9 files changed, 429 insertions(+), 707 deletions(-) delete mode 100644 src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java create mode 100644 src/main/java/noppes/npcs/client/gui/hud/GuiOverlayQuestEditor.java create mode 100644 src/main/java/noppes/npcs/client/gui/hud/OverlayQuestTracking.java diff --git a/src/main/java/kamkeel/npcs/network/packets/data/OverlayQuestTrackingPacket.java b/src/main/java/kamkeel/npcs/network/packets/data/OverlayQuestTrackingPacket.java index f31baf305..af999382a 100644 --- a/src/main/java/kamkeel/npcs/network/packets/data/OverlayQuestTrackingPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/data/OverlayQuestTrackingPacket.java @@ -12,7 +12,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.ClientCacheHandler; -import noppes.npcs.client.gui.OverlayQuestTracking; +import noppes.npcs.client.gui.hud.OverlayQuestTracking; import java.io.IOException; diff --git a/src/main/java/noppes/npcs/client/ClientCacheHandler.java b/src/main/java/noppes/npcs/client/ClientCacheHandler.java index e4771c4e3..16a81a286 100644 --- a/src/main/java/noppes/npcs/client/ClientCacheHandler.java +++ b/src/main/java/noppes/npcs/client/ClientCacheHandler.java @@ -1,7 +1,7 @@ package noppes.npcs.client; import net.minecraft.util.ResourceLocation; -import noppes.npcs.client.gui.OverlayQuestTracking; +import noppes.npcs.client.gui.hud.OverlayQuestTracking; import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.gui.select.GuiSoundSelection; import noppes.npcs.client.gui.select.GuiTextureSelection; diff --git a/src/main/java/noppes/npcs/client/ClientEventHandler.java b/src/main/java/noppes/npcs/client/ClientEventHandler.java index e142c5286..eb9e4825a 100644 --- a/src/main/java/noppes/npcs/client/ClientEventHandler.java +++ b/src/main/java/noppes/npcs/client/ClientEventHandler.java @@ -91,7 +91,7 @@ public class ClientEventHandler { } if (ClientCacheHandler.questTrackingOverlay != null) { - ClientCacheHandler.questTrackingOverlay.renderGameOverlay(event.partialTicks); + ClientCacheHandler.questTrackingOverlay.renderOverlay(event.partialTicks); } } } diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index eaafdf0f6..c7dfa9a66 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -597,7 +597,7 @@ public class ClientProxy extends CommonProxy { } public static class FontContainer { - private StringCache textFont = null; + public StringCache textFont = null; public boolean useCustomFont = true; private FontContainer(){ diff --git a/src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java b/src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java deleted file mode 100644 index 33818aeff..000000000 --- a/src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java +++ /dev/null @@ -1,703 +0,0 @@ -package noppes.npcs.client.gui; - -import com.ibm.icu.text.ArabicShaping; -import com.ibm.icu.text.ArabicShapingException; -import com.ibm.icu.text.Bidi; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.util.ResourceLocation; -import noppes.npcs.config.ConfigClient; -import noppes.npcs.controllers.data.Quest; -import org.lwjgl.opengl.GL11; - -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; - -public class OverlayQuestTracking extends Gui { - public Minecraft mc; - - private ScaledResolution res = null; - public static int scaledWidth = 0; - public static int scaledHeight = 0; - - int color = 0xFFFFFF; - float alpha = 1.0F; - - private boolean randomStyle = false; - private boolean boldStyle = false; - private boolean italicStyle = false; - private boolean underlineStyle = false; - private boolean strikethroughStyle = false; - private boolean bidiFlag = false; - private boolean unicodeFlag = false; - - private static final ResourceLocation[] unicodePageLocations = new ResourceLocation[256]; - private final FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer; - protected final ResourceLocation locationFontTexture = new ResourceLocation("textures/font/ascii.png");; - protected int[] charWidth = new int[256]; - protected byte[] glyphWidth = new byte[65536]; - private final int[] colorCode = new int[32]; - - private float red; - private float green; - private float blue; - - private float posX; - private float posY; - - private float renderOffsetY; - private final int overlayWidth = 120; - - public ArrayList trackedQuestLines = new ArrayList<>(); - public ArrayList categoryNameLines = new ArrayList<>(); - public ArrayList objectiveLines = new ArrayList<>(); - public ArrayList turnInText = new ArrayList<>(); - - public OverlayQuestTracking(Minecraft mc) { - this.mc = mc; - readFontTexture(); - readGlyphSizes(); - for (int i = 0; i < 32; ++i) - { - int j = (i >> 3 & 1) * 85; - int k = (i >> 2 & 1) * 170 + j; - int l = (i >> 1 & 1) * 170 + j; - int i1 = (i >> 0 & 1) * 170 + j; - - if (i == 6) - { - k += 85; - } - - if (Minecraft.getMinecraft().gameSettings.anaglyph) - { - int j1 = (k * 30 + l * 59 + i1 * 11) / 100; - int k1 = (k * 30 + l * 70) / 100; - int l1 = (k * 30 + i1 * 70) / 100; - k = j1; - l = k1; - i1 = l1; - } - - if (i >= 16) - { - k /= 4; - l /= 4; - i1 /= 4; - } - - this.colorCode[i] = (k & 255) << 16 | (l & 255) << 8 | i1 & 255; - } - } - - public void initOverlay() { - res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); - scaledWidth = res.getScaledWidth(); - scaledHeight = res.getScaledHeight(); - } - - public void setOverlayData(NBTTagCompound compound) { - Quest trackedQuest = new Quest(); - trackedQuest.readNBT(compound.getCompoundTag("Quest")); - - trackedQuestLines = getLineList(trackedQuest.getName()); - categoryNameLines = getLineList(compound.getString("CategoryName")); - - NBTTagList nbtTagList = compound.getTagList("ObjectiveList",8); - for (int i = 0; i < nbtTagList.tagCount(); i++) { - String objective = nbtTagList.getStringTagAt(i); - - String[] split = objective.split(":"); - split = split[split.length-1].split("/"); - - boolean completed = false; - - try { - if(split.length < 2) - throw new NumberFormatException("catch"); - - int killed = Integer.parseInt(split[0].trim()); - int total = Integer.parseInt(split[1].trim()); - - if (killed/total == 1) { - completed = true; - } - } catch (NumberFormatException e) { - if (objective.endsWith("(Done)") || objective.endsWith("(read)") || (objective.endsWith("Found") && !objective.endsWith("Not Found"))) { - completed = true; - } - } - - if (completed) { - objective = "&a&o&m" + objective; - } else { - objective = "&o" + objective; - } - - objectiveLines.add(objective); - } - - boolean instantComplete = compound.getBoolean("Instant"); - if(instantComplete){ - turnInText.add("Completed automatically"); - } - else { - String npcName = compound.getString("TurnInNPC"); - if (!npcName.isEmpty()) { - turnInText.add("Complete with " + npcName); - } - } - - this.initOverlay(); - } - - public ArrayList getLineList(String string) { - String[] split = string.split(" "); - - ArrayList lines = new ArrayList<>(); - lines.add(split[0]); - - for (int i = 1; i < split.length; i++) { - String s = split[i]; - if (this.fontRenderer.getStringWidth(lines.get(lines.size() - 1) + " " + s) > 100) { - lines.add(s); - } else { - lines.set(lines.size() - 1, lines.get(lines.size() - 1) + " " + s); - } - } - - return lines; - } - - public void renderGameOverlay(float partialTicks){ - res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); - - float overallScale = (float) ConfigClient.TrackingScale / 100; - - scaledWidth = (int) (res.getScaledWidth()); - scaledHeight = (int) (res.getScaledHeight()); - - GL11.glEnable(GL11.GL_BLEND); - OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); - GL11.glDisable(GL11.GL_ALPHA_TEST); - - GL11.glPushMatrix(); - GL11.glTranslatef(ConfigClient.TrackingInfoAlignment%3*((float)(scaledWidth)/2), (float) (Math.floor((float)(ConfigClient.TrackingInfoAlignment/3))*((float)(scaledHeight)/2)),0.0F); - - float offsetX = ConfigClient.TrackingInfoAlignment%3 == 0 ? 5 : -5; - - float offsetY = ConfigClient.TrackingInfoAlignment < 3 ? 5 : 0; - offsetY = ConfigClient.TrackingInfoAlignment > 5 ? -5 : offsetY; - - GL11.glTranslatef(ConfigClient.TrackingInfoX + offsetX, ConfigClient.TrackingInfoY + offsetY, 0.0F); - - red = (color >> 16 & 255) / 255f; - green = (color >> 8 & 255) / 255f; - blue = (color & 255) / 255f; - - float centerX = (float) -overlayWidth /2 * overallScale; - if (ConfigClient.TrackingInfoAlignment % 3 == 1) { // For Center alignment - centerX = 0; - } else { - centerX *= ConfigClient.TrackingInfoAlignment % 3 == 0 ? -1 : 1; - } - - float questTitleTop; - this.renderOffsetY = -40 * overallScale; - GL11.glPushMatrix(); - GL11.glTranslatef(centerX, 0.0F, 0.0F); - this.renderStringLines(trackedQuestLines,1.2F * overallScale, false, true, 0); - GL11.glPopMatrix(); - questTitleTop = this.renderOffsetY; - this.renderOffsetY -= 10 * overallScale; - GL11.glPushMatrix(); - GL11.glTranslatef(centerX, 0.0F, 0.0F); - this.renderStringLines(categoryNameLines,0.85F * overallScale, false, false, 0); - GL11.glPopMatrix(); - - this.renderOffsetY = -10 * overallScale; - GL11.glPushMatrix(); - this.renderStringLines(objectiveLines, 1F * overallScale, true, false, ConfigClient.TrackingInfoAlignment % 3 == 0 ? 1 : (ConfigClient.TrackingInfoAlignment % 3 == 2 ? 2 : 0)); - GL11.glPopMatrix(); - - this.renderOffsetY += 10 * overallScale; - GL11.glPushMatrix(); - this.renderStringLines(turnInText, 1F * overallScale, true, false, ConfigClient.TrackingInfoAlignment % 3 == 0 ? 1 : (ConfigClient.TrackingInfoAlignment % 3 == 2 ? 2 : 0)); - GL11.glPopMatrix(); - - this.renderOffsetY = -20 * overallScale; - GL11.glPushMatrix(); - if(overallScale < 0.6){ - this.drawHorizontalLine((int) (centerX - (overlayWidth / 2 * overallScale)), (int) (centerX + (overlayWidth / 2 * overallScale)), (int) ((this.renderOffsetY)), 0xFFFFFFFF); - } else if (overallScale < 0.8){ - this.drawHorizontalLine((int) (centerX - (overlayWidth / 2 * overallScale)), (int) (centerX + (overlayWidth / 2 * overallScale)), (int) ((this.renderOffsetY)), 0xFFA8A8A8); - this.drawHorizontalLine((int) (centerX - (overlayWidth / 2 * overallScale)), (int) (centerX + (overlayWidth / 2 * overallScale)), (int) ((this.renderOffsetY + 1)), 0xFFFFFFFF); - } else { - this.drawHorizontalLine((int) (centerX - (overlayWidth / 2 * overallScale)), (int) (centerX + (overlayWidth / 2 * overallScale)), (int) (this.renderOffsetY), 0xFF777777); - this.drawHorizontalLine((int) (centerX - (overlayWidth / 2 * overallScale)), (int) (centerX + (overlayWidth / 2 * overallScale)), (int) ((this.renderOffsetY + 1)), 0xFFA8A8A8); - this.drawHorizontalLine((int) (centerX - (overlayWidth / 2 * overallScale)), (int) (centerX + (overlayWidth / 2 * overallScale)), (int) ((this.renderOffsetY + 2)), 0xFFFFFFFF); - } - GL11.glPopMatrix(); - this.renderOffsetY = questTitleTop + 2; - GL11.glPushMatrix(); - - if(overallScale < 0.6){ - this.drawHorizontalLine((int) (centerX - (overlayWidth / 2 * overallScale)), (int) (centerX + (overlayWidth / 2 * overallScale)), (int) (this.renderOffsetY - 2), 0xFFFFFFFF); - } else if (overallScale < 0.8){ - this.drawHorizontalLine((int) (centerX - (overlayWidth / 2 * overallScale)), (int) (centerX + (overlayWidth / 2 * overallScale)), (int) ((this.renderOffsetY)), 0xFFA8A8A8); - this.drawHorizontalLine((int) (centerX - (overlayWidth / 2 * overallScale)), (int) (centerX + (overlayWidth / 2 * overallScale)), (int) (this.renderOffsetY - 1), 0xFFFFFFFF); - } else { - this.drawHorizontalLine((int) (centerX - (overlayWidth / 2 * overallScale)), (int) (centerX + (overlayWidth / 2 * overallScale)), (int) ((this.renderOffsetY)), 0xFF777777); - this.drawHorizontalLine((int) (centerX - (overlayWidth / 2 * overallScale)), (int) (centerX + (overlayWidth / 2 * overallScale)), (int) ((this.renderOffsetY -1)), 0xFFA8A8A8); - this.drawHorizontalLine((int) (centerX - (overlayWidth / 2 * overallScale)), (int) (centerX + (overlayWidth / 2 * overallScale)), (int) (this.renderOffsetY - 2), 0xFFFFFFFF); - } - GL11.glPopMatrix(); - GL11.glPopMatrix(); - - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_ALPHA_TEST); - } - - public void renderStringLines(ArrayList lines, float scale, boolean downwards, boolean bold, int facing) { - for (int i = 0; i < lines.size(); i++) { - String s = lines.get(i); - if (!downwards) { - s = lines.get(lines.size()-1 - i); - } - - int stringWidth = this.fontRenderer.getStringWidth(s.replace("&o","")); - if (s.startsWith("&a&o&m")) { - stringWidth = this.fontRenderer.getStringWidth(s.replace("&a&o&m","")); - } - - float overallScale = (float) ConfigClient.TrackingScale / 100; - - GL11.glPushMatrix(); - switch (facing) { - case 0://center - GL11.glTranslatef(scale * (-stringWidth / 2.0F), this.renderOffsetY, 0.0F); - break; - case 1://left - GL11.glTranslatef(0, this.renderOffsetY, 0.0F); - break; - case 2://right - GL11.glTranslatef(scale * (-stringWidth), this.renderOffsetY, 0.0F); - break; - } - - GL11.glScalef(scale, scale, scale); - this.drawString(s, 0, 0, this.color, true); - if (bold) { - GL11.glTranslatef(0.2F, 0.2F, 0.0F); - this.drawString(s, 0, 0, this.color, false); - } - this.renderOffsetY += (downwards ? 10 : -10) * overallScale; - GL11.glPopMatrix(); - } - } - - public int drawString(String p_85187_1_, int p_85187_2_, int p_85187_3_, int p_85187_4_, boolean p_85187_5_) - { - this.resetStyles(); - int l; - - if (p_85187_5_) - { - l = this.renderString(p_85187_1_, p_85187_2_ + 1, p_85187_3_ + 1, p_85187_4_, true); - l = Math.max(l, this.renderString(p_85187_1_, p_85187_2_, p_85187_3_, p_85187_4_, false)); - } - else - { - l = this.renderString(p_85187_1_, p_85187_2_, p_85187_3_, p_85187_4_, false); - } - - return l; - } - - private void resetStyles() - { - this.randomStyle = false; - this.boldStyle = false; - this.italicStyle = false; - this.underlineStyle = false; - this.strikethroughStyle = false; - } - - private int renderString(String p_78258_1_, int p_78258_2_, int p_78258_3_, int p_78258_4_, boolean p_78258_5_) - { - if (p_78258_1_ == null) - { - return 0; - } - else - { - if (this.bidiFlag) - { - p_78258_1_ = this.bidiReorder(p_78258_1_); - } - - setColor(this.red, this.green, this.blue, this.alpha); - if (p_78258_5_) { - setColor(0,0,0,1.0F); - } - this.posX = (float)p_78258_2_; - this.posY = (float)p_78258_3_; - this.renderStringAtPos(p_78258_1_, p_78258_5_); - return (int)this.posX; - } - } - - private void renderStringAtPos(String p_78255_1_, boolean p_78255_2_) - { - for (int i = 0; i < p_78255_1_.length(); ++i) - { - char c0 = p_78255_1_.charAt(i); - int j; - int k; - - if (c0 == 38 && i + 1 < p_78255_1_.length()) - { - j = "0123456789abcdefklmnor".indexOf(p_78255_1_.toLowerCase().charAt(i + 1)); - - if(j < 16){ - this.randomStyle = false; - this.boldStyle = false; - this.strikethroughStyle = false; - this.underlineStyle = false; - this.italicStyle = false; - - if (j < 0 || j > 15) - { - j = 15; - } - - if (p_78255_2_) - { - j += 16; - } - - k = this.colorCode[j]; - setColor((float)(k >> 16) / 255.0F, (float)(k >> 8 & 255) / 255.0F, (float)(k & 255) / 255.0F, this.alpha); - } - else if (j == 16) - { - this.randomStyle = true; - } - else if (j == 17) - { - this.boldStyle = true; - } - else if (j == 18) - { - this.strikethroughStyle = true; - } - else if (j == 19) - { - this.underlineStyle = true; - } - else if (j == 20) - { - this.italicStyle = true; - } - else if (j == 21) - { - this.randomStyle = false; - this.boldStyle = false; - this.strikethroughStyle = false; - this.underlineStyle = false; - this.italicStyle = false; - } - - ++i; - } - else - { - j = "\u00c0\u00c1\u00c2\u00c8\u00ca\u00cb\u00cd\u00d3\u00d4\u00d5\u00da\u00df\u00e3\u00f5\u011f\u0130\u0131\u0152\u0153\u015e\u015f\u0174\u0175\u017e\u0207\u0000\u0000\u0000\u0000\u0000\u0000\u0000 !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u0000\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f8\u00a3\u00d8\u00d7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u00ae\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\u03b2\u0393\u03c0\u03a3\u03c3\u03bc\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u2205\u2208\u2229\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u00b7\u221a\u207f\u00b2\u25a0\u0000".indexOf(c0); - - if (this.randomStyle && j != -1) - { - do - { - k = Minecraft.getMinecraft().fontRenderer.fontRandom.nextInt(this.charWidth.length); - } - while (this.charWidth[j] != this.charWidth[k]); - - j = k; - } - - float f1 = this.unicodeFlag ? 0.5F : 1.0F; - boolean flag1 = (c0 == 0 || j == -1 || this.unicodeFlag) && p_78255_2_; - - if (flag1) - { - this.posX -= f1; - this.posY -= f1; - } - - float f = this.renderCharAtPos(j, c0, this.italicStyle); - - if (flag1) - { - this.posX += f1; - this.posY += f1; - } - - if (this.boldStyle) - { - this.posX += f1; - - if (flag1) - { - this.posX -= f1; - this.posY -= f1; - } - - this.renderCharAtPos(j, c0, this.italicStyle); - this.posX -= f1; - - if (flag1) - { - this.posX += f1; - this.posY += f1; - } - - ++f; - } - - doDraw(f); - } - } - } - - protected void doDraw(float f) - { - { - { - Tessellator tessellator; - - if (this.strikethroughStyle) - { - tessellator = Tessellator.instance; - GL11.glDisable(GL11.GL_TEXTURE_2D); - tessellator.startDrawingQuads(); - tessellator.addVertex((double)this.posX, (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2)), 0.0D); - tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2)), 0.0D); - tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2) - 1.0F), 0.0D); - tessellator.addVertex((double)this.posX, (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2) - 1.0F), 0.0D); - tessellator.draw(); - GL11.glEnable(GL11.GL_TEXTURE_2D); - } - - if (this.underlineStyle) - { - tessellator = Tessellator.instance; - GL11.glDisable(GL11.GL_TEXTURE_2D); - tessellator.startDrawingQuads(); - int l = this.underlineStyle ? -1 : 0; - tessellator.addVertex((double)(this.posX + (float)l), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT), 0.0D); - tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT), 0.0D); - tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT - 1.0F), 0.0D); - tessellator.addVertex((double)(this.posX + (float)l), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT - 1.0F), 0.0D); - tessellator.draw(); - GL11.glEnable(GL11.GL_TEXTURE_2D); - } - - this.posX += (float)((int)f); - } - } - } - - private float renderCharAtPos(int p_78278_1_, char p_78278_2_, boolean p_78278_3_) - { - return p_78278_2_ == 32 ? 4.0F : ("\u00c0\u00c1\u00c2\u00c8\u00ca\u00cb\u00cd\u00d3\u00d4\u00d5\u00da\u00df\u00e3\u00f5\u011f\u0130\u0131\u0152\u0153\u015e\u015f\u0174\u0175\u017e\u0207\u0000\u0000\u0000\u0000\u0000\u0000\u0000 !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u0000\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f8\u00a3\u00d8\u00d7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u00ae\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\u03b2\u0393\u03c0\u03a3\u03c3\u03bc\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u2205\u2208\u2229\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u00b7\u221a\u207f\u00b2\u25a0\u0000".indexOf(p_78278_2_) != -1 && !this.unicodeFlag ? this.renderDefaultChar(p_78278_1_, p_78278_3_) : this.renderUnicodeChar(p_78278_2_, p_78278_3_)); - } - - protected float renderDefaultChar(int p_78266_1_, boolean p_78266_2_) - { - float f = (float)(p_78266_1_ % 16 * 8); - float f1 = (float)(p_78266_1_ / 16 * 8); - float f2 = p_78266_2_ ? 1.0F : 0.0F; - bindTexture(this.locationFontTexture); - float f3 = (float)this.charWidth[p_78266_1_] - 0.01F; - GL11.glBegin(GL11.GL_TRIANGLE_STRIP); - GL11.glTexCoord2f(f / 128.0F, f1 / 128.0F); - GL11.glVertex3f(this.posX + f2, this.posY, 0.0F); - GL11.glTexCoord2f(f / 128.0F, (f1 + 7.99F) / 128.0F); - GL11.glVertex3f(this.posX - f2, this.posY + 7.99F, 0.0F); - GL11.glTexCoord2f((f + f3 - 1.0F) / 128.0F, f1 / 128.0F); - GL11.glVertex3f(this.posX + f3 - 1.0F + f2, this.posY, 0.0F); - GL11.glTexCoord2f((f + f3 - 1.0F) / 128.0F, (f1 + 7.99F) / 128.0F); - GL11.glVertex3f(this.posX + f3 - 1.0F - f2, this.posY + 7.99F, 0.0F); - GL11.glEnd(); - return (float)this.charWidth[p_78266_1_]; - } - - private ResourceLocation getUnicodePageLocation(int p_111271_1_) - { - if (unicodePageLocations[p_111271_1_] == null) - { - unicodePageLocations[p_111271_1_] = new ResourceLocation(String.format("textures/font/unicode_page_%02x.png", new Object[] {Integer.valueOf(p_111271_1_)})); - } - - return unicodePageLocations[p_111271_1_]; - } - - private void loadGlyphTexture(int p_78257_1_) - { - bindTexture(this.getUnicodePageLocation(p_78257_1_)); - } - - /** - * Render a single Unicode character at current (posX,posY) location using one of the /font/glyph_XX.png files... - */ - protected float renderUnicodeChar(char p_78277_1_, boolean p_78277_2_) - { - if (this.glyphWidth[p_78277_1_] == 0) - { - return 0.0F; - } - else - { - int i = p_78277_1_ / 256; - this.loadGlyphTexture(i); - int j = this.glyphWidth[p_78277_1_] >>> 4; - int k = this.glyphWidth[p_78277_1_] & 15; - float f = (float)j; - float f1 = (float)(k + 1); - float f2 = (float)(p_78277_1_ % 16 * 16) + f; - float f3 = (float)((p_78277_1_ & 255) / 16 * 16); - float f4 = f1 - f - 0.02F; - float f5 = p_78277_2_ ? 1.0F : 0.0F; - GL11.glBegin(GL11.GL_TRIANGLE_STRIP); - GL11.glTexCoord2f(f2 / 256.0F, f3 / 256.0F); - GL11.glVertex3f(this.posX + f5, this.posY, 0.0F); - GL11.glTexCoord2f(f2 / 256.0F, (f3 + 15.98F) / 256.0F); - GL11.glVertex3f(this.posX - f5, this.posY + 7.99F, 0.0F); - GL11.glTexCoord2f((f2 + f4) / 256.0F, f3 / 256.0F); - GL11.glVertex3f(this.posX + f4 / 2.0F + f5, this.posY, 0.0F); - GL11.glTexCoord2f((f2 + f4) / 256.0F, (f3 + 15.98F) / 256.0F); - GL11.glVertex3f(this.posX + f4 / 2.0F - f5, this.posY + 7.99F, 0.0F); - GL11.glEnd(); - return (f1 - f) / 2.0F + 1.0F; - } - } - - protected void setColor(float r, float g, float b, float a) - { - GL11.glColor4f(r, g, b, a); - } - - protected void bindTexture(ResourceLocation location) - { - Minecraft.getMinecraft().renderEngine.bindTexture(location); - } - - private void readFontTexture() - { - BufferedImage bufferedimage; - - try - { - bufferedimage = ImageIO.read(getResourceInputStream(this.locationFontTexture)); - } - catch (IOException ioexception) - { - throw new RuntimeException(ioexception); - } - - int i = bufferedimage.getWidth(); - int j = bufferedimage.getHeight(); - int[] aint = new int[i * j]; - bufferedimage.getRGB(0, 0, i, j, aint, 0, i); - int k = j / 16; - int l = i / 16; - byte b0 = 1; - float f = 8.0F / (float)l; - int i1 = 0; - - while (i1 < 256) - { - int j1 = i1 % 16; - int k1 = i1 / 16; - - if (i1 == 32) - { - this.charWidth[i1] = 3 + b0; - } - - int l1 = l - 1; - - while (true) - { - if (l1 >= 0) - { - int i2 = j1 * l + l1; - boolean flag = true; - - for (int j2 = 0; j2 < k && flag; ++j2) - { - int k2 = (k1 * l + j2) * i; - - if ((aint[i2 + k2] >> 24 & 255) != 0) - { - flag = false; - } - } - - if (flag) - { - --l1; - continue; - } - } - - ++l1; - this.charWidth[i1] = (int)(0.5D + (double)((float)l1 * f)) + b0; - ++i1; - break; - } - } - } - - private void readGlyphSizes() - { - try - { - InputStream inputstream = getResourceInputStream(new ResourceLocation("font/glyph_sizes.bin")); - inputstream.read(this.glyphWidth); - } - catch (IOException ioexception) - { - throw new RuntimeException(ioexception); - } - } - - protected InputStream getResourceInputStream(ResourceLocation location) throws IOException - { - return Minecraft.getMinecraft().getResourceManager().getResource(location).getInputStream(); - } - - private String bidiReorder(String p_147647_1_) - { - try - { - Bidi bidi = new Bidi((new ArabicShaping(8)).shape(p_147647_1_), 127); - bidi.setReorderingMode(0); - return bidi.writeReordered(2); - } - catch (ArabicShapingException arabicshapingexception) - { - return p_147647_1_; - } - } -} diff --git a/src/main/java/noppes/npcs/client/gui/hud/GuiOverlayQuestEditor.java b/src/main/java/noppes/npcs/client/gui/hud/GuiOverlayQuestEditor.java new file mode 100644 index 000000000..4ce36b5aa --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/hud/GuiOverlayQuestEditor.java @@ -0,0 +1,199 @@ +package noppes.npcs.client.gui.hud; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; +import noppes.npcs.config.ConfigClient; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +public class GuiOverlayQuestEditor extends GuiScreen { + private GuiScreen parent; + // posX and posY are stored as percentages (0-100) of the scaled resolution. + private int posX, posY, scale, textAlign; + private final int overlayWidth = 200, overlayHeight = 120; + + private boolean dragging = false; + private int dragOffsetX, dragOffsetY; + private boolean resizing = false; + private int initialScale, initialMouseX, initialMouseY; + private final int HANDLE_SIZE = 10; + + private GuiButton saveButton, alignButton, resetButton; + + public GuiOverlayQuestEditor(GuiScreen parent) { + this.parent = parent; + // Load config values (stored as percentages) + posX = ConfigClient.QuestOverlayX; + posY = ConfigClient.QuestOverlayY; + scale = ConfigClient.QuestOverlayScale; + textAlign = ConfigClient.QuestOverlayTextAlign; + } + + @Override + public void initGui() { + buttonList.clear(); + saveButton = new GuiButton(0, width / 2 - 60, height - 45, 120, 20, "Save and Close"); + alignButton = new GuiButton(1, width / 2 - 60, height - 70, 120, 20, getAlignText()); + resetButton = new GuiButton(3, width / 2 - 60, height - 95, 120, 20, "Reset to Center"); + buttonList.add(saveButton); + buttonList.add(alignButton); + buttonList.add(resetButton); + } + + private String getAlignText() { + switch (textAlign) { + case 0: return "Align: Left"; + case 1: return "Align: Center"; + case 2: return "Align: Right"; + default: return "Align: Unknown"; + } + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + drawDefaultBackground(); + ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + int actualX = (int) ((float) posX / 100F * res.getScaledWidth()); + int actualY = (int) ((float) posY / 100F * res.getScaledHeight()); + + GL11.glPushMatrix(); + GL11.glTranslatef(actualX, actualY, 0); + float s = scale / 100.0F; + GL11.glScalef(s, s, s); + + // Draw preview background + drawRect(0, 0, overlayWidth, overlayHeight, 0x40FFFFFF); + + int currentY = 5; + currentY = renderDemoTextBlock(new String[] { "Dummy Quest Title" }, currentY, textAlign, 0xFFFFFF); + drawDecorativeLine(currentY - 1); + currentY += 8; + + currentY = renderDemoTextBlock(new String[] { "Dummy Category" }, currentY, textAlign, 0xCCCCCC); + drawDecorativeLine(currentY - 1); + currentY += 8; + + currentY = renderDemoTextBlock(new String[] { "Objective: Kill 10 mobs", "Objective: Collect 5 items" }, currentY, textAlign, 0xAAAAAA); + drawDecorativeLine(currentY - 1); + currentY += 8; + + renderDemoTextBlock(new String[] { "Turn in with NPC" }, currentY, textAlign, 0xAAAAAA); + + // Draw resize handle at bottom-right + drawRect(overlayWidth - HANDLE_SIZE, overlayHeight - HANDLE_SIZE, overlayWidth, overlayHeight, 0xFFCCCCCC); + GL11.glPopMatrix(); + + super.drawScreen(mouseX, mouseY, partialTicks); + } + + private int renderDemoTextBlock(String[] lines, int startY, int align, int color) { + int y = startY; + FontRenderer font = Minecraft.getMinecraft().fontRenderer; + for (String line : lines) { + int strWidth = font.getStringWidth(line); + int xOffset; + if (align == 1) + xOffset = (overlayWidth - strWidth) / 2; + else if (align == 2) + xOffset = overlayWidth - strWidth - 5; + else + xOffset = 5; + font.drawStringWithShadow(line, xOffset, y, color); + y += font.FONT_HEIGHT + 4; + } + return y; + } + + private void drawDecorativeLine(int y) { + drawHorizontalLine(5, overlayWidth - 5, y, 0xFF777777); + drawHorizontalLine(5, overlayWidth - 5, y + 1, 0xFFA8A8A8); + drawHorizontalLine(5, overlayWidth - 5, y + 2, 0xFFFFFFFF); + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { + ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + int actualX = (int) ((float) posX / 100F * res.getScaledWidth()); + int actualY = (int) ((float) posY / 100F * res.getScaledHeight()); + float s = scale / 100.0F; + int absWidth = (int) (overlayWidth * s); + int absHeight = (int) (overlayHeight * s); + if (mouseX >= actualX && mouseX <= actualX + absWidth && + mouseY >= actualY && mouseY <= actualY + absHeight) { + // Check if within resize handle + if (mouseX >= actualX + absWidth - HANDLE_SIZE && mouseY >= actualY + absHeight - HANDLE_SIZE) { + resizing = true; + initialScale = scale; + initialMouseX = mouseX; + initialMouseY = mouseY; + } else { + dragging = true; + dragOffsetX = mouseX - actualX; + dragOffsetY = mouseY - actualY; + } + } + super.mouseClicked(mouseX, mouseY, mouseButton); + } + + // For Minecraft 1.7.10, use mouseMovedOrUp for button release. + @Override + protected void mouseMovedOrUp(int mouseX, int mouseY, int state) { + dragging = false; + resizing = false; + super.mouseMovedOrUp(mouseX, mouseY, state); + } + + @Override + public void updateScreen() { + ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + int scaledWidth = res.getScaledWidth(); + int scaledHeight = res.getScaledHeight(); + // Calculate absolute dimensions for the overlay preview + int absWidth = (int) (overlayWidth * (scale / 100.0F)); + int absHeight = (int) (overlayHeight * (scale / 100.0F)); + + if (dragging) { + // Compute new absolute position in pixels + int newX = Mouse.getX() * width / mc.displayWidth - dragOffsetX; + int newY = scaledHeight - (Mouse.getY() * scaledHeight / mc.displayHeight) - dragOffsetY; + // Clamp the absolute position so that the overlay stays fully on screen + if (newX < 0) newX = 0; + if (newY < 0) newY = 0; + if (newX + absWidth > scaledWidth) newX = scaledWidth - absWidth; + if (newY + absHeight > scaledHeight) newY = scaledHeight - absHeight; + // Convert back to percentage values + posX = (int) (100F * newX / scaledWidth); + posY = (int) (100F * newY / scaledHeight); + } + if (resizing) { + int currentMouseX = Mouse.getX() * width / mc.displayWidth; + int deltaX = currentMouseX - initialMouseX; + scale = initialScale + deltaX; // 1 pixel = 1% change + if (scale < 50) scale = 50; + if (scale > 300) scale = 300; + } + super.updateScreen(); + } + + @Override + protected void actionPerformed(GuiButton button) { + if (button.id == 0) { // Save and close + ConfigClient.QuestOverlayX = posX; + ConfigClient.QuestOverlayY = posY; + ConfigClient.QuestOverlayScale = scale; + ConfigClient.QuestOverlayTextAlign = textAlign; + if (ConfigClient.config.hasChanged()) + ConfigClient.config.save(); + mc.displayGuiScreen(parent); + } else if (button.id == 1) { // Cycle alignment + textAlign = (textAlign + 1) % 3; + button.displayString = getAlignText(); + } else if (button.id == 3) { // Reset to center + posX = 50; + posY = 50; + } + } +} diff --git a/src/main/java/noppes/npcs/client/gui/hud/OverlayQuestTracking.java b/src/main/java/noppes/npcs/client/gui/hud/OverlayQuestTracking.java new file mode 100644 index 000000000..a68cd746a --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/hud/OverlayQuestTracking.java @@ -0,0 +1,191 @@ +package noppes.npcs.client.gui.hud; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import noppes.npcs.config.ConfigClient; +import noppes.npcs.controllers.data.Quest; +import org.lwjgl.opengl.GL11; + +import java.util.ArrayList; +import java.util.List; + +public class OverlayQuestTracking extends Gui { + private Minecraft mc; + + // Dimensions for overlay background + private int overlayWidth = 200; + private int overlayHeight = 120; + + // Text lists for each section + private ArrayList questTitleLines = new ArrayList<>(); + private ArrayList questCategoryLines = new ArrayList<>(); + private ArrayList objectiveLines = new ArrayList<>(); + private ArrayList turnInLines = new ArrayList<>(); + + public OverlayQuestTracking(Minecraft mc) { + this.mc = mc; + } + + /** + * Updates overlay text based on quest data. + * Converts "&" codes into Minecraft formatting codes. + */ + public void setQuestData(Quest quest, String category, List objectives, String turnIn) { + questTitleLines = splitLines(convertColorCodes(quest.getName()), overlayWidth - 10); + questCategoryLines = splitLines(convertColorCodes(category), overlayWidth - 10); + objectiveLines.clear(); + for (String obj : objectives) { + objectiveLines.add(convertColorCodes(obj)); + } + turnInLines.clear(); + if (turnIn != null && !turnIn.isEmpty()) { + turnInLines.add(convertColorCodes(turnIn)); + } + } + + /** + * Reads overlay data from an NBT compound and updates the overlay. + */ + public void setOverlayData(NBTTagCompound compound) { + Quest quest = new Quest(); + quest.readNBT(compound.getCompoundTag("Quest")); + String category = compound.getString("CategoryName"); + + ArrayList objectives = new ArrayList<>(); + NBTTagList objectiveList = compound.getTagList("ObjectiveList", 8); + for (int i = 0; i < objectiveList.tagCount(); i++) { + String objective = objectiveList.getStringTagAt(i); + String[] split = objective.split(":"); + split = split[split.length - 1].split("/"); + boolean completed = false; + try { + if (split.length < 2) + throw new NumberFormatException("Insufficient data"); + int killed = Integer.parseInt(split[0].trim()); + int total = Integer.parseInt(split[1].trim()); + if (killed / total == 1) + completed = true; + } catch (NumberFormatException e) { + if (objective.endsWith("(Done)") || objective.endsWith("(read)") || + (objective.endsWith("Found") && !objective.endsWith("Not Found"))) + completed = true; + } + if (completed) { + objective = "&a&o&m" + objective; + } else { + objective = "&o" + objective; + } + objectives.add(objective); + } + + String turnIn = ""; + boolean instantComplete = compound.getBoolean("Instant"); + if (instantComplete) { + turnIn = "Completed automatically"; + } else { + String npcName = compound.getString("TurnInNPC"); + if (!npcName.isEmpty()) { + turnIn = "Complete with " + npcName; + } + } + setQuestData(quest, category, objectives, turnIn); + } + + /** + * Renders the overlay using the current configuration settings. + * Here, posX and posY (from config, treated as percentages) are used relative to the current scaled resolution. + */ + public void renderOverlay(float partialTicks) { + ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + int actualX = (int) ((float) ConfigClient.QuestOverlayX / 100F * res.getScaledWidth()); + int actualY = (int) ((float) ConfigClient.QuestOverlayY / 100F * res.getScaledHeight()); + float s = ConfigClient.QuestOverlayScale / 100.0F; + int textAlign = ConfigClient.QuestOverlayTextAlign; // 0: left, 1: center, 2: right + + GL11.glPushMatrix(); + GL11.glTranslatef(actualX, actualY, 0); + GL11.glScalef(s, s, s); + + // Draw a lighter, semi-transparent background + drawRect(0, 0, overlayWidth, overlayHeight, 0x40FFFFFF); + + int currentY = 5; + currentY = renderTextBlock(questTitleLines, currentY, textAlign, 0xFFFFFF); + drawDecorativeLine(currentY - 1); + currentY += 8; + + currentY = renderTextBlock(questCategoryLines, currentY, textAlign, 0xCCCCCC); + drawDecorativeLine(currentY - 1); + currentY += 8; + + currentY = renderTextBlock(objectiveLines, currentY, textAlign, 0xAAAAAA); + if (!turnInLines.isEmpty()) { + drawDecorativeLine(currentY - 1); + currentY += 8; + } + + renderTextBlock(turnInLines, currentY, textAlign, 0xAAAAAA); + + GL11.glPopMatrix(); + } + + private int renderTextBlock(List lines, int startY, int align, int color) { + int y = startY; + FontRenderer font = mc.fontRenderer; + for (String line : lines) { + int strWidth = font.getStringWidth(line); + int xOffset; + if (align == 1) + xOffset = (overlayWidth - strWidth) / 2; + else if (align == 2) + xOffset = overlayWidth - strWidth - 5; + else + xOffset = 5; + font.drawStringWithShadow(line, xOffset, y, color); + y += font.FONT_HEIGHT + 4; + } + return y; + } + + private void drawDecorativeLine(int y) { + int lineStart = 5; + int lineEnd = overlayWidth - 5; + drawHorizontalLine(lineStart, lineEnd, y, 0xFF777777); + drawHorizontalLine(lineStart, lineEnd, y + 1, 0xFFA8A8A8); + drawHorizontalLine(lineStart, lineEnd, y + 2, 0xFFFFFFFF); + } + + private ArrayList splitLines(String text, int maxWidth) { + ArrayList lines = new ArrayList<>(); + String[] words = text.split(" "); + StringBuilder current = new StringBuilder(); + FontRenderer font = mc.fontRenderer; + for (String word : words) { + String test = current.length() == 0 ? word : current.toString() + " " + word; + if (font.getStringWidth(test) > maxWidth) { + if (current.length() > 0) { + lines.add(current.toString()); + current = new StringBuilder(word); + } else { + lines.add(word); + } + } else { + if (current.length() > 0) + current.append(" ").append(word); + else + current.append(word); + } + } + if (current.length() > 0) + lines.add(current.toString()); + return lines; + } + + private String convertColorCodes(String text) { + return text.replaceAll("&([0-9a-fk-or])", "§$1"); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java index 44f2af54e..2cf7d1d09 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java @@ -8,6 +8,7 @@ import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import noppes.npcs.client.ClientCacheHandler; +import noppes.npcs.client.gui.hud.GuiOverlayQuestEditor; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.GuiNpcTextField; @@ -83,6 +84,9 @@ public class GuiSettings extends GuiCNPCInventory implements ITextfieldListener, y += 22; + this.addLabel(new GuiNpcLabel(90, "overlayer", guiLeft + 8, guiTop + 14 + y)); + this.addButton(new GuiNpcButton(90, guiLeft + 105, guiTop + 9 + y, "EDIT")); + y += 22; this.addButton(new GuiNpcButton(5, guiLeft + 8, guiTop + 9 + y, 150, 20, "settings.clearSkin")); this.addButton(new GuiNpcButton(4, guiLeft + 8 + 155, guiTop + 9 + y, 150, 20, "settings.clearTrack")); @@ -162,6 +166,9 @@ public class GuiSettings extends GuiCNPCInventory implements ITextfieldListener, ConfigClient.HideEffectsBar = button.getValue() == 1; ConfigClient.HideEffectsBarProperty.set(ConfigClient.HideEffectsBar); } + if(button.id == 90){ + mc.displayGuiScreen(new GuiOverlayQuestEditor(this)); + } ConfigClient.config.save(); } diff --git a/src/main/java/noppes/npcs/config/ConfigClient.java b/src/main/java/noppes/npcs/config/ConfigClient.java index d2d7d1a85..6a36160d7 100644 --- a/src/main/java/noppes/npcs/config/ConfigClient.java +++ b/src/main/java/noppes/npcs/config/ConfigClient.java @@ -77,6 +77,20 @@ public class ConfigClient public static Property BannerAlertsProperty; public static boolean BannerAlerts = true; + // New Quest Overlay configuration properties + public static Property QuestOverlayXProperty; + public static int QuestOverlayX = 100; + + public static Property QuestOverlayYProperty; + public static int QuestOverlayY = 100; + + public static Property QuestOverlayScaleProperty; + public static int QuestOverlayScale = 100; + + public static Property QuestOverlayTextAlignProperty; + public static int QuestOverlayTextAlign = 1; // 0: Left, 1: Center, 2: Right + + /** * Texture Properties **/ @@ -107,6 +121,20 @@ public class ConfigClient { config.load(); + // Load new Quest Overlay settings + QuestOverlayXProperty = config.get(QUESTING, "QuestOverlayX", 100, "X position of the quest overlay."); + QuestOverlayX = QuestOverlayXProperty.getInt(100); + + QuestOverlayYProperty = config.get(QUESTING, "QuestOverlayY", 100, "Y position of the quest overlay."); + QuestOverlayY = QuestOverlayYProperty.getInt(100); + + QuestOverlayScaleProperty = config.get(QUESTING, "QuestOverlayScale", 100, "Scale percentage of the quest overlay."); + QuestOverlayScale = QuestOverlayScaleProperty.getInt(100); + + QuestOverlayTextAlignProperty = config.get(QUESTING, "QuestOverlayTextAlign", 1, "Text alignment in quest overlay (0: Left, 1: Center, 2: Right)."); + QuestOverlayTextAlign = QuestOverlayTextAlignProperty.getInt(1); + + // General CacheLifeProperty = config.get(GENERAL, "Cache Life", 10, "How long should downloaded imagery data be saved client side? (In minutes)"); CacheLife = CacheLifeProperty.getInt(10); From fe9bb02aea73f6d50ba3e31cdf017a2cf9cc5225 Mon Sep 17 00:00:00 2001 From: Kam Date: Sun, 23 Feb 2025 04:58:41 -0500 Subject: [PATCH 42/59] Better Hud System CNPC+ --- .../data/OverlayQuestTrackingPacket.java | 12 +- .../npcs/client/ClientCacheHandler.java | 3 - .../npcs/client/ClientEventHandler.java | 13 +- .../npcs/client/gui/hud/ClientHudManager.java | 36 +++ .../npcs/client/gui/hud/EnumHudComponent.java | 5 + .../npcs/client/gui/hud/GuiHudEditor.java | 180 ++++++++++++ .../client/gui/hud/GuiOverlayQuestEditor.java | 199 ------------- .../npcs/client/gui/hud/HudComponent.java | 55 ++++ .../client/gui/hud/OverlayQuestTracking.java | 191 ------------ .../gui/hud/QuestTrackingComponent.java | 278 ++++++++++++++++++ .../gui/player/inventory/GuiSettings.java | 4 +- 11 files changed, 575 insertions(+), 401 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/hud/ClientHudManager.java create mode 100644 src/main/java/noppes/npcs/client/gui/hud/EnumHudComponent.java create mode 100644 src/main/java/noppes/npcs/client/gui/hud/GuiHudEditor.java delete mode 100644 src/main/java/noppes/npcs/client/gui/hud/GuiOverlayQuestEditor.java create mode 100644 src/main/java/noppes/npcs/client/gui/hud/HudComponent.java delete mode 100644 src/main/java/noppes/npcs/client/gui/hud/OverlayQuestTracking.java create mode 100644 src/main/java/noppes/npcs/client/gui/hud/QuestTrackingComponent.java diff --git a/src/main/java/kamkeel/npcs/network/packets/data/OverlayQuestTrackingPacket.java b/src/main/java/kamkeel/npcs/network/packets/data/OverlayQuestTrackingPacket.java index af999382a..f64756ba1 100644 --- a/src/main/java/kamkeel/npcs/network/packets/data/OverlayQuestTrackingPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/data/OverlayQuestTrackingPacket.java @@ -12,7 +12,9 @@ import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.ClientCacheHandler; -import noppes.npcs.client.gui.hud.OverlayQuestTracking; +import noppes.npcs.client.gui.hud.ClientHudManager; +import noppes.npcs.client.gui.hud.EnumHudComponent; +import noppes.npcs.client.gui.hud.HudComponent; import java.io.IOException; @@ -46,12 +48,14 @@ public final class OverlayQuestTrackingPacket extends AbstractPacket { @SideOnly(Side.CLIENT) @Override public void receiveData(ByteBuf in, EntityPlayer player) throws IOException { + HudComponent component = ClientHudManager.getInstance().getHudComponents().get(EnumHudComponent.QuestTracker); try { NBTTagCompound nbt = ByteBufUtils.readNBT(in); - ClientCacheHandler.questTrackingOverlay = new OverlayQuestTracking(Minecraft.getMinecraft()); - ClientCacheHandler.questTrackingOverlay.setOverlayData(nbt); + component.loadData(nbt); + if(nbt.hasNoTags()) + component.hasData = false; } catch (IOException e) { - ClientCacheHandler.questTrackingOverlay = null; + component.hasData = false; } } } diff --git a/src/main/java/noppes/npcs/client/ClientCacheHandler.java b/src/main/java/noppes/npcs/client/ClientCacheHandler.java index 16a81a286..abfc0993e 100644 --- a/src/main/java/noppes/npcs/client/ClientCacheHandler.java +++ b/src/main/java/noppes/npcs/client/ClientCacheHandler.java @@ -1,7 +1,6 @@ package noppes.npcs.client; import net.minecraft.util.ResourceLocation; -import noppes.npcs.client.gui.hud.OverlayQuestTracking; import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.gui.select.GuiSoundSelection; import noppes.npcs.client.gui.select.GuiTextureSelection; @@ -19,7 +18,6 @@ import java.util.UUID; public class ClientCacheHandler { private static final CacheHashMap> imageDataCache = new CacheHashMap<>((long) ConfigClient.CacheLife * 60 * 1000); public static PlayerData playerData = new PlayerData(); - public static OverlayQuestTracking questTrackingOverlay = null; public static HashMap customOverlays = new HashMap<>(); public static HashMap> skinOverlays = new HashMap<>(); public static HashMap playerAnimations = new HashMap<>(); @@ -56,7 +54,6 @@ public class ClientCacheHandler { public static void clearCache() { ClientCacheHandler.imageDataCache.clear(); - ClientCacheHandler.questTrackingOverlay = null; ClientCacheHandler.customOverlays.clear(); ClientCacheHandler.skinOverlays.clear(); ClientCacheHandler.playerAnimations.clear(); diff --git a/src/main/java/noppes/npcs/client/ClientEventHandler.java b/src/main/java/noppes/npcs/client/ClientEventHandler.java index eb9e4825a..6d5bfedd8 100644 --- a/src/main/java/noppes/npcs/client/ClientEventHandler.java +++ b/src/main/java/noppes/npcs/client/ClientEventHandler.java @@ -16,6 +16,9 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.*; import noppes.npcs.client.gui.customoverlay.OverlayCustom; +import noppes.npcs.client.gui.hud.ClientHudManager; +import noppes.npcs.client.gui.hud.EnumHudComponent; +import noppes.npcs.client.gui.hud.QuestTrackingComponent; import noppes.npcs.client.renderer.MarkRenderer; import noppes.npcs.client.renderer.RenderCNPCPlayer; import noppes.npcs.constants.EnumAnimationPart; @@ -90,9 +93,15 @@ public class ClientEventHandler { overlayCustom.renderGameOverlay(event.partialTicks); } - if (ClientCacheHandler.questTrackingOverlay != null) { - ClientCacheHandler.questTrackingOverlay.renderOverlay(event.partialTicks); + if(ClientHudManager.getInstance().getHudComponents().isEmpty()){ + ClientHudManager.getInstance().registerHud(EnumHudComponent.QuestTracker, new QuestTrackingComponent(Minecraft.getMinecraft())); } + + ClientHudManager.getInstance().renderAllHUDs(event.partialTicks); + +// if (ClientCacheHandler.questTrackingOverlay != null) { +// ClientCacheHandler.questTrackingOverlay.renderOverlay(event.partialTicks); +// } } } diff --git a/src/main/java/noppes/npcs/client/gui/hud/ClientHudManager.java b/src/main/java/noppes/npcs/client/gui/hud/ClientHudManager.java new file mode 100644 index 000000000..362773b63 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/hud/ClientHudManager.java @@ -0,0 +1,36 @@ +package noppes.npcs.client.gui.hud; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class ClientHudManager { + private static ClientHudManager instance; + private HashMap hudComponents = new HashMap<>(); + + private ClientHudManager() {} + + public static ClientHudManager getInstance() { + if(instance == null) + instance = new ClientHudManager(); + return instance; + } + + public void registerHud(EnumHudComponent enumHudComponent, HudComponent hud) { + hudComponents.put(enumHudComponent, hud); + } + + public HashMap getHudComponents() { + return hudComponents; + } + + /** + * Renders all enabled HUD components (normal mode). + */ + public void renderAllHUDs(float partialTicks) { + for (HudComponent hud : hudComponents.values()) { + if(hud.enabled) + hud.renderOnScreen(partialTicks); + } + } +} diff --git a/src/main/java/noppes/npcs/client/gui/hud/EnumHudComponent.java b/src/main/java/noppes/npcs/client/gui/hud/EnumHudComponent.java new file mode 100644 index 000000000..c1ac41239 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/hud/EnumHudComponent.java @@ -0,0 +1,5 @@ +package noppes.npcs.client.gui.hud; + +public enum EnumHudComponent { + QuestTracker +} diff --git a/src/main/java/noppes/npcs/client/gui/hud/GuiHudEditor.java b/src/main/java/noppes/npcs/client/gui/hud/GuiHudEditor.java new file mode 100644 index 000000000..f7752f0e8 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/hud/GuiHudEditor.java @@ -0,0 +1,180 @@ +package noppes.npcs.client.gui.hud; + +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.Minecraft; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; +import java.util.List; +import java.util.ArrayList; + +public class GuiHudEditor extends GuiScreen { + private GuiScreen parent; + // Currently selected HUD component for moving/resizing. + private HudComponent selectedComponent; + private int dragOffsetX, dragOffsetY; + private boolean dragging = false; + private boolean resizing = false; + private int initialScale, initialMouseX, initialMouseY; + private final int HANDLE_SIZE = 10; + private final int RESET_POSITION_ID = 100; + + public GuiHudEditor(GuiScreen parent) { + this.parent = parent; + selectedComponent = ClientHudManager.getInstance().getHudComponents().get(EnumHudComponent.QuestTracker); + } + + @Override + public void initGui() { + buttonList.clear(); + // Global "Save and Close" button always visible. + buttonList.add(new GuiButton(0, width / 2 - 60, height - 45, 120, 20, "Save and Close")); + updateCustomButtons(); + } + + /** + * Updates the custom buttons shown on screen. + * Removes all buttons except the global Save button (id 0) + * then adds the selected component's custom buttons plus a Reset Position button. + */ + private void updateCustomButtons() { + // Remove any buttons that are not the global Save (id 0) + for (int i = buttonList.size() - 1; i >= 0; i--) { + GuiButton btn = (GuiButton) buttonList.get(i); + if (btn.id != 0) { + buttonList.remove(i); + } + } + if (selectedComponent != null) { + int baseX = width / 2 - 60; + int baseY = height - 70; // Start above the Save button. + List customButtons = new ArrayList<>(); + selectedComponent.addEditorButtons(customButtons); + int offsetY = 0; + for (GuiButton btn : customButtons) { + btn.xPosition = baseX; + btn.yPosition = baseY - offsetY; + offsetY += btn.height + 5; + buttonList.add(btn); + } + // Always add the Reset Position button. + GuiButton resetPos = new GuiButton(RESET_POSITION_ID, baseX, baseY - offsetY, 120, 20, "Reset Position"); + buttonList.add(resetPos); + } + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + drawDefaultBackground(); + // Render each HUD in editing mode. + for (HudComponent hud : ClientHudManager.getInstance().getHudComponents().values()) { + hud.renderEditing(); + } + super.drawScreen(mouseX, mouseY, partialTicks); + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { + // Iterate over HUD components to check for selection. + for (HudComponent hud : ClientHudManager.getInstance().getHudComponents().values()) { + ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + // Use base scaling (scale/100.0F) + float effectiveScale = (hud.scale / 100.0F); + int actualX = (int)((float)hud.posX / 100F * res.getScaledWidth()); + int actualY = (int)((float)hud.posY / 100F * res.getScaledHeight()); + int absWidth = (int)(hud.overlayWidth * effectiveScale); + int absHeight = (int)(hud.overlayHeight * effectiveScale); + if (mouseX >= actualX && mouseX <= actualX + absWidth && + mouseY >= actualY && mouseY <= actualY + absHeight) { + // Check if clicking on the resize handle (bottom-right). + if (mouseX >= actualX + absWidth - HANDLE_SIZE && mouseY >= actualY + absHeight - HANDLE_SIZE) { + resizing = true; + selectedComponent = hud; + initialScale = hud.scale; + initialMouseX = mouseX; + initialMouseY = mouseY; + } else { + dragging = true; + selectedComponent = hud; + dragOffsetX = mouseX - actualX; + dragOffsetY = mouseY - actualY; + } + updateCustomButtons(); + break; + } + } + super.mouseClicked(mouseX, mouseY, mouseButton); + } + + @Override + protected void mouseMovedOrUp(int mouseX, int mouseY, int state) { + dragging = false; + resizing = false; + // Optionally keep selectedComponent so its buttons remain visible. + super.mouseMovedOrUp(mouseX, mouseY, state); + } + + @Override + public void updateScreen() { + if (selectedComponent != null) { + ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + int scaledWidth = res.getScaledWidth(); + int scaledHeight = res.getScaledHeight(); + float effectiveScale = (selectedComponent.scale / 100.0F); + if (dragging) { + int newX = Mouse.getX() * width / mc.displayWidth - dragOffsetX; + int newY = scaledHeight - (Mouse.getY() * scaledHeight / mc.displayHeight) - dragOffsetY; + if (newX < 0) newX = 0; + if (newY < 0) newY = 0; + if (newX + (int)(selectedComponent.overlayWidth * effectiveScale) > scaledWidth) + newX = scaledWidth - (int)(selectedComponent.overlayWidth * effectiveScale); + if (newY + (int)(selectedComponent.overlayHeight * effectiveScale) > scaledHeight) + newY = scaledHeight - (int)(selectedComponent.overlayHeight * effectiveScale); + selectedComponent.posX = (int)(100F * newX / scaledWidth); + selectedComponent.posY = (int)(100F * newY / scaledHeight); + } + if (resizing) { + int currentMouseX = Mouse.getX() * width / mc.displayWidth; + int deltaX = currentMouseX - initialMouseX; + selectedComponent.scale = initialScale + deltaX; // 1 pixel = 1% change. + if (selectedComponent.scale < 50) selectedComponent.scale = 50; + if (selectedComponent.scale > 300) selectedComponent.scale = 300; + } + } + super.updateScreen(); + } + + @Override + protected void actionPerformed(GuiButton button) { + if (button.id == 0) { + close(); + } else if (button.id == RESET_POSITION_ID) { + // Reset position for selected HUD. + if (selectedComponent != null) { + selectedComponent.posX = 50; + selectedComponent.posY = 50; + updateCustomButtons(); + } + } else { + // Dispatch other button actions to the selected component. + if (selectedComponent != null) { + selectedComponent.onEditorButtonPressed(button); + updateCustomButtons(); + } + } + } + protected void keyTyped(char typedChar, int keyCode) { + if (keyCode == 1) { + close(); + } + } + + public void close() { + for (HudComponent hud : ClientHudManager.getInstance().getHudComponents().values()) { + hud.isEditting = false; + hud.save(); + } + mc.displayGuiScreen(parent); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/hud/GuiOverlayQuestEditor.java b/src/main/java/noppes/npcs/client/gui/hud/GuiOverlayQuestEditor.java deleted file mode 100644 index 4ce36b5aa..000000000 --- a/src/main/java/noppes/npcs/client/gui/hud/GuiOverlayQuestEditor.java +++ /dev/null @@ -1,199 +0,0 @@ -package noppes.npcs.client.gui.hud; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.ScaledResolution; -import noppes.npcs.config.ConfigClient; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; - -public class GuiOverlayQuestEditor extends GuiScreen { - private GuiScreen parent; - // posX and posY are stored as percentages (0-100) of the scaled resolution. - private int posX, posY, scale, textAlign; - private final int overlayWidth = 200, overlayHeight = 120; - - private boolean dragging = false; - private int dragOffsetX, dragOffsetY; - private boolean resizing = false; - private int initialScale, initialMouseX, initialMouseY; - private final int HANDLE_SIZE = 10; - - private GuiButton saveButton, alignButton, resetButton; - - public GuiOverlayQuestEditor(GuiScreen parent) { - this.parent = parent; - // Load config values (stored as percentages) - posX = ConfigClient.QuestOverlayX; - posY = ConfigClient.QuestOverlayY; - scale = ConfigClient.QuestOverlayScale; - textAlign = ConfigClient.QuestOverlayTextAlign; - } - - @Override - public void initGui() { - buttonList.clear(); - saveButton = new GuiButton(0, width / 2 - 60, height - 45, 120, 20, "Save and Close"); - alignButton = new GuiButton(1, width / 2 - 60, height - 70, 120, 20, getAlignText()); - resetButton = new GuiButton(3, width / 2 - 60, height - 95, 120, 20, "Reset to Center"); - buttonList.add(saveButton); - buttonList.add(alignButton); - buttonList.add(resetButton); - } - - private String getAlignText() { - switch (textAlign) { - case 0: return "Align: Left"; - case 1: return "Align: Center"; - case 2: return "Align: Right"; - default: return "Align: Unknown"; - } - } - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - drawDefaultBackground(); - ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); - int actualX = (int) ((float) posX / 100F * res.getScaledWidth()); - int actualY = (int) ((float) posY / 100F * res.getScaledHeight()); - - GL11.glPushMatrix(); - GL11.glTranslatef(actualX, actualY, 0); - float s = scale / 100.0F; - GL11.glScalef(s, s, s); - - // Draw preview background - drawRect(0, 0, overlayWidth, overlayHeight, 0x40FFFFFF); - - int currentY = 5; - currentY = renderDemoTextBlock(new String[] { "Dummy Quest Title" }, currentY, textAlign, 0xFFFFFF); - drawDecorativeLine(currentY - 1); - currentY += 8; - - currentY = renderDemoTextBlock(new String[] { "Dummy Category" }, currentY, textAlign, 0xCCCCCC); - drawDecorativeLine(currentY - 1); - currentY += 8; - - currentY = renderDemoTextBlock(new String[] { "Objective: Kill 10 mobs", "Objective: Collect 5 items" }, currentY, textAlign, 0xAAAAAA); - drawDecorativeLine(currentY - 1); - currentY += 8; - - renderDemoTextBlock(new String[] { "Turn in with NPC" }, currentY, textAlign, 0xAAAAAA); - - // Draw resize handle at bottom-right - drawRect(overlayWidth - HANDLE_SIZE, overlayHeight - HANDLE_SIZE, overlayWidth, overlayHeight, 0xFFCCCCCC); - GL11.glPopMatrix(); - - super.drawScreen(mouseX, mouseY, partialTicks); - } - - private int renderDemoTextBlock(String[] lines, int startY, int align, int color) { - int y = startY; - FontRenderer font = Minecraft.getMinecraft().fontRenderer; - for (String line : lines) { - int strWidth = font.getStringWidth(line); - int xOffset; - if (align == 1) - xOffset = (overlayWidth - strWidth) / 2; - else if (align == 2) - xOffset = overlayWidth - strWidth - 5; - else - xOffset = 5; - font.drawStringWithShadow(line, xOffset, y, color); - y += font.FONT_HEIGHT + 4; - } - return y; - } - - private void drawDecorativeLine(int y) { - drawHorizontalLine(5, overlayWidth - 5, y, 0xFF777777); - drawHorizontalLine(5, overlayWidth - 5, y + 1, 0xFFA8A8A8); - drawHorizontalLine(5, overlayWidth - 5, y + 2, 0xFFFFFFFF); - } - - @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { - ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); - int actualX = (int) ((float) posX / 100F * res.getScaledWidth()); - int actualY = (int) ((float) posY / 100F * res.getScaledHeight()); - float s = scale / 100.0F; - int absWidth = (int) (overlayWidth * s); - int absHeight = (int) (overlayHeight * s); - if (mouseX >= actualX && mouseX <= actualX + absWidth && - mouseY >= actualY && mouseY <= actualY + absHeight) { - // Check if within resize handle - if (mouseX >= actualX + absWidth - HANDLE_SIZE && mouseY >= actualY + absHeight - HANDLE_SIZE) { - resizing = true; - initialScale = scale; - initialMouseX = mouseX; - initialMouseY = mouseY; - } else { - dragging = true; - dragOffsetX = mouseX - actualX; - dragOffsetY = mouseY - actualY; - } - } - super.mouseClicked(mouseX, mouseY, mouseButton); - } - - // For Minecraft 1.7.10, use mouseMovedOrUp for button release. - @Override - protected void mouseMovedOrUp(int mouseX, int mouseY, int state) { - dragging = false; - resizing = false; - super.mouseMovedOrUp(mouseX, mouseY, state); - } - - @Override - public void updateScreen() { - ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); - int scaledWidth = res.getScaledWidth(); - int scaledHeight = res.getScaledHeight(); - // Calculate absolute dimensions for the overlay preview - int absWidth = (int) (overlayWidth * (scale / 100.0F)); - int absHeight = (int) (overlayHeight * (scale / 100.0F)); - - if (dragging) { - // Compute new absolute position in pixels - int newX = Mouse.getX() * width / mc.displayWidth - dragOffsetX; - int newY = scaledHeight - (Mouse.getY() * scaledHeight / mc.displayHeight) - dragOffsetY; - // Clamp the absolute position so that the overlay stays fully on screen - if (newX < 0) newX = 0; - if (newY < 0) newY = 0; - if (newX + absWidth > scaledWidth) newX = scaledWidth - absWidth; - if (newY + absHeight > scaledHeight) newY = scaledHeight - absHeight; - // Convert back to percentage values - posX = (int) (100F * newX / scaledWidth); - posY = (int) (100F * newY / scaledHeight); - } - if (resizing) { - int currentMouseX = Mouse.getX() * width / mc.displayWidth; - int deltaX = currentMouseX - initialMouseX; - scale = initialScale + deltaX; // 1 pixel = 1% change - if (scale < 50) scale = 50; - if (scale > 300) scale = 300; - } - super.updateScreen(); - } - - @Override - protected void actionPerformed(GuiButton button) { - if (button.id == 0) { // Save and close - ConfigClient.QuestOverlayX = posX; - ConfigClient.QuestOverlayY = posY; - ConfigClient.QuestOverlayScale = scale; - ConfigClient.QuestOverlayTextAlign = textAlign; - if (ConfigClient.config.hasChanged()) - ConfigClient.config.save(); - mc.displayGuiScreen(parent); - } else if (button.id == 1) { // Cycle alignment - textAlign = (textAlign + 1) % 3; - button.displayString = getAlignText(); - } else if (button.id == 3) { // Reset to center - posX = 50; - posY = 50; - } - } -} diff --git a/src/main/java/noppes/npcs/client/gui/hud/HudComponent.java b/src/main/java/noppes/npcs/client/gui/hud/HudComponent.java new file mode 100644 index 000000000..b004ecfa1 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/hud/HudComponent.java @@ -0,0 +1,55 @@ +package noppes.npcs.client.gui.hud; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.client.gui.GuiButton; +import java.util.List; + +public abstract class HudComponent { + // Stored as percentages (0-100) of the current screen resolution. + protected int posX = 50, posY = 50, scale = 100, textAlign = 0; + + public boolean enabled = true; + public boolean hasData = false; + public boolean isEditting = false; + + protected final int overlayWidth = 200, overlayHeight = 120; + + /** + * Loads custom HUD data from an NBT compound. + */ + public abstract void loadData(NBTTagCompound compound); + + /** + * Loads HUD settings from the config. + */ + public abstract void load(); + + /** + * Saves HUD settings to the config. + */ + public abstract void save(); + + /** + * Renders the HUD as it appears during normal gameplay. + */ + public abstract void renderOnScreen(float partialTicks); + + /** + * Renders the HUD in edit mode (with handles, borders, dummy data, etc.). + */ + public abstract void renderEditing(); + + /** + * Allows the component to add its own editor buttons. + */ + public void addEditorButtons(List buttonList) { + // Default: do nothing. + } + + /** + * Handles editor button actions specific to this HUD component. + */ + public void onEditorButtonPressed(GuiButton button) { + // Default: do nothing. + } +} diff --git a/src/main/java/noppes/npcs/client/gui/hud/OverlayQuestTracking.java b/src/main/java/noppes/npcs/client/gui/hud/OverlayQuestTracking.java deleted file mode 100644 index a68cd746a..000000000 --- a/src/main/java/noppes/npcs/client/gui/hud/OverlayQuestTracking.java +++ /dev/null @@ -1,191 +0,0 @@ -package noppes.npcs.client.gui.hud; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import noppes.npcs.config.ConfigClient; -import noppes.npcs.controllers.data.Quest; -import org.lwjgl.opengl.GL11; - -import java.util.ArrayList; -import java.util.List; - -public class OverlayQuestTracking extends Gui { - private Minecraft mc; - - // Dimensions for overlay background - private int overlayWidth = 200; - private int overlayHeight = 120; - - // Text lists for each section - private ArrayList questTitleLines = new ArrayList<>(); - private ArrayList questCategoryLines = new ArrayList<>(); - private ArrayList objectiveLines = new ArrayList<>(); - private ArrayList turnInLines = new ArrayList<>(); - - public OverlayQuestTracking(Minecraft mc) { - this.mc = mc; - } - - /** - * Updates overlay text based on quest data. - * Converts "&" codes into Minecraft formatting codes. - */ - public void setQuestData(Quest quest, String category, List objectives, String turnIn) { - questTitleLines = splitLines(convertColorCodes(quest.getName()), overlayWidth - 10); - questCategoryLines = splitLines(convertColorCodes(category), overlayWidth - 10); - objectiveLines.clear(); - for (String obj : objectives) { - objectiveLines.add(convertColorCodes(obj)); - } - turnInLines.clear(); - if (turnIn != null && !turnIn.isEmpty()) { - turnInLines.add(convertColorCodes(turnIn)); - } - } - - /** - * Reads overlay data from an NBT compound and updates the overlay. - */ - public void setOverlayData(NBTTagCompound compound) { - Quest quest = new Quest(); - quest.readNBT(compound.getCompoundTag("Quest")); - String category = compound.getString("CategoryName"); - - ArrayList objectives = new ArrayList<>(); - NBTTagList objectiveList = compound.getTagList("ObjectiveList", 8); - for (int i = 0; i < objectiveList.tagCount(); i++) { - String objective = objectiveList.getStringTagAt(i); - String[] split = objective.split(":"); - split = split[split.length - 1].split("/"); - boolean completed = false; - try { - if (split.length < 2) - throw new NumberFormatException("Insufficient data"); - int killed = Integer.parseInt(split[0].trim()); - int total = Integer.parseInt(split[1].trim()); - if (killed / total == 1) - completed = true; - } catch (NumberFormatException e) { - if (objective.endsWith("(Done)") || objective.endsWith("(read)") || - (objective.endsWith("Found") && !objective.endsWith("Not Found"))) - completed = true; - } - if (completed) { - objective = "&a&o&m" + objective; - } else { - objective = "&o" + objective; - } - objectives.add(objective); - } - - String turnIn = ""; - boolean instantComplete = compound.getBoolean("Instant"); - if (instantComplete) { - turnIn = "Completed automatically"; - } else { - String npcName = compound.getString("TurnInNPC"); - if (!npcName.isEmpty()) { - turnIn = "Complete with " + npcName; - } - } - setQuestData(quest, category, objectives, turnIn); - } - - /** - * Renders the overlay using the current configuration settings. - * Here, posX and posY (from config, treated as percentages) are used relative to the current scaled resolution. - */ - public void renderOverlay(float partialTicks) { - ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); - int actualX = (int) ((float) ConfigClient.QuestOverlayX / 100F * res.getScaledWidth()); - int actualY = (int) ((float) ConfigClient.QuestOverlayY / 100F * res.getScaledHeight()); - float s = ConfigClient.QuestOverlayScale / 100.0F; - int textAlign = ConfigClient.QuestOverlayTextAlign; // 0: left, 1: center, 2: right - - GL11.glPushMatrix(); - GL11.glTranslatef(actualX, actualY, 0); - GL11.glScalef(s, s, s); - - // Draw a lighter, semi-transparent background - drawRect(0, 0, overlayWidth, overlayHeight, 0x40FFFFFF); - - int currentY = 5; - currentY = renderTextBlock(questTitleLines, currentY, textAlign, 0xFFFFFF); - drawDecorativeLine(currentY - 1); - currentY += 8; - - currentY = renderTextBlock(questCategoryLines, currentY, textAlign, 0xCCCCCC); - drawDecorativeLine(currentY - 1); - currentY += 8; - - currentY = renderTextBlock(objectiveLines, currentY, textAlign, 0xAAAAAA); - if (!turnInLines.isEmpty()) { - drawDecorativeLine(currentY - 1); - currentY += 8; - } - - renderTextBlock(turnInLines, currentY, textAlign, 0xAAAAAA); - - GL11.glPopMatrix(); - } - - private int renderTextBlock(List lines, int startY, int align, int color) { - int y = startY; - FontRenderer font = mc.fontRenderer; - for (String line : lines) { - int strWidth = font.getStringWidth(line); - int xOffset; - if (align == 1) - xOffset = (overlayWidth - strWidth) / 2; - else if (align == 2) - xOffset = overlayWidth - strWidth - 5; - else - xOffset = 5; - font.drawStringWithShadow(line, xOffset, y, color); - y += font.FONT_HEIGHT + 4; - } - return y; - } - - private void drawDecorativeLine(int y) { - int lineStart = 5; - int lineEnd = overlayWidth - 5; - drawHorizontalLine(lineStart, lineEnd, y, 0xFF777777); - drawHorizontalLine(lineStart, lineEnd, y + 1, 0xFFA8A8A8); - drawHorizontalLine(lineStart, lineEnd, y + 2, 0xFFFFFFFF); - } - - private ArrayList splitLines(String text, int maxWidth) { - ArrayList lines = new ArrayList<>(); - String[] words = text.split(" "); - StringBuilder current = new StringBuilder(); - FontRenderer font = mc.fontRenderer; - for (String word : words) { - String test = current.length() == 0 ? word : current.toString() + " " + word; - if (font.getStringWidth(test) > maxWidth) { - if (current.length() > 0) { - lines.add(current.toString()); - current = new StringBuilder(word); - } else { - lines.add(word); - } - } else { - if (current.length() > 0) - current.append(" ").append(word); - else - current.append(word); - } - } - if (current.length() > 0) - lines.add(current.toString()); - return lines; - } - - private String convertColorCodes(String text) { - return text.replaceAll("&([0-9a-fk-or])", "§$1"); - } -} diff --git a/src/main/java/noppes/npcs/client/gui/hud/QuestTrackingComponent.java b/src/main/java/noppes/npcs/client/gui/hud/QuestTrackingComponent.java new file mode 100644 index 000000000..5236c0c19 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/hud/QuestTrackingComponent.java @@ -0,0 +1,278 @@ +package noppes.npcs.client.gui.hud; + +import net.minecraft.client.Minecraft; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.gui.GuiButton; +import noppes.npcs.config.ConfigClient; +import org.lwjgl.opengl.GL11; +import noppes.npcs.controllers.data.Quest; +import java.util.ArrayList; +import java.util.List; + +public class QuestTrackingComponent extends HudComponent { + private Minecraft mc; + private ArrayList questTitleLines = new ArrayList<>(); + private ArrayList questCategoryLines = new ArrayList<>(); + private ArrayList objectiveLines = new ArrayList<>(); + private ArrayList turnInLines = new ArrayList<>(); + + public QuestTrackingComponent(Minecraft mc) { + this.mc = mc; + load(); + } + + /** + * Sets quest data similar to the original OverlayQuestTracking. + */ + public void setQuestData(Quest quest, String category, List objectives, String turnIn) { + questTitleLines = splitLines(convertColorCodes(quest.getName()), overlayWidth - 10); + questCategoryLines = splitLines(convertColorCodes(category), overlayWidth - 10); + objectiveLines.clear(); + for (String obj : objectives) { + objectiveLines.add(convertColorCodes(obj)); + } + turnInLines.clear(); + if (turnIn != null && !turnIn.isEmpty()) { + turnInLines.add(convertColorCodes(turnIn)); + } + } + + /** + * Loads overlay data from an NBT compound. + */ + public void setOverlayData(NBTTagCompound compound) { + Quest quest = new Quest(); + quest.readNBT(compound.getCompoundTag("Quest")); + String category = compound.getString("CategoryName"); + + ArrayList objectives = new ArrayList<>(); + NBTTagList objectiveList = compound.getTagList("ObjectiveList", 8); + for (int i = 0; i < objectiveList.tagCount(); i++) { + String objective = objectiveList.getStringTagAt(i); + // Process objective if needed. + objectives.add(objective); + } + String turnIn = ""; + boolean instantComplete = compound.getBoolean("Instant"); + if (instantComplete) { + turnIn = "Completed automatically"; + } else { + String npcName = compound.getString("TurnInNPC"); + if (!npcName.isEmpty()) { + turnIn = "Complete with " + npcName; + } + } + setQuestData(quest, category, objectives, turnIn); + hasData = true; + } + + @Override + public void loadData(NBTTagCompound compound) { + setOverlayData(compound); + } + + @Override + public void load() { + posX = ConfigClient.QuestOverlayX; + posY = ConfigClient.QuestOverlayY; + scale = ConfigClient.QuestOverlayScale; + textAlign = ConfigClient.QuestOverlayTextAlign; + } + + @Override + public void save() { + ConfigClient.QuestOverlayX = posX; + ConfigClient.QuestOverlayXProperty.set(ConfigClient.QuestOverlayX); + + ConfigClient.QuestOverlayY = posY; + ConfigClient.QuestOverlayYProperty.set(ConfigClient.QuestOverlayY); + + ConfigClient.QuestOverlayScale = scale; + ConfigClient.QuestOverlayScaleProperty.set(ConfigClient.QuestOverlayScale); + + ConfigClient.QuestOverlayTextAlign = textAlign; + ConfigClient.QuestOverlayTextAlignProperty.set(ConfigClient.QuestOverlayTextAlign); + + if (ConfigClient.config.hasChanged()) { + ConfigClient.config.save(); + } + } + + @Override + public void renderOnScreen(float partialTicks) { + if (!hasData || isEditting) + return; + + ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + int actualX = (int)((float) posX / 100F * res.getScaledWidth()); + int actualY = (int)((float) posY / 100F * res.getScaledHeight()); + // Use base scaling: effective scale = scale/100.0F + float s = (scale / 100.0F); + + GL11.glPushMatrix(); + GL11.glTranslatef(actualX, actualY, 0); + GL11.glScalef(s, s, s); + + // Draw background (semi-transparent). + drawRect(0, 0, overlayWidth, overlayHeight, 0x40FFFFFF); + + int currentY = 5; + currentY = renderTextBlock(questTitleLines, currentY, textAlign, 0xFFFFFF); + drawDecorativeLine(currentY - 1); + currentY += 8; + + currentY = renderTextBlock(questCategoryLines, currentY, textAlign, 0xCCCCCC); + drawDecorativeLine(currentY - 1); + currentY += 8; + + currentY = renderTextBlock(objectiveLines, currentY, textAlign, 0xAAAAAA); + if (!turnInLines.isEmpty()) { + drawDecorativeLine(currentY - 1); + currentY += 8; + } + renderTextBlock(turnInLines, currentY, textAlign, 0xAAAAAA); + + GL11.glPopMatrix(); + } + + @Override + public void renderEditing() { + isEditting = true; + ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + int actualX = (int)((float) posX / 100F * res.getScaledWidth()); + int actualY = (int)((float) posY / 100F * res.getScaledHeight()); + float s = (scale / 100.0F); + + GL11.glPushMatrix(); + GL11.glTranslatef(actualX, actualY, 0); + GL11.glScalef(s, s, s); + + // Draw editing background, border, and resize handle. + drawRect(0, 0, overlayWidth, overlayHeight, 0x40FFFFFF); + drawRectOutline(0, 0, overlayWidth, overlayHeight, 0xFFAAAAAA); + drawRect(overlayWidth - 10, overlayHeight - 10, overlayWidth, overlayHeight, 0xFFCCCCCC); + + int currentY = 5; + currentY = renderDemoTextBlock(new String[] { "Dummy Quest Title" }, currentY, textAlign, 0xFFFFFF); + drawDecorativeLine(currentY - 1); + currentY += 8; + currentY = renderDemoTextBlock(new String[] { "Dummy Category" }, currentY, textAlign, 0xCCCCCC); + drawDecorativeLine(currentY - 1); + currentY += 8; + currentY = renderDemoTextBlock(new String[] { "Objective: Kill 10 mobs", "Objective: Collect 5 items" }, currentY, textAlign, 0xAAAAAA); + drawDecorativeLine(currentY - 1); + currentY += 8; + renderDemoTextBlock(new String[] { "Turn in with NPC" }, currentY, textAlign, 0xAAAAAA); + + GL11.glPopMatrix(); + } + + @Override + public void addEditorButtons(List buttonList) { + // Add buttons similar to the original editor: ID 1 for alignment, ID 3 for reset. + buttonList.add(new GuiButton(1, 100, Minecraft.getMinecraft().displayHeight - 70, 120, 20, getAlignText())); + buttonList.add(new GuiButton(3, 100, Minecraft.getMinecraft().displayHeight - 95, 120, 20, "Reset to Center")); + } + + @Override + public void onEditorButtonPressed(GuiButton button) { + if (button.id == 1) { // Cycle alignment. + textAlign = (textAlign + 1) % 3; + button.displayString = getAlignText(); + } else if (button.id == 3) { // Reset to center. + posX = 50; + posY = 50; + } + } + + private String getAlignText() { + switch (textAlign) { + case 0: return "Align: Left"; + case 1: return "Align: Center"; + case 2: return "Align: Right"; + default: return "Align: Unknown"; + } + } + + // ---------- Helper rendering methods ----------- + private int renderTextBlock(List lines, int startY, int align, int color) { + int y = startY; + FontRenderer font = mc.fontRenderer; + for (String line : lines) { + int strWidth = font.getStringWidth(line); + int xOffset = (align == 1) ? (overlayWidth - strWidth) / 2 + : (align == 2) ? overlayWidth - strWidth - 5 : 5; + font.drawStringWithShadow(line, xOffset, y, color); + y += font.FONT_HEIGHT + 4; + } + return y; + } + + private int renderDemoTextBlock(String[] lines, int startY, int align, int color) { + int y = startY; + FontRenderer font = mc.fontRenderer; + for (String line : lines) { + int strWidth = font.getStringWidth(line); + int xOffset = (align == 1) ? (overlayWidth - strWidth) / 2 + : (align == 2) ? overlayWidth - strWidth - 5 : 5; + font.drawStringWithShadow(line, xOffset, y, color); + y += font.FONT_HEIGHT + 4; + } + return y; + } + + private void drawDecorativeLine(int y) { + drawHorizontalLine(5, overlayWidth - 5, y, 0xFF777777); + drawHorizontalLine(5, overlayWidth - 5, y + 1, 0xFFA8A8A8); + drawHorizontalLine(5, overlayWidth - 5, y + 2, 0xFFFFFFFF); + } + + // Simple wrappers for drawing. + private void drawRect(int left, int top, int right, int bottom, int color) { + net.minecraft.client.gui.Gui.drawRect(left, top, right, bottom, color); + } + + private void drawHorizontalLine(int left, int right, int y, int color) { + net.minecraft.client.gui.Gui.drawRect(left, y, right, y + 1, color); + } + + private void drawRectOutline(int left, int top, int right, int bottom, int color) { + drawHorizontalLine(left, right, top, color); + drawHorizontalLine(left, right, bottom - 1, color); + net.minecraft.client.gui.Gui.drawRect(left, top, left + 1, bottom, color); + net.minecraft.client.gui.Gui.drawRect(right - 1, top, right, bottom, color); + } + + private String convertColorCodes(String text) { + return text.replaceAll("&([0-9a-fk-or])", "§$1"); + } + + private ArrayList splitLines(String text, int maxWidth) { + ArrayList lines = new ArrayList<>(); + String[] words = text.split(" "); + StringBuilder current = new StringBuilder(); + FontRenderer font = mc.fontRenderer; + for (String word : words) { + String test = current.length() == 0 ? word : current.toString() + " " + word; + if (font.getStringWidth(test) > maxWidth) { + if (current.length() > 0) { + lines.add(current.toString()); + current = new StringBuilder(word); + } else { + lines.add(word); + } + } else { + if (current.length() > 0) + current.append(" ").append(word); + else + current.append(word); + } + } + if (current.length() > 0) + lines.add(current.toString()); + return lines; + } +} diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java index 2cf7d1d09..4451ecb18 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java @@ -8,7 +8,7 @@ import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import noppes.npcs.client.ClientCacheHandler; -import noppes.npcs.client.gui.hud.GuiOverlayQuestEditor; +import noppes.npcs.client.gui.hud.GuiHudEditor; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; import noppes.npcs.client.gui.util.GuiNpcTextField; @@ -167,7 +167,7 @@ public class GuiSettings extends GuiCNPCInventory implements ITextfieldListener, ConfigClient.HideEffectsBarProperty.set(ConfigClient.HideEffectsBar); } if(button.id == 90){ - mc.displayGuiScreen(new GuiOverlayQuestEditor(this)); + mc.displayGuiScreen(new GuiHudEditor(this)); } ConfigClient.config.save(); From 7135f1ad27fd991fd1a69fa265602d4b35a1acc0 Mon Sep 17 00:00:00 2001 From: Kam Date: Sun, 23 Feb 2025 05:58:56 -0500 Subject: [PATCH 43/59] Compass --- .../npcs/client/ClientEventHandler.java | 2 + .../client/gui/hud/CompassHudComponent.java | 214 ++++++++++++++++++ .../npcs/client/gui/hud/EnumHudComponent.java | 3 +- .../npcs/client/gui/hud/HudComponent.java | 3 +- .../gui/player/inventory/GuiSettings.java | 38 +--- .../java/noppes/npcs/config/ConfigClient.java | 103 +++++---- 6 files changed, 281 insertions(+), 82 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/hud/CompassHudComponent.java diff --git a/src/main/java/noppes/npcs/client/ClientEventHandler.java b/src/main/java/noppes/npcs/client/ClientEventHandler.java index 6d5bfedd8..b82e19e32 100644 --- a/src/main/java/noppes/npcs/client/ClientEventHandler.java +++ b/src/main/java/noppes/npcs/client/ClientEventHandler.java @@ -17,6 +17,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.*; import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.gui.hud.ClientHudManager; +import noppes.npcs.client.gui.hud.CompassHudComponent; import noppes.npcs.client.gui.hud.EnumHudComponent; import noppes.npcs.client.gui.hud.QuestTrackingComponent; import noppes.npcs.client.renderer.MarkRenderer; @@ -95,6 +96,7 @@ public class ClientEventHandler { if(ClientHudManager.getInstance().getHudComponents().isEmpty()){ ClientHudManager.getInstance().registerHud(EnumHudComponent.QuestTracker, new QuestTrackingComponent(Minecraft.getMinecraft())); + ClientHudManager.getInstance().registerHud(EnumHudComponent.QuestCompass, new CompassHudComponent(Minecraft.getMinecraft())); } ClientHudManager.getInstance().renderAllHUDs(event.partialTicks); diff --git a/src/main/java/noppes/npcs/client/gui/hud/CompassHudComponent.java b/src/main/java/noppes/npcs/client/gui/hud/CompassHudComponent.java new file mode 100644 index 000000000..87ab0532e --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/hud/CompassHudComponent.java @@ -0,0 +1,214 @@ +package noppes.npcs.client.gui.hud; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.MathHelper; +import noppes.npcs.config.ConfigClient; +import org.lwjgl.opengl.GL11; +import java.util.ArrayList; +import java.util.List; + +public class CompassHudComponent extends HudComponent { + private final Minecraft mc; + private final List targets = new ArrayList<>(); + private final int BAR_HEIGHT = 20; + private final int BASE_ICON_SIZE = 8; + private final int MAX_ICON_SIZE = 16; + private final int SCALE_DISTANCE_MIN = 10; + private final int SCALE_DISTANCE_MAX = 40; + private static final int HANDLE_SIZE = 10; + + public static class TargetEntry { + public int x, z; + public int color; + + public TargetEntry(int x, int z, int color) { + this.x = x; + this.z = z; + this.color = color; + } + } + + public CompassHudComponent(Minecraft minecraft) { + mc = minecraft; + overlayWidth = 200; + overlayHeight = BAR_HEIGHT; + load(); + } + + @Override + public void loadData(NBTTagCompound compound) { + targets.clear(); + NBTTagList list = compound.getTagList("Targets", 10); + for(int i = 0; i < list.tagCount(); i++) { + NBTTagCompound entry = list.getCompoundTagAt(i); + targets.add(new TargetEntry( + entry.getInteger("x"), + entry.getInteger("z"), + entry.getInteger("color") + )); + } + hasData = !targets.isEmpty(); + } + + @Override + public void load() { + posX = ConfigClient.CompassOverlayX; + posY = ConfigClient.CompassOverlayY; + scale = ConfigClient.CompassOverlayScale; + overlayWidth = ConfigClient.CompassOverlayWidth; + } + + @Override + public void save() { + // Save to config + ConfigClient.CompassOverlayX = posX; + ConfigClient.CompassOverlayY = posY; + ConfigClient.CompassOverlayScale = scale; + ConfigClient.CompassOverlayWidth = overlayWidth; + ConfigClient.config.save(); + } + + @Override + public void renderOnScreen(float partialTicks) { + if (!hasData || isEditting) return; + + ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + int actualX = (int)((float) posX / 100F * res.getScaledWidth()); + int actualY = (int)((float) posY / 100F * res.getScaledHeight()); + float scaleFactor = scale / 100.0F; + + GL11.glPushMatrix(); + GL11.glTranslatef(actualX, actualY, 0); + GL11.glScalef(scaleFactor, scaleFactor, scaleFactor); + + // Draw background bar + drawRect(0, 0, overlayWidth, BAR_HEIGHT, 0x80000000); + + // Render all targets + for(TargetEntry target : targets) { + renderTargetIcon(target); + } + + GL11.glPopMatrix(); + } + + private void renderTargetIcon(TargetEntry target) { + if (mc.thePlayer == null) return; + + // Calculate position on bar + float iconPos = calculateIconPosition(target.x, target.z); + int barWidth = overlayWidth; + + // Calculate dynamic size + float distance = (float) Math.sqrt( + Math.pow(target.x - mc.thePlayer.posX, 2) + + Math.pow(target.z - mc.thePlayer.posZ, 2) + ); + + int iconSize = calculateIconSize(distance); + int iconX = MathHelper.clamp_int((int)iconPos, iconSize/2, barWidth - iconSize/2); + + // Calculate vertical position + int iconY = (BAR_HEIGHT - iconSize)/2; + + // Draw icon + drawRect(iconX - iconSize/2, iconY, + iconX + iconSize/2, iconY + iconSize, target.color); + } + + private float calculateIconPosition(double targetX, double targetZ) { + double dx = targetX - mc.thePlayer.posX; + double dz = targetZ - mc.thePlayer.posZ; + + double angle = Math.toDegrees(Math.atan2(dz, dx)) - 90; + angle = (angle + 360) % 360; + + double playerYaw = (mc.thePlayer.rotationYaw % 360 + 360) % 360; + double relativeAngle = (angle - playerYaw + 360) % 360; + + return (float)(relativeAngle / 360.0 * overlayWidth); + } + + private int calculateIconSize(float distance) { + if(distance <= SCALE_DISTANCE_MIN) return MAX_ICON_SIZE; + if(distance >= SCALE_DISTANCE_MAX) return BASE_ICON_SIZE; + + float t = (distance - SCALE_DISTANCE_MIN) / + (SCALE_DISTANCE_MAX - SCALE_DISTANCE_MIN); + return (int)(MAX_ICON_SIZE - (MAX_ICON_SIZE - BASE_ICON_SIZE) * t); + } + + @Override + public void renderEditing() { + isEditting = true; + ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + int actualX = (int)((float) posX / 100F * res.getScaledWidth()); + int actualY = (int)((float) posY / 100F * res.getScaledHeight()); + float scaleFactor = scale / 100.0F; + + GL11.glPushMatrix(); + GL11.glTranslatef(actualX, actualY, 0); + GL11.glScalef(scaleFactor, scaleFactor, scaleFactor); + + // Draw editor background and handles + drawRect(0, 0, overlayWidth, overlayHeight, 0x80000000); + drawRectOutline(0, 0, overlayWidth, overlayHeight, 0xFF00FF00); + + // Add resize handle (bottom-right corner) + drawRect(overlayWidth - HANDLE_SIZE, overlayHeight - HANDLE_SIZE, + overlayWidth, overlayHeight, 0xFFCCCCCC); + + // Demo targets + renderDemoIcon(overlayWidth * 0.25f, 0xFF0000FF); + renderDemoIcon(overlayWidth * 0.75f, 0xFF00FF00); + + GL11.glPopMatrix(); + } + + private void renderDemoIcon(float position, int color) { + // Animate size + float pulse = (System.currentTimeMillis() % 1000) / 1000f; + int size = (int)(BASE_ICON_SIZE + (MAX_ICON_SIZE - BASE_ICON_SIZE) * pulse); + + int iconX = (int)position - size/2; + int iconY = (BAR_HEIGHT - size)/2; + drawRect(iconX, iconY, iconX + size, iconY + size, color); + } + + // Management methods + public void addTarget(int x, int z, int color) { + targets.add(new TargetEntry(x, z, color)); + hasData = true; + } + + public void removeTarget(int index) { + if(index >= 0 && index < targets.size()) { + targets.remove(index); + hasData = !targets.isEmpty(); + } + } + + public void clearTargets() { + targets.clear(); + hasData = false; + } + + // Helper drawing methods (same as in QuestTrackingComponent) + private void drawRect(int left, int top, int right, int bottom, int color) { + net.minecraft.client.gui.Gui.drawRect(left, top, right, bottom, color); + } + + private void drawRectOutline(int left, int top, int right, int bottom, int color) { + drawHorizontalLine(left, right, top, color); + drawHorizontalLine(left, right, bottom - 1, color); + net.minecraft.client.gui.Gui.drawRect(left, top, left + 1, bottom, color); + net.minecraft.client.gui.Gui.drawRect(right - 1, top, right, bottom, color); + } + + private void drawHorizontalLine(int left, int right, int y, int color) { + net.minecraft.client.gui.Gui.drawRect(left, y, right, y + 1, color); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/hud/EnumHudComponent.java b/src/main/java/noppes/npcs/client/gui/hud/EnumHudComponent.java index c1ac41239..fe6eb07b6 100644 --- a/src/main/java/noppes/npcs/client/gui/hud/EnumHudComponent.java +++ b/src/main/java/noppes/npcs/client/gui/hud/EnumHudComponent.java @@ -1,5 +1,6 @@ package noppes.npcs.client.gui.hud; public enum EnumHudComponent { - QuestTracker + QuestTracker, + QuestCompass } diff --git a/src/main/java/noppes/npcs/client/gui/hud/HudComponent.java b/src/main/java/noppes/npcs/client/gui/hud/HudComponent.java index b004ecfa1..955a8e66d 100644 --- a/src/main/java/noppes/npcs/client/gui/hud/HudComponent.java +++ b/src/main/java/noppes/npcs/client/gui/hud/HudComponent.java @@ -11,8 +11,7 @@ public abstract class HudComponent { public boolean enabled = true; public boolean hasData = false; public boolean isEditting = false; - - protected final int overlayWidth = 200, overlayHeight = 120; + public int overlayWidth = 200, overlayHeight = 120; /** * Loads custom HUD data from an NBT compound. diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java index 4451ecb18..5ad6c4882 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiSettings.java @@ -39,17 +39,14 @@ public class GuiSettings extends GuiCNPCInventory implements ITextfieldListener, this.addLabel(new GuiNpcLabel(1, "settings.chatBubbles", guiLeft + 8, guiTop + 14 + y)); this.addButton(new GuiNpcButton(1, guiLeft + 105, guiTop + 9 + y, 50, 20, new String[]{"gui.no", "gui.yes"}, ConfigClient.EnableChatBubbles?1:0)); - this.addLabel(new GuiNpcLabel(3, "settings.trackAlignment", guiLeft + 8 + 155, guiTop + 14 + y)); - this.addButton(new GuiNpcButton(3, guiLeft + 105 + 160, guiTop + 9 + y, 50, 20, new String[]{"TLeft", "TCenter", "TRight", "Left", "Center", "Right", "BLeft", "BCenter", "BRight"}, ConfigClient.TrackingInfoAlignment)); - y += 22; this.addLabel(new GuiNpcLabel(2, "settings.dialogSound", guiLeft + 8, guiTop + 14 + y)); this.addButton(new GuiNpcButton(2, guiLeft + 105, guiTop + 9 + y, 50, 20, new String[]{"gui.no", "gui.yes"}, ConfigClient.DialogSound?1:0)); - this.addLabel(new GuiNpcLabel(12,"settings.alignmentX", guiLeft + 8 + 155, guiTop + 14 + y)); - this.addTextField(new GuiNpcTextField(12, this, this.fontRendererObj, guiLeft + 107 + 160, guiTop + 9 + y, 45, 20, ConfigClient.TrackingInfoX + "")); - getTextField(12).integersOnly = true; - getTextField(12).setMinMaxDefault(-2000, 2000, 0); +// this.addLabel(new GuiNpcLabel(12,"settings.alignmentX", guiLeft + 8 + 155, guiTop + 14 + y)); +// this.addTextField(new GuiNpcTextField(12, this, this.fontRendererObj, guiLeft + 107 + 160, guiTop + 9 + y, 45, 20, ConfigClient.TrackingInfoX + "")); +// getTextField(12).integersOnly = true; +// getTextField(12).setMinMaxDefault(-2000, 2000, 0); y += 22; this.addLabel(new GuiNpcLabel(10,"settings.dialogSpeed", guiLeft + 8, guiTop + 14 + y)); @@ -57,21 +54,12 @@ public class GuiSettings extends GuiCNPCInventory implements ITextfieldListener, getTextField(10).integersOnly = true; getTextField(10).setMinMaxDefault(1, 20, 10); - this.addLabel(new GuiNpcLabel(13,"settings.alignmentY", guiLeft + 8 + 155, guiTop + 14 + y)); - this.addTextField(new GuiNpcTextField(13, this, this.fontRendererObj, guiLeft + 107 + 160, guiTop + 9 + y, 45, 20, ConfigClient.TrackingInfoY + "")); - getTextField(13).integersOnly = true; - getTextField(13).setMinMaxDefault(-2000, 2000, 0); y += 22; this.addLabel(new GuiNpcLabel(6, "settings.chatAlerts", guiLeft + 8, guiTop + 14 + y)); this.addButton(new GuiNpcButton(6, guiLeft + 105, guiTop + 9 + y, 50, 20, new String[]{"gui.no", "gui.yes"}, ConfigClient.ChatAlerts?1:0)); - this.addLabel(new GuiNpcLabel(14,"settings.trackScale", guiLeft + 8 + 155, guiTop + 14 + y)); - this.addTextField(new GuiNpcTextField(14, this, this.fontRendererObj, guiLeft + 107 + 160, guiTop + 9 + y, 45, 20, ConfigClient.TrackingScale + "")); - getTextField(14).integersOnly = true; - getTextField(14).setMinMaxDefault(0, 300, 100); - y += 22; this.addLabel(new GuiNpcLabel(7, "settings.bannerAlerts", guiLeft + 8, guiTop + 14 + y)); @@ -142,10 +130,6 @@ public class GuiSettings extends GuiCNPCInventory implements ITextfieldListener, ConfigClient.DialogSound = button.getValue() == 1; ConfigClient.DialogSoundProperty.set(ConfigClient.DialogSound); } - if(button.id == 3){ - ConfigClient.TrackingInfoAlignment = button.getValue(); - ConfigClient.TrackingInfoAlignmentProperty.set(ConfigClient.TrackingInfoAlignment); - } if(button.id == 4){ GuiYesNo yesNoTrack = new GuiYesNo(this, "Confirm", StatCollector.translateToLocal("settings.confirmClearTrack"), 0); displayGuiScreen(yesNoTrack); @@ -194,19 +178,5 @@ public class GuiSettings extends GuiCNPCInventory implements ITextfieldListener, ConfigClient.DialogSpeed = textfield.getInteger(); ConfigClient.DialogSpeedProperty.set(ConfigClient.DialogSound); } - - // Quest Tracking - if(textfield.id == 12){ - ConfigClient.TrackingInfoX = textfield.getInteger(); - ConfigClient.TrackingInfoXProperty.set(ConfigClient.TrackingInfoX); - } - if(textfield.id == 13){ - ConfigClient.TrackingInfoY = textfield.getInteger(); - ConfigClient.TrackingInfoYProperty.set(ConfigClient.TrackingInfoY); - } - if(textfield.id == 14){ - ConfigClient.TrackingScale = textfield.getInteger(); - ConfigClient.TrackingScaleProperty.set(ConfigClient.TrackingScale); - } } } diff --git a/src/main/java/noppes/npcs/config/ConfigClient.java b/src/main/java/noppes/npcs/config/ConfigClient.java index 6a36160d7..7b0a0f641 100644 --- a/src/main/java/noppes/npcs/config/ConfigClient.java +++ b/src/main/java/noppes/npcs/config/ConfigClient.java @@ -18,6 +18,7 @@ public class ConfigClient public final static String QUESTING = "Questing"; public final static String MODEL = "Model"; public final static String TEXTURE = "Texture"; + public final static String HUD = "Hud"; /** @@ -53,18 +54,6 @@ public class ConfigClient /** * Questing Properties **/ - public static Property TrackingInfoAlignmentProperty; - public static int TrackingInfoAlignment = 3; - - public static Property TrackingInfoXProperty; - public static int TrackingInfoX = 0; - - public static Property TrackingInfoYProperty; - public static int TrackingInfoY = 0; - - public static Property TrackingScaleProperty; - public static int TrackingScale = 100; - public static Property DialogSpeedProperty; public static int DialogSpeed = 10; @@ -77,7 +66,7 @@ public class ConfigClient public static Property BannerAlertsProperty; public static boolean BannerAlerts = true; - // New Quest Overlay configuration properties + // HUD PROPERTIES public static Property QuestOverlayXProperty; public static int QuestOverlayX = 100; @@ -90,6 +79,16 @@ public class ConfigClient public static Property QuestOverlayTextAlignProperty; public static int QuestOverlayTextAlign = 1; // 0: Left, 1: Center, 2: Right + public static Property CompassOverlayXProperty; + public static Property CompassOverlayYProperty; + public static Property CompassOverlayScaleProperty; + public static Property CompassOverlayWidthProperty; + + public static int CompassOverlayX; + public static int CompassOverlayY; + public static int CompassOverlayScale; + public static int CompassOverlayWidth; + /** * Texture Properties @@ -121,19 +120,60 @@ public class ConfigClient { config.load(); - // Load new Quest Overlay settings - QuestOverlayXProperty = config.get(QUESTING, "QuestOverlayX", 100, "X position of the quest overlay."); + // Hud Quest Overlay settings + QuestOverlayXProperty = config.get(HUD, "Quest Hud X", 100, "X position of the quest overlay."); QuestOverlayX = QuestOverlayXProperty.getInt(100); - QuestOverlayYProperty = config.get(QUESTING, "QuestOverlayY", 100, "Y position of the quest overlay."); + QuestOverlayYProperty = config.get(HUD, "Quest Hud Y", 100, "Y position of the quest overlay."); QuestOverlayY = QuestOverlayYProperty.getInt(100); - QuestOverlayScaleProperty = config.get(QUESTING, "QuestOverlayScale", 100, "Scale percentage of the quest overlay."); + QuestOverlayScaleProperty = config.get(HUD, "Quest Hud Scale", 100, "Scale percentage of the quest overlay."); QuestOverlayScale = QuestOverlayScaleProperty.getInt(100); - QuestOverlayTextAlignProperty = config.get(QUESTING, "QuestOverlayTextAlign", 1, "Text alignment in quest overlay (0: Left, 1: Center, 2: Right)."); + QuestOverlayTextAlignProperty = config.get(HUD, "Quest Hud Text Alignment", 1, "Text alignment in quest overlay (0: Left, 1: Center, 2: Right)."); QuestOverlayTextAlign = QuestOverlayTextAlignProperty.getInt(1); + // Compass HUD Configs + CompassOverlayXProperty = config.get( + HUD, + "Compass Hud X", + 50, + "Horizontal position of compass overlay (0-100 percentage)", + 0, + 100 + ); + CompassOverlayX = CompassOverlayXProperty.getInt(); + + CompassOverlayYProperty = config.get( + HUD, + "Compass Hud Y", + 5, + "Vertical position of compass overlay (0-100 percentage)", + 0, + 100 + ); + CompassOverlayY = CompassOverlayYProperty.getInt(); + + CompassOverlayScaleProperty = config.get( + HUD, + "Compass Hud Scale", + 100, + "Scale percentage of compass overlay", + 50, + 300 + ); + CompassOverlayScale = CompassOverlayScaleProperty.getInt(); + + CompassOverlayWidthProperty = config.get( + HUD, + "Compass Hud Width", + 200, + "Base width of compass bar in pixels", + 100, + 1000 + ); + CompassOverlayWidth = CompassOverlayWidthProperty.getInt(); + // General CacheLifeProperty = config.get(GENERAL, "Cache Life", 10, "How long should downloaded imagery data be saved client side? (In minutes)"); @@ -161,19 +201,6 @@ public class ConfigClient HideEffectsBarProperty = config.get(VISUAL, "Hide Effects Bar", false, "Hides CNPC+ Inventory Effects Bar"); HideEffectsBar = HideEffectsBarProperty.getBoolean(false); - // Questing - TrackingInfoAlignmentProperty = config.get(QUESTING, "Tracking Info Alignment", 3, "Client sided! Determines where tracking quest info shows up on the screen based on a number from 0 to 8. Default: 3"); - TrackingInfoAlignment = TrackingInfoAlignmentProperty.getInt(3); - - TrackingInfoXProperty = config.get(QUESTING, "Tracking Info X", 0, "Client sided! Offsets the tracking info GUI by this amount in the X direction."); - TrackingInfoX = TrackingInfoXProperty.getInt(0); - - TrackingInfoYProperty = config.get(QUESTING, "Tracking Info Y", 0, "Client sided! Offsets the tracking info GUI by this amount in the Y direction."); - TrackingInfoY = TrackingInfoYProperty.getInt(0); - - TrackingScaleProperty = config.get(QUESTING, "Tracking Scale", 100, "Client sided! Adjusts the scaling of the Quest Tracking"); - TrackingScale = TrackingScaleProperty.getInt(100); - DialogSpeedProperty = config.get(VISUAL, "Dialog Speed", true, "Only set for gradual dialogs"); DialogSpeed = DialogSpeedProperty.getInt(10); @@ -215,21 +242,7 @@ public class ConfigClient FontSize = LegacyConfig.FontSize; FontSizeProperty.set(FontSize); - - TrackingInfoAlignment = LegacyConfig.TrackingInfoAlignment; - TrackingInfoAlignmentProperty.set(TrackingInfoAlignment); - - TrackingInfoX = LegacyConfig.TrackingInfoX; - TrackingInfoXProperty.set(TrackingInfoX); - - TrackingInfoY = LegacyConfig.TrackingInfoY; - TrackingInfoYProperty.set(TrackingInfoY); } - - if (TrackingInfoAlignment < 0) - TrackingInfoAlignment = 0; - if (TrackingInfoAlignment > 8) - TrackingInfoAlignment = 8; } catch (Exception e) { From 84b07f4f6fae190f06f9947c8eda2138243a98e1 Mon Sep 17 00:00:00 2001 From: Kam Date: Sun, 23 Feb 2025 06:29:53 -0500 Subject: [PATCH 44/59] Compass in Progress --- .../noppes/npcs/client/ClientTickHandler.java | 57 +++++++ .../client/gui/hud/CompassHudComponent.java | 155 +++++++++++------- 2 files changed, 153 insertions(+), 59 deletions(-) diff --git a/src/main/java/noppes/npcs/client/ClientTickHandler.java b/src/main/java/noppes/npcs/client/ClientTickHandler.java index 33e979c89..e66bf90e6 100644 --- a/src/main/java/noppes/npcs/client/ClientTickHandler.java +++ b/src/main/java/noppes/npcs/client/ClientTickHandler.java @@ -11,17 +11,27 @@ import kamkeel.npcs.network.packets.player.InputDevicePacket; import kamkeel.npcs.network.packets.player.ScreenSizePacket; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ContainerPlayer; import net.minecraft.world.World; import noppes.npcs.CustomNpcs; import noppes.npcs.client.controllers.MusicController; import noppes.npcs.client.controllers.ScriptSoundController; +import noppes.npcs.client.gui.hud.ClientHudManager; +import noppes.npcs.client.gui.hud.CompassHudComponent; +import noppes.npcs.client.gui.hud.EnumHudComponent; +import noppes.npcs.client.gui.hud.HudComponent; import noppes.npcs.client.gui.player.inventory.GuiCNPCInventory; import noppes.npcs.client.renderer.RenderNPCInterface; +import noppes.npcs.constants.MarkType; +import noppes.npcs.controllers.data.MarkData; +import noppes.npcs.entity.EntityNPCInterface; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import tconstruct.client.tabs.InventoryTabCustomNpc; +import java.util.ArrayList; + import static noppes.npcs.client.ClientEventHandler.renderCNPCPlayer; public class ClientTickHandler{ @@ -77,6 +87,13 @@ public class ClientTickHandler{ prevHeight = mc.displayHeight; PacketClient.sendClient(new ScreenSizePacket(mc.displayWidth,mc.displayHeight)); } + + if(mc.theWorld == null) + return; + + if(mc.theWorld.getTotalWorldTime() % 20 == 0) { // Update every second + updateCompassMarks(); + } } @SubscribeEvent @@ -119,4 +136,44 @@ public class ClientTickHandler{ return false; } + + private final int SCAN_RANGE = 128; + private void updateCompassMarks() { + Minecraft mc = Minecraft.getMinecraft(); + EntityPlayer player = mc.thePlayer; + ArrayList marks = new ArrayList<>(); + + // Scan entities in loaded chunks + for(Object entity : mc.theWorld.loadedEntityList) { + if(entity instanceof EntityNPCInterface) { + EntityNPCInterface npc = (EntityNPCInterface) entity; + + // Check distance + if(player.getDistanceToEntity(npc) > SCAN_RANGE) + continue; + + // Get marks + MarkData markData = MarkData.get(npc); + for(MarkData.Mark mark : markData.marks) { + if(mark.getType() != MarkType.NONE && + mark.availability.isAvailable(player)) { + marks.add(new CompassHudComponent.MarkTargetEntry( + (int)npc.posX, + (int)npc.posZ, + mark.getType(), + mark.color + )); + break; // Only show first valid mark per NPC + } + } + } + } + + // Update compass + HudComponent compass = ClientHudManager.getInstance() + .getHudComponents().get(EnumHudComponent.QuestCompass); + if(compass != null) { + ((CompassHudComponent) compass).updateMarkTargets(marks); + } + } } diff --git a/src/main/java/noppes/npcs/client/gui/hud/CompassHudComponent.java b/src/main/java/noppes/npcs/client/gui/hud/CompassHudComponent.java index 87ab0532e..67d1e50d3 100644 --- a/src/main/java/noppes/npcs/client/gui/hud/CompassHudComponent.java +++ b/src/main/java/noppes/npcs/client/gui/hud/CompassHudComponent.java @@ -2,31 +2,37 @@ package noppes.npcs.client.gui.hud; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.Tessellator; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; import noppes.npcs.config.ConfigClient; +import noppes.npcs.constants.MarkType; import org.lwjgl.opengl.GL11; import java.util.ArrayList; import java.util.List; public class CompassHudComponent extends HudComponent { private final Minecraft mc; - private final List targets = new ArrayList<>(); + private final List markTargets = new ArrayList<>(); private final int BAR_HEIGHT = 20; private final int BASE_ICON_SIZE = 8; private final int MAX_ICON_SIZE = 16; private final int SCALE_DISTANCE_MIN = 10; private final int SCALE_DISTANCE_MAX = 40; private static final int HANDLE_SIZE = 10; + private final int SCAN_RANGE = 128; - public static class TargetEntry { + public static class MarkTargetEntry { public int x, z; + public int type; public int color; - public TargetEntry(int x, int z, int color) { + public MarkTargetEntry(int x, int z, int type, int color) { this.x = x; this.z = z; + this.type = type; this.color = color; } } @@ -40,17 +46,18 @@ public class CompassHudComponent extends HudComponent { @Override public void loadData(NBTTagCompound compound) { - targets.clear(); - NBTTagList list = compound.getTagList("Targets", 10); + markTargets.clear(); + NBTTagList list = compound.getTagList("MarkTargets", 10); for(int i = 0; i < list.tagCount(); i++) { NBTTagCompound entry = list.getCompoundTagAt(i); - targets.add(new TargetEntry( + markTargets.add(new MarkTargetEntry( entry.getInteger("x"), entry.getInteger("z"), + entry.getInteger("type"), entry.getInteger("color") )); } - hasData = !targets.isEmpty(); + hasData = !markTargets.isEmpty(); } @Override @@ -63,7 +70,6 @@ public class CompassHudComponent extends HudComponent { @Override public void save() { - // Save to config ConfigClient.CompassOverlayX = posX; ConfigClient.CompassOverlayY = posY; ConfigClient.CompassOverlayScale = scale; @@ -73,7 +79,7 @@ public class CompassHudComponent extends HudComponent { @Override public void renderOnScreen(float partialTicks) { - if (!hasData || isEditting) return; +// if (!hasData || isEditting) return; ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); int actualX = (int)((float) posX / 100F * res.getScaledWidth()); @@ -87,49 +93,92 @@ public class CompassHudComponent extends HudComponent { // Draw background bar drawRect(0, 0, overlayWidth, BAR_HEIGHT, 0x80000000); - // Render all targets - for(TargetEntry target : targets) { - renderTargetIcon(target); + // Render all marks + for(MarkTargetEntry mark : markTargets) { + renderMarkIcon(mark); } GL11.glPopMatrix(); } - private void renderTargetIcon(TargetEntry target) { + private void renderMarkIcon(MarkTargetEntry mark) { if (mc.thePlayer == null) return; - // Calculate position on bar - float iconPos = calculateIconPosition(target.x, target.z); - int barWidth = overlayWidth; + Float iconPos = calculateIconPosition(mark.x, mark.z); + if(iconPos == null) { + // Target is behind the player; don't render. + return; + } - // Calculate dynamic size + int barWidth = overlayWidth; float distance = (float) Math.sqrt( - Math.pow(target.x - mc.thePlayer.posX, 2) + - Math.pow(target.z - mc.thePlayer.posZ, 2) + Math.pow(mark.x - mc.thePlayer.posX, 2) + + Math.pow(mark.z - mc.thePlayer.posZ, 2) ); int iconSize = calculateIconSize(distance); - int iconX = MathHelper.clamp_int((int)iconPos, iconSize/2, barWidth - iconSize/2); - - // Calculate vertical position + int iconX = MathHelper.clamp_int((int)iconPos.floatValue(), iconSize/2, barWidth - iconSize/2); int iconY = (BAR_HEIGHT - iconSize)/2; - // Draw icon - drawRect(iconX - iconSize/2, iconY, - iconX + iconSize/2, iconY + iconSize, target.color); + ResourceLocation texture = getTextureForMark(mark.type); + if(texture != null) { + renderTextureIcon(iconX - iconSize/2, iconY, iconSize, texture, mark.color); + } } - private float calculateIconPosition(double targetX, double targetZ) { + private ResourceLocation getTextureForMark(int type) { + switch(type) { + case MarkType.EXCLAMATION: return new ResourceLocation("customnpcs", "textures/marks/exclamation.png"); + case MarkType.QUESTION: return new ResourceLocation("customnpcs", "textures/marks/question.png"); + case MarkType.POINTER: return new ResourceLocation("customnpcs", "textures/marks/pointer.png"); + case MarkType.CROSS: return new ResourceLocation("customnpcs", "textures/marks/cross.png"); + case MarkType.SKULL: return new ResourceLocation("customnpcs", "textures/marks/skull.png"); + case MarkType.STAR: return new ResourceLocation("customnpcs", "textures/marks/star.png"); + default: return null; + } + } + + private void renderTextureIcon(int x, int y, int size, ResourceLocation texture, int color) { + float red = (color >> 16 & 255) / 255.0F; + float green = (color >> 8 & 255) / 255.0F; + float blue = (color & 255) / 255.0F; + + GL11.glPushMatrix(); + GL11.glColor4f(red, green, blue, 1); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + mc.getTextureManager().bindTexture(texture); + + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV(x, y + size, 0, 0, 1); + tessellator.addVertexWithUV(x + size, y + size, 0, 1, 1); + tessellator.addVertexWithUV(x + size, y, 0, 1, 0); + tessellator.addVertexWithUV(x, y, 0, 0, 0); + tessellator.draw(); + + GL11.glColor4f(1, 1, 1, 1); + GL11.glDisable(GL11.GL_BLEND); + GL11.glPopMatrix(); + } + + private Float calculateIconPosition(double targetX, double targetZ) { double dx = targetX - mc.thePlayer.posX; double dz = targetZ - mc.thePlayer.posZ; + double angleToTarget = Math.toDegrees(Math.atan2(dz, dx)); + double adjustedPlayerYaw = mc.thePlayer.rotationYaw + 90; + double relativeAngle = angleToTarget - adjustedPlayerYaw; + while(relativeAngle < -180) relativeAngle += 360; + while(relativeAngle > 180) relativeAngle -= 360; - double angle = Math.toDegrees(Math.atan2(dz, dx)) - 90; - angle = (angle + 360) % 360; + // Only render if the target is within 90° to either side (180° front) + if (Math.abs(relativeAngle) > 90) { + return null; + } - double playerYaw = (mc.thePlayer.rotationYaw % 360 + 360) % 360; - double relativeAngle = (angle - playerYaw + 360) % 360; - - return (float)(relativeAngle / 360.0 * overlayWidth); + // Map -90..90 to 0..overlayWidth so that 0 becomes the left edge and 90 the right edge. + return (float)(overlayWidth / 2.0 + (relativeAngle / 90.0) * (overlayWidth / 2.0)); } private int calculateIconSize(float distance) { @@ -153,50 +202,38 @@ public class CompassHudComponent extends HudComponent { GL11.glTranslatef(actualX, actualY, 0); GL11.glScalef(scaleFactor, scaleFactor, scaleFactor); - // Draw editor background and handles drawRect(0, 0, overlayWidth, overlayHeight, 0x80000000); drawRectOutline(0, 0, overlayWidth, overlayHeight, 0xFF00FF00); - - // Add resize handle (bottom-right corner) drawRect(overlayWidth - HANDLE_SIZE, overlayHeight - HANDLE_SIZE, overlayWidth, overlayHeight, 0xFFCCCCCC); - // Demo targets - renderDemoIcon(overlayWidth * 0.25f, 0xFF0000FF); - renderDemoIcon(overlayWidth * 0.75f, 0xFF00FF00); + // Demo marks + renderDemoIcon(overlayWidth * 0.25f, MarkType.EXCLAMATION, 0xFF00FF00); + renderDemoIcon(overlayWidth * 0.75f, MarkType.QUESTION, 0xFFFF0000); GL11.glPopMatrix(); } - private void renderDemoIcon(float position, int color) { - // Animate size + private void renderDemoIcon(float position, int type, int color) { float pulse = (System.currentTimeMillis() % 1000) / 1000f; int size = (int)(BASE_ICON_SIZE + (MAX_ICON_SIZE - BASE_ICON_SIZE) * pulse); + ResourceLocation texture = getTextureForMark(type); - int iconX = (int)position - size/2; - int iconY = (BAR_HEIGHT - size)/2; - drawRect(iconX, iconY, iconX + size, iconY + size, color); - } - - // Management methods - public void addTarget(int x, int z, int color) { - targets.add(new TargetEntry(x, z, color)); - hasData = true; - } - - public void removeTarget(int index) { - if(index >= 0 && index < targets.size()) { - targets.remove(index); - hasData = !targets.isEmpty(); + if(texture != null) { + GL11.glPushMatrix(); + GL11.glTranslatef(position - size/2, (BAR_HEIGHT - size)/2, 0); + renderTextureIcon(0, 0, size, texture, color); + GL11.glPopMatrix(); } } - public void clearTargets() { - targets.clear(); - hasData = false; + public void updateMarkTargets(List newMarks) { + markTargets.clear(); + markTargets.addAll(newMarks); + hasData = !markTargets.isEmpty(); } - // Helper drawing methods (same as in QuestTrackingComponent) + // Helper drawing methods private void drawRect(int left, int top, int right, int bottom, int color) { net.minecraft.client.gui.Gui.drawRect(left, top, right, bottom, color); } From 3e23893e7856c563de3634ae5cad4d1132198b89 Mon Sep 17 00:00:00 2001 From: Kam Date: Sun, 23 Feb 2025 15:38:42 -0500 Subject: [PATCH 45/59] Fix Effective Scaling --- .../noppes/npcs/client/ClientTickHandler.java | 18 ++- .../client/gui/hud/CompassHudComponent.java | 37 ++++-- .../npcs/client/gui/hud/GuiHudEditor.java | 110 ++++++++++++++---- .../npcs/client/gui/hud/HudComponent.java | 22 +++- .../gui/hud/QuestTrackingComponent.java | 28 ++--- 5 files changed, 162 insertions(+), 53 deletions(-) diff --git a/src/main/java/noppes/npcs/client/ClientTickHandler.java b/src/main/java/noppes/npcs/client/ClientTickHandler.java index e66bf90e6..65e06bf6b 100644 --- a/src/main/java/noppes/npcs/client/ClientTickHandler.java +++ b/src/main/java/noppes/npcs/client/ClientTickHandler.java @@ -141,6 +141,14 @@ public class ClientTickHandler{ private void updateCompassMarks() { Minecraft mc = Minecraft.getMinecraft(); EntityPlayer player = mc.thePlayer; + + // Update compass + HudComponent compass = ClientHudManager.getInstance() + .getHudComponents().get(EnumHudComponent.QuestCompass); + + if(!compass.enabled || mc.thePlayer == null) + return; + ArrayList marks = new ArrayList<>(); // Scan entities in loaded chunks @@ -148,6 +156,9 @@ public class ClientTickHandler{ if(entity instanceof EntityNPCInterface) { EntityNPCInterface npc = (EntityNPCInterface) entity; + if(npc.dimension != player.dimension) + continue; + // Check distance if(player.getDistanceToEntity(npc) > SCAN_RANGE) continue; @@ -169,11 +180,6 @@ public class ClientTickHandler{ } } - // Update compass - HudComponent compass = ClientHudManager.getInstance() - .getHudComponents().get(EnumHudComponent.QuestCompass); - if(compass != null) { - ((CompassHudComponent) compass).updateMarkTargets(marks); - } + ((CompassHudComponent) compass).updateMarkTargets(marks); } } diff --git a/src/main/java/noppes/npcs/client/gui/hud/CompassHudComponent.java b/src/main/java/noppes/npcs/client/gui/hud/CompassHudComponent.java index 67d1e50d3..b2cc71fb2 100644 --- a/src/main/java/noppes/npcs/client/gui/hud/CompassHudComponent.java +++ b/src/main/java/noppes/npcs/client/gui/hud/CompassHudComponent.java @@ -22,8 +22,12 @@ public class CompassHudComponent extends HudComponent { private final int SCALE_DISTANCE_MIN = 10; private final int SCALE_DISTANCE_MAX = 40; private static final int HANDLE_SIZE = 10; + private static final int WIDTH_BAR_SIZE = 6; // Width adjust bar width private final int SCAN_RANGE = 128; + // Flag to indicate if the width bar is being dragged in editing mode. + public boolean resizingWidth = false; + public static class MarkTargetEntry { public int x, z; public int type; @@ -79,16 +83,17 @@ public class CompassHudComponent extends HudComponent { @Override public void renderOnScreen(float partialTicks) { -// if (!hasData || isEditting) return; + // If no mark data or in edit mode, skip normal rendering. + if (!hasData || isEditting) return; ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); - int actualX = (int)((float) posX / 100F * res.getScaledWidth()); - int actualY = (int)((float) posY / 100F * res.getScaledHeight()); - float scaleFactor = scale / 100.0F; + int actualX = (int)(posX / 100F * res.getScaledWidth()); + int actualY = (int)(posY / 100F * res.getScaledHeight()); + float effectiveScale = getEffectiveScale(res); GL11.glPushMatrix(); GL11.glTranslatef(actualX, actualY, 0); - GL11.glScalef(scaleFactor, scaleFactor, scaleFactor); + GL11.glScalef(effectiveScale, effectiveScale, effectiveScale); // Draw background bar drawRect(0, 0, overlayWidth, BAR_HEIGHT, 0x80000000); @@ -194,20 +199,27 @@ public class CompassHudComponent extends HudComponent { public void renderEditing() { isEditting = true; ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); - int actualX = (int)((float) posX / 100F * res.getScaledWidth()); - int actualY = (int)((float) posY / 100F * res.getScaledHeight()); - float scaleFactor = scale / 100.0F; + int actualX = (int)(posX / 100F * res.getScaledWidth()); + int actualY = (int)(posY / 100F * res.getScaledHeight()); + float effectiveScale = getEffectiveScale(res); GL11.glPushMatrix(); GL11.glTranslatef(actualX, actualY, 0); - GL11.glScalef(scaleFactor, scaleFactor, scaleFactor); + GL11.glScalef(effectiveScale, effectiveScale, effectiveScale); + // Draw background bar and border. drawRect(0, 0, overlayWidth, overlayHeight, 0x80000000); drawRectOutline(0, 0, overlayWidth, overlayHeight, 0xFF00FF00); + // Resize handle (bottom-right for scale) drawRect(overlayWidth - HANDLE_SIZE, overlayHeight - HANDLE_SIZE, overlayWidth, overlayHeight, 0xFFCCCCCC); + // Width adjust bar on right side (centered vertically) + int margin = 5; + int barX = overlayWidth + margin; + int barY = (overlayHeight - BAR_HEIGHT) / 2; + drawRect(barX, barY, barX + WIDTH_BAR_SIZE, barY + BAR_HEIGHT, 0xFF888888); - // Demo marks + // Demo marks for preview. renderDemoIcon(overlayWidth * 0.25f, MarkType.EXCLAMATION, 0xFF00FF00); renderDemoIcon(overlayWidth * 0.75f, MarkType.QUESTION, 0xFFFF0000); @@ -227,6 +239,11 @@ public class CompassHudComponent extends HudComponent { } } + /** + * Updates the mark targets directly. + * (This method assumes external code (CNPC+ mark data) supplies the new marks + * without having to loop through all loaded entities.) + */ public void updateMarkTargets(List newMarks) { markTargets.clear(); markTargets.addAll(newMarks); diff --git a/src/main/java/noppes/npcs/client/gui/hud/GuiHudEditor.java b/src/main/java/noppes/npcs/client/gui/hud/GuiHudEditor.java index f7752f0e8..35c2899c0 100644 --- a/src/main/java/noppes/npcs/client/gui/hud/GuiHudEditor.java +++ b/src/main/java/noppes/npcs/client/gui/hud/GuiHudEditor.java @@ -1,9 +1,9 @@ package noppes.npcs.client.gui.hud; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import java.util.List; @@ -16,12 +16,18 @@ public class GuiHudEditor extends GuiScreen { private int dragOffsetX, dragOffsetY; private boolean dragging = false; private boolean resizing = false; + // For general scaling resize. private int initialScale, initialMouseX, initialMouseY; + // For Compass width adjustment. + private boolean resizingWidth = false; + private int initialOverlayWidth, initialWidthMouseX; + private final int HANDLE_SIZE = 10; private final int RESET_POSITION_ID = 100; public GuiHudEditor(GuiScreen parent) { this.parent = parent; + // For example, default to QuestTracker if available. selectedComponent = ClientHudManager.getInstance().getHudComponents().get(EnumHudComponent.QuestTracker); } @@ -37,6 +43,7 @@ public class GuiHudEditor extends GuiScreen { * Updates the custom buttons shown on screen. * Removes all buttons except the global Save button (id 0) * then adds the selected component's custom buttons plus a Reset Position button. + * Buttons are now arranged in two columns. */ private void updateCustomButtons() { // Remove any buttons that are not the global Save (id 0) @@ -47,19 +54,41 @@ public class GuiHudEditor extends GuiScreen { } } if (selectedComponent != null) { - int baseX = width / 2 - 60; - int baseY = height - 70; // Start above the Save button. List customButtons = new ArrayList<>(); selectedComponent.addEditorButtons(customButtons); - int offsetY = 0; - for (GuiButton btn : customButtons) { - btn.xPosition = baseX; - btn.yPosition = baseY - offsetY; - offsetY += btn.height + 5; - buttonList.add(btn); + // Arrange buttons in 2 columns. + int spacingX = 10; + int spacingY = 5; + int buttonWidth = 120; // assuming uniform width + int startXLeft = width / 2 - buttonWidth - spacingX/2; + int startXRight = width / 2 + spacingX/2; + int rowHeight = 0; + int numButtons = customButtons.size(); + for (int i = 0; i < numButtons; i += 2) { + // If two buttons in this row. + if (i + 1 < numButtons) { + GuiButton btnLeft = customButtons.get(i); + GuiButton btnRight = customButtons.get(i+1); + btnLeft.xPosition = startXLeft; + btnRight.xPosition = startXRight; + // Determine row y based on button height. + int rowY = height - 70 - rowHeight; + btnLeft.yPosition = rowY; + btnRight.yPosition = rowY; + rowHeight += btnLeft.height + spacingY; + buttonList.add(btnLeft); + buttonList.add(btnRight); + } else { + // One button: center it. + GuiButton btn = customButtons.get(i); + btn.xPosition = width / 2 - buttonWidth / 2; + btn.yPosition = height - 70 - rowHeight; + buttonList.add(btn); + rowHeight += btn.height + spacingY; + } } - // Always add the Reset Position button. - GuiButton resetPos = new GuiButton(RESET_POSITION_ID, baseX, baseY - offsetY, 120, 20, "Reset Position"); + // Always add the Reset Position button below the custom buttons. + GuiButton resetPos = new GuiButton(RESET_POSITION_ID, width / 2 - buttonWidth / 2, height - 70 - rowHeight, buttonWidth, 20, "Reset Position"); buttonList.add(resetPos); } } @@ -77,12 +106,40 @@ public class GuiHudEditor extends GuiScreen { @Override protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { // Iterate over HUD components to check for selection. + // First, check for Compass width adjust hitbox if the mouse is near a CompassHudComponent. + for (HudComponent hud : ClientHudManager.getInstance().getHudComponents().values()) { + if (!(hud instanceof CompassHudComponent)) + continue; + + ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + float effectiveScale = hud.getEffectiveScale(res); + int actualX = (int)(hud.posX / 100F * res.getScaledWidth()); + int actualY = (int)(hud.posY / 100F * res.getScaledHeight()); + + // Even if the mouse is outside the hud bounds, we want to check for the floating adjust bar. + int margin = 5; + int barWidth = 6; // same as WIDTH_BAR_SIZE + // The adjust bar is drawn to the right of the component. + int barX = actualX + (int)(hud.overlayWidth * effectiveScale) + margin; + int barY = actualY + (int)(((hud.overlayHeight - 20) / 2.0F) * effectiveScale); // 20 = BAR_HEIGHT + int barHeight = (int)(20 * effectiveScale); + if (mouseX >= barX && mouseX <= barX + barWidth && + mouseY >= barY && mouseY <= barY + barHeight) { + resizingWidth = true; + selectedComponent = hud; + initialOverlayWidth = hud.overlayWidth; + initialWidthMouseX = mouseX; + updateCustomButtons(); + return; + } + } + + // Next, proceed with the normal hit detection for dragging/resizing of the HUD components. for (HudComponent hud : ClientHudManager.getInstance().getHudComponents().values()) { ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); - // Use base scaling (scale/100.0F) - float effectiveScale = (hud.scale / 100.0F); - int actualX = (int)((float)hud.posX / 100F * res.getScaledWidth()); - int actualY = (int)((float)hud.posY / 100F * res.getScaledHeight()); + float effectiveScale = hud.getEffectiveScale(res); + int actualX = (int)(hud.posX / 100F * res.getScaledWidth()); + int actualY = (int)(hud.posY / 100F * res.getScaledHeight()); int absWidth = (int)(hud.overlayWidth * effectiveScale); int absHeight = (int)(hud.overlayHeight * effectiveScale); if (mouseX >= actualX && mouseX <= actualX + absWidth && @@ -94,14 +151,16 @@ public class GuiHudEditor extends GuiScreen { initialScale = hud.scale; initialMouseX = mouseX; initialMouseY = mouseY; + updateCustomButtons(); + return; } else { dragging = true; selectedComponent = hud; dragOffsetX = mouseX - actualX; dragOffsetY = mouseY - actualY; + updateCustomButtons(); + return; } - updateCustomButtons(); - break; } } super.mouseClicked(mouseX, mouseY, mouseButton); @@ -111,7 +170,7 @@ public class GuiHudEditor extends GuiScreen { protected void mouseMovedOrUp(int mouseX, int mouseY, int state) { dragging = false; resizing = false; - // Optionally keep selectedComponent so its buttons remain visible. + resizingWidth = false; super.mouseMovedOrUp(mouseX, mouseY, state); } @@ -121,7 +180,7 @@ public class GuiHudEditor extends GuiScreen { ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); int scaledWidth = res.getScaledWidth(); int scaledHeight = res.getScaledHeight(); - float effectiveScale = (selectedComponent.scale / 100.0F); + float effectiveScale = selectedComponent.getEffectiveScale(res); if (dragging) { int newX = Mouse.getX() * width / mc.displayWidth - dragOffsetX; int newY = scaledHeight - (Mouse.getY() * scaledHeight / mc.displayHeight) - dragOffsetY; @@ -141,6 +200,13 @@ public class GuiHudEditor extends GuiScreen { if (selectedComponent.scale < 50) selectedComponent.scale = 50; if (selectedComponent.scale > 300) selectedComponent.scale = 300; } + if (resizingWidth && (selectedComponent instanceof CompassHudComponent)) { + int currentMouseX = Mouse.getX() * width / mc.displayWidth; + int delta = currentMouseX - initialWidthMouseX; + selectedComponent.overlayWidth = initialOverlayWidth + delta; + if (selectedComponent.overlayWidth < 50) selectedComponent.overlayWidth = 50; + if (selectedComponent.overlayWidth > 500) selectedComponent.overlayWidth = 500; + } } super.updateScreen(); } @@ -164,6 +230,8 @@ public class GuiHudEditor extends GuiScreen { } } } + + @Override protected void keyTyped(char typedChar, int keyCode) { if (keyCode == 1) { close(); diff --git a/src/main/java/noppes/npcs/client/gui/hud/HudComponent.java b/src/main/java/noppes/npcs/client/gui/hud/HudComponent.java index 955a8e66d..48bfece66 100644 --- a/src/main/java/noppes/npcs/client/gui/hud/HudComponent.java +++ b/src/main/java/noppes/npcs/client/gui/hud/HudComponent.java @@ -1,7 +1,8 @@ package noppes.npcs.client.gui.hud; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.nbt.NBTTagCompound; import java.util.List; public abstract class HudComponent { @@ -40,15 +41,30 @@ public abstract class HudComponent { /** * Allows the component to add its own editor buttons. + * The default implementation adds a toggle button for enabling/disabling the component. */ public void addEditorButtons(List buttonList) { - // Default: do nothing. + // Toggle enabled/disabled button (id 999 reserved for toggle) + String label = enabled ? "Enabled" : "Disabled"; + buttonList.add(new GuiButton(999, 0, 0, 120, 20, label)); } /** * Handles editor button actions specific to this HUD component. + * The default implementation toggles the enabled state if button id is 999. */ public void onEditorButtonPressed(GuiButton button) { - // Default: do nothing. + if(button.id == 999){ + enabled = !enabled; + button.displayString = enabled ? "Enabled" : "Disabled"; + } + } + + /** + * Computes the effective scale factor for rendering and hitbox calculations. + * Uses the current resolution (with 1920 as the base width). + */ + public float getEffectiveScale(ScaledResolution res) { + return (scale / 100.0F) * (res.getScaledWidth() / 1920.0F); } } diff --git a/src/main/java/noppes/npcs/client/gui/hud/QuestTrackingComponent.java b/src/main/java/noppes/npcs/client/gui/hud/QuestTrackingComponent.java index 5236c0c19..20ffe5595 100644 --- a/src/main/java/noppes/npcs/client/gui/hud/QuestTrackingComponent.java +++ b/src/main/java/noppes/npcs/client/gui/hud/QuestTrackingComponent.java @@ -52,7 +52,6 @@ public class QuestTrackingComponent extends HudComponent { NBTTagList objectiveList = compound.getTagList("ObjectiveList", 8); for (int i = 0; i < objectiveList.tagCount(); i++) { String objective = objectiveList.getStringTagAt(i); - // Process objective if needed. objectives.add(objective); } String turnIn = ""; @@ -107,14 +106,13 @@ public class QuestTrackingComponent extends HudComponent { return; ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); - int actualX = (int)((float) posX / 100F * res.getScaledWidth()); - int actualY = (int)((float) posY / 100F * res.getScaledHeight()); - // Use base scaling: effective scale = scale/100.0F - float s = (scale / 100.0F); + int actualX = (int)(posX / 100F * res.getScaledWidth()); + int actualY = (int)(posY / 100F * res.getScaledHeight()); + float effectiveScale = getEffectiveScale(res); GL11.glPushMatrix(); GL11.glTranslatef(actualX, actualY, 0); - GL11.glScalef(s, s, s); + GL11.glScalef(effectiveScale, effectiveScale, effectiveScale); // Draw background (semi-transparent). drawRect(0, 0, overlayWidth, overlayHeight, 0x40FFFFFF); @@ -142,13 +140,13 @@ public class QuestTrackingComponent extends HudComponent { public void renderEditing() { isEditting = true; ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); - int actualX = (int)((float) posX / 100F * res.getScaledWidth()); - int actualY = (int)((float) posY / 100F * res.getScaledHeight()); - float s = (scale / 100.0F); + int actualX = (int)(posX / 100F * res.getScaledWidth()); + int actualY = (int)(posY / 100F * res.getScaledHeight()); + float effectiveScale = getEffectiveScale(res); GL11.glPushMatrix(); GL11.glTranslatef(actualX, actualY, 0); - GL11.glScalef(s, s, s); + GL11.glScalef(effectiveScale, effectiveScale, effectiveScale); // Draw editing background, border, and resize handle. drawRect(0, 0, overlayWidth, overlayHeight, 0x40FFFFFF); @@ -172,9 +170,11 @@ public class QuestTrackingComponent extends HudComponent { @Override public void addEditorButtons(List buttonList) { - // Add buttons similar to the original editor: ID 1 for alignment, ID 3 for reset. - buttonList.add(new GuiButton(1, 100, Minecraft.getMinecraft().displayHeight - 70, 120, 20, getAlignText())); - buttonList.add(new GuiButton(3, 100, Minecraft.getMinecraft().displayHeight - 95, 120, 20, "Reset to Center")); + // First add the default toggle button. + super.addEditorButtons(buttonList); + // Then add other custom buttons. + buttonList.add(new GuiButton(1, 100, 0, 120, 20, getAlignText())); + buttonList.add(new GuiButton(3, 100, 0, 120, 20, "Reset to Center")); } @Override @@ -185,6 +185,8 @@ public class QuestTrackingComponent extends HudComponent { } else if (button.id == 3) { // Reset to center. posX = 50; posY = 50; + } else { + super.onEditorButtonPressed(button); } } From 2640a6c7e0dbc3117196e0e3eb535d27e06d08fc Mon Sep 17 00:00:00 2001 From: Kam Date: Sun, 23 Feb 2025 15:50:45 -0500 Subject: [PATCH 46/59] Hud Component Modifications --- .../client/gui/hud/CompassHudComponent.java | 15 ++++++++++- .../java/noppes/npcs/config/ConfigClient.java | 27 +++++++++++++------ .../noppes/npcs/config/LoadConfiguration.java | 2 ++ 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/hud/CompassHudComponent.java b/src/main/java/noppes/npcs/client/gui/hud/CompassHudComponent.java index b2cc71fb2..f29bd9d18 100644 --- a/src/main/java/noppes/npcs/client/gui/hud/CompassHudComponent.java +++ b/src/main/java/noppes/npcs/client/gui/hud/CompassHudComponent.java @@ -66,6 +66,7 @@ public class CompassHudComponent extends HudComponent { @Override public void load() { + enabled = ConfigClient.CompassEnabled; posX = ConfigClient.CompassOverlayX; posY = ConfigClient.CompassOverlayY; scale = ConfigClient.CompassOverlayScale; @@ -74,11 +75,23 @@ public class CompassHudComponent extends HudComponent { @Override public void save() { + ConfigClient.CompassEnabled = enabled; + ConfigClient.CompassEnabledProperty.set(ConfigClient.CompassEnabled); + ConfigClient.CompassOverlayX = posX; + ConfigClient.CompassOverlayXProperty.set(ConfigClient.CompassOverlayX); + ConfigClient.CompassOverlayY = posY; + ConfigClient.CompassOverlayYProperty.set(ConfigClient.CompassOverlayY); + ConfigClient.CompassOverlayScale = scale; + ConfigClient.CompassOverlayScaleProperty.set(ConfigClient.CompassOverlayScale); + ConfigClient.CompassOverlayWidth = overlayWidth; - ConfigClient.config.save(); + ConfigClient.CompassOverlayWidthProperty.set(ConfigClient.CompassOverlayWidth); + + if(ConfigClient.config.hasChanged()) + ConfigClient.config.save(); } @Override diff --git a/src/main/java/noppes/npcs/config/ConfigClient.java b/src/main/java/noppes/npcs/config/ConfigClient.java index 7b0a0f641..96fc12067 100644 --- a/src/main/java/noppes/npcs/config/ConfigClient.java +++ b/src/main/java/noppes/npcs/config/ConfigClient.java @@ -15,7 +15,6 @@ public class ConfigClient public final static String GENERAL = "General"; public final static String VISUAL = "Visual"; - public final static String QUESTING = "Questing"; public final static String MODEL = "Model"; public final static String TEXTURE = "Texture"; public final static String HUD = "Hud"; @@ -79,16 +78,20 @@ public class ConfigClient public static Property QuestOverlayTextAlignProperty; public static int QuestOverlayTextAlign = 1; // 0: Left, 1: Center, 2: Right + public static Property CompassEnabledProperty; + public static boolean CompassEnabled; + public static Property CompassOverlayXProperty; - public static Property CompassOverlayYProperty; - public static Property CompassOverlayScaleProperty; - public static Property CompassOverlayWidthProperty; - public static int CompassOverlayX; - public static int CompassOverlayY; - public static int CompassOverlayScale; - public static int CompassOverlayWidth; + public static Property CompassOverlayYProperty; + public static int CompassOverlayY; + + public static Property CompassOverlayScaleProperty; + public static int CompassOverlayScale; + + public static Property CompassOverlayWidthProperty; + public static int CompassOverlayWidth; /** * Texture Properties @@ -133,6 +136,14 @@ public class ConfigClient QuestOverlayTextAlignProperty = config.get(HUD, "Quest Hud Text Alignment", 1, "Text alignment in quest overlay (0: Left, 1: Center, 2: Right)."); QuestOverlayTextAlign = QuestOverlayTextAlignProperty.getInt(1); + CompassEnabledProperty = config.get( + HUD, + "Compass Hud Enabled", + true, + "Enable Compass Hud Component" + ); + CompassEnabled = CompassEnabledProperty.getBoolean(); + // Compass HUD Configs CompassOverlayXProperty = config.get( HUD, diff --git a/src/main/java/noppes/npcs/config/LoadConfiguration.java b/src/main/java/noppes/npcs/config/LoadConfiguration.java index f415674b7..43152620b 100644 --- a/src/main/java/noppes/npcs/config/LoadConfiguration.java +++ b/src/main/java/noppes/npcs/config/LoadConfiguration.java @@ -1,5 +1,7 @@ package noppes.npcs.config; +import net.minecraftforge.common.config.Property; + import java.io.File; public class LoadConfiguration { From 3bd3a125b6be1650d841fee9b1e1f7ce8b3a9398 Mon Sep 17 00:00:00 2001 From: Kam Date: Sun, 23 Feb 2025 15:51:35 -0500 Subject: [PATCH 47/59] Dont Print Magics or Register them yet --- .../npcs/controllers/MagicController.java | 414 +++++++++--------- 1 file changed, 207 insertions(+), 207 deletions(-) diff --git a/src/main/java/noppes/npcs/controllers/MagicController.java b/src/main/java/noppes/npcs/controllers/MagicController.java index c92465252..881c58e44 100644 --- a/src/main/java/noppes/npcs/controllers/MagicController.java +++ b/src/main/java/noppes/npcs/controllers/MagicController.java @@ -57,213 +57,213 @@ public class MagicController { } catch (Exception ee) { } } magics.clear(); - if (false) { - // Create default Pokémon types - Magic normal = new Magic(0, "Normal", 0xA8A878); - normal.setIconItem(new ItemStack(net.minecraft.init.Items.paper)); // using paper for Normal - - Magic fire = new Magic(1, "Fire", 0xF08030); - fire.setIconItem(new ItemStack(net.minecraft.init.Items.flint)); // flint for Fire - - Magic water = new Magic(2, "Water", 0x6890F0); - water.setIconItem(new ItemStack(net.minecraft.init.Items.water_bucket)); // water bucket - - Magic electric = new Magic(3, "Electric", 0xF8D030); - electric.setIconItem(new ItemStack(net.minecraft.init.Items.redstone)); // redstone - - Magic grass = new Magic(4, "Grass", 0x78C850); - grass.setIconItem(new ItemStack(net.minecraft.init.Items.wheat_seeds)); // wheat seeds - - Magic ice = new Magic(5, "Ice", 0x98D8D8); - ice.setIconItem(new ItemStack(net.minecraft.init.Items.snowball)); // snowball for Ice - - Magic fighting = new Magic(6, "Fighting", 0xC03028); - fighting.setIconItem(new ItemStack(net.minecraft.init.Items.iron_sword)); // sword for Fighting - - Magic poison = new Magic(7, "Poison", 0xA040A0); - poison.setIconItem(new ItemStack(net.minecraft.init.Items.potionitem)); // potion item for Poison - - Magic ground = new Magic(8, "Ground", 0xE0C068); - ground.setIconItem(new ItemStack(Blocks.dirt)); // dirt for Ground - - Magic flying = new Magic(9, "Flying", 0xA890F0); - flying.setIconItem(new ItemStack(net.minecraft.init.Items.feather)); // feather for Flying - - Magic psychic = new Magic(10, "Psychic", 0xF85888); - psychic.setIconItem(new ItemStack(net.minecraft.init.Items.ender_pearl)); // ender pearl for Psychic - - Magic bug = new Magic(11, "Bug", 0xA8B820); - bug.setIconItem(new ItemStack(net.minecraft.init.Items.spider_eye)); // spider eye for Bug - - Magic rock = new Magic(12, "Rock", 0xB8A038); - rock.setIconItem(new ItemStack(Blocks.cobblestone)); // cobblestone for Rock - - Magic ghost = new Magic(13, "Ghost", 0x705898); - ghost.setIconItem(new ItemStack(net.minecraft.init.Items.skull)); // skull for Ghost - - Magic dragon = new Magic(14, "Dragon", 0x7038F8); - dragon.setIconItem(new ItemStack(Blocks.dragon_egg)); // dragon egg - - Magic dark = new Magic(15, "Dark", 0x705848); - dark.setIconItem(new ItemStack(net.minecraft.init.Items.coal)); // coal for Dark - - Magic steel = new Magic(16, "Steel", 0xB8B8D0); - steel.setIconItem(new ItemStack(net.minecraft.init.Items.iron_ingot)); // iron ingot for Steel - - Magic fairy = new Magic(17, "Fairy", 0xEE99AC); - fairy.setIconItem(new ItemStack(net.minecraft.init.Items.sugar)); // sugar for Fairy - - // Now set weaknesses (using a multiplier of 2.0f to indicate “double damage”). - // The following is based on a common Pokémon type chart. - normal.weaknesses.put(fighting.id, 2.0f); - - fire.weaknesses.put(water.id, 2.0f); - fire.weaknesses.put(ground.id, 2.0f); - fire.weaknesses.put(rock.id, 2.0f); - - water.weaknesses.put(electric.id, 2.0f); - water.weaknesses.put(grass.id, 2.0f); - - electric.weaknesses.put(ground.id, 2.0f); - - grass.weaknesses.put(fire.id, 2.0f); - grass.weaknesses.put(ice.id, 2.0f); - grass.weaknesses.put(poison.id, 2.0f); - grass.weaknesses.put(flying.id, 2.0f); - grass.weaknesses.put(bug.id, 2.0f); - - ice.weaknesses.put(fire.id, 2.0f); - ice.weaknesses.put(fighting.id, 2.0f); - ice.weaknesses.put(rock.id, 2.0f); - ice.weaknesses.put(steel.id, 2.0f); - - fighting.weaknesses.put(flying.id, 2.0f); - fighting.weaknesses.put(psychic.id, 2.0f); - fighting.weaknesses.put(fairy.id, 2.0f); - - poison.weaknesses.put(ground.id, 2.0f); - poison.weaknesses.put(psychic.id, 2.0f); - - ground.weaknesses.put(water.id, 2.0f); - ground.weaknesses.put(grass.id, 2.0f); - ground.weaknesses.put(ice.id, 2.0f); - - flying.weaknesses.put(electric.id, 2.0f); - flying.weaknesses.put(ice.id, 2.0f); - flying.weaknesses.put(rock.id, 2.0f); - - psychic.weaknesses.put(bug.id, 2.0f); - psychic.weaknesses.put(ghost.id, 2.0f); - psychic.weaknesses.put(dark.id, 2.0f); - - bug.weaknesses.put(fire.id, 2.0f); - bug.weaknesses.put(flying.id, 2.0f); - bug.weaknesses.put(rock.id, 2.0f); - - rock.weaknesses.put(water.id, 2.0f); - rock.weaknesses.put(grass.id, 2.0f); - rock.weaknesses.put(fighting.id, 2.0f); - rock.weaknesses.put(ground.id, 2.0f); - rock.weaknesses.put(steel.id, 2.0f); - - ghost.weaknesses.put(ghost.id, 2.0f); - ghost.weaknesses.put(dark.id, 2.0f); - - dragon.weaknesses.put(ice.id, 2.0f); - dragon.weaknesses.put(dragon.id, 2.0f); - dragon.weaknesses.put(fairy.id, 2.0f); - - dark.weaknesses.put(fighting.id, 2.0f); - dark.weaknesses.put(bug.id, 2.0f); - dark.weaknesses.put(fairy.id, 2.0f); - - steel.weaknesses.put(fire.id, 2.0f); - steel.weaknesses.put(fighting.id, 2.0f); - steel.weaknesses.put(ground.id, 2.0f); - - fairy.weaknesses.put(poison.id, 2.0f); - fairy.weaknesses.put(steel.id, 2.0f); - - // Register the types. - magics.put(normal.id, normal); - magics.put(fire.id, fire); - magics.put(water.id, water); - magics.put(electric.id, electric); - magics.put(grass.id, grass); - magics.put(ice.id, ice); - magics.put(fighting.id, fighting); - magics.put(poison.id, poison); - magics.put(ground.id, ground); - magics.put(flying.id, flying); - magics.put(psychic.id, psychic); - magics.put(bug.id, bug); - magics.put(rock.id, rock); - magics.put(ghost.id, ghost); - magics.put(dragon.id, dragon); - magics.put(dark.id, dark); - magics.put(steel.id, steel); - magics.put(fairy.id, fairy); - } - - if (true) { - // Create default magics - Magic earth = new Magic(0, "Earth", 0x00DD00, 1, 1); - earth.setIconItem(new ItemStack(CustomItems.earthElement)); - - Magic water = new Magic(1, "Water", 0xF2DD00, 1, 2); - water.setIconItem(new ItemStack(CustomItems.waterElement)); - - Magic fire = new Magic(2, "Fire", 0xDD0000, 1, 3); - fire.setIconItem(new ItemStack(CustomItems.spellFire)); - - Magic air = new Magic(3, "Air", 0xDD0000, 1, 0); - air.setIconItem(new ItemStack(CustomItems.airElement)); - - Magic dark = new Magic(4, "Dark", 0xDD0000, 0, 3); - dark.setIconItem(new ItemStack(CustomItems.spellDark)); - - Magic holy = new Magic(5, "Holy", 0xDD0000, 0, 1); - holy.setIconItem(new ItemStack(CustomItems.spellHoly)); - - Magic nature = new Magic(6, "Nature", 0xDD0000, 0, 0); - nature.setIconItem(new ItemStack(CustomItems.spellNature)); - - Magic arcane = new Magic(7, "Arcane", 0xDD0000, 0, 2); - arcane.setIconItem(new ItemStack(CustomItems.spellArcane)); - - // Insiders - earth.weaknesses.put(air.id, 0.60f); - water.weaknesses.put(earth.id, 0.60f); - fire.weaknesses.put(water.id, 0.60f); - air.weaknesses.put(fire.id, 0.60f); - - // Outsiders - dark.weaknesses.put(nature.id, 0.60f); - nature.weaknesses.put(holy.id, 0.60f); - holy.weaknesses.put(arcane.id, 0.60f); - arcane.weaknesses.put(dark.id, 0.60f); - - // Cross Interactions - earth.weaknesses.put(nature.id, 0.30f); - water.weaknesses.put(holy.id, 0.30f); - fire.weaknesses.put(arcane.id, 0.30f); - air.weaknesses.put(dark.id, 0.30f); - dark.weaknesses.put(fire.id, 0.30f); - nature.weaknesses.put(air.id, 0.30f); - holy.weaknesses.put(earth.id, 0.30f); - arcane.weaknesses.put(water.id, 0.30f); - - // Add them to the registry - magics.put(earth.id, earth); - magics.put(water.id, water); - magics.put(fire.id, fire); - magics.put(air.id, air); - magics.put(dark.id, dark); - magics.put(holy.id, holy); - magics.put(nature.id, nature); - magics.put(arcane.id, arcane); - } - printAllMagicInteractions(); +// if (false) { +// // Create default Pokémon types +// Magic normal = new Magic(0, "Normal", 0xA8A878); +// normal.setIconItem(new ItemStack(net.minecraft.init.Items.paper)); // using paper for Normal +// +// Magic fire = new Magic(1, "Fire", 0xF08030); +// fire.setIconItem(new ItemStack(net.minecraft.init.Items.flint)); // flint for Fire +// +// Magic water = new Magic(2, "Water", 0x6890F0); +// water.setIconItem(new ItemStack(net.minecraft.init.Items.water_bucket)); // water bucket +// +// Magic electric = new Magic(3, "Electric", 0xF8D030); +// electric.setIconItem(new ItemStack(net.minecraft.init.Items.redstone)); // redstone +// +// Magic grass = new Magic(4, "Grass", 0x78C850); +// grass.setIconItem(new ItemStack(net.minecraft.init.Items.wheat_seeds)); // wheat seeds +// +// Magic ice = new Magic(5, "Ice", 0x98D8D8); +// ice.setIconItem(new ItemStack(net.minecraft.init.Items.snowball)); // snowball for Ice +// +// Magic fighting = new Magic(6, "Fighting", 0xC03028); +// fighting.setIconItem(new ItemStack(net.minecraft.init.Items.iron_sword)); // sword for Fighting +// +// Magic poison = new Magic(7, "Poison", 0xA040A0); +// poison.setIconItem(new ItemStack(net.minecraft.init.Items.potionitem)); // potion item for Poison +// +// Magic ground = new Magic(8, "Ground", 0xE0C068); +// ground.setIconItem(new ItemStack(Blocks.dirt)); // dirt for Ground +// +// Magic flying = new Magic(9, "Flying", 0xA890F0); +// flying.setIconItem(new ItemStack(net.minecraft.init.Items.feather)); // feather for Flying +// +// Magic psychic = new Magic(10, "Psychic", 0xF85888); +// psychic.setIconItem(new ItemStack(net.minecraft.init.Items.ender_pearl)); // ender pearl for Psychic +// +// Magic bug = new Magic(11, "Bug", 0xA8B820); +// bug.setIconItem(new ItemStack(net.minecraft.init.Items.spider_eye)); // spider eye for Bug +// +// Magic rock = new Magic(12, "Rock", 0xB8A038); +// rock.setIconItem(new ItemStack(Blocks.cobblestone)); // cobblestone for Rock +// +// Magic ghost = new Magic(13, "Ghost", 0x705898); +// ghost.setIconItem(new ItemStack(net.minecraft.init.Items.skull)); // skull for Ghost +// +// Magic dragon = new Magic(14, "Dragon", 0x7038F8); +// dragon.setIconItem(new ItemStack(Blocks.dragon_egg)); // dragon egg +// +// Magic dark = new Magic(15, "Dark", 0x705848); +// dark.setIconItem(new ItemStack(net.minecraft.init.Items.coal)); // coal for Dark +// +// Magic steel = new Magic(16, "Steel", 0xB8B8D0); +// steel.setIconItem(new ItemStack(net.minecraft.init.Items.iron_ingot)); // iron ingot for Steel +// +// Magic fairy = new Magic(17, "Fairy", 0xEE99AC); +// fairy.setIconItem(new ItemStack(net.minecraft.init.Items.sugar)); // sugar for Fairy +// +// // Now set weaknesses (using a multiplier of 2.0f to indicate “double damage”). +// // The following is based on a common Pokémon type chart. +// normal.weaknesses.put(fighting.id, 2.0f); +// +// fire.weaknesses.put(water.id, 2.0f); +// fire.weaknesses.put(ground.id, 2.0f); +// fire.weaknesses.put(rock.id, 2.0f); +// +// water.weaknesses.put(electric.id, 2.0f); +// water.weaknesses.put(grass.id, 2.0f); +// +// electric.weaknesses.put(ground.id, 2.0f); +// +// grass.weaknesses.put(fire.id, 2.0f); +// grass.weaknesses.put(ice.id, 2.0f); +// grass.weaknesses.put(poison.id, 2.0f); +// grass.weaknesses.put(flying.id, 2.0f); +// grass.weaknesses.put(bug.id, 2.0f); +// +// ice.weaknesses.put(fire.id, 2.0f); +// ice.weaknesses.put(fighting.id, 2.0f); +// ice.weaknesses.put(rock.id, 2.0f); +// ice.weaknesses.put(steel.id, 2.0f); +// +// fighting.weaknesses.put(flying.id, 2.0f); +// fighting.weaknesses.put(psychic.id, 2.0f); +// fighting.weaknesses.put(fairy.id, 2.0f); +// +// poison.weaknesses.put(ground.id, 2.0f); +// poison.weaknesses.put(psychic.id, 2.0f); +// +// ground.weaknesses.put(water.id, 2.0f); +// ground.weaknesses.put(grass.id, 2.0f); +// ground.weaknesses.put(ice.id, 2.0f); +// +// flying.weaknesses.put(electric.id, 2.0f); +// flying.weaknesses.put(ice.id, 2.0f); +// flying.weaknesses.put(rock.id, 2.0f); +// +// psychic.weaknesses.put(bug.id, 2.0f); +// psychic.weaknesses.put(ghost.id, 2.0f); +// psychic.weaknesses.put(dark.id, 2.0f); +// +// bug.weaknesses.put(fire.id, 2.0f); +// bug.weaknesses.put(flying.id, 2.0f); +// bug.weaknesses.put(rock.id, 2.0f); +// +// rock.weaknesses.put(water.id, 2.0f); +// rock.weaknesses.put(grass.id, 2.0f); +// rock.weaknesses.put(fighting.id, 2.0f); +// rock.weaknesses.put(ground.id, 2.0f); +// rock.weaknesses.put(steel.id, 2.0f); +// +// ghost.weaknesses.put(ghost.id, 2.0f); +// ghost.weaknesses.put(dark.id, 2.0f); +// +// dragon.weaknesses.put(ice.id, 2.0f); +// dragon.weaknesses.put(dragon.id, 2.0f); +// dragon.weaknesses.put(fairy.id, 2.0f); +// +// dark.weaknesses.put(fighting.id, 2.0f); +// dark.weaknesses.put(bug.id, 2.0f); +// dark.weaknesses.put(fairy.id, 2.0f); +// +// steel.weaknesses.put(fire.id, 2.0f); +// steel.weaknesses.put(fighting.id, 2.0f); +// steel.weaknesses.put(ground.id, 2.0f); +// +// fairy.weaknesses.put(poison.id, 2.0f); +// fairy.weaknesses.put(steel.id, 2.0f); +// +// // Register the types. +// magics.put(normal.id, normal); +// magics.put(fire.id, fire); +// magics.put(water.id, water); +// magics.put(electric.id, electric); +// magics.put(grass.id, grass); +// magics.put(ice.id, ice); +// magics.put(fighting.id, fighting); +// magics.put(poison.id, poison); +// magics.put(ground.id, ground); +// magics.put(flying.id, flying); +// magics.put(psychic.id, psychic); +// magics.put(bug.id, bug); +// magics.put(rock.id, rock); +// magics.put(ghost.id, ghost); +// magics.put(dragon.id, dragon); +// magics.put(dark.id, dark); +// magics.put(steel.id, steel); +// magics.put(fairy.id, fairy); +// } +// +// if (true) { +// // Create default magics +// Magic earth = new Magic(0, "Earth", 0x00DD00, 1, 1); +// earth.setIconItem(new ItemStack(CustomItems.earthElement)); +// +// Magic water = new Magic(1, "Water", 0xF2DD00, 1, 2); +// water.setIconItem(new ItemStack(CustomItems.waterElement)); +// +// Magic fire = new Magic(2, "Fire", 0xDD0000, 1, 3); +// fire.setIconItem(new ItemStack(CustomItems.spellFire)); +// +// Magic air = new Magic(3, "Air", 0xDD0000, 1, 0); +// air.setIconItem(new ItemStack(CustomItems.airElement)); +// +// Magic dark = new Magic(4, "Dark", 0xDD0000, 0, 3); +// dark.setIconItem(new ItemStack(CustomItems.spellDark)); +// +// Magic holy = new Magic(5, "Holy", 0xDD0000, 0, 1); +// holy.setIconItem(new ItemStack(CustomItems.spellHoly)); +// +// Magic nature = new Magic(6, "Nature", 0xDD0000, 0, 0); +// nature.setIconItem(new ItemStack(CustomItems.spellNature)); +// +// Magic arcane = new Magic(7, "Arcane", 0xDD0000, 0, 2); +// arcane.setIconItem(new ItemStack(CustomItems.spellArcane)); +// +// // Insiders +// earth.weaknesses.put(air.id, 0.60f); +// water.weaknesses.put(earth.id, 0.60f); +// fire.weaknesses.put(water.id, 0.60f); +// air.weaknesses.put(fire.id, 0.60f); +// +// // Outsiders +// dark.weaknesses.put(nature.id, 0.60f); +// nature.weaknesses.put(holy.id, 0.60f); +// holy.weaknesses.put(arcane.id, 0.60f); +// arcane.weaknesses.put(dark.id, 0.60f); +// +// // Cross Interactions +// earth.weaknesses.put(nature.id, 0.30f); +// water.weaknesses.put(holy.id, 0.30f); +// fire.weaknesses.put(arcane.id, 0.30f); +// air.weaknesses.put(dark.id, 0.30f); +// dark.weaknesses.put(fire.id, 0.30f); +// nature.weaknesses.put(air.id, 0.30f); +// holy.weaknesses.put(earth.id, 0.30f); +// arcane.weaknesses.put(water.id, 0.30f); +// +// // Add them to the registry +// magics.put(earth.id, earth); +// magics.put(water.id, water); +// magics.put(fire.id, fire); +// magics.put(air.id, air); +// magics.put(dark.id, dark); +// magics.put(holy.id, holy); +// magics.put(nature.id, nature); +// magics.put(arcane.id, arcane); +// } +// printAllMagicInteractions(); } private void loadMagicFile(File file) throws IOException { From 8b1fdc5132d69913d0685b5c623b2262fd244cbc Mon Sep 17 00:00:00 2001 From: Kam Date: Sun, 23 Feb 2025 16:15:00 -0500 Subject: [PATCH 48/59] Better Brush Controls --- .../noppes/npcs/ScriptPlayerEventHandler.java | 6 ++++ .../gui/hud/QuestTrackingComponent.java | 2 +- .../java/noppes/npcs/items/ItemNpcTool.java | 34 ++++++++++++++----- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java index b2e7e984c..bd6b56de8 100644 --- a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java @@ -30,6 +30,7 @@ import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.data.*; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.items.ItemNpcTool; import noppes.npcs.quests.QuestItem; import noppes.npcs.scripted.NpcAPI; @@ -154,6 +155,11 @@ public class ScriptPlayerEventHandler { if(event.getPlayer() == null || event.getPlayer().worldObj == null) return; + if(event.getPlayer().getHeldItem() != null && event.getPlayer().getHeldItem().getItem() instanceof ItemNpcTool){ + event.setCanceled(true); + return; + } + if(!event.getPlayer().worldObj.isRemote && event.world instanceof WorldServer) { PlayerDataScript handler = ScriptController.Instance.playerScripts; IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.getPlayer()); diff --git a/src/main/java/noppes/npcs/client/gui/hud/QuestTrackingComponent.java b/src/main/java/noppes/npcs/client/gui/hud/QuestTrackingComponent.java index 20ffe5595..a3477a6cf 100644 --- a/src/main/java/noppes/npcs/client/gui/hud/QuestTrackingComponent.java +++ b/src/main/java/noppes/npcs/client/gui/hud/QuestTrackingComponent.java @@ -115,7 +115,7 @@ public class QuestTrackingComponent extends HudComponent { GL11.glScalef(effectiveScale, effectiveScale, effectiveScale); // Draw background (semi-transparent). - drawRect(0, 0, overlayWidth, overlayHeight, 0x40FFFFFF); + drawRect(0, 0, overlayWidth, overlayHeight, 0x40000000); int currentY = 5; currentY = renderTextBlock(questTitleLines, currentY, textAlign, 0xFFFFFF); diff --git a/src/main/java/noppes/npcs/items/ItemNpcTool.java b/src/main/java/noppes/npcs/items/ItemNpcTool.java index fd7e49c9d..bc245e08f 100644 --- a/src/main/java/noppes/npcs/items/ItemNpcTool.java +++ b/src/main/java/noppes/npcs/items/ItemNpcTool.java @@ -31,7 +31,7 @@ public class ItemNpcTool extends Item { // Define our tool types based on metadata: // meta 0: Hammer, meta 1: Paintbrush, meta 2: Wrench - public static final String[] toolTypes = new String[] {"hammer", "paintbrush", "wrench"}; + public static final String[] toolTypes = new String[] {"hammer", "paintbrush"}; public static String BRUSH_COLOR_TAG = "BrushColor"; @SideOnly(Side.CLIENT) @@ -84,7 +84,7 @@ public class ItemNpcTool extends Item { if(world.isRemote) return stack; - if(isPaintbrush(stack) && !player.isSneaking()){ + if(isPaintbrush(stack) && player.isSneaking()){ if(CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.PAINTBRUSH_GUI)){ NoppesUtil.requestOpenGUI(EnumGuiType.Paintbrush); } @@ -107,13 +107,7 @@ public class ItemNpcTool extends Item { TileEntity tile = world.getTileEntity(x, y, z); if(tile instanceof TileColorable) { - if(player.isSneaking()){ - int color = ((TileColorable) tile).color; - PacketClient.sendClient(new ColorBrushPacket(color)); - } - else { - PacketClient.sendClient(new ColorSetPacket(x, y, z)); - } + PacketClient.sendClient(new ColorSetPacket(x, y, z)); return true; } } @@ -121,6 +115,28 @@ public class ItemNpcTool extends Item { return false; } + public boolean onBlockStartBreak(ItemStack itemstack, int x, int y, int z, EntityPlayer player) + { + if(!player.worldObj.isRemote) + return true; + + if(isPaintbrush(itemstack)) { + Block block = player.worldObj.getBlock(x, y, z); + if(block instanceof BlockTallLamp || block instanceof BlockBanner){ + int meta = player.worldObj.getBlockMetadata(x, y, z); + if(meta >= 7) + y--; + } + + TileEntity tile = player.worldObj.getTileEntity(x, y, z); + if(tile instanceof TileColorable) { + int color = ((TileColorable) tile).color; + PacketClient.sendClient(new ColorBrushPacket(color)); + } + } + + return true; + } public static boolean isPaintbrush(ItemStack itemStack){ return itemStack.getItemDamage() == 1; From ab9209e4f84b7a6edf4ceae9403780f8061eb441 Mon Sep 17 00:00:00 2001 From: Kam Date: Sun, 23 Feb 2025 19:58:54 -0500 Subject: [PATCH 49/59] 1.10 Beta --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 2d866a64f..30013f9b8 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id 'idea' } -version = "1.9.4-beta3.5" +version = "1.10-beta1" group= "kamkeel.customnpc-plus" archivesBaseName = "CustomNPC-Plus" From 56ab018320893793d65b80369db16a0f38fce286 Mon Sep 17 00:00:00 2001 From: Kam Date: Sun, 23 Feb 2025 22:26:08 -0500 Subject: [PATCH 50/59] Fix Profile Locked Bug --- src/main/java/kamkeel/npcs/controllers/ProfileController.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index e7d14dbfd..56253b86b 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -162,6 +162,8 @@ public class ProfileController implements IProfileHandler { backupProfile(uuid, compound); } catch (Exception e) { LogWriter.except(e); + } finally { + profile.setLocked(false); } }); } From ef0581799183c42c0135d4eb8daec0b195604295 Mon Sep 17 00:00:00 2001 From: Kam Date: Sun, 23 Feb 2025 22:43:55 -0500 Subject: [PATCH 51/59] Sort Profile Info --- .../java/kamkeel/npcs/controllers/ProfileController.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index 56253b86b..0a4078450 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -601,8 +601,11 @@ public class ProfileController implements IProfileHandler { Profile profile = getProfile(player); if (profile == null) return infoList; + + List dataList = new ArrayList<>(profileTypes.values()); + dataList.sort(Comparator.comparingInt(IProfileData::getSwitchPriority)); if (slotId == profile.getCurrentSlotId()) { - for (IProfileData pd : profileTypes.values()) { + for (IProfileData pd : dataList) { NBTTagCompound currentNBT = pd.getCurrentNBT(player); List subInfo = pd.getInfo(player, currentNBT); infoList.addAll(subInfo); @@ -611,7 +614,7 @@ public class ProfileController implements IProfileHandler { if (!profile.getSlots().containsKey(slotId)) return infoList; ISlot slot = profile.getSlots().get(slotId); - for (IProfileData pd : profileTypes.values()) { + for (IProfileData pd : dataList) { if (slot.getComponents().containsKey(pd.getTagName())) { NBTTagCompound sub = slot.getComponentData(pd.getTagName()); List subInfo = pd.getInfo(player, sub); From b099e78093739916444bc66d7a02d3a8d82b0738 Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 24 Feb 2025 02:57:43 -0500 Subject: [PATCH 52/59] magic --- .../npcs/controllers/MagicController.java | 605 ++++-------------- .../noppes/npcs/controllers/data/Magic.java | 53 +- .../controllers/data/MagicAssociation.java | 11 + .../npcs/controllers/data/MagicCategory.java | 46 ++ 4 files changed, 177 insertions(+), 538 deletions(-) create mode 100644 src/main/java/noppes/npcs/controllers/data/MagicAssociation.java create mode 100644 src/main/java/noppes/npcs/controllers/data/MagicCategory.java diff --git a/src/main/java/noppes/npcs/controllers/MagicController.java b/src/main/java/noppes/npcs/controllers/MagicController.java index 881c58e44..c0a4903d1 100644 --- a/src/main/java/noppes/npcs/controllers/MagicController.java +++ b/src/main/java/noppes/npcs/controllers/MagicController.java @@ -1,48 +1,53 @@ package noppes.npcs.controllers; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import noppes.npcs.CustomItems; import noppes.npcs.CustomNpcs; import noppes.npcs.LogWriter; -import noppes.npcs.api.handler.data.IMagic; import noppes.npcs.controllers.data.Magic; +import noppes.npcs.controllers.data.MagicCategory; +import noppes.npcs.controllers.data.MagicAssociation; -import java.io.*; -import java.util.*; +import java.io.BufferedInputStream; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.HashMap; import java.util.zip.GZIPInputStream; public class MagicController { - public HashMap magicSync = new HashMap(); - public HashMap magics; + public HashMap magics = new HashMap<>(); + public HashMap magicSync = new HashMap<>(); - private static MagicController instance; + public HashMap categoriesSync = new HashMap<>(); + public HashMap categories = new HashMap<>(); + public int lastUsedCategoryID = 0; private int lastUsedID = 0; + private static MagicController instance; public MagicController() { instance = this; - magics = new HashMap(); } public static MagicController getInstance() { return instance; } - public Magic getMagic(int magic) { - return magics.get(magic); + public Magic getMagic(int magicId) { + return magics.get(magicId); + } + + public MagicCategory getCategory(int categoryId) { + return categories.get(categoryId); } public void load() { - magics = new HashMap(); - lastUsedID = 0; File saveDir = CustomNpcs.getWorldSaveDirectory(); - if (saveDir == null) { - return; - } + if (saveDir == null) return; try { File file = new File(saveDir, "magic.dat"); if (file.exists()) { @@ -56,214 +61,6 @@ public class MagicController { } } catch (Exception ee) { } } - magics.clear(); -// if (false) { -// // Create default Pokémon types -// Magic normal = new Magic(0, "Normal", 0xA8A878); -// normal.setIconItem(new ItemStack(net.minecraft.init.Items.paper)); // using paper for Normal -// -// Magic fire = new Magic(1, "Fire", 0xF08030); -// fire.setIconItem(new ItemStack(net.minecraft.init.Items.flint)); // flint for Fire -// -// Magic water = new Magic(2, "Water", 0x6890F0); -// water.setIconItem(new ItemStack(net.minecraft.init.Items.water_bucket)); // water bucket -// -// Magic electric = new Magic(3, "Electric", 0xF8D030); -// electric.setIconItem(new ItemStack(net.minecraft.init.Items.redstone)); // redstone -// -// Magic grass = new Magic(4, "Grass", 0x78C850); -// grass.setIconItem(new ItemStack(net.minecraft.init.Items.wheat_seeds)); // wheat seeds -// -// Magic ice = new Magic(5, "Ice", 0x98D8D8); -// ice.setIconItem(new ItemStack(net.minecraft.init.Items.snowball)); // snowball for Ice -// -// Magic fighting = new Magic(6, "Fighting", 0xC03028); -// fighting.setIconItem(new ItemStack(net.minecraft.init.Items.iron_sword)); // sword for Fighting -// -// Magic poison = new Magic(7, "Poison", 0xA040A0); -// poison.setIconItem(new ItemStack(net.minecraft.init.Items.potionitem)); // potion item for Poison -// -// Magic ground = new Magic(8, "Ground", 0xE0C068); -// ground.setIconItem(new ItemStack(Blocks.dirt)); // dirt for Ground -// -// Magic flying = new Magic(9, "Flying", 0xA890F0); -// flying.setIconItem(new ItemStack(net.minecraft.init.Items.feather)); // feather for Flying -// -// Magic psychic = new Magic(10, "Psychic", 0xF85888); -// psychic.setIconItem(new ItemStack(net.minecraft.init.Items.ender_pearl)); // ender pearl for Psychic -// -// Magic bug = new Magic(11, "Bug", 0xA8B820); -// bug.setIconItem(new ItemStack(net.minecraft.init.Items.spider_eye)); // spider eye for Bug -// -// Magic rock = new Magic(12, "Rock", 0xB8A038); -// rock.setIconItem(new ItemStack(Blocks.cobblestone)); // cobblestone for Rock -// -// Magic ghost = new Magic(13, "Ghost", 0x705898); -// ghost.setIconItem(new ItemStack(net.minecraft.init.Items.skull)); // skull for Ghost -// -// Magic dragon = new Magic(14, "Dragon", 0x7038F8); -// dragon.setIconItem(new ItemStack(Blocks.dragon_egg)); // dragon egg -// -// Magic dark = new Magic(15, "Dark", 0x705848); -// dark.setIconItem(new ItemStack(net.minecraft.init.Items.coal)); // coal for Dark -// -// Magic steel = new Magic(16, "Steel", 0xB8B8D0); -// steel.setIconItem(new ItemStack(net.minecraft.init.Items.iron_ingot)); // iron ingot for Steel -// -// Magic fairy = new Magic(17, "Fairy", 0xEE99AC); -// fairy.setIconItem(new ItemStack(net.minecraft.init.Items.sugar)); // sugar for Fairy -// -// // Now set weaknesses (using a multiplier of 2.0f to indicate “double damage”). -// // The following is based on a common Pokémon type chart. -// normal.weaknesses.put(fighting.id, 2.0f); -// -// fire.weaknesses.put(water.id, 2.0f); -// fire.weaknesses.put(ground.id, 2.0f); -// fire.weaknesses.put(rock.id, 2.0f); -// -// water.weaknesses.put(electric.id, 2.0f); -// water.weaknesses.put(grass.id, 2.0f); -// -// electric.weaknesses.put(ground.id, 2.0f); -// -// grass.weaknesses.put(fire.id, 2.0f); -// grass.weaknesses.put(ice.id, 2.0f); -// grass.weaknesses.put(poison.id, 2.0f); -// grass.weaknesses.put(flying.id, 2.0f); -// grass.weaknesses.put(bug.id, 2.0f); -// -// ice.weaknesses.put(fire.id, 2.0f); -// ice.weaknesses.put(fighting.id, 2.0f); -// ice.weaknesses.put(rock.id, 2.0f); -// ice.weaknesses.put(steel.id, 2.0f); -// -// fighting.weaknesses.put(flying.id, 2.0f); -// fighting.weaknesses.put(psychic.id, 2.0f); -// fighting.weaknesses.put(fairy.id, 2.0f); -// -// poison.weaknesses.put(ground.id, 2.0f); -// poison.weaknesses.put(psychic.id, 2.0f); -// -// ground.weaknesses.put(water.id, 2.0f); -// ground.weaknesses.put(grass.id, 2.0f); -// ground.weaknesses.put(ice.id, 2.0f); -// -// flying.weaknesses.put(electric.id, 2.0f); -// flying.weaknesses.put(ice.id, 2.0f); -// flying.weaknesses.put(rock.id, 2.0f); -// -// psychic.weaknesses.put(bug.id, 2.0f); -// psychic.weaknesses.put(ghost.id, 2.0f); -// psychic.weaknesses.put(dark.id, 2.0f); -// -// bug.weaknesses.put(fire.id, 2.0f); -// bug.weaknesses.put(flying.id, 2.0f); -// bug.weaknesses.put(rock.id, 2.0f); -// -// rock.weaknesses.put(water.id, 2.0f); -// rock.weaknesses.put(grass.id, 2.0f); -// rock.weaknesses.put(fighting.id, 2.0f); -// rock.weaknesses.put(ground.id, 2.0f); -// rock.weaknesses.put(steel.id, 2.0f); -// -// ghost.weaknesses.put(ghost.id, 2.0f); -// ghost.weaknesses.put(dark.id, 2.0f); -// -// dragon.weaknesses.put(ice.id, 2.0f); -// dragon.weaknesses.put(dragon.id, 2.0f); -// dragon.weaknesses.put(fairy.id, 2.0f); -// -// dark.weaknesses.put(fighting.id, 2.0f); -// dark.weaknesses.put(bug.id, 2.0f); -// dark.weaknesses.put(fairy.id, 2.0f); -// -// steel.weaknesses.put(fire.id, 2.0f); -// steel.weaknesses.put(fighting.id, 2.0f); -// steel.weaknesses.put(ground.id, 2.0f); -// -// fairy.weaknesses.put(poison.id, 2.0f); -// fairy.weaknesses.put(steel.id, 2.0f); -// -// // Register the types. -// magics.put(normal.id, normal); -// magics.put(fire.id, fire); -// magics.put(water.id, water); -// magics.put(electric.id, electric); -// magics.put(grass.id, grass); -// magics.put(ice.id, ice); -// magics.put(fighting.id, fighting); -// magics.put(poison.id, poison); -// magics.put(ground.id, ground); -// magics.put(flying.id, flying); -// magics.put(psychic.id, psychic); -// magics.put(bug.id, bug); -// magics.put(rock.id, rock); -// magics.put(ghost.id, ghost); -// magics.put(dragon.id, dragon); -// magics.put(dark.id, dark); -// magics.put(steel.id, steel); -// magics.put(fairy.id, fairy); -// } -// -// if (true) { -// // Create default magics -// Magic earth = new Magic(0, "Earth", 0x00DD00, 1, 1); -// earth.setIconItem(new ItemStack(CustomItems.earthElement)); -// -// Magic water = new Magic(1, "Water", 0xF2DD00, 1, 2); -// water.setIconItem(new ItemStack(CustomItems.waterElement)); -// -// Magic fire = new Magic(2, "Fire", 0xDD0000, 1, 3); -// fire.setIconItem(new ItemStack(CustomItems.spellFire)); -// -// Magic air = new Magic(3, "Air", 0xDD0000, 1, 0); -// air.setIconItem(new ItemStack(CustomItems.airElement)); -// -// Magic dark = new Magic(4, "Dark", 0xDD0000, 0, 3); -// dark.setIconItem(new ItemStack(CustomItems.spellDark)); -// -// Magic holy = new Magic(5, "Holy", 0xDD0000, 0, 1); -// holy.setIconItem(new ItemStack(CustomItems.spellHoly)); -// -// Magic nature = new Magic(6, "Nature", 0xDD0000, 0, 0); -// nature.setIconItem(new ItemStack(CustomItems.spellNature)); -// -// Magic arcane = new Magic(7, "Arcane", 0xDD0000, 0, 2); -// arcane.setIconItem(new ItemStack(CustomItems.spellArcane)); -// -// // Insiders -// earth.weaknesses.put(air.id, 0.60f); -// water.weaknesses.put(earth.id, 0.60f); -// fire.weaknesses.put(water.id, 0.60f); -// air.weaknesses.put(fire.id, 0.60f); -// -// // Outsiders -// dark.weaknesses.put(nature.id, 0.60f); -// nature.weaknesses.put(holy.id, 0.60f); -// holy.weaknesses.put(arcane.id, 0.60f); -// arcane.weaknesses.put(dark.id, 0.60f); -// -// // Cross Interactions -// earth.weaknesses.put(nature.id, 0.30f); -// water.weaknesses.put(holy.id, 0.30f); -// fire.weaknesses.put(arcane.id, 0.30f); -// air.weaknesses.put(dark.id, 0.30f); -// dark.weaknesses.put(fire.id, 0.30f); -// nature.weaknesses.put(air.id, 0.30f); -// holy.weaknesses.put(earth.id, 0.30f); -// arcane.weaknesses.put(water.id, 0.30f); -// -// // Add them to the registry -// magics.put(earth.id, earth); -// magics.put(water.id, water); -// magics.put(fire.id, fire); -// magics.put(air.id, air); -// magics.put(dark.id, dark); -// magics.put(holy.id, holy); -// magics.put(nature.id, nature); -// magics.put(arcane.id, arcane); -// } -// printAllMagicInteractions(); } private void loadMagicFile(File file) throws IOException { @@ -275,67 +72,67 @@ public class MagicController { } public void loadMagic(DataInputStream stream) throws IOException { - HashMap magic = new HashMap(); - NBTTagCompound nbttagcompound1 = CompressedStreamTools.read(stream); - lastUsedID = nbttagcompound1.getInteger("lastID"); - NBTTagList list = nbttagcompound1.getTagList("NPCMagic", 10); // using "NPCMagic" as tag + NBTTagCompound compound = CompressedStreamTools.read(stream); + lastUsedID = compound.getInteger("lastID"); - if (list != null) { - for (int i = 0; i < list.tagCount(); i++) { - NBTTagCompound nbttagcompound = list.getCompoundTagAt(i); - Magic loadMagic = new Magic(); - loadMagic.readNBT(nbttagcompound); - magic.put(loadMagic.id, loadMagic); - } + // Load magics + magics.clear(); + NBTTagList magicList = compound.getTagList("Magics", 10); + for (int i = 0; i < magicList.tagCount(); i++) { + NBTTagCompound magCompound = magicList.getCompoundTagAt(i); + Magic mag = new Magic(); + mag.readNBT(magCompound); + magics.put(mag.id, mag); + } + + // Load categories + categories.clear(); + NBTTagList catList = compound.getTagList("Categories", 10); + for (int i = 0; i < catList.tagCount(); i++) { + NBTTagCompound catCompound = catList.getCompoundTagAt(i); + MagicCategory cat = new MagicCategory(); + cat.readNBT(catCompound); + categories.put(cat.id, cat); } - this.magics = magic; } public NBTTagCompound getNBT() { - NBTTagList list = new NBTTagList(); - for (int slot : magics.keySet()) { - Magic mag = magics.get(slot); - NBTTagCompound nbtMagic = new NBTTagCompound(); - mag.writeNBT(nbtMagic); - list.appendTag(nbtMagic); + NBTTagList magicList = new NBTTagList(); + for (Magic mag : magics.values()) { + NBTTagCompound magCompound = new NBTTagCompound(); + mag.writeNBT(magCompound); + magicList.appendTag(magCompound); } - NBTTagCompound nbttagcompound = new NBTTagCompound(); - nbttagcompound.setInteger("lastID", lastUsedID); - nbttagcompound.setTag("NPCMagic", list); // use same tag as loadMagic - return nbttagcompound; + NBTTagList catList = new NBTTagList(); + for (MagicCategory cat : categories.values()) { + NBTTagCompound catCompound = new NBTTagCompound(); + cat.writeNBT(catCompound); + catList.appendTag(catCompound); + } + NBTTagCompound compound = new NBTTagCompound(); + compound.setInteger("lastID", lastUsedID); + compound.setTag("Magics", magicList); + compound.setTag("Categories", catList); + return compound; } - public void saveFactions() { + public void saveMagicData() { try { File saveDir = CustomNpcs.getWorldSaveDirectory(); - File file = new File(saveDir, "magic.dat_new"); - File file1 = new File(saveDir, "magic.dat_old"); - File file2 = new File(saveDir, "magic.dat"); - CompressedStreamTools.writeCompressed(getNBT(), new FileOutputStream(file)); - if (file1.exists()) { - file1.delete(); - } - file2.renameTo(file1); - if (file2.exists()) { - file2.delete(); - } - file.renameTo(file2); - if (file.exists()) { - file.delete(); - } + File fileNew = new File(saveDir, "magic.dat_new"); + File fileOld = new File(saveDir, "magic.dat_old"); + File fileCurrent = new File(saveDir, "magic.dat"); + CompressedStreamTools.writeCompressed(getNBT(), new FileOutputStream(fileNew)); + if (fileOld.exists()) fileOld.delete(); + fileCurrent.renameTo(fileOld); + if (fileCurrent.exists()) fileCurrent.delete(); + fileNew.renameTo(fileCurrent); + if (fileNew.exists()) fileNew.delete(); } catch (Exception e) { LogWriter.except(e); } } - public Magic get(int magicID) { - return magics.get(magicID); - } - - public List list() { - return new ArrayList(this.magics.values()); - } - public void saveMagic(Magic mag) { if (mag.id < 0) { mag.id = getUnusedId(); @@ -347,252 +144,76 @@ public class MagicController { while (hasName(mag.name)) mag.name += "_"; } - magics.remove(mag.id); magics.put(mag.id, mag); - - NBTTagCompound facCompound = new NBTTagCompound(); - mag.writeNBT(facCompound); - // Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.MAGIC, facCompound); - saveFactions(); + saveMagicData(); } public int getUnusedId() { if (lastUsedID == 0) { - for (int catid : magics.keySet()) - if (catid > lastUsedID) - lastUsedID = catid; + for (int id : magics.keySet()) + if (id > lastUsedID) + lastUsedID = id; } lastUsedID++; return lastUsedID; } public boolean hasName(String newName) { - if (newName.trim().isEmpty()) - return true; + if (newName.trim().isEmpty()) return true; for (Magic mag : magics.values()) if (mag.name.equals(newName)) return true; return false; } - public Magic getMagicFromName(String magicName) { - for (Map.Entry entryMag : MagicController.getInstance().magics.entrySet()) { - if (entryMag.getValue().name.equalsIgnoreCase(magicName)) { - return entryMag.getValue(); - } - } - return null; - } + // === Category management methods === - public String[] getNames() { - String[] names = new String[magics.size()]; - int i = 0; - for (Magic mag : magics.values()) { - names[i] = mag.name.toLowerCase(); - i++; - } - return names; - } - - // --- New functions for applying magic NBT stats and calculating damage --- - - /** - * Applies magic-type damage to an item. A weapon/item can have multiple magic damage values. - * The damage is stored under a compound tag "MagicDamage" where each key is the magic ID. - */ - public static void addMagicDamageToItem(ItemStack item, int magicId, float damage) { - if (item == null) return; - if (item.stackTagCompound == null) - item.stackTagCompound = new NBTTagCompound(); - NBTTagCompound compound = item.stackTagCompound; - NBTTagCompound magicDamage; - if (compound.hasKey("MagicDamage")) { - magicDamage = compound.getCompoundTag("MagicDamage"); + public void addCategory(MagicCategory category) { + if (category.id < 0) { + lastUsedCategoryID++; + category.id = lastUsedCategoryID; } else { - magicDamage = new NBTTagCompound(); + while (containsCategoryName(category.title)) + category.title += "_"; + } + categories.put(category.id, category); + saveMagicData(); + } + + public boolean containsCategoryName(String title) { + title = title.toLowerCase(); + for (MagicCategory cat : categories.values()) { + if (cat.title.toLowerCase().equals(title)) + return true; + } + return false; + } + + public void removeCategory(int categoryId) { + if (categories.containsKey(categoryId)) { + categories.remove(categoryId); + saveMagicData(); } - magicDamage.setFloat(String.valueOf(magicId), damage); - compound.setTag("MagicDamage", magicDamage); } /** - * Applies magic resistance to an armor piece. - * The resistance is stored under a compound tag "MagicResistances" with the magic ID as key. + * Associates a magic with a category along with its per-category ordering data. */ - public static void addMagicResistanceToArmor(ItemStack armor, int magicId, float resistance) { - if (armor == null) return; - if (armor.stackTagCompound == null) - armor.stackTagCompound = new NBTTagCompound(); - NBTTagCompound compound = armor.stackTagCompound; - NBTTagCompound magicResist; - if (compound.hasKey("MagicResistances")) { - magicResist = compound.getCompoundTag("MagicResistances"); - } else { - magicResist = new NBTTagCompound(); - } - magicResist.setFloat(String.valueOf(magicId), resistance); - compound.setTag("MagicResistances", magicResist); + public void addMagicToCategory(int magicId, int categoryId, int index, int priority) { + MagicCategory cat = categories.get(categoryId); + if (cat == null) return; + MagicAssociation assoc = new MagicAssociation(); + assoc.magicId = magicId; + assoc.index = index; + assoc.priority = priority; + cat.associations.put(magicId, assoc); + saveMagicData(); } - /** - * Given a collection of armor pieces, sums the resistance value for the specified magic ID. - */ - public static float calculateTotalMagicResistance(int magicId, Iterable armors) { - float totalResistance = 0.0F; - for (ItemStack armor : armors) { - if (armor != null && armor.hasTagCompound() && armor.stackTagCompound.hasKey("MagicResistances")) { - NBTTagCompound magicResist = armor.stackTagCompound.getCompoundTag("MagicResistances"); - if (magicResist.hasKey(String.valueOf(magicId))) { - totalResistance += magicResist.getFloat(String.valueOf(magicId)); - } - } - } - return totalResistance; - } - - /** - * Calculates the final magic damage after applying armor resistances. - * For a given magic type, the resistance is applied. - * - * @param magicId the magic type - * @param baseDamage the base damage value - * @param armors an Iterable collection of armor ItemStacks - * @return the final damage after reduction - */ - public static float calculateFinalMagicDamage(int magicId, float baseDamage, Iterable armors) { - if (getInstance().getMagic(magicId) == null) { - // If the magic type is not defined, treat it as non-magical. - return baseDamage; - } - float resistance = calculateTotalMagicResistance(magicId, armors); - // Resistance is assumed to be a fractional reduction (e.g., 0.2 = 20% reduction). - return baseDamage * (1.0F - resistance); - } - - /** - * Extracts magic damage values from a weapon ItemStack. - * It looks for a compound tag "CNPCMagic" first; if not found, it falls back to "MagicDamage". - * Returns a mapping of magic ID to its damage value. - */ - public static Map getMagicDamageFromItem(ItemStack item) { - Map damageMap = new HashMap(); - if (item == null || item.stackTagCompound == null) return damageMap; - NBTTagCompound compound = item.stackTagCompound; - NBTTagCompound damageCompound = null; - if (compound.hasKey("CNPCMagic")) { - NBTTagCompound magicCompound = compound.getCompoundTag("CNPCMagic"); - if (magicCompound.hasKey("MagicDamage")) { - damageCompound = magicCompound.getCompoundTag("MagicDamage"); - } - } else if (compound.hasKey("MagicDamage")) { - damageCompound = compound.getCompoundTag("MagicDamage"); - } - if (damageCompound != null) { - Set keys = damageCompound.func_150296_c(); - for (String key : keys) { - try { - int magicId = Integer.parseInt(key); - float dmg = damageCompound.getFloat(key); - damageMap.put(magicId, dmg); - } catch (NumberFormatException e) { - // Ignore non-integer keys. - } - } - } - return damageMap; - } - - /** - * Extracts magic resistances from an armor ItemStack. - * It checks for a "CNPCMagic" container first; if not present, it falls back to "MagicResistances". - * Returns a mapping of magic ID to its resistance value. - */ - public static Map getMagicResistancesFromItem(ItemStack item) { - Map resistMap = new HashMap(); - if (item == null || item.stackTagCompound == null) return resistMap; - NBTTagCompound compound = item.stackTagCompound; - NBTTagCompound resistCompound = null; - if (compound.hasKey("CNPCMagic")) { - NBTTagCompound magicCompound = compound.getCompoundTag("CNPCMagic"); - if (magicCompound.hasKey("MagicResistances")) { - resistCompound = magicCompound.getCompoundTag("MagicResistances"); - } - } else if (compound.hasKey("MagicResistances")) { - resistCompound = compound.getCompoundTag("MagicResistances"); - } - if (resistCompound != null) { - Set keys = resistCompound.func_150296_c(); - for (String key : keys) { - try { - int magicId = Integer.parseInt(key); - float res = resistCompound.getFloat(key); - resistMap.put(magicId, res); - } catch (NumberFormatException e) { - // Ignore non-integer keys. - } - } - } - return resistMap; - } - - /** - * Validates whether an item (weapon or armor) contains any magic-related NBT. - */ - public static boolean hasMagicStats(ItemStack item) { - if (item == null || item.stackTagCompound == null) return false; - NBTTagCompound compound = item.stackTagCompound; - return compound.hasKey("CNPCMagic") || compound.hasKey("MagicDamage") || compound.hasKey("MagicResistances"); - } - - /** - * Calculates a damage breakdown for each magic type from a weapon when applied against a set of armors. - * This function will ignore any magic with ID 0 (neutral), so only magic damage is returned. - * Returns a map where keys are magic IDs (non-zero) and values are the final damage for that type. - */ - public static Map calculateDamageBreakdown(ItemStack weapon, Iterable armors) { - Map breakdown = new HashMap(); - Map weaponDamage = getMagicDamageFromItem(weapon); - for (Map.Entry entry : weaponDamage.entrySet()) { - int magicId = entry.getKey(); - // Skip magic ID 0 (neutral) - if (magicId == 0) continue; - float dmg = entry.getValue(); - float finalDmg = calculateFinalMagicDamage(magicId, dmg, armors); - breakdown.put(magicId, finalDmg); - } - return breakdown; - } - - /** - * Calculates the total final magic damage of a weapon after applying the resistances of a set of armor pieces. - * This sums only the magic interactions (magic IDs other than 0). - */ - public static float calculateTotalDamage(ItemStack weapon, Iterable armors) { - float totalDamage = 0.0F; - Map breakdown = calculateDamageBreakdown(weapon, armors); - for (Float dmg : breakdown.values()) { - totalDamage += dmg; - } - return totalDamage; - } - - /** - * Prints all magic interactions (weaknesses) in the registry. - * For each magic (defender) that has weaknesses, prints the corresponding attacker and the extra damage percentage. - * Format: "Magic ID: [attacker id], Name: "[attacker name]" does [percentage*100]% extra damage to Magic ID: [defender id], Name: "[defender name]". - */ - public static void printAllMagicInteractions() { - MagicController mc = getInstance(); - for (Magic defender : mc.magics.values()) { - for (Map.Entry entry : defender.weaknesses.entrySet()) { - int attackerId = entry.getKey(); - float percentage = entry.getValue(); - Magic attacker = mc.getMagic(attackerId); - if (attacker != null) { - System.out.println("Magic ID: " + attacker.id + ", Name: \"" + attacker.name + "\" does " - + (percentage * 100) + "% extra damage to Magic ID: " + defender.id + ", Name: \"" + defender.name + "\""); - } - } - } + public void removeMagicFromCategory(int magicId, int categoryId) { + MagicCategory cat = categories.get(categoryId); + if (cat == null) return; + cat.associations.remove(magicId); + saveMagicData(); } } diff --git a/src/main/java/noppes/npcs/controllers/data/Magic.java b/src/main/java/noppes/npcs/controllers/data/Magic.java index 1b5636bc1..25b5b1474 100644 --- a/src/main/java/noppes/npcs/controllers/data/Magic.java +++ b/src/main/java/noppes/npcs/controllers/data/Magic.java @@ -5,7 +5,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import noppes.npcs.api.handler.data.IMagic; import noppes.npcs.controllers.MagicController; - import java.util.HashMap; import java.util.Map; @@ -14,16 +13,9 @@ public class Magic implements IMagic { public int color = Integer.parseInt("FF00", 16); public int id = -1; - public int index; - public int priority; - - // Icon as an ItemStack or as a texture file public ItemStack iconItem = null; public String iconTexture = ""; - - // Weaknesses mapping: key = magic ID this magic is weak against, - // value = extra damage percentage (as a fraction, e.g. 0.2 for 20% extra damage) - public Map weaknesses = new HashMap(); + public Map weaknesses = new HashMap<>(); public Magic() {} @@ -33,14 +25,6 @@ public class Magic implements IMagic { this.id = id; } - public Magic(int id, String name, int color, int index, int priority) { - this.name = name; - this.color = color; - this.id = id; - this.index = index; - this.priority = priority; - } - public static String formatName(String name) { name = name.toLowerCase().trim(); return name.substring(0, 1).toUpperCase() + name.substring(1); @@ -50,19 +34,15 @@ public class Magic implements IMagic { name = compound.getString("Name"); color = compound.getInteger("Color"); id = compound.getInteger("Slot"); - index = compound.getInteger("Index"); - priority = compound.getInteger("Priority"); - + // No longer reading index/priority here. if(compound.hasKey("IconItem")){ NBTTagCompound itemTag = compound.getCompoundTag("IconItem"); iconItem = ItemStack.loadItemStackFromNBT(itemTag); } iconTexture = compound.getString("IconTexture"); - - // Read the weaknesses mapping from NBT. weaknesses.clear(); if(compound.hasKey("Weaknesses")) { - NBTTagList weaknessList = compound.getTagList("Weaknesses", 10); // compound tags + NBTTagList weaknessList = compound.getTagList("Weaknesses", 10); for(int i = 0; i < weaknessList.tagCount(); i++){ NBTTagCompound weaknessTag = weaknessList.getCompoundTagAt(i); int weakMagicId = weaknessTag.getInteger("MagicID"); @@ -76,9 +56,7 @@ public class Magic implements IMagic { compound.setInteger("Slot", id); compound.setString("Name", name); compound.setInteger("Color", color); - compound.setInteger("Index", index); - compound.setInteger("Priority", priority); - + // No longer writing index/priority here. if(iconItem != null) { NBTTagCompound itemTag = new NBTTagCompound(); iconItem.writeToNBT(itemTag); @@ -87,8 +65,6 @@ public class Magic implements IMagic { if(iconTexture != null && !iconTexture.isEmpty()){ compound.setString("IconTexture", iconTexture); } - - // Write the weaknesses mapping. NBTTagList weaknessList = new NBTTagList(); for(Map.Entry entry : weaknesses.entrySet()){ NBTTagCompound weaknessTag = new NBTTagCompound(); @@ -111,26 +87,11 @@ public class Magic implements IMagic { this.name = name; } - public int getPriority() { - return priority; - } - - public void setPriority(int priority) { - this.priority = priority; - } - - public int getIndex() { - return index; - } - - public void setIndex(int index) { - this.index = index; - } - - public void setColor(int color) { - this.color = color; + public void setColor(int c) { + this.color = c; } + @Override public int getColor() { return this.color; } diff --git a/src/main/java/noppes/npcs/controllers/data/MagicAssociation.java b/src/main/java/noppes/npcs/controllers/data/MagicAssociation.java new file mode 100644 index 000000000..2589233c9 --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/data/MagicAssociation.java @@ -0,0 +1,11 @@ +package noppes.npcs.controllers.data; + +/** + * A helper class that represents the relationship between a Magic and a Category. + * It holds per-category ordering data. + */ +public class MagicAssociation { + public int magicId; + public int index; + public int priority; +} diff --git a/src/main/java/noppes/npcs/controllers/data/MagicCategory.java b/src/main/java/noppes/npcs/controllers/data/MagicCategory.java new file mode 100644 index 000000000..d3a3b029e --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/data/MagicCategory.java @@ -0,0 +1,46 @@ +package noppes.npcs.controllers.data; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import java.util.HashMap; + +/** + * Holds category information for magic. + * Each category can have many magic associations. + */ +public class MagicCategory { + public int id = -1; + public String title = ""; + public HashMap associations = new HashMap<>(); + + public MagicCategory() {} + + public void readNBT(NBTTagCompound compound) { + id = compound.getInteger("CategoryID"); + title = compound.getString("Title"); + associations.clear(); + NBTTagList list = compound.getTagList("Associations", 10); // compound tags + for (int i = 0; i < list.tagCount(); i++) { + NBTTagCompound assocTag = list.getCompoundTagAt(i); + MagicAssociation assoc = new MagicAssociation(); + assoc.magicId = assocTag.getInteger("MagicID"); + assoc.index = assocTag.getInteger("Index"); + assoc.priority = assocTag.getInteger("Priority"); + associations.put(assoc.magicId, assoc); + } + } + + public void writeNBT(NBTTagCompound compound) { + compound.setInteger("CategoryID", id); + compound.setString("Title", title); + NBTTagList list = new NBTTagList(); + for (MagicAssociation assoc : associations.values()) { + NBTTagCompound assocTag = new NBTTagCompound(); + assocTag.setInteger("MagicID", assoc.magicId); + assocTag.setInteger("Index", assoc.index); + assocTag.setInteger("Priority", assoc.priority); + list.appendTag(assocTag); + } + compound.setTag("Associations", list); + } +} From 4faa85107865dea4869725565b7d487bfda709cb Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 24 Feb 2025 15:37:39 -0500 Subject: [PATCH 53/59] Update MagicController.java --- src/main/java/noppes/npcs/controllers/MagicController.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/controllers/MagicController.java b/src/main/java/noppes/npcs/controllers/MagicController.java index c0a4903d1..adb3fe138 100644 --- a/src/main/java/noppes/npcs/controllers/MagicController.java +++ b/src/main/java/noppes/npcs/controllers/MagicController.java @@ -22,11 +22,12 @@ public class MagicController { public HashMap magics = new HashMap<>(); public HashMap magicSync = new HashMap<>(); - public HashMap categoriesSync = new HashMap<>(); public HashMap categories = new HashMap<>(); - public int lastUsedCategoryID = 0; + public HashMap categoriesSync = new HashMap<>(); + public int lastUsedCategoryID = 0; private int lastUsedID = 0; + private static MagicController instance; public MagicController() { @@ -74,6 +75,7 @@ public class MagicController { public void loadMagic(DataInputStream stream) throws IOException { NBTTagCompound compound = CompressedStreamTools.read(stream); lastUsedID = compound.getInteger("lastID"); + lastUsedCategoryID = compound.getInteger("lastCatID"); // Load magics magics.clear(); @@ -111,6 +113,7 @@ public class MagicController { } NBTTagCompound compound = new NBTTagCompound(); compound.setInteger("lastID", lastUsedID); + compound.setInteger("lastCatID", lastUsedCategoryID); compound.setTag("Magics", magicList); compound.setTag("Categories", catList); return compound; From 5818060656bde9ee5ab0bd1278dace0b400615bc Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 24 Feb 2025 16:08:22 -0500 Subject: [PATCH 54/59] Large Unused Attribute Push --- .../npcs/attribute/AttributeController.java | 32 +++++ .../npcs/attribute/AttributeDefinition.java | 36 ++++++ .../npcs/attribute/AttributeModifier.java | 38 ++++++ .../attribute/CNPCItemAttributeHelper.java | 79 ++++++++++++ .../npcs/attribute/CustomAttributeMap.java | 29 +++++ .../npcs/attribute/DamageCalculator.java | 59 +++++++++ .../npcs/attribute/IAttributeInstance.java | 17 +++ .../noppes/npcs/attribute/ModAttributes.java | 21 ++++ .../ModifiableAttributeInstance.java | 66 ++++++++++ .../java/noppes/npcs/attribute/Operation.java | 6 + .../attribute/PlayerAttributeManager.java | 31 +++++ .../attribute/PlayerAttributeTickHandler.java | 21 ++++ .../attribute/PlayerAttributeTracker.java | 118 ++++++++++++++++++ 13 files changed, 553 insertions(+) create mode 100644 src/main/java/noppes/npcs/attribute/AttributeController.java create mode 100644 src/main/java/noppes/npcs/attribute/AttributeDefinition.java create mode 100644 src/main/java/noppes/npcs/attribute/AttributeModifier.java create mode 100644 src/main/java/noppes/npcs/attribute/CNPCItemAttributeHelper.java create mode 100644 src/main/java/noppes/npcs/attribute/CustomAttributeMap.java create mode 100644 src/main/java/noppes/npcs/attribute/DamageCalculator.java create mode 100644 src/main/java/noppes/npcs/attribute/IAttributeInstance.java create mode 100644 src/main/java/noppes/npcs/attribute/ModAttributes.java create mode 100644 src/main/java/noppes/npcs/attribute/ModifiableAttributeInstance.java create mode 100644 src/main/java/noppes/npcs/attribute/Operation.java create mode 100644 src/main/java/noppes/npcs/attribute/PlayerAttributeManager.java create mode 100644 src/main/java/noppes/npcs/attribute/PlayerAttributeTickHandler.java create mode 100644 src/main/java/noppes/npcs/attribute/PlayerAttributeTracker.java diff --git a/src/main/java/noppes/npcs/attribute/AttributeController.java b/src/main/java/noppes/npcs/attribute/AttributeController.java new file mode 100644 index 000000000..4e4ffbb5d --- /dev/null +++ b/src/main/java/noppes/npcs/attribute/AttributeController.java @@ -0,0 +1,32 @@ +package noppes.npcs.attribute; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +/** + * Central registry for valid attribute definitions. + * Other mods can register new attributes here so that items only need to store a + * small namespaced key. + */ +public class AttributeController { + private static final Map definitions = new HashMap<>(); + private static int nextId = 0; + + public static AttributeDefinition registerAttribute(String key, String displayName, Operation op) { + if (definitions.containsKey(key)) { + return definitions.get(key); + } + AttributeDefinition def = new AttributeDefinition(nextId++, key, displayName, op); + definitions.put(key, def); + return def; + } + + public static AttributeDefinition getAttribute(String key) { + return definitions.get(key); + } + + public static Collection getAllAttributes() { + return definitions.values(); + } +} diff --git a/src/main/java/noppes/npcs/attribute/AttributeDefinition.java b/src/main/java/noppes/npcs/attribute/AttributeDefinition.java new file mode 100644 index 000000000..5ba597661 --- /dev/null +++ b/src/main/java/noppes/npcs/attribute/AttributeDefinition.java @@ -0,0 +1,36 @@ +package noppes.npcs.attribute; + +/** + * Defines a valid attribute – for example, "cnpc:main_attack_flat" (a flat bonus) + * or "cnpc:main_attack_percent" (a percent bonus). These definitions are registered + * once in the AttributeController. + */ +public class AttributeDefinition { + private final int id; + private final String key; // e.g., "cnpc:main_attack_flat" + private final String displayName; // Human‑readable name + private final Operation operation; + + public AttributeDefinition(int id, String key, String displayName, Operation operation) { + this.id = id; + this.key = key; + this.displayName = displayName; + this.operation = operation; + } + + public int getId() { + return id; + } + + public String getKey() { + return key; + } + + public String getDisplayName() { + return displayName; + } + + public Operation getOperation() { + return operation; + } +} diff --git a/src/main/java/noppes/npcs/attribute/AttributeModifier.java b/src/main/java/noppes/npcs/attribute/AttributeModifier.java new file mode 100644 index 000000000..9f821283f --- /dev/null +++ b/src/main/java/noppes/npcs/attribute/AttributeModifier.java @@ -0,0 +1,38 @@ +package noppes.npcs.attribute; + +import java.util.UUID; + +/** + * An AttributeModifier represents a bonus or penalty that’s applied to an attribute. + * It stores a unique UUID, a name, an amount, and whether it is FLAT (added directly) + * or PERCENT (applied as a multiplier) to the base value. + */ +public class AttributeModifier { + private final UUID id; + private final String name; + private final double amount; + private final Operation operation; + + public AttributeModifier(UUID id, String name, double amount, Operation operation) { + this.id = id; + this.name = name; + this.amount = amount; + this.operation = operation; + } + + public UUID getId() { + return id; + } + + public String getName() { + return name; + } + + public double getAmount() { + return amount; + } + + public Operation getOperation() { + return operation; + } +} diff --git a/src/main/java/noppes/npcs/attribute/CNPCItemAttributeHelper.java b/src/main/java/noppes/npcs/attribute/CNPCItemAttributeHelper.java new file mode 100644 index 000000000..44b286773 --- /dev/null +++ b/src/main/java/noppes/npcs/attribute/CNPCItemAttributeHelper.java @@ -0,0 +1,79 @@ +package noppes.npcs.attribute; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import java.util.Set; +import java.util.HashMap; +import java.util.Map; + +/** + * Handles writing/reading item attributes. + * Non‑magic attributes are stored under a "CNPCAttributes" tag. + * Magic-based attributes are stored as a compound mapping magic ID to value, + * for example under "cnpc:magic_damage_flat". + */ +public class CNPCItemAttributeHelper { + public static final String TAG_ROOT = "CNPCAttributes"; + + public static void applyAttribute(ItemStack item, String attributeKey, double value) { + if(item == null) return; + if(item.stackTagCompound == null) { + item.stackTagCompound = new NBTTagCompound(); + } + NBTTagCompound root = item.stackTagCompound; + NBTTagCompound attrTag; + if(root.hasKey(TAG_ROOT)) { + attrTag = root.getCompoundTag(TAG_ROOT); + } else { + attrTag = new NBTTagCompound(); + } + attrTag.setDouble(attributeKey, value); + root.setTag(TAG_ROOT, attrTag); + } + + public static Map readAttributes(ItemStack item) { + Map map = new HashMap<>(); + if(item == null || item.stackTagCompound == null) return map; + NBTTagCompound root = item.stackTagCompound; + if(root.hasKey(TAG_ROOT)) { + NBTTagCompound attrTag = root.getCompoundTag(TAG_ROOT); + Set keys = attrTag.func_150296_c(); + for(String key : keys) { + map.put(key, attrTag.getDouble(key)); + } + } + return map; + } + + public static Map readMagicAttributeMap(ItemStack item, String attributeTag) { + Map map = new HashMap<>(); + if(item == null || item.stackTagCompound == null) return map; + if(item.stackTagCompound.hasKey(attributeTag)) { + NBTTagCompound magicMap = item.stackTagCompound.getCompoundTag(attributeTag); + Set keys = magicMap.func_150296_c(); + for(String key : keys) { + try { + int magicId = Integer.parseInt(key); + map.put(magicId, magicMap.getDouble(key)); + } catch(NumberFormatException e) { + // Skip invalid key. + } + } + } + return map; + } + + public static void writeMagicAttribute(ItemStack item, String attributeTag, int magicId, double value) { + if(item == null) return; + if(item.stackTagCompound == null) + item.stackTagCompound = new NBTTagCompound(); + NBTTagCompound magicMap; + if(item.stackTagCompound.hasKey(attributeTag)) { + magicMap = item.stackTagCompound.getCompoundTag(attributeTag); + } else { + magicMap = new NBTTagCompound(); + } + magicMap.setDouble(String.valueOf(magicId), value); + item.stackTagCompound.setTag(attributeTag, magicMap); + } +} diff --git a/src/main/java/noppes/npcs/attribute/CustomAttributeMap.java b/src/main/java/noppes/npcs/attribute/CustomAttributeMap.java new file mode 100644 index 000000000..bc8d8780a --- /dev/null +++ b/src/main/java/noppes/npcs/attribute/CustomAttributeMap.java @@ -0,0 +1,29 @@ +package noppes.npcs.attribute; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +/** + * Holds a collection of attribute instances (for a weapon, item, or aggregated for a player). + */ +public class CustomAttributeMap { + private final Map map = new HashMap<>(); + + public IAttributeInstance registerAttribute(AttributeDefinition attribute, double baseValue) { + if (map.containsKey(attribute)) { + throw new IllegalArgumentException("Attribute already registered: " + attribute.getKey()); + } + IAttributeInstance instance = new ModifiableAttributeInstance(attribute, baseValue); + map.put(attribute, instance); + return instance; + } + + public IAttributeInstance getAttributeInstance(AttributeDefinition attribute) { + return map.get(attribute); + } + + public Collection getAllAttributes() { + return map.values(); + } +} diff --git a/src/main/java/noppes/npcs/attribute/DamageCalculator.java b/src/main/java/noppes/npcs/attribute/DamageCalculator.java new file mode 100644 index 000000000..c8258b20c --- /dev/null +++ b/src/main/java/noppes/npcs/attribute/DamageCalculator.java @@ -0,0 +1,59 @@ +package noppes.npcs.attribute; + +import java.util.Map; +import java.util.Random; +import java.util.Collection; +import net.minecraft.item.ItemStack; + +/** + * Calculates a weapon’s total damage against an armor set. + * It reads the weapon’s main attack (flat and percent) plus any magic-based attributes. + * Then applies a critical chance (if the random roll is below the crit chance, + * the damage is doubled and a flat crit bonus is added). + */ +public class DamageCalculator { + private static final Random random = new Random(); + + public static double calculateTotalDamage(ItemStack weapon, Collection armorSet) { + // Read non-magic weapon attributes: + Map weaponAttrs = CNPCItemAttributeHelper.readAttributes(weapon); + double mainFlat = weaponAttrs.getOrDefault("cnpc:main_attack_flat", 0.0); + double mainPercent = weaponAttrs.getOrDefault("cnpc:main_attack_percent", 0.0); + double baseDamage = mainFlat * (1 + mainPercent); + + double totalMagicDamage = 0.0; + Map weaponMagicFlat = CNPCItemAttributeHelper.readMagicAttributeMap(weapon, "cnpc:magic_damage_flat"); + Map weaponMagicPercent = CNPCItemAttributeHelper.readMagicAttributeMap(weapon, "cnpc:magic_damage_percent"); + + for(Map.Entry entry : weaponMagicFlat.entrySet()) { + int magicId = entry.getKey(); + double flat = entry.getValue(); + double percent = weaponMagicPercent.getOrDefault(magicId, 0.0); + double weaponMagicDamage = flat * (1 + percent); + + // Aggregate defenses from all armor pieces for this magic. + double armorMagicDefense = 0.0; + double armorMagicResistance = 0.0; + for(ItemStack armor : armorSet) { + Map armorDefFlat = CNPCItemAttributeHelper.readMagicAttributeMap(armor, "cnpc:magic_defense_flat"); + Map armorResistPercent = CNPCItemAttributeHelper.readMagicAttributeMap(armor, "cnpc:magic_resistance_percent"); + armorMagicDefense += armorDefFlat.getOrDefault(magicId, 0.0); + armorMagicResistance += armorResistPercent.getOrDefault(magicId, 0.0); + } + double effectiveMagicDamage = weaponMagicDamage - armorMagicDefense; + effectiveMagicDamage *= (1 - armorMagicResistance); + if(effectiveMagicDamage < 0) effectiveMagicDamage = 0; + totalMagicDamage += effectiveMagicDamage; + } + + double totalDamage = baseDamage + totalMagicDamage; + + // Process critical hit chance. + double critChance = weaponAttrs.getOrDefault("cnpc:critical_chance_percent", 0.0); + double critBonus = weaponAttrs.getOrDefault("cnpc:critical_damage_flat", 0.0); + if(random.nextDouble() < critChance) { + totalDamage = totalDamage * 2 + critBonus; + } + return Math.max(totalDamage, 0); + } +} diff --git a/src/main/java/noppes/npcs/attribute/IAttributeInstance.java b/src/main/java/noppes/npcs/attribute/IAttributeInstance.java new file mode 100644 index 000000000..67bab94b5 --- /dev/null +++ b/src/main/java/noppes/npcs/attribute/IAttributeInstance.java @@ -0,0 +1,17 @@ +package noppes.npcs.attribute; + +import java.util.Collection; + +/** + * Represents an attribute instance – a value (plus any applied modifiers) + * corresponding to a given AttributeDefinition. + */ +public interface IAttributeInstance { + AttributeDefinition getAttribute(); + double getBaseValue(); + void setBaseValue(double value); + void applyModifier(AttributeModifier modifier); + void removeModifier(AttributeModifier modifier); + Collection getModifiers(); + double getAttributeValue(); // Final value after modifiers. +} diff --git a/src/main/java/noppes/npcs/attribute/ModAttributes.java b/src/main/java/noppes/npcs/attribute/ModAttributes.java new file mode 100644 index 000000000..f533d755f --- /dev/null +++ b/src/main/java/noppes/npcs/attribute/ModAttributes.java @@ -0,0 +1,21 @@ +package noppes.npcs.attribute; + +/** + * Registers core (non‑magic) attribute definitions. + * For example, main attack damage, health, critical chance, etc. + */ +public class ModAttributes { + public static final AttributeDefinition MAIN_ATTACK_FLAT; + public static final AttributeDefinition MAIN_ATTACK_PERCENT; + public static final AttributeDefinition HEALTH; + public static final AttributeDefinition CRITICAL_CHANCE_PERCENT; + public static final AttributeDefinition CRITICAL_DAMAGE_FLAT; + + static { + MAIN_ATTACK_FLAT = AttributeController.registerAttribute("cnpc:main_attack_flat", "Main Attack Damage (Flat)", Operation.FLAT); + MAIN_ATTACK_PERCENT = AttributeController.registerAttribute("cnpc:main_attack_percent", "Main Attack Damage (%)", Operation.PERCENT); + HEALTH = AttributeController.registerAttribute("cnpc:health", "Health", Operation.FLAT); + CRITICAL_CHANCE_PERCENT = AttributeController.registerAttribute("cnpc:critical_chance_percent", "Critical Chance (%)", Operation.PERCENT); + CRITICAL_DAMAGE_FLAT = AttributeController.registerAttribute("cnpc:critical_damage_flat", "Critical Damage Bonus (Flat)", Operation.FLAT); + } +} diff --git a/src/main/java/noppes/npcs/attribute/ModifiableAttributeInstance.java b/src/main/java/noppes/npcs/attribute/ModifiableAttributeInstance.java new file mode 100644 index 000000000..6fa459283 --- /dev/null +++ b/src/main/java/noppes/npcs/attribute/ModifiableAttributeInstance.java @@ -0,0 +1,66 @@ +package noppes.npcs.attribute; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +public class ModifiableAttributeInstance implements IAttributeInstance { + private final AttributeDefinition attribute; + private double baseValue; + private final Set modifiers = new HashSet<>(); + + public ModifiableAttributeInstance(AttributeDefinition attribute, double baseValue) { + this.attribute = attribute; + this.baseValue = baseValue; + } + + @Override + public AttributeDefinition getAttribute() { + return attribute; + } + + @Override + public double getBaseValue() { + return baseValue; + } + + @Override + public void setBaseValue(double value) { + this.baseValue = value; + } + + @Override + public void applyModifier(AttributeModifier modifier) { + modifiers.add(modifier); + } + + @Override + public void removeModifier(AttributeModifier modifier) { + modifiers.remove(modifier); + } + + @Override + public Collection getModifiers() { + return modifiers; + } + + @Override + public double getAttributeValue() { + double finalValue = baseValue; + // Apply flat modifiers first: + for (AttributeModifier mod : modifiers) { + if (mod.getOperation() == Operation.FLAT) { + finalValue += mod.getAmount(); + } + } + // Then apply percentage modifiers additively: + double percentSum = 0; + for (AttributeModifier mod : modifiers) { + if (mod.getOperation() == Operation.PERCENT) { + percentSum += mod.getAmount(); + } + } + finalValue *= (1 + percentSum); + return finalValue; + } +} diff --git a/src/main/java/noppes/npcs/attribute/Operation.java b/src/main/java/noppes/npcs/attribute/Operation.java new file mode 100644 index 000000000..6f5d5f0b3 --- /dev/null +++ b/src/main/java/noppes/npcs/attribute/Operation.java @@ -0,0 +1,6 @@ +package noppes.npcs.attribute; + +public enum Operation { + FLAT, // e.g., +10 Health or +3 Damage + PERCENT // e.g., +0.25 means +25% bonus +} diff --git a/src/main/java/noppes/npcs/attribute/PlayerAttributeManager.java b/src/main/java/noppes/npcs/attribute/PlayerAttributeManager.java new file mode 100644 index 000000000..08adb8e91 --- /dev/null +++ b/src/main/java/noppes/npcs/attribute/PlayerAttributeManager.java @@ -0,0 +1,31 @@ +package noppes.npcs.attribute; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import net.minecraft.entity.player.EntityPlayer; + +/** + * Central manager mapping player UUIDs to their attribute trackers. + */ +public class PlayerAttributeManager { + private static final Map trackers = new HashMap<>(); + + public static PlayerAttributeTracker getTracker(UUID playerId) { + return trackers.computeIfAbsent(playerId, id -> new PlayerAttributeTracker(id)); + } + + public static void removeTracker(UUID playerId) { + trackers.remove(playerId); + } + + /** + * Should be called every 10 ticks for all online players. + */ + public static void updateAllTrackers(Iterable players) { + for (EntityPlayer player : players) { + PlayerAttributeTracker tracker = getTracker(player.getUniqueID()); + tracker.updateIfChanged(player); + } + } +} diff --git a/src/main/java/noppes/npcs/attribute/PlayerAttributeTickHandler.java b/src/main/java/noppes/npcs/attribute/PlayerAttributeTickHandler.java new file mode 100644 index 000000000..5c7960251 --- /dev/null +++ b/src/main/java/noppes/npcs/attribute/PlayerAttributeTickHandler.java @@ -0,0 +1,21 @@ +package noppes.npcs.attribute; + +import net.minecraft.server.MinecraftServer; +import net.minecraft.entity.player.EntityPlayer; + +/** + * Tick handler that runs every tick and, every 10 ticks, checks all players for equipment changes. + */ +public class PlayerAttributeTickHandler { + private int tickCount = 0; + + public void onTick() { + tickCount++; + if (tickCount % 10 == 0) { + for (Object o : MinecraftServer.getServer().getConfigurationManager().playerEntityList) { + EntityPlayer player = (EntityPlayer) o; + PlayerAttributeManager.getTracker(player.getUniqueID()).updateIfChanged(player); + } + } + } +} diff --git a/src/main/java/noppes/npcs/attribute/PlayerAttributeTracker.java b/src/main/java/noppes/npcs/attribute/PlayerAttributeTracker.java new file mode 100644 index 000000000..9b9505f75 --- /dev/null +++ b/src/main/java/noppes/npcs/attribute/PlayerAttributeTracker.java @@ -0,0 +1,118 @@ +package noppes.npcs.attribute; + +import java.util.UUID; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import java.util.Map; + +/** + * A tracker that holds a cached aggregation of a player’s attributes (derived from their held item and armor). + * It does not “own” the attributes but recalculates them when equipment changes. + * A simple snapshot of equipment is used to detect changes. + */ +public class PlayerAttributeTracker { + private final UUID playerId; + private CustomAttributeMap aggregatedAttributes = new CustomAttributeMap(); + private String equipmentSnapshot = ""; + + public PlayerAttributeTracker(UUID playerId) { + this.playerId = playerId; + recalcAttributes(null); + } + + public CustomAttributeMap getAggregatedAttributes() { + return aggregatedAttributes; + } + + /** + * Computes a snapshot string representing current equipment. + * For simplicity, concatenates item class names and damage values. + */ + private String computeEquipmentSnapshot(EntityPlayer player) { + StringBuilder sb = new StringBuilder(); + ItemStack held = player.getHeldItem(); + if(held != null) { + sb.append(held.getItem().toString()).append(held.getItemDamage()); + } + for (ItemStack armor : player.inventory.armorInventory) { + if(armor != null) { + sb.append(armor.getItem().toString()).append(armor.getItemDamage()); + } + } + return sb.toString(); + } + + /** + * Recalculates the aggregated attribute map from the player's equipment. + */ + public void recalcAttributes(EntityPlayer player) { + CustomAttributeMap newMap = new CustomAttributeMap(); + // Register base (non-magic) attributes with default values. + newMap.registerAttribute(ModAttributes.MAIN_ATTACK_FLAT, 0.0); + newMap.registerAttribute(ModAttributes.MAIN_ATTACK_PERCENT, 0.0); + newMap.registerAttribute(ModAttributes.HEALTH, 20.0); + newMap.registerAttribute(ModAttributes.CRITICAL_CHANCE_PERCENT, 0.0); + newMap.registerAttribute(ModAttributes.CRITICAL_DAMAGE_FLAT, 0.0); + + if(player != null) { + // Process held item: + ItemStack held = player.getHeldItem(); + if(held != null) { + for (Map.Entry entry : CNPCItemAttributeHelper.readAttributes(held).entrySet()) { + String key = entry.getKey(); + double value = entry.getValue(); + if("cnpc:main_attack_flat".equals(key)) { + IAttributeInstance inst = newMap.getAttributeInstance(ModAttributes.MAIN_ATTACK_FLAT); + inst.setBaseValue(inst.getBaseValue() + value); + } else if("cnpc:main_attack_percent".equals(key)) { + IAttributeInstance inst = newMap.getAttributeInstance(ModAttributes.MAIN_ATTACK_PERCENT); + inst.setBaseValue(inst.getBaseValue() + value); + } else if("cnpc:critical_chance_percent".equals(key)) { + IAttributeInstance inst = newMap.getAttributeInstance(ModAttributes.CRITICAL_CHANCE_PERCENT); + inst.setBaseValue(inst.getBaseValue() + value); + } else if("cnpc:critical_damage_flat".equals(key)) { + IAttributeInstance inst = newMap.getAttributeInstance(ModAttributes.CRITICAL_DAMAGE_FLAT); + inst.setBaseValue(inst.getBaseValue() + value); + } + } + } + // Process armor pieces: + for (ItemStack armor : player.inventory.armorInventory) { + if(armor != null) { + for (Map.Entry entry : CNPCItemAttributeHelper.readAttributes(armor).entrySet()) { + String key = entry.getKey(); + double value = entry.getValue(); + if("cnpc:main_attack_flat".equals(key)) { + IAttributeInstance inst = newMap.getAttributeInstance(ModAttributes.MAIN_ATTACK_FLAT); + inst.setBaseValue(inst.getBaseValue() + value); + } else if("cnpc:main_attack_percent".equals(key)) { + IAttributeInstance inst = newMap.getAttributeInstance(ModAttributes.MAIN_ATTACK_PERCENT); + inst.setBaseValue(inst.getBaseValue() + value); + } else if("cnpc:health".equals(key)) { + IAttributeInstance inst = newMap.getAttributeInstance(ModAttributes.HEALTH); + inst.setBaseValue(inst.getBaseValue() + value); + } + } + } + } + } + aggregatedAttributes = newMap; + } + + /** + * Checks if the player's equipment has changed (by comparing a snapshot) and recalculates if needed. + * This should be called every 10 ticks. + */ + public void updateIfChanged(EntityPlayer player) { + String currentSnapshot = computeEquipmentSnapshot(player); + if (!currentSnapshot.equals(equipmentSnapshot)) { + equipmentSnapshot = currentSnapshot; + recalcAttributes(player); + } + } + + public double getAttributeValue(AttributeDefinition def) { + IAttributeInstance inst = aggregatedAttributes.getAttributeInstance(def); + return inst != null ? inst.getAttributeValue() : 0.0; + } +} From 3d90ddab46ab8231094d3fd8b571f38fd74fd1b3 Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 24 Feb 2025 19:43:40 -0500 Subject: [PATCH 55/59] Renaming --- .../noppes/npcs/attribute/AttributeController.java | 2 +- .../noppes/npcs/attribute/AttributeDefinition.java | 10 +++++----- .../java/noppes/npcs/attribute/AttributeModifier.java | 10 +++++----- .../{Operation.java => AttributeValueType.java} | 2 +- src/main/java/noppes/npcs/attribute/ModAttributes.java | 10 +++++----- .../npcs/attribute/ModifiableAttributeInstance.java | 4 ++-- 6 files changed, 19 insertions(+), 19 deletions(-) rename src/main/java/noppes/npcs/attribute/{Operation.java => AttributeValueType.java} (79%) diff --git a/src/main/java/noppes/npcs/attribute/AttributeController.java b/src/main/java/noppes/npcs/attribute/AttributeController.java index 4e4ffbb5d..516620796 100644 --- a/src/main/java/noppes/npcs/attribute/AttributeController.java +++ b/src/main/java/noppes/npcs/attribute/AttributeController.java @@ -13,7 +13,7 @@ public class AttributeController { private static final Map definitions = new HashMap<>(); private static int nextId = 0; - public static AttributeDefinition registerAttribute(String key, String displayName, Operation op) { + public static AttributeDefinition registerAttribute(String key, String displayName, AttributeValueType op) { if (definitions.containsKey(key)) { return definitions.get(key); } diff --git a/src/main/java/noppes/npcs/attribute/AttributeDefinition.java b/src/main/java/noppes/npcs/attribute/AttributeDefinition.java index 5ba597661..9657d1572 100644 --- a/src/main/java/noppes/npcs/attribute/AttributeDefinition.java +++ b/src/main/java/noppes/npcs/attribute/AttributeDefinition.java @@ -9,13 +9,13 @@ public class AttributeDefinition { private final int id; private final String key; // e.g., "cnpc:main_attack_flat" private final String displayName; // Human‑readable name - private final Operation operation; + private final AttributeValueType attributeValueType; - public AttributeDefinition(int id, String key, String displayName, Operation operation) { + public AttributeDefinition(int id, String key, String displayName, AttributeValueType attributeValueType) { this.id = id; this.key = key; this.displayName = displayName; - this.operation = operation; + this.attributeValueType = attributeValueType; } public int getId() { @@ -30,7 +30,7 @@ public class AttributeDefinition { return displayName; } - public Operation getOperation() { - return operation; + public AttributeValueType getOperation() { + return attributeValueType; } } diff --git a/src/main/java/noppes/npcs/attribute/AttributeModifier.java b/src/main/java/noppes/npcs/attribute/AttributeModifier.java index 9f821283f..9401f93c7 100644 --- a/src/main/java/noppes/npcs/attribute/AttributeModifier.java +++ b/src/main/java/noppes/npcs/attribute/AttributeModifier.java @@ -11,13 +11,13 @@ public class AttributeModifier { private final UUID id; private final String name; private final double amount; - private final Operation operation; + private final AttributeValueType attributeValueType; - public AttributeModifier(UUID id, String name, double amount, Operation operation) { + public AttributeModifier(UUID id, String name, double amount, AttributeValueType attributeValueType) { this.id = id; this.name = name; this.amount = amount; - this.operation = operation; + this.attributeValueType = attributeValueType; } public UUID getId() { @@ -32,7 +32,7 @@ public class AttributeModifier { return amount; } - public Operation getOperation() { - return operation; + public AttributeValueType getOperation() { + return attributeValueType; } } diff --git a/src/main/java/noppes/npcs/attribute/Operation.java b/src/main/java/noppes/npcs/attribute/AttributeValueType.java similarity index 79% rename from src/main/java/noppes/npcs/attribute/Operation.java rename to src/main/java/noppes/npcs/attribute/AttributeValueType.java index 6f5d5f0b3..6fa3b7ca7 100644 --- a/src/main/java/noppes/npcs/attribute/Operation.java +++ b/src/main/java/noppes/npcs/attribute/AttributeValueType.java @@ -1,6 +1,6 @@ package noppes.npcs.attribute; -public enum Operation { +public enum AttributeValueType { FLAT, // e.g., +10 Health or +3 Damage PERCENT // e.g., +0.25 means +25% bonus } diff --git a/src/main/java/noppes/npcs/attribute/ModAttributes.java b/src/main/java/noppes/npcs/attribute/ModAttributes.java index f533d755f..4cc11339e 100644 --- a/src/main/java/noppes/npcs/attribute/ModAttributes.java +++ b/src/main/java/noppes/npcs/attribute/ModAttributes.java @@ -12,10 +12,10 @@ public class ModAttributes { public static final AttributeDefinition CRITICAL_DAMAGE_FLAT; static { - MAIN_ATTACK_FLAT = AttributeController.registerAttribute("cnpc:main_attack_flat", "Main Attack Damage (Flat)", Operation.FLAT); - MAIN_ATTACK_PERCENT = AttributeController.registerAttribute("cnpc:main_attack_percent", "Main Attack Damage (%)", Operation.PERCENT); - HEALTH = AttributeController.registerAttribute("cnpc:health", "Health", Operation.FLAT); - CRITICAL_CHANCE_PERCENT = AttributeController.registerAttribute("cnpc:critical_chance_percent", "Critical Chance (%)", Operation.PERCENT); - CRITICAL_DAMAGE_FLAT = AttributeController.registerAttribute("cnpc:critical_damage_flat", "Critical Damage Bonus (Flat)", Operation.FLAT); + MAIN_ATTACK_FLAT = AttributeController.registerAttribute("cnpc:main_attack_flat", "Main Attack Damage (Flat)", AttributeValueType.FLAT); + MAIN_ATTACK_PERCENT = AttributeController.registerAttribute("cnpc:main_attack_percent", "Main Attack Damage (%)", AttributeValueType.PERCENT); + HEALTH = AttributeController.registerAttribute("cnpc:health", "Health", AttributeValueType.FLAT); + CRITICAL_CHANCE_PERCENT = AttributeController.registerAttribute("cnpc:critical_chance_percent", "Critical Chance (%)", AttributeValueType.PERCENT); + CRITICAL_DAMAGE_FLAT = AttributeController.registerAttribute("cnpc:critical_damage_flat", "Critical Damage Bonus (Flat)", AttributeValueType.FLAT); } } diff --git a/src/main/java/noppes/npcs/attribute/ModifiableAttributeInstance.java b/src/main/java/noppes/npcs/attribute/ModifiableAttributeInstance.java index 6fa459283..2a2344236 100644 --- a/src/main/java/noppes/npcs/attribute/ModifiableAttributeInstance.java +++ b/src/main/java/noppes/npcs/attribute/ModifiableAttributeInstance.java @@ -49,14 +49,14 @@ public class ModifiableAttributeInstance implements IAttributeInstance { double finalValue = baseValue; // Apply flat modifiers first: for (AttributeModifier mod : modifiers) { - if (mod.getOperation() == Operation.FLAT) { + if (mod.getOperation() == AttributeValueType.FLAT) { finalValue += mod.getAmount(); } } // Then apply percentage modifiers additively: double percentSum = 0; for (AttributeModifier mod : modifiers) { - if (mod.getOperation() == Operation.PERCENT) { + if (mod.getOperation() == AttributeValueType.PERCENT) { percentSum += mod.getAmount(); } } From 865978a97179658829a3116c6cfcf8b9baf9bd19 Mon Sep 17 00:00:00 2001 From: Kam Date: Mon, 24 Feb 2025 20:07:32 -0500 Subject: [PATCH 56/59] Another Attribute Refactor --- .../npcs/attribute/AttributeController.java | 12 +- .../noppes/npcs/attribute/AttributeKeys.java | 17 ++ .../npcs/attribute/AttributeModifier.java | 15 +- .../npcs/attribute/AttributeValueType.java | 5 +- .../attribute/CNPCItemAttributeHelper.java | 33 ++-- .../npcs/attribute/CustomAttributeMap.java | 2 +- .../npcs/attribute/DamageCalculator.java | 70 +++----- .../npcs/attribute/IAttributeInstance.java | 5 +- .../noppes/npcs/attribute/ModAttributes.java | 23 ++- .../ModifiableAttributeInstance.java | 10 +- .../attribute/PlayerAttributeManager.java | 4 +- .../attribute/PlayerAttributeTickHandler.java | 3 +- .../attribute/PlayerAttributeTracker.java | 169 ++++++++++++++---- 13 files changed, 234 insertions(+), 134 deletions(-) create mode 100644 src/main/java/noppes/npcs/attribute/AttributeKeys.java diff --git a/src/main/java/noppes/npcs/attribute/AttributeController.java b/src/main/java/noppes/npcs/attribute/AttributeController.java index 516620796..505062895 100644 --- a/src/main/java/noppes/npcs/attribute/AttributeController.java +++ b/src/main/java/noppes/npcs/attribute/AttributeController.java @@ -5,19 +5,17 @@ import java.util.HashMap; import java.util.Map; /** - * Central registry for valid attribute definitions. - * Other mods can register new attributes here so that items only need to store a - * small namespaced key. + * AttributeController is the central registry for attribute definitions. + * It ensures that keys are unique. */ public class AttributeController { private static final Map definitions = new HashMap<>(); - private static int nextId = 0; - public static AttributeDefinition registerAttribute(String key, String displayName, AttributeValueType op) { + public static AttributeDefinition registerAttribute(String key, String displayName, AttributeValueType valueType) { if (definitions.containsKey(key)) { - return definitions.get(key); + throw new IllegalArgumentException("Attribute already registered with key: " + key); } - AttributeDefinition def = new AttributeDefinition(nextId++, key, displayName, op); + AttributeDefinition def = new AttributeDefinition(key, displayName, valueType); definitions.put(key, def); return def; } diff --git a/src/main/java/noppes/npcs/attribute/AttributeKeys.java b/src/main/java/noppes/npcs/attribute/AttributeKeys.java new file mode 100644 index 000000000..5707a770a --- /dev/null +++ b/src/main/java/noppes/npcs/attribute/AttributeKeys.java @@ -0,0 +1,17 @@ +package noppes.npcs.attribute; + +public final class AttributeKeys { + public static final String MAIN_ATTACK_FLAT = "cnpc:main_attack_flat"; + public static final String MAIN_ATTACK_PERCENT = "cnpc:main_attack_percent"; + public static final String HEALTH = "cnpc:health"; + public static final String CRITICAL_CHANCE_PERCENT = "cnpc:critical_chance_percent"; + public static final String CRITICAL_DAMAGE_FLAT = "cnpc:critical_damage_flat"; + + // Magic–based attribute keys: + public static final String MAGIC_DAMAGE_FLAT = "cnpc:magic_damage_flat"; + public static final String MAGIC_DAMAGE_PERCENT = "cnpc:magic_damage_percent"; + public static final String MAGIC_DEFENSE_FLAT = "cnpc:magic_defense_flat"; + public static final String MAGIC_RESISTANCE_PERCENT = "cnpc:magic_resistance_percent"; + + private AttributeKeys() { } +} diff --git a/src/main/java/noppes/npcs/attribute/AttributeModifier.java b/src/main/java/noppes/npcs/attribute/AttributeModifier.java index 9401f93c7..ccaed7c15 100644 --- a/src/main/java/noppes/npcs/attribute/AttributeModifier.java +++ b/src/main/java/noppes/npcs/attribute/AttributeModifier.java @@ -3,21 +3,20 @@ package noppes.npcs.attribute; import java.util.UUID; /** - * An AttributeModifier represents a bonus or penalty that’s applied to an attribute. - * It stores a unique UUID, a name, an amount, and whether it is FLAT (added directly) - * or PERCENT (applied as a multiplier) to the base value. + * An AttributeModifier represents a bonus (or penalty) that is applied to an attribute. + * It carries a UUID, a human–readable name, an amount, and a type (FLAT, PERCENT, etc). */ public class AttributeModifier { private final UUID id; private final String name; private final double amount; - private final AttributeValueType attributeValueType; + private final AttributeValueType valueType; - public AttributeModifier(UUID id, String name, double amount, AttributeValueType attributeValueType) { + public AttributeModifier(UUID id, String name, double amount, AttributeValueType valueType) { this.id = id; this.name = name; this.amount = amount; - this.attributeValueType = attributeValueType; + this.valueType = valueType; } public UUID getId() { @@ -32,7 +31,7 @@ public class AttributeModifier { return amount; } - public AttributeValueType getOperation() { - return attributeValueType; + public AttributeValueType getValueType() { + return valueType; } } diff --git a/src/main/java/noppes/npcs/attribute/AttributeValueType.java b/src/main/java/noppes/npcs/attribute/AttributeValueType.java index 6fa3b7ca7..26c35b6ff 100644 --- a/src/main/java/noppes/npcs/attribute/AttributeValueType.java +++ b/src/main/java/noppes/npcs/attribute/AttributeValueType.java @@ -1,6 +1,7 @@ package noppes.npcs.attribute; public enum AttributeValueType { - FLAT, // e.g., +10 Health or +3 Damage - PERCENT // e.g., +0.25 means +25% bonus + FLAT, // e.g., +10 Health or +3 Damage + PERCENT, // e.g., +0.25 means +25% bonus + MAGIC // Represents a container of magic–based values (summed up as a double) } diff --git a/src/main/java/noppes/npcs/attribute/CNPCItemAttributeHelper.java b/src/main/java/noppes/npcs/attribute/CNPCItemAttributeHelper.java index 44b286773..02a38b4eb 100644 --- a/src/main/java/noppes/npcs/attribute/CNPCItemAttributeHelper.java +++ b/src/main/java/noppes/npcs/attribute/CNPCItemAttributeHelper.java @@ -7,22 +7,21 @@ import java.util.HashMap; import java.util.Map; /** - * Handles writing/reading item attributes. - * Non‑magic attributes are stored under a "CNPCAttributes" tag. - * Magic-based attributes are stored as a compound mapping magic ID to value, - * for example under "cnpc:magic_damage_flat". + * Provides helper functions to write/read item attributes to/from NBT. + * Non–magic attributes are stored under a compound tag (TAG_ROOT), + * and magic attributes are stored as a compound mapping (by magic ID) under specific keys. */ public class CNPCItemAttributeHelper { public static final String TAG_ROOT = "CNPCAttributes"; public static void applyAttribute(ItemStack item, String attributeKey, double value) { - if(item == null) return; - if(item.stackTagCompound == null) { + if (item == null) return; + if (item.stackTagCompound == null) { item.stackTagCompound = new NBTTagCompound(); } NBTTagCompound root = item.stackTagCompound; NBTTagCompound attrTag; - if(root.hasKey(TAG_ROOT)) { + if (root.hasKey(TAG_ROOT)) { attrTag = root.getCompoundTag(TAG_ROOT); } else { attrTag = new NBTTagCompound(); @@ -33,12 +32,12 @@ public class CNPCItemAttributeHelper { public static Map readAttributes(ItemStack item) { Map map = new HashMap<>(); - if(item == null || item.stackTagCompound == null) return map; + if (item == null || item.stackTagCompound == null) return map; NBTTagCompound root = item.stackTagCompound; - if(root.hasKey(TAG_ROOT)) { + if (root.hasKey(TAG_ROOT)) { NBTTagCompound attrTag = root.getCompoundTag(TAG_ROOT); Set keys = attrTag.func_150296_c(); - for(String key : keys) { + for (String key : keys) { map.put(key, attrTag.getDouble(key)); } } @@ -47,15 +46,15 @@ public class CNPCItemAttributeHelper { public static Map readMagicAttributeMap(ItemStack item, String attributeTag) { Map map = new HashMap<>(); - if(item == null || item.stackTagCompound == null) return map; - if(item.stackTagCompound.hasKey(attributeTag)) { + if (item == null || item.stackTagCompound == null) return map; + if (item.stackTagCompound.hasKey(attributeTag)) { NBTTagCompound magicMap = item.stackTagCompound.getCompoundTag(attributeTag); Set keys = magicMap.func_150296_c(); - for(String key : keys) { + for (String key : keys) { try { int magicId = Integer.parseInt(key); map.put(magicId, magicMap.getDouble(key)); - } catch(NumberFormatException e) { + } catch (NumberFormatException e) { // Skip invalid key. } } @@ -64,11 +63,11 @@ public class CNPCItemAttributeHelper { } public static void writeMagicAttribute(ItemStack item, String attributeTag, int magicId, double value) { - if(item == null) return; - if(item.stackTagCompound == null) + if (item == null) return; + if (item.stackTagCompound == null) item.stackTagCompound = new NBTTagCompound(); NBTTagCompound magicMap; - if(item.stackTagCompound.hasKey(attributeTag)) { + if (item.stackTagCompound.hasKey(attributeTag)) { magicMap = item.stackTagCompound.getCompoundTag(attributeTag); } else { magicMap = new NBTTagCompound(); diff --git a/src/main/java/noppes/npcs/attribute/CustomAttributeMap.java b/src/main/java/noppes/npcs/attribute/CustomAttributeMap.java index bc8d8780a..be4edecff 100644 --- a/src/main/java/noppes/npcs/attribute/CustomAttributeMap.java +++ b/src/main/java/noppes/npcs/attribute/CustomAttributeMap.java @@ -5,7 +5,7 @@ import java.util.HashMap; import java.util.Map; /** - * Holds a collection of attribute instances (for a weapon, item, or aggregated for a player). + * CustomAttributeMap holds a set of attribute instances for an entity (or item). */ public class CustomAttributeMap { private final Map map = new HashMap<>(); diff --git a/src/main/java/noppes/npcs/attribute/DamageCalculator.java b/src/main/java/noppes/npcs/attribute/DamageCalculator.java index c8258b20c..d776b1929 100644 --- a/src/main/java/noppes/npcs/attribute/DamageCalculator.java +++ b/src/main/java/noppes/npcs/attribute/DamageCalculator.java @@ -1,59 +1,39 @@ package noppes.npcs.attribute; -import java.util.Map; import java.util.Random; -import java.util.Collection; -import net.minecraft.item.ItemStack; /** - * Calculates a weapon’s total damage against an armor set. - * It reads the weapon’s main attack (flat and percent) plus any magic-based attributes. - * Then applies a critical chance (if the random roll is below the crit chance, - * the damage is doubled and a flat crit bonus is added). + * Calculates damage using cached (aggregated) offensive and defensive ratings from players. + * The formula here is simple: baseDamage = attacker.getOffense() - defender.getDefense(), + * then a critical chance is applied (if a random roll is below the attacker's crit chance, + * damage is doubled and a flat crit bonus is added). */ public class DamageCalculator { private static final Random random = new Random(); - public static double calculateTotalDamage(ItemStack weapon, Collection armorSet) { - // Read non-magic weapon attributes: - Map weaponAttrs = CNPCItemAttributeHelper.readAttributes(weapon); - double mainFlat = weaponAttrs.getOrDefault("cnpc:main_attack_flat", 0.0); - double mainPercent = weaponAttrs.getOrDefault("cnpc:main_attack_percent", 0.0); - double baseDamage = mainFlat * (1 + mainPercent); + /** + * Calculates damage given attacker and defender attribute trackers. + */ + public static double calculateDamage(PlayerAttributeTracker attacker, PlayerAttributeTracker defender) { + double offense = attacker.getOffense(); + double defense = defender.getDefense(); + double damage = offense - defense; - double totalMagicDamage = 0.0; - Map weaponMagicFlat = CNPCItemAttributeHelper.readMagicAttributeMap(weapon, "cnpc:magic_damage_flat"); - Map weaponMagicPercent = CNPCItemAttributeHelper.readMagicAttributeMap(weapon, "cnpc:magic_damage_percent"); - - for(Map.Entry entry : weaponMagicFlat.entrySet()) { - int magicId = entry.getKey(); - double flat = entry.getValue(); - double percent = weaponMagicPercent.getOrDefault(magicId, 0.0); - double weaponMagicDamage = flat * (1 + percent); - - // Aggregate defenses from all armor pieces for this magic. - double armorMagicDefense = 0.0; - double armorMagicResistance = 0.0; - for(ItemStack armor : armorSet) { - Map armorDefFlat = CNPCItemAttributeHelper.readMagicAttributeMap(armor, "cnpc:magic_defense_flat"); - Map armorResistPercent = CNPCItemAttributeHelper.readMagicAttributeMap(armor, "cnpc:magic_resistance_percent"); - armorMagicDefense += armorDefFlat.getOrDefault(magicId, 0.0); - armorMagicResistance += armorResistPercent.getOrDefault(magicId, 0.0); - } - double effectiveMagicDamage = weaponMagicDamage - armorMagicDefense; - effectiveMagicDamage *= (1 - armorMagicResistance); - if(effectiveMagicDamage < 0) effectiveMagicDamage = 0; - totalMagicDamage += effectiveMagicDamage; + // Process critical hit chance from attacker's aggregated non-magic attributes. + double critChance = attacker.getAttributeValue(ModAttributes.CRITICAL_CHANCE_PERCENT); + double critBonus = attacker.getAttributeValue(ModAttributes.CRITICAL_DAMAGE_FLAT); + if (random.nextDouble() < critChance) { + damage = damage * 2 + critBonus; } + return Math.max(damage, 0); + } - double totalDamage = baseDamage + totalMagicDamage; - - // Process critical hit chance. - double critChance = weaponAttrs.getOrDefault("cnpc:critical_chance_percent", 0.0); - double critBonus = weaponAttrs.getOrDefault("cnpc:critical_damage_flat", 0.0); - if(random.nextDouble() < critChance) { - totalDamage = totalDamage * 2 + critBonus; - } - return Math.max(totalDamage, 0); + /** + * Optionally, calculates damage for a specific magic type. + */ + public static double calculateMagicDamage(PlayerAttributeTracker attacker, PlayerAttributeTracker defender, int magicId) { + double offense = attacker.getOffense(magicId); + double defense = defender.getDefense(magicId); + return Math.max(offense - defense, 0); } } diff --git a/src/main/java/noppes/npcs/attribute/IAttributeInstance.java b/src/main/java/noppes/npcs/attribute/IAttributeInstance.java index 67bab94b5..5aadb8efd 100644 --- a/src/main/java/noppes/npcs/attribute/IAttributeInstance.java +++ b/src/main/java/noppes/npcs/attribute/IAttributeInstance.java @@ -3,8 +3,7 @@ package noppes.npcs.attribute; import java.util.Collection; /** - * Represents an attribute instance – a value (plus any applied modifiers) - * corresponding to a given AttributeDefinition. + * IAttributeInstance represents an instance of an attribute (with a base value and applied modifiers). */ public interface IAttributeInstance { AttributeDefinition getAttribute(); @@ -13,5 +12,5 @@ public interface IAttributeInstance { void applyModifier(AttributeModifier modifier); void removeModifier(AttributeModifier modifier); Collection getModifiers(); - double getAttributeValue(); // Final value after modifiers. + double getAttributeValue(); // Final computed value after modifiers } diff --git a/src/main/java/noppes/npcs/attribute/ModAttributes.java b/src/main/java/noppes/npcs/attribute/ModAttributes.java index 4cc11339e..1000e8efe 100644 --- a/src/main/java/noppes/npcs/attribute/ModAttributes.java +++ b/src/main/java/noppes/npcs/attribute/ModAttributes.java @@ -1,8 +1,7 @@ package noppes.npcs.attribute; /** - * Registers core (non‑magic) attribute definitions. - * For example, main attack damage, health, critical chance, etc. + * ModAttributes registers the core attributes (both non–magic and magic–based). */ public class ModAttributes { public static final AttributeDefinition MAIN_ATTACK_FLAT; @@ -11,11 +10,21 @@ public class ModAttributes { public static final AttributeDefinition CRITICAL_CHANCE_PERCENT; public static final AttributeDefinition CRITICAL_DAMAGE_FLAT; + public static final AttributeDefinition MAGIC_DAMAGE_FLAT; + public static final AttributeDefinition MAGIC_DAMAGE_PERCENT; + public static final AttributeDefinition MAGIC_DEFENSE_FLAT; + public static final AttributeDefinition MAGIC_RESISTANCE_PERCENT; + static { - MAIN_ATTACK_FLAT = AttributeController.registerAttribute("cnpc:main_attack_flat", "Main Attack Damage (Flat)", AttributeValueType.FLAT); - MAIN_ATTACK_PERCENT = AttributeController.registerAttribute("cnpc:main_attack_percent", "Main Attack Damage (%)", AttributeValueType.PERCENT); - HEALTH = AttributeController.registerAttribute("cnpc:health", "Health", AttributeValueType.FLAT); - CRITICAL_CHANCE_PERCENT = AttributeController.registerAttribute("cnpc:critical_chance_percent", "Critical Chance (%)", AttributeValueType.PERCENT); - CRITICAL_DAMAGE_FLAT = AttributeController.registerAttribute("cnpc:critical_damage_flat", "Critical Damage Bonus (Flat)", AttributeValueType.FLAT); + MAIN_ATTACK_FLAT = AttributeController.registerAttribute(AttributeKeys.MAIN_ATTACK_FLAT, "Main Attack Damage (Flat)", AttributeValueType.FLAT); + MAIN_ATTACK_PERCENT = AttributeController.registerAttribute(AttributeKeys.MAIN_ATTACK_PERCENT, "Main Attack Damage (%)", AttributeValueType.PERCENT); + HEALTH = AttributeController.registerAttribute(AttributeKeys.HEALTH, "Health", AttributeValueType.FLAT); + CRITICAL_CHANCE_PERCENT = AttributeController.registerAttribute(AttributeKeys.CRITICAL_CHANCE_PERCENT, "Critical Chance (%)", AttributeValueType.PERCENT); + CRITICAL_DAMAGE_FLAT = AttributeController.registerAttribute(AttributeKeys.CRITICAL_DAMAGE_FLAT, "Critical Damage Bonus (Flat)", AttributeValueType.FLAT); + + MAGIC_DAMAGE_FLAT = AttributeController.registerAttribute(AttributeKeys.MAGIC_DAMAGE_FLAT, "Magic Damage (Flat)", AttributeValueType.MAGIC); + MAGIC_DAMAGE_PERCENT = AttributeController.registerAttribute(AttributeKeys.MAGIC_DAMAGE_PERCENT, "Magic Damage (%)", AttributeValueType.MAGIC); + MAGIC_DEFENSE_FLAT = AttributeController.registerAttribute(AttributeKeys.MAGIC_DEFENSE_FLAT, "Magic Defense (Flat)", AttributeValueType.MAGIC); + MAGIC_RESISTANCE_PERCENT = AttributeController.registerAttribute(AttributeKeys.MAGIC_RESISTANCE_PERCENT, "Magic Resistance (%)", AttributeValueType.MAGIC); } } diff --git a/src/main/java/noppes/npcs/attribute/ModifiableAttributeInstance.java b/src/main/java/noppes/npcs/attribute/ModifiableAttributeInstance.java index 2a2344236..5645165c3 100644 --- a/src/main/java/noppes/npcs/attribute/ModifiableAttributeInstance.java +++ b/src/main/java/noppes/npcs/attribute/ModifiableAttributeInstance.java @@ -47,16 +47,16 @@ public class ModifiableAttributeInstance implements IAttributeInstance { @Override public double getAttributeValue() { double finalValue = baseValue; - // Apply flat modifiers first: + // Apply FLAT modifiers for (AttributeModifier mod : modifiers) { - if (mod.getOperation() == AttributeValueType.FLAT) { + if (mod.getValueType() == AttributeValueType.FLAT) { finalValue += mod.getAmount(); } } - // Then apply percentage modifiers additively: - double percentSum = 0; + // Apply PERCENT modifiers additively. + double percentSum = 0.0; for (AttributeModifier mod : modifiers) { - if (mod.getOperation() == AttributeValueType.PERCENT) { + if (mod.getValueType() == AttributeValueType.PERCENT) { percentSum += mod.getAmount(); } } diff --git a/src/main/java/noppes/npcs/attribute/PlayerAttributeManager.java b/src/main/java/noppes/npcs/attribute/PlayerAttributeManager.java index 08adb8e91..9b6a3dbef 100644 --- a/src/main/java/noppes/npcs/attribute/PlayerAttributeManager.java +++ b/src/main/java/noppes/npcs/attribute/PlayerAttributeManager.java @@ -6,7 +6,7 @@ import java.util.UUID; import net.minecraft.entity.player.EntityPlayer; /** - * Central manager mapping player UUIDs to their attribute trackers. + * PlayerAttributeManager maps player UUIDs to their attribute trackers. */ public class PlayerAttributeManager { private static final Map trackers = new HashMap<>(); @@ -20,7 +20,7 @@ public class PlayerAttributeManager { } /** - * Should be called every 10 ticks for all online players. + * Update all trackers (e.g. called every 10 ticks for all online players). */ public static void updateAllTrackers(Iterable players) { for (EntityPlayer player : players) { diff --git a/src/main/java/noppes/npcs/attribute/PlayerAttributeTickHandler.java b/src/main/java/noppes/npcs/attribute/PlayerAttributeTickHandler.java index 5c7960251..a65f70479 100644 --- a/src/main/java/noppes/npcs/attribute/PlayerAttributeTickHandler.java +++ b/src/main/java/noppes/npcs/attribute/PlayerAttributeTickHandler.java @@ -4,7 +4,8 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.entity.player.EntityPlayer; /** - * Tick handler that runs every tick and, every 10 ticks, checks all players for equipment changes. + * Tick handler that runs every tick and, every 10 ticks, checks all players + * for equipment changes to update their attribute trackers. */ public class PlayerAttributeTickHandler { private int tickCount = 0; diff --git a/src/main/java/noppes/npcs/attribute/PlayerAttributeTracker.java b/src/main/java/noppes/npcs/attribute/PlayerAttributeTracker.java index 9b9505f75..b11bea45a 100644 --- a/src/main/java/noppes/npcs/attribute/PlayerAttributeTracker.java +++ b/src/main/java/noppes/npcs/attribute/PlayerAttributeTracker.java @@ -1,18 +1,30 @@ package noppes.npcs.attribute; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import java.util.Map; +import java.util.Map.Entry; /** - * A tracker that holds a cached aggregation of a player’s attributes (derived from their held item and armor). - * It does not “own” the attributes but recalculates them when equipment changes. - * A simple snapshot of equipment is used to detect changes. + * Aggregates a player's attributes based on their held item and armor. + * Non‑magic attributes are stored in a CustomAttributeMap. + * Magic–based attributes (offense and defense) are aggregated as maps: + * for each magic type, we sum the FLAT and PERCENT values. + * + * This tracker is updated (for example, every 10 ticks) if the player's equipment changes. */ public class PlayerAttributeTracker { private final UUID playerId; private CustomAttributeMap aggregatedAttributes = new CustomAttributeMap(); + // Aggregated magic offensive values from items (weapon, etc.) + private final Map aggregatedMagicDamageFlat = new HashMap<>(); + private final Map aggregatedMagicDamagePercent = new HashMap<>(); + // Aggregated magic defensive values from armor + private final Map aggregatedMagicDefenseFlat = new HashMap<>(); + private final Map aggregatedMagicResistancePercent = new HashMap<>(); + private String equipmentSnapshot = ""; public PlayerAttributeTracker(UUID playerId) { @@ -25,17 +37,16 @@ public class PlayerAttributeTracker { } /** - * Computes a snapshot string representing current equipment. - * For simplicity, concatenates item class names and damage values. + * Builds a snapshot string from the player's held item and armor. */ private String computeEquipmentSnapshot(EntityPlayer player) { StringBuilder sb = new StringBuilder(); ItemStack held = player.getHeldItem(); - if(held != null) { + if (held != null) { sb.append(held.getItem().toString()).append(held.getItemDamage()); } for (ItemStack armor : player.inventory.armorInventory) { - if(armor != null) { + if (armor != null) { sb.append(armor.getItem().toString()).append(armor.getItemDamage()); } } @@ -43,65 +54,96 @@ public class PlayerAttributeTracker { } /** - * Recalculates the aggregated attribute map from the player's equipment. + * Recalculates the aggregated attributes from the player's equipment. + * Non‑magic attributes are processed into a CustomAttributeMap, + * while magic attributes (offense and defense) are aggregated into separate maps. */ public void recalcAttributes(EntityPlayer player) { + // Reinitialize non-magic attributes: CustomAttributeMap newMap = new CustomAttributeMap(); - // Register base (non-magic) attributes with default values. newMap.registerAttribute(ModAttributes.MAIN_ATTACK_FLAT, 0.0); newMap.registerAttribute(ModAttributes.MAIN_ATTACK_PERCENT, 0.0); newMap.registerAttribute(ModAttributes.HEALTH, 20.0); newMap.registerAttribute(ModAttributes.CRITICAL_CHANCE_PERCENT, 0.0); newMap.registerAttribute(ModAttributes.CRITICAL_DAMAGE_FLAT, 0.0); + aggregatedAttributes = newMap; - if(player != null) { - // Process held item: + // Reset magic aggregates: + aggregatedMagicDamageFlat.clear(); + aggregatedMagicDamagePercent.clear(); + aggregatedMagicDefenseFlat.clear(); + aggregatedMagicResistancePercent.clear(); + + if (player != null) { + // Process held item (assumed to be offense—weapon): ItemStack held = player.getHeldItem(); - if(held != null) { - for (Map.Entry entry : CNPCItemAttributeHelper.readAttributes(held).entrySet()) { + if (held != null) { + // Non-magic: + for (Entry entry : CNPCItemAttributeHelper.readAttributes(held).entrySet()) { String key = entry.getKey(); double value = entry.getValue(); - if("cnpc:main_attack_flat".equals(key)) { - IAttributeInstance inst = newMap.getAttributeInstance(ModAttributes.MAIN_ATTACK_FLAT); + if (AttributeKeys.MAIN_ATTACK_FLAT.equals(key)) { + IAttributeInstance inst = aggregatedAttributes.getAttributeInstance(ModAttributes.MAIN_ATTACK_FLAT); inst.setBaseValue(inst.getBaseValue() + value); - } else if("cnpc:main_attack_percent".equals(key)) { - IAttributeInstance inst = newMap.getAttributeInstance(ModAttributes.MAIN_ATTACK_PERCENT); + } else if (AttributeKeys.MAIN_ATTACK_PERCENT.equals(key)) { + IAttributeInstance inst = aggregatedAttributes.getAttributeInstance(ModAttributes.MAIN_ATTACK_PERCENT); inst.setBaseValue(inst.getBaseValue() + value); - } else if("cnpc:critical_chance_percent".equals(key)) { - IAttributeInstance inst = newMap.getAttributeInstance(ModAttributes.CRITICAL_CHANCE_PERCENT); + } else if (AttributeKeys.CRITICAL_CHANCE_PERCENT.equals(key)) { + IAttributeInstance inst = aggregatedAttributes.getAttributeInstance(ModAttributes.CRITICAL_CHANCE_PERCENT); inst.setBaseValue(inst.getBaseValue() + value); - } else if("cnpc:critical_damage_flat".equals(key)) { - IAttributeInstance inst = newMap.getAttributeInstance(ModAttributes.CRITICAL_DAMAGE_FLAT); + } else if (AttributeKeys.CRITICAL_DAMAGE_FLAT.equals(key)) { + IAttributeInstance inst = aggregatedAttributes.getAttributeInstance(ModAttributes.CRITICAL_DAMAGE_FLAT); inst.setBaseValue(inst.getBaseValue() + value); } } + // Magic offense: + Map weaponMagicFlat = CNPCItemAttributeHelper.readMagicAttributeMap(held, AttributeKeys.MAGIC_DAMAGE_FLAT); + for (Entry entry : weaponMagicFlat.entrySet()) { + int magicId = entry.getKey(); + double value = entry.getValue(); + aggregatedMagicDamageFlat.put(magicId, aggregatedMagicDamageFlat.getOrDefault(magicId, 0.0) + value); + } + Map weaponMagicPercent = CNPCItemAttributeHelper.readMagicAttributeMap(held, AttributeKeys.MAGIC_DAMAGE_PERCENT); + for (Entry entry : weaponMagicPercent.entrySet()) { + int magicId = entry.getKey(); + double value = entry.getValue(); + aggregatedMagicDamagePercent.put(magicId, aggregatedMagicDamagePercent.getOrDefault(magicId, 0.0) + value); + } } - // Process armor pieces: + // Process armor (assumed to contribute defense): for (ItemStack armor : player.inventory.armorInventory) { - if(armor != null) { - for (Map.Entry entry : CNPCItemAttributeHelper.readAttributes(armor).entrySet()) { + if (armor != null) { + // Non-magic: + for (Entry entry : CNPCItemAttributeHelper.readAttributes(armor).entrySet()) { String key = entry.getKey(); double value = entry.getValue(); - if("cnpc:main_attack_flat".equals(key)) { - IAttributeInstance inst = newMap.getAttributeInstance(ModAttributes.MAIN_ATTACK_FLAT); - inst.setBaseValue(inst.getBaseValue() + value); - } else if("cnpc:main_attack_percent".equals(key)) { - IAttributeInstance inst = newMap.getAttributeInstance(ModAttributes.MAIN_ATTACK_PERCENT); - inst.setBaseValue(inst.getBaseValue() + value); - } else if("cnpc:health".equals(key)) { - IAttributeInstance inst = newMap.getAttributeInstance(ModAttributes.HEALTH); + if (AttributeKeys.HEALTH.equals(key)) { + IAttributeInstance inst = aggregatedAttributes.getAttributeInstance(ModAttributes.HEALTH); inst.setBaseValue(inst.getBaseValue() + value); } + // Could add other non-magic defensive bonuses here. + } + // Magic defense: + Map armorMagicFlat = CNPCItemAttributeHelper.readMagicAttributeMap(armor, AttributeKeys.MAGIC_DEFENSE_FLAT); + for (Entry entry : armorMagicFlat.entrySet()) { + int magicId = entry.getKey(); + double value = entry.getValue(); + aggregatedMagicDefenseFlat.put(magicId, aggregatedMagicDefenseFlat.getOrDefault(magicId, 0.0) + value); + } + Map armorMagicPercent = CNPCItemAttributeHelper.readMagicAttributeMap(armor, AttributeKeys.MAGIC_RESISTANCE_PERCENT); + for (Entry entry : armorMagicPercent.entrySet()) { + int magicId = entry.getKey(); + double value = entry.getValue(); + aggregatedMagicResistancePercent.put(magicId, aggregatedMagicResistancePercent.getOrDefault(magicId, 0.0) + value); } } } } - aggregatedAttributes = newMap; } /** - * Checks if the player's equipment has changed (by comparing a snapshot) and recalculates if needed. - * This should be called every 10 ticks. + * Checks if the player's equipment has changed (using a snapshot) and recalculates if so. + * Should be called periodically (e.g. every 10 ticks). */ public void updateIfChanged(EntityPlayer player) { String currentSnapshot = computeEquipmentSnapshot(player); @@ -111,8 +153,63 @@ public class PlayerAttributeTracker { } } + /** + * Returns the aggregated non-magic value for a given attribute. + */ public double getAttributeValue(AttributeDefinition def) { IAttributeInstance inst = aggregatedAttributes.getAttributeInstance(def); return inst != null ? inst.getAttributeValue() : 0.0; } + + /** + * Returns overall offensive rating: + * Non-magic offense (MAIN_ATTACK_FLAT*(1+MAIN_ATTACK_PERCENT)) + * plus the sum over all magic offense: for each magic type, flat*(1+percent). + */ + public double getOffense() { + double nonMagic = getAttributeValue(ModAttributes.MAIN_ATTACK_FLAT) * (1 + getAttributeValue(ModAttributes.MAIN_ATTACK_PERCENT)); + double magicOffense = 0.0; + for (Map.Entry entry : aggregatedMagicDamageFlat.entrySet()) { + int magicId = entry.getKey(); + double flat = entry.getValue(); + double percent = aggregatedMagicDamagePercent.getOrDefault(magicId, 0.0); + magicOffense += flat * (1 + percent); + } + return nonMagic + magicOffense; + } + + /** + * Returns offensive value for a specific magic type. + */ + public double getOffense(int magicId) { + double flat = aggregatedMagicDamageFlat.getOrDefault(magicId, 0.0); + double percent = aggregatedMagicDamagePercent.getOrDefault(magicId, 0.0); + return flat * (1 + percent); + } + + /** + * Returns overall defensive rating: + * Non-magic defense is given by HEALTH. + * Plus sum over all magic defense: for each magic type, flat*(1+percent). + */ + public double getDefense() { + double nonMagic = getAttributeValue(ModAttributes.HEALTH); + double magicDefense = 0.0; + for (Map.Entry entry : aggregatedMagicDefenseFlat.entrySet()) { + int magicId = entry.getKey(); + double flat = entry.getValue(); + double percent = aggregatedMagicResistancePercent.getOrDefault(magicId, 0.0); + magicDefense += flat * (1 + percent); + } + return nonMagic + magicDefense; + } + + /** + * Returns defensive value for a specific magic type. + */ + public double getDefense(int magicId) { + double flat = aggregatedMagicDefenseFlat.getOrDefault(magicId, 0.0); + double percent = aggregatedMagicResistancePercent.getOrDefault(magicId, 0.0); + return flat * (1 + percent); + } } From f2286a382ff1ffdd7728aba4e1c88834cf34f1aa Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 25 Feb 2025 16:05:40 -0500 Subject: [PATCH 57/59] Fix to RPGCore for Future Porting --- .../npcs/attribute/AttributeDefinition.java | 10 ++-------- .../noppes/npcs/attribute/AttributeKeys.java | 18 +++++++++--------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/main/java/noppes/npcs/attribute/AttributeDefinition.java b/src/main/java/noppes/npcs/attribute/AttributeDefinition.java index 9657d1572..f68995a0b 100644 --- a/src/main/java/noppes/npcs/attribute/AttributeDefinition.java +++ b/src/main/java/noppes/npcs/attribute/AttributeDefinition.java @@ -6,22 +6,16 @@ package noppes.npcs.attribute; * once in the AttributeController. */ public class AttributeDefinition { - private final int id; - private final String key; // e.g., "cnpc:main_attack_flat" + private final String key; // e.g., "rpgcore:main_attack_flat" private final String displayName; // Human‑readable name private final AttributeValueType attributeValueType; - public AttributeDefinition(int id, String key, String displayName, AttributeValueType attributeValueType) { - this.id = id; + public AttributeDefinition(String key, String displayName, AttributeValueType attributeValueType) { this.key = key; this.displayName = displayName; this.attributeValueType = attributeValueType; } - public int getId() { - return id; - } - public String getKey() { return key; } diff --git a/src/main/java/noppes/npcs/attribute/AttributeKeys.java b/src/main/java/noppes/npcs/attribute/AttributeKeys.java index 5707a770a..4e50af762 100644 --- a/src/main/java/noppes/npcs/attribute/AttributeKeys.java +++ b/src/main/java/noppes/npcs/attribute/AttributeKeys.java @@ -1,17 +1,17 @@ package noppes.npcs.attribute; public final class AttributeKeys { - public static final String MAIN_ATTACK_FLAT = "cnpc:main_attack_flat"; - public static final String MAIN_ATTACK_PERCENT = "cnpc:main_attack_percent"; - public static final String HEALTH = "cnpc:health"; - public static final String CRITICAL_CHANCE_PERCENT = "cnpc:critical_chance_percent"; - public static final String CRITICAL_DAMAGE_FLAT = "cnpc:critical_damage_flat"; + public static final String MAIN_ATTACK_FLAT = "rpgcore:main_attack_flat"; + public static final String MAIN_ATTACK_PERCENT = "rpgcore:main_attack_percent"; + public static final String HEALTH = "rpgcore:health"; + public static final String CRITICAL_CHANCE_PERCENT = "rpgcore:critical_chance_percent"; + public static final String CRITICAL_DAMAGE_FLAT = "rpgcore:critical_damage_flat"; // Magic–based attribute keys: - public static final String MAGIC_DAMAGE_FLAT = "cnpc:magic_damage_flat"; - public static final String MAGIC_DAMAGE_PERCENT = "cnpc:magic_damage_percent"; - public static final String MAGIC_DEFENSE_FLAT = "cnpc:magic_defense_flat"; - public static final String MAGIC_RESISTANCE_PERCENT = "cnpc:magic_resistance_percent"; + public static final String MAGIC_DAMAGE_FLAT = "rpgcore:magic_damage_flat"; + public static final String MAGIC_DAMAGE_PERCENT = "rpgcore:magic_damage_percent"; + public static final String MAGIC_DEFENSE_FLAT = "rpgcore:magic_defense_flat"; + public static final String MAGIC_RESISTANCE_PERCENT = "rpgcore:magic_resistance_percent"; private AttributeKeys() { } } From 0c1ce7ed7a57420b551331621d2519ac9b6d081d Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 25 Feb 2025 16:25:08 -0500 Subject: [PATCH 58/59] Equipment Tracker for Players --- .../attribute/PlayerAttributeTracker.java | 155 +++++++++--------- .../attribute/PlayerEquipmentTracker.java | 65 ++++++++ 2 files changed, 140 insertions(+), 80 deletions(-) create mode 100644 src/main/java/noppes/npcs/attribute/PlayerEquipmentTracker.java diff --git a/src/main/java/noppes/npcs/attribute/PlayerAttributeTracker.java b/src/main/java/noppes/npcs/attribute/PlayerAttributeTracker.java index b11bea45a..7cd849d5e 100644 --- a/src/main/java/noppes/npcs/attribute/PlayerAttributeTracker.java +++ b/src/main/java/noppes/npcs/attribute/PlayerAttributeTracker.java @@ -8,27 +8,29 @@ import net.minecraft.item.ItemStack; import java.util.Map.Entry; /** - * Aggregates a player's attributes based on their held item and armor. - * Non‑magic attributes are stored in a CustomAttributeMap. - * Magic–based attributes (offense and defense) are aggregated as maps: - * for each magic type, we sum the FLAT and PERCENT values. - * - * This tracker is updated (for example, every 10 ticks) if the player's equipment changes. + * Aggregates a player's attributes based on the attributes found on their held item and armor. + * Non–magic attributes are stored in a CustomAttributeMap (using string keys via AttributeController). + * Magic attributes (offense and defense) are aggregated as maps, keyed by magic type. + * This tracker uses a PlayerEquipmentTracker to keep track of the player's equipment, + * and recalculates only when the player's held item or armor changes. */ public class PlayerAttributeTracker { private final UUID playerId; private CustomAttributeMap aggregatedAttributes = new CustomAttributeMap(); - // Aggregated magic offensive values from items (weapon, etc.) + + // Aggregated magic offensive values: private final Map aggregatedMagicDamageFlat = new HashMap<>(); private final Map aggregatedMagicDamagePercent = new HashMap<>(); - // Aggregated magic defensive values from armor + // Aggregated magic defensive values: private final Map aggregatedMagicDefenseFlat = new HashMap<>(); private final Map aggregatedMagicResistancePercent = new HashMap<>(); - private String equipmentSnapshot = ""; + // Stores the last-known equipment. + private PlayerEquipmentTracker equipmentTracker = new PlayerEquipmentTracker(); public PlayerAttributeTracker(UUID playerId) { this.playerId = playerId; + // Initialize equipmentTracker from a null player (will be updated on first tick). recalcAttributes(null); } @@ -36,125 +38,115 @@ public class PlayerAttributeTracker { return aggregatedAttributes; } - /** - * Builds a snapshot string from the player's held item and armor. - */ - private String computeEquipmentSnapshot(EntityPlayer player) { - StringBuilder sb = new StringBuilder(); - ItemStack held = player.getHeldItem(); - if (held != null) { - sb.append(held.getItem().toString()).append(held.getItemDamage()); - } - for (ItemStack armor : player.inventory.armorInventory) { - if (armor != null) { - sb.append(armor.getItem().toString()).append(armor.getItemDamage()); - } - } - return sb.toString(); - } - /** * Recalculates the aggregated attributes from the player's equipment. - * Non‑magic attributes are processed into a CustomAttributeMap, - * while magic attributes (offense and defense) are aggregated into separate maps. + * Non–magic attributes are read from each item's CNPCAttributes, and magic attributes + * are aggregated by summing values from their NBT maps. */ public void recalcAttributes(EntityPlayer player) { - // Reinitialize non-magic attributes: + // Start with a fresh attribute map. CustomAttributeMap newMap = new CustomAttributeMap(); + // Pre-register core non-magic attributes (if they appear on items). newMap.registerAttribute(ModAttributes.MAIN_ATTACK_FLAT, 0.0); newMap.registerAttribute(ModAttributes.MAIN_ATTACK_PERCENT, 0.0); - newMap.registerAttribute(ModAttributes.HEALTH, 20.0); newMap.registerAttribute(ModAttributes.CRITICAL_CHANCE_PERCENT, 0.0); newMap.registerAttribute(ModAttributes.CRITICAL_DAMAGE_FLAT, 0.0); + // (HEALTH is handled separately.) aggregatedAttributes = newMap; - // Reset magic aggregates: + // Reset magic aggregates. aggregatedMagicDamageFlat.clear(); aggregatedMagicDamagePercent.clear(); aggregatedMagicDefenseFlat.clear(); aggregatedMagicResistancePercent.clear(); if (player != null) { - // Process held item (assumed to be offense—weapon): - ItemStack held = player.getHeldItem(); + // Update equipmentTracker with the player's current equipment. + PlayerEquipmentTracker currentEquip = new PlayerEquipmentTracker(); + currentEquip.updateFrom(player); + + // Process held item (offense). + ItemStack held = currentEquip.heldItem; if (held != null) { - // Non-magic: + // Process non-magic attributes. for (Entry entry : CNPCItemAttributeHelper.readAttributes(held).entrySet()) { String key = entry.getKey(); double value = entry.getValue(); - if (AttributeKeys.MAIN_ATTACK_FLAT.equals(key)) { - IAttributeInstance inst = aggregatedAttributes.getAttributeInstance(ModAttributes.MAIN_ATTACK_FLAT); - inst.setBaseValue(inst.getBaseValue() + value); - } else if (AttributeKeys.MAIN_ATTACK_PERCENT.equals(key)) { - IAttributeInstance inst = aggregatedAttributes.getAttributeInstance(ModAttributes.MAIN_ATTACK_PERCENT); - inst.setBaseValue(inst.getBaseValue() + value); - } else if (AttributeKeys.CRITICAL_CHANCE_PERCENT.equals(key)) { - IAttributeInstance inst = aggregatedAttributes.getAttributeInstance(ModAttributes.CRITICAL_CHANCE_PERCENT); - inst.setBaseValue(inst.getBaseValue() + value); - } else if (AttributeKeys.CRITICAL_DAMAGE_FLAT.equals(key)) { - IAttributeInstance inst = aggregatedAttributes.getAttributeInstance(ModAttributes.CRITICAL_DAMAGE_FLAT); + AttributeDefinition def = AttributeController.getAttribute(key); + if (def != null) { + IAttributeInstance inst = aggregatedAttributes.getAttributeInstance(def); + if (inst == null) { + inst = aggregatedAttributes.registerAttribute(def, 0.0); + } inst.setBaseValue(inst.getBaseValue() + value); } } - // Magic offense: - Map weaponMagicFlat = CNPCItemAttributeHelper.readMagicAttributeMap(held, AttributeKeys.MAGIC_DAMAGE_FLAT); - for (Entry entry : weaponMagicFlat.entrySet()) { + // Process magic offense. + Map magicFlat = CNPCItemAttributeHelper.readMagicAttributeMap(held, AttributeKeys.MAGIC_DAMAGE_FLAT); + for (Entry entry : magicFlat.entrySet()) { int magicId = entry.getKey(); double value = entry.getValue(); aggregatedMagicDamageFlat.put(magicId, aggregatedMagicDamageFlat.getOrDefault(magicId, 0.0) + value); } - Map weaponMagicPercent = CNPCItemAttributeHelper.readMagicAttributeMap(held, AttributeKeys.MAGIC_DAMAGE_PERCENT); - for (Entry entry : weaponMagicPercent.entrySet()) { + Map magicPercent = CNPCItemAttributeHelper.readMagicAttributeMap(held, AttributeKeys.MAGIC_DAMAGE_PERCENT); + for (Entry entry : magicPercent.entrySet()) { int magicId = entry.getKey(); double value = entry.getValue(); aggregatedMagicDamagePercent.put(magicId, aggregatedMagicDamagePercent.getOrDefault(magicId, 0.0) + value); } } - // Process armor (assumed to contribute defense): - for (ItemStack armor : player.inventory.armorInventory) { - if (armor != null) { - // Non-magic: - for (Entry entry : CNPCItemAttributeHelper.readAttributes(armor).entrySet()) { + // Process armor (defense). + // Assuming armor order: 0: boots, 1: leggings, 2: chestplate, 3: helmet. + ItemStack[] armor = new ItemStack[] { currentEquip.boots, currentEquip.leggings, currentEquip.chestplate, currentEquip.helmet }; + for (ItemStack piece : armor) { + if (piece != null) { + // Process non-magic attributes. + for (Entry entry : CNPCItemAttributeHelper.readAttributes(piece).entrySet()) { String key = entry.getKey(); double value = entry.getValue(); - if (AttributeKeys.HEALTH.equals(key)) { - IAttributeInstance inst = aggregatedAttributes.getAttributeInstance(ModAttributes.HEALTH); + AttributeDefinition def = AttributeController.getAttribute(key); + if (def != null) { + IAttributeInstance inst = aggregatedAttributes.getAttributeInstance(def); + if (inst == null) { + inst = aggregatedAttributes.registerAttribute(def, 0.0); + } inst.setBaseValue(inst.getBaseValue() + value); } - // Could add other non-magic defensive bonuses here. } - // Magic defense: - Map armorMagicFlat = CNPCItemAttributeHelper.readMagicAttributeMap(armor, AttributeKeys.MAGIC_DEFENSE_FLAT); - for (Entry entry : armorMagicFlat.entrySet()) { + // Process magic defense. + Map magicDefFlat = CNPCItemAttributeHelper.readMagicAttributeMap(piece, AttributeKeys.MAGIC_DEFENSE_FLAT); + for (Entry entry : magicDefFlat.entrySet()) { int magicId = entry.getKey(); double value = entry.getValue(); aggregatedMagicDefenseFlat.put(magicId, aggregatedMagicDefenseFlat.getOrDefault(magicId, 0.0) + value); } - Map armorMagicPercent = CNPCItemAttributeHelper.readMagicAttributeMap(armor, AttributeKeys.MAGIC_RESISTANCE_PERCENT); - for (Entry entry : armorMagicPercent.entrySet()) { + Map magicResist = CNPCItemAttributeHelper.readMagicAttributeMap(piece, AttributeKeys.MAGIC_RESISTANCE_PERCENT); + for (Entry entry : magicResist.entrySet()) { int magicId = entry.getKey(); double value = entry.getValue(); aggregatedMagicResistancePercent.put(magicId, aggregatedMagicResistancePercent.getOrDefault(magicId, 0.0) + value); } } } + // Update our stored equipment. + equipmentTracker = currentEquip; } } /** - * Checks if the player's equipment has changed (using a snapshot) and recalculates if so. - * Should be called periodically (e.g. every 10 ticks). + * Checks if the player's equipment has changed by comparing stored equipment with the current equipment. + * This should be called periodically (e.g., every 10 ticks). */ public void updateIfChanged(EntityPlayer player) { - String currentSnapshot = computeEquipmentSnapshot(player); - if (!currentSnapshot.equals(equipmentSnapshot)) { - equipmentSnapshot = currentSnapshot; + PlayerEquipmentTracker currentEquip = new PlayerEquipmentTracker(); + currentEquip.updateFrom(player); + if (!equipmentTracker.equals(player)) { recalcAttributes(player); } } /** - * Returns the aggregated non-magic value for a given attribute. + * Returns the aggregated non-magic value for a given attribute definition. */ public double getAttributeValue(AttributeDefinition def) { IAttributeInstance inst = aggregatedAttributes.getAttributeInstance(def); @@ -162,14 +154,19 @@ public class PlayerAttributeTracker { } /** - * Returns overall offensive rating: + * Overall offense is calculated as: * Non-magic offense (MAIN_ATTACK_FLAT*(1+MAIN_ATTACK_PERCENT)) * plus the sum over all magic offense: for each magic type, flat*(1+percent). */ public double getOffense() { - double nonMagic = getAttributeValue(ModAttributes.MAIN_ATTACK_FLAT) * (1 + getAttributeValue(ModAttributes.MAIN_ATTACK_PERCENT)); + double nonMagic = 0.0; + AttributeDefinition atkFlat = AttributeController.getAttribute(AttributeKeys.MAIN_ATTACK_FLAT); + AttributeDefinition atkPercent = AttributeController.getAttribute(AttributeKeys.MAIN_ATTACK_PERCENT); + if (atkFlat != null && atkPercent != null) { + nonMagic = getAttributeValue(atkFlat) * (1 + getAttributeValue(atkPercent)); + } double magicOffense = 0.0; - for (Map.Entry entry : aggregatedMagicDamageFlat.entrySet()) { + for (Entry entry : aggregatedMagicDamageFlat.entrySet()) { int magicId = entry.getKey(); double flat = entry.getValue(); double percent = aggregatedMagicDamagePercent.getOrDefault(magicId, 0.0); @@ -179,7 +176,7 @@ public class PlayerAttributeTracker { } /** - * Returns offensive value for a specific magic type. + * Returns offense for a specific magic type. */ public double getOffense(int magicId) { double flat = aggregatedMagicDamageFlat.getOrDefault(magicId, 0.0); @@ -188,24 +185,22 @@ public class PlayerAttributeTracker { } /** - * Returns overall defensive rating: - * Non-magic defense is given by HEALTH. - * Plus sum over all magic defense: for each magic type, flat*(1+percent). + * Overall defense is calculated solely from magic defensive attributes. + * (HEALTH is managed separately.) */ public double getDefense() { - double nonMagic = getAttributeValue(ModAttributes.HEALTH); double magicDefense = 0.0; - for (Map.Entry entry : aggregatedMagicDefenseFlat.entrySet()) { + for (Entry entry : aggregatedMagicDefenseFlat.entrySet()) { int magicId = entry.getKey(); double flat = entry.getValue(); double percent = aggregatedMagicResistancePercent.getOrDefault(magicId, 0.0); magicDefense += flat * (1 + percent); } - return nonMagic + magicDefense; + return magicDefense; } /** - * Returns defensive value for a specific magic type. + * Returns defense for a specific magic type. */ public double getDefense(int magicId) { double flat = aggregatedMagicDefenseFlat.getOrDefault(magicId, 0.0); diff --git a/src/main/java/noppes/npcs/attribute/PlayerEquipmentTracker.java b/src/main/java/noppes/npcs/attribute/PlayerEquipmentTracker.java new file mode 100644 index 000000000..83372f690 --- /dev/null +++ b/src/main/java/noppes/npcs/attribute/PlayerEquipmentTracker.java @@ -0,0 +1,65 @@ +package noppes.npcs.attribute; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +public class PlayerEquipmentTracker { + public ItemStack heldItem; + public ItemStack helmet; + public ItemStack chestplate; + public ItemStack leggings; + public ItemStack boots; + + /** + * Updates the stored equipment based on the player's current held item and armor. + */ + public void updateFrom(EntityPlayer player) { + heldItem = copyIfNotNull(player.getHeldItem()); + ItemStack[] armor = player.inventory.armorInventory; + // Armor inventory order: 0=boots, 1=leggings, 2=chestplate, 3=helmet. + boots = copyIfNotNull(armor[0]); + leggings = copyIfNotNull(armor[1]); + chestplate = copyIfNotNull(armor[2]); + helmet = copyIfNotNull(armor[3]); + } + + /** + * Compares the stored equipment with the player's current equipment. + * Ignores changes like durability by comparing the item and the CNPCAttributes NBT only. + */ + public boolean equals(EntityPlayer player) { + if (player == null) return false; + if (!areItemStacksEquivalent(heldItem, player.getHeldItem())) return false; + ItemStack[] armor = player.inventory.armorInventory; + if (!areItemStacksEquivalent(boots, armor[0])) return false; + if (!areItemStacksEquivalent(leggings, armor[1])) return false; + if (!areItemStacksEquivalent(chestplate, armor[2])) return false; + if (!areItemStacksEquivalent(helmet, armor[3])) return false; + return true; + } + + /** + * Returns a copy of the given ItemStack, or null if it is null. + */ + private ItemStack copyIfNotNull(ItemStack stack) { + return (stack == null) ? null : stack.copy(); + } + + /** + * Compares two ItemStacks for equivalence, ignoring durability differences. + * It checks if the items are the same and if the "CNPCAttributes" NBT compound is equal. + */ + private boolean areItemStacksEquivalent(ItemStack a, ItemStack b) { + if (a == b) return true; + if (a == null || b == null) return false; + if (a.getItem() != b.getItem()) return false; + NBTTagCompound tagA = a.stackTagCompound; + NBTTagCompound tagB = b.stackTagCompound; + String attrA = (tagA != null && tagA.hasKey(CNPCItemAttributeHelper.TAG_ROOT)) + ? tagA.getCompoundTag(CNPCItemAttributeHelper.TAG_ROOT).toString() : ""; + String attrB = (tagB != null && tagB.hasKey(CNPCItemAttributeHelper.TAG_ROOT)) + ? tagB.getCompoundTag(CNPCItemAttributeHelper.TAG_ROOT).toString() : ""; + return attrA.equals(attrB); + } +} From f1b77fe94f813939cf63af67ff48c66693766c42 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 25 Feb 2025 16:46:05 -0500 Subject: [PATCH 59/59] Tick Attribute Tracker --- .../noppes/npcs/ScriptPlayerEventHandler.java | 5 ++++- .../noppes/npcs/attribute/ModAttributes.java | 8 +++---- .../attribute/PlayerAttributeTickHandler.java | 22 ------------------- .../attribute/PlayerAttributeTracker.java | 10 +-------- 4 files changed, 9 insertions(+), 36 deletions(-) delete mode 100644 src/main/java/noppes/npcs/attribute/PlayerAttributeTickHandler.java diff --git a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java index bd6b56de8..2247d4448 100644 --- a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java @@ -23,6 +23,7 @@ import net.minecraftforge.event.entity.player.*; import net.minecraftforge.event.world.BlockEvent; import noppes.npcs.api.entity.IPlayer; import noppes.npcs.api.item.IItemCustomizable; +import noppes.npcs.attribute.PlayerAttributeManager; import noppes.npcs.constants.EnumQuestType; import noppes.npcs.controllers.CustomEffectController; import noppes.npcs.controllers.PartyController; @@ -47,7 +48,7 @@ public class ScriptPlayerEventHandler { if (event.side == Side.SERVER && event.phase == TickEvent.Phase.START) { EntityPlayer player = event.player; - if (player.ticksExisted%10 == 0) { + if (player.ticksExisted % 10 == 0) { PlayerDataScript handler = ScriptController.Instance.playerScripts; IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player); EventHooks.onPlayerTick(handler, scriptPlayer); @@ -59,6 +60,8 @@ public class ScriptPlayerEventHandler { EventHooks.onScriptItemUpdate(isw, player); } } + + PlayerAttributeManager.getTracker(player.getUniqueID()).updateIfChanged(player); } if (PlayerDataController.Instance != null) { diff --git a/src/main/java/noppes/npcs/attribute/ModAttributes.java b/src/main/java/noppes/npcs/attribute/ModAttributes.java index 1000e8efe..d780b88bf 100644 --- a/src/main/java/noppes/npcs/attribute/ModAttributes.java +++ b/src/main/java/noppes/npcs/attribute/ModAttributes.java @@ -16,15 +16,15 @@ public class ModAttributes { public static final AttributeDefinition MAGIC_RESISTANCE_PERCENT; static { - MAIN_ATTACK_FLAT = AttributeController.registerAttribute(AttributeKeys.MAIN_ATTACK_FLAT, "Main Attack Damage (Flat)", AttributeValueType.FLAT); + MAIN_ATTACK_FLAT = AttributeController.registerAttribute(AttributeKeys.MAIN_ATTACK_FLAT, "Main Attack Damage", AttributeValueType.FLAT); MAIN_ATTACK_PERCENT = AttributeController.registerAttribute(AttributeKeys.MAIN_ATTACK_PERCENT, "Main Attack Damage (%)", AttributeValueType.PERCENT); HEALTH = AttributeController.registerAttribute(AttributeKeys.HEALTH, "Health", AttributeValueType.FLAT); CRITICAL_CHANCE_PERCENT = AttributeController.registerAttribute(AttributeKeys.CRITICAL_CHANCE_PERCENT, "Critical Chance (%)", AttributeValueType.PERCENT); - CRITICAL_DAMAGE_FLAT = AttributeController.registerAttribute(AttributeKeys.CRITICAL_DAMAGE_FLAT, "Critical Damage Bonus (Flat)", AttributeValueType.FLAT); + CRITICAL_DAMAGE_FLAT = AttributeController.registerAttribute(AttributeKeys.CRITICAL_DAMAGE_FLAT, "Critical Damage Bonus", AttributeValueType.FLAT); - MAGIC_DAMAGE_FLAT = AttributeController.registerAttribute(AttributeKeys.MAGIC_DAMAGE_FLAT, "Magic Damage (Flat)", AttributeValueType.MAGIC); + MAGIC_DAMAGE_FLAT = AttributeController.registerAttribute(AttributeKeys.MAGIC_DAMAGE_FLAT, "Magic Damage", AttributeValueType.MAGIC); MAGIC_DAMAGE_PERCENT = AttributeController.registerAttribute(AttributeKeys.MAGIC_DAMAGE_PERCENT, "Magic Damage (%)", AttributeValueType.MAGIC); - MAGIC_DEFENSE_FLAT = AttributeController.registerAttribute(AttributeKeys.MAGIC_DEFENSE_FLAT, "Magic Defense (Flat)", AttributeValueType.MAGIC); + MAGIC_DEFENSE_FLAT = AttributeController.registerAttribute(AttributeKeys.MAGIC_DEFENSE_FLAT, "Magic Defense", AttributeValueType.MAGIC); MAGIC_RESISTANCE_PERCENT = AttributeController.registerAttribute(AttributeKeys.MAGIC_RESISTANCE_PERCENT, "Magic Resistance (%)", AttributeValueType.MAGIC); } } diff --git a/src/main/java/noppes/npcs/attribute/PlayerAttributeTickHandler.java b/src/main/java/noppes/npcs/attribute/PlayerAttributeTickHandler.java deleted file mode 100644 index a65f70479..000000000 --- a/src/main/java/noppes/npcs/attribute/PlayerAttributeTickHandler.java +++ /dev/null @@ -1,22 +0,0 @@ -package noppes.npcs.attribute; - -import net.minecraft.server.MinecraftServer; -import net.minecraft.entity.player.EntityPlayer; - -/** - * Tick handler that runs every tick and, every 10 ticks, checks all players - * for equipment changes to update their attribute trackers. - */ -public class PlayerAttributeTickHandler { - private int tickCount = 0; - - public void onTick() { - tickCount++; - if (tickCount % 10 == 0) { - for (Object o : MinecraftServer.getServer().getConfigurationManager().playerEntityList) { - EntityPlayer player = (EntityPlayer) o; - PlayerAttributeManager.getTracker(player.getUniqueID()).updateIfChanged(player); - } - } - } -} diff --git a/src/main/java/noppes/npcs/attribute/PlayerAttributeTracker.java b/src/main/java/noppes/npcs/attribute/PlayerAttributeTracker.java index 7cd849d5e..b4aae36bb 100644 --- a/src/main/java/noppes/npcs/attribute/PlayerAttributeTracker.java +++ b/src/main/java/noppes/npcs/attribute/PlayerAttributeTracker.java @@ -44,15 +44,7 @@ public class PlayerAttributeTracker { * are aggregated by summing values from their NBT maps. */ public void recalcAttributes(EntityPlayer player) { - // Start with a fresh attribute map. - CustomAttributeMap newMap = new CustomAttributeMap(); - // Pre-register core non-magic attributes (if they appear on items). - newMap.registerAttribute(ModAttributes.MAIN_ATTACK_FLAT, 0.0); - newMap.registerAttribute(ModAttributes.MAIN_ATTACK_PERCENT, 0.0); - newMap.registerAttribute(ModAttributes.CRITICAL_CHANCE_PERCENT, 0.0); - newMap.registerAttribute(ModAttributes.CRITICAL_DAMAGE_FLAT, 0.0); - // (HEALTH is handled separately.) - aggregatedAttributes = newMap; + aggregatedAttributes = new CustomAttributeMap(); // Reset magic aggregates. aggregatedMagicDamageFlat.clear();