vanilla-fixes

Minecraft: Better than Adventure! mod that fixes some issues
git clone git://memoryshards.xyz/vanilla-fixes.git
Log | Files | Refs | README | LICENSE

commit b0b73cffa7db5d057e136894df41f68d97e961a9
parent 25cb7308cc4e1685d6dc90f648244d94a497467c
Author: Amb0s <ambos@disroot.org>
Date:   Thu, 25 Jun 2020 08:07:12 +0200

Important update

- Updated mappings
- Added library
- Improved mixin code
- Cleaned repository

Diffstat:
Mbuild.gradle | 16++++++++++++++--
Mgradle.properties | 4++--
Dplasma-b1.7.3+build.7.jar | 0
Dsettings.gradle | 10----------
Msrc/main/java/ambos/vanillafixes/MinecraftUtil.java | 64+++++++++++++++++++++++++++++++++++++++++++++++++---------------
Msrc/main/java/ambos/vanillafixes/mixin/AbstractClientPlayerMixin.java | 4++--
Msrc/main/java/ambos/vanillafixes/mixin/DeathScreenMixin.java | 4++--
Msrc/main/java/ambos/vanillafixes/mixin/LoginThreadMixin.java | 2+-
Asrc/main/java/ambos/vanillafixes/mixin/PlayerMixin.java | 30++++++++++++++++++++++++++++++
Msrc/main/java/ambos/vanillafixes/mixin/RemoteClientPlayerMixin.java | 2+-
Msrc/main/java/ambos/vanillafixes/mixin/ResourceDownloadThreadMixin.java | 4++--
Msrc/main/java/ambos/vanillafixes/mixin/class_520Mixin.java | 2+-
Msrc/main/resources/vanillafixes.mixins.json | 1+
13 files changed, 105 insertions(+), 38 deletions(-)

