diff options
author | syeyoung <42869671+cyoung06@users.noreply.github.com> | 2020-11-22 14:38:55 +0900 |
---|---|---|
committer | syeyoung <42869671+cyoung06@users.noreply.github.com> | 2020-11-22 14:38:55 +0900 |
commit | a2d37ac4c47e4612178cbbfa2ba0c3affdff88e0 (patch) | |
tree | 71bbcbed9c03cfbd505e9572bc320ee7aa9daa52 | |
parent | 57fa3552e1ebbd39940343a4db12968d5f9931b9 (diff) | |
download | Skyblock-Dungeons-Guide-a2d37ac4c47e4612178cbbfa2ba0c3affdff88e0.tar.gz Skyblock-Dungeons-Guide-a2d37ac4c47e4612178cbbfa2ba0c3affdff88e0.tar.bz2 Skyblock-Dungeons-Guide-a2d37ac4c47e4612178cbbfa2ba0c3affdff88e0.zip |
Map Utils and Gap and startroom determination
-rw-r--r-- | options.txt | 6 | ||||
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java | 29 | ||||
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java | 112 | ||||
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/utils/MapUtils.java | 73 |
4 files changed, 192 insertions, 28 deletions
diff --git a/options.txt b/options.txt index 3435e451..25252add 100644 --- a/options.txt +++ b/options.txt @@ -4,7 +4,7 @@ fov:1.0 gamma:0.0 saturation:0.0 renderDistance:12 -guiScale:0 +guiScale:2 particles:0 bobView:true anaglyph3d:false @@ -24,7 +24,7 @@ chatLinks:true chatLinksPrompt:true chatOpacity:1.0 snooperEnabled:true -fullscreen:false +fullscreen:true enableVsync:true useVbo:false hideServerAddress:false @@ -66,7 +66,7 @@ key_key.right:32 key_key.jump:57 key_key.sneak:42 key_key.sprint:58 -key_key.drop:16 +key_key.drop:0 key_key.inventory:18 key_key.chat:20 key_key.playerlist:15 diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java index 104225f3..e08ee94a 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java @@ -11,38 +11,17 @@ import net.minecraft.world.storage.MapData; public class DungeonContext { @Getter private World world; - - private byte[] lastMapData; + @Getter + private MapProcessor mapProcessor; public DungeonContext(World world) { this.world = world; + mapProcessor = new MapProcessor(this); } public void tick() { - mapTick(); - } - - private void buildMap(byte[] mapData) { - + mapProcessor.tick(); } - private void processMap(byte[] mapData) { - } - - private void mapTick() { - ItemStack stack = Minecraft.getMinecraft().thePlayer.inventory.getStackInSlot(8); - byte[] mapData; - if (stack == null || !(stack.getItem() instanceof ItemMap)) { - mapData = lastMapData; - } else { - MapData mapData1 = ((ItemMap)stack.getItem()).getMapData(stack, world); - mapData = mapData1.colors; - } - - if (lastMapData == null && mapData != null) buildMap(mapData); - processMap(mapData); - - lastMapData = mapData; - } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java new file mode 100644 index 00000000..36e538f6 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java @@ -0,0 +1,112 @@ +package kr.syeyoung.dungeonsguide.dungeon; + +import com.google.common.collect.Sets; +import kr.syeyoung.dungeonsguide.utils.MapUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemMap; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.storage.MapData; + +import javax.vecmath.Vector2d; +import java.awt.*; +import java.util.Set; + +public class MapProcessor { + + private final DungeonContext context; + + private byte[] lastMapData; + + private Dimension unitRoomDimension; + private Dimension doorDimension; // width: width of door, height: gap between rooms + private Point topLeftMapPoint; + + private boolean bugged = false; + + public MapProcessor(DungeonContext context) { + this.context = context; + } + + private static final Set<Vector2d> directions = Sets.newHashSet(new Vector2d(0,1), new Vector2d(0, -1), new Vector2d(1, 0), new Vector2d(-1 , 0)); + + private void buildMap(final byte[] mapData) { + final Point startroom = MapUtils.findFirstColorWithIn(mapData, (byte) 30, new Rectangle(0,0,128,128)); + if (startroom == null){ + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("BUGGED MAP")); + bugged = true; + return; + } + // Determine room dimension + { + int width = MapUtils.getWidthOfColorAt(mapData, (byte) 30, startroom); + int height = MapUtils.getHeightOfColorAt(mapData, (byte) 30, startroom); + unitRoomDimension = new Dimension(width, height); + } + // determine the gap + { + Point midStartRoom = new Point(startroom.x + unitRoomDimension.width / 2, startroom.y +unitRoomDimension.height / 2); + final int halfWidth = unitRoomDimension.width / 2 + 4; + Vector2d dir = null; + for (Vector2d v:directions) { + byte color = MapUtils.getMapColorAt(mapData, (int)(v.x * halfWidth +midStartRoom.x), (int)(v.y *halfWidth +midStartRoom.y)); + if (color != 0) { + dir = v; + break; + } + } + + if (dir == null) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("BUGGED MAP, no connected door found")); + bugged = true; + return; + } + Point basePoint = new Point(startroom.x, startroom.y); + if (dir.x > 0) basePoint.x += unitRoomDimension.width; + if (dir.x < 0) basePoint.x += -1; + 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)); + if (pt == null) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("BUGGED MAP, can't find door")); + bugged = true; + return; + } + int doorWidth = MapUtils.getLengthOfColorExtending(mapData, MapUtils.getMapColorAt(mapData, pt.x, pt.y), pt, new Vector2d((int)Math.abs(dir.y), (int)Math.abs(dir.x))); + doorDimension = new Dimension(doorWidth, gap); + } + // Determine Top Left + { + 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; + topLeftMapPoint = new Point(x, y); + } + + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Found Green room:"+startroom)); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Dimension:"+unitRoomDimension)); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("top Left:"+topLeftMapPoint)); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("door dimension:"+doorDimension)); + } + private void processMap(byte[] mapData) { + + } + + public void tick() { + ItemStack stack = Minecraft.getMinecraft().thePlayer.inventory.getStackInSlot(8); + byte[] mapData; + if (stack == null || !(stack.getItem() instanceof ItemMap)) { + mapData = lastMapData; + } else { + MapData mapData1 = ((ItemMap)stack.getItem()).getMapData(stack, context.getWorld()); + mapData = mapData1.colors; + } + + if (lastMapData == null && mapData != null) buildMap(mapData); + processMap(mapData); + + lastMapData = mapData; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/utils/MapUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/utils/MapUtils.java new file mode 100644 index 00000000..a0364f62 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/utils/MapUtils.java @@ -0,0 +1,73 @@ +package kr.syeyoung.dungeonsguide.utils; + +import net.minecraft.block.material.MapColor; +import org.w3c.dom.css.Rect; + +import javax.vecmath.Vector2d; +import java.awt.*; + +public class MapUtils { + 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 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].func_151643_b(j & 3); + } + + return theColor; + } + + 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); + } + } + 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) 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++) { + 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++) { + 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); + if (getMapColorAt(colors, x,y) != color) return i; + } + return -1; + } + +} |