Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.20] Clean up Pixelmon fix #517

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}

}
}
Loading