Skip to content

Commit

Permalink
Replace @Redirect
Browse files Browse the repository at this point in the history
Fix for something like #13
  • Loading branch information
dima-dencep committed Jun 14, 2024
1 parent 312f170 commit 10d1352
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.kosmx.bendylib.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import io.github.kosmx.bendylib.ModelPartAccessor;
import io.github.kosmx.bendylib.MutableCuboid;
import io.github.kosmx.bendylib.impl.accessors.CuboidSideAccessor;
Expand All @@ -10,7 +12,6 @@
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Iterator;
Expand All @@ -33,8 +34,6 @@ public abstract class IModelPartMixin implements IModelPartAccessor {
*/
private ModelPartAccessor.Workaround workaround = ModelPartAccessor.Workaround.VanillaDraw;

@Shadow protected abstract void renderCuboids(MatrixStack.Entry entry, VertexConsumer vertexConsumer, int light, int overlay, int color);

@Override
public List<ModelPart.Cuboid> getCuboids() {
hasMutatedCuboid = true;
Expand All @@ -60,9 +59,9 @@ private void copyTransformExtended(ModelPart part, CallbackInfo ci){

}

@Redirect(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;III)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/ModelPart;renderCuboids(Lnet/minecraft/client/util/math/MatrixStack$Entry;Lnet/minecraft/client/render/VertexConsumer;III)V"), require = 0) //It might not find anything if OF already broke the game
private void redirectRenderCuboids(ModelPart modelPart, MatrixStack.Entry entry, VertexConsumer vertexConsumer, int light, int overlay, int color){
redirectedFunction(modelPart, entry, vertexConsumer, light, overlay, color);
@WrapOperation(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;III)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/ModelPart;renderCuboids(Lnet/minecraft/client/util/math/MatrixStack$Entry;Lnet/minecraft/client/render/VertexConsumer;III)V"), require = 0) //It might not find anything if OF already broke the game
private void redirectRenderCuboids(ModelPart modelPart, MatrixStack.Entry entry, VertexConsumer vertexConsumer, int light, int overlay, int color, Operation<Void> original){
redirectedFunction(modelPart, entry, vertexConsumer, light, overlay, color, original);
}

/* // check what they do here
Expand All @@ -73,19 +72,19 @@ private void redirectOF(ModelPart modelPart, MatrixStack.Entry entry, VertexCons
}*/

@Unique
private void redirectedFunction(ModelPart modelPart, MatrixStack.Entry entry, VertexConsumer vertexConsumer, int light, int overlay, int color) {
private void redirectedFunction(ModelPart modelPart, MatrixStack.Entry entry, VertexConsumer vertexConsumer, int light, int overlay, int color, Operation<Void> original) {
if(workaround == ModelPartAccessor.Workaround.ExportQuads){
for(ModelPart.Cuboid cuboid:cuboids){
((CuboidSideAccessor)cuboid).doSideSwapping(); //:D
}
renderCuboids(entry, vertexConsumer, light, overlay, color);
original.call(modelPart, entry, vertexConsumer, light, overlay, color);
for(ModelPart.Cuboid cuboid:cuboids){
((CuboidSideAccessor)cuboid).resetSides(); //:D
}
}
else if(workaround == ModelPartAccessor.Workaround.VanillaDraw){
if(!hasMutatedCuboid || cuboids.size() == 1 && ((MutableCuboid)cuboids.get(0)).getActiveMutator() == null){
renderCuboids(entry, vertexConsumer, light, overlay, color);
original.call(modelPart, entry, vertexConsumer, light, overlay, color);
}
else {
for(ModelPart.Cuboid cuboid:cuboids){
Expand All @@ -94,7 +93,7 @@ else if(workaround == ModelPartAccessor.Workaround.VanillaDraw){
}
}
else {
renderCuboids(entry, vertexConsumer, light, overlay, color);
original.call(modelPart, entry, vertexConsumer, light, overlay, color);
}
}

Expand Down

0 comments on commit 10d1352

Please sign in to comment.