Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
run
.idea
.vscode
.idx
.gradle
build
bin
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand All @@ -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())
)
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Void> signal;
private final Output<PlayerValue> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<PlayerValue> player = new Input<>("player", "Player", PlayerType.INSTANCE);
Output<Vec3d> 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();
}
}
Original file line number Diff line number Diff line change
@@ -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<Void> signal = new Input<>("signal", "Signal", SignalType.INSTANCE);
Input<PlayerValue> player = new Input<>("player", "Player", PlayerType.INSTANCE);
Input<Boolean> allow = new Input<>("allow", "Allow", ConditionType.INSTANCE);
Output<Void> 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();
}
}
Original file line number Diff line number Diff line change
@@ -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<String> inputString = new Input<>("inputString", "Input String", StringType.INSTANCE);
Input<String> exprString = new Input<>("exprString", "Expression", StringType.INSTANCE);
Output<ListValue<String>> 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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,4 +26,9 @@ private void dontLoad(ServerPlayerEntity player, CallbackInfoReturnable<Optional
cir.setReturnValue(Optional.empty());
}

@Inject(method = "respawnPlayer", at = @At("HEAD"))
private void onRespawn(ServerPlayerEntity player, boolean alive, RemovalReason reason, CallbackInfoReturnable<ServerPlayerEntity> cir) {
if (player.getWorld() instanceof PlayWorld playWorld) playWorld.space.evaluator.onRespawn(player);
}

}