Skip to content

Commit

Permalink
New config option, fix classload error outside of dev
Browse files Browse the repository at this point in the history
Signed-off-by: roadhog360 <[email protected]>
  • Loading branch information
Roadhog360 committed Sep 7, 2024
1 parent 0161a0a commit 2802a9e
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@

public class ConfigMain extends ConfigBase {

public static DefaultPlayerSkin.Set defaultSkinSet;
public static DefaultPlayerSkin.Set defaultSkinSet = DefaultPlayerSkin.Set.ALL_DEFAULTS;
public static boolean oldSlimArms = false;

static final String catSkins = "skins";
static final String catHeads = "skins";
static final String catHeads = "heads";

public ConfigMain(File file) {
super(file);

getCategory(catSkins).setComment("Settings for mod-specific patches.");

configCats.add(getCategory(catSkins));
configCats.add(getCategory(catHeads));
}

@Override
Expand All @@ -30,5 +32,9 @@ protected void syncConfigOptions() {
Each set contains the following skins:
""" + ConfigBase.getSkinReplacementDescriptions(), ConfigBase.getSkinReplacementModes(false))
);
oldSlimArms = getBoolean("oldSlimArms", catSkins, false,
"""
Before 1.15, slim-armed skins were a half-pixel lower than the player's torso. Set this to true to re-enable that behavior.
""");
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
package roadhog360.simpleskinbackport.core;

import com.google.common.collect.Lists;
import net.minecraft.util.ResourceLocation;
import org.apache.commons.lang3.tuple.Pair;

import java.util.Arrays;
import java.util.List;
import java.util.UUID;

public class DefaultPlayerSkin {
private static final ResourceLocation[] DEFAULT_SKINS = new ResourceLocation[] {
new ResourceLocation("textures/entity/player/slim/alex.png"),
new ResourceLocation("textures/entity/player/slim/ari.png"),
new ResourceLocation("textures/entity/player/slim/efe.png"),
new ResourceLocation("textures/entity/player/slim/kai.png"),
new ResourceLocation("textures/entity/player/slim/makena.png"),
new ResourceLocation("textures/entity/player/slim/noor.png"),
new ResourceLocation("textures/entity/player/slim/steve.png"),
new ResourceLocation("textures/entity/player/slim/sunny.png"),
new ResourceLocation("textures/entity/player/slim/zuri.png"),

new ResourceLocation("textures/entity/player/wide/alex.png"),
new ResourceLocation("textures/entity/player/wide/ari.png"),
new ResourceLocation("textures/entity/player/wide/efe.png"),
new ResourceLocation("textures/entity/player/wide/kai.png"),
new ResourceLocation("textures/entity/player/wide/makena.png"),
new ResourceLocation("textures/entity/player/wide/noor.png"),
new ResourceLocation("textures/entity/player/wide/steve.png"),
new ResourceLocation("textures/entity/player/wide/sunny.png"),
new ResourceLocation("textures/entity/player/wide/zuri.png")};

public static final ResourceLocation ALEX = DEFAULT_SKINS[0];
public static final ResourceLocation STEVE = DEFAULT_SKINS[15];
private static final PlayerSkin[] DEFAULT_SKINS = new PlayerSkin[] {
new PlayerSkin(true, "alex"), new PlayerSkin(true, "ari"),
new PlayerSkin(true, "efe"), new PlayerSkin(true, "kai"),
new PlayerSkin(true, "makena"), new PlayerSkin(true, "noor"),
new PlayerSkin(true, "steve"), new PlayerSkin(true, "sunny"),
new PlayerSkin(true, "zuri"),

new PlayerSkin(false, "alex"), new PlayerSkin(false, "ari"),
new PlayerSkin(false, "efe"), new PlayerSkin(false, "kai"),
new PlayerSkin(false, "makena"), new PlayerSkin(false, "noor"),
new PlayerSkin(false, "steve"), new PlayerSkin(false, "sunny"),
new PlayerSkin(false, "zuri")};

public static final PlayerSkin ALEX = DEFAULT_SKINS[0];
public static final PlayerSkin STEVE = DEFAULT_SKINS[15];

public static final UUID NULL_UUID = UUID.randomUUID(); //Used if the UUID passed in is somehow null.

Expand All @@ -44,33 +34,23 @@ public enum Set {
// BONUS_CHARACTERS, //Some of the alternate skins from the old legacy console default skin packs. Currently not implemented
;

private final List<Pair<ResourceLocation, Boolean>> skins = Lists.newLinkedList();
private final List<PlayerSkin> skins = Lists.newLinkedList();
private final String description;

Set(String description, ResourceLocation... locs) {
Set(String description, PlayerSkin... locs) {
this.description = description;
for(ResourceLocation location : locs) {
skins.add(Pair.of(location, location.toString().contains("slim")));
}
}

public ResourceLocation getDefaultSkin(int index) {
return getEntryFromIndex(index).getLeft();
}

public ResourceLocation getDefaultSkin(UUID uuid) {
return getDefaultSkin(uuid.hashCode());
skins.addAll(Arrays.asList(locs));
}

public boolean isDefaultSkinSlim(int index) {
return getEntryFromIndex(index).getRight();
public PlayerSkin getDefaultSkin(int index) {
return getEntryFromIndex(index);
}

public boolean isDefaultSkinSlim(UUID uuid) {
return isDefaultSkinSlim(uuid.hashCode());
public PlayerSkin getDefaultSkin(UUID uuid) {
return getDefaultSkin((uuid == null ? NULL_UUID : uuid).hashCode());
}

private Pair<ResourceLocation, Boolean> getEntryFromIndex(int index) {
private PlayerSkin getEntryFromIndex(int index) {
if(skins.isEmpty()) {
throw new RuntimeException("Default skin set " + name() + " had empty skin list. What are you doing!?");
}
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/roadhog360/simpleskinbackport/core/PlayerSkin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package roadhog360.simpleskinbackport.core;

import net.minecraft.util.ResourceLocation;

public class PlayerSkin {
private final boolean slim;
private final String domain;
private final String skinName;
/**
* Lazy loaded and cached. We need to do this since class loading order with mixins is an annoying bitch
*/
private ResourceLocation resource;

public PlayerSkin(boolean slim, String domain, String skinName) {
this.slim = slim;
this.domain = domain;
this.skinName = skinName;
}

public PlayerSkin(boolean slim, String skinName) {
this(slim, null, skinName);
}

public ResourceLocation getResource() {
if(resource == null) {
resource = new ResourceLocation(domain, "textures/entity/player/" + (slim ? "slim" : "wide") + "/" + skinName + ".png");
}
return resource;
}

public boolean isSlim() {
return slim;
}

public String getDomain() {
return domain;
}

public String getSkinName() {
return skinName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,35 @@
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import roadhog360.simpleskinbackport.configuration.configs.ConfigMain;
import roadhog360.simpleskinbackport.core.PlayerSkin;
import roadhog360.simpleskinbackport.ducks.IArmsState;

@Mixin(AbstractClientPlayer.class)
public abstract class MixinAbstractClientPlayer extends EntityPlayer implements SkinManager.SkinAvailableCallback, IArmsState {

@Unique
private PlayerSkin simpleSkinBackport$defaultSkin;

public MixinAbstractClientPlayer(World p_i45324_1_, GameProfile p_i45324_2_) {
super(p_i45324_1_, p_i45324_2_);
}

@Inject(method = "<init>", at = @At(value = "TAIL"))
private void setDefaultSkinState(World p_i45074_1_, GameProfile p_i45074_2_, CallbackInfo ci) {
simpleSkinBackport$setSlim(ConfigMain.defaultSkinSet.isDefaultSkinSlim(getPersistentID()));
simpleSkinBackport$defaultSkin = ConfigMain.defaultSkinSet.getDefaultSkin(getPersistentID());
}

@Redirect(method = "getLocationSkin()Lnet/minecraft/util/ResourceLocation;",
at = @At(value = "FIELD", target = "Lnet/minecraft/client/entity/AbstractClientPlayer;locationStevePng:Lnet/minecraft/util/ResourceLocation;"))
private ResourceLocation setNewDefaultSkinBehavior() {
return ConfigMain.defaultSkinSet.getDefaultSkin(getPersistentID());
private ResourceLocation setNewDefaultSkin() {
simpleSkinBackport$setSlim(simpleSkinBackport$defaultSkin.isSlim());
return simpleSkinBackport$defaultSkin.getResource();
}

// UUID uuid = UUID.randomUUID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import roadhog360.simpleskinbackport.configuration.configs.ConfigMain;
import roadhog360.simpleskinbackport.core.ArmPair;
import roadhog360.simpleskinbackport.core.Utils;
import roadhog360.simpleskinbackport.ducks.INewBipedModel;
Expand Down Expand Up @@ -113,6 +114,9 @@ private void injectNewLimbs(float size, float p_i1149_2_, int texWidth, int texH
@Unique
private ArmPair simpleSkinBackport$slimArmwear;

@Unique
private float simpleSkinBackport$armsRotationPointY;

/**
* Creates the ModelBox instances used for slim arms. Creates dummy models currently, this could probably be more efficient...
*/
Expand Down Expand Up @@ -158,6 +162,8 @@ private void injectNewLimbs(float size, float p_i1149_2_, int texWidth, int texH

simpleSkinBackport$wideArmwear = ArmPair.of(simpleSkinBackport$bipedLeftArmwear, simpleSkinBackport$bipedRightArmwear);
simpleSkinBackport$slimArmwear = ArmPair.of(tempLeftArmwearSlim, tempRightArmwearSlim);

simpleSkinBackport$armsRotationPointY = bipedLeftArm.rotationPointY;
}

@Override
Expand All @@ -168,6 +174,15 @@ private void injectNewLimbs(float size, float p_i1149_2_, int texWidth, int texH
// }

if(simpleSkinBackport$isPlayerModel) {
if(ConfigMain.oldSlimArms) {
if (slim) {
bipedLeftArm.rotationPointY = simpleSkinBackport$armsRotationPointY + 0.5F;
bipedRightArm.rotationPointY = simpleSkinBackport$armsRotationPointY + 0.5F;
} else {
bipedLeftArm.rotationPointY = simpleSkinBackport$armsRotationPointY;
bipedRightArm.rotationPointY = simpleSkinBackport$armsRotationPointY;
}
}
ArmPair arms = slim ? simpleSkinBackport$slimArms : simpleSkinBackport$wideArms;
ArmPair armwear = slim ? simpleSkinBackport$slimArmwear : simpleSkinBackport$wideArmwear;
bipedLeftArm.displayList = arms.getLeftDisplayList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public MixinRenderTFGiant(ModelBiped p_i1257_1_, float p_i1257_2_) {
@Inject(method = "getEntityTexture", at = @At(value = "HEAD"), cancellable = true)
private void overrideSkinAndSetResourceLocation(Entity par1Entity, CallbackInfoReturnable<ResourceLocation> cir) {
boolean usePlayerModel = ConfigModCompat.TFgiantSkinSet == null;
boolean slim = usePlayerModel ? simpleSkinBackport$isClientPlayerSlim() : ConfigModCompat.TFgiantSkinSet.isDefaultSkinSlim(par1Entity.getPersistentID());
boolean slim = usePlayerModel ? simpleSkinBackport$isClientPlayerSlim() : ConfigModCompat.TFgiantSkinSet.getDefaultSkin(par1Entity.getPersistentID()).isSlim();
if(this.modelBipedMain instanceof INewBipedModel model) {
model.simpleSkinBackport$setSlim(slim);
}
if(!usePlayerModel) {
cir.setReturnValue(ConfigModCompat.TFgiantSkinSet.getDefaultSkin(par1Entity.getPersistentID()));
cir.setReturnValue(ConfigModCompat.TFgiantSkinSet.getDefaultSkin(par1Entity.getPersistentID()).getResource());
}
}

Expand Down

0 comments on commit 2802a9e

Please sign in to comment.