aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorsyeyoung <cyong06@naver.com>2021-02-02 12:49:47 +0900
committersyeyoung <cyong06@naver.com>2021-02-02 12:49:47 +0900
commitbdf4d8869c80d74ff9fe628d3887152396ea68ac (patch)
tree0df3f2c3a8a90190d0d39002e8a0359b5931d4dc /src/main/java
parent125068bf522ea8314a72920d05d17131aab6d3be (diff)
downloadSkyblock-Dungeons-Guide-bdf4d8869c80d74ff9fe628d3887152396ea68ac.tar.gz
Skyblock-Dungeons-Guide-bdf4d8869c80d74ff9fe628d3887152396ea68ac.tar.bz2
Skyblock-Dungeons-Guide-bdf4d8869c80d74ff9fe628d3887152396ea68ac.zip
chunk loadin and stabilize map first
Diffstat (limited to 'src/main/java')
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java34
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/RoomMatcher.java17
2 files changed, 46 insertions, 5 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java
index 665d8a7f..0852ef79 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/MapProcessor.java
@@ -224,6 +224,7 @@ public class MapProcessor {
if (color != 0 && color != 85) {
MapUtils.record(mapData, mapPoint.x, mapPoint.y, new Color(0,255,255,80));
DungeonRoom rooms = buildRoom(mapData, new Point(x,y));
+ if (rooms == null) continue;
e.sendDebugChat(new ChatComponentText("New Map discovered! shape: "+rooms.getShape()+ " color: "+rooms.getColor()+" unitPos: "+x+","+y));
e.sendDebugChat(new ChatComponentText("New Map discovered! mapMin: "+rooms.getMin()));
StringBuilder builder = new StringBuilder();
@@ -286,7 +287,12 @@ public class MapProcessor {
Point pt2 = roomPointToMapPoint(ayConnected.get(0));
byte unit1 = MapUtils.getMapColorAt(mapData, pt2.x, pt2.y);
- return new DungeonRoom(ayConnected, shape, unit1, roomPointToWorldPoint(new Point(minX, minY)), roomPointToWorldPoint(new Point(maxX+1, maxY+1)).add(-1, 0, -1), context);
+ try{
+ return new DungeonRoom(ayConnected, shape, unit1, roomPointToWorldPoint(new Point(minX, minY)), roomPointToWorldPoint(new Point(maxX+1, maxY+1)).add(-1, 0, -1), context);
+ } catch (IllegalStateException ex) {
+ e.sendDebugChat(new ChatComponentText("Failed to load room, retrying later :: "+ex.getLocalizedMessage()));
+ return null;
+ }
}
private boolean checkIfConnected(byte[] mapData, Point unitPoint1, Point unitPoint2) {
@@ -309,6 +315,14 @@ public class MapProcessor {
return unit1 == unit2 && unit2 == unit3 && unit1 != 0;
}
+ public boolean isThereDifference(byte[] colors1, byte[] colors) {
+ if (colors1 == null || colors == null) return true;
+ for (int i =0; i < colors.length; i++)
+ if (colors[i] != colors1[i]) return true;
+ return false;
+ }
+ private int stabilizationTick = 0;
+
public void tick() {
if (waitCnt < 5) {
waitCnt++;
@@ -325,11 +339,22 @@ public class MapProcessor {
else {
mapData = mapData1.colors;
lastMapData2 = mapData1;
+
+ if (isThereDifference(lastMapData, mapData)) {
+ stabilizationTick =0;
+ } else {
+ stabilizationTick++;
+ }
+
+ if (stabilizationTick > 5) {
+ if (doorDimension == null) buildMap(mapData);
+ else processMap(mapData);
+ }
+ lastMapData = mapData;
}
+
}
- if (lastMapData == null && mapData != null) buildMap(mapData);
- else if (mapData != null) processMap(mapData);
if (lastMapData2 != null && mapIconToPlayerMap.size() < context.getPlayers().size()) {
label: for (Map.Entry<String, Vec4b> stringVec4bEntry : lastMapData2.mapDecorations.entrySet()) {
@@ -341,7 +366,7 @@ public class MapProcessor {
for (String player : context.getPlayers()) { // check nearby players
if (mapIconToPlayerMap.containsKey(player)) continue;
EntityPlayer entityPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(player);
- if (entityPlayer == null) continue;
+ if (entityPlayer == null || entityPlayer.isInvisible()) continue;
BlockPos pos = entityPlayer.getPosition();
int dx = mapPos.getX() - pos.getX();
int dz = mapPos.getZ() - pos.getZ();
@@ -367,6 +392,5 @@ public class MapProcessor {
}
}
- lastMapData = mapData;
}
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/RoomMatcher.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/RoomMatcher.java
index 43675f61..41967e6c 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/RoomMatcher.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/RoomMatcher.java
@@ -5,6 +5,8 @@ import kr.syeyoung.dungeonsguide.utils.ArrayUtils;
import kr.syeyoung.dungeonsguide.utils.ShortUtils;
import lombok.Getter;
import net.minecraft.block.Block;
+import net.minecraft.util.BlockPos;
+import net.minecraft.world.World;
import java.util.List;
@@ -17,12 +19,26 @@ public class RoomMatcher {
private int rotation; // how much the "found room" has to rotate to match the given dungeon room info. !
private boolean triedMatch = false;
+ private World w;
+
public RoomMatcher(DungeonRoom dungeonRoom) {
this.dungeonRoom = dungeonRoom;
+ w = dungeonRoom.getContext().getWorld();
}
public DungeonRoomInfo match() {
if (triedMatch) return match;
+
+ int zz = dungeonRoom.getMax().getZ() - dungeonRoom.getMin().getZ() + 1;
+ int xx = dungeonRoom.getMax().getX() - dungeonRoom.getMin().getX() + 1;
+ for (int z = 0; z < zz; z ++) {
+ for (int x = 0; x < xx; x++) {
+ if (x % 8 == 0 && z % 8 == 0 && dungeonRoom.getContext().getWorld().getChunkFromBlockCoords(dungeonRoom.getRelativeBlockPosAt(x, 0, z)).isEmpty()) {
+ throw new IllegalStateException("chunk is not loaded");
+ }
+ }
+ }
+
triedMatch = true;
for (int rotation = 0; rotation < 4; rotation++) {
short shape = dungeonRoom.getShape();
@@ -54,6 +70,7 @@ public class RoomMatcher {
int data = res[z][x];
if (data == -1) continue;
Block b = dungeonRoom.getRelativeBlockAt(x,0,z);
+
if (b == null || Block.getIdFromBlock(b) != data) {
return false;
}