diff options
author | Walker Selby <git@walkerselby.com> | 2022-03-29 01:38:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-29 08:38:49 +0000 |
commit | 924f5da75b3c5ab8bdcfee8b9f16496c6e07f8f0 (patch) | |
tree | 5f6585431c5050942daa8b2ef40f095190f76d8d | |
parent | f237ae4cecdfa5c00ee83bd0176a591a2b174913 (diff) | |
download | NotEnoughUpdates-924f5da75b3c5ab8bdcfee8b9f16496c6e07f8f0.tar.gz NotEnoughUpdates-924f5da75b3c5ab8bdcfee8b9f16496c6e07f8f0.tar.bz2 NotEnoughUpdates-924f5da75b3c5ab8bdcfee8b9f16496c6e07f8f0.zip |
NEU Pack Dev Additions (#103)
3 files changed, 273 insertions, 28 deletions
diff --git a/Update Notes/2.1.md b/Update Notes/2.1.md index 4e8e7bf8..8c8006b3 100644 --- a/Update Notes/2.1.md +++ b/Update Notes/2.1.md @@ -69,6 +69,9 @@ - Added NBT data to Profile Viewer Tab Icons - whalker - Added NBT data to Profile Viewer XP Bar Icons - whalker - Added Blaze Slayer information - whalker +- Added subcommand to /neupackdev allowing you to get NBT data from nearby mob(s) - whalker +- Added subcommand to /neupackdev allowing you to get NBT data from nearby armor stand(s) - whalker +- Added optional radius argument for neupackdev subcommands. -whalker ### **Bug Fixes:** - Fix wiki pages freezing the entire game - nea89 - Made titanium overlay and waypoints work with dwarven overlay off diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.java index e809ed72..a52541a4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.java @@ -8,6 +8,9 @@ import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.item.EntityArmorStand; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; @@ -18,42 +21,281 @@ public class PackDevCommand extends ClientCommandBase { super("neupackdev"); } + EntityPlayerSP p = Minecraft.getMinecraft().thePlayer; + double dist = 5; + double distSq = 25; @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { - if (args.length == 1 && args[0].equalsIgnoreCase("getnpc")) { - double distSq = 25; - EntityPlayer closestNPC = null; - EntityPlayerSP p = Minecraft.getMinecraft().thePlayer; - for (EntityPlayer player : Minecraft.getMinecraft().theWorld.playerEntities) { - if (player instanceof AbstractClientPlayer && p != player && player.getUniqueID().version() != 4) { - double dSq = player.getDistanceSq(p.posX, p.posY, p.posZ); - if (dSq < distSq) { - distSq = dSq; - closestNPC = player; - } + if (args.length >= 1) { + + if (args.length == 2) { + try { + distSq = Double.parseDouble(args[1]) * Double.parseDouble(args[1]); + dist = Double.parseDouble(args[1]); + } catch (NumberFormatException e) { + sender.addChatMessage(new ChatComponentText( + EnumChatFormatting.RED + "Invalid distance! Must be a number, defaulting to a radius of 5.")); } } + StringBuilder value; + switch (args[0].toLowerCase()) { + case "getnpc": + getNPCData(); + break; + + case "getmob": + value = getMobData(); + if (value != null) MiscUtils.copyToClipboard(value.toString()); + break; + + case "getmobs": + value = getMobsData(); + if (value != null) MiscUtils.copyToClipboard(value.toString()); + break; + + case "getarmorstand": + value = getArmorStandData(); + if (value != null) MiscUtils.copyToClipboard(value.toString()); + break; + + case "getarmorstands": + value = getArmorStandsData(); + if (value != null) MiscUtils.copyToClipboard(value.toString()); + break; + + case "getall": + value = getMobsData(); + StringBuilder value2 = getArmorStandsData(); + if (value == null && value2 == null) { + break; + } else if (value != null && value2 != null) { + MiscUtils.copyToClipboard(value.append(value2).toString()); + } else if (value == null) { + MiscUtils.copyToClipboard(value2.toString()); + } else { + MiscUtils.copyToClipboard(value.toString()); + } + break; + + default: + break; + } - if (closestNPC == null) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.RED + "No NPCs found within 5 blocks :(")); + } else { + NotEnoughUpdates.INSTANCE.packDevEnabled = !NotEnoughUpdates.INSTANCE.packDevEnabled; + if (NotEnoughUpdates.INSTANCE.packDevEnabled) { + sender.addChatMessage(new ChatComponentText( + EnumChatFormatting.GREEN + "Enabled pack developer mode.")); } else { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.GREEN + "Copied entity texture id to clipboard")); - MiscUtils.copyToClipboard(((AbstractClientPlayer) closestNPC) - .getLocationSkin() - .getResourcePath() - .replace("skins/", "")); + sender.addChatMessage(new ChatComponentText( + EnumChatFormatting.RED + "Disabled pack developer mode.")); + } + } + } + + public void getNPCData() { + EntityPlayer closestNPC = null; + for (EntityPlayer player : Minecraft.getMinecraft().theWorld.playerEntities) { + if (player instanceof AbstractClientPlayer && p != player && player.getUniqueID().version() != 4) { + double dSq = player.getDistanceSq(p.posX, p.posY, p.posZ); + if (dSq < distSq) { + distSq = dSq; + closestNPC = player; + } + } + } + + if (closestNPC == null) { + p.addChatMessage(new ChatComponentText( + EnumChatFormatting.RED + "No NPCs found within " + dist + " blocks. :(")); + } else { + p.addChatMessage(new ChatComponentText( + EnumChatFormatting.GREEN + "Copied NPC entity texture id to clipboard")); + MiscUtils.copyToClipboard(((AbstractClientPlayer) closestNPC) + .getLocationSkin() + .getResourcePath() + .replace("skins/", "")); + } + } + + public StringBuilder getMobData(){ + Entity closestMob = null; + for (Entity mob : Minecraft.getMinecraft().theWorld.loadedEntityList) { + if (mob != null && mob != Minecraft.getMinecraft().thePlayer && mob instanceof EntityLiving) { + double dSq = mob.getDistanceSq(p.posX, p.posY, p.posZ); + if (dSq < distSq) { + distSq = dSq; + closestMob = mob; + } + } + } + + + if (closestMob == null) { + p.addChatMessage(new ChatComponentText( + EnumChatFormatting.RED + "No mobs found within" + dist + " blocks. :(")); + } else { + p.addChatMessage(new ChatComponentText( + EnumChatFormatting.GREEN + "Copied mob data to clipboard")); + + return mobDataBuilder(closestMob); + + } + return null; + } + + public StringBuilder getMobsData(){ + StringBuilder mobStringBuilder = new StringBuilder(); + for (Entity mob : Minecraft.getMinecraft().theWorld.loadedEntityList) { + if (mob != null && mob != Minecraft.getMinecraft().thePlayer && mob instanceof EntityLiving && + mob.getDistanceSq(p.posX, p.posY, p.posZ) < distSq) { + mobStringBuilder.append(mobDataBuilder(mob)); + } + } + + if (mobStringBuilder.toString().equals("")) { + p.addChatMessage(new ChatComponentText( + EnumChatFormatting.RED + "No mobs found within" + dist + " blocks. :(")); + } else { + p.addChatMessage(new ChatComponentText( + EnumChatFormatting.GREEN + "Copied mob data to clipboard")); + return mobStringBuilder; + } + return null; + } + + public StringBuilder getArmorStandData(){ + EntityArmorStand closestArmorStand = null; + for (Entity armorStand : Minecraft.getMinecraft().theWorld.loadedEntityList) { + if (armorStand instanceof EntityArmorStand) { + double dSq = armorStand.getDistanceSq(p.posX, p.posY, p.posZ); + if (dSq < distSq) { + distSq = dSq; + closestArmorStand = (EntityArmorStand) armorStand; + } + } + } + + if (closestArmorStand == null) { + p.addChatMessage(new ChatComponentText( + EnumChatFormatting.RED + "No armor stands found within " + dist + " blocks. :(")); + } else { + p.addChatMessage(new ChatComponentText( + EnumChatFormatting.GREEN + "Copied armor stand data to clipboard")); + + return(armorStandDataBuilder(closestArmorStand)); + + } + return null; + } + + public StringBuilder getArmorStandsData(){ + + StringBuilder armorStandStringBuilder = new StringBuilder(); + for (Entity armorStand : Minecraft.getMinecraft().theWorld.loadedEntityList) { + if (armorStand instanceof EntityArmorStand && + armorStand.getDistanceSq(p.posX, p.posY, p.posZ) < distSq) { + armorStandStringBuilder.append(armorStandDataBuilder((EntityArmorStand) armorStand)); } - return; } - NotEnoughUpdates.INSTANCE.packDevEnabled = !NotEnoughUpdates.INSTANCE.packDevEnabled; - if (NotEnoughUpdates.INSTANCE.packDevEnabled) { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.GREEN + "Enabled pack developer mode.")); + + if (armorStandStringBuilder.toString().equals("")) { + p.addChatMessage(new ChatComponentText( + EnumChatFormatting.RED + "No armor stands found within" + dist + " blocks. :(")); + } else { + p.addChatMessage(new ChatComponentText( + EnumChatFormatting.GREEN + "Copied armor stand data to clipboard")); + return armorStandStringBuilder; + } + return null; + } + + + + + public StringBuilder mobDataBuilder(Entity mob) { + StringBuilder mobData = new StringBuilder(); + + //Preventing Null Pointer Exception + //Entity Information + mobData + .append("Entity Id: ") + .append(mob.getEntityId() != -1 ? mob.getEntityId() : "null") + .append("\nMob: ") + .append(mob.getName() != null ? mob.getName() : "null") + .append("\nCuston Name: ") + .append(mob.getCustomNameTag() != null ? mob.getCustomNameTag() : "null"); + + //Held Item + if (((EntityLiving) mob).getHeldItem() != null) { + mobData + .append("\nItem: ") + .append(((EntityLiving) mob).getHeldItem()) + .append("\nItem Display Name: ") + .append(((EntityLiving) mob).getHeldItem().getDisplayName()!= null ? ((EntityLiving) mob).getHeldItem().getDisplayName() : "null") + .append("\nItem Tag Compound: ") + .append(((EntityLiving) mob).getHeldItem().getTagCompound().toString() != null ? ((EntityLiving) mob).getHeldItem().getTagCompound().toString() : "null") + .append("\nItem Tag Compound Extra Attributes: ") + .append(((EntityLiving) mob).getHeldItem().getTagCompound().getTag("ExtraAttributes") != null ? ((EntityLiving) mob).getHeldItem().getTagCompound().getTag("ExtraAttributes").toString() : "null"); + } else { + mobData.append("\nItem: null"); + } + + //Armor + mobData + .append("\nBoots: ") + .append(((EntityLiving) mob).getCurrentArmor(0).getTagCompound() != null ? ((EntityLiving) mob).getCurrentArmor(0).getTagCompound().toString() : "null") + .append("\nLeggings: ") + .append(((EntityLiving) mob).getCurrentArmor(1).getTagCompound() != null ? ((EntityLiving) mob).getCurrentArmor(1).getTagCompound() : "null") + .append("\nChestplate: ") + .append(((EntityLiving) mob).getCurrentArmor(2).getTagCompound() != null ? ((EntityLiving) mob).getCurrentArmor(2).getTagCompound() : "null") + .append("\nHelmet: ") + .append(((EntityLiving) mob).getCurrentArmor(3).getTagCompound() != null ? ((EntityLiving) mob).getCurrentArmor(3).getTagCompound() : "null") + .append("\n\n"); + + return mobData; + } + + public StringBuilder armorStandDataBuilder(EntityArmorStand armorStand) { + StringBuilder armorStandData = new StringBuilder(); + + //Preventing Null Pointer Exception + //Entity Information + armorStandData + .append("Entity Id: ") + .append(armorStand.getEntityId()) + .append("\nMob: ") + .append(armorStand.getName() != null ? armorStand.getName() : "null") + .append("\nCustom Name: ") + .append(armorStand.getCustomNameTag() != null ? armorStand.getCustomNameTag() : "null"); + + //Held Item + if (armorStand.getHeldItem() != null) { + armorStandData + .append("\nItem: ") + .append(armorStand.getHeldItem()) + .append("\nItem Display Name: ") + .append(armorStand.getHeldItem().getDisplayName() != null ? armorStand.getHeldItem().getDisplayName() : "null") + .append("\nItem Tag Compound: ") + .append(armorStand.getHeldItem().getTagCompound().toString() != null ? armorStand.getHeldItem().getTagCompound().toString() : "null") + .append("\nItem Tag Compound Extra Attributes: ") + .append(armorStand.getHeldItem().getTagCompound().getTag("ExtraAttributes") != null ? armorStand.getHeldItem().getTagCompound().getTag("ExtraAttributes") : "null"); + } else { - Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - EnumChatFormatting.RED + "Disabled pack developer mode.")); + armorStandData.append("\nItem: null"); } + + //Armor + armorStandData + .append("\nBoots: ") + .append(armorStand.getCurrentArmor(0).getTagCompound() != null ? armorStand.getCurrentArmor(0).getTagCompound() : "null") + .append("\nLeggings: ") + .append(armorStand.getCurrentArmor(1).getTagCompound() != null ? armorStand.getCurrentArmor(1).getTagCompound() : "null") + .append("\nChestplate: ") + .append(armorStand.getCurrentArmor(2).getTagCompound() != null ? armorStand.getCurrentArmor(2).getTagCompound() : "null") + .append("\nHelmet: ") + .append(armorStand.getCurrentArmor(3).getTagCompound() != null ? armorStand.getCurrentArmor(3).getTagCompound() : "null"); + armorStandData.append("\n\n"); + return armorStandData; } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.java index 9669be60..f84b238d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.java @@ -46,7 +46,7 @@ public class HelpCommand extends ClientCommandBase { "\u00a76/neureloadrepo \u00a7r\u00a77- Debug command with repo.", "", "\u00a76\u00a7lDev commands:", - "\u00a76/neupackdev \u00a7r\u00a77- pack creator command - getnpc" + "\u00a76/neupackdev \u00a7r\u00a77- pack creator command - getnpc, getmob(s), getarmorstand(s), getall. Optional radius argument for all. " ); for (String neuHelpMessage : neuHelpMessages) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(neuHelpMessage)); |