Skip to content

Commit

Permalink
infer release target from minecraft mod container
Browse files Browse the repository at this point in the history
  • Loading branch information
gnembon committed May 16, 2024
1 parent dd1813c commit 7a1e152
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/main/java/carpet/CarpetSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import carpet.utils.CommandHelper;
import carpet.utils.Messenger;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.SemanticVersion;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -48,7 +49,10 @@
public class CarpetSettings
{
public static final String carpetVersion = FabricLoader.getInstance().getModContainer("carpet").orElseThrow().getMetadata().getVersion().toString();
public static final String releaseTarget = "1.20.5";
public static final int [] releaseTarget = {
((SemanticVersion)FabricLoader.getInstance().getModContainer("minecraft").orElseThrow().getMetadata().getVersion()).getVersionComponent(1),
((SemanticVersion)FabricLoader.getInstance().getModContainer("minecraft").orElseThrow().getMetadata().getVersion()).getVersionComponent(2)
};
public static final Logger LOG = LoggerFactory.getLogger("carpet");
public static final ThreadLocal<Boolean> skipGenerationChecks = ThreadLocal.withInitial(() -> false);
public static final ThreadLocal<Boolean> impendingFillSkipUpdates = ThreadLocal.withInitial(() -> false);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/carpet/script/external/Vanilla.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ public static int MinecraftServer_getRunPermissionLevel(MinecraftServer server)
return CarpetSettings.runPermissionLevel;
}

@Deprecated
public static String MinecraftServer_getReleaseTarget(MinecraftServer server)
public static int [] MinecraftServer_getReleaseTarget(MinecraftServer server)
{
return CarpetSettings.releaseTarget;
}
Expand Down
14 changes: 5 additions & 9 deletions src/main/java/carpet/script/utils/SystemInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,12 @@ public class SystemInfo
put("game_view_distance", c -> new NumericValue(c.server().getPlayerList().getViewDistance()));
put("game_mod_name", c -> StringValue.of(c.server().getServerModName()));
put("game_version", c -> StringValue.of(c.server().getServerVersion()));
put("game_target", c -> StringValue.of(Vanilla.MinecraftServer_getReleaseTarget(c.server())));
put("game_target", c -> StringValue.of(String.format("1.%d.%d",
Vanilla.MinecraftServer_getReleaseTarget(c.server())[0],
Vanilla.MinecraftServer_getReleaseTarget(c.server())[1])));
put("game_protocol", c -> NumericValue.of(SharedConstants.getProtocolVersion()));
put("game_major_target", c -> {
String[] vers = Vanilla.MinecraftServer_getReleaseTarget(c.server()).split("\\.");
return NumericValue.of((vers.length > 1) ? Integer.parseInt(vers[1]) : 0);
});
put("game_minor_target", c -> {
String[] vers = Vanilla.MinecraftServer_getReleaseTarget(c.server()).split("\\.");
return NumericValue.of((vers.length > 2) ? Integer.parseInt(vers[2]) : 0);
});
put("game_major_target", c -> NumericValue.of(Vanilla.MinecraftServer_getReleaseTarget(c.server())[0]));
put("game_minor_target", c -> NumericValue.of(Vanilla.MinecraftServer_getReleaseTarget(c.server())[1]));
put("game_stable", c -> BooleanValue.of(SharedConstants.getCurrentVersion().isStable()));
put("game_data_version", c -> NumericValue.of(SharedConstants.getCurrentVersion().getDataVersion().getVersion()));
put("game_pack_version", c -> NumericValue.of(SharedConstants.getCurrentVersion().getPackVersion(PackType.SERVER_DATA)));
Expand Down

0 comments on commit 7a1e152

Please sign in to comment.