Compare commits

...

1 commit
main ... sleep

Author SHA1 Message Date
petrak@ 41442c8e85 who needs sleep, well you're never gonna get it 2023-02-26 19:11:57 -06:00
4 changed files with 74 additions and 0 deletions

View file

@ -0,0 +1,35 @@
package at.petrak.hexcasting.common.casting.operators.spells
import at.petrak.hexcasting.api.casting.ParticleSpray
import at.petrak.hexcasting.api.casting.RenderedSpell
import at.petrak.hexcasting.api.casting.castables.SpellAction
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.getEntity
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.server.level.ServerLevel
import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.entity.Mob
object OpSleep : SpellAction {
override val argc = 1
override fun execute(args: List<Iota>, ctx: CastingEnvironment): Triple<RenderedSpell, Int, List<ParticleSpray>>? {
val target = args.getEntity(0, argc)
if (target is Mob) {
val goals = IXplatAbstractions.INSTANCE.getGoalSelector(target)
val targets = IXplatAbstractions.INSTANCE.getTargetSelector(target)
goals.runningGoals.forEach { it.stop() }
targets.runningGoals.forEach { it.stop() }
} else if (target is ServerPlayer) {
}
TODO()
}
@JvmStatic
fun getPostSleepTime(level: ServerLevel): Long {
TODO()
}
}

View file

@ -0,0 +1,32 @@
package at.petrak.hexcasting.common.command;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.phys.Vec3;
public class SleepTestCommand {
public static void add(LiteralArgumentBuilder<CommandSourceStack> cmd) {
cmd.then(Commands.literal("sleep")
.requires(dp -> dp.hasPermission(Commands.LEVEL_ADMINS))
.then(Commands.argument("start", BoolArgumentType.bool()).executes(ctx -> {
var start = BoolArgumentType.getBool(ctx, "start");
var user = ctx.getSource().getPlayerOrException();
if (start) {
user.setPose(Pose.SLEEPING);
user.setSleepingPos(user.getOnPos());
user.setDeltaMovement(Vec3.ZERO);
user.hasImpulse = true;
} else {
Vec3 vec3 = user.position();
user.setPose(Pose.STANDING);
user.setPos(vec3.x, vec3.y, vec3.z);
user.clearSleepingPos();
}
return 0;
})));
}
}

View file

@ -3,6 +3,7 @@ package at.petrak.hexcasting.common.lib;
import at.petrak.hexcasting.common.command.BrainsweepCommand;
import at.petrak.hexcasting.common.command.ListPatternsCommand;
import at.petrak.hexcasting.common.command.RecalcPatternsCommand;
import at.petrak.hexcasting.common.command.SleepTestCommand;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
@ -14,6 +15,7 @@ public class HexCommands {
BrainsweepCommand.add(mainCmd);
ListPatternsCommand.add(mainCmd);
RecalcPatternsCommand.add(mainCmd);
SleepTestCommand.add(mainCmd);
dispatcher.register(mainCmd);
}

View file

@ -25,6 +25,7 @@ import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.goal.GoalSelector;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
@ -169,6 +170,10 @@ public interface IXplatAbstractions {
boolean isPlacingAllowed(Level world, BlockPos pos, ItemStack blockStack, Player player);
GoalSelector getGoalSelector(Mob mob);
GoalSelector getTargetSelector(Mob mob);
// interop
PehkuiInterop.ApiAbstraction getPehkuiApi();