Report invalid block bake errors and dont crash (will probably cause an insane amount of spam)

This commit is contained in:
mcrcortex
2025-09-02 11:19:11 +10:00
parent ea884f1583
commit 8384b9f88b
2 changed files with 12 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ package me.cortex.voxy.client.core.model;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import me.cortex.voxy.common.Logger;
import me.cortex.voxy.common.world.other.Mapper; import me.cortex.voxy.common.world.other.Mapper;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryKeys;
@@ -23,11 +24,13 @@ public class ModelBakerySubsystem {
private final ModelStore storage = new ModelStore(); private final ModelStore storage = new ModelStore();
public final ModelFactory factory; public final ModelFactory factory;
private final Mapper mapper;
private final AtomicInteger blockIdCount = new AtomicInteger(); private final AtomicInteger blockIdCount = new AtomicInteger();
private final ConcurrentLinkedDeque<Integer> blockIdQueue = new ConcurrentLinkedDeque<>();//TODO: replace with custom DS private final ConcurrentLinkedDeque<Integer> blockIdQueue = new ConcurrentLinkedDeque<>();//TODO: replace with custom DS
private final ConcurrentLinkedDeque<Mapper.BiomeEntry> biomeQueue = new ConcurrentLinkedDeque<>(); private final ConcurrentLinkedDeque<Mapper.BiomeEntry> biomeQueue = new ConcurrentLinkedDeque<>();
public ModelBakerySubsystem(Mapper mapper) { public ModelBakerySubsystem(Mapper mapper) {
this.mapper = mapper;
this.factory = new ModelFactory(mapper, this.storage); this.factory = new ModelFactory(mapper, this.storage);
} }
@@ -102,8 +105,12 @@ public class ModelBakerySubsystem {
//This is on this side only and done like this as only worker threads call this code //This is on this side only and done like this as only worker threads call this code
private final ReentrantLock seenIdsLock = new ReentrantLock(); private final ReentrantLock seenIdsLock = new ReentrantLock();
private final IntOpenHashSet seenIds = new IntOpenHashSet(6000); private final IntOpenHashSet seenIds = new IntOpenHashSet(6000);//TODO: move to a lock free concurrent hashmap
public void requestBlockBake(int blockId) { public void requestBlockBake(int blockId) {
if (this.mapper.getBlockStateCount() < blockId) {
Logger.error("Error, got bakeing request for out of range state id. StateId: " + blockId + " max id: " + this.mapper.getBlockStateCount(), new Exception());
return;
}
this.seenIdsLock.lock(); this.seenIdsLock.lock();
if (!this.seenIds.add(blockId)) { if (!this.seenIds.add(blockId)) {
this.seenIdsLock.unlock(); this.seenIdsLock.unlock();

View File

@@ -158,6 +158,10 @@ public class Mapper {
} }
public final int getBlockStateCount() {
return this.blockId2stateEntry.size();
}
private StateEntry registerNewBlockState(BlockState state) { private StateEntry registerNewBlockState(BlockState state) {
this.blockLock.lock(); this.blockLock.lock();
var entry = this.block2stateEntry.get(state); var entry = this.block2stateEntry.get(state);