Avoid refresh loop if no model data needs refreshing
This commit is contained in:
parent
7174ae1454
commit
c678ebbb91
|
|
@ -6,6 +6,7 @@ import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraftforge.client.model.ModelDataManager;
|
import net.minecraftforge.client.model.ModelDataManager;
|
||||||
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
|
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
|
@ -13,6 +14,7 @@ import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
@ -27,6 +29,8 @@ public abstract class ModelDataManagerMixin {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Shadow @Final private static Map<ChunkPos, Set<BlockPos>> needModelDataRefresh;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make the set of positions to refresh a real concurrent hash set rather than relying on synchronizedSet,
|
* Make the set of positions to refresh a real concurrent hash set rather than relying on synchronizedSet,
|
||||||
* because the returned iterator won't be thread-safe otherwise. See https://github.com/AppliedEnergistics/Applied-Energistics-2/issues/7511
|
* because the returned iterator won't be thread-safe otherwise. See https://github.com/AppliedEnergistics/Applied-Energistics-2/issues/7511
|
||||||
|
|
@ -40,7 +44,8 @@ public abstract class ModelDataManagerMixin {
|
||||||
private static void onlyRefreshOnMainThread(Level toUpdate, ChunkPos pos) {
|
private static void onlyRefreshOnMainThread(Level toUpdate, ChunkPos pos) {
|
||||||
// Only refresh model data on the main thread. This prevents calling getBlockEntity from worker threads
|
// Only refresh model data on the main thread. This prevents calling getBlockEntity from worker threads
|
||||||
// which could cause weird CMEs or other behavior.
|
// which could cause weird CMEs or other behavior.
|
||||||
if(Minecraft.getInstance().isSameThread()) {
|
// Avoid the loop if no model data needs to be refreshed, to prevent unnecessary allocation.
|
||||||
|
if(Minecraft.getInstance().isSameThread() && !needModelDataRefresh.isEmpty()) {
|
||||||
// Refresh the given chunk, and all its neighbors. This is less efficient than the default code
|
// Refresh the given chunk, and all its neighbors. This is less efficient than the default code
|
||||||
// but we have no choice since we need to not do refreshing on workers, and blocks might
|
// but we have no choice since we need to not do refreshing on workers, and blocks might
|
||||||
// try to access model data in neighboring chunks.
|
// try to access model data in neighboring chunks.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user