From 70d24e377fe79a71c2d34a0dae7affb9788fa3d9 Mon Sep 17 00:00:00 2001 From: Matthew Messinger Date: Sat, 29 Jun 2019 22:01:28 -0400 Subject: [PATCH] Add some proxies for hdskins. Might remove later. It can run without crashing without HDSkins --- build.gradle | 1 - .../client/hdskins/HDSkinsProxy.java | 26 +++++++++++ .../client/hdskins/MineLPHDSkins.java | 43 +++++++------------ .../client/hdskins/package-info.java | 4 ++ .../client/ClientReadyCallback.java | 42 ++++++++++++++++++ .../com/minelittlepony/client/FabMod.java | 34 +++------------ .../minelittlepony/client/MineLPClient.java | 14 +----- .../com/minelittlepony/client/SkinsProxy.java | 33 ++++++++++++++ .../client/gui/hdskins/IndirectHDSkins.java | 13 +++--- .../client/mixin/MixinClientPlayerEntity.java | 32 ++++++++++++++ .../client/mixin/MixinPlayerEntity.java | 35 --------------- .../skull/PlayerSkullRenderer.java | 25 +++-------- src/main/resources/minelp.mixin.json | 2 +- 13 files changed, 174 insertions(+), 130 deletions(-) create mode 100644 src/hdskins/java/com/minelittlepony/client/hdskins/HDSkinsProxy.java create mode 100644 src/hdskins/java/com/minelittlepony/client/hdskins/package-info.java create mode 100644 src/main/java/com/minelittlepony/client/ClientReadyCallback.java create mode 100644 src/main/java/com/minelittlepony/client/SkinsProxy.java create mode 100644 src/main/java/com/minelittlepony/client/mixin/MixinClientPlayerEntity.java delete mode 100644 src/main/java/com/minelittlepony/client/mixin/MixinPlayerEntity.java diff --git a/build.gradle b/build.gradle index 25524ff1..97f5f92e 100644 --- a/build.gradle +++ b/build.gradle @@ -58,7 +58,6 @@ dependencies { compile "com.minelittlepony:Kirin:${project.kirin_version}" include "com.minelittlepony:Kirin:${project.kirin_version}" - hdskinsCompile sourceSets.main.output hdskinsCompile "com.minelittlepony:HDSkins:${project.hd_skins_version}" } diff --git a/src/hdskins/java/com/minelittlepony/client/hdskins/HDSkinsProxy.java b/src/hdskins/java/com/minelittlepony/client/hdskins/HDSkinsProxy.java new file mode 100644 index 00000000..ff438e53 --- /dev/null +++ b/src/hdskins/java/com/minelittlepony/client/hdskins/HDSkinsProxy.java @@ -0,0 +1,26 @@ +package com.minelittlepony.client.hdskins; + +import com.minelittlepony.client.SkinsProxy; +import com.minelittlepony.client.pony.Pony; +import com.minelittlepony.hdskins.HDSkins; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.minecraft.MinecraftProfileTexture; +import net.minecraft.util.Identifier; + +public class HDSkinsProxy extends SkinsProxy { + + @Override + public Identifier getSkinTexture(GameProfile profile) { + + Identifier skin = HDSkins.getInstance().getTextures(profile).get(MinecraftProfileTexture.Type.SKIN); + if (skin != null && Pony.getBufferedImage(skin) != null) { + return skin; + } + return super.getSkinTexture(profile); + } + + @Override + public void parseSkins() { + HDSkins.getInstance().getSkinParser().execute(); + } +} diff --git a/src/hdskins/java/com/minelittlepony/client/hdskins/MineLPHDSkins.java b/src/hdskins/java/com/minelittlepony/client/hdskins/MineLPHDSkins.java index 99bbc576..33f9a77f 100644 --- a/src/hdskins/java/com/minelittlepony/client/hdskins/MineLPHDSkins.java +++ b/src/hdskins/java/com/minelittlepony/client/hdskins/MineLPHDSkins.java @@ -1,37 +1,34 @@ package com.minelittlepony.client.hdskins; +import com.minelittlepony.MineLittlePony; +import com.minelittlepony.client.ClientReadyCallback; +import com.minelittlepony.client.SkinsProxy; import com.minelittlepony.client.hdskins.gui.DummyPony; import com.minelittlepony.client.hdskins.gui.GuiSkinsMineLP; import com.minelittlepony.client.hdskins.gui.RenderDummyPony; import net.fabricmc.fabric.api.client.render.EntityRendererRegistry; import net.minecraft.client.MinecraftClient; -import net.minecraft.util.Identifier; - -import com.minelittlepony.client.MineLPClient; import com.minelittlepony.client.settings.ClientPonyConfig; import com.minelittlepony.client.LegacySkinConverter; +import com.minelittlepony.client.pony.PonyManager; import com.minelittlepony.hdskins.HDSkins; import com.minelittlepony.hdskins.net.LegacySkinServer; import com.minelittlepony.hdskins.net.SkinServer; import com.minelittlepony.hdskins.net.ValhallaSkinServer; -import com.mojang.authlib.GameProfile; -import com.mojang.authlib.minecraft.MinecraftProfileTexture; - -import javax.annotation.Nullable; - -import java.util.Map; /** * All the interactions with HD Skins. */ -public class MineLPHDSkins extends MineLPClient { +public class MineLPHDSkins { private static final String MINELP_VALHALLA_SERVER = "http://skins.minelittlepony-mod.com"; private static final String MINELP_LEGACY_SERVER = "http://minelpskins.voxelmodpack.com"; private static final String MINELP_LEGACY_GATEWAY = "http://minelpskinmanager.voxelmodpack.com"; public MineLPHDSkins() { + SkinsProxy.instance = new HDSkinsProxy(); + SkinServer legacy = new LegacySkinServer(MINELP_LEGACY_SERVER, MINELP_LEGACY_GATEWAY); SkinServer valhalla = new ValhallaSkinServer(MINELP_VALHALLA_SERVER); // Register pony servers @@ -41,18 +38,13 @@ public class MineLPHDSkins extends MineLPClient { SkinServer.defaultServers.add(legacy); // And make valhalla the default SkinServer.defaultServers.add(0, valhalla); + + ClientReadyCallback.EVENT.register(this::postInit); + + EntityRendererRegistry.INSTANCE.register(DummyPony.class, RenderDummyPony::new); } - /** - * Called when the game is ready. - */ - @Override - public void postInit(MinecraftClient minecraft) { - super.postInit(minecraft); - - // Preview on the select skin gui - EntityRendererRegistry.INSTANCE.register(DummyPony.class, RenderDummyPony::new); - + private void postInit(MinecraftClient minecraft) { HDSkins manager = HDSkins.getInstance(); // Convert legacy pony skins @@ -60,18 +52,15 @@ public class MineLPHDSkins extends MineLPClient { // Parse trigger pixel data manager.addSkinParser(new PonySkinParser()); // Clear ponies when skins are cleared - manager.addClearListener(getManager()::onSkinCacheCleared); + PonyManager ponyManager = (PonyManager) MineLittlePony.getInstance().getManager(); + manager.addClearListener(ponyManager::onSkinCacheCleared); + // Ponify the skins GUI. manager.setSkinsGui(GuiSkinsMineLP::new); } - @Override +// @Override protected ClientPonyConfig createConfig() { return new ClientPonyConfigHDSkins(); } - - @Override - public Map getProfileTextures(@Nullable GameProfile profile) { - return HDSkins.getInstance().getTextures(profile); - } } diff --git a/src/hdskins/java/com/minelittlepony/client/hdskins/package-info.java b/src/hdskins/java/com/minelittlepony/client/hdskins/package-info.java new file mode 100644 index 00000000..9ae247af --- /dev/null +++ b/src/hdskins/java/com/minelittlepony/client/hdskins/package-info.java @@ -0,0 +1,4 @@ +@ParametersAreNonnullByDefault +package com.minelittlepony.client.hdskins; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/client/ClientReadyCallback.java b/src/main/java/com/minelittlepony/client/ClientReadyCallback.java new file mode 100644 index 00000000..daed70af --- /dev/null +++ b/src/main/java/com/minelittlepony/client/ClientReadyCallback.java @@ -0,0 +1,42 @@ +package com.minelittlepony.client; + +import net.fabricmc.fabric.api.event.Event; +import net.fabricmc.fabric.api.event.EventFactory; +import net.fabricmc.fabric.api.event.client.ClientTickCallback; +import net.minecraft.client.MinecraftClient; + +public interface ClientReadyCallback { + + Event EVENT = EventFactory.createArrayBacked(ClientReadyCallback.class, listeners -> client -> { + for (ClientReadyCallback event : listeners) { + event.onClientPostInit(client); + } + }); + + void onClientPostInit(MinecraftClient client); + + class Handler implements ClientTickCallback { + + private static Handler instance; + + private boolean firstTick = true; + + private Handler() {} + + public static void register() { + // make sure to only register once + if (instance == null) { + instance = new Handler(); + ClientTickCallback.EVENT.register(instance); + } + } + + public void tick(MinecraftClient client) { + if (firstTick) { + ClientReadyCallback.EVENT.invoker().onClientPostInit(client); + firstTick = false; + } + + } + } +} diff --git a/src/main/java/com/minelittlepony/client/FabMod.java b/src/main/java/com/minelittlepony/client/FabMod.java index a6fee38e..27521718 100644 --- a/src/main/java/com/minelittlepony/client/FabMod.java +++ b/src/main/java/com/minelittlepony/client/FabMod.java @@ -3,42 +3,20 @@ package com.minelittlepony.client; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.event.client.ClientTickCallback; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.MinecraftClient; import com.minelittlepony.client.gui.hdskins.IndirectHDSkins; -import javax.annotation.Nullable; - -public class FabMod implements ClientModInitializer, ClientTickCallback { - - @Nullable - private MineLPClient mlp; - - private boolean firstTick = true; +public class FabMod implements ClientModInitializer { @Override public void onInitializeClient() { - ClientTickCallback.EVENT.register(this); + MineLPClient mlp = new MineLPClient(); + ClientReadyCallback.Handler.register(); + ClientTickCallback.EVENT.register(mlp::onTick); + ClientReadyCallback.EVENT.register(mlp::postInit); if (FabricLoader.getInstance().isModLoaded("hdskins")) { - mlp = IndirectHDSkins.getConstructor().get(); - } else { - mlp = new MineLPClient(); - } - } - - @Override - public void tick(MinecraftClient client) { - if (mlp == null) { - return; - } - - if (firstTick) { - firstTick = false; - - mlp.postInit(client); - } else { - mlp.onTick(client, client.world != null && client.player != null); + IndirectHDSkins.initialize(); } } } diff --git a/src/main/java/com/minelittlepony/client/MineLPClient.java b/src/main/java/com/minelittlepony/client/MineLPClient.java index 9ae74bd6..0185e3df 100644 --- a/src/main/java/com/minelittlepony/client/MineLPClient.java +++ b/src/main/java/com/minelittlepony/client/MineLPClient.java @@ -76,10 +76,9 @@ public class MineLPClient extends MineLittlePony { renderManager.initialiseRenderers(rm); } - public void onTick(MinecraftClient minecraft, boolean inGame) { - - inGame &= minecraft.currentScreen == null; + public void onTick(MinecraftClient minecraft) { + boolean inGame = minecraft.world != null && minecraft.player != null && minecraft.currentScreen == null; boolean mainMenu = minecraft.currentScreen instanceof TitleScreen; if (!inGame && mainMenu) { @@ -113,15 +112,6 @@ public class MineLPClient extends MineLittlePony { PonySkullRenderer.resolve(); } - public Map getProfileTextures(@Nullable GameProfile profile) { - PlayerSkinProvider provider = MinecraftClient.getInstance().getSkinProvider(); - - return provider.getTextures(profile) - .entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> { - return provider.loadSkin(entry.getValue(), entry.getKey()); - })); - } - @Override public PonyManager getManager() { return ponyManager; diff --git a/src/main/java/com/minelittlepony/client/SkinsProxy.java b/src/main/java/com/minelittlepony/client/SkinsProxy.java new file mode 100644 index 00000000..deabd58e --- /dev/null +++ b/src/main/java/com/minelittlepony/client/SkinsProxy.java @@ -0,0 +1,33 @@ +package com.minelittlepony.client; + +import com.minelittlepony.client.pony.Pony; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.minecraft.MinecraftProfileTexture; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.texture.PlayerSkinProvider; +import net.minecraft.util.Identifier; + +import javax.annotation.Nullable; + +public class SkinsProxy { + + public static SkinsProxy instance = new SkinsProxy(); + + @Nullable + public Identifier getSkinTexture(GameProfile profile) { + PlayerSkinProvider skins = MinecraftClient.getInstance().getSkinProvider(); + + MinecraftProfileTexture texture = skins.getTextures(profile).get(MinecraftProfileTexture.Type.SKIN); + Identifier loc = skins.loadSkin(texture, MinecraftProfileTexture.Type.SKIN); + + if (Pony.getBufferedImage(loc) != null) { + return loc; + } + return null; + } + + public void parseSkins() { + // TODO probably doesn't work without hdskins installed. + // Find a way to re-parse skins without help of hdskins + } +} diff --git a/src/main/java/com/minelittlepony/client/gui/hdskins/IndirectHDSkins.java b/src/main/java/com/minelittlepony/client/gui/hdskins/IndirectHDSkins.java index b665f0d2..fcf81a75 100644 --- a/src/main/java/com/minelittlepony/client/gui/hdskins/IndirectHDSkins.java +++ b/src/main/java/com/minelittlepony/client/gui/hdskins/IndirectHDSkins.java @@ -1,11 +1,12 @@ package com.minelittlepony.client.gui.hdskins; -import com.minelittlepony.client.MineLPClient; - -import java.util.function.Supplier; - public final class IndirectHDSkins { - public static Supplier getConstructor() { - return MineLPHDSkins::new; + public static void initialize() { + try { + Class mlphd = Class.forName("com.minelittlepony.client.hdskins.MineLPHDSkins"); + mlphd.getConstructor().newInstance(); + } catch (Exception e) { + e.printStackTrace(); + } } } diff --git a/src/main/java/com/minelittlepony/client/mixin/MixinClientPlayerEntity.java b/src/main/java/com/minelittlepony/client/mixin/MixinClientPlayerEntity.java new file mode 100644 index 00000000..06faafd1 --- /dev/null +++ b/src/main/java/com/minelittlepony/client/mixin/MixinClientPlayerEntity.java @@ -0,0 +1,32 @@ +package com.minelittlepony.client.mixin; + +import com.minelittlepony.MineLittlePony; +import com.minelittlepony.pony.IPony; +import com.mojang.authlib.GameProfile; +import net.minecraft.client.network.AbstractClientPlayerEntity; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.entity.EntityDimensions; +import net.minecraft.entity.EntityPose; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(ClientPlayerEntity.class) +public abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity { + + public MixinClientPlayerEntity(ClientWorld clientWorld_1, GameProfile gameProfile_1) { + super(clientWorld_1, gameProfile_1); + } + + @Override + public float getActiveEyeHeight(EntityPose entityPose_1, EntityDimensions entitySize_1) { + float value = super.getActiveEyeHeight(entityPose_1, entitySize_1); + + IPony pony = MineLittlePony.getInstance().getManager().getPony(this); + + if (!pony.getRace(false).isHuman()) { + value *= pony.getMetadata().getSize().getEyeHeightFactor(); + } + + return value; + } +} diff --git a/src/main/java/com/minelittlepony/client/mixin/MixinPlayerEntity.java b/src/main/java/com/minelittlepony/client/mixin/MixinPlayerEntity.java deleted file mode 100644 index e784bc7e..00000000 --- a/src/main/java/com/minelittlepony/client/mixin/MixinPlayerEntity.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.minelittlepony.client.mixin; - -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.MineLittlePony; -import com.minelittlepony.pony.IPony; - -import net.minecraft.entity.EntityPose; -import net.minecraft.entity.EntityDimensions; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; - -@Mixin(PlayerEntity.class) -public abstract class MixinPlayerEntity extends LivingEntity { - - private MixinPlayerEntity() {super(null, null);} - - @Inject(method = "getActiveEyeHeight(Lnet/minecraft/entity/EntityPose;Lnet/minecraft/entity/EntityDimensions;)F", - at = @At("RETURN"), - cancellable = true) - protected void redirectGetActiveEyeHeight(EntityPose pose, EntityDimensions size, CallbackInfoReturnable info) { - float value = info.getReturnValueF(); - - IPony pony = MineLittlePony.getInstance().getManager().getPony((PlayerEntity)(Object)this); - - if (!pony.getRace(false).isHuman()) { - value *= pony.getMetadata().getSize().getEyeHeightFactor(); - } - - info.setReturnValue(value); - } -} diff --git a/src/main/java/com/minelittlepony/client/render/tileentities/skull/PlayerSkullRenderer.java b/src/main/java/com/minelittlepony/client/render/tileentities/skull/PlayerSkullRenderer.java index 8e44278f..141732ff 100644 --- a/src/main/java/com/minelittlepony/client/render/tileentities/skull/PlayerSkullRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/tileentities/skull/PlayerSkullRenderer.java @@ -1,25 +1,19 @@ package com.minelittlepony.client.render.tileentities.skull; -import com.minelittlepony.client.MineLPClient; +import com.minelittlepony.client.SkinsProxy; import com.minelittlepony.client.model.components.ModelDeadMau5Ears; -import com.minelittlepony.client.pony.Pony; import com.minelittlepony.client.render.RenderPony; import com.minelittlepony.settings.PonyConfig; import com.minelittlepony.settings.PonyLevel; import com.mojang.authlib.GameProfile; -import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.blaze3d.platform.GlStateManager; -import net.minecraft.client.MinecraftClient; import net.minecraft.client.util.DefaultSkinHelper; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.Identifier; -import java.util.Map; import javax.annotation.Nullable; -import static com.mojang.authlib.minecraft.MinecraftProfileTexture.*; - public class PlayerSkullRenderer extends PonySkull { private final ModelDeadMau5Ears deadMau5 = new ModelDeadMau5Ears(); @@ -43,22 +37,12 @@ public class PlayerSkullRenderer extends PonySkull { deadMau5.setVisible(profile != null && "deadmau5".equals(profile.getName())); if (profile != null) { - Identifier skin = MineLPClient.getInstance().getProfileTextures(profile).get(Type.SKIN); - if (skin != null && Pony.getBufferedImage(skin) != null) { + + Identifier skin = SkinsProxy.instance.getSkinTexture(profile); + if (skin != null) { return skin; } - - MinecraftClient minecraft = MinecraftClient.getInstance(); - Map map = minecraft.getSkinProvider().getTextures(profile); - - if (map.containsKey(Type.SKIN)) { - Identifier loc = minecraft.getSkinProvider().loadSkin(map.get(Type.SKIN), Type.SKIN); - if (Pony.getBufferedImage(loc) != null) { - return loc; - } - } return DefaultSkinHelper.getTexture(PlayerEntity.getUuidFromProfile(profile)); - } return DefaultSkinHelper.getTexture(); @@ -67,6 +51,7 @@ public class PlayerSkullRenderer extends PonySkull { @Override public void render(float animateTicks, float rotation, float scale) { super.render(animateTicks, rotation, scale); + /*render*/ deadMau5.render(animateTicks, 0, 0, rotation, 0, scale); } } diff --git a/src/main/resources/minelp.mixin.json b/src/main/resources/minelp.mixin.json index e172f28d..f369c3f3 100644 --- a/src/main/resources/minelp.mixin.json +++ b/src/main/resources/minelp.mixin.json @@ -11,6 +11,6 @@ "MixinFirstPersonRenderer", "MixinGlStateManager", "MixinItemRenderer", - "MixinPlayerEntity" + "MixinClientPlayerEntity" ] }