2019-06-27 02:33:05 +02:00
|
|
|
package com.minelittlepony.client.hdskins;
|
2019-05-28 12:41:06 +02:00
|
|
|
|
2019-07-08 04:47:13 +02:00
|
|
|
import com.minelittlepony.client.MineLittlePony;
|
2019-06-30 04:01:28 +02:00
|
|
|
import com.minelittlepony.client.SkinsProxy;
|
2020-11-10 21:49:30 +01:00
|
|
|
import com.minelittlepony.client.model.ClientPonyModel;
|
2021-05-16 19:05:35 +02:00
|
|
|
import com.minelittlepony.common.client.gui.ScrollContainer;
|
|
|
|
import com.minelittlepony.common.client.gui.element.Button;
|
2019-07-08 04:47:13 +02:00
|
|
|
import com.minelittlepony.common.event.ClientReadyCallback;
|
2020-01-28 11:40:44 +01:00
|
|
|
import com.minelittlepony.hdskins.client.SkinCacheClearCallback;
|
2020-11-10 21:49:30 +01:00
|
|
|
import com.minelittlepony.hdskins.client.ducks.ClientPlayerInfo;
|
|
|
|
import com.minelittlepony.hdskins.client.dummy.DummyPlayer;
|
2020-01-28 11:40:44 +01:00
|
|
|
import com.minelittlepony.hdskins.client.gui.GuiSkins;
|
2020-11-10 21:49:30 +01:00
|
|
|
import com.minelittlepony.hdskins.client.resources.LocalTexture;
|
|
|
|
import com.minelittlepony.hdskins.mixin.client.MixinClientPlayer;
|
2020-03-27 19:14:50 +01:00
|
|
|
import com.minelittlepony.hdskins.profile.SkinType;
|
2020-06-21 00:41:51 +02:00
|
|
|
|
2019-12-09 16:44:47 +01:00
|
|
|
import com.mojang.authlib.GameProfile;
|
2019-11-23 18:28:42 +01:00
|
|
|
|
2021-05-17 23:27:21 +02:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2019-12-09 16:44:47 +01:00
|
|
|
import net.fabricmc.api.ClientModInitializer;
|
2021-05-16 19:05:35 +02:00
|
|
|
import net.minecraft.client.MinecraftClient;
|
|
|
|
import net.minecraft.client.gui.screen.Screen;
|
2020-11-10 21:49:30 +01:00
|
|
|
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
|
|
|
import net.minecraft.item.Items;
|
2019-12-09 16:44:47 +01:00
|
|
|
import net.minecraft.util.Identifier;
|
2019-06-27 02:33:05 +02:00
|
|
|
|
2019-06-30 04:01:28 +02:00
|
|
|
import com.minelittlepony.client.pony.PonyManager;
|
2020-11-10 21:49:30 +01:00
|
|
|
import com.minelittlepony.client.render.EquineRenderManager;
|
2020-01-28 11:40:44 +01:00
|
|
|
import com.minelittlepony.hdskins.client.HDSkins;
|
2019-05-28 12:41:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* All the interactions with HD Skins.
|
|
|
|
*/
|
2019-12-09 16:44:47 +01:00
|
|
|
public class MineLPHDSkins extends SkinsProxy implements ClientModInitializer {
|
2019-05-28 12:41:06 +02:00
|
|
|
|
2020-11-10 21:49:30 +01:00
|
|
|
static SkinType seaponySkinType;
|
|
|
|
|
2019-12-09 16:44:47 +01:00
|
|
|
@Override
|
|
|
|
public void onInitializeClient() {
|
|
|
|
SkinsProxy.instance = this;
|
2019-06-30 04:01:28 +02:00
|
|
|
|
2020-11-10 21:49:30 +01:00
|
|
|
seaponySkinType = SkinType.register(new Identifier("minelp", "seapony"), Items.COD_BUCKET.getDefaultStack());
|
|
|
|
|
2019-12-09 16:44:47 +01:00
|
|
|
ClientReadyCallback.EVENT.register(client -> {
|
|
|
|
// Clear ponies when skins are cleared
|
|
|
|
PonyManager ponyManager = (PonyManager) MineLittlePony.getInstance().getManager();
|
2020-04-04 00:24:08 +02:00
|
|
|
SkinCacheClearCallback.EVENT.register(ponyManager::clearCache);
|
2019-12-09 16:44:47 +01:00
|
|
|
|
|
|
|
// Ponify the skins GUI.
|
2020-01-28 11:40:44 +01:00
|
|
|
GuiSkins.setSkinsGui(GuiSkinsMineLP::new);
|
2019-12-09 16:44:47 +01:00
|
|
|
});
|
2019-06-30 04:01:28 +02:00
|
|
|
}
|
2019-06-30 12:05:38 +02:00
|
|
|
|
2021-05-16 19:05:35 +02:00
|
|
|
@Override
|
2021-05-17 23:27:21 +02:00
|
|
|
public void renderOption(Screen screen, @Nullable Screen parent, int row, int RIGHT, ScrollContainer content) {
|
2021-05-16 19:05:35 +02:00
|
|
|
content.addButton(new Button(RIGHT, row += 20, 150, 20))
|
2021-05-17 23:27:21 +02:00
|
|
|
.onClick(button -> MinecraftClient.getInstance().openScreen(
|
|
|
|
parent instanceof GuiSkins ? parent : GuiSkins.create(screen, HDSkins.getInstance().getSkinServerList())
|
|
|
|
))
|
2021-05-16 19:05:35 +02:00
|
|
|
.getStyle()
|
|
|
|
.setText("minelp.options.skins.hdskins.open");;
|
|
|
|
}
|
|
|
|
|
2020-11-10 21:49:30 +01:00
|
|
|
@Override
|
|
|
|
public Identifier getSeaponySkin(EquineRenderManager<AbstractClientPlayerEntity, ClientPonyModel<AbstractClientPlayerEntity>> manager, AbstractClientPlayerEntity player) {
|
|
|
|
if (player instanceof DummyPlayer) {
|
|
|
|
LocalTexture tex = ((DummyPlayer)player).getTextures().get(seaponySkinType);
|
|
|
|
Identifier id = tex.getId();
|
|
|
|
return id == null ? tex.getDefault() : id;
|
|
|
|
} else {
|
|
|
|
ClientPlayerInfo info = (ClientPlayerInfo)((MixinClientPlayer)player).getBackingClientData();
|
|
|
|
Identifier tex = info.getSkins().getSkin(seaponySkinType);
|
|
|
|
if (tex != null) {
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.getSeaponySkin(manager, player);
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:44:47 +01:00
|
|
|
@Override
|
|
|
|
public Identifier getSkinTexture(GameProfile profile) {
|
|
|
|
|
|
|
|
Identifier skin = HDSkins.getInstance().getProfileRepository().getTextures(profile).get(SkinType.SKIN);
|
2019-05-28 12:41:06 +02:00
|
|
|
|
2019-12-09 16:44:47 +01:00
|
|
|
if (skin != null) {
|
|
|
|
return skin;
|
|
|
|
}
|
2019-06-30 04:01:28 +02:00
|
|
|
|
2019-12-09 16:44:47 +01:00
|
|
|
return super.getSkinTexture(profile);
|
2019-05-28 12:41:06 +02:00
|
|
|
}
|
|
|
|
}
|