11package dev .ryanhcode .sable .mixin .compatibility .vista ;
22
3+ import com .llamalad7 .mixinextras .injector .wrapmethod .WrapMethod ;
34import com .llamalad7 .mixinextras .injector .wrapoperation .Operation ;
4- import com .llamalad7 .mixinextras .injector .wrapoperation .WrapOperation ;
55import dev .ryanhcode .sable .Sable ;
66import dev .ryanhcode .sable .sublevel .ClientSubLevel ;
77import net .mehvahdjukaar .moonlight .api .client .util .LOD ;
88import net .minecraft .client .Camera ;
99import net .minecraft .client .Minecraft ;
1010import net .minecraft .client .multiplayer .ClientLevel ;
11- import net .minecraft .core .Direction ;
1211import net .minecraft .world .phys .Vec3 ;
1312import org .joml .Vector3d ;
14- import org .joml .Vector3f ;
1513import org .spongepowered .asm .mixin .*;
1614import org .spongepowered .asm .mixin .injection .At ;
1715import org .spongepowered .asm .mixin .injection .Inject ;
@@ -37,21 +35,27 @@ public class LODMixin {
3735 @ Final
3836 private Vec3 cameraPosition ;
3937
40- @ WrapOperation (method = "isPlaneCulled(Lnet/minecraft/core/Direction;FFF)Z" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/core/Direction;step()Lorg/joml/Vector3f;" ))
41- private Vector3f sable$step (final Direction instance , final Operation <Vector3f > original ) {
42- final Vector3f dir = original .call (instance );
43- final ClientSubLevel clientSubLevel = Sable .HELPER .getContainingClient (this .objCenter );
44- if (clientSubLevel != null ) {
45- sable$direction .set (dir );
46- clientSubLevel .renderPose ().transformNormal (sable$direction );
47- dir .set (sable$direction );
38+ @ Unique
39+ private Vec3 sable$localPos = null ;
40+
41+ @ WrapMethod (method = "isPlaneCulled(Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/Vec3;FF)Z" )
42+ private boolean sable$isPlaneCulled (Vec3 planeNormal , Vec3 offset , final float discRadius , final float cosTolerance , final Operation <Boolean > original ) {
43+ final ClientSubLevel clientSubLevel = Sable .HELPER .getContainingClient (this .sable$localPos );
44+
45+ if (clientSubLevel != null ) {
46+ planeNormal = clientSubLevel .renderPose ().transformNormal (planeNormal );
47+
48+ if (offset != null )
49+ offset = clientSubLevel .renderPose ().transformNormal (offset );
4850 }
49- return dir ;
51+
52+ return original .call (planeNormal , offset , discRadius , cosTolerance );
5053 }
5154
5255 @ Inject (method = "<init>(Lnet/minecraft/client/Camera;Lnet/minecraft/world/phys/Vec3;)V" , at = @ At ("TAIL" ))
53- private void sable$init (Camera camera , Vec3 objCenter , CallbackInfo ci ) {
54- ClientLevel level = Minecraft .getInstance ().level ;
56+ private void sable$init (final Camera camera , final Vec3 objCenter , final CallbackInfo ci ) {
57+ final ClientLevel level = Minecraft .getInstance ().level ;
58+ this .sable$localPos = objCenter ;
5559 this .objCenter = Sable .HELPER .projectOutOfSubLevel (level , objCenter );
5660 this .distSq = LOD .isScoping () ? (double ) 1.0F : Sable .HELPER .distanceSquaredWithSubLevels (level , this .cameraPosition , objCenter );
5761 }
0 commit comments