diff --git a/modules/development/src/main/java/unnamed/mmo/server/dev/Main.java b/modules/development/src/main/java/unnamed/mmo/server/dev/Main.java index 575f7bf2..f248bb10 100644 --- a/modules/development/src/main/java/unnamed/mmo/server/dev/Main.java +++ b/modules/development/src/main/java/unnamed/mmo/server/dev/Main.java @@ -1,147 +1,84 @@ package unnamed.mmo.server.dev; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.mattworzala.debug.DebugMessage; +import com.mojang.serialization.JsonOps; import net.minestom.server.MinecraftServer; +import net.minestom.server.command.builder.Command; import net.minestom.server.coordinate.Pos; +import net.minestom.server.entity.GameMode; import net.minestom.server.entity.Player; import net.minestom.server.event.GlobalEventHandler; import net.minestom.server.event.player.PlayerLoginEvent; -import net.minestom.server.event.player.PlayerPacketOutEvent; +import net.minestom.server.event.player.PlayerSpawnEvent; +import net.minestom.server.extras.MojangAuth; import net.minestom.server.instance.Instance; import net.minestom.server.instance.InstanceManager; import net.minestom.server.instance.block.Block; -import net.minestom.server.network.packet.server.CachedPacket; -import net.minestom.server.network.packet.server.FramedPacket; -import net.minestom.server.network.packet.server.LazyPacket; -import net.minestom.server.network.packet.server.SendablePacket; -import net.minestom.server.network.packet.server.play.EntityHeadLookPacket; -import net.minestom.server.network.packet.server.play.EntityPositionAndRotationPacket; -import net.minestom.server.network.packet.server.play.EntityRotationPacket; -import unnamed.mmo.entity.HeadRotationZombie; -import unnamed.mmo.logging.LoggerFactory; +import net.minestom.server.potion.Potion; +import net.minestom.server.potion.PotionEffect; +import net.minestom.server.world.DimensionType; +import unnamed.mmo.blocks.BlockInteracter; +import unnamed.mmo.blocks.ore.Ore; +import unnamed.mmo.chat.ChatManager; +import unnamed.mmo.chat.storage.ChatStorage; +import unnamed.mmo.command.BaseCommandRegister; +import unnamed.mmo.damage.DamageProcessor; +import unnamed.mmo.entity.UnnamedEntity; +import unnamed.mmo.entity.brain.task.Task; +import unnamed.mmo.item.Item; +import unnamed.mmo.item.ItemManager; +import unnamed.mmo.item.entity.OwnedItemEntity; +import unnamed.mmo.player.PlayerImpl; +import unnamed.mmo.quest.QuestFacet; +import unnamed.mmo.server.dev.tool.DebugToolManager; +import unnamed.mmo.server.instance.TickTrackingInstance; + +import java.util.UUID; +import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.TimeUnit; public class Main { public static void main(String[] args) { - System.setProperty("minestom.viewable-packet", "false"); + System.setProperty("minestom.terminal.disabled", "true"); +// System.setProperty("minestom.viewable-packet", "false"); - // MinecraftServer server = MinecraftServer.init(); InstanceManager instanceManager = MinecraftServer.getInstanceManager(); - // - Instance instance = instanceManager.createInstanceContainer(); - // + Instance instance = new TickTrackingInstance(UUID.randomUUID(), DimensionType.OVERWORLD); + instanceManager.registerInstance(instance); instance.setGenerator(unit -> unit.modifier().fillHeight(0, 40, Block.STONE)); // GlobalEventHandler eventHandler = MinecraftServer.getGlobalEventHandler(); eventHandler.addListener(PlayerLoginEvent.class, event -> { final Player player = event.getPlayer(); - player.setPermissionLevel(2); event.setSpawningInstance(instance); player.setRespawnPoint(new Pos(0, 40, 0)); - - new HeadRotationZombie(){ - @Override - public void tick(long time) { -// System.out.println(position.sameView(lastSyncedPosition)); - super.tick(time); - var rot = new EntityPositionAndRotationPacket(getEntityId(), (short) 0, (short) 0, (short) 0, position.yaw(), position.pitch(), isOnGround()); - sendPacketToViewersAndSelf(rot); -// var headLook = new EntityHeadLookPacket(getEntityId(), position.yaw()); -// sendPacketToViewersAndSelf(headLook); -// System.out.println(onGround); - } - }.setInstance(instance, new Pos(5, 40, 0)); - }); - - eventHandler.addListener(PlayerPacketOutEvent.class, event -> { - SendablePacket packet = event.getPacket(); - if (packet instanceof CachedPacket cached) - packet = cached.packet(); - if (packet instanceof FramedPacket framed) - packet = framed.packet(); - if (packet instanceof LazyPacket lazy) - packet = lazy.packet(); - String name = packet.getClass().getSimpleName(); - if (packet.getClass().getSimpleName().contains("Entity")) { - if (name.equals("EntityVelocityPacket")) return; - if (name.equals("EntityPositionPacket")) return; - System.out.println(packet.getClass().getSimpleName()); - - if (packet instanceof EntityHeadLookPacket headLook) { -// System.out.println("POS/ROT : " + headLook); -// Vec dir = new Pos(0, 0, 0, headLook.yaw(), 0).direction(); -// Pos entityPos = Entity.getEntity(headLook.entityId()).getPosition(); -// DebugMessage.builder() -// .set(NamespaceID.from(ThreadLocalRandom.current().nextInt() + ""), new Line.Builder() -// .point(entityPos.asVec()) -// .point(dir.mul(2).add(entityPos.asVec())) -// .layer(Layer.TOP) -// .color(0xFFFFFF00) -// .build()) -//// .set(NamespaceID.from(ThreadLocalRandom.current().nextInt() + ""), new Text.Builder() -//// .content(System.currentTimeMillis() + "") -//// .position(dir.mul(2).add(entityPos.asVec())) -//// .layer(Layer.TOP) -//// .color(0xFFFFFF00) -//// .build()) -// .build() -// .sendTo(Audience.audience(MinecraftServer.getConnectionManager().getOnlinePlayers())); - } - if (packet instanceof EntityPositionAndRotationPacket posAndRot) { - System.out.println("POS/ROT : " + posAndRot.onGround()); -// Vec dir = new Pos(0, 0, 0, posAndRot.yaw(), posAndRot.pitch()).direction(); -// Pos entityPos = Entity.getEntity(posAndRot.entityId()).getPosition(); -// DebugMessage.builder() -// .set(NamespaceID.from(ThreadLocalRandom.current().nextInt() + ""), new Line.Builder() -// .point(entityPos.asVec()) -// .point(dir.mul(2).add(entityPos.asVec())) -// .layer(Layer.TOP) -// .color(0xFFFF00FF) -// .build()) -//// .set(NamespaceID.from(ThreadLocalRandom.current().nextInt() + ""), new Text.Builder() -//// .content(System.currentTimeMillis() + "") -//// .position(dir.mul(2).add(entityPos.asVec().withY(y -> y + 0.5))) -//// .layer(Layer.TOP) -//// .color(0xFFFF00FF) -//// .build()) -// .build() -// .sendTo(Audience.audience(MinecraftServer.getConnectionManager().getOnlinePlayers())); - } - } }); - // - server.start("0.0.0.0", 25565); - -// System.setProperty("minestom.terminal.disabled", "true"); -// System.setProperty("minestom.viewable-packet", "false"); + MojangAuth.init(); + MinecraftServer.getConnectionManager().setPlayerProvider(PlayerImpl::new); + eventHandler.addListener(PlayerSpawnEvent.class, event -> { + final Player player = event.getPlayer(); + player.setGameMode(GameMode.SURVIVAL); + player.setPermissionLevel(4); + player.setAllowFlying(true); -// MojangAuth.init(); -// MinecraftServer.getConnectionManager().setPlayerProvider(PlayerImpl::new); + // Testing + event.getSpawnInstance().setBlock(5, 43, 5, Ore.fromNamespaceId("unnamed:gold_ore").asBlock()); + event.getSpawnInstance().setBlock(4, 43, 5, Ore.fromNamespaceId("unnamed:diamond_ore").asBlock()); + player.getInventory().addItemStack(Item.fromNamespaceId("unnamed:diamond_pickaxe").asItemStack()); + //todo this needs to be done elsewhere + player.addEffect(new Potion(PotionEffect.MINING_FATIGUE, (byte) -1, Short.MAX_VALUE, (byte) 0x0)); -// Instance instance = new TickTrackingInstance(UUID.randomUUID(), DimensionType.OVERWORLD); -// instanceManager.registerInstance(instance); - -// eventHandler.addListener(PlayerSpawnEvent.class, event -> { -// final Player player = event.getPlayer(); -// player.setGameMode(GameMode.SURVIVAL); -// player.setPermissionLevel(4); -// player.setAllowFlying(true); - - // Testing -// event.getSpawnInstance().setBlock(5, 43, 5, Ore.fromNamespaceId("unnamed:gold_ore").asBlock()); -// event.getSpawnInstance().setBlock(4, 43, 5, Ore.fromNamespaceId("unnamed:diamond_ore").asBlock()); -// player.getInventory().addItemStack(Item.fromNamespaceId("unnamed:diamond_pickaxe").asItemStack()); -// -// //todo this needs to be done elsewhere -// player.addEffect(new Potion(PotionEffect.MINING_FATIGUE, (byte) -1, Short.MAX_VALUE, (byte) 0x0)); -// -// //todo a command for this -// player.getInventory().addItemStack(DebugToolManager.createTool("unnamed:hello")); + //todo a command for this + player.getInventory().addItemStack(DebugToolManager.createTool("unnamed:hello")); //todo test entity @@ -168,125 +105,58 @@ public void tick(long time) { // } // } // }"""); -// JsonElement json = JsonParser.parseString(""" -// { -// "type": "unnamed:sequence", -// "children": [ -// { -// "type": "unnamed:wander_in_region" -// }, -// { -// "type": "unnamed:idle", -// "time": 20 -// } -// ] -// }"""); -// Task task = JsonOps.INSTANCE.withDecoder(Task.Spec.CODEC) -// .apply(json).getOrThrow(false, System.err::println).getFirst().create(); -// UnnamedEntity entity = new UnnamedEntity(task); -// entity.setInstance(instance, new Pos(0, 40, 0)) -// .thenAccept(unused -> System.out.println("Spawned")); - -// Entity entity = new Entity(EntityType.ZOMBIE) { -// @Override -// public void tick(long time) { -// super.tick(time); -// -// lookAt(player); -// } -// }; -// }); -// eventHandler.addListener(PlayerPacketOutEvent.class, event -> { -// SendablePacket packet = event.getPacket(); -// if (packet instanceof CachedPacket cached) -// packet = cached.packet(); -// if (packet instanceof FramedPacket framed) -// packet = framed.packet(); -// if (packet instanceof LazyPacket lazy) -// packet = lazy.packet(); -// String name = packet.getClass().getSimpleName(); -// if (packet.getClass().getSimpleName().contains("Entity")) { -// if (name.equals("EntityVelocityPacket")) return; -// if (name.equals("EntityPositionPacket")) return; -// System.out.println(packet.getClass().getSimpleName()); -// -// if (packet instanceof EntityHeadLookPacket headLook) { -//// Vec dir = new Pos(0, 0, 0, headLook.yaw(), 0).direction(); -//// Pos entityPos = Entity.getEntity(headLook.entityId()).getPosition(); -//// DebugMessage.builder() -//// .set(NamespaceID.from(ThreadLocalRandom.current().nextInt() + ""), new Line.Builder() -//// .point(entityPos.asVec()) -//// .point(dir.mul(2).add(entityPos.asVec())) -//// .layer(Layer.TOP) -//// .color(0xFFFFFF00) -//// .build()) -////// .set(NamespaceID.from(ThreadLocalRandom.current().nextInt() + ""), new Text.Builder() -////// .content(System.currentTimeMillis() + "") -////// .position(dir.mul(2).add(entityPos.asVec())) -////// .layer(Layer.TOP) -////// .color(0xFFFFFF00) -////// .build()) -//// .build() -//// .sendTo(Audience.audience(MinecraftServer.getConnectionManager().getOnlinePlayers())); -// } -// if (packet instanceof EntityPositionAndRotationPacket posAndRot) { -// Vec dir = new Pos(0, 0, 0, posAndRot.yaw(), posAndRot.pitch()).direction(); -// Pos entityPos = Entity.getEntity(posAndRot.entityId()).getPosition(); -// DebugMessage.builder() -// .set(NamespaceID.from(ThreadLocalRandom.current().nextInt() + ""), new Line.Builder() -// .point(entityPos.asVec()) -// .point(dir.mul(2).add(entityPos.asVec())) -// .layer(Layer.TOP) -// .color(0xFFFF00FF) -// .build()) -//// .set(NamespaceID.from(ThreadLocalRandom.current().nextInt() + ""), new Text.Builder() -//// .content(System.currentTimeMillis() + "") -//// .position(dir.mul(2).add(entityPos.asVec().withY(y -> y + 0.5))) -//// .layer(Layer.TOP) -//// .color(0xFFFF00FF) -//// .build()) -// .build() -// .sendTo(Audience.audience(MinecraftServer.getConnectionManager().getOnlinePlayers())); -// } -// } -// }); + JsonElement json = JsonParser.parseString(""" + { + "type": "unnamed:sequence", + "children": [ + { + "type": "unnamed:wander_in_region" + }, + { + "type": "unnamed:idle", + "time": 20 + } + ] + }"""); + Task task = JsonOps.INSTANCE.withDecoder(Task.Spec.CODEC) + .apply(json).getOrThrow(false, System.err::println).getFirst().create(); + UnnamedEntity entity = new UnnamedEntity(task); + entity.setInstance(instance, new Pos(0, 40, 0)) + .thenAccept(unused -> System.out.println("Spawned")); + }); -// BaseCommandRegister.registerCommands(); + BaseCommandRegister.registerCommands(); -// Command c = new Command("clear"); -// c.setDefaultExecutor((sender, context) -> { -// DebugMessage.builder().clear().build().sendTo(sender); -// }); -// MinecraftServer.getCommandManager().register(c); + Command c = new Command("clear"); + c.setDefaultExecutor((sender, context) -> { + DebugMessage.builder().clear().build().sendTo(sender); + }); + MinecraftServer.getCommandManager().register(c); - // For now, manually register chat (with conn to mongo :/ need a config system) -// MongoClient mongoClient = MongoClients.create(MongoClientSettings.builder() -// .applyConnectionString(new ConnectionString("mongodb://localhost:27017")) -// .uuidRepresentation(UuidRepresentation.STANDARD) -// .build()); -// ChatStorage chatStorage = ChatStorage.mongo(mongoClient); -// ChatStorage chatStorage = ChatStorage.noop(); -// ChatManager chatManager = new ChatManager(chatStorage); -// chatManager.hook(MinecraftServer.process()); + ChatStorage chatStorage = ChatStorage.noop(); + ChatManager chatManager = new ChatManager(chatStorage); + chatManager.hook(MinecraftServer.process()); //todo properly implement a config system & use facets better -// ItemManager itemManager = new ItemManager(); -// itemManager.hook(MinecraftServer.process()); -// OwnedItemEntity.Handler itemEntityHandler = new OwnedItemEntity.Handler(); -// itemEntityHandler.hook(MinecraftServer.process()); + ItemManager itemManager = new ItemManager(); + itemManager.hook(MinecraftServer.process()); + OwnedItemEntity.Handler itemEntityHandler = new OwnedItemEntity.Handler(); + itemEntityHandler.hook(MinecraftServer.process()); //todo stupid facet implementation -// DebugToolManager debugToolManager = new DebugToolManager(); -// debugToolManager.hook(MinecraftServer.process()); + DebugToolManager debugToolManager = new DebugToolManager(); + debugToolManager.hook(MinecraftServer.process()); + + QuestFacet questFacet = new QuestFacet(); + questFacet.hook(MinecraftServer.process()); -// QuestFacet questFacet = new QuestFacet(); -// questFacet.hook(MinecraftServer.process()); + MinecraftServer.getSchedulerManager().buildShutdownTask(() -> + ForkJoinPool.commonPool().awaitQuiescence(10, TimeUnit.SECONDS)); -// MinecraftServer.getSchedulerManager().buildShutdownTask(() -> -// ForkJoinPool.commonPool().awaitQuiescence(10, TimeUnit.SECONDS)); + BlockInteracter.registerEvents(); + DamageProcessor.init(); -// BlockInteracter.registerEvents(); -// DamageProcessor.init(); + server.start("0.0.0.0", 25565); } diff --git a/modules/entity/build.gradle.kts b/modules/entity/build.gradle.kts index df480752..5612c744 100644 --- a/modules/entity/build.gradle.kts +++ b/modules/entity/build.gradle.kts @@ -4,5 +4,4 @@ plugins { dependencies { implementation(project(":modules:common")) - implementation(files("libs/enodia-pf-1.0.1.jar")) } diff --git a/modules/entity/libs/enodia-pf-1.0.1.jar b/modules/entity/libs/enodia-pf-1.0.1.jar deleted file mode 100644 index b1b2d5b1..00000000 Binary files a/modules/entity/libs/enodia-pf-1.0.1.jar and /dev/null differ diff --git a/modules/entity/src/main/java/unnamed/mmo/entity/brain/navigator/EnodiaNavigator.java b/modules/entity/src/main/java/unnamed/mmo/entity/brain/navigator/EnodiaNavigator.java deleted file mode 100644 index ffaa6f76..00000000 --- a/modules/entity/src/main/java/unnamed/mmo/entity/brain/navigator/EnodiaNavigator.java +++ /dev/null @@ -1,68 +0,0 @@ -package unnamed.mmo.entity.brain.navigator; - -import net.minestom.server.attribute.Attribute; -import net.minestom.server.coordinate.Point; -import net.minestom.server.entity.Entity; -import net.minestom.server.entity.LivingEntity; -import net.minestom.server.instance.Instance; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import sexy.kostya.enodia.EnodiaPF; -import sexy.kostya.enodia.movement.MovementProcessingHub; -import sexy.kostya.enodia.movement.MovementProcessor; -import sexy.kostya.enodia.movement.importance.MovementImportance; -import sexy.kostya.enodia.pathfinding.PathfindingCapabilities; -import unnamed.mmo.entity.brain.Brain; - -final class EnodiaNavigator implements Navigator { - private static final EnodiaPF INSTANCE = EnodiaPF.Companion.forImmutableWorlds(); - private static final MovementProcessingHub MOVEMENT_HUB = INSTANCE.initializeMovementProcessingHub( - 2, 5, - ent -> ent instanceof LivingEntity ? - ((LivingEntity) ent).getAttributeValue(Attribute.MOVEMENT_SPEED) : - Attribute.MOVEMENT_SPEED.defaultValue(), - (unused1, unused2, unused3) -> true - ); - - private static final PathfindingCapabilities DEFAULT_CAPABILITIES = PathfindingCapabilities.Companion.getDefault(); - private static final MovementImportance DEFAULT_IMPORTANCE = MovementImportance.Companion.getUNIMPORTANT(); - - private final Entity entity; - private MovementProcessor enodia; - - EnodiaNavigator(@NotNull Entity entity) { - this.entity = entity; - this.enodia = null; - } - - @Override - public void setInstance(@NotNull Instance instance) { - enodia = MOVEMENT_HUB.createMovementProcessor(entity, DEFAULT_CAPABILITIES); - } - - @Override - public boolean setPathTo(@Nullable Point point) { - if (point == null) { - this.enodia.stop(true); - return true; - } - - // Last parameter here is the max distance from the value. - return enodia.goTo(point, DEFAULT_IMPORTANCE, 0.5f); - } - - @Override - public boolean isActive() { - if (enodia == null) { - return false; - } - return enodia.isActive(); - } - - @Override - public void tick(long time) { - if (enodia != null) { - enodia.tick(time); - } - } -} diff --git a/modules/entity/src/main/java/unnamed/mmo/entity/brain/navigator/Navigator.java b/modules/entity/src/main/java/unnamed/mmo/entity/brain/navigator/Navigator.java index 05dfa7ba..4fe35168 100644 --- a/modules/entity/src/main/java/unnamed/mmo/entity/brain/navigator/Navigator.java +++ b/modules/entity/src/main/java/unnamed/mmo/entity/brain/navigator/Navigator.java @@ -11,10 +11,6 @@ public interface Navigator { - static @NotNull Navigator enodia(@NotNull Entity entity) { - return new EnodiaNavigator(entity); - } - static @NotNull Navigator hydrazine(@NotNull Entity entity) { return new HydrazineNavigator(entity); } diff --git a/modules/entity/src/test/java/unnamed/mmo/entity/brain/TestEnodiaPF.java b/modules/entity/src/test/java/unnamed/mmo/entity/brain/TestEnodiaPF.java deleted file mode 100644 index 5f1d4fbe..00000000 --- a/modules/entity/src/test/java/unnamed/mmo/entity/brain/TestEnodiaPF.java +++ /dev/null @@ -1,72 +0,0 @@ -package unnamed.mmo.entity.brain; - -import net.minestom.server.attribute.Attribute; -import net.minestom.server.coordinate.Pos; -import net.minestom.server.coordinate.Vec; -import net.minestom.server.entity.Entity; -import net.minestom.server.entity.EntityType; -import net.minestom.server.test.Env; -import net.minestom.server.test.EnvTest; -import org.junit.jupiter.api.Test; -import sexy.kostya.enodia.EnodiaPF; -import sexy.kostya.enodia.movement.MovementProcessor; -import sexy.kostya.enodia.movement.importance.MovementImportance; -import sexy.kostya.enodia.pathfinding.PathfindingCapabilities; - -import java.time.Duration; - -import static com.google.common.truth.Truth.assertThat; - -@EnvTest -public class TestEnodiaPF { - - @Test - public void test(Env env) { - var enodia = EnodiaPF.Companion.forImmutableWorlds(); - var hub = enodia.initializeMovementProcessingHub( - 2, - 5, - ent -> Attribute.MOVEMENT_SPEED.defaultValue(), - (a, b, c) -> true - ); - - var instance = env.createFlatInstance(); - var player = env.createPlayer(instance, new Pos(0, 42, 0)); - - var capabilities = PathfindingCapabilities.Companion.getDefault(); - var entity = new EnodiaEntity(); - entity.setInstance(instance, new Pos(5, 42, 5)) - .thenAccept(unused -> { - entity.movementProcessor = hub.createMovementProcessor(entity, capabilities); - - entity.movementProcessor.goTo(player, MovementImportance.Companion.getUNIMPORTANT(), 2); - }) - .join(); - - boolean result = env.tickWhile(() -> { - System.out.println(entity.getPosition()); -// return !entity.getPosition().sameBlock(new Vec(0, 40, 0)); - return entity.movementProcessor.isActive(); - }, Duration.ofMillis(100)); - - assertThat(result).isTrue(); - assertThat(entity.movementProcessor.isActive()).isFalse(); - } - - static class EnodiaEntity extends Entity { - - public EnodiaEntity() { - super(EntityType.ZOMBIE); - } - - MovementProcessor movementProcessor = null; - - @Override - public void update(long time) { - super.update(time); - if (movementProcessor != null) { - movementProcessor.tick(time); - } - } - } -} diff --git a/modules/entity/src/test/java/unnamed/mmo/entity/brain/navigator/TestUtil.java b/modules/entity/src/test/java/unnamed/mmo/entity/brain/navigator/TestUtil.java index 6c59a9ad..4256618c 100644 --- a/modules/entity/src/test/java/unnamed/mmo/entity/brain/navigator/TestUtil.java +++ b/modules/entity/src/test/java/unnamed/mmo/entity/brain/navigator/TestUtil.java @@ -11,7 +11,6 @@ public class TestUtil { public static Stream navigators() { return Stream.of( -// Arguments.of("enodia", (Function) EnodiaNavigator::new), // Arguments.of("hydrazine", (Function) HydrazineNavigator::new), // Arguments.of("custom", (Function) CustomNavigator::new), Arguments.of("motion", (Function) MotionNavigator::new)