aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/EventListener.java19
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java11
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/utils/MapUtils.java44
3 files changed, 67 insertions, 7 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java b/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java
index d80a474d..8512e902 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java
@@ -1,10 +1,17 @@
package kr.syeyoung.dungeonsguide;
import kr.syeyoung.dungeonsguide.dungeon.DungeonContext;
+import kr.syeyoung.dungeonsguide.utils.MapUtils;
import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiScreen;
+import net.minecraft.client.renderer.texture.DynamicTexture;
+import net.minecraft.util.ResourceLocation;
+import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
+import java.util.Map;
+
public class EventListener {
private int timerTick = 0;
@SubscribeEvent
@@ -18,6 +25,7 @@ public class EventListener {
skyblockStatus.updateStatus();
if (!skyblockStatus.isOnDungeon()) {
skyblockStatus.setContext(null);
+ MapUtils.clearMap();
return;
}
if (isOnDungeon) skyblockStatus.getContext().tick();
@@ -25,4 +33,15 @@ public class EventListener {
}
}
}
+
+ DynamicTexture dynamicTexture = new DynamicTexture(128, 128);
+ ResourceLocation location = Minecraft.getMinecraft().renderEngine.getDynamicTextureLocation("dungeons/map/", dynamicTexture);
+ @SubscribeEvent
+ public void onRender(RenderGameOverlayEvent.Post postRender) {
+ int[] textureData = dynamicTexture.getTextureData();
+ MapUtils.getImage().getRGB(0,0,128,128, textureData, 0, 128);
+ dynamicTexture.updateDynamicTexture();
+ Minecraft.getMinecraft().getTextureManager().bindTexture(location);
+ GuiScreen.drawModalRectWithCustomSizedTexture(0,0, 0, 0, 128, 128, 128, 128);
+ }
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java
index 36e538f6..5f4f06db 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java
@@ -46,7 +46,7 @@ public class MapProcessor {
// determine the gap
{
Point midStartRoom = new Point(startroom.x + unitRoomDimension.width / 2, startroom.y +unitRoomDimension.height / 2);
- final int halfWidth = unitRoomDimension.width / 2 + 4;
+ final int halfWidth = unitRoomDimension.width / 2 + 2;
Vector2d dir = null;
for (Vector2d v:directions) {
byte color = MapUtils.getMapColorAt(mapData, (int)(v.x * halfWidth +midStartRoom.x), (int)(v.y *halfWidth +midStartRoom.y));
@@ -67,7 +67,7 @@ public class MapProcessor {
if (dir.y > 0) basePoint.y += unitRoomDimension.height;
if (dir.y < 0) basePoint.y += -1;
int gap = MapUtils.getLengthOfColorExtending(mapData, (byte) 0, basePoint, dir);
- Point pt = MapUtils.findFirstColorWithInNegate(mapData, (byte)0, new Rectangle(basePoint.x, basePoint.y, (int)Math.abs(dir.y) * 128, (int)Math.abs(dir.x) *128));
+ Point pt = MapUtils.findFirstColorWithInNegate(mapData, (byte)0, new Rectangle(basePoint.x, basePoint.y, (int)Math.abs(dir.y) * unitRoomDimension.width + 1, (int)Math.abs(dir.x) * unitRoomDimension.height + 1));
if (pt == null) {
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("BUGGED MAP, can't find door"));
bugged = true;
@@ -80,8 +80,8 @@ public class MapProcessor {
{
int x = startroom.x;
int y = startroom.y;
- while (x > unitRoomDimension.width + doorDimension.height) x -= unitRoomDimension.width + doorDimension.height;
- while (y > unitRoomDimension.height + doorDimension.height) y -= unitRoomDimension.height + doorDimension.height;
+ while (x >= unitRoomDimension.width + doorDimension.height) x -= unitRoomDimension.width + doorDimension.height;
+ while (y >= unitRoomDimension.height + doorDimension.height) y -= unitRoomDimension.height + doorDimension.height;
topLeftMapPoint = new Point(x, y);
}
@@ -101,7 +101,8 @@ public class MapProcessor {
mapData = lastMapData;
} else {
MapData mapData1 = ((ItemMap)stack.getItem()).getMapData(stack, context.getWorld());
- mapData = mapData1.colors;
+ if (mapData1 == null) mapData = lastMapData;
+ else mapData = mapData1.colors;
}
if (lastMapData == null && mapData != null) buildMap(mapData);
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/utils/MapUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/utils/MapUtils.java
index a0364f62..78c605d4 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/utils/MapUtils.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/utils/MapUtils.java
@@ -5,13 +5,44 @@ import org.w3c.dom.css.Rect;
import javax.vecmath.Vector2d;
import java.awt.*;
+import java.awt.image.BufferedImage;
public class MapUtils {
+
+ private static Color[] colorMasks = new Color[128 * 128];
+ 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] = new Color(255, 255, 255, 50);
+ }
+
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;
@@ -33,7 +64,10 @@ public class MapUtils {
public static Point findFirstColorWithIn(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) return new Point(x,y);
+ if (getMapColorAt(colors, x ,y) == color) {
+ record(colors, x, y, new Color(255, 0, 0, 40));
+ return new Point(x,y);
+ }
}
}
return null;
@@ -42,7 +76,10 @@ public class MapUtils {
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) return new Point(x,y);
+ if (getMapColorAt(colors, x ,y) != color) {
+ record(colors, x, y, new Color(255, 0, 0, 40));
+ return new Point(x,y);
+ }
}
}
return null;
@@ -50,12 +87,14 @@ public class MapUtils {
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;
@@ -65,6 +104,7 @@ public class MapUtils {
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;