Skip to content

Commit 6e61cb4

Browse files
committed
Fix unstable ordering of properties in micro material registry names.
1 parent 737bf3f commit 6e61cb4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/main/java/codechicken/microblock/api/BlockMicroMaterial.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import codechicken.microblock.part.MicroblockPart;
99
import codechicken.microblock.util.MaskedCuboid;
1010
import codechicken.multipart.util.PartRayTraceResult;
11+
import net.covers1624.quack.collection.FastStream;
1112
import net.minecraft.client.Minecraft;
1213
import net.minecraft.client.multiplayer.ClientLevel;
1314
import net.minecraft.client.particle.ParticleEngine;
@@ -31,6 +32,8 @@
3132
import net.minecraft.world.level.block.state.properties.Property;
3233
import org.jetbrains.annotations.Nullable;
3334

35+
import java.util.Comparator;
36+
import java.util.HashMap;
3437
import java.util.List;
3538
import java.util.Map;
3639
import java.util.function.Consumer;
@@ -172,7 +175,11 @@ public static ResourceLocation makeMaterialKey(BlockState state) {
172175
if (!state.getProperties().isEmpty()) {
173176
path.append("//");
174177

175-
for (Map.Entry<Property<?>, Comparable<?>> entry : state.getValues().entrySet()) {
178+
// Stable sort all keys based off their name, otherwise they may differ on the server/client.
179+
Map<Property<?>, Comparable<?>> entries = FastStream.of(state.getValues().entrySet())
180+
.sorted(Comparator.comparing(e -> e.getKey().getName()))
181+
.toMap(Map.Entry::getKey, Map.Entry::getValue);
182+
for (Map.Entry<Property<?>, Comparable<?>> entry : entries.entrySet()) {
176183
Property<?> property = entry.getKey();
177184
if (path.charAt(path.length() - 2) != '/') {
178185
path.append('/');

0 commit comments

Comments
 (0)