diff options
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/mod/utils')
21 files changed, 3168 insertions, 0 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/AhUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/AhUtils.java new file mode 100644 index 00000000..6e6bdf52 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/AhUtils.java @@ -0,0 +1,98 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.utils; + +import com.google.common.base.Throwables; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import kr.syeyoung.dungeonsguide.auth.AuthManager; +import kr.syeyoung.dungeonsguide.auth.AuthUtil; +import kr.syeyoung.dungeonsguide.mod.events.impl.AuthChangedEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import java.security.*; +import java.security.cert.CertificateException; +import java.util.*; + +public class AhUtils { + public static volatile Map<String, AuctionData> auctions = new HashMap<String, AuctionData>(); + + static Logger logger = LogManager.getLogger("AhUtils"); + + public static Timer timer = new Timer(); + + public static int totalAuctions = 0; + + @SubscribeEvent + public void onAuthChanged(AuthChangedEvent event) { + if(AuthManager.getInstance().isPlebUser()){ + registerTimer(); + } + } + + public static void registerTimer() { + timer.schedule(new TimerTask() { + public void run() { + try { + AhUtils.loadAuctions(); + } catch (CertificateException | NoSuchAlgorithmException | InvalidKeyException | InvalidAlgorithmParameterException | NoSuchPaddingException | BadPaddingException | KeyStoreException | IllegalBlockSizeException | KeyManagementException e) { + logger.error("Error loading auctions {}", String.valueOf(Throwables.getRootCause(e))); + } + } + }, 0L, 1800000L); + } + + public static void loadAuctions() throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, InvalidAlgorithmParameterException, NoSuchPaddingException, BadPaddingException, KeyStoreException, IllegalBlockSizeException, KeyManagementException { + try { + + Map<String, AuctionData> semi_auctions = new HashMap<String, AuctionData>(); + JsonElement object = AuthUtil.getJsonSecured("https://dungeons.guide/resource/keys"); + for (JsonElement element : object.getAsJsonArray()) { + JsonObject object1 = element.getAsJsonObject(); + AuctionData auctionData = new AuctionData(object1.get("id").getAsString()); + auctionData.lowestBin = object1.get("lowestBin").getAsInt(); + auctionData.sellPrice = object1.get("sellPrice").getAsInt(); + auctionData.buyPrice = object1.get("buyPrice").getAsInt(); + semi_auctions.put(auctionData.id, auctionData); + } + auctions = semi_auctions; + } catch (Throwable e) { + e.printStackTrace(); + } + } + + public static class AuctionData { + public String id; + + public long lowestBin = -1; + + public int sellPrice = -1; + + public int buyPrice = -1; + + public AuctionData(String id) { + this.id = id; + } + } +}
\ No newline at end of file diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/ArrayUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/ArrayUtils.java new file mode 100755 index 00000000..be5b1088 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/ArrayUtils.java @@ -0,0 +1,40 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.utils; + +public class ArrayUtils { + public static int[][] rotateCounterClockwise(int[][] arr) { + int[][] res = new int[arr[0].length][arr.length]; + for(int y=0; y<arr.length; y++) { + for (int x = 0; x< arr[0].length; x++) { + res[res.length - x - 1][y] = arr[y][x]; + } + } + return res; + } + public static int[][] rotateClockwise(int[][] arr) { + int[][] res = new int[arr[0].length][arr.length]; + for(int y=0; y<arr.length; y++) { + for (int x = 0; x< arr[0].length; x++) { + res[x][res[0].length - y - 1] = arr[y][x]; + } + } + return res; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/BlockCache.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/BlockCache.java new file mode 100644 index 00000000..b8313778 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/BlockCache.java @@ -0,0 +1,50 @@ +package kr.syeyoung.dungeonsguide.mod.utils; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.util.BlockPos; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.world.WorldEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.jetbrains.annotations.NotNull; + +import java.util.concurrent.TimeUnit; + +public class BlockCache { + public BlockCache() { + MinecraftForge.EVENT_BUS.register(this); + } + + @SuppressWarnings("UnstableApiUsage") + private final LoadingCache<BlockPos, IBlockState> cache = CacheBuilder.newBuilder() + .maximumSize(10000) + .expireAfterWrite(3, TimeUnit.SECONDS) + .build( + new CacheLoader<BlockPos, IBlockState>() { + public IBlockState load(@NotNull BlockPos pos) { + return Minecraft.getMinecraft().theWorld.getBlockState(pos); + } + }); + + + @SuppressWarnings("UnstableApiUsage") + public IBlockState getBlockState(@NotNull BlockPos pos){ + if(FeatureRegistry.DEBUG_BLOCK_CACHING.isEnabled()){ + return cache.getUnchecked(pos); + } else { + return Minecraft.getMinecraft().theWorld.getBlockState(pos); + } + } + + + @SubscribeEvent @SuppressWarnings("UnstableApiUsage") + public void onWorldLoad(WorldEvent.Load e){ + cache.invalidateAll(); + } + + +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/GlStateUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/GlStateUtils.java new file mode 100644 index 00000000..4fee85d0 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/GlStateUtils.java @@ -0,0 +1,68 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.utils; + +import net.minecraft.client.renderer.GlStateManager; + +import java.lang.reflect.Field; +import java.util.*; + +public class GlStateUtils { + public static Map<String, Object> dumpStates() { + Map<String, Object> primitiveDump = new LinkedHashMap<>(); + try { + recursivelyDump(primitiveDump, "GlStateManager", null, GlStateManager.class); + } catch (IllegalAccessException e) { + e.printStackTrace(); + primitiveDump.put("$ERROR", true); + } + return primitiveDump; + } + + public static void printDump(Map<String, Object> dump) { + for (Map.Entry<String, Object> stringObjectEntry : dump.entrySet()) { + System.out.println(stringObjectEntry+": "+stringObjectEntry.getValue()); + } + } + + public static void compareDump(Map<String, Object> dump1, Map<String,Object> dump2) { + Set<String> set = new HashSet<>(); + set.addAll(dump1.keySet()); + set.addAll(dump2.keySet()); + + for (String s : set) { + Object obj1 = dump1.get(s); + Object obj2 = dump2.get(s); + if (!Objects.equals(obj1, obj2)) System.out.println(s+": Prev {"+obj1+"} New {"+obj2+"}"); + } + } + + public static void recursivelyDump(Map<String, Object> primitiveDump, String objPath, Object obj, Class clazz) throws IllegalAccessException { + primitiveDump.put(objPath+".$class", clazz.getName()); + for (Field declaredField : clazz.getDeclaredFields()) { + declaredField.setAccessible(true); + Object fieldData = declaredField.get(obj); + if (fieldData.getClass().getName().startsWith("java.lang")) { + primitiveDump.put(objPath+"."+declaredField.getName(), fieldData); + } else { + recursivelyDump(primitiveDump, objPath+"."+declaredField.getName(), fieldData, fieldData.getClass()); + } + } + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/MapUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/MapUtils.java new file mode 100755 index 00000000..cf16cb93 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/MapUtils.java @@ -0,0 +1,176 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.utils; + +import lombok.Getter; +import net.minecraft.block.material.MapColor; + +import javax.vecmath.Vector2d; +import java.awt.*; +import java.awt.image.BufferedImage; + +public class MapUtils { + + private static Color[] colorMasks = new Color[128 * 128]; + @Getter + private static byte[] colors; + + public static void clearMap() { + colorMasks = new Color[128 * 128]; + colors = null; + } + + public static void record(byte[] colors, int x, int y, Color c) { + MapUtils.colors = colors; + colorMasks[y *128 +x] = c; + } + + public static byte getMapColorAt(byte[] colors, int x, int y) { + if (y <0 || y>= 128 || x < 0 || x >= 128) return 0; + return colors[y * 128 +x]; + } + + public static BufferedImage getImage() { + BufferedImage bufferedImage = new BufferedImage(128, 128,BufferedImage.TYPE_INT_ARGB); + if (colors == null) return bufferedImage; + Graphics graphics = bufferedImage.getGraphics(); + for (int y = 0; y < 128; y++) { + for (int x = 0; x <128; x++) { + bufferedImage.setRGB(x,y, getRGBColorAt(colors, x, y)); + if (colorMasks[y * 128 + x] != null) { + graphics.setColor(colorMasks[y *128 +x]); + graphics.drawLine(x,y,x,y); + } + } + } + return bufferedImage; + } + + public static int getRGBColorAt(byte[] colors, int x, int y) { + if (y <0 || y>= 128 || x < 0 || x >= 128) return 0; + int i = y * 128 +x; + int j = colors[i] & 255; + + int theColor; + if (j / 4 == 0) + { + theColor = (i + i / 128 & 1) * 8 + 16 << 24; + } + else + { + theColor = MapColor.mapColorArray[j / 4].getMapColor(j & 3); + } + + return theColor; + } + + public static Point findFirstColorWithIn(byte[] colors, byte color, Rectangle dimension) { + boolean found = true; + for (int y = dimension.y; y < (dimension.y + dimension.height);y++) { + for (int x = dimension.x; x < (dimension.x + dimension.width); x ++) { + if (getMapColorAt(colors, x ,y) == color && found) { + record(colors, x, y, new Color(255, 0, 0, 40)); + return new Point(x,y); + } + found = getMapColorAt(colors, x,y) == 0; + } + } + return null; + } + + public static Point findFirstColorWithInNegate(byte[] colors, byte color, Rectangle dimension) { + for (int y = dimension.y; y < (dimension.y + dimension.height);y++) { + for (int x = dimension.x; x < (dimension.x + dimension.width); x ++) { + if (getMapColorAt(colors, x ,y) != color) { + record(colors, x, y, new Color(255, 0, 0, 40)); + return new Point(x,y); + } + } + } + return null; + } + + public static int getWidthOfColorAt(byte[] colors, byte color, Point point) { + for (int x = point.x; x < 128; x++) { + record(colors, x, point.y, new Color(0, 255, 0, 40)); + if (getMapColorAt(colors, x, point.y) != color) return x - point.x; + } + return 128 - point.x; + } + public static int getHeightOfColorAt(byte[] colors, byte color, Point point) { + for (int y = point.y; y < 128; y++) { + record(colors, point.x, y, new Color(0, 255, 0, 40)); + if (getMapColorAt(colors, point.x,y) != color) return y - point.y; + } + return 128 - point.y; + } + + public static int getLengthOfColorExtending(byte[] colors, byte color, Point basePoint, Vector2d vector2d) { + for (int i = 0; i < 128; i++) { + int x = (int) (basePoint.x + vector2d.x * i); + int y = (int) (basePoint.y + vector2d.y * i); + record(colors, x, y, new Color(0, 0, 255, 40)); + if (getMapColorAt(colors, x,y) != color) return i; + } + return -1; + } + + + public static boolean matches(byte[] colors, byte[] stencil, int targetColor, int x, int y) { + for (int i = y; i < y + stencil.length; i++) { + for (int j = x; j < x + 8; j++) { + boolean current = getMapColorAt(colors, j, i) == targetColor; + boolean expected = ((stencil[i - y] >> (7-(j-x))) & 0x1) == 1; + if (current != expected) return false; + } + } + return true; + } + + public static int readDigit(byte[] colors, int x, int y) { + for (int i = 0; i < NUMBER_STENCIL.length; i++) { + if (matches(colors, NUMBER_STENCIL[i],34, x, y)) return i; + } + return -1; + } + public static int readNumber(byte[] colors, int x, int y, int gap) { + int number = 0; + for (int i = x; i < 128; i += gap) { + int digit = readDigit(colors, i, y); + if (digit != -1) number = number * 10 + digit; + } + return number; + } + + private static final byte[][] NUMBER_STENCIL = { + {0x0, 0x7F, 0x7F, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x7F, 0x7F, 0x0}, + {0x0, 0x1E, 0x1E, 0x1E, 0xE, 0xE, 0xE, 0xE, 0xE, 0xE, 0xE, 0xE, 0xE, 0x0}, + {0x0, 0x7F, 0x7F, 0x7F, 0x77, 0x77, 0x7, 0x7F, 0x7F, 0x70, 0x7F, 0x7F, 0x7F, 0x0}, + {0x0, 0x7F, 0x7F, 0x7F, 0x7, 0x7, 0x1F, 0x1F, 0x7, 0x7, 0x7F, 0x7F, 0x7F, 0x0}, + {0x0, 0x6E, 0x6E, 0x6E, 0x6E, 0x6E, 0x6E, 0x7F, 0x7F, 0x7F, 0xE, 0xE, 0xE, 0x0}, + {0x0, 0x7F, 0x7F, 0x7F, 0x70, 0x7F, 0x7F, 0x7, 0x77, 0x77, 0x7F, 0x7F, 0x7F, 0x0}, + {0x0, 0x7F, 0x7F, 0x7F, 0x70, 0x7F, 0x7F, 0x77, 0x77, 0x77, 0x77, 0x7F, 0x7F, 0x0}, + {0x0, 0x7F, 0x7F, 0x7F, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x0}, + {0x0, 0x7F, 0x7F, 0x77, 0x77, 0x77, 0x3E, 0x77, 0x77, 0x77, 0x77, 0x7F, 0x7F, 0x0}, + {0x0, 0x7F, 0x7F, 0x77, 0x77, 0x77, 0x77, 0x7F, 0x7F, 0x7, 0x7F, 0x7F, 0x7F, 0x0} + }; + + + +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/RenderUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/RenderUtils.java new file mode 100755 index 00000000..065986c5 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/RenderUtils.java @@ -0,0 +1,1372 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.utils; + +import kr.syeyoung.dungeonsguide.mod.config.types.AColor; +import kr.syeyoung.dungeonsguide.mod.dungeon.doorfinder.DungeonDoor; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityArmorStand; +import net.minecraft.entity.passive.EntityBat; +import net.minecraft.util.*; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; + +import javax.vecmath.Vector3f; +import java.awt.*; +import java.util.List; + +public class RenderUtils { + public static final ResourceLocation icons = new ResourceLocation("textures/gui/icons.png"); + private static final ResourceLocation beaconBeam = new ResourceLocation("textures/entity/beacon_beam.png"); + + /** + * Taken from NotEnoughUpdates under Creative Commons Attribution-NonCommercial 3.0 + * And modified to fit out need. + * https://github.com/Moulberry/NotEnoughUpdates/blob/master/LICENSE + * @author Moulberry + */ + public static void renderBeaconBeam(double x, double y, double z, AColor aColor, float partialTicks) { + Entity player = Minecraft.getMinecraft().thePlayer; + double playerX = player.prevPosX + (player.posX - player.prevPosX) * partialTicks; + double playerY = player.prevPosY + (player.posY - player.prevPosY) * partialTicks; + double playerZ = player.prevPosZ + (player.posZ - player.prevPosZ) * partialTicks; +//because of the way 3D rendering is done, all coordinates are relative to the camera. This "resets" the "0,0,0" position to the location that is (0,0,0) in the world. + + + GlStateManager.pushMatrix(); + GlStateManager.translate(-playerX, -playerY, -playerZ); + int height = 300; + int bottomOffset = 0; + int topOffset = bottomOffset + height; + + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + + Minecraft.getMinecraft().getTextureManager().bindTexture(beaconBeam); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, 10497.0F); + GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, 10497.0F); + GlStateManager.disableLighting(); + GlStateManager.disableDepth(); + GlStateManager.enableTexture2D(); + GlStateManager.tryBlendFuncSeparate(770, 1, 1, 0); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + + double time = Minecraft.getMinecraft().theWorld.getTotalWorldTime() + (double)partialTicks; + double d1 = MathHelper.func_181162_h(-time * 0.2D - (double)MathHelper.floor_double(-time * 0.1D)); + + int c = getColorAt(x,y,z, aColor); + float alpha = ((c >> 24) & 0xFF) / 255.0f; + + float r = ((c >> 16) & 0xFF) / 255f; + float g = ((c >> 8) & 0xFF) / 255f; + float b = (c & 0xFF) / 255f; + double d2 = time * 0.025D * -1.5D; + double d4 = 0.5D + Math.cos(d2 + 2.356194490192345D) * 0.2D; + double d5 = 0.5D + Math.sin(d2 + 2.356194490192345D) * 0.2D; + double d6 = 0.5D + Math.cos(d2 + (Math.PI / 4D)) * 0.2D; + double d7 = 0.5D + Math.sin(d2 + (Math.PI / 4D)) * 0.2D; + double d8 = 0.5D + Math.cos(d2 + 3.9269908169872414D) * 0.2D; + double d9 = 0.5D + Math.sin(d2 + 3.9269908169872414D) * 0.2D; + double d10 = 0.5D + Math.cos(d2 + 5.497787143782138D) * 0.2D; + double d11 = 0.5D + Math.sin(d2 + 5.497787143782138D) * 0.2D; + double d14 = -1.0D + d1; + double d15 = (double)(height) * 2.5D + d14; + worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); + worldrenderer.pos(x + d4, y + topOffset, z + d5).tex(1.0D, d15).color(r, g, b, alpha).endVertex(); + worldrenderer.pos(x + d4, y + bottomOffset, z + d5).tex(1.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d6, y + bottomOffset, z + d7).tex(0.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d6, y + topOffset, z + d7).tex(0.0D, d15).color(r, g, b, alpha).endVertex(); + worldrenderer.pos(x + d10, y + topOffset, z + d11).tex(1.0D, d15).color(r, g, b, alpha).endVertex(); + worldrenderer.pos(x + d10, y + bottomOffset, z + d11).tex(1.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d8, y + bottomOffset, z + d9).tex(0.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d8, y + topOffset, z + d9).tex(0.0D, d15).color(r, g, b, alpha).endVertex(); + worldrenderer.pos(x + d6, y + topOffset, z + d7).tex(1.0D, d15).color(r, g, b, alpha).endVertex(); + worldrenderer.pos(x + d6, y + bottomOffset, z + d7).tex(1.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d10, y + bottomOffset, z + d11).tex(0.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d10, y + topOffset, z + d11).tex(0.0D, d15).color(r, g, b, alpha).endVertex(); + worldrenderer.pos(x + d8, y + topOffset, z + d9).tex(1.0D, d15).color(r, g, b, alpha).endVertex(); + worldrenderer.pos(x + d8, y + bottomOffset, z + d9).tex(1.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d4, y + bottomOffset, z + d5).tex(0.0D, d14).color(r, g, b, 1.0F).endVertex(); + worldrenderer.pos(x + d4, y + topOffset, z + d5).tex(0.0D, d15).color(r, g, b, alpha).endVertex(); + tessellator.draw(); + + double d12 = -1.0D + d1; + double d13 = height + d12; + + worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); + worldrenderer.pos(x + 0.2D, y + topOffset, z + 0.2D).tex(1.0D, d13).color(r, g, b, 0.25F*alpha).endVertex(); + worldrenderer.pos(x + 0.2D, y + bottomOffset, z + 0.2D).tex(1.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.8D, y + bottomOffset, z + 0.2D).tex(0.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.8D, y + topOffset, z + 0.2D).tex(0.0D, d13).color(r, g, b, 0.25F*alpha).endVertex(); + worldrenderer.pos(x + 0.8D, y + topOffset, z + 0.8D).tex(1.0D, d13).color(r, g, b, 0.25F*alpha).endVertex(); + worldrenderer.pos(x + 0.8D, y + bottomOffset, z + 0.8D).tex(1.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.2D, y + bottomOffset, z + 0.8D).tex(0.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.2D, y + topOffset, z + 0.8D).tex(0.0D, d13).color(r, g, b, 0.25F*alpha).endVertex(); + worldrenderer.pos(x + 0.8D, y + topOffset, z + 0.2D).tex(1.0D, d13).color(r, g, b, 0.25F*alpha).endVertex(); + worldrenderer.pos(x + 0.8D, y + bottomOffset, z + 0.2D).tex(1.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.8D, y + bottomOffset, z + 0.8D).tex(0.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.8D, y + topOffset, z + 0.8D).tex(0.0D, d13).color(r, g, b, 0.25F*alpha).endVertex(); + worldrenderer.pos(x + 0.2D, y + topOffset, z + 0.8D).tex(1.0D, d13).color(r, g, b, 0.25F*alpha).endVertex(); + worldrenderer.pos(x + 0.2D, y + bottomOffset, z + 0.8D).tex(1.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.2D, y + bottomOffset, z + 0.2D).tex(0.0D, d12).color(r, g, b, 0.25F).endVertex(); + worldrenderer.pos(x + 0.2D, y + topOffset, z + 0.2D).tex(0.0D, d13).color(r, g, b, 0.25F*alpha).endVertex(); + tessellator.draw(); + + GlStateManager.enableDepth(); + + GlStateManager.popMatrix(); + } + + + public static void drawTexturedRect(float x, float y, float width, float height, int filter) { + drawTexturedRect(x, y, width, height, 0.0F, 1.0F, 0.0F, 1.0F, filter); + } + private static float zLevel = 0; + public static int scrollY = 0; + public static boolean allowScrolling; + public static int scrollX = 0; + + public static void drawGradientRect(int left, int top, int right, int bottom, int startColor, int endColor) + { + float f = (float)(startColor >> 24 & 255) / 255.0F; + float f1 = (float)(startColor >> 16 & 255) / 255.0F; + float f2 = (float)(startColor >> 8 & 255) / 255.0F; + float f3 = (float)(startColor & 255) / 255.0F; + float f4 = (float)(endColor >> 24 & 255) / 255.0F; + float f5 = (float)(endColor >> 16 & 255) / 255.0F; + float f6 = (float)(endColor >> 8 & 255) / 255.0F; + float f7 = (float)(endColor & 255) / 255.0F; + GlStateManager.disableTexture2D(); + GlStateManager.enableBlend(); + GlStateManager.disableAlpha(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GlStateManager.shadeModel(7425); + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); + worldrenderer.pos((double)right, (double)top, (double)0).color(f1, f2, f3, f).endVertex(); + worldrenderer.pos((double)left, (double)top, (double)0).color(f1, f2, f3, f).endVertex(); + worldrenderer.pos((double)left, (double)bottom, (double)0).color(f5, f6, f7, f4).endVertex(); + worldrenderer.pos((double)right, (double)bottom, (double)0).color(f5, f6, f7, f4).endVertex(); + tessellator.draw(); + GlStateManager.shadeModel(7424); + GlStateManager.enableAlpha(); + GlStateManager.enableTexture2D(); + } + + public static void drawRect(int left, int top, int right, int bottom, AColor color) + { + if (left < right) + { + int i = left; + left = right; + right = i; + } + + if (top < bottom) + { + int j = top; + top = bottom; + bottom = j; + } + + float f3 = (float)(color.getRGB() >> 24 & 255) / 255.0F; + float f = (float)(color.getRGB() >> 16 & 255) / 255.0F; + float f1 = (float)(color.getRGB() >> 8 & 255) / 255.0F; + float f2 = (float)(color.getRGB() & 255) / 255.0F; + if (!color.isChroma() && f3 == 0) return; + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + GlStateManager.enableBlend(); + GlStateManager.disableTexture2D(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + if (!color.isChroma()) { + GlStateManager.color(f, f1, f2, f3); + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); + worldrenderer.pos(left, bottom, 0.0D).endVertex(); + worldrenderer.pos(right, bottom, 0.0D).endVertex(); + worldrenderer.pos(right, top, 0.0D).endVertex(); + worldrenderer.pos(left, top, 0.0D).endVertex(); + } else { + worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); + GlStateManager.shadeModel(GL11.GL_SMOOTH); + color(worldrenderer.pos(left, bottom, 0.0D), getColorAt(left, bottom, color)).endVertex(); + color(worldrenderer.pos(right, bottom, 0.0D), getColorAt(right, bottom, color)).endVertex(); + color(worldrenderer.pos(right, top, 0.0D), getColorAt(right, top, color)).endVertex(); + color(worldrenderer.pos(left, top, 0.0D), getColorAt(left, top, color)).endVertex(); + } + tessellator.draw(); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + } + + + public static void drawRoundedRectangle(int x, int y, int width, int height, int radius, double delta, int color) { + GlStateManager.pushMatrix(); + GlStateManager.translate(width/2.0+x, height/2.0+y, 0); + Tessellator t = Tessellator.getInstance(); + GlStateManager.disableTexture2D(); + RenderUtils.GL_SETCOLOR(color); + WorldRenderer wr = t.getWorldRenderer(); + wr.begin(GL11.GL_POLYGON, DefaultVertexFormats.POSITION); + for (double i = 0.1; i < Math.PI*2; i+= delta) { + double cos = MathHelper.cos((float) i); + double sin = MathHelper.sin((float) i); + if (cos * MathHelper.cos((float) (i + delta)) <= 0) { + wr.pos(sin * radius + (sin > 0 ? 1 : -1) * (width/2.0 - radius), + cos * radius + (cos > 0 ? 1 : -1) * (height/2.0 - radius),0).endVertex(); + wr.pos(sin * radius + (sin > 0 ? 1 : -1) * (width/2.0 - radius), + cos * radius + (cos > 0 ? -1 : 1) * (height/2.0 - radius),0).endVertex(); + } else if (sin * MathHelper.sin((float) (i+delta)) <= 0) { + wr.pos(sin * radius + (sin > 0 ? 1 : -1) * (width/2.0 - radius), + cos * radius + (cos > 0 ? 1 : -1) * (height/2.0 - radius), 0).endVertex(); + wr.pos(sin * radius + (sin > 0 ? -1 : 1) * (width/2.0 - radius), + cos * radius + (cos > 0 ? 1 : -1) * (height/2.0 - radius), 0).endVertex(); + } else { + wr.pos(sin * radius + (sin > 0 ? 1 : -1) * (width/2.0 - radius), + cos * radius + (cos > 0 ? 1 : -1) * (height/2.0 - radius), 0).endVertex(); + } + } + t.draw(); + GlStateManager.popMatrix(); + } + + public static void GL_SETCOLOR(int color) { + float f3 = (float)(color >> 24 & 255) / 255.0F; + float f = (float)(color >> 16 & 255) / 255.0F; + float f1 = (float)(color >> 8 & 255) / 255.0F; + float f2 = (float)(color & 255) / 255.0F; + GlStateManager.color(f, f1, f2, f3); + } + + public static int blendTwoColors(int background, int newColor) { + float alpha = ((newColor >> 24) & 0xFF) /255.0f; + int r1 = (background >> 16) & 0xFF, r2 = (newColor >> 16) & 0xFF; + int g1 = (background >> 8) & 0xFF, g2 = (newColor >> 8) & 0xFF; + int b1 = (background) & 0xFF, b2 = (newColor) & 0xFF; + + int rr = (int) (r1 + (r2-r1) * alpha) & 0xFF; + int rg = (int) (g1 + (g2-g1) * alpha) & 0xFF; + int rb = (int) (b1 + (b2-b1) * alpha) & 0xFF; + return 0xFF000000 | ((rr << 16) & 0xFF0000) | ((rg << 8) & 0xFF00) | (rb & 0xFF); + } + + public static int blendAlpha(int origColor, float alphaPerc) { + return blendTwoColors(origColor, (int)(alphaPerc*255) << 24 | 0xFFFFFF); + } + + public static void drawTexturedRect(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax, int filter) { + GlStateManager.enableTexture2D(); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 771); + GL11.glTexParameteri(3553, 10241, filter); + GL11.glTexParameteri(3553, 10240, filter); + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX); + worldrenderer.pos(x, y + height, 0.0D).tex(uMin, vMax).endVertex(); + worldrenderer.pos(x + width, y + height, 0.0D).tex(uMax, vMax).endVertex(); + worldrenderer.pos(x + width, y, 0.0D).tex(uMax, vMin).endVertex(); + worldrenderer.pos(x, y, 0.0D).tex(uMin, vMin).endVertex(); + tessellator.draw(); + GL11.glTexParameteri(3553, 10241, 9728); + GL11.glTexParameteri(3553, 10240, 9728); + GlStateManager.disableBlend(); + } + public static void renderBar(float x, float y, float xSize, float completed) { + Minecraft.getMinecraft().getTextureManager().bindTexture(icons); + completed = (float)Math.round(completed / 0.05F) * 0.05F; + float notcompleted = 1.0F - completed; + int displayNum = 0; + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + float width = 0.0F; + if (completed < 0.5F && (displayNum == 1 || displayNum == 0)) { + width = (0.5F - completed) * xSize; + drawTexturedRect(x + xSize * completed, y, width, 5.0F, xSize * completed / 256.0F, xSize / 2.0F / 256.0F, 0.2890625F, 0.30859375F, 9728); + } + + if (completed < 1.0F && (displayNum == 2 || displayNum == 0)) { + width = Math.min(xSize * notcompleted, xSize / 2.0F); + drawTexturedRect(x + xSize / 2.0F + Math.max(xSize * (completed - 0.5F), 0.0F), y, width, 5.0F, (182.0F - xSize / 2.0F + Math.max(xSize * (completed - 0.5F), 0.0F)) / 256.0F, 0.7109375F, 0.2890625F, 0.30859375F, 9728); + } + + if (completed > 0.0F && (displayNum == 3 || displayNum == 0)) { + width = Math.min(xSize * completed, xSize / 2.0F); + drawTexturedRect(x, y, width, 5.0F, 0.0F, width / 256.0F, 0.30859375F, 0.328125F, 9728); + } + + if (completed > 0.5F && (displayNum == 4 || displayNum == 0)) { + width = Math.min(xSize * (completed - 0.5F), xSize / 2.0F); + drawTexturedRect(x + xSize / 2.0F, y, width, 5.0F, (182.0F - xSize / 2.0F) / 256.0F, (182.0F - xSize / 2.0F + width) / 256.0F, 0.30859375F, 0.328125F, 9728); + } + + } + + public static void drawUnfilledBox(int left, int top, int right, int bottom, int color, boolean chroma) + { + if (left < right) + { + int i = left; + left = right; + right = i; + } + + if (top < bottom) + { + int j = top; + top = bottom; + bottom = j; + } + + float f3 = (float)(color >> 24 & 255) / 255.0F; + float f = (float)(color >> 16 & 255) / 255.0F; + float f1 = (float)(color >> 8 & 255) / 255.0F; + float f2 = (float)(color & 255) / 255.0F; + if (!chroma && f3 == 0) return; + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + GlStateManager.enableBlend(); + GlStateManager.disableTexture2D(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + if (!chroma) { + GlStateManager.color(f, f1, f2, f3); + worldrenderer.begin(GL11.GL_LINE_LOOP, DefaultVertexFormats.POSITION); + worldrenderer.pos(left, bottom, 0.0D).endVertex(); + worldrenderer.pos(right, bottom, 0.0D).endVertex(); + worldrenderer.pos(right, top, 0.0D).endVertex(); + worldrenderer.pos(left, top, 0.0D).endVertex(); + } else { + worldrenderer.begin(GL11.GL_LINE_LOOP, DefaultVertexFormats.POSITION_COLOR); + float blah = (System.currentTimeMillis() / 10) % 360; + GlStateManager.shadeModel(GL11.GL_SMOOTH); + color(worldrenderer.pos(left, bottom, 0.0D), Color.HSBtoRGB((((blah + 20) % 360) / 360.0f), 1, 1)).endVertex(); + color(worldrenderer.pos(right, bottom, 0.0D), Color.HSBtoRGB((((blah + 40) % 360) / 360.0f), 1, 1)).endVertex(); + color(worldrenderer.pos(right, top, 0.0D), Color.HSBtoRGB((((blah + 20) % 360) / 360.0f), 1, 1)).endVertex(); + color(worldrenderer.pos(left, top, 0.0D), Color.HSBtoRGB(blah / 360.0f, 1, 1)).endVertex(); + } + tessellator.draw(); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + } + + + public static void drawUnfilledBox(int left, int top, int right, int bottom, AColor color) + { + if (left < right) + { + int i = left; + left = right; + right = i; + } + + if (top < bottom) + { + int j = top; + top = bottom; + bottom = j; + } + + float f3 = (float)(color.getRGB() >> 24 & 255) / 255.0F; + float f = (float)(color.getRGB() >> 16 & 255) / 255.0F; + float f1 = (float)(color.getRGB() >> 8 & 255) / 255.0F; + float f2 = (float)(color.getRGB() & 255) / 255.0F; + if (!color.isChroma() && f3 == 0) return; + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldrenderer = tessellator.getWorldRenderer(); + GlStateManager.enableBlend(); + GlStateManager.disableTexture2D(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + if (!color.isChroma()) { + GlStateManager.color(f, f1, f2, f3); + worldrenderer.begin(GL11.GL_LINE_LOOP, DefaultVertexFormats.POSITION); + worldrenderer.pos(left, bottom, 0.0D).endVertex(); + worldrenderer.pos(right, bottom, 0.0D).endVertex(); + worldrenderer.pos(right, top, 0.0D).endVertex(); + worldrenderer.pos(left, top, 0.0D).endVertex(); + } else { + worldrenderer.begin(GL11.GL_LINE_LOOP, DefaultVertexFormats.POSITION_COLOR); + GlStateManager.shadeModel(GL11.GL_SMOOTH); + color(worldrenderer.pos(left, bottom, 0.0D), getColorAt(left, bottom, color)).endVertex(); + color(worldrenderer.pos(right, bottom, 0.0D), getColorAt(right, bottom, color)).endVertex(); + color(worldrenderer.pos(right, top, 0.0D), getColorAt(right, top, color)).endVertex(); + color(worldrenderer.pos(left, top, 0.0D), getColorAt(left, top, color)).endVertex(); + } + tessellator.draw(); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + } + + public static int getChromaColorAt(int x, int y, float speed, float s, float b, float alpha) { + double blah = ((double)(speed) * (System.currentTimeMillis() / 2)) % 360; + return (Color.HSBtoRGB((float) (((blah - (x + y) / 2.0f) % 360) / 360.0f), s,b) & 0xffffff) + | (((int)(alpha * 255)<< 24) & 0xff000000); + } + public static int getColorAt(double x, double y, AColor color) { + if (!color.isChroma()) + return color.getRGB(); + + double blah = ((double)(color.getChromaSpeed()) * (System.currentTimeMillis() / 2)) % 360; + float[] hsv = new float[3]; + Color.RGBtoHSB(color.getRed(), color.getBlue(), color.getGreen(), hsv); + + + return (Color.HSBtoRGB((float) (((blah - (x + y) / 2.0f) % 360) / 360.0f), hsv[1],hsv[2]) & 0xffffff) + | ((color.getAlpha() << 24) & 0xff000000); + } + public static int getColorAt(double x, double y,double z, AColor color) { + if (!color.isChroma()) + return color.getRGB(); + + double blah = ((double)(color.getChromaSpeed()) * (System.currentTimeMillis() / 2)) % 360; + float[] hsv = new float[3]; + Color.RGBtoHSB(color.getRed(), color.getBlue(), color.getGreen(), hsv); + + + return (Color.HSBtoRGB((float) (((blah - ((x + y+z) / 2.0f) % 360)) / 360.0f), hsv[1],hsv[2]) & 0xffffff) + | ((color.getAlpha() << 24) & 0xff000000); + } + + public static WorldRenderer color(WorldRenderer worldRenderer, int color ){ + return worldRenderer.color(((color >> 16) & 0xFF) / 255.0f, ((color >> 8) & 0xFF) / 255.0f, (color &0xFF) / 255.0f, ((color >> 24) & 0xFF) / 255.0f); + } + + public static void renderDoor(DungeonDoor dungeonDoor, float partialTicks) { + Entity player = Minecraft.getMinecraft().thePlayer; + double playerX = player.prevPosX + (player.posX - player.prevPosX) * partialTicks; + double playerY = player.prevPosY + (player.posY - player.prevPosY) * partialTicks; + double playerZ = player.prevPosZ + (player.posZ - player.prevPosZ) * partialTicks; + + GlStateManager.pushMatrix(); + GlStateManager.translate(-playerX, -playerY, -playerZ); + GlStateManager.disableTexture2D(); + GlStateManager.enableAlpha(); + + if (dungeonDoor.getType().isExist()) + GlStateManager.color(0,1,0,1); + else + GlStateManager.color(1,0,0,1); + + double x = dungeonDoor.getPosition().getX() + 0.5; + double y = dungeonDoor.getPosition().getY() -0.99; + double z = dungeonDoor.getPosition().getZ() + 0.5; + GL11.glBegin(GL11.GL_QUADS); + + GL11.glVertex3d(x - 2.5, y, z - 2.5); + GL11.glVertex3d(x - 2.5, y, z + 2.5); + GL11.glVertex3d(x + 2.5, y, z + 2.5); + GL11.glVertex3d(x + 2.5, y, z - 2.5); + + GL11.glEnd(); + + if (dungeonDoor.getType().isExist()) { + GL11.glBegin(GL11.GL_QUADS); + + GlStateManager.color(0,0,1,1); + if (dungeonDoor.isZDir()) { + GL11.glVertex3d(x - 0.5, y + 0.1, z - 2.5); + GL11.glVertex3d(x - 0.5, y+ 0.1, z + 2.5); + GL11.glVertex3d(x + 0.5, y+ 0.1, z + 2.5); + GL11.glVertex3d(x + 0.5, y+ 0.1, z - 2.5); + } else { + GL11.glVertex3d(x - 2.5, y+ 0.1, z - 0.5); + GL11.glVertex3d(x - 2.5, y+ 0.1, z + 0.5); + GL11.glVertex3d(x + 2.5, y+ 0.1, z + 0.5); + GL11.glVertex3d(x + 2.5, y+ 0.1, z - 0.5); + } + + GL11.glEnd(); + } else { + GL11.glLineWidth(5); + GL11.glBegin(GL11.GL_LINE_LOOP); + GL11.glVertex3d(x - 2.5, y, z - 2.5); + GL11.glVertex3d(x + 2.5, y + 5, z - 2.5); + GL11.glVertex3d(x + 2.5, y, z + 2.5); + GL11.glVertex3d(x - 2.5, y + 5, z + 2.5); + GL11.glEnd(); + GL11.glBegin(GL11.GL_LINE_LOOP); + GL11.glVertex3d(x - 2.5, y +5, z - 2.5); + GL11.glVertex3d(x + 2.5, y, z - 2.5); + GL11.glVertex3d(x + 2.5, y + 5, z + 2.5); + GL11.glVertex3d(x - 2.5, y, z + 2.5); + GL11.glEnd(); + GL11.glLineWidth(1); + } +// GlStateManager.disableAlpha(); + GlStateManager.disableBlend(); + + GlStateManager.enableTexture2D(); + + + RenderManager renderManager = Minecraft.getMinecraft().getRenderManager(); + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + + GlStateManager.translate( dungeonDoor.getPosition().getX(), dungeonDoor.getPosition().getY(), dungeonDoor.getPosition().getZ()); + GlStateManager.rotate(-renderManager.playerViewY, 0.0f, 1.0f, 0.0f); + GlStateManager.rotate(renderManager.playerViewX, 1.0f, 0.0f, 0.0f); + + float lScale = 0.02f; + GlStateManager.scale(-lScale, -lScale, lScale); + GlStateManager.disableLighting(); + GlStateManager.enableBlend(); + GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + String text = "Type: "+dungeonDoor.getType(); + int textWidth = fontRenderer.getStringWidth(text); + + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + GlStateManager.enableBlend(); + GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + fontRenderer.drawString(text, -textWidth / 2, 0, 0xFF00FFFF); + + GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); + GlStateManager.popMatrix(); + } + + public static void drawLine(Vec3 pos1, Vec3 pos2, Color colour, float partialTicks , boolean depth) { + Entity render = Minecraft.getMinecraft().getRenderViewEntity(); + WorldRenderer worldRenderer = Tessellator.getInstance().getWorldRenderer(); + + double realX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks; + double realY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks; + double realZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks; + + GlStateManager.pushMatrix(); + GlStateManager.translate(-realX, -realY, -realZ); + GlStateManager.disableTexture2D(); + if (!depth) { + GlStateManager.disableDepth(); + GlStateManager.depthMask(false); + } + GlStateManager.enableBlend(); + GlStateManager.disableAlpha(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GL11.glLineWidth(2); + GlStateManager.color(colour.getRed() / 255f, colour.getGreen() / 255f, colour.getBlue()/ 255f, colour.getAlpha() / 255f); + worldRenderer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION); + + worldRenderer.pos(pos1.xCoord, pos1.yCoord, pos1.zCoord).endVertex(); + worldRenderer.pos(pos2.xCoord, pos2.yCoord, pos2.zCoord).endVertex(); + Tessellator.getInstance().draw(); + + GlStateManager.translate(realX, realY, realZ); + GlStateManager.disableBlend(); + if (!depth) { + GlStateManager.enableDepth(); + GlStateManager.depthMask(true); + } + GlStateManager.enableAlpha(); + GlStateManager.enableTexture2D(); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.popMatrix(); + } + + public static void drawLinesVec3(List<Vec3> poses, AColor colour, float thickness, float partialTicks, boolean depth) { + Entity render = Minecraft.getMinecraft().getRenderViewEntity(); + WorldRenderer worldRenderer = Tessellator.getInstance().getWorldRenderer(); + + double realX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks; + double realY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks; + double realZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks; + + GlStateManager.pushMatrix(); + GlStateManager.translate(-realX, -realY, -realZ); + GlStateManager.disableTexture2D(); + GlStateManager.disableLighting(); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GlStateManager.enableBlend(); + GlStateManager.disableAlpha(); + GL11.glLineWidth(thickness); + if (!depth) { + GlStateManager.disableDepth(); + GlStateManager.depthMask(false); + } + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + +// GlStateManager.color(colour.getRed() / 255f, colour.getGreen() / 255f, colour.getBlue()/ 255f, colour.getAlpha() / 255f); + GlStateManager.color(1,1,1,1); + worldRenderer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION_COLOR); + int num = 0; + for (Vec3 pos:poses) { + int i = getColorAt(num++ * 10,0, colour); + worldRenderer.pos(pos.xCoord, pos.yCoord, pos.zCoord).color( + ((i >> 16) &0xFF)/255.0f, + ((i >> 8) &0xFF)/255.0f, + (i &0xFF)/255.0f, + ((i >> 24) &0xFF)/255.0f + ).endVertex(); + } + Tessellator.getInstance().draw(); + + GlStateManager.translate(realX, realY, realZ); + GlStateManager.disableBlend(); + GlStateManager.enableAlpha(); + GlStateManager.enableTexture2D(); + if (!depth) { + GlStateManager.enableDepth(); + GlStateManager.depthMask(true); + } + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.popMatrix(); + GL11.glLineWidth(1); + } + public static void drawLines(List<BlockPos> poses, AColor colour, float thickness, float partialTicks, boolean depth) { + Entity render = Minecraft.getMinecraft().getRenderViewEntity(); + WorldRenderer worldRenderer = Tessellator.getInstance().getWorldRenderer(); + + double realX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks; + double realY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks; + double realZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks; + + GlStateManager.pushMatrix(); + GlStateManager.translate(-realX, -realY, -realZ); + GlStateManager.disableTexture2D(); + GlStateManager.disableLighting(); + GlStateManager.enableBlend(); + GlStateManager.disableAlpha(); + GL11.glLineWidth(thickness); + if (!depth) { + GlStateManager.disableDepth(); + GlStateManager.depthMask(false); + } + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + +// GlStateManager.color(colour.getRed() / 255f, colour.getGreen() / 255f, colour.getBlue()/ 255f, colour.getAlpha() / 255f); + GlStateManager.color(1,1,1,1); + worldRenderer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION_COLOR); + int num = 0; + for (BlockPos pos:poses) { + int i = getColorAt(num++ * 10,0, colour); + worldRenderer.pos(pos.getX() +0.5, pos.getY() +0.5, pos.getZ() +0.5).color( + ((i >> 16) &0xFF)/255.0f, + ((i >> 8) &0xFF)/255.0f, + (i &0xFF)/255.0f, + ((i >> 24) &0xFF)/255.0f + ).endVertex(); + } + Tessellator.getInstance().draw(); + + GlStateManager.translate(realX, realY, realZ); + GlStateManager.disableBlend(); + GlStateManager.enableAlpha(); + GlStateManager.enableTexture2D(); + if (!depth) { + GlStateManager.enableDepth(); + GlStateManager.depthMask(true); + } + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.popMatrix(); + GL11.glLineWidth(1); + } + + public static void drawLines(List<BlockPos> poses, Color colour, float thickness, float partialTicks, boolean depth) { + if (colour instanceof AColor) drawLines(poses, (AColor)colour, thickness, partialTicks,depth); + Entity render = Minecraft.getMinecraft().getRenderViewEntity(); + WorldRenderer worldRenderer = Tessellator.getInstance().getWorldRenderer(); + + double realX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks; + double realY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks; + double realZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks; + + GlStateManager.pushMatrix(); + GlStateManager.translate(-realX, -realY, -realZ); + GlStateManager.disableTexture2D(); + GlStateManager.disableLighting(); + GlStateManager.enableBlend(); + GlStateManager.disableAlpha(); + GL11.glLineWidth(thickness); + if (!depth) { + GlStateManager.disableDepth(); + GlStateManager.depthMask(false); + } + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + + GlStateManager.color(colour.getRed() / 255f, colour.getGreen() / 255f, colour.getBlue()/ 255f, colour.getAlpha() / 255f); + worldRenderer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION); + for (BlockPos pos:poses) { + worldRenderer.pos(pos.getX() +0.5, pos.getY() +0.5, pos.getZ() +0.5).endVertex(); + } + Tessellator.getInstance().draw(); + + GlStateManager.translate(realX, realY, realZ); + GlStateManager.disableBlend(); + GlStateManager.enableAlpha(); + GlStateManager.enableTexture2D(); + if (!depth) { + GlStateManager.enableDepth(); + GlStateManager.depthMask(true); + } + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.popMatrix(); + } + + public static void highlightBlock(BlockPos blockpos, Color c, float partialTicks) { + highlightBlock(blockpos,c,partialTicks,false); + } + public static void highlightBlock(BlockPos blockpos, Color c, float partialTicks, boolean depth) { + Entity viewing_from = Minecraft.getMinecraft().getRenderViewEntity(); + + double x_fix = viewing_from.lastTickPosX + ((viewing_from.posX - viewing_from.lastTickPosX) * partialTicks); + double y_fix = viewing_from.lastTickPosY + ((viewing_from.posY - viewing_from.lastTickPosY) * partialTicks); + double z_fix = viewing_from.lastTickPosZ + ((viewing_from.posZ - viewing_from.lastTickPosZ) * partialTicks); + + GlStateManager.pushMatrix(); + + GlStateManager.translate(-x_fix, -y_fix, -z_fix); + + GlStateManager.disableLighting(); + GlStateManager.enableBlend(); + GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GlStateManager.disableTexture2D(); + + if (!depth) { + GlStateManager.disableDepth(); GL11.glDisable(GL11.GL_DEPTH_TEST); + GlStateManager.depthMask(false); + } + GlStateManager.color(c.getRed() /255.0f, c.getGreen() / 255.0f, c.getBlue()/ 255.0f, c.getAlpha()/ 255.0f); + + GlStateManager.translate(blockpos.getX(), blockpos.getY(), blockpos.getZ()); + + GL11.glBegin(GL11.GL_QUADS); + GL11.glVertex3d(0, 0, 0); + GL11.glVertex3d(0, 0, 1); + GL11.glVertex3d(0, 1, 1); + GL11.glVertex3d(0, 1, 0); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT + + GL11.glVertex3d(1, 0, 1); + GL11.glVertex3d(1, 0, 0); + GL11.glVertex3d(1, 1, 0); + GL11.glVertex3d(1, 1, 1); + + GL11.glVertex3d(0, 1, 1); + GL11.glVertex3d(0, 0, 1); + GL11.glVertex3d(1, 0, 1); + GL11.glVertex3d(1, 1, 1); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT + + GL11.glVertex3d(0, 0, 0); + GL11.glVertex3d(0, 1, 0); + GL11.glVertex3d(1, 1, 0); + GL11.glVertex3d(1, 0, 0); + + GL11.glVertex3d(0,1,0); + GL11.glVertex3d(0,1,1); + GL11.glVertex3d(1,1,1); + GL11.glVertex3d(1,1,0); + + GL11.glVertex3d(0,0,1); + GL11.glVertex3d(0,0,0); + GL11.glVertex3d(1,0,0); + GL11.glVertex3d(1,0,1); + + + + GL11.glEnd(); + + + if (!depth) { + GlStateManager.enableDepth(); + GlStateManager.depthMask(true); + } + GlStateManager.enableTexture2D(); + GlStateManager.enableLighting(); + GlStateManager.popMatrix(); + + + +//... + + } + + public static void highlightBox(AxisAlignedBB axisAlignedBB, Color c, float partialTicks, boolean depth) { + Entity viewing_from = Minecraft.getMinecraft().getRenderViewEntity(); + + double x_fix = viewing_from.lastTickPosX + ((viewing_from.posX - viewing_from.lastTickPosX) * partialTicks); + double y_fix = viewing_from.lastTickPosY + ((viewing_from.posY - viewing_from.lastTickPosY) * partialTicks); + double z_fix = viewing_from.lastTickPosZ + ((viewing_from.posZ - viewing_from.lastTickPosZ) * partialTicks); + + GlStateManager.pushMatrix(); + + GlStateManager.translate(-x_fix, -y_fix, -z_fix); + + GlStateManager.disableLighting(); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GlStateManager.disableTexture2D(); + + if (!depth) { + GlStateManager.disableDepth(); + GlStateManager.depthMask(false); + } + int rgb = c.getRGB(); + GlStateManager.color(((rgb >> 16) &0XFF)/ 255.0f, ((rgb>>8) &0XFF)/ 255.0f, (rgb & 0xff)/ 255.0f, ((rgb >> 24) & 0xFF) / 255.0f); + + GlStateManager.translate(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.minZ); + + double x = axisAlignedBB.maxX - axisAlignedBB.minX; + double y = axisAlignedBB.maxY - axisAlignedBB.minY; + double z = axisAlignedBB.maxZ - axisAlignedBB.minZ; + GL11.glBegin(GL11.GL_QUADS); + GL11.glVertex3d(0, 0, 0); + GL11.glVertex3d(0, 0, z); + GL11.glVertex3d(0, y, z); + GL11.glVertex3d(0, y, 0); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT + + GL11.glVertex3d(x, 0, z); + GL11.glVertex3d(x, 0, 0); + GL11.glVertex3d(x, y, 0); + GL11.glVertex3d(x, y, z); + + GL11.glVertex3d(0, y, z); + GL11.glVertex3d(0, 0, z); + GL11.glVertex3d(x, 0, z); + GL11.glVertex3d(x, y, z); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT + + GL11.glVertex3d(0, 0, 0); + GL11.glVertex3d(0, y, 0); + GL11.glVertex3d(x, y, 0); + GL11.glVertex3d(x, 0, 0); + + GL11.glVertex3d(0,y,0); + GL11.glVertex3d(0,y,z); + GL11.glVertex3d(x,y,z); + GL11.glVertex3d(x,y,0); + + GL11.glVertex3d(0,0,z); + GL11.glVertex3d(0,0,0); + GL11.glVertex3d(x,0,0); + GL11.glVertex3d(x,0,z); + + + + GL11.glEnd(); + + + if (!depth) { + GlStateManager.enableDepth(); + GlStateManager.depthMask(true); + } + GlStateManager.enableTexture2D(); + GlStateManager.enableLighting(); + GlStateManager.popMatrix(); + + } + public static void highlightBoxAColor(AxisAlignedBB axisAlignedBB, AColor c, float partialTicks, boolean depth) { + Entity viewing_from = Minecraft.getMinecraft().getRenderViewEntity(); + + double x_fix = viewing_from.lastTickPosX + ((viewing_from.posX - viewing_from.lastTickPosX) * partialTicks); + double y_fix = viewing_from.lastTickPosY + ((viewing_from.posY - viewing_from.lastTickPosY) * partialTicks); + double z_fix = viewing_from.lastTickPosZ + ((viewing_from.posZ - viewing_from.lastTickPosZ) * partialTicks); + + GlStateManager.pushMatrix(); + + GlStateManager.translate(-x_fix, -y_fix, -z_fix); + + GlStateManager.disableLighting(); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GlStateManager.disableTexture2D(); + + if (!depth) { + GlStateManager.disableDepth(); + GlStateManager.depthMask(false); + } + int rgb = RenderUtils.getColorAt(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.minZ, c); + GlStateManager.color(((rgb >> 16) &0XFF)/ 255.0f, ((rgb>>8) &0XFF)/ 255.0f, (rgb & 0xff)/ 255.0f, ((rgb >> 24) & 0xFF) / 255.0f); + + GlStateManager.translate(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.minZ); + + double x = axisAlignedBB.maxX - axisAlignedBB.minX; + double y = axisAlignedBB.maxY - axisAlignedBB.minY; + double z = axisAlignedBB.maxZ - axisAlignedBB.minZ; + GL11.glBegin(GL11.GL_QUADS); + GL11.glVertex3d(0, 0, 0); + GL11.glVertex3d(0, 0, z); + GL11.glVertex3d(0, y, z); + GL11.glVertex3d(0, y, 0); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT + + GL11.glVertex3d(x, 0, z); + GL11.glVertex3d(x, 0, 0); + GL11.glVertex3d(x, y, 0); + GL11.glVertex3d(x, y, z); + + GL11.glVertex3d(0, y, z); + GL11.glVertex3d(0, 0, z); + GL11.glVertex3d(x, 0, z); + GL11.glVertex3d(x, y, z); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT + + GL11.glVertex3d(0, 0, 0); + GL11.glVertex3d(0, y, 0); + GL11.glVertex3d(x, y, 0); + GL11.glVertex3d(x, 0, 0); + + GL11.glVertex3d(0,y,0); + GL11.glVertex3d(0,y,z); + GL11.glVertex3d(x,y,z); + GL11.glVertex3d(x,y,0); + + GL11.glVertex3d(0,0,z); + GL11.glVertex3d(0,0,0); + GL11.glVertex3d(x,0,0); + GL11.glVertex3d(x,0,z); + + + + GL11.glEnd(); + + + if (!depth) { + GlStateManager.enableDepth(); + GlStateManager.depthMask(true); + } + GlStateManager.enableTexture2D(); + GlStateManager.enableLighting(); + GlStateManager.popMatrix(); + + } + public static void highlightBox(Entity entity, AxisAlignedBB axisAlignedBB, AColor c, float partialTicks, boolean depth) { + Entity viewing_from = Minecraft.getMinecraft().getRenderViewEntity(); + + double x_fix = viewing_from.lastTickPosX + ((viewing_from.posX - viewing_from.lastTickPosX) * partialTicks); + double y_fix = viewing_from.lastTickPosY + ((viewing_from.posY - viewing_from.lastTickPosY) * partialTicks); + double z_fix = viewing_from.lastTickPosZ + ((viewing_from.posZ - viewing_from.lastTickPosZ) * partialTicks); + + GlStateManager.pushMatrix(); + + GlStateManager.translate(-x_fix, -y_fix, -z_fix); + + GlStateManager.disableLighting(); + GlStateManager.enableBlend(); + GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GlStateManager.disableTexture2D(); + + if (!depth) { + GlStateManager.disableDepth(); + GlStateManager.depthMask(false); + } + int rgb = RenderUtils.getColorAt(entity.posX * 10,entity.posY * 10,c); + GlStateManager.color(((rgb >> 16) &0XFF)/ 255.0f, ((rgb>>8) &0XFF)/ 255.0f, (rgb & 0xff)/ 255.0f, ((rgb >> 24) & 0xFF) / 255.0f); + if (axisAlignedBB == null) { + if (entity instanceof EntityArmorStand) { + axisAlignedBB = AxisAlignedBB.fromBounds(-0.4, -1.5, -0.4, 0.4, 0, 0.4); + } else if (entity instanceof EntityBat) { + axisAlignedBB = AxisAlignedBB.fromBounds(-0.4, -1.4, -0.4, 0.4, 0.4, 0.4); + } else { + axisAlignedBB = AxisAlignedBB.fromBounds(-0.4, -1.5, -0.4, 0.4, 0, 0.4); + } + } + + Vec3 renderPos = new Vec3( + (float) (entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTicks), + (float) (entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTicks), + (float) (entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTicks) + ); + GlStateManager.translate(axisAlignedBB.minX + renderPos.xCoord, axisAlignedBB.minY + renderPos.yCoord, axisAlignedBB.minZ + renderPos.zCoord); + + double x = axisAlignedBB.maxX - axisAlignedBB.minX; + double y = axisAlignedBB.maxY - axisAlignedBB.minY; + double z = axisAlignedBB.maxZ - axisAlignedBB.minZ; + GL11.glBegin(GL11.GL_QUADS); + GL11.glVertex3d(0, 0, 0); + GL11.glVertex3d(0, 0, z); + GL11.glVertex3d(0, y, z); + GL11.glVertex3d(0, y, 0); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT + + GL11.glVertex3d(x, 0, z); + GL11.glVertex3d(x, 0, 0); + GL11.glVertex3d(x, y, 0); + GL11.glVertex3d(x, y, z); + + GL11.glVertex3d(0, y, z); + GL11.glVertex3d(0, 0, z); + GL11.glVertex3d(x, 0, z); + GL11.glVertex3d(x, y, z); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT + + GL11.glVertex3d(0, 0, 0); + GL11.glVertex3d(0, y, 0); + GL11.glVertex3d(x, y, 0); + GL11.glVertex3d(x, 0, 0); + + GL11.glVertex3d(0,y,0); + GL11.glVertex3d(0,y,z); + GL11.glVertex3d(x,y,z); + GL11.glVertex3d(x,y,0); + + GL11.glVertex3d(0,0,z); + GL11.glVertex3d(0,0,0); + GL11.glVertex3d(x,0,0); + GL11.glVertex3d(x,0,z); + + + + GL11.glEnd(); + + + if (!depth) { + GlStateManager.enableDepth(); + GlStateManager.depthMask(true); + } + GlStateManager.enableTexture2D(); + GlStateManager.enableLighting(); + GlStateManager.popMatrix(); + + } + + public static void highlightBox(Entity entity, AxisAlignedBB axisAlignedBB, Color c, float partialTicks, boolean depth) { + Entity viewing_from = Minecraft.getMinecraft().getRenderViewEntity(); + + double x_fix = viewing_from.lastTickPosX + ((viewing_from.posX - viewing_from.lastTickPosX) * partialTicks); + double y_fix = viewing_from.lastTickPosY + ((viewing_from.posY - viewing_from.lastTickPosY) * partialTicks); + double z_fix = viewing_from.lastTickPosZ + ((viewing_from.posZ - viewing_from.lastTickPosZ) * partialTicks); + + GlStateManager.pushMatrix(); + + GlStateManager.translate(-x_fix, -y_fix, -z_fix); + + GlStateManager.disableLighting(); + GlStateManager.enableBlend(); + GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GlStateManager.disableTexture2D(); + + if (!depth) { + GlStateManager.disableDepth(); + GlStateManager.depthMask(false); + } + GlStateManager.color(c.getRed()/ 255.0f, c.getGreen()/ 255.0f, c.getBlue()/ 255.0f, c.getAlpha()/ 255.0f); + if (axisAlignedBB == null) { + if (entity instanceof EntityArmorStand) { + axisAlignedBB = AxisAlignedBB.fromBounds(-0.4, -1.5, -0.4, 0.4, 0, 0.4); + } else if (entity instanceof EntityBat) { + axisAlignedBB = AxisAlignedBB.fromBounds(-0.4, -1.4, -0.4, 0.4, 0.4, 0.4); + } else { + axisAlignedBB = AxisAlignedBB.fromBounds(-0.4, -1.5, -0.4, 0.4, 0, 0.4); + } + } + + Vec3 renderPos = new Vec3( + (float) (entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTicks), + (float) (entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTicks), + (float) (entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTicks) + ); + GlStateManager.translate(axisAlignedBB.minX + renderPos.xCoord, axisAlignedBB.minY + renderPos.yCoord, axisAlignedBB.minZ + renderPos.zCoord); + + double x = axisAlignedBB.maxX - axisAlignedBB.minX; + double y = axisAlignedBB.maxY - axisAlignedBB.minY; + double z = axisAlignedBB.maxZ - axisAlignedBB.minZ; + GL11.glBegin(GL11.GL_QUADS); + GL11.glVertex3d(0, 0, 0); + GL11.glVertex3d(0, 0, z); + GL11.glVertex3d(0, y, z); + GL11.glVertex3d(0, y, 0); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT + + GL11.glVertex3d(x, 0, z); + GL11.glVertex3d(x, 0, 0); + GL11.glVertex3d(x, y, 0); + GL11.glVertex3d(x, y, z); + + GL11.glVertex3d(0, y, z); + GL11.glVertex3d(0, 0, z); + GL11.glVertex3d(x, 0, z); + GL11.glVertex3d(x, y, z); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT + + GL11.glVertex3d(0, 0, 0); + GL11.glVertex3d(0, y, 0); + GL11.glVertex3d(x, y, 0); + GL11.glVertex3d(x, 0, 0); + + GL11.glVertex3d(0,y,0); + GL11.glVertex3d(0,y,z); + GL11.glVertex3d(x,y,z); + GL11.glVertex3d(x,y,0); + + GL11.glVertex3d(0,0,z); + GlStateManager.disableDepth(); + GL11.glVertex3d(0,0,0); + GL11.glVertex3d(x,0,0); + GL11.glVertex3d(x,0,z); + + + + GL11.glEnd(); + + + if (!depth) { + GlStateManager.enableDepth(); + GlStateManager.depthMask(true); + } + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + GlStateManager.enableLighting(); + GlStateManager.popMatrix(); + + } + public static void highlightBox(Entity entity, Color c, float partialTicks, boolean depth) { + Entity viewing_from = Minecraft.getMinecraft().getRenderViewEntity(); + + double x_fix = viewing_from.lastTickPosX + ((viewing_from.posX - viewing_from.lastTickPosX) * partialTicks); + double y_fix = viewing_from.lastTickPosY + ((viewing_from.posY - viewing_from.lastTickPosY) * partialTicks); + double z_fix = viewing_from.lastTickPosZ + ((viewing_from.posZ - viewing_from.lastTickPosZ) * partialTicks); + + GlStateManager.pushMatrix(); + + GlStateManager.translate(-x_fix, -y_fix, -z_fix); + + GlStateManager.disableLighting(); + GlStateManager.enableBlend(); + GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GlStateManager.disableTexture2D(); + + if (!depth) { + GlStateManager.disableDepth(); + GlStateManager.depthMask(false); + } + GlStateManager.color(c.getRed()/ 255.0f, c.getGreen()/ 255.0f, c.getBlue()/ 255.0f, c.getAlpha()/ 255.0f); + AxisAlignedBB axisAlignedBB; + if (entity instanceof EntityArmorStand) { + axisAlignedBB = AxisAlignedBB.fromBounds(-0.4, -1.5, -0.4, 0.4, 0, 0.4); + } else if (entity instanceof EntityBat) { + axisAlignedBB = AxisAlignedBB.fromBounds(-0.4, -1.4, -0.4, 0.4, 0.4, 0.4); + } else { + axisAlignedBB = AxisAlignedBB.fromBounds(-0.4, -1.5, -0.4, 0.4, 0, 0.4); + } + + Vec3 renderPos = new Vec3( + (float) (entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTicks), + (float) (entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTicks), + (float) (entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTicks) + ); + GlStateManager.translate(axisAlignedBB.minX + renderPos.xCoord, axisAlignedBB.minY + renderPos.yCoord, axisAlignedBB.minZ + renderPos.zCoord); + + double x = axisAlignedBB.maxX - axisAlignedBB.minX; + double y = axisAlignedBB.maxY - axisAlignedBB.minY; + double z = axisAlignedBB.maxZ - axisAlignedBB.minZ; + GL11.glBegin(GL11.GL_QUADS); + GL11.glVertex3d(0, 0, 0); + GL11.glVertex3d(0, 0, z); + GL11.glVertex3d(0, y, z); + GL11.glVertex3d(0, y, 0); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT + + GL11.glVertex3d(x, 0, z); + GL11.glVertex3d(x, 0, 0); + GL11.glVertex3d(x, y, 0); + GL11.glVertex3d(x, y, z); + + GL11.glVertex3d(0, y, z); + GL11.glVertex3d(0, 0, z); + GL11.glVertex3d(x, 0, z); + GL11.glVertex3d(x, y, z); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT + + GL11.glVertex3d(0, 0, 0); + GL11.glVertex3d(0, y, 0); + GL11.glVertex3d(x, y, 0); + GL11.glVertex3d(x, 0, 0); + + GL11.glVertex3d(0,y,0); + GL11.glVertex3d(0,y,z); + GL11.glVertex3d(x,y,z); + GL11.glVertex3d(x,y,0); + + GL11.glVertex3d(0,0,z); + GL11.glVertex3d(0,0,0); + GL11.glVertex3d(x,0,0); + GL11.glVertex3d(x,0,z); + + + + GL11.glEnd(); + + + if (!depth) { + GlStateManager.enableDepth(); + GlStateManager.depthMask(true); + } + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + GlStateManager.enableLighting(); + GlStateManager.popMatrix(); + + + +//... + + } + + public static void highlightBox(Entity entity, AColor c, float partialTicks, boolean depth) { + Entity viewing_from = Minecraft.getMinecraft().getRenderViewEntity(); + + double x_fix = viewing_from.lastTickPosX + ((viewing_from.posX - viewing_from.lastTickPosX) * partialTicks); + double y_fix = viewing_from.lastTickPosY + ((viewing_from.posY - viewing_from.lastTickPosY) * partialTicks); + double z_fix = viewing_from.lastTickPosZ + ((viewing_from.posZ - viewing_from.lastTickPosZ) * partialTicks); + + GlStateManager.pushMatrix(); + + GlStateManager.translate(-x_fix, -y_fix, -z_fix); + + GlStateManager.disableLighting(); + GlStateManager.enableBlend(); + GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GlStateManager.disableTexture2D(); + + if (!depth) { + GlStateManager.disableDepth(); + GlStateManager.depthMask(false); + } + + int rgb = RenderUtils.getColorAt(entity.posX % 20,entity.posY % 20,c); + GlStateManager.color(((rgb >> 16) &0XFF)/ 255.0f, ((rgb>>8) &0XFF)/ 255.0f, (rgb & 0xff)/ 255.0f, ((rgb >> 24) & 0xFF) / 255.0f); + + AxisAlignedBB axisAlignedBB; + if (entity instanceof EntityArmorStand) { + axisAlignedBB = AxisAlignedBB.fromBounds(-0.4, -1.5, -0.4, 0.4, 0, 0.4); + } else if (entity instanceof EntityBat) { + axisAlignedBB = AxisAlignedBB.fromBounds(-0.4, -1.4, -0.4, 0.4, 0.4, 0.4); + } else { + axisAlignedBB = AxisAlignedBB.fromBounds(-0.4, -1.5, -0.4, 0.4, 0, 0.4); + } + + Vec3 renderPos = new Vec3( + (float) (entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTicks), + (float) (entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTicks), + (float) (entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTicks) + ); + GlStateManager.translate(axisAlignedBB.minX + renderPos.xCoord, axisAlignedBB.minY + renderPos.yCoord, axisAlignedBB.minZ + renderPos.zCoord); + + double x = axisAlignedBB.maxX - axisAlignedBB.minX; + double y = axisAlignedBB.maxY - axisAlignedBB.minY; + double z = axisAlignedBB.maxZ - axisAlignedBB.minZ; + GL11.glBegin(GL11.GL_QUADS); + GL11.glVertex3d(0, 0, 0); + GL11.glVertex3d(0, 0, z); + GL11.glVertex3d(0, y, z); + GL11.glVertex3d(0, y, 0); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT + + GL11.glVertex3d(x, 0, z); + GL11.glVertex3d(x, 0, 0); + GL11.glVertex3d(x, y, 0); + GL11.glVertex3d(x, y, z); + + GL11.glVertex3d(0, y, z); + GL11.glVertex3d(0, 0, z); + GL11.glVertex3d(x, 0, z); + GL11.glVertex3d(x, y, z); // TOP LEFT / BOTTOM LEFT / TOP RIGHT/ BOTTOM RIGHT + + GL11.glVertex3d(0, 0, 0); + GL11.glVertex3d(0, y, 0); + GL11.glVertex3d(x, y, 0); + GL11.glVertex3d(x, 0, 0); + + GL11.glVertex3d(0,y,0); + GL11.glVertex3d(0,y,z); + GL11.glVertex3d(x,y,z); + GL11.glVertex3d(x,y,0); + + GL11.glVertex3d(0,0,z); + GL11.glVertex3d(0,0,0); + GL11.glVertex3d(x,0,0); + GL11.glVertex3d(x,0,z); + + + + GL11.glEnd(); + + + if (!depth) { + GlStateManager.enableDepth(); + GlStateManager.depthMask(true); + } + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + GlStateManager.enableLighting(); + GlStateManager.popMatrix(); + + + +//... + + } + public static void drawTextAtWorld(String text, float x, float y, float z, int color, float scale, boolean increase, boolean renderBlackBox, float partialTicks) { + float lScale = scale; + + RenderManager renderManager = Minecraft.getMinecraft().getRenderManager(); + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + + Vector3f renderPos = getRenderPos(x, y, z, partialTicks); + + if (increase) { + double distance = Math.sqrt(renderPos.x * renderPos.x + renderPos.y * renderPos.y + renderPos.z * renderPos.z); + double multiplier = distance / 120f; //mobs only render ~120 blocks away + lScale *= 0.45f * multiplier; + } + + GlStateManager.color(1f, 1f, 1f, 0.5f); + GlStateManager.pushMatrix(); + GlStateManager.translate(renderPos.x, renderPos.y, renderPos.z); + GlStateManager.rotate(-renderManager.playerViewY, 0.0f, 1.0f, 0.0f); + GlStateManager.rotate(renderManager.playerViewX, 1.0f, 0.0f, 0.0f); + GlStateManager.scale(-lScale, -lScale, lScale); + GlStateManager.disableLighting(); + GlStateManager.depthMask(false); GL11.glDisable(GL11.GL_DEPTH_TEST); + GlStateManager.disableDepth(); + GlStateManager.enableBlend(); + GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + int textWidth = fontRenderer.getStringWidth(text); + + Tessellator tessellator = Tessellator.getInstance(); + WorldRenderer worldRenderer = tessellator.getWorldRenderer(); + if (renderBlackBox) { + double j = textWidth / 2; + GlStateManager.disableTexture2D(); + worldRenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); + worldRenderer.pos(-j - 1, -1, 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex(); + worldRenderer.pos(-j - 1, 8, 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex(); + worldRenderer.pos(j + 1, 8, 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex(); + worldRenderer.pos(j + 1, -1, 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex(); + tessellator.draw(); + GlStateManager.enableTexture2D(); + } + + GlStateManager.enableBlend(); + GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); + fontRenderer.drawString(text, -textWidth / 2, 0, color); + + GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); + GlStateManager.depthMask(true); + GlStateManager.enableDepth(); + GlStateManager.popMatrix(); + } + + public static Vector3f getRenderPos(float x, float y, float z, float partialTicks) { + EntityPlayerSP sp = Minecraft.getMinecraft().thePlayer; + return new Vector3f( + x - (float) (sp.lastTickPosX + (sp.posX - sp.lastTickPosX) * partialTicks), + y - (float) (sp.lastTickPosY + (sp.posY - sp.lastTickPosY) * partialTicks), + z - (float) (sp.lastTickPosZ + (sp.posZ - sp.lastTickPosZ) * partialTicks) + ); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/ScoreBoardUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/ScoreBoardUtils.java new file mode 100644 index 00000000..b14041e8 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/ScoreBoardUtils.java @@ -0,0 +1,58 @@ +package kr.syeyoung.dungeonsguide.mod.utils; + +import net.minecraft.client.Minecraft; +import net.minecraft.scoreboard.Score; +import net.minecraft.scoreboard.ScoreObjective; +import net.minecraft.scoreboard.ScorePlayerTeam; +import net.minecraft.scoreboard.Scoreboard; + +import java.util.function.Consumer; + +public class ScoreBoardUtils { + + public static void forEachLine(Consumer<String> lineConsumer){ + Scoreboard scoreboard = Minecraft.getMinecraft().thePlayer.getWorldScoreboard(); + ScoreObjective objective = scoreboard.getObjectiveInDisplaySlot(1); + for (Score sc : scoreboard.getSortedScores(objective)) { + ScorePlayerTeam scorePlayerTeam = scoreboard.getPlayersTeam(sc.getPlayerName()); + String line = ScorePlayerTeam.formatPlayerName(scorePlayerTeam, sc.getPlayerName()).trim(); + String stripped = TextUtils.keepScoreboardCharacters(TextUtils.stripColor(line)); +// if (line.contains("[") && line.endsWith("❤")) { +// String name = stripped.split(" ")[stripped.split(" ").length - 2]; +// int health = Integer.parseInt(stripped.split(" ")[stripped.split(" ").length - 1]); +// if (health < lowestHealth) { +// lowestHealth = health; +// lowestHealthName = name; +// } +// } + + lineConsumer.accept(line); + + } + } + + public static void forEachLineClean(Consumer<String> lineConsumer){ + Scoreboard scoreboard = Minecraft.getMinecraft().thePlayer.getWorldScoreboard(); + ScoreObjective objective = scoreboard.getObjectiveInDisplaySlot(1); + for (Score sc : scoreboard.getSortedScores(objective)) { + ScorePlayerTeam scorePlayerTeam = scoreboard.getPlayersTeam(sc.getPlayerName()); + String line = ScorePlayerTeam.formatPlayerName(scorePlayerTeam, sc.getPlayerName()).trim(); + String stripped = TextUtils.keepScoreboardCharacters(TextUtils.stripColor(line)); +// if (line.contains("[") && line.endsWith("❤")) { +// String name = stripped.split(" ")[stripped.split(" ").length - 2]; +// int health = Integer.parseInt(stripped.split(" ")[stripped.split(" ").length - 1]); +// if (health < lowestHealth) { +// lowestHealth = health; +// lowestHealthName = name; +// } +// } + + lineConsumer.accept(stripped); + + } + } + + + + +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/ShortUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/ShortUtils.java new file mode 100755 index 00000000..523988d1 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/ShortUtils.java @@ -0,0 +1,47 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.utils; + +public class ShortUtils { + public static short rotateCounterClockwise(short integer) { + int res = 0; + for(int i=0; i<16; i++){ + int x = i % 4; + int y = i / 4; + res |= (integer >> i & 0x1) << ((4-x-1)*4 + y); + } + return (short) (res & 0xFFFF); + } + public static short rotateClockwise(short integer) { + int res = 0; + for(int i=0; i<16; i++){ + int x = i % 4; + int y = i / 4; + res |= (integer >> i & 0x1) << (x *4 +(4 - y - 1)); + } + return (short) (res & 0xFFFF); + } + + public static short topLeftifyInt(short integer) { + int it = integer & 0xFFFF; + while ((it & (0x1111)) == 0) it >>= 1; + while ((it & (0xF)) == 0) it >>= 4; + return (short) (it & 0xFFFF); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/SkyblockUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/SkyblockUtils.java new file mode 100755 index 00000000..6d7af229 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/SkyblockUtils.java @@ -0,0 +1,52 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.utils; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +public class SkyblockUtils { + public static long getSkyblockYear() throws IOException { + URL url = new URL("https://hypixel-api.inventivetalent.org/api/skyblock/calendar"); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("User-Agent", "DungeonsGuide/1.0"); + InputStreamReader inputStreamReader = new InputStreamReader(connection.getInputStream()); + JsonObject object = (JsonObject) new JsonParser().parse(inputStreamReader); + if (!object.get("success").getAsBoolean()) { + return -1; + } + long now = System.currentTimeMillis() / 1000; + + JsonObject real = object.getAsJsonObject("real"); + long secondsPerYear = real.get("SECONDS_PER_MONTH").getAsLong() * 12; + JsonObject lastLog = object.getAsJsonObject("lastLog"); + long lastTime = lastLog.get("time").getAsLong(); + long year = lastLog.get("year").getAsLong(); + + long passedTime = now - lastTime; + year += passedTime / secondsPerYear; + return year; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/TabListUtil.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/TabListUtil.java new file mode 100644 index 00000000..91ccb4fd --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/TabListUtil.java @@ -0,0 +1,75 @@ +package kr.syeyoung.dungeonsguide.mod.utils; + +import kr.syeyoung.dungeonsguide.mod.features.impl.dungeon.FeatureDungeonMap; +import net.minecraft.client.Minecraft; +import net.minecraft.client.network.NetworkPlayerInfo; +import net.minecraft.scoreboard.ScorePlayerTeam; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class TabListUtil { + final static Pattern tabListRegex = Pattern.compile("\\*[a-zA-Z0-9_]{2,16}\\*", Pattern.MULTILINE); + + public static List<String> getPlayersInDungeon(){ + List<String> players = new ArrayList<>(); + List<NetworkPlayerInfo> list = FeatureDungeonMap.sorter.sortedCopy(Minecraft.getMinecraft().thePlayer.sendQueue.getPlayerInfoMap()); + + if(list.size() >= 20){ + for (int i = 1; i < 20; i++) { + + String na = getPlayerNameWithChecks(list.get(i)); + + if(na != null){ + players.add(na); + } + } + } + + return players; + } + + /** + * We make sure that the player is alive and regex their name out + * @param networkPlayerInfo the network player info of player + * @return the username of player + */ + @Nullable + public static String getPlayerNameWithChecks(NetworkPlayerInfo networkPlayerInfo) { + String name; + if (networkPlayerInfo.getDisplayName() != null) { + name = networkPlayerInfo.getDisplayName().getFormattedText(); + } else { + name = ScorePlayerTeam.formatPlayerName( + networkPlayerInfo.getPlayerTeam(), + networkPlayerInfo.getGameProfile().getName() + ); + } + + if (name.trim().equals("§r") || name.startsWith("§r ")) return null; + + name = TextUtils.stripColor(name); + + if(name.contains("(DEAD)")) { + return null; + } + + return getString(name, tabListRegex); + } + + @Nullable + public static String getString(String name, Pattern tabListRegex) { + name = name.replace(" ", "*"); + + Matcher matcher = tabListRegex.matcher(name); + if (!matcher.find()) return null; + + name = matcher.group(0); + name = name.substring(0, name.length() - 1); + name = name.substring(1); + return name; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/TextUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/TextUtils.java new file mode 100755 index 00000000..1da4e8e7 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/TextUtils.java @@ -0,0 +1,121 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.utils; + +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import java.util.regex.Pattern; + +public class TextUtils { + private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)§[0-9A-FK-OR]"); + + private static final Pattern SCOREBOARD_CHARACTERS = Pattern.compile("[^a-z A-Z:0-9/'.]"); + + private static final Pattern INTEGER_CHARACTERS = Pattern.compile("[^0-9]"); + + public static String stripColor(String input) { + return STRIP_COLOR_PATTERN.matcher(input).replaceAll(""); + } + + public static String keepScoreboardCharacters(String text) { + return SCOREBOARD_CHARACTERS.matcher(text).replaceAll(""); + } + + public static String keepIntegerCharactersOnly(String text) { + return INTEGER_CHARACTERS.matcher(text).replaceAll(""); + } + + public static String join(List list, String delimeter) { + if (list.isEmpty()) return ""; + StringBuilder stringBuilder = new StringBuilder(); + for (int i = 0; i < list.size() - 1; i++) { + stringBuilder.append(list.get(i).toString()).append(delimeter); + } + stringBuilder.append(list.get(list.size() - 1).toString()); + return stringBuilder.toString(); + } + + + private static final TreeMap<Long, String> suffixes = new TreeMap<Long, String>(); + + static { + suffixes.put(1000L, "k"); + suffixes.put(1000000L, "m"); + suffixes.put(1000000000L, "b"); + } + + public static String format(long value) { +// return String.valueOf(value); + if (value == Long.MIN_VALUE) + return format(-9223372036854775807L); + if (value < 0L) + return "-" + format(-value); + if (value < 1000L) + return Long.toString(value); + Map.Entry<Long, String> e = suffixes.floorEntry(value); + Long divideBy = e.getKey(); + String suffix = e.getValue(); + long truncated = value * 10 / divideBy ; + boolean hasDecimal = (truncated < 100L && (truncated / 10.0D) != (truncated / 10L)); + return hasDecimal ? ((truncated / 10.0D) + suffix) : ((truncated / 10L) + suffix); + } + public static long reverseFormat(String str2) { + String str = str2.toLowerCase(); + String integerPart = str.substring(0, str.length() - 1); + long multiplier = 1; + if (str.endsWith("k")) multiplier = 1000; + else if (str.endsWith("m")) multiplier = 1000000; + else if (str.endsWith("b")) multiplier = 1000000000; + else integerPart = str; + return (long) (Double.parseDouble(integerPart) * multiplier); + } + + public static String formatTime(long ms) { + long seconds = (long) Math.ceil(ms / 1000.0); + long hr = seconds / (60 * 60); seconds -= hr * 60 * 60; + long min = seconds / 60; seconds -= min * 60; + + StringBuilder stringBuilder = new StringBuilder(); + if (hr > 0) { + stringBuilder.append(hr).append("h "); + } + if (hr > 0 || min > 0) { + stringBuilder.append(min).append("m "); + } + if (hr > 0 || min > 0 || seconds > 0) { + stringBuilder.append(seconds).append("s "); + } + + return stringBuilder.toString(); + } + public static String insertDashUUID(String uuid) { + StringBuilder sb = new StringBuilder(uuid); + sb.insert(8, "-"); + sb = new StringBuilder(sb.toString()); + sb.insert(13, "-"); + sb = new StringBuilder(sb.toString()); + sb.insert(18, "-"); + sb = new StringBuilder(sb.toString()); + sb.insert(23, "-"); + + return sb.toString(); + } + +}
\ No newline at end of file diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/TimeScoreUtil.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/TimeScoreUtil.java new file mode 100644 index 00000000..def77def --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/TimeScoreUtil.java @@ -0,0 +1,82 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.utils; + +import kr.syeyoung.dungeonsguide.Main; +import org.apache.commons.io.IOUtils; + +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +public class TimeScoreUtil { + private static final TreeMap<Integer, Integer> min8 = new TreeMap<Integer, Integer>(); + private static final TreeMap<Integer, Integer> min10 = new TreeMap<Integer, Integer>(); + private static final TreeMap<Integer, Integer> min12 = new TreeMap<Integer, Integer>(); + public static void init() { + try { + load("8.csv", min8); + } catch (IOException e) { + e.printStackTrace(); + } + try { + load("10.csv", min10); + } catch (IOException e) { + e.printStackTrace(); + } + try { + load("12.csv", min12); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static void load(String name, TreeMap<Integer, Integer> minutes) throws IOException { + minutes.clear(); + List<String> lines = IOUtils.readLines(Main.class.getResourceAsStream("/timescore/"+name)); + for (String line:lines) { + String[] split = line.split(","); + minutes.put(Integer.parseInt(split[0]), Integer.parseInt(split[1])); + } + } + + public static int estimate(int mills, int drop) { + if (drop == 600) return estimate(mills, min10); + if (drop == 480) return estimate(mills, min8); + if (drop == 720) return estimate(mills, min12); + return -1; + } + + private static int estimate(int mills, TreeMap<Integer, Integer> lookup_table){ + Map.Entry<Integer, Integer> high = lookup_table.ceilingEntry(mills); + Map.Entry<Integer, Integer> low = lookup_table.floorEntry(mills); + + + if (low == null && high == null) return 0; + if (low == null) return high.getValue(); + if (high == null) return low.getValue(); + + int distHigh = high.getKey() - mills; + int distLow = mills - low.getKey(); + + if (distHigh > distLow) return high.getValue(); + else return low.getValue(); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/TitleRender.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/TitleRender.java new file mode 100644 index 00000000..dfc0b0a1 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/TitleRender.java @@ -0,0 +1,139 @@ +package kr.syeyoung.dungeonsguide.mod.utils; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.MathHelper; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.NotNull; + +/** + * STOLEN FROM VANILLA 1.8.9, DONT @ ME + * CREDS TO MOJANG AND THE CREW + */ +public class TitleRender { + + Logger logger = LogManager.getLogger("TitleRender"); + + private static TitleRender instance; + public static TitleRender getInstance() { + return instance == null ? instance = new TitleRender() : instance; + } + + private TitleRender() { + MinecraftForge.EVENT_BUS.register(this); + } + + protected static int titlesTimer; + /** + * The current title displayed + */ + protected static String displayedTitle = ""; + /** + * The current sub-title displayed + */ + protected static String displayedSubTitle = ""; + /** + * The time that the title take to fade in + */ + protected static int titleFadeIn; + /** + * The time that the title is display + */ + protected static int titleDisplayTime; + + /** + * The time that the title take to fade out + */ + protected static int titleFadeOut; + Minecraft mc = Minecraft.getMinecraft(); + + FontRenderer fontRenderer = mc.fontRendererObj; + + + @SubscribeEvent + public void onClinetTick(TickEvent.ClientTickEvent e){ + if(e.phase == TickEvent.Phase.START){ + tick(); + } + } + + @SubscribeEvent + public void onGameOverLay(RenderGameOverlayEvent.Post e){ + if (!(e.type == RenderGameOverlayEvent.ElementType.EXPERIENCE || e.type == RenderGameOverlayEvent.ElementType.JUMPBAR)) return; + GlStateManager.enableBlend(); + draw(e.partialTicks); + } + + + void tick(){ + if (titlesTimer > 0) { + --titlesTimer; + if (titlesTimer <= 0) { + displayedTitle = ""; + displayedSubTitle = ""; + } + } + } + + + public static void clearTitle(){ + displayedTitle = ""; + displayedSubTitle = ""; + titlesTimer = 0; + } + + + public static void displayTitle(@NotNull String title, String subTitle, int timeFadeIn, int displayTime, int timeFadeOut) { + displayedTitle = title; + displayedSubTitle = subTitle; + titleFadeIn = timeFadeIn; + titleDisplayTime = displayTime; + titleFadeOut = timeFadeOut; + titlesTimer = titleFadeIn + titleDisplayTime + titleFadeOut; + } + + void draw(float partialTicks){ + float g; + int l; + ScaledResolution scaledResolution = new ScaledResolution(mc); + int i = scaledResolution.getScaledWidth(); + int j = scaledResolution.getScaledHeight(); + if (titlesTimer > 0) { + g = titlesTimer - partialTicks; + l = 255; + if (titlesTimer > titleFadeOut + titleDisplayTime) { + float h = (float)(titleFadeIn + titleDisplayTime + titleFadeOut) - g; + l = (int)(h * 255.0f / (float)titleFadeIn); + } + if (titlesTimer <= titleFadeOut) { + float h = g; + l = (int)(h * 255.0f / (float)titleFadeOut); + } + if ((l = MathHelper.clamp_int(l, 0, 255)) > 8) { + GlStateManager.pushMatrix(); + GlStateManager.translate(i / 2, j / 2, 0.0f); + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GlStateManager.pushMatrix(); + GlStateManager.scale(6.0f, 6.0f, 6.0f); + int m = l << 24 & 0xFF000000; + fontRenderer.drawString(displayedTitle, -fontRenderer.getStringWidth(displayedTitle) / 2, -10.0f, 0xFFFFFF | m, true); + GlStateManager.popMatrix(); + GlStateManager.pushMatrix(); + GlStateManager.scale(2.0f, 2.0f, 2.0f); + fontRenderer.drawString(displayedSubTitle, -fontRenderer.getStringWidth(displayedSubTitle) / 2, 5.0f, 0xFFFFFF | m, true); + GlStateManager.popMatrix(); + GlStateManager.disableBlend(); + GlStateManager.popMatrix(); + } + } + } + +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/VectorUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/VectorUtils.java new file mode 100755 index 00000000..f3e51578 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/VectorUtils.java @@ -0,0 +1,51 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.utils; + +import lombok.AllArgsConstructor; +import lombok.Data; +import net.minecraft.util.Vec3; + +import javax.vecmath.Vector2d; + +public class VectorUtils { + // Ior rooms, different coordinate system is used. Y Increses as marker goes down. X is same. + + + public static Vector2d rotateCounterClockwise(Vector2d vector2d) { + return new Vector2d(vector2d.y, -vector2d.x); + } + public static Vector2d rotateClockwise(Vector2d vector2d) { + return new Vector2d(-vector2d.y, vector2d.x); + } + + @Data @AllArgsConstructor + public static class ProjectionResult { + private float x; + private float y; + private boolean back; + } + + public static double distSquared(Vec3 lookVec, Vec3 posVec, Vec3 objectVec) { + Vec3 v = objectVec.subtract(posVec); + double t = v.dotProduct(lookVec); + Vec3 p = posVec.addVector(lookVec.xCoord * t, lookVec.yCoord * t, lookVec.zCoord * t); + return p.squareDistanceTo(objectVec) / p.squareDistanceTo(posVec); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/XPUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/XPUtils.java new file mode 100644 index 00000000..12804565 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/XPUtils.java @@ -0,0 +1,222 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.utils; + +import kr.syeyoung.dungeonsguide.mod.features.impl.party.playerpreview.api.playerprofile.dataclasses.Skill; +import lombok.Data; + +import java.util.Map; +import java.util.TreeMap; + +public class XPUtils { + @Data + public static class XPCalcResult { + private int level; + private double remainingXp; + private double nextLvXp; + } + + private static final TreeMap<Double, Integer> catacombXp = new TreeMap<>(); + private static final TreeMap<Double, Integer> skillXp = new TreeMap<>(); + private static final TreeMap<Double, Integer> skillXp2 = new TreeMap<>(); + static { + catacombXp.put(50.0, 1); + catacombXp.put(125.0, 2); + catacombXp.put(235.0, 3); + catacombXp.put(395.0, 4); + catacombXp.put(625.0, 5); + catacombXp.put(955.0, 6); + catacombXp.put(1425.0, 7); + catacombXp.put(2095.0, 8); + catacombXp.put(3045.0, 9); + catacombXp.put(4385.0, 10); + catacombXp.put(6275.0, 11); + catacombXp.put(8940.0, 12); + catacombXp.put(12700.0, 13); + catacombXp.put(17960.0, 14); + catacombXp.put(25340.0, 15); + catacombXp.put(35640.0, 16); + catacombXp.put(50040.0, 17); + catacombXp.put(70040.0, 18); + catacombXp.put(97640.0, 19); + catacombXp.put(135640.0, 20); + catacombXp.put(188140.0, 21); + catacombXp.put(259640.0, 22); + catacombXp.put(356640.0, 23); + catacombXp.put(488640.0, 24); + catacombXp.put(668640.0, 25); + catacombXp.put(911640.0, 26); + catacombXp.put(1239640.0, 27); + catacombXp.put(1684640.0, 28); + catacombXp.put(2284640.0, 29); + catacombXp.put(3084640.0, 30); + catacombXp.put(4149640.0, 31); + catacombXp.put(5559640.0, 32); + catacombXp.put(7459640.0, 33); + catacombXp.put(9959640.0, 34); + catacombXp.put(13259640.0, 35); + catacombXp.put(17559640.0, 36); + catacombXp.put(23159640.0, 37); + catacombXp.put(30359640.0, 38); + catacombXp.put(39559640.0, 39); + catacombXp.put(51559640.0, 40); + catacombXp.put(66559640.0, 41); + catacombXp.put(85559640.0, 42); + catacombXp.put(109559640.0, 43); + catacombXp.put(139559640.0, 44); + catacombXp.put(177559640.0, 45); + catacombXp.put(225559640.0, 46); + catacombXp.put(285559640.0, 47); + catacombXp.put(360559640.0, 48); + catacombXp.put(453559640.0, 49); + catacombXp.put(569809640.0, 50); + skillXp.put(0.0, 0); + skillXp.put(50.0, 1); + skillXp.put(175.0, 2); + skillXp.put(375.0, 3); + skillXp.put(675.0, 4); + skillXp.put(1175.0, 5); + skillXp.put(1925.0, 6); + skillXp.put(2925.0, 7); + skillXp.put(4425.0, 8); + skillXp.put(6425.0, 9); + skillXp.put(9925.0, 10); + skillXp.put(14925.0, 11); + skillXp.put(22425.0, 12); + skillXp.put(32425.0, 13); + skillXp.put(47425.0, 14); + skillXp.put(67425.0, 15); + skillXp.put(97425.0, 16); + skillXp.put(147425.0, 17); + skillXp.put(222425.0, 18); + skillXp.put(322425.0, 19); + skillXp.put(522425.0, 20); + skillXp.put(822425.0, 21); + skillXp.put(1222425.0, 22); + skillXp.put(1722425.0, 23); + skillXp.put(2322425.0, 24); + skillXp.put(3022425.0, 25); + skillXp.put(3822425.0, 26); + skillXp.put(4722425.0, 27); + skillXp.put(5722425.0, 28); + skillXp.put(6822425.0, 29); + skillXp.put(8022425.0, 30); + skillXp.put(9322425.0, 31); + skillXp.put(10722425.0, 32); + skillXp.put(12222425.0, 33); + skillXp.put(13722425.0, 34); + skillXp.put(15522425.0, 35); + skillXp.put(17322425.0, 36); + skillXp.put(19222425.0, 37); + skillXp.put(21222425.0, 38); + skillXp.put(23322425.0, 39); + skillXp.put(25522425.0, 40); + skillXp.put(27822425.0, 41); + skillXp.put(30222425.0, 42); + skillXp.put(32722425.0, 43); + skillXp.put(35322425.0, 44); + skillXp.put(38072425.0, 45); + skillXp.put(40972425.0, 46); + skillXp.put(44072425.0, 47); + skillXp.put(47472425.0, 48); + skillXp.put(51172425.0, 49); + skillXp.put(55172425.0, 50); + skillXp.put(59472425.0, 51); + skillXp.put(64072425.0, 52); + skillXp.put(68972425.0, 53); + skillXp.put(74172425.0, 54); + skillXp.put(79672425.0, 55); + skillXp.put(85472425.0, 56); + skillXp.put(91572425.0, 57); + skillXp.put(97972425.0, 58); + skillXp.put(104672425.0, 59); + skillXp.put(111672425.0, 60); + skillXp2.put(0.0, 0); + skillXp2.put(50.0, 1); + skillXp2.put(150.0, 2); + skillXp2.put(275.0, 3); + skillXp2.put(435.0, 4); + skillXp2.put(635.0, 5); + skillXp2.put(885.0, 6); + skillXp2.put(1200.0, 7); + skillXp2.put(1600.0, 8); + skillXp2.put(2100.0, 9); + skillXp2.put(2725.0, 10); + skillXp2.put(3510.0, 11); + skillXp2.put(4510.0, 12); + skillXp2.put(5760.0, 13); + skillXp2.put(7324.0, 14); + skillXp2.put(9325.0, 15); + skillXp2.put(11825.0, 16); + skillXp2.put(14950.0, 17); + skillXp2.put(18950.0, 18); + skillXp2.put(23950.0, 19); + skillXp2.put(30200.0, 20); + skillXp2.put(38050.0, 21); + skillXp2.put(47850.0, 22); + skillXp2.put(60100.0, 23); + skillXp2.put(75400.0, 24); + skillXp2.put(94450.0, 25); + } + + public static XPCalcResult getCataXp(double totalXp) { + Map.Entry<Double, Integer> totalXpEn = catacombXp.floorEntry(totalXp); + XPCalcResult xpCalcResult = new XPCalcResult(); + if (totalXpEn == null) { + xpCalcResult.setLevel(0); + xpCalcResult.remainingXp = totalXp; + } else { + xpCalcResult.level = totalXpEn.getValue(); + xpCalcResult.remainingXp = totalXp - totalXpEn.getKey(); + } + Map.Entry<Double, Integer> asdasd = catacombXp.ceilingEntry(totalXp); + xpCalcResult.nextLvXp = asdasd == null ? 0 : (asdasd.getKey() - (totalXpEn != null ? totalXpEn.getKey() : 0)); + return xpCalcResult; + } + public static XPCalcResult getSkillXp(Skill skill, double totalXp) { + switch(skill) { + case RUNECRAFTING: + Map.Entry<Double, Integer> totalXpEn = skillXp2.floorEntry(totalXp); + XPCalcResult xpCalcResult = new XPCalcResult(); + if (totalXpEn == null) { + xpCalcResult.setLevel(0); + xpCalcResult.remainingXp = totalXp; + } else { + xpCalcResult.level = totalXpEn.getValue(); + xpCalcResult.remainingXp = totalXp - totalXpEn.getKey(); + } + Map.Entry<Double, Integer> asdasd = catacombXp.ceilingEntry(totalXp); + xpCalcResult.nextLvXp = asdasd == null ? 0 : (asdasd.getKey() - (totalXpEn != null ? totalXpEn.getKey() : 0)); + return xpCalcResult; + default: + totalXpEn = skillXp.floorEntry(totalXp); + xpCalcResult = new XPCalcResult(); + if (totalXpEn == null) { + xpCalcResult.setLevel(0); + xpCalcResult.remainingXp = totalXp; + } else { + xpCalcResult.level = totalXpEn.getValue(); + xpCalcResult.remainingXp = totalXp - totalXpEn.getKey(); + } + asdasd = catacombXp.ceilingEntry(totalXp); + xpCalcResult.nextLvXp = asdasd == null ? 0 : (asdasd.getKey() - (totalXpEn != null ? totalXpEn.getKey() : 0)); + return xpCalcResult; + } + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/CursorReader.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/CursorReader.java new file mode 100644 index 00000000..48dcc357 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/CursorReader.java @@ -0,0 +1,95 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.utils.cursor; + +import com.google.common.io.LittleEndianDataInputStream; +import com.twelvemonkeys.imageio.plugins.bmp.CURImageReader; +import lombok.Data; + +import javax.imageio.ImageIO; +import javax.imageio.stream.ImageInputStream; +import java.awt.image.BufferedImage; +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +public class CursorReader { + public static List<CursorData> readFromInputStream(InputStream inputStream) throws IOException { + LittleEndianDataInputStream dataInputStream = new LittleEndianDataInputStream(new BufferedInputStream(inputStream)); + dataInputStream.mark(Integer.MAX_VALUE); + + + int magicValue = dataInputStream.readUnsignedShort(); + if (magicValue != 0) throw new RuntimeException("Invalid Cursor file"); + int type = dataInputStream.readUnsignedShort(); + if (type != 2) throw new RuntimeException("not cursor"); + int size = dataInputStream.readShort(); + + List<CursorData> directoryList = new ArrayList<>(); + for (int i = 0; i < size; i++) { + + CursorData directory = new CursorData(); + directory.setWidth((short) dataInputStream.readUnsignedByte()); + directory.setHeight((short) dataInputStream.readUnsignedByte()); + directory.setColorCnt((short) dataInputStream.readUnsignedByte()); + directory.setMagicValue(dataInputStream.readByte()); + directory.setXHotSpot(dataInputStream.readShort()); + directory.setYHotSpot(dataInputStream.readShort()); + directory.setSizeBitmap(dataInputStream.readInt() & 0x00000000ffffffffL); + directory.setOffset(dataInputStream.readInt() & 0x00000000ffffffffL); + + directoryList.add(directory); + } + dataInputStream.reset(); + + try (ImageInputStream imageInputStream = ImageIO.createImageInputStream(dataInputStream)) { + CURImageReader imageReader = new CURImageReader(); + imageReader.setInput(imageInputStream); + + for (int i = 0; i < directoryList.size(); i++) { + directoryList.get(i).setBufferedImage(imageReader.read(i)); + } + } + inputStream.close(); + + return directoryList; + } + + private static void setIntLittleEndian(byte[] bytes, int index, int value) { + byte[] ins = new byte[] { + (byte) ((value >> 24)& 0xFF), (byte) ((value >> 16)& 0xFF), (byte) ((value >> 8)& 0xFF), (byte) (value & 0xFF) + }; + bytes[index+3] = ins[0]; + bytes[index+2] = ins[1]; + bytes[index+1] = ins[2]; + bytes[index] = ins[3]; + } + + + @Data + public static class CursorData { + private short width, height, colorCnt, magicValue; + private int xHotSpot, yHotSpot; + private long sizeBitmap; + private long offset; + private BufferedImage bufferedImage; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/EnumCursor.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/EnumCursor.java new file mode 100644 index 00000000..e7762ba5 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/EnumCursor.java @@ -0,0 +1,54 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.utils.cursor; + +import lombok.AllArgsConstructor; +import lombok.Getter; + + +@AllArgsConstructor +@Getter +public enum EnumCursor { + DEFAULT(32512,68,"arrowCursor","arrowCursor.cur"), + POINTING_HAND(32649,60,"pointingHandCursor", "pointingHandCursor.cur"), + OPEN_HAND(32646,58,"openHandCursor","openHandCursor.cur"), + CLOSED_HAND(32646,52,"closedHandCursor","closedHandCursor.cur"), + BEAM_CURSOR(32513, 152, "IBeamCursor", "IBeamCursor.cur"), + RESIZE_LEFT(32644, 70,"resizeLeftCursor", "resizeLeftCursor.cur"), + RESIZE_RIGHT(32644, 96,"resizeRightCursor", "resizeRightCursor.cur"), + RESIZE_LEFT_RIGHT(32644, 108, "resizeLeftRightCursor", "resizeLeftRightCursor.cur"), + RESIZE_UP(32645,138,"resizeUpCursor", "resizeUpCursor.cur"), + RESIZE_DOWN(32645,16,"resizeDownCursor", "resizeDownCursor.cur"), + RESIZE_UP_DOWN(32645,116,"resizeUpDownCursor", "resizeUpDownCursor.cur"), + RESIZE_TL(32642, 134, null, "resizeNW.cur"), + RESIZE_DR(32642, 14, null, "resizeSE.cur"), + RESIZE_TLDR(32642, 14, null, "resizeNWSE.cur"), + RESIZE_TR(32643, 136, null, "resizeNE.cur"), + RESIZE_DL(32643, 12, null, "resizeSW.cur"), + RESIZE_TRDL(32643, 12, null, "resizeNESW.cur"), + CROSS(32515, 34,"crosshairCursor", "crosshairCursor.cur"), + NOT_ALLOWED(32648, -1,"operationNotAllowedCursor", "operationNotAllowedCursor.cur"), + TEST(-1, -1, null, "testnonexistant.cur"); + + + private int windows; + private int linux; + private String macos; + private String altFileName; +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/Foundation.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/Foundation.java new file mode 100644 index 00000000..7474c85a --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/Foundation.java @@ -0,0 +1,33 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.utils.cursor; + +import com.sun.jna.Library; +import com.sun.jna.Native; +import com.sun.jna.Pointer; + + +public interface Foundation extends Library { + Foundation INSTANCE = (Foundation) Native.loadLibrary("Foundation", + Foundation.class); + + Pointer objc_getClass(String className); + Pointer sel_registerName(String selectorName); + Pointer objc_msgSend(Pointer receiver, Pointer selector, Object... args); +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/GLCursors.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/GLCursors.java new file mode 100644 index 00000000..23f62fa5 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/GLCursors.java @@ -0,0 +1,231 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.utils.cursor; + +import com.google.common.base.Throwables; +import com.sun.jna.Pointer; +import kr.syeyoung.dungeonsguide.mod.utils.RenderUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.lwjgl.BufferUtils; +import org.lwjgl.LWJGLException; +import org.lwjgl.LWJGLUtil; +import org.lwjgl.input.Cursor; +import sun.misc.Unsafe; + +import java.awt.image.BufferedImage; +import java.lang.reflect.Array; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.IntBuffer; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + + +@SuppressWarnings("unsafe") +public class GLCursors { + + static Logger logger = LogManager.getLogger("DG-GlCursors"); + + @SuppressWarnings("unsafe") + static boolean verbose = false; + + private static Unsafe unsafe; + private static Class cursorElement; + private static Constructor constructor; + private static Field cursorField; + + private static Map<EnumCursor, Cursor> enumCursorCursorMap = new HashMap<>(); + + + static { + try { + Field f = Unsafe.class.getDeclaredField("theUnsafe"); + f.setAccessible(true); + unsafe = (Unsafe) f.get(null); + cursorElement = Class.forName("org.lwjgl.input.Cursor$CursorElement"); + constructor = cursorElement.getDeclaredConstructor(Object.class, long.class, long.class); + constructor.setAccessible(true); + cursorField = Cursor.class.getDeclaredField("cursors"); + cursorField.setAccessible(true); + } catch (NoSuchFieldException | IllegalAccessException | ClassNotFoundException | NoSuchMethodException e) { + e.printStackTrace(); + } + } + + public static void setupCursors() { + if (enumCursorCursorMap.size() != 0) return; + int platform = LWJGLUtil.getPlatform(); + for (EnumCursor value : EnumCursor.values()) { + Cursor c = null; + try { + switch(platform) { + case LWJGLUtil.PLATFORM_WINDOWS: + if (value.getWindows() != -1) + c = createCursorWindows(value.getWindows()); + break; + case LWJGLUtil.PLATFORM_LINUX: + if (value.getLinux() != -1) + c = createCursorLinux(value.getLinux()); + break; + case LWJGLUtil.PLATFORM_MACOSX: + if (value.getMacos() != null) + c = createCursorMac(value.getMacos()); + break; + } + } catch (Throwable e) { + if(verbose) logger.error("Error occured while loading cursor: {}", value); + e.printStackTrace(); + } + try { + if (c == null) { + int hotspotX = 0, hotspotY = 0; + BufferedImage bufferedImage = null; + int minC = Cursor.getMinCursorSize(), maxC = Cursor.getMaxCursorSize(); + try { + ResourceLocation cursorinfo = new ResourceLocation("dungeonsguide:cursors/"+value.getAltFileName()); + List<CursorReader.CursorData> cursorDataList = CursorReader.readFromInputStream(Minecraft.getMinecraft().getResourceManager().getResource(cursorinfo).getInputStream()); + List<CursorReader.CursorData> cursorDataList2 = cursorDataList.stream() + .filter(cdata -> cdata.getBufferedImage() != null) + .filter(cdata -> minC <= cdata.getHeight() && cdata.getHeight() <= maxC && minC <= cdata.getWidth() && cdata.getWidth() <= maxC) + .sorted(Comparator.comparingInt(CursorReader.CursorData::getWidth)).collect(Collectors.toList()); + + CursorReader.CursorData cursorData = + cursorDataList2.size() == 0 ? cursorDataList.get(0) : cursorDataList2.get(0); + if(verbose) logger.info(cursorData); + bufferedImage = cursorData.getBufferedImage(); + hotspotX = cursorData.getXHotSpot(); + hotspotY = cursorData.getYHotSpot(); + } catch (Throwable t) { + if(verbose) logger.error("loading currsor failed with message, {}", String.valueOf(Throwables.getRootCause(t))); + } + + + int width = bufferedImage == null ? 16 : bufferedImage.getWidth(); + int height = bufferedImage == null ? 16 : bufferedImage.getHeight(); + int effWidth = MathHelper.clamp_int(width, Cursor.getMinCursorSize(), Cursor.getMaxCursorSize()); + int effHeight = MathHelper.clamp_int(height, Cursor.getMinCursorSize(), Cursor.getMaxCursorSize()); + int length = effHeight * effWidth; + IntBuffer intBuffer = BufferUtils.createIntBuffer(length); + for (int i = 0; i < length; i++) { + int x = i % effWidth; + int y = i / effWidth; + if (bufferedImage == null) { + intBuffer.put(RenderUtils.getChromaColorAt(x,y,1.0f, 1.0f, 1.0f, 1.0f)); + } else if (x >= width || y >= height) { + intBuffer.put(0); + } else { + intBuffer.put(bufferedImage.getRGB(x, height - y - 1)); + } + } + intBuffer.flip(); + c = new Cursor(effWidth, effHeight, hotspotX, height - hotspotY - 1,1,intBuffer, null); + } + } catch (Throwable e) { + if(verbose) logger.error("Error occured while loading cursor from resource: "+value); + e.printStackTrace(); + } + if (c != null) { + try { + Object arr = cursorField.get(c); + Object cursor = Array.get(arr, 0); + for (Field declaredField : cursor.getClass().getDeclaredFields()) { + declaredField.setAccessible(true); + Object obj = declaredField.get(cursor); + if(verbose) logger.info(declaredField.getName()+": "+obj+" - "+(obj instanceof ByteBuffer)); + if (obj instanceof ByteBuffer) { + ByteBuffer b = (ByteBuffer) declaredField.get(cursor); + StringBuilder sb = new StringBuilder("Contents: "); + for (int i = 0; i < b.limit(); i++) { + sb.append(Integer.toHexString(b.get(i) & 0xFF)).append(" "); + } + if(verbose) logger.info(sb.toString()); + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + enumCursorCursorMap.put(value, c); + } + } + } + + public static Cursor getCursor(EnumCursor enumCursor) { + return enumCursorCursorMap.get(enumCursor); + } + + private static Cursor createCursorWindows(int cursor) throws LWJGLException, InstantiationException, InvocationTargetException, IllegalAccessException { + User32 user32 = User32.INSTANCE; + Pointer hIcon = user32 + .LoadCursorW(Pointer.NULL, cursor); + long ptrVal = Pointer.nativeValue(hIcon); + ByteBuffer handle = BufferUtils.createByteBuffer(Pointer.SIZE); // Why does it have to be direct? well it crashes without it. + if (handle.order() == ByteOrder.LITTLE_ENDIAN) { + for (int i = 0; i < Pointer.SIZE; i++) { + byte value = (byte) ((ptrVal >> i * 8) & 0xFF); + handle.put(value); + } + } else { + for (int i = Pointer.SIZE; i >= 0; i++) { + byte value = (byte) ((ptrVal >> i * 8) & 0xFF); + handle.put(value); + } + } + handle.position(0); + return createCursor(handle); + } + private static Cursor createCursorLinux(int cursor) throws LWJGLException, InstantiationException, InvocationTargetException, IllegalAccessException { + X11.Display display = X11.INSTANCE.XOpenDisplay(null); + Pointer fontCursor = X11.INSTANCE.XCreateFontCursor(display, cursor); + long iconPtr = Pointer.nativeValue(fontCursor); + + return createCursor(iconPtr); + } + private static Cursor createCursorMac(String cursor) throws LWJGLException, InstantiationException, InvocationTargetException, IllegalAccessException { + // trust me, it's horrible. + Foundation foundation = Foundation.INSTANCE; + Pointer nsCursor = foundation.objc_getClass("NSCursor"); + Pointer selector = foundation.sel_registerName(cursor); + Pointer thePointer = foundation.objc_msgSend(nsCursor, selector); + long iconPtr = Pointer.nativeValue(thePointer); + + return createCursor(iconPtr); + } + + + private static Cursor createCursor(Object handle) throws IllegalAccessException, InvocationTargetException, InstantiationException { + // Yes. I had no way. + Cursor ADANGEROUSOBJECT = (Cursor) unsafe.allocateInstance(Cursor.class); + Object cursorElement = constructor.newInstance(handle, 0, LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_LINUX ? -1 : System.currentTimeMillis()); + Object array = Array.newInstance(GLCursors.cursorElement, 1); + Array.set(array, 0, cursorElement); + cursorField.set(ADANGEROUSOBJECT, array); + return ADANGEROUSOBJECT; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/User32.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/User32.java new file mode 100644 index 00000000..dfbbc03d --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/User32.java @@ -0,0 +1,67 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.utils.cursor; + +import com.sun.jna.Library; +import com.sun.jna.Native; +import com.sun.jna.Pointer; + +public interface User32 extends Library { + + public static User32 INSTANCE = (User32) Native + .loadLibrary("User32", User32.class); + + /** @see #LoadCursorW(Pointer, int) */ + public static final int IDC_ARROW = 32512; + /** @see #LoadCursorW(Pointer, int) */ + public static final int IDC_IBEAM = 32513; + /** @see #LoadCursorW(Pointer, int) */ + public static final int IDC_WAIT = 32514; + /** @see #LoadCursorW(Pointer, int) */ + public static final int IDC_CROSS = 32515; + /** @see #LoadCursorW(Pointer, int) */ + public static final int IDC_UPARROW = 32516; + /** @see #LoadCursorW(Pointer, int) */ + public static final int IDC_SIZENWSE = 32642; + /** @see #LoadCursorW(Pointer, int) */ + public static final int IDC_SIZENESW = 32643; + /** @see #LoadCursorW(Pointer, int) */ + public static final int IDC_SIZEWE = 32644; + /** @see #LoadCursorW(Pointer, int) */ + public static final int IDC_SIZENS = 32645; + /** @see #LoadCursorW(Pointer, int) */ + public static final int IDC_SIZEALL = 32646; + /** @see #LoadCursorW(Pointer, int) */ + public static final int IDC_NO = 32648; + /** @see #LoadCursorW(Pointer, int) */ + public static final int IDC_HAND = 32649; + /** @see #LoadCursorW(Pointer, int) */ + public static final int IDC_APPSTARTING = 32650; + /** @see #LoadCursorW(Pointer, int) */ + public static final int IDC_HELP = 32651; + /** @see #LoadCursorW(Pointer, int) */ + public static final int IDC_ICON = 32641; + /** @see #LoadCursorW(Pointer, int) */ + public static final int IDC_SIZE = 32640; + + /** http://msdn.microsoft.com/en-us/library/ms648391(VS.85).aspx */ + public Pointer LoadCursorW(Pointer hInstance, + int lpCursorName); + +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/X11.java b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/X11.java new file mode 100644 index 00000000..dc5a8894 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/X11.java @@ -0,0 +1,37 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.utils.cursor; + +import com.sun.jna.Library; +import com.sun.jna.Native; +import com.sun.jna.Pointer; +import com.sun.jna.PointerType; + +public interface X11 extends Library { + X11 INSTANCE = (X11) Native.loadLibrary("X11", X11.class); + public Pointer XCreateFontCursor(Display display, + int shape); + public Display XOpenDisplay(String var1); + + public static class Display extends PointerType { + public Display() { + } + } + +} |