From ac9e00f675a800257823df50a566186f57854ab1 Mon Sep 17 00:00:00 2001 From: "petrak@" Date: Thu, 16 Feb 2023 13:53:37 -0600 Subject: [PATCH] gas my own light, gate my own keep, and girl my own boss --- .../be/BlockEntityQuenchedAllayRenderer.java | 16 ++++++++- .../xplat/IClientXplatAbstractions.java | 5 ++- .../client/FabricLevelRendererMixin.java | 34 +++++++++++++++++++ .../fabric/xplat/FabricClientXplatImpl.java | 17 ++++++++-- .../main/resources/fabricasting.mixins.json | 2 ++ .../forge/xplat/ForgeClientXplatImpl.java | 8 ++++- 6 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 Fabric/src/main/java/at/petrak/hexcasting/fabric/mixin/client/FabricLevelRendererMixin.java diff --git a/Common/src/main/java/at/petrak/hexcasting/client/be/BlockEntityQuenchedAllayRenderer.java b/Common/src/main/java/at/petrak/hexcasting/client/be/BlockEntityQuenchedAllayRenderer.java index 1878d533..5387c554 100644 --- a/Common/src/main/java/at/petrak/hexcasting/client/be/BlockEntityQuenchedAllayRenderer.java +++ b/Common/src/main/java/at/petrak/hexcasting/client/be/BlockEntityQuenchedAllayRenderer.java @@ -3,12 +3,14 @@ package at.petrak.hexcasting.client.be; import at.petrak.hexcasting.client.RegisterClientStuff; import at.petrak.hexcasting.common.blocks.BlockQuenchedAllay; import at.petrak.hexcasting.common.blocks.entity.BlockEntityQuenchedAllay; +import at.petrak.hexcasting.xplat.IClientXplatAbstractions; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.block.BlockRenderDispatcher; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; +import net.minecraft.world.phys.AABB; public class BlockEntityQuenchedAllayRenderer implements BlockEntityRenderer { private static int GASLIGHTING_AMOUNT = 0; @@ -36,7 +38,19 @@ public class BlockEntityQuenchedAllayRenderer implements BlockEntityRenderer p.type().getName()).collect(Collectors.joining(",", "[", "]")); throw new IllegalStateException( - "There should be exactly one IClientXplatAbstractions implementation on the classpath. Found: " + names); + "There should be exactly one IClientXplatAbstractions implementation on the classpath. Found: " + names); } else { var provider = providers.get(0); HexAPI.LOGGER.debug("Instantiating client xplat impl: " + provider.type().getName()); diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/mixin/client/FabricLevelRendererMixin.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/mixin/client/FabricLevelRendererMixin.java new file mode 100644 index 00000000..12853606 --- /dev/null +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/mixin/client/FabricLevelRendererMixin.java @@ -0,0 +1,34 @@ +package at.petrak.hexcasting.fabric.mixin.client; + +import at.petrak.hexcasting.fabric.xplat.FabricClientXplatImpl; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Matrix4f; +import net.minecraft.client.Camera; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.culling.Frustum; +import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.world.phys.Vec3; +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.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(LevelRenderer.class) +public class FabricLevelRendererMixin { + @SuppressWarnings("InvalidInjectorMethodSignature") + @Inject( + method = "renderLevel", + at = @At( + value = "INVOKE", target = "Lnet/minecraft/client/renderer/FogRenderer;levelFogColor()V", + ordinal = 0), + locals = LocalCapture.CAPTURE_FAILSOFT) + private void snagFrustumFromLevelRenderer(PoseStack poseStack, float f, long arg2, boolean bl, Camera camera, + GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, CallbackInfo ci, + ProfilerFiller profilerFiller, boolean bl2, Vec3 vec3, double d, double e, double g, Matrix4f matrix4f2, + boolean bl3, Frustum frustum) { + FabricClientXplatImpl.LEVEL_RENDERER_FRUSTUM = frustum; + } +} diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricClientXplatImpl.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricClientXplatImpl.java index 82d50a8f..86f5580b 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricClientXplatImpl.java +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricClientXplatImpl.java @@ -11,6 +11,7 @@ import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.culling.Frustum; import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.item.ClampedItemPropertyFunction; import net.minecraft.client.renderer.item.ItemProperties; @@ -23,6 +24,7 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; +import net.minecraft.world.phys.AABB; import org.jetbrains.annotations.Nullable; public class FabricClientXplatImpl implements IClientXplatAbstractions { @@ -45,7 +47,7 @@ public class FabricClientXplatImpl implements IClientXplatAbstractions { @Override public void registerEntityRenderer(EntityType type, - EntityRendererProvider renderer) { + EntityRendererProvider renderer) { EntityRendererRegistry.register(type, renderer); } @@ -53,7 +55,7 @@ public class FabricClientXplatImpl implements IClientXplatAbstractions { private record UnclampedClampedItemPropFunc(ItemPropertyFunction inner) implements ClampedItemPropertyFunction { @Override public float unclampedCall(ItemStack stack, @Nullable ClientLevel level, @Nullable LivingEntity entity, - int seed) { + int seed) { return inner.call(stack, level, entity, seed); } @@ -77,4 +79,15 @@ public class FabricClientXplatImpl implements IClientXplatAbstractions { public void restoreLastFilter(AbstractTexture texture) { ((ExtendedTexture) texture).restoreLastFilter(); } + + // Set by FabricLevelRendererMixin + public static Frustum LEVEL_RENDERER_FRUSTUM = null; + + @Override + public boolean fabricAdditionalQuenchFrustumCheck(AABB aabb) { + if (LEVEL_RENDERER_FRUSTUM == null) { + return true; // fail safe + } + return LEVEL_RENDERER_FRUSTUM.isVisible(aabb); + } } diff --git a/Fabric/src/main/resources/fabricasting.mixins.json b/Fabric/src/main/resources/fabricasting.mixins.json index 1c715f2b..aef62875 100644 --- a/Fabric/src/main/resources/fabricasting.mixins.json +++ b/Fabric/src/main/resources/fabricasting.mixins.json @@ -16,7 +16,9 @@ ], "client": [ "client.FabricAbstractTextureMixin", + "client.FabricLevelRendererMixin", "client.FabricMixinGameRenderer", + "client.FabricModelManagerMixin", "client.FabricMouseHandlerMixin", "client.FabricParticleEngineMixin" ] diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeClientXplatImpl.java b/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeClientXplatImpl.java index 0fb4230a..9843f6ef 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeClientXplatImpl.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeClientXplatImpl.java @@ -14,6 +14,7 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; +import net.minecraft.world.phys.AABB; public class ForgeClientXplatImpl implements IClientXplatAbstractions { @Override @@ -34,7 +35,7 @@ public class ForgeClientXplatImpl implements IClientXplatAbstractions { @Override public void registerEntityRenderer(EntityType type, - EntityRendererProvider renderer) { + EntityRendererProvider renderer) { EntityRenderers.register(type, renderer); } @@ -52,4 +53,9 @@ public class ForgeClientXplatImpl implements IClientXplatAbstractions { public void restoreLastFilter(AbstractTexture texture) { texture.restoreLastBlurMipmap(); } + + @Override + public boolean fabricAdditionalQuenchFrustumCheck(AABB aabb) { + return true; // forge fixes this with a patch so we just say "yep" + } }