From 17b3b9ce29495b554d38c1de4af38904be0fcc23 Mon Sep 17 00:00:00 2001 From: syeyoung <42869671+cyoung06@users.noreply.github.com> Date: Mon, 23 Nov 2020 11:39:30 +0900 Subject: room data! --- .../kr/syeyoung/dungeonsguide/EventListener.java | 7 ++- .../dungeonsguide/dungeon/DungeonContext.java | 8 +-- .../dungeonsguide/dungeon/MapProcessor.java | 3 +- .../dungeonsguide/dungeon/data/DungeonDoor.java | 37 ------------ .../dungeonsguide/dungeon/data/DungeonRoom.java | 53 ----------------- .../dungeon/data/DungeonRoomInfo.java | 21 +++++++ .../dungeon/doorfinder/DungeonDoor.java | 37 ++++++++++++ .../dungeon/roomfinder/DungeonRoom.java | 69 ++++++++++++++++++++++ .../roomfinder/DungeonRoomInfoRegistry.java | 41 +++++++++++++ .../dungeon/roomfinder/RoomMatcher.java | 18 ++++++ .../syeyoung/dungeonsguide/utils/RenderUtils.java | 4 +- 11 files changed, 193 insertions(+), 105 deletions(-) delete mode 100644 src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonDoor.java delete mode 100644 src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoom.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoomInfo.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/dungeon/doorfinder/DungeonDoor.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java create mode 100644 src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/RoomMatcher.java (limited to 'src/main/java/kr/syeyoung') diff --git a/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java b/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java index 42705f78..9bdd2d41 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java @@ -1,8 +1,8 @@ package kr.syeyoung.dungeonsguide; import kr.syeyoung.dungeonsguide.dungeon.DungeonContext; -import kr.syeyoung.dungeonsguide.dungeon.data.DungeonDoor; -import kr.syeyoung.dungeonsguide.dungeon.data.DungeonRoom; +import kr.syeyoung.dungeonsguide.dungeon.doorfinder.DungeonDoor; +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; import kr.syeyoung.dungeonsguide.utils.MapUtils; import kr.syeyoung.dungeonsguide.utils.RenderUtils; import net.minecraft.client.Minecraft; @@ -18,7 +18,6 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import java.awt.*; -import java.util.Map; public class EventListener { private int timerTick = 0; @@ -68,6 +67,8 @@ public class EventListener { fontRenderer.drawString("Where are you?!", 5, 128, 0xFFFFFF); } else { fontRenderer.drawString("you're in the room... "+dungeonRoom.getColor()+" / "+dungeonRoom.getShape(), 5, 128, 0xFFFFFF); + fontRenderer.drawString("room uuid: "+dungeonRoom.getDungeonRoomInfo().getUuid() + (dungeonRoom.getDungeonRoomInfo().isRegistered() ?"":" (not registered)"), 5, 148, 0xFFFFFF); + fontRenderer.drawString("room name: "+dungeonRoom.getDungeonRoomInfo().getName(), 5, 148, 0xFFFFFF); } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java index 543cca6f..30250107 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java @@ -1,16 +1,10 @@ package kr.syeyoung.dungeonsguide.dungeon; -import kr.syeyoung.dungeonsguide.dungeon.data.DungeonRoom; +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; import lombok.Getter; import lombok.Setter; -import net.minecraft.block.BlockPackedIce; -import net.minecraft.client.Minecraft; -import net.minecraft.init.Items; -import net.minecraft.item.ItemMap; -import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; import net.minecraft.world.World; -import net.minecraft.world.storage.MapData; import java.awt.*; import java.util.ArrayList; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java index 7cfbdfba..490af242 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java @@ -1,9 +1,8 @@ package kr.syeyoung.dungeonsguide.dungeon; import com.google.common.collect.Sets; -import jdk.nashorn.internal.ir.Block; import kr.syeyoung.dungeonsguide.DungeonsGuide; -import kr.syeyoung.dungeonsguide.dungeon.data.DungeonRoom; +import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom; import kr.syeyoung.dungeonsguide.dungeon.doorfinder.DoorFinderRegistry; import kr.syeyoung.dungeonsguide.dungeon.doorfinder.StartDoorFinder; import kr.syeyoung.dungeonsguide.utils.MapUtils; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonDoor.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonDoor.java deleted file mode 100644 index 4dea9cdb..00000000 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonDoor.java +++ /dev/null @@ -1,37 +0,0 @@ -package kr.syeyoung.dungeonsguide.dungeon.data; - -import com.google.common.collect.Sets; -import lombok.Getter; -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.util.BlockPos; -import net.minecraft.world.World; - -import java.util.Set; - -@Getter -public class DungeonDoor { - private final World w; - private final BlockPos position; - private boolean exist = true; - private boolean isZDir; - - private static final Set legalBlocks = Sets.newHashSet(Blocks.coal_block, Blocks.barrier, Blocks.monster_egg, Blocks.air, Blocks.hardened_clay); - - - public DungeonDoor(World world, BlockPos pos) { - this.w = world; - this.position = pos; - for (int x = -1; x<=1; x++) - for (int y = -1; y<=1; y++) - for (int z = -1; z<=1; z++) { - BlockPos pos2 = pos.add(x,y,z); - Block block = world.getChunkFromBlockCoords(pos2).getBlock(pos2); - if (!legalBlocks.contains(block)) exist = false; - } - if (exist) { - BlockPos ZCheck = pos.add(0,0,2); - isZDir = world.getChunkFromBlockCoords(ZCheck).getBlock(ZCheck) == Blocks.air; - } - } -} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoom.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoom.java deleted file mode 100644 index 5d79b119..00000000 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoom.java +++ /dev/null @@ -1,53 +0,0 @@ -package kr.syeyoung.dungeonsguide.dungeon.data; - -import com.google.common.collect.Sets; -import kr.syeyoung.dungeonsguide.dungeon.DungeonContext; -import lombok.Getter; -import net.minecraft.util.BlockPos; - -import javax.vecmath.Vector2d; -import java.awt.*; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -@Getter -public class DungeonRoom { - private final List unitPoints; - private final short shape; - private final byte color; - - private final BlockPos min; - - private final DungeonContext context; - - private final List doors = new ArrayList(); - - public DungeonRoom(List points, short shape, byte color, BlockPos min, DungeonContext context) { - this.unitPoints = points; - this.shape = shape; - this.color = color; - this.min = min; - this.context = context; - buildDoors(); - } - - private static final Set directions = Sets.newHashSet(new Vector2d(0,16), new Vector2d(0, -16), new Vector2d(16, 0), new Vector2d(-16 , 0)); - - private void buildDoors() { - Set positions = new HashSet(); - for (Point p:unitPoints) { - BlockPos pos = context.getMapProcessor().roomPointToWorldPoint(p).add(16,0,16); - for (Vector2d vector2d : directions){ - BlockPos doorLoc = pos.add(vector2d.x, 0, vector2d.y); - if (positions.contains(doorLoc)) positions.remove(doorLoc); - else positions.add(doorLoc); - } - } - - for (BlockPos door : positions) { - doors.add(new DungeonDoor(context.getWorld(), door)); - } - } -} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoomInfo.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoomInfo.java new file mode 100644 index 00000000..c3d0a65d --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/data/DungeonRoomInfo.java @@ -0,0 +1,21 @@ +package kr.syeyoung.dungeonsguide.dungeon.data; + +import lombok.Getter; +import lombok.Setter; + +import java.util.UUID; + +@Getter +@Setter +public class DungeonRoomInfo { + + private transient boolean registered; + + private short shape; + private byte color; + + private int[][] blocks; + + private UUID uuid; + private String name; +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/doorfinder/DungeonDoor.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/doorfinder/DungeonDoor.java new file mode 100644 index 00000000..2855b05f --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/doorfinder/DungeonDoor.java @@ -0,0 +1,37 @@ +package kr.syeyoung.dungeonsguide.dungeon.doorfinder; + +import com.google.common.collect.Sets; +import lombok.Getter; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.util.BlockPos; +import net.minecraft.world.World; + +import java.util.Set; + +@Getter +public class DungeonDoor { + private final World w; + private final BlockPos position; + private boolean exist = true; + private boolean isZDir; + + private static final Set legalBlocks = Sets.newHashSet(Blocks.coal_block, Blocks.barrier, Blocks.monster_egg, Blocks.air, Blocks.hardened_clay); + + + public DungeonDoor(World world, BlockPos pos) { + this.w = world; + this.position = pos; + for (int x = -1; x<=1; x++) + for (int y = -1; y<=1; y++) + for (int z = -1; z<=1; z++) { + BlockPos pos2 = pos.add(x,y,z); + Block block = world.getChunkFromBlockCoords(pos2).getBlock(pos2); + if (!legalBlocks.contains(block)) exist = false; + } + if (exist) { + BlockPos ZCheck = pos.add(0,0,2); + isZDir = world.getChunkFromBlockCoords(ZCheck).getBlock(ZCheck) == Blocks.air; + } + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java new file mode 100644 index 00000000..91761c7c --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java @@ -0,0 +1,69 @@ +package kr.syeyoung.dungeonsguide.dungeon.roomfinder; + +import com.google.common.collect.Sets; +import kr.syeyoung.dungeonsguide.dungeon.DungeonContext; +import kr.syeyoung.dungeonsguide.dungeon.data.DungeonRoomInfo; +import kr.syeyoung.dungeonsguide.dungeon.doorfinder.DungeonDoor; +import lombok.Getter; +import net.minecraft.util.BlockPos; + +import javax.vecmath.Vector2d; +import java.awt.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@Getter +public class DungeonRoom { + private final List unitPoints; + private final short shape; + private final byte color; + + private final BlockPos min; + + private final DungeonContext context; + + private final List doors = new ArrayList(); + + private DungeonRoomInfo dungeonRoomInfo; + + public DungeonRoom(List points, short shape, byte color, BlockPos min, DungeonContext context) { + this.unitPoints = points; + this.shape = shape; + this.color = color; + this.min = min; + this.context = context; + buildDoors(); + buildRoom(); + } + + private static final Set directions = Sets.newHashSet(new Vector2d(0,16), new Vector2d(0, -16), new Vector2d(16, 0), new Vector2d(-16 , 0)); + + private void buildDoors() { + Set positions = new HashSet(); + for (Point p:unitPoints) { + BlockPos pos = context.getMapProcessor().roomPointToWorldPoint(p).add(16,0,16); + for (Vector2d vector2d : directions){ + BlockPos doorLoc = pos.add(vector2d.x, 0, vector2d.y); + if (positions.contains(doorLoc)) positions.remove(doorLoc); + else positions.add(doorLoc); + } + } + + for (BlockPos door : positions) { + doors.add(new DungeonDoor(context.getWorld(), door)); + } + } + + private RoomMatcher roomMatcher = null; + private void buildRoom() { + if (roomMatcher == null) + roomMatcher = new RoomMatcher(this); + DungeonRoomInfo dungeonRoomInfo = roomMatcher.match(); + if (dungeonRoomInfo == null) + dungeonRoomInfo = roomMatcher.createNew(); + + this.dungeonRoomInfo = dungeonRoomInfo; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java new file mode 100644 index 00000000..a382273c --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java @@ -0,0 +1,41 @@ +package kr.syeyoung.dungeonsguide.dungeon.roomfinder; + +import kr.syeyoung.dungeonsguide.dungeon.data.DungeonRoomInfo; + +import java.util.*; + +public class DungeonRoomInfoRegistry { + private static List registered = new ArrayList(); + private static Map> shapeMap = new HashMap>(); + private static Map uuidMap = new HashMap(); + + public static void register(DungeonRoomInfo dungeonRoomInfo) { + if (dungeonRoomInfo == null) throw new NullPointerException("what the fak parameter is noll?"); + dungeonRoomInfo.setRegistered(true); + registered.add(dungeonRoomInfo); + uuidMap.put(dungeonRoomInfo.getUuid(), dungeonRoomInfo); + List roomInfos = shapeMap.get(dungeonRoomInfo.getShape()); + if (roomInfos == null) roomInfos = new ArrayList(); + roomInfos.add(dungeonRoomInfo); + shapeMap.put(dungeonRoomInfo.getShape(), roomInfos); + } + + + public static List getByShape(Short shape) { + List dungeonRoomInfos = shapeMap.get(shape); + return dungeonRoomInfos == null ? Collections.emptyList() : dungeonRoomInfos; + } + + public static DungeonRoomInfo getByUUID(UUID uid) { + return uuidMap.get(uid); + } + + public static void unregister(DungeonRoomInfo dungeonRoomInfo) { + if (!dungeonRoomInfo.isRegistered()) throw new IllegalStateException("what tha fak? that is not registered one"); + if (!uuidMap.containsKey(dungeonRoomInfo.getUuid())) throw new IllegalStateException("what tha fak? that is not registered one, but you desperately wanted to trick this program"); + dungeonRoomInfo.setRegistered(false); + registered.remove(dungeonRoomInfo); + shapeMap.get(dungeonRoomInfo.getShape()).remove(dungeonRoomInfo); + uuidMap.remove(dungeonRoomInfo.getUuid()); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/RoomMatcher.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/RoomMatcher.java new file mode 100644 index 00000000..197348bf --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/RoomMatcher.java @@ -0,0 +1,18 @@ +package kr.syeyoung.dungeonsguide.dungeon.roomfinder; + +import kr.syeyoung.dungeonsguide.dungeon.data.DungeonRoomInfo; + +public class RoomMatcher { + private DungeonRoom dungeonRoom; + public RoomMatcher(DungeonRoom dungeonRoom) { + this.dungeonRoom = dungeonRoom; + } + + public DungeonRoomInfo match() { + return null; + } + + public DungeonRoomInfo createNew() { + return new DungeonRoomInfo(); + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java index 269629e2..659e25ca 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/utils/RenderUtils.java @@ -1,10 +1,8 @@ package kr.syeyoung.dungeonsguide.utils; -import kr.syeyoung.dungeonsguide.dungeon.data.DungeonDoor; +import kr.syeyoung.dungeonsguide.dungeon.doorfinder.DungeonDoor; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.entity.Entity; import net.minecraft.util.BlockPos; import net.minecraft.util.Vec3; -- cgit