aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java
diff options
context:
space:
mode:
authorMoulberry <jjenour@student.unimelb.edu.au>2022-03-03 11:03:58 +0800
committerGitHub <noreply@github.com>2022-03-03 11:03:58 +0800
commit7c6d37b2eb758a13b342b906f0aef88b940bc52a (patch)
tree9602a014425b859e3aba98f31f93d6de04521356 /src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java
parentb11742988dec635b5c5da7c2363803cbfafb37b1 (diff)
parentdb59eba3fd9121c7c0a88363994876c5b582c08c (diff)
downloadnotenoughupdates-7c6d37b2eb758a13b342b906f0aef88b940bc52a.tar.gz
notenoughupdates-7c6d37b2eb758a13b342b906f0aef88b940bc52a.tar.bz2
notenoughupdates-7c6d37b2eb758a13b342b906f0aef88b940bc52a.zip
Merge pull request #248 from NotEnoughUpdates/master
NEU 2.1 🙂
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java3064
1 files changed, 1594 insertions, 1470 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java
index 658f72df..592f5b19 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/DungeonMap.java
@@ -2,10 +2,10 @@ package io.github.moulberry.notenoughupdates.dungeons;
import com.google.common.collect.Iterables;
import com.google.gson.JsonObject;
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.core.BackgroundBlur;
import io.github.moulberry.notenoughupdates.core.config.Position;
import io.github.moulberry.notenoughupdates.util.NEUResourceManager;
-import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.util.SpecialColour;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.block.material.MapColor;
@@ -13,7 +13,10 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
-import net.minecraft.client.renderer.*;
+import net.minecraft.client.renderer.GlStateManager;
+import net.minecraft.client.renderer.OpenGlHelper;
+import net.minecraft.client.renderer.Tessellator;
+import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.resources.DefaultPlayerSkin;
@@ -29,11 +32,12 @@ import net.minecraft.scoreboard.Score;
import net.minecraft.scoreboard.ScoreObjective;
import net.minecraft.scoreboard.ScorePlayerTeam;
import net.minecraft.scoreboard.Scoreboard;
-import net.minecraft.util.*;
+import net.minecraft.util.Matrix4f;
+import net.minecraft.util.ResourceLocation;
+import net.minecraft.util.Vec4b;
import net.minecraft.world.storage.MapData;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.event.world.WorldEvent;
-import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL14;
@@ -42,357 +46,393 @@ import java.awt.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
-import java.util.*;
import java.util.List;
+import java.util.*;
public class DungeonMap {
-
- private static final ResourceLocation GREEN_CHECK = new ResourceLocation("notenoughupdates:dungeon_map/green_check.png");
- private static final ResourceLocation WHITE_CHECK = new ResourceLocation("notenoughupdates:dungeon_map/white_check.png");
- private static final ResourceLocation QUESTION = new ResourceLocation("notenoughupdates:dungeon_map/question.png");
- private static final ResourceLocation CROSS = new ResourceLocation("notenoughupdates:dungeon_map/cross.png");
-
- private static final ResourceLocation ROOM_RED = new ResourceLocation("notenoughupdates:dungeon_map/rooms_default/red_room.png");
- private static final ResourceLocation ROOM_BROWN = new ResourceLocation("notenoughupdates:dungeon_map/rooms_default/brown_room.png");
- private static final ResourceLocation ROOM_GRAY = new ResourceLocation("notenoughupdates:dungeon_map/rooms_default/gray_room.png");
- private static final ResourceLocation ROOM_GREEN = new ResourceLocation("notenoughupdates:dungeon_map/rooms_default/green_room.png");
- private static final ResourceLocation ROOM_PINK = new ResourceLocation("notenoughupdates:dungeon_map/rooms_default/pink_room.png");
- private static final ResourceLocation ROOM_PURPLE = new ResourceLocation("notenoughupdates:dungeon_map/rooms_default/purple_room.png");
- private static final ResourceLocation ROOM_YELLOW = new ResourceLocation("notenoughupdates:dungeon_map/rooms_default/yellow_room.png");
- private static final ResourceLocation ROOM_ORANGE = new ResourceLocation("notenoughupdates:dungeon_map/rooms_default/orange_room.png");
-
- private static final ResourceLocation CORRIDOR_RED = new ResourceLocation("notenoughupdates:dungeon_map/corridors_default/red_corridor.png");
- private static final ResourceLocation CORRIDOR_BROWN = new ResourceLocation("notenoughupdates:dungeon_map/corridors_default/brown_corridor.png");
- private static final ResourceLocation CORRIDOR_GRAY = new ResourceLocation("notenoughupdates:dungeon_map/corridors_default/gray_corridor.png");
- private static final ResourceLocation CORRIDOR_GREEN = new ResourceLocation("notenoughupdates:dungeon_map/corridors_default/green_corridor.png");
- private static final ResourceLocation CORRIDOR_PINK = new ResourceLocation("notenoughupdates:dungeon_map/corridors_default/pink_corridor.png");
- private static final ResourceLocation CORRIDOR_PURPLE = new ResourceLocation("notenoughupdates:dungeon_map/corridors_default/purple_corridor.png");
- private static final ResourceLocation CORRIDOR_YELLOW = new ResourceLocation("notenoughupdates:dungeon_map/corridors_default/yellow_corridor.png");
- private static final ResourceLocation CORRIDOR_ORANGE = new ResourceLocation("notenoughupdates:dungeon_map/corridors_default/orange_corridor.png");
-
- private static final ResourceLocation DIVIDER_BROWN = new ResourceLocation("notenoughupdates:dungeon_map/dividers_default/brown_divider.png");
-
- private static final ResourceLocation CORNER_BROWN = new ResourceLocation("notenoughupdates:dungeon_map/corners_default/brown_corner.png");
-
- private final HashMap<RoomOffset, Room> roomMap = new HashMap<>();
- private Color[][] colourMap = new Color[128][128];
- private int startRoomX = -1;
- private int startRoomY = -1;
- private int connectorSize = 5;
- private int roomSize = 0;
-
- //private final List<MapDecoration> decorations = new ArrayList<>();
- //private final List<MapDecoration> lastDecorations = new ArrayList<>();
- private long lastDecorationsMillis = -1;
- private long lastLastDecorationsMillis = -1;
-
- private Map<String, MapPosition> playerEntityMapPositions = new HashMap<>();
- private Map<String, MapPosition> playerMarkerMapPositions = new HashMap<>();
- private Set<MapPosition> rawPlayerMarkerMapPositions = new HashSet<>();
- private Map<String, MapPosition> playerMarkerMapPositionsLast = new HashMap<>();
- private HashMap<String, Integer> playerIdMap = new HashMap<>();
-
- private Map<String, ResourceLocation> playerSkinMap = new HashMap<>();
-
- private class RoomOffset {
- int x;
- int y;
-
- public RoomOffset(int x, int y) {
- this.x = x;
- this.y = y;
- }
-
- public RoomOffset left() {
- return new RoomOffset(x-1, y);
- }
-
- public RoomOffset right() {
- return new RoomOffset(x+1, y);
- }
-
- public RoomOffset up() {
- return new RoomOffset(x, y-1);
- }
-
- public RoomOffset down() {
- return new RoomOffset(x, y+1);
- }
-
- public RoomOffset[] getNeighbors() {
- return new RoomOffset[]{left(), right(), up(), down()};
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- RoomOffset that = (RoomOffset) o;
- return x == that.x && y == that.y;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(x, y);
- }
- }
-
- private enum RoomConnectionType {
- NONE, WALL, CORRIDOR, ROOM_DIVIDER
- }
-
- private class RoomConnection {
- RoomConnectionType type;
- Color colour;
-
- public RoomConnection(RoomConnectionType type, Color colour) {
- this.type = type;
- this.colour = colour;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- RoomConnection that = (RoomConnection) o;
- return type == that.type &&
- Objects.equals(colour, that.colour);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(type, colour);
- }
- }
-
- private class Room {
- Color colour = new Color(0, 0, 0, 0);
- int tickColour = 0;
- boolean fillCorner = false;
-
- RoomConnection left = new RoomConnection(RoomConnectionType.NONE, new Color(0, true));
- RoomConnection up = new RoomConnection(RoomConnectionType.NONE, new Color(0, true));
- RoomConnection right = new RoomConnection(RoomConnectionType.NONE, new Color(0, true));
- RoomConnection down = new RoomConnection(RoomConnectionType.NONE, new Color(0, true));
-
- public void renderNoRotate(int roomSize, int connectorSize, int rotation) {
- if(tickColour != 0) {
- Color tick = new Color(tickColour, true);
- ResourceLocation indicatorTex = null;
- if(tick.getRed() == 255 && tick.getGreen() == 255 && tick.getBlue() == 255) {
- indicatorTex = WHITE_CHECK;
- } else if(tick.getRed() == 0 && tick.getGreen() == 124 && tick.getBlue() == 0) {
- indicatorTex = GREEN_CHECK;
- } else if(tick.getRed() == 13 && tick.getGreen() == 13 && tick.getBlue() == 13) {
- indicatorTex = QUESTION;
- } else if(tick.getRed() == 255 && tick.getGreen() == 0 && tick.getBlue() == 0) {
- indicatorTex = CROSS;
- }
- if(indicatorTex != null) {
- Minecraft.getMinecraft().getTextureManager().bindTexture(indicatorTex);
- float x = 0;
- float y = 0;
-
- if(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmCenterCheck) {
- if(fillCorner) {
- x += -(roomSize+connectorSize)/2f*Math.cos(Math.toRadians(rotation-45))*1.414f;
- y += (roomSize+connectorSize)/2f*Math.sin(Math.toRadians(rotation-45))*1.414;
- }
- if(down.type == RoomConnectionType.ROOM_DIVIDER && right.type != RoomConnectionType.ROOM_DIVIDER) {
- x += -(roomSize+connectorSize)/2f*Math.sin(Math.toRadians(rotation));
- y += -(roomSize+connectorSize)/2f*Math.cos(Math.toRadians(rotation));
- } else if(down.type != RoomConnectionType.ROOM_DIVIDER && right.type == RoomConnectionType.ROOM_DIVIDER) {
- x += -(roomSize+connectorSize)/2f*Math.cos(Math.toRadians(rotation));
- y += (roomSize+connectorSize)/2f*Math.sin(Math.toRadians(rotation));
- }
- }
- GlStateManager.translate(x, y, 0);
- if(!NotEnoughUpdates.INSTANCE.config.dungeonMap.dmOrientCheck) {
- GlStateManager.rotate(-rotation+180, 0, 0, 1);
- }
-
- GlStateManager.pushMatrix();
- GlStateManager.scale(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmIconScale,
- NotEnoughUpdates.INSTANCE.config.dungeonMap.dmIconScale, 1);
- Utils.drawTexturedRect(-5, -5, 10, 10, GL11.GL_NEAREST);
- GlStateManager.popMatrix();
-
- if(!NotEnoughUpdates.INSTANCE.config.dungeonMap.dmOrientCheck) {
- GlStateManager.rotate(rotation-180, 0, 0, 1);
- }
- GlStateManager.translate(-x, -y, 0);
- }
- }
- }
-
- public void render(int roomSize, int connectorSize) {
- ResourceLocation roomTex = null;
- if(colour.getRed() == 114 && colour.getGreen() == 67 && colour.getBlue() == 27) {
- roomTex = ROOM_BROWN;
- } else if(colour.getRed() == 65 && colour.getGreen() == 65 && colour.getBlue() == 65) {
- roomTex = ROOM_GRAY;
- } else if(colour.getRed() == 0 && colour.getGreen() == 124 && colour.getBlue() == 0) {
- roomTex = ROOM_GREEN;
- } else if(colour.getRed() == 242 && colour.getGreen() == 127 && colour.getBlue() == 165) {
- roomTex = ROOM_PINK;
- } else if(colour.getRed() == 178 && colour.getGreen() == 76 && colour.getBlue() == 216) {
- roomTex = ROOM_PURPLE;
- } else if(colour.getRed() == 255 && colour.getGreen() == 0 && colour.getBlue() == 0) {
- roomTex = ROOM_RED;
- } else if(colour.getRed() == 229 && colour.getGreen() == 229 && colour.getBlue() == 51) {
- roomTex = ROOM_YELLOW;
- } else if(colour.getRed() == 216 && colour.getGreen() == 127 && colour.getBlue() == 51) {
- roomTex = ROOM_ORANGE;
- }
-
- if(roomTex != null) {
- Minecraft.getMinecraft().getTextureManager().bindTexture(roomTex);
- GlStateManager.color(1, 1, 1, 1);
- Utils.drawTexturedRect(0, 0, roomSize, roomSize, GL11.GL_LINEAR);
- } else {
- Gui.drawRect(0, 0, roomSize, roomSize, colour.getRGB());
- }
-
- if(fillCorner) {
- GlStateManager.color(1, 1, 1, 1);
- Minecraft.getMinecraft().getTextureManager().bindTexture(CORNER_BROWN);
- Utils.drawTexturedRect(roomSize, roomSize, connectorSize, connectorSize, GL11.GL_NEAREST);
- }
-
- for(int k=0; k<2; k++) {
- RoomConnection connection = down;
- if(k == 1) connection = right;
-
- if(connection.type == RoomConnectionType.NONE || connection.type == RoomConnectionType.WALL) continue;
-
- ResourceLocation corridorTex = null;
- if(connection.colour.getRed() == 114 && connection.colour.getGreen() == 67 && connection.colour.getBlue() == 27) {
- corridorTex = connection.type == RoomConnectionType.CORRIDOR ? CORRIDOR_BROWN : DIVIDER_BROWN;
- } else if(connection.colour.getRed() == 65 && connection.colour.getGreen() == 65 && connection.colour.getBlue() == 65) {
- corridorTex = CORRIDOR_GRAY;
- } else if(connection.colour.getRed() == 0 && connection.colour.getGreen() == 124 && connection.colour.getBlue() == 0) {
- corridorTex = CORRIDOR_GREEN;
- } else if(connection.colour.getRed() == 242 && connection.colour.getGreen() == 127 && connection.colour.getBlue() == 165) {
- corridorTex = CORRIDOR_PINK;
- } else if(connection.colour.getRed() == 178 && connection.colour.getGreen() == 76 && connection.colour.getBlue() == 216) {
- corridorTex = CORRIDOR_PURPLE;
- } else if(connection.colour.getRed() == 255 && connection.colour.getGreen() == 0 && connection.colour.getBlue() == 0) {
- corridorTex = CORRIDOR_RED;
- } else if(connection.colour.getRed() == 229 && connection.colour.getGreen() == 229 && connection.colour.getBlue() == 51) {
- corridorTex = CORRIDOR_YELLOW;
- } else if(connection.colour.getRed() == 216 && connection.colour.getGreen() == 127 && connection.colour.getBlue() == 51) {
- corridorTex = CORRIDOR_ORANGE;
- }
-
- if(corridorTex == null) {
- int xOffset = 0;
- int yOffset = 0;
- int width = 0;
- int height = 0;
-
- if(connection == right) {
- xOffset = roomSize;
- width = connectorSize;
- height = roomSize;
-
- if(connection.type == RoomConnectionType.CORRIDOR) {
- height = 8;
- yOffset += 4;
- }
- } else if(connection == down) {
- yOffset = roomSize;
- width = roomSize;
- height = connectorSize;
-
- if(connection.type == RoomConnectionType.CORRIDOR) {
- width = 8;
- xOffset += 4;
- }
- }
-
- Gui.drawRect(xOffset, yOffset, xOffset+width, yOffset+height, connection.colour.getRGB());
- } else {
- GlStateManager.color(1, 1, 1, 1);
- Minecraft.getMinecraft().getTextureManager().bindTexture(corridorTex);
- GlStateManager.pushMatrix();
- if(connection==right) {
- GlStateManager.translate(roomSize/2f, roomSize/2f, 0);
- GlStateManager.rotate(-90, 0, 0, 1);
- GlStateManager.translate(-roomSize/2f, -roomSize/2f, 0);
- }
- Utils.drawTexturedRect(0, roomSize, roomSize, connectorSize, GL11.GL_NEAREST);
- GlStateManager.popMatrix();
- }
- }
- }
- }
-
- private static final ResourceLocation mapIcons = new ResourceLocation("textures/map/map_icons.png");
-
- public static Framebuffer mapFramebuffer1 = null;
- public static Framebuffer mapFramebuffer2 = null;
- public static Matrix4f projectionMatrix = null;
- public static Shader mapShader = null;
-
- private static Framebuffer checkFramebufferSizes(Framebuffer framebuffer, int width, int height) {
- if(framebuffer == null || framebuffer.framebufferWidth != width || framebuffer.framebufferHeight != height) {
- if(framebuffer == null) {
- framebuffer = new Framebuffer(width, height, true);
- } else {
- framebuffer.createBindFramebuffer(width, height);
- }
- framebuffer.setFramebufferFilter(GL11.GL_NEAREST);
- }
- return framebuffer;
- }
-
- private static void upload(Shader shader, int width, int height, int scale, float radiusSq) {
- if(shader == null) return;
- shader.getShaderManager().getShaderUniformOrDefault("ProjMat").set(projectionMatrix);
- shader.getShaderManager().getShaderUniformOrDefault("InSize").set(width*scale, height*scale);
- shader.getShaderManager().getShaderUniformOrDefault("OutSize").set(width, height);
- shader.getShaderManager().getShaderUniformOrDefault("ScreenSize").set((float)width, (float)height);
- shader.getShaderManager().getShaderUniformOrDefault("radiusSq").set(radiusSq);
- }
-
- public int getRenderRoomSize() {
- double roomSizeOption = NotEnoughUpdates.INSTANCE.config.dungeonMap.dmRoomSize;
- if(roomSizeOption <= 0) return 12;
- return 12 + (int)Math.round(roomSizeOption*4);
- }
-
- public int getRenderConnSize() {
- int roomSizeOption = (int)Math.round(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmRoomSize);
- if(roomSizeOption <= 0) return 3;
- return 3 + roomSizeOption;
- }
-
- private HashMap<Integer, Float> borderRadiusCache = new HashMap<>();
- public float getBorderRadius() {
- int borderSizeOption = Math.round(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBorderSize);
- String sizeId = borderSizeOption == 0 ? "small" : borderSizeOption == 2 ? "large" : "medium";
-
- int style = NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBorderStyle;
- if(borderRadiusCache.containsKey(style)) {
- return borderRadiusCache.get(style);
- }
-
- try(BufferedReader reader = new BufferedReader(new InputStreamReader(Minecraft.getMinecraft().getResourceManager().getResource(
- new ResourceLocation("notenoughupdates:dungeon_map/borders/"+sizeId+"/"+style+".json")).getInputStream(), StandardCharsets.UTF_8))) {
- JsonObject json = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(reader, JsonObject.class);
- float radiusSq = json.get("radiusSq").getAsFloat();
-
- borderRadiusCache.put(style, radiusSq);
- return radiusSq;
- } catch(Exception ignored) { }
-
- borderRadiusCache.put(style, 1f);
- return 1f;
- }
-
- public void render(int centerX, int centerY) {
- boolean useFb = NotEnoughUpdates.INSTANCE.config.dungeonMap.dmCompat <= 1 && OpenGlHelper.isFramebufferEnabled();
- boolean useShd = NotEnoughUpdates.INSTANCE.config.dungeonMap.dmCompat <= 0 && OpenGlHelper.areShadersSupported();
+ private static final ResourceLocation GREEN_CHECK = new ResourceLocation(
+ "notenoughupdates:dungeon_map/green_check.png");
+ private static final ResourceLocation WHITE_CHECK = new ResourceLocation(
+ "notenoughupdates:dungeon_map/white_check.png");
+ private static final ResourceLocation QUESTION = new ResourceLocation("notenoughupdates:dungeon_map/question.png");
+ private static final ResourceLocation CROSS = new ResourceLocation("notenoughupdates:dungeon_map/cross.png");
+
+ private static final ResourceLocation ROOM_RED = new ResourceLocation(
+ "notenoughupdates:dungeon_map/rooms_default/red_room.png");
+ private static final ResourceLocation ROOM_BROWN = new ResourceLocation(
+ "notenoughupdates:dungeon_map/rooms_default/brown_room.png");
+ private static final ResourceLocation ROOM_GRAY = new ResourceLocation(
+ "notenoughupdates:dungeon_map/rooms_default/gray_room.png");
+ private static final ResourceLocation ROOM_GREEN = new ResourceLocation(
+ "notenoughupdates:dungeon_map/rooms_default/green_room.png");
+ private static final ResourceLocation ROOM_PINK = new ResourceLocation(
+ "notenoughupdates:dungeon_map/rooms_default/pink_room.png");
+ private static final ResourceLocation ROOM_PURPLE = new ResourceLocation(
+ "notenoughupdates:dungeon_map/rooms_default/purple_room.png");
+ private static final ResourceLocation ROOM_YELLOW = new ResourceLocation(
+ "notenoughupdates:dungeon_map/rooms_default/yellow_room.png");
+ private static final ResourceLocation ROOM_ORANGE = new ResourceLocation(
+ "notenoughupdates:dungeon_map/rooms_default/orange_room.png");
+
+ private static final ResourceLocation CORRIDOR_RED = new ResourceLocation(
+ "notenoughupdates:dungeon_map/corridors_default/red_corridor.png");
+ private static final ResourceLocation CORRIDOR_BROWN = new ResourceLocation(
+ "notenoughupdates:dungeon_map/corridors_default/brown_corridor.png");
+ private static final ResourceLocation CORRIDOR_GRAY = new ResourceLocation(
+ "notenoughupdates:dungeon_map/corridors_default/gray_corridor.png");
+ private static final ResourceLocation CORRIDOR_GREEN = new ResourceLocation(
+ "notenoughupdates:dungeon_map/corridors_default/green_corridor.png");
+ private static final ResourceLocation CORRIDOR_PINK = new ResourceLocation(
+ "notenoughupdates:dungeon_map/corridors_default/pink_corridor.png");
+ private static final ResourceLocation CORRIDOR_PURPLE = new ResourceLocation(
+ "notenoughupdates:dungeon_map/corridors_default/purple_corridor.png");
+ private static final ResourceLocation CORRIDOR_YELLOW = new ResourceLocation(
+ "notenoughupdates:dungeon_map/corridors_default/yellow_corridor.png");
+ private static final ResourceLocation CORRIDOR_ORANGE = new ResourceLocation(
+ "notenoughupdates:dungeon_map/corridors_default/orange_corridor.png");
+
+ private static final ResourceLocation DIVIDER_BROWN = new ResourceLocation(
+ "notenoughupdates:dungeon_map/dividers_default/brown_divider.png");
+
+ private static final ResourceLocation CORNER_BROWN = new ResourceLocation(
+ "notenoughupdates:dungeon_map/corners_default/brown_corner.png");
+
+ private final HashMap<RoomOffset, Room> roomMap = new HashMap<>();
+ private Color[][] colourMap = new Color[128][128];
+ private int startRoomX = -1;
+ private int startRoomY = -1;
+ private int connectorSize = 5;
+ private int roomSize = 0;
+
+ //private final List<MapDecoration> decorations = new ArrayList<>();
+ //private final List<MapDecoration> lastDecorations = new ArrayList<>();
+ private long lastDecorationsMillis = -1;
+ private long lastLastDecorationsMillis = -1;
+
+ private final Map<String, MapPosition> playerEntityMapPositions = new HashMap<>();
+ private final Map<String, MapPosition> playerMarkerMapPositions = new HashMap<>();
+ private final Set<MapPosition> rawPlayerMarkerMapPositions = new HashSet<>();
+ private final Map<String, MapPosition> playerMarkerMapPositionsLast = new HashMap<>();
+ private final HashMap<String, Integer> playerIdMap = new HashMap<>();
+
+ private final Map<String, ResourceLocation> playerSkinMap = new HashMap<>();
+
+ private static class RoomOffset {
+ int x;
+ int y;
+
+ public RoomOffset(int x, int y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ public RoomOffset left() {
+ return new RoomOffset(x - 1, y);
+ }
+
+ public RoomOffset right() {
+ return new RoomOffset(x + 1, y);
+ }
+
+ public RoomOffset up() {
+ return new RoomOffset(x, y - 1);
+ }
+
+ public RoomOffset down() {
+ return new RoomOffset(x, y + 1);
+ }
+
+ public RoomOffset[] getNeighbors() {
+ return new RoomOffset[]{left(), right(), up(), down()};
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ RoomOffset that = (RoomOffset) o;
+ return x == that.x && y == that.y;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(x, y);
+ }
+ }
+
+ private enum RoomConnectionType {
+ NONE, WALL, CORRIDOR, ROOM_DIVIDER
+ }
+
+ private static class RoomConnection {
+ RoomConnectionType type;
+ Color colour;
+
+ public RoomConnection(RoomConnectionType type, Color colour) {
+ this.type = type;
+ this.colour = colour;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ RoomConnection that = (RoomConnection) o;
+ return type == that.type &&
+ Objects.equals(colour, that.colour);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(type, colour);
+ }
+ }
+
+ private class Room {
+ Color colour = new Color(0, 0, 0, 0);
+ int tickColour = 0;
+ boolean fillCorner = false;
+
+ RoomConnection left = new RoomConnection(RoomConnectionType.NONE, new Color(0, true));
+ RoomConnection up = new RoomConnection(RoomConnectionType.NONE, new Color(0, true));
+ RoomConnection right = new RoomConnection(RoomConnectionType.NONE, new Color(0, true));
+ RoomConnection down = new RoomConnection(RoomConnectionType.NONE, new Color(0, true));
+
+ public void renderNoRotate(int roomSize, int connectorSize, int rotation) {
+ if (tickColour != 0) {
+ Color tick = new Color(tickColour, true);
+ ResourceLocation indicatorTex = null;
+ if (tick.getRed() == 255 && tick.getGreen() == 255 && tick.getBlue() == 255) {
+ indicatorTex = WHITE_CHECK;
+ } else if (tick.getRed() == 0 && tick.getGreen() == 124 && tick.getBlue() == 0) {
+ indicatorTex = GREEN_CHECK;
+ } else if (tick.getRed() == 13 && tick.getGreen() == 13 && tick.getBlue() == 13) {
+ indicatorTex = QUESTION;
+ } else if (tick.getRed() == 255 && tick.getGreen() == 0 && tick.getBlue() == 0) {
+ indicatorTex = CROSS;
+ }
+ if (indicatorTex != null) {
+ Minecraft.getMinecraft().getTextureManager().bindTexture(indicatorTex);
+ float x = 0;
+ float y = 0;
+
+ if (NotEnoughUpdates.INSTANCE.config.dungeonMap.dmCenterCheck) {
+ if (fillCorner) {
+ x += -(roomSize + connectorSize) / 2f * Math.cos(Math.toRadians(rotation - 45)) * 1.414f;
+ y += (roomSize + connectorSize) / 2f * Math.sin(Math.toRadians(rotation - 45)) * 1.414;
+ }
+ if (down.type == RoomConnectionType.ROOM_DIVIDER && right.type != RoomConnectionType.ROOM_DIVIDER) {
+ x += -(roomSize + connectorSize) / 2f * Math.sin(Math.toRadians(rotation));
+ y += -(roomSize + connectorSize) / 2f * Math.cos(Math.toRadians(rotation));
+ } else if (down.type != RoomConnectionType.ROOM_DIVIDER && right.type == RoomConnectionType.ROOM_DIVIDER) {
+ x += -(roomSize + connectorSize) / 2f * Math.cos(Math.toRadians(rotation));
+ y += (roomSize + connectorSize) / 2f * Math.sin(Math.toRadians(rotation));
+ }
+ }
+ GlStateManager.translate(x, y, 0);
+ if (!NotEnoughUpdates.INSTANCE.config.dungeonMap.dmOrientCheck) {
+ GlStateManager.rotate(-rotation + 180, 0, 0, 1);
+ }
+
+ GlStateManager.pushMatrix();
+ GlStateManager.scale(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmIconScale,
+ NotEnoughUpdates.INSTANCE.config.dungeonMap.dmIconScale, 1
+ );
+ Utils.drawTexturedRect(-5, -5, 10, 10, GL11.GL_NEAREST);
+ GlStateManager.popMatrix();
+
+ if (!NotEnoughUpdates.INSTANCE.config.dungeonMap.dmOrientCheck) {
+ GlStateManager.rotate(rotation - 180, 0, 0, 1);
+ }
+ GlStateManager.translate(-x, -y, 0);
+ }
+ }
+ }
+
+ public void render(int roomSize, int connectorSize) {
+ ResourceLocation roomTex = null;
+ if (colour.getRed() == 114 && colour.getGreen() == 67 && colour.getBlue() == 27) {
+ roomTex = ROOM_BROWN;
+ } else if (colour.getRed() == 65 && colour.getGreen() == 65 && colour.getBlue() == 65) {
+ roomTex = ROOM_GRAY;
+ } else if (colour.getRed() == 0 && colour.getGreen() == 124 && colour.getBlue() == 0) {
+ roomTex = ROOM_GREEN;
+ } else if (colour.getRed() == 242 && colour.getGreen() == 127 && colour.getBlue() == 165) {
+ roomTex = ROOM_PINK;
+ } else if (colour.getRed() == 178 && colour.getGreen() == 76 && colour.getBlue() == 216) {
+ roomTex = ROOM_PURPLE;
+ } else if (colour.getRed() == 255 && colour.getGreen() == 0 && colour.getBlue() == 0) {
+ roomTex = ROOM_RED;
+ } else if (colour.getRed() == 229 && colour.getGreen() == 229 && colour.getBlue() == 51) {
+ roomTex = ROOM_YELLOW;
+ } else if (colour.getRed() == 216 && colour.getGreen() == 127 && colour.getBlue() == 51) {
+ roomTex = ROOM_ORANGE;
+ }
+
+ if (roomTex != null) {
+ Minecraft.getMinecraft().getTextureManager().bindTexture(roomTex);
+ GlStateManager.color(1, 1, 1, 1);
+ Utils.drawTexturedRect(0, 0, roomSize, roomSize, GL11.GL_LINEAR);
+ } else {
+ Gui.drawRect(0, 0, roomSize, roomSize, colour.getRGB());
+ }
+
+ if (fillCorner) {
+ GlStateManager.color(1, 1, 1, 1);
+ Minecraft.getMinecraft().getTextureManager().bindTexture(CORNER_BROWN);
+ Utils.drawTexturedRect(roomSize, roomSize, connectorSize, connectorSize, GL11.GL_NEAREST);
+ }
+
+ for (int k = 0; k < 2; k++) {
+ RoomConnection connection = down;
+ if (k == 1) connection = right;
+
+ if (connection.type == RoomConnectionType.NONE || connection.type == RoomConnectionType.WALL) continue;
+
+ ResourceLocation corridorTex = null;
+ if (connection.colour.getRed() == 114 && connection.colour.getGreen() == 67 &&
+ connection.colour.getBlue() == 27) {
+ corridorTex = connection.type == RoomConnectionType.CORRIDOR ? CORRIDOR_BROWN : DIVIDER_BROWN;
+ } else if (connection.colour.getRed() == 65 && connection.colour.getGreen() == 65 &&
+ connection.colour.getBlue() == 65) {
+ corridorTex = CORRIDOR_GRAY;
+ } else if (connection.colour.getRed() == 0 && connection.colour.getGreen() == 124 &&
+ connection.colour.getBlue() == 0) {
+ corridorTex = CORRIDOR_GREEN;
+ } else if (connection.colour.getRed() == 242 && connection.colour.getGreen() == 127 &&
+ connection.colour.getBlue() == 165) {
+ corridorTex = CORRIDOR_PINK;
+ } else if (connection.colour.getRed() == 178 && connection.colour.getGreen() == 76 &&
+ connection.colour.getBlue() == 216) {
+ corridorTex = CORRIDOR_PURPLE;
+ } else if (connection.colour.getRed() == 255 && connection.colour.getGreen() == 0 &&
+ connection.colour.getBlue() == 0) {
+ corridorTex = CORRIDOR_RED;
+ } else if (connection.colour.getRed() == 229 && connection.colour.getGreen() == 229 &&
+ connection.colour.getBlue() == 51) {
+ corridorTex = CORRIDOR_YELLOW;
+ } else if (connection.colour.getRed() == 216 && connection.colour.getGreen() == 127 &&
+ connection.colour.getBlue() == 51) {
+ corridorTex = CORRIDOR_ORANGE;
+ }
+
+ if (corridorTex == null) {
+ int xOffset = 0;
+ int yOffset = 0;
+ int width = 0;
+ int height = 0;
+
+ if (connection == right) {
+ xOffset = roomSize;
+ width = connectorSize;
+ height = roomSize;
+
+ if (connection.type == RoomConnectionType.CORRIDOR) {
+ height = 8;
+ yOffset += 4;
+ }
+ } else if (connection == down) {
+ yOffset = roomSize;
+ width = roomSize;
+ height = connectorSize;
+
+ if (connection.type == RoomConnectionType.CORRIDOR) {
+ width = 8;
+ xOffset += 4;
+ }
+ }
+
+ Gui.drawRect(xOffset, yOffset, xOffset + width, yOffset + height, connection.colour.getRGB());
+ } else {
+ GlStateManager.color(1, 1, 1, 1);
+ Minecraft.getMinecraft().getTextureManager().bindTexture(corridorTex);
+ GlStateManager.pushMatrix();
+ if (connection == right) {
+ GlStateManager.translate(roomSize / 2f, roomSize / 2f, 0);
+ GlStateManager.rotate(-90, 0, 0, 1);
+ GlStateManager.translate(-roomSize / 2f, -roomSize / 2f, 0);
+ }
+ Utils.drawTexturedRect(0, roomSize, roomSize, connectorSize, GL11.GL_NEAREST);
+ GlStateManager.popMatrix();
+ }
+ }
+ }
+ }
+
+ private static final ResourceLocation mapIcons = new ResourceLocation("textures/map/map_icons.png");
+
+ public static Framebuffer mapFramebuffer1 = null;
+ public static Framebuffer mapFramebuffer2 = null;
+ public static Matrix4f projectionMatrix = null;
+ public static Shader mapShader = null;
+
+ private static Framebuffer checkFramebufferSizes(Framebuffer framebuffer, int width, int height) {
+ if (framebuffer == null || framebuffer.framebufferWidth != width || framebuffer.framebufferHeight != height) {
+ if (framebuffer == null) {
+ framebuffer = new Framebuffer(width, height, true);
+ } else {
+ framebuffer.createBindFramebuffer(width, height);
+ }
+ framebuffer.setFramebufferFilter(GL11.GL_NEAREST);
+ }
+ return framebuffer;
+ }
+
+ private static void upload(Shader shader, int width, int height, int scale, float radiusSq) {
+ if (shader == null) return;
+ shader.getShaderManager().getShaderUniformOrDefault("ProjMat").set(projectionMatrix);
+ shader.getShaderManager().getShaderUniformOrDefault("InSize").set(width * scale, height * scale);
+ shader.getShaderManager().getShaderUniformOrDefault("OutSize").set(width, height);
+ shader.getShaderManager().getShaderUniformOrDefault("ScreenSize").set((float) width, (float) height);
+ shader.getShaderManager().getShaderUniformOrDefault("radiusSq").set(radiusSq);
+ }
+
+ public int getRenderRoomSize() {
+ double roomSizeOption = NotEnoughUpdates.INSTANCE.config.dungeonMap.dmRoomSize;
+ if (roomSizeOption <= 0) return 12;
+ return 12 + (int) Math.round(roomSizeOption * 4);
+ }
+
+ public int getRenderConnSize() {
+ int roomSizeOption = Math.round(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmRoomSize);
+ if (roomSizeOption <= 0) return 3;
+ return 3 + roomSizeOption;
+ }
+
+ private final HashMap<Integer, Float> borderRadiusCache = new HashMap<>();
+
+ public float getBorderRadius() {
+ int borderSizeOption = Math.round(NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBorderSize);
+ String sizeId = borderSizeOption == 0 ? "small" : borderSizeOption == 2 ? "large" : "medium";
+
+ int style = NotEnoughUpdates.INSTANCE.config.dungeonMap.dmBorderStyle;
+ if (borderRadiusCache.containsKey(style)) {
+ return borderRadiusCache.get(style);
+ }
+
+ try (
+ BufferedReader reader = new BufferedReader(new InputStreamReader(Minecraft
+ .getMinecraft()
+ .getResourceManager()
+ .getResource(
+ new ResourceLocation("notenoughupdates:dungeon_map/borders/" + sizeId + "/" + style + ".json"))
+ .getInputStream(), StandardCharsets.UTF_8))
+ ) {
+ JsonObject json = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(reader, JsonObject.class);
+ float radiusSq = json.get("radiusSq").getAsFloat();
+
+ borderRadiusCache.put(style, radiusSq);
+ return radiusSq;
+ } catch (Exception ignored) {
+ }
+
+ borderRadiusCache.put(style, 1f);
+ return 1f;
+ }
+
+ public void render(int centerX, int centerY) {
+ boolean useFb = NotEnoughUpdates.INSTANCE.config.dungeonMap.dmCompat <= 1 && OpenGlHelper.isFramebufferEnabled();
+ boolean useShd = NotEnoughUpdates.INSTANCE.config.dungeonMap.dmCompat <= 0 && OpenGlHelper.areShadersSupported();
/*if((useFb && !OpenGlHelper.isFramebufferEnabled()) || (useShd && !OpenGlHelper.areShadersSupported())) {
Utils.drawStringCentered(EnumChatFormatting.RED+"NEU Dungeon Map requires framebuffers & shaders",
@@ -404,203 +444,221 @@ public class Dunge