Skip to content

Commit c099b5f

Browse files
committed
Rewrote everything basically
- `common` now uses mojang mappings - `fabric` now uses parchment mappings - `neoforge` was set up (not tested)
1 parent 800e6ee commit c099b5f

35 files changed

Lines changed: 618 additions & 383 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ replay_*.log
4141

4242
# misc
4343
/code_changes.json
44-
/git_diff_monitor.py
44+
/git_diff_monitor.py
45+
/neoforge/run/

build.gradle

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
plugins {
2-
id 'dev.architectury.loom' version '1.7-SNAPSHOT' apply false
3-
id 'architectury-plugin' version '3.4-SNAPSHOT'
4-
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
5-
}
6-
71
task openBuildDir {
82
doLast {
93
def buildDir = file("${layout.buildDirectory.get().asFile.absolutePath}/libs").absolutePath
@@ -16,18 +10,8 @@ task openBuildDir {
1610
}
1711
}
1812

19-
architectury {
20-
minecraft = project.minecraft_version
21-
}
22-
23-
allprojects {
24-
group = rootProject.maven_group
25-
version = rootProject.mod_version
26-
}
27-
2813
subprojects {
29-
apply plugin: 'dev.architectury.loom'
30-
apply plugin: 'architectury-plugin'
14+
apply plugin: 'java'
3115

3216
base {
3317
archivesName = "${archives_name}-${project.name.toUpperCase()}-${minecraft_version}"
@@ -57,7 +41,6 @@ subprojects {
5741
"fabric_loader_version" : fabric_loader_version,
5842
"fabric_api_version" : fabric_api_version,
5943
"neoforge_version" : neoforge_version,
60-
"yarn_mappings_patch_neoforge_version" : yarn_mappings_patch_neoforge_version,
6144
]
6245

6346
filesMatching(["pack.mcmeta", "fabric.mod.json", "META-INF/neoforge.mods.toml", "*.mixins.json"]) {
@@ -69,18 +52,10 @@ subprojects {
6952
jar {
7053
exclude "assets/time-loop/icon.psd"
7154
}
72-
73-
if (project.name != "common") {
74-
jar {
75-
finalizedBy openBuildDir
76-
}
77-
}
7855

79-
dependencies {
80-
minecraft "net.minecraft:minecraft:$rootProject.minecraft_version"
81-
mappings loom.layered {
82-
it.mappings("net.fabricmc:yarn:$rootProject.yarn_mappings:v2")
83-
it.mappings("dev.architectury:yarn-mappings-patch-neoforge:$rootProject.yarn_mappings_patch_neoforge_version")
56+
if (project.name in ["fabric", "neoforge"]) {
57+
tasks.named("jar") {
58+
finalizedBy rootProject.tasks.named("openBuildDir")
8459
}
8560
}
8661

common/build.gradle

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1-
architectury {
2-
common rootProject.enabled_platforms.split(',')
1+
plugins {
2+
id "java-library"
3+
id "fabric-loom" version "${fabric_loom_version}"
34
}
45

6+
repositories {
7+
mavenCentral()
8+
maven { url = "https://maven.parchmentmc.org/" }
9+
maven { url = "https://repo.spongepowered.org/repository/maven-public" }
10+
}
11+
12+
group = project.maven_group // Set group from root project
13+
version = project.mod_version // Set version from root project
14+
515
dependencies {
6-
// We depend on Fabric Loader here to use the Fabric @Environment annotations,
7-
// which get remapped to the correct annotations on each platform.
8-
// Do NOT use other classes from Fabric Loader.
9-
modImplementation "net.fabricmc:fabric-loader:$rootProject.fabric_loader_version"
16+
minecraft "com.mojang:minecraft:${minecraft_version}"
17+
// mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
18+
mappings loom.officialMojangMappings()
19+
20+
compileOnly "org.spongepowered:mixin:0.8.5:processor"
21+
}
22+
23+
loom {
24+
mixin.useLegacyMixinAp = false
25+
officialMojangMappings()
1026
}

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

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
11
package com.vltno.timeloop;
22

3-
import net.minecraft.entity.boss.ServerBossBar;
4-
import net.minecraft.entity.boss.BossBar.Color;
5-
import net.minecraft.entity.boss.BossBar.Style;
6-
import net.minecraft.server.network.ServerPlayerEntity;
7-
import net.minecraft.text.Text;
8-
import org.slf4j.LoggerFactory;
9-
import org.slf4j.Logger;
3+
import net.minecraft.server.level.ServerBossEvent;
4+
import net.minecraft.world.BossEvent.BossBarColor;
5+
import net.minecraft.world.BossEvent.BossBarOverlay;
6+
import net.minecraft.server.level.ServerPlayer;
7+
import net.minecraft.network.chat.Component;
108

119
public class LoopBossBar {
12-
private static final Logger LOGGER = LoggerFactory.getLogger("LoopCommands");
13-
private final ServerBossBar bossBar;
14-
10+
private final ServerBossEvent bossBar;
1511

1612
public LoopBossBar() {
17-
bossBar = new ServerBossBar(Text.literal("TimeLoop"), Color.YELLOW, Style.PROGRESS);
13+
bossBar = new ServerBossEvent(Component.literal("TimeLoop"), BossBarColor.YELLOW, BossBarOverlay.PROGRESS);
1814
}
1915

2016
public void visible(boolean bool) {
2117
bossBar.setVisible(bool);
2218
}
2319

2420
public void setBossBarName(String bossBarName) {
25-
bossBar.setName(Text.literal(bossBarName));
21+
bossBar.setName(Component.literal(bossBarName));
2622
}
2723

2824
public void setBossBarPercentage(int whole, int part) {
29-
bossBar.setPercent(1.0f - ((float) part / whole));
25+
if (whole <= 0) {
26+
bossBar.setProgress(1.0f);
27+
return;
28+
}
29+
// Calculate progress (fraction remaining)
30+
float progress = 1.0f - ((float) part / whole);
31+
// Clamp progress between 0.0 and 1.0
32+
bossBar.setProgress(Math.max(0.0f, Math.min(1.0f, progress)));
3033
}
3134

32-
public void addPlayer(ServerPlayerEntity player) {
33-
LOGGER.info("Adding player: {}", player.getName().getString());
35+
public void addPlayer(ServerPlayer player) {
36+
TimeLoop.LOOP_LOGGER.info("Adding player to boss bar: {}", player.getName().getString());
3437
bossBar.addPlayer(player);
3538
}
3639

37-
public void removePlayer(ServerPlayerEntity player) {
38-
LOGGER.info("Removing player: {}", player.getName().getString());
40+
public void removePlayer(ServerPlayer player) {
41+
TimeLoop.LOOP_LOGGER.info("Removing player from boss bar: {}", player.getName().getString());
3942
bossBar.removePlayer(player);
4043
}
41-
}
44+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.vltno.timeloop;
2+
3+
import com.mojang.brigadier.CommandDispatcher;
4+
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
5+
import com.vltno.timeloop.commands.BaseCommands;
6+
import com.vltno.timeloop.commands.SettingsCommands;
7+
import net.minecraft.commands.CommandSourceStack;
8+
import net.minecraft.commands.Commands;
9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
11+
12+
public class LoopCommands {
13+
public static final Logger LOOP_COMMANDS_LOGGER = LoggerFactory.getLogger("LoopCommands");
14+
15+
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
16+
{
17+
LiteralArgumentBuilder<CommandSourceStack> commandBuilder = Commands.literal("loop");
18+
19+
BaseCommands.register(commandBuilder);
20+
SettingsCommands.register(commandBuilder);
21+
// TogglesCommands.register is called within SettingsCommands.register
22+
23+
dispatcher.register(commandBuilder);
24+
}
25+
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package com.vltno.timeloop;
22

3-
import net.minecraft.util.StringIdentifiable;
3+
import net.minecraft.util.StringRepresentable;
4+
import org.jetbrains.annotations.NotNull;
45

5-
public enum LoopTypes implements StringIdentifiable {
6+
public enum LoopTypes implements StringRepresentable {
67
TICKS,
78
TIME_OF_DAY,
89
SLEEP,
910
DEATH;
1011

1112
@Override
12-
public String asString() {
13+
public @NotNull String getSerializedName() {
1314
return name();
1415
}
15-
}
16+
}

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

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
import com.google.gson.JsonArray;
44
import com.google.gson.JsonObject;
55
import com.google.gson.JsonParser;
6+
import com.mojang.brigadier.exceptions.CommandSyntaxException;
7+
import net.minecraft.commands.CommandSourceStack;
8+
import net.minecraft.commands.Commands;
69
import net.minecraft.server.MinecraftServer;
7-
import net.minecraft.server.world.ServerWorld;
10+
import net.minecraft.server.level.ServerLevel;
811
import org.slf4j.Logger;
912
import org.slf4j.LoggerFactory;
1013

@@ -17,8 +20,8 @@
1720
public class TimeLoop {
1821
public static final Logger LOOP_LOGGER = LoggerFactory.getLogger("TimeLoop");
1922
public static MinecraftServer server;
20-
public static ServerWorld serverWorld;
21-
23+
public static ServerLevel serverLevel;
24+
2225
public static LoopBossBar loopBossBar;
2326

2427
// These fields will be initialized from the configuration file.
@@ -62,16 +65,27 @@ public static void init(boolean isDedicatedServer) {
6265
* Executes a minecraft chat command.
6366
*/
6467
public static void executeCommand(String command) {
65-
if (server != null) {
66-
LOOP_LOGGER.info("Executing command: {}", command);
67-
// Execute the command without expecting a return value.
68-
server.getCommandManager().executeWithPrefix(server.getCommandSource(), command);
69-
LOOP_LOGGER.info("Command executed successfully: {}", command);
70-
// For commands like "mocap recording save" you might need an alternative method
71-
// to verify success (for example, by checking for expected side effects).
72-
} else {
68+
if (server == null) {
7369
LOOP_LOGGER.error("Attempted to execute command while server is null: {}", command);
7470
}
71+
72+
server.execute(() -> {
73+
try {
74+
Commands commands = server.getCommands();
75+
76+
CommandSourceStack commandSource = server.createCommandSourceStack();
77+
78+
LOOP_LOGGER.info("Executing command: {}", command);
79+
80+
commands.getDispatcher().execute(command, commandSource);
81+
82+
LOOP_LOGGER.info("Command executed successfully: {}", command);
83+
} catch (CommandSyntaxException e) {
84+
LOOP_LOGGER.error("Failed to execute command '{}' due to syntax error: {}", command, e.getMessage());
85+
} catch (Exception e) {
86+
LOOP_LOGGER.error("An unexpected error occurred while executing command '{}': {}", command, e.getMessage(), e);
87+
}
88+
});
7589
}
7690

7791

@@ -83,7 +97,7 @@ public static void runLoopIteration() {
8397
saveRecordings();
8498
removeOldSceneEntries();
8599
startRecordings();
86-
if (trackTimeOfDay) { serverWorld.setTimeOfDay(startTimeOfDay); }
100+
if (trackTimeOfDay) { serverLevel.setDayTime(startTimeOfDay); }
87101
TimeLoop.executeCommand("mocap playback stop_all including_others");
88102

89103
loopSceneManager.forEachRecordingPlayer(playerData -> {

common/src/main/java/com/vltno/timeloop/TimeLoopLoaderInterface.java

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

0 commit comments

Comments
 (0)