Skip to content

Commit

Permalink
add: world module
Browse files Browse the repository at this point in the history
  • Loading branch information
sakurawald committed Jul 8, 2024
1 parent 77efb8b commit c330106
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main/java/io/github/sakurawald/Fuji.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@

// TODO: a light-weight way to implement chat module

// TODO: revert some custom events

// TODO: remove fabric-api dep

// TODO: a program to generate module reference DAG

// TODO: luckperms context calculator

public class Fuji implements ModInitializer {
public static final String MOD_ID = "fuji";
public static final Logger LOGGER = LogUtil.createLogger(StringUtils.capitalize(MOD_ID));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

@Data
Expand Down Expand Up @@ -37,6 +38,11 @@ public static Position of(ServerPlayerEntity player) {
return new Position(player.getWorld().getRegistryKey().getValue().toString(), player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch());
}

public static Position of(ServerPlayerEntity player, ServerWorld world) {
BlockPos spawnPos = world.getSpawnPos();
return new Position(world, spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), player.getYaw(), player.getPitch());
}

public boolean sameLevel(World level) {
return this.level.equals(level.getRegistryKey().getValue().toString());
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/io/github/sakurawald/config/model/ConfigModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -927,19 +927,32 @@ public class CommandRewrite {
}

public Loom loom = new Loom();

@Documentation("This module provides `/loom` command.")
public class Loom {
public boolean enable = false;
}

public Cartography cartography = new Cartography();

@Documentation("This module provides `/cartography` command.")
public class Cartography {
public boolean enable = false;
}

public Smithing smithing = new Smithing();

@Documentation("This module provides `/smithing` command.")
public class Smithing {
public boolean enable = false;
}

public World world = new World();
@Documentation("This module provides `/world` command, which teleport the player to target dimension.")
public class World {
public boolean enable = false;

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher, C
int latency = target.networkHandler.getLatency();
MessageUtil.sendMessage(ctx.getSource(), "ping.player", name, latency);
} catch (Exception e) {
MessageUtil.sendMessage(ctx.getSource(), "ping.target.no_found");
MessageUtil.sendMessage(ctx.getSource(), "entity.no_found");
}

return Command.SINGLE_SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.github.sakurawald.module.initializer.world;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import io.github.sakurawald.common.structure.Position;
import io.github.sakurawald.module.initializer.ModuleInitializer;
import io.github.sakurawald.util.CommandUtil;
import io.github.sakurawald.util.MessageUtil;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.command.argument.DimensionArgumentType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.CraftingScreenHandler;
import net.minecraft.screen.ScreenHandlerContext;
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.stat.Stats;
import net.minecraft.text.Text;

import java.awt.*;

import static net.minecraft.server.command.CommandManager.argument;


public class WorldInitializer extends ModuleInitializer {

@Override
public void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
dispatcher.register(CommandManager.literal("world").then(argument(CommandUtil.ARGUMENT_NAME_DIMENSION, DimensionArgumentType.dimension()).executes(this::$world)));
}

private int $world(CommandContext<ServerCommandSource> ctx) {
return CommandUtil.playerOnlyCommand(ctx, player -> {

try {
ServerWorld serverWorld = DimensionArgumentType.getDimensionArgument(ctx, CommandUtil.ARGUMENT_NAME_DIMENSION);
Position.of(player, serverWorld).teleport(player);
} catch (CommandSyntaxException e) {
MessageUtil.sendMessage(player,"dimension.no_found");
}

return Command.SINGLE_SUCCESS;
});
}
}
3 changes: 3 additions & 0 deletions src/main/java/io/github/sakurawald/util/CommandUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

@UtilityClass
public class CommandUtil {

public static final String ARGUMENT_NAME_DIMENSION = "dimension";

public static RequiredArgumentBuilder<ServerCommandSource, String> offlinePlayerArgument(String argumentName) {
return argument(argumentName, StringArgumentType.string())
.suggests((context, builder) -> {
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/assets/fuji/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"overworld": "overworld",
"the_nether": "the nether",
"the_end": "the end",
"entity.no_found": "<red>Target entity no found.",
"dimension.no_found": "<red>Target dimension no found.",
"command.player_only": "<red>This command can only be executed by a player",
"level.no_exists": "<red>Level %s doesn't exist",
"input.syntax.error": "<red>Input Syntax Error",
Expand Down Expand Up @@ -163,7 +165,6 @@
"home.unset.success": "<gold>Home %s removed.",
"home.no_found": "<red>Home %s not found.",
"ping.player": "<gold>Ping of %s: %d ms",
"ping.target.no_found": "<red>Ping target no found.",
"bed.not_found": "<red>No bed found.",
"bed.success": "<gold>Teleported to bed.",
"chat.format.set": "<gold>Chat format has been modified, current style:</gold><newline>%s<reset><newline><red><click:run_command:/chat format reset> [Reset]</click></red>",
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/assets/fuji/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"overworld": "主世界",
"the_nether": "下界",
"the_end": "末地",
"entity.no_found": "<red>目标实体未找到",
"dimension.no_found": "<red>目标维度未找到",
"command.player_only": "<red>该命名只能由玩家执行",
"level.no_exists": "<red>维度 %s 不存在",
"input.syntax.error": "<red>输入的格式错误",
Expand Down Expand Up @@ -163,7 +165,6 @@
"home.unset.success": "<gold>家 %s 已移除.",
"home.no_found": "<red>家 %s 不存在.",
"ping.player": "<gold>玩家 %s 的延迟: %d ms",
"ping.target.no_found": "<red>目标玩家未找到",
"bed.not_found": "<red>未找到床",
"bed.success": "<gold>已传送到床",
"chat.format.set": "<gold>已修改聊天样式, 当前样式:</gold><newline>%s<reset><newline><red><click:run_command:/chat format reset> [重置]</click></red>",
Expand Down

0 comments on commit c330106

Please sign in to comment.