Support clearing model registry in dev for testing purposes
This commit is contained in:
parent
3ad4e2478e
commit
588b56530e
|
|
@ -14,4 +14,5 @@ public interface IExtendedModelBakery {
|
|||
ImmutableList<BlockState> getBlockStatesForMRL(StateDefinition<Block, BlockState> stateDefinition, ModelResourceLocation location);
|
||||
BakedModel bakeDefault(ResourceLocation modelLocation, ModelState state);
|
||||
UnbakedModel mfix$getUnbakedMissingModel();
|
||||
void mfix$clearModels();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import net.minecraft.world.level.block.Block;
|
|||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.embeddedt.modernfix.duck.IExtendedModelBakery;
|
||||
import org.embeddedt.modernfix.ModernFix;
|
||||
import org.embeddedt.modernfix.platform.ModernFixPlatformHooks;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
|
@ -194,7 +195,14 @@ public class DynamicBakedModelProvider implements Map<ResourceLocation, BakedMod
|
|||
|
||||
@Override
|
||||
public void clear() {
|
||||
throw new UnsupportedOperationException();
|
||||
if (ModernFixPlatformHooks.INSTANCE.isDevEnv()) {
|
||||
ModernFix.LOGGER.warn("Clearing model registry");
|
||||
permanentOverrides.clear();
|
||||
bakedCache.clear();
|
||||
((IExtendedModelBakery)bakery).mfix$clearModels();
|
||||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
|
|
|||
|
|
@ -325,4 +325,10 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
|
|||
public UnbakedModel mfix$getUnbakedMissingModel() {
|
||||
return missingModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mfix$clearModels() {
|
||||
loadedModels.invalidateAll();
|
||||
loadedBakedModels.invalidateAll();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package org.embeddedt.modernfix.forge.mixin.perf.dynamic_resources;
|
|||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.RemovalCause;
|
||||
import com.google.common.cache.RemovalNotification;
|
||||
import com.google.common.collect.ForwardingMap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
|
@ -128,6 +129,12 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
|
|||
private <K, V> void onModelRemoved(RemovalNotification<K, V> notification) {
|
||||
if(!debugDynamicModelLoading)
|
||||
return;
|
||||
// If the entry was replaced (happens because of the Minecraft model loading code structure), or
|
||||
// was explicitly removed, we don't really care.
|
||||
var reason = notification.getCause();
|
||||
if (reason == RemovalCause.REPLACED || reason == RemovalCause.EXPLICIT) {
|
||||
return;
|
||||
}
|
||||
Object k = notification.getKey();
|
||||
if(k == null)
|
||||
return;
|
||||
|
|
@ -341,4 +348,10 @@ public abstract class ModelBakeryMixin implements IExtendedModelBakery {
|
|||
public UnbakedModel mfix$getUnbakedMissingModel() {
|
||||
return missingModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mfix$clearModels() {
|
||||
loadedModels.invalidateAll();
|
||||
loadedBakedModels.invalidateAll();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user