From cdfc4babb40d979d9989787b1cf3c1d7fb96c2b6 Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 20 Feb 2024 18:40:04 +0000 Subject: [PATCH] Fix leaf flowers rendering on fast graphics --- build.gradle | 7 ++- gradle.properties | 12 +++-- .../unicopia/client/URenderers.java | 1 + .../client/render/LeavesAdditionsModel.java | 54 +++++++++++++++++++ .../unicopia/compat/sodium/Impl.java | 17 ------ .../compat/sodium/SodiumDelegate.java | 19 ------- .../enchantment/StressfulEnchantment.java | 16 +++++- .../mixin/client/MixinBlockModels.java | 29 ---------- .../blockstates/green_apple_leaves.json | 19 +++---- .../blockstates/sour_apple_leaves.json | 19 +++---- .../blockstates/sweet_apple_leaves.json | 19 +++---- .../block/green_apple_leaves_flowering.json | 5 +- .../block/sour_apple_leaves_flowering.json | 5 +- .../block/sweet_apple_leaves_flowering.json | 37 +++---------- src/main/resources/unicopia.mixin.json | 1 - 15 files changed, 113 insertions(+), 147 deletions(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/client/render/LeavesAdditionsModel.java delete mode 100644 src/main/java/com/minelittlepony/unicopia/compat/sodium/Impl.java delete mode 100644 src/main/java/com/minelittlepony/unicopia/compat/sodium/SodiumDelegate.java delete mode 100644 src/main/java/com/minelittlepony/unicopia/mixin/client/MixinBlockModels.java diff --git a/build.gradle b/build.gradle index 5d45804e..a24981db 100644 --- a/build.gradle +++ b/build.gradle @@ -44,6 +44,7 @@ repositories { maven { name 'minelp-snapshot'; url 'https://repo.minelittlepony-mod.com/maven/snapshot' } maven { name 'minelp-releases'; url 'https://repo.minelittlepony-mod.com/maven/release' } maven { name 'TerraformersMC'; url 'https://maven.terraformersmc.com/' } + maven { name 'Nodium'; url 'https://maven.cafeteria.dev/releases/' } maven { name 'Modrinth'; url 'https://api.modrinth.com/maven' } maven { name 'JitPack'; url 'https://jitpack.io'; content { includeGroup "com.github.Virtuoel" } } } @@ -73,6 +74,9 @@ dependencies { modImplementation "com.terraformersmc.terraform-api:terraform-wood-api-v1:${project.terraformer_api_version}" include "com.terraformersmc.terraform-api:terraform-wood-api-v1:${project.terraformer_api_version}" + + modImplementation "me.luligabi:NoIndium:${project.nodium_version}" + include "me.luligabi:NoIndium:${project.nodium_version}" modCompileOnly "maven.modrinth:farmers-delight-fabric:${project.farmers_delight_version}", { exclude group: "net.fabricmc.fabric-api" } if (project.use_pehkui == '1') { @@ -81,8 +85,9 @@ dependencies { } if (project.use_sodium == '1') { + modCompileOnly "maven.modrinth:indium:${project.indium_version}", { exclude group: "net.fabricmc.fabric-api" } modCompileOnly "maven.modrinth:sodium:${project.sodium_version}", { exclude group: "net.fabricmc.fabric-api" } - modCompileOnly "maven.modrinth:iris:${project.iris_version}", { exclude group: "net.fabricmc.fabric-api" } + // modCompileOnly "maven.modrinth:iris:${project.iris_version}", { exclude group: "net.fabricmc.fabric-api" } } if (project.tmi_type == 'emi') { diff --git a/gradle.properties b/gradle.properties index 950040b3..b83bd439 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,9 +4,9 @@ org.gradle.daemon=false # Fabric Properties # check these on https://fabricmc.net/develop minecraft_version=1.20.1 - yarn_mappings=1.20.1+build.9 - loader_version=0.14.21 - fabric_version=0.85.0+1.20.1 + yarn_mappings=1.20.1+build.10 + loader_version=0.15.7 + fabric_version=0.92.0+1.20.1 # Mod Properties group=com.minelittlepony @@ -27,6 +27,7 @@ org.gradle.daemon=false reach_attributes_version=2.3.4 trinkets_version=3.7.1 terraformer_api_version=7.0.0-beta.1 + nodium_version=1.1.0+1.20 # Testing use_pehkui=0 @@ -34,8 +35,9 @@ org.gradle.daemon=false farmers_delight_version=1.4.3 pehkui_version=3.7.8+1.14.4-1.20.1 - iris_version=1.6.8+1.20.1 - sodium_version=mc1.20.1-0.5.2 + iris_version=1.6.17+1.20.1 + sodium_version=mc1.20.1-0.5.8 + indium_version=1.0.30+mc1.20.4 # TMI Testing tmi_type=emi diff --git a/src/main/java/com/minelittlepony/unicopia/client/URenderers.java b/src/main/java/com/minelittlepony/unicopia/client/URenderers.java index 4f436d79..2d7155b2 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/URenderers.java +++ b/src/main/java/com/minelittlepony/unicopia/client/URenderers.java @@ -156,6 +156,7 @@ public interface URenderers { BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getTranslucent(), UBlocks.SEMI_TRANSPARENT_BLOCKS.stream().toArray(Block[]::new)); // for lava boats BlockRenderLayerMap.INSTANCE.putFluids(RenderLayer.getTranslucent(), Fluids.LAVA, Fluids.FLOWING_LAVA); + LeavesAdditionsModel.bootstrap(); TerraformBoatClientHelper.registerModelLayers(Unicopia.id("palm"), false); diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/LeavesAdditionsModel.java b/src/main/java/com/minelittlepony/unicopia/client/render/LeavesAdditionsModel.java new file mode 100644 index 00000000..8fb9735d --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/client/render/LeavesAdditionsModel.java @@ -0,0 +1,54 @@ +package com.minelittlepony.unicopia.client.render; + +import java.util.function.Supplier; + +import com.minelittlepony.unicopia.block.FruitBearingBlock; + +import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin; +import net.fabricmc.fabric.api.client.model.loading.v1.ModelModifier; +import net.fabricmc.fabric.api.renderer.v1.RendererAccess; +import net.fabricmc.fabric.api.renderer.v1.material.BlendMode; +import net.fabricmc.fabric.api.renderer.v1.material.MaterialFinder; +import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel; +import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; +import net.minecraft.block.BlockState; +import net.minecraft.client.render.model.BakedModel; +import net.minecraft.registry.Registries; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.random.Random; +import net.minecraft.world.BlockRenderView; + +public final class LeavesAdditionsModel extends ForwardingBakedModel { + public static void bootstrap() { + ModelLoadingPlugin.register(ctx -> { + ctx.modifyModelAfterBake().register(ModelModifier.WRAP_PHASE, (model, context) -> { + Identifier id = context.id(); + if (!id.getPath().endsWith("_flowering") || !(Registries.BLOCK.get(id.withPath(p -> p.replace("block/", "").replace("_flowering", ""))) instanceof FruitBearingBlock)) { + return model; + } + return model == null ? null : new LeavesAdditionsModel(model); + }); + }); + } + + private LeavesAdditionsModel(BakedModel model) { + this.wrapped = model; + } + + @Override + public boolean isVanillaAdapter() { + return false; + } + + @Override + public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier randomSupplier, RenderContext context) { + MaterialFinder finder = RendererAccess.INSTANCE.getRenderer().materialFinder(); + context.pushTransform(quad -> { + quad.material(finder.copyFrom(quad.material()).blendMode(BlendMode.CUTOUT).find()); + return true; + }); + super.emitBlockQuads(blockView, state, pos, randomSupplier, context); + context.popTransform(); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/compat/sodium/Impl.java b/src/main/java/com/minelittlepony/unicopia/compat/sodium/Impl.java deleted file mode 100644 index 32b6d887..00000000 --- a/src/main/java/com/minelittlepony/unicopia/compat/sodium/Impl.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.minelittlepony.unicopia.compat.sodium; - -import me.jellysquid.mods.sodium.client.SodiumClientMod; -import net.fabricmc.fabric.api.util.TriState; - -public class Impl implements SodiumDelegate { - static Impl INSTANCE = new Impl(); - - @Override - public TriState isFancyLeavesOrBetter() { - return switch (SodiumClientMod.options().quality.leavesQuality) { - case FAST -> TriState.FALSE; - case FANCY -> TriState.TRUE; - case DEFAULT -> TriState.DEFAULT; - }; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/compat/sodium/SodiumDelegate.java b/src/main/java/com/minelittlepony/unicopia/compat/sodium/SodiumDelegate.java deleted file mode 100644 index c3cbb465..00000000 --- a/src/main/java/com/minelittlepony/unicopia/compat/sodium/SodiumDelegate.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.minelittlepony.unicopia.compat.sodium; - -import net.fabricmc.fabric.api.util.TriState; -import net.fabricmc.loader.api.FabricLoader; - -public interface SodiumDelegate { - SodiumDelegate EMPTY = new SodiumDelegate() {}; - - static SodiumDelegate getInstance() { - if (FabricLoader.getInstance().isModLoaded("sodium")) { - return Impl.INSTANCE; - } - return EMPTY; - } - - default TriState isFancyLeavesOrBetter() { - return TriState.DEFAULT; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/StressfulEnchantment.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/StressfulEnchantment.java index 56b8e9a9..aac70928 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/StressfulEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/StressfulEnchantment.java @@ -5,6 +5,8 @@ import com.minelittlepony.unicopia.entity.player.MagicReserves.Bar; import com.minelittlepony.unicopia.entity.player.Pony; +import net.minecraft.entity.mob.HostileEntity; + public class StressfulEnchantment extends SimpleEnchantment { protected StressfulEnchantment(Options options) { @@ -13,8 +15,18 @@ public class StressfulEnchantment extends SimpleEnchantment { @Override public void onUserTick(Living user, int level) { - if (user instanceof Pony) { - Bar bar = ((Pony)user).getMagicalReserves().getEnergy(); + if (user instanceof Pony pony && pony.asEntity().age % 10 == 0) { + int range = (level + 1) * 3; + if (pony.asWorld().getEntitiesByClass(HostileEntity.class, user.asEntity().getBoundingBox().expand(range, 0, range), enemy -> { + return enemy != null + && enemy.canTarget(user.asEntity()) + && enemy.canSee(user.asEntity()) + && enemy.getTarget() == user.asEntity(); + }).isEmpty()) { + return; + } + + Bar bar = pony.getMagicalReserves().getEnergy(); float targetPercent = (level / (float)getMaxLevel()) * 0.05125F; float increase = 1F + (level * level)/100F; if (bar.getPercentFill() < targetPercent) { diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinBlockModels.java b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinBlockModels.java deleted file mode 100644 index fad25baa..00000000 --- a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinBlockModels.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.minelittlepony.unicopia.mixin.client; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyVariable; - -import com.minelittlepony.unicopia.block.FruitBearingBlock; -import com.minelittlepony.unicopia.compat.sodium.SodiumDelegate; - -import net.minecraft.block.BlockState; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.block.BlockModels; - -@Mixin(BlockModels.class) -abstract class MixinBlockModels { - @ModifyVariable( - method = "getModel(Lnet/minecraft/block/BlockState;)Lnet/minecraft/client/render/model/BakedModel;", - at = @At("HEAD"), - argsOnly = true, - ordinal = 0 - ) - private BlockState getAppearance(BlockState state) { - if (state.contains(FruitBearingBlock.STAGE) - && !SodiumDelegate.getInstance().isFancyLeavesOrBetter().orElse(MinecraftClient.isFancyGraphicsOrBetter())) { - return state.with(FruitBearingBlock.STAGE, FruitBearingBlock.Stage.IDLE); - } - return state; - } -} diff --git a/src/main/resources/assets/unicopia/blockstates/green_apple_leaves.json b/src/main/resources/assets/unicopia/blockstates/green_apple_leaves.json index 635befb5..79c8b6a4 100644 --- a/src/main/resources/assets/unicopia/blockstates/green_apple_leaves.json +++ b/src/main/resources/assets/unicopia/blockstates/green_apple_leaves.json @@ -1,16 +1,11 @@ { - "variants": { - "stage=flowering": { - "model": "unicopia:block/green_apple_leaves_flowering" + "multipart": [ + { + "apply": { "model": "unicopia:block/green_apple_leaves" } }, - "stage=idle": { - "model": "unicopia:block/green_apple_leaves" - }, - "stage=fruiting": { - "model": "unicopia:block/green_apple_leaves" - }, - "stage=withering": { - "model": "unicopia:block/green_apple_leaves" + { + "apply": { "model": "unicopia:block/green_apple_leaves_flowering" }, + "when": { "stage": "flowering" } } - } + ] } diff --git a/src/main/resources/assets/unicopia/blockstates/sour_apple_leaves.json b/src/main/resources/assets/unicopia/blockstates/sour_apple_leaves.json index e15d3600..30f1e327 100644 --- a/src/main/resources/assets/unicopia/blockstates/sour_apple_leaves.json +++ b/src/main/resources/assets/unicopia/blockstates/sour_apple_leaves.json @@ -1,16 +1,11 @@ { - "variants": { - "stage=flowering": { - "model": "unicopia:block/sour_apple_leaves_flowering" + "multipart": [ + { + "apply": { "model": "unicopia:block/sour_apple_leaves" } }, - "stage=idle": { - "model": "unicopia:block/sour_apple_leaves" - }, - "stage=fruiting": { - "model": "unicopia:block/sour_apple_leaves" - }, - "stage=withering": { - "model": "unicopia:block/sour_apple_leaves" + { + "apply": { "model": "unicopia:block/sour_apple_leaves_flowering" }, + "when": { "stage": "flowering" } } - } + ] } diff --git a/src/main/resources/assets/unicopia/blockstates/sweet_apple_leaves.json b/src/main/resources/assets/unicopia/blockstates/sweet_apple_leaves.json index e09ef0b9..372d59d5 100644 --- a/src/main/resources/assets/unicopia/blockstates/sweet_apple_leaves.json +++ b/src/main/resources/assets/unicopia/blockstates/sweet_apple_leaves.json @@ -1,16 +1,11 @@ { - "variants": { - "stage=flowering": { - "model": "unicopia:block/sweet_apple_leaves_flowering" + "multipart": [ + { + "apply": { "model": "unicopia:block/sweet_apple_leaves" } }, - "stage=idle": { - "model": "unicopia:block/sweet_apple_leaves" - }, - "stage=fruiting": { - "model": "unicopia:block/sweet_apple_leaves" - }, - "stage=withering": { - "model": "unicopia:block/sweet_apple_leaves" + { + "apply": { "model": "unicopia:block/sweet_apple_leaves_flowering" }, + "when": { "stage": "flowering" } } - } + ] } diff --git a/src/main/resources/assets/unicopia/models/block/green_apple_leaves_flowering.json b/src/main/resources/assets/unicopia/models/block/green_apple_leaves_flowering.json index 1ab7bd8c..3809eb32 100644 --- a/src/main/resources/assets/unicopia/models/block/green_apple_leaves_flowering.json +++ b/src/main/resources/assets/unicopia/models/block/green_apple_leaves_flowering.json @@ -1,7 +1,6 @@ { - "parent": "unicopia:block/sweet_apple_leaves_flowering", + "parent": "minecraft:block/cube_all", "textures": { - "all": "unicopia:block/green_apple_leaves", - "overlay": "unicopia:block/green_apple_leaves_flowering" + "all": "unicopia:block/green_apple_leaves_flowering" } } \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/models/block/sour_apple_leaves_flowering.json b/src/main/resources/assets/unicopia/models/block/sour_apple_leaves_flowering.json index 42924cd9..a3e5a7bd 100644 --- a/src/main/resources/assets/unicopia/models/block/sour_apple_leaves_flowering.json +++ b/src/main/resources/assets/unicopia/models/block/sour_apple_leaves_flowering.json @@ -1,7 +1,6 @@ { - "parent": "unicopia:block/sweet_apple_leaves_flowering", + "parent": "minecraft:block/cube_all", "textures": { - "all": "unicopia:block/sour_apple_leaves", - "overlay": "unicopia:block/sour_apple_leaves_flowering" + "all": "unicopia:block/sour_apple_leaves_flowering" } } \ No newline at end of file diff --git a/src/main/resources/assets/unicopia/models/block/sweet_apple_leaves_flowering.json b/src/main/resources/assets/unicopia/models/block/sweet_apple_leaves_flowering.json index 3d04aabc..773c2e74 100644 --- a/src/main/resources/assets/unicopia/models/block/sweet_apple_leaves_flowering.json +++ b/src/main/resources/assets/unicopia/models/block/sweet_apple_leaves_flowering.json @@ -1,31 +1,6 @@ -{ "parent": "minecraft:block/block", - "textures": { - "all": "unicopia:block/sweet_apple_leaves", - "particle": "#all", - "overlay": "unicopia:block/sweet_apple_leaves_flowering" - }, - "elements": [ - { "from": [ 0, 0, 0 ], - "to": [ 16, 16, 16 ], - "faces": { - "down": { "uv": [ 0, 0, 16, 16 ], "texture": "#all", "tintindex": 0, "cullface": "down" }, - "up": { "uv": [ 0, 0, 16, 16 ], "texture": "#all", "tintindex": 0, "cullface": "up" }, - "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#all", "tintindex": 0, "cullface": "north" }, - "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#all", "tintindex": 0, "cullface": "south" }, - "west": { "uv": [ 0, 0, 16, 16 ], "texture": "#all", "tintindex": 0, "cullface": "west" }, - "east": { "uv": [ 0, 0, 16, 16 ], "texture": "#all", "tintindex": 0, "cullface": "east" } - } - }, - { "from": [ 0, 0, 0 ], - "to": [ 16, 16, 16 ], - "faces": { - "down": { "uv": [ 0, 0, 16, 16 ], "texture": "#overlay", "cullface": "down" }, - "up": { "uv": [ 0, 0, 16, 16 ], "texture": "#overlay", "cullface": "up" }, - "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#overlay", "cullface": "north" }, - "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#overlay", "cullface": "south" }, - "west": { "uv": [ 0, 0, 16, 16 ], "texture": "#overlay", "cullface": "west" }, - "east": { "uv": [ 0, 0, 16, 16 ], "texture": "#overlay", "cullface": "east" } - } - } - ] -} +{ + "parent": "minecraft:block/cube_all", + "textures": { + "all": "unicopia:block/sweet_apple_leaves_flowering" + } +} \ No newline at end of file diff --git a/src/main/resources/unicopia.mixin.json b/src/main/resources/unicopia.mixin.json index 5cdd7249..20a09367 100644 --- a/src/main/resources/unicopia.mixin.json +++ b/src/main/resources/unicopia.mixin.json @@ -65,7 +65,6 @@ "client.MixinAnimalModel", "client.MixinArmorFeatureRenderer", "client.MixinBackgroundRenderer", - "client.MixinBlockModels", "client.MixinCamera", "client.MixinClientWorld", "client.MixinClientPlayNetworkHandler",