Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package betterblockentities.mixin.minecraft;

import it.unimi.dsi.fastutil.ints.IntArrays;
import net.minecraft.client.render.command.ModelCommandRenderer;
import net.minecraft.client.render.command.OrderedRenderCommandQueueImpl;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

@Mixin(ModelCommandRenderer.class)
public class ModelCommandRendererMixin {

@Redirect(method = "render(Lnet/minecraft/client/render/command/BatchingRenderCommandQueue;Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;Lnet/minecraft/client/render/OutlineVertexConsumerProvider;Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;)V", at = @At(value = "INVOKE", target = "Ljava/util/List;sort(Ljava/util/Comparator;)V"))
private void arrayIntSort(List<OrderedRenderCommandQueueImpl.BlendedModelCommand<?>> list,
Comparator<?> comparator) {
int size = list.size();
if (size < 2)
return;

double[] keys = new double[size];
int[] indices = new int[size];

for (int i = 0; i < size; i++) {
keys[i] = -list.get(i).position().lengthSquared();
indices[i] = i;
}

IntArrays.quickSort(indices, (a, b) -> {
int c = Double.compare(keys[a], keys[b]);
return c == 0 ? Integer.compare(a, b) : c;
});

List<OrderedRenderCommandQueueImpl.BlendedModelCommand<?>> sorted = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
sorted.add(list.get(indices[i]));
}

list.clear();
list.addAll(sorted);
}
}
9 changes: 2 additions & 7 deletions src/main/resources/betterblockentities.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,25 @@
"compatibilityLevel": "JAVA_21",
"mixins": [
"minecraft.bell.BellBlockEntityMixin",

"minecraft.chest.ChestBlockEntityAccessor",
"minecraft.chest.ChestBlockEntityMixin",
"minecraft.chest.ChestBlockEntityRendererMixin",
"minecraft.chest.ChestLidAnimatorAccessor",
"minecraft.chest.EnderChestBlockEntityMixin",

"minecraft.decordatedpot.DecoratedPotBlockEntityMixin",

"minecraft.shulker.ShulkerBoxBlockEntityMixin",

"minecraft.sign.AbstractSignBlockEntityRendererMixin",

"sodium.AbstractBlockRenderContextAccessor",
"sodium.BlockRendererMixin",
"sodium.SodiumWorldRendererMixin",

"minecraft.AbstractBlockMixin",
"minecraft.BlockEntityMixin",
"minecraft.ClientWorldMixin",
"minecraft.OrderedRenderCommandQueueImplMixin",
"minecraft.RenderLayersMixin",
"minecraft.ResourcePackManagerMixin",
"minecraft.WorldRendererMixin"
"minecraft.WorldRendererMixin",
"minecraft.ModelCommandRendererMixin"
],
"server": [],
"injectors": {
Expand Down