Skip to content

Commit 588b565

Browse files
committed
Support clearing model registry in dev for testing purposes
1 parent 3ad4e24 commit 588b565

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

common/src/main/java/org/embeddedt/modernfix/duck/IExtendedModelBakery.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ public interface IExtendedModelBakery {
1414
ImmutableList<BlockState> getBlockStatesForMRL(StateDefinition<Block, BlockState> stateDefinition, ModelResourceLocation location);
1515
BakedModel bakeDefault(ResourceLocation modelLocation, ModelState state);
1616
UnbakedModel mfix$getUnbakedMissingModel();
17+
void mfix$clearModels();
1718
}

common/src/main/java/org/embeddedt/modernfix/dynamicresources/DynamicBakedModelProvider.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import net.minecraft.world.level.block.state.BlockState;
2020
import org.embeddedt.modernfix.duck.IExtendedModelBakery;
2121
import org.embeddedt.modernfix.ModernFix;
22+
import org.embeddedt.modernfix.platform.ModernFixPlatformHooks;
2223
import org.jetbrains.annotations.NotNull;
2324
import org.jetbrains.annotations.Nullable;
2425

@@ -194,7 +195,14 @@ public void putAll(@NotNull Map<? extends ResourceLocation, ? extends BakedModel
194195

195196
@Override
196197
public void clear() {
197-
throw new UnsupportedOperationException();
198+
if (ModernFixPlatformHooks.INSTANCE.isDevEnv()) {
199+
ModernFix.LOGGER.warn("Clearing model registry");
200+
permanentOverrides.clear();
201+
bakedCache.clear();
202+
((IExtendedModelBakery)bakery).mfix$clearModels();
203+
} else {
204+
throw new UnsupportedOperationException();
205+
}
198206
}
199207

200208
@NotNull

fabric/src/main/java/org/embeddedt/modernfix/fabric/mixin/perf/dynamic_resources/ModelBakeryMixin.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,10 @@ public ImmutableList<BlockState> getBlockStatesForMRL(StateDefinition<Block, Blo
325325
public UnbakedModel mfix$getUnbakedMissingModel() {
326326
return missingModel;
327327
}
328+
329+
@Override
330+
public void mfix$clearModels() {
331+
loadedModels.invalidateAll();
332+
loadedBakedModels.invalidateAll();
333+
}
328334
}

forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/dynamic_resources/ModelBakeryMixin.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.common.cache.Cache;
44
import com.google.common.cache.CacheBuilder;
5+
import com.google.common.cache.RemovalCause;
56
import com.google.common.cache.RemovalNotification;
67
import com.google.common.collect.ForwardingMap;
78
import com.google.common.collect.ImmutableList;
@@ -128,6 +129,12 @@ private String ignoreFutureModelLoads(String name) {
128129
private <K, V> void onModelRemoved(RemovalNotification<K, V> notification) {
129130
if(!debugDynamicModelLoading)
130131
return;
132+
// If the entry was replaced (happens because of the Minecraft model loading code structure), or
133+
// was explicitly removed, we don't really care.
134+
var reason = notification.getCause();
135+
if (reason == RemovalCause.REPLACED || reason == RemovalCause.EXPLICIT) {
136+
return;
137+
}
131138
Object k = notification.getKey();
132139
if(k == null)
133140
return;
@@ -341,4 +348,10 @@ public BakedModel getBakedMissingModel() {
341348
public UnbakedModel mfix$getUnbakedMissingModel() {
342349
return missingModel;
343350
}
351+
352+
@Override
353+
public void mfix$clearModels() {
354+
loadedModels.invalidateAll();
355+
loadedBakedModels.invalidateAll();
356+
}
344357
}

0 commit comments

Comments
 (0)