Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entities v1 #28

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
52f5232
initial behavior entries & sanity test of enodia
mworzala Aug 15, 2022
175bd05
more entity work
mworzala Aug 16, 2022
ef7eb43
more tests
mworzala Aug 18, 2022
1ad4d14
add my dumb pathfinding impl, it needs a lot more testing
mworzala Aug 21, 2022
888956b
add debug renderer
mworzala Aug 21, 2022
92d1539
start testing selectors, not very happy with the system at all
mworzala Aug 21, 2022
2048b7e
very basic working selection
mworzala Aug 21, 2022
7a54bd8
more entity planning, start on mql for entity selectors
mworzala Aug 30, 2022
89403f7
minor tweaks and experimentation
mworzala Sep 1, 2022
a6bd6bf
Rework selector task to use mql script, add the concept of stimuli bu…
mworzala Sep 1, 2022
89867db
attack testing in FollowTargetTask, factor in path optimizer and iams…
mworzala Sep 4, 2022
5f499e0
base interface for new PF, first version of water path generator
mworzala Sep 4, 2022
17f6935
first version of land path generator
mworzala Sep 4, 2022
581c5af
first a star draft
mworzala Sep 5, 2022
cf19db5
add first version of string pull optimizer
mworzala Sep 5, 2022
f25851a
first (pretty bad) draft of slime movement.
mworzala Sep 5, 2022
dc19ab9
minor tweaks and debugging entity direction problem
mworzala Sep 5, 2022
8543b22
more debugging
mworzala Sep 5, 2022
5c6fee6
minor tweaks and debugging
mworzala Sep 5, 2022
b3fb1a9
remove debugging stuff
mworzala Sep 5, 2022
9097194
examples
mworzala Sep 5, 2022
406d0cc
rebase fixes
mworzala Sep 17, 2022
ff83587
mql improvement for defining query functions
mworzala Sep 17, 2022
04f5996
add gradle configuration cache
mworzala Sep 22, 2022
326e5b4
cleanup entity class, remove unused classes.
mworzala Sep 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.unsafe.configuration-cache = true
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minestom.server.instance.Instance;
import net.minestom.server.instance.block.Block;
import net.minestom.server.instance.block.BlockHandler;
import net.minestom.server.thread.TickThread;
import net.minestom.server.utils.NamespaceID;
import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
Expand All @@ -15,7 +16,6 @@
import net.hollowcube.blocks.ore.Ore;
import net.hollowcube.blocks.ore.event.PlayerOreBreakEvent;
import net.hollowcube.loot.LootContext;
import net.hollowcube.server.instance.TickTrackingInstance;
import net.hollowcube.util.BlockUtil;
import net.hollowcube.util.FutureUtil;

