mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-07 16:01:55 +01:00
Initial hydrazine commit
This commit is contained in:
parent
5c1e6e7572
commit
2ea4c2d996
@ -3,8 +3,7 @@ package fr.themode.demo;
|
||||
import fr.themode.demo.blocks.BurningTorchBlock;
|
||||
import fr.themode.demo.blocks.StoneBlock;
|
||||
import fr.themode.demo.blocks.UpdatableBlockDemo;
|
||||
import fr.themode.demo.commands.EntitySelectorCommand;
|
||||
import fr.themode.demo.commands.TestCommand;
|
||||
import fr.themode.demo.commands.*;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.command.CommandManager;
|
||||
import net.minestom.server.instance.block.BlockManager;
|
||||
@ -31,10 +30,10 @@ public class Main {
|
||||
CommandManager commandManager = MinecraftServer.getCommandManager();
|
||||
commandManager.register(new EntitySelectorCommand());
|
||||
commandManager.register(new TestCommand());
|
||||
//commandManager.register(new HealthCommand());
|
||||
//commandManager.register(new SimpleCommand());
|
||||
//commandManager.register(new GamemodeCommand());
|
||||
//commandManager.register(new DimensionCommand());
|
||||
commandManager.register(new HealthCommand());
|
||||
commandManager.register(new SimpleCommand());
|
||||
commandManager.register(new GamemodeCommand());
|
||||
commandManager.register(new DimensionCommand());
|
||||
|
||||
/*RecipeManager recipeManager = MinecraftServer.getRecipeManager();
|
||||
ShapelessRecipe shapelessRecipe = new ShapelessRecipe("test", "groupname") {
|
||||
|
@ -38,7 +38,6 @@ import net.minestom.server.utils.time.TimeUnit;
|
||||
import net.minestom.server.utils.time.UpdateOption;
|
||||
import net.minestom.server.world.DimensionType;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -55,7 +54,7 @@ public class PlayerInit {
|
||||
//instanceContainer = MinecraftServer.getInstanceManager().createInstanceContainer(storageFolder);
|
||||
instanceContainer = MinecraftServer.getInstanceManager().createInstanceContainer(DimensionType.OVERWORLD);
|
||||
instanceContainer.enableAutoChunkLoad(true);
|
||||
instanceContainer.setChunkGenerator(noiseTestGenerator);
|
||||
instanceContainer.setChunkGenerator(chunkGeneratorDemo);
|
||||
|
||||
netherTest = MinecraftServer.getInstanceManager().createInstanceContainer(DimensionType.NETHER);
|
||||
netherTest.enableAutoChunkLoad(true);
|
||||
@ -267,7 +266,10 @@ public class PlayerInit {
|
||||
mapDataPacket.z = 0;
|
||||
|
||||
final byte[] data = new byte[127 * 127];
|
||||
Arrays.fill(data, (byte) 10);
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
final byte color = (byte) (i % 2 == 0 ? 5 : 10);
|
||||
data[i] = color;
|
||||
}
|
||||
|
||||
mapDataPacket.data = data;
|
||||
|
||||
|
@ -1,11 +1,18 @@
|
||||
package fr.themode.demo.commands;
|
||||
|
||||
import com.extollit.gaming.ai.path.HydrazinePathFinder;
|
||||
import com.extollit.gaming.ai.path.model.PathObject;
|
||||
import com.extollit.linalg.immutable.Vec3i;
|
||||
import fr.themode.demo.entity.ChickenCreature;
|
||||
import net.minestom.server.command.CommandProcessor;
|
||||
import net.minestom.server.command.CommandSender;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.entity.pathfinding.hydrazine.PFInstanceSpace;
|
||||
import net.minestom.server.entity.pathfinding.hydrazine.PFPathingEntity;
|
||||
import net.minestom.server.instance.Instance;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class SimpleCommand implements CommandProcessor {
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
@ -55,21 +62,21 @@ public class SimpleCommand implements CommandProcessor {
|
||||
ChickenCreature chickenCreature = new ChickenCreature(player.getPosition());
|
||||
chickenCreature.setInstance(instance);
|
||||
|
||||
/*PFPathingEntity pathingEntity = new PFPathingEntity(chickenCreature);
|
||||
PFPathingEntity pathingEntity = new PFPathingEntity(chickenCreature);
|
||||
PFInstanceSpace instanceSpace = new PFInstanceSpace(instance);
|
||||
|
||||
final HydrazinePathFinder pathFinder = new HydrazinePathFinder(pathingEntity, instanceSpace);
|
||||
|
||||
final PathObject path = pathFinder.initiatePathTo(-10, 42, -10);
|
||||
final PathObject path = pathFinder.initiatePathTo(-10, 40, -10);
|
||||
|
||||
System.out.println("path: "+path);
|
||||
System.out.println("path: " + path);
|
||||
|
||||
for (Iterator<Vec3i> it = path.iterator(); it.hasNext(); ) {
|
||||
Vec3i ite = it.next();
|
||||
|
||||
System.out.println("test: " + ite);
|
||||
|
||||
}*/
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
package net.minestom.server.entity.pathfinding.hydrazine;
|
||||
|
||||
import com.extollit.gaming.ai.path.model.IBlockDescription;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
|
||||
public class PFBlockDescription implements IBlockDescription {
|
||||
|
||||
private Block block;
|
||||
|
||||
public PFBlockDescription(Block block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFenceLike() {
|
||||
return block.name().toLowerCase().contains("FENCE");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClimbable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDoor() {
|
||||
return block.name().toLowerCase().contains("DOOR");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isImpeding() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullyBounded() {
|
||||
return block.isSolid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLiquid() {
|
||||
return block.isLiquid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncinerating() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package net.minestom.server.entity.pathfinding.hydrazine;
|
||||
|
||||
import com.extollit.gaming.ai.path.model.IBlockObject;
|
||||
import com.extollit.linalg.immutable.AxisAlignedBBox;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
|
||||
public class PFBlockObject implements IBlockObject {
|
||||
|
||||
private Block block;
|
||||
|
||||
public PFBlockObject(Block block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBBox bounds() {
|
||||
return new AxisAlignedBBox(
|
||||
0, 0, 0,
|
||||
1, 1, 1
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFenceLike() {
|
||||
return block.name().toLowerCase().contains("FENCE");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClimbable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDoor() {
|
||||
return block.name().toLowerCase().contains("DOOR");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isImpeding() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullyBounded() {
|
||||
return block.isSolid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLiquid() {
|
||||
return block.isLiquid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncinerating() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package net.minestom.server.entity.pathfinding.hydrazine;
|
||||
|
||||
import com.extollit.gaming.ai.path.model.ColumnarOcclusionFieldList;
|
||||
import com.extollit.gaming.ai.path.model.IBlockDescription;
|
||||
import com.extollit.gaming.ai.path.model.IColumnarSpace;
|
||||
import com.extollit.gaming.ai.path.model.IInstanceSpace;
|
||||
import net.minestom.server.instance.Chunk;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
|
||||
public class PFColumnarSpace implements IColumnarSpace {
|
||||
|
||||
private final ColumnarOcclusionFieldList occlusionFieldList = new ColumnarOcclusionFieldList(this);
|
||||
private PFInstanceSpace instanceSpace;
|
||||
private Chunk chunk;
|
||||
|
||||
|
||||
public PFColumnarSpace(PFInstanceSpace instanceSpace, Chunk chunk) {
|
||||
this.instanceSpace = instanceSpace;
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockDescription blockAt(int x, int y, int z) {
|
||||
short blockId = chunk.getBlockId(x, y, z);
|
||||
Block block = Block.fromId(blockId);
|
||||
return new PFBlockDescription(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int metaDataAt(int x, int y, int z) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColumnarOcclusionFieldList occlusionFields() {
|
||||
return occlusionFieldList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInstanceSpace instance() {
|
||||
return instanceSpace;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package net.minestom.server.entity.pathfinding.hydrazine;
|
||||
|
||||
import com.extollit.gaming.ai.path.model.IBlockObject;
|
||||
import com.extollit.gaming.ai.path.model.IColumnarSpace;
|
||||
import com.extollit.gaming.ai.path.model.IInstanceSpace;
|
||||
import net.minestom.server.instance.Chunk;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PFInstanceSpace implements IInstanceSpace {
|
||||
|
||||
private Instance instance;
|
||||
private Map<Chunk, PFColumnarSpace> chunkSpaceMap = new HashMap<>();
|
||||
|
||||
public PFInstanceSpace(Instance instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockObject blockObjectAt(int x, int y, int z) {
|
||||
short blockId = instance.getBlockId(x, y, z);
|
||||
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));
|
||||
return columnarSpace;
|
||||
}
|
||||
|
||||
public Instance getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
package net.minestom.server.entity.pathfinding.hydrazine;
|
||||
|
||||
import com.extollit.gaming.ai.path.model.IPathingEntity;
|
||||
import com.extollit.linalg.immutable.Vec3d;
|
||||
import net.minestom.server.attribute.Attribute;
|
||||
import net.minestom.server.entity.EntityCreature;
|
||||
import net.minestom.server.utils.Position;
|
||||
|
||||
public class PFPathingEntity implements IPathingEntity {
|
||||
|
||||
private static final float SEARCH_RANGE = 32;
|
||||
|
||||
private EntityCreature entity;
|
||||
|
||||
public PFPathingEntity(EntityCreature entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int age() {
|
||||
return (int) entity.getAliveTicks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float searchRange() {
|
||||
return SEARCH_RANGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Capabilities capabilities() {
|
||||
return new Capabilities() {
|
||||
@Override
|
||||
public float speed() {
|
||||
return entity.getAttributeValue(Attribute.MOVEMENT_SPEED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fireResistant() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cautious() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean climber() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean swimmer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean aquaphobic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean avoidsDoorways() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean opensDoors() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveTo(Vec3d position) {
|
||||
float speed = entity.getAttributeValue(Attribute.MOVEMENT_SPEED);
|
||||
entity.moveTowards(new Position((float) position.x, (float) position.y, (float) position.z), speed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3d coordinates() {
|
||||
Position position = entity.getPosition();
|
||||
return new Vec3d(position.getX(), position.getY(), position.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public float width() {
|
||||
return entity.getBoundingBox().getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float height() {
|
||||
return entity.getBoundingBox().getHeight();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user