Skip to content

Commit 37ff50c

Browse files
committed
Do not pass model random supplier to quad processors
Quad processors run within a transform, so invoking the random supplier would clear the state for the supplier's random object, which might be currently in use by the model. Continuity itself does not use the random supplier, so any default methods were not affected by this issue.
1 parent f83a331 commit 37ff50c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/main/java/me/pepperbell/continuity/client/model/CtmBakedModel.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos
6565
// especially if there is an actual use case for it.
6666
BlockState appearanceState = state.getAppearance(blockView, pos, Direction.DOWN, state, pos);
6767

68-
quadTransform.prepare(blockView, appearanceState, state, pos, randomSupplier, context, ContinuityConfig.INSTANCE.useManualCulling.get(), getSliceFunc(appearanceState));
68+
quadTransform.prepare(blockView, appearanceState, state, pos, randomSupplier.get().nextLong(), context, ContinuityConfig.INSTANCE.useManualCulling.get(), getSliceFunc(appearanceState));
6969

7070
context.pushTransform(quadTransform);
7171
super.emitBlockQuads(blockView, state, pos, randomSupplier, context);
@@ -102,12 +102,21 @@ protected Function<Sprite, QuadProcessors.Slice> getSliceFunc(BlockState state)
102102

103103
protected static class CtmQuadTransform implements RenderContext.QuadTransform {
104104
protected final ProcessingContextImpl processingContext = new ProcessingContextImpl();
105+
protected final Supplier<Random> randomSupplier = new Supplier<>() {
106+
private final Random random = Random.createLocal();
107+
108+
@Override
109+
public Random get() {
110+
random.setSeed(randomSeed);
111+
return random;
112+
}
113+
};
105114

106115
protected BlockRenderView blockView;
107116
protected BlockState appearanceState;
108117
protected BlockState state;
109118
protected BlockPos pos;
110-
protected Supplier<Random> randomSupplier;
119+
protected long randomSeed;
111120
protected RenderContext renderContext;
112121
protected boolean useManualCulling;
113122
protected Function<Sprite, QuadProcessors.Slice> sliceFunc;
@@ -156,12 +165,12 @@ public boolean isActive() {
156165
return active;
157166
}
158167

159-
public void prepare(BlockRenderView blockView, BlockState appearanceState, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext renderContext, boolean useManualCulling, Function<Sprite, QuadProcessors.Slice> sliceFunc) {
168+
public void prepare(BlockRenderView blockView, BlockState appearanceState, BlockState state, BlockPos pos, long randomSeed, RenderContext renderContext, boolean useManualCulling, Function<Sprite, QuadProcessors.Slice> sliceFunc) {
160169
this.blockView = blockView;
161170
this.appearanceState = appearanceState;
162171
this.state = state;
163172
this.pos = pos;
164-
this.randomSupplier = randomSupplier;
173+
this.randomSeed = randomSeed;
165174
this.renderContext = renderContext;
166175
this.useManualCulling = useManualCulling;
167176
this.sliceFunc = sliceFunc;
@@ -176,7 +185,6 @@ public void reset() {
176185
appearanceState = null;
177186
state = null;
178187
pos = null;
179-
randomSupplier = null;
180188
renderContext = null;
181189
useManualCulling = false;
182190
sliceFunc = null;

0 commit comments

Comments
 (0)