Skip to content

Commit

Permalink
Clean up Pixelmon fix (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt authored Dec 21, 2023
1 parent 9a4f55c commit cbcf03d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 46 deletions.
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ dependencies {
modCompileOnly "org.embeddedt:embeddium-${minecraft_version}:${embeddium_version}"
compileOnly "maven.modrinth:distanthorizons:2.0.1-a-1.20.1"

modCompileOnly "curse.maven:pixelmon-389487:4782028"

forgeRuntimeLibrary(implementation(shadow(project(path: ":glsl-relocated", configuration: "bundledJar")))) {
transitive = false
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,23 @@
package net.coderbot.iris.mixin.compat.pixelmon;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
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 org.joml.Matrix3f;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.joml.Vector4f;
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(value = NormalizedFace.class, remap = false)
@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 Asek3
* @reason We should deal with this...
* @author embeddedt (original idea by NanoLive)
* @reason Pixelmon manipulates the buffer of a {@link BufferBuilder} directly which causes problems.
* We bypass that 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();
DeformVertex vertex = this.vertices[i];
Vector4f transformedPosition = pose.transform(new Vector4f(vertex.getX(partialTick), vertex.getY(partialTick), vertex.getZ(partialTick), 1.0F));
Vector3f transformedNormal = normal.transform(new Vector3f(vertex.getXN(partialTick), vertex.getYN(partialTick), vertex.getZN(partialTick)));
bufferBuilder.vertex(transformedPosition.x(), transformedPosition.y(), transformedPosition.z(), r, g, b, a, this.textureCoordinates[i].u, this.textureCoordinates[i].v, packedOverlay, packedLight, transformedNormal.x(), transformedNormal.y(), transformedNormal.z());
}
@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
}

}
}

0 comments on commit cbcf03d

Please sign in to comment.