diff --git a/build.gradle b/build.gradle @@ -12,7 +12,7 @@ buildscript { } } dependencies { - classpath 'com.github.Chocohead:Fabric-Loom:97d30fb' + classpath 'com.github.Chocohead:Fabric-Loom:bbaa5d7' } } @@ -48,12 +48,24 @@ dependencies { implementation 'org.ow2.asm:asm-commons:8.0' implementation 'org.ow2.asm:asm-tree:8.0' implementation 'org.ow2.asm:asm-util:8.0' + + // java mojang API + implementation group: 'commons-codec', name: 'commons-codec', version: '1.14' + implementation group: 'commons-logging', name: 'commons-logging', version: '1.2' + implementation group: 'org.apache.httpcomponents', name: 'httpasyncclient', version: '4.1.4' + implementation group: 'org.apache.httpcomponents', name: 'httpcore-nio', version: '4.4.13' + implementation group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.13' + implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.8' + implementation group: 'com.mashape.unirest', name: 'unirest-java', version: '1.4.9' + implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1' implementation 'com.github.SparklingComet:java-mojang-api:-SNAPSHOT' //to change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings files("plasma-b1.7.3+build.7.jar") + mappings loom.fromCommit("minecraft-cursed-legacy/Plasma", "b464f27") {spec -> + spec.version = "b1.7.3-12" + } modImplementation "com.github.minecraft-cursed-legacy:cursed-fabric-loader:${project.loader_version}" diff --git a/gradle.properties b/gradle.properties @@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties minecraft_version=b1.7.3 - loader_version=392aab7 - api_version=v0.2.1 + loader_version=8f014a3 + api_version=0.6.0 # Mod Properties mod_version = 1.0.0 diff --git a/plasma-b1.7.3+build.7.jar b/plasma-b1.7.3+build.7.jar Binary files differ. diff --git a/settings.gradle b/settings.gradle @@ -1,10 +0,0 @@ -pluginManagement { - repositories { - jcenter() - maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' - } - gradlePluginPortal() - } -} diff --git a/src/main/java/ambos/vanillafixes/MinecraftUtil.java b/src/main/java/ambos/vanillafixes/MinecraftUtil.java @@ -1,7 +1,11 @@ package ambos.vanillafixes; +import org.apache.commons.codec.binary.Base64; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; import org.shanerx.mojang.Mojang; import org.shanerx.mojang.PlayerProfile; import java.io.IOException; @@ -12,7 +16,7 @@ import java.util.Arrays; import java.util.Optional; public final class MinecraftUtil { - public final static ArrayList<String> RESOURCES_PROXY_URLs = new ArrayList<>(Arrays.asList( + private final static ArrayList<String> RESOURCES_PROXY_URLs = new ArrayList<>(Arrays.asList( "http://resourceproxy.pymcl.net/MinecraftResources/", "https://betacraft.pl/MinecraftResources/" )); @@ -33,22 +37,46 @@ public final class MinecraftUtil { if (!(statusCode == 404)) { return false; } - } catch (IOException e) { + } catch (IOException ignored) { } return true; } + private static boolean isSlim(PlayerProfile playerProfile) { + JSONObject value = null; + + try { + Optional<PlayerProfile.Property> property = playerProfile.getProperties().stream() + .findFirst(); + + if(property.isPresent()) { + value = (JSONObject) new JSONParser() + .parse(new String(Base64.decodeBase64(property.get().getValue()))); + } + + } catch (ParseException e) { + return true; + } + + return value != null && value.toJSONString().contains(Mojang.SkinType.SLIM.toString()); + } + public static String getPlayerSkin(String username) { Mojang mojang = new Mojang(); - String uuid = mojang.getUUIDOfUsername(username); - PlayerProfile playerProfile = mojang.getPlayerProfile(uuid); - Optional<URL> playerSkin = playerProfile.getTextures().get().getSkin(); - if (playerSkin.isPresent()) { - logger.info("Getting player skin: " + playerSkin.get().toString()); - return playerSkin.get().toString(); + try { + String uuid = mojang.getUUIDOfUsername(username); + PlayerProfile playerProfile = mojang.getPlayerProfile(uuid); + Optional<URL> playerSkin = playerProfile.getTextures().flatMap(PlayerProfile.TexturesProperty::getSkin); + + if (playerSkin.isPresent() && !isSlim(playerProfile)) { + logger.info("Getting player skin: " + playerSkin.get().toString()); + return playerSkin.get().toString(); + } + } catch (NullPointerException ignored) { + } return null; @@ -56,19 +84,24 @@ public final class MinecraftUtil { public static String getPlayerCape(String username) { Mojang mojang = new Mojang(); - String uuid = mojang.getUUIDOfUsername(username); - PlayerProfile playerProfile = mojang.getPlayerProfile(uuid); - Optional<URL> playerCape = playerProfile.getTextures().get().getCape(); - if (playerCape.isPresent()) { - logger.info("Getting player cape: " + playerCape.get().toString()); - return playerCape.get().toString(); + try { + String uuid = mojang.getUUIDOfUsername(username); + PlayerProfile playerProfile = mojang.getPlayerProfile(uuid); + Optional<URL> playerCape = playerProfile.getTextures().flatMap(PlayerProfile.TexturesProperty::getCape); + + if (playerCape.isPresent()) { + logger.info("Getting player cape: " + playerCape.get().toString()); + return playerCape.get().toString(); + } + } catch (NullPointerException ignored) { + } return null; } - public static String getResourcesURL() { + public static String getResources() { for (String url : RESOURCES_PROXY_URLs) { if (!isDown(url)) { logger.info("Resource proxy found: " + url); @@ -79,3 +112,4 @@ public final class MinecraftUtil { return null; } } + diff --git a/src/main/java/ambos/vanillafixes/mixin/AbstractClientPlayerMixin.java b/src/main/java/ambos/vanillafixes/mixin/AbstractClientPlayerMixin.java @@ -14,12 +14,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(AbstractClientPlayer.class) abstract class AbstractClientPlayerMixin extends Player { - public AbstractClientPlayerMixin(Level level) { + private AbstractClientPlayerMixin(Level level) { super(level); } @Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Ljava/lang/StringBuilder;toString()Ljava/lang/String;")) - private String toStr(StringBuilder builder, Minecraft minecraft, Level level, Session session, int integer) { + private String changeSkin(StringBuilder builder, Minecraft minecraft, Level level, Session session, int integer) { return MinecraftUtil.getPlayerSkin(session.username); } diff --git a/src/main/java/ambos/vanillafixes/mixin/DeathScreenMixin.java b/src/main/java/ambos/vanillafixes/mixin/DeathScreenMixin.java @@ -9,8 +9,8 @@ import org.spongepowered.asm.mixin.injection.invoke.arg.Args; @Mixin(DeathScreen.class) final class DeathScreenMixin extends Screen { - @ModifyArgs(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/DeathScreen;drawTextWithShadowCentred(Lnet/minecraft/sortme/TextManager;Ljava/lang/String;III)V")) - public void changeString(Args args) { + @ModifyArgs(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/DeathScreen;drawTextWithShadowCentred(Lnet/minecraft/client/render/TextRenderer;Ljava/lang/String;III)V")) + public void changeDeathMessage(Args args) { if (args.get(1) != "Game over!") { args.set(1, "Score: §e" + minecraft.player.method_481()); } diff --git a/src/main/java/ambos/vanillafixes/mixin/LoginThreadMixin.java b/src/main/java/ambos/vanillafixes/mixin/LoginThreadMixin.java @@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(Minecraft.LoginThread.class) final class LoginThreadMixin { @Inject(method = "run", at = @At("HEAD"), cancellable = true, remap = false) - private void run(CallbackInfo info) { + private void onRun(CallbackInfo info) { info.cancel(); } } \ No newline at end of file diff --git a/src/main/java/ambos/vanillafixes/mixin/PlayerMixin.java b/src/main/java/ambos/vanillafixes/mixin/PlayerMixin.java @@ -0,0 +1,30 @@ +package ambos.vanillafixes.mixin; + +import ambos.vanillafixes.MinecraftUtil; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.Player; +import net.minecraft.level.Level; +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.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Player.class) +final class PlayerMixin extends LivingEntity { + @Shadow + public String playerCloakUrl; + + @Shadow + public String name; + + private PlayerMixin(Level level) { + super(level); + } + + @Inject(method = "initCloak", at = @At("RETURN")) + private void onInitCloak(CallbackInfo ci) { + playerCloakUrl = MinecraftUtil.getPlayerCape(name); + cloakUrl = playerCloakUrl; + } +} diff --git a/src/main/java/ambos/vanillafixes/mixin/RemoteClientPlayerMixin.java b/src/main/java/ambos/vanillafixes/mixin/RemoteClientPlayerMixin.java @@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(RemoteClientPlayer.class) abstract class RemoteClientPlayerMixin extends Player { - public RemoteClientPlayerMixin(Level level) { + private RemoteClientPlayerMixin(Level level) { super(level); } diff --git a/src/main/java/ambos/vanillafixes/mixin/ResourceDownloadThreadMixin.java b/src/main/java/ambos/vanillafixes/mixin/ResourceDownloadThreadMixin.java @@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.injection.ModifyConstant; @Mixin(ResourceDownloadThread.class) final class ResourceDownloadThreadMixin { @ModifyConstant(method = "run", constant = @Constant(stringValue = "http://s3.amazonaws.com/MinecraftResources/"), remap = false) - private String getResourcesUrl(String def) { - return MinecraftUtil.getResourcesURL(); + private String changeResourcesURL(String def) { + return MinecraftUtil.getResources(); } } diff --git a/src/main/java/ambos/vanillafixes/mixin/class_520Mixin.java b/src/main/java/ambos/vanillafixes/mixin/class_520Mixin.java @@ -13,7 +13,7 @@ final class class_520Mixin { private int field_2187; @Inject(method = "method_1721", at = @At("RETURN"), cancellable = true) - private void changeBlockHitDelay(CallbackInfo ci) { + private void changeHitDelay(CallbackInfo ci) { field_2187 = 0; } } diff --git a/src/main/resources/vanillafixes.mixins.json b/src/main/resources/vanillafixes.mixins.json @@ -12,6 +12,7 @@ "DeathScreenMixin", "LoginThreadMixin", "MinecraftMixin", + "PlayerMixin", "RemoteClientPlayerMixin", "ResourceDownloadThreadMixin", "TitleScreenMixin"