diff --git a/common/src/main/java/com/iafenvoy/iceandfire/registry/IafRenderers.java b/common/src/main/java/com/iafenvoy/iceandfire/registry/IafRenderers.java index 85e97fb..acec9e5 100644 --- a/common/src/main/java/com/iafenvoy/iceandfire/registry/IafRenderers.java +++ b/common/src/main/java/com/iafenvoy/iceandfire/registry/IafRenderers.java @@ -23,6 +23,7 @@ import com.iafenvoy.uranus.client.model.util.TabulaModelHandlerHelper; import com.iafenvoy.uranus.client.render.DynamicItemRenderer; import com.iafenvoy.uranus.client.render.armor.IArmorRendererBase; +import com.iafenvoy.uranus.util.function.MemorizeSupplier; import dev.architectury.registry.client.level.entity.EntityRendererRegistry; import dev.architectury.registry.client.particle.ParticleProviderRegistry; import dev.architectury.registry.client.rendering.BlockEntityRendererRegistry; @@ -42,9 +43,9 @@ public final class IafRenderers { public static final Identifier SEA_SERPENT = new Identifier(IceAndFire.MOD_ID, "seaserpent/seaserpent_base"); public static void registerEntityRenderers() { - EntityRendererRegistry.register(IafEntities.FIRE_DRAGON, x -> new RenderDragonBase(x, TabulaModelHandlerHelper.getModel(FIRE_DRAGON, FireDragonTabulaModelAnimator::new), 0)); - EntityRendererRegistry.register(IafEntities.ICE_DRAGON, manager -> new RenderDragonBase(manager, TabulaModelHandlerHelper.getModel(ICE_DRAGON, IceDragonTabulaModelAnimator::new), 1)); - EntityRendererRegistry.register(IafEntities.LIGHTNING_DRAGON, manager -> new RenderLightningDragon(manager, TabulaModelHandlerHelper.getModel(LIGHTNING_DRAGON, LightningTabulaDragonAnimator::new), 2)); + EntityRendererRegistry.register(IafEntities.FIRE_DRAGON, x -> new RenderDragonBase(x, TabulaModelHandlerHelper.getModel(FIRE_DRAGON, new MemorizeSupplier<>(FireDragonTabulaModelAnimator::new)), 0)); + EntityRendererRegistry.register(IafEntities.ICE_DRAGON, manager -> new RenderDragonBase(manager, TabulaModelHandlerHelper.getModel(ICE_DRAGON, new MemorizeSupplier<>(IceDragonTabulaModelAnimator::new)), 1)); + EntityRendererRegistry.register(IafEntities.LIGHTNING_DRAGON, manager -> new RenderLightningDragon(manager, TabulaModelHandlerHelper.getModel(LIGHTNING_DRAGON, new MemorizeSupplier<>(LightningTabulaDragonAnimator::new)), 2)); EntityRendererRegistry.register(IafEntities.DRAGON_EGG, RenderDragonEgg::new); EntityRendererRegistry.register(IafEntities.DRAGON_ARROW, RenderDragonArrow::new); EntityRendererRegistry.register(IafEntities.DRAGON_SKULL, RenderDragonSkull::new); diff --git a/common/src/main/java/com/iafenvoy/iceandfire/render/entity/RenderDragonSkull.java b/common/src/main/java/com/iafenvoy/iceandfire/render/entity/RenderDragonSkull.java index 3f51508..4ce9f44 100644 --- a/common/src/main/java/com/iafenvoy/iceandfire/render/entity/RenderDragonSkull.java +++ b/common/src/main/java/com/iafenvoy/iceandfire/render/entity/RenderDragonSkull.java @@ -10,6 +10,7 @@ import com.iafenvoy.uranus.client.model.TabulaModel; import com.iafenvoy.uranus.client.model.basic.BasicModelPart; import com.iafenvoy.uranus.client.model.util.TabulaModelHandlerHelper; +import com.iafenvoy.uranus.util.function.MemorizeSupplier; import com.mojang.datafixers.util.Pair; import net.minecraft.client.render.OverlayTexture; import net.minecraft.client.render.RenderLayer; @@ -26,7 +27,7 @@ import java.util.function.Supplier; public class RenderDragonSkull extends EntityRenderer { - public static final Map>>> MODELS = new HashMap<>(); + public static final Map>>> MODELS = new HashMap<>(); public static final float[] growth_stage_1 = new float[]{1F, 3F}; public static final float[] growth_stage_2 = new float[]{3F, 7F}; public static final float[] growth_stage_3 = new float[]{7F, 12.5F}; @@ -34,9 +35,9 @@ public class RenderDragonSkull extends EntityRenderer { public static final float[] growth_stage_5 = new float[]{20F, 30F}; static { - MODELS.put(DragonType.FIRE, Pair.of(IafRenderers.FIRE_DRAGON, FireDragonTabulaModelAnimator::new)); - MODELS.put(DragonType.ICE, Pair.of(IafRenderers.ICE_DRAGON, IceDragonTabulaModelAnimator::new)); - MODELS.put(DragonType.LIGHTNING, Pair.of(IafRenderers.LIGHTNING_DRAGON, LightningTabulaDragonAnimator::new)); + MODELS.put(DragonType.FIRE, Pair.of(IafRenderers.FIRE_DRAGON, new MemorizeSupplier<>(FireDragonTabulaModelAnimator::new))); + MODELS.put(DragonType.ICE, Pair.of(IafRenderers.ICE_DRAGON, new MemorizeSupplier<>(IceDragonTabulaModelAnimator::new))); + MODELS.put(DragonType.LIGHTNING, Pair.of(IafRenderers.LIGHTNING_DRAGON, new MemorizeSupplier<>(LightningTabulaDragonAnimator::new))); } public final float[][] growth_stages; @@ -54,7 +55,7 @@ private static void setRotationAngles(BasicModelPart cube, float rotX) { @Override public void render(EntityDragonSkull entity, float entityYaw, float partialTicks, MatrixStack matrixStackIn, VertexConsumerProvider bufferIn, int packedLightIn) { - Pair>> p = MODELS.get(DragonType.getTypeById(entity.getDragonType())); + Pair>> p = MODELS.get(DragonType.getTypeById(entity.getDragonType())); TabulaModel model = TabulaModelHandlerHelper.getModel(p.getFirst(), p.getSecond()::get); if (model == null) return; VertexConsumer ivertexbuilder = bufferIn.getBuffer(RenderLayer.getEntityTranslucent(this.getTexture(entity))); diff --git a/common/src/main/java/com/iafenvoy/iceandfire/render/model/animator/DragonTabulaModelAnimator.java b/common/src/main/java/com/iafenvoy/iceandfire/render/model/animator/DragonTabulaModelAnimator.java index bd7937b..1f40b3e 100644 --- a/common/src/main/java/com/iafenvoy/iceandfire/render/model/animator/DragonTabulaModelAnimator.java +++ b/common/src/main/java/com/iafenvoy/iceandfire/render/model/animator/DragonTabulaModelAnimator.java @@ -9,7 +9,12 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.util.math.MathHelper; +import java.util.LinkedHashMap; +import java.util.Map; + public abstract class DragonTabulaModelAnimator extends IceAndFireTabulaModelAnimator implements ITabulaModelAnimator { + //FIXME::Will not reload + private final Map CACHES = new LinkedHashMap<>(); protected TabulaModel[] walkPoses; protected TabulaModel[] flyPoses; protected TabulaModel[] swimPoses; @@ -240,7 +245,14 @@ protected void genderMob(T entity, AdvancedModelBox cube) { } } - protected abstract TabulaModel getModel(EnumDragonPoses pose); + protected TabulaModel getModel(EnumDragonPoses pose) { + if (CACHES.containsKey(pose)) return CACHES.get(pose); + TabulaModel model = this.getModelInternal(pose); + CACHES.put(pose, model); + return model; + } + + protected abstract TabulaModel getModelInternal(EnumDragonPoses pose); protected void animate(TabulaModel model, T entity, float limbSwing, float limbSwingAmount, float ageInTicks, float rotationYaw, float rotationPitch, float scale) { AdvancedModelBox modelCubeJaw = model.getCube("Jaw"); diff --git a/common/src/main/java/com/iafenvoy/iceandfire/render/model/animator/FireDragonTabulaModelAnimator.java b/common/src/main/java/com/iafenvoy/iceandfire/render/model/animator/FireDragonTabulaModelAnimator.java index d2095cf..35440eb 100644 --- a/common/src/main/java/com/iafenvoy/iceandfire/render/model/animator/FireDragonTabulaModelAnimator.java +++ b/common/src/main/java/com/iafenvoy/iceandfire/render/model/animator/FireDragonTabulaModelAnimator.java @@ -15,7 +15,7 @@ public FireDragonTabulaModelAnimator() { } @Override - protected TabulaModel getModel(EnumDragonPoses pose) { + protected TabulaModel getModelInternal(EnumDragonPoses pose) { return DragonAnimationsLibrary.getModel(pose, EnumDragonModelTypes.FIRE_DRAGON_MODEL); } } diff --git a/common/src/main/java/com/iafenvoy/iceandfire/render/model/animator/IceDragonTabulaModelAnimator.java b/common/src/main/java/com/iafenvoy/iceandfire/render/model/animator/IceDragonTabulaModelAnimator.java index 401a292..cbbbaed 100644 --- a/common/src/main/java/com/iafenvoy/iceandfire/render/model/animator/IceDragonTabulaModelAnimator.java +++ b/common/src/main/java/com/iafenvoy/iceandfire/render/model/animator/IceDragonTabulaModelAnimator.java @@ -15,7 +15,7 @@ public IceDragonTabulaModelAnimator() { } @Override - protected TabulaModel getModel(EnumDragonPoses pose) { + protected TabulaModel getModelInternal(EnumDragonPoses pose) { return DragonAnimationsLibrary.getModel(pose, EnumDragonModelTypes.ICE_DRAGON_MODEL); } } diff --git a/common/src/main/java/com/iafenvoy/iceandfire/render/model/animator/LightningTabulaDragonAnimator.java b/common/src/main/java/com/iafenvoy/iceandfire/render/model/animator/LightningTabulaDragonAnimator.java index 80320fc..5158755 100644 --- a/common/src/main/java/com/iafenvoy/iceandfire/render/model/animator/LightningTabulaDragonAnimator.java +++ b/common/src/main/java/com/iafenvoy/iceandfire/render/model/animator/LightningTabulaDragonAnimator.java @@ -15,7 +15,7 @@ public LightningTabulaDragonAnimator() { } @Override - protected TabulaModel getModel(EnumDragonPoses pose) { + protected TabulaModel getModelInternal(EnumDragonPoses pose) { return DragonAnimationsLibrary.getModel(pose, EnumDragonModelTypes.LIGHTNING_DRAGON_MODEL); } } diff --git a/common/src/main/java/com/iafenvoy/iceandfire/render/model/util/DragonAnimationsLibrary.java b/common/src/main/java/com/iafenvoy/iceandfire/render/model/util/DragonAnimationsLibrary.java index be4c655..f27969d 100644 --- a/common/src/main/java/com/iafenvoy/iceandfire/render/model/util/DragonAnimationsLibrary.java +++ b/common/src/main/java/com/iafenvoy/iceandfire/render/model/util/DragonAnimationsLibrary.java @@ -5,14 +5,21 @@ import com.iafenvoy.uranus.client.model.util.TabulaModelHandlerHelper; import net.minecraft.util.Identifier; +import java.util.LinkedHashMap; +import java.util.Map; + /** * A library containing all animations for all dragons. Contains methods for registering and retrieving models */ public class DragonAnimationsLibrary { + private static final Map CACHES = new LinkedHashMap<>(); + public static TabulaModel getModel(IEnumDragonPoses pose, IEnumDragonModelTypes modelType) { Identifier id = new Identifier(IceAndFire.MOD_ID, modelType.getModelType() + "dragon/" + modelType.getModelType() + "dragon_" + pose.getPose()); + if (CACHES.containsKey(id)) return CACHES.get(id); TabulaModel result = TabulaModelHandlerHelper.getModel(id); if (result == null) IceAndFire.LOGGER.error("No model defined for {} have you registered your animations?", id); + CACHES.put(id, result); return result; } } diff --git a/gradle.properties b/gradle.properties index 7655635..587e628 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx2G org.gradle.parallel=true # Mod properties -mod_version = 0.8.1 +mod_version = 0.8.2 maven_group = com.iafenvoy.iceandfire archives_name = IceAndFireCE enabled_platforms = fabric,forge