aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsyeyoung <cyoung06@naver.com>2021-10-02 23:37:44 +0900
committersyeyoung <cyoung06@naver.com>2021-10-02 23:37:44 +0900
commit2a60380de52cce7a895e8200751e8e854178796a (patch)
tree5d20bfc36735a577a1df16fd01fabdfaf8dde480 /src
parent5469f3041832885ccf33b5b1d9959d610e1bd6c2 (diff)
downloadSkyblock-Dungeons-Guide-2a60380de52cce7a895e8200751e8e854178796a.tar.gz
Skyblock-Dungeons-Guide-2a60380de52cce7a895e8200751e8e854178796a.tar.bz2
Skyblock-Dungeons-Guide-2a60380de52cce7a895e8200751e8e854178796a.zip
- Block Changed Event
- Optimization on JPS Pathfinder
Diffstat (limited to 'src')
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java115
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/eventlistener/DungeonListener.java32
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/eventlistener/PacketListener.java69
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/events/BlockUpdateEvent.java38
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/pathfinding/JPSPathfinder.java147
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/roomprocessor/GeneralRoomProcessor.java10
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessor.java3
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/GeneralDefuseChamberProcessor.java5
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bossfight/GeneralBossfightProcessor.java5
9 files changed, 308 insertions, 116 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java
index 00b81f59..f92d21c5 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoom.java
@@ -27,6 +27,7 @@ import kr.syeyoung.dungeonsguide.dungeon.events.DungeonStateChangeEvent;
import kr.syeyoung.dungeonsguide.dungeon.mechanics.DungeonMechanic;
import kr.syeyoung.dungeonsguide.dungeon.mechanics.DungeonRoomDoor;
import kr.syeyoung.dungeonsguide.features.FeatureRegistry;
+import kr.syeyoung.dungeonsguide.pathfinding.CachedWorld;
import kr.syeyoung.dungeonsguide.pathfinding.JPSPathfinder;
import kr.syeyoung.dungeonsguide.pathfinding.NodeProcessorDungeonRoom;
import kr.syeyoung.dungeonsguide.roomedit.EditingContext;
@@ -37,13 +38,18 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.block.Block;
+import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.pathfinding.PathEntity;
import net.minecraft.pathfinding.PathFinder;
import net.minecraft.pathfinding.PathPoint;
+import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
+import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
+import net.minecraft.world.ChunkCache;
import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.World;
import javax.vecmath.Vector2d;
import java.awt.*;
@@ -78,6 +84,9 @@ public class DungeonRoom {
private RoomState currentState = RoomState.DISCOVERED;
private Map<String, DungeonMechanic> cached = null;
+
+ @Getter
+ private World cachedWorld;
public Map<String, DungeonMechanic> getMechanics() {
if (cached == null || EditingContext.getEditingContext() != null) {
cached = new HashMap<String, DungeonMechanic>(dungeonRoomInfo.getMechanics());
@@ -99,7 +108,7 @@ public class DungeonRoom {
ScheduledFuture<List<Vec3>> sf = asyncPathFinder.schedule(() -> {
BlockPos min = new BlockPos(getMin().getX(), 0, getMin().getZ());
BlockPos max= new BlockPos(getMax().getX(), 255, getMax().getZ());
- JPSPathfinder pathFinder = new JPSPathfinder(context.getWorld(), min, max);
+ JPSPathfinder pathFinder = new JPSPathfinder(this);
pathFinder.pathfind(entityIn.getPositionVector(), new Vec3(targetPos).addVector(0.5, 0.5, 0.5), 1.5f,timeout);
return pathFinder.getRoute();
}, 0, TimeUnit.MILLISECONDS);
@@ -154,10 +163,26 @@ public class DungeonRoom {
unitWidth = (int) Math.ceil(max.getX() - min.getX() / 32.0);
unitHeight = (int) Math.ceil(max.getZ() - min.getZ() / 32.0);
+
+ ChunkCache chunkCache = new ChunkCache(getContext().getWorld(), min.add(-3, 0, -3), max.add(3,0,3), 0);
+ this.cachedWorld = new CachedWorld(chunkCache);
+
+
+
+ minx = min.getX() * 2; miny = 0; minz = min.getZ() * 2;
+ maxx = max.getX() * 2 + 2; maxy = 255 * 2 + 2; maxz = max.getZ() * 2 + 2;
+
+ lenx = maxx - minx;
+ leny = maxy - miny;
+ lenz = maxz - minz;
+ arr = new long[lenx *leny * lenz * 2 / 8];;
+
buildDoors();
buildRoom();
nodeProcessorDungeonRoom = new NodeProcessorDungeonRoom(this);
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));
@@ -201,7 +226,7 @@ public class DungeonRoom {
// validate x y z's
BlockPos pos = new BlockPos(x,y,z);
if (canAccessAbsolute(pos)) {
- return this.context.getWorld().getChunkFromBlockCoords(pos).getBlock(pos);
+ return cachedWorld.getBlockState(pos).getBlock();
}
return null;
}
@@ -210,7 +235,7 @@ public class DungeonRoom {
// validate x y z's
if (canAccessRelative(x,z)) {
BlockPos pos = new BlockPos(x,y,z).add(min.getX(),min.getY(),min.getZ());
- return this.context.getWorld().getChunkFromBlockCoords(pos).getBlock(pos);
+ return cachedWorld.getBlockState(pos).getBlock();
}
return null;
}
@@ -224,7 +249,8 @@ public class DungeonRoom {
// validate x y z's
if (canAccessRelative(x,z)) {
BlockPos pos = new BlockPos(x,y,z).add(min.getX(),min.getY(),min.getZ());
- return this.context.getWorld().getChunkFromBlockCoords(pos).getBlockMetadata(pos);
+ IBlockState iBlockState = cachedWorld.getBlockState(pos);
+ return iBlockState.getBlock().getMetaFromState(iBlockState);
}
return -1;
}
@@ -233,7 +259,8 @@ public class DungeonRoom {
// validate x y z's
BlockPos pos = new BlockPos(x,y,z);
if (canAccessAbsolute(pos)) {
- return this.context.getWorld().getChunkFromBlockCoords(pos).getBlockMetadata(pos);
+ IBlockState iBlockState = cachedWorld.getBlockState(pos);
+ return iBlockState.getBlock().getMetaFromState(iBlockState);
}
return -1;
}
@@ -248,4 +275,82 @@ public class DungeonRoom {
public boolean canAccessRelative(int x, int z) {
return x>= 0 && z >= 0 && (shape >>((z/32) *4 +(x/32)) & 0x1) > 0;
}
+
+
+
+ long arr[];
+ private final int minx, miny, minz, maxx, maxy, maxz;
+ private final int lenx, leny, lenz;
+ private static final float playerWidth = 0.3f;
+ public boolean isBlocked(int x,int y, int z) {
+ if (x < minx || z < minz || x >= maxx || z >= maxz || y < miny || y >= maxy) return true;
+ int dx = x - minx, dy = y - miny, dz = z - minz;
+ int bitIdx = dx * leny * lenz + dy * lenz + dz;
+ int location = bitIdx / 4;
+ int bitStart = (2 * (bitIdx % 4));
+ long theBit = arr[location];
+ if (((theBit >> bitStart) & 0x2) > 0) return ((theBit >> bitStart) & 1) > 0;
+ float wX = x / 2.0f, wY = y / 2.0f, wZ = z / 2.0f;
+
+
+ AxisAlignedBB bb = AxisAlignedBB.fromBounds(wX - playerWidth, wY, wZ - playerWidth, wX + playerWidth, wY + 1.9f, wZ + playerWidth);
+
+ int i = MathHelper.floor_double(bb.minX);
+ int j = MathHelper.floor_double(bb.maxX + 1.0D);
+ int k = MathHelper.floor_double(bb.minY);
+ int l = MathHelper.floor_double(bb.maxY + 1.0D);
+ int i1 = MathHelper.floor_double(bb.minZ);
+ int j1 = MathHelper.floor_double(bb.maxZ + 1.0D);
+ BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos();
+
+ List<AxisAlignedBB> list = new ArrayList<>();
+ for (int k1 = i; k1 < j; ++k1) {
+ for (int l1 = i1; l1 < j1; ++l1) {
+ for (int i2 = k - 1; i2 < l; ++i2) {
+ blockPos.set(k1, i2, l1);
+ IBlockState iblockstate1 = cachedWorld.getBlockState(blockPos);
+ Block b = iblockstate1.getBlock();
+ if (!b.getMaterial().blocksMovement())continue;
+ if (b.isFullCube() && i2 == k-1) continue;
+ if (iblockstate1.equals( NodeProcessorDungeonRoom.preBuilt)) continue;
+ if (b.isFullCube()) {
+ theBit |= (3L << bitStart);
+ arr[location] = theBit;
+ return true;
+ }
+ try {
+ b.addCollisionBoxesToList(cachedWorld, blockPos, iblockstate1, bb, list, null);
+ } catch (Exception e) {
+ return true;
+ }
+ if (list.size() > 0) {
+ theBit |= (3L << bitStart);
+ arr[location] = theBit;
+ return true;
+ }
+ }
+ }
+ }
+ theBit |= 2L << bitStart;
+ arr[location] = theBit;
+ return false;
+ }
+
+
+ public void resetBlock(BlockPos pos) {
+ for (int x = -1; x <= 1; x++) {
+ for (int y = -1; y <= 1; y++) {
+ for (int z = -1; z <= 1; z++) {
+ resetBlock(pos.getX()*2 + x, pos.getY()*2 + y, pos.getZ()*2 + z);
+ }
+ }
+ }
+ }
+ private void resetBlock(int x, int y, int z) {
+ if (x < minx || z < minz || x >= maxx || z >= maxz || y < miny || y >= maxy) return;
+ int dx = x - minx, dy = y - miny, dz = z - minz;
+ int bitIdx = dx * leny * lenz + dy * lenz + dz;
+ int location = bitIdx / 4;
+ arr[location] = 0;
+ }
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/DungeonListener.java b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/DungeonListener.java
index bbf28adc..d01a5ea9 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/DungeonListener.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/DungeonListener.java
@@ -457,6 +457,38 @@ public class DungeonListener {
}
}
+ @SubscribeEvent()
+ public void onBlockChange(BlockUpdateEvent.Post postInteract) {
+ try {
+ SkyblockStatus skyblockStatus = DungeonsGuide.getDungeonsGuide().getSkyblockStatus();
+ if (!skyblockStatus.isOnDungeon()) return;
+
+ DungeonContext context = skyblockStatus.getContext();
+
+ if (skyblockStatus.getContext() != null) {
+ EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer;
+ Point roomPt = context.getMapProcessor().worldPointToRoomPoint(thePlayer.getPosition());
+
+ if (context.getBossfightProcessor() != null) {
+ context.getBossfightProcessor().onBlockUpdate(postInteract);
+ }
+ RoomProcessor roomProcessor = null;
+ try {
+ DungeonRoom dungeonRoom = context.getRoomMapper().get(roomPt);
+ if (dungeonRoom != null) {
+ if (dungeonRoom.getRoomProcessor() != null) {
+ dungeonRoom.getRoomProcessor().onBlockUpdate(postInteract);
+ }
+ }
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+
@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent keyInputEvent) {
if (FeatureRegistry.DEBUG.isEnabled() && FeatureRegistry.ADVANCED_ROOMEDIT.isEnabled() && Keybinds.editingSession.isKeyDown() ){
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/PacketListener.java b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/PacketListener.java
index b89a5fde..afb60168 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/PacketListener.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/eventlistener/PacketListener.java
@@ -25,15 +25,16 @@ import io.netty.channel.ChannelPromise;
import kr.syeyoung.dungeonsguide.SkyblockStatus;
import kr.syeyoung.dungeonsguide.DungeonsGuide;
import kr.syeyoung.dungeonsguide.cosmetics.CustomPacketPlayerListItem;
-import kr.syeyoung.dungeonsguide.events.PlayerInteractEntityEvent;
-import kr.syeyoung.dungeonsguide.events.PlayerListItemPacketEvent;
-import kr.syeyoung.dungeonsguide.events.TitleEvent;
-import kr.syeyoung.dungeonsguide.events.WindowUpdateEvent;
+import kr.syeyoung.dungeonsguide.events.*;
import kr.syeyoung.dungeonsguide.features.FeatureRegistry;
+import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.network.Packet;
+import net.minecraft.network.play.INetHandlerPlayClient;
import net.minecraft.network.play.client.C02PacketUseEntity;
import net.minecraft.network.play.server.*;
+import net.minecraft.util.BlockPos;
+import net.minecraft.util.Tuple;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
@@ -63,9 +64,69 @@ public class PacketListener extends ChannelDuplexHandler {
if (packet instanceof S30PacketWindowItems || packet instanceof S2FPacketSetSlot) {
MinecraftForge.EVENT_BUS.post(new WindowUpdateEvent(packet instanceof S30PacketWindowItems ? (S30PacketWindowItems)packet : null , packet instanceof S2FPacketSetSlot ? (S2FPacketSetSlot)packet : null));
}
+ if (packet instanceof S23PacketBlockChange) {
+ packet = new SingleBlockChange((S23PacketBlockChange) packet);
+ } else if (packet instanceof S22PacketMultiBlockChange) {
+ packet = new MultiBlockChange((S22PacketMultiBlockChange) packet);
+ }
super.channelRead(ctx, packet);
}
+ private static class SingleBlockChange extends S23PacketBlockChange {
+ private S23PacketBlockChange old;
+ public SingleBlockChange(S23PacketBlockChange blockChange) {
+ this.old = blockChange;
+ }
+
+ @Override
+ public void processPacket(INetHandlerPlayClient handler) {
+ BlockUpdateEvent blockUpdateEvent = new BlockUpdateEvent.Pre();
+ blockUpdateEvent.getUpdatedBlocks().add(new Tuple<>(getBlockPosition(),getBlockState()));
+ MinecraftForge.EVENT_BUS.post(blockUpdateEvent);
+ super.processPacket(handler);
+ blockUpdateEvent = new BlockUpdateEvent.Post();
+ blockUpdateEvent.getUpdatedBlocks().add(new Tuple<>(getBlockPosition(), getBlockState()));
+ MinecraftForge.EVENT_BUS.post(blockUpdateEvent);
+ }
+
+ @Override
+ public BlockPos getBlockPosition() {
+ return old.getBlockPosition();
+ }
+
+ @Override
+ public IBlockState getBlockState() {
+ return old.getBlockState();
+ }
+ }
+
+
+ private static class MultiBlockChange extends S22PacketMultiBlockChange {
+ private S22PacketMultiBlockChange old;
+ public MultiBlockChange(S22PacketMultiBlockChange blockChange) {
+ this.old = blockChange;
+ }
+ @Override
+ public void processPacket(INetHandlerPlayClient handler) {
+ BlockUpdateEvent blockUpdateEvent = new BlockUpdateEvent.Pre();
+ for (S22PacketMultiBlockChange.BlockUpdateData changedBlock : getChangedBlocks()) {
+ blockUpdateEvent.getUpdatedBlocks().add(new Tuple<>(changedBlock.getPos(), changedBlock.getBlockState()));
+ }
+ MinecraftForge.EVENT_BUS.post(blockUpdateEvent);
+ super.processPacket(handler);
+ blockUpdateEvent = new BlockUpdateEvent.Post();
+ for (S22PacketMultiBlockChange.BlockUpdateData changedBlock : getChangedBlocks()) {
+ blockUpdateEvent.getUpdatedBlocks().add(new Tuple<>(changedBlock.getPos(), changedBlock.getBlockState()));
+ }
+ MinecraftForge.EVENT_BUS.post(blockUpdateEvent);
+ }
+
+ @Override
+ public BlockUpdateData[] getChangedBlocks() {
+ return old.getChangedBlocks();
+ }
+ }
+
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
Packet packet = (Packet) msg;
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/events/BlockUpdateEvent.java b/src/main/java/kr/syeyoung/dungeonsguide/events/BlockUpdateEvent.java
new file mode 100644
index 00000000..e6e94dcc
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/events/BlockUpdateEvent.java
@@ -0,0 +1,38 @@
+/*
+ * 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.events;
+
+import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
+import net.minecraft.block.state.IBlockState;
+import net.minecraft.util.BlockPos;
+import net.minecraft.util.Tuple;
+import net.minecraftforge.fml.common.eventhandler.Event;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public abstract class BlockUpdateEvent extends Event {
+ @Getter @Setter
+ private Set<Tuple<BlockPos, IBlockState>> updatedBlocks = new HashSet<>();
+
+ public static class Pre extends BlockUpdateEvent {};
+ public static class Post extends BlockUpdateEvent {};
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/pathfinding/JPSPathfinder.java b/src/main/java/kr/syeyoung/dungeonsguide/pathfinding/JPSPathfinder.java
index f3f058a7..657f3cb3 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/pathfinding/JPSPathfinder.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/pathfinding/JPSPathfinder.java
@@ -18,6 +18,7 @@
package kr.syeyoung.dungeonsguide.pathfinding;
+import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@@ -38,24 +39,17 @@ public class JPSPathfinder {
private Vec3 start;
private Vec3 destination;
+ private DungeonRoom dungeonRoom;
@Getter
private AxisAlignedBB destinationBB;
- public JPSPathfinder(World world, BlockPos min, BlockPos max ){
- this.min = min;
- this.max = max;
-
- ChunkCache chunkCache = new ChunkCache(world, min, max, 0);
- this.world = new CachedWorld(chunkCache);
-
- minx = min.getX() * 2; miny = min.getY() * 2; minz = min.getZ() * 2;
- maxx = max.getX() * 2 + 2; maxy = max.getY() * 2 + 2; maxz = max.getZ() * 2 + 2;
-
- lenx = maxx - minx;
- leny = maxy - miny;
- lenz = maxz - minz;
+ public JPSPathfinder(DungeonRoom dungeonRoom){
+ this.min = new BlockPos(dungeonRoom.getMinx(), 0, dungeonRoom.getMinz());
+ this.max = new BlockPos(dungeonRoom.getMaxx(), 255, dungeonRoom.getMaxz());
+ this.world = dungeonRoom.getCachedWorld();
+ this.dungeonRoom = dungeonRoom;
}
private IntHashMap<Node> nodeMap = new IntHashMap();
@@ -82,9 +76,6 @@ public class JPSPathfinder {
private int tx, ty, tz;
- private final int minx, miny, minz, maxx, maxy, maxz;
- private final int lenx, leny, lenz;
-
private Node addNode(Node parent, Node jumpPt, boolean addToOpen) {
float ng = parent.g + distSq(jumpPt.x - parent.x, jumpPt.y - parent.y, jumpPt.z - parent.z);
@@ -117,8 +108,6 @@ public class JPSPathfinder {
ty = (int)(to.yCoord * 2);
tz = (int)(to.zCoord * 2);
- arr = new long[lenx *leny * lenz * 2 / 8];
-
destinationBB = AxisAlignedBB.fromBounds((to.xCoord - within)* 2, (to.yCoord - within) * 2, (to.zCoord - within) * 2, (to.xCoord + within) * 2, (to.yCoord + within)* 2, (to.zCoord + within) *2);
open.clear();
Node start;
@@ -150,7 +139,7 @@ public class JPSPathfinder {
if (end == null) return false;
Node p = end;
while (p != null) {
- route.addLast(new Vec3(p.x / 2.0f, p.y / 2.0f, p.z / 2.0f));
+ route.addLast(new Vec3(p.x / 2.0f, p.y / 2.0f + 0.1, p.z / 2.0f));
p = p.parent;
}
@@ -184,9 +173,9 @@ public class JPSPathfinder {
for (int i = -1; i<=1; i++) {
for (int j = - 1; j<=1; j++) {
if (i == 0 && j == 0) continue;
- if (dx != 0 && isBlocked(x, y + i, z + j)) nexts.add(openNode(nx,y+i,z+j));
- if (dy != 0 && isBlocked(x + i, y, z + j)) nexts.add(openNode(x+i,ny,z+j));
- if (dz != 0 && isBlocked(x + i, y + j, z)) nexts.add(openNode(x+i,y+j,nz));
+ if (dx != 0 && dungeonRoom.isBlocked(x, y + i, z + j)) nexts.add(openNode(nx,y+i,z+j));
+ if (dy != 0 && dungeonRoom.isBlocked(x + i, y, z + j)) nexts.add(openNode(x+i,ny,z+j));
+ if (dz != 0 && dungeonRoom.isBlocked(x + i, y + j, z)) nexts.add(openNode(x+i,y+j,nz));
}
}
} else if (determinant == 2) {
@@ -195,37 +184,37 @@ public class JPSPathfinder {
if (dx != 0) nexts.add(openNode(nx,y,z));
nexts.add(openNode(nx,ny,nz));
if (dx == 0) {
- if (isBlocked(x, y, z-dz)) {
+ if (dungeonRoom.isBlocked(x, y, z-dz)) {
nexts.add(openNode(x, ny, z-dz));
- if (isBlocked(x+1, y, z-dz)) nexts.add(openNode(x+1, ny, z-dz));
- if (isBlocked(x-1, y, z-dz)) nexts.add(openNode(x-1, ny, z-dz));
+ if (dungeonRoom.isBlocked(x+1, y, z-dz)) nexts.add(openNode(x+1, ny, z-dz));
+ if (dungeonRoom.isBlocked(x-1, y, z-dz)) nexts.add(openNode(x-1, ny, z-dz));
}
- if (isBlocked(x, y-dy, z)) {
+ if (dungeonRoom.isBlocked(x, y-dy, z)) {
nexts.add(openNode(x, y-dy, nz));
- if (isBlocked(x+1, y-dy, z))nexts.add(openNode(x+1, y-dy, nz));
- if (isBlocked(x-1, y-dy, z))nexts.add(openNode(x+1, y-dy, nz));
+ if (dungeonRoom.isBlocked(x+1, y-dy, z))nexts.add(openNode(x+1, y-dy, nz));
+ if (dungeonRoom.isBlocked(x-1, y-dy, z))nexts.add(openNode(x+1, y-dy, nz));
}
} else if (dy == 0) {
- if (isBlocked(x, y, z-dz)) {
+ if (dungeonRoom.isBlocked(x, y, z-dz)) {
nexts.add(openNode(x, ny, z-dz));
- if (isBlocked(x, y+1, z-dz)) nexts.add(openNode(nx, y+1, z-dz));
- if (isBlocked(x, y-1, z-dz)) nexts.add(openNode(nx, y-1, z-dz));
+ if (dungeonRoom.isBlocked(x, y+1, z-dz)) nexts.add(openNode(nx, y+1, z-dz));
+ if (dungeonRoom.isBlocked(x, y-1, z-dz)) nexts.add(openNode(nx, y-1, z-dz));
}
- if (isBlocked(x-dx, y, z)) {
+ if (dungeonRoom.isBlocked(x-dx, y, z)) {
nexts.add(openNode(x-dx, y, nz));
- if (isBlocked(x-dx, y+1, z))nexts.add(openNode(x-dx, y+1, nz));
- if (isBlocked(x-dx, y-1, z))nexts.add(openNode(x-dx, y-1, nz));
+ if (dungeonRoom.isBlocked(x-dx, y+1, z))nexts.add(openNode(x-dx, y+1, nz));
+ if (dungeonRoom.isBlocked(x-dx, y-1, z))nexts.add(openNode(x-dx, y-1, nz));
}
} else if (dz == 0) {
- if (isBlocked(x, y-dy, z)) {
+ if (dungeonRoom.isBlocked(x, y-dy, z)) {
nexts.add(openNode(nx, y-dy, z));
- if (isBlocked(x, y-dy, z+1))nexts.add(openNode(nx, y-dy, z+1));
- if (isBlocked(x, y-dy, z-1))nexts.add(openNode(nx, y-dy, z-1));
+ if (dungeonRoom.isBlocked(x, y-dy, z+1))nexts.add(openNode(nx, y-dy, z+1));
+ if (dungeonRoom.isBlocked(x, y-dy, z-1))nexts.add(openNode(nx, y-dy, z-1));
}
- if (isBlocked(x-dx, y, z)) {
+ if (dungeonRoom.isBlocked(x-dx, y, z)) {
nexts.add(openNode(x-dx, ny, z));
- if (isBlocked(x-dx, y, z+1))nexts.add(openNode(x-dx, ny, z+1));
- if (isBlocked(x-dx, y, z-1))nexts.add(openNode(x-dx, ny, z-1));
+ if (dungeonRoom.isBlocked(x-dx, y, z+1))nexts.add(openNode(x-dx, ny, z+1));
+ if (dungeonRoom.isBlocked(x-dx, y, z-1))nexts.add(openNode(x-dx, ny, z-1));
}
}
} else if (determinant == 3) {
@@ -237,17 +226,17 @@ public class JPSPathfinder {
nexts.add(openNode(nx,ny,z));
nexts.add(openNode(nx,ny,nz));
- if (isBlocked(x,y,z-dz)) {
+ if (dungeonRoom.isBlocked(x,y,z-dz)) {
nexts.add(openNode(x,ny,z-dz));
nexts.add(openNode(nx,ny,z-dz));
nexts.add(openNode(nx,y,z-dz));
}
- if (isBlocked(x-dx,y,z)) {
+ if (dungeonRoom.isBlocked(x-dx,y,z)) {
nexts.add(openNode(x-dx,ny,nz));
nexts.add(openNode(x-dx,ny,z));
nexts.add(openNode(x-dx,y,nz));
}
- if (isBlocked(x,y-dy,z)) {
+ if (dungeonRoom.isBlocked(x,y-dy,z)) {
nexts.add(openNode(x,y-dy,nz));
nexts.add(openNode(nx,y-dy,x));
nexts.add(openNode(nx,y-dy,nz));
@@ -259,7 +248,7 @@ public class JPSPathfinder {
public Node expand(int x, int y, int z, int dx, int dy, int dz) {
while(true) {
int nx = x + dx, ny = y + dy, nz = z + dz;
- if (isBlocked(nx, ny, nz)) return null;
+ if (dungeonRoom.isBlocked(nx, ny, nz)) return null;
if (nx > destinationBB.minX && nx < destinationBB.maxX && ny > destinationBB.minY && ny < destinationBB.maxY && nz > destinationBB.minZ && nz < destinationBB.maxZ) return openNode(nx,ny,nz);
@@ -268,20 +257,20 @@ public class JPSPathfinder {
for (int i = -1; i<=1; i++) {
for (int j = - 1; j<=1; j++) {
if (i == 0 && j == 0) continue;
- if (dx != 0 && isBlocked(nx, ny + i, nz + j) && !isBlocked(nx+dx, ny + i, nz + j)) return openNode(nx,ny,nz);
- if (dy != 0 && isBlocked(nx + i, ny, nz + j) && !isBlocked(nx + i, ny+dy, nz + j)) return openNode(nx,ny,nz);
- if (dz != 0 && isBlocked(nx + i, ny + j , nz) && !isBlocked(nx + i, ny + j , nz+dz)) return openNode(nx,ny,nz);
+ if (dx != 0 && dungeonRoom.isBlocked(nx, ny + i, nz + j) && !dungeonRoom.isBlocked(nx+dx, ny + i, nz + j)) return openNode(nx,ny,nz);
+ if (dy != 0 && dungeonRoom.isBlocked(nx + i, ny, nz + j) && !dungeonRoom.isBlocked(nx + i, ny+dy, nz + j)) return openNode(nx,ny,nz);
+ if (dz != 0 && dungeonRoom.isBlocked(nx + i, ny + j , nz) && !dungeonRoom.isBlocked(nx + i, ny + j , nz+dz)) return openNode(nx,ny,nz);
}
}
} else if (determinant == 2) {
- if ((dx != 0 && isBlocked(nx , y , z ) && !isBlocked(nx + dx, y , z))
- || (dy != 0 && isBlocked(x , ny , z) && !isBlocked(x , ny+dy , z))
- || (dz != 0 && isBlocked(x , y , nz ) && !isBlocked(x , y , nz+dz))) return openNode(nx,ny,nz);
+ if ((dx != 0 && dungeonRoom.isBlocked(nx , y , z ) && !dungeonRoom.isBlocked(nx + dx, y , z))
+ || (dy != 0 && dungeonRoom.isBlocked(x , ny , z) && !dungeonRoom.isBlocked(x , ny+dy , z))
+ || (dz != 0 && dungeonRoom.isBlocked(x , y , nz ) && !dungeonRoom.isBlocked(x , y , nz+dz))) return openNode(nx,ny,nz);
if (dx != 0 && expand(nx, ny, nz, dx, 0,0) != null) return openNode(nx,ny,nz);
if (dy != 0 && expand(nx, ny, nz, 0, dy,0) != null) return openNode(nx,ny,nz);
if (dz != 0 && expand(nx, ny, nz, 0, 0,dz) != null) return openNode(nx,ny,nz);
} else if (determinant == 3) {
- if (isBlocked(x, ny, nz ) || isBlocked(nx, y , nz) || isBlocked(nx, ny, z)) return openNode(nx,ny,nz);
+ if (dungeonRoom.isBlocked(x, ny, nz ) || dungeonRoom.isBlocked(nx, y , nz) || dungeonRoom.isBlocked(nx, ny, z)) return openNode(nx,ny,nz);
if (expand(nx, ny, nz, dx, 0, 0) != null ||
expand(nx, ny, nz, dx, dy, 0) != null ||
expand(nx, ny, nz, dx, 0, dz) != null ||
@@ -293,62 +282,6 @@ public class JPSPathfinder {
}
}
- private static final float playerWidth = 0.3f;
- public boolean isBlocked(int x,int y, int z) {
- if (x < minx || z < minz || x >= maxx || z >= maxz || y < miny || y >= maxy) return true;
- int dx = x - minx, dy = y - miny, dz = z - minz;
- int bitIdx = dx * leny * lenz + dy * lenz + dz;
- int location = bitIdx / 4;
- int bitStart = (2 * (bitIdx % 4));
- long theBit = arr[location];
- if (((theBit >> bitStart) & 0x2) > 0) return ((theBit >> bitStart) & 1) > 0;
- float wX = x / 2.0f, wY = y / 2.0f, wZ = z / 2.0f;
-
-
- AxisAlignedBB bb = AxisAlignedBB.fromBounds(wX - playerWidth, wY, wZ - playerWidth, wX + playerWidth, wY + 1.9f, wZ + playerWidth);
-
- int i = MathHelper.floor_double(bb.minX);
- int j = MathHelper.floor_double(bb.maxX + 1.0D);
- int k = MathHelper.floor_double(bb.minY);
- int l = MathHelper.floor_double(bb.maxY + 1.0D);
- int i1 = MathHelper.floor_double(bb.minZ);
- int j1 = MathHelper.floor_double(bb.maxZ + 1.0D);
- BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos();
-
- List<AxisAlignedBB> list = new ArrayList<>();
- for (int k1 = i; k1 < j; ++k1) {
- for (int l1 = i1; l1 < j1; ++l1) {
- for (int i2 = k - 1; i2 < l; ++i2) {
- blockPos.set(k1, i2, l1);
- IBlockState iblockstate1 = world.getBlockState(blockPos);
- Block b = iblockstate1.getBlock();
- if (!b.getMaterial().blocksMovement())continue;
- if (b.isFullCube() && i2 == k-1) continue;
- if (iblockstate1.equals( NodeProcessorDungeonRoom.preBuilt)) continue;
- if (b.isFullCube()) {
- theBit |= (3L << bitStart);
- arr[location] = theBit;
- return true;
- }
- try {
- b.addCollisionBoxesToList(world, blockPos, iblockstate1, bb, list, null);
- } catch (Exception e) {
- return true;
- }
- if (list.size() > 0) {
- theBit |= (3L << bitStart);
- arr[location] = theBit;
- return true;
- }
- }
- }
- }
- theBit |= 2L << bitStart;
- arr[location] = theBit;
- return false;
- }
-
-
@RequiredArgsConstructor
@Data
public static final class Node {
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/GeneralRoomProcessor.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/GeneralRoomProcessor.java
index c0696a9e..0b002161 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/GeneralRoomProcessor.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/GeneralRoomProcessor.java
@@ -30,8 +30,10 @@ import kr.syeyoung.dungeonsguide.dungeon.data.OffsetPoint;
import kr.syeyoung.dungeonsguide.dungeon.mechanics.DungeonMechanic;
import kr.syeyoung.dungeonsguide.dungeon.mechanics.DungeonSecret;
import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom;
+import kr.syeyoung.dungeonsguide.events.BlockUpdateEvent;
import kr.syeyoung.dungeonsguide.events.PlayerInteractEntityEvent;
import kr.syeyoung.dungeonsguide.features.FeatureRegistry;
+import kr.syeyoung.dungeonsguide.pathfinding.NodeProcessorDungeonRoom;
import kr.syeyoung.dungeonsguide.roomedit.EditingContext;
import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonAddSet;
import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonRoomEdit;
@@ -72,6 +74,7 @@ public class GeneralRoomProcessor implements RoomProcessor {
}
private boolean ticked = false;
+
@Override
public void tick() {
if (!ticked && FeatureRegistry.SECRET_AUTO_START.isEnabled())
@@ -412,6 +415,13 @@ public class GeneralRoomProcessor implements RoomProcessor {
}
}
}
+ @Override
+ public void onBlockUpdate(BlockUpdateEvent blockUpdateEvent) {
+ for (Tuple<BlockPos, IBlockState> updatedBlock : blockUpdateEvent.getUpdatedBlocks()) {
+ if (updatedBlock.getSecond().equals(NodeProcessorDungeonRoom.preBuilt)) continue;
+ dungeonRoom.resetBlock(updatedBlock.getFirst());
+ }
+ }
public static class Generator implements RoomProcessorGenerator<GeneralRoomProcessor> {
@Override
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessor.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessor.java
index 0f4cce7c..848bd71a 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessor.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessor.java
@@ -19,6 +19,7 @@
package kr.syeyoung.dungeonsguide.roomprocessor;
import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom;
+import kr.syeyoung.dungeonsguide.events.BlockUpdateEvent;
import kr.syeyoung.dungeonsguide.events.PlayerInteractEntityEvent;
import net.minecraft.util.IChatComponent;
import net.minecraftforge.client.event.GuiScreenEvent;
@@ -46,4 +47,6 @@ public interface RoomProcessor {
void onInteract(PlayerInteractEntityEvent event);
void onInteractBlock(PlayerInteractEvent event);
+
+ void onBlockUpdate(BlockUpdateEvent blockUpdateEvent);
} \ No newline at end of file
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/GeneralDefuseChamberProcessor.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/GeneralDefuseChamberProcessor.java
index 6ea0fd95..823e322b 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/GeneralDefuseChamberProcessor.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bombdefuse/chambers/GeneralDefuseChamberProcessor.java
@@ -19,6 +19,7 @@
package kr.syeyoung.dungeonsguide.roomprocessor.bombdefuse.chambers;
import kr.syeyoung.dungeonsguide.Keybinds;
+import kr.syeyoung.dungeonsguide.events.BlockUpdateEvent;
import kr.syeyoung.dungeonsguide.events.PlayerInteractEntityEvent;
import kr.syeyoung.dungeonsguide.roomprocessor.bombdefuse.RoomProcessorBombDefuseSolver;
import lombok.Getter;
@@ -84,6 +85,10 @@ public abstract class GeneralDefuseChamberProcessor implements ChamberProcessor
public void actionbarReceived(IChatComponent chat) {
}
+ @Override
+ public void onBlockUpdate(BlockUpdateEvent blockUpdateEvent) {
+
+ }
@Override
public boolean readGlobalChat() {
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bossfight/GeneralBossfightProcessor.java b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bossfight/GeneralBossfightProcessor.java
index 8ea4b5a6..1d297a0d 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bossfight/GeneralBossfightProcessor.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/bossfight/GeneralBossfightProcessor.java
@@ -18,6 +18,7 @@
package kr.syeyoung.dungeonsguide.roomprocessor.bossfight;
+import kr.syeyoung.dungeonsguide.events.BlockUpdateEvent;
import kr.syeyoung.dungeonsguide.events.PlayerInteractEntityEvent;
import lombok.*;
import net.minecraft.entity.boss.BossStatus;
@@ -127,6 +128,10 @@ public abstract class GeneralBossfightProcessor implements BossfightProcessor {
public void onEntityDeath(LivingDeathEvent deathEvent) {
}
+ @Override
+ public void onBlockUpdate(BlockUpdateEvent blockUpdateEvent) {
+
+ }
public void onPhaseChange() {}