Skip to content

Commit 37d23e1

Browse files
committed
fix a crash with modernui;
try compat draconicevolution; try compat Gateways to Eternity
1 parent 8c15a4c commit 37d23e1

File tree

22 files changed

+486
-52
lines changed

22 files changed

+486
-52
lines changed

common/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dependencies {
3535
// modCompileOnly "maven.modrinth:pretty-rain:TGjK6ChS"
3636

3737
/* Effectual */
38-
modCompileOnly 'maven.modrinth:effectual:0.5.2-1.20.1'
38+
modCompileOnly 'maven.modrinth:effectual:0.6.0-1.20.1'
3939

4040
/* Mmmmmmmmmmmm */
4141
// modCompileOnly 'maven.modrinth:mmmmmmmmmmmm:1.20-2.0.5'

common/src/main/java/fun/qu_an/minecraft/asyncparticles/client/APMixinPlugin.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ yield switch (split[1]) {
7070
default -> throw new IllegalArgumentException("Unknown legacy mod mixin: " + mixinClassName);
7171
};
7272
}
73-
case "fake_renders" -> true;
73+
case "fake_renders",
74+
"off_thread_access" -> true;
75+
case "modernui" -> ModListHelper.MODERN_UI_LOADED;
7476
case "vs2" -> ModListHelper.VS_LOADED;
7577
case "create" -> ModListHelper.CREATE_LOADED;
7678
case "iris_like" -> ModListHelper.IRIS_LIKE_LOADED;

common/src/main/java/fun/qu_an/minecraft/asyncparticles/client/AsyncRenderer.java

-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ private static void addSyncByClassName(String className) {
9393
private static final Map<ParticleRenderType, List<Particle>> SYNC_PARTICLES = Collections.synchronizedMap(new IdentityHashMap<>());
9494
public static final ForkJoinPool EXECUTOR;
9595
public static final String THREAD_PREFIX = "AsyncParticleRenderer";
96-
public static final Set<Thread> PARTICLE_THREADS = Collections.synchronizedSet(Collections.newSetFromMap(new WeakHashMap<>()));
9796

9897
static {
9998
AtomicInteger workerCount = new AtomicInteger(1);
@@ -112,7 +111,6 @@ protected void onTermination(Throwable throwable) {
112111
};
113112
forkJoinWorkerThread.setName(THREAD_PREFIX + "-" + workerCount.getAndIncrement());
114113
forkJoinWorkerThread.setDaemon(true);
115-
PARTICLE_THREADS.add(forkJoinWorkerThread);
116114
return forkJoinWorkerThread;
117115
}, Util::onThreadException, true);
118116
}

common/src/main/java/fun/qu_an/minecraft/asyncparticles/client/ModListHelper.java

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public class ModListHelper {
6161
public static final boolean PHYSICSMOD_LOADED = isModLoaded("physicsmod");
6262
/* Draconic Evolution */
6363
public static final boolean FORGE_DRACONIC_EVOLUTION_LOADED = isForgeModLoaded("draconicevolution");
64+
/* Modern UI */
65+
public static final boolean MODERN_UI_LOADED = isModLoaded("modernui");
6466

6567
@ExpectPlatform
6668
private static boolean isForge() {

common/src/main/java/fun/qu_an/minecraft/asyncparticles/client/compat/create/CreateCompat.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.simibubi.create.foundation.collision.Matrix3d;
66
import com.simibubi.create.foundation.collision.OrientedBB;
77
import com.simibubi.create.foundation.utility.BlockHelper;
8-
import dev.architectury.injectables.annotations.ExpectPlatform;
98
import fun.qu_an.minecraft.asyncparticles.client.ModListHelper;
109
import fun.qu_an.minecraft.asyncparticles.client.mixin.create.InvokerContraptionCollider;
1110
import net.minecraft.client.multiplayer.ClientLevel;
@@ -134,7 +133,7 @@ public static boolean collideWithContraption(ClientLevel level,
134133
public static Vec3 collideMotionWithContraptions(ClientLevel level, Vec3 position, Vec3 motion, AABB bounds) {
135134
AABB bounds1 = bounds.inflate(0.1).move(motion);
136135
Vector3d result = new Vector3d(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE);
137-
forEachContraption(level, bounds1, contraptionEntity -> {
136+
forEachContraption(level, contraptionEntity -> {
138137
Vec3 vec3 = collideMotionWithContraption(level, position, motion, bounds1, contraptionEntity);
139138
if (vec3 == null) {
140139
return true;
@@ -149,7 +148,7 @@ public static Vec3 collideMotionWithContraptions(ClientLevel level, Vec3 positio
149148
return new Vec3(result.x, result.y, result.z);
150149
}
151150

152-
public static void forEachContraption(ClientLevel level, AABB bounds1, Predicate<AbstractContraptionEntity> consumer) {
151+
public static void forEachContraption(ClientLevel level, Predicate<AbstractContraptionEntity> consumer) {
153152
try {
154153
for (WeakReference<AbstractContraptionEntity> r : contraptions(level)) {
155154
AbstractContraptionEntity contraptionEntity = r.get();
@@ -426,7 +425,7 @@ public static boolean isUnderContraption(ClientLevel level, double x, double y,
426425
boolean[] b = {false};
427426
Vec3 pos = new Vec3(x, y, z);
428427
AABB bounds = new AABB(x - 1, y - 1, z - 1, x + 1, Math.max(y + 16, level.getMaxBuildHeight()), z + 1);
429-
forEachContraption(level, bounds, contraptionEntity -> {
428+
forEachContraption(level, contraptionEntity -> {
430429
boolean b1 = collideWithContraption(level, pos, Vec3.ZERO, bounds, contraptionEntity, true);
431430
// estimate = true for a better performance
432431
if (!b1) {

common/src/main/java/fun/qu_an/minecraft/asyncparticles/client/compat/particlerain/fabric/ParticleRainCompatImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static void onCreateCollision(@NotNull ClientLevel level, Vec3 originalMo
7171
AABB aabb1 = new AABB(center.x, aabb.minY - 1, center.z, center.x, aabb.minY, center.z);
7272
Vec3 spawnPos = new Vec3(center.x, aabb.minY, center.z);
7373
Vec3 motion1 = originalMotion.scale(2);
74-
CreateCompat.forEachContraption(level, aabb1, contraptionEntity -> {
74+
CreateCompat.forEachContraption(level, contraptionEntity -> {
7575
if (CreateCompat.collideWithContraption(level, spawnPos, motion1, aabb1, contraptionEntity)) {
7676
Minecraft.getInstance().particleEngine
7777
.createParticle(ParticleTypes.RAIN, spawnPos.x, spawnPos.y, spawnPos.z, 0, 0, 0);

common/src/main/java/fun/qu_an/minecraft/asyncparticles/client/mixin/MixinClassInstanceMultiMap.java

-27
This file was deleted.

common/src/main/java/fun/qu_an/minecraft/asyncparticles/client/mixin/fabric/effectual/MixinAllEffects.java

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.imeetake.effects.Bubbles.BubbleBreathEffect;
44
import com.imeetake.effects.Bubbles.BubbleChestEffect;
5+
import com.imeetake.effects.Bubbles.BubblePotsEffect;
56
import com.imeetake.effects.CaveDust.CaveDustEffect;
67
import com.imeetake.effects.Firefly.FireflyEffect;
78
import com.imeetake.effects.GoldGlow.LanternGlowEffect;
@@ -19,9 +20,11 @@
1920
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
2021
import net.fabricmc.fabric.api.event.Event;
2122
import org.spongepowered.asm.mixin.Mixin;
23+
import org.spongepowered.asm.mixin.Pseudo;
2224
import org.spongepowered.asm.mixin.injection.At;
2325
import org.spongepowered.asm.mixin.injection.Redirect;
2426

27+
@Pseudo
2528
@Mixin(value = {
2629
SteamEffect.class,
2730
WaterDripEffect.class,
@@ -38,6 +41,7 @@
3841
CaveDustEffect.class,
3942
BubbleBreathEffect.class,
4043
BubbleChestEffect.class,
44+
BubblePotsEffect.class,
4145
})
4246
public abstract class MixinAllEffects {
4347
@Redirect(method = "register", remap = false, at = @At(value = "INVOKE", remap = false, target = "Lnet/fabricmc/fabric/api/event/Event;register(Ljava/lang/Object;)V"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package fun.qu_an.minecraft.asyncparticles.client.mixin.modernui;
2+
3+
import com.mojang.blaze3d.systems.RenderSystem;
4+
import fun.qu_an.minecraft.asyncparticles.client.util.ThreadUtil;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
import org.spongepowered.asm.mixin.injection.Inject;
8+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
9+
10+
@Mixin(value = RenderSystem.class, remap = false)
11+
public class MixinRenderSystem {
12+
@Inject(method = "assertOnRenderThread", at = @At("HEAD"))
13+
private static void onRenderThread(CallbackInfo ci) {
14+
ThreadUtil.assertNotParticleRendererThread();
15+
}
16+
}

common/src/main/java/fun/qu_an/minecraft/asyncparticles/client/mixin/MixinChunkAccess.java common/src/main/java/fun/qu_an/minecraft/asyncparticles/client/mixin/off_thread_access/MixinChunkAccess.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package fun.qu_an.minecraft.asyncparticles.client.mixin;
1+
package fun.qu_an.minecraft.asyncparticles.client.mixin.off_thread_access;
22

33
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
44
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package fun.qu_an.minecraft.asyncparticles.client.mixin.off_thread_access;
2+
3+
import fun.qu_an.minecraft.asyncparticles.client.util.IterationSafeArrayList;
4+
import net.minecraft.util.ClassInstanceMultiMap;
5+
import org.spongepowered.asm.mixin.Final;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.Mutable;
8+
import org.spongepowered.asm.mixin.Shadow;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
import org.spongepowered.asm.mixin.injection.Inject;
11+
import org.spongepowered.asm.mixin.injection.Redirect;
12+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
13+
14+
import java.util.List;
15+
import java.util.Map;
16+
import java.util.concurrent.ConcurrentHashMap;
17+
import java.util.stream.Collector;
18+
import java.util.stream.Collectors;
19+
20+
// some mod get entities when ticking particles, may cause a CME
21+
@Mixin(ClassInstanceMultiMap.class)
22+
public class MixinClassInstanceMultiMap {
23+
@Final
24+
@Mutable
25+
@Shadow
26+
private Map<Class<?>, List<?>> byClass;
27+
28+
@Mutable
29+
@Final
30+
@Shadow
31+
private List<?> allInstances;
32+
33+
// FIXME: 这样不行啊,到处漏风
34+
@Inject(method = "<init>", at = @At(value = "RETURN"))
35+
private void newHashMap(Class<?> baseClass, CallbackInfo ci) {
36+
byClass = new ConcurrentHashMap<>();
37+
allInstances = new IterationSafeArrayList<>();
38+
byClass.put(baseClass, allInstances);
39+
}
40+
41+
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"))
42+
private <K, V> V put(Map<K, V> map, K key, V value) {
43+
// do nothing
44+
return null;
45+
}
46+
47+
@Redirect(method = "method_15217", at = @At(value = "INVOKE", target = "Ljava/util/stream/Collectors;toList()Ljava/util/stream/Collector;"))
48+
private <T> Collector<T, ?, List<T>> collect() {
49+
return Collectors.toCollection(IterationSafeArrayList::new);
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package fun.qu_an.minecraft.asyncparticles.client.mixin.off_thread_access;
2+
3+
import net.minecraft.core.Registry;
4+
import net.minecraft.world.level.ChunkPos;
5+
import net.minecraft.world.level.Level;
6+
import net.minecraft.world.level.LevelHeightAccessor;
7+
import net.minecraft.world.level.biome.Biome;
8+
import net.minecraft.world.level.chunk.ChunkAccess;
9+
import net.minecraft.world.level.chunk.LevelChunk;
10+
import net.minecraft.world.level.chunk.LevelChunkSection;
11+
import net.minecraft.world.level.chunk.UpgradeData;
12+
import net.minecraft.world.level.levelgen.blending.BlendingData;
13+
import org.jetbrains.annotations.Nullable;
14+
import org.spongepowered.asm.mixin.Final;
15+
import org.spongepowered.asm.mixin.Mixin;
16+
import org.spongepowered.asm.mixin.Shadow;
17+
import org.spongepowered.asm.mixin.injection.At;
18+
import org.spongepowered.asm.mixin.injection.Inject;
19+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
20+
21+
import java.util.HashMap;
22+
import java.util.concurrent.ConcurrentHashMap;
23+
24+
@Mixin(LevelChunk.class)
25+
public abstract class MixinLevelChunk extends ChunkAccess {
26+
@Shadow
27+
@Final
28+
Level level;
29+
30+
public MixinLevelChunk(ChunkPos chunkPos, UpgradeData upgradeData, LevelHeightAccessor levelHeightAccessor, Registry<Biome> biomeRegistry, long inhabitedTime, @Nullable LevelChunkSection[] sections, @Nullable BlendingData blendingData) {
31+
super(chunkPos, upgradeData, levelHeightAccessor, biomeRegistry, inhabitedTime, sections, blendingData);
32+
}
33+
34+
// FIXME: any better way to do this?
35+
@Inject(method = "<init>(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/level/ChunkPos;Lnet/minecraft/world/level/chunk/UpgradeData;Lnet/minecraft/world/ticks/LevelChunkTicks;Lnet/minecraft/world/ticks/LevelChunkTicks;J[Lnet/minecraft/world/level/chunk/LevelChunkSection;Lnet/minecraft/world/level/chunk/LevelChunk$PostLoadProcessor;Lnet/minecraft/world/level/levelgen/blending/BlendingData;)V", at = @At("RETURN"))
36+
private void onInit(CallbackInfo ci) {
37+
if (level.isClientSide) {
38+
blockEntities = new ConcurrentHashMap<>();
39+
} else {
40+
blockEntities = new HashMap<>();
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)