Skip to content

Commit 2486573

Browse files
committed
See ya later streamagator
1 parent 4503482 commit 2486573

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package dev.ithundxr.railwaystweaks.mixin.client.compat.create;
2+
3+
import com.jozufozu.flywheel.event.BeginFrameEvent;
4+
import com.simibubi.create.content.contraptions.AbstractContraptionEntity;
5+
import com.simibubi.create.content.contraptions.Contraption;
6+
import com.simibubi.create.content.contraptions.ContraptionHandler;
7+
import com.simibubi.create.content.contraptions.render.ContraptionRenderInfo;
8+
import com.simibubi.create.content.contraptions.render.ContraptionRenderingWorld;
9+
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
10+
import net.minecraft.world.level.Level;
11+
import org.spongepowered.asm.mixin.Final;
12+
import org.spongepowered.asm.mixin.Mixin;
13+
import org.spongepowered.asm.mixin.Overwrite;
14+
import org.spongepowered.asm.mixin.Shadow;
15+
16+
import java.lang.ref.WeakReference;
17+
import java.util.List;
18+
19+
@Mixin(ContraptionRenderingWorld.class)
20+
public abstract class ContraptionRenderingWorldMixin<C extends ContraptionRenderInfo> {
21+
@Shadow @Final protected Level world;
22+
23+
@Shadow private int removalTimer;
24+
25+
@Shadow @Final protected Int2ObjectMap<C> renderInfos;
26+
@Shadow @Final protected List<C> visible;
27+
28+
@Shadow public abstract void removeDeadRenderers();
29+
@Shadow public abstract C getRenderInfo(Contraption c);
30+
31+
32+
/**
33+
* @author IThundxr
34+
* @reason Replace stream with for loops to help with performance
35+
*/
36+
@Overwrite
37+
public void tick() {
38+
removalTimer++;
39+
if (removalTimer >= 20) {
40+
removeDeadRenderers();
41+
removalTimer = 0;
42+
}
43+
44+
for (WeakReference<AbstractContraptionEntity> ref : ContraptionHandler.loadedContraptions.get(world).values()) {
45+
AbstractContraptionEntity entity = ref.get();
46+
47+
// contraptions that are too large will not be synced, and un-synced contraptions will be null
48+
if (entity != null && entity.getContraption() != null) {
49+
getRenderInfo(entity.getContraption());
50+
}
51+
}
52+
}
53+
54+
/**
55+
* @author IThundxr
56+
* @reason Replace stream with for loops to help with performance
57+
*/
58+
@Overwrite
59+
public void beginFrame(BeginFrameEvent event) {
60+
renderInfos.forEach((key, renderInfo) ->
61+
renderInfo.beginFrame(event)
62+
);
63+
64+
collectVisible();
65+
}
66+
67+
/**
68+
* @author IThundxr
69+
* @reason Replace stream with for loops to help with performance
70+
*/
71+
@Overwrite
72+
protected void collectVisible() {
73+
visible.clear();
74+
75+
renderInfos.forEach((key, renderInfo) -> {
76+
if (renderInfo.isVisible()) {
77+
visible.add(renderInfo);
78+
}
79+
});
80+
}
81+
}

Diff for: src/main/resources/railwaystweaks.mixins.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"client": [
2020
"client.HttpTextureMixin",
2121
"client.PlayerRendererMixin",
22-
"client.compat.copycatsplus.MultiStateCopycatModelMixin"
22+
"client.compat.copycatsplus.MultiStateCopycatModelMixin",
23+
"client.compat.create.ContraptionRenderingWorldMixin"
2324
],
2425
"injectors": {
2526
"defaultRequire": 1

0 commit comments

Comments
 (0)