Expand Down Expand Up @@ -118,8 +118,9 @@ public void tick(@NotNull Tick tick) {
// Only tick once a second.
// This could be adjusted in the future if necessary.
final Instance instance = tick.getInstance();
long currentTick = ((TickTrackingInstance) instance).getTick();
if (currentTick % 20 != 0)
final TickThread thread = TickThread.current();
Check.notNull(thread, "TickThread.current() returned null");
if (thread.getTick() % 20 != 0)
return;

final Point pos = tick.getBlockPosition();
Expand Down
2 changes: 1 addition & 1 deletion modules/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ subprojects {
implementation("com.google.auto.service:auto-service-annotations:1.0.1")

// Minestom
implementation("com.github.minestommmo:Minestom:c6c97162a6")
implementation("com.github.minestommmo:Minestom:ec6035d939")

// Testing
testImplementation(project(":modules:test"))
Expand Down
2 changes: 2 additions & 0 deletions modules/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ dependencies {

implementation("org.tinylog:tinylog-impl:2.4.1")

api("com.github.mworzala.mc_debug_renderer:minestom:3ed4c6e97536a19")

implementation("io.github.cdimascio:dotenv-java:2.2.4")

// Optional components
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.mattworzala.debug.shape;

import com.mattworzala.debug.Layer;
import net.minestom.server.coordinate.Vec;
import net.minestom.server.utils.binary.BinaryWriter;
import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;

//todo remove me (this isn't present in mainline debug renderer currently)
public record OutlineBox(
Vec start,
Vec end,
int color,
Layer layer,
int colorLine,
Layer layerLine
) implements Shape {
private static final int ID = 3;

@Override
public void write(@NotNull BinaryWriter buffer) {
buffer.writeVarInt(ID);
buffer.writeDouble(start.x());
buffer.writeDouble(start.y());
buffer.writeDouble(start.z());
buffer.writeDouble(end.x());
buffer.writeDouble(end.y());
buffer.writeDouble(end.z());
buffer.writeInt(color);
buffer.writeVarInt(layer.ordinal());
buffer.writeInt(colorLine);
buffer.writeVarInt(layerLine.ordinal());
}

public static class Builder {
private Vec start;
private Vec end;
private int color = 0xFFFFFFFF;
private Layer layer = Layer.INLINE;
private int colorLine = 0xFFFFFFFF;
private Layer layerLine = Layer.INLINE;

public Builder start(Vec start) {
this.start = start;
return this;
}

public Builder end(Vec end) {
this.end = end;
return this;
}

public Builder block(int x, int y, int z) {
return block(x, y, z, 0.05);
}

public Builder block(int x, int y, int z, double expand) {
return start(new Vec(x - expand, y - expand, z - expand))
.end(new Vec(x + 1 + expand, y + 1 + expand, z + 1 + expand));
}

public Builder color(int color) {
this.color = color;
return this;
}

public Builder layer(Layer layer) {
this.layer = layer;
return this;
}

public Builder colorLine(int color) {
this.colorLine = color;
return this;
}

public Builder layerLine(Layer layer) {
this.layerLine = layer;
return this;
}

public OutlineBox build() {
Check.notNull(start, "start");
Check.notNull(end, "end");
return new OutlineBox(start, end, color, layer, colorLine, layerLine);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public ResourceFactory(NamespaceID namespace, Class<? extends T> type, Codec<? e
this.codec = codec;
}

public ResourceFactory(String namespace, Class<? extends T> type, Codec<? extends T> codec) {
this.namespace = NamespaceID.from(namespace);
this.type = type;
this.codec = codec;
}

@Override
public @NotNull NamespaceID namespace() {
return this.namespace;
Expand Down

This file was deleted.

14 changes: 14 additions & 0 deletions modules/common/src/main/java/net/hollowcube/util/StringUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.hollowcube.util;

import org.intellij.lang.annotations.Language;

public final class StringUtil {
private StringUtil() {}

private static final @Language("regexp") String CAMEL_TO_SNAKE_CASE_REGEX = "([a-z])([A-Z]+)";
private static final String CAMEL_TO_SNAKE_CASE_REPLACEMENT = "$1_$2";

public static String camelCaseToSnakeCase(String str) {
return str.replaceAll(CAMEL_TO_SNAKE_CASE_REGEX, CAMEL_TO_SNAKE_CASE_REPLACEMENT).toLowerCase();
}
}
1 change: 1 addition & 0 deletions modules/development/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies {
implementation(project(":modules:item"))
implementation(project(":modules:player"))
implementation(project(":modules:quest"))
implementation(project(":modules:entity"))

implementation("org.mongodb:mongodb-driver-sync:4.7.1")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import net.hollowcube.item.crafting.RecipeList;
import net.hollowcube.item.crafting.ToolCraftingInventory;
import net.hollowcube.player.PlayerImpl;
import net.hollowcube.server.dev.tool.DebugToolManager;
import net.hollowcube.server.instance.TickTrackingInstance;
import net.minestom.server.MinecraftServer;
import net.minestom.server.ServerProcess;
import net.minestom.server.command.builder.Command;
Expand All @@ -15,14 +13,12 @@
import net.minestom.server.event.GlobalEventHandler;
import net.minestom.server.event.player.PlayerLoginEvent;
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.instance.block.BlockHandler;
import net.minestom.server.potion.Potion;
import net.minestom.server.potion.PotionEffect;
import net.minestom.server.world.DimensionType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import net.hollowcube.blocks.BlockInteracter;
Expand All @@ -35,7 +31,6 @@
import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.UUID;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
Expand All @@ -47,18 +42,14 @@ public static void main(String[] args) {

MinecraftServer server = MinecraftServer.init();

MojangAuth.init();
MinecraftServer.getConnectionManager().setPlayerProvider(PlayerImpl::new);

InstanceManager instanceManager = MinecraftServer.getInstanceManager();

Instance instance = new TickTrackingInstance(UUID.randomUUID(), DimensionType.OVERWORLD);
instanceManager.registerInstance(instance);
Instance instance = instanceManager.createInstanceContainer();
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, 42, 0));
});
Expand All @@ -78,6 +69,7 @@ public static void main(String[] args) {

//todo a command for this
player.getInventory().addItemStack(DebugToolManager.createTool("unnamed:hello"));

});

BaseCommandRegister.registerCommands(); //todo this should be in a facet?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private void handAnimation(@NotNull PlayerHandAnimationEvent event) {
if (tool == null || debounce(player)) return;

final Point targetBlock = player.getTargetBlockPosition(3);
//todo ray trace for target entity
//todo ray trace for value entity

final ItemStack newItemStack = tool.leftClicked(player, itemStack, targetBlock, null);
if (itemStack != newItemStack) {
Expand Down
66 changes: 66 additions & 0 deletions modules/entity/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Entities
Module for defining entities as well as their associated behavior.

## Entity Definition
```json5
{
"namespace": "unnamed:test",

// The model to use. For now this must be a vanilla entity type.
"model": "minecraft:pig",
// A reference to a behavior file
"behavior": "unnamed:test_behavior",
// (optional) The navigator to use for this entity. If not specified, the land navigator will be used.
"navigator": "minecraft:land",

// (optional) The loot table to use when the entity dies
"loot_table": "unnamed:test_loot",

// Stats
//todo need to be able to specify things like walk speed, jump height, etc. These are navigator parameters i suppose
}
```

## Behavior Definition
```json5
{
"namespace": "test_behavior",

// Root behavior node
"type": "sequence",
"children": [/* ... */],
// (optional) If true, the task may be interrupted during execution by a parent sequence. Defaults to false.
"canInterrupt": false,
}
```

A behavior node is a JSON object with a type and some set of properties defined on the node itself. The basic primitives
are `sequence`s and `selector`s. They are documented below:

```json5
{
// Sequence is a set of tasks to perform in order. If any task fails, the sequence fails.
"type": "unnamed:sequence",
// Each child is executed in order. If the sequence may be interrupted then any child task may be interrupted.
"children": [/* ... */],
}
```

```json5
{
// Selector is a set of tasks which will be performed based on their order and condition.
"type": "unnamed:selector",
// An array of stimuli definitions which will be active as long as this selector is active. This can be used for
// performance reasons (e.g. do not tick a stimuli source if you do not have to), but should not be used if there
// are two conflicting stimuli sources (e.g. do not have two targeting stimuli nested within each other).
"stimuli": [/* ... */],
// A set of mql expressions and tasks. Each expression is evaluated in order, executing the first task to completion.
// If the selected task may not be interrupted, it is executed to completion. If it may be interrupted, the
// conditions will be continuously evaluated, and the selected task will change if an earlier condition passes.
// An empty mql expression will always evaluate to true.
"children": {
"q.has_target": {/* ... */},
"": {/* ... */},
}
}
```
7 changes: 7 additions & 0 deletions modules/entity/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
`java-library`
}

dependencies {
implementation(project(":modules:common"))
}
27 changes: 27 additions & 0 deletions modules/entity/src/main/java/net/hollowcube/entity/EntityType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.hollowcube.entity;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.hollowcube.dfu.ExtraCodecs;
import net.hollowcube.entity.task.Task;
import net.hollowcube.registry.Registry;
import net.hollowcube.registry.Resource;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.NotNull;

public record EntityType(
@NotNull NamespaceID namespace,
@NotNull NamespaceID model,
@NotNull Task.Spec behavior
) implements Resource {

public static final Codec<EntityType> CODEC = RecordCodecBuilder.create(i -> i.group(
ExtraCodecs.NAMESPACE_ID.fieldOf("namespace").forGetter(EntityType::namespace),
ExtraCodecs.NAMESPACE_ID.fieldOf("model").forGetter(EntityType::model),
ExtraCodecs.NAMESPACE_ID.xmap(ns -> Task.Spec.REGISTRY.required(ns.asString()), Task.Spec::namespace)
.fieldOf("behavior").forGetter(EntityType::behavior)
).apply(i, EntityType::new));

public static final Registry<EntityType> REGISTRY = Registry.codec("entities", CODEC);

}
Loading