forked from shedaniel/LightOverlay
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: shedaniel <daniel@shedaniel.me>
- Loading branch information
Showing
16 changed files
with
199 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
plugins { | ||
id("fabric-loom") version "0.5-SNAPSHOT" | ||
id("fabric-loom") version "0.4-SNAPSHOT" | ||
} | ||
|
||
minecraft { | ||
|
31 changes: 31 additions & 0 deletions
31
fabric/src/main/java/me/shedaniel/lightoverlay/fabric/FrustumHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package me.shedaniel.lightoverlay.fabric; | ||
|
||
import net.minecraft.client.render.Frustum; | ||
import net.minecraft.client.util.math.Vector4f; | ||
|
||
public class FrustumHelper { | ||
public static boolean isVisible(Frustum frustum, double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { | ||
float x1 = (float) (minX - frustum.x); | ||
float y1 = (float) (minY - frustum.y); | ||
float z1 = (float) (minZ - frustum.z); | ||
float x2 = (float) (maxX - frustum.x); | ||
float y2 = (float) (maxY - frustum.y); | ||
float z2 = (float) (maxZ - frustum.z); | ||
return isAnyCornerVisible(frustum, x1, y1, z1, x2, y2, z2); | ||
} | ||
|
||
private static boolean isAnyCornerVisible(Frustum frustum, float x1, float y1, float z1, float x2, float y2, float z2) { | ||
Vector4f[] homogeneousCoordinates = frustum.homogeneousCoordinates; | ||
for (Vector4f vector4f : homogeneousCoordinates) { | ||
if (dotProduct(vector4f, x1, y1, z1, 1.0F) <= 0.0F && dotProduct(vector4f, x2, y1, z1, 1.0F) <= 0.0F && dotProduct(vector4f, x1, y2, z1, 1.0F) <= 0.0F && dotProduct(vector4f, x2, y2, z1, 1.0F) <= 0.0F && dotProduct(vector4f, x1, y1, z2, 1.0F) <= 0.0F && dotProduct(vector4f, x2, y1, z2, 1.0F) <= 0.0F && dotProduct(vector4f, x1, y2, z2, 1.0F) <= 0.0F && dotProduct(vector4f, x2, y2, z2, 1.0F) <= 0.0F) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private static float dotProduct(Vector4f self, float x, float y, float z, float w) { | ||
return self.getX() * x + self.getY() * y + self.getZ() * z + self.getW() * w; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
fabric/src/main/java/me/shedaniel/lightoverlay/fabric/mixin/MixinWorldRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package me.shedaniel.lightoverlay.fabric.mixin; | ||
|
||
import me.shedaniel.lightoverlay.fabric.LightOverlay; | ||
import net.minecraft.client.render.Camera; | ||
import net.minecraft.client.render.Frustum; | ||
import net.minecraft.client.render.WorldRenderer; | ||
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; | ||
|
||
@Mixin(WorldRenderer.class) | ||
public class MixinWorldRenderer { | ||
@Inject(method = "setupTerrain", at = @At("HEAD")) | ||
private void setupTerrain(Camera camera, Frustum frustum, boolean hasForcedFrustum, int frame, boolean spectator, CallbackInfo ci) { | ||
LightOverlay.frustum = frustum; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
accessWidener v1 named | ||
accessible field net/minecraft/network/packet/s2c/play/ChunkDeltaUpdateS2CPacket sectionPos Lnet/minecraft/util/math/ChunkSectionPos; | ||
accessible field net/minecraft/network/packet/s2c/play/ChunkDeltaUpdateS2CPacket sectionPos Lnet/minecraft/util/math/ChunkSectionPos; | ||
accessible field net/minecraft/client/render/Frustum x D | ||
accessible field net/minecraft/client/render/Frustum y D | ||
accessible field net/minecraft/client/render/Frustum z D | ||
accessible field net/minecraft/client/render/Frustum homogeneousCoordinates [Lnet/minecraft/client/util/math/Vector4f; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
forge/src/main/java/me/shedaniel/lightoverlay/forge/FrustumHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package me.shedaniel.lightoverlay.forge; | ||
|
||
import net.minecraft.client.renderer.culling.ClippingHelper; | ||
import net.minecraft.util.math.vector.Vector4f; | ||
|
||
public class FrustumHelper { | ||
public static boolean isVisible(ClippingHelper frustum, double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { | ||
float x1 = (float) (minX - frustum.cameraX); | ||
float y1 = (float) (minY - frustum.cameraY); | ||
float z1 = (float) (minZ - frustum.cameraZ); | ||
float x2 = (float) (maxX - frustum.cameraX); | ||
float y2 = (float) (maxY - frustum.cameraY); | ||
float z2 = (float) (maxZ - frustum.cameraZ); | ||
return isAnyCornerVisible(frustum, x1, y1, z1, x2, y2, z2); | ||
} | ||
|
||
private static boolean isAnyCornerVisible(ClippingHelper frustum, float x1, float y1, float z1, float x2, float y2, float z2) { | ||
Vector4f[] homogeneousCoordinates = frustum.frustum; | ||
for (Vector4f vector4f : homogeneousCoordinates) { | ||
if (dotProduct(vector4f, x1, y1, z1, 1.0F) <= 0.0F && dotProduct(vector4f, x2, y1, z1, 1.0F) <= 0.0F && dotProduct(vector4f, x1, y2, z1, 1.0F) <= 0.0F && dotProduct(vector4f, x2, y2, z1, 1.0F) <= 0.0F && dotProduct(vector4f, x1, y1, z2, 1.0F) <= 0.0F && dotProduct(vector4f, x2, y1, z2, 1.0F) <= 0.0F && dotProduct(vector4f, x1, y2, z2, 1.0F) <= 0.0F && dotProduct(vector4f, x2, y2, z2, 1.0F) <= 0.0F) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private static float dotProduct(Vector4f self, float x, float y, float z, float w) { | ||
return self.getX() * x + self.getY() * y + self.getZ() * z + self.getW() * w; | ||
} | ||
} |
Oops, something went wrong.