diff --git a/src/main/java/com/minelittlepony/client/MineLittlePony.java b/src/main/java/com/minelittlepony/client/MineLittlePony.java index 1c16d8b9..de6f9ba1 100644 --- a/src/main/java/com/minelittlepony/client/MineLittlePony.java +++ b/src/main/java/com/minelittlepony/client/MineLittlePony.java @@ -4,6 +4,7 @@ import com.minelittlepony.api.pony.IPonyManager; import com.minelittlepony.api.pony.network.fabric.Channel; import com.minelittlepony.client.model.ModelType; import com.minelittlepony.client.pony.PonyManager; +import com.minelittlepony.client.pony.VariatedTextureSupplier; import com.minelittlepony.client.render.PonyRenderDispatcher; import com.minelittlepony.client.settings.ClientPonyConfig; import com.minelittlepony.common.client.gui.VisibilityMode; @@ -44,6 +45,7 @@ public class MineLittlePony implements ClientModInitializer { private ClientPonyConfig config; private PonyManager ponyManager; + private VariatedTextureSupplier variatedTextures; private final KeyBinding keyBinding = new KeyBinding("key.minelittlepony.settings", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_F9, "key.categories.misc"); @@ -68,10 +70,12 @@ public class MineLittlePony implements ClientModInitializer { config = new ClientPonyConfig(GamePaths.getConfigDirectory().resolve("minelp.json")); ponyManager = new PonyManager(config); + variatedTextures = new VariatedTextureSupplier(); KeyBindingHelper.registerKeyBinding(keyBinding); ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(ponyManager); + ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(variatedTextures); // convert legacy pony skins SkinFilterCallback.EVENT.register(new LegacySkinConverter()); @@ -141,5 +145,9 @@ public class MineLittlePony implements ClientModInitializer { public IPonyManager getManager() { return ponyManager; } + + public VariatedTextureSupplier getVariatedTextures() { + return variatedTextures; + } } diff --git a/src/main/java/com/minelittlepony/client/model/ModelType.java b/src/main/java/com/minelittlepony/client/model/ModelType.java index 0899bde9..1974d0d9 100644 --- a/src/main/java/com/minelittlepony/client/model/ModelType.java +++ b/src/main/java/com/minelittlepony/client/model/ModelType.java @@ -6,6 +6,7 @@ import net.minecraft.client.render.entity.model.ArmorStandEntityModel; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.mob.VexEntity; import net.minecraft.entity.passive.AllayEntity; +import net.minecraft.entity.passive.StriderEntity; import net.minecraft.util.Identifier; import com.minelittlepony.api.model.gear.IGear; @@ -69,8 +70,8 @@ public final class ModelType { public static final ModelKey> ILLAGER = register("illager", IllagerPonyModel::new); public static final ModelKey GUARDIAN = register("guardian", GuardianPonyModel::new); public static final ModelKey ENDERMAN = register("enderman", EnderStallionModel::new); - public static final ModelKey> BREEZIE = register("breezie", BreezieModel::new); - public static final ModelKey PARASPRITE = register("parasprite", ParaspriteModel::new); + public static final ModelKey> VEX = register("vex", ParaspriteModel::new); + public static final ModelKey> STRIDER = register("strider", ParaspriteModel::new); public static final ModelKey> ALLAY = register("allay", BreezieModel::new); public static final ModelKey> ELYTRA = register("elytra", PonyElytra::new); diff --git a/src/main/java/com/minelittlepony/client/model/entity/ParaspriteModel.java b/src/main/java/com/minelittlepony/client/model/entity/ParaspriteModel.java index 67627528..cbebdcbe 100644 --- a/src/main/java/com/minelittlepony/client/model/entity/ParaspriteModel.java +++ b/src/main/java/com/minelittlepony/client/model/entity/ParaspriteModel.java @@ -5,46 +5,64 @@ import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.entity.model.EntityModel; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.passive.StriderEntity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.mob.VexEntity; -public class ParaspriteModel extends EntityModel { +import com.minelittlepony.common.util.animation.Interpolator; - private ModelPart body; - private ModelPart leftWing; - private ModelPart rightWing; +public class ParaspriteModel extends EntityModel { - private ModelPart saddle; + private final ModelPart root; + + private final ModelPart body; + private final ModelPart jaw; + private final ModelPart lips; + private final ModelPart leftWing; + private final ModelPart rightWing; public ParaspriteModel(ModelPart tree) { super(RenderLayer::getEntityTranslucent); child = false; - body = tree; - saddle = tree.getChild("saddle"); + root = tree; + body = tree.getChild("body"); + jaw = body.getChild("jaw"); + lips = body.getChild("lips"); leftWing = tree.getChild("leftWing"); rightWing = tree.getChild("rightWing"); } @Override public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { - body.render(matrices, vertices, light, overlay, red, green, blue, alpha); - saddle.render(matrices, vertices, light, overlay, red, green, blue, alpha); + root.render(matrices, vertices, light, overlay, red, green, blue, alpha); } @Override - public void setAngles(StriderEntity entity, float move, float swing, float ticks, float headYaw, float headPitch) { + public void setAngles(T entity, float move, float swing, float ticks, float headYaw, float headPitch) { + body.pitch = 0; + lips.visible = false; if (entity.hasPassengers()) { - body.yaw = 0; - body.pitch = 0; + root.yaw = 0; + root.pitch = 0; } else { - body.yaw = headYaw * 0.017453292F; - body.pitch = headPitch * 0.017453292F; + root.yaw = headYaw * 0.017453292F; + root.pitch = headPitch * 0.017453292F; } - saddle.copyTransform(body); float sin = (float)Math.sin(ticks) / 2; float cos = (float)Math.cos(ticks) / 3; + float jawOpenAmount = Interpolator.linear(entity.getUuid()).interpolate("jawOpen", entity instanceof VexEntity vex && vex.isCharging() ? 1 : 0, 10); + + if (jawOpenAmount > 0) { + jaw.pivotY = Math.max(0, 2 * jawOpenAmount); + lips.pivotY = jaw.pivotY - 1; + lips.visible = true; + body.pitch += 0.3F * jawOpenAmount; + jaw.pitch = 0.6F * jawOpenAmount; + lips.pitch = 0.25F * jawOpenAmount; + } + leftWing.visible = true; leftWing.roll = 0.5F + cos; leftWing.yaw = 0.5F - sin; diff --git a/src/main/java/com/minelittlepony/client/pony/BackgroundPonyList.java b/src/main/java/com/minelittlepony/client/pony/BackgroundPonyList.java index 46060022..39e71121 100644 --- a/src/main/java/com/minelittlepony/client/pony/BackgroundPonyList.java +++ b/src/main/java/com/minelittlepony/client/pony/BackgroundPonyList.java @@ -15,12 +15,18 @@ import java.util.UUID; /** * All currently loaded background ponies. */ -class BackgroundPonyList { +class BackgroundPonyList implements VariatedTextureSupplier.VariatedTexture { /** * All currently loaded background ponies. */ private final List backgroundPonyList = new ArrayList<>(); + private final Identifier id; + + public BackgroundPonyList(Identifier id) { + this.id = id; + } + public Identifier getId(UUID uuid) { if (backgroundPonyList.isEmpty() || isUser(uuid)) { return IPonyManager.getDefaultSkin(uuid); @@ -33,12 +39,17 @@ class BackgroundPonyList { public void reloadAll(ResourceManager resourceManager) { backgroundPonyList.clear(); - backgroundPonyList.addAll(resourceManager.findResources("textures/entity/pony", path -> path.getPath().endsWith(".png")).keySet()); - MineLittlePony.logger.info("Detected {} background ponies installed.", backgroundPonyList.size()); + backgroundPonyList.addAll(resourceManager.findResources(id.getPath(), path -> path.getPath().endsWith(".png")).keySet()); + MineLittlePony.logger.info("Detected {} ponies installed at {}.", backgroundPonyList.size(), id); } - private boolean isUser(UUID uuid) { + static boolean isUser(UUID uuid) { return MinecraftClient.getInstance().player != null && MinecraftClient.getInstance().player.getUuid().equals(uuid); } + + @Override + public Identifier get(UUID uuid) { + return getId(uuid); + } } diff --git a/src/main/java/com/minelittlepony/client/pony/PonyManager.java b/src/main/java/com/minelittlepony/client/pony/PonyManager.java index a44f636b..992d96e9 100644 --- a/src/main/java/com/minelittlepony/client/pony/PonyManager.java +++ b/src/main/java/com/minelittlepony/client/pony/PonyManager.java @@ -11,30 +11,25 @@ import com.minelittlepony.settings.PonyConfig; import com.minelittlepony.settings.PonyLevel; import org.jetbrains.annotations.Nullable; -import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; +import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener; import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.util.DefaultSkinHelper; import net.minecraft.resource.ResourceManager; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.Identifier; -import net.minecraft.util.profiler.Profiler; import java.util.UUID; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; /** * The PonyManager is responsible for reading and recoding all the pony data associated with an entity of skin. * */ -public class PonyManager implements IPonyManager, IdentifiableResourceReloadListener { +public class PonyManager implements IPonyManager, SimpleSynchronousResourceReloadListener { private static final Identifier ID = new Identifier("minelittlepony", "background_ponies"); - private final BackgroundPonyList backgroundPonyList = new BackgroundPonyList(); - private final PonyConfig config; private final LoadingCache poniesCache = CacheBuilder.newBuilder() @@ -105,7 +100,7 @@ public class PonyManager implements IPonyManager, IdentifiableResourceReloadList @Override public IPony getBackgroundPony(UUID uuid) { - return ((Pony)getPony(backgroundPonyList.getId(uuid))).defaulted(); + return ((Pony)getPony(MineLittlePony.getInstance().getVariatedTextures().get(VariatedTextureSupplier.BACKGROUND_PONIES).get(uuid))).defaulted(); } @Override @@ -119,24 +114,14 @@ public class PonyManager implements IPonyManager, IdentifiableResourceReloadList } @Override - public CompletableFuture reload(Synchronizer sync, ResourceManager sender, - Profiler serverProfiler, Profiler clientProfiler, - Executor serverExecutor, Executor clientExecutor) { - - sync.getClass(); - return sync.whenPrepared(null).thenRunAsync(() -> { - clientProfiler.startTick(); - clientProfiler.push("Reloading all background ponies"); - poniesCache.invalidateAll(); - backgroundPonyList.reloadAll(sender); - PonySkullRenderer.reload(); - clientProfiler.pop(); - clientProfiler.endTick(); - }, clientExecutor); + public void reload(ResourceManager var1) { + clearCache(); + PonySkullRenderer.reload(); } @Override public Identifier getFabricId() { return ID; } + } diff --git a/src/main/java/com/minelittlepony/client/pony/VariatedTextureSupplier.java b/src/main/java/com/minelittlepony/client/pony/VariatedTextureSupplier.java new file mode 100644 index 00000000..d1058bc0 --- /dev/null +++ b/src/main/java/com/minelittlepony/client/pony/VariatedTextureSupplier.java @@ -0,0 +1,48 @@ +package com.minelittlepony.client.pony; + +import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener; +import net.minecraft.entity.Entity; +import net.minecraft.resource.ResourceManager; +import net.minecraft.util.Identifier; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class VariatedTextureSupplier implements SimpleSynchronousResourceReloadListener { + private static final Identifier ID = new Identifier("minelittlepony", "variated_textures"); + + public static final Identifier BACKGROUND_PONIES = new Identifier("minelittlepony", "textures/entity/pony"); + public static final Identifier BREEZIE_PONIES = new Identifier("minelittlepony", "textures/entity/allay/pony"); + public static final Identifier PARASPRITE_PONIES = new Identifier("minelittlepony", "textures/entity/illager/vex_pony"); + + private final Map entries = new HashMap<>(); + + public VariatedTextureSupplier() { + get(BACKGROUND_PONIES); + get(BREEZIE_PONIES); + get(PARASPRITE_PONIES); + } + + @Override + public void reload(ResourceManager manager) { + entries.forEach((key, value) -> value.reloadAll(manager)); + } + + @Override + public Identifier getFabricId() { + return ID; + } + + public VariatedTexture get(Identifier id) { + return entries.computeIfAbsent(id, BackgroundPonyList::new); + } + + public interface VariatedTexture { + Identifier get(UUID uuid); + + default Identifier get(Entity entity) { + return get(entity.getUuid()); + } + } +} diff --git a/src/main/java/com/minelittlepony/client/render/MobRenderers.java b/src/main/java/com/minelittlepony/client/render/MobRenderers.java index 9f9d29f3..fd275b59 100644 --- a/src/main/java/com/minelittlepony/client/render/MobRenderers.java +++ b/src/main/java/com/minelittlepony/client/render/MobRenderers.java @@ -57,7 +57,7 @@ public final class MobRenderers { pony.switchRenderer(state, EntityType.ARMOR_STAND, PonyStandRenderer::new); }); public static final MobRenderers STRIDER = register("striders", (state, pony) -> { - pony.switchRenderer(state, EntityType.STRIDER, ParaspriteRenderer::new); + pony.switchRenderer(state, EntityType.STRIDER, StriderRenderer::new); }); public static final MobRenderers ALLAY = register("allays", (state, pony) -> { pony.switchRenderer(state, EntityType.ALLAY, AllayRenderer::new); diff --git a/src/main/java/com/minelittlepony/client/render/entity/AllayRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/AllayRenderer.java index a47c511b..4a6cf75a 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/AllayRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/AllayRenderer.java @@ -7,12 +7,15 @@ import net.minecraft.entity.passive.AllayEntity; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; +import com.minelittlepony.client.MineLittlePony; import com.minelittlepony.client.model.ModelType; import com.minelittlepony.client.model.entity.BreezieModel; +import com.minelittlepony.client.pony.VariatedTextureSupplier; +/** + * AKA a breezie :D + */ public class AllayRenderer extends MobEntityRenderer> { - private static final Identifier TEXTURE = new Identifier("minelittlepony", "textures/entity/allay/allay_pony.png"); - public AllayRenderer(EntityRendererFactory.Context context) { super(context, ModelType.ALLAY.createModel(), 0.4f); addFeature(new HeldItemFeatureRenderer>(this, context.getHeldItemRenderer())); @@ -20,7 +23,7 @@ public class AllayRenderer extends MobEntityRenderer { - +public class StriderRenderer extends MobEntityRenderer> { private static final Identifier NORMAL = new Identifier("minelittlepony", "textures/entity/strider/strider_pony.png"); private static final Identifier CONFUSED = new Identifier("minelittlepony", "textures/entity/strider/strider_confused_pony.png"); private static final Identifier SADDLE = new Identifier("minelittlepony", "textures/entity/strider/strider_saddle_pony.png"); - public ParaspriteRenderer(EntityRendererFactory.Context context) { - super(context, ModelType.PARASPRITE.createModel(), 0.5F); - addFeature(new SaddleFeatureRenderer<>(this, ModelType.PARASPRITE.createModel(), SADDLE)); + public StriderRenderer(EntityRendererFactory.Context context) { + super(context, ModelType.STRIDER.createModel(), 0.5F); + addFeature(new SaddleFeatureRenderer<>(this, ModelType.STRIDER.createModel(), SADDLE)); } @Override diff --git a/src/main/java/com/minelittlepony/client/render/entity/VexRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/VexRenderer.java index 4ed1e3fc..91806be9 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/VexRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/VexRenderer.java @@ -1,24 +1,18 @@ package com.minelittlepony.client.render.entity; -import net.minecraft.client.render.entity.BipedEntityRenderer; -import net.minecraft.client.render.entity.EntityRendererFactory; +import net.minecraft.client.render.entity.*; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.mob.VexEntity; import net.minecraft.util.Identifier; +import com.minelittlepony.client.MineLittlePony; import com.minelittlepony.client.model.ModelType; -import com.minelittlepony.client.model.entity.BreezieModel; - -/** - * AKA a breezie :D - */ -public class VexRenderer extends BipedEntityRenderer> { - - private static final Identifier VEX = new Identifier("minelittlepony", "textures/entity/illager/vex_pony.png"); - private static final Identifier VEX_CHARGING = new Identifier("minelittlepony", "textures/entity/illager/vex_charging_pony.png"); +import com.minelittlepony.client.model.entity.ParaspriteModel; +import com.minelittlepony.client.pony.VariatedTextureSupplier; +public class VexRenderer extends MobEntityRenderer> { public VexRenderer(EntityRendererFactory.Context context) { - super(context, ModelType.BREEZIE.createModel(), 0.3F); + super(context, ModelType.VEX.createModel(), 0.3F); } @Override @@ -28,7 +22,7 @@ public class VexRenderer extends BipedEntityRenderer