Skip to content

Commit

Permalink
fixed pixelmon issue
Browse files Browse the repository at this point in the history
Fixes #458
  • Loading branch information
Asek3 committed Dec 12, 2023
1 parent e21975b commit 9eb8ddf
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 1 deletion.
12 changes: 11 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ loom {
"mixins.oculus.compat.sodium.json",
"mixins.oculus.compat.indigo.json",
"mixins.oculus.compat.dh.json",
"mixins.oculus.compat.indium.json"
"mixins.oculus.compat.indium.json",
"mixins.oculus.compat.json"
]
}
mixin.defaultRefmapName = "oculus-mixins-refmap.json"
Expand Down Expand Up @@ -76,6 +77,13 @@ loom {
}

repositories {
maven {
name = "CurseForge"
url = "https://cursemaven.com"
content {
includeGroup "curse.maven"
}
}
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
Expand All @@ -97,6 +105,8 @@ 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
@@ -0,0 +1,49 @@
package net.coderbot.iris.mixin.compat;

import net.minecraftforge.fml.loading.FMLLoader;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Set;

public class CompatMixinPlugin implements IMixinConfigPlugin {
@Override
public void onLoad(String mixinPackage) {

}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
int startIndex = mixinClassName.indexOf("compat.") + "compat.".length();
int endIndex = mixinClassName.indexOf(".", startIndex);
String modid = mixinClassName.substring(startIndex, endIndex);
return FMLLoader.getLoadingModList().getModFileById(modid) != null;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {

}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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 org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(value = NormalizedFace.class, remap = false)
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...
*/
@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());
/*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));*/
}
}

}
14 changes: 14 additions & 0 deletions src/main/resources/mixins.oculus.compat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"required": true,
"minVersion": "0.8",
"package": "net.coderbot.iris.mixin.compat",
"plugin": "net.coderbot.iris.mixin.compat.CompatMixinPlugin",
"refmap": "oculus-refmap.json",
"compatibilityLevel": "JAVA_8",
"client": [
"pixelmon.MixinNormalizedFace"
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit 9eb8ddf

Please sign in to comment.