From a0e7d174472d034142003e58a42d6beefe36a92b Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 16 Feb 2021 03:08:30 +0800 Subject: PRE21 --- .../notenoughupdates/NEUEventListener.java | 22 +- .../moulberry/notenoughupdates/NEUOverlay.java | 28 +- .../notenoughupdates/NotEnoughUpdates.java | 25 +- .../notenoughupdates/core/BackgroundBlur.java | 12 +- .../notenoughupdates/core/GuiElementTextField.java | 3 + .../notenoughupdates/core/config/Position.java | 33 +- .../core/config/gui/GuiOptionEditorDropdown.java | 1 + .../core/config/gui/GuiPositionEditor.java | 29 + .../notenoughupdates/cosmetics/NEUCape.java | 27 +- .../notenoughupdates/cosmetics/ShaderManager.java | 1 + .../notenoughupdates/dungeons/DungeonMap.java | 1 + .../miscfeatures/CustomItemEffects.java | 4 +- .../miscfeatures/CustomSkulls.java | 283 +++++++++ .../miscfeatures/DamageCommas.java | 43 +- .../miscfeatures/DwarvenMinesTextures.java | 4 +- .../miscfeatures/ItemCooldowns.java | 8 +- .../notenoughupdates/miscfeatures/PetInfo.java | 372 ------------ .../miscfeatures/PetInfoOverlay.java | 646 +++++++++++++++++++++ .../mixins/MixinTileEntitySkullRenderer.java | 24 + .../notenoughupdates/options/NEUConfig.java | 59 +- .../notenoughupdates/options/NEUConfigEditor.java | 2 +- .../overlays/AuctionSearchOverlay.java | 187 ++++-- .../notenoughupdates/overlays/FarmingOverlay.java | 35 +- .../notenoughupdates/overlays/OverlayManager.java | 26 + .../overlays/RancherBootOverlay.java | 1 + .../notenoughupdates/overlays/TextOverlay.java | 78 ++- .../profileviewer/GuiProfileViewer.java | 13 +- .../profileviewer/ProfileViewer.java | 5 +- .../notenoughupdates/util/XPInformation.java | 6 +- 29 files changed, 1420 insertions(+), 558 deletions(-) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomSkulls.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfo.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinTileEntitySkullRenderer.java (limited to 'src/main/java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java index 710561f8..adf204d1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUEventListener.java @@ -169,6 +169,10 @@ public class NEUEventListener { } else { itemPreloader.shutdown(); } + + for(TextOverlay overlay : OverlayManager.textOverlays) { + overlay.shouldUpdateFrequent = true; + } } boolean longUpdate = false; @@ -183,9 +187,6 @@ public class NEUEventListener { DungeonWin.tick(); FlyFix.tick(); - for(TextOverlay overlay : OverlayManager.textOverlays) { - overlay.shouldUpdateFrequent = true; - } if(longUpdate) { /*for(Entity entity : Minecraft.getMinecraft().theWorld.loadedEntityList) { @@ -204,11 +205,11 @@ public class NEUEventListener { ProfileApiSyncer.getInstance().tick(); DamageCommas.tick(); BackgroundBlur.markDirty(); - if(neu.config.overlay.enablePetInfo || neu.config.treecap.enableMonkeyCheck || neu.config.notifications.showWrongPetMsg){ - PetInfo.longTick(); - } - for(TextOverlay overlay : OverlayManager.textOverlays) { - overlay.tick(); + + if(neu.hasSkyblockScoreboard()) { + for(TextOverlay overlay : OverlayManager.textOverlays) { + overlay.tick(); + } } if(TradeWindow.hypixelTradeWindowActive()) { for(int i=0; i<16; i++) { @@ -416,7 +417,7 @@ public class NEUEventListener { @SubscribeEvent public void onRenderGameOverlayPost(RenderGameOverlayEvent.Post event) { long timeRemaining = 15000 - (System.currentTimeMillis() - notificationDisplayMillis); - if(event.type == RenderGameOverlayEvent.ElementType.ALL) { + if(neu.hasSkyblockScoreboard() && event.type == RenderGameOverlayEvent.ElementType.ALL) { DungeonWin.render(event.partialTicks); for(TextOverlay overlay : OverlayManager.textOverlays) { if(OverlayManager.dontRenderOverlay != null && OverlayManager.dontRenderOverlay.isAssignableFrom(overlay.getClass())) { @@ -470,7 +471,8 @@ public class NEUEventListener { AtomicBoolean missingRecipe = new AtomicBoolean(false); @SubscribeEvent public void onGuiOpen(GuiOpenEvent event) { - if(Minecraft.getMinecraft().currentScreen instanceof GuiScreenElementWrapper && + if((Minecraft.getMinecraft().currentScreen instanceof GuiScreenElementWrapper || + Minecraft.getMinecraft().currentScreen instanceof GuiItemRecipe) && event.gui == null && !(Keyboard.getEventKeyState() && Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) && System.currentTimeMillis() - NotEnoughUpdates.INSTANCE.lastOpenedGui < 500) { NotEnoughUpdates.INSTANCE.lastOpenedGui = 0; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index 7a43235a..a87d266a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -99,7 +99,7 @@ public class NEUOverlay extends Gui { private InfoPane activeInfoPane = null; private TreeSet searchedItems = null; - private JsonObject[] searchedItemsArr = null; + private final List searchedItemsArr = new ArrayList<>(); private HashMap> searchedItemsSubgroup = new HashMap<>(); @@ -1227,7 +1227,9 @@ public class NEUOverlay extends Gui { this.searchedItems = searchedItems; this.searchedItemsSubgroup = searchedItemsSubgroup; - this.searchedItemsArr = null; + synchronized(this.searchedItemsArr) { + this.searchedItemsArr.clear(); + } redrawItems = true; }); @@ -1237,18 +1239,15 @@ public class NEUOverlay extends Gui { * Returns an index-able array containing the elements in searchedItems. * Whenever searchedItems is updated in updateSearch(), the array is recreated here. */ - public JsonObject[] getSearchedItems() { + public List getSearchedItems() { if(searchedItems == null) { updateSearch(); - return new JsonObject[0]; + return new ArrayList<>(); } - if(searchedItemsArr==null) { - searchedItemsArr = new JsonObject[searchedItems.size()]; - int i=0; - for(JsonObject item : searchedItems) { - searchedItemsArr[i] = item; - i++; + if(searchedItems.size() > 0 && searchedItemsArr.size() == 0) { + synchronized(searchedItemsArr) { + searchedItemsArr.addAll(searchedItems); } } return searchedItemsArr; @@ -1261,8 +1260,9 @@ public class NEUOverlay extends Gui { public JsonObject getSearchedItemPage(int index) { if(index < getSlotsXSize()*getSlotsYSize()) { int actualIndex = index + getSlotsXSize()*getSlotsYSize()*page; - if(actualIndex < getSearchedItems().length) { - return getSearchedItems()[actualIndex]; + List searchedItems = getSearchedItems(); + if(actualIndex < searchedItems.size()) { + return searchedItems.get(actualIndex); } else { return null; } @@ -1352,8 +1352,8 @@ public class NEUOverlay extends Gui { } public int getMaxPages() { - if(getSearchedItems().length == 0) return 1; - return (int)Math.ceil(getSearchedItems().length/(float)getSlotsYSize()/getSlotsXSize()); + if(getSearchedItems().size() == 0) return 1; + return (int)Math.ceil(getSearchedItems().size()/(float)getSlotsYSize()/getSlotsXSize()); } public int getSearchBarYSize() { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index dea4d520..55ba7756 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -25,6 +25,7 @@ import io.github.moulberry.notenoughupdates.miscgui.NEUOverlayPlacements; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.options.NEUConfigEditor; import io.github.moulberry.notenoughupdates.overlays.FuelBar; +import io.github.moulberry.notenoughupdates.overlays.OverlayManager; import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; import io.github.moulberry.notenoughupdates.profileviewer.PlayerStats; import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; @@ -38,6 +39,7 @@ import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.resources.IReloadableResourceManager; import net.minecraft.client.settings.KeyBinding; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; @@ -45,7 +47,6 @@ import net.minecraft.event.ClickEvent; import net.minecraft.event.HoverEvent; import net.minecraft.item.ItemMap; import net.minecraft.item.ItemStack; -import net.minecraft.network.play.client.C13PacketPlayerAbilities; import net.minecraft.scoreboard.ScoreObjective; import net.minecraft.scoreboard.Scoreboard; import net.minecraft.util.*; @@ -77,8 +78,6 @@ import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -import java.util.regex.Matcher; -import java.util.regex.Pattern; @Mod(modid = NotEnoughUpdates.MODID, version = NotEnoughUpdates.VERSION, clientSideOnly = true) public class NotEnoughUpdates { @@ -669,6 +668,14 @@ public class NotEnoughUpdates { } }); + SimpleCommand dnCommand = new SimpleCommand("dn", new SimpleCommand.ProcessCommandRunnable() { + @Override + public void processCommand(ICommandSender sender, String[] args) { + Minecraft.getMinecraft().thePlayer.sendChatMessage("/warp dungeon_hub"); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.AQUA+"Warping to:"+EnumChatFormatting.YELLOW+" Deez Nuts lmao")); + } + }); + SimpleCommand viewCataCommand = new SimpleCommand("cata", new SimpleCommand.ProcessCommandRunnable() { @Override public void processCommand(ICommandSender sender, String[] args) { @@ -879,7 +886,10 @@ public class NotEnoughUpdates { public void preinit(FMLPreInitializationEvent event) { INSTANCE = this; - if(Minecraft.getMinecraft().getSession().getPlayerID().equalsIgnoreCase("ea9b1c5a-bf68-4fa2-9492-2d4e69693228")) throw new RuntimeException("Ding-dong, racism is wrong."); + String uuid = Minecraft.getMinecraft().getSession().getPlayerID(); + if(uuid.equalsIgnoreCase("ea9b1c5a-bf68-4fa2-9492-2d4e69693228")) throw new RuntimeException("Ding-dong, racism is wrong."); + if(uuid.equalsIgnoreCase("1f4bc571-783a-490a-8ef6-54d18bb72c7c")) throw new RuntimeException("Oops misclicked"); + if(uuid.equalsIgnoreCase("784747a0-3ac9-4ad6-bc75-8cf1bc9d7080")) throw new RuntimeException("Oops did it again"); neuDir = new File(event.getModConfigurationDirectory(), "notenoughupdates"); neuDir.mkdirs(); @@ -917,7 +927,11 @@ public class NotEnoughUpdates { MinecraftForge.EVENT_BUS.register(new DwarvenMinesWaypoints()); MinecraftForge.EVENT_BUS.register(new FuelBar()); MinecraftForge.EVENT_BUS.register(XPInformation.getInstance()); - MinecraftForge.EVENT_BUS.register(new PetInfo()); + MinecraftForge.EVENT_BUS.register(OverlayManager.petInfoOverlay); + + if(Minecraft.getMinecraft().getResourceManager() instanceof IReloadableResourceManager) { + ((IReloadableResourceManager)Minecraft.getMinecraft().getResourceManager()).registerReloadListener(CustomSkulls.getInstance()); + } ClientCommandHandler.instance.registerCommand(collectionLogCommand); ClientCommandHandler.instance.registerCommand(cosmeticsCommand); @@ -930,6 +944,7 @@ public class NotEnoughUpdates { ClientCommandHandler.instance.registerCommand(viewProfileCommand); ClientCommandHandler.instance.registerCommand(viewProfileShortCommand); ClientCommandHandler.instance.registerCommand(dhCommand); + ClientCommandHandler.instance.registerCommand(dnCommand); if(!Loader.isModLoaded("skyblockextras")) ClientCommandHandler.instance.registerCommand(viewCataCommand); ClientCommandHandler.instance.registerCommand(peekCommand); ClientCommandHandler.instance.registerCommand(tutorialCommand); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/BackgroundBlur.java b/src/main/java/io/github/moulberry/notenoughupdates/core/BackgroundBlur.java index d23df8c3..b0f0bff3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/BackgroundBlur.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/BackgroundBlur.java @@ -80,6 +80,7 @@ public class BackgroundBlur { } remove.remove((float)NotEnoughUpdates.INSTANCE.config.itemlist.bgBlurFactor); + lastBlurUse.keySet().removeAll(remove); blurOutput.keySet().removeAll(remove); requestedBlurs.clear(); @@ -165,11 +166,10 @@ public class BackgroundBlur { //Corrupted shader? return; } - if(blurFactor != lastBgBlurFactor) { - blurShaderHorz.getShaderManager().getShaderUniform("Radius").set(blurFactor); - blurShaderVert.getShaderManager().getShaderUniform("Radius").set(blurFactor); - lastBgBlurFactor = blurFactor; - } + + blurShaderHorz.getShaderManager().getShaderUniform("Radius").set(blurFactor); + blurShaderVert.getShaderManager().getShaderUniform("Radius").set(blurFactor); + GL11.glPushMatrix(); /*GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, Minecraft.getMinecraft().getFramebuffer().framebufferObject); GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, blurOutputVert.framebufferObject); @@ -192,6 +192,7 @@ public class BackgroundBlur { */ public static void renderBlurredBackground(float blurStrength, int screenWidth, int screenHeight, int x, int y, int blurWidth, int blurHeight) { + if(blurStrength < 0.5) return; requestedBlurs.add(blurStrength); if(!OpenGlHelper.isFramebufferEnabled() || !OpenGlHelper.areShadersSupported()) return; @@ -200,6 +201,7 @@ public class BackgroundBlur { Framebuffer fb = blurOutput.get(blurStrength); if(fb == null) { + System.out.println("Blur not found:"+blurStrength); fb = blurOutput.values().iterator().next(); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementTextField.java b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementTextField.java index 56dbe77d..b2f947d6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementTextField.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementTextField.java @@ -90,6 +90,9 @@ public class GuiElementTextField { return textField.getText(); } + public void setFocus(boolean focus) { + this.focus = focus; + } public boolean getFocus() { return focus; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/Position.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/Position.java index e7198631..66df27c6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/Position.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/Position.java @@ -27,8 +27,15 @@ public class Position { this.centerY = centerY; } + public void set(Position other) { + this.x = other.x; + this.y = other.y; + this.centerX = other.centerX; + this.centerY = other.centerY; + } + public Position clone() { - return new Position(x, y); + return new Position(x, y, centerX, centerY); } public boolean isCenterX() { @@ -90,14 +97,14 @@ public class Position { if(centerX) { if(wasPositiveX) { - if(this.x > screenWidth/2-objWidth) { - deltaX += screenWidth/2-objWidth-this.x; - this.x = screenWidth/2-objWidth; + if(this.x > screenWidth/2-objWidth/2) { + deltaX += screenWidth/2-objWidth/2-this.x; + this.x = screenWidth/2-objWidth/2; } } else { - if(this.x < -screenWidth/2) { - deltaX += -screenWidth/2-this.x; - this.x = -screenWidth/2; + if(this.x < -screenWidth/2+objWidth/2) { + deltaX += -screenWidth/2+objWidth/2-this.x; + this.x = -screenWidth/2+objWidth/2; } } return deltaX; @@ -139,14 +146,14 @@ public class Position { if(centerY) { if(wasPositiveY) { - if(this.y > screenHeight/2-objHeight) { - deltaY += screenHeight/2-objHeight-this.y; - this.y = screenHeight/2-objHeight; + if(this.y > screenHeight/2-objHeight/2) { + deltaY += screenHeight/2-objHeight/2-this.y; + this.y = screenHeight/2-objHeight/2; } } else { - if(this.y < -screenHeight/2) { - deltaY += -screenHeight/2-this.y; - this.y = -screenHeight/2; + if(this.y < -screenHeight/2+objHeight/2) { + deltaY += -screenHeight/2+objHeight/2-this.y; + this.y = -screenHeight/2+objHeight/2; } } return deltaY; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDropdown.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDropdown.java index 9ca6b85b..0451b459 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDropdown.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDropdown.java @@ -19,6 +19,7 @@ public class GuiOptionEditorDropdown extends GuiOptionEditor { public GuiOptionEditorDropdown(ConfigProcessor.ProcessedOption option, String[] values, int selected, boolean useOrdinal) { super(option); + if(selected >= values.length) selected = values.length; this.values = values; this.selected = selected; this.useOrdinal = useOrdinal; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiPositionEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiPositionEditor.java index 3b0df42d..e979e832 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiPositionEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiPositionEditor.java @@ -6,6 +6,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; +import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import java.io.IOException; @@ -83,6 +84,12 @@ public class GuiPositionEditor extends GuiScreen { if(guiScaleOverride >= 0) { Utils.pushGuiScale(-1); } + + scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + Utils.drawStringCentered("Position Editor", Minecraft.getMinecraft().fontRendererObj, + scaledResolution.getScaledWidth()/2, 8, true, 0xffffff); + Utils.drawStringCentered("R to Reset - Arrow keys/mouse to move", Minecraft.getMinecraft().fontRendererObj, + scaledResolution.getScaledWidth()/2, 18, true, 0xffffff); } @Override @@ -117,6 +124,28 @@ public class GuiPositionEditor extends GuiScreen { } } + @Override + protected void keyTyped(char typedChar, int keyCode) throws IOException { + Keyboard.enableRepeatEvents(true); + + if(keyCode == Keyboard.KEY_R) { + position.set(originalPosition); + } else if(!clicked) { + boolean shiftHeld = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); + int dist = shiftHeld ? 10 : 1; + if(keyCode == Keyboard.KEY_DOWN) { + position.moveY(dist, elementHeight, new ScaledResolution(Minecraft.getMinecraft())); + } else if(keyCode == Keyboard.KEY_UP) { + position.moveY(-dist, elementHeight, new ScaledResolution(Minecraft.getMinecraft())); + } else if(keyCode == Keyboard.KEY_LEFT) { + position.moveX(-dist, elementWidth, new ScaledResolution(Minecraft.getMinecraft())); + } else if(keyCode == Keyboard.KEY_RIGHT) { + position.moveX(dist, elementWidth, new ScaledResolution(Minecraft.getMinecraft())); + } + } + super.keyTyped(typedChar, keyCode); + } + @Override protected void mouseReleased(int mouseX, int mouseY, int state) { super.mouseReleased(mouseX, mouseY, state); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/NEUCape.java b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/NEUCape.java index 3af37cdd..927ef8cf 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/NEUCape.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/NEUCape.java @@ -310,29 +310,30 @@ public class NEUCape { } private void loadShaderUniforms(ShaderManager shaderManager) { + String shaderId = "capes/"+shaderName+"/"+shaderName; if(shaderName.equalsIgnoreCase("fade_cape")) { - shaderManager.loadData(shaderName, "millis", (int)(System.currentTimeMillis()-startTime)); + shaderManager.loadData(shaderId, "millis", (int)(System.currentTimeMillis()-startTime)); } else if(shaderName.equalsIgnoreCase("space_cape")) { - shaderManager.loadData(shaderName, "millis", (int)(System.currentTimeMillis()-startTime)); - shaderManager.loadData(shaderName, "eventMillis", (int)(System.currentTimeMillis()-eventMillis)); - shaderManager.loadData(shaderName, "eventRand", eventRandom); + shaderManager.loadData(shaderId, "millis", (int)(System.currentTimeMillis()-startTime)); + shaderManager.loadData(shaderId, "eventMillis", (int)(System.currentTimeMillis()-eventMillis)); + shaderManager.loadData(shaderId, "eventRand", eventRandom); } else if(shaderName.equalsIgnoreCase("mcworld_cape")) { - shaderManager.loadData(shaderName, "millis", (int) (System.currentTimeMillis() - startTime)); + shaderManager.loadData(shaderId, "millis", (int) (System.currentTimeMillis() - startTime)); } else if(shaderName.equalsIgnoreCase("lava_cape")) { - shaderManager.loadData(shaderName, "millis", (int) (System.currentTimeMillis() - startTime)); + shaderManager.loadData(shaderId, "millis", (int) (System.currentTimeMillis() - startTime)); } else if(shaderName.equalsIgnoreCase("lightning_cape")) { - shaderManager.loadData(shaderName, "millis", (int) (System.currentTimeMillis() - startTime)); + shaderManager.loadData(shaderId, "millis", (int) (System.currentTimeMillis() - startTime)); } else if(shaderName.equalsIgnoreCase("biscuit_cape") || shaderName.equalsIgnoreCase("shiny_cape")) { - shaderManager.loadData(shaderName, "millis", (int) (System.currentTimeMillis() - startTime)); - shaderManager.loadData(shaderName, "eventMillis", (int)(System.currentTimeMillis()-eventMillis)); + shaderManager.loadData(shaderId, "millis", (int) (System.currentTimeMillis() - startTime)); + shaderManager.loadData(shaderId, "eventMillis", (int)(System.currentTimeMillis()-eventMillis)); } else if(shaderName.equalsIgnoreCase("negative")) { - shaderManager.loadData(shaderName, "screensize", new Vector2f( + shaderManager.loadData(shaderId, "screensize", new Vector2f( Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight )); } else if(shaderName.equalsIgnoreCase("void")) { - shaderManager.loadData(shaderName, "millis", (int) (System.currentTimeMillis() - startTime)); - shaderManager.loadData(shaderName, "screensize", new Vector2f( + shaderManager.loadData(shaderId, "millis", (int) (System.currentTimeMillis() - startTime)); + shaderManager.loadData(shaderId, "screensize", new Vector2f( Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight )); @@ -375,7 +376,7 @@ public class NEUCape { GL11.glTranslatef(-(float)viewerX, -(float)viewerY, -(float)viewerZ); ShaderManager shaderManager = ShaderManager.getInstance(); - shaderManager.loadShader(shaderName); + shaderManager.loadShader("capes/"+shaderName+"/"+shaderName); loadShaderUniforms(shaderManager); renderCape(player, e.partialRenderTick); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/ShaderManager.java b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/ShaderManager.java index a750f597..70fe6745 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/ShaderManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/cosmetics/ShaderManager.java @@ -151,6 +151,7 @@ public class ShaderManager { } return source.toString(); } catch(IOException e) { + e.printStackTrace(); } return ""; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java index d4b161de..f6b5b722 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java @@ -1382,6 +1382,7 @@ public class DungeonMap { @SubscribeEvent public void onRenderOverlay(RenderGameOverlayEvent.Post event) { + if(!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return; if(event.type == RenderGameOverlayEvent.ElementType.ALL) { if(!NotEnoughUpdates.INSTANCE.config.dungeonMap.dmEnable) return; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomItemEffects.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomItemEffects.java index 8e334d3b..e198e8e5 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomItemEffects.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomItemEffects.java @@ -41,7 +41,7 @@ public class CustomItemEffects { public static final CustomItemEffects INSTANCE = new CustomItemEffects(); - private static final int MAX_BUILDERS_BLOCKS = 164; + private static final int MAX_BUILDERS_BLOCKS = 241; public long aoteUseMillis = 0; @@ -389,7 +389,7 @@ public class CustomItemEffects { } } else if(NotEnoughUpdates.INSTANCE.config.builderWand.enableWandOverlay) { if(heldInternal.equals("BUILDERS_WAND")) { - int maxBlocks = 164; + int maxBlocks = MAX_BUILDERS_BLOCKS; if (event.target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { IBlockState hover = Minecraft.getMinecraft().theWorld.getBlockState(event.target.getBlockPos().offset(event.target.sideHit, 1)); if(hover.getBlock() == Blocks.air) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomSkulls.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomSkulls.java new file mode 100644 index 00000000..30b99e1c --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomSkulls.java @@ -0,0 +1,283 @@ +package io.github.moulberry.notenoughupdates.miscfeatures; + +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.minecraft.MinecraftProfileTexture; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.util.TexLoc; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelHumanoidHead; +import net.minecraft.client.model.ModelSkeletonHead; +import net.minecraft.client.renderer.EntityRenderer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.block.model.*; +import net.minecraft.client.renderer.texture.*; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.client.resources.DefaultPlayerSkin; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.client.resources.IResourceManagerReloadListener; +import net.minecraft.client.resources.model.IBakedModel; +import net.minecraft.client.resources.model.ModelBakery; +import net.minecraft.client.resources.model.ModelRotation; +import net.minecraft.client.resources.model.SimpleBakedModel; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.*; + +public class CustomSkulls implements IResourceManagerReloadListener { + + private static final CustomSkulls INSTANCE = new CustomSkulls(); + + public static CustomSkulls getInstance() { + return INSTANCE; + } + + private ResourceLocation atlas = new ResourceLocation("notenoughupdates:custom_skull_textures_atlas"); + private ResourceLocation configuration = new ResourceLocation("notenoughupdates:custom_skull_textures/customskull.json"); + protected final TextureMap textureMap = new TextureMap("custom_skull_textures"); + + protected final Map sprites = Maps.newHashMap(); + + private final FaceBakery faceBakery = new FaceBakery(); + private final ModelSkeletonHead humanoidHead = new ModelHumanoidHead(); + + private final HashMap customSkulls = new HashMap<>(); + + private final Gson gson = new GsonBuilder().create(); + + private class CustomSkull { + private ModelBlock model; + private IBakedModel modelBaked; + + private ResourceLocation texture; + } + + @Override + public void onResourceManagerReload(IResourceManager resourceManager) { + customSkulls.clear(); + + try(BufferedReader reader = new BufferedReader(new InputStreamReader( + Minecraft.getMinecraft().getResourceManager().getResource(configuration).getInputStream(), StandardCharsets.UTF_8))) { + JsonObject json = gson.fromJson(reader, JsonObject.class); + + if(json == null) return; + + for(Map.Entry entry : json.entrySet()) { + if(entry.getValue().isJsonObject()) { + JsonObject obj = entry.getValue().getAsJsonObject(); + if(obj.has("model")) { + String location = obj.get("model").getAsString(); + ResourceLocation loc = new ResourceLocation("notenoughupdates:custom_skull_textures/" + location + ".json"); + + CustomSkull skull = new CustomSkull(); + skull.model = ModelBlock.deserialize(new InputStreamReader(Minecraft.getMinecraft().getResourceManager().getResource(loc).getInputStream())); + + customSkulls.put(entry.getKey(), skull); + } else if(obj.has("texture")) { + String location = obj.get("texture").getAsString(); + ResourceLocation loc = new ResourceLocation("notenoughupdates:custom_skull_textures/" + location + ".png"); + + CustomSkull skull = new CustomSkull(); + skull.texture = loc; + + customSkulls.put(entry.getKey(), skull); + } + } + } + + loadSprites(); + + for(CustomSkull skull : customSkulls.values()) { + if(skull.model != null) { + skull.modelBaked = bakeModel(skull.model, ModelRotation.X0_Y0, false); + } + } + + Minecraft.getMinecraft().getTextureManager().loadTickableTexture(atlas, textureMap); + } catch(Exception e) { + e.printStackTrace(); + } + } + + private void loadSprites() { + final Set set = this.getAllTextureLocations(); + set.remove(TextureMap.LOCATION_MISSING_TEXTURE); + IIconCreator iiconcreator = new IIconCreator() { + public void registerSprites(TextureMap iconRegistry) { + for(ResourceLocation resourcelocation : set) { + TextureAtlasSprite textureatlassprite = iconRegistry.registerSprite(resourcelocation); + CustomSkulls.this.sprites.put(resourcelocation, textureatlassprite); + } + } + }; + this.textureMap.loadSprites(Minecraft.getMinecraft().getResourceManager(), iiconcreator); + this.sprites.put(new ResourceLocation("missingno"), this.textureMap.getMissingSprite()); + } + + protected Set getAllTextureLocations() { + Set set = new HashSet<>(); + + for(CustomSkull skull : customSkulls.values()) { + if(skull.model != null) { + set.addAll(getTextureLocations(skull.model)); + } + } + + return set; + } + + protected Set getTextureLocations(ModelBlock modelBlock) { + Set set = Sets.newHashSet(); + + for(BlockPart blockpart : modelBlock.getElements()) { + for(BlockPartFace blockpartface : blockpart.mapFaces.values()) { + ResourceLocation resourcelocation = new ResourceLocation("notenoughupdates", modelBlock.resolveTextureName(blockpartface.texture)); + set.add(resourcelocation); + } + } + + set.add(new ResourceLocation("notenoughupdates", modelBlock.resolveTextureName("particle"))); + return set; + } + + protected IBakedModel bakeModel(ModelBlock modelBlockIn, net.minecraftforge.client.model.ITransformation modelRotationIn, boolean uvLocked) { + TextureAtlasSprite textureatlassprite = this.sprites.get(new ResourceLocation("notenoughupdates", modelBlockIn.resolveTextureName("particle"))); + SimpleBakedModel.Builder simplebakedmodel$builder = (new SimpleBakedModel.Builder(modelBlockIn)).setTexture(textureatlassprite); + + for(BlockPart blockpart : modelBlockIn.getElements()) { + for(EnumFacing enumfacing : blockpart.mapFaces.keySet()) { + BlockPartFace blockpartface = blockpart.mapFaces.get(enumfacing); + TextureAtlasSprite textureatlassprite1 = this.sprites.get(new ResourceLocation("notenoughupdates", modelBlockIn.resolveTextureName(blockpartface.texture))); + + if(blockpartface.cullFace == null || !net.minecraftforge.client.model.TRSRTransformation.isInteger(modelRotationIn.getMatrix())) { + simplebakedmodel$builder.addGeneralQuad(this.makeBakedQuad(blockpart, blockpartface, textureatlassprite1, enumfacing, modelRotationIn, uvLocked)); + } else { + simplebakedmodel$builder.addFaceQuad(modelRotationIn.rotate(blockpartface.cullFace), this.makeBakedQuad(blockpart, blockpartface, textureatlassprite1, enumfacing, modelRotationIn, uvLocked)); + } + } + } + + return simplebakedmodel$builder.makeBakedModel(); + } + + private BakedQuad makeBakedQuad(BlockPart p_177589_1_, BlockPartFace p_177589_2_, TextureAtlasSprite p_177589_3_, EnumFacing p_177589_4_, ModelRotation p_177589_5_, boolean p_177589_6_) { + return makeBakedQuad(p_177589_1_, p_177589_2_, p_177589_3_, p_177589_4_, (net.minecraftforge.client.model.ITransformation) p_177589_5_, p_177589_6_); + } + + protected BakedQuad makeBakedQuad(BlockPart p_177589_1_, BlockPartFace p_177589_2_, TextureAtlasSprite p_177589_3_, EnumFacing p_177589_4_, net.minecraftforge.client.model.ITransformation p_177589_5_, boolean p_177589_6_) { + return this.faceBakery.makeBakedQuad(p_177589_1_.positionFrom, p_177589_1_.positionTo, p_177589_2_, p_177589_3_, p_177589_4_, p_177589_5_, p_177589_1_.partRotation, p_177589_6_, p_177589_1_.shade); + } + + private void renderModel(IBakedModel model, int color) { + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + worldrenderer.begin(7, DefaultVertexFormats.ITEM); + + for(EnumFacing enumfacing : EnumFacing.values()) { + this.renderQuads(worldrenderer, model.getFaceQuads(enumfacing), color); + } + + this.renderQuads(worldrenderer, model.getGeneralQuads(), color); + tessellator.draw(); + } + + private void renderQuads(WorldRenderer renderer, List quads, int color) { + int i = 0; + + for(int j = quads.size(); i < j; ++i) { + BakedQuad bakedquad = quads.get(i); + int k = color; + + net.minecraftforge.client.model.pipeline.LightUtil.renderQuadColor(renderer, bakedquad, k); + } + } + + public boolean renderSkull(float xOffset, float yOffset, float zOffset, EnumFacing placedDirection, + float rotationDeg, int skullType, GameProfile skullOwner, int damage) { + if(skullOwner == null || placedDirection != EnumFacing.UP || skullType != 3) { + return false; + } + + CustomSkull skull = customSkulls.get(skullOwner.getId().toString()); + if(skull == null) { + return false; + } + + if(skull.modelBaked != null) { + Minecraft.getMinecraft().getTextureManager().bindTexture(atlas); + GlStateManager.pushMatrix(); + GlStateManager.disableCull(); + + GlStateManager.translate(xOffset + 0.5F, yOffset, zOffset + 0.5F); + + GlStateManager.enableRescaleNormal(); + GlStateManager.enableAlpha(); + GlStateManager.scale(1, 1, -1); + GlStateManager.translate(-0.5f, 0.25f, -0.5f); + renderModel(skull.modelBaked, 0xffffffff); + GlStateManager.popMatrix(); + } else if(skull.texture != null) { + if( Minecraft.getMinecraft().getTextureManager().getTexture(skull.texture) == null) { + try { + BufferedImage image = ImageIO.read(Minecraft.getMinecraft().getResourceManager().getResource(skull.texture).getInputStream()); + int size = Math.max(image.getHeight(), image.getWidth()); + + Minecraft.getMinecraft().getTextureManager().loadTexture(skull.texture, new AbstractTexture() { + @Override + public void loadTexture(IResourceManager resourceManager) { + TextureUtil.allocateTexture(this.getGlTextureId(), size, size); + + int[] rgb = new int[size*size]; + + image.getRGB(0, 0, image.getWidth(), image.getHeight(), rgb, 0, image.getWidth()); + + TextureUtil.uploadTexture(this.getGlTextureId(), rgb, size, size); + } + }); + } catch(IOException ignored) {} + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(skull.texture); + + GlStateManager.pushMatrix(); + GlStateManager.disableCull(); + + GlStateManager.translate(xOffset + 0.5F, yOffset, zOffset + 0.5F); + + float f = 0.0625F; + GlStateManager.enableRescaleNormal(); + GlStateManager.scale(-1.0F, -1.0F, 1.0F); + GlStateManager.enableAlpha(); + humanoidHead.render(null, 0.0F, 0.0F, 0.0F, rotationDeg, 0.0F, f); + GlStateManager.popMatrix(); + } else { + return false; + } + + return true; + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java index 36f4b908..a3f6dbf4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java @@ -1,6 +1,7 @@ package io.github.moulberry.notenoughupdates.miscfeatures; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.entity.item.EntityArmorStand; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; @@ -13,12 +14,14 @@ public class DamageCommas { private static final HashMap replacementMap = new HashMap<>(); + private static final EnumChatFormatting[] colours = {EnumChatFormatting.RED, EnumChatFormatting.GOLD, EnumChatFormatting.YELLOW, EnumChatFormatting.WHITE}; + public static void tick() { replacementMap.clear(); } public static IChatComponent replaceName(IChatComponent name) { - if(!NotEnoughUpdates.INSTANCE.config.misc.damageCommas) return name; + if(NotEnoughUpdates.INSTANCE.config.misc.damageCommas == 0) return name; String formatted = name.getFormattedText(); int hashCode = formatted.hashCode(); @@ -32,6 +35,37 @@ public class DamageCommas { if(formatted.length() >= 7 && formatted.startsWith("\u00A7f\u2727") && formatted.endsWith("\u2727\u00a7r")) { + if(NotEnoughUpdates.INSTANCE.config.misc.damageCommas == 2) { + String numbers = Utils.cleanColour(formatted.substring(3, formatted.length()-3)).trim().replaceAll("[^0-9]", ""); + try { + int damage = Integer.parseInt(numbers); + + String damageString; + if(damage > 999) { + damageString = Utils.shortNumberFormat(damage, 0); + } else { + damageString = NumberFormat.getIntegerInstance().format(damage); + } + + StringBuilder colouredString = new StringBuilder(); + int colourIndex = 0; + for(int i=0; i= '0' && c <= '9') { + colouredString.insert(0, c); + colouredString.insert(0, colours[colourIndex++ % colours.length]); + } else { + colouredString.insert(0, c); + } + } + + ChatComponentText ret = new ChatComponentText("\u00A7f\u2727"+colouredString+"\u00a7r\u2727\u00a7r"); + replacementMap.put(hashCode, ret); + return ret; + } catch(NumberFormatException ignored) {} + } + StringBuilder builder = new StringBuilder(); boolean numLast = false; boolean colLast = false; @@ -81,7 +115,12 @@ public class DamageCommas { try { int damage = Integer.parseInt(damageS); - String damageFormatted = NumberFormat.getIntegerInstance().format(damage); + String damageFormatted; + if(NotEnoughUpdates.INSTANCE.config.misc.damageCommas == 2 && damage > 999) { + damageFormatted = Utils.shortNumberFormat(damage, 0); + } else { + damageFormatted = NumberFormat.getIntegerInstance().format(damage); + } ChatComponentText ret = new ChatComponentText(EnumChatFormatting.GRAY+damageFormatted+EnumChatFormatting.RESET); replacementMap.put(hashCode, ret); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DwarvenMinesTextures.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DwarvenMinesTextures.java index 2fa8d5be..186f4abc 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DwarvenMinesTextures.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DwarvenMinesTextures.java @@ -168,8 +168,8 @@ public class DwarvenMinesTextures { if(modZ < 0) modZ += 16; ChunkCoordIntPair offset = new ChunkCoordIntPair(modX, modZ); - if(map.containsKey(offset)) { - IgnoreColumn ignore = map.get(offset); + IgnoreColumn ignore = map.get(offset); + if(ignore != null) { if(ignore.always) { return 1; } else { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCooldowns.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCooldowns.java index f3a21b1d..a2276b0e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCooldowns.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCooldowns.java @@ -53,13 +53,13 @@ public class ItemCooldowns { } public static long getTreecapCooldownWithPet(){ - if (NotEnoughUpdates.INSTANCE.config.treecap.enableMonkeyCheck && PetInfo.currentPet != null) { - PetInfo.pet pet = PetInfo.currentPet; + if (NotEnoughUpdates.INSTANCE.config.treecap.enableMonkeyCheck && PetInfoOverlay.currentPet != null) { + PetInfoOverlay.Pet pet = PetInfoOverlay.currentPet; if (pet.petLevel != null && pet.petType.equalsIgnoreCase("monkey") && - pet.rarity.equals(PetInfo.Rarity.LEGENDARY) + pet.rarity.equals(PetInfoOverlay.Rarity.LEGENDARY) ) { - return 2000 - (int) (2000 * (0.005 * (int) PetInfo.currentPet.petLevel.level)); + return 2000 - (int) (2000 * (0.005 * (int) PetInfoOverlay.currentPet.petLevel.level)); } } return 2000; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfo.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfo.java deleted file mode 100644 index 187ca897..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfo.java +++ /dev/null @@ -1,372 +0,0 @@ -package io.github.moulberry.notenoughupdates.miscfeatures; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import io.github.moulberry.notenoughupdates.NotEnoughUpdates; -import io.github.moulberry.notenoughupdates.core.config.gui.GuiPositionEditor; -import io.github.moulberry.notenoughupdates.options.NEUConfig; -import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; -import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; -import io.github.moulberry.notenoughupdates.util.Constants; -import io.github.moulberry.notenoughupdates.util.ProfileApiSyncer; -import io.github.moulberry.notenoughupdates.util.Utils; -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.GlStateManager; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; -import net.minecraftforge.client.event.ClientChatReceivedEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.event.world.WorldEvent; -import net.minecraftforge.fml.common.Loader; -import net.minecraftforge.fml.common.eventhandler.EventPriority; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import org.apache.commons.lang3.text.WordUtils; - -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.util.HashMap; -import java.util.Locale; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class PetInfo { - - private static final Pattern XP_GAIN_AND_SKILL_PATTERN = Pattern.compile("\\+(\\d*\\.?\\d*) (Farming|Mining|Combat|Foraging|Fishing|Enchanting|Alchemy) (\\(([0-9.,]+)/([0-9.,]+)\\))"); - private static final Pattern XP_BOOST_PATTERN = Pattern.compile("PET_ITEM_(COMBAT|FISHING|MINING|FORAGING|ALL|FARMING)_(SKILL|SKILLS)_BOOST_(COMMON|UNCOMMON|RARE|EPIC)"); - - public enum Rarity { - COMMON(0, 0, 1, EnumChatFormatting.WHITE), - UNCOMMON(6, 1, 2, EnumChatFormatting.GREEN), - RARE(11, 2, 3, EnumChatFormatting.BLUE), - EPIC(16, 3, 4, EnumChatFormatting.DARK_PURPLE), - LEGENDARY(20, 4, 5, EnumChatFormatting.GOLD), - MYTHIC(20, 4, 5, EnumChatFormatting.LIGHT_PURPLE); - - public int petOffset; - public EnumChatFormatting chatFormatting; - public int petId; - public int beastcreatMultiplyer; - - Rarity(int petOffset, int petId, int beastcreatMultiplyer, EnumChatFormatting chatFormatting){ - this.chatFormatting = chatFormatting; - this.petOffset = petOffset; - this.petId = petId; - this.beastcreatMultiplyer = beastcreatMultiplyer; - } - - public static Rarity getRarityFromColor(EnumChatFormatting chatFormatting){ - for (int i = 0; i < Rarity.values().length; i++) { - if (Rarity.values()[i].chatFormatting.equals(chatFormatting)) - return Rarity.values()[i]; - } - return COMMON; - } - } - - public static class pet { - public String petType; - public double petExp; - public Rarity rarity; - public GuiProfileViewer.PetLevel petLevel; - public String petXpType; - public String petItem; - } - - public static pet currentPet = null; - public static HashMap petList = new HashMap<>(); - - public static double currentXp = 0.0; - public static String currentXpType = ""; - public static int tamingLevel = 1; - public static double beastMultiplier = 0; - public static boolean ignoreNextXp = false; - - public static void clearPet(){ currentPet = null; } - - public float getLevelPercent(){ - DecimalFormat df = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); - try { - return Float.parseFloat(df.format(currentPet.petLevel.levelPercentage * 100f )); - }catch (Exception ignored){ return 0; } - } - - private static void getAndSetPet(ProfileViewer.Profile profile) { - JsonObject petObject = profile.getPetsInfo(profile.getLatestProfile()); - JsonObject skillInfo = profile.getSkillInfo(profile.getLatestProfile()); - JsonObject invInfo = profile.getInventoryInfo(profile.getLatestProfile()); - JsonObject profileInfo = profile.getProfileInformation(profile.getLatestProfile()); - if (invInfo != null && profileInfo != null){ - JsonObject stats = profileInfo.get("stats").getAsJsonObject(); - boolean hasBeastmasterCrest = false; - Rarity currentBeastRarity = Rarity.COMMON; - for (JsonElement talisman : invInfo.get("talisman_bag").getAsJsonArray()) { - if (talisman.isJsonNull()) continue; - String internalName = talisman.getAsJsonObject().get("internalname").getAsString(); - if (internalName.startsWith("BEASTMASTER_CREST")) { - hasBeastmasterCrest = true; - try { - Rarity talismanRarity = Rarity.valueOf(internalName.replace("BEASTMASTER_CREST_", "")); - if (talismanRarity.beastcreatMultiplyer > currentBeastRarity.beastcreatMultiplyer) currentBeastRarity = talismanRarity; - } catch (Exception ignored) {} - } - } - if (hasBeastmasterCrest) { - if (stats.has("mythos_kills")) { - int mk = stats.get("mythos_kills").getAsInt(); - double petXpBoost = mk > 10000 ? 1 : mk > 7500 ? 0.9 : mk > 5000 ? 0.8 : mk > 2500 ? 0.7 : - mk > 1000 ? 0.6 : mk > 500 ? 0.5 : mk > 250 ? 0.4 : mk > 100 ? 0.3 : mk > 25 ? 0.2 : 0.1; - beastMultiplier = petXpBoost * currentBeastRarity.beastcreatMultiplyer; - }else beastMultiplier = 0.1 * currentBeastRarity.beastcreatMultiplyer; - } - } - if (skillInfo != null) tamingLevel = skillInfo.get("level_skill_taming").getAsInt(); - JsonObject petsJson = Constants.PETS; - if (petsJson != null) { - if (petObject != null) { - boolean hasActivePet = false; - petList.clear(); - - for (int i = 0; i < petObject.getAsJsonArray("pets").size(); i++) { - JsonElement petElement = petObject.getAsJsonArray("pets").get(i); - JsonObject petObj = petElement.getAsJsonObject(); - pet pet = new pet(); - pet.petType = petObj.get("type").getAsString(); - Rarity rarity; - try { - rarity = Rarity.valueOf(petObj.get("tier").getAsString()); - } catch (Exception ignored) { - rarity = Rarity.COMMON; - } - pet.rarity = rarity; - pet.petExp = petObj.get("exp").getAsDouble(); - pet.petLevel = GuiProfileViewer.getPetLevel(petsJson.get("pet_levels").getAsJsonArray(), rarity.petOffset, (float) pet.petExp); - JsonElement heldItem = petObj.get("heldItem"); - pet.petItem = heldItem.isJsonNull() ? null : heldItem.getAsString(); - JsonObject petTypes = petsJson.get("pet_types").getAsJsonObject(); - pet.petXpType = petTypes.has(pet.petType) ? petTypes.get(pet.petType.toUpperCase()).getAsString().toLowerCase() : "unknown"; - - petList.put(pet.petType + ";" + pet.rarity.petId, pet); - if (petObj.get("active").getAsBoolean()) { - hasActivePet = true; - if (currentPet == null || (pet.petType.equalsIgnoreCase(currentPet.petType) && pet.rarity.equals(currentPet.rarity))) { - if (currentPet != null && ((currentPet.petLevel.level == pet.petLevel.level && currentPet.petLevel.levelPercentage > pet.petLevel.levelPercentage) || currentPet.petLevel.level > pet.petLevel.level)) - pet.petLevel = currentPet.petLevel; - currentPet = pet; - } - } - } - if (!hasActivePet){ - clearPet(); - } - } - } - } - - public static void longTick(){ - NEUConfig config = NotEnoughUpdates.INSTANCE.config; - int updateTime = 90000; - if ((config.treecap.enableMonkeyCheck || config.notifications.showWrongPetMsg) && !config.overlay.enablePetInfo) updateTime = 300000; - - if (NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()){ - ProfileApiSyncer.getInstance().requestResync("petinfo", updateTime, () -> {}, PetInfo::getAndSetPet); - } - } - - public static float getCurrentLevelReqs(float level, pet pet){ - JsonObject petsJson = Constants.PETS; - if (petsJson != null){ - return petsJson.get("pet_levels").getAsJsonArray().get((int) (level+pet.rarity.petOffset)).getAsFloat(); - } - return 0; - } - - public static double getBoostMultiplyer(String boostName){ - if (boostName == null) return 1; - if (boostName.equalsIgnoreCase("PET_ITEM_ALL_SKILLS_BOOST_COMMON")) { - return 1.1; - }else if (boostName.equalsIgnoreCase("ALL_SKILLS_SUPER_BOOST")){ - return 1.2; - }else if (boostName.endsWith("epic")){ - return 1.5; - }else if (boostName.endsWith("rare")){ - return 1.4; - }else if (boostName.endsWith("uncommon")){ - return 1.3; - }else if (boostName.endsWith("common")){ - return 1.2; - } - else return 1; - } - - public static double getXpGain(pet pet, double xp, String xpType){ - double tamingPercent = 1.0 + (tamingLevel / 100f); - xp = xp * tamingPercent; - xp = xp + (xp * beastMultiplier); - if (pet.petXpType != null && !pet.petXpType.equalsIgnoreCase(xpType)){ - xp = ((xpType.equalsIgnoreCase("alchemy") && !pet.petXpType.equalsIgnoreCase("alchemy")) || xpType.equalsIgnoreCase("enchanting") ) ? - xp * 0.08 : xp * 0.33; - } - if (xpType.equalsIgnoreCase("mining") || xpType.equalsIgnoreCase("fishing")){ - xp = xp * 1.5; - } - if (pet.petItem != null) { - Matcher petItemMatcher = XP_BOOST_PATTERN.matcher(pet.petItem); - if ((petItemMatcher.matches() && petItemMatcher.group(1).equalsIgnoreCase(pet.petXpType)) || pet.petItem.equalsIgnoreCase("ALL_SKILLS_SUPER_BOOST")) - xp = xp * getBoostMultiplyer(pet.petItem); - } - return xp; - } - - - @SubscribeEvent - public void onOverlayDrawn(RenderGameOverlayEvent.Post event) { - NEUConfig config = NotEnoughUpdates.INSTANCE.config; - if(NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() && config.overlay.enablePetInfo && ((event.type == null && Loader.isModLoaded("labymod")) || - event.type == RenderGameOverlayEvent.ElementType.ALL) - ){ - Minecraft mc = Minecraft.getMinecraft(); - if (mc.gameSettings.showDebugInfo || - (mc.gameSettings.keyBindPlayerList.isKeyDown() && - (!mc.isIntegratedServerRunning() || - mc.thePlayer.sendQueue.getPlayerInfoMap().size() > 1))) { - return; - } - - if (currentPet != null && currentPet.petLevel != null && !currentPet.petType.isEmpty()) { - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - - FontRenderer font = mc.fontRendererObj; - - int overlayStyle = config.overlay.petInfoOverlayStyle; - - String petName = EnumChatFormatting.GREEN + "[Lvl " + (int) currentPet.petLevel.level + "] " + currentPet.rarity.chatFormatting + - WordUtils.capitalizeFully(currentPet.petType.replace("_", " ")); - String lvlString = EnumChatFormatting.AQUA + "" + Utils.shortNumberFormat((currentPet.petLevel.currentLevelRequirement * currentPet.petLevel.levelPercentage), 0) + "/" + Utils.shortNumberFormat(currentPet.petLevel.currentLevelRequirement, 0) + EnumChatFormatting.YELLOW + " (" + getLevelPercent() + "%)"; - - int xPos = config.overlay.petInfoPosition.getAbsX(scaledResolution, Math.max(font.getStringWidth(petName), font.getStringWidth(lvlString)) + 20); - int yPos = config.overlay.petInfoPosition.getAbsY(scaledResolution, (currentPet.petLevel.level < 100 ? 22 : 11)) + 2; - - if (!(mc.currentScreen instanceof GuiPositionEditor) && (overlayStyle == 0 || overlayStyle == 4)) - Gui.drawRect(xPos, yPos-2, xPos+Math.max(font.getStringWidth(lvlString), font.getStringWidth(petName))+22, yPos+(currentPet.petLevel.level < 100 ? 20 : 16), 0x80000000); - - if (overlayStyle == 3) { - for (int xO = -2; xO <= 2; xO++) { - for (int yO = -2; yO <= 2; yO++) { - if (Math.abs(xO) != Math.abs(yO)) { - font.drawString(Utils.cleanColour(petName), xPos + 20 + xO / 2f, yPos + (currentPet.petLevel.level < 100 ? 0 : 4) + yO / 2f, 0x000000, false); - } - } - } - } - - font.drawString(petName, xPos + 20, yPos + (currentPet.petLevel.level < 100 ? 0 : 4), 0xffffff, overlayStyle == 2 || overlayStyle == 4); - if (currentPet.petLevel.level < 100){ - if (overlayStyle == 3) { - for (int xO = -2; xO <= 2; xO++) { - for (int yO = -2; yO <= 2; yO++) { - if (Math.abs(xO) != Math.abs(yO)) { - font.drawString(Utils.cleanColour(lvlString), xPos + 20 + xO / 2f, yPos + font.FONT_HEIGHT + yO / 2f, 0x000000, false); - } - } - } - } - font.drawString(lvlString, xPos + 20, yPos + font.FONT_HEIGHT, 0xffffff, overlayStyle == 2 || overlayStyle == 4); - } - - JsonObject petItem = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(currentPet.petType+";"+currentPet.rarity.petId); - if(petItem != null) { - ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(petItem, false, false, false); - Utils.drawItemStack(stack, xPos, yPos); - } - GlStateManager.color(0,0,0); - } - } - } - - @SubscribeEvent - public void switchWorld(WorldEvent.Load event) { - if (NotE