diff options
| author | syeyoung <42869671+cyoung06@users.noreply.github.com> | 2020-11-23 11:39:30 +0900 |
|---|---|---|
| committer | syeyoung <42869671+cyoung06@users.noreply.github.com> | 2020-11-23 11:39:30 +0900 |
| commit | 17b3b9ce29495b554d38c1de4af38904be0fcc23 (patch) | |
| tree | 117e3c2a4d2ab1f2a3a770527a22b533f647a45d /src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder | |
| parent | 46a86f18ebd62a3771ca4fcb7d1cf17f69b80c73 (diff) | |
| download | Skyblock-Dungeons-Guide-17b3b9ce29495b554d38c1de4af38904be0fcc23.tar.gz Skyblock-Dungeons-Guide-17b3b9ce29495b554d38c1de4af38904be0fcc23.tar.bz2 Skyblock-Dungeons-Guide-17b3b9ce29495b554d38c1de4af38904be0fcc23.zip | |
room data!
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder')
3 files changed, 128 insertions, 0 deletions
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<Point> unitPoints; + private final short shape; + private final byte color; + + private final BlockPos min; + + private final DungeonContext context; + + private final List<DungeonDoor> doors = new ArrayList<DungeonDoor>(); + + private DungeonRoomInfo dungeonRoomInfo; + + public DungeonRoom(List<Point> 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<Vector2d> directions = Sets.newHashSet(new Vector2d(0,16), new Vector2d(0, -16), new Vector2d(16, 0), new Vector2d(-16 , 0)); + + private void buildDoors() { + Set<BlockPos> positions = new HashSet<BlockPos>(); + 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<DungeonRoomInfo> registered = new ArrayList<DungeonRoomInfo>(); + private static Map<Short, List<DungeonRoomInfo>> shapeMap = new HashMap<Short, List<DungeonRoomInfo>>(); + private static Map<UUID, DungeonRoomInfo> uuidMap = new HashMap<UUID, DungeonRoomInfo>(); + + 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<DungeonRoomInfo> roomInfos = shapeMap.get(dungeonRoomInfo.getShape()); + if (roomInfos == null) roomInfos = new ArrayList<DungeonRoomInfo>(); + roomInfos.add(dungeonRoomInfo); + shapeMap.put(dungeonRoomInfo.getShape(), roomInfos); + } + + + public static List<DungeonRoomInfo> getByShape(Short shape) { + List<DungeonRoomInfo> dungeonRoomInfos = shapeMap.get(shape); + return dungeonRoomInfos == null ? Collections.<DungeonRoomInfo>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(); + } +} |
