Fixed crash due to duplicate buffers

This commit is contained in:
Sollace 2023-03-20 19:50:37 +00:00
parent 0eae23ea48
commit 718cae82e8
2 changed files with 41 additions and 1 deletions

View file

@ -0,0 +1,39 @@
package com.minelittlepony.client.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Arrays;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumers;
/**
* Unmojang this code so the game doesn't crash
* any time you try to create a union with multiples of the same vertex consumer.
*/
@Mixin(VertexConsumers.class)
abstract class MixinVertextConsumers {
private static final String T = "Lnet/minecraft/client/render/VertexConsumer;";
@Inject(method = "union(" + T + T + ")" + T, at = @At("HEAD"), cancellable = true)
private static void onUnion(VertexConsumer first, VertexConsumer second, CallbackInfoReturnable<VertexConsumer> info) {
if (first == second) {
info.setReturnValue(first);
}
}
@Inject(method = "union([" + T + ")" + T, at = @At("HEAD"), cancellable = true)
private static void onUnion(VertexConsumer[] delegates, CallbackInfoReturnable<VertexConsumer> info) {
int oldLength = delegates.length;
delegates = Arrays.stream(delegates).distinct().toArray(VertexConsumer[]::new);
if (delegates.length == 1) {
info.setReturnValue(delegates[0]);
} else if (delegates.length != oldLength) {
info.setReturnValue(new VertexConsumers.Union(delegates));
}
}
}

View file

@ -14,6 +14,7 @@
"MixinHeldItemRenderer",
"MixinClientPlayerEntity",
"MixinPlayerMoveC2SPacket",
"MixinPlayerPositionLookS2CPacket"
"MixinPlayerPositionLookS2CPacket",
"MixinVertextConsumers"
]
}