Skip to content

Commit 24530a4

Browse files
committed
Fix for room arg serializing; fix giveMachine "dim not found", lang
1 parent 5caed9f commit 24530a4

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

src/datagen/java/dev/compactmods/machines/datagen/lang/EnglishLangGenerator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ protected void addTranslations() {
7676
addCommand(CMCommands.CANNOT_GIVE_MACHINE, "Failed to give a new machine to player.");
7777
addCommand(CMCommands.MACHINE_GIVEN, "Created a new machine item and gave it to %s.");
7878

79+
addMessage(Messages.UNKNOWN_ROOM_CHUNK, "Unknown room at %s; please verify it exists.");
80+
7981
add("itemGroup." + CompactMachines.MOD_ID, "Compact Machines");
8082

8183
add("biome." + CompactMachines.MOD_ID + ".machine", "Compact Machine");

src/main/java/dev/compactmods/machines/command/CMCommandRoot.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33
import com.mojang.brigadier.CommandDispatcher;
44
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
55
import dev.compactmods.machines.CompactMachines;
6+
import dev.compactmods.machines.command.argument.RoomPositionArgument;
67
import dev.compactmods.machines.command.data.CMDataSubcommand;
78
import dev.compactmods.machines.command.subcommand.*;
89
import net.minecraft.commands.CommandSourceStack;
10+
import net.minecraft.commands.synchronization.ArgumentTypes;
11+
import net.minecraft.commands.synchronization.EmptyArgumentSerializer;
912

1013
public class CMCommandRoot {
1114

1215
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
16+
ArgumentTypes.register("room_pos", RoomPositionArgument.class, new EmptyArgumentSerializer<>(RoomPositionArgument::room));
17+
1318
final LiteralArgumentBuilder<CommandSourceStack> root = LiteralArgumentBuilder.literal(CompactMachines.MOD_ID);
1419
root.then(CMEjectSubcommand.make());
1520
root.then(CMSummarySubcommand.make());

src/main/java/dev/compactmods/machines/command/argument/RoomPositionArgument.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@
88
import com.mojang.brigadier.suggestion.Suggestions;
99
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
1010
import net.minecraft.commands.CommandSourceStack;
11-
import net.minecraft.commands.arguments.coordinates.*;
12-
import net.minecraft.core.BlockPos;
11+
import net.minecraft.commands.arguments.coordinates.WorldCoordinate;
1312
import net.minecraft.network.chat.TranslatableComponent;
14-
import net.minecraft.server.level.ColumnPos;
1513
import net.minecraft.world.level.ChunkPos;
1614

1715
import java.util.concurrent.CompletableFuture;
1816

19-
import static net.minecraft.commands.arguments.coordinates.WorldCoordinate.ERROR_EXPECTED_INT;
20-
2117
public class RoomPositionArgument implements ArgumentType<RoomCoordinates> {
2218
public static final SimpleCommandExceptionType ERROR_NOT_COMPLETE = new SimpleCommandExceptionType(new TranslatableComponent("argument.pos2d.incomplete"));
2319

src/main/java/dev/compactmods/machines/command/subcommand/CMGiveMachineSubcommand.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.mojang.brigadier.exceptions.CommandSyntaxException;
66
import dev.compactmods.machines.CompactMachines;
77
import dev.compactmods.machines.api.core.CMCommands;
8+
import dev.compactmods.machines.api.core.Messages;
89
import dev.compactmods.machines.command.argument.RoomPositionArgument;
910
import dev.compactmods.machines.config.ServerConfig;
1011
import dev.compactmods.machines.core.MissingDimensionException;
@@ -40,8 +41,9 @@ private static int giveMachine(CommandContext<CommandSourceStack> ctx) throws Co
4041
final var roomPos = RoomPositionArgument.get(ctx, "room");
4142

4243
if(!Rooms.exists(server, roomPos)) {
43-
CompactMachines.LOGGER.error("Error giving player a new machine block: compact dimension not found.");
44-
throw new CommandRuntimeException(TranslationUtil.command(CMCommands.LEVEL_NOT_FOUND));
44+
CompactMachines.LOGGER.error("Error giving player a new machine block: room not found.");
45+
src.sendFailure(TranslationUtil.message(Messages.UNKNOWN_ROOM_CHUNK, "%s, %s".formatted(roomPos.x, roomPos.z)));
46+
return -1;
4547
}
4648

4749
try {

src/main/java/dev/compactmods/machines/command/subcommand/CMRoomsSubcommand.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import dev.compactmods.machines.room.Rooms;
1616
import dev.compactmods.machines.room.data.CompactRoomData;
1717
import dev.compactmods.machines.room.exceptions.NonexistentRoomException;
18+
import net.minecraft.ChatFormatting;
1819
import net.minecraft.commands.CommandRuntimeException;
1920
import net.minecraft.commands.CommandSourceStack;
2021
import net.minecraft.commands.Commands;
@@ -80,7 +81,10 @@ private static int findByContainingPlayer(CommandContext<CommandSourceStack> ctx
8081
ctx.getSource().sendSuccess(m, false);
8182
} catch (NonexistentRoomException e) {
8283
CompactMachines.LOGGER.error("Player is inside an unregistered chunk ({}) in the compact world.", playerChunk, e);
83-
throw new CommandRuntimeException(TranslationUtil.message(Messages.UNKNOWN_ROOM_CHUNK));
84+
final var tc = new TextComponent("%s, %s".formatted(playerChunk.x, playerChunk.z))
85+
.withStyle(ChatFormatting.RED);
86+
87+
throw new CommandRuntimeException(TranslationUtil.message(Messages.UNKNOWN_ROOM_CHUNK, tc));
8488
}
8589

8690
return 0;

0 commit comments

Comments
 (0)