Skip to content

Commit 1b375fc

Browse files
committed
Return success values from various commands
1 parent 4d5cb95 commit 1b375fc

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

src/main/java/mekanism/common/command/CommandMek.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mekanism.common.command;
22

33

4+
import com.mojang.brigadier.Command;
45
import com.mojang.brigadier.builder.ArgumentBuilder;
56
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
67
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
@@ -55,7 +56,7 @@ private static class DebugCommand {
5556
.executes(ctx -> {
5657
MekanismAPI.debug = !MekanismAPI.debug;
5758
ctx.getSource().sendSuccess(() -> MekanismLang.COMMAND_DEBUG.translateColored(EnumColor.GRAY, OnOff.of(MekanismAPI.debug, true)), true);
58-
return 0;
59+
return Command.SINGLE_SUCCESS;
5960
});
6061
}
6162
}
@@ -78,7 +79,7 @@ private static class TestRulesCommand {
7879
//Act as if /weather clear was ran
7980
source.getLevel().setWeatherParameters(ServerLevel.RAIN_DELAY.sample(server.overworld().getRandom()), 0, false, false);
8081
source.sendSuccess(() -> MekanismLang.COMMAND_TEST_RULES.translateColored(EnumColor.GRAY), true);
81-
return 0;
82+
return Command.SINGLE_SUCCESS;
8283
});
8384
}
8485
}
@@ -102,7 +103,7 @@ private static class TpCommand {
102103
// Teleport user to new location
103104
player.connection.teleport(position.x(), position.y(), position.z(), player.getYRot(), player.getXRot());
104105
source.sendSuccess(() -> MekanismLang.COMMAND_TP.translateColored(EnumColor.GRAY, EnumColor.INDIGO, getPosition(position)), true);
105-
return 0;
106+
return Command.SINGLE_SUCCESS;
106107
})
107108
);
108109
}
@@ -133,7 +134,7 @@ private static class TppopCommand {
133134
BlockPos lastPos = playerLocations.pop();
134135
player.connection.teleport(lastPos.getX(), lastPos.getY(), lastPos.getZ(), player.getYRot(), player.getXRot());
135136
source.sendSuccess(() -> MekanismLang.COMMAND_TPOP.translateColored(EnumColor.GRAY, EnumColor.INDIGO, getPosition(lastPos), EnumColor.INDIGO, playerLocations.size()), true);
136-
return 0;
137+
return Command.SINGLE_SUCCESS;
137138
});
138139
}
139140

src/main/java/mekanism/common/command/ForceRetrogenCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,21 @@ private static int addChunksToRegen(CommandSourceStack source, ColumnPos start,
5959
int chunkZEnd = SectionPos.blockToSectionCoord(zEnd);
6060
ServerLevel world = source.getLevel();
6161
ResourceKey<Level> registryKey = world.dimension();
62-
boolean hasChunks = false;
62+
int chunks = 0;
6363
for (int chunkX = chunkXStart; chunkX <= chunkXEnd; chunkX++) {
6464
for (int chunkZ = chunkZStart; chunkZ <= chunkZEnd; chunkZ++) {
6565
if (world.hasChunk(chunkX, chunkZ)) {
6666
Mekanism.worldTickHandler.addRegenChunk(registryKey, new ChunkPos(chunkX, chunkZ));
6767
int finalChunkX = chunkX, finalChunkZ = chunkZ;
6868
source.sendSuccess(() -> MekanismLang.COMMAND_RETROGEN_CHUNK_QUEUED.translateColored(EnumColor.GRAY, EnumColor.INDIGO,
6969
MekanismLang.GENERIC_WITH_COMMA.translate(finalChunkX, finalChunkZ), EnumColor.INDIGO, world), true);
70-
hasChunks = true;
70+
chunks++;
7171
}
7272
}
7373
}
74-
if (!hasChunks) {
74+
if (chunks == 0) {
7575
throw NO_CHUNKS_QUEUED.create();
7676
}
77-
return 0;
77+
return chunks;
7878
}
7979
}

src/main/java/mekanism/common/command/RadiationCommand.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package mekanism.common.command;
22

3+
import com.mojang.brigadier.Command;
34
import com.mojang.brigadier.arguments.DoubleArgumentType;
45
import com.mojang.brigadier.builder.ArgumentBuilder;
6+
import mekanism.api.math.MathUtils;
57
import mekanism.api.radiation.IRadiationManager;
68
import mekanism.api.radiation.capability.IRadiationEntity;
79
import mekanism.api.text.EnumColor;
@@ -41,7 +43,7 @@ public class RadiationCommand {
4143
.executes(ctx -> {
4244
RadiationManager.get().clearSources();
4345
ctx.getSource().sendSuccess(() -> MekanismLang.COMMAND_RADIATION_REMOVE_ALL.translateColored(EnumColor.GRAY), true);
44-
return 0;
46+
return Command.SINGLE_SUCCESS;
4547
})
4648
);
4749
}
@@ -84,6 +86,7 @@ public class RadiationCommand {
8486
cap.radiate(magnitude);
8587
source.sendSuccess(() -> MekanismLang.COMMAND_RADIATION_ADD_ENTITY.translateColored(EnumColor.GRAY, RadiationScale.getSeverityColor(magnitude),
8688
UnitDisplayUtils.getDisplayShort(magnitude, RadiationUnit.SVH, 3)), true);
89+
return getReturnLevelFromRadiation(magnitude);
8790
}
8891
return 0;
8992
})
@@ -144,7 +147,7 @@ public class RadiationCommand {
144147
cap.set(RadiationManager.BASELINE);
145148
source.sendSuccess(() -> MekanismLang.COMMAND_RADIATION_CLEAR.translateColored(EnumColor.GRAY), true);
146149
}
147-
return 0;
150+
return Command.SINGLE_SUCCESS;
148151
}).then(Commands.argument("targets", EntityArgument.entities())
149152
.requires(MekanismPermissions.COMMAND_RADIATION_HEAL_OTHERS)
150153
.executes(ctx -> {
@@ -181,6 +184,7 @@ public class RadiationCommand {
181184
cap.set(newValue);
182185
source.sendSuccess(() -> MekanismLang.COMMAND_RADIATION_REDUCE.translateColored(EnumColor.GRAY, RadiationScale.getSeverityColor(reduced),
183186
UnitDisplayUtils.getDisplayShort(reduced, RadiationUnit.SVH, 3)), true);
187+
return getReturnLevelFromRadiation(reduced);
184188
}
185189
return 0;
186190
})
@@ -221,7 +225,7 @@ private static int addRadiation(CommandSourceStack source, Vec3 pos, Level world
221225
IRadiationManager.INSTANCE.radiate(location, magnitude);
222226
source.sendSuccess(() -> MekanismLang.COMMAND_RADIATION_ADD.translateColored(EnumColor.GRAY, RadiationScale.getSeverityColor(magnitude),
223227
UnitDisplayUtils.getDisplayShort(magnitude, RadiationUnit.SVH, 3), EnumColor.INDIGO, getPosition(location.pos()), EnumColor.INDIGO, world), true);
224-
return 0;
228+
return getReturnLevelFromRadiation(magnitude);
225229
}
226230

227231
private static int getRadiationLevel(CommandSourceStack source, Coordinates location, Level world) {
@@ -234,10 +238,18 @@ private static int getRadiationLevel(CommandSourceStack source, Vec3 pos, Level
234238
source.sendSuccess(() -> MekanismLang.COMMAND_RADIATION_GET.translateColored(EnumColor.GRAY, EnumColor.INDIGO, getPosition(location.pos()), EnumColor.INDIGO,
235239
world, RadiationScale.getSeverityColor(magnitude), UnitDisplayUtils.getDisplayShort(magnitude, RadiationUnit.SVH, 3)),
236240
true);
237-
return 0;
241+
return getReturnLevelFromRadiation(magnitude);
238242
}
239243

240244
private static Component getPosition(BlockPos pos) {
241245
return MekanismLang.GENERIC_BLOCK_POS.translate(pos.getX(), pos.getY(), pos.getZ());
242246
}
247+
248+
private static int getReturnLevelFromRadiation(double magnitude) {
249+
if (magnitude < RadiationManager.MIN_MAGNITUDE) {
250+
return 0;
251+
}
252+
//Multiply to make it so that we can differentiate various levels based on what the micro sievert rate would be
253+
return MathUtils.clampToInt(magnitude * 1_000_000);
254+
}
243255
}

src/main/java/mekanism/common/command/builders/BuildCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package mekanism.common.command.builders;
22

3+
import com.mojang.brigadier.Command;
34
import com.mojang.brigadier.builder.ArgumentBuilder;
45
import com.mojang.brigadier.context.CommandContext;
56
import com.mojang.brigadier.exceptions.CommandSyntaxException;
@@ -52,7 +53,7 @@ private BuildCommand() {
5253
CommandSourceStack source = ctx.getSource();
5354
destroy(source.getLevel(), rayTracePos(source));
5455
source.sendSuccess(() -> MekanismLang.COMMAND_BUILD_REMOVED.translateColored(EnumColor.GRAY), true);
55-
return 0;
56+
return Command.SINGLE_SUCCESS;
5657
}));
5758

5859
public static void register(String name, ILangEntry localizedName, StructureBuilder builder) {
@@ -89,7 +90,7 @@ private static int build(CommandContext<CommandSourceStack> ctx, ILangEntry loca
8990
ILangEntry builtEntry = empty ? MekanismLang.COMMAND_BUILD_BUILT_EMPTY : MekanismLang.COMMAND_BUILD_BUILT;
9091
return builtEntry.translateColored(EnumColor.GRAY, EnumColor.INDIGO, localizedName);
9192
}, true);
92-
return 0;
93+
return Command.SINGLE_SUCCESS;
9394
}
9495

9596
private static void destroy(Level world, BlockPos pos) throws CommandSyntaxException {

0 commit comments

Comments
 (0)