feat: commit broken commands
Some checks failed
build / build (21) (push) Failing after 2s

This commit is contained in:
blryface 2024-07-13 00:23:01 -03:00
parent ec3a633161
commit 03c45caa74
7 changed files with 162 additions and 3 deletions

View file

@ -1,9 +1,8 @@
package cc.crss.mod;
import net.fabricmc.api.DedicatedServerModInitializer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import cc.crss.mod.util.CommandRegister;
public class CRSSMod implements DedicatedServerModInitializer {
@ -12,5 +11,6 @@ public class CRSSMod implements DedicatedServerModInitializer {
public void onInitializeServer() {
LOGGER.info("Hello World!");
CommandRegister.registerCommands();
}
}

View file

@ -0,0 +1,41 @@
package cc.crss.mod.command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.LiteralText;
import net.minecraft.world.dimension.DimensionType;
public class SkipNightCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, boolean dedicated) {
dispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder) CommandManager.literal("sleep"))
.executes(SkipNightCommand::run));
}
public static int run(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
if (context.getSource().getPlayer().dimension == DimensionType.OVERWORLD) {
for(ServerWorld world : context.getSource().getMinecraftServer().getWorlds()) {
long rTime = 24000 - world.getTime();
world.setTimeOfDay(world.getTime() + rTime);
if (world.isThundering()) {
world.setThunderGradient(0);
}
}
context.getSource().sendFeedback(new LiteralText("[CRSS] " + "The night has been passed."), false);
}
return 1;
}
}

View file

@ -0,0 +1,56 @@
package cc.crss.mod.command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.command.arguments.MessageArgumentType;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.LiteralText;
import java.util.Random;
public class WhenCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, boolean dedicated) {
dispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder)CommandManager.literal("when"))
.then(CommandManager.argument("query", MessageArgumentType.message()).executes(WhenCommand::run)));
}
public static int run(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
Random rand = new Random();
String weekSuffix;
String daysSuffix;
String monthsSuffix;
String yearsSuffix;
int weeks = rand.nextInt(4) + 1;
int days = rand.nextInt(7) + 1;
int months = rand.nextInt(12) + 1;
int years = rand.nextInt(5) + 1;
if (weeks > 1) weekSuffix = "weeks"; else weekSuffix = "week";
if (days > 1) daysSuffix = "days"; else daysSuffix = "day";
if (months > 1) monthsSuffix = "months"; else monthsSuffix = "month";
if (years > 1) yearsSuffix = "years"; else yearsSuffix = "year";
String[] dateStrings = {
"now", "later", "never", "tomorrow", "yesterday", "Releasing 2025:tm:",
"When Alto releases", "Soon:tm:" };
String randomDateString = dateStrings[rand.nextInt(dateStrings.length)];
String[] datesSelection = {
days + " " + daysSuffix, weeks + " " + weekSuffix,
months + " " + monthsSuffix, years + " " + yearsSuffix,
randomDateString };
String randomDate = datesSelection[rand.nextInt(datesSelection.length)];
context.getSource().sendFeedback(new LiteralText("[CRSS] " + randomDate), false);
return 1;
}
}

View file

@ -0,0 +1,16 @@
package cc.crss.mod.mixin;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import cc.crss.mod.CRSSMod;
@Mixin(PlayerEntity.class)
public class PlayerEntityMixin {
@Redirect(method = "trySleep", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;sleep(Lnet/minecraft/util/math/BlockPos;)V"))
private void trySleep(PlayerEntity instance, BlockPos pos) {
CRSSMod.LOGGER.info("IT WORKIES");
}
}

View file

@ -0,0 +1,12 @@
package cc.crss.mod.util;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import cc.crss.mod.command.SkipNightCommand;
import cc.crss.mod.command.WhenCommand;
public class CommandRegister {
public static void registerCommands() {
CommandRegistrationCallback.EVENT.register(WhenCommand::register);
CommandRegistrationCallback.EVENT.register(SkipNightCommand::register);
}
}

View file

@ -0,0 +1,33 @@
package cc.crss.mod.util;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.world.ServerWorld;
public class SleepHandler {
public void handleSleepCommand(CommandContext<ServerCommandSource> context) {
for(ServerWorld world : context.getSource().getMinecraftServer().getWorlds()) {
handleSleep(world);
}
}
public void handleSleepBed() {
}
private void handleSleep(ServerWorld world) {
long rTime = 24000 - world.getTime();
world.setTimeOfDay(world.getTime() + rTime);
if (world.isThundering()) {
world.setThunderGradient(0);
}
}
}

View file

@ -3,7 +3,8 @@
"package": "cc.crss.mod.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"CRSSMixin"
"CRSSMixin",
"PlayerEntityMixin"
],
"injectors": {
"defaultRequire": 1