|
1 | 1 | package org.embeddedt.modernfix.common.mixin.safety; |
2 | 2 |
|
| 3 | +import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; |
| 4 | +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
| 5 | +import net.minecraft.client.Minecraft; |
| 6 | +import net.minecraft.client.model.EntityModel; |
3 | 7 | import net.minecraft.client.renderer.entity.LivingEntityRenderer; |
4 | 8 | import net.minecraft.client.renderer.entity.layers.RenderLayer; |
| 9 | +import net.minecraft.world.entity.Entity; |
| 10 | +import org.embeddedt.modernfix.ModernFix; |
5 | 11 | import org.embeddedt.modernfix.annotation.ClientOnlyMixin; |
6 | | -import org.spongepowered.asm.mixin.Final; |
7 | 12 | import org.spongepowered.asm.mixin.Mixin; |
8 | | -import org.spongepowered.asm.mixin.Mutable; |
9 | 13 | import org.spongepowered.asm.mixin.Shadow; |
10 | | -import org.spongepowered.asm.mixin.injection.At; |
11 | | -import org.spongepowered.asm.mixin.injection.Inject; |
12 | | -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
13 | | - |
14 | | -import java.util.Collections; |
15 | | -import java.util.List; |
16 | 14 |
|
17 | 15 | @Mixin(LivingEntityRenderer.class) |
18 | 16 | @ClientOnlyMixin |
19 | | -public class LivingEntityRendererMixin { |
20 | | - @Shadow @Final @Mutable |
21 | | - protected List<RenderLayer<?, ?>> layers; |
| 17 | +public abstract class LivingEntityRendererMixin<T extends Entity, M extends EntityModel<T>> { |
| 18 | + @Shadow |
| 19 | + public abstract boolean addLayer(RenderLayer<T, M> layer); |
22 | 20 |
|
23 | | - @Inject(method = "<init>", at = @At("RETURN")) |
24 | | - private void synchronizeLayerList(CallbackInfo ci) { |
25 | | - /* allows buggy mods to call addLayer concurrently, order is not deterministic but can't fix that */ |
26 | | - this.layers = Collections.synchronizedList(layers); |
| 21 | + /** |
| 22 | + * @author embeddedt |
| 23 | + * @reason avoid CMEs from buggy mods calling addLayer on wrong thread |
| 24 | + */ |
| 25 | + @WrapMethod(method = "addLayer") |
| 26 | + private boolean handleOffThreadLayerAdd(RenderLayer<T, M> layer, Operation<Boolean> original) { |
| 27 | + if (!Minecraft.getInstance().isSameThread()) { |
| 28 | + ModernFix.LOGGER.error("LivingEntityRenderer.addLayer called on wrong thread", new Exception()); |
| 29 | + Minecraft.getInstance().tell(() -> this.addLayer(layer)); |
| 30 | + return true; |
| 31 | + } |
| 32 | + return original.call(layer); |
27 | 33 | } |
28 | 34 | } |
0 commit comments