mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-22 04:27:59 +01:00
Add some proxies for hdskins. Might remove later.
It can run without crashing without HDSkins
This commit is contained in:
parent
0bcd2c1968
commit
70d24e377f
13 changed files with 174 additions and 130 deletions
|
@ -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}"
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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<MinecraftProfileTexture.Type, Identifier> getProfileTextures(@Nullable GameProfile profile) {
|
||||
return HDSkins.getInstance().getTextures(profile);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
@ParametersAreNonnullByDefault
|
||||
package com.minelittlepony.client.hdskins;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
|
@ -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<ClientReadyCallback> 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<MinecraftProfileTexture.Type, Identifier> 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;
|
||||
|
|
33
src/main/java/com/minelittlepony/client/SkinsProxy.java
Normal file
33
src/main/java/com/minelittlepony/client/SkinsProxy.java
Normal file
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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<MineLPClient> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<Float> 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);
|
||||
}
|
||||
}
|
|
@ -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<Type, MinecraftProfileTexture> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,6 @@
|
|||
"MixinFirstPersonRenderer",
|
||||
"MixinGlStateManager",
|
||||
"MixinItemRenderer",
|
||||
"MixinPlayerEntity"
|
||||
"MixinClientPlayerEntity"
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue