diff options
author | syeyoung <42869671+cyoung06@users.noreply.github.com> | 2020-11-22 18:22:10 +0900 |
---|---|---|
committer | syeyoung <42869671+cyoung06@users.noreply.github.com> | 2020-11-22 18:22:10 +0900 |
commit | 527732c2242d1dc0556c6a6cd49f4847b1f9c716 (patch) | |
tree | 30b18c31ef5565ef8e346416b563355d09b6a36c /src/main/java | |
parent | 38c3841567f188626cf37ab02893eb29d304c21d (diff) | |
download | Skyblock-Dungeons-Guide-527732c2242d1dc0556c6a6cd49f4847b1f9c716.tar.gz Skyblock-Dungeons-Guide-527732c2242d1dc0556c6a6cd49f4847b1f9c716.tar.bz2 Skyblock-Dungeons-Guide-527732c2242d1dc0556c6a6cd49f4847b1f9c716.zip |
door determination
Diffstat (limited to 'src/main/java')
7 files changed, 143 insertions, 11 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java b/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java index 8512e902..291a158f 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/EventListener.java @@ -4,6 +4,7 @@ import kr.syeyoung.dungeonsguide.dungeon.DungeonContext; import kr.syeyoung.dungeonsguide.utils.MapUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.RenderGameOverlayEvent; @@ -42,6 +43,8 @@ public class EventListener { MapUtils.getImage().getRGB(0,0,128,128, textureData, 0, 128); dynamicTexture.updateDynamicTexture(); Minecraft.getMinecraft().getTextureManager().bindTexture(location); + GlStateManager.enableBlend(); + GlStateManager.enableAlpha(); GuiScreen.drawModalRectWithCustomSizedTexture(0,0, 0, 0, 128, 128, 128, 128); } } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java b/src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java index e05edb00..7cc75d4d 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/SkyblockStatus.java @@ -23,6 +23,9 @@ public class SkyblockStatus { @Setter private DungeonContext context; + @Getter + private String dungeonName; + private final Pattern SERVER_BRAND_PATTERN = Pattern.compile("(.+) <- (?:.+)"); @@ -72,10 +75,13 @@ public class SkyblockStatus { for (Score sc:scores) { ScorePlayerTeam scorePlayerTeam = scoreboard.getPlayersTeam(sc.getPlayerName()); String strippedLine = TextUtils.keepScoreboardCharacters(TextUtils.stripColor(ScorePlayerTeam.formatPlayerName(scorePlayerTeam, sc.getPlayerName()))).trim(); - if (strippedLine.contains("Dungeon Cleared: ")) { foundDungeon = true; } + if (ScorePlayerTeam.formatPlayerName(scorePlayerTeam, sc.getPlayerName()).startsWith(" §7⏣")) { + System.out.println(strippedLine); + dungeonName = strippedLine; + } } isOnDungeon = foundDungeon; diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java index e08ee94a..d20da271 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/DungeonContext.java @@ -1,10 +1,13 @@ package kr.syeyoung.dungeonsguide.dungeon; import lombok.Getter; +import lombok.Setter; +import net.minecraft.block.BlockPackedIce; import net.minecraft.client.Minecraft; import net.minecraft.init.Items; import net.minecraft.item.ItemMap; import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; import net.minecraft.world.World; import net.minecraft.world.storage.MapData; @@ -14,6 +17,10 @@ public class DungeonContext { @Getter private MapProcessor mapProcessor; + @Getter + @Setter + private BlockPos dungeonMin; + public DungeonContext(World world) { this.world = world; mapProcessor = new MapProcessor(this); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java index 5f4f06db..5d04b720 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java @@ -1,15 +1,24 @@ package kr.syeyoung.dungeonsguide.dungeon; +import com.google.common.base.Predicate; import com.google.common.collect.Sets; +import kr.syeyoung.dungeonsguide.DungeonsGuide; +import kr.syeyoung.dungeonsguide.SkyblockStatus; +import kr.syeyoung.dungeonsguide.dungeon.doorfinder.DoorFinderRegistry; +import kr.syeyoung.dungeonsguide.dungeon.doorfinder.StartDoorFinder; import kr.syeyoung.dungeonsguide.utils.MapUtils; import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityOtherPlayerMP; +import net.minecraft.entity.item.EntityArmorStand; import net.minecraft.item.ItemMap; import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; import net.minecraft.util.ChatComponentText; import net.minecraft.world.storage.MapData; import javax.vecmath.Vector2d; import java.awt.*; +import java.util.Collection; import java.util.Set; public class MapProcessor { @@ -43,37 +52,37 @@ public class MapProcessor { int height = MapUtils.getHeightOfColorAt(mapData, (byte) 30, startroom); unitRoomDimension = new Dimension(width, height); } + Vector2d doorDir = null; // determine the gap { Point midStartRoom = new Point(startroom.x + unitRoomDimension.width / 2, startroom.y +unitRoomDimension.height / 2); final int halfWidth = unitRoomDimension.width / 2 + 2; - Vector2d dir = null; for (Vector2d v:directions) { byte color = MapUtils.getMapColorAt(mapData, (int)(v.x * halfWidth +midStartRoom.x), (int)(v.y *halfWidth +midStartRoom.y)); if (color != 0) { - dir = v; + doorDir = v; break; } } - if (dir == null) { + if (doorDir == null) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("BUGGED MAP, no connected door found")); bugged = true; return; } Point basePoint = new Point(startroom.x, startroom.y); - if (dir.x > 0) basePoint.x += unitRoomDimension.width; - if (dir.x < 0) basePoint.x += -1; - if (dir.y > 0) basePoint.y += unitRoomDimension.height; - if (dir.y < 0) basePoint.y += -1; - int gap = MapUtils.getLengthOfColorExtending(mapData, (byte) 0, basePoint, dir); - Point pt = MapUtils.findFirstColorWithInNegate(mapData, (byte)0, new Rectangle(basePoint.x, basePoint.y, (int)Math.abs(dir.y) * unitRoomDimension.width + 1, (int)Math.abs(dir.x) * unitRoomDimension.height + 1)); + 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) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("BUGGED MAP, can't find door")); bugged = true; return; } - int doorWidth = MapUtils.getLengthOfColorExtending(mapData, MapUtils.getMapColorAt(mapData, pt.x, pt.y), pt, new Vector2d((int)Math.abs(dir.y), (int)Math.abs(dir.x))); + 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))); doorDimension = new Dimension(doorWidth, gap); } // Determine Top Left @@ -84,12 +93,46 @@ public class MapProcessor { while (y >= unitRoomDimension.height + doorDimension.height) y -= unitRoomDimension.height + doorDimension.height; topLeftMapPoint = new Point(x, y); } + // determine door location based on npc, and determine map min from there + { + StartDoorFinder doorFinder = DoorFinderRegistry.getDoorFinder(DungeonsGuide.getDungeonsGuide().getSkyblockStatus().getDungeonName()); + if (doorFinder == null) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Couldn't find door finder for :: "+DungeonsGuide.getDungeonsGuide().getSkyblockStatus().getDungeonName())); + bugged = true; + return; + } + BlockPos door = doorFinder.find(context.getWorld()); + if (door == null) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Couldn't find door :: "+DungeonsGuide.getDungeonsGuide().getSkyblockStatus().getDungeonName())); + bugged = true; + return; + } + + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("door Pos:"+door)); + + Point unitPoint = mapPointToRoomPoint(startroom); + unitPoint.translate(unitPoint.x + 1, unitPoint.y + 1); + unitPoint.translate((int)doorDir.x, (int)doorDir.y); + + int worldX = unitPoint.x * 16; + int worldY = unitPoint.y * 16; + BlockPos worldMin = door.add(-worldX, 0, -worldY); + context.setDungeonMin(worldMin); + + } Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Found Green room:"+startroom)); Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Dimension:"+unitRoomDimension)); Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("top Left:"+topLeftMapPoint)); Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("door dimension:"+doorDimension)); } + + private Point mapPointToRoomPoint(Point mapPoint) { + int x = (int)((mapPoint.x - topLeftMapPoint.x) / ((double)unitRoomDimension.width + doorDimension.height)); + int y = (int)((mapPoint.y - topLeftMapPoint.y) / ((double)unitRoomDimension.height + doorDimension.height)); + return new Point(x,y); + } + private void processMap(byte[] mapData) { } diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/doorfinder/CatacombDoorFinder.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/doorfinder/CatacombDoorFinder.java new file mode 100644 index 00000000..c3b67d9e --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/doorfinder/CatacombDoorFinder.java @@ -0,0 +1,45 @@ +package kr.syeyoung.dungeonsguide.dungeon.doorfinder; + +import com.google.common.base.Predicate; +import com.google.common.collect.Sets; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.item.EntityArmorStand; +import net.minecraft.init.Blocks; +import net.minecraft.util.BlockPos; +import net.minecraft.util.ChatComponentText; +import net.minecraft.world.World; + +import javax.vecmath.Vector2d; +import java.util.Collection; +import java.util.Set; + +public class CatacombDoorFinder implements StartDoorFinder { + + private static final Set<Vector2d> directions = Sets.newHashSet(new Vector2d(0,1), new Vector2d(0, -1), new Vector2d(1, 0), new Vector2d(-1 , 0)); + + @Override + public BlockPos find(World w) { + Collection<EntityArmorStand> armorStand = w.getEntities(EntityArmorStand.class, new Predicate<EntityArmorStand>() { + @Override + public boolean apply(EntityArmorStand input) { + System.out.println(input.getName()); + return input.getName().equals("§bMort"); + } + }); + + if (armorStand.size() != 0) { + EntityArmorStand mort = armorStand.iterator().next(); + BlockPos pos = mort.getPosition(); + pos = pos.add(0, 3, 0); + for (int i = 0; i < 5; i++) { + for (Vector2d vector2d:directions) { + BlockPos test = pos.add(vector2d.x * i, 0, vector2d.y * i); + if (w.getChunkFromBlockCoords(test).getBlock(test) == Blocks.iron_bars) { + return pos.add(vector2d.x * (i + 2), -2, vector2d.y * (i+2)); + } + } + } + } + return null; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/doorfinder/DoorFinderRegistry.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/doorfinder/DoorFinderRegistry.java new file mode 100644 index 00000000..306b1993 --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/doorfinder/DoorFinderRegistry.java @@ -0,0 +1,20 @@ +package kr.syeyoung.dungeonsguide.dungeon.doorfinder; + +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Pattern; + +public class DoorFinderRegistry { + private static final Map<Pattern, StartDoorFinder> doorFinders = new HashMap<Pattern, StartDoorFinder>(); + + static { + doorFinders.put(Pattern.compile("The Catacombs F[0-9]"), new CatacombDoorFinder()); + } + + public static StartDoorFinder getDoorFinder(String dungeonName) { + for (Map.Entry<Pattern, StartDoorFinder> doorFinderEntry :doorFinders.entrySet()){ + if (doorFinderEntry.getKey().matcher(dungeonName).matches()) return doorFinderEntry.getValue(); + } + return null; + } +} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/doorfinder/StartDoorFinder.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/doorfinder/StartDoorFinder.java new file mode 100644 index 00000000..5096fe7b --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/doorfinder/StartDoorFinder.java @@ -0,0 +1,8 @@ +package kr.syeyoung.dungeonsguide.dungeon.doorfinder; + +import net.minecraft.util.BlockPos; +import net.minecraft.world.World; + +public interface StartDoorFinder { + BlockPos find(World w); +} |