diff --git a/.gitignore b/.gitignore index f4c0745..3e17adc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ run .idea +.vscode +.idx .gradle build bin \ No newline at end of file diff --git a/src/main/java/de/blazemcworld/fireflow/code/CodeEvaluator.java b/src/main/java/de/blazemcworld/fireflow/code/CodeEvaluator.java index 530e441..651e9e8 100644 --- a/src/main/java/de/blazemcworld/fireflow/code/CodeEvaluator.java +++ b/src/main/java/de/blazemcworld/fireflow/code/CodeEvaluator.java @@ -290,6 +290,14 @@ public boolean allowDeath(LivingEntity target, DamageSource source, float damage return !cancel; } + public void onRespawn(ServerPlayerEntity player) { + for (Node node : nodes) { + if (node instanceof OnPlayerRespawnNode n) { + n.onRespawn(this, player); + } + } + } + public void nextTick(Runnable r) { synchronized (tickTasks) { tickTasks.add(r); diff --git a/src/main/java/de/blazemcworld/fireflow/code/node/NodeList.java b/src/main/java/de/blazemcworld/fireflow/code/node/NodeList.java index 22e648d..e979489 100644 --- a/src/main/java/de/blazemcworld/fireflow/code/node/NodeList.java +++ b/src/main/java/de/blazemcworld/fireflow/code/node/NodeList.java @@ -120,6 +120,7 @@ public static void init() { .add(new OnPlayerDropItemNode()) .add(new OnPlayerInteractBlockNode()) .add(new OnPlayerPlaceBlockNode()) + .add(new OnPlayerRespawnNode()) ) .add(new OnPlayerLoseFoodNode()) .add(new OnPlayerLoseSaturationNode()) @@ -230,6 +231,7 @@ public static void init() { .add(new PlayerListNode()) ) .add(new Category("Movement", Items.FEATHER) + .add(new GetPlayerVelocityNode()) .add(new IsPlayerSneakingNode()) .add(new IsPlayerSprintingNode()) .add(new PlayerCanFlyNode()) @@ -239,6 +241,7 @@ public static void init() { .add(new PlayerStandingBlockNode()) .add(new SetAllowFlyingNode()) .add(new SetPlayerFlyingNode()) + .add(new SetPlayerGlidingNode()) .add(new SetPlayerVelocityNode()) .add(new TeleportPlayerNode()) ) @@ -273,6 +276,7 @@ public static void init() { .add(new CharacterAtNode()) .add(new CombineStringsNode()) .add(new LowercaseNode()) + .add(new MatchRegExpNode()) .add(new ReplaceStringNode()) .add(new SplitStringNode()) .add(new StringContainsNode()) diff --git a/src/main/java/de/blazemcworld/fireflow/code/node/impl/event/world/OnPlayerRespawnNode.java b/src/main/java/de/blazemcworld/fireflow/code/node/impl/event/world/OnPlayerRespawnNode.java new file mode 100644 index 0000000..615d472 --- /dev/null +++ b/src/main/java/de/blazemcworld/fireflow/code/node/impl/event/world/OnPlayerRespawnNode.java @@ -0,0 +1,35 @@ +package de.blazemcworld.fireflow.code.node.impl.event.world; + +import de.blazemcworld.fireflow.code.CodeEvaluator; +import de.blazemcworld.fireflow.code.CodeThread; +import de.blazemcworld.fireflow.code.node.Node; +import de.blazemcworld.fireflow.code.type.PlayerType; +import de.blazemcworld.fireflow.code.type.SignalType; +import de.blazemcworld.fireflow.code.value.PlayerValue; +import net.minecraft.item.Items; +import net.minecraft.server.network.ServerPlayerEntity; + +public class OnPlayerRespawnNode extends Node { + private final Output signal; + private final Output player; + + public OnPlayerRespawnNode() { + super("on_player_respawn", "On Player Respawn", "Emits a signal when a player respawns.", Items.OAK_SAPLING); + + signal = new Output<>("signal", "Signal", SignalType.INSTANCE); + player = new Output<>("player", "Player", PlayerType.INSTANCE); + player.valueFromScope(); + } + + @Override + public Node copy() { + return new OnPlayerRespawnNode(); + } + + public void onRespawn(CodeEvaluator evaluator, ServerPlayerEntity p) { + CodeThread thread = evaluator.newCodeThread(); + thread.setScopeValue(player, new PlayerValue(p)); + thread.sendSignal(signal); + thread.clearQueue(); + } +} diff --git a/src/main/java/de/blazemcworld/fireflow/code/node/impl/player/gameplay/SetGamemodeNode.java b/src/main/java/de/blazemcworld/fireflow/code/node/impl/player/gameplay/SetGamemodeNode.java index beb9b8c..0e9797a 100644 --- a/src/main/java/de/blazemcworld/fireflow/code/node/impl/player/gameplay/SetGamemodeNode.java +++ b/src/main/java/de/blazemcworld/fireflow/code/node/impl/player/gameplay/SetGamemodeNode.java @@ -20,11 +20,11 @@ public SetGamemodeNode() { signal.onSignal((ctx) -> { player.getValue(ctx).tryUse(ctx, p -> { - GameMode mode = switch (gamemode.getValue(ctx)) { - case "Creative" -> GameMode.CREATIVE; - case "Survival" -> GameMode.SURVIVAL; - case "Adventure" -> GameMode.ADVENTURE; - case "Spectator" -> GameMode.SPECTATOR; + GameMode mode = switch (gamemode.getValue(ctx).toLowerCase()) { + case "creative" -> GameMode.CREATIVE; + case "survival" -> GameMode.SURVIVAL; + case "adventure" -> GameMode.ADVENTURE; + case "spectator" -> GameMode.SPECTATOR; default -> null; }; if (mode != null) p.changeGameMode(mode); diff --git a/src/main/java/de/blazemcworld/fireflow/code/node/impl/player/movement/GetPlayerVelocityNode.java b/src/main/java/de/blazemcworld/fireflow/code/node/impl/player/movement/GetPlayerVelocityNode.java new file mode 100644 index 0000000..b68534b --- /dev/null +++ b/src/main/java/de/blazemcworld/fireflow/code/node/impl/player/movement/GetPlayerVelocityNode.java @@ -0,0 +1,23 @@ +package de.blazemcworld.fireflow.code.node.impl.player.movement; + +import de.blazemcworld.fireflow.code.node.Node; +import de.blazemcworld.fireflow.code.type.PlayerType; +import de.blazemcworld.fireflow.code.type.VectorType; +import de.blazemcworld.fireflow.code.value.PlayerValue; +import net.minecraft.item.Items; +import net.minecraft.util.math.Vec3d; + +public class GetPlayerVelocityNode extends Node { + public GetPlayerVelocityNode() { + super("get_player_velocity", "Get Player Velocity", "Gets the player's velocity", Items.ARROW); + Input player = new Input<>("player", "Player", PlayerType.INSTANCE); + Output velocity = new Output<>("velocity", "Velocity", VectorType.INSTANCE); + + velocity.valueFrom(ctx -> player.getValue(ctx).tryGet(ctx, p -> p.getVelocity(), null)); + } + + @Override + public Node copy() { + return new GetPlayerVelocityNode(); + } +} diff --git a/src/main/java/de/blazemcworld/fireflow/code/node/impl/player/movement/SetPlayerGlidingNode.java b/src/main/java/de/blazemcworld/fireflow/code/node/impl/player/movement/SetPlayerGlidingNode.java new file mode 100644 index 0000000..b360f0a --- /dev/null +++ b/src/main/java/de/blazemcworld/fireflow/code/node/impl/player/movement/SetPlayerGlidingNode.java @@ -0,0 +1,30 @@ +package de.blazemcworld.fireflow.code.node.impl.player.movement; + +import de.blazemcworld.fireflow.code.node.Node; +import de.blazemcworld.fireflow.code.type.ConditionType; +import de.blazemcworld.fireflow.code.type.PlayerType; +import de.blazemcworld.fireflow.code.type.SignalType; +import de.blazemcworld.fireflow.code.value.PlayerValue; +import net.minecraft.item.Items; + +public class SetPlayerGlidingNode extends Node { + public SetPlayerGlidingNode() { + super("set_player_gliding", "Set Player Gliding", "Sets the gliding state of the player", Items.ELYTRA); + Input signal = new Input<>("signal", "Signal", SignalType.INSTANCE); + Input player = new Input<>("player", "Player", PlayerType.INSTANCE); + Input allow = new Input<>("allow", "Allow", ConditionType.INSTANCE); + Output next = new Output<>("next", "Next", SignalType.INSTANCE); + signal.onSignal((ctx) -> { + player.getValue(ctx).tryUse(ctx, p -> { + if (allow.getValue(ctx)) p.startGliding(); + else p.stopGliding(); + }); + ctx.sendSignal(next); + }); + } + + @Override + public Node copy() { + return new SetPlayerGlidingNode(); + } +} diff --git a/src/main/java/de/blazemcworld/fireflow/code/node/impl/string/MatchRegExpNode.java b/src/main/java/de/blazemcworld/fireflow/code/node/impl/string/MatchRegExpNode.java new file mode 100644 index 0000000..62c10ea --- /dev/null +++ b/src/main/java/de/blazemcworld/fireflow/code/node/impl/string/MatchRegExpNode.java @@ -0,0 +1,30 @@ +package de.blazemcworld.fireflow.code.node.impl.string; + +import java.util.regex.MatchResult; +import java.util.regex.Pattern; + +import de.blazemcworld.fireflow.code.node.Node; +import de.blazemcworld.fireflow.code.type.ListType; +import de.blazemcworld.fireflow.code.type.StringType; +import de.blazemcworld.fireflow.code.value.ListValue; +import net.minecraft.item.Items; + +public class MatchRegExpNode extends Node { + public MatchRegExpNode() { + super("match_regexp", "Match RegExp", "Match a regular expression against a string.", Items.TRIPWIRE_HOOK); + + Input inputString = new Input<>("inputString", "Input String", StringType.INSTANCE); + Input exprString = new Input<>("exprString", "Expression", StringType.INSTANCE); + Output> result = new Output<>("result", "Result", ListType.of(StringType.INSTANCE)); + + result.valueFrom(ctx -> new ListValue<>(StringType.INSTANCE, Pattern.compile(exprString.getValue(ctx)) + .matcher(inputString.getValue(ctx)) + .results().map(MatchResult::group) + .toList())); + } + + @Override + public Node copy() { + return new MatchRegExpNode(); + } +} diff --git a/src/main/java/de/blazemcworld/fireflow/mixin/PlayerManagerMixin.java b/src/main/java/de/blazemcworld/fireflow/mixin/PlayerManagerMixin.java index 24418b8..0527b2c 100644 --- a/src/main/java/de/blazemcworld/fireflow/mixin/PlayerManagerMixin.java +++ b/src/main/java/de/blazemcworld/fireflow/mixin/PlayerManagerMixin.java @@ -1,5 +1,7 @@ package de.blazemcworld.fireflow.mixin; +import de.blazemcworld.fireflow.space.PlayWorld; +import net.minecraft.entity.Entity.RemovalReason; import net.minecraft.nbt.NbtCompound; import net.minecraft.server.PlayerManager; import net.minecraft.server.network.ServerPlayerEntity; @@ -24,4 +26,9 @@ private void dontLoad(ServerPlayerEntity player, CallbackInfoReturnable cir) { + if (player.getWorld() instanceof PlayWorld playWorld) playWorld.space.evaluator.onRespawn(player); + } + }