Move the model cache inside TurtleModelParts

This removes a tiny bit of duplication (at the cost of mode code), but
makes the interface more intuitive, as there's no bouncing between
getCombination -> cache -> buildModel.
This commit is contained in:
Jonathan Coates
2023-07-01 18:27:36 +01:00
parent ecf880ed82
commit 9eabb29999
4 changed files with 30 additions and 23 deletions
@@ -11,9 +11,8 @@ import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.client.model.BakedModelWrapper;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
/**
* The custom model for turtle items, which renders tools and overlays as part of the model.
@@ -21,12 +20,11 @@ import java.util.Map;
* @see TurtleModelParts
*/
public class TurtleModel extends BakedModelWrapper<BakedModel> {
private final TurtleModelParts parts;
private final Map<TurtleModelParts.Combination, List<BakedModel>> cachedModels = new HashMap<>();
private final TurtleModelParts<List<BakedModel>> parts;
public TurtleModel(BakedModel familyModel, BakedModel colourModel) {
super(familyModel);
parts = new TurtleModelParts(familyModel, colourModel, TransformedBakedModel::new);
parts = new TurtleModelParts<>(familyModel, colourModel, TransformedBakedModel::new, Function.identity());
}
@Override
@@ -37,6 +35,6 @@ public class TurtleModel extends BakedModelWrapper<BakedModel> {
@Override
public List<BakedModel> getRenderPasses(ItemStack stack, boolean fabulous) {
return cachedModels.computeIfAbsent(parts.getCombination(stack), parts::buildModel);
return parts.getModel(stack);
}
}