|
3 | 3 | import com.google.common.cache.CacheBuilder; |
4 | 4 | import com.google.common.cache.CacheLoader; |
5 | 5 | import com.google.common.cache.LoadingCache; |
| 6 | +import com.google.common.collect.ForwardingMap; |
6 | 7 | import com.google.common.collect.Iterators; |
7 | 8 | import com.google.common.collect.Maps; |
8 | 9 | import com.google.gson.JsonObject; |
|
40 | 41 | import net.minecraft.world.level.block.state.BlockState; |
41 | 42 | import net.minecraft.world.level.block.state.StateDefinition; |
42 | 43 | import org.embeddedt.modernfix.ModernFix; |
| 44 | +import org.embeddedt.modernfix.duck.IModelHoldingBlockState; |
43 | 45 | import org.jetbrains.annotations.NotNull; |
44 | 46 | import org.jetbrains.annotations.Nullable; |
45 | 47 |
|
@@ -202,6 +204,33 @@ public Map<BlockState, BlockStateModel> getTopLevelEmulatedRegistry() { |
202 | 204 | return new EmulatedRegistry<>(BlockState.class, this.loadedBakedModels, BlockStateSet::instance, this.mrlModelOverrides); |
203 | 205 | } |
204 | 206 |
|
| 207 | + public Map<BlockState, BlockStateModel> getFastTopLevelEmulatedRegistry() { |
| 208 | + var dynamicRegistry = getTopLevelEmulatedRegistry(); |
| 209 | + |
| 210 | + return new ForwardingMap<>() { |
| 211 | + @Override |
| 212 | + protected Map<BlockState, BlockStateModel> delegate() { |
| 213 | + return dynamicRegistry; |
| 214 | + } |
| 215 | + |
| 216 | + @Override |
| 217 | + public BlockStateModel get(Object key) { |
| 218 | + BlockStateModel result; |
| 219 | + if (key instanceof IModelHoldingBlockState state) { |
| 220 | + result = state.mfix$getModel(); |
| 221 | + if (result != null) { |
| 222 | + return result; |
| 223 | + } |
| 224 | + } |
| 225 | + result = dynamicRegistry.getOrDefault(key, getMissingBakedModel()); |
| 226 | + if (key instanceof IModelHoldingBlockState state) { |
| 227 | + state.mfix$setModel(result); |
| 228 | + } |
| 229 | + return result; |
| 230 | + } |
| 231 | + }; |
| 232 | + } |
| 233 | + |
205 | 234 | /* |
206 | 235 | public Map<ResourceLocation, BakedModel> getStandaloneEmulatedRegistry() { |
207 | 236 | return new EmulatedRegistry<>(ResourceLocation.class, this.loadedStandaloneModels, Set::of, this.standaloneModelOverrides); |
|
0 commit comments