Quick fix for mixin conflict which caused ponies to be broken

This commit is contained in:
Matthew Messinger 2018-08-25 16:53:42 -04:00
parent ca48785add
commit 8eb19c117f
2 changed files with 9 additions and 30 deletions

View file

@ -16,7 +16,6 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -51,12 +50,14 @@ public abstract class MixinPlayerInfo implements INetworkPlayerInfo {
return getResourceLocation(type).orElseGet(() -> playerTextures.get(type)); return getResourceLocation(type).orElseGet(() -> playerTextures.get(type));
} }
@Inject(method = "getSkinType", at = @At("RETURN"), cancellable = true) @Redirect(method = "getSkinType()Ljava/lang/String;",
private void getTextureModel(CallbackInfoReturnable<String> cir) { at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/NetworkPlayerInfo;skinType:Ljava/lang/String;"))
getProfileTexture(Type.SKIN).ifPresent(profile -> {
private String getTextureModel(NetworkPlayerInfo self) {
return getProfileTexture(Type.SKIN).map(profile -> {
String model = profile.getMetadata("model"); String model = profile.getMetadata("model");
cir.setReturnValue(model != null ? model : "default"); return model != null ? model : "default";
}); }).orElse(this.skinType);
} }
@Inject(method = "loadPlayerTextures", @Inject(method = "loadPlayerTextures",

View file

@ -1,44 +1,22 @@
package com.minelittlepony.mixin; package com.minelittlepony.mixin;
import com.minelittlepony.MineLittlePony; import com.minelittlepony.MineLittlePony;
import com.minelittlepony.PonyManager;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
import com.voxelmodpack.hdskins.INetworkPlayerInfo; import com.voxelmodpack.hdskins.INetworkPlayerInfo;
import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.client.network.NetworkPlayerInfo;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(value = NetworkPlayerInfo.class, priority = 999) @Mixin(NetworkPlayerInfo.class)
public abstract class MixinNetworkPlayerInfo implements INetworkPlayerInfo { public abstract class MixinNetworkPlayerInfo implements INetworkPlayerInfo {
@Shadow private String skinType;
@Shadow @Final private GameProfile gameProfile;
@Inject(method = "getSkinType()Ljava/lang/String;", at = @At("RETURN"), cancellable = true) @Inject(method = "getSkinType()Ljava/lang/String;", at = @At("RETURN"), cancellable = true)
private void getSkinType(CallbackInfoReturnable<String> info) { private void getSkinType(CallbackInfoReturnable<String> info) {
info.setReturnValue(MineLittlePony.getInstance().getManager() info.setReturnValue(MineLittlePony.getInstance().getManager()
.getPony((NetworkPlayerInfo) (Object) this) .getPony((NetworkPlayerInfo) (Object) this)
.getRace(false) .getRace(false)
.getModel() .getModel()
.getId(usesSlimArms())); .getId("slim".equals(info.getReturnValue())));
}
private boolean usesSlimArms() {
if (skinType == null) {
return getProfileTexture(Type.SKIN)
.map(profile -> profile.getMetadata("model"))
.filter("slim"::equals)
.isPresent() || PonyManager.isSlimSkin(this.gameProfile.getId());
}
return "slim".equals(skinType);
} }
} }