aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures
diff options
context:
space:
mode:
authorBuildTools <james.jenour@protonmail.com>2021-02-16 03:08:30 +0800
committerBuildTools <james.jenour@protonmail.com>2021-02-16 03:08:30 +0800
commita0e7d174472d034142003e58a42d6beefe36a92b (patch)
tree37fbdf5c5c3af3e85ed05e6e17d64207b2a6d8c9 /src/main/java/io/github/moulberry/notenoughupdates/miscfeatures
parent6024bdf69193ad216e95fca53d7d28746f4269e0 (diff)
downloadnotenoughupdates-a0e7d174472d034142003e58a42d6beefe36a92b.tar.gz
notenoughupdates-a0e7d174472d034142003e58a42d6beefe36a92b.tar.bz2
notenoughupdates-a0e7d174472d034142003e58a42d6beefe36a92b.zip
PRE21
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomItemEffects.java4
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CustomSkulls.java283
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java43
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DwarvenMinesTextures.java4
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCooldowns.java8
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfo.java372
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java646
7 files changed, 978 insertions, 382 deletions
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<ResourceLocation, TextureAtlasSprite> sprites = Maps.<ResourceLocation, TextureAtlasSprite>newHashMap();
+
+ private final FaceBakery faceBakery = new FaceBakery();
+ private final ModelSkeletonHead humanoidHead = new ModelHumanoidHead();
+
+ private final HashMap<String, CustomSkull> 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<String, JsonElement> 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<ResourceLocation> 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<ResourceLocation> getAllTextureLocations() {
+ Set<ResourceLocation> set = new HashSet<>();
+
+ for(CustomSkull skull : customSkulls.values()) {
+ if(skull.model != null) {
+ set.addAll(getTextureLocations(skull.model));
+ }
+ }
+
+ return set;
+ }
+
+ protected Set<ResourceLocation> getTextureLocations(ModelBlock modelBlock) {
+ Set<ResourceLocation> set = Sets.<ResourceLocation>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<BakedQuad> 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<Integer, ChatComponentText> 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<damageString.length(); i++) {
+ int index = damageString.length() - 1 - i;
+ char c = damageString.charAt(index);
+ if(c >= '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<String, pet> 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.