diff options
author | syeyoung <cyoung06@naver.com> | 2023-01-23 00:12:17 +0900 |
---|---|---|
committer | syeyoung <cyoung06@naver.com> | 2023-01-23 00:12:17 +0900 |
commit | 6f00f738c29dd296fe962c990b0221092d29fb53 (patch) | |
tree | d2f91965708cdbdbedd50efaac383f34344fe933 | |
parent | b0d7506511a58190f523ebcfb76a61e6186e1081 (diff) | |
download | Skyblock-Dungeons-Guide-6f00f738c29dd296fe962c990b0221092d29fb53.tar.gz Skyblock-Dungeons-Guide-6f00f738c29dd296fe962c990b0221092d29fb53.tar.bz2 Skyblock-Dungeons-Guide-6f00f738c29dd296fe962c990b0221092d29fb53.zip |
- taught dg about procrastination
=> Lazy dungeon building
=> Fixes #233
=> Fixes #264
Signed-off-by: syeyoung <cyoung06@naver.com>
37 files changed, 1319 insertions, 1075 deletions
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/SkyblockStatus.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/SkyblockStatus.java index dc48415f..e74b69da 100755 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/SkyblockStatus.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/SkyblockStatus.java @@ -41,6 +41,8 @@ import java.util.Set; public class SkyblockStatus { boolean wasOnHypixel = false; + public static String locationName; + @SubscribeEvent public void onTick(TickEvent.ClientTickEvent ev) { @@ -144,7 +146,7 @@ public class SkyblockStatus { } } if (sc.getJustTeam().startsWith(" §7⏣")) { - DungeonContext.setDungeonName(strippedLine.trim()); + locationName = strippedLine.trim(); } } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDgDebug.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDgDebug.java index 45eb7dd2..b6742c9c 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDgDebug.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/commands/CommandDgDebug.java @@ -24,23 +24,17 @@ import kr.syeyoung.dungeonsguide.dungeon.mechanics.*; import kr.syeyoung.dungeonsguide.dungeon.mechanics.dunegonmechanic.DungeonMechanic; import kr.syeyoung.dungeonsguide.launcher.Main; import kr.syeyoung.dungeonsguide.mod.DungeonsGuide; +import kr.syeyoung.dungeonsguide.mod.SkyblockStatus; import kr.syeyoung.dungeonsguide.mod.chat.ChatTransmitter; import kr.syeyoung.dungeonsguide.mod.config.guiconfig.NestedCategory; import kr.syeyoung.dungeonsguide.mod.dungeon.DungeonContext; -import kr.syeyoung.dungeonsguide.mod.dungeon.MapProcessor; -import kr.syeyoung.dungeonsguide.mod.dungeon.doorfinder.DungeonSpecificDataProvider; -import kr.syeyoung.dungeonsguide.mod.dungeon.doorfinder.DungeonSpecificDataProviderRegistry; import kr.syeyoung.dungeonsguide.mod.dungeon.events.DungeonEventHolder; -import kr.syeyoung.dungeonsguide.mod.dungeon.roomedit.EditingContext; -import kr.syeyoung.dungeonsguide.mod.dungeon.roomedit.gui.GuiDungeonRoomEdit; import kr.syeyoung.dungeonsguide.mod.dungeon.roomfinder.DungeonRoom; import kr.syeyoung.dungeonsguide.mod.dungeon.roomfinder.DungeonRoomInfoRegistry; import kr.syeyoung.dungeonsguide.mod.dungeon.roomprocessor.GeneralRoomProcessor; -import kr.syeyoung.dungeonsguide.mod.dungeon.roomprocessor.bossfight.BossfightProcessor; import kr.syeyoung.dungeonsguide.mod.events.impl.DungeonLeftEvent; import kr.syeyoung.dungeonsguide.mod.features.AbstractFeature; import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; -import kr.syeyoung.dungeonsguide.mod.features.impl.dungeon.FeatureDungeonMap; import kr.syeyoung.dungeonsguide.mod.guiv2.GuiScreenAdapter; import kr.syeyoung.dungeonsguide.mod.guiv2.view.TestView; import kr.syeyoung.dungeonsguide.mod.parallelUniverse.scoreboard.Score; @@ -51,30 +45,19 @@ import kr.syeyoung.dungeonsguide.mod.party.PartyContext; import kr.syeyoung.dungeonsguide.mod.party.PartyManager; import kr.syeyoung.dungeonsguide.mod.utils.AhUtils; import kr.syeyoung.dungeonsguide.mod.utils.MapUtils; -import kr.syeyoung.dungeonsguide.mod.utils.ShortUtils; -import kr.syeyoung.dungeonsguide.mod.utils.TabListUtil; import kr.syeyoung.dungeonsguide.mod.wsresource.StaticResourceCache; -import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.scoreboard.ScorePlayerTeam; -import net.minecraft.server.MinecraftServer; -import net.minecraft.util.BlockPos; import net.minecraft.util.ChatComponentText; import net.minecraft.util.Tuple; -import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; -import javax.vecmath.Vector2d; import java.awt.*; import java.io.*; import java.nio.file.Files; @@ -82,7 +65,6 @@ import java.security.*; import java.security.cert.CertificateException; import java.util.List; import java.util.*; -import java.util.regex.Pattern; public class CommandDgDebug extends CommandBase { @Override @@ -179,9 +161,9 @@ public class CommandDgDebug extends CommandBase { EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; if (thePlayer == null) return; if (context.getBossfightProcessor() != null) context.getBossfightProcessor().tick(); - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); GeneralRoomProcessor grp = (GeneralRoomProcessor) dungeonRoom.getRoomProcessor(); grp.pathfind("COMMAND", args[1], args[2], FeatureRegistry.SECRET_LINE_PROPERTIES_GLOBAL.getRouteProperties()); } catch (Throwable t) { @@ -283,7 +265,7 @@ public class CommandDgDebug extends CommandBase { } else if ("partyid".equals(arg)) { sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §fInternal Party id: " + Optional.ofNullable(PartyManager.INSTANCE.getPartyContext()).map(PartyContext::getPartyID).orElse(null))); } else if ("loc".equals(arg)) { - sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §fYou're in " + DungeonContext.getDungeonName())); + sender.addChatMessage(new ChatComponentText("§eDungeons Guide §7:: §fYou're in " + SkyblockStatus.locationName)); } else if ("saverun".equals(arg)) { try { File f = Main.getConfigDir(); @@ -300,7 +282,7 @@ public class CommandDgDebug extends CommandBase { DungeonEventHolder dungeonEventHolder = new DungeonEventHolder(); dungeonEventHolder.setDate(dungeonContext.getInit()); dungeonEventHolder.setPlayers(dungeonContext.getPlayers()); - dungeonEventHolder.setEventDataList(dungeonContext.getEvents()); + dungeonEventHolder.setEventDataList(dungeonContext.getRecorder().getEvents()); ObjectOutputStream oos = new ObjectOutputStream(Files.newOutputStream(runFile.toPath())); @@ -318,80 +300,80 @@ public class CommandDgDebug extends CommandBase { sender.addChatMessage(new ChatComponentText(a.getResourceID() + ": " + a.getValue() + ": " + a.isExists())); }); } else if ("createfakeroom".equals(arg)) {// load schematic - File f = new File(Main.getConfigDir(), "schematics/new roonm-b2df250c-4af2-4201-963c-0ee1cb6bd3de-5efb1f0c-c05f-4064-bde7-cad0874fdf39.schematic"); - NBTTagCompound compound; - try { - compound = CompressedStreamTools.readCompressed(new FileInputStream(f)); - } catch (IOException e) { - e.printStackTrace(); - return; - } - - byte[] blocks = compound.getByteArray("Blocks"); - byte[] meta = compound.getByteArray("Data"); - for (int x = 0; x < compound.getShort("Width"); x++) { - for (int y = 0; y < compound.getShort("Height"); y++) { - for (int z = 0; z < compound.getShort("Length"); z++) { - int index = x + (y * compound.getShort("Length") + z) * compound.getShort("Width"); - BlockPos pos = new BlockPos(x, y, z); - World w = MinecraftServer.getServer().getEntityWorld(); - w.setBlockState(pos, Block.getBlockById(blocks[index] & 0xFF).getStateFromMeta(meta[index] & 0xFF), 2); - } - } - } - - - DungeonSpecificDataProviderRegistry.doorFinders.put(Pattern.compile("TEST DG"), new DungeonSpecificDataProvider() { - @Override - public BlockPos findDoor(World w, String dungeonName) { - return new BlockPos(0, 0, 0); - } - - @Override - public Vector2d findDoorOffset(World w, String dungeonName) { - return null; - } - - @Override - public BossfightProcessor createBossfightProcessor(World w, String dungeonName) { - return null; - } - - @Override - public boolean isTrapSpawn(String dungeonName) { - return false; - } - - @Override - public double secretPercentage(String dungeonName) { - return 0; - } - - @Override - public int speedSecond(String dungeonName) { - return 0; - } - }); - DungeonContext.setDungeonName("TEST DG"); - DungeonContext fakeContext = new DungeonContext(Minecraft.getMinecraft().theWorld); - DungeonsGuide.getDungeonsGuide().getDungeonFacade().setContext(fakeContext); - DungeonsGuide.getDungeonsGuide().getSkyblockStatus().setForceIsOnDungeon(true); - MapProcessor mapProcessor = fakeContext.getMapProcessor(); - mapProcessor.setUnitRoomDimension(new Dimension(16, 16)); - mapProcessor.setBugged(false); - mapProcessor.setDoorDimensions(new Dimension(4, 4)); - mapProcessor.setTopLeftMapPoint(new Point(0, 0)); - fakeContext.setDungeonMin(new BlockPos(0, 70, 0)); - - DungeonRoom dungeonRoom = new DungeonRoom(Arrays.asList(new Point(0, 0)), ShortUtils.topLeftifyInt((short) 1), (byte) 63, new BlockPos(0, 70, 0), new BlockPos(31, 70, 31), fakeContext, Collections.emptySet()); - - fakeContext.getDungeonRoomList().add(dungeonRoom); - for (Point p : Arrays.asList(new Point(0, 0))) { - fakeContext.getRoomMapper().put(p, dungeonRoom); - } - - EditingContext.createEditingContext(dungeonRoom); - EditingContext.getEditingContext().openGui(new GuiDungeonRoomEdit(dungeonRoom)); +// File f = new File(Main.getConfigDir(), "schematics/new roonm-b2df250c-4af2-4201-963c-0ee1cb6bd3de-5efb1f0c-c05f-4064-bde7-cad0874fdf39.schematic"); +// NBTTagCompound compound; +// try { +// compound = CompressedStreamTools.readCompressed(new FileInputStream(f)); +// } catch (IOException e) { +// e.printStackTrace(); +// return; +// } +// +// byte[] blocks = compound.getByteArray("Blocks"); +// byte[] meta = compound.getByteArray("Data"); +// for (int x = 0; x < compound.getShort("Width"); x++) { +// for (int y = 0; y < compound.getShort("Height"); y++) { +// for (int z = 0; z < compound.getShort("Length"); z++) { +// int index = x + (y * compound.getShort("Length") + z) * compound.getShort("Width"); +// BlockPos pos = new BlockPos(x, y, z); +// World w = MinecraftServer.getServer().getEntityWorld(); +// w.setBlockState(pos, Block.getBlockById(blocks[index] & 0xFF).getStateFromMeta(meta[index] & 0xFF), 2); +// } +// } +// } +// +// +// DungeonSpecificDataProviderRegistry.doorFinders.put(Pattern.compile("TEST DG"), new DungeonSpecificDataProvider() { +// @Override +// public BlockPos findDoor(World w, String dungeonName) { +// return new BlockPos(0, 0, 0); +// } +// +// @Override +// public Vector2d findDoorOffset(World w, String dungeonName) { +// return null; +// } +// +// @Override +// public BossfightProcessor createBossfightProcessor(World w, String dungeonName) { +// return null; +// } +// +// @Override +// public boolean isTrapSpawn(String dungeonName) { +// return false; +// } +// +// @Override +// public double secretPercentage(String dungeonName) { +// return 0; +// } +// +// @Override +// public int speedSecond(String dungeonName) { +// return 0; +// } +// }); +// DungeonContext.setDungeonName("TEST DG"); +// DungeonContext fakeContext = new DungeonContext(Minecraft.getMinecraft().theWorld); +// DungeonsGuide.getDungeonsGuide().getDungeonFacade().setContext(fakeContext); +// DungeonsGuide.getDungeonsGuide().getSkyblockStatus().setForceIsOnDungeon(true); +// MapPlayerProcessor mapProcessor = fakeContext.getp(); +// mapProcessor.setUnitRoomDimension(new Dimension(16, 16)); +// mapProcessor.setBugged(false); +// mapProcessor.setDoorDimensions(new Dimension(4, 4)); +// mapProcessor.setTopLeftMapPoint(new Point(0, 0)); +// fakeContext.setDungeonMin(new BlockPos(0, 70, 0)); +// +// DungeonRoom dungeonRoom = new DungeonRoom(Arrays.asList(new Point(0, 0)), ShortUtils.topLeftifyInt((short) 1), (byte) 63, new BlockPos(0, 70, 0), new BlockPos(31, 70, 31), fakeContext, Collections.emptySet()); +// +// fakeContext.getDungeonRoomList().add(dungeonRoom); +// for (Point p : Arrays.asList(new Point(0, 0))) { +// fakeContext.getRoomMapper().put(p, dungeonRoom); +// } +// +// EditingContext.createEditingContext(dungeonRoom); +// EditingContext.getEditingContext().openGui(new GuiDungeonRoomEdit(dungeonRoom)); } else if ("closecontext".equals(arg)) { DungeonsGuide.getDungeonsGuide().getSkyblockStatus().setForceIsOnDungeon(false); diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/DiscordIntegrationManager.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/DiscordIntegrationManager.java index 601783cd..35684242 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/DiscordIntegrationManager.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/DiscordIntegrationManager.java @@ -199,7 +199,7 @@ public class DiscordIntegrationManager implements IPCListener { if (!skyblockStatus.isOnHypixel() || !FeatureRegistry.DISCORD_RICHPRESENCE.isEnabled() || (!skyblockStatus.isOnSkyblock() && FeatureRegistry.DISCORD_RICHPRESENCE.<Boolean>getParameter("disablenotskyblock").getValue())) { sendRichPresence(null); } else { - String name = DungeonContext.getDungeonName() == null ? "" : DungeonContext.getDungeonName(); + String name = SkyblockStatus.locationName == null ? "" : SkyblockStatus.locationName; if (!skyblockStatus.isOnSkyblock()) name ="Somewhere on Hypixel"; if (name.trim().equals("Your Island")) name = "Private Island"; diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/DungeonContext.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/DungeonContext.java index 8041f6ac..037eb442 100755 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/DungeonContext.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/DungeonContext.java @@ -22,17 +22,20 @@ package kr.syeyoung.dungeonsguide.mod.dungeon; import kr.syeyoung.dungeonsguide.mod.chat.ChatTransmitter; import kr.syeyoung.dungeonsguide.mod.dungeon.doorfinder.DungeonSpecificDataProvider; import kr.syeyoung.dungeonsguide.mod.dungeon.doorfinder.DungeonSpecificDataProviderRegistry; -import kr.syeyoung.dungeonsguide.mod.dungeon.events.DungeonEvent; -import kr.syeyoung.dungeonsguide.mod.dungeon.events.DungeonEventData; -import kr.syeyoung.dungeonsguide.mod.dungeon.events.impl.DungeonCryptBrokenEvent; +import kr.syeyoung.dungeonsguide.mod.dungeon.events.DungeonEventRecorder; import kr.syeyoung.dungeonsguide.mod.dungeon.events.impl.DungeonNodataEvent; import kr.syeyoung.dungeonsguide.mod.dungeon.events.impl.DungeonPuzzleFailureEvent; -import kr.syeyoung.dungeonsguide.mod.dungeon.events.impl.DungeonSecretCountChangeEvent; +import kr.syeyoung.dungeonsguide.mod.dungeon.map.DungeonMapConstantRetreiver; +import kr.syeyoung.dungeonsguide.mod.dungeon.map.DungeonMapLayout; +import kr.syeyoung.dungeonsguide.mod.dungeon.map.DungeonRoomScaffoldParser; +import kr.syeyoung.dungeonsguide.mod.dungeon.map.MapPlayerProcessor; import kr.syeyoung.dungeonsguide.mod.dungeon.roomfinder.DungeonRoom; import kr.syeyoung.dungeonsguide.mod.dungeon.roomprocessor.RoomProcessor; import kr.syeyoung.dungeonsguide.mod.dungeon.roomprocessor.bossfight.BossfightProcessor; import kr.syeyoung.dungeonsguide.mod.events.impl.BossroomEnterEvent; +import kr.syeyoung.dungeonsguide.mod.events.impl.MapUpdateEvent; import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; +import kr.syeyoung.dungeonsguide.mod.utils.MapUtils; import kr.syeyoung.dungeonsguide.mod.utils.TabListUtil; import kr.syeyoung.dungeonsguide.mod.utils.TextUtils; import lombok.Getter; @@ -45,72 +48,52 @@ import net.minecraft.world.World; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.common.MinecraftForge; +import javax.vecmath.Vector2d; import java.awt.*; import java.util.List; import java.util.*; public class DungeonContext { - /** - * This is static because its used in the constructor, - * it means we cannot set the name without having an object, - * and we cannot create an object without the name - * so its static :) - */ @Getter @Setter - private static String dungeonName; - @Getter - @Setter - public int percentage; + private String dungeonName; @Getter private final World world; @Getter - private final MapProcessor mapProcessor; - - @Getter - @Setter - private BlockPos dungeonMin; - + private final MapPlayerProcessor mapPlayerMarkerProcessor; @Getter - private final Map<Point, DungeonRoom> roomMapper = new HashMap<>(); + private DungeonRoomScaffoldParser scaffoldParser; @Getter - private final List<DungeonRoom> dungeonRoomList = new ArrayList<>(); + private DungeonEventRecorder recorder = new DungeonEventRecorder(); + @Getter private final List<RoomProcessor> globalRoomProcessors = new ArrayList<>(); - @Getter - private final Map<String, Integer> deaths = new HashMap<>(); - @Getter - private final List<String[]> milestoneReached = new ArrayList<>(); - @Getter - @Setter - private long BossRoomEnterSeconds = -1; - @Getter - @Setter + // bunch of statistics + @Getter @Setter + private long bossRoomEnterSeconds = -1; + @Getter @Setter private long init = -1; - @Getter - @Setter + @Getter @Setter private BlockPos bossroomSpawnPos = null; - @Getter - @Setter + private boolean gotMimic = false; + + + // general info + @Getter @Setter private boolean trapRoomGen = false; - @Getter - private boolean gotMimic = false; + @Getter private int maxSpeed = 600; + @Getter private double secretPercentage = 1.0; - private int latestSecretCnt = 0; - private int latestTotalSecret = 0; - private int latestCrypts = 0; + @Getter @Setter + public int percentage; - @Getter - private int maxSpeed = 600; - @Getter - private double secretPercentage = 1.0; public void setGotMimic(boolean gotMimic) { this.gotMimic = gotMimic; - createEvent(new DungeonNodataEvent("MIMIC_KILLED")); + recorder.createEvent(new DungeonNodataEvent("MIMIC_KILLED")); } @Getter @@ -120,40 +103,43 @@ public class DungeonContext { @Getter private final Set<String> players = new HashSet<>(); - @Getter - private final List<DungeonEvent> events = new ArrayList<>(); - public DungeonContext(World world) { + private Vector2d doorOffset; + private BlockPos door; + + public DungeonContext(String dungeonName, World world) { + this.dungeonName = dungeonName; this.world = world; - createEvent(new DungeonNodataEvent("DUNGEON_CONTEXT_CREATION")); - mapProcessor = new MapProcessor(this); + recorder.createEvent(new DungeonNodataEvent("DUNGEON_CONTEXT_CREATION")); + mapPlayerMarkerProcessor = new MapPlayerProcessor(this); DungeonSpecificDataProvider doorFinder = DungeonSpecificDataProviderRegistry.getDoorFinder(getDungeonName()); if (doorFinder != null) { trapRoomGen = doorFinder.isTrapSpawn(getDungeonName()); - secretPercentage = doorFinder.secretPercentage(getDungeonName()); maxSpeed = doorFinder.speedSecond(getDungeonName()); } else { - mapProcessor.setBugged(true); + throw new IllegalStateException("No door finder found"); } + + doorOffset = doorFinder.findDoorOffset(world, getDungeonName()); + door = doorFinder.findDoor(world, getDungeonName()); + + if (doorOffset == null || door == null) throw new IllegalStateException("?"); + + init = System.currentTimeMillis(); } - public void createEvent(DungeonEventData eventData) { -// events.add(new DungeonEvent(eventData)); - } private final Rectangle roomBoundary = new Rectangle(-10, -10, 138, 138); public void tick() { - - - if (mapProcessor.isInitialized() && BossRoomEnterSeconds == -1 && !roomBoundary.contains(mapProcessor.worldPointToMapPoint(Minecraft.getMinecraft().thePlayer.getPositionVector()))) { - BossRoomEnterSeconds = FeatureRegistry.DUNGEON_SBTIME.getTimeElapsed() / 1000; + if (scaffoldParser != null && bossRoomEnterSeconds == -1 && !roomBoundary.contains(scaffoldParser.getDungeonMapLayout().worldPointToMapPoint(Minecraft.getMinecraft().thePlayer.getPositionVector()))) { + bossRoomEnterSeconds = FeatureRegistry.DUNGEON_SBTIME.getTimeElapsed() / 1000; bossroomSpawnPos = Minecraft.getMinecraft().thePlayer.getPosition(); MinecraftForge.EVENT_BUS.post(new BossroomEnterEvent()); - createEvent(new DungeonNodataEvent("BOSSROOM_ENTER")); + recorder.createEvent(new DungeonNodataEvent("BOSSROOM_ENTER")); DungeonSpecificDataProvider doorFinder = DungeonSpecificDataProviderRegistry.getDoorFinder(getDungeonName()); if (doorFinder != null) { bossfightProcessor = doorFinder.createBossfightProcessor(world, getDungeonName()); @@ -162,23 +148,55 @@ public class DungeonContext { } } + if (scaffoldParser != null) { + for (DungeonRoom dungeonRoom : scaffoldParser.getDungeonRoomList()) { + if (!dungeonRoom.isMatched()) { + dungeonRoom.tryRematch(); + } + } + } + players.clear(); players.addAll(TabListUtil.getPlayersInDungeon()); + } - if (latestSecretCnt != FeatureRegistry.DUNGEON_SECRETS.getSecretsFound()) { - int newSecretCnt = FeatureRegistry.DUNGEON_SECRETS.getSecretsFound(); - createEvent(new DungeonSecretCountChangeEvent(latestSecretCnt, newSecretCnt, latestTotalSecret, FeatureRegistry.DUNGEON_SECRETS.sureOfTotalSecrets())); - latestSecretCnt = newSecretCnt; + private boolean processed = false; + private void processFinishedMap(byte[] mapData) { + if (MapUtils.getMapColorAt(mapData, 0, 0) == 0) { + return; } - if (latestTotalSecret != FeatureRegistry.DUNGEON_SECRETS.getTotalSecretsInt()) { - latestTotalSecret = FeatureRegistry.DUNGEON_SECRETS.getTotalSecretsInt(); - createEvent(new DungeonSecretCountChangeEvent(latestSecretCnt, latestSecretCnt, latestTotalSecret, FeatureRegistry.DUNGEON_SECRETS.sureOfTotalSecrets())); + if (processed) { + return; } - if (latestCrypts != FeatureRegistry.DUNGEON_TOMBS.getTombsFound()) { - int newlatestCrypts = FeatureRegistry.DUNGEON_TOMBS.getTombsFound(); - createEvent(new DungeonCryptBrokenEvent(latestCrypts, newlatestCrypts)); - this.latestCrypts = newlatestCrypts; + processed = true; + + MapUtils.clearMap(); + MapUtils.record(mapData, 0, 0, Color.GREEN); + + + FeatureRegistry.ETC_COLLECT_SCORE.collectDungeonRunData(mapData, this); + } + private int mapId = -1; + public void onMapUpdate(MapUpdateEvent mapUpdateEvent) { + if (mapUpdateEvent.getMapId() > 10000) return; // tictactoe + if (mapId == -1) { + mapId = mapUpdateEvent.getMapId(); + } + if (mapId != mapUpdateEvent.getMapId()) return; + + if (isEnded()) { + processFinishedMap(mapUpdateEvent.getMapData().colors); + } + if (getScaffoldParser() == null) { + DungeonMapLayout layout = DungeonMapConstantRetreiver.beginParsingMap(mapUpdateEvent.getMapData().colors, door, doorOffset); + if (layout != null) + scaffoldParser = new DungeonRoomScaffoldParser( + layout, + this + ); + } else { + getScaffoldParser().processMap(mapUpdateEvent.getMapData()); } } @@ -199,18 +217,18 @@ public class DungeonContext { int x = Integer.parseInt(coords.split("/")[0]); int z = Integer.parseInt(coords.split("/")[1]); int secrets2 = Integer.parseInt(secrets); - Point roomPt = mapProcessor.worldPointToRoomPoint(new BlockPos(x, 70, z)); + Point roomPt = scaffoldParser.getDungeonMapLayout().worldPointToRoomPoint(new BlockPos(x, 70, z)); ChatTransmitter.sendDebugChat(new ChatComponentText("Message from Other dungeons guide :: " + roomPt.x + " / " + roomPt.y + " total secrets " + secrets2)); - DungeonRoom dr = roomMapper.get(roomPt); + DungeonRoom dr = scaffoldParser.getRoomMap().get(roomPt); if (dr != null) { dr.setTotalSecrets(secrets2); } } else if (formatted.contains("$DG-Mimic")) { setGotMimic(true); } else if (formatted.startsWith("§r§c§lPUZZLE FAIL! ") && formatted.endsWith(" §r§4Y§r§ci§r§6k§r§ee§r§as§r§2!§r")) { - createEvent(new DungeonPuzzleFailureEvent(TextUtils.stripColor(formatted.split(" ")[2]), formatted)); + recorder.createEvent(new DungeonPuzzleFailureEvent(TextUtils.stripColor(formatted.split(" ")[2]), formatted)); } else if (formatted.contains("§6> §e§lEXTRA STATS §6<")) { - createEvent(new DungeonNodataEvent("DUNGEON_END")); + recorder.createEvent(new DungeonNodataEvent("DUNGEON_END")); ended = true; } else if (formatted.contains("§r§c☠ §r§eDefeated ")) { defeated = true; diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/MapProcessor.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/MapProcessor.java deleted file mode 100755 index 84adf8a0..00000000 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/MapProcessor.java +++ /dev/null @@ -1,543 +0,0 @@ -/* - * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod - * Copyright (C) 2021 cyoung06 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - */ - -package kr.syeyoung.dungeonsguide.mod.dungeon; - -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; -import com.google.common.collect.Sets; -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import kr.syeyoung.dungeonsguide.mod.DungeonsGuide; -import kr.syeyoung.dungeonsguide.mod.chat.ChatTransmitter; -import kr.syeyoung.dungeonsguide.mod.dungeon.doorfinder.EDungeonDoorType; -import kr.syeyoung.dungeonsguide.mod.dungeon.events.SerializableBlockPos; -import kr.syeyoung.dungeonsguide.mod.dungeon.events.impl.DungeonMapUpdateEvent; -import kr.syeyoung.dungeonsguide.mod.dungeon.events.impl.DungeonRoomDiscoverEvent; -import kr.syeyoung.dungeonsguide.mod.dungeon.map.DungeonMapData; -import kr.syeyoung.dungeonsguide.mod.dungeon.roomfinder.DungeonRoom; -import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; -import kr.syeyoung.dungeonsguide.mod.utils.MapUtils; -import lombok.Getter; -import lombok.Setter; -import net.minecraft.client.Minecraft; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemMap; -import net.minecraft.item.ItemStack; -import net.minecraft.util.*; -import net.minecraft.world.storage.MapData; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import javax.vecmath.Vector2d; -import java.awt.*; -import java.util.List; -import java.util.Queue; -import java.util.*; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -public class MapProcessor { - - 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 static final Set<Vector2d> door_dirs = Sets.newHashSet(new Vector2d(0, 0.5), new Vector2d(0, -0.5), new Vector2d(0.5, 0), new Vector2d(-0.5, 0)); - private static final Minecraft mc = Minecraft.getMinecraft(); - private final DungeonContext context; - @Getter - private final BiMap<String, String> mapIconToPlayerMap = HashBiMap.create(); - private final List<Point> roomsFound = new ArrayList<>(); - Logger logger = LogManager.getLogger("MapProcessor"); - /** - * If the player on the map is closer than value this it won't save it - * this should be done with render-distance but whateva - */ - int clossnessDistance = 50; - @Getter - @Setter - private Dimension unitRoomDimension; - @Getter @Setter - private Dimension doorDimensions; // width: width of door, height: gap between rooms - @Getter - @Setter - private Point topLeftMapPoint; - @Setter - private boolean bugged = false; - @Getter - private boolean initialized = false; - @Getter - private int undiscoveredRoom = 0; - private boolean processed = false; - @Getter - private MapData latestMapData; - private int waitDelay = 0; - private boolean processlock; - - public MapProcessor(DungeonContext context) { - this.context = context; - } - - private static void error(String prefix) { - ChatTransmitter.addToQueue(new ChatComponentText(ChatTransmitter.prefix + prefix)); - } - - - ExecutorService es = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder() - .setThreadFactory(DungeonsGuide.THREAD_FACTORY) - .setNameFormat("Dg-MapProcessor-%d").build()); - - - int processMapThroddle; - - public void tick() { - if (waitDelay < 5) { - waitDelay++; - return; - } - if (bugged) { - return; - } - ItemStack stack = Minecraft.getMinecraft().thePlayer.inventory.getStackInSlot(8); - - if (stack == null || !(stack.getItem() instanceof ItemMap)) { - return; - } - - MapData mapData = ((ItemMap) stack.getItem()).getMapData(stack, mc.theWorld); - - if (mapData != null) { - - if(processMapThroddle > 5 && !processlock){ - processMapData(mapData); - processMapThroddle = 0; - } - processMapThroddle++; - - } - - latestMapData = mapData; - - if (latestMapData != null && mapIconToPlayerMap.size() < context.getPlayers().size() && initialized) { - getPlayersFromMap(latestMapData); - } - - } - - private void processMapData(MapData mapData) { - byte[] mapColorData = mapData.colors; - - // i just cant get this to work sad - if (isThereDifference(latestMapData, mapColorData)) { - context.createEvent(new DungeonMapUpdateEvent(mapColorData)); - - es.execute(() -> { - processlock = true; - if (doorDimensions == null || !initialized) { - assembleMap(mapColorData); - } else { - processMap(mapColorData); - } - - if (context.isEnded()) { - processFinishedMap(mapColorData); - } - processlock = false; - }); - - } - - } - - void assembleMap(final byte[] mapData){ - DungeonMapData data = new DungeonMapData(context, Minecraft.getMinecraft()); - - data.eat(mapData); - - bugged = data.bugged; - - unitRoomDimension = data.unitRoomDimension; - - topLeftMapPoint = data.topLeftMapPoint; - - initialized = data.initialized; - - doorDimensions = data.doorDimensions; - - } - - - public static Point mapPointToRoomPoint(Point mapPoint, Point topLeftMapPoint, Dimension unitRoomDimension, Dimension doorDimensions) { - int x = (int) ((mapPoint.x - topLeftMapPoint.x) / ((double) unitRoomDimension.width + doorDimensions.height)); - int y = (int) ((mapPoint.y - topLeftMapPoint.y) / ((double) unitRoomDimension.height + doorDimensions.height)); - return new Point(x, y); - } - - public BlockPos mapPointToWorldPoint(Point mapPoint) { - int x = (int) ((mapPoint.x - topLeftMapPoint.x) / ((double) unitRoomDimension.width + doorDimensions.height) * 32 + context.getDungeonMin().getX()); - int y = (int) ((mapPoint.y - topLeftMapPoint.y) / ((double) unitRoomDimension.height + doorDimensions.height) * 32 + context.getDungeonMin().getZ()); - return new BlockPos(x, 70, y); - } - - public Point roomPointToMapPoint(Point roomPoint) { - return new Point(roomPoint.x * (unitRoomDimension.width + doorDimensions.height) + topLeftMapPoint.x, roomPoint.y * (unitRoomDimension.height + doorDimensions.height) + topLeftMapPoint.y); - } - - public BlockPos roomPointToWorldPoint(Point roomPoint) { - return new BlockPos(context.getDungeonMin().getX() + (roomPoint.x * 32), context.getDungeonMin().getY(), context.getDungeonMin().getZ() + (roomPoint.y * 32)); - } - - public Point worldPointToRoomPoint(BlockPos worldPoint) { - if (context.getDungeonMin() == null) return null; - return new Point((worldPoint.getX() - context.getDungeonMin().getX()) / 32, (worldPoint.getZ() - context.getDungeonMin().getZ()) / 32); - } - - public Point worldPointToMapPoint(Vec3 worldPoint) { - if (context.getDungeonMin() == null) return null; - return new Point(topLeftMapPoint.x + (int) ((worldPoint.xCoord - context.getDungeonMin().getX()) / 32.0f * (unitRoomDimension.width + doorDimensions.height)), topLeftMapPoint.y + (int) ((worldPoint.zCoord - context.getDungeonMin().getZ()) / 32.0f * (unitRoomDimension.height + doorDimensions.height))); - } - - public Vector2d worldPointToMapPointFLOAT(Vec3 worldPoint) { - if (context.getDungeonMin() == null) return null; - double x = topLeftMapPoint.x + ((worldPoint.xCoord - context.getDungeonMin().getX()) / 32.0f * (unitRoomDimension.width + doorDimensions.height)); - double y = topLeftMapPoint.y + ((worldPoint.zCoord - context.getDungeonMin().getZ()) / 32.0f * (unitRoomDimension.height + doorDimensions.height)); - return new Vector2d(x, y); - } - - private void processMap(byte[] mapData) { - int roomHeight = (int) ((128.0 - topLeftMapPoint.y) / (unitRoomDimension.height + doorDimensions.height)); - int roomWidth = (int) ((128.0 - topLeftMapPoint.x) / (unitRoomDimension.width + doorDimensions.height)); - if (MapUtils.getMapColorAt(mapData, 0, 0) != 0) return; - undiscoveredRoom = 0; - for (int y = 0; y <= roomHeight; y++) { - for (int x = 0; x <= roomWidth; x++) { - Point mapPoint = roomPointToMapPoint(new Point(x, y)); - byte color = MapUtils.getMapColorAt(mapData, mapPoint.x, mapPoint.y); - MapUtils.record(mapData, mapPoint.x, mapPoint.y, new Color(255, 255, 0, 80)); - if (roomsFound.contains(new Point(x, y))) { - DungeonRoom dungeonRoom = context.getRoomMapper().get(new Point(x, y)); - if (color == 18 && dungeonRoom.getCurrentState() != DungeonRoom.RoomState.FINISHED) { - dungeonRoom.setCurrentState(DungeonRoom.RoomState.COMPLETE_WITHOUT_SECRETS); - dungeonRoom.setTotalSecrets(0); - } else if (color == 30) { - dungeonRoom.setCurrentState(DungeonRoom.RoomState.FINISHED); - dungeonRoom.setTotalSecrets(0); - } else if (dungeonRoom.getCurrentState() != DungeonRoom.RoomState.FINISHED) { - byte centerColor = MapUtils.getMapColorAt(mapData, mapPoint.x + unitRoomDimension.width / 2, mapPoint.y + unitRoomDimension.height / 2); - MapUtils.record(mapData, mapPoint.x + unitRoomDimension.width / 2, mapPoint.y + unitRoomDimension.height / 2, new Color(0, 255, 0, 80)); - if (centerColor == 34) { - dungeonRoom.setCurrentState(DungeonRoom.RoomState.COMPLETE_WITHOUT_SECRETS); - } else if (centerColor == 30) { - dungeonRoom.setCurrentState(DungeonRoom.RoomState.FINISHED); - } else if (centerColor == 18) { // red - dungeonRoom.setCurrentState(DungeonRoom.RoomState.FAILED); - } - } - if (dungeonRoom.getTotalSecrets() == -1) { - if (dungeonRoom.getColor() == 82 || dungeonRoom.getColor() == 74) { - dungeonRoom.setTotalSecrets(0); - } - MapUtils.record(mapData, mapPoint.x, mapPoint.y + 1, new Color(0, 255, 0, 80)); - } - continue; - } - - if (color != 0 && color != 85) { - MapUtils.record(mapData, mapPoint.x, mapPoint.y, new Color(0, 255, 255, 80)); - DungeonRoom room = buildRoom(mapData, new Point(x, y)); - - - // USELESS DEBUG CODE - context.createEvent(new DungeonRoomDiscoverEvent(room.getUnitPoints().get(0), room.getRoomMatcher().getRotation(), new SerializableBlockPos(room.getMin()), new SerializableBlockPos(room.getMax()), room.getShape(), room.getColor(), room.getDungeonRoomInfo().getUuid(), room.getDungeonRoomInfo().getName(), room.getDungeonRoomInfo().getProcessorId())); - ChatTransmitter.sendDebugChat(new ChatComponentText("New Map discovered! shape: " + room.getShape() + " color: " + room.getColor() + " unitPos: " + x + "," + y)); - ChatTransmitter.sendDebugChat(new ChatComponentText("New Map discovered! mapMin: " + room.getMin() + " mapMx: " + room.getMax())); - StringBuilder builder = new StringBuilder(); - for (int dy = 0; dy < 4; dy++) { - builder.append("\n"); - for (int dx = 0; dx < 4; dx++) { - boolean isSet = ((room.getShape() >> (dy * 4 + dx)) & 0x1) != 0; - builder.append(isSet ? "O" : "X"); - } - } - ChatTransmitter.sendDebugChat(new ChatComponentText("Shape visual: " + builder)); - // END - - - context.getDungeonRoomList().add(room); - for (Point p : room.getUnitPoints()) { - roomsFound.add(p); - context.getRoomMapper().put(p, room); - } - if (room.getRoomProcessor() != null && room.getRoomProcessor().readGlobalChat()) { - context.getGlobalRoomProcessors().add(room.getRoomProcessor()); - } - } else if (color == 85) { - undiscoveredRoom++; - } - - } - } - } - - private DungeonRoom buildRoom(byte[] mapData, Point unitPoint) { - Queue<Point[]> toCheck = new LinkedList<>(); - toCheck.add(new Point[]{unitPoint, unitPoint}); // requestor, target - Set<Point> checked = new HashSet<>(); - List<Point> ayConnected = new ArrayList<>(); - - int minX = Integer.MAX_VALUE; - int minY = Integer.MAX_VALUE; - int maxX = 0; - int maxY = 0; - while (toCheck.peek() != null) { - Point[] check = toCheck.poll(); - if (checked.contains(check[1])) { - continue; - } - checked.add(check[1]); - - if (checkIfConnected(mapData, check[0], check[1])) { - ayConnected.add(check[1]); - if (check[1].x < minX) minX = check[1].x; - if (check[1].y < minY) minY = check[1].y; - if (check[1].x > maxX) maxX = check[1].x; - if (check[1].y > maxY) maxY = check[1].y; - for (Vector2d dir : directions) { - Point newPt = new Point(check[1].x + (int) dir.x, check[1].y + (int) dir.y); - toCheck.add(new Point[]{check[1], newPt}); - } - } - } - - short shape = 0; - for (Point p : ayConnected) { - int localX = p.x - minX; - int localY = p.y - minY; - shape |= 1 << (localY * 4 + localX); - } - Set<Vector2d> doors = new HashSet<>(); - for (Point p : ayConnected) { - for (Vector2d v : door_dirs) { - Vector2d v2 = new Vector2d(p.x + v.x, p.y + v.y); - if (doors.contains(v2)) doors.remove(v2); - else doors.add(v2); - } - } - Point pt2 = roomPointToMapPoint(ayConnected.get(0)); - byte unit1 = MapUtils.getMapColorAt(mapData, pt2.x, pt2.y); - - // 0: none 1: open door 2. unopen door 3: wither door 4. red door - Set<Tuple<Vector2d, EDungeonDoorType>> doorsAndStates = new HashSet<>(); - final int halfWidth = unitRoomDimension.width + 4; - for (Vector2d door : doors) { - int floorX = (int) Math.floor(door.x); - int floorY = (int) Math.floor(door.y); - Point mapPt = roomPointToMapPoint(new Point(floorX, floorY)); - Point target = new Point(mapPt.x + unitRoomDimension.width / 2 + (int) (halfWidth * (door.x - floorX)), mapPt.y + unitRoomDimension.height / 2 + (int) (halfWidth * (door.y - floorY))); - MapUtils.record(mapData, target.x, target.y, Color.green); - - byte color = MapUtils.getMapColorAt(mapData, target.x, target.y); - - Vector2d vector2d = new Vector2d(door.x - minX, door.y - minY); - - if (color == 0) { - doorsAndStates.add(new Tuple<>(vector2d, EDungeonDoorType.NONE)); - } else if (color == 85) { - doorsAndStates.add(new Tuple<>(vector2d, EDungeonDoorType.UNOPEN)); - } else if (color == 119) { - doorsAndStates.add(new Tuple<>(vector2d, EDungeonDoorType.WITHER)); - } else if (color == 18 && unit1 != 18) { - doorsAndStates.add(new Tuple<>(vector2d, EDungeonDoorType.BLOOD)); - } else { - doorsAndStates.add(new Tuple<>(vector2d, EDungeonDoorType.ENTRANCE)); - } - - } - - - return new DungeonRoom(ayConnected, shape, unit1, roomPointToWorldPoint(new Point(minX, minY)), roomPointToWorldPoint(new Point(maxX + 1, maxY + 1)).add(-1, 0, -1), context, doorsAndStates); - - } - - private boolean checkIfConnected(byte[] mapData, Point unitPoint1, Point unitPoint2) { - if (unitPoint1 == unitPoint2) return true; - if (unitPoint1.equals(unitPoint2)) return true; - - - Point high; - if (unitPoint2.y > unitPoint1.y) { - high = unitPoint2; - } else { - if (unitPoint2.x > unitPoint1.x) { - high = unitPoint2; - } else { - high = unitPoint1; - } - } - - Point low; - if (high == unitPoint2) { - low = unitPoint1; - } else { - low = unitPoint2; - } - - int xOff = low.x - high.x; - int yOff = low.y - high.y; - Point pt = roomPointToMapPoint(high); - Point pt2 = roomPointToMapPoint(low); - byte unit1 = MapUtils.getMapColorAt(mapData, pt.x, pt.y); - byte unit2 = MapUtils.getMapColorAt(mapData, pt2.x, pt2.y); - pt.translate(xOff, yOff); - byte unit3 = MapUtils.getMapColorAt(mapData, pt.x, pt.y); - - return unit1 == unit2 && unit2 == unit3 && unit1 != 0; - } - - public boolean isThereDifference(MapData latestMapData, byte[] colorData1) { - byte[] colorData = null; - - if(latestMapData != null){ - colorData = latestMapData.colors; - } - - return true; -// boolean equals = Arrays.equals(colorData1, colorData); -// -// boolean foundDIffrentThen0 = false; -// -// -// for (byte colorDatum : colorData) { -// if(colorDatum != 0){ -// foundDIffrentThen0 = true; -// break; -// } -// } -// -// -// return !(equals && foundDIffrentThen0); - } - - private void processFinishedMap(byte[] mapData) { - if (MapUtils.getMapColorAt(mapData, 0, 0) == 0) { - return; - } - if (processed) { - return; - } - processed = true; - - MapUtils.clearMap(); - MapUtils.record(mapData, 0, 0, Color.GREEN); - - - FeatureRegistry.ETC_COLLECT_SCORE.collectDungeonRunData(mapData, context); - - } - - private void getPlayersFromMap(MapData mapdata) { - - if (DungeonsGuide.getDungeonsGuide().verbose) logger.info("Getting players from map"); - - for (Map.Entry<String, Vec4b> stringVec4bEntry : mapdata.mapDecorations.entrySet()) { - String mapDecString = stringVec4bEntry.getKey(); - Vec4b vec4 = stringVec4bEntry.getValue(); - - if (!mapIconToPlayerMap.containsValue(mapDecString)) { - if (DungeonsGuide.getDungeonsGuide().verbose) logger.info("mapIconToPlayerMap dosent have Player"); - - int x = vec4.func_176112_b() / 2 + 64; - int y = vec4.func_176113_c() / 2 + 64; - BlockPos mapPos = mapPointToWorldPoint(new Point(x, y)); - String potentialPlayer = null; - - for (String player : context.getPlayers()) { - if (DungeonsGuide.getDungeonsGuide().verbose) - logger.info("Player: {} isNear: {} ", player, isPlayerNear(player, mapPos)); -// if (!mapIconToPlayerMap.containsKey(player) && isPlayerNear(player, mapPos)) { - if (!mapIconToPlayerMap.containsKey(player)) { - if (DungeonsGuide.getDungeonsGuide().verbose) logger.info("Potential profile is: " + player); - potentialPlayer = player; - break; - } - } - - - if (potentialPlayer != null) { - if (DungeonsGuide.getDungeonsGuide().verbose) logger.info("potentialPlayer is not null"); - boolean shouldSave = true; - - for (Map.Entry<String, Vec4b> vec4bEntry : mapdata.mapDecorations.entrySet()) { -// String aaa = vec4bEntry.getKey(); - Vec4b bbb = vec4bEntry.getValue(); - -// if (mapIconToPlayerMap.containsValue(aaa) || mapDecString.equals(aaa)) { -// shouldSave = false; -// break; -// } -// else { - int x2 = bbb.func_176112_b() / 2 + 64; - int y2 = bbb.func_176113_c() / 2 + 64; - int dx = x2 - x; - int dy = y2 - y; - if (dx * dx + dy * dy < clossnessDistance) { - shouldSave = false; - break; - } -// } - } - - if (shouldSave) { - if (DungeonsGuide.getDungeonsGuide().verbose) - logger.info("added {} to mapIconPlayerMap with {}", potentialPlayer, stringVec4bEntry.getKey()); - if (mapIconToPlayerMap.containsKey(potentialPlayer)) { - mapIconToPlayerMap.replace(potentialPlayer, stringVec4bEntry.getKey()); - } else { - mapIconToPlayerMap.put(potentialPlayer, stringVec4bEntry.getKey()); - } - if (DungeonsGuide.getDungeonsGuide().verbose) logger.info("mapIconToPlayerMap:"); - if (DungeonsGuide.getDungeonsGuide().verbose) - mapIconToPlayerMap.forEach((key, value) -> logger.info(" {}: {}", key, value)); - } else { - if (DungeonsGuide.getDungeonsGuide().verbose) logger.info("shouldSave is false"); - } - - - } else { - if (DungeonsGuide.getDungeonsGuide().verbose) logger.info("potentialPlayer is null"); - } - - } else { - if (DungeonsGuide.getDungeonsGuide().verbose) logger.info("mapIconToPlayerMap has player "); - } - } - - - } - - private boolean isPlayerNear(String player, BlockPos mapPos) { - EntityPlayer entityPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(player); - - if (entityPlayer != null && !entityPlayer.isInvisible()) { - BlockPos pos = entityPlayer.getPosition(); - int dx = mapPos.getX() - pos.getX(); - int dz = mapPos.getZ() - pos.getZ(); - return dx * dx + dz * dz < clossnessDistance; - - } - - return false; - } -} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/events/DungeonEventRecorder.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/events/DungeonEventRecorder.java new file mode 100644 index 00000000..ff3061e5 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/events/DungeonEventRecorder.java @@ -0,0 +1,58 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2023 cyoung06 (syeyoung) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.dungeon.events; + +import kr.syeyoung.dungeonsguide.mod.dungeon.events.impl.DungeonCryptBrokenEvent; +import kr.syeyoung.dungeonsguide.mod.dungeon.events.impl.DungeonSecretCountChangeEvent; +import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; +import lombok.Getter; + +import java.util.ArrayList; +import java.util.List; + +public class DungeonEventRecorder { + private int latestSecretCnt = 0; + private int latestTotalSecret = 0; + private int latestCrypts = 0; + + @Getter + private final List<DungeonEvent> events = new ArrayList<>(); + + + public void tick() { + if (latestSecretCnt != FeatureRegistry.DUNGEON_SECRETS.getSecretsFound()) { + int newSecretCnt = FeatureRegistry.DUNGEON_SECRETS.getSecretsFound(); + createEvent(new DungeonSecretCountChangeEvent(latestSecretCnt, newSecretCnt, latestTotalSecret, FeatureRegistry.DUNGEON_SECRETS.sureOfTotalSecrets())); + latestSecretCnt = newSecretCnt; + } + if (latestTotalSecret != FeatureRegistry.DUNGEON_SECRETS.getTotalSecretsInt()) { + latestTotalSecret = FeatureRegistry.DUNGEON_SECRETS.getTotalSecretsInt(); + createEvent(new DungeonSecretCountChangeEvent(latestSecretCnt, latestSecretCnt, latestTotalSecret, FeatureRegistry.DUNGEON_SECRETS.sureOfTotalSecrets())); + } + if (latestCrypts != FeatureRegistry.DUNGEON_TOMBS.getTombsFound()) { + int newlatestCrypts = FeatureRegistry.DUNGEON_TOMBS.getTombsFound(); + createEvent(new DungeonCryptBrokenEvent(latestCrypts, newlatestCrypts)); + this.latestCrypts = newlatestCrypts; + } + } + + public void createEvent(DungeonEventData eventData) { + events.add(new DungeonEvent(eventData)); + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/events/impl/DungeonRoomDiscoverEvent.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/events/impl/DungeonRoomDiscoverEvent.java index 09fd64a5..49f065bb 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/events/impl/DungeonRoomDiscoverEvent.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/events/impl/DungeonRoomDiscoverEvent.java @@ -30,14 +30,10 @@ import java.util.UUID; @AllArgsConstructor public class DungeonRoomDiscoverEvent implements DungeonEventData { private Point unitPt; - private int rotation; private SerializableBlockPos min; private SerializableBlockPos max; private int shape; private int color; - private UUID roomUID; - private String roomName; - private String roomProc; @Override public String getEventName() { diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/events/impl/DungeonRoomMatchEvent.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/events/impl/DungeonRoomMatchEvent.java new file mode 100644 index 00000000..1aa98601 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/events/impl/DungeonRoomMatchEvent.java @@ -0,0 +1,46 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.dungeon.events.impl; + +import kr.syeyoung.dungeonsguide.mod.dungeon.events.DungeonEventData; +import kr.syeyoung.dungeonsguide.mod.dungeon.events.SerializableBlockPos; +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.awt.*; +import java.util.UUID; + +@Data +@AllArgsConstructor +public class DungeonRoomMatchEvent implements DungeonEventData { + private Point unitPt; + private int rotation; + private SerializableBlockPos min; + private SerializableBlockPos max; + private int shape; + private int color; + private UUID roomUID; + private String roomName; + private String roomProc; + + @Override + public String getEventName() { + return "ROOM_DISCOVER"; + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/map/DungeonMapConstantRetreiver.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/map/DungeonMapConstantRetreiver.java new file mode 100644 index 00000000..34e12e05 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/map/DungeonMapConstantRetreiver.java @@ -0,0 +1,139 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2023 cyoung06 (syeyoung) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.dungeon.map; + +import com.google.common.collect.Sets; +import kr.syeyoung.dungeonsguide.mod.chat.ChatTransmitter; +import kr.syeyoung.dungeonsguide.mod.dungeon.events.impl.DungeonNodataEvent; +import kr.syeyoung.dungeonsguide.mod.events.impl.DungeonContextInitializationEvent; +import kr.syeyoung.dungeonsguide.mod.utils.MapUtils; +import net.minecraft.util.BlockPos; +import net.minecraft.util.ChatComponentText; +import net.minecraftforge.common.MinecraftForge; + +import javax.vecmath.Vector2d; +import java.awt.*; +import java.util.Set; + + +// This class is responsible for matching the world to hand held map. +public class DungeonMapConstantRetreiver { + public static DungeonMapLayout beginParsingMap(byte[] mapData, BlockPos worldDoorLocation, Vector2d worldDoorDirection) { + if (worldDoorLocation == null || worldDoorDirection == null) return null; + +// context.createEvent(new DungeonNodataEvent("MAP_PROCESSOR_INIT")); +// MinecraftForge.EVENT_BUS.post(new DungeonContextInitializationEvent()); + + Rectangle firstRoom = obtainStartingRoom(mapData); + if (firstRoom == null) return null; + Dimension unitRoomSize = firstRoom.getSize(); + Vector2d mapDoorDirection = obtainStartingRoomToFirstRoomDoorDirection(mapData, firstRoom); + if (mapDoorDirection == null) return null; + Dimension mapDoorDimension = obtainMapDoorDimensions(mapData, firstRoom, mapDoorDirection); + if (mapDoorDimension == null) return null; + int mapDoorWidth = mapDoorDimension.width; + int mapRoomGap = mapDoorDimension.height; + + Point mapOriginPoint = obtainTopLeft(mapData, firstRoom, mapDoorDimension); + BlockPos worldMin = obtainWorldMin(mapData, firstRoom, mapOriginPoint, mapDoorDimension, + mapDoorDirection, worldDoorDirection, worldDoorLocation); + + ChatTransmitter.sendDebugChat(new ChatComponentText("door Pos:" + worldDoorDirection)); + + + ChatTransmitter.sendDebugChat(new ChatComponentText("Found Green room:" + firstRoom)); + ChatTransmitter.sendDebugChat(new ChatComponentText("World Min:" + worldMin)); + ChatTransmitter.sendDebugChat(new ChatComponentText("Dimension:" + unitRoomSize)); + ChatTransmitter.sendDebugChat(new ChatComponentText("top Left:" + mapOriginPoint)); + ChatTransmitter.sendDebugChat(new ChatComponentText("door dimension:" + mapDoorDimension)); + return new DungeonMapLayout(unitRoomSize, mapRoomGap, mapOriginPoint, worldMin); + } + + private static Point mapPointToRoomPoint(Point mapPoint, Point topLeftMapPoint, Dimension unitRoomDimension, Dimension doorDimensions) { + int x = (int) ((mapPoint.x - topLeftMapPoint.x) / ((double) unitRoomDimension.width + doorDimensions.height)); + int y = (int) ((mapPoint.y - topLeftMapPoint.y) / ((double) unitRoomDimension.height + doorDimensions.height)); + return new Point(x, y); + } + private static BlockPos obtainWorldMin(byte[] mapData, Rectangle firstRoom, Point topLeftMapPoint, Dimension doorDimension, + Vector2d mapDoorOffset, + Vector2d worldDoorOffset, BlockPos worldDoor) { + Point unitPoint = mapPointToRoomPoint(firstRoom.getLocation(), topLeftMapPoint, firstRoom.getSize(), doorDimension); + unitPoint.translate(unitPoint.x + 1, unitPoint.y + 1); // basically we make each room 2x2 large in this coordinate, and get the center coord + unitPoint.translate((int) mapDoorOffset.x, (int) mapDoorOffset.y); + + if (!worldDoorOffset.equals(mapDoorOffset)) + throw new IllegalStateException("Map door offset does not match world door offset!! DG is not prepared for this kind of situation"); + + int worldX = unitPoint.x * 16; + int worldY = unitPoint.y * 16; + BlockPos worldMin = worldDoor.add(-worldX, 0, -worldY); + return worldMin; + } + private static Point obtainTopLeft(byte[] mapData, Rectangle firstRoom, Dimension doorDimension) { + int topLeftX = firstRoom.x; + int topLeftY = firstRoom.y; + while (topLeftX >= firstRoom.width + doorDimension.height) + topLeftX -= firstRoom.width + doorDimension.height; + while (topLeftY >= firstRoom.height + doorDimension.height) + topLeftY -= firstRoom.height + doorDimension.height; + return new Point(topLeftX, topLeftY); + } + private static Rectangle obtainStartingRoom(byte[] mapData) { + final Point firstRoom = MapUtils.findFirstColorWithIn(mapData, (byte) 30, new Rectangle(0, 0, 128, 128)); + if (firstRoom == null) return null; + // Determine room dimension + int width = MapUtils.getWidthOfColorAt(mapData, (byte) 30, firstRoom); + int height = MapUtils.getHeightOfColorAt(mapData, (byte) 30, firstRoom); + + return new Rectangle(firstRoom, new Dimension(width, height)); + } + + 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 static Dimension obtainMapDoorDimensions(byte[] mapData, Rectangle firstRoom, Vector2d doorDirection) { + Point basePoint = new Point(firstRoom.x, firstRoom.y); + if (doorDirection.x > 0) basePoint.x += firstRoom.width; + if (doorDirection.x < 0) basePoint.x -= 1; + if (doorDirection.y > 0) basePoint.y += firstRoom.height; + if (doorDirection.y < 0) basePoint.y -= 1; + // Base Point is the point I would want to start searching next room from. + + int gap = MapUtils.getLengthOfColorExtending(mapData, (byte) 0, basePoint, doorDirection); + Point pt = MapUtils.findFirstColorWithInNegate(mapData, (byte) 0, new Rectangle(basePoint.x, basePoint.y, (int) Math.abs(doorDirection.y) * firstRoom.width + 1, (int) Math.abs(doorDirection.x) * firstRoom.height + 1)); + if (pt == null) { + return null; + } + int doorWidth = MapUtils.getLengthOfColorExtending(mapData, MapUtils.getMapColorAt(mapData, pt.x, pt.y), pt, new Vector2d((int) Math.abs(doorDirection.y), (int) Math.abs(doorDirection.x))); + return new Dimension(doorWidth, gap); + } + + private static Vector2d obtainStartingRoomToFirstRoomDoorDirection(byte[] mapData, Rectangle firstRoom) { + Vector2d doorDir = null; + Point midfirstRoom = new Point(firstRoom.x + firstRoom.width / 2, firstRoom.y + firstRoom.height / 2); + final int halfWidth = firstRoom.width / 2 + 2; + for (Vector2d v : directions) { + byte color = MapUtils.getMapColorAt(mapData, (int) (v.x * halfWidth + midfirstRoom.x), (int) (v.y * halfWidth + midfirstRoom.y)); + if (color != 0) { + doorDir = v; + break; + } + } + return doorDir; + } + +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/map/DungeonMapData.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/map/DungeonMapData.java deleted file mode 100644 index 1949a93f..00000000 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/map/DungeonMapData.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod - * Copyright (C) 2022 cyoung06 (syeyoung) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - */ - -package kr.syeyoung.dungeonsguide.mod.dungeon.map; - -import com.google.common.collect.Sets; -import kr.syeyoung.dungeonsguide.mod.chat.ChatTransmitter; -import kr.syeyoung.dungeonsguide.mod.dungeon.DungeonContext; -import kr.syeyoung.dungeonsguide.mod.dungeon.MapProcessor; -import kr.syeyoung.dungeonsguide.mod.dungeon.doorfinder.DungeonSpecificDataProvider; -import kr.syeyoung.dungeonsguide.mod.dungeon.doorfinder.DungeonSpecificDataProviderRegistry; -import kr.syeyoung.dungeonsguide.mod.dungeon.events.impl.DungeonNodataEvent; -import kr.syeyoung.dungeonsguide.mod.events.impl.DungeonContextInitializationEvent; -import kr.syeyoung.dungeonsguide.mod.utils.MapUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.util.BlockPos; -import net.minecraft.util.ChatComponentText; -import net.minecraftforge.common.MinecraftForge; - -import javax.vecmath.Vector2d; -import java.awt.*; -import java.util.Set; - -public class DungeonMapData { - 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 static final Set<Vector2d> door_dirs = Sets.newHashSet(new Vector2d(0, 0.5), new Vector2d(0, -0.5), new Vector2d(0.5, 0), new Vector2d(-0.5, 0)); - public Dimension unitRoomDimension; - public boolean bugged; - public Dimension doorDimensions; - public Point topLeftMapPoint; - private final DungeonContext context; - private final Minecraft mc; - public boolean initialized; - - public DungeonMapData(DungeonContext context, Minecraft mc) { - this.context = context; - this.mc = mc; - } - - - public void eat(final byte[] mapData){ - final Point firstRoom = MapUtils.findFirstColorWithIn(mapData, (byte) 30, new Rectangle(0, 0, 128, 128)); - // Determine room dimension - int width = MapUtils.getWidthOfColorAt(mapData, (byte) 30, firstRoom); - int height = MapUtils.getHeightOfColorAt(mapData, (byte) 30, firstRoom); - unitRoomDimension = new Dimension(width, height); - Vector2d doorDir = null; - Point midfirstRoom = new Point(firstRoom.x + unitRoomDimension.width / 2, firstRoom.y + unitRoomDimension.height / 2); - final int halfWidth = unitRoomDimension.width / 2 + 2; - for (Vector2d v : directions) { - byte color = MapUtils.getMapColorAt(mapData, (int) (v.x * halfWidth + midfirstRoom.x), (int) (v.y * halfWidth + midfirstRoom.y)); - if (color != 0) { - doorDir = v; - break; - } - } - - if (doorDir == null) { - bugged = true; - return; - } - - Point basePoint = new Point(firstRoom.x, firstRoom.y); - if (doorDir.x > 0) basePoint.x += unitRoomDimension.width; - if (doorDir.x < 0) basePoint.x -= 1; - if (doorDir.y > 0) basePoint.y += unitRoomDimension.height; - if (doorDir.y < 0) basePoint.y -= 1; - int gap = MapUtils.getLengthOfColorExtending(mapData, (byte) 0, basePoint, doorDir); - Point pt = MapUtils.findFirstColorWithInNegate(mapData, (byte) 0, new Rectangle(basePoint.x, basePoint.y, (int) Math.abs(doorDir.y) * unitRoomDimension.width + 1, (int) Math.abs(doorDir.x) * unitRoomDimension.height + 1)); - if (pt == null) { - bugged = true; - return; - } - int doorWidth = MapUtils.getLengthOfColorExtending(mapData, MapUtils.getMapColorAt(mapData, pt.x, pt.y), pt, new Vector2d((int) Math.abs(doorDir.y), (int) Math.abs(doorDir.x))); - doorDimensions = new Dimension(doorWidth, gap); - - // Determine Top Left - int topLeftX = firstRoom.x; - int topLeftY = firstRoom.y; - while (topLeftX >= unitRoomDimension.width + doorDimensions.height) - topLeftX -= unitRoomDimension.width + doorDimensions.height; - while (topLeftY >= unitRoomDimension.height + doorDimensions.height) - topLeftY -= unitRoomDimension.height + doorDimensions.height; - topLeftMapPoint = new Point(topLeftX, topLeftY); - // determine door location based on npc, and determine map min from there - DungeonSpecificDataProvider doorFinder = DungeonSpecificDataProviderRegistry.getDoorFinder(DungeonContext.getDungeonName()); - if (doorFinder == null) { - bugged = true; - return; - } - BlockPos door = doorFinder.findDoor(mc.theWorld, DungeonContext.getDungeonName()); - if (door == null) { - bugged = true; - return; - } - - ChatTransmitter.sendDebugChat(new ChatComponentText("door Pos:" + door)); - - Point unitPoint = MapProcessor.mapPointToRoomPoint(firstRoom, topLeftMapPoint, unitRoomDimension, doorDimensions); - unitPoint.translate(unitPoint.x + 1, unitPoint.y + 1); - unitPoint.translate((int) doorDir.x, (int) doorDir.y); - - Vector2d offset = doorFinder.findDoorOffset(mc.theWorld, DungeonContext.getDungeonName()); - boolean axisMatch = doorDir.equals(offset); - - int worldX = unitPoint.x * 16; - int worldY = unitPoint.y * 16; - BlockPos worldMin = door.add(-worldX, 0, -worldY); - context.setDungeonMin(worldMin); - - ChatTransmitter.sendDebugChat(new ChatComponentText("Found Green room:" + firstRoom)); - ChatTransmitter.sendDebugChat(new ChatComponentText("Axis match:" + axisMatch)); - ChatTransmitter.sendDebugChat(new ChatComponentText("World Min:" + context.getDungeonMin())); - ChatTransmitter.sendDebugChat(new ChatComponentText("Dimension:" + unitRoomDimension)); - ChatTransmitter.sendDebugChat(new ChatComponentText("top Left:" + topLeftMapPoint)); - ChatTransmitter.sendDebugChat(new ChatComponentText("door dimension:" + doorDimensions)); - context.createEvent(new DungeonNodataEvent("MAP_PROCESSOR_INIT")); - initialized = true; - MinecraftForge.EVENT_BUS.post(new DungeonContextInitializationEvent()); - - - } - -} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/map/DungeonMapLayout.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/map/DungeonMapLayout.java new file mode 100644 index 00000000..b67baa76 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/map/DungeonMapLayout.java @@ -0,0 +1,70 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2023 cyoung06 (syeyoung) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.dungeon.map; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import net.minecraft.util.BlockPos; +import net.minecraft.util.Vec3; + +import javax.vecmath.Vector2d; +import java.awt.*; + +@AllArgsConstructor @Getter +public class DungeonMapLayout { + private final Dimension unitRoomSize; + private final int mapRoomGap; + // top left room pos + private final Point originPoint; + + private final BlockPos worldMin; + + + public BlockPos mapPointToWorldPoint(Point mapPoint) { + int x = (int) ((mapPoint.x - originPoint.x) / ((double) unitRoomSize.width + mapRoomGap) * 32 + worldMin.getX()); + int y = (int) ((mapPoint.y - originPoint.y) / ((double) unitRoomSize.height + mapRoomGap) * 32 + worldMin.getZ()); + return new BlockPos(x, 70, y); + } + + public Point roomPointToMapPoint(Point roomPoint) { + return new Point(roomPoint.x * (unitRoomSize.width + mapRoomGap) + originPoint.x, roomPoint.y * (unitRoomSize.height + mapRoomGap) + originPoint.y); + } + + public BlockPos roomPointToWorldPoint(Point roomPoint) { + return new BlockPos(worldMin.getX() + (roomPoint.x * 32), worldMin.getY(), worldMin.getZ() + (roomPoint.y * 32)); + } + + public Point worldPointToRoomPoint(BlockPos worldPoint) { + if (worldMin == null) return null; + return new Point((worldPoint.getX() - worldMin.getX()) / 32, (worldPoint.getZ() - worldMin.getZ()) / 32); + } + + public Point worldPointToMapPoint(Vec3 worldPoint) { + if (worldMin == null) return null; + return new Point(originPoint.x + (int) ((worldPoint.xCoord - worldMin.getX()) / 32.0f * (unitRoomSize.width + mapRoomGap)), originPoint.y + (int) ((worldPoint.zCoord - worldMin.getZ()) / 32.0f * (unitRoomSize.height + mapRoomGap))); + } + + public Vector2d worldPointToMapPointFLOAT(Vec3 worldPoint) { + if (worldMin == null) return null; + double x = originPoint.x + ((worldPoint.xCoord - worldMin.getX()) / 32.0f * (unitRoomSize.width + mapRoomGap)); + double y = originPoint.y + ((worldPoint.zCoord - worldMin.getZ()) / 32.0f * (unitRoomSize.height + mapRoomGap)); + return new Vector2d(x, y); + } + +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/map/DungeonRoomScaffoldParser.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/map/DungeonRoomScaffoldParser.java new file mode 100644 index 00000000..9b32e541 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/map/DungeonRoomScaffoldParser.java @@ -0,0 +1,265 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2023 cyoung06 (syeyoung) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.dungeon.map; + +import com.google.common.collect.Sets; +import com.google.common.util.concurrent.ThreadFactoryBuilder; +import kr.syeyoung.dungeonsguide.mod.DungeonsGuide; +import kr.syeyoung.dungeonsguide.mod.chat.ChatTransmitter; +import kr.syeyoung.dungeonsguide.mod.dungeon.DungeonContext; +import kr.syeyoung.dungeonsguide.mod.dungeon.doorfinder.EDungeonDoorType; +import kr.syeyoung.dungeonsguide.mod.dungeon.events.SerializableBlockPos; +import kr.syeyoung.dungeonsguide.mod.dungeon.events.impl.DungeonRoomDiscoverEvent; +import kr.syeyoung.dungeonsguide.mod.dungeon.roomfinder.DungeonRoom; +import kr.syeyoung.dungeonsguide.mod.utils.MapUtils; +import lombok.Getter; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.Tuple; +import net.minecraft.world.storage.MapData; + +import javax.vecmath.Vector2d; +import java.awt.*; +import java.util.*; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class DungeonRoomScaffoldParser { + @Getter + private DungeonMapLayout dungeonMapLayout; + private DungeonContext context; + + @Getter + private MapData latestMapData; + + + + ExecutorService es = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder() + .setThreadFactory(DungeonsGuide.THREAD_FACTORY) + .setNameFormat("Dg-MapPlayerProcessor-%d").build()); + + @Getter + private final Map<Point, DungeonRoom> roomMap = new HashMap<>(); + @Getter + private final List<DungeonRoom> dungeonRoomList = new ArrayList<>(); + + public DungeonRoomScaffoldParser(DungeonMapLayout layout, DungeonContext context) { + this.dungeonMapLayout = layout; + this.context = context; + } + + @Getter + private int undiscoveredRoom = 0; + + public void processMap(MapData mapData2) { + int roomHeight = (int) ((128.0 - dungeonMapLayout.getOriginPoint().y) / (dungeonMapLayout.getUnitRoomSize().height + dungeonMapLayout.getMapRoomGap())); + int roomWidth = (int) ((128.0 - dungeonMapLayout.getOriginPoint().x) / (dungeonMapLayout.getUnitRoomSize().width + dungeonMapLayout.getMapRoomGap())); + latestMapData = mapData2; + byte[] mapData = mapData2.colors; + if (MapUtils.getMapColorAt(mapData, 0, 0) != 0) return; + undiscoveredRoom = 0; + for (int y = 0; y <= roomHeight; y++) { + for (int x = 0; x <= roomWidth; x++) { + Point mapPoint = dungeonMapLayout.roomPointToMapPoint(new Point(x, y)); + byte color = MapUtils.getMapColorAt(mapData, mapPoint.x, mapPoint.y); + MapUtils.record(mapData, mapPoint.x, mapPoint.y, new Color(255, 255, 0, 80)); + if (roomMap.containsKey(new Point(x, y))) { + DungeonRoom dungeonRoom = roomMap.get(new Point(x, y)); + if (color == 18 && dungeonRoom.getCurrentState() != DungeonRoom.RoomState.FINISHED) { + dungeonRoom.setCurrentState(DungeonRoom.RoomState.COMPLETE_WITHOUT_SECRETS); + dungeonRoom.setTotalSecrets(0); + } else if (color == 30) { + dungeonRoom.setCurrentState(DungeonRoom.RoomState.FINISHED); + dungeonRoom.setTotalSecrets(0); + } else if (dungeonRoom.getCurrentState() != DungeonRoom.RoomState.FINISHED) { + byte centerColor = MapUtils.getMapColorAt(mapData, mapPoint.x + dungeonMapLayout.getUnitRoomSize().width / 2, mapPoint.y + dungeonMapLayout.getUnitRoomSize().height / 2); + MapUtils.record(mapData, mapPoint.x + dungeonMapLayout.getUnitRoomSize().width / 2, mapPoint.y + dungeonMapLayout.getUnitRoomSize().height / 2, new Color(0, 255, 0, 80)); + if (centerColor == 34) { + dungeonRoom.setCurrentState(DungeonRoom.RoomState.COMPLETE_WITHOUT_SECRETS); + } else if (centerColor == 30) { + dungeonRoom.setCurrentState(DungeonRoom.RoomState.FINISHED); + } else if (centerColor == 18) { // red + dungeonRoom.setCurrentState(DungeonRoom.RoomState.FAILED); + } + } + if (dungeonRoom.getTotalSecrets() == -1) { + if (dungeonRoom.getColor() == 82 || dungeonRoom.getColor() == 74) { + dungeonRoom.setTotalSecrets(0); + } + MapUtils.record(mapData, mapPoint.x, mapPoint.y + 1, new Color(0, 255, 0, 80)); + } + continue; + } + + if (color != 0 && color != 85) { + MapUtils.record(mapData, mapPoint.x, mapPoint.y, new Color(0, 255, 255, 80)); + DungeonRoom room = buildRoom(mapData, new Point(x, y)); + + + // USELESS DEBUG CODE + context.getRecorder().createEvent(new DungeonRoomDiscoverEvent(room.getUnitPoints().iterator().next(), + new SerializableBlockPos(room.getMin()), new SerializableBlockPos(room.getMax()), + room.getShape(), room.getColor())); + ChatTransmitter.sendDebugChat(new ChatComponentText("New Map discovered! shape: " + room.getShape() + " color: " + room.getColor() + " unitPos: " + x + "," + y)); + ChatTransmitter.sendDebugChat(new ChatComponentText("New Map discovered! mapMin: " + room.getMin() + " mapMx: " + room.getMax())); + StringBuilder builder = new StringBuilder(); + for (int dy = 0; dy < 4; dy++) { + builder.append("\n"); + for (int dx = 0; dx < 4; dx++) { + boolean isSet = ((room.getShape() >> (dy * 4 + dx)) & 0x1) != 0; + builder.append(isSet ? "O" : "X"); + } + } + ChatTransmitter.sendDebugChat(new ChatComponentText("Shape visual: " + builder)); + // END + + + dungeonRoomList.add(room); + for (Point p : room.getUnitPoints()) { + roomMap.put(p, room); + } + if (room.getRoomProcessor() != null && room.getRoomProcessor().readGlobalChat()) { + context.getGlobalRoomProcessors().add(room.getRoomProcessor()); + } + } else if (color == 85) { + undiscoveredRoom++; + } + + } + } + } + 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 static final Set<Vector2d> door_dirs = Sets.newHashSet(new Vector2d(0, 0.5), new Vector2d(0, -0.5), new Vector2d(0.5, 0), new Vector2d(-0.5, 0)); + + private DungeonRoom buildRoom(byte[] mapData, Point unitPoint) { + java.util.Queue<Point[]> toCheck = new LinkedList<>(); + toCheck.add(new Point[]{unitPoint, unitPoint}); // requestor, target + Set<Point> checked = new HashSet<>(); + Set<Point> ayConnected = new HashSet<>(); + + int minX = Integer.MAX_VALUE; + int minY = Integer.MAX_VALUE; + int maxX = 0; + int maxY = 0; + while (toCheck.peek() != null) { + Point[] check = toCheck.poll(); + if (checked.contains(check[1])) { + continue; + } + checked.add(check[1]); + + if (checkIfConnected(mapData, check[0], check[1])) { + ayConnected.add(check[1]); + if (check[1].x < minX) minX = check[1].x; + if (check[1].y < minY) minY = check[1].y; + if (check[1].x > maxX) maxX = check[1].x; + if (check[1].y > maxY) maxY = check[1].y; + for (Vector2d dir : directions) { + Point newPt = new Point(check[1].x + (int) dir.x, check[1].y + (int) dir.y); + toCheck.add(new Point[]{check[1], newPt}); + } + } + } + + short shape = 0; + for (Point p : ayConnected) { + int localX = p.x - minX; + int localY = p.y - minY; + shape |= 1 << (localY * 4 + localX); + } + Set<Vector2d> doors = new HashSet<>(); + for (Point p : ayConnected) { + for (Vector2d v : door_dirs) { + Vector2d v2 = new Vector2d(p.x + v.x, p.y + v.y); + if (doors.contains(v2)) doors.remove(v2); + else doors.add(v2); + } + } + Point pt2 = dungeonMapLayout.roomPointToMapPoint(ayConnected.iterator().next()); + byte unit1 = MapUtils.getMapColorAt(mapData, pt2.x, pt2.y); + + // 0: none 1: open door 2. unopen door 3: wither door 4. red door + Set<Tuple<Vector2d, EDungeonDoorType>> doorsAndStates = new HashSet<>(); + final int halfWidth = dungeonMapLayout.getUnitRoomSize().width + 4; + for (Vector2d door : doors) { + int floorX = (int) Math.floor(door.x); + int floorY = (int) Math.floor(door.y); + Point mapPt = dungeonMapLayout.roomPointToMapPoint(new Point(floorX, floorY)); + Point target = new Point(mapPt.x + dungeonMapLayout.getUnitRoomSize().width / 2 + (int) (halfWidth * (door.x - floorX)), mapPt.y + + dungeonMapLayout.getUnitRoomSize().height / 2 + (int) (halfWidth * (door.y - floorY))); + MapUtils.record(mapData, target.x, target.y, Color.green); + + byte color = MapUtils.getMapColorAt(mapData, target.x, target.y); + + Vector2d vector2d = new Vector2d(door.x - minX, door.y - minY); + + if (color == 0) { + doorsAndStates.add(new Tuple<>(vector2d, EDungeonDoorType.NONE)); + } else if (color == 85) { + doorsAndStates.add(new Tuple<>(vector2d, EDungeonDoorType.UNOPEN)); + } else if (color == 119) { + doorsAndStates.add(new Tuple<>(vector2d, EDungeonDoorType.WITHER)); + } else if (color == 18 && unit1 != 18) { + doorsAndStates.add(new Tuple<>(vector2d, EDungeonDoorType.BLOOD)); + } else { + doorsAndStates.add(new Tuple<>(vector2d, EDungeonDoorType.ENTRANCE)); + } + + } + + + return new DungeonRoom(ayConnected, shape, unit1, dungeonMapLayout.roomPointToWorldPoint(new Point(minX, minY)), dungeonMapLayout.roomPointToWorldPoint(new Point(maxX + 1, maxY + 1)).add(-1, 0, -1), context, doorsAndStates); + + } + + private boolean checkIfConnected(byte[] mapData, Point unitPoint1, Point unitPoint2) { + if (unitPoint1 == unitPoint2) return true; + if (unitPoint1.equals(unitPoint2)) return true; + + + Point high; + if (unitPoint2.y > unitPoint1.y) { + high = unitPoint2; + } else { + if (unitPoint2.x > unitPoint1.x) { + high = unitPoint2; + } else { + high = unitPoint1; + } + } + + Point low; + if (high == unitPoint2) { + low = unitPoint1; + } else { + low = unitPoint2; + } + + int xOff = low.x - high.x; + int yOff = low.y - high.y; + Point pt = dungeonMapLayout.roomPointToMapPoint(high); + Point pt2 = dungeonMapLayout.roomPointToMapPoint(low); + byte unit1 = MapUtils.getMapColorAt(mapData, pt.x, pt.y); + byte unit2 = MapUtils.getMapColorAt(mapData, pt2.x, pt2.y); + pt.translate(xOff, yOff); + byte unit3 = MapUtils.getMapColorAt(mapData, pt.x, pt.y); + + return unit1 == unit2 && unit2 == unit3 && unit1 != 0; + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/map/MapPlayerProcessor.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/map/MapPlayerProcessor.java new file mode 100755 index 00000000..29f39a08 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/map/MapPlayerProcessor.java @@ -0,0 +1,177 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2023 cyoung06 (syeyoung) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.dungeon.map; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import kr.syeyoung.dungeonsguide.mod.DungeonsGuide; +import kr.syeyoung.dungeonsguide.mod.chat.ChatTransmitter; +import kr.syeyoung.dungeonsguide.mod.dungeon.DungeonContext; +import lombok.Getter; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemMap; +import net.minecraft.item.ItemStack; +import net.minecraft.util.*; +import net.minecraft.world.storage.MapData; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.awt.*; +import java.util.*; + +public class MapPlayerProcessor { + + private static final Minecraft mc = Minecraft.getMinecraft(); + private final DungeonContext context; + @Getter + private final BiMap<String, String> mapIconToPlayerMap = HashBiMap.create(); + Logger logger = LogManager.getLogger("DG-MapPlayerProcessor"); + /** + * If the player on the map is closer than value this it won't save it + * this should be done with render-distance but whateva + */ + int clossnessDistance = 50; + private int waitDelay = 0; + + public MapPlayerProcessor(DungeonContext context) { + this.context = context; + } + + private static void error(String prefix) { + ChatTransmitter.addToQueue(new ChatComponentText(ChatTransmitter.prefix + prefix)); + } + + + + public void tick() { + if (waitDelay < 5) { + waitDelay++; + return; + } + ItemStack stack = Minecraft.getMinecraft().thePlayer.inventory.getStackInSlot(8); + + if (stack == null || !(stack.getItem() instanceof ItemMap)) { + return; + } + + MapData mapData = ((ItemMap) stack.getItem()).getMapData(stack, mc.theWorld); + + if (mapData != null && mapIconToPlayerMap.size() < context.getPlayers().size()) { + getPlayersFromMap(mapData); + } + + } + + + private void getPlayersFromMap(MapData mapdata) { + + if (DungeonsGuide.getDungeonsGuide().verbose) logger.info("Getting players from map"); + + if (context.getScaffoldParser() == null) return; + for (Map.Entry<String, Vec4b> stringVec4bEntry : mapdata.mapDecorations.entrySet()) { + String mapDecString = stringVec4bEntry.getKey(); + Vec4b vec4 = stringVec4bEntry.getValue(); + + if (!mapIconToPlayerMap.containsValue(mapDecString)) { + if (DungeonsGuide.getDungeonsGuide().verbose) logger.info("mapIconToPlayerMap dosent have Player"); + + int x = vec4.func_176112_b() / 2 + 64; + int y = vec4.func_176113_c() / 2 + 64; + BlockPos mapPos = context.getScaffoldParser().getDungeonMapLayout().mapPointToWorldPoint(new Point(x, y)); + String potentialPlayer = null; + + for (String player : context.getPlayers()) { + if (DungeonsGuide.getDungeonsGuide().verbose) + logger.info("Player: {} isNear: {} ", player, isPlayerNear(player, mapPos)); +// if (!mapIconToPlayerMap.containsKey(player) && isPlayerNear(player, mapPos)) { + if (!mapIconToPlayerMap.containsKey(player)) { + if (DungeonsGuide.getDungeonsGuide().verbose) logger.info("Potential profile is: " + player); + potentialPlayer = player; + break; + } + } + + + if (potentialPlayer != null) { + if (DungeonsGuide.getDungeonsGuide().verbose) logger.info("potentialPlayer is not null"); + boolean shouldSave = true; + + for (Map.Entry<String, Vec4b> vec4bEntry : mapdata.mapDecorations.entrySet()) { +// String aaa = vec4bEntry.getKey(); + Vec4b bbb = vec4bEntry.getValue(); + +// if (mapIconToPlayerMap.containsValue(aaa) || mapDecString.equals(aaa)) { +// shouldSave = false; +// break; +// } +// else { + int x2 = bbb.func_176112_b() / 2 + 64; + int y2 = bbb.func_176113_c() / 2 + 64; + int dx = x2 - x; + int dy = y2 - y; + if (dx * dx + dy * dy < clossnessDistance) { + shouldSave = false; + break; + } +// } + } + + if (shouldSave) { + if (DungeonsGuide.getDungeonsGuide().verbose) + logger.info("added {} to mapIconPlayerMap with {}", potentialPlayer, stringVec4bEntry.getKey()); + if (mapIconToPlayerMap.containsKey(potentialPlayer)) { + mapIconToPlayerMap.replace(potentialPlayer, stringVec4bEntry.getKey()); + } else { + mapIconToPlayerMap.put(potentialPlayer, stringVec4bEntry.getKey()); + } + if (DungeonsGuide.getDungeonsGuide().verbose) logger.info("mapIconToPlayerMap:"); + if (DungeonsGuide.getDungeonsGuide().verbose) + mapIconToPlayerMap.forEach((key, value) -> logger.info(" {}: {}", key, value)); + } else { + if (DungeonsGuide.getDungeonsGuide().verbose) logger.info("shouldSave is false"); + } + + + } else { + if (DungeonsGuide.getDungeonsGuide().verbose) logger.info("potentialPlayer is null"); + } + + } else { + if (DungeonsGuide.getDungeonsGuide().verbose) logger.info("mapIconToPlayerMap has player "); + } + } + + + } + + private boolean isPlayerNear(String player, BlockPos mapPos) { + EntityPlayer entityPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(player); + + if (entityPlayer != null && !entityPlayer.isInvisible()) { + BlockPos pos = entityPlayer.getPosition(); + int dx = mapPos.getX() - pos.getX(); + int dz = mapPos.getZ() - pos.getZ(); + return dx * dx + dz * dz < clossnessDistance; + + } + + return false; + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomfinder/DungeonRoom.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomfinder/DungeonRoom.java index f57e1d24..809f7272 100755 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomfinder/DungeonRoom.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomfinder/DungeonRoom.java @@ -23,11 +23,15 @@ import kr.syeyoung.dungeonsguide.dungeon.data.DungeonRoomInfo; import kr.syeyoung.dungeonsguide.dungeon.mechanics.DungeonRoomDoor; import kr.syeyoung.dungeonsguide.dungeon.mechanics.dunegonmechanic.DungeonMechanic; import kr.syeyoung.dungeonsguide.mod.DungeonsGuide; +import kr.syeyoung.dungeonsguide.mod.chat.ChatTransmitter; import kr.syeyoung.dungeonsguide.mod.dungeon.DungeonContext; -import kr.syeyoung.dungeonsguide.mod.dungeon.MapProcessor; import kr.syeyoung.dungeonsguide.mod.dungeon.doorfinder.DungeonDoor; import kr.syeyoung.dungeonsguide.mod.dungeon.doorfinder.EDungeonDoorType; +import kr.syeyoung.dungeonsguide.mod.dungeon.events.SerializableBlockPos; +import kr.syeyoung.dungeonsguide.mod.dungeon.events.impl.DungeonRoomDiscoverEvent; +import kr.syeyoung.dungeonsguide.mod.dungeon.events.impl.DungeonRoomMatchEvent; import kr.syeyoung.dungeonsguide.mod.dungeon.events.impl.DungeonStateChangeEvent; +import kr.syeyoung.dungeonsguide.mod.dungeon.map.DungeonRoomScaffoldParser; import kr.syeyoung.dungeonsguide.mod.dungeon.pathfinding.*; import kr.syeyoung.dungeonsguide.mod.dungeon.roomedit.EditingContext; import kr.syeyoung.dungeonsguide.mod.dungeon.roomprocessor.ProcessorFactory; @@ -53,14 +57,11 @@ import javax.vecmath.Vector2d; import java.awt.*; import java.util.List; import java.util.*; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; @Getter public class DungeonRoom { - private final List<Point> unitPoints; + private final Set<Point> unitPoints; private final short shape; private final byte color; @@ -97,7 +98,7 @@ public class DungeonRoom { } public void setCurrentState(RoomState currentState) { - context.createEvent(new DungeonStateChangeEvent(unitPoints.get(0), dungeonRoomInfo.getName(), this.currentState, currentState)); + context.getRecorder().createEvent(new DungeonStateChangeEvent(unitPoints.iterator().next(), dungeonRoomInfo.getName(), this.currentState, currentState)); this.currentState = currentState; } @@ -152,6 +153,7 @@ public class DungeonRoom { }, 0, TimeUnit.MILLISECONDS); } } + private static final ExecutorService roomMatcherThread = Executors.newSingleThreadExecutor( DungeonsGuide.THREAD_FACTORY); private static final ScheduledExecutorService asyncPathFinder = Executors.newScheduledThreadPool(4, DungeonsGuide.THREAD_FACTORY); @Getter @@ -169,7 +171,7 @@ public class DungeonRoom { private RoomProcessor roomProcessor; - public DungeonRoom(List<Point> points, short shape, byte color, BlockPos min, BlockPos max, DungeonContext context, Set<Tuple<Vector2d, EDungeonDoorType>> doorsAndStates) { + public DungeonRoom(Set<Point> points, short shape, byte color, BlockPos min, BlockPos max, DungeonContext context, Set<Tuple<Vector2d, EDungeonDoorType>> doorsAndStates) { this.unitPoints = points; this.shape = shape; this.color = color; @@ -200,18 +202,45 @@ public class DungeonRoom { arr = new long[lenx *leny * lenz * 2 / 8];; buildDoors(doorsAndStates); - buildRoom(); nodeProcessorDungeonRoom = new NodeProcessorDungeonRoom(this); - updateRoomProcessor(); - + roomMatcherThread.submit(() -> { + try { + matchRoomAndSetupRoomProcessor(); + matched = true; + } catch (Exception e) { + e.printStackTrace(); + } + }); + } + private volatile boolean matched = false; + private volatile boolean matching = false; + + public void tryRematch() { + if (matched) return; + if (matching )return; + matching = true; + roomMatcherThread.submit(() -> { + try { + matchRoomAndSetupRoomProcessor(); + matched = true; + } catch (Exception e) { + e.printStackTrace(); + } finally { + matching = false; + } + }); + } + private void matchRoomAndSetupRoomProcessor() { + buildRoom(); + updateRoomProcessor(); } 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<Tuple<Vector2d, EDungeonDoorType>> doorsAndStates) { Set<Tuple<BlockPos, EDungeonDoorType>> positions = new HashSet<>(); - BlockPos pos = context.getMapProcessor().roomPointToWorldPoint(minRoomPt).add(16,0,16); + BlockPos pos = context.getScaffoldParser().getDungeonMapLayout().roomPointToWorldPoint(minRoomPt).add(16,0,16); for (Tuple<Vector2d, EDungeonDoorType> doorsAndState : doorsAndStates) { Vector2d vector2d = doorsAndState.getFirst(); BlockPos neu = pos.add(vector2d.x * 32, 0, vector2d.y * 32); @@ -231,7 +260,19 @@ public class DungeonRoom { if (dungeonRoomInfo == null) { dungeonRoomInfo = roomMatcher.createNew(); if (color == 18) dungeonRoomInfo.setProcessorId("bossroom"); + } else { + context.getRecorder().createEvent(new DungeonRoomMatchEvent(getUnitPoints().iterator().next(), + getRoomMatcher().getRotation(), new SerializableBlockPos(getMin()), + new SerializableBlockPos(getMax()), getShape(), getColor(), + dungeonRoomInfo.getUuid(), + dungeonRoomInfo.getName(), + dungeonRoomInfo.getProcessorId())); } + ChatTransmitter.sendDebugChat(new ChatComponentText("New Map matched! shape: " + getShape() + " color: " +getColor() + " unitPos: " + unitPoints.iterator().next().x + "," + unitPoints.iterator().next().y)); + ChatTransmitter.sendDebugChat(new ChatComponentText("New Map matched! mapMin: " + getMin() + " mapMx: " + getMax())); + ChatTransmitter.sendDebugChat(new ChatComponentText("New Map matched! id: " + dungeonRoomInfo.getUuid() + " name: " + dungeonRoomInfo.getName() +" proc: "+dungeonRoomInfo.getProcessorId())); + + this.dungeonRoomInfo = dungeonRoomInfo; totalSecrets = dungeonRoomInfo.getTotalSecrets(); } @@ -286,8 +327,8 @@ public class DungeonRoom { } public boolean canAccessAbsolute(BlockPos pos) { - MapProcessor mapProcessor = this.context.getMapProcessor(); - Point roomPt = mapProcessor.worldPointToRoomPoint(pos); + DungeonRoomScaffoldParser mapProcessor = this.context.getScaffoldParser(); + Point roomPt = mapProcessor.getDungeonMapLayout().worldPointToRoomPoint(pos); roomPt.translate(-minRoomPt.x, -minRoomPt.y); return (shape >>(roomPt.y *4 +roomPt.x) & 0x1) > 0; diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomfinder/RoomMatcher.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomfinder/RoomMatcher.java index 472f7cb2..bdc6d516 100755 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomfinder/RoomMatcher.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomfinder/RoomMatcher.java @@ -51,6 +51,7 @@ public class RoomMatcher { for (int x = 0; x < xx; x++) { if (x % 8 == 0 && z % 8 == 0 && dungeonRoom.getContext().getWorld().getChunkFromBlockCoords(dungeonRoom.getRelativeBlockPosAt(x, 0, z)).isEmpty()) { ChatTransmitter.sendDebugChat(new ChatComponentText("Chunk Not loaded in Room Matcher")); + throw new IllegalStateException("Chunk not loaded"); } } } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomprocessor/GeneralRoomProcessor.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomprocessor/GeneralRoomProcessor.java index f1dd4901..f2ab49ad 100755 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomprocessor/GeneralRoomProcessor.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomprocessor/GeneralRoomProcessor.java @@ -254,8 +254,8 @@ public class GeneralRoomProcessor implements RoomProcessor { BlockPos pos = Minecraft.getMinecraft().thePlayer.getPosition(); DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); - Point pt1 = context.getMapProcessor().worldPointToRoomPoint(pos.add(2, 0, 2)); - Point pt2 = context.getMapProcessor().worldPointToRoomPoint(pos.add(-2, 0, -2)); + Point pt1 = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(pos.add(2, 0, 2)); + Point pt2 = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(pos.add(-2, 0, -2)); if (!pt1.equals(pt2)) { stack = 0; secrets2 = -1; diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/impl/MapUpdateEvent.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/impl/MapUpdateEvent.java new file mode 100644 index 00000000..d405f402 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/impl/MapUpdateEvent.java @@ -0,0 +1,35 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2021 cyoung06 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.events.impl; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import net.minecraft.network.play.server.S2FPacketSetSlot; +import net.minecraft.network.play.server.S30PacketWindowItems; +import net.minecraft.world.storage.MapData; +import net.minecraftforge.fml.common.eventhandler.Event; + +@Data +@EqualsAndHashCode(callSuper=false) +@AllArgsConstructor +public class MapUpdateEvent extends Event { + private int mapId; + private MapData mapData; +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/DungeonListener.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/DungeonListener.java index d29f1084..99e6ae29 100755 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/DungeonListener.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/DungeonListener.java @@ -46,7 +46,6 @@ import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.passive.EntityBat; -import net.minecraft.scoreboard.Scoreboard; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.BlockPos; import net.minecraft.util.ChatComponentText; @@ -106,11 +105,13 @@ public class DungeonListener { context.getBossfightProcessor().onPostGuiRender(e); } - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); + if (context.getScaffoldParser() != null) { + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); - if (dungeonRoom != null && dungeonRoom.getRoomProcessor() != null) { - dungeonRoom.getRoomProcessor().onPostGuiRender(e); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); + if (dungeonRoom != null && dungeonRoom.getRoomProcessor() != null) { + dungeonRoom.getRoomProcessor().onPostGuiRender(e); + } } } @@ -130,11 +131,13 @@ public class DungeonListener { EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; if (thePlayer == null) return; if (context.getBossfightProcessor() != null) context.getBossfightProcessor().onEntityUpdate(e); - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); + if (context.getScaffoldParser() != null) { + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); - if (dungeonRoom != null && dungeonRoom.getRoomProcessor() != null) { - dungeonRoom.getRoomProcessor().onEntityUpdate(e); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); + if (dungeonRoom != null && dungeonRoom.getRoomProcessor() != null) { + dungeonRoom.getRoomProcessor().onEntityUpdate(e); + } } } } @@ -159,11 +162,13 @@ public class DungeonListener { if (SkyblockStatus.isOnSkyblock()) { DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); if (context != null) { - context.getMapProcessor().tick(); + context.getMapPlayerMarkerProcessor().tick(); context.tick(); } else { if (SkyblockStatus.isOnDungeon()) { - DungeonsGuide.getDungeonsGuide().getDungeonFacade().setContext(new DungeonContext(Minecraft.getMinecraft().thePlayer.worldObj)); + DungeonsGuide.getDungeonsGuide().getDungeonFacade().setContext(new DungeonContext( + SkyblockStatus.locationName, + Minecraft.getMinecraft().thePlayer.worldObj)); MinecraftForge.EVENT_BUS.post(new DungeonStartedEvent()); } } @@ -182,13 +187,14 @@ public class DungeonListener { if (context.getBossfightProcessor() != null) { context.getBossfightProcessor().tick(); } + if (context.getScaffoldParser() != null) { + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); - - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); - if (dungeonRoom != null && dungeonRoom.getRoomProcessor() != null) { - dungeonRoom.getRoomProcessor().tick(); + if (dungeonRoom != null && dungeonRoom.getRoomProcessor() != null) { + dungeonRoom.getRoomProcessor().tick(); + } } } @@ -207,14 +213,16 @@ public class DungeonListener { if (context != null) { EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); if (context.getBossfightProcessor() != null) context.getBossfightProcessor().drawScreen(postRender.partialTicks); - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); - if (dungeonRoom != null) { - if (dungeonRoom.getRoomProcessor() != null) { - dungeonRoom.getRoomProcessor().drawScreen(postRender.partialTicks); + if (context.getScaffoldParser() != null) { + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); + if (dungeonRoom != null) { + if (dungeonRoom.getRoomProcessor() != null) { + dungeonRoom.getRoomProcessor().drawScreen(postRender.partialTicks); + } } } @@ -227,6 +235,16 @@ public class DungeonListener { GlStateManager.enableAlpha(); } + @SubscribeEvent() + public void onMapUpdate(MapUpdateEvent mapUpdateEvent) { + if (!SkyblockStatus.isOnDungeon()) return; + + DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); + + if (context != null) { + context.onMapUpdate(mapUpdateEvent); + } + } @SubscribeEvent(receiveCanceled = true, priority = EventPriority.HIGHEST) public void onChatReceived(ClientChatReceivedEvent clientChatReceivedEvent) { if (!SkyblockStatus.isOnDungeon()) return; @@ -240,8 +258,6 @@ public class DungeonListener { if (context != null) { EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); - context.onChat(clientChatReceivedEvent); if (context.getBossfightProcessor() != null) { @@ -251,26 +267,30 @@ public class DungeonListener { context.getBossfightProcessor().chatReceived(clientChatReceivedEvent.message); } } - - RoomProcessor roomProcessor = null; - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); - if (dungeonRoom != null) { - if (dungeonRoom.getRoomProcessor() != null) { - if (clientChatReceivedEvent.type == 2) { - dungeonRoom.getRoomProcessor().actionbarReceived(clientChatReceivedEvent.message); - roomProcessor = dungeonRoom.getRoomProcessor(); - } else { - dungeonRoom.getRoomProcessor().chatReceived(clientChatReceivedEvent.message); - roomProcessor = dungeonRoom.getRoomProcessor(); + if (context.getScaffoldParser() != null) { + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); + + + RoomProcessor roomProcessor = null; + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); + if (dungeonRoom != null) { + if (dungeonRoom.getRoomProcessor() != null) { + if (clientChatReceivedEvent.type == 2) { + dungeonRoom.getRoomProcessor().actionbarReceived(clientChatReceivedEvent.message); + roomProcessor = dungeonRoom.getRoomProcessor(); + } else { + dungeonRoom.getRoomProcessor().chatReceived(clientChatReceivedEvent.message); + roomProcessor = dungeonRoom.getRoomProcessor(); + } } } - } - if (clientChatReceivedEvent.type == 2) { - return; - } - for (RoomProcessor globalRoomProcessor : context.getGlobalRoomProcessors()) { - if (globalRoomProcessor != roomProcessor) { - globalRoomProcessor.chatReceived(clientChatReceivedEvent.message); + if (clientChatReceivedEvent.type == 2) { + return; + } + for (RoomProcessor globalRoomProcessor : context.getGlobalRoomProcessors()) { + if (globalRoomProcessor != roomProcessor) { + globalRoomProcessor.chatReceived(clientChatReceivedEvent.message); + } } } } @@ -288,9 +308,11 @@ public class DungeonListener { } if (FeatureRegistry.DEBUG.isEnabled()) { - for (DungeonRoom dungeonRoom : context.getDungeonRoomList()) { - for (DungeonDoor door : dungeonRoom.getDoors()) { - RenderUtils.renderDoor(door, renderWorldLastEvent.partialTicks); + if (context.getScaffoldParser() != null) { + for (DungeonRoom dungeonRoom : context.getScaffoldParser().getDungeonRoomList()) { + for (DungeonDoor door : dungeonRoom.getDoors()) { + RenderUtils.renderDoor(door, renderWorldLastEvent.partialTicks); + } } } } @@ -300,29 +322,32 @@ public class DungeonListener { context.getBossfightProcessor().drawWorld(renderWorldLastEvent.partialTicks); } - EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); + if (context.getScaffoldParser() != null) { + EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); - if (dungeonRoom != null) { - if (dungeonRoom.getRoomProcessor() != null) { - dungeonRoom.getRoomProcessor().drawWorld(renderWorldLastEvent.partialTicks); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); + if (dungeonRoom != null) { + if (dungeonRoom.getRoomProcessor() != null) { + dungeonRoom.getRoomProcessor().drawWorld(renderWorldLastEvent.partialTicks); + } } - } - if (FeatureRegistry.DEBUG.isEnabled() && dungeonRoom != null) { - Vec3 player = Minecraft.getMinecraft().thePlayer.getPositionVector(); - BlockPos real = new BlockPos(player.xCoord * 2, player.yCoord * 2, player.zCoord * 2); - for (BlockPos allInBox : BlockPos.getAllInBox(real.add(-1, -1, -1), real.add(1, 1, 1))) { - boolean blocked = dungeonRoom.isBlocked(allInBox.getX(), allInBox.getY(), allInBox.getZ()); + if (FeatureRegistry.DEBUG.isEnabled() && dungeonRoom != null) { + + Vec3 player = Minecraft.getMinecraft().thePlayer.getPositionVector(); + BlockPos real = new BlockPos(player.xCoord * 2, player.yCoord * 2, player.zCoord * 2); + for (BlockPos allInBox : BlockPos.getAllInBox(real.add(-1, -1, -1), real.add(1, 1, 1))) { + boolean blocked = dungeonRoom.isBlocked(allInBox.getX(), allInBox.getY(), allInBox.getZ()); - RenderUtils.highlightBox( - AxisAlignedBB.fromBounds( - allInBox.getX() / 2.0 - 0.1, allInBox.getY() / 2.0 - 0.1, allInBox.getZ() / 2.0 - 0.1, - allInBox.getX() / 2.0 + 0.1, allInBox.getY() / 2.0 + 0.1, allInBox.getZ() / 2.0 + 0.1 - ), blocked ? new Color(0x55FF0000, true) : new Color(0x3300FF00, true), renderWorldLastEvent.partialTicks, false); + RenderUtils.highlightBox( + AxisAlignedBB.fromBounds( + allInBox.getX() / 2.0 - 0.1, allInBox.getY() / 2.0 - 0.1, allInBox.getZ() / 2.0 - 0.1, + allInBox.getX() / 2.0 + 0.1, allInBox.getY() / 2.0 + 0.1, allInBox.getZ() / 2.0 + 0.1 + ), blocked ? new Color(0x55FF0000, true) : new Color(0x3300FF00, true), renderWorldLastEvent.partialTicks, false); + } } } @@ -355,15 +380,17 @@ public class DungeonListener { if (DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext() != null) { EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); if (context.getBossfightProcessor() != null) { context.getBossfightProcessor().onKeybindPress(keyInputEvent); } - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); - if (dungeonRoom != null) { - if (dungeonRoom.getRoomProcessor() != null) { - dungeonRoom.getRoomProcessor().onKeybindPress(keyInputEvent); + if (context.getScaffoldParser() != null) { + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); + if (dungeonRoom != null) { + if (dungeonRoom.getRoomProcessor() != null) { + dungeonRoom.getRoomProcessor().onKeybindPress(keyInputEvent); + } } } } @@ -377,35 +404,22 @@ public class DungeonListener { if (DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext() != null) { EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); if (context.getBossfightProcessor() != null) { context.getBossfightProcessor().onInteract(interact); } - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); - if (dungeonRoom != null) { - if (dungeonRoom.getRoomProcessor() != null) { - dungeonRoom.getRoomProcessor().onInteract(interact); + if (context.getScaffoldParser() != null) { + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); + if (dungeonRoom != null) { + if (dungeonRoom.getRoomProcessor() != null) { + dungeonRoom.getRoomProcessor().onInteract(interact); + } } } } } - - String getCurrentRoomName(){ - EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; - - DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(player.getPosition()); - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); - String in = "unknown"; - if (dungeonRoom != null){ - in = dungeonRoom.getDungeonRoomInfo().getName(); - } - - return in; - } - @SubscribeEvent public void onBlockChange(BlockUpdateEvent.Post postInteract) { if (!SkyblockStatus.isOnDungeon()) return; @@ -416,15 +430,18 @@ public class DungeonListener { if (DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext() != null) { EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); if (context.getBossfightProcessor() != null) { context.getBossfightProcessor().onBlockUpdate(postInteract); } - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); - if (dungeonRoom != null) { - if (dungeonRoom.getRoomProcessor() != null) { - dungeonRoom.getRoomProcessor().onBlockUpdate(postInteract); + if (context.getScaffoldParser() != null) { + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); + + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); + if (dungeonRoom != null) { + if (dungeonRoom.getRoomProcessor() != null) { + dungeonRoom.getRoomProcessor().onBlockUpdate(postInteract); + } } } } @@ -441,21 +458,23 @@ public class DungeonListener { return; } EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); + if (context.getScaffoldParser() != null) { + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); - if (dungeonRoom == null) { - ChatTransmitter.addToQueue(new ChatComponentText("Can't determine the dungeon room you're in")); - return; - } + if (dungeonRoom == null) { + ChatTransmitter.addToQueue(new ChatComponentText("Can't determine the dungeon room you're in")); + return; + } - if (EditingContext.getEditingContext() != null) { - ChatTransmitter.addToQueue(new ChatComponentText("There is an editing session currently open.")); - return; - } + if (EditingContext.getEditingContext() != null) { + ChatTransmitter.addToQueue(new ChatComponentText("There is an editing session currently open.")); + return; + } - EditingContext.createEditingContext(dungeonRoom); - EditingContext.getEditingContext().openGui(new GuiDungeonRoomEdit(dungeonRoom)); + EditingContext.createEditingContext(dungeonRoom); + EditingContext.getEditingContext().openGui(new GuiDungeonRoomEdit(dungeonRoom)); + } } else ec.reopen(); } } @@ -469,16 +488,18 @@ public class DungeonListener { if (context != null) { EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); if (context.getBossfightProcessor() != null) { context.getBossfightProcessor().onInteractBlock(keyInputEvent); } - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); - if (dungeonRoom != null) { - if (dungeonRoom.getRoomProcessor() != null) { - dungeonRoom.getRoomProcessor().onInteractBlock(keyInputEvent); + if (context.getScaffoldParser() != null) { + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); + if (dungeonRoom != null) { + if (dungeonRoom.getRoomProcessor() != null) { + dungeonRoom.getRoomProcessor().onInteractBlock(keyInputEvent); + } } } } @@ -504,15 +525,17 @@ public class DungeonListener { if (DungeonsGuide.getDungeonsGuide().getDungeonFacade() != null) { EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); if (context.getBossfightProcessor() != null) { context.getBossfightProcessor().onEntityDeath(deathEvent); } - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); - if (dungeonRoom != null) { - if (dungeonRoom.getRoomProcessor() != null) { - dungeonRoom.getRoomProcessor().onEntityDeath(deathEvent); + if (context.getScaffoldParser() != null) { + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); + if (dungeonRoom != null) { + if (dungeonRoom.getRoomProcessor() != null) { + dungeonRoom.getRoomProcessor().onEntityDeath(deathEvent); + } } } } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/PacketInjector.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/PacketInjector.java index a18a3641..f3df018a 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/PacketInjector.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/PacketInjector.java @@ -47,6 +47,7 @@ public class PacketInjector extends ChannelDuplexHandler { targettedPackets.add(S3CPacketUpdateScore.class); targettedPackets.add(S3DPacketDisplayScoreboard.class); targettedPackets.add(S3EPacketTeams.class); + targettedPackets.add(S34PacketMaps.class); } @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/PacketListener.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/PacketListener.java index 2012f129..5ef43e8c 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/PacketListener.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/events/listener/PacketListener.java @@ -22,6 +22,7 @@ import kr.syeyoung.dungeonsguide.mod.DungeonsGuide; import kr.syeyoung.dungeonsguide.mod.SkyblockStatus; import kr.syeyoung.dungeonsguide.mod.events.impl.*; import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; +import kr.syeyoung.dungeonsguide.mod.parallelUniverse.map.MapDataManager; import kr.syeyoung.dungeonsguide.mod.parallelUniverse.scoreboard.Objective; import kr.syeyoung.dungeonsguide.mod.parallelUniverse.scoreboard.ScoreboardManager; import kr.syeyoung.dungeonsguide.mod.parallelUniverse.tab.TabList; @@ -34,6 +35,7 @@ import net.minecraft.network.Packet; import net.minecraft.network.play.server.*; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.Tuple; +import net.minecraft.world.storage.MapData; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -77,6 +79,10 @@ public class PacketListener { MinecraftForge.EVENT_BUS.post(new TitleEvent((S45PacketTitle) packet)); } else if (packet instanceof S38PacketPlayerListItem) { MinecraftForge.EVENT_BUS.post(new PlayerListItemPacketEvent((S38PacketPlayerListItem) packet)); + }else if (packet instanceof S34PacketMaps) { + MapData mapData = MapDataManager.INSTANCE.createMapData(((S34PacketMaps) packet).getMapId()); + ((S34PacketMaps) packet).setMapdataTo(mapData); + MinecraftForge.EVENT_BUS.post(new MapUpdateEvent(((S34PacketMaps) packet).getMapId(), mapData)); } } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureDebugTrap.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureDebugTrap.java index b76e88aa..738e97fd 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureDebugTrap.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureDebugTrap.java @@ -68,7 +68,7 @@ public class FeatureDebugTrap extends TextHUDFeature { @Override public boolean isHUDViewable() { - return skyblockStatus.isOnDungeon() && DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext() != null && DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getMapProcessor() != null; + return skyblockStatus.isOnDungeon() && DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext() != null; } @Override diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureRoomCoordDisplay.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureRoomCoordDisplay.java index 9088668c..f59e3187 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureRoomCoordDisplay.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureRoomCoordDisplay.java @@ -65,8 +65,9 @@ public class FeatureRoomCoordDisplay extends TextHUDFeature { if (context == null) return false; EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); + if (context.getScaffoldParser() == null) return false; + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); if (dungeonRoom == null) { return false; } @@ -85,8 +86,8 @@ public class FeatureRoomCoordDisplay extends TextHUDFeature { if (context == null) return Collections.emptyList(); EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); if (dungeonRoom == null) { return Collections.emptyList(); } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureRoomDebugInfo.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureRoomDebugInfo.java index 7efd966b..e2908a18 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureRoomDebugInfo.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureRoomDebugInfo.java @@ -77,8 +77,9 @@ public class FeatureRoomDebugInfo extends TextHUDFeature { DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); if (context == null) return Collections.emptyList(); EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); + if (context.getScaffoldParser() == null) return Collections.emptyList(); + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; String str = ""; diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/boss/FeatureWarningOnPortal.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/boss/FeatureWarningOnPortal.java index e9eb80f5..35607d58 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/boss/FeatureWarningOnPortal.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/boss/FeatureWarningOnPortal.java @@ -112,9 +112,9 @@ public class FeatureWarningOnPortal extends SimpleFeature implements StyledTextP DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); FeatureDungeonScore.ScoreCalculation scoreCalculation = FeatureRegistry.DUNGEON_SCORE.calculateScore(); - boolean failed = context.getDungeonRoomList().stream().anyMatch(a -> a.getCurrentState() == DungeonRoom.RoomState.FAILED); - if (context.getMapProcessor().getUndiscoveredRoom() > 0) { - texts.add(new StyledText("There are at least "+context.getMapProcessor().getUndiscoveredRoom()+" undiscovered rooms!\n", "warning")); + boolean failed = context.getScaffoldParser().getDungeonRoomList().stream().anyMatch(a -> a.getCurrentState() == DungeonRoom.RoomState.FAILED); + if (context.getScaffoldParser().getUndiscoveredRoom() > 0) { + texts.add(new StyledText("There are at least "+context.getScaffoldParser().getUndiscoveredRoom()+" undiscovered rooms!\n", "warning")); } else if (failed) { texts.add(new StyledText("There is a failed puzzle room! Yikes!\n", "warning")); } else if (!scoreCalculation.isFullyCleared()) { diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureCollectScore.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureCollectScore.java index f9ea3a49..8462881e 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureCollectScore.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureCollectScore.java @@ -19,6 +19,7 @@ package kr.syeyoung.dungeonsguide.mod.features.impl.dungeon; import kr.syeyoung.dungeonsguide.mod.DungeonsGuide; +import kr.syeyoung.dungeonsguide.mod.SkyblockStatus; import kr.syeyoung.dungeonsguide.mod.chat.ChatTransmitter; import kr.syeyoung.dungeonsguide.mod.dungeon.DungeonContext; import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; @@ -52,7 +53,7 @@ public class FeatureCollectScore extends SimpleFeature { .put("completionStage", context.getBossRoomEnterSeconds() == -1 ? 0 : context.isDefeated() ? 2 : 1) .put("percentage", DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getPercentage() / 100.0) - .put("floor", DungeonContext.getDungeonName()); + .put("floor", SkyblockStatus.locationName); ChatTransmitter.sendDebugChat(new ChatComponentText(payload.toString())); if(!StompManager.getInstance().isStompConnected()){ diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonDeaths.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonDeaths.java index 5534fffb..f2fdaaf1 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonDeaths.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonDeaths.java @@ -26,22 +26,22 @@ import kr.syeyoung.dungeonsguide.mod.config.types.AColor; import kr.syeyoung.dungeonsguide.mod.dungeon.DungeonContext; import kr.syeyoung.dungeonsguide.mod.dungeon.events.impl.DungeonDeathEvent; import kr.syeyoung.dungeonsguide.mod.events.annotations.DGEventHandler; +import kr.syeyoung.dungeonsguide.mod.events.impl.DungeonEndedEvent; +import kr.syeyoung.dungeonsguide.mod.events.impl.DungeonLeftEvent; import kr.syeyoung.dungeonsguide.mod.features.text.StyledText; import kr.syeyoung.dungeonsguide.mod.features.text.TextHUDFeature; import kr.syeyoung.dungeonsguide.mod.features.text.TextStyle; import kr.syeyoung.dungeonsguide.mod.parallelUniverse.tab.TabList; import kr.syeyoung.dungeonsguide.mod.parallelUniverse.tab.TabListEntry; import kr.syeyoung.dungeonsguide.mod.utils.TextUtils; +import lombok.Getter; import net.minecraft.client.Minecraft; import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.scoreboard.ScorePlayerTeam; import net.minecraft.util.ChatComponentText; import net.minecraftforge.client.event.ClientChatReceivedEvent; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -73,14 +73,15 @@ public class FeatureDungeonDeaths extends TextHUDFeature { public List<String> getUsedTextStyle() { return Arrays.asList("username", "separator", "deaths", "total", "totalDeaths"); } + @Getter + private final Map<String, Integer> deaths = new HashMap<>(); @Override public List<StyledText> getText() { List<StyledText> text= new ArrayList<StyledText>(); - DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); - Map<String, Integer> deaths = context.getDeaths(); + Map<String, Integer> deaths = getDeaths(); int i = 0; int deathsCnt = 0; for (Map.Entry<String, Integer> death:deaths.entrySet()) { @@ -136,7 +137,7 @@ public class FeatureDungeonDeaths extends TextHUDFeature { DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); if (context == null) return 0; int d = 0; - for (Integer value : context.getDeaths().values()) { + for (Integer value : getDeaths().values()) { d += value; } return d; @@ -145,6 +146,10 @@ public class FeatureDungeonDeaths extends TextHUDFeature { Pattern deathPattern = Pattern.compile("§r§c ☠ (.+?)§r§7 .+and became a ghost.+"); Pattern meDeathPattern = Pattern.compile("§r§c ☠ §r§7You .+and became a ghost.+"); + @DGEventHandler(ignoreDisabled = true) + public void onDungeonEnd(DungeonLeftEvent dungeonEndedEvent) { + this.deaths.clear(); + } @DGEventHandler() public void onChat(ClientChatReceivedEvent clientChatReceivedEvent) { if (clientChatReceivedEvent.type == 2) return; @@ -156,17 +161,17 @@ public class FeatureDungeonDeaths extends TextHUDFeature { Matcher m = deathPattern.matcher(txt); if (m.matches()) { String nickname = TextUtils.stripColor(m.group(1)); - int deaths = context.getDeaths().getOrDefault(nickname, 0); - context.getDeaths().put(nickname, deaths + 1); - context.createEvent(new DungeonDeathEvent(nickname, txt, deaths)); + int deaths = getDeaths().getOrDefault(nickname, 0); + getDeaths().put(nickname, deaths + 1); + context.getRecorder().createEvent(new DungeonDeathEvent(nickname, txt, deaths)); ChatTransmitter.sendDebugChat(new ChatComponentText("Death verified :: "+nickname+" / "+(deaths + 1))); } Matcher m2 = meDeathPattern.matcher(txt); if (m2.matches()) { String nickname = "me"; - int deaths = context.getDeaths().getOrDefault(nickname, 0); - context.getDeaths().put(nickname, deaths + 1); - context.createEvent(new DungeonDeathEvent(Minecraft.getMinecraft().thePlayer.getName(), txt, deaths)); + int deaths = getDeaths().getOrDefault(nickname, 0); + getDeaths().put(nickname, deaths + 1); + context.getRecorder().createEvent(new DungeonDeathEvent(Minecraft.getMinecraft().thePlayer.getName(), txt, deaths)); ChatTransmitter.sendDebugChat(new ChatComponentText("Death verified :: me / "+(deaths + 1))); } } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonMap.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonMap.java index 36e0afaf..51664280 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonMap.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonMap.java @@ -24,7 +24,7 @@ import kr.syeyoung.dungeonsguide.mod.DungeonsGuide; import kr.syeyoung.dungeonsguide.mod.chat.ChatTransmitter; import kr.syeyoung.dungeonsguide.mod.config.types.AColor; import kr.syeyoung.dungeonsguide.mod.dungeon.DungeonContext; -import kr.syeyoung.dungeonsguide.mod.dungeon.MapProcessor; +import kr.syeyoung.dungeonsguide.mod.dungeon.map.DungeonRoomScaffoldParser; import kr.syeyoung.dungeonsguide.mod.dungeon.roomfinder.DungeonRoom; import kr.syeyoung.dungeonsguide.mod.events.annotations.DGEventHandler; import kr.syeyoung.dungeonsguide.mod.events.impl.BossroomEnterEvent; @@ -52,11 +52,9 @@ import net.minecraft.entity.player.EnumPlayerModelParts; import net.minecraft.scoreboard.ScorePlayerTeam; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.Tuple; import net.minecraft.util.Vec4b; import net.minecraft.world.WorldSettings; import net.minecraft.world.storage.MapData; -import org.jetbrains.annotations.Nullable; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL14; @@ -129,9 +127,9 @@ public class FeatureDungeonMap extends RawRenderingGuiFeature { if (!DungeonsGuide.getDungeonsGuide().getSkyblockStatus().isOnDungeon()) return; DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); - if (context == null || !context.getMapProcessor().isInitialized()) return; + if (context == null || context.getScaffoldParser() == null) return; + DungeonRoomScaffoldParser mapProcessor = context.getScaffoldParser(); - MapProcessor mapProcessor = context.getMapProcessor(); MapData mapData = mapProcessor.getLatestMapData(); Rectangle featureRect = getFeatureRect().getRectangle(); Gui.drawRect(0, 0, featureRect.width, featureRect.height, RenderUtils.getColorAt(featureRect.x, featureRect.y, backgroudColor)); @@ -150,7 +148,7 @@ public class FeatureDungeonMap extends RawRenderingGuiFeature { @Override public void drawDemo(float partialTicks) { DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); - if (DungeonsGuide.getDungeonsGuide().getSkyblockStatus().isOnDungeon() && context != null && context.getMapProcessor().isInitialized() && on) { + if (DungeonsGuide.getDungeonsGuide().getSkyblockStatus().isOnDungeon() && context != null && context.getScaffoldParser() != null && on) { drawHUD(partialTicks); return; } @@ -166,7 +164,7 @@ public class FeatureDungeonMap extends RawRenderingGuiFeature { RenderUtils.drawUnfilledBox(0, 0, featureRect.width, featureRect.height, this.<AColor>getParameter("border_color").getValue()); } - public void renderMap(float partialTicks, MapProcessor mapProcessor, MapData mapData, DungeonContext context) { + public void renderMap(float partialTicks, DungeonRoomScaffoldParser mapProcessor, MapData mapData, DungeonContext context) { EntityPlayer p = Minecraft.getMinecraft().thePlayer; float postScale = this.centerMapOnPlayer ? postscaleOfMap : 1; @@ -180,7 +178,7 @@ public class FeatureDungeonMap extends RawRenderingGuiFeature { GlStateManager.scale(scale, scale, 0); GlStateManager.scale(postScale, postScale, 0); - Vector2d pt = mapProcessor.worldPointToMapPointFLOAT(p.getPositionEyes(partialTicks)); + Vector2d pt = mapProcessor.getDungeonMapLayout().worldPointToMapPointFLOAT(p.getPositionEyes(partialTicks)); double yaw = p.rotationYaw; if (this.centerMapOnPlayer) { if (this.shouldRotateWithPlayer) { @@ -191,7 +189,7 @@ public class FeatureDungeonMap extends RawRenderingGuiFeature { GlStateManager.translate(-64, -64, 0); } - updateMapTexture(mapData.colors, mapProcessor, context.getDungeonRoomList()); + updateMapTexture(mapData.colors, mapProcessor, mapProcessor.getDungeonRoomList()); render(); @@ -208,11 +206,11 @@ public class FeatureDungeonMap extends RawRenderingGuiFeature { FontRenderer fr = getFontRenderer(); if (this.showSecretCount) { - for (DungeonRoom dungeonRoom : context.getDungeonRoomList()) { + for (DungeonRoom dungeonRoom : mapProcessor.getDungeonRoomList()) { GlStateManager.pushMatrix(); - Point mapPt = mapProcessor.roomPointToMapPoint(dungeonRoom.getUnitPoints().get(0)); - GlStateManager.translate(mapPt.x + mapProcessor.getUnitRoomDimension().width / 2d, mapPt.y + mapProcessor.getUnitRoomDimension().height / 2d, 0); + Point mapPt = mapProcessor.getDungeonMapLayout().roomPointToMapPoint(dungeonRoom.getUnitPoints().iterator().next()); + GlStateManager.translate(mapPt.x + mapProcessor.getDungeonMapLayout().getUnitRoomSize().width / 2d, mapPt.y + mapProcessor.getDungeonMapLayout().getUnitRoomSize().height / 2d, 0); if (this.centerMapOnPlayer && this.shouldRotateWithPlayer) { GlStateManager.rotate((float) (yaw - 180), 0, 0, 1); @@ -266,7 +264,7 @@ public class FeatureDungeonMap extends RawRenderingGuiFeature { private final ResourceLocation generatedMapTexture = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation("dungeonmap/map", mapTexture); private final int[] mapTextureData = mapTexture.getTextureData(); - private void updateMapTexture(byte[] colors, MapProcessor mapProcessor, List<DungeonRoom> dungeonRooms) { + private void updateMapTexture(byte[] colors, DungeonRoomScaffoldParser mapProcessor, List<DungeonRoom> dungeonRooms) { if(shouldCacheMap){ if(!didMapChange(dungeonRooms)){ @@ -288,10 +286,10 @@ public class FeatureDungeonMap extends RawRenderingGuiFeature { if (this.showSecretCount) { for (DungeonRoom dungeonRoom : dungeonRooms) { for (Point pt : dungeonRoom.getUnitPoints()) { - for (int y1 = 0; y1 < mapProcessor.getUnitRoomDimension().height; y1++) { - for (int x1 = 0; x1 < mapProcessor.getUnitRoomDimension().width; x1++) { - int x = MathHelper.clamp_int(pt.x * (mapProcessor.getUnitRoomDimension().width + mapProcessor.getDoorDimensions().height) + x1 + mapProcessor.getTopLeftMapPoint().x, 0, 128); - int y = MathHelper.clamp_int(pt.y * (mapProcessor.getUnitRoomDimension().height + mapProcessor.getDoorDimensions().height) + y1 + mapProcessor.getTopLeftMapPoint().y, 0, 128); + for (int y1 = 0; y1 < mapProcessor.getDungeonMapLayout().getUnitRoomSize().height; y1++) { + for (int x1 = 0; x1 < mapProcessor.getDungeonMapLayout().getUnitRoomSize().width; x1++) { + int x = MathHelper.clamp_int(pt.x * (mapProcessor.getDungeonMapLayout().getUnitRoomSize().width + mapProcessor.getDungeonMapLayout().getMapRoomGap()) + x1 + mapProcessor.getDungeonMapLayout().getOriginPoint().x, 0, 128); + int y = MathHelper.clamp_int(pt.y * (mapProcessor.getDungeonMapLayout().getUnitRoomSize().height + mapProcessor.getDungeonMapLayout().getMapRoomGap()) + y1 + mapProcessor.getDungeonMapLayout().getOriginPoint().y, 0, 128); int i = y * 128 + x; int j = dungeonRoom.getColor(); @@ -354,7 +352,7 @@ public class FeatureDungeonMap extends RawRenderingGuiFeature { } - private void renderHeads(MapProcessor mapProcessor, MapData mapData, float scale, float postScale, float partialTicks) { + private void renderHeads(DungeonRoomScaffoldParser mapProcessor, MapData mapData, float scale, float postScale, float partialTicks) { EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; Set<TabListEntry> playerList = getPlayerListCached(); @@ -376,7 +374,7 @@ public class FeatureDungeonMap extends RawRenderingGuiFeature { if (entityplayer != null && (!entityplayer.isInvisible() || entityplayer == thePlayer)) { // getting location from player entity - pt2 = mapProcessor.worldPointToMapPointFLOAT(entityplayer.getPositionEyes(partialTicks)); + pt2 = mapProcessor.getDungeonMapLayout().worldPointToMapPointFLOAT(entityplayer.getPositionEyes(partialTicks)); yaw2 = entityplayer.prevRotationYawHead + (entityplayer.rotationYawHead - entityplayer.prevRotationYawHead) * partialTicks; if(DungeonsGuide.getDungeonsGuide().verbose) System.out.println("Got player location from entity"); } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonMilestone.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonMilestone.java index 7331b34c..7fcb9c06 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonMilestone.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonMilestone.java @@ -25,6 +25,8 @@ import kr.syeyoung.dungeonsguide.mod.chat.ChatTransmitter; import kr.syeyoung.dungeonsguide.mod.config.types.AColor; import kr.syeyoung.dungeonsguide.mod.dungeon.DungeonContext; import kr.syeyoung.dungeonsguide.mod.events.annotations.DGEventHandler; +import kr.syeyoung.dungeonsguide.mod.events.impl.DungeonEndedEvent; +import kr.syeyoung.dungeonsguide.mod.events.impl.DungeonLeftEvent; import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; import kr.syeyoung.dungeonsguide.mod.features.text.StyledText; import kr.syeyoung.dungeonsguide.mod.features.text.TextHUDFeature; @@ -32,6 +34,7 @@ import kr.syeyoung.dungeonsguide.mod.features.text.TextStyle; import kr.syeyoung.dungeonsguide.mod.parallelUniverse.tab.TabList; import kr.syeyoung.dungeonsguide.mod.parallelUniverse.tab.TabListEntry; import kr.syeyoung.dungeonsguide.mod.utils.TextUtils; +import lombok.Getter; import net.minecraft.client.Minecraft; import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.scoreboard.ScorePlayerTeam; @@ -91,6 +94,12 @@ public class FeatureDungeonMilestone extends TextHUDFeature { } return actualBit; } + @DGEventHandler(ignoreDisabled = true) + public void onDungeonEnd(DungeonLeftEvent dungeonEndedEvent) { + milestoneReached.clear(); + } + @Getter + private final List<String[]> milestoneReached = new ArrayList<>(); public static final Pattern milestone_pattern = Pattern.compile("§r§e§l(.+) Milestone §r§e(.)§r§7: .+ §r§a(.+)§r"); @@ -103,7 +112,7 @@ public class FeatureDungeonMilestone extends TextHUDFeature { if (context == null) return; String txt = clientChatReceivedEvent.message.getFormattedText(); if (milestone_pattern.matcher(txt).matches()) { - context.getMilestoneReached().add(new String[] { + milestoneReached.add(new String[] { TextUtils.formatTime(FeatureRegistry.DUNGEON_REALTIME.getTimeElapsed()), TextUtils.formatTime(FeatureRegistry.DUNGEON_SBTIME.getTimeElapsed()) }); diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonRoomName.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonRoomName.java index 405b6c11..0e12fe34 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonRoomName.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonRoomName.java @@ -47,7 +47,7 @@ public class FeatureDungeonRoomName extends TextHUDFeature { public int getTotalSecretsInt() { DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); int totalSecrets = 0; - for (DungeonRoom dungeonRoom : context.getDungeonRoomList()) { + for (DungeonRoom dungeonRoom : context.getScaffoldParser().getDungeonRoomList()) { if (dungeonRoom.getTotalSecrets() != -1) totalSecrets += dungeonRoom.getTotalSecrets(); } @@ -62,7 +62,7 @@ public class FeatureDungeonRoomName extends TextHUDFeature { @Override public boolean isHUDViewable() { - return skyblockStatus.isOnDungeon() && DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext() != null && DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getMapProcessor() != null; + return skyblockStatus.isOnDungeon() && DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext() != null && DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getScaffoldParser() != null; } @Override @@ -79,8 +79,8 @@ public class FeatureDungeonRoomName extends TextHUDFeature { public List<StyledText> getText() { EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; - Point roomPt = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getMapProcessor().worldPointToRoomPoint(player.getPosition()); - DungeonRoom dungeonRoom = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getRoomMapper().get(roomPt); + Point roomPt = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(player.getPosition()); + DungeonRoom dungeonRoom = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getScaffoldParser().getRoomMap().get(roomPt); List<StyledText> actualBit = new ArrayList<StyledText>(); actualBit.add(new StyledText("You're in ","in")); if (dungeonRoom == null) { diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonScore.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonScore.java index e06d4c3c..3897a8a5 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonScore.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonScore.java @@ -23,6 +23,7 @@ import kr.syeyoung.dungeonsguide.mod.DungeonsGuide; import kr.syeyoung.dungeonsguide.mod.SkyblockStatus; import kr.syeyoung.dungeonsguide.mod.config.types.AColor; import kr.syeyoung.dungeonsguide.mod.dungeon.DungeonContext; +import kr.syeyoung.dungeonsguide.mod.dungeon.map.DungeonRoomScaffoldParser; import kr.syeyoung.dungeonsguide.mod.dungeon.roomfinder.DungeonRoom; import kr.syeyoung.dungeonsguide.mod.features.FeatureParameter; import kr.syeyoung.dungeonsguide.mod.features.FeatureRegistry; @@ -37,9 +38,6 @@ import kr.syeyoung.dungeonsguide.mod.wsresource.StaticResource; import kr.syeyoung.dungeonsguide.mod.wsresource.StaticResourceCache; import lombok.AllArgsConstructor; import lombok.Data; -import net.minecraft.client.Minecraft; -import net.minecraft.client.network.NetworkPlayerInfo; -import net.minecraft.scoreboard.ScorePlayerTeam; import net.minecraft.util.MathHelper; import java.util.ArrayList; @@ -208,8 +206,10 @@ public class FeatureDungeonScore extends TextHUDFeature { if (!skyblockStatus.isOnDungeon()) return null; DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); if (context == null) return null; - if (!context.getMapProcessor().isInitialized()) return null; + if (context.getScaffoldParser() == null) return null; + + DungeonRoomScaffoldParser parser = context.getScaffoldParser(); int skill = 100; int deaths = 0; { @@ -222,7 +222,7 @@ public class FeatureDungeonScore extends TextHUDFeature { boolean traproomIncomplete = context.isTrapRoomGen(); int incompletePuzzles = getUndiscoveredPuzzles(); - for (DungeonRoom dungeonRoom : context.getDungeonRoomList()) { + for (DungeonRoom dungeonRoom : parser.getDungeonRoomList()) { // if (dungeonRoom.getColor() == 74 && dungeonRoom.getCurrentState() != DungeonRoom.RoomState.DISCOVERED) // bossroomIncomplete = false; if (dungeonRoom.getColor() == 62 && dungeonRoom.getCurrentState() != DungeonRoom.RoomState.DISCOVERED) @@ -234,7 +234,7 @@ public class FeatureDungeonScore extends TextHUDFeature { roomCnt += dungeonRoom.getUnitPoints().size(); } roomSkillPenalty += incompletePuzzles * 10; - if (context.getMapProcessor().getUndiscoveredRoom() != 0) + if (parser.getUndiscoveredRoom() != 0) roomCnt = getTotalRooms(); roomSkillPenalty += (roomCnt - totalCompRooms) * 4; // if (bossroomIncomplete) roomSkillPenalty -=1; @@ -256,7 +256,7 @@ public class FeatureDungeonScore extends TextHUDFeature { int completed = 0; double total = 0; - for (DungeonRoom dungeonRoom : context.getDungeonRoomList()) { + for (DungeonRoom dungeonRoom : parser.getDungeonRoomList()) { if (dungeonRoom.getCurrentState() != DungeonRoom.RoomState.DISCOVERED && dungeonRoom.getCurrentState() != DungeonRoom.RoomState.FAILED) completed += dungeonRoom.getUnitPoints().size(); total += dungeonRoom.getUnitPoints().size(); @@ -265,8 +265,8 @@ public class FeatureDungeonScore extends TextHUDFeature { totalSecrets = FeatureRegistry.DUNGEON_SECRETS.getTotalSecretsInt() ; totalSecretsKnown = FeatureRegistry.DUNGEON_SECRETS.sureOfTotalSecrets(); - fullyCleared = completed >= getTotalRooms() && context.getMapProcessor().getUndiscoveredRoom() == 0; - explorer += MathHelper.clamp_int((int) Math.floor(6.0 / 10.0 * (context.getMapProcessor().getUndiscoveredRoom() != 0 ? DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getPercentage() : completed / total * 100)), 0, 60); + fullyCleared = completed >= getTotalRooms() && parser.getUndiscoveredRoom() == 0; + explorer += MathHelper.clamp_int((int) Math.floor(6.0 / 10.0 * (parser.getUndiscoveredRoom() != 0 ? DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getPercentage() : completed / total * 100)), 0, 60); explorer += MathHelper.clamp_int((int) Math.floor(40 * (secrets = FeatureRegistry.DUNGEON_SECRETS.getSecretsFound()) / Math.ceil(totalSecrets * context.getSecretPercentage())),0,40); } int time = 0; diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonSecrets.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonSecrets.java index bcc5d168..53a415b6 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonSecrets.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureDungeonSecrets.java @@ -30,12 +30,10 @@ import kr.syeyoung.dungeonsguide.mod.features.text.TextStyle; import kr.syeyoung.dungeonsguide.mod.parallelUniverse.tab.TabList; import kr.syeyoung.dungeonsguide.mod.parallelUniverse.tab.TabListEntry; import kr.syeyoung.dungeonsguide.mod.utils.TextUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.network.NetworkPlayerInfo; -import net.minecraft.scoreboard.ScorePlayerTeam; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; public class FeatureDungeonSecrets extends TextHUDFeature { @@ -76,7 +74,8 @@ public class FeatureDungeonSecrets extends TextHUDFeature { if (getSecretsFound() != 0) return (int) Math.ceil (getSecretsFound() / getSecretPercentage() * 100); DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); int totalSecrets = 0; - for (DungeonRoom dungeonRoom : context.getDungeonRoomList()) { + if (context.getScaffoldParser() == null) return 0; + for (DungeonRoom dungeonRoom : context.getScaffoldParser().getDungeonRoomList()) { if (dungeonRoom.getTotalSecrets() != -1) totalSecrets += dungeonRoom.getTotalSecrets(); } @@ -85,9 +84,10 @@ public class FeatureDungeonSecrets extends TextHUDFeature { public boolean sureOfTotalSecrets() { if (getSecretsFound() != 0) return true; DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); - if (context.getMapProcessor().getUndiscoveredRoom() > 0) return false; + if (context.getScaffoldParser() == null) return false; + if (context.getScaffoldParser().getUndiscoveredRoom() > 0) return false; boolean allknown = true; - for (DungeonRoom dungeonRoom : context.getDungeonRoomList()) { + for (DungeonRoom dungeonRoom : context.getScaffoldParser().getDungeonRoomList()) { if (dungeonRoom.getTotalSecrets() == -1) allknown = false; } return allknown; @@ -96,9 +96,10 @@ public class FeatureDungeonSecrets extends TextHUDFeature { public String getTotalSecrets() { DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); if (context == null) return "?"; + if (context.getScaffoldParser() == null) return "?"; int totalSecrets = 0; boolean allknown = true; - for (DungeonRoom dungeonRoom : context.getDungeonRoomList()) { + for (DungeonRoom dungeonRoom : context.getScaffoldParser().getDungeonRoomList()) { if (dungeonRoom.getTotalSecrets() != -1) totalSecrets += dungeonRoom.getTotalSecrets(); else allknown = false; diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureWatcherWarning.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureWatcherWarning.java index d55b65b1..da8908f2 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureWatcherWarning.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/dungeon/FeatureWatcherWarning.java @@ -26,6 +26,7 @@ import kr.syeyoung.dungeonsguide.mod.dungeon.DungeonContext; import kr.syeyoung.dungeonsguide.mod.dungeon.roomfinder.DungeonRoom; import kr.syeyoung.dungeonsguide.mod.events.annotations.DGEventHandler; import kr.syeyoung.dungeonsguide.mod.events.impl.DungeonEndedEvent; +import kr.syeyoung.dungeonsguide.mod.events.impl.DungeonLeftEvent; import kr.syeyoung.dungeonsguide.mod.features.text.StyledText; import kr.syeyoung.dungeonsguide.mod.features.text.TextHUDFeature; import kr.syeyoung.dungeonsguide.mod.features.text.TextStyle; @@ -74,7 +75,7 @@ public class FeatureWatcherWarning extends TextHUDFeature { warning = System.currentTimeMillis() + 2500; DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); if (context ==null) return; - for (DungeonRoom dungeonRoom : context.getDungeonRoomList()) { + for (DungeonRoom dungeonRoom : context.getScaffoldParser().getDungeonRoomList()) { if (dungeonRoom != null && dungeonRoom.getColor() == 18) dungeonRoom.setCurrentState(DungeonRoom.RoomState.DISCOVERED); } @@ -82,7 +83,7 @@ public class FeatureWatcherWarning extends TextHUDFeature { } @DGEventHandler(ignoreDisabled = true) - public void onDungeonEnd(DungeonEndedEvent event) { + public void onDungeonEnd(DungeonLeftEvent event) { warning = 0; } } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/party/FeaturePartyReady.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/party/FeaturePartyReady.java index d4cef1f3..d899fe18 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/party/FeaturePartyReady.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/party/FeaturePartyReady.java @@ -19,8 +19,8 @@ package kr.syeyoung.dungeonsguide.mod.features.impl.party; +import kr.syeyoung.dungeonsguide.mod.SkyblockStatus; import kr.syeyoung.dungeonsguide.mod.config.types.AColor; -import kr.syeyoung.dungeonsguide.mod.dungeon.DungeonContext; import kr.syeyoung.dungeonsguide.mod.events.annotations.DGEventHandler; import kr.syeyoung.dungeonsguide.mod.events.impl.DungeonStartedEvent; import kr.syeyoung.dungeonsguide.mod.features.text.StyledText; @@ -46,7 +46,7 @@ public class FeaturePartyReady extends TextHUDFeature { @Override public boolean isHUDViewable() { - return PartyManager.INSTANCE.getPartyContext() != null && PartyManager.INSTANCE.getPartyContext().isPartyExistHypixel() && "Dungeon Hub".equals(DungeonContext.getDungeonName()); + return PartyManager.INSTANCE.getPartyContext() != null && PartyManager.INSTANCE.getPartyContext().isPartyExistHypixel() && "Dungeon Hub".equals(SkyblockStatus.locationName); } @Override diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/FeatureActions.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/FeatureActions.java index 1a12ae92..4bf5642a 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/FeatureActions.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/FeatureActions.java @@ -62,12 +62,12 @@ public class FeatureActions extends TextHUDFeature { @Override public boolean isHUDViewable() { if (!SkyblockStatus.isOnDungeon()) return false; - if (DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext() == null || !DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getMapProcessor().isInitialized()) return false; + if (DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext() == null || DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getScaffoldParser() == null) return false; DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); if (dungeonRoom == null) return false; return dungeonRoom.getRoomProcessor() instanceof GeneralRoomProcessor; } @@ -112,8 +112,8 @@ public class FeatureActions extends TextHUDFeature { DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); for (ActionRoute path : ((GeneralRoomProcessor) dungeonRoom.getRoomProcessor()).getPath().values()) { actualBit.add(new StyledText("Pathfinding ","pathfinding")); diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/FeatureSoulRoomWarning.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/FeatureSoulRoomWarning.java index a40db3c9..cc41d233 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/FeatureSoulRoomWarning.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/FeatureSoulRoomWarning.java @@ -93,13 +93,13 @@ public class FeatureSoulRoomWarning extends TextHUDFeature { @DGEventHandler public void onTick(DGTickEvent event) { if (!skyblockStatus.isOnDungeon()) return; - if (DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext() == null || !DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getMapProcessor().isInitialized()) return; + if (DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext() == null || DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getScaffoldParser() == null) return; DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; if (thePlayer == null) return; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); if (dungeonRoom == null) return; if (!(dungeonRoom.getRoomProcessor() instanceof GeneralRoomProcessor)) return; diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/FeatureMechanicBrowse.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/FeatureMechanicBrowse.java index 87cc7381..87f28a3c 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/FeatureMechanicBrowse.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/secret/mechanicbrowser/FeatureMechanicBrowse.java @@ -95,12 +95,12 @@ public class FeatureMechanicBrowse extends RawRenderingGuiFeature { public void drawHUD(float partialTicks) { SkyblockStatus skyblockStatus = DungeonsGuide.getDungeonsGuide().getSkyblockStatus(); if (!skyblockStatus.isOnDungeon()) return; - if (DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext() == null || !DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getMapProcessor().isInitialized()) return; + if (DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext() == null || DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getScaffoldParser() == null) return; DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); if (dungeonRoom == null) return; if (!(dungeonRoom.getRoomProcessor() instanceof GeneralRoomProcessor)) return; GeneralRoomProcessor grp = (GeneralRoomProcessor) dungeonRoom.getRoomProcessor(); @@ -134,14 +134,15 @@ public class FeatureMechanicBrowse extends RawRenderingGuiFeature { SkyblockStatus skyblockStatus = DungeonsGuide.getDungeonsGuide().getSkyblockStatus(); if (!skyblockStatus.isOnDungeon()) return; - if (DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext() == null || !DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getMapProcessor().isInitialized()) return; + if (DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext() == null || DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getScaffoldParser() == null) return; DungeonContext context = DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext(); EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; - Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition()); - DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt); + Point roomPt = context.getScaffoldParser().getDungeonMapLayout().worldPointToRoomPoint(thePlayer.getPosition()); + DungeonRoom dungeonRoom = context.getScaffoldParser().getRoomMap().get(roomPt); if (dungeonRoom == null) return; if (!(dungeonRoom.getRoomProcessor() instanceof GeneralRoomProcessor)) return; + if (mechanicBrowser == null) return; String id = mechanicBrowser.getSelectedId(); if (id != null) { Optional.ofNullable(dungeonRoom.getMechanics().get(mechanicBrowser.getSelectedId())) @@ -183,10 +184,9 @@ public class FeatureMechanicBrowse extends RawRenderingGuiFeature { @DGEventHandler public void onTick(DGTickEvent event) { Optional<DungeonRoom> dungeonRoomOpt = Optional.ofNullable(DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext()) - .map(DungeonContext::getMapProcessor).map(a->a.worldPointToRoomPoint(Minecraft.getMinecraft().thePlayer.getPosition())) - .map(a -> { - return DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getRoomMapper().get(a); - }); + .map(DungeonContext::getScaffoldParser) + .map(a->a.getDungeonMapLayout().worldPointToRoomPoint(Minecraft.getMinecraft().thePlayer.getPosition())) + .map(a -> DungeonsGuide.getDungeonsGuide().getDungeonFacade().getContext().getScaffoldParser().getRoomMap().get(a)); UUID currentUID = dungeonRoomOpt.map(a -> a.getDungeonRoomInfo().getUuid()).orElse(null); // Event-ify above this. diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/parallelUniverse/map/MapDataManager.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/parallelUniverse/map/MapDataManager.java new file mode 100644 index 00000000..764f7408 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/parallelUniverse/map/MapDataManager.java @@ -0,0 +1,49 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2023 cyoung06 (syeyoung) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.parallelUniverse.map; + +import net.minecraft.world.storage.MapData; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public class MapDataManager { + public static final MapDataManager INSTANCE = new MapDataManager(); + private Map<Integer, MapData> mapDataMap = new HashMap<>(); + + public MapData createMapData(int mapId) { + if (!mapDataMap.containsKey(mapId)) + mapDataMap.put(mapId, new MapData("map_"+mapId)); + return mapDataMap.get(mapId); + + } + + public MapData getMapData(int mapId) { + return mapDataMap.get(mapId); + } + + public void refresh() { + mapDataMap.clear(); + } + + public Map<Integer, MapData> getMapDataMap() { + return Collections.unmodifiableMap(mapDataMap); + } +} |