diff --git a/projects/common-api/src/client/java/dan200/computercraft/api/client/turtle/TurtleUpgradeModeller.java b/projects/common-api/src/client/java/dan200/computercraft/api/client/turtle/TurtleUpgradeModeller.java index 76a57ecf3..3a70d82db 100644 --- a/projects/common-api/src/client/java/dan200/computercraft/api/client/turtle/TurtleUpgradeModeller.java +++ b/projects/common-api/src/client/java/dan200/computercraft/api/client/turtle/TurtleUpgradeModeller.java @@ -11,10 +11,13 @@ import dan200.computercraft.api.turtle.ITurtleUpgrade; import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser; import net.minecraft.client.resources.model.ModelResourceLocation; +import net.minecraft.client.resources.model.UnbakedModel; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import javax.annotation.Nullable; +import java.util.Collection; +import java.util.List; /** * Provides models for a {@link ITurtleUpgrade}. @@ -50,6 +53,21 @@ public interface TurtleUpgradeModeller { return getModel(upgrade, (ITurtleAccess) null, side); } + + /** + * Get a list of models that this turtle modeller depends on. + *

+ * Models included in this list will be loaded and baked alongside item and block models, and so may be referenced + * by {@link TransformedModel#of(ResourceLocation)}. You do not need to override this method if you will load models + * by other means. + * + * @return A list of models that this modeller depends on. + * @see UnbakedModel#getDependencies() + */ + default Collection getDependencies() { + return List.of(); + } + /** * A basic {@link TurtleUpgradeModeller} which renders using the upgrade's {@linkplain ITurtleUpgrade#getCraftingItem() * crafting item}. @@ -74,7 +92,8 @@ public interface TurtleUpgradeModeller { * @return The constructed modeller. */ static TurtleUpgradeModeller sided(ModelResourceLocation left, ModelResourceLocation right) { - return (upgrade, turtle, side) -> TransformedModel.of(side == TurtleSide.LEFT ? left : right); + // TODO(1.21.0): Remove this. + return sided((ResourceLocation) left, right); } /** @@ -86,6 +105,16 @@ public interface TurtleUpgradeModeller { * @return The constructed modeller. */ static TurtleUpgradeModeller sided(ResourceLocation left, ResourceLocation right) { - return (upgrade, turtle, side) -> TransformedModel.of(side == TurtleSide.LEFT ? left : right); + return new TurtleUpgradeModeller<>() { + @Override + public TransformedModel getModel(T upgrade, @Nullable ITurtleAccess turtle, TurtleSide side) { + return TransformedModel.of(side == TurtleSide.LEFT ? left : right); + } + + @Override + public Collection getDependencies() { + return List.of(left, right); + } + }; } } diff --git a/projects/common/src/client/java/dan200/computercraft/client/ClientRegistry.java b/projects/common/src/client/java/dan200/computercraft/client/ClientRegistry.java index c3aead672..5a5da7852 100644 --- a/projects/common/src/client/java/dan200/computercraft/client/ClientRegistry.java +++ b/projects/common/src/client/java/dan200/computercraft/client/ClientRegistry.java @@ -13,6 +13,7 @@ import dan200.computercraft.client.render.RenderTypes; import dan200.computercraft.client.render.TurtleBlockEntityRenderer; import dan200.computercraft.client.render.monitor.MonitorBlockEntityRenderer; import dan200.computercraft.client.turtle.TurtleModemModeller; +import dan200.computercraft.client.turtle.TurtleUpgradeModellers; import dan200.computercraft.core.util.Colour; import dan200.computercraft.shared.ModRegistry; import dan200.computercraft.shared.common.IColouredItem; @@ -107,24 +108,6 @@ public final class ClientRegistry { } private static final String[] EXTRA_MODELS = new String[]{ - // Turtle upgrades - "block/turtle_modem_normal_off_left", - "block/turtle_modem_normal_on_left", - "block/turtle_modem_normal_off_right", - "block/turtle_modem_normal_on_right", - - "block/turtle_modem_advanced_off_left", - "block/turtle_modem_advanced_on_left", - "block/turtle_modem_advanced_off_right", - "block/turtle_modem_advanced_on_right", - - "block/turtle_crafting_table_left", - "block/turtle_crafting_table_right", - - "block/turtle_speaker_left", - "block/turtle_speaker_right", - - // Turtle block renderer "block/turtle_colour", "block/turtle_elf_overlay", "block/turtle_rainbow_overlay", @@ -133,6 +116,7 @@ public final class ClientRegistry { public static void registerExtraModels(Consumer register) { for (var model : EXTRA_MODELS) register.accept(new ResourceLocation(ComputerCraftAPI.MOD_ID, model)); + TurtleUpgradeModellers.getDependencies().forEach(register); } public static void registerItemColours(BiConsumer register) { diff --git a/projects/common/src/client/java/dan200/computercraft/client/turtle/TurtleModemModeller.java b/projects/common/src/client/java/dan200/computercraft/client/turtle/TurtleModemModeller.java index c5271e95f..c933dca67 100644 --- a/projects/common/src/client/java/dan200/computercraft/client/turtle/TurtleModemModeller.java +++ b/projects/common/src/client/java/dan200/computercraft/client/turtle/TurtleModemModeller.java @@ -13,6 +13,9 @@ import dan200.computercraft.shared.turtle.upgrades.TurtleModem; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.Nullable; +import java.util.Collection; +import java.util.List; + /** * A {@link TurtleUpgradeModeller} for modems, providing different models depending on if the modem is on/off. */ @@ -48,4 +51,9 @@ public class TurtleModemModeller implements TurtleUpgradeModeller { ? TransformedModel.of(active ? leftOnModel : leftOffModel) : TransformedModel.of(active ? rightOnModel : rightOffModel); } + + @Override + public Collection getDependencies() { + return List.of(leftOffModel, rightOffModel, leftOnModel, rightOnModel); + } } diff --git a/projects/common/src/client/java/dan200/computercraft/client/turtle/TurtleUpgradeModellers.java b/projects/common/src/client/java/dan200/computercraft/client/turtle/TurtleUpgradeModellers.java index 49b08801c..74c5a12ec 100644 --- a/projects/common/src/client/java/dan200/computercraft/client/turtle/TurtleUpgradeModellers.java +++ b/projects/common/src/client/java/dan200/computercraft/client/turtle/TurtleUpgradeModellers.java @@ -15,10 +15,12 @@ import dan200.computercraft.impl.TurtleUpgrades; import dan200.computercraft.impl.UpgradeManager; import net.minecraft.client.Minecraft; import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; import java.util.Map; import java.util.WeakHashMap; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Stream; /** * A registry of {@link TurtleUpgradeModeller}s. @@ -71,4 +73,8 @@ public final class TurtleUpgradeModellers { var modeller = turtleModels.get(wrapper.serialiser()); return modeller == null ? NULL_TURTLE_MODELLER : modeller; } + + public static Stream getDependencies() { + return turtleModels.values().stream().flatMap(x -> x.getDependencies().stream()); + } }