diff --git a/build.gradle b/build.gradle index b3d58a3a..8fcd8d71 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { } } plugins { - id 'fabric-loom' version '1.5-SNAPSHOT' + id 'fabric-loom' version '1.6-SNAPSHOT' id 'maven-publish' id 'com.modrinth.minotaur' version '2.+' id 'org.ajoberstar.reckon' version '0.13.0' @@ -13,7 +13,7 @@ apply plugin: 'dex.plugins.outlet' java { toolchain { - languageVersion = JavaLanguageVersion.of(17) + languageVersion = JavaLanguageVersion.of(21) } withSourcesJar() } diff --git a/gradle.properties b/gradle.properties index 8885ff12..f5b597e9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,10 @@ org.gradle.daemon=false # Fabric Properties # check these on https://fabricmc.net/develop - minecraft_version=1.20.4 - yarn_mappings=1.20.4+build.1 - loader_version=0.15.1 - fabric_version=0.91.2+1.20.4 + minecraft_version=1.20.5 + yarn_mappings=1.20.5+build.1 + loader_version=0.15.7 + fabric_version=0.97.5+1.20.5 # Mod Properties group=com.minelittlepony @@ -19,7 +19,7 @@ org.gradle.daemon=false modrinth_project_id=JBjInUXM # Dependencies - modmenu_version=9.0.0-pre.1 - kirin_version=1.17.1+1.20.4 - hd_skins_version=6.12.2+1.20.4 - mson_version=1.9.3+1.20.2 + modmenu_version=10.0.0-beta.1 + kirin_version=1.18.0-beta.1+1.20.5 + hd_skins_version=6.12.3-beta.2+1.20.5 + mson_version=1.9.3+1.20.5 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index db9a6b82..17655d0e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/com/minelittlepony/api/events/Channel.java b/src/main/java/com/minelittlepony/api/events/Channel.java index 0bf588ac..1df76dec 100644 --- a/src/main/java/com/minelittlepony/api/events/Channel.java +++ b/src/main/java/com/minelittlepony/api/events/Channel.java @@ -4,10 +4,11 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.networking.v1.ClientLoginConnectionEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; -import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.fabricmc.fabric.api.networking.v1.*; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.packet.CustomPayload; import net.minecraft.util.Identifier; import org.apache.logging.log4j.LogManager; @@ -17,8 +18,6 @@ import com.minelittlepony.api.pony.PonyData; @Environment(EnvType.CLIENT) public class Channel { - private static final Identifier CLIENT_PONY_DATA = new Identifier("minelittlepony", "pony_data"); - private static final Identifier REQUEST_PONY_DATA = new Identifier("minelittlepony", "request_pony_data"); private static final Logger LOGGER = LogManager.getLogger("MineLittlePony:Networking"); private static boolean registered; @@ -27,20 +26,24 @@ public class Channel { ClientLoginConnectionEvents.INIT.register((handler, client) -> { registered = false; }); + ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> { LOGGER.info("Sending consent packet to " + handler.getPlayer().getName().getString()); - - sender.sendPacket(REQUEST_PONY_DATA, PacketByteBufs.empty()); + sender.sendPacket(PonyDataRequest.INSTANCE); }); - ClientPlayNetworking.registerGlobalReceiver(REQUEST_PONY_DATA, (client, handler, ignored, sender) -> { + PayloadTypeRegistry.playS2C().register(PonyDataRequest.ID, PonyDataRequest.CODEC); + PayloadTypeRegistry.playS2C().register(PonyDataPayload.ID, PonyDataPayload.CODEC); + PayloadTypeRegistry.playC2S().register(PonyDataPayload.ID, PonyDataPayload.CODEC); + + ClientPlayNetworking.registerGlobalReceiver(PonyDataRequest.ID, (packet, context) -> { registered = true; LOGGER.info("Server has just consented"); }); - ServerPlayNetworking.registerGlobalReceiver(CLIENT_PONY_DATA, (server, player, ignore, buffer, ignore2) -> { - PonyData packet = MsgPonyData.read(buffer); - server.execute(() -> { - PonyDataCallback.EVENT.invoker().onPonyDataAvailable(player, packet, EnvType.SERVER); + + ServerPlayNetworking.registerGlobalReceiver(PonyDataPayload.ID, (packet, context) -> { + context.player().server.execute(() -> { + PonyDataCallback.EVENT.invoker().onPonyDataAvailable(context.player(), packet.data(), EnvType.SERVER); }); }); } @@ -57,7 +60,31 @@ public class Channel { throw new RuntimeException("Client packet send called by the server"); } - ClientPlayNetworking.send(CLIENT_PONY_DATA, MsgPonyData.write(packet, PacketByteBufs.create())); + ClientPlayNetworking.send(new PonyDataPayload(packet)); return true; } + + record PonyDataPayload(PonyData data) implements CustomPayload { + public static final Id ID = new Id<>(new Identifier("minelittlepony", "pony_data")); + public static final PacketCodec CODEC = CustomPayload.codecOf( + (p, buffer) -> MsgPonyData.write(p.data(), buffer), + buffer -> new PonyDataPayload(MsgPonyData.read(buffer)) + ); + + @Override + public Id getId() { + return ID; + } + } + + record PonyDataRequest() implements CustomPayload { + public static final PonyDataRequest INSTANCE = new PonyDataRequest(); + private static final Id ID = new Id<>(new Identifier("minelittlepony", "request_pony_data")); + public static final PacketCodec CODEC = PacketCodec.unit(INSTANCE); + + @Override + public Id getId() { + return ID; + } + } } \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/api/pony/DefaultPonySkinHelper.java b/src/main/java/com/minelittlepony/api/pony/DefaultPonySkinHelper.java index 052bc52f..70b020c0 100644 --- a/src/main/java/com/minelittlepony/api/pony/DefaultPonySkinHelper.java +++ b/src/main/java/com/minelittlepony/api/pony/DefaultPonySkinHelper.java @@ -3,30 +3,31 @@ package com.minelittlepony.api.pony; import net.minecraft.client.util.DefaultSkinHelper; import net.minecraft.client.util.SkinTextures; import net.minecraft.util.Identifier; +import net.minecraft.util.Util; import com.minelittlepony.api.pony.meta.Race; +import com.minelittlepony.client.MineLittlePony; import java.util.*; +import java.util.function.Function; public final class DefaultPonySkinHelper { - public static final Identifier STEVE = new Identifier("minelittlepony", "textures/entity/player/wide/steve_pony.png"); + public static final Identifier STEVE = MineLittlePony.id("textures/entity/player/wide/steve_pony.png"); - public static final Identifier SEAPONY_SKIN_TYPE_ID = new Identifier("minelp", "seapony"); - public static final Identifier NIRIK_SKIN_TYPE_ID = new Identifier("minelp", "nirik"); + public static final Identifier SEAPONY_SKIN_TYPE_ID = MineLittlePony.id("seapony"); + public static final Identifier NIRIK_SKIN_TYPE_ID = MineLittlePony.id("nirik"); - private static final Map SKINS = new HashMap<>(); + private static final Function SKINS = Util.memoize(original -> new SkinTextures( + new Identifier("minelittlepony", original.texture().getPath().replace(".png", "_pony.png")), + null, + null, + null, + original.model(), + false + )); public static SkinTextures getTextures(SkinTextures original) { - return SKINS.computeIfAbsent(original, o -> { - return new SkinTextures( - new Identifier("minelittlepony", original.texture().getPath().replace(".png", "_pony.png")), - null, - null, - null, - original.model(), - false - ); - }); + return SKINS.apply(original); } public static String getModelType(UUID id) { diff --git a/src/main/java/com/minelittlepony/client/HorseCam.java b/src/main/java/com/minelittlepony/client/HorseCam.java index 5c183458..6d8c80d5 100644 --- a/src/main/java/com/minelittlepony/client/HorseCam.java +++ b/src/main/java/com/minelittlepony/client/HorseCam.java @@ -87,7 +87,7 @@ public class HorseCam { public static float rescaleCameraPitch(double toHeight, float originalPitch) { MinecraftClient client = MinecraftClient.getInstance(); PlayerEntity player = client.player; - client.gameRenderer.updateTargetedEntity(client.getTickDelta()); + client.gameRenderer.updateCrosshairTarget(client.getTickDelta()); HitResult hit = client.crosshairTarget; if (client.targetedEntity != null) { diff --git a/src/main/java/com/minelittlepony/client/MineLittlePony.java b/src/main/java/com/minelittlepony/client/MineLittlePony.java index 8fdbaf6e..49bfad77 100644 --- a/src/main/java/com/minelittlepony/client/MineLittlePony.java +++ b/src/main/java/com/minelittlepony/client/MineLittlePony.java @@ -9,7 +9,6 @@ import com.minelittlepony.client.render.PonyRenderDispatcher; import com.minelittlepony.common.client.gui.VisibilityMode; import com.minelittlepony.common.client.gui.element.Button; import com.minelittlepony.common.client.gui.sprite.TextureSprite; -import com.minelittlepony.common.event.ClientReadyCallback; import com.minelittlepony.common.event.ScreenInitCallback; import com.minelittlepony.common.event.SkinFilterCallback; import com.minelittlepony.common.util.GamePaths; @@ -48,6 +47,7 @@ public class MineLittlePony implements ClientModInitializer { private final KeyBinding keyBinding = new KeyBinding("key.minelittlepony.settings", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_F9, "key.categories.misc"); private final PonyRenderDispatcher renderDispatcher = new PonyRenderDispatcher(); + private boolean initialized; private boolean hasHdSkins; private boolean hasModMenu; @@ -63,6 +63,10 @@ public class MineLittlePony implements ClientModInitializer { return instance; } + public static Identifier id(String name) { + return new Identifier("minelittlepony", name); + } + @Override public void onInitializeClient() { hasHdSkins = FabricLoader.getInstance().isModLoaded("hdskins"); @@ -81,11 +85,7 @@ public class MineLittlePony implements ClientModInitializer { SkinFilterCallback.EVENT.register(new LegacySkinConverter()); // general events - ClientReadyCallback.Handler.register(); ClientTickEvents.END_CLIENT_TICK.register(this::onTick); - ClientReadyCallback.EVENT.register(client -> { - renderDispatcher.initialise(client.getEntityRenderDispatcher(), false); - }); ScreenInitCallback.EVENT.register(this::onScreenInit); config.load(); @@ -97,6 +97,10 @@ public class MineLittlePony implements ClientModInitializer { } private void onTick(MinecraftClient client) { + if (!initialized) { + initialized = true; + renderDispatcher.initialise(client.getEntityRenderDispatcher(), false); + } boolean inGame = client.world != null && client.player != null && client.currentScreen == null; boolean mainMenu = client.currentScreen instanceof TitleScreen; diff --git a/src/main/java/com/minelittlepony/client/compat/hdskins/MineLPHDSkins.java b/src/main/java/com/minelittlepony/client/compat/hdskins/MineLPHDSkins.java index d697fb6c..266121a5 100644 --- a/src/main/java/com/minelittlepony/client/compat/hdskins/MineLPHDSkins.java +++ b/src/main/java/com/minelittlepony/client/compat/hdskins/MineLPHDSkins.java @@ -6,11 +6,11 @@ import com.minelittlepony.api.pony.*; import com.minelittlepony.api.pony.meta.Wearable; import com.minelittlepony.common.client.gui.ScrollContainer; import com.minelittlepony.common.client.gui.element.Button; -import com.minelittlepony.common.event.ClientReadyCallback; import com.minelittlepony.hdskins.client.*; import com.minelittlepony.hdskins.client.gui.GuiSkins; import com.minelittlepony.hdskins.client.gui.player.DummyPlayer; import com.minelittlepony.hdskins.client.gui.player.skins.PlayerSkins.PlayerSkin; +import com.minelittlepony.hdskins.client.profile.SkinLoader.ProvidedSkins; import com.minelittlepony.hdskins.profile.SkinType; import com.mojang.authlib.GameProfile; @@ -37,7 +37,7 @@ public class MineLPHDSkins extends SkinsProxy implements ClientModInitializer { static SkinType seaponySkinType; static SkinType nirikSkinType; - static final Map wearableTypes = new HashMap<>(); + static final Map WEARABLE_TYPES = new HashMap<>(); @Override public void onInitializeClient() { @@ -48,18 +48,18 @@ public class MineLPHDSkins extends SkinsProxy implements ClientModInitializer { nirikSkinType = SkinType.register(DefaultPonySkinHelper.NIRIK_SKIN_TYPE_ID, Items.LAVA_BUCKET.getDefaultStack()); Wearable.REGISTRY.values().forEach(wearable -> { if (wearable != Wearable.NONE) { - wearableTypes.put(SkinType.register(wearable.getId(), Items.BUNDLE.getDefaultStack()), wearable); + WEARABLE_TYPES.put(SkinType.register(wearable.getId(), Items.BUNDLE.getDefaultStack()), wearable); } }); - ClientReadyCallback.EVENT.register(client -> { - // Clear ponies when skins are cleared - SkinCacheClearCallback.EVENT.register(MineLittlePony.getInstance().getManager()::clearCache); - - // Ponify the skins GUI. - GuiSkins.setSkinsGui(GuiSkinsMineLP::new); + // Clear ponies when skins are cleared + SkinCacheClearCallback.EVENT.register(() -> { + MineLittlePony.getInstance().getManager().clearCache(); }); + // Ponify the skins GUI. + GuiSkins.setSkinsGui(GuiSkinsMineLP::new); + HDSkins.getInstance().getSkinPrioritySorter().addSelector((skinType, playerSkins) -> { if (skinType == SkinType.SKIN && PonyConfig.getInstance().mixedHumanSkins.get()) { Optional hdPony = getPony(playerSkins.hd()); @@ -75,7 +75,7 @@ public class MineLPHDSkins extends SkinsProxy implements ClientModInitializer { }); } - static Optional getPony(PlayerSkins.Layer layer) { + static Optional getPony(PlayerSkinLayers.Layer layer) { return layer .getSkin(SkinType.SKIN) .map(Pony.getManager()::getPony); @@ -103,8 +103,9 @@ public class MineLPHDSkins extends SkinsProxy implements ClientModInitializer { if (entity instanceof AbstractClientPlayerEntity player) { return PlayerSkins.of(player) - .map(PlayerSkins::combined) - .map(PlayerSkins.Layer::getProvidedSkinTypes) + .map(PlayerSkins::layers) + .map(PlayerSkinLayers::combined) + .map(PlayerSkinLayers.Layer::getProvidedSkinTypes) .orElseGet(Set::of); } @@ -132,13 +133,17 @@ public class MineLPHDSkins extends SkinsProxy implements ClientModInitializer { } } - return Optional.of(player).flatMap(PlayerSkins::of).map(PlayerSkins::combined).flatMap(skins -> skins.getSkin(type)); + return Optional.of(player) + .flatMap(PlayerSkins::of) + .map(PlayerSkins::layers) + .map(PlayerSkinLayers::combined) + .flatMap(skins -> skins.getSkin(type)); } @Override public Identifier getSkinTexture(GameProfile profile) { return HDSkins.getInstance().getProfileRepository() - .getNow(profile) + .load(profile).getNow(ProvidedSkins.EMPTY) .getSkin(SkinType.SKIN) .orElseGet(() -> super.getSkinTexture(profile)); } diff --git a/src/main/java/com/minelittlepony/client/compat/hdskins/PonifiedDualCarouselWidget.java b/src/main/java/com/minelittlepony/client/compat/hdskins/PonifiedDualCarouselWidget.java index 60b48817..77abe02b 100644 --- a/src/main/java/com/minelittlepony/client/compat/hdskins/PonifiedDualCarouselWidget.java +++ b/src/main/java/com/minelittlepony/client/compat/hdskins/PonifiedDualCarouselWidget.java @@ -35,7 +35,7 @@ class PonifiedDualCarouselWidget extends DualCarouselWidget { return super.getDefaultSkin(SkinType.SKIN, modelVariant); } - Wearable wearable = MineLPHDSkins.wearableTypes.getOrDefault(type, Wearable.NONE); + Wearable wearable = MineLPHDSkins.WEARABLE_TYPES.getOrDefault(type, Wearable.NONE); if (wearable != Wearable.NONE) { return NativeImageFilters.GREYSCALE.load(wearable.getDefaultTexture(), wearable.getDefaultTexture(), getExclusion()); diff --git a/src/main/java/com/minelittlepony/client/mixin/MixinClientPlayerEntity.java b/src/main/java/com/minelittlepony/client/mixin/MixinClientPlayerEntity.java index 1926b1bd..024ff010 100644 --- a/src/main/java/com/minelittlepony/client/mixin/MixinClientPlayerEntity.java +++ b/src/main/java/com/minelittlepony/client/mixin/MixinClientPlayerEntity.java @@ -1,19 +1,10 @@ package com.minelittlepony.client.mixin; -import com.minelittlepony.api.pony.Pony; import com.minelittlepony.client.render.EquineRenderManager; import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityDimensions; -import net.minecraft.entity.EntityPose; - import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(ClientPlayerEntity.class) abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity implements EquineRenderManager.RegistrationHandler { @@ -21,39 +12,8 @@ abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity implem private final EquineRenderManager.SyncedPony syncedPony = new EquineRenderManager.SyncedPony(); - @Inject(method = "startRiding(Lnet/minecraft/entity/Entity;Z)Z", at = @At("RETURN")) - private void onStartRiding(Entity entity, boolean bl, CallbackInfoReturnable info) { - calculateDimensions(); - } - - @Inject(method = "dismountVehicle()V", at = @At("RETURN")) - private void onStopRiding(CallbackInfo info) { - calculateDimensions(); - } - @Override public EquineRenderManager.SyncedPony getSyncedPony() { return syncedPony; } - - @Override - public float getActiveEyeHeight(EntityPose pose, EntityDimensions dimensions) { - float value = super.getActiveEyeHeight(pose, dimensions); - - Pony pony = Pony.getManager().getPony(this); - - if (!pony.race().isHuman()) { - float factor = pony.size().eyeHeightFactor(); - if (factor != 1) { - value *= factor; - - if (hasVehicle()) { - value += getVehicle().getHeight(); - } - return Math.max(value, 0.1F); - } - } - - return value; - } } diff --git a/src/main/java/com/minelittlepony/client/mixin/MixinGameRenderer.java b/src/main/java/com/minelittlepony/client/mixin/MixinGameRenderer.java index e8b09518..d321e8fe 100644 --- a/src/main/java/com/minelittlepony/client/mixin/MixinGameRenderer.java +++ b/src/main/java/com/minelittlepony/client/mixin/MixinGameRenderer.java @@ -1,7 +1,6 @@ package com.minelittlepony.client.mixin; import net.minecraft.client.render.*; -import net.minecraft.client.util.math.MatrixStack; import org.joml.Matrix4f; import org.spongepowered.asm.mixin.Mixin; @@ -14,12 +13,12 @@ import com.minelittlepony.api.model.RenderPass; @Mixin(GameRenderer.class) abstract class MixinGameRenderer { @Inject(method = "renderWorld", at = @At("HEAD")) - private void beforeRenderWorld(float tickDelta, long limitTime, MatrixStack matrices, CallbackInfo info) { + private void beforeRenderWorld(float tickDelta, long limitTime, CallbackInfo info) { RenderPass.swap(RenderPass.WORLD); } @Inject(method = "renderWorld", at = @At("RETURN")) - private void afterRenderWorld(float tickDelta, long limitTime, MatrixStack matrices, CallbackInfo info) { + private void afterRenderWorld(float tickDelta, long limitTime, CallbackInfo info) { RenderPass.swap(RenderPass.GUI); } } @@ -31,7 +30,14 @@ abstract class MixinWorldRenderer { target = "net.minecraft.client.render.VertexConsumerProvider$Immediate.drawCurrentLayer()V", ordinal = 0 )) - private void onRender(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f positionMatrix, CallbackInfo info) { + private void onRender( float tickDelta, + long limitTime, + boolean renderBlockOutline, + Camera camera, + GameRenderer gameRenderer, + LightmapTextureManager lightmapTextureManager, + Matrix4f matrix4f, + Matrix4f matrix4f2, CallbackInfo info) { RenderPass.swap(RenderPass.HUD); } } \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/client/mixin/MixinLivingEntity.java b/src/main/java/com/minelittlepony/client/mixin/MixinLivingEntity.java new file mode 100644 index 00000000..ee4f8bd9 --- /dev/null +++ b/src/main/java/com/minelittlepony/client/mixin/MixinLivingEntity.java @@ -0,0 +1,29 @@ +package com.minelittlepony.client.mixin; + +import net.minecraft.entity.*; +import net.minecraft.entity.player.PlayerEntity; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import com.minelittlepony.api.pony.Pony; + +@Mixin(LivingEntity.class) +abstract class MixinLivingEntity { + @Inject(method = "getBaseDimensions", at = @At("RETURN"), cancellable = true) + private void onGetBaseDimensions(EntityPose pose, CallbackInfoReturnable info) { + if (((Object)this) instanceof PlayerEntity player) { + Pony pony = Pony.getManager().getPony(player); + + if (!pony.race().isHuman()) { + float factor = pony.size().eyeHeightFactor(); + if (factor != 1) { + EntityDimensions dimensions = info.getReturnValue(); + info.setReturnValue(dimensions.withEyeHeight(dimensions.eyeHeight() * factor)); + } + } + } + } +} diff --git a/src/main/java/com/minelittlepony/client/mixin/MixinSkullBlockEntityRenderer.java b/src/main/java/com/minelittlepony/client/mixin/MixinSkullBlockEntityRenderer.java index 44f3b7e9..13c22e1f 100644 --- a/src/main/java/com/minelittlepony/client/mixin/MixinSkullBlockEntityRenderer.java +++ b/src/main/java/com/minelittlepony/client/mixin/MixinSkullBlockEntityRenderer.java @@ -8,6 +8,7 @@ import net.minecraft.client.render.block.entity.BlockEntityRenderer; import net.minecraft.client.render.block.entity.SkullBlockEntityModel; import net.minecraft.client.render.block.entity.SkullBlockEntityRenderer; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.component.type.ProfileComponent; import net.minecraft.util.math.Direction; import org.spongepowered.asm.mixin.Mixin; @@ -17,7 +18,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import com.minelittlepony.client.render.blockentity.skull.PonySkullRenderer; -import com.mojang.authlib.GameProfile; import org.jetbrains.annotations.Nullable; @@ -46,9 +46,9 @@ abstract class MixinSkullBlockEntityRenderer implements BlockEntityRenderer info) { + private static void onGetRenderLayer(SkullBlock.SkullType skullType, @Nullable ProfileComponent profile, CallbackInfoReturnable info) { if (!info.isCancelled()) { RenderLayer result = PonySkullRenderer.getSkullRenderLayer(skullType, profile); if (result != null) { diff --git a/src/main/java/com/minelittlepony/client/model/armour/ArmourTextureResolver.java b/src/main/java/com/minelittlepony/client/model/armour/ArmourTextureResolver.java index 63d04bbd..31a1274d 100644 --- a/src/main/java/com/minelittlepony/client/model/armour/ArmourTextureResolver.java +++ b/src/main/java/com/minelittlepony/client/model/armour/ArmourTextureResolver.java @@ -2,11 +2,12 @@ package com.minelittlepony.client.model.armour; import net.minecraft.client.MinecraftClient; import net.minecraft.client.texture.TextureManager; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.CustomModelDataComponent; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.EquipmentSlot; import net.minecraft.item.ArmorItem; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtElement; import net.minecraft.registry.Registries; import net.minecraft.util.Identifier; import com.google.common.base.Strings; @@ -48,7 +49,7 @@ public class ArmourTextureResolver { public Identifier getTexture(LivingEntity entity, ItemStack stack, EquipmentSlot slot, ArmourLayer layer, @Nullable String type) { Identifier material = stack.getItem() instanceof ArmorItem armor - ? new Identifier(armor.getMaterial().getName()) + ? armor.getMaterial().getKey().get().getValue() : Registries.ITEM.getId(stack.getItem()); String custom = getCustom(stack); @@ -79,8 +80,9 @@ public class ArmourTextureResolver { } private String getCustom(ItemStack stack) { - if (stack.hasNbt() && stack.getNbt().contains("CustomModelData", NbtElement.NUMBER_TYPE)) { - return "custom_" + stack.getNbt().getInt("CustomModelData"); + CustomModelDataComponent customModelData = stack.get(DataComponentTypes.CUSTOM_MODEL_DATA); + if (customModelData != null) { + return "custom_" + customModelData.value(); } return "none"; } diff --git a/src/main/java/com/minelittlepony/client/render/EquineRenderManager.java b/src/main/java/com/minelittlepony/client/render/EquineRenderManager.java index dae39170..88f2c8dc 100644 --- a/src/main/java/com/minelittlepony/client/render/EquineRenderManager.java +++ b/src/main/java/com/minelittlepony/client/render/EquineRenderManager.java @@ -86,7 +86,7 @@ public class EquineRenderManager { - void setupTransforms(T entity, MatrixStack stack, float ageInTicks, float rotationYaw, float partialTicks); + void setupTransforms(T entity, MatrixStack stack, float animationProgress, float bodyYaw, float tickDelta, float scale); } public interface RegistrationHandler { diff --git a/src/main/java/com/minelittlepony/client/render/blockentity/skull/MobSkull.java b/src/main/java/com/minelittlepony/client/render/blockentity/skull/MobSkull.java index 4faffc1b..89348bd9 100644 --- a/src/main/java/com/minelittlepony/client/render/blockentity/skull/MobSkull.java +++ b/src/main/java/com/minelittlepony/client/render/blockentity/skull/MobSkull.java @@ -7,13 +7,13 @@ import com.minelittlepony.client.model.AbstractPonyModel; import com.minelittlepony.client.render.MobRenderers; import com.minelittlepony.client.render.blockentity.skull.PonySkullRenderer.ISkull; import com.minelittlepony.mson.api.ModelKey; -import com.mojang.authlib.GameProfile; import java.util.function.Supplier; import net.minecraft.client.model.ModelPart; import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.component.type.ProfileComponent; import net.minecraft.util.Identifier; import net.minecraft.util.math.RotationAxis; @@ -38,7 +38,7 @@ public class MobSkull implements ISkull { } @Override - public Identifier getSkinResource(@Nullable GameProfile profile) { + public Identifier getSkinResource(@Nullable ProfileComponent profile) { return texture; } diff --git a/src/main/java/com/minelittlepony/client/render/blockentity/skull/PlayerPonySkull.java b/src/main/java/com/minelittlepony/client/render/blockentity/skull/PlayerPonySkull.java index 5b069d18..7fba9f14 100644 --- a/src/main/java/com/minelittlepony/client/render/blockentity/skull/PlayerPonySkull.java +++ b/src/main/java/com/minelittlepony/client/render/blockentity/skull/PlayerPonySkull.java @@ -7,7 +7,6 @@ import com.minelittlepony.api.pony.SkinsProxy; import com.minelittlepony.api.pony.meta.Race; import com.minelittlepony.client.model.*; import com.minelittlepony.client.render.blockentity.skull.PonySkullRenderer.ISkull; -import com.mojang.authlib.GameProfile; import java.util.HashMap; import java.util.Map; @@ -15,6 +14,7 @@ import java.util.Map; import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.util.DefaultSkinHelper; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.component.type.ProfileComponent; import net.minecraft.util.Identifier; import net.minecraft.util.math.RotationAxis; @@ -35,17 +35,17 @@ public class PlayerPonySkull implements ISkull { } @Override - public Identifier getSkinResource(@Nullable GameProfile profile) { - renderingEars = profile != null && "deadmau5".equals(profile.getName()); + public Identifier getSkinResource(@Nullable ProfileComponent profile) { + renderingEars = profile != null && "deadmau5".equals(profile.gameProfile().getName()); if (profile != null) { - Identifier skin = SkinsProxy.instance.getSkinTexture(profile); + Identifier skin = SkinsProxy.instance.getSkinTexture(profile.gameProfile()); if (skin != null) { return skin; } - return DefaultSkinHelper.getSkinTextures(profile).texture(); + return DefaultSkinHelper.getSkinTextures(profile.gameProfile()).texture(); } return DefaultSkinHelper.getTexture(); diff --git a/src/main/java/com/minelittlepony/client/render/blockentity/skull/PonySkullRenderer.java b/src/main/java/com/minelittlepony/client/render/blockentity/skull/PonySkullRenderer.java index 6863b1a7..6d7c5501 100644 --- a/src/main/java/com/minelittlepony/client/render/blockentity/skull/PonySkullRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/blockentity/skull/PonySkullRenderer.java @@ -7,7 +7,6 @@ import com.minelittlepony.client.model.ModelType; import com.minelittlepony.client.render.MobRenderers; import com.minelittlepony.client.render.entity.SkeleponyRenderer; import com.minelittlepony.client.render.entity.ZomponyRenderer; -import com.mojang.authlib.GameProfile; import net.minecraft.block.SkullBlock; import net.minecraft.client.render.OverlayTexture; @@ -15,6 +14,7 @@ import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.component.type.ProfileComponent; import net.minecraft.util.Identifier; import net.minecraft.util.math.Direction; @@ -43,7 +43,7 @@ public class PonySkullRenderer { skullMap.put(SkullBlock.Type.PLAYER, new PlayerPonySkull()); } - public static RenderLayer getSkullRenderLayer(SkullBlock.SkullType skullType, @Nullable GameProfile profile) { + public static RenderLayer getSkullRenderLayer(SkullBlock.SkullType skullType, @Nullable ProfileComponent profile) { selectedSkull = null; selectedSkin = null; @@ -109,7 +109,7 @@ public class PonySkullRenderer { boolean canRender(PonyConfig config); - Identifier getSkinResource(@Nullable GameProfile profile); + Identifier getSkinResource(@Nullable ProfileComponent profile); boolean bindPony(Pony pony); } diff --git a/src/main/java/com/minelittlepony/client/render/entity/AbstractPonyRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/AbstractPonyRenderer.java index 124074fc..29526465 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/AbstractPonyRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/AbstractPonyRenderer.java @@ -27,6 +27,7 @@ import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.mob.MobEntity; import net.minecraft.text.Text; import net.minecraft.util.Identifier; +import net.minecraft.util.math.Vec3d; public abstract class AbstractPonyRenderer & PonyModel & ModelWithArms> extends MobEntityRenderer implements PonyRenderContext { @@ -74,8 +75,8 @@ public abstract class AbstractPonyRenderer> { private final Function>> modelsCache; @@ -70,7 +71,9 @@ public class PlayerPonyRenderer extends PlayerEntityRenderer implements PonyRend @Override protected void scale(AbstractClientPlayerEntity entity, MatrixStack stack, float tickDelta) { if (manager.getModels().body().getAttributes().isSitting && entity.hasVehicle()) { - stack.translate(0, entity.getRidingOffset(entity.getVehicle()), 0); + // TODO: Check this + Vec3d attachmentPos = entity.getVehicleAttachmentPos(entity.getVehicle()); + stack.translate(attachmentPos.getX(), attachmentPos.getY(), attachmentPos.getZ()); } } @@ -102,8 +105,8 @@ public class PlayerPonyRenderer extends PlayerEntityRenderer implements PonyRend } @Override - protected void setupTransforms(AbstractClientPlayerEntity entity, MatrixStack stack, float ageInTicks, float rotationYaw, float partialTicks) { - manager.setupTransforms(entity, stack, ageInTicks, rotationYaw, partialTicks); + protected void setupTransforms(AbstractClientPlayerEntity entity, MatrixStack matrices, float animationProgress, float bodyYaw, float tickDelta, float scale) { + manager.setupTransforms(entity, matrices, animationProgress, bodyYaw, tickDelta, scale); } @Override @@ -116,7 +119,7 @@ public class PlayerPonyRenderer extends PlayerEntityRenderer implements PonyRend } @Override - protected void renderLabelIfPresent(AbstractClientPlayerEntity entity, Text name, MatrixStack stack, VertexConsumerProvider renderContext, int maxDistance) { + protected void renderLabelIfPresent(AbstractClientPlayerEntity entity, Text name, MatrixStack stack, VertexConsumerProvider renderContext, int light, float tickDelta) { stack.push(); if (entity.isSleeping()) { @@ -127,7 +130,7 @@ public class PlayerPonyRenderer extends PlayerEntityRenderer implements PonyRend } } stack.translate(0, manager.getNamePlateYOffset(entity), 0); - super.renderLabelIfPresent(entity, name, stack, renderContext, maxDistance); + super.renderLabelIfPresent(entity, name, stack, renderContext, light, tickDelta); stack.pop(); } diff --git a/src/main/java/com/minelittlepony/client/render/entity/PonyStandRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/PonyStandRenderer.java index 5c50c214..da4615f0 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/PonyStandRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/PonyStandRenderer.java @@ -52,10 +52,10 @@ public class PonyStandRenderer extends ArmorStandEntityRenderer { } @Override - protected void setupTransforms(ArmorStandEntity entity, MatrixStack stack, float f, float g, float h) { - super.setupTransforms(entity, stack, f, g, h); + protected void setupTransforms(ArmorStandEntity entity, MatrixStack stack, float animationProgress, float bodyYaw, float tickDelta, float scale) { + super.setupTransforms(entity, stack, animationProgress, bodyYaw, tickDelta, scale); if (isPonita(entity)) { - stack.translate(0, 0, -4/16F); + stack.translate(0, 0, scale * -4/16F); } } diff --git a/src/main/java/com/minelittlepony/client/render/entity/SeaponyRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/SeaponyRenderer.java index 43953930..c7aa1f63 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/SeaponyRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/SeaponyRenderer.java @@ -64,7 +64,7 @@ public class SeaponyRenderer extends GuardianEntityRenderer { } @Override - protected void setupTransforms(GuardianEntity entity, MatrixStack stack, float ageInTicks, float rotationYaw, float partialTicks) { - ponyRenderer.manager.setupTransforms(entity, stack, ageInTicks, rotationYaw, partialTicks); + protected void setupTransforms(GuardianEntity entity, MatrixStack stack, float animationProgress, float bodyYaw, float tickDelta, float scale) { + ponyRenderer.manager.setupTransforms(entity, stack, animationProgress, bodyYaw, tickDelta, scale); } } diff --git a/src/main/java/com/minelittlepony/client/render/entity/feature/ArmourFeature.java b/src/main/java/com/minelittlepony/client/render/entity/feature/ArmourFeature.java index 71fb0d7c..b484104e 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/feature/ArmourFeature.java +++ b/src/main/java/com/minelittlepony/client/render/entity/feature/ArmourFeature.java @@ -15,10 +15,13 @@ import net.minecraft.client.render.model.BakedModelManager; import net.minecraft.client.texture.Sprite; import net.minecraft.client.texture.SpriteAtlasTexture; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.DyedColorComponent; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; import net.minecraft.item.*; import net.minecraft.item.trim.ArmorTrim; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.util.Identifier; public class ArmourFeature & PonyModel> extends AbstractPonyFeature { @@ -56,7 +59,6 @@ public class ArmourFeature & Po ArmourVariant variant = ArmourTextureResolver.INSTANCE.getVariant(layer, texture); boolean glint = stack.hasGlint(); - Item item = stack.getItem(); pony.getArmourModel(stack, layer, variant) .filter(m -> m.poseModel(entity, limbAngle, limbDistance, age, headYaw, headPitch, armorSlot, layer, pony.body())) @@ -65,8 +67,10 @@ public class ArmourFeature & Po float green = 1; float blue = 1; - if (item instanceof DyeableArmorItem dyeable) { - int color = dyeable.getColor(stack); + DyedColorComponent colorComponent = stack.get(DataComponentTypes.DYED_COLOR); + + if (colorComponent != null) { + int color = colorComponent.rgb(); red = Color.r(color); green = Color.g(color); blue = Color.b(color); @@ -74,7 +78,7 @@ public class ArmourFeature & Po model.render(matrices, getArmorConsumer(renderContext, texture, glint), light, OverlayTexture.DEFAULT_UV, red, green, blue, 1); - if (item instanceof DyeableArmorItem) { + if (colorComponent != null) { Identifier tex = ArmourTextureResolver.INSTANCE.getTexture(entity, stack, armorSlot, layer, "overlay"); pony.getArmourModel(stack, layer, ArmourTextureResolver.INSTANCE.getVariant(layer, tex)) .filter(m -> m.poseModel(entity, limbAngle, limbDistance, age, headYaw, headPitch, armorSlot, layer, pony.body())) @@ -83,13 +87,13 @@ public class ArmourFeature & Po }); } - if (stack.getItem() instanceof ArmorItem armor) { - ArmorTrim.getTrim(entity.getWorld().getRegistryManager(), stack, true).ifPresent(trim -> { - pony.getArmourModel(stack, layer, ArmourVariant.TRIM) - .filter(m -> m.poseModel(entity, limbAngle, limbDistance, age, headYaw, headPitch, armorSlot, layer, pony.body())) - .ifPresent(m -> { - m.render(matrices, getTrimConsumer(renderContext, armor.getMaterial(), trim, layer, glint), light, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1); - }); + ArmorTrim trim = stack.get(DataComponentTypes.TRIM); + + if (trim != null && stack.getItem() instanceof ArmorItem armor) { + pony.getArmourModel(stack, layer, ArmourVariant.TRIM) + .filter(m -> m.poseModel(entity, limbAngle, limbDistance, age, headYaw, headPitch, armorSlot, layer, pony.body())) + .ifPresent(m -> { + m.render(matrices, getTrimConsumer(renderContext, armor.getMaterial(), trim, layer, glint), light, OverlayTexture.DEFAULT_UV, 1, 1, 1, 1); }); } }); @@ -99,7 +103,7 @@ public class ArmourFeature & Po return ItemRenderer.getArmorGlintConsumer(provider, ArmorRenderLayers.getArmorTranslucentNoCull(texture, false), false, glint); } - private static VertexConsumer getTrimConsumer(VertexConsumerProvider provider, ArmorMaterial material, ArmorTrim trim, ArmourLayer layer, boolean glint) { + private static VertexConsumer getTrimConsumer(VertexConsumerProvider provider, RegistryEntry material, ArmorTrim trim, ArmourLayer layer, boolean glint) { SpriteAtlasTexture armorTrimsAtlas = MinecraftClient.getInstance().getBakedModelManager().getAtlas(TexturedRenderLayers.ARMOR_TRIMS_ATLAS_TEXTURE); Sprite sprite = armorTrimsAtlas.getSprite( layer == ArmourLayer.INNER ? trim.getLeggingsModelId(material) : trim.getGenericModelId(material) diff --git a/src/main/java/com/minelittlepony/client/render/entity/feature/SkullFeature.java b/src/main/java/com/minelittlepony/client/render/entity/feature/SkullFeature.java index 4965edd9..b310d904 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/feature/SkullFeature.java +++ b/src/main/java/com/minelittlepony/client/render/entity/feature/SkullFeature.java @@ -4,7 +4,6 @@ import com.minelittlepony.api.model.BodyPart; import com.minelittlepony.api.model.PonyModel; import com.minelittlepony.client.model.AbstractPonyModel; import com.minelittlepony.client.render.PonyRenderContext; -import com.mojang.authlib.GameProfile; import java.util.Map; @@ -19,6 +18,7 @@ import net.minecraft.client.render.entity.model.EntityModel; import net.minecraft.client.render.entity.model.EntityModelLoader; import net.minecraft.client.render.model.json.ModelTransformationMode; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.component.DataComponentTypes; import net.minecraft.util.math.RotationAxis; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; @@ -26,8 +26,6 @@ import net.minecraft.item.ArmorItem; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtHelper; import net.minecraft.village.VillagerDataContainer; public class SkullFeature & PonyModel> extends AbstractPonyFeature { @@ -87,20 +85,10 @@ public class SkullFeature & Pon stack.translate(0, 0.0625F, 0); } - GameProfile profile = null; - - if (itemstack.hasNbt()) { - NbtCompound nbt = itemstack.getNbt(); - - if (nbt.contains("SkullOwner", 10)) { - profile = NbtHelper.toGameProfile(nbt.getCompound("SkullOwner")); - } - } - stack.translate(-0.5, 0, -0.5); SkullType type = ((AbstractSkullBlock) ((BlockItem) itemstack.getItem()).getBlock()).getSkullType(); SkullBlockEntityModel skullBlockEntityModel = (SkullBlockEntityModel)this.headModels.get(type); - RenderLayer renderLayer = SkullBlockEntityRenderer.getRenderLayer(type, profile); + RenderLayer renderLayer = SkullBlockEntityRenderer.getRenderLayer(type, itemstack.get(DataComponentTypes.PROFILE)); SkullBlockEntityRenderer.renderSkull(null, 180, f, stack, renderContext, lightUv, skullBlockEntityModel, renderLayer); } diff --git a/src/main/java/com/minelittlepony/client/render/entity/npc/ZomponyVillagerRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/npc/ZomponyVillagerRenderer.java index 6f660324..4edfb7f4 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/npc/ZomponyVillagerRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/npc/ZomponyVillagerRenderer.java @@ -33,11 +33,11 @@ public class ZomponyVillagerRenderer extends AbstractNpcRenderer TextureSupplier create(TextureSupplier fallback) { Function> customNameCache = Util.memoize(name -> { - return SkullBlockEntity.fetchProfile(name).thenApply(profile -> { + return SkullBlockEntity.fetchProfileByName(name).thenApply(profile -> { return profile .map(p -> SkinsProxy.instance.getSkinTexture(p)) .filter(skin -> !Pony.getManager().getPony(skin).race().isHuman()) diff --git a/src/main/java/com/minelittlepony/client/transform/PonyPosture.java b/src/main/java/com/minelittlepony/client/transform/PonyPosture.java index 08f46c4b..e7ecd2a7 100644 --- a/src/main/java/com/minelittlepony/client/transform/PonyPosture.java +++ b/src/main/java/com/minelittlepony/client/transform/PonyPosture.java @@ -64,7 +64,7 @@ public interface PonyPosture { } } - float roll = (float)player.getRoll() + tickDelta; + float roll = (float)player.getFallFlyingTicks() + tickDelta; float targetRoll = MathHelper.clamp(roll * roll / 100F, 0, 1); if (!player.isUsingRiptide()) { stack.multiply(RotationAxis.NEGATIVE_X.rotationDegrees(targetRoll * (-90 - player.getPitch()))); diff --git a/src/main/resources/minelp.aw b/src/main/resources/minelp.aw index 7271f6fc..ea742184 100644 --- a/src/main/resources/minelp.aw +++ b/src/main/resources/minelp.aw @@ -9,5 +9,3 @@ accessible method net/minecraft/client/render/RenderLayer accessible method net/minecraft/client/render/RenderLayer$MultiPhase getPhases ()Lnet/minecraft/client/render/RenderLayer$MultiPhaseParameters; accessible method net/minecraft/client/render/RenderPhase$TextureBase getId ()Ljava/util/Optional; accessible field net/minecraft/client/render/RenderLayer$MultiPhaseParameters texture Lnet/minecraft/client/render/RenderPhase$TextureBase; - -accessible method net/minecraft/block/entity/SkullBlockEntity fetchProfile (Ljava/lang/String;)Ljava/util/concurrent/CompletableFuture; \ No newline at end of file diff --git a/src/main/resources/minelp.mixin.json b/src/main/resources/minelp.mixin.json index ac4aa1d6..0bd6c039 100644 --- a/src/main/resources/minelp.mixin.json +++ b/src/main/resources/minelp.mixin.json @@ -12,6 +12,7 @@ "MixinSkullBlockEntityRenderer", "MixinHeldItemRenderer", "MixinClientPlayerEntity", + "MixinLivingEntity", "MixinPlayerMoveC2SPacket", "MixinPlayerPositionLookS2CPacket", "MixinVertextConsumers",