From 7cdd12331c2df058eaac8f24b61e2b8931c498a3 Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Sat, 5 Mar 2022 14:32:51 -0800 Subject: [PATCH] Update to 1.18.2 - Update biome code - Update resource redirect code - Switch to slf4j logging - Update build dependencies --- build.gradle | 6 +++--- gradle.properties | 10 ++++----- .../continuity/client/ContinuityClient.java | 6 +++--- .../client/config/ContinuityConfig.java | 9 ++++---- .../client/config/ContinuityConfigScreen.java | 4 ++-- .../mixin/ChunkRendererRegionMixin.java | 3 ++- ...> LifecycledResourceManagerImplMixin.java} | 21 ++++--------------- ...ReloadableResourceManagerImplAccessor.java | 13 ++++++++++++ ...fecycledResourceManagerImplExtension.java} | 2 +- .../client/util/ResourceRedirectHelper.java | 8 +++++-- .../client/util/biome/BiomeRetriever.java | 6 +++--- .../client/util/biome/BiomeView.java | 3 ++- src/main/resources/continuity.mixins.json | 3 ++- 13 files changed, 50 insertions(+), 44 deletions(-) rename src/main/java/me/pepperbell/continuity/client/mixin/{ReloadableResourceManagerImplMixin.java => LifecycledResourceManagerImplMixin.java} (66%) create mode 100644 src/main/java/me/pepperbell/continuity/client/mixin/ReloadableResourceManagerImplAccessor.java rename src/main/java/me/pepperbell/continuity/client/mixinterface/{ReloadableResourceManagerImplExtension.java => LifecycledResourceManagerImplExtension.java} (71%) diff --git a/build.gradle b/build.gradle index d7f6a3f..658ee84 100644 --- a/build.gradle +++ b/build.gradle @@ -40,12 +40,12 @@ dependencies { // Fabric API modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modImplementation('com.terraformersmc:modmenu:3.0.1') { + modImplementation('com.terraformersmc:modmenu:3.1.0') { exclude group: 'net.fabricmc.fabric-api' } - modCompileOnly 'maven.modrinth:sodium:mc1.18.1-0.4.0-alpha6' - modCompileOnly 'io.vram:canvas-fabric-mc118:1.0.2291' + modCompileOnly 'maven.modrinth:sodium:mc1.18.2-0.4.1' + modCompileOnly 'io.vram:canvas-fabric-mc118:1.0.2308' } String getExtraBuildMetadata() { diff --git a/gradle.properties b/gradle.properties index e5352d9..0f6cf5e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,15 +3,15 @@ org.gradle.jvmargs = -Xmx1G # Fabric Properties loom_version = 0.11-SNAPSHOT - minecraft_version = 1.18.1 - yarn_mappings = 1.18.1+build.22 - loader_version = 0.13.2 + minecraft_version = 1.18.2 + yarn_mappings = 1.18.2+build.2 + loader_version = 0.13.3 # Mod Properties mod_version = 1.1.0 - mod_minecraft_version = 1.18 + mod_minecraft_version = 1.18.2 maven_group = me.pepperbell archives_base_name = continuity # Dependencies - fabric_version = 0.46.4+1.18 + fabric_version = 0.47.10+1.18.2 diff --git a/src/main/java/me/pepperbell/continuity/client/ContinuityClient.java b/src/main/java/me/pepperbell/continuity/client/ContinuityClient.java index 29fc4ce..f050b02 100644 --- a/src/main/java/me/pepperbell/continuity/client/ContinuityClient.java +++ b/src/main/java/me/pepperbell/continuity/client/ContinuityClient.java @@ -3,8 +3,8 @@ import java.util.List; import java.util.Map; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import me.pepperbell.continuity.api.client.CTMLoader; @@ -58,7 +58,7 @@ public class ContinuityClient implements ClientModInitializer { public static final String ID = "continuity"; public static final String NAME = "Continuity"; - public static final Logger LOGGER = LogManager.getLogger(NAME); + public static final Logger LOGGER = LoggerFactory.getLogger(NAME); @Override public void onInitializeClient() { diff --git a/src/main/java/me/pepperbell/continuity/client/config/ContinuityConfig.java b/src/main/java/me/pepperbell/continuity/client/config/ContinuityConfig.java index 691fac5..cdfd074 100644 --- a/src/main/java/me/pepperbell/continuity/client/config/ContinuityConfig.java +++ b/src/main/java/me/pepperbell/continuity/client/config/ContinuityConfig.java @@ -6,9 +6,9 @@ import java.util.Collections; import java.util.Map; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -24,8 +24,7 @@ import net.minecraft.client.MinecraftClient; public class ContinuityConfig { - protected static final Logger LOGGER = LogManager.getLogger("Continuity Config"); - protected static final JsonParser PARSER = new JsonParser(); + protected static final Logger LOGGER = LoggerFactory.getLogger("Continuity Config"); protected static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); public static final ContinuityConfig INSTANCE = new ContinuityConfig(FabricLoader.getInstance().getConfigDir().resolve("continuity.json").toFile()); @@ -47,7 +46,7 @@ public ContinuityConfig(File file) { public void load() { if (file.exists()) { try (FileReader reader = new FileReader(file)) { - fromJson(PARSER.parse(reader)); + fromJson(JsonParser.parseReader(reader)); } catch (Exception e) { LOGGER.error("Could not load config from file '" + file.getAbsolutePath() + "'", e); } diff --git a/src/main/java/me/pepperbell/continuity/client/config/ContinuityConfigScreen.java b/src/main/java/me/pepperbell/continuity/client/config/ContinuityConfigScreen.java index cc509b5..301eeac 100644 --- a/src/main/java/me/pepperbell/continuity/client/config/ContinuityConfigScreen.java +++ b/src/main/java/me/pepperbell/continuity/client/config/ContinuityConfigScreen.java @@ -23,7 +23,7 @@ protected void init() { addDrawableChild(createBooleanOptionButton(width / 2 - 75 - 90, height / 2 - 10, 150, 20, config.disableCTM)); addDrawableChild(createBooleanOptionButton(width / 2 - 75 + 90, height / 2 - 10, 150, 20, config.useManualCulling)); - addDrawableChild(new ButtonWidget(width / 2 - 100, height - 40, 200, 20, ScreenTexts.DONE, button -> onClose())); + addDrawableChild(new ButtonWidget(width / 2 - 100, height - 40, 200, 20, ScreenTexts.DONE, button -> close())); } @Override @@ -34,7 +34,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { } @Override - public void onClose() { + public void close() { client.setScreen(parent); } diff --git a/src/main/java/me/pepperbell/continuity/client/mixin/ChunkRendererRegionMixin.java b/src/main/java/me/pepperbell/continuity/client/mixin/ChunkRendererRegionMixin.java index e97a4ce..06b6628 100644 --- a/src/main/java/me/pepperbell/continuity/client/mixin/ChunkRendererRegionMixin.java +++ b/src/main/java/me/pepperbell/continuity/client/mixin/ChunkRendererRegionMixin.java @@ -7,6 +7,7 @@ import me.pepperbell.continuity.client.util.biome.BiomeView; import net.minecraft.client.render.chunk.ChunkRendererRegion; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.registry.RegistryEntry; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; @@ -17,7 +18,7 @@ public class ChunkRendererRegionMixin implements BiomeView { protected World world; @Override - public Biome getBiome(BlockPos pos) { + public RegistryEntry getBiome(BlockPos pos) { return world.getBiome(pos); } } diff --git a/src/main/java/me/pepperbell/continuity/client/mixin/ReloadableResourceManagerImplMixin.java b/src/main/java/me/pepperbell/continuity/client/mixin/LifecycledResourceManagerImplMixin.java similarity index 66% rename from src/main/java/me/pepperbell/continuity/client/mixin/ReloadableResourceManagerImplMixin.java rename to src/main/java/me/pepperbell/continuity/client/mixin/LifecycledResourceManagerImplMixin.java index 437ef20..2b23cc6 100644 --- a/src/main/java/me/pepperbell/continuity/client/mixin/ReloadableResourceManagerImplMixin.java +++ b/src/main/java/me/pepperbell/continuity/client/mixin/LifecycledResourceManagerImplMixin.java @@ -1,27 +1,19 @@ package me.pepperbell.continuity.client.mixin; -import java.util.List; import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyVariable; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; -import me.pepperbell.continuity.client.mixinterface.ReloadableResourceManagerImplExtension; -import net.minecraft.resource.ReloadableResourceManagerImpl; -import net.minecraft.resource.ResourcePack; -import net.minecraft.resource.ResourceReload; +import me.pepperbell.continuity.client.mixinterface.LifecycledResourceManagerImplExtension; +import net.minecraft.resource.LifecycledResourceManagerImpl; import net.minecraft.util.Identifier; -import net.minecraft.util.Unit; -@Mixin(ReloadableResourceManagerImpl.class) -public class ReloadableResourceManagerImplMixin implements ReloadableResourceManagerImplExtension { +@Mixin(LifecycledResourceManagerImpl.class) +public class LifecycledResourceManagerImplMixin implements LifecycledResourceManagerImplExtension { @Unique private final Map redirects = new Object2ObjectOpenHashMap<>(); @@ -64,9 +56,4 @@ private Identifier redirectGetAllResourcesId(Identifier id) { // } // } // } - - @Inject(method = "reload(Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;Ljava/util/concurrent/CompletableFuture;Ljava/util/List;)Lnet/minecraft/resource/ResourceReload;", at = @At("HEAD")) - private void onHeadReload(Executor prepareExecutor, Executor applyExecutor, CompletableFuture initialStage, List packs, CallbackInfoReturnable cir) { - redirects.clear(); - } } diff --git a/src/main/java/me/pepperbell/continuity/client/mixin/ReloadableResourceManagerImplAccessor.java b/src/main/java/me/pepperbell/continuity/client/mixin/ReloadableResourceManagerImplAccessor.java new file mode 100644 index 0000000..7c82d2e --- /dev/null +++ b/src/main/java/me/pepperbell/continuity/client/mixin/ReloadableResourceManagerImplAccessor.java @@ -0,0 +1,13 @@ +package me.pepperbell.continuity.client.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import net.minecraft.resource.LifecycledResourceManager; +import net.minecraft.resource.ReloadableResourceManagerImpl; + +@Mixin(ReloadableResourceManagerImpl.class) +public interface ReloadableResourceManagerImplAccessor { + @Accessor("activeManager") + LifecycledResourceManager getActiveManager(); +} diff --git a/src/main/java/me/pepperbell/continuity/client/mixinterface/ReloadableResourceManagerImplExtension.java b/src/main/java/me/pepperbell/continuity/client/mixinterface/LifecycledResourceManagerImplExtension.java similarity index 71% rename from src/main/java/me/pepperbell/continuity/client/mixinterface/ReloadableResourceManagerImplExtension.java rename to src/main/java/me/pepperbell/continuity/client/mixinterface/LifecycledResourceManagerImplExtension.java index 1ba9dc7..4cb075d 100644 --- a/src/main/java/me/pepperbell/continuity/client/mixinterface/ReloadableResourceManagerImplExtension.java +++ b/src/main/java/me/pepperbell/continuity/client/mixinterface/LifecycledResourceManagerImplExtension.java @@ -2,6 +2,6 @@ import net.minecraft.util.Identifier; -public interface ReloadableResourceManagerImplExtension { +public interface LifecycledResourceManagerImplExtension { void addRedirect(Identifier from, Identifier to); } diff --git a/src/main/java/me/pepperbell/continuity/client/util/ResourceRedirectHelper.java b/src/main/java/me/pepperbell/continuity/client/util/ResourceRedirectHelper.java index 86d294e..0ac21d1 100644 --- a/src/main/java/me/pepperbell/continuity/client/util/ResourceRedirectHelper.java +++ b/src/main/java/me/pepperbell/continuity/client/util/ResourceRedirectHelper.java @@ -1,12 +1,16 @@ package me.pepperbell.continuity.client.util; -import me.pepperbell.continuity.client.mixinterface.ReloadableResourceManagerImplExtension; +import me.pepperbell.continuity.client.mixin.ReloadableResourceManagerImplAccessor; +import me.pepperbell.continuity.client.mixinterface.LifecycledResourceManagerImplExtension; import net.minecraft.resource.ResourceManager; import net.minecraft.util.Identifier; public final class ResourceRedirectHelper { public static void addRedirect(ResourceManager resourceManager, Identifier from, Identifier to) { - if (resourceManager instanceof ReloadableResourceManagerImplExtension extension) { + if (resourceManager instanceof ReloadableResourceManagerImplAccessor accessor) { + resourceManager = accessor.getActiveManager(); + } + if (resourceManager instanceof LifecycledResourceManagerImplExtension extension) { extension.addRedirect(from, to); } } diff --git a/src/main/java/me/pepperbell/continuity/client/util/biome/BiomeRetriever.java b/src/main/java/me/pepperbell/continuity/client/util/biome/BiomeRetriever.java index 4c3d898..22b9581 100644 --- a/src/main/java/me/pepperbell/continuity/client/util/biome/BiomeRetriever.java +++ b/src/main/java/me/pepperbell/continuity/client/util/biome/BiomeRetriever.java @@ -58,14 +58,14 @@ public static void init() { private static Biome getBiomeByWorldView(BlockRenderView blockView, BlockPos pos) { if (blockView instanceof WorldView worldView) { - return worldView.getBiome(pos); + return worldView.getBiome(pos).value(); } return null; } private static Biome getBiomeByExtension(BlockRenderView blockView, BlockPos pos) { if (blockView instanceof BiomeView biomeView) { - return biomeView.getBiome(pos); + return biomeView.getBiome(pos).value(); } return getBiomeByWorldView(blockView, pos); } @@ -73,7 +73,7 @@ private static Biome getBiomeByExtension(BlockRenderView blockView, BlockPos pos // Sodium private static Biome getBiomeByWorldSlice(BlockRenderView blockView, BlockPos pos) { if (blockView instanceof WorldSlice worldSlice) { - return worldSlice.getBiomeAccess().getBiome(pos); + return worldSlice.getBiomeAccess().getBiome(pos).value(); } return getBiomeByWorldView(blockView, pos); } diff --git a/src/main/java/me/pepperbell/continuity/client/util/biome/BiomeView.java b/src/main/java/me/pepperbell/continuity/client/util/biome/BiomeView.java index 3c1d665..b457cf3 100644 --- a/src/main/java/me/pepperbell/continuity/client/util/biome/BiomeView.java +++ b/src/main/java/me/pepperbell/continuity/client/util/biome/BiomeView.java @@ -1,8 +1,9 @@ package me.pepperbell.continuity.client.util.biome; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.registry.RegistryEntry; import net.minecraft.world.biome.Biome; public interface BiomeView { - Biome getBiome(BlockPos pos); + RegistryEntry getBiome(BlockPos pos); } diff --git a/src/main/resources/continuity.mixins.json b/src/main/resources/continuity.mixins.json index fbfe1df..5ed59bc 100644 --- a/src/main/resources/continuity.mixins.json +++ b/src/main/resources/continuity.mixins.json @@ -8,9 +8,10 @@ "ChunkRendererRegionMixin", "FallingBlockEntityRendererMixin", "IdentifierMixin", + "LifecycledResourceManagerImplMixin", "ModelLoaderMixin", "NamespaceResourceManagerMixin", - "ReloadableResourceManagerImplMixin", + "ReloadableResourceManagerImplAccessor", "RenderLayersMixin" ], "injectors": {