From c392815d6457a4ee3ae6b649eface8fc0043a360 Mon Sep 17 00:00:00 2001 From: 1foxy2 <127777030+1foxy2@users.noreply.github.com> Date: Tue, 22 Oct 2024 19:25:51 +0200 Subject: [PATCH] 1.21.2 (#305) Update to 1.21.2 --- .github/workflows/publish.yml | 8 +- build.gradle | 4 +- .../src/main/groovy/multiloader-common.gradle | 26 +--- common/build.gradle | 2 +- .../api/renderers/ExtendedItemRenderer.java | 4 +- .../mixin/CloudRenderer_cloudsMixin.java | 131 ++++++++++++++++++ .../mixin/LevelRenderer_cloudsMixin.java | 125 ----------------- .../mixin/LevelRenderer_rainMixin.java | 71 ---------- .../mixin/Minecraft_managersMixin.java | 6 +- .../WeatherEffectRenderer_rainMixin.java | 61 ++++++++ .../blockentity/SignRenderer_textMixin.java | 2 +- .../blocks/EndGatewayBlock_cullMixin.java | 5 +- .../blocks/ShulkerBoxBlock_cullMixin.java | 5 +- .../BrewingStandBlock_voxelMixin.java | 4 +- .../cullshape/CampfireBlock_voxelMixin.java | 5 +- .../ChorusFlowerBlock_voxelMixin.java | 5 +- .../blockstates/Block_drawSideMixin.java | 26 ---- .../BlockOcclusionCache_sodiumMixin.java | 2 +- .../entities/ItemFrameRenderer_cullMixin.java | 80 ++++++----- .../mixin/models/BuiltInModel_cacheMixin.java | 5 +- .../cullshape/BlockModel_cullShapeMixin.java | 18 +-- ...ava => BlockStateBase_cullShapeMixin.java} | 26 ++-- .../renderers/ItemRenderer_apiMixin.java | 15 +- .../ModelBlockRenderer_cullMixin.java | 2 +- .../states/ItemRendererStates.java | 4 +- .../fxco/moreculling/utils/CullingUtils.java | 45 +++--- .../resources/META-INF/accesstransformer.cfg | 21 +-- .../main/resources/moreculling.accesswidener | 8 +- .../main/resources/moreculling.mixins.json | 6 +- fabric/build.gradle | 8 +- .../Block_fabricDrawSideMixin.java | 42 ++++++ .../MultiPartBakedModel_cacheMixin.java | 8 +- .../SimpleBakedModel_fabricCacheMixin.java | 10 +- .../ItemRenderer_fabricFaceCullingMixin.java | 25 ++-- .../resources/moreculling.fabric.mixins.json | 1 + gradle.properties | 19 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- neoforge/build.gradle | 5 +- .../Block_neoforgeDrawSideMixin.java | 48 +++++++ .../MultiPartBakedModel_cacheMixin.java | 8 +- .../SimpleBakedModel_neoforgeCacheMixin.java | 11 +- ...ItemRenderer_neoforgeFaceCullingMixin.java | 28 ++-- .../resources/META-INF/neoforge.mods.toml | 4 +- .../moreculling.neoforge.mixins.json | 1 + 44 files changed, 492 insertions(+), 450 deletions(-) create mode 100644 common/src/main/java/ca/fxco/moreculling/mixin/CloudRenderer_cloudsMixin.java delete mode 100644 common/src/main/java/ca/fxco/moreculling/mixin/LevelRenderer_cloudsMixin.java delete mode 100644 common/src/main/java/ca/fxco/moreculling/mixin/LevelRenderer_rainMixin.java create mode 100644 common/src/main/java/ca/fxco/moreculling/mixin/WeatherEffectRenderer_rainMixin.java rename common/src/main/java/ca/fxco/moreculling/mixin/models/cullshape/{Cache_cullShapeMixin.java => BlockStateBase_cullShapeMixin.java} (70%) create mode 100644 fabric/src/main/java/ca/fxco/moreculling/mixin/blockstates/Block_fabricDrawSideMixin.java create mode 100644 neoforge/src/main/java/ca/fxco/moreculling/mixin/blockstates/Block_neoforgeDrawSideMixin.java diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b006839c..5d6fb72b 100755 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -24,8 +24,8 @@ jobs: with: files: neoforge/build/libs/!(*-@(dev|sources|api|javadoc)).jar github-files: neoforge/build/libs/*-@(dev|sources|api|javadoc).jar - version-type: release - game-versions: 1.21.1 + version-type: beta + game-versions: 1.21.2 game-version-filter: releases dependencies: | cloth-config(required){modrinth:9s6osm5g}{curseforge:348521}#(ignore:github) @@ -59,8 +59,8 @@ jobs: with: files: fabric/build/libs/!(*-@(dev|sources|api|javadoc)).jar github-files: fabric/build/libs/*-@(dev|sources|api|javadoc).jar - version-type: release - game-versions: 1.21.1 + version-type: beta + game-versions: 1.21.2 game-version-filter: releases dependencies: | cloth-config(required){modrinth:9s6osm5g}{curseforge:348521}#(ignore:github) diff --git a/build.gradle b/build.gradle index 2d6ac894..14935870 100755 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { // see https://fabricmc.net/develop/ for new versions - id 'fabric-loom' version '1.7-SNAPSHOT' apply false + id 'fabric-loom' version '1.8-SNAPSHOT' apply false // see https://projects.neoforged.net/neoforged/moddevgradle for new versions - id 'net.neoforged.moddev' version '1.0.19' apply false + id 'net.neoforged.moddev' version '2.0.40-beta' apply false } \ No newline at end of file diff --git a/buildSrc/src/main/groovy/multiloader-common.gradle b/buildSrc/src/main/groovy/multiloader-common.gradle index 4d1252a6..a82ef818 100644 --- a/buildSrc/src/main/groovy/multiloader-common.gradle +++ b/buildSrc/src/main/groovy/multiloader-common.gradle @@ -16,15 +16,6 @@ java { repositories { mavenCentral() // https://docs.gradle.org/current/userguide/declaring_repositories.html#declaring_content_exclusively_found_in_one_repository - exclusiveContent { - forRepository { - maven { - name = 'Sponge' - url = 'https://repo.spongepowered.org/repository/maven-public' - } - } - filter { includeGroupAndSubgroups('org.spongepowered') } - } exclusiveContent { forRepositories( maven { @@ -43,18 +34,17 @@ repositories { filter { includeGroup('org.parchmentmc.data') includeGroup "maven.modrinth" + includeModule("net.neoforged", "testframework") + includeModule("net.neoforged", "neoforge") } } - maven { - name = 'BlameJared' - url = 'https://maven.blamejared.com' - } maven { //AutoConfig name = "Shedaniel's Maven" url = "https://maven.shedaniel.me/" } maven { url 'https://maven.fallenbreath.me/releases' } maven { url 'https://maven.bawnorton.com/releases' } + maven { url 'https://libraries.minecraft.net/' } } // Declare capabilities on the outgoing configurations. @@ -70,17 +60,7 @@ repositories { } } -sourcesJar { - from(rootProject.file('LICENSE')) { - rename { "${it}_${mod_name}" } - } -} - jar { - from(rootProject.file('LICENSE')) { - rename { "${it}_${mod_name}" } - } - manifest { attributes([ 'Specification-Title' : mod_name, diff --git a/common/build.gradle b/common/build.gradle index e9158984..79f90a3c 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -17,7 +17,7 @@ neoForge { } dependencies { - compileOnly group: 'org.spongepowered', name: 'mixin', version: '0.8.5' + compileOnly group: 'org.spongepowered', name: 'mixin', version: '0.8.7' compileOnly group: 'io.github.llamalad7', name: 'mixinextras-common', version: '0.3.5' annotationProcessor group: 'io.github.llamalad7', name: 'mixinextras-common', version: '0.3.5' diff --git a/common/src/main/java/ca/fxco/moreculling/api/renderers/ExtendedItemRenderer.java b/common/src/main/java/ca/fxco/moreculling/api/renderers/ExtendedItemRenderer.java index d3c7fb14..e68b2016 100644 --- a/common/src/main/java/ca/fxco/moreculling/api/renderers/ExtendedItemRenderer.java +++ b/common/src/main/java/ca/fxco/moreculling/api/renderers/ExtendedItemRenderer.java @@ -5,9 +5,9 @@ import net.minecraft.client.Camera; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.client.renderer.entity.state.ItemFrameRenderState; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.Direction; -import net.minecraft.world.entity.decoration.ItemFrame; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.Nullable; @@ -58,5 +58,5 @@ public interface ExtendedItemRenderer { * @since 0.25.0 */ void moreculling$renderItemFrameItem(ItemStack stack, PoseStack poseStack, MultiBufferSource multiBufferSource, - int light, ItemFrame frame, Camera camera); + int light, ItemFrameRenderState frame, Camera camera); } \ No newline at end of file diff --git a/common/src/main/java/ca/fxco/moreculling/mixin/CloudRenderer_cloudsMixin.java b/common/src/main/java/ca/fxco/moreculling/mixin/CloudRenderer_cloudsMixin.java new file mode 100644 index 00000000..0d6e1f05 --- /dev/null +++ b/common/src/main/java/ca/fxco/moreculling/mixin/CloudRenderer_cloudsMixin.java @@ -0,0 +1,131 @@ +package ca.fxco.moreculling.mixin; + +import ca.fxco.moreculling.MoreCulling; +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.BufferBuilder; +import me.fallenbreath.conditionalmixin.api.annotation.Condition; +import me.fallenbreath.conditionalmixin.api.annotation.Restriction; +import net.minecraft.client.renderer.CloudRenderer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Restriction(conflict = { + @Condition("cullclouds"), + @Condition("extended-clouds"), + @Condition("extendedclouds") +}) +@Mixin(CloudRenderer.class) +public abstract class CloudRenderer_cloudsMixin { + @Shadow + private static boolean isNorthEmpty(long l) { + return false; + } + + @Shadow + private static boolean isSouthEmpty(long l) { + return false; + } + + @Shadow + private static boolean isWestEmpty(long l) { + return false; + } + + @Shadow + private static boolean isEastEmpty(long l) { + return false; + } + + @Inject( + method = "buildExtrudedCell", + at = @At(value = "HEAD"), + cancellable = true + ) + private void moreculling$renderClouds(CloudRenderer.RelativeCameraPos relativeCameraPos, + BufferBuilder bufferBuilder, int i, int j, int k, + int l, int m, int n, long o, CallbackInfo ci) { + if (!MoreCulling.CONFIG.cloudCulling) { + return; + } + RenderSystem.enableCull(); + float f = (float)m * 12.0F; + float g = f + 12.0F; + float h = 0.0F; + float p = 4.0F; + float q = (float)n * 12.0F; + float r = q + 12.0F; + if (relativeCameraPos != CloudRenderer.RelativeCameraPos.BELOW_CLOUDS) { + bufferBuilder.addVertex(g, 4.0F, q).setColor(j); + bufferBuilder.addVertex(g, 4.0F, r).setColor(j); + bufferBuilder.addVertex(f, 4.0F, r).setColor(j); + bufferBuilder.addVertex(f, 4.0F, q).setColor(j); + } + + if (relativeCameraPos != CloudRenderer.RelativeCameraPos.ABOVE_CLOUDS) { + bufferBuilder.addVertex(g, 0.0F, q).setColor(i); + bufferBuilder.addVertex(g, 0.0F, r).setColor(i); + bufferBuilder.addVertex(f, 0.0F, r).setColor(i); + bufferBuilder.addVertex(f, 0.0F, q).setColor(i); + } + + if (isNorthEmpty(o) && n > 0) { + bufferBuilder.addVertex(f, 0.0F, q).setColor(l); + bufferBuilder.addVertex(f, 4.0F, q).setColor(l); + bufferBuilder.addVertex(g, 4.0F, q).setColor(l); + bufferBuilder.addVertex(g, 0.0F, q).setColor(l); + } + + if (isSouthEmpty(o) && n < 0) { + bufferBuilder.addVertex(f, 0.0F, r).setColor(l); + bufferBuilder.addVertex(f, 4.0F, r).setColor(l); + bufferBuilder.addVertex(g, 4.0F, r).setColor(l); + bufferBuilder.addVertex(g, 0.0F, r).setColor(l); + } + + if (isWestEmpty(o) && m > 0) { + bufferBuilder.addVertex(f, 0.0F, r).setColor(k); + bufferBuilder.addVertex(f, 4.0F, r).setColor(k); + bufferBuilder.addVertex(f, 4.0F, q).setColor(k); + bufferBuilder.addVertex(f, 0.0F, q).setColor(k); + } + + if (isEastEmpty(o) && m < 0) { + bufferBuilder.addVertex(g, 0.0F, r).setColor(k); + bufferBuilder.addVertex(g, 4.0F, r).setColor(k); + bufferBuilder.addVertex(g, 4.0F, q).setColor(k); + bufferBuilder.addVertex(g, 0.0F, q).setColor(k); + } + + boolean bl = Math.abs(m) <= 1 && Math.abs(n) <= 1; + if (bl) { + bufferBuilder.addVertex(g, 4.0F, q).setColor(j); + bufferBuilder.addVertex(g, 4.0F, r).setColor(j); + bufferBuilder.addVertex(f, 4.0F, r).setColor(j); + bufferBuilder.addVertex(f, 4.0F, q).setColor(j); + bufferBuilder.addVertex(f, 0.0F, q).setColor(i); + bufferBuilder.addVertex(f, 0.0F, r).setColor(i); + bufferBuilder.addVertex(g, 0.0F, r).setColor(i); + bufferBuilder.addVertex(g, 0.0F, q).setColor(i); + bufferBuilder.addVertex(g, 0.0F, q).setColor(l); + bufferBuilder.addVertex(g, 4.0F, q).setColor(l); + bufferBuilder.addVertex(f, 4.0F, q).setColor(l); + bufferBuilder.addVertex(f, 0.0F, q).setColor(l); + bufferBuilder.addVertex(f, 0.0F, r).setColor(l); + bufferBuilder.addVertex(f, 4.0F, r).setColor(l); + bufferBuilder.addVertex(g, 4.0F, r).setColor(l); + bufferBuilder.addVertex(g, 0.0F, r).setColor(l); + bufferBuilder.addVertex(f, 0.0F, q).setColor(k); + bufferBuilder.addVertex(f, 4.0F, q).setColor(k); + bufferBuilder.addVertex(f, 4.0F, r).setColor(k); + bufferBuilder.addVertex(f, 0.0F, r).setColor(k); + bufferBuilder.addVertex(g, 0.0F, r).setColor(k); + bufferBuilder.addVertex(g, 4.0F, r).setColor(k); + bufferBuilder.addVertex(g, 4.0F, q).setColor(k); + bufferBuilder.addVertex(g, 0.0F, q).setColor(k); + } + ci.cancel(); + } +} diff --git a/common/src/main/java/ca/fxco/moreculling/mixin/LevelRenderer_cloudsMixin.java b/common/src/main/java/ca/fxco/moreculling/mixin/LevelRenderer_cloudsMixin.java deleted file mode 100644 index 7b5fff03..00000000 --- a/common/src/main/java/ca/fxco/moreculling/mixin/LevelRenderer_cloudsMixin.java +++ /dev/null @@ -1,125 +0,0 @@ -package ca.fxco.moreculling.mixin; - -import ca.fxco.moreculling.MoreCulling; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.*; -import me.fallenbreath.conditionalmixin.api.annotation.Condition; -import me.fallenbreath.conditionalmixin.api.annotation.Restriction; -import net.minecraft.client.CloudStatus; -import net.minecraft.client.renderer.LevelRenderer; -import net.minecraft.util.Mth; -import net.minecraft.world.phys.Vec3; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -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.callback.CallbackInfoReturnable; - -@Restriction(conflict = { - @Condition("cullclouds"), - @Condition("extended-clouds"), - @Condition("extendedclouds") -}) -@Mixin(LevelRenderer.class) -public class LevelRenderer_cloudsMixin { - - @Unique - private static final float SCALE = 0.00390625F; - - @Shadow - @Nullable - private CloudStatus prevCloudsType; - - @Inject( - method = "buildClouds", - at = @At("HEAD"), - cancellable = true - ) - private void moreculling$renderClouds(Tesselator tesselator, double x, double y, double z, Vec3 color, CallbackInfoReturnable cir) { - if (!MoreCulling.CONFIG.cloudCulling) { - return; - } - float k = (float) Mth.floor(x) * SCALE; - float l = (float) Mth.floor(z) * SCALE; - float m = (float) color.x; - float n = (float) color.y; - float o = (float) color.z; - float p = m * 0.9F; - float q = n * 0.9F; - float r = o * 0.9F; - float s = m * 0.7F; - float t = n * 0.7F; - float u = o * 0.7F; - float v = m * 0.8F; - float w = n * 0.8F; - float aa = o * 0.8F; - BufferBuilder builder = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR_NORMAL); - float ab = (float) Math.floor(y / 4.0) * 4.0F; - if (this.prevCloudsType == CloudStatus.FANCY) { - RenderSystem.enableCull(); // Enable culling - for (int ac = -3; ac <= 4; ++ac) { - for (int ad = -3; ad <= 4; ++ad) { - float ae = (float) (ac * 8); - float af = (float) (ad * 8); - if (ab > -5.0F) { // bottom [-y] - Reversed Winding Order - builder.addVertex(ae + 0.0F, ab + 0.0F, af + 0.0F).setUv((ae + 0.0F) * SCALE + k, (af + 0.0F) * SCALE + l).setColor(s, t, u, 0.8F).setNormal(0.0F, -1.0F, 0.0F); - builder.addVertex(ae + 8.0F, ab + 0.0F, af + 0.0F).setUv((ae + 8.0F) * SCALE + k, (af + 0.0F) * SCALE + l).setColor(s, t, u, 0.8F).setNormal(0.0F, -1.0F, 0.0F); - builder.addVertex(ae + 8.0F, ab + 0.0F, af + 8.0F).setUv((ae + 8.0F) * SCALE + k, (af + 8.0F) * SCALE + l).setColor(s, t, u, 0.8F).setNormal(0.0F, -1.0F, 0.0F); - builder.addVertex(ae + 0.0F, ab + 0.0F, af + 8.0F).setUv((ae + 0.0F) * SCALE + k, (af + 8.0F) * SCALE + l).setColor(s, t, u, 0.8F).setNormal(0.0F, -1.0F, 0.0F); - } - if (ab <= 5.0F) { // top [+y] - builder.addVertex(ae + 0.0F, ab + 4.0F - 9.765625E-4F, af + 8.0F).setUv((ae + 0.0F) * SCALE + k, (af + 8.0F) * SCALE + l).setColor(m, n, o, 0.8F).setNormal(0.0F, 1.0F, 0.0F); - builder.addVertex(ae + 8.0F, ab + 4.0F - 9.765625E-4F, af + 8.0F).setUv((ae + 8.0F) * SCALE + k, (af + 8.0F) * SCALE + l).setColor(m, n, o, 0.8F).setNormal(0.0F, 1.0F, 0.0F); - builder.addVertex(ae + 8.0F, ab + 4.0F - 9.765625E-4F, af + 0.0F).setUv((ae + 8.0F) * SCALE + k, (af + 0.0F) * SCALE + l).setColor(m, n, o, 0.8F).setNormal(0.0F, 1.0F, 0.0F); - builder.addVertex(ae + 0.0F, ab + 4.0F - 9.765625E-4F, af + 0.0F).setUv((ae + 0.0F) * SCALE + k, (af + 0.0F) * SCALE + l).setColor(m, n, o, 0.8F).setNormal(0.0F, 1.0F, 0.0F); - } - int ag; - if (ac > -1) { // west [-x] - for (ag = 0; ag < 8; ++ag) { - builder.addVertex(ae + (float) ag + 0.0F, ab + 0.0F, af + 8.0F).setUv((ae + (float) ag + 0.5F) * SCALE + k, (af + 8.0F) * SCALE + l).setColor(p, q, r, 0.8F).setNormal(-1.0F, 0.0F, 0.0F); - builder.addVertex(ae + (float) ag + 0.0F, ab + 4.0F, af + 8.0F).setUv((ae + (float) ag + 0.5F) * SCALE + k, (af + 8.0F) * SCALE + l).setColor(p, q, r, 0.8F).setNormal(-1.0F, 0.0F, 0.0F); - builder.addVertex(ae + (float) ag + 0.0F, ab + 4.0F, af + 0.0F).setUv((ae + (float) ag + 0.5F) * SCALE + k, (af + 0.0F) * SCALE + l).setColor(p, q, r, 0.8F).setNormal(-1.0F, 0.0F, 0.0F); - builder.addVertex(ae + (float) ag + 0.0F, ab + 0.0F, af + 0.0F).setUv((ae + (float) ag + 0.5F) * SCALE + k, (af + 0.0F) * SCALE + l).setColor(p, q, r, 0.8F).setNormal(-1.0F, 0.0F, 0.0F); - } - } - if (ac <= 1) { // east [+x] - Reversed Winding Order - for (ag = 0; ag < 8; ++ag) { - builder.addVertex(ae + (float) ag + 1.0F - 9.765625E-4F, ab + 0.0F, af + 0.0F).setUv((ae + (float) ag + 0.5F) * SCALE + k, (af + 0.0F) * SCALE + l).setColor(p, q, r, 0.8F).setNormal(1.0F, 0.0F, 0.0F); - builder.addVertex(ae + (float) ag + 1.0F - 9.765625E-4F, ab + 4.0F, af + 0.0F).setUv((ae + (float) ag + 0.5F) * SCALE + k, (af + 0.0F) * SCALE + l).setColor(p, q, r, 0.8F).setNormal(1.0F, 0.0F, 0.0F); - builder.addVertex(ae + (float) ag + 1.0F - 9.765625E-4F, ab + 4.0F, af + 8.0F).setUv((ae + (float) ag + 0.5F) * SCALE + k, (af + 8.0F) * SCALE + l).setColor(p, q, r, 0.8F).setNormal(1.0F, 0.0F, 0.0F); - builder.addVertex(ae + (float) ag + 1.0F - 9.765625E-4F, ab + 0.0F, af + 8.0F).setUv((ae + (float) ag + 0.5F) * SCALE + k, (af + 8.0F) * SCALE + l).setColor(p, q, r, 0.8F).setNormal(1.0F, 0.0F, 0.0F); - } - } - if (ad > -1) { // north [-z] - for (ag = 0; ag < 8; ++ag) { - builder.addVertex(ae + 0.0F, ab + 4.0F, af + (float) ag + 0.0F).setUv((ae + 0.0F) * SCALE + k, (af + (float) ag + 0.5F) * SCALE + l).setColor(v, w, aa, 0.8F).setNormal(0.0F, 0.0F, -1.0F); - builder.addVertex(ae + 8.0F, ab + 4.0F, af + (float) ag + 0.0F).setUv((ae + 8.0F) * SCALE + k, (af + (float) ag + 0.5F) * SCALE + l).setColor(v, w, aa, 0.8F).setNormal(0.0F, 0.0F, -1.0F); - builder.addVertex(ae + 8.0F, ab + 0.0F, af + (float) ag + 0.0F).setUv((ae + 8.0F) * SCALE + k, (af + (float) ag + 0.5F) * SCALE + l).setColor(v, w, aa, 0.8F).setNormal(0.0F, 0.0F, -1.0F); - builder.addVertex(ae + 0.0F, ab + 0.0F, af + (float) ag + 0.0F).setUv((ae + 0.0F) * SCALE + k, (af + (float) ag + 0.5F) * SCALE + l).setColor(v, w, aa, 0.8F).setNormal(0.0F, 0.0F, -1.0F); - } - } - if (ad <= 1) { // south [+z] - Reversed Winding Order - for (ag = 0; ag < 8; ++ag) { - builder.addVertex(ae + 0.0F, ab + 0.0F, af + (float) ag + 1.0F - 9.765625E-4F).setUv((ae + 0.0F) * SCALE + k, (af + (float) ag + 0.5F) * SCALE + l).setColor(v, w, aa, 0.8F).setNormal(0.0F, 0.0F, 1.0F); - builder.addVertex(ae + 8.0F, ab + 0.0F, af + (float) ag + 1.0F - 9.765625E-4F).setUv((ae + 8.0F) * SCALE + k, (af + (float) ag + 0.5F) * SCALE + l).setColor(v, w, aa, 0.8F).setNormal(0.0F, 0.0F, 1.0F); - builder.addVertex(ae + 8.0F, ab + 4.0F, af + (float) ag + 1.0F - 9.765625E-4F).setUv((ae + 8.0F) * SCALE + k, (af + (float) ag + 0.5F) * SCALE + l).setColor(v, w, aa, 0.8F).setNormal(0.0F, 0.0F, 1.0F); - builder.addVertex(ae + 0.0F, ab + 4.0F, af + (float) ag + 1.0F - 9.765625E-4F).setUv((ae + 0.0F) * SCALE + k, (af + (float) ag + 0.5F) * SCALE + l).setColor(v, w, aa, 0.8F).setNormal(0.0F, 0.0F, 1.0F); - } - } - } - } - } else { - for (int ah = -32; ah < 32; ah += 32) { - for (int ai = -32; ai < 32; ai += 32) { - builder.addVertex(ah, ab, ai + 32).setUv((float) (ah) * SCALE + k, (float) (ai + 32) * SCALE + l).setColor(m, n, o, 0.8F).setNormal(0.0F, -1.0F, 0.0F); - builder.addVertex(ah + 32, ab, ai + 32).setUv((float) (ah + 32) * SCALE + k, (float) (ai + 32) * SCALE + l).setColor(m, n, o, 0.8F).setNormal(0.0F, -1.0F, 0.0F); - builder.addVertex(ah + 32, ab, ai).setUv((float) (ah + 32) * SCALE + k, (float) (ai) * SCALE + l).setColor(m, n, o, 0.8F).setNormal(0.0F, -1.0F, 0.0F); - builder.addVertex(ah, ab, ai).setUv((float) (ah) * SCALE + k, (float) (ai) * SCALE + l).setColor(m, n, o, 0.8F).setNormal(0.0F, -1.0F, 0.0F); - } - } - } - cir.setReturnValue(builder.buildOrThrow()); - } -} diff --git a/common/src/main/java/ca/fxco/moreculling/mixin/LevelRenderer_rainMixin.java b/common/src/main/java/ca/fxco/moreculling/mixin/LevelRenderer_rainMixin.java deleted file mode 100644 index 38abbcb5..00000000 --- a/common/src/main/java/ca/fxco/moreculling/mixin/LevelRenderer_rainMixin.java +++ /dev/null @@ -1,71 +0,0 @@ -package ca.fxco.moreculling.mixin; - -import ca.fxco.moreculling.MoreCulling; -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import com.llamalad7.mixinextras.sugar.Share; -import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef; -import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.blaze3d.vertex.Tesselator; -import net.minecraft.client.renderer.LevelRenderer; -import net.minecraft.client.renderer.LightTexture; -import net.minecraft.client.renderer.culling.Frustum; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.levelgen.Heightmap; -import net.minecraft.world.phys.AABB; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(LevelRenderer.class) -public class LevelRenderer_rainMixin { - - @Shadow - private Frustum cullingFrustum; - - @Inject( - method = "renderSnowAndRain", - locals = LocalCapture.CAPTURE_FAILSOFT, - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/level/Level;getBiome(" + - "Lnet/minecraft/core/BlockPos;)Lnet/minecraft/core/Holder;", - shift = At.Shift.BEFORE - ) - ) - private void moreculling$checkRainFrustum(LightTexture manager, float tickDelta, double cameraX, - double cameraY, double cameraZ, CallbackInfo ci, float f, Level level, - int i, int j, int k, Tesselator tessellator, - BufferBuilder bufferBuilder, int l, int m, float g, - BlockPos.MutableBlockPos mutable, - @Share("skipLoop") LocalBooleanRef skipLoopRef) { - if (!MoreCulling.CONFIG.rainCulling) { - return; - } - skipLoopRef.set(!this.cullingFrustum.isVisible(new AABB( - mutable.getX() + 1, - level.getHeight(), - mutable.getZ() + 1, - mutable.getX(), - level.getHeight(Heightmap.Types.MOTION_BLOCKING, mutable.getX(), mutable.getZ()), - mutable.getZ() - ))); - } - - @WrapOperation( - method = "renderSnowAndRain", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/level/biome/Biome;hasPrecipitation()Z" - ) - ) - private boolean moreculling$skipRainLoop(Biome instance, Operation original, - @Share("skipLoop") LocalBooleanRef skipLoopRef) { - return !skipLoopRef.get() && original.call(instance); - } -} diff --git a/common/src/main/java/ca/fxco/moreculling/mixin/Minecraft_managersMixin.java b/common/src/main/java/ca/fxco/moreculling/mixin/Minecraft_managersMixin.java index b44abae0..52ebf2b3 100644 --- a/common/src/main/java/ca/fxco/moreculling/mixin/Minecraft_managersMixin.java +++ b/common/src/main/java/ca/fxco/moreculling/mixin/Minecraft_managersMixin.java @@ -7,7 +7,8 @@ import net.minecraft.client.resources.model.ModelManager; import net.minecraft.server.packs.resources.ReloadableResourceManager; import net.minecraft.server.packs.resources.ResourceManagerReloadListener; -import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockBehaviour; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -55,6 +56,7 @@ public class Minecraft_managersMixin { MoreCulling.blockRenderManager = this.blockRenderer; // Make sure to reload block states on resource reload - this.resourceManager.registerReloadListener((ResourceManagerReloadListener) manager -> Blocks.rebuildCache()); + this.resourceManager.registerReloadListener((ResourceManagerReloadListener) manager -> + Block.BLOCK_STATE_REGISTRY.forEach(BlockBehaviour.BlockStateBase::initCache)); } } diff --git a/common/src/main/java/ca/fxco/moreculling/mixin/WeatherEffectRenderer_rainMixin.java b/common/src/main/java/ca/fxco/moreculling/mixin/WeatherEffectRenderer_rainMixin.java new file mode 100644 index 00000000..d2b3e462 --- /dev/null +++ b/common/src/main/java/ca/fxco/moreculling/mixin/WeatherEffectRenderer_rainMixin.java @@ -0,0 +1,61 @@ +package ca.fxco.moreculling.mixin; + +import ca.fxco.moreculling.MoreCulling; +import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.Share; +import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.WeatherEffectRenderer; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.levelgen.Heightmap; +import net.minecraft.world.phys.AABB; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(WeatherEffectRenderer.class) +public class WeatherEffectRenderer_rainMixin { + @Inject( + method = "getPrecipitationAt", + locals = LocalCapture.CAPTURE_FAILSOFT, + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/level/Level;getBiome(" + + "Lnet/minecraft/core/BlockPos;)Lnet/minecraft/core/Holder;", + shift = At.Shift.BEFORE + ) + ) + private void moreculling$checkRainFrustum(Level level, BlockPos mutable, CallbackInfoReturnable cir, @Share("skipLoop") LocalBooleanRef skipLoopRef) { + if (!MoreCulling.CONFIG.rainCulling) { + return; + } + skipLoopRef.set(!Minecraft.getInstance().levelRenderer.cullingFrustum.isVisible(new AABB( + mutable.getX() + 1, + level.getHeight(), + mutable.getZ() + 1, + mutable.getX(), + level.getHeight(Heightmap.Types.MOTION_BLOCKING, mutable.getX(), mutable.getZ()), + mutable.getZ() + ))); + } + + @Inject( + method = "getPrecipitationAt", + at = @At( + value = "RETURN", + ordinal = 1 + ), + cancellable = true + ) + private void moreculling$skipRainLoop(Level level, BlockPos blockPos, + CallbackInfoReturnable cir, + @Share("skipLoop") LocalBooleanRef skipLoopRef, @Local Biome biome) { + if (skipLoopRef.get() && !biome.hasPrecipitation()) { + cir.setReturnValue(Biome.Precipitation.NONE); + } + } +} diff --git a/common/src/main/java/ca/fxco/moreculling/mixin/blockentity/SignRenderer_textMixin.java b/common/src/main/java/ca/fxco/moreculling/mixin/blockentity/SignRenderer_textMixin.java index dd9cd249..0e2f1a63 100644 --- a/common/src/main/java/ca/fxco/moreculling/mixin/blockentity/SignRenderer_textMixin.java +++ b/common/src/main/java/ca/fxco/moreculling/mixin/blockentity/SignRenderer_textMixin.java @@ -79,7 +79,7 @@ public class SignRenderer_textMixin { if (state.hasProperty(WallSignBlock.FACING) && (cameraPos = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition()) != null) { Direction dir = state.getValue(WallSignBlock.FACING); - if (model instanceof SignRenderer.SignModel) { + if (model instanceof Model.Simple) { return front == !shouldHideWallSignText( dir, pos.getCenter().subtract(dir.getStepX() * 0.39, 0, dir.getStepZ() * 0.39), diff --git a/common/src/main/java/ca/fxco/moreculling/mixin/blocks/EndGatewayBlock_cullMixin.java b/common/src/main/java/ca/fxco/moreculling/mixin/blocks/EndGatewayBlock_cullMixin.java index 8e092e4b..4567292c 100644 --- a/common/src/main/java/ca/fxco/moreculling/mixin/blocks/EndGatewayBlock_cullMixin.java +++ b/common/src/main/java/ca/fxco/moreculling/mixin/blocks/EndGatewayBlock_cullMixin.java @@ -2,13 +2,10 @@ import ca.fxco.moreculling.MoreCulling; import ca.fxco.moreculling.api.block.MoreBlockCulling; -import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.BaseEntityBlock; import net.minecraft.world.level.block.EndGatewayBlock; import net.minecraft.world.level.block.RenderShape; -import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; @@ -32,7 +29,7 @@ public RenderShape getRenderShape(BlockState state) { } @Override - public VoxelShape getOcclusionShape(BlockState state, BlockGetter world, BlockPos pos) { + public VoxelShape getOcclusionShape(BlockState state) { return Shapes.block(); } } diff --git a/common/src/main/java/ca/fxco/moreculling/mixin/blocks/ShulkerBoxBlock_cullMixin.java b/common/src/main/java/ca/fxco/moreculling/mixin/blocks/ShulkerBoxBlock_cullMixin.java index 3895238f..2b82c626 100644 --- a/common/src/main/java/ca/fxco/moreculling/mixin/blocks/ShulkerBoxBlock_cullMixin.java +++ b/common/src/main/java/ca/fxco/moreculling/mixin/blocks/ShulkerBoxBlock_cullMixin.java @@ -1,13 +1,10 @@ package ca.fxco.moreculling.mixin.blocks; import ca.fxco.moreculling.api.block.MoreBlockCulling; -import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.DirectionalBlock; import net.minecraft.world.level.block.ShulkerBoxBlock; -import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; @@ -22,7 +19,7 @@ public ShulkerBoxBlock_cullMixin(Properties settings) { } @Override - public VoxelShape getOcclusionShape(BlockState state, BlockGetter world, BlockPos pos) { + public VoxelShape getOcclusionShape(BlockState state) { return Shapes.block(); } diff --git a/common/src/main/java/ca/fxco/moreculling/mixin/blocks/cullshape/BrewingStandBlock_voxelMixin.java b/common/src/main/java/ca/fxco/moreculling/mixin/blocks/cullshape/BrewingStandBlock_voxelMixin.java index 9c020f63..1a4376e5 100644 --- a/common/src/main/java/ca/fxco/moreculling/mixin/blocks/cullshape/BrewingStandBlock_voxelMixin.java +++ b/common/src/main/java/ca/fxco/moreculling/mixin/blocks/cullshape/BrewingStandBlock_voxelMixin.java @@ -1,8 +1,6 @@ package ca.fxco.moreculling.mixin.blocks.cullshape; import ca.fxco.moreculling.api.block.MoreBlockCulling; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.BaseEntityBlock; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.BrewingStandBlock; @@ -26,7 +24,7 @@ protected BrewingStandBlock_voxelMixin(Properties settings) { } @Override - public VoxelShape getOcclusionShape(BlockState state, BlockGetter level, BlockPos pos) { + public VoxelShape getOcclusionShape(BlockState state) { return moreculling$occlusionShape; } } diff --git a/common/src/main/java/ca/fxco/moreculling/mixin/blocks/cullshape/CampfireBlock_voxelMixin.java b/common/src/main/java/ca/fxco/moreculling/mixin/blocks/cullshape/CampfireBlock_voxelMixin.java index 7a7938b4..df5ebd6a 100644 --- a/common/src/main/java/ca/fxco/moreculling/mixin/blocks/cullshape/CampfireBlock_voxelMixin.java +++ b/common/src/main/java/ca/fxco/moreculling/mixin/blocks/cullshape/CampfireBlock_voxelMixin.java @@ -1,11 +1,8 @@ package ca.fxco.moreculling.mixin.blocks.cullshape; -import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.CampfireBlock; -import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; @@ -40,7 +37,7 @@ public CampfireBlock_voxelMixin(Properties settings) { } @Override - public VoxelShape getOcclusionShape(BlockState state, BlockGetter world, BlockPos pos) { + public VoxelShape getOcclusionShape(BlockState state) { return state.getValue(FACING).getAxis() == Direction.Axis.X ? moreculling$CULL_SHAPE_X : moreculling$CULL_SHAPE_Z; } diff --git a/common/src/main/java/ca/fxco/moreculling/mixin/blocks/cullshape/ChorusFlowerBlock_voxelMixin.java b/common/src/main/java/ca/fxco/moreculling/mixin/blocks/cullshape/ChorusFlowerBlock_voxelMixin.java index 0320522b..34054b09 100644 --- a/common/src/main/java/ca/fxco/moreculling/mixin/blocks/cullshape/ChorusFlowerBlock_voxelMixin.java +++ b/common/src/main/java/ca/fxco/moreculling/mixin/blocks/cullshape/ChorusFlowerBlock_voxelMixin.java @@ -1,10 +1,7 @@ package ca.fxco.moreculling.mixin.blocks.cullshape; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.ChorusFlowerBlock; -import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; @@ -26,7 +23,7 @@ public ChorusFlowerBlock_voxelMixin(Properties settings) { } @Override - public VoxelShape getOcclusionShape(BlockState state, BlockGetter world, BlockPos pos) { + public VoxelShape getOcclusionShape(BlockState state) { return moreculling$CULL_SHAPE; } } diff --git a/common/src/main/java/ca/fxco/moreculling/mixin/blockstates/Block_drawSideMixin.java b/common/src/main/java/ca/fxco/moreculling/mixin/blockstates/Block_drawSideMixin.java index 9ba41fde..0e59f1b2 100644 --- a/common/src/main/java/ca/fxco/moreculling/mixin/blockstates/Block_drawSideMixin.java +++ b/common/src/main/java/ca/fxco/moreculling/mixin/blockstates/Block_drawSideMixin.java @@ -1,22 +1,14 @@ package ca.fxco.moreculling.mixin.blockstates; -import ca.fxco.moreculling.MoreCulling; import ca.fxco.moreculling.api.block.MoreBlockCulling; -import ca.fxco.moreculling.api.blockstate.MoreStateCulling; import ca.fxco.moreculling.api.model.BakedOpacity; -import ca.fxco.moreculling.utils.CullingUtils; import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.util.RandomSource; -import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; 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.callback.CallbackInfoReturnable; import static ca.fxco.moreculling.MoreCulling.DONT_CULL; import static ca.fxco.moreculling.MoreCulling.blockRenderManager; @@ -48,22 +40,4 @@ public class Block_drawSideMixin implements MoreBlockCulling { public void moreculling$setCanCull(boolean canCull) { this.allowCulling = canCull; } - - - /** - * Many mods use Block.shouldDrawSide() directly so its basically required that we override it (using an inject) - * If your mixin breaks due to this, please use the API if MoreCulling is present - */ - @Inject( - method = "shouldRenderFace", - at = @At("HEAD"), - cancellable = true - ) - private static void moreculling$customShouldDrawSide(BlockState state, BlockGetter world, BlockPos pos, - Direction side, BlockPos otherPos, - CallbackInfoReturnable cir) { - if (MoreCulling.CONFIG.useBlockStateCulling && ((MoreStateCulling) state).moreculling$canCull()) { - cir.setReturnValue(CullingUtils.shouldDrawSideCulling(state, world, pos, side, otherPos)); - } - } } diff --git a/common/src/main/java/ca/fxco/moreculling/mixin/compat/BlockOcclusionCache_sodiumMixin.java b/common/src/main/java/ca/fxco/moreculling/mixin/compat/BlockOcclusionCache_sodiumMixin.java index 5b6156c0..5b5dde84 100644 --- a/common/src/main/java/ca/fxco/moreculling/mixin/compat/BlockOcclusionCache_sodiumMixin.java +++ b/common/src/main/java/ca/fxco/moreculling/mixin/compat/BlockOcclusionCache_sodiumMixin.java @@ -38,7 +38,7 @@ public class BlockOcclusionCache_sodiumMixin { Direction facing, CallbackInfoReturnable cir, @Local BlockPos.MutableBlockPos adjPos) { if (MoreCulling.CONFIG.useBlockStateCulling) { - cir.setReturnValue(CullingUtils.shouldDrawSideCulling(selfState, view, pos, facing, adjPos)); + cir.setReturnValue(CullingUtils.shouldDrawSideCulling(selfState, view.getBlockState(adjPos), view, pos, facing, adjPos)); } } } diff --git a/common/src/main/java/ca/fxco/moreculling/mixin/entities/ItemFrameRenderer_cullMixin.java b/common/src/main/java/ca/fxco/moreculling/mixin/entities/ItemFrameRenderer_cullMixin.java index 1133fca8..e1d9597e 100644 --- a/common/src/main/java/ca/fxco/moreculling/mixin/entities/ItemFrameRenderer_cullMixin.java +++ b/common/src/main/java/ca/fxco/moreculling/mixin/entities/ItemFrameRenderer_cullMixin.java @@ -9,6 +9,7 @@ import com.mojang.math.Axis; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.MapRenderer; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.Sheets; import net.minecraft.client.renderer.block.BlockRenderDispatcher; @@ -16,6 +17,7 @@ import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.entity.ItemFrameRenderer; import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.client.renderer.entity.state.ItemFrameRenderState; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.resources.model.ModelManager; import net.minecraft.client.resources.model.ModelResourceLocation; @@ -37,7 +39,7 @@ import static ca.fxco.moreculling.utils.CullingUtils.shouldShowMapFace; @Mixin(value = ItemFrameRenderer.class, priority = 1200) -public abstract class ItemFrameRenderer_cullMixin extends EntityRenderer { +public abstract class ItemFrameRenderer_cullMixin extends EntityRenderer { @Unique private static final Direction[] MAP_RENDER_SIDES = new Direction[]{ @@ -53,12 +55,11 @@ public abstract class ItemFrameRenderer_cullMixin extends E private ItemRenderer itemRenderer; @Shadow - protected abstract ModelResourceLocation getFrameModelResourceLoc(T entity, ItemStack stack); + protected abstract ModelResourceLocation getFrameModelResourceLoc(boolean isGlow, ItemStack stack); - @Shadow - protected abstract int getLightVal(T itemFrame, int glowLight, int regularLight); + @Shadow protected abstract int getLightVal(boolean par1, int par2, int par3); - @Shadow public abstract Vec3 getRenderOffset(T itemFrame, float f); + @Shadow @Final private MapRenderer mapRenderer; protected ItemFrameRenderer_cullMixin(EntityRendererProvider.Context ctx) { super(ctx); @@ -66,69 +67,78 @@ protected ItemFrameRenderer_cullMixin(EntityRendererProvider.Context ctx) { @Inject( - method = "render(Lnet/minecraft/world/entity/decoration/ItemFrame;" + - "FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", + method = "render(Lnet/minecraft/client/renderer/entity/state/ItemFrameRenderState;" + + "Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", at = @At( value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/EntityRenderer;render(" + - "Lnet/minecraft/world/entity/Entity;FFLcom/mojang/blaze3d/vertex/PoseStack;" + + "Lnet/minecraft/client/renderer/entity/state/EntityRenderState;" + + "Lcom/mojang/blaze3d/vertex/PoseStack;" + "Lnet/minecraft/client/renderer/MultiBufferSource;I)V", shift = At.Shift.AFTER ), cancellable = true ) - private void moreculling$optimizedRender(T itemFrameEntity, float f, float g, PoseStack poseStack, + private void moreculling$optimizedRender(ItemFrameRenderState itemFrameState, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, CallbackInfo ci) { if (!MoreCulling.CONFIG.useCustomItemFrameRenderer) { return; } ci.cancel(); poseStack.pushPose(); - Direction direction = itemFrameEntity.getDirection(); - Vec3 vec3d = this.getRenderOffset(itemFrameEntity, g); + Direction direction = itemFrameState.direction; + Vec3 vec3d = this.getRenderOffset(itemFrameState); poseStack.translate(-vec3d.x(), -vec3d.y(), -vec3d.z()); double d = 0.46875; poseStack.translate( - (double) direction.getStepX() * d, - (double) direction.getStepY() * d, - (double) direction.getStepZ() * d + (double)direction.getStepX() * d, + (double)direction.getStepY() * d, + (double)direction.getStepZ() * d ); - poseStack.mulPose(Axis.XP.rotationDegrees(itemFrameEntity.getXRot())); - poseStack.mulPose(Axis.YP.rotationDegrees(180.0f - itemFrameEntity.getYRot())); - boolean isInvisible = itemFrameEntity.isInvisible(); - ItemStack itemStack = itemFrameEntity.getItem(); + float xRot; + float yRot; + if (direction.getAxis().isHorizontal()) { + xRot = 0.0F; + yRot = 180.0F - direction.toYRot(); + } else { + xRot = (float)(-90 * direction.getAxisDirection().getStep()); + yRot = 180.0F; + } + + poseStack.mulPose(Axis.XP.rotationDegrees(xRot)); + poseStack.mulPose(Axis.YP.rotationDegrees(yRot)); + ItemStack itemStack = itemFrameState.itemStack; boolean skipFrontRender = false; if (!itemStack.isEmpty()) { poseStack.pushPose(); - MapId mapIdComponent = itemFrameEntity.getFramedMapId(itemStack); + MapId mapIdComponent = itemFrameState.mapId; if (mapIdComponent != null) { - MapItemSavedData mapState = MapItem.getSavedData(mapIdComponent, itemFrameEntity.level()); + MapItemSavedData mapState = MapItem.getSavedData(mapIdComponent, Minecraft.getInstance().level); if (mapState != null) { // Map is present - if (shouldShowMapFace(direction, itemFrameEntity.position(), + if (shouldShowMapFace(direction, itemFrameState, this.entityRenderDispatcher.camera.getPosition())) { skipFrontRender = !((MapOpacity) mapState).moreculling$hasTransparency(); double di; - double offsetZFighting = isInvisible ? 0.5 : + double offsetZFighting = itemFrameState.isInvisible ? 0.5 : skipFrontRender ? - ((di = this.entityRenderDispatcher.distanceToSqr(itemFrameEntity) / 5000) > 6 ? + ((di = this.entityRenderDispatcher.distanceToSqr(itemFrameState.x, itemFrameState.y - 1, itemFrameState.z) / 5000) > 6 ? Math.max(0.4452 - di, 0.4) : 0.4452) : 0.4375; poseStack.translate(0.0, 0.0, offsetZFighting); - int j = itemFrameEntity.getRotation() % 4 * 2; + int j = itemFrameState.rotation % 4 * 2; poseStack.mulPose(Axis.ZP.rotationDegrees((float) j * 360.0f / 8.0f)); poseStack.mulPose(Axis.ZP.rotationDegrees(180.0f)); float h = 0.0078125f; poseStack.scale(h, h, h); poseStack.translate(-64.0, -64.0, 0.0); poseStack.translate(0.0, 0.0, -1.0); - Minecraft.getInstance().gameRenderer.getMapRenderer().render( + mapRenderer.render( + itemFrameState.mapRenderState, poseStack, multiBufferSource, - mapIdComponent, - mapState, true, this.getLightVal( - itemFrameEntity, + itemFrameState.isGlowFrame, LightTexture.FULL_SKY | 0xD2, i ) @@ -136,11 +146,11 @@ protected ItemFrameRenderer_cullMixin(EntityRendererProvider.Context ctx) { } } } else { - poseStack.translate(0.0, 0.0, isInvisible ? 0.5 : 0.4375); + poseStack.translate(0.0, 0.0, itemFrameState.isInvisible ? 0.5 : 0.4375); poseStack.mulPose(Axis.ZP.rotationDegrees( - (float) itemFrameEntity.getRotation() * 360.0f / 8.0f) + (float) itemFrameState.rotation * 360.0f / 8.0f) ); - int l = this.getLightVal(itemFrameEntity, LightTexture.FULL_BRIGHT, i); + int l = this.getLightVal(itemFrameState.isGlowFrame, LightTexture.FULL_BRIGHT, i); poseStack.scale(0.5f, 0.5f, 0.5f); // Use extended item renderer here ((ExtendedItemRenderer) this.itemRenderer).moreculling$renderItemFrameItem( @@ -148,18 +158,18 @@ protected ItemFrameRenderer_cullMixin(EntityRendererProvider.Context ctx) { poseStack, multiBufferSource, l, - itemFrameEntity, + itemFrameState, this.entityRenderDispatcher.camera ); } poseStack.popPose(); } - if (!isInvisible) { // Render Item Frame block model + if (!itemFrameState.isInvisible) { // Render Item Frame block model ModelManager modelManager = this.blockRenderer.getBlockModelShaper().getModelManager(); - ModelResourceLocation modelResourceLocation = this.getFrameModelResourceLoc(itemFrameEntity, itemStack); + ModelResourceLocation modelResourceLocation = this.getFrameModelResourceLoc(itemFrameState.isGlowFrame, itemStack); poseStack.translate(-0.5, -0.5, -0.5); var modelRenderer = (ExtendedBlockModelRenderer) this.blockRenderer.getModelRenderer(); - if (CullingUtils.shouldCullBack(itemFrameEntity)) { + if (CullingUtils.shouldCullBack(itemFrameState)) { if (skipFrontRender) { modelRenderer.moreculling$renderModelForFaces( poseStack.last(), diff --git a/common/src/main/java/ca/fxco/moreculling/mixin/models/BuiltInModel_cacheMixin.java b/common/src/main/java/ca/fxco/moreculling/mixin/models/BuiltInModel_cacheMixin.java index 095b97be..001c59ea 100644 --- a/common/src/main/java/ca/fxco/moreculling/mixin/models/BuiltInModel_cacheMixin.java +++ b/common/src/main/java/ca/fxco/moreculling/mixin/models/BuiltInModel_cacheMixin.java @@ -2,7 +2,6 @@ import ca.fxco.moreculling.api.model.BakedOpacity; import ca.fxco.moreculling.api.sprite.SpriteOpacity; -import net.minecraft.client.renderer.block.model.ItemOverrides; import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.BuiltInModel; @@ -59,8 +58,8 @@ public abstract class BuiltInModel_cacheMixin implements BakedOpacity { method = "", at = @At("RETURN") ) - private void moreculling$onInit(ItemTransforms transformation, ItemOverrides itemPropertyOverrides, - TextureAtlasSprite sprite, boolean sideLit, CallbackInfo ci) { + private void moreculling$onInit(ItemTransforms transformation, TextureAtlasSprite sprite, + boolean sideLit, CallbackInfo ci) { moreculling$resetTranslucencyCache(); } } diff --git a/common/src/main/java/ca/fxco/moreculling/mixin/models/cullshape/BlockModel_cullShapeMixin.java b/common/src/main/java/ca/fxco/moreculling/mixin/models/cullshape/BlockModel_cullShapeMixin.java index 134e41eb..9b8623c8 100644 --- a/common/src/main/java/ca/fxco/moreculling/mixin/models/cullshape/BlockModel_cullShapeMixin.java +++ b/common/src/main/java/ca/fxco/moreculling/mixin/models/cullshape/BlockModel_cullShapeMixin.java @@ -12,7 +12,6 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.client.resources.model.Material; -import net.minecraft.client.resources.model.ModelBaker; import net.minecraft.client.resources.model.ModelState; import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; @@ -90,10 +89,9 @@ public abstract class BlockModel_cullShapeMixin implements ExtendedUnbakedModel } @Redirect( - method = {"bake(Lnet/minecraft/client/resources/model/ModelBaker;" + - "Lnet/minecraft/client/renderer/block/model/BlockModel;Ljava/util/function/Function;" + - "Lnet/minecraft/client/resources/model/ModelState;Z)" + - "Lnet/minecraft/client/resources/model/BakedModel;", "bakeVanilla"}, + method = {"bake(Ljava/util/function/Function;" + + "Lnet/minecraft/client/resources/model/ModelState;" + + "Z)Lnet/minecraft/client/resources/model/BakedModel;"}, at = @At( value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;" @@ -104,17 +102,15 @@ public abstract class BlockModel_cullShapeMixin implements ExtendedUnbakedModel } @Inject( - method = "bake(Lnet/minecraft/client/resources/model/ModelBaker;" + - "Lnet/minecraft/client/renderer/block/model/BlockModel;Ljava/util/function/Function;" + - "Lnet/minecraft/client/resources/model/ModelState;Z)" + - "Lnet/minecraft/client/resources/model/BakedModel;", + method = "bake(Ljava/util/function/Function;" + + "Lnet/minecraft/client/resources/model/ModelState;" + + "Z)Lnet/minecraft/client/resources/model/BakedModel;", at = @At( value = "RETURN", shift = At.Shift.BEFORE ) ) - private void moreculling$onBake(ModelBaker baker, BlockModel parent, - Function textureGetter, ModelState settings, + private void moreculling$onBake(Function textureGetter, ModelState settings, boolean hasDepth, CallbackInfoReturnable cir) { BakedModel bakedModel = cir.getReturnValue(); if (bakedModel == null) { diff --git a/common/src/main/java/ca/fxco/moreculling/mixin/models/cullshape/Cache_cullShapeMixin.java b/common/src/main/java/ca/fxco/moreculling/mixin/models/cullshape/BlockStateBase_cullShapeMixin.java similarity index 70% rename from common/src/main/java/ca/fxco/moreculling/mixin/models/cullshape/Cache_cullShapeMixin.java rename to common/src/main/java/ca/fxco/moreculling/mixin/models/cullshape/BlockStateBase_cullShapeMixin.java index 70ae8d36..954a7356 100644 --- a/common/src/main/java/ca/fxco/moreculling/mixin/models/cullshape/Cache_cullShapeMixin.java +++ b/common/src/main/java/ca/fxco/moreculling/mixin/models/cullshape/BlockStateBase_cullShapeMixin.java @@ -2,9 +2,8 @@ import ca.fxco.moreculling.api.model.BakedOpacity; import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.shapes.VoxelShape; import org.spongepowered.asm.mixin.Mixin; @@ -13,17 +12,18 @@ import static ca.fxco.moreculling.MoreCulling.blockRenderManager; -@Mixin(targets = "net/minecraft/world/level/block/state/BlockBehaviour$BlockStateBase$Cache") -public class Cache_cullShapeMixin { +@Mixin(BlockBehaviour.BlockStateBase.class) +public class BlockStateBase_cullShapeMixin { @Redirect( - method = "", + method = "initCache", at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/level/block/state/BlockState;canOcclude()Z" + value = "FIELD", + target = "Lnet/minecraft/world/level/block/state/BlockBehaviour$BlockStateBase;canOcclude:Z" ) ) - private boolean moreculling$shouldDoShapeCache(BlockState state) { + private boolean moreculling$shouldDoShapeCache(BlockBehaviour.BlockStateBase instance) { + BlockState state = (BlockState) instance; if (blockRenderManager != null) { BakedModel model = blockRenderManager.getBlockModel(state); if (model != null && ((BakedOpacity) model).moreculling$getCullingShape(state) != null) { @@ -34,17 +34,15 @@ public class Cache_cullShapeMixin { } @Redirect( - method = "", + method = "initCache", at = @At( value = "INVOKE", target = "Lnet/minecraft/world/level/block/Block;getOcclusionShape(" + - "Lnet/minecraft/world/level/block/state/BlockState;" + - "Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)" + + "Lnet/minecraft/world/level/block/state/BlockState;)" + "Lnet/minecraft/world/phys/shapes/VoxelShape;" ) ) - private VoxelShape moreculling$customCullingShape(Block instance, BlockState state, BlockGetter BlockGetter, - BlockPos blockPos) { + private VoxelShape moreculling$customCullingShape(Block instance, BlockState state) { if (blockRenderManager != null) { BakedModel model = blockRenderManager.getBlockModel(state); if (model != null) { @@ -54,6 +52,6 @@ public class Cache_cullShapeMixin { } } } - return instance.getOcclusionShape(state, BlockGetter, blockPos); + return instance.getOcclusionShape(state); } } diff --git a/common/src/main/java/ca/fxco/moreculling/mixin/renderers/ItemRenderer_apiMixin.java b/common/src/main/java/ca/fxco/moreculling/mixin/renderers/ItemRenderer_apiMixin.java index dacacb6f..28256db8 100644 --- a/common/src/main/java/ca/fxco/moreculling/mixin/renderers/ItemRenderer_apiMixin.java +++ b/common/src/main/java/ca/fxco/moreculling/mixin/renderers/ItemRenderer_apiMixin.java @@ -8,13 +8,12 @@ import net.minecraft.client.Camera; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.client.renderer.entity.state.ItemFrameRenderState; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.Direction; -import net.minecraft.world.entity.decoration.ItemFrame; import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -25,9 +24,9 @@ public abstract class ItemRenderer_apiMixin implements ExtendedItemRenderer { @Shadow protected abstract void renderModelLists(BakedModel model, ItemStack stack, int light, int overlay, PoseStack poseStack, VertexConsumer vertices); - @Shadow public abstract void renderStatic(ItemStack stack, ItemDisplayContext itemDisplayContext, int light, - int overlay, PoseStack poseStack, MultiBufferSource multiBufferSource, - @Nullable Level level, int seed); + @Shadow public abstract void render(ItemStack itemStack, ItemDisplayContext displayContext, boolean leftHand, + PoseStack poseStack, MultiBufferSource bufferSource, int combinedLight, + int combinedOverlay, BakedModel model); @Override public void moreculling$renderBakedItemModelWithoutFace(BakedModel model, ItemStack stack, int light, int overlay, @@ -59,11 +58,11 @@ public abstract class ItemRenderer_apiMixin implements ExtendedItemRenderer { @Override public void moreculling$renderItemFrameItem(ItemStack stack, PoseStack pose, MultiBufferSource multiBufferSource, - int light, ItemFrame frame, Camera camera) { + int light, ItemFrameRenderState frame, Camera camera) { ItemRendererStates.ITEM_FRAME = frame; ItemRendererStates.CAMERA = camera; - this.renderStatic(stack, ItemDisplayContext.FIXED, light, OverlayTexture.NO_OVERLAY, pose, - multiBufferSource, frame.level(), frame.getId()); + this.render(stack, ItemDisplayContext.FIXED, false, pose, + multiBufferSource, light, OverlayTexture.NO_OVERLAY, frame.itemModel); ItemRendererStates.ITEM_FRAME = null; ItemRendererStates.CAMERA = null; } diff --git a/common/src/main/java/ca/fxco/moreculling/mixin/renderers/ModelBlockRenderer_cullMixin.java b/common/src/main/java/ca/fxco/moreculling/mixin/renderers/ModelBlockRenderer_cullMixin.java index fba3c78f..9f3843ee 100644 --- a/common/src/main/java/ca/fxco/moreculling/mixin/renderers/ModelBlockRenderer_cullMixin.java +++ b/common/src/main/java/ca/fxco/moreculling/mixin/renderers/ModelBlockRenderer_cullMixin.java @@ -28,7 +28,7 @@ public abstract class ModelBlockRenderer_cullMixin implements ExtendedBlockModel @Shadow @Final - private static Direction[] DIRECTIONS; + static Direction[] DIRECTIONS; @Override public void moreculling$renderQuad(PoseStack.Pose pose, VertexConsumer vertices, float red, float green, diff --git a/common/src/main/java/ca/fxco/moreculling/states/ItemRendererStates.java b/common/src/main/java/ca/fxco/moreculling/states/ItemRendererStates.java index f1ca0b36..a9e0c51d 100644 --- a/common/src/main/java/ca/fxco/moreculling/states/ItemRendererStates.java +++ b/common/src/main/java/ca/fxco/moreculling/states/ItemRendererStates.java @@ -1,8 +1,8 @@ package ca.fxco.moreculling.states; import net.minecraft.client.Camera; +import net.minecraft.client.renderer.entity.state.ItemFrameRenderState; import net.minecraft.core.Direction; -import net.minecraft.world.entity.decoration.ItemFrame; import org.jetbrains.annotations.Nullable; /** @@ -12,7 +12,7 @@ */ public class ItemRendererStates { - public static @Nullable ItemFrame ITEM_FRAME; + public static @Nullable ItemFrameRenderState ITEM_FRAME; public static Camera CAMERA; public static Direction[] DIRECTIONS; } diff --git a/common/src/main/java/ca/fxco/moreculling/utils/CullingUtils.java b/common/src/main/java/ca/fxco/moreculling/utils/CullingUtils.java index 037f54a5..d97df0f9 100644 --- a/common/src/main/java/ca/fxco/moreculling/utils/CullingUtils.java +++ b/common/src/main/java/ca/fxco/moreculling/utils/CullingUtils.java @@ -6,10 +6,10 @@ import net.caffeinemc.mods.sodium.client.SodiumClientMod; import net.minecraft.client.GraphicsStatus; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.entity.state.ItemFrameRenderState; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.util.RandomSource; -import net.minecraft.world.entity.decoration.ItemFrame; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.LeavesBlock; @@ -29,10 +29,9 @@ public class CullingUtils { /** * Replaces the default vanilla culling with a custom implementation */ - public static boolean shouldDrawSideCulling(BlockState thisState, + public static boolean shouldDrawSideCulling(BlockState thisState, BlockState sideState, BlockGetter world, BlockPos thisPos, Direction side, BlockPos sidePos) { - BlockState sideState = world.getBlockState(sidePos); if (thisState.skipRendering(sideState, side)) { return false; } @@ -61,28 +60,34 @@ private static boolean shouldDrawFace(BlockGetter world, BlockState thisState, B if (((MoreStateCulling) sideState).moreculling$cantCullAgainst(side)) { return true; // Check if we can cull against this block } - Block.BlockStatePairKey statePairKey = new Block.BlockStatePairKey(thisState, sideState, side); - Object2ByteLinkedOpenHashMap object2ByteLinkedOpenHashMap = Block.OCCLUSION_CACHE.get(); - byte b = object2ByteLinkedOpenHashMap.getAndMoveToFirst(statePairKey); + Direction opposite = side.getOpposite(); + VoxelShape thisShape = thisState.getFaceOcclusionShape(side); + if (thisShape.isEmpty()) //vanilla 1.21.2 will just return empty if block cant occlude instead of its shape + thisShape = thisState.getBlock().getOcclusionShape(thisState).getFaceShape(side); + VoxelShape sideShape = sideState.getFaceOcclusionShape(opposite); + if (sideShape.isEmpty()) + sideShape = sideState.getBlock().getOcclusionShape(sideState).getFaceShape(opposite); + + Block.ShapePairKey shapePairKey = new Block.ShapePairKey( + thisShape, + sideShape + ); + Object2ByteLinkedOpenHashMap object2ByteLinkedOpenHashMap = Block.OCCLUSION_CACHE.get(); + byte b = object2ByteLinkedOpenHashMap.getAndMoveToFirst(shapePairKey); if (b != 127) { return b != 0; } - Direction opposite = side.getOpposite(); - VoxelShape thisShape = thisState.getFaceOcclusionShape(world, thisPos, side); - VoxelShape sideShape; // Culling face may not be required, so we can save performance by skipping it if (thisShape.isEmpty()) { // It this shape is empty if (!sideState.isFaceSturdy(world, sidePos, opposite) || - (sideShape = sideState.getFaceOcclusionShape(world, sidePos, opposite)).isEmpty()) { + sideShape.isEmpty()) { return true; // Face should be drawn if the side face is not a full square or its empty } - } else { - sideShape = sideState.getFaceOcclusionShape(world, sidePos, opposite); } boolean bl = Shapes.joinIsNotEmpty(thisShape, sideShape, BooleanOp.ONLY_FIRST); - if (object2ByteLinkedOpenHashMap.size() == 2048) { + if (object2ByteLinkedOpenHashMap.size() == 256) { object2ByteLinkedOpenHashMap.removeLastByte(); } - object2ByteLinkedOpenHashMap.putAndMoveToFirst(statePairKey, (byte) (bl ? 1 : 0)); + object2ByteLinkedOpenHashMap.putAndMoveToFirst(shapePairKey, (byte) (bl ? 1 : 0)); return bl; } @@ -154,14 +159,14 @@ public static Optional shouldDrawFaceRandom(BlockGetter view, BlockStat return Optional.of(true); } - public static boolean shouldCullBack(ItemFrame frame) { - Direction dir = frame.getDirection(); - BlockPos posBehind = frame.getPos().relative(dir.getOpposite()); - BlockState blockState = frame.level().getBlockState(posBehind); - return blockState.canOcclude() && blockState.isFaceSturdy(frame.level(), posBehind, dir); + public static boolean shouldCullBack(ItemFrameRenderState frame) { + Direction dir = frame.direction; + BlockPos posBehind = new BlockPos((int) frame.x, (int) frame.y - 1, (int) frame.z) .relative(dir.getOpposite()); + BlockState blockState = Minecraft.getInstance().level.getBlockState(posBehind); + return blockState.canOcclude() && blockState.isFaceSturdy(Minecraft.getInstance().level, posBehind, dir); } - public static boolean shouldShowMapFace(Direction facingDir, Vec3 framePos, Vec3 cameraPos) { + public static boolean shouldShowMapFace(Direction facingDir, ItemFrameRenderState framePos, Vec3 cameraPos) { if (MoreCulling.CONFIG.itemFrameMapCulling) { return switch (facingDir) { case DOWN -> cameraPos.y <= framePos.y; diff --git a/common/src/main/resources/META-INF/accesstransformer.cfg b/common/src/main/resources/META-INF/accesstransformer.cfg index 22caef9c..e621f684 100644 --- a/common/src/main/resources/META-INF/accesstransformer.cfg +++ b/common/src/main/resources/META-INF/accesstransformer.cfg @@ -2,11 +2,16 @@ public net.minecraft.world.level.block.Block OCCLUSION_CACHE public net.minecraft.client.model.geom.ModelPart$Polygon public net.minecraft.client.renderer.block.model.BlockModel parentLocation public net.minecraft.client.model.geom.ModelPart$Vertex -public net.minecraft.world.level.block.state.BlockBehaviour getOcclusionShape(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/phys/shapes/VoxelShape; -public net.minecraft.world.level.block.SkullBlock getOcclusionShape(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/phys/shapes/VoxelShape; -public net.minecraft.world.level.block.FenceBlock getOcclusionShape(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/phys/shapes/VoxelShape; -public net.minecraft.world.level.block.FenceGateBlock getOcclusionShape(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/phys/shapes/VoxelShape; -public net.minecraft.world.level.block.LecternBlock getOcclusionShape(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/phys/shapes/VoxelShape; -public net.minecraft.world.level.block.PointedDripstoneBlock getOcclusionShape(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/phys/shapes/VoxelShape; -public net.minecraft.world.level.block.PowderSnowBlock getOcclusionShape(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/phys/shapes/VoxelShape; -public net.minecraft.world.level.block.SculkShriekerBlock getOcclusionShape(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/phys/shapes/VoxelShape; +public net.minecraft.world.level.block.Block$ShapePairKey +public net.minecraft.world.level.block.Block$ShapePairKey (Lnet.minecraft.world.phys.shapes.VoxelShape;Lnet.minecraft.world.phys.shapes.VoxelShape;)V +public net.minecraft.client.renderer.LevelRenderer cullingFrustum +public net.minecraft.client.renderer.CloudRenderer$RelativeCameraPos + +public net.minecraft.world.level.block.state.BlockBehaviour getOcclusionShape(Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/phys/shapes/VoxelShape; +public net.minecraft.world.level.block.SkullBlock getOcclusionShape(Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/phys/shapes/VoxelShape; +public net.minecraft.world.level.block.SculkShriekerBlock getOcclusionShape(Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/phys/shapes/VoxelShape; +public net.minecraft.world.level.block.PointedDripstoneBlock getOcclusionShape(Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/phys/shapes/VoxelShape; +public net.minecraft.world.level.block.MossyCarpetBlock getOcclusionShape(Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/phys/shapes/VoxelShape; +public net.minecraft.world.level.block.LecternBlock getOcclusionShape(Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/phys/shapes/VoxelShape; +public net.minecraft.world.level.block.FenceGateBlock getOcclusionShape(Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/phys/shapes/VoxelShape; +public net.minecraft.world.level.block.FenceBlock getOcclusionShape(Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/phys/shapes/VoxelShape; diff --git a/common/src/main/resources/moreculling.accesswidener b/common/src/main/resources/moreculling.accesswidener index 89d65055..ce506964 100644 --- a/common/src/main/resources/moreculling.accesswidener +++ b/common/src/main/resources/moreculling.accesswidener @@ -1,4 +1,8 @@ accessWidener v1 named accessible field net/minecraft/world/level/block/Block OCCLUSION_CACHE Ljava/lang/ThreadLocal; -accessible method net/minecraft/world/level/block/state/BlockBehaviour getOcclusionShape (Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/phys/shapes/VoxelShape; -accessible field net/minecraft/client/renderer/block/model/BlockModel parentLocation Lnet/minecraft/resources/ResourceLocation; \ No newline at end of file +accessible method net/minecraft/world/level/block/state/BlockBehaviour getOcclusionShape (Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/phys/shapes/VoxelShape; +accessible field net/minecraft/client/renderer/block/model/BlockModel parentLocation Lnet/minecraft/resources/ResourceLocation; +accessible field net/minecraft/client/renderer/LevelRenderer cullingFrustum Lnet/minecraft/client/renderer/culling/Frustum; +accessible class net/minecraft/client/renderer/CloudRenderer$RelativeCameraPos +accessible class net/minecraft/world/level/block/Block$ShapePairKey +accessible method net/minecraft/world/level/block/Block$ShapePairKey (Lnet/minecraft/world/phys/shapes/VoxelShape;Lnet/minecraft/world/phys/shapes/VoxelShape;)V \ No newline at end of file diff --git a/common/src/main/resources/moreculling.mixins.json b/common/src/main/resources/moreculling.mixins.json index 92521d62..545c7160 100644 --- a/common/src/main/resources/moreculling.mixins.json +++ b/common/src/main/resources/moreculling.mixins.json @@ -10,8 +10,8 @@ "MapItemSavedData_cacheMixin", "Minecraft_managersMixin", "TextureAtlasSprite_opacityMixin", - "LevelRenderer_cloudsMixin", - "LevelRenderer_rainMixin", + "CloudRenderer_cloudsMixin", + "WeatherEffectRenderer_rainMixin", "accessors.BlockModelShaperAccessor", "accessors.SpriteContentsAccessor", "accessors.LevelRendererAccessor", @@ -43,7 +43,7 @@ "models.BuiltInModel_cacheMixin", "models.cullshape.Deserializer_cullShapeMixin", "models.cullshape.BlockModel_cullShapeMixin", - "models.cullshape.Cache_cullShapeMixin", + "models.cullshape.BlockStateBase_cullShapeMixin", "renderers.ModelBlockRenderer_cullMixin", "renderers.ItemRenderer_apiMixin", "renderers.ItemRenderer_faceCullingMixin" diff --git a/fabric/build.gradle b/fabric/build.gradle index df9c714d..661af81d 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -11,10 +11,12 @@ dependencies { modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}" - modImplementation "maven.modrinth:modmenu:${project.modmenu_version}" - modImplementation "maven.modrinth:sodium:${project.sodium_version}-fabric" + modCompileOnly "maven.modrinth:modmenu:${project.modmenu_version}" + modCompileOnly "maven.modrinth:sodium:${project.sodium_version}-fabric" // ^ Change to `modCompileOnly` to test without sodium - modImplementation "me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}" + modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") { + exclude(group: "net.fabricmc.fabric-api") + } modImplementation("me.fallenbreath:conditional-mixin-fabric:${project.conditional_mixins_version}") include("me.fallenbreath:conditional-mixin-fabric:${project.conditional_mixins_version}") diff --git a/fabric/src/main/java/ca/fxco/moreculling/mixin/blockstates/Block_fabricDrawSideMixin.java b/fabric/src/main/java/ca/fxco/moreculling/mixin/blockstates/Block_fabricDrawSideMixin.java new file mode 100644 index 00000000..c384ff37 --- /dev/null +++ b/fabric/src/main/java/ca/fxco/moreculling/mixin/blockstates/Block_fabricDrawSideMixin.java @@ -0,0 +1,42 @@ +package ca.fxco.moreculling.mixin.blockstates; + +import ca.fxco.moreculling.MoreCulling; +import ca.fxco.moreculling.api.block.MoreBlockCulling; +import ca.fxco.moreculling.api.blockstate.MoreStateCulling; +import ca.fxco.moreculling.api.model.BakedOpacity; +import ca.fxco.moreculling.utils.CullingUtils; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.util.RandomSource; +import net.minecraft.world.level.EmptyBlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +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.callback.CallbackInfoReturnable; + +import static ca.fxco.moreculling.MoreCulling.DONT_CULL; +import static ca.fxco.moreculling.MoreCulling.blockRenderManager; + +@Mixin(value = Block.class, priority = 2500) +public class Block_fabricDrawSideMixin implements MoreBlockCulling { + /** + * Many mods use Block.shouldDrawSide() directly so its basically required that we override it (using an inject) + * If your mixin breaks due to this, please use the API if MoreCulling is present + */ + @Inject( + method = "shouldRenderFace", + at = @At("HEAD"), + cancellable = true + ) + private static void moreculling$customShouldDrawSide(BlockState thisState, BlockState sideState, + Direction side, CallbackInfoReturnable cir) { + if (MoreCulling.CONFIG.useBlockStateCulling && ((MoreStateCulling) thisState).moreculling$canCull()) { + cir.setReturnValue(CullingUtils.shouldDrawSideCulling(thisState, sideState, + EmptyBlockGetter.INSTANCE, BlockPos.ZERO, side, BlockPos.ZERO)); + } + } +} diff --git a/fabric/src/main/java/ca/fxco/moreculling/mixin/models/MultiPartBakedModel_cacheMixin.java b/fabric/src/main/java/ca/fxco/moreculling/mixin/models/MultiPartBakedModel_cacheMixin.java index ffa26f70..fc6a0bc2 100644 --- a/fabric/src/main/java/ca/fxco/moreculling/mixin/models/MultiPartBakedModel_cacheMixin.java +++ b/fabric/src/main/java/ca/fxco/moreculling/mixin/models/MultiPartBakedModel_cacheMixin.java @@ -31,7 +31,7 @@ public abstract class MultiPartBakedModel_cacheMixin implements BakedOpacity { @Shadow @Final - private List, BakedModel>> selectors; + private List selectors; @Unique // Only works on chunk update, so the best performance is after placing a block private byte solidFaces = 0; // 0 = all sides translucent @@ -52,9 +52,9 @@ public abstract class MultiPartBakedModel_cacheMixin implements BakedOpacity { @Override public @Nullable VoxelShape moreculling$getCullingShape(BlockState state) { VoxelShape cachedShape = null; - for (Pair, BakedModel> pair : this.selectors) { - if ((pair.getLeft()).test(state)) { - VoxelShape shape = ((BakedOpacity) pair.getRight()).moreculling$getCullingShape(state); + for (MultiPartBakedModel.Selector selector : this.selectors) { + if ((selector.condition()).test(state)) { + VoxelShape shape = ((BakedOpacity) selector.model()).moreculling$getCullingShape(state); if (shape != null) { if (cachedShape == null) { cachedShape = shape; diff --git a/fabric/src/main/java/ca/fxco/moreculling/mixin/models/SimpleBakedModel_fabricCacheMixin.java b/fabric/src/main/java/ca/fxco/moreculling/mixin/models/SimpleBakedModel_fabricCacheMixin.java index f6860d57..58c43a26 100644 --- a/fabric/src/main/java/ca/fxco/moreculling/mixin/models/SimpleBakedModel_fabricCacheMixin.java +++ b/fabric/src/main/java/ca/fxco/moreculling/mixin/models/SimpleBakedModel_fabricCacheMixin.java @@ -1,12 +1,9 @@ package ca.fxco.moreculling.mixin.models; import ca.fxco.moreculling.api.model.BakedOpacity; -import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.client.renderer.block.model.ItemOverrides; import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.SimpleBakedModel; -import net.minecraft.core.Direction; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -21,10 +18,9 @@ public abstract class SimpleBakedModel_fabricCacheMixin implements BakedOpacity method = "", at = @At("RETURN") ) - private void moreculling$onInit(List quads, Map> faceQuads, boolean usesAo, - boolean isSideLit, boolean hasDepth, TextureAtlasSprite sprite, - ItemTransforms transformation, ItemOverrides itemOverrides, - CallbackInfo ci) { + private void moreculling$onInit(List list, Map map, boolean bl, boolean bl2, boolean bl3, + TextureAtlasSprite textureAtlasSprite, + ItemTransforms itemTransforms, CallbackInfo ci) { moreculling$resetTranslucencyCache(); } } diff --git a/fabric/src/main/java/ca/fxco/moreculling/mixin/renderers/ItemRenderer_fabricFaceCullingMixin.java b/fabric/src/main/java/ca/fxco/moreculling/mixin/renderers/ItemRenderer_fabricFaceCullingMixin.java index 6960352e..6aa495e0 100644 --- a/fabric/src/main/java/ca/fxco/moreculling/mixin/renderers/ItemRenderer_fabricFaceCullingMixin.java +++ b/fabric/src/main/java/ca/fxco/moreculling/mixin/renderers/ItemRenderer_fabricFaceCullingMixin.java @@ -14,9 +14,9 @@ import net.minecraft.client.renderer.block.model.ItemTransform; import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.client.renderer.entity.state.ItemFrameRenderState; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.Direction; -import net.minecraft.world.entity.decoration.ItemFrame; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; @@ -34,7 +34,7 @@ public class ItemRenderer_fabricFaceCullingMixin { @WrapOperation( - method = "render", + method = "renderItemModelRaw", at = @At( value = "INVOKE", target = "Lnet/minecraft/client/renderer/block/model/ItemTransforms;getTransform(" + @@ -54,7 +54,7 @@ public class ItemRenderer_fabricFaceCullingMixin { } @Inject( - method = "render", + method = "renderItem", at = @At( value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/ItemRenderer;renderModelLists(" + @@ -64,20 +64,21 @@ public class ItemRenderer_fabricFaceCullingMixin { ) ) private void moreculling$faceRemoval(ItemStack stack, ItemDisplayContext displayContext, - boolean leftHanded, PoseStack poseStack, - MultiBufferSource multiBufferSource, int light, int overlay, - BakedModel model, CallbackInfo ci, + PoseStack poseStack, MultiBufferSource multiBufferSource, int light, int overlay, + BakedModel model, boolean bl, CallbackInfo ci, @Share("transformation") LocalRef transformationRef) { - ItemFrame frame = ItemRendererStates.ITEM_FRAME; + ItemFrameRenderState frame = ItemRendererStates.ITEM_FRAME; if (frame == null) { ItemRendererStates.DIRECTIONS = null; return; } Vec3 cameraPos = ItemRendererStates.CAMERA.getPosition(); - Vec3 framePos = frame.position(); + Vec3 framePos = new Vec3(frame.x, frame.y, frame.z) ; boolean isBlockItem = stack.getItem() instanceof BlockItem; ItemTransform transformation = transformationRef.get(); - boolean canCull = ((!isBlockItem && !frame.isInvisible()) || CullingUtils.shouldCullBack(frame)) && + if (transformation == null) + return; + boolean canCull = ((!isBlockItem && !frame.isInvisible) || CullingUtils.shouldCullBack(frame)) && TransformationUtils.canCullTransformation(transformation); double dist = ItemRendererStates.CAMERA.getPosition().distanceTo(framePos); // Make blocks use LOD - If more than range, only render the front and maybe back if it can't cull @@ -95,13 +96,13 @@ public class ItemRenderer_fabricFaceCullingMixin { // TODO: Add model rotation logic (items need this!) Currently we only support blocks and some models if (MoreCulling.CONFIG.useItemFrame3FaceCulling && dist > MoreCulling.CONFIG.itemFrame3FaceCullingRange && - frame.getRotation() % 2 == 0 && + frame.rotation % 2 == 0 && transformation.rotation.y() == 0 && transformation.rotation.x() == 0 && transformation.rotation.z() == 0 ) { - int rotation = frame.getRotation() * 45; - Direction facing = frame.getDirection(); + int rotation = frame.rotation * 45; + Direction facing = frame.direction; Direction dirX = shiftDirection(facing, cameraPos.x > framePos.x ? Direction.EAST : Direction.WEST, rotation); Direction dirY = shiftDirection(facing, diff --git a/fabric/src/main/resources/moreculling.fabric.mixins.json b/fabric/src/main/resources/moreculling.fabric.mixins.json index 8dc766f4..e3b1a1fb 100644 --- a/fabric/src/main/resources/moreculling.fabric.mixins.json +++ b/fabric/src/main/resources/moreculling.fabric.mixins.json @@ -6,6 +6,7 @@ "compatibilityLevel": "JAVA_21", "plugin": "ca.fxco.moreculling.config.MixinConfigPlugin", "client": [ + "blockstates.Block_fabricDrawSideMixin", "models.ForwardingBakedModel_compatMixin", "models.MultiPartBakedModel_cacheMixin", "models.SimpleBakedModel_fabricCacheMixin", diff --git a/gradle.properties b/gradle.properties index 8345f0c3..1a992348 100755 --- a/gradle.properties +++ b/gradle.properties @@ -1,24 +1,27 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx3G +org.gradle.parallel=true +org.gradle.caching=true +org.gradle.configuration-cache=true # Minecraft version -minecraft_version=1.21.1 -minecraft_version_range=[1.21,1.21.1) -neo_form_version=1.21.1-20240808.144430 +minecraft_version=1.21.2 +minecraft_version_range=[1.21.2,) +neo_form_version=1.21.2-20241022.151510 # Parchment parchment_minecraft=1.21 parchment_version=2024.07.28 # NeoForge -neoforge_version=21.1.20 +neoforge_version=21.2.0-beta neoforge_loader_version_range=[21.0.0-beta,) # Fabric version -fabric_loader_version=0.15.11 +fabric_loader_version=0.16.4 # Mod Properties -mod_version=1.0.0 +mod_version=1.1.0-beta.1 maven_group=ca.fxco.moreculling archives_base_name=moreculling license=GPL-3.0-only @@ -28,10 +31,10 @@ mod_author=FX - PR0CESS, 1Foxy2 java_version=21 # Mod Menu -modmenu_version=11.0.1 +modmenu_version=12.0.0-beta.1 # Fabric Compatibility -fabric_version=0.102.1+1.21.1 +fabric_version=0.105.3+1.21.2 # Sodium Compatibility sodium_version=mc1.21-0.6.0-beta.2 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a4413138..df97d72b 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/neoforge/build.gradle b/neoforge/build.gradle index e142d62f..0a800ae6 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -1,6 +1,3 @@ -import groovy.json.JsonSlurper -import groovy.json.JsonOutput - plugins { id 'multiloader-loader' id 'net.neoforged.moddev' @@ -40,7 +37,7 @@ neoForge { } dependencies { - implementation "maven.modrinth:sodium:${project.sodium_version}-neoforge" + compileOnly "maven.modrinth:sodium:${project.sodium_version}-neoforge" runtimeOnly "me.shedaniel.cloth:cloth-config-neoforge:${project.cloth_config_version}" implementation(jarJar("me.fallenbreath:conditional-mixin-neoforge:${project.conditional_mixins_version}")) diff --git a/neoforge/src/main/java/ca/fxco/moreculling/mixin/blockstates/Block_neoforgeDrawSideMixin.java b/neoforge/src/main/java/ca/fxco/moreculling/mixin/blockstates/Block_neoforgeDrawSideMixin.java new file mode 100644 index 00000000..87529fea --- /dev/null +++ b/neoforge/src/main/java/ca/fxco/moreculling/mixin/blockstates/Block_neoforgeDrawSideMixin.java @@ -0,0 +1,48 @@ +package ca.fxco.moreculling.mixin.blockstates; + +import ca.fxco.moreculling.MoreCulling; +import ca.fxco.moreculling.api.block.MoreBlockCulling; +import ca.fxco.moreculling.api.blockstate.MoreStateCulling; +import ca.fxco.moreculling.api.model.BakedOpacity; +import ca.fxco.moreculling.utils.CullingUtils; +import com.mojang.logging.LogUtils; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.util.RandomSource; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.EmptyBlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +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.callback.CallbackInfoReturnable; + +import static ca.fxco.moreculling.MoreCulling.DONT_CULL; +import static ca.fxco.moreculling.MoreCulling.blockRenderManager; + +@Mixin(value = Block.class, priority = 2500) +public class Block_neoforgeDrawSideMixin implements MoreBlockCulling { + /** + * Many mods use Block.shouldDrawSide() directly so its basically required that we override it (using an inject) + * If your mixin breaks due to this, please use the API if MoreCulling is present + */ + @Inject( + method = "shouldRenderFace(Lnet/minecraft/world/level/BlockGetter;" + + "Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;" + + "Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/Direction;)Z", + at = @At("HEAD"), + cancellable = true + ) + private static void moreculling$customShouldDrawSide(BlockGetter level, BlockPos pos, BlockState thisState, + BlockState sideState, Direction side, + CallbackInfoReturnable cir) { + if (MoreCulling.CONFIG.useBlockStateCulling && ((MoreStateCulling) thisState).moreculling$canCull()) { + cir.setReturnValue(CullingUtils.shouldDrawSideCulling(thisState, sideState, + EmptyBlockGetter.INSTANCE, pos, side, BlockPos.ZERO)); + } + } +} diff --git a/neoforge/src/main/java/ca/fxco/moreculling/mixin/models/MultiPartBakedModel_cacheMixin.java b/neoforge/src/main/java/ca/fxco/moreculling/mixin/models/MultiPartBakedModel_cacheMixin.java index 52a66019..e0b79cf3 100644 --- a/neoforge/src/main/java/ca/fxco/moreculling/mixin/models/MultiPartBakedModel_cacheMixin.java +++ b/neoforge/src/main/java/ca/fxco/moreculling/mixin/models/MultiPartBakedModel_cacheMixin.java @@ -33,7 +33,7 @@ public abstract class MultiPartBakedModel_cacheMixin implements BakedOpacity { @Shadow @Final - private List, BakedModel>> selectors; + private List selectors; @Unique // Only works on chunk update, so the best performance is after placing a block private byte solidFaces = 0; // 0 = all sides translucent @@ -54,9 +54,9 @@ public abstract class MultiPartBakedModel_cacheMixin implements BakedOpacity { @Override public @Nullable VoxelShape moreculling$getCullingShape(BlockState state) { VoxelShape cachedShape = null; - for (Pair, BakedModel> pair : this.selectors) { - if ((pair.getLeft()).test(state)) { - VoxelShape shape = ((BakedOpacity) pair.getRight()).moreculling$getCullingShape(state); + for (MultiPartBakedModel.Selector pair : this.selectors) { + if ((pair.condition()).test(state)) { + VoxelShape shape = ((BakedOpacity) pair.model()).moreculling$getCullingShape(state); if (shape != null) { if (cachedShape == null) { cachedShape = shape; diff --git a/neoforge/src/main/java/ca/fxco/moreculling/mixin/models/SimpleBakedModel_neoforgeCacheMixin.java b/neoforge/src/main/java/ca/fxco/moreculling/mixin/models/SimpleBakedModel_neoforgeCacheMixin.java index 50b0f58d..c407480f 100644 --- a/neoforge/src/main/java/ca/fxco/moreculling/mixin/models/SimpleBakedModel_neoforgeCacheMixin.java +++ b/neoforge/src/main/java/ca/fxco/moreculling/mixin/models/SimpleBakedModel_neoforgeCacheMixin.java @@ -1,7 +1,6 @@ package ca.fxco.moreculling.mixin.models; import ca.fxco.moreculling.api.model.BakedOpacity; -import net.minecraft.client.renderer.block.model.ItemOverrides; import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.SimpleBakedModel; @@ -17,16 +16,14 @@ @Mixin(SimpleBakedModel.class) public abstract class SimpleBakedModel_neoforgeCacheMixin implements BakedOpacity { @Inject( - method = "(Ljava/util/List;Ljava/util/Map;ZZZ" + - "Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;" + + method = "(Ljava/util/List;Ljava/util/Map;" + + "ZZZLnet/minecraft/client/renderer/texture/TextureAtlasSprite;" + "Lnet/minecraft/client/renderer/block/model/ItemTransforms;" + - "Lnet/minecraft/client/renderer/block/model/ItemOverrides;" + "Lnet/neoforged/neoforge/client/RenderTypeGroup;)V", at = @At("RETURN") ) - private void moreculling$onInit(List unculledFaces, Map culledFaces, boolean hasAmbientOcclusion, - boolean usesBlockLight, boolean isGui3d, TextureAtlasSprite particleIcon, - ItemTransforms transforms, ItemOverrides overrides, + private void moreculling$onInit(List p_119489_, Map p_119490_, boolean p_119491_, boolean p_119492_, + boolean p_119493_, TextureAtlasSprite p_119494_, ItemTransforms p_119495_, RenderTypeGroup renderTypes, CallbackInfo ci) { moreculling$resetTranslucencyCache(); } diff --git a/neoforge/src/main/java/ca/fxco/moreculling/mixin/renderers/ItemRenderer_neoforgeFaceCullingMixin.java b/neoforge/src/main/java/ca/fxco/moreculling/mixin/renderers/ItemRenderer_neoforgeFaceCullingMixin.java index 56110684..d89eafcf 100644 --- a/neoforge/src/main/java/ca/fxco/moreculling/mixin/renderers/ItemRenderer_neoforgeFaceCullingMixin.java +++ b/neoforge/src/main/java/ca/fxco/moreculling/mixin/renderers/ItemRenderer_neoforgeFaceCullingMixin.java @@ -8,15 +8,14 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.llamalad7.mixinextras.sugar.Share; -import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef; import com.llamalad7.mixinextras.sugar.ref.LocalRef; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.block.model.ItemTransform; import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.client.renderer.entity.state.ItemFrameRenderState; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.Direction; -import net.minecraft.world.entity.decoration.ItemFrame; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; @@ -34,7 +33,7 @@ public class ItemRenderer_neoforgeFaceCullingMixin { @WrapOperation( - method = "render", + method = "renderItemModelRaw", at = @At( value = "INVOKE", target = "Lnet/neoforged/neoforge/client/ClientHooks;handleCameraTransforms(" + @@ -56,7 +55,7 @@ public class ItemRenderer_neoforgeFaceCullingMixin { } @Inject( - method = "render", + method = "renderItem", at = @At( value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/ItemRenderer;renderModelLists(" + @@ -65,21 +64,22 @@ public class ItemRenderer_neoforgeFaceCullingMixin { "Lcom/mojang/blaze3d/vertex/VertexConsumer;)V" ) ) - private void moreculling$faceRemoval(ItemStack stack, ItemDisplayContext displayContext, - boolean leftHanded, PoseStack poseStack, - MultiBufferSource multiBufferSource, int light, int overlay, - BakedModel model, CallbackInfo ci, + private void moreculling$faceRemoval(ItemStack stack, ItemDisplayContext p_361627_, PoseStack p_360423_, + MultiBufferSource p_360415_, int p_361265_, int p_364771_, + BakedModel p_363970_, boolean p_364829_, CallbackInfo ci, @Share("transformation") LocalRef transformationRef) { - ItemFrame frame = ItemRendererStates.ITEM_FRAME; + ItemFrameRenderState frame = ItemRendererStates.ITEM_FRAME; if (frame == null) { ItemRendererStates.DIRECTIONS = null; return; } Vec3 cameraPos = ItemRendererStates.CAMERA.getPosition(); - Vec3 framePos = frame.position(); + Vec3 framePos = new Vec3(frame.x, frame.y, frame.z) ; boolean isBlockItem = stack.getItem() instanceof BlockItem; ItemTransform transformation = transformationRef.get(); - boolean canCull = ((!isBlockItem && !frame.isInvisible()) || CullingUtils.shouldCullBack(frame)) && + if (transformation == null) + return; + boolean canCull = ((!isBlockItem && !frame.isInvisible) || CullingUtils.shouldCullBack(frame)) && TransformationUtils.canCullTransformation(transformation); double dist = ItemRendererStates.CAMERA.getPosition().distanceTo(framePos); // Make blocks use LOD - If more than range, only render the front and maybe back if it can't cull @@ -97,13 +97,13 @@ public class ItemRenderer_neoforgeFaceCullingMixin { // TODO: Add model rotation logic (items need this!) Currently we only support blocks and some models if (MoreCulling.CONFIG.useItemFrame3FaceCulling && dist > MoreCulling.CONFIG.itemFrame3FaceCullingRange && - frame.getRotation() % 2 == 0 && + frame.rotation % 2 == 0 && transformation.rotation.y() == 0 && transformation.rotation.x() == 0 && transformation.rotation.z() == 0 ) { - int rotation = frame.getRotation() * 45; - Direction facing = frame.getDirection(); + int rotation = frame.rotation * 45; + Direction facing = frame.direction; Direction dirX = shiftDirection(facing, cameraPos.x > framePos.x ? Direction.EAST : Direction.WEST, rotation); Direction dirY = shiftDirection(facing, diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index 479f4bf3..6d28b030 100644 --- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -9,7 +9,7 @@ version="${mod_version}" #mandatory displayName="${mod_name}" #mandatory #updateJSONURL="https://change.me.example.invalid/updates.json" #optional displayURL="https://modrinth.com/mod/moreculling" #optional -issueTrackerURL="https://github.com/fxmorin/moreculling" #optional +issueTrackerURL="https://github.com/fxmorin/moreculling/issues" #optional logoFile="assets/moreculling/MoreCulling.png" #optional #credits="" #optional authors="${mod_author}" #optional @@ -18,7 +18,7 @@ description='''${description}''' [modproperties.modmenu] badges=["client"] links=["mod_menu.discord=https://discord.gg/SGFDrvA"] -sources="https://github.com/fxmorin/moreculling/issues" +sources="https://github.com/fxmorin/moreculling" [[mixins]] config = "${mod_id}.mixins.json" diff --git a/neoforge/src/main/resources/moreculling.neoforge.mixins.json b/neoforge/src/main/resources/moreculling.neoforge.mixins.json index d46eb571..b4fb5259 100644 --- a/neoforge/src/main/resources/moreculling.neoforge.mixins.json +++ b/neoforge/src/main/resources/moreculling.neoforge.mixins.json @@ -5,6 +5,7 @@ "compatibilityLevel": "JAVA_21", "plugin": "ca.fxco.moreculling.config.MixinConfigPlugin", "client": [ + "blockstates.Block_neoforgeDrawSideMixin", "models.BakedModelWrapper_compatMixin", "models.MultiPartBakedModel_cacheMixin", "models.SimpleBakedModel_neoforgeCacheMixin",