From 88b5978a05511754849f2d249230a8a726f38a60 Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:50:17 -0700 Subject: [PATCH] WIP - Port to 1.21 --- build.gradle | 6 -- gradle.properties | 13 ++-- .../continuity/client/ContinuityClient.java | 4 +- .../client/mixin/AtlasLoaderMixin.java | 2 +- .../processor/BaseProcessingPredicate.java | 5 +- .../client/properties/BaseCtmProperties.java | 14 ++--- .../properties/PropertiesParsingHelper.java | 6 +- .../overlay/OverlayPropertiesSection.java | 4 +- .../client/resource/CustomBlockLayers.java | 2 +- .../client/resource/EmissiveSuffixLoader.java | 2 +- .../client/resource/ModelWrappingHandler.java | 11 ++-- .../resource/ResourceRedirectHandler.java | 2 +- .../client/util/biome/BiomeHolderManager.java | 2 +- .../client/util/biome/BiomeRetriever.java | 60 ------------------- src/main/resources/fabric.mod.json | 4 +- .../resourcepacks/default/pack.mcmeta | 4 +- .../glass_pane_culling_fix/pack.mcmeta | 4 +- 17 files changed, 39 insertions(+), 106 deletions(-) delete mode 100644 src/main/java/me/pepperbell/continuity/client/util/biome/BiomeRetriever.java diff --git a/build.gradle b/build.gradle index 98c2766..9a7775d 100644 --- a/build.gradle +++ b/build.gradle @@ -27,10 +27,6 @@ repositories { name 'Modrinth' url 'https://api.modrinth.com/maven' } - maven { - name 'VRAM' - url 'https://maven.vram.io' - } maven { name 'Shedaniel' url 'https://maven.shedaniel.me' @@ -49,8 +45,6 @@ dependencies { modImplementation("com.terraformersmc:modmenu:${modmenu_version}") { exclude group: 'net.fabricmc.fabric-api' } - - modCompileOnly "io.vram:canvas-fabric:${canvas_version}" } processResources { diff --git a/gradle.properties b/gradle.properties index 243cc81..3daa00e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,17 +4,16 @@ org.gradle.parallel = true # Fabric Properties loom_version = 1.6.11 -minecraft_version = 1.20.5 -yarn_mappings = 1.20.5+build.1 -loader_version = 0.15.10 +minecraft_version = 1.21 +yarn_mappings = 1.21+build.1 +loader_version = 0.15.11 # Mod Properties mod_version = 3.0.0-beta.5 -mod_minecraft_version = 1.20.5 +mod_minecraft_version = 1.21 maven_group = me.pepperbell archives_base_name = continuity # Dependencies -fabric_version = 0.97.6+1.20.5 -modmenu_version = 10.0.0-beta.1 -canvas_version = 20.2.2627 +fabric_version = 0.100.1+1.21 +modmenu_version = 11.0.0-beta.1 diff --git a/src/main/java/me/pepperbell/continuity/client/ContinuityClient.java b/src/main/java/me/pepperbell/continuity/client/ContinuityClient.java index 0849f4a..ef7cb01 100644 --- a/src/main/java/me/pepperbell/continuity/client/ContinuityClient.java +++ b/src/main/java/me/pepperbell/continuity/client/ContinuityClient.java @@ -40,7 +40,6 @@ import me.pepperbell.continuity.client.resource.ModelWrappingHandler; import me.pepperbell.continuity.client.util.RenderUtil; import me.pepperbell.continuity.client.util.biome.BiomeHolderManager; -import me.pepperbell.continuity.client.util.biome.BiomeRetriever; import me.pepperbell.continuity.impl.client.ProcessingDataKeyRegistryImpl; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.resource.ResourceManagerHelper; @@ -58,7 +57,6 @@ public class ContinuityClient implements ClientModInitializer { public void onInitializeClient() { ProcessingDataKeyRegistryImpl.INSTANCE.init(); BiomeHolderManager.init(); - BiomeRetriever.init(); ProcessingDataKeys.init(); ModelWrappingHandler.init(); RenderUtil.ReloadListener.init(); @@ -270,6 +268,6 @@ private static CtmProperties.Factory wrapWithOptifi } public static Identifier asId(String path) { - return new Identifier(ID, path); + return Identifier.of(ID, path); } } diff --git a/src/main/java/me/pepperbell/continuity/client/mixin/AtlasLoaderMixin.java b/src/main/java/me/pepperbell/continuity/client/mixin/AtlasLoaderMixin.java index 1775180..05cf6c5 100644 --- a/src/main/java/me/pepperbell/continuity/client/mixin/AtlasLoaderMixin.java +++ b/src/main/java/me/pepperbell/continuity/client/mixin/AtlasLoaderMixin.java @@ -63,7 +63,7 @@ abstract class AtlasLoaderMixin { Map emissiveIdMap = new Object2ObjectOpenHashMap<>(); suppliers.forEach((id, supplier) -> { if (!id.getPath().endsWith(emissiveSuffix)) { - Identifier emissiveId = new Identifier(id.getNamespace(), id.getPath() + emissiveSuffix); + Identifier emissiveId = id.withPath(id.getPath() + emissiveSuffix); if (!suppliers.containsKey(emissiveId)) { Identifier emissiveLocation = emissiveId.withPath("textures/" + emissiveId.getPath() + ".png"); Optional optionalResource = resourceManager.getResource(emissiveLocation); diff --git a/src/main/java/me/pepperbell/continuity/client/processor/BaseProcessingPredicate.java b/src/main/java/me/pepperbell/continuity/client/processor/BaseProcessingPredicate.java index 449052a..fc7d3fc 100644 --- a/src/main/java/me/pepperbell/continuity/client/processor/BaseProcessingPredicate.java +++ b/src/main/java/me/pepperbell/continuity/client/processor/BaseProcessingPredicate.java @@ -8,7 +8,6 @@ import me.pepperbell.continuity.api.client.ProcessingDataProvider; import me.pepperbell.continuity.client.properties.BaseCtmProperties; -import me.pepperbell.continuity.client.util.biome.BiomeRetriever; import net.fabricmc.fabric.api.renderer.v1.mesh.QuadView; import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; @@ -78,13 +77,14 @@ public static BaseProcessingPredicate fromProperties(BaseCtmProperties propertie } public static class BiomeCache { + @Nullable protected Biome biome; protected boolean invalid = true; @Nullable public Biome get(BlockRenderView blockView, BlockPos pos) { if (invalid) { - biome = BiomeRetriever.getBiome(blockView, pos); + biome = blockView.hasBiomes() ? blockView.getBiomeFabric(pos).value() : null; invalid = false; } return biome; @@ -96,6 +96,7 @@ public void reset() { } public static class BlockEntityNameCache { + @Nullable protected String blockEntityName; protected boolean invalid = true; diff --git a/src/main/java/me/pepperbell/continuity/client/properties/BaseCtmProperties.java b/src/main/java/me/pepperbell/continuity/client/properties/BaseCtmProperties.java index fe5b761..1740ec1 100644 --- a/src/main/java/me/pepperbell/continuity/client/properties/BaseCtmProperties.java +++ b/src/main/java/me/pepperbell/continuity/client/properties/BaseCtmProperties.java @@ -153,7 +153,7 @@ protected void detectMatches() { if (matchBlocksPredicate == null) { if (baseName.startsWith("block_")) { try { - Identifier id = new Identifier(baseName.substring(6)); + Identifier id = Identifier.of(baseName.substring(6)); if (Registries.BLOCK.containsId(id)) { Block block = Registries.BLOCK.get(id); matchBlocksPredicate = state -> state.getBlock() == block; @@ -208,7 +208,7 @@ protected void parseTiles() { if (min <= max) { try { for (int tile = min; tile <= max; tile++) { - listBuilder.add(new Identifier(resourceId.getNamespace(), basePath + tile + ".png")); + listBuilder.add(resourceId.withPath(basePath + tile + ".png")); } } catch (InvalidIdentifierException e) { ContinuityClient.LOGGER.warn("Invalid 'tiles' element '" + tileStr + "' at index " + i + " in file '" + resourceId + "' in pack '" + packName + "'", e); @@ -269,7 +269,7 @@ protected void parseTiles() { } try { - listBuilder.add(new Identifier(namespace, path)); + listBuilder.add(Identifier.of(namespace, path)); } catch (InvalidIdentifierException e) { ContinuityClient.LOGGER.warn("Invalid 'tiles' element '" + tileStr + "' at index " + i + " in file '" + resourceId + "' in pack '" + packName + "'", e); } @@ -353,7 +353,7 @@ protected void parseBiomes() { } try { - Identifier biomeId = new Identifier(biomeStr.toLowerCase(Locale.ROOT)); + Identifier biomeId = Identifier.of(biomeStr.toLowerCase(Locale.ROOT)); biomeHolderSet.add(BiomeHolderManager.getOrCreateHolder(biomeId)); } catch (InvalidIdentifierException e) { ContinuityClient.LOGGER.warn("Invalid 'biomes' element '" + biomeStr + "' at index " + i + " in file '" + resourceId + "' in pack '" + packName + "'", e); @@ -584,7 +584,7 @@ protected void parseResourceCondition() { String resourceStr = parts[0]; Identifier resourceId; try { - resourceId = new Identifier(resourceStr); + resourceId = Identifier.of(resourceStr); } catch (InvalidIdentifierException e) { ContinuityClient.LOGGER.warn("Invalid resource '" + resourceStr + "' in 'resourceCondition' element '" + conditionStr + "' at index " + i + " in file '" + this.resourceId + "' in pack '" + packName + "'", e); continue; @@ -643,12 +643,12 @@ protected void resolveTiles() { path = path.substring(0, path.length() - 4); } - spriteId = TextureUtil.toSpriteId(new Identifier(namespace, path)); + spriteId = TextureUtil.toSpriteId(Identifier.of(namespace, path)); textureDependencies.add(spriteId); } else if (redirectHandler != null) { path = redirectHandler.getSourceSpritePath(path); - spriteId = TextureUtil.toSpriteId(new Identifier(namespace, path)); + spriteId = TextureUtil.toSpriteId(Identifier.of(namespace, path)); textureDependencies.add(spriteId); } else { spriteId = TextureUtil.MISSING_SPRITE_ID; diff --git a/src/main/java/me/pepperbell/continuity/client/properties/PropertiesParsingHelper.java b/src/main/java/me/pepperbell/continuity/client/properties/PropertiesParsingHelper.java index 53f5ba7..0f7f50c 100644 --- a/src/main/java/me/pepperbell/continuity/client/properties/PropertiesParsingHelper.java +++ b/src/main/java/me/pepperbell/continuity/client/properties/PropertiesParsingHelper.java @@ -97,7 +97,7 @@ public static Set parseMatchTiles(Properties properties, String prop } try { - set.add(new Identifier(namespace, path)); + set.add(Identifier.of(namespace, path)); } catch (InvalidIdentifierException e) { ContinuityClient.LOGGER.warn("Invalid '" + propertyKey + "' element '" + matchTileStr + "' at index " + i + " in file '" + fileLocation + "' in pack '" + packName + "'", e); } @@ -137,10 +137,10 @@ public static Predicate parseBlockStates(Properties properties, Stri int startIndex; try { if (parts.length == 1 || parts[1].contains("=")) { - blockId = new Identifier(parts[0]); + blockId = Identifier.ofVanilla(parts[0]); startIndex = 1; } else { - blockId = new Identifier(parts[0], parts[1]); + blockId = Identifier.of(parts[0], parts[1]); startIndex = 2; } } catch (InvalidIdentifierException e) { diff --git a/src/main/java/me/pepperbell/continuity/client/properties/overlay/OverlayPropertiesSection.java b/src/main/java/me/pepperbell/continuity/client/properties/overlay/OverlayPropertiesSection.java index f05d185..14e927b 100644 --- a/src/main/java/me/pepperbell/continuity/client/properties/overlay/OverlayPropertiesSection.java +++ b/src/main/java/me/pepperbell/continuity/client/properties/overlay/OverlayPropertiesSection.java @@ -64,9 +64,9 @@ protected void parseTintBlock() { Identifier blockId; try { if (parts.length == 1 || parts[1].contains("=")) { - blockId = new Identifier(parts[0]); + blockId = Identifier.ofVanilla(parts[0]); } else { - blockId = new Identifier(parts[0], parts[1]); + blockId = Identifier.of(parts[0], parts[1]); } } catch (InvalidIdentifierException e) { ContinuityClient.LOGGER.warn("Invalid 'tintBlock' value '" + tintBlockStr + "' in file '" + id + "' in pack '" + packName + "'", e); diff --git a/src/main/java/me/pepperbell/continuity/client/resource/CustomBlockLayers.java b/src/main/java/me/pepperbell/continuity/client/resource/CustomBlockLayers.java index fe82229..a0ca4c6 100644 --- a/src/main/java/me/pepperbell/continuity/client/resource/CustomBlockLayers.java +++ b/src/main/java/me/pepperbell/continuity/client/resource/CustomBlockLayers.java @@ -23,7 +23,7 @@ import net.minecraft.world.EmptyBlockView; public final class CustomBlockLayers { - public static final Identifier LOCATION = new Identifier("optifine/block.properties"); + public static final Identifier LOCATION = Identifier.ofVanilla("optifine/block.properties"); @SuppressWarnings("unchecked") private static final Predicate[] EMPTY_LAYER_PREDICATES = new Predicate[BlockLayer.VALUES.length]; diff --git a/src/main/java/me/pepperbell/continuity/client/resource/EmissiveSuffixLoader.java b/src/main/java/me/pepperbell/continuity/client/resource/EmissiveSuffixLoader.java index afba957..847a880 100644 --- a/src/main/java/me/pepperbell/continuity/client/resource/EmissiveSuffixLoader.java +++ b/src/main/java/me/pepperbell/continuity/client/resource/EmissiveSuffixLoader.java @@ -13,7 +13,7 @@ import net.minecraft.util.Identifier; public final class EmissiveSuffixLoader { - public static final Identifier LOCATION = new Identifier("optifine/emissive.properties"); + public static final Identifier LOCATION = Identifier.ofVanilla("optifine/emissive.properties"); private static String emissiveSuffix; diff --git a/src/main/java/me/pepperbell/continuity/client/resource/ModelWrappingHandler.java b/src/main/java/me/pepperbell/continuity/client/resource/ModelWrappingHandler.java index 1d9b4be..d610558 100644 --- a/src/main/java/me/pepperbell/continuity/client/resource/ModelWrappingHandler.java +++ b/src/main/java/me/pepperbell/continuity/client/resource/ModelWrappingHandler.java @@ -2,6 +2,7 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.UnknownNullability; import com.google.common.collect.ImmutableMap; @@ -51,11 +52,11 @@ private static ImmutableMap createBlockStateModelId return builder.build(); } - public BakedModel wrap(@Nullable BakedModel model, Identifier modelId) { - if (model != null && !model.isBuiltin() && !modelId.equals(ModelLoader.MISSING_ID)) { + public BakedModel wrap(@Nullable BakedModel model, @UnknownNullability Identifier resourceId, @UnknownNullability ModelIdentifier topLevelId) { + if (model != null && !model.isBuiltin() && (resourceId == null || !resourceId.equals(ModelLoader.MISSING_ID))) { if (wrapCtm) { - if (modelId instanceof ModelIdentifier) { - BlockState state = blockStateModelIds.get(modelId); + if (topLevelId != null) { + BlockState state = blockStateModelIds.get(topLevelId); if (state != null) { model = new CtmBakedModel(model, state); } @@ -75,7 +76,7 @@ public static void init() { ModelLoader modelLoader = ctx.loader(); ModelWrappingHandler wrappingHandler = ((ModelLoaderExtension) modelLoader).continuity$getModelWrappingHandler(); if (wrappingHandler != null) { - return wrappingHandler.wrap(model, ctx.id()); + return wrappingHandler.wrap(model, ctx.resourceId(), ctx.topLevelId()); } return model; }); diff --git a/src/main/java/me/pepperbell/continuity/client/resource/ResourceRedirectHandler.java b/src/main/java/me/pepperbell/continuity/client/resource/ResourceRedirectHandler.java index 58cef42..a57b995 100644 --- a/src/main/java/me/pepperbell/continuity/client/resource/ResourceRedirectHandler.java +++ b/src/main/java/me/pepperbell/continuity/client/resource/ResourceRedirectHandler.java @@ -88,7 +88,7 @@ public Identifier redirect(Identifier id) { BooleanState invalidIdentifierState = InvalidIdentifierStateHolder.get(); invalidIdentifierState.enable(); - Identifier newId = new Identifier(id.getNamespace(), newPath); + Identifier newId = id.withPath(newPath); invalidIdentifierState.disable(); return newId; diff --git a/src/main/java/me/pepperbell/continuity/client/util/biome/BiomeHolderManager.java b/src/main/java/me/pepperbell/continuity/client/util/biome/BiomeHolderManager.java index c80247d..d4fd669 100644 --- a/src/main/java/me/pepperbell/continuity/client/util/biome/BiomeHolderManager.java +++ b/src/main/java/me/pepperbell/continuity/client/util/biome/BiomeHolderManager.java @@ -44,7 +44,7 @@ public static void refreshHolders() { String path = id.getPath(); String compactPath = path.replace("_", ""); if (!path.equals(compactPath)) { - Identifier compactId = new Identifier(id.getNamespace(), compactPath); + Identifier compactId = id.withPath(compactPath); if (!biomeRegistry.containsId(compactId)) { compactIdMap.put(compactId, id); } 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 deleted file mode 100644 index 5d20296..0000000 --- a/src/main/java/me/pepperbell/continuity/client/util/biome/BiomeRetriever.java +++ /dev/null @@ -1,60 +0,0 @@ -package me.pepperbell.continuity.client.util.biome; - -import org.jetbrains.annotations.Nullable; - -import grondag.canvas.terrain.region.input.InputRegion; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockRenderView; -import net.minecraft.world.biome.Biome; - -// TODO: Inline this class and always use the API once Canvas properly supports it. -public final class BiomeRetriever { - private static final Provider PROVIDER = createProvider(); - - private static Provider createProvider() { - ClassLoader classLoader = BiomeRetriever.class.getClassLoader(); - - if (FabricLoader.getInstance().isModLoaded("canvas")) { - try { - Class inputRegionClass = Class.forName("grondag.canvas.terrain.region.input.InputRegion", false, classLoader); - inputRegionClass.getMethod("getBiome", BlockPos.class); - return BiomeRetriever::getBiomeByInputRegion; - } catch (ClassNotFoundException | NoSuchMethodException e) { - // - } - } - - return BiomeRetriever::getBiomeByAPI; - } - - @Nullable - public static Biome getBiome(BlockRenderView blockView, BlockPos pos) { - return PROVIDER.getBiome(blockView, pos); - } - - public static void init() { - } - - @Nullable - private static Biome getBiomeByAPI(BlockRenderView blockView, BlockPos pos) { - if (blockView.hasBiomes()) { - return blockView.getBiomeFabric(pos).value(); - } - return null; - } - - // Canvas - @Nullable - private static Biome getBiomeByInputRegion(BlockRenderView blockView, BlockPos pos) { - if (blockView instanceof InputRegion inputRegion) { - return inputRegion.getBiome(pos); - } - return getBiomeByAPI(blockView, pos); - } - - private interface Provider { - @Nullable - Biome getBiome(BlockRenderView blockView, BlockPos pos); - } -} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index def2299..c4ee139 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -31,9 +31,9 @@ ], "depends": { - "minecraft": ">=1.20.5", + "minecraft": ">=1.21", "fabricloader": ">=0.15.0", - "fabric-api": ">=0.97.6" + "fabric-api": ">=0.100.1" }, "custom": { diff --git a/src/main/resources/resourcepacks/default/pack.mcmeta b/src/main/resources/resourcepacks/default/pack.mcmeta index 655ac88..467786c 100644 --- a/src/main/resources/resourcepacks/default/pack.mcmeta +++ b/src/main/resources/resourcepacks/default/pack.mcmeta @@ -1,7 +1,7 @@ { "pack": { - "pack_format": 32, - "supported_formats": [32, 999], + "pack_format": 34, + "supported_formats": [34, 999], "description": { "translate": "resourcePack.continuity.default.description" } diff --git a/src/main/resources/resourcepacks/glass_pane_culling_fix/pack.mcmeta b/src/main/resources/resourcepacks/glass_pane_culling_fix/pack.mcmeta index 827b01b..c74bf0e 100644 --- a/src/main/resources/resourcepacks/glass_pane_culling_fix/pack.mcmeta +++ b/src/main/resources/resourcepacks/glass_pane_culling_fix/pack.mcmeta @@ -1,7 +1,7 @@ { "pack": { - "pack_format": 32, - "supported_formats": [32, 999], + "pack_format": 34, + "supported_formats": [34, 999], "description": { "translate": "resourcePack.continuity.glass_pane_culling_fix.description" }