Skip to content

Commit

Permalink
Theoretically fix compat with Ore Stages
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt committed Mar 31, 2024
1 parent cd2ed93 commit 7b9cccb
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.ImmutableMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ModelBlock;
Expand All @@ -23,6 +24,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.embeddedt.vintagefix.VintageFix;
import org.embeddedt.vintagefix.dynamicresources.IBlockModelShapes;
import org.embeddedt.vintagefix.event.DynamicModelBakeEvent;
import org.embeddedt.vintagefix.util.ExceptionHelper;

Expand Down Expand Up @@ -50,10 +52,16 @@ public class DynamicBakedModelProvider extends RegistrySimple<ModelResourceLocat
.softValues()
.build();

private final BakedModelStore bakedModelStore = new BakedModelStore();

public DynamicBakedModelProvider(DynamicModelProvider modelProvider) {
this.modelProvider = modelProvider;
}

public Map<IBlockState, IBakedModel> getBakedModelStore() {
return this.bakedModelStore;
}

@Override
protected Map<ModelResourceLocation, IBakedModel> createUnderlyingMap() {
return ImmutableMap.of();
Expand Down Expand Up @@ -187,4 +195,73 @@ public void invalidateThrough(ModelResourceLocation key) {
loadedBakedModels.invalidate(key);
((DynamicModelProvider)modelProvider).invalidate(key);
}

class BakedModelStore implements Map<IBlockState, IBakedModel> {

@Override
public int size() {
return DynamicBakedModelProvider.this.permanentlyLoadedBakedModels.size();
}

@Override
public boolean isEmpty() {
return false;
}

@Override
public boolean containsKey(Object key) {
return true;
}

@Override
public boolean containsValue(Object value) {
return true;
}

@Override
public IBakedModel get(Object key) {
if(key instanceof IBlockState) {
return Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState((IBlockState)key);
} else {
return null;
}
}

@Override
public IBakedModel put(IBlockState key, IBakedModel value) {
ModelResourceLocation mrl = ((IBlockModelShapes) Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes()).getLocationForState(key);
DynamicBakedModelProvider.this.putObject(mrl, value);
return null;
}

@Override
public IBakedModel remove(Object key) {
return null;
}

@Override
public void putAll(Map<? extends IBlockState, ? extends IBakedModel> m) {
m.forEach(this::put);
}

@Override
public void clear() {

}

@Override
public Set<IBlockState> keySet() {
return Collections.emptySet();
}

@Override
public Collection<IBakedModel> values() {
return DynamicBakedModelProvider.this.permanentlyLoadedBakedModels.values();
}

@Override
public Set<Entry<IBlockState, IBakedModel>> entrySet() {
return Collections.emptySet();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import org.embeddedt.vintagefix.annotation.ClientOnlyMixin;
import org.embeddedt.vintagefix.dynamicresources.IBlockModelShapes;
import org.embeddedt.vintagefix.dynamicresources.StateMapperHandler;
import org.embeddedt.vintagefix.dynamicresources.model.DynamicBakedModelProvider;
import org.embeddedt.vintagefix.dynamicresources.model.DynamicModelCache;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

Expand All @@ -29,6 +31,10 @@ public abstract class MixinBlockModelShapes implements IBlockModelShapes {
@Shadow @Final private ModelManager modelManager;
@Shadow @Final private BlockStateMapper blockStateMapper;

@Shadow
@Final
@Mutable
private Map<IBlockState, IBakedModel> bakedModelStore;
private final DynamicModelCache<IBlockState> vintage$modelCache = new DynamicModelCache<>(this::getModelForStateSlow, false);

private static StateMapperHandler stateMapperHandler;
Expand All @@ -44,6 +50,7 @@ public void reloadModels() {
stateMapperHandler = new StateMapperHandler(this.blockStateMapper);
}
this.vintage$modelCache.clear();
this.bakedModelStore = DynamicBakedModelProvider.instance.getBakedModelStore();
}

private IBakedModel getModelForStateSlow(IBlockState state) {
Expand Down

0 comments on commit 7b9cccb

Please sign in to comment.