Skip to content

Commit

Permalink
Merge 1.18 into 1.19.2
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt committed Dec 21, 2023
2 parents 0111102 + 00fa822 commit f59aa5b
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,31 @@
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;

import java.lang.ref.WeakReference;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
* Delegate model that stores the location of an actual baked model, for use in ItemOverrides.
*/
public class ItemOverrideBakedModel implements BakedModel {
private static final Map<ResourceLocation, ItemOverrideBakedModel> OVERRIDE_MODELS = new ConcurrentHashMap<>();
public final ResourceLocation realLocation;
private WeakReference<BakedModel> realModel = new WeakReference<>(null);

private ItemOverrideBakedModel(ResourceLocation realLocation) {
this.realLocation = realLocation;
}

public static ItemOverrideBakedModel of(ResourceLocation realLocation) {
return OVERRIDE_MODELS.computeIfAbsent(realLocation, ItemOverrideBakedModel::new);
return new ItemOverrideBakedModel(realLocation);
}

public BakedModel getRealModel() {
return DynamicBakedModelProvider.currentInstance.get(realLocation);
BakedModel m = realModel.get();
if(m == null) {
m = DynamicBakedModelProvider.currentInstance.get(realLocation);
realModel = new WeakReference<>(m);
}
return m;
}

@Override
Expand Down

0 comments on commit f59aa5b

Please sign in to comment.