forked from Asek3/Oculus
-
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.
Avoids depending on a 300MB mod jar
- Loading branch information
Showing
2 changed files
with
16 additions
and
45 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
60 changes: 16 additions & 44 deletions
60
src/main/java/net/coderbot/iris/mixin/compat/pixelmon/MixinNormalizedFace.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 |
---|---|---|
@@ -1,51 +1,23 @@ | ||
package net.coderbot.iris.mixin.compat.pixelmon; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.blaze3d.vertex.VertexConsumer; | ||
import com.mojang.math.Matrix3f; | ||
import com.mojang.math.Matrix4f; | ||
import com.pixelmonmod.pixelmon.client.models.smd.DeformVertex; | ||
import com.pixelmonmod.pixelmon.client.models.smd.NormalizedFace; | ||
import com.pixelmonmod.pixelmon.client.models.smd.TextureCoordinate; | ||
import com.pixelmonmod.pixelmon.client.models.smd.Vertex; | ||
import com.mojang.blaze3d.vertex.BufferBuilder; | ||
import org.objectweb.asm.Opcodes; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Pseudo; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Coerce; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@Mixin(NormalizedFace.class) | ||
@Pseudo | ||
@Mixin(targets = {"com/pixelmonmod/pixelmon/client/models/smd/NormalizedFace"}) | ||
public class MixinNormalizedFace { | ||
|
||
@Shadow | ||
public DeformVertex[] vertices; | ||
|
||
@Shadow | ||
public TextureCoordinate[] textureCoordinates; | ||
|
||
@Shadow | ||
public Vertex faceNormal; | ||
|
||
@Shadow | ||
public Vertex calculateFaceNormal() { | ||
return null; | ||
/** | ||
* @author embeddedt (original idea by NanoLive) | ||
* @reason Pixelmon manipulates the buffer of a {@link BufferBuilder} directly which causes problems. | ||
* We bypass that code path. | ||
*/ | ||
@Redirect(method = "addFaceForRender", at = @At(value = "FIELD", opcode = Opcodes.GETFIELD, target = "Lcom/pixelmonmod/pixelmon/client/models/smd/DeformVertex;id2:I")) | ||
public int hideBufferBuilderId(@Coerce Object instance) { | ||
return -1; // prevent using "optimized" code path | ||
} | ||
|
||
@Overwrite | ||
public void addFaceForRender(PoseStack matrixStack, VertexConsumer bufferBuilder, int packedLight, int packedOverlay, boolean smoothShading, float partialTick, float r, float g, float b, float a) { | ||
if (!smoothShading && | ||
this.faceNormal == null) | ||
this.faceNormal = calculateFaceNormal(); | ||
for (int i = 0; i < 3; i++) { | ||
Matrix4f pose = matrixStack.last().pose(); | ||
Matrix3f normal = matrixStack.last().normal(); | ||
bufferBuilder.vertex(pose.m00 * this.vertices[i] | ||
.getX(partialTick) + pose.m01 * this.vertices[i].getY(partialTick) + pose.m02 * this.vertices[i].getZ(partialTick) + pose.m03, pose.m10 * this.vertices[i] | ||
.getX(partialTick) + pose.m11 * this.vertices[i].getY(partialTick) + pose.m12 * this.vertices[i].getZ(partialTick) + pose.m13, pose.m20 * this.vertices[i] | ||
.getX(partialTick) + pose.m21 * this.vertices[i].getY(partialTick) + pose.m22 * this.vertices[i].getZ(partialTick) + pose.m23, r, g, b, a, (this.textureCoordinates[i]).u, (this.textureCoordinates[i]).v, packedOverlay, packedLight, normal.m00 * this.vertices[i] | ||
|
||
.getXN(partialTick) + normal.m01 * this.vertices[i].getYN(partialTick) + normal.m02 * this.vertices[i].getZN(partialTick), normal.m10 * this.vertices[i] | ||
.getXN(partialTick) + normal.m11 * this.vertices[i].getYN(partialTick) + normal.m12 * this.vertices[i].getZN(partialTick), normal.m20 * this.vertices[i] | ||
.getXN(partialTick) + normal.m21 * this.vertices[i].getYN(partialTick) + normal.m22 * this.vertices[i].getZN(partialTick)); | ||
} | ||
} | ||
|
||
} |