Skip to content

Commit 04f8df1

Browse files
committed
-Removed LoopTypes enum (to prevent issues on fabric clients without the mod)
-LoopType is now a string -Changed ver from 1.7.2 to 1.7.3 -removed unnecessary imports
1 parent 00b6603 commit 04f8df1

7 files changed

Lines changed: 50 additions & 94 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ yarn_mappings=1.21.1+build.3
99
loader_version=0.16.10
1010

1111
# Mod Properties
12-
mod_version=1.7.2
12+
mod_version=1.7.3
1313
maven_group=com.vltno.timeloop
1414
archives_base_name=time-loop
1515

src/main/java/com/vltno/timeloop/Commands.java

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.mojang.brigadier.arguments.BoolArgumentType;
55
import com.mojang.brigadier.arguments.IntegerArgumentType;
66
import com.mojang.brigadier.arguments.StringArgumentType;
7-
import net.minecraft.command.CommandRegistryAccess;
7+
import net.minecraft.command.CommandSource;
88
import net.minecraft.server.command.CommandManager;
99
import net.minecraft.server.command.ServerCommandSource;
1010
import net.minecraft.text.Text;
@@ -19,7 +19,7 @@ public Commands(TimeLoop mod) {
1919
this.mod = mod;
2020
}
2121

22-
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
22+
public void register(CommandDispatcher<ServerCommandSource> dispatcher) {
2323
dispatcher.register(CommandManager.literal("loop")
2424
.then(CommandManager.literal("start")
2525
.requires(source -> source.hasPermissionLevel(2))
@@ -53,7 +53,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
5353

5454
.then(CommandManager.literal("status")
5555
.executes(context -> {
56-
String extras = " Looping on " + mod.loopType.asString() + "." + (mod.isLooping && mod.loopType == LoopTypes.TICKS ? " Ticks Left: " + mod.ticksLeft : "") + (mod.trackItems ? " Tracking items." : "");
56+
String extras = " Looping on " + mod.loopType + "." + (mod.isLooping && mod.loopType == "TICKS" ? " Ticks Left: " + mod.ticksLeft : "") + (mod.trackItems ? " Tracking items." : "");
5757
String status = mod.isLooping ?
5858
"Loop is active. Current iteration: " + mod.loopIteration + extras:
5959
"Loop is inactive. Last iteration: " + mod.loopIteration + extras;
@@ -68,21 +68,35 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
6868
.then(CommandManager.literal("setLoopType")
6969
.requires(source -> source.hasPermissionLevel(2))
7070
.executes(context -> {
71-
context.getSource().sendMessage(Text.literal("Loop type is set to: " + mod.loopType.asString()));
71+
context.getSource().sendMessage(Text.literal("Loop type is set to: " + mod.loopType));
7272
return 1;
7373
})
74-
.then(CommandManager.argument("loopType", new LoopTypesArgumentType())
74+
.then(CommandManager.argument("loopType", StringArgumentType.word())
75+
.suggests((context, builder) ->
76+
CommandSource.suggestMatching(new String[]{"TICKS", "TIME_OF_DAY", "SLEEP", "DEATH"}, builder)
77+
)
7578
.executes(context -> {
76-
LoopTypes newLoopType = LoopTypesArgumentType.getLoopType(context, "loopType");
79+
String newLoopType = StringArgumentType.getString(context, "loopType").toUpperCase();
80+
if (!newLoopType.equals("TICKS") && !newLoopType.equals("TIME_OF_DAY") &&
81+
!newLoopType.equals("SLEEP") && !newLoopType.equals("DEATH")) {
82+
context.getSource().sendMessage(Text.literal("Invalid loop type. Allowed types: TICKS, TIME_OF_DAY, SLEEP, DEATH."));
83+
return 0;
84+
}
7785
mod.loopType = newLoopType;
7886
mod.config.loopType = newLoopType;
7987
mod.config.save();
8088

81-
context.getSource().sendMessage(Text.literal("Looping type is set to: " + newLoopType.asString()));
82-
LOGGER.info("Loop type set to {}", newLoopType.asString());
89+
//Hide BossBar when loopType is not Ticks or TimeOfDay
90+
if (mod.showLoopInfo) {
91+
mod.loopBossBar.visible(newLoopType.equals("TICKS") || newLoopType.equals("TIME_OF_DAY"));
92+
}
93+
94+
context.getSource().sendMessage(Text.literal("Looping type is set to: " + newLoopType));
95+
LOGGER.info("Loop type set to {}", newLoopType);
8396
return 1;
8497
})))
8598

99+
86100
.then(CommandManager.literal("setLength")
87101
.requires(source -> source.hasPermissionLevel(2))
88102
.executes(context -> {
@@ -224,7 +238,9 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
224238
mod.config.showLoopInfo = newShowLoopInfo;
225239
mod.config.save();
226240

227-
mod.loopBossBar.visible(newShowLoopInfo);
241+
if (newShowLoopInfo) {
242+
mod.loopBossBar.visible(mod.loopType.equals("TICKS") || mod.loopType.equals("TIME_OF_DAY"));
243+
}
228244

229245
context.getSource().sendMessage(Text.literal("Showing loop info is set to: " + newShowLoopInfo));
230246
LOGGER.info("Show loop info set to {}", newShowLoopInfo);
@@ -248,8 +264,8 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
248264
mod.trackItems = false;
249265
mod.config.trackItems = false;
250266

251-
mod.loopType = LoopTypes.TICKS;
252-
mod.config.loopType = LoopTypes.TICKS;
267+
mod.loopType = "TICKS";
268+
mod.config.loopType = "TICKS";
253269

254270
mod.displayTimeInTicks = false;
255271
mod.config.displayTimeInTicks = false;

src/main/java/com/vltno/timeloop/LoopTypes.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/main/java/com/vltno/timeloop/LoopTypesArgumentType.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/main/java/com/vltno/timeloop/TimeLoop.java

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@
44
import com.google.gson.JsonObject;
55
import com.google.gson.JsonParser;
66
import net.fabricmc.api.ModInitializer;
7-
import net.fabricmc.fabric.api.command.v2.ArgumentTypeRegistry;
87
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
98
import net.fabricmc.fabric.api.entity.event.v1.EntitySleepEvents;
109
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
1110
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
1211
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
1312
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
14-
import net.minecraft.command.argument.serialize.ConstantArgumentSerializer;
1513
import net.minecraft.server.MinecraftServer;
1614
import net.minecraft.server.network.ServerPlayerEntity;
1715
import net.minecraft.server.world.ServerWorld;
1816
import net.minecraft.text.Text;
19-
import net.minecraft.util.Identifier;
2017
import net.minecraft.util.WorldSavePath;
2118
import org.slf4j.Logger;
2219
import org.slf4j.LoggerFactory;
@@ -27,6 +24,7 @@
2724
import java.util.ArrayList;
2825
import java.util.Arrays;
2926
import java.util.List;
27+
import java.util.Objects;
3028

3129
public class TimeLoop implements ModInitializer {
3230
public static final Logger LOOP_LOGGER = LoggerFactory.getLogger("TimeLoop");
@@ -50,7 +48,7 @@ public class TimeLoop implements ModInitializer {
5048
public boolean showLoopInfo;
5149
public boolean displayTimeInTicks;
5250
public boolean trackItems;
53-
public LoopTypes loopType;
51+
public String loopType;
5452

5553
// The configuration object loaded from disk
5654
public TimeLoopConfig config;
@@ -66,20 +64,20 @@ public class TimeLoop implements ModInitializer {
6664
public void onInitialize() {
6765
LOOP_LOGGER.info("Initializing TimeLoop mod");
6866

69-
// Register the custom ArgumentType
70-
ArgumentTypeRegistry.registerArgumentType(Identifier.of("timeloop",""), LoopTypesArgumentType.class, ConstantArgumentSerializer.of(LoopTypesArgumentType::new));
71-
7267
// Register commands
7368
commands = new Commands(this);
74-
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) ->
75-
commands.register(dispatcher, registryAccess, environment)
76-
);
69+
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
70+
// Only register commands on the logical server
71+
if (environment.dedicated || environment.integrated) {
72+
commands.register(dispatcher);
73+
}
74+
});
7775

7876
// BossBar
7977
loopBossBar = new LoopBossBar();
8078

8179
EntitySleepEvents.STOP_SLEEPING.register((entity, sleepingPos) -> {
82-
if (entity.isPlayer() && (loopType == LoopTypes.SLEEP) ) {
80+
if (entity.isPlayer() && (Objects.equals(loopType, "SLEEP")) ) {
8381
LOOP_LOGGER.info("Player slept, looping.");
8482
runLoopIteration();
8583
}
@@ -112,11 +110,6 @@ public void onInitialize() {
112110
TimeLoop.server = server;
113111
serverWorld = server.getOverworld();
114112

115-
// Loop boss bar info
116-
String loopInfo = (loopType == LoopTypes.TICKS ? "Ticks Left: " + loopLengthTicks : loopType == LoopTypes.TIME_OF_DAY ? "Time left: " + (startTimeOfDay - timeSetting) : "");
117-
loopBossBar.visible(false);
118-
loopBossBar.setBossBarName(loopInfo);
119-
120113
// set mocap settings
121114
executeCommand("mocap settings advanced experimental_release_warning false");
122115
executeCommand("mocap settings playback start_as_recorded true");
@@ -164,7 +157,9 @@ public void onInitialize() {
164157
if (isLooping) {
165158
LOOP_LOGGER.info("Starting recording for newly joined player: {}", playerName);
166159
executeCommand(String.format("mocap recording start %s", playerName));
167-
if (showLoopInfo) { loopBossBar.visible(true); }
160+
if (showLoopInfo) {
161+
loopBossBar.visible(loopType.equals("TICKS") || loopType.equals("TIME_OF_DAY"));
162+
}
168163
}
169164
});
170165

@@ -181,15 +176,15 @@ public void onInitialize() {
181176
});
182177

183178
ServerPlayerEvents.AFTER_RESPAWN.register((oldPlayer, newPlayer, alive) -> {
184-
if (loopType != LoopTypes.DEATH) { return; }
179+
if (!Objects.equals(loopType, "DEATH")) { return; }
185180
runLoopIteration();
186181
});
187182

188183
ServerTickEvents.END_SERVER_TICK.register(server -> {
189-
if (loopType == LoopTypes.SLEEP || loopType == LoopTypes.DEATH) { return; }
184+
if (Objects.equals(loopType, "SLEEP") || Objects.equals(loopType, "DEATH")) { return; }
190185

191186
if (isLooping) {
192-
if (loopType == LoopTypes.TIME_OF_DAY) {
187+
if (Objects.equals(loopType, "TIME_OF_DAY")) {
193188
if (timeSetting <= startTimeOfDay) { // prevent stupid 1 tick loop bug
194189
startTimeOfDay = 0;
195190
config.startTimeOfDay = 0;}
@@ -204,7 +199,7 @@ public void onInitialize() {
204199
}
205200
}
206201

207-
else if (loopType == LoopTypes.TICKS) {
202+
else if (Objects.equals(loopType, "TICKS")) {
208203
tickCounter++;
209204
ticksLeft = loopLengthTicks - tickCounter;
210205

@@ -229,7 +224,10 @@ public void startLoop() {
229224
LOOP_LOGGER.info("Attempted to start already running recording loop");
230225
return;
231226
}
232-
if (showLoopInfo) { loopBossBar.visible(true); }
227+
if (showLoopInfo) {
228+
loopBossBar.visible(loopType.equals("TICKS") || loopType.equals("TIME_OF_DAY"));
229+
}
230+
233231
isLooping = true;
234232
config.isLooping = true;
235233
tickCounter = 0;

src/main/java/com/vltno/timeloop/TimeLoopConfig.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
import java.io.Writer;
99
import java.nio.file.Files;
1010
import java.nio.file.Path;
11-
import java.util.ArrayList;
1211
import java.util.HashMap;
13-
import java.util.List;
1412
import java.util.Map;
1513

1614
public class TimeLoopConfig {
@@ -29,7 +27,7 @@ public class TimeLoopConfig {
2927
public boolean showLoopInfo = true;
3028
public boolean displayTimeInTicks = false;
3129
public boolean trackItems = false;
32-
public LoopTypes loopType = LoopTypes.TICKS;
30+
public String loopType = "TICKS";
3331

3432
public Map<String, PlayerData> recordingPlayers = new HashMap<>();
3533

src/main/resources/fabric.mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
],
1111
"license": "CC0-1.0",
1212
"icon": "assets/time-loop/icon.png",
13-
"environment": "server",
13+
"environment": "*",
1414
"entrypoints": {
1515
"main": [
1616
"com.vltno.timeloop.TimeLoop"

0 commit comments

Comments
 (0)