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