mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-03 23:17:48 +01:00
pathfinding update
This commit is contained in:
parent
b54599a1f1
commit
e57485367c
@ -18,7 +18,7 @@ public class PFBlockDescription implements IBlockDescription {
|
||||
|
||||
@Override
|
||||
public boolean isClimbable() {
|
||||
return false;
|
||||
return block == Block.LADDER;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,6 +43,6 @@ public class PFBlockDescription implements IBlockDescription {
|
||||
|
||||
@Override
|
||||
public boolean isIncinerating() {
|
||||
return false;
|
||||
return block == Block.LAVA || block == Block.FIRE;
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class PFBlockObject implements IBlockObject {
|
||||
|
||||
@Override
|
||||
public boolean isClimbable() {
|
||||
return false;
|
||||
return block == Block.LADDER;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,6 +52,6 @@ public class PFBlockObject implements IBlockObject {
|
||||
|
||||
@Override
|
||||
public boolean isIncinerating() {
|
||||
return false;
|
||||
return block == Block.LAVA || block == Block.FIRE;
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,8 @@ public class PFColumnarSpace implements IColumnarSpace {
|
||||
|
||||
@Override
|
||||
public IBlockDescription blockAt(int x, int y, int z) {
|
||||
short blockId = chunk.getBlockId(x, y, z);
|
||||
Block block = Block.fromId(blockId);
|
||||
final short blockId = chunk.getBlockId(x, y, z);
|
||||
final Block block = Block.fromId(blockId);
|
||||
return new PFBlockDescription(block);
|
||||
}
|
||||
|
||||
|
@ -21,16 +21,21 @@ public class PFInstanceSpace implements IInstanceSpace {
|
||||
|
||||
@Override
|
||||
public IBlockObject blockObjectAt(int x, int y, int z) {
|
||||
short blockId = instance.getBlockId(x, y, z);
|
||||
Block block = Block.fromId(blockId);
|
||||
final short blockId = instance.getBlockId(x, y, z);
|
||||
final Block block = Block.fromId(blockId);
|
||||
return new PFBlockObject(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IColumnarSpace columnarSpaceAt(int cx, int cz) {
|
||||
Chunk chunk = instance.getChunk(cx, cz);
|
||||
PFColumnarSpace columnarSpace =
|
||||
chunkSpaceMap.computeIfAbsent(chunk, c -> new PFColumnarSpace(this, c));
|
||||
final Chunk chunk = instance.getChunk(cx, cz);
|
||||
final PFColumnarSpace columnarSpace =
|
||||
chunkSpaceMap.computeIfAbsent(chunk, c -> {
|
||||
final PFColumnarSpace cs = new PFColumnarSpace(this, c);
|
||||
c.setColumnarSpace(cs);
|
||||
return cs;
|
||||
});
|
||||
|
||||
return columnarSpace;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.instance;
|
||||
|
||||
import com.extollit.gaming.ai.path.model.ColumnarOcclusionFieldList;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import it.unimi.dsi.fastutil.ints.*;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
@ -7,6 +8,8 @@ import net.minestom.server.Viewable;
|
||||
import net.minestom.server.data.Data;
|
||||
import net.minestom.server.data.SerializableData;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.entity.pathfinding.PFBlockDescription;
|
||||
import net.minestom.server.entity.pathfinding.PFColumnarSpace;
|
||||
import net.minestom.server.event.player.PlayerChunkLoadEvent;
|
||||
import net.minestom.server.event.player.PlayerChunkUnloadEvent;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
@ -63,6 +66,9 @@ public final class Chunk implements Viewable {
|
||||
// Block entities
|
||||
private Set<Integer> blockEntities = new CopyOnWriteArraySet<>();
|
||||
|
||||
// Path finding
|
||||
private PFColumnarSpace columnarSpace;
|
||||
|
||||
// Cache
|
||||
private boolean loaded = true;
|
||||
private Set<Player> viewers = new CopyOnWriteArraySet<>();
|
||||
@ -146,6 +152,12 @@ public final class Chunk implements Viewable {
|
||||
}
|
||||
|
||||
this.packetUpdated = false;
|
||||
|
||||
if (columnarSpace != null) {
|
||||
final ColumnarOcclusionFieldList columnarOcclusionFieldList = columnarSpace.occlusionFields();
|
||||
final PFBlockDescription blockDescription = new PFBlockDescription(Block.fromId(blockId));
|
||||
columnarOcclusionFieldList.onBlockChanged(x, y, z, blockDescription, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBlockData(int x, int y, int z, Data data) {
|
||||
@ -278,6 +290,26 @@ public final class Chunk implements Viewable {
|
||||
return blockEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the columnar space linked to this chunk
|
||||
* <p>
|
||||
* Used internally by the pathfinder
|
||||
*
|
||||
* @return this chunk columnar space
|
||||
*/
|
||||
public PFColumnarSpace getColumnarSpace() {
|
||||
return columnarSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change this chunk columnar space
|
||||
*
|
||||
* @param columnarSpace the new columnar space
|
||||
*/
|
||||
public void setColumnarSpace(PFColumnarSpace columnarSpace) {
|
||||
this.columnarSpace = columnarSpace;
|
||||
}
|
||||
|
||||
public void setFullDataPacket(ByteBuf fullDataPacket) {
|
||||
this.fullDataPacket = fullDataPacket;
|
||||
this.packetUpdated = true;
|
||||
|
Loading…
Reference in New Issue
Block a user