From 9f280f79eb75da894611a25636949ebf0ad7d63e Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 28 Sep 2023 14:07:36 +0100 Subject: [PATCH] Move SkinsProxy to the api package and decouple from the implementations a little better --- .../api/model/ModelAttributes.java | 1 - .../api/pony/DefaultPonySkinHelper.java | 2 ++ .../minelittlepony/api/pony/PonyPosture.java | 4 +--- .../{client => api/pony}/SkinsProxy.java | 20 ++++--------------- .../client/PonySettingsScreen.java | 14 ++++++++++++- .../client/compat/hdskins/MineLPHDSkins.java | 10 ++++------ .../blockentity/skull/PlayerPonySkull.java | 2 +- .../entity/AquaticPlayerPonyRenderer.java | 8 ++------ .../render/entity/PlayerPonyRenderer.java | 2 +- .../npc/textures/PlayerTextureSupplier.java | 2 +- 10 files changed, 29 insertions(+), 36 deletions(-) rename src/main/java/com/minelittlepony/{client => api/pony}/SkinsProxy.java (55%) diff --git a/src/main/java/com/minelittlepony/api/model/ModelAttributes.java b/src/main/java/com/minelittlepony/api/model/ModelAttributes.java index 8f5c5993..c12c18ff 100644 --- a/src/main/java/com/minelittlepony/api/model/ModelAttributes.java +++ b/src/main/java/com/minelittlepony/api/model/ModelAttributes.java @@ -2,7 +2,6 @@ package com.minelittlepony.api.model; import com.minelittlepony.api.config.PonyConfig; import com.minelittlepony.api.pony.*; -import com.minelittlepony.client.*; import com.minelittlepony.common.util.animation.Interpolator; import com.minelittlepony.util.MathUtil; diff --git a/src/main/java/com/minelittlepony/api/pony/DefaultPonySkinHelper.java b/src/main/java/com/minelittlepony/api/pony/DefaultPonySkinHelper.java index a1b4c69f..5eb9065d 100644 --- a/src/main/java/com/minelittlepony/api/pony/DefaultPonySkinHelper.java +++ b/src/main/java/com/minelittlepony/api/pony/DefaultPonySkinHelper.java @@ -11,6 +11,8 @@ import java.util.*; public final class DefaultPonySkinHelper { public static final Identifier STEVE = new Identifier("minelittlepony", "textures/entity/player/wide/steve_pony.png"); + public static final Identifier SEAPONY_SKIN_TYPE_ID = new Identifier("minelp", "seapony"); + private static final Map SKINS = new HashMap<>(); public static SkinTextures getTextures(SkinTextures original) { diff --git a/src/main/java/com/minelittlepony/api/pony/PonyPosture.java b/src/main/java/com/minelittlepony/api/pony/PonyPosture.java index 7e70ad41..cbc28e3d 100644 --- a/src/main/java/com/minelittlepony/api/pony/PonyPosture.java +++ b/src/main/java/com/minelittlepony/api/pony/PonyPosture.java @@ -2,8 +2,6 @@ package com.minelittlepony.api.pony; import com.minelittlepony.api.pony.meta.Race; import com.minelittlepony.api.model.PreviewModel; -import com.minelittlepony.client.SkinsProxy; -import com.minelittlepony.client.render.entity.AquaticPlayerPonyRenderer; import java.util.Optional; @@ -101,7 +99,7 @@ public final class PonyPosture { } return Pony.getManager().getPony(entity).filter(pony -> { return (pony.race() == Race.SEAPONY - || (entity instanceof AbstractClientPlayerEntity player && SkinsProxy.instance.getSkin(AquaticPlayerPonyRenderer.SKIN_TYPE_ID, player).isPresent()) + || (entity instanceof AbstractClientPlayerEntity player && SkinsProxy.instance.getSkin(DefaultPonySkinHelper.SEAPONY_SKIN_TYPE_ID, player).isPresent()) ); }).isPresent(); } diff --git a/src/main/java/com/minelittlepony/client/SkinsProxy.java b/src/main/java/com/minelittlepony/api/pony/SkinsProxy.java similarity index 55% rename from src/main/java/com/minelittlepony/client/SkinsProxy.java rename to src/main/java/com/minelittlepony/api/pony/SkinsProxy.java index ab75877c..2aa92b71 100644 --- a/src/main/java/com/minelittlepony/client/SkinsProxy.java +++ b/src/main/java/com/minelittlepony/api/pony/SkinsProxy.java @@ -1,24 +1,20 @@ -package com.minelittlepony.client; +package com.minelittlepony.api.pony; -import com.minelittlepony.common.client.gui.ScrollContainer; -import com.minelittlepony.common.client.gui.Tooltip; -import com.minelittlepony.common.client.gui.element.Button; import com.mojang.authlib.GameProfile; import java.util.Optional; import java.util.Set; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.texture.PlayerSkinProvider; import net.minecraft.entity.Entity; import net.minecraft.util.Identifier; -import org.jetbrains.annotations.Nullable; - +/** + * Proxy handler for getting player skin data from HDSkins + */ public class SkinsProxy { - public static SkinsProxy instance = new SkinsProxy(); public Identifier getSkinTexture(GameProfile profile) { @@ -26,14 +22,6 @@ public class SkinsProxy { return skins.getSkinTextures(profile).texture(); } - public void renderOption(Screen screen, @Nullable Screen parent, int row, int RIGHT, ScrollContainer content) { - content.addButton(new Button(RIGHT, row += 20, 150, 20)) - .setEnabled(false) - .getStyle() - .setTooltip(Tooltip.of("minelp.options.skins.hdskins.disabled", 200)) - .setText("minelp.options.skins.hdskins.open"); - } - public Optional getSkin(Identifier skinTypeId, AbstractClientPlayerEntity player) { return Optional.empty(); } diff --git a/src/main/java/com/minelittlepony/client/PonySettingsScreen.java b/src/main/java/com/minelittlepony/client/PonySettingsScreen.java index 9c9c4474..ad1068c5 100644 --- a/src/main/java/com/minelittlepony/client/PonySettingsScreen.java +++ b/src/main/java/com/minelittlepony/client/PonySettingsScreen.java @@ -35,6 +35,14 @@ public class PonySettingsScreen extends GameGui { public static final Text SCALE_SHOW = Text.translatable("minelp.debug.scale.sa"); public static final Text SCALE_MIN = Text.translatable("minelp.debug.scale.min"); + public static HorseButtonFactory buttonFactory = (screen, parent, row, RIGHT, content) -> { + content.addButton(new Button(RIGHT, row += 20, 150, 20)) + .setEnabled(false) + .getStyle() + .setTooltip(Tooltip.of("minelp.options.skins.hdskins.disabled", 200)) + .setText("minelp.options.skins.hdskins.open"); + }; + private final PonyConfig config = PonyConfig.getInstance(); private final ScrollContainer content = new ScrollContainer(); @@ -156,7 +164,7 @@ public class PonySettingsScreen extends GameGui { row += 15; content.addButton(new Label(RIGHT, row)).getStyle().setText("minelp.options.skins"); - SkinsProxy.instance.renderOption(this, parent, row, RIGHT, content); + buttonFactory.renderOption(this, parent, row, RIGHT, content); } public Text describeCurrentScale(AbstractSlider sender) { @@ -194,4 +202,8 @@ public class PonySettingsScreen extends GameGui { public void removed() { config.save(); } + + public interface HorseButtonFactory { + void renderOption(Screen screen, @Nullable Screen parent, int row, int RIGHT, ScrollContainer content); + } } 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 9d5784d1..09d8b0d3 100644 --- a/src/main/java/com/minelittlepony/client/compat/hdskins/MineLPHDSkins.java +++ b/src/main/java/com/minelittlepony/client/compat/hdskins/MineLPHDSkins.java @@ -2,8 +2,7 @@ package com.minelittlepony.client.compat.hdskins; import com.minelittlepony.api.config.PonyConfig; import com.minelittlepony.api.config.PonyLevel; -import com.minelittlepony.api.pony.Pony; -import com.minelittlepony.api.pony.PonyData; +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; @@ -29,7 +28,6 @@ import net.minecraft.item.Items; import net.minecraft.util.Identifier; import com.minelittlepony.client.*; -import com.minelittlepony.client.render.entity.AquaticPlayerPonyRenderer; /** * All the interactions with HD Skins. @@ -43,8 +41,9 @@ public class MineLPHDSkins extends SkinsProxy implements ClientModInitializer { @Override public void onInitializeClient() { SkinsProxy.instance = this; + PonySettingsScreen.buttonFactory = this::renderOption; - seaponySkinType = SkinType.register(AquaticPlayerPonyRenderer.SKIN_TYPE_ID, Items.COD_BUCKET.getDefaultStack()); + seaponySkinType = SkinType.register(DefaultPonySkinHelper.SEAPONY_SKIN_TYPE_ID, Items.COD_BUCKET.getDefaultStack()); Wearable.REGISTRY.values().forEach(wearable -> { if (wearable != Wearable.NONE) { wearableTypes.put(SkinType.register(wearable.getId(), Items.BUNDLE.getDefaultStack()), wearable); @@ -80,8 +79,7 @@ public class MineLPHDSkins extends SkinsProxy implements ClientModInitializer { .map(Pony.getManager()::getPony); } - @Override - public void renderOption(Screen screen, @Nullable Screen parent, int row, int RIGHT, ScrollContainer content) { + private void renderOption(Screen screen, @Nullable Screen parent, int row, int RIGHT, ScrollContainer content) { content.addButton(new Button(RIGHT, row += 20, 150, 20)) .onClick(button -> MinecraftClient.getInstance().setScreen( parent instanceof GuiSkins ? parent : GuiSkins.create(screen, HDSkins.getInstance().getSkinServerList()) 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 4ff07b58..be373fdb 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 @@ -3,8 +3,8 @@ package com.minelittlepony.client.render.blockentity.skull; import com.minelittlepony.api.config.PonyConfig; import com.minelittlepony.api.config.PonyLevel; import com.minelittlepony.api.pony.Pony; +import com.minelittlepony.api.pony.SkinsProxy; import com.minelittlepony.api.pony.meta.Race; -import com.minelittlepony.client.SkinsProxy; import com.minelittlepony.client.model.*; import com.minelittlepony.client.render.blockentity.skull.PonySkullRenderer.ISkull; import com.mojang.authlib.GameProfile; diff --git a/src/main/java/com/minelittlepony/client/render/entity/AquaticPlayerPonyRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/AquaticPlayerPonyRenderer.java index 7589e3f4..c15f4654 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/AquaticPlayerPonyRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/AquaticPlayerPonyRenderer.java @@ -1,10 +1,8 @@ package com.minelittlepony.client.render.entity; import com.minelittlepony.api.model.PreviewModel; -import com.minelittlepony.api.pony.Pony; -import com.minelittlepony.api.pony.PonyPosture; +import com.minelittlepony.api.pony.*; import com.minelittlepony.api.pony.meta.Race; -import com.minelittlepony.client.SkinsProxy; import com.minelittlepony.util.MathUtil; import net.minecraft.client.network.AbstractClientPlayerEntity; @@ -16,8 +14,6 @@ import net.minecraft.util.Arm; import net.minecraft.util.Identifier; public class AquaticPlayerPonyRenderer extends PlayerPonyRenderer { - public static final Identifier SKIN_TYPE_ID = new Identifier("minelp", "seapony"); - private boolean wet; public AquaticPlayerPonyRenderer(EntityRendererFactory.Context context, boolean slim) { @@ -27,7 +23,7 @@ public class AquaticPlayerPonyRenderer extends PlayerPonyRenderer { @Override public Identifier getTexture(AbstractClientPlayerEntity player) { if (wet) { - return SkinsProxy.instance.getSkin(SKIN_TYPE_ID, player).orElseGet(() -> super.getTexture(player)); + return SkinsProxy.instance.getSkin(DefaultPonySkinHelper.SEAPONY_SKIN_TYPE_ID, player).orElseGet(() -> super.getTexture(player)); } return super.getTexture(player); } diff --git a/src/main/java/com/minelittlepony/client/render/entity/PlayerPonyRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/PlayerPonyRenderer.java index 4ee63186..89154018 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/PlayerPonyRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/PlayerPonyRenderer.java @@ -3,9 +3,9 @@ package com.minelittlepony.client.render.entity; import com.minelittlepony.api.model.ModelAttributes; import com.minelittlepony.api.model.ModelWrapper; import com.minelittlepony.api.pony.Pony; +import com.minelittlepony.api.pony.SkinsProxy; import com.minelittlepony.api.pony.meta.Race; import com.minelittlepony.api.pony.meta.Wearable; -import com.minelittlepony.client.SkinsProxy; import com.minelittlepony.client.model.*; import com.minelittlepony.client.render.DebugBoundingBoxRenderer; import com.minelittlepony.client.render.PonyRenderContext; diff --git a/src/main/java/com/minelittlepony/client/render/entity/npc/textures/PlayerTextureSupplier.java b/src/main/java/com/minelittlepony/client/render/entity/npc/textures/PlayerTextureSupplier.java index 08f26104..d96ae050 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/npc/textures/PlayerTextureSupplier.java +++ b/src/main/java/com/minelittlepony/client/render/entity/npc/textures/PlayerTextureSupplier.java @@ -6,7 +6,7 @@ import net.minecraft.util.Identifier; import net.minecraft.util.Util; import com.minelittlepony.api.pony.Pony; -import com.minelittlepony.client.SkinsProxy; +import com.minelittlepony.api.pony.SkinsProxy; import java.util.concurrent.CompletableFuture; import java.util.function.Function;