Skip to content

Commit 5e3c7e7

Browse files
committed
fixed a compatibility issue with iris.
Now compatible with A Good Place mod.
1 parent 8a0d5d8 commit 5e3c7e7

File tree

47 files changed

+375
-234
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+375
-234
lines changed

Diff for: common/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ dependencies {
6868
/* Particle Core */
6969
// modCompileOnly "maven.modrinth:particle-core:0.2.5+1.20.1"
7070

71+
/* A Good Place */
72+
modCompileOnly "curse.maven:a-good-place-1020455:6277409" // 1.2.6
73+
7174
/* Physics Mod */
7275
modCompileOnly fileTree(dir: '../libs', include: 'physics-mod-pro-v171b-fabric-1.20.1.jar')
7376
}

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
4747
yield !ModListHelper.IS_FORGE;
4848
}
4949
yield switch (split[1]) {
50-
case "particlerain_vs" -> ModListHelper.FABRIC_PARTICLERAIN_LOADED && ModListHelper.FABRIC_VS_LOADED;
51-
case "particlerain_create" -> ModListHelper.FABRIC_PARTICLERAIN_LOADED && ModListHelper.FABRIC_CREATE_LOADED;
50+
case "particlerain_vs" ->
51+
ModListHelper.FABRIC_PARTICLERAIN_LOADED && ModListHelper.FABRIC_VS_LOADED;
52+
case "particlerain_create" ->
53+
ModListHelper.FABRIC_PARTICLERAIN_LOADED && ModListHelper.FABRIC_CREATE_LOADED;
5254
case "particlerain" -> ModListHelper.FABRIC_PARTICLERAIN_LOADED;
5355
case "create_5" -> ModListHelper.FABRIC_CREATE_LOADED && ModListHelper.CREATE_MAJOR_VERSION < 6;
5456
case "create_6" -> ModListHelper.FABRIC_CREATE_LOADED && ModListHelper.CREATE_MAJOR_VERSION == 6;
@@ -73,11 +75,10 @@ yield switch (split[1]) {
7375
case "create" -> ModListHelper.CREATE_LOADED;
7476
case "iris_like" -> ModListHelper.IRIS_LIKE_LOADED;
7577
case "lodestone" -> ModListHelper.LODESTONE_LOADED;
76-
case "hexcasting" -> ModListHelper.HEXCASTING_LOADED;
7778
case "flywheel" -> ModListHelper.FLYWHEEL_LOADED && ModListHelper.FLYWHEEL_MAJOR_VERSION == 1;
7879
case "particle_core" -> ModListHelper.PARTICLE_CORE_LOADED;
7980
case "physicsmod" -> ModListHelper.PHYSICSMOD_LOADED;
80-
// case "enhancedblockentities" -> ModListHelper.ENHANCEDBLOCKENTITIES_LOADED;
81+
case "a_good_place" -> ModListHelper.A_GOOD_PLACE_LOADED;
8182
default -> throw new IllegalArgumentException("Unknown mixin: " + mixinClassName);
8283
};
8384
}

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

+104-25
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package fun.qu_an.minecraft.asyncparticles.client;
22

33
import com.mojang.blaze3d.pipeline.RenderTarget;
4+
import com.mojang.blaze3d.systems.RenderSystem;
45
import com.mojang.blaze3d.vertex.BufferBuilder;
56
import com.mojang.blaze3d.vertex.PoseStack;
7+
import com.mojang.blaze3d.vertex.Tesselator;
68
import com.mojang.blaze3d.vertex.VertexFormat;
79
import com.mojang.logging.LogUtils;
10+
import fun.qu_an.minecraft.asyncparticles.client.addon.ParticleAddon;
811
import fun.qu_an.minecraft.asyncparticles.client.util.FakeBufferBuilder;
912
import fun.qu_an.minecraft.asyncparticles.client.util.FakeTesselator;
1013
import fun.qu_an.minecraft.asyncparticles.client.util.TryAndStoreFakeBufferBuilder;
@@ -15,6 +18,9 @@
1518
import net.irisshaders.iris.fantastic.PhasedParticleEngine;
1619
import net.irisshaders.iris.pipeline.WorldRenderingPipeline;
1720
import net.irisshaders.iris.shaderpack.properties.ParticleRenderingSettings;
21+
import net.minecraft.CrashReport;
22+
import net.minecraft.CrashReportCategory;
23+
import net.minecraft.ReportedException;
1824
import net.minecraft.Util;
1925
import net.minecraft.client.Camera;
2026
import net.minecraft.client.Minecraft;
@@ -153,8 +159,39 @@ public static void start(PoseStack poseStack, float f, Camera camera, LightTextu
153159
profiler.pop();
154160
}
155161

162+
public static void join(PoseStack poseStack, float f, Camera camera, LightTexture lightTexture) {
163+
if (isMixedRenderingSetting()) {
164+
return;
165+
}
166+
Minecraft mc = Minecraft.getInstance();
167+
ProfilerFiller profiler = mc.getProfiler();
168+
profiler.popPush("async_particles");
169+
LevelRenderer levelRenderer = mc.levelRenderer;
170+
if (levelRenderer.transparencyChain != null) {
171+
RenderTarget particlesTarget = levelRenderer.getParticlesTarget();
172+
particlesTarget.clear(Minecraft.ON_OSX);
173+
particlesTarget.copyDepthFrom(mc.getMainRenderTarget());
174+
RenderStateShard.PARTICLES_TARGET.setupRenderState();
175+
}
176+
profiler.push("wait_for_async_tasks");
177+
asyncTask.join();
178+
profiler.pop();
179+
isStart = false;
180+
181+
MultiBufferSource.BufferSource bufferSource = mc.levelRenderer.renderBuffers.bufferSource();
182+
ParticleEngine particleEngine = mc.particleEngine;
183+
if (ModListHelper.IRIS_LIKE_LOADED) {
184+
((PhasedParticleEngine) particleEngine).setParticleRenderingPhase(ParticleRenderingPhase.EVERYTHING);
185+
}
186+
particleEngine.render(poseStack, bufferSource, lightTexture, camera, f);
187+
188+
if (levelRenderer.transparencyChain != null) {
189+
RenderStateShard.PARTICLES_TARGET.clearRenderState();
190+
}
191+
}
192+
156193
public static void irisOpaque(PoseStack poseStack, float f, Camera camera, LightTexture lightTexture) {
157-
if (!ModListHelper.IRIS_LIKE_LOADED || !IrisApi.getInstance().isShaderPackInUse() || getRenderingSettings() != ParticleRenderingSettings.MIXED) {
194+
if (!isMixedRenderingSetting()) {
158195
return;
159196
}
160197
Minecraft mc = Minecraft.getInstance();
@@ -171,10 +208,18 @@ public static void irisOpaque(PoseStack poseStack, float f, Camera camera, Light
171208
ParticleEngine particleEngine = mc.particleEngine;
172209
((PhasedParticleEngine) particleEngine).setParticleRenderingPhase(ParticleRenderingPhase.OPAQUE);
173210
particleEngine.render(poseStack, bufferSource, lightTexture, camera, f);
211+
212+
if (levelRenderer.getItemEntityTarget() != null) {
213+
levelRenderer.getItemEntityTarget().clear(Minecraft.ON_OSX);
214+
levelRenderer.getItemEntityTarget().copyDepthFrom(mc.getMainRenderTarget());
215+
mc.getMainRenderTarget().bindWrite(false);
216+
}
217+
// poseStack1.last().pose().set(pose);
218+
// RenderSystem.applyModelViewMatrix();
174219
}
175220

176221
public static void irisTranslucent(PoseStack poseStack, float f, Camera camera, LightTexture lightTexture) {
177-
if (!ModListHelper.IRIS_LIKE_LOADED || !IrisApi.getInstance().isShaderPackInUse() || getRenderingSettings() != ParticleRenderingSettings.MIXED) {
222+
if (!isMixedRenderingSetting()) {
178223
return;
179224
}
180225
Minecraft mc = Minecraft.getInstance();
@@ -198,35 +243,69 @@ public static void irisTranslucent(PoseStack poseStack, float f, Camera camera,
198243
}
199244
}
200245

201-
public static void join(PoseStack poseStack, float f, Camera camera, LightTexture lightTexture) {
202-
if (ModListHelper.IRIS_LIKE_LOADED && IrisApi.getInstance().isShaderPackInUse() && getRenderingSettings() == ParticleRenderingSettings.MIXED) {
246+
// FIXME: 这是个临时解决方案,最好找出 ModelMatrixStack 错乱的原因
247+
public static void irisSync(PoseStack poseStack, float f, Camera camera, LightTexture lightTexture) {
248+
if (!isMixedRenderingSetting()) {
203249
return;
204250
}
251+
PoseStack poseStack2 = null;
205252
Minecraft mc = Minecraft.getInstance();
206-
ProfilerFiller profiler = mc.getProfiler();
207-
profiler.popPush("async_particles");
208-
LevelRenderer levelRenderer = mc.levelRenderer;
209-
if (levelRenderer.transparencyChain != null) {
210-
RenderTarget particlesTarget = levelRenderer.getParticlesTarget();
211-
particlesTarget.clear(Minecraft.ON_OSX);
212-
particlesTarget.copyDepthFrom(mc.getMainRenderTarget());
213-
RenderStateShard.PARTICLES_TARGET.setupRenderState();
214-
}
215-
profiler.push("wait_for_async_tasks");
216-
asyncTask.join();
217-
profiler.pop();
218-
isStart = false;
219-
220-
MultiBufferSource.BufferSource bufferSource = mc.levelRenderer.renderBuffers.bufferSource();
221253
ParticleEngine particleEngine = mc.particleEngine;
222-
if (ModListHelper.IRIS_LIKE_LOADED) {
223-
((PhasedParticleEngine) particleEngine).setParticleRenderingPhase(ParticleRenderingPhase.EVERYTHING);
254+
for (Map.Entry<ParticleRenderType, Queue<Particle>> entry : particleEngine.particles.entrySet()) {
255+
ParticleRenderType particleRenderType = entry.getKey();
256+
if (particleRenderType == ParticleRenderType.NO_RENDER) {
257+
continue;
258+
}
259+
Queue<Particle> queue = entry.getValue();
260+
if (queue.isEmpty()
261+
|| FORMATS.get(particleRenderType) != EMPTY_FORMAT) {
262+
continue;
263+
}
264+
if (poseStack2 == null) {
265+
lightTexture.turnOnLightLayer();
266+
RenderSystem.enableDepthTest();
267+
poseStack2 = RenderSystem.getModelViewStack();
268+
poseStack2.pushPose();
269+
poseStack2.mulPoseMatrix(poseStack.last().pose());
270+
RenderSystem.applyModelViewMatrix();
271+
}
272+
particleRenderType.begin(FakeBufferBuilder.INSTANCE, particleEngine.textureManager);
273+
for (Particle particle : queue) {
274+
renderSync0(f, camera, particle, FakeBufferBuilder.INSTANCE, particleRenderType);
275+
}
224276
}
225-
particleEngine.render(poseStack, bufferSource, lightTexture, camera, f);
277+
if (poseStack2 != null) {
278+
poseStack2.popPose();
279+
RenderSystem.applyModelViewMatrix();
280+
RenderSystem.depthMask(true);
281+
RenderSystem.disableBlend();
282+
lightTexture.turnOffLightLayer();
283+
}
284+
}
226285

227-
if (levelRenderer.transparencyChain != null) {
228-
RenderStateShard.PARTICLES_TARGET.clearRenderState();
286+
private static void renderSync0(float f, Camera camera, Particle particle, BufferBuilder bufferBuilder, ParticleRenderType particleRenderType) {
287+
if (!particle.isAlive()) {
288+
return;
289+
}
290+
if (((ParticleAddon) particle).shouldCull() && !frustum.isVisible(particle.getBoundingBox())) {
291+
return;
229292
}
293+
float g = ((ParticleAddon) particle).asyncParticles$isTicked() ? f : f + 1f;
294+
try {
295+
particle.render(bufferBuilder, camera, g);
296+
} catch (Throwable throwable) {
297+
CrashReport crashReport = CrashReport.forThrowable(throwable, "Rendering Particle");
298+
CrashReportCategory crashReportCategory = crashReport.addCategory("Particle being rendered");
299+
Objects.requireNonNull(particle);
300+
crashReportCategory.setDetail("Particle", particle::toString);
301+
Objects.requireNonNull(particleRenderType);
302+
crashReportCategory.setDetail("Particle Type", particleRenderType::toString);
303+
throw new ReportedException(crashReport);
304+
}
305+
}
306+
307+
public static boolean isMixedRenderingSetting() {
308+
return ModListHelper.IRIS_LIKE_LOADED && IrisApi.getInstance().isShaderPackInUse() && getRenderingSettings() == ParticleRenderingSettings.MIXED;
230309
}
231310

232311
private static ParticleRenderingSettings getRenderingSettings() {
@@ -302,7 +381,7 @@ public static void recordSync(ParticleRenderType particleRenderType, Particle pa
302381
}
303382
}
304383

305-
public static List<? extends Particle> getSync(ParticleRenderType particleRenderType) {
384+
public static List<Particle> getSync(ParticleRenderType particleRenderType) {
306385
List<Particle> list = SYNC_PARTICLES.get(particleRenderType);
307386
return list == null ? List.of() : list;
308387
}

Diff for: common/src/main/java/fun/qu_an/minecraft/asyncparticles/client/AsyncTicker.java

+30-19
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package fun.qu_an.minecraft.asyncparticles.client;
22

33
import com.google.common.collect.EvictingQueue;
4-
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
5-
import fun.qu_an.minecraft.asyncparticles.client.addon.LightCachedParticleAddon;
64
import fun.qu_an.minecraft.asyncparticles.client.addon.ParticleAddon;
7-
import fun.qu_an.minecraft.asyncparticles.client.compat.vs2.VSClientUtils;
5+
import fun.qu_an.minecraft.asyncparticles.client.compat.a_good_place.AGoodPlaceCompat;
6+
import fun.qu_an.minecraft.asyncparticles.client.compat.particlerain.ParticleRainCompat;
7+
import fun.qu_an.minecraft.asyncparticles.client.compat.vs2.VSCompat;
88
import fun.qu_an.minecraft.asyncparticles.client.config.SimplePropertiesConfig;
9+
import fun.qu_an.minecraft.asyncparticles.client.mixin.a_good_place.InvokerBlocksParticlesManager;
910
import net.minecraft.ReportedException;
1011
import net.minecraft.Util;
1112
import net.minecraft.client.Minecraft;
@@ -16,6 +17,7 @@
1617
import net.minecraft.util.Mth;
1718
import net.minecraft.util.profiling.ProfilerFiller;
1819
import net.minecraft.world.level.chunk.MissingPaletteEntryException;
20+
import nl.enjarai.a_good_place.particles.BlocksParticlesManager;
1921
import org.apache.logging.log4j.LogManager;
2022
import org.apache.logging.log4j.Logger;
2123
import org.jetbrains.annotations.NotNull;
@@ -63,7 +65,6 @@ public class AsyncTicker {
6365
private static boolean tickingSync;
6466
public static boolean shouldTickParticles = true;
6567
public static CompletableFuture<Void> particleCleanup;
66-
public static Operation<Void> tickParticleEngine;
6768
private final static List<Runnable> END_TICK_EVENTS = new ArrayList<>();
6869
public final static List<Runnable> END_TICK_OPERATIONS = new ArrayList<>();
6970
private static CompletableFuture<Void> particleFuture;
@@ -123,6 +124,8 @@ public static void onRunAllTasks() {
123124
}
124125

125126
public static void onTickBefore(int j) {
127+
ProfilerFiller profiler = Minecraft.getInstance().getProfiler();
128+
profiler.push("async_particles");
126129
if (j != 0) {
127130
if (blockEntityTickFuture != null) {
128131
blockEntityTickFuture.join();
@@ -176,24 +179,22 @@ public static void onTickBefore(int j) {
176179
particleCleanup = CompletableFuture.allOf(futures);
177180
}
178181
}
179-
}
180-
181-
public static void updateLightCache(LightCachedParticleAddon lightCachedParticle) {
182+
profiler.pop();
182183
}
183184

184185
public static void onTickAfter(int j) {
185186
Minecraft mc = Minecraft.getInstance();
186-
if (tickParticleEngine != null) {
187-
ProfilerFiller profiler = mc.getProfiler();
188-
profiler.push("particles");
187+
ProfilerFiller profiler = mc.getProfiler();
188+
profiler.push("async_particles");
189+
if (!mc.isPaused()){
190+
profiler.push("particle_tick");
189191
try {
190-
tickParticleEngine.call();
192+
mc.particleEngine.tick();
191193
} catch (Exception e) {
192194
if (mc.level != null && mc.player != null) {
193195
throw e;
194196
}
195197
}
196-
tickParticleEngine = null;
197198
profiler.pop();
198199
}
199200
if (j != 0) {
@@ -246,10 +247,7 @@ && isTolerable(e)) {
246247
throw toThrowDirectly(e);
247248
}))
248249
.toArray(CompletableFuture[]::new)));
249-
}
250-
251-
public static boolean isTickingSync() {
252-
return tickingSync;
250+
profiler.pop();
253251
}
254252

255253
private static Void tickBeforeExceptionally(Throwable e) {
@@ -285,6 +283,10 @@ public static boolean isTolerable(@NotNull Throwable e) {
285283

286284
/* Sync Ticking */
287285

286+
public static boolean isTickingSync() {
287+
return tickingSync;
288+
}
289+
288290
public static void tickSync() {
289291
if (SYNC_PARTICLES.isEmpty()) {
290292
return;
@@ -303,9 +305,7 @@ public static void tickSync() {
303305
((ParticleAddon) particle).asyncParticles$setTicked();
304306
}
305307
if (ModListHelper.VS_LOADED) {
306-
if (VSClientUtils.isOutOfSight(particle)) {
307-
particle.remove();
308-
}
308+
VSCompat.removeIfOutSight(particle);
309309
}
310310
if (!particle.isAlive()) {
311311
// we manage the count in cleanup task
@@ -427,6 +427,17 @@ public static void destroy() {
427427
cancelled = false;
428428
}
429429

430+
public static void onParticleEngineClear() {
431+
// this fix a good placement mod block invisible
432+
if (ModListHelper.A_GOOD_PLACE_LOADED) {
433+
AGoodPlaceCompat.onParticleEngineClear();
434+
}
435+
// this fix particlerain's particle count management bug
436+
if (ModListHelper.PARTICLERAIN_LOADED) {
437+
ParticleRainCompat.clearCounters();
438+
}
439+
}
440+
430441
@FunctionalInterface
431442
public interface MinecraftConsumer {
432443
void accept(Minecraft mc);

Diff for: common/src/main/java/fun/qu_an/minecraft/asyncparticles/client/AsyncparticlesClient.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package fun.qu_an.minecraft.asyncparticles.client;
22

3-
import fun.qu_an.minecraft.asyncparticles.client.compat.create.CreateUtils;
4-
import fun.qu_an.minecraft.asyncparticles.client.compat.particlerain.ParticleRainUtils;
3+
import fun.qu_an.minecraft.asyncparticles.client.compat.create.CreateCompat;
4+
import fun.qu_an.minecraft.asyncparticles.client.compat.particlerain.ParticleRainCompat;
55
import fun.qu_an.minecraft.asyncparticles.client.compat.particlerain.WeatherParticleAddon;
66
import fun.qu_an.minecraft.asyncparticles.client.compat.vs2.VSClientUtils;
77
import fun.qu_an.minecraft.asyncparticles.client.config.SimplePropertiesConfig;
@@ -25,7 +25,7 @@ public static void init() {
2525
if (shipMovement == null) {
2626
return v;
2727
}
28-
ParticleRainUtils.onShipCollision(level, location, shipMovement, aabb);
28+
ParticleRainCompat.onShipCollision(level, location, shipMovement, aabb);
2929
return shipMovement;
3030
});
3131
WeatherParticleAddon.CollisionFunction function = (level, location, v, aabb) -> {
@@ -37,15 +37,15 @@ public static void init() {
3737
}
3838
if (ModListHelper.CREATE_LOADED) {
3939
WeatherParticleAddon.Type.RAIN.register((level, position, motion, aabb) -> {
40-
Vec3 collide = CreateUtils.collideMotionWithContraptions(level, position, motion, aabb);
40+
Vec3 collide = CreateCompat.collideMotionWithContraptions(level, position, motion, aabb);
4141
if (collide == null) {
4242
return motion;
4343
}
44-
ParticleRainUtils.onCreateCollision(level, motion, collide, aabb);
44+
ParticleRainCompat.onCreateCollision(level, motion, collide, aabb);
4545
return collide;
4646
});
4747
WeatherParticleAddon.CollisionFunction function = (level, position, motion, aabb) -> {
48-
Vec3 collide = CreateUtils.collideMotionWithContraptions(level, position, motion, aabb);
48+
Vec3 collide = CreateCompat.collideMotionWithContraptions(level, position, motion, aabb);
4949
return collide == null ? motion : collide;
5050
};
5151
WeatherParticleAddon.Type.SNOW.register(function);

0 commit comments

Comments
 (0)