diff --git a/build.gradle b/build.gradle index 0604a1f1..4892b2bc 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,7 @@ java.toolchain.languageVersion = JavaLanguageVersion.of(16) println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch')) minecraft { mappings channel: "${mcp_channel}", version: "${mcp_mappings}" - + accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') runs { @@ -129,6 +129,15 @@ def reobfArtifact = artifacts.add('default', reobfFile) { type 'jar' builtBy 'reobfJar' } + + +task deobfJar(type: Jar) { + build.dependsOn it + from sourceSets.main.output + classifier = 'deobf' + from file("LICENSE") +} + publishing { publications { mavenJava(MavenPublication) { diff --git a/src/main/java/com/shynieke/statues/client/render/PlayerStatueRenderer.java b/src/main/java/com/shynieke/statues/client/render/PlayerStatueRenderer.java index 9fa9e1dc..84101092 100644 --- a/src/main/java/com/shynieke/statues/client/render/PlayerStatueRenderer.java +++ b/src/main/java/com/shynieke/statues/client/render/PlayerStatueRenderer.java @@ -7,10 +7,12 @@ import com.mojang.math.Vector3f; import com.shynieke.statues.client.model.PlayerStatueModel; import com.shynieke.statues.entity.PlayerStatue; +import com.shynieke.statues.util.SkinUtil; import net.minecraft.client.Minecraft; import net.minecraft.client.model.HumanoidModel; import net.minecraft.client.model.geom.ModelLayers; import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.entity.LivingEntityRenderer; import net.minecraft.client.renderer.entity.layers.CustomHeadLayer; @@ -18,12 +20,9 @@ import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer; import net.minecraft.client.renderer.entity.layers.ItemInHandLayer; import net.minecraft.client.resources.DefaultPlayerSkin; -import net.minecraft.client.resources.SkinManager; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; -import java.util.Map; - public class PlayerStatueRenderer extends LivingEntityRenderer { private final PlayerStatueModel playerModel; private final PlayerStatueModel slimPlayerModel; @@ -56,15 +55,8 @@ private ResourceLocation getSkin(GameProfile gameProfile) { if (!gameProfile.isComplete()) { return defaultTexture; } else { - final Minecraft minecraft = Minecraft.getInstance(); - SkinManager skinManager = minecraft.getSkinManager(); - final Map loadSkinFromCache = skinManager.getInsecureSkinInformation(gameProfile); // returned map may or may not be typed - if (loadSkinFromCache.containsKey(MinecraftProfileTexture.Type.SKIN)) { - return skinManager.registerTexture(loadSkinFromCache.get(Type.SKIN), Type.SKIN); - } - else { - return DefaultPlayerSkin.getDefaultSkin(gameProfile.getId()); - } + SkinUtil.SkinRenderData skinRenderData = SkinUtil.getSkinRenderData(gameProfile); + return skinRenderData.skinLocation; } } diff --git a/src/main/java/com/shynieke/statues/client/render/PlayerTileInventoryRenderer.java b/src/main/java/com/shynieke/statues/client/render/PlayerTileInventoryRenderer.java index 2c620703..bb518058 100644 --- a/src/main/java/com/shynieke/statues/client/render/PlayerTileInventoryRenderer.java +++ b/src/main/java/com/shynieke/statues/client/render/PlayerTileInventoryRenderer.java @@ -11,6 +11,7 @@ import net.minecraft.client.model.geom.EntityModelSet; import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.nbt.CompoundTag; @@ -123,9 +124,9 @@ public void renderPlayerItem(ItemStack stack, PoseStack poseStack, MultiBufferSo } public void renderItem(GameProfile gameprofile, PoseStack poseStack, MultiBufferSource bufferSource, int combinedLight) { - boolean flag = gameprofile != null && gameprofile.isComplete() && SkinUtil.isSlimSkin(gameprofile.getId()); - VertexConsumer vertexConsumer = bufferSource.getBuffer(PlayerTileRenderer.getRenderType(gameprofile)); - if(flag) { + SkinUtil.SkinRenderData skinRenderData = SkinUtil.getSkinRenderData(gameprofile); + VertexConsumer vertexConsumer = bufferSource.getBuffer(RenderType.entityTranslucent(skinRenderData.skinLocation)); + if(skinRenderData.isSlim) { if(slimModel != null) { slimModel.renderToBuffer(poseStack, vertexConsumer, combinedLight, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F); } @@ -135,4 +136,4 @@ public void renderItem(GameProfile gameprofile, PoseStack poseStack, MultiBuffer } } } -} \ No newline at end of file +} diff --git a/src/main/java/com/shynieke/statues/client/render/PlayerTileRenderer.java b/src/main/java/com/shynieke/statues/client/render/PlayerTileRenderer.java index e8c554fe..4d088fea 100644 --- a/src/main/java/com/shynieke/statues/client/render/PlayerTileRenderer.java +++ b/src/main/java/com/shynieke/statues/client/render/PlayerTileRenderer.java @@ -1,8 +1,6 @@ package com.shynieke.statues.client.render; import com.mojang.authlib.GameProfile; -import com.mojang.authlib.minecraft.MinecraftProfileTexture; -import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.math.Vector3f; @@ -10,7 +8,7 @@ import com.shynieke.statues.client.ClientHandler; import com.shynieke.statues.client.model.StatuePlayerTileModel; import com.shynieke.statues.tiles.PlayerBlockEntity; -import net.minecraft.client.Minecraft; +import com.shynieke.statues.util.SkinUtil; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; @@ -19,13 +17,11 @@ import net.minecraft.client.resources.DefaultPlayerSkin; import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import javax.annotation.Nullable; -import java.util.Map; @OnlyIn(Dist.CLIENT) public class PlayerTileRenderer implements BlockEntityRenderer { @@ -82,13 +78,8 @@ public static RenderType getRenderType(@Nullable GameProfile gameProfileIn) { if (gameProfileIn == null || !gameProfileIn.isComplete()) { return RenderType.entityCutoutNoCull(defaultTexture); } else { - final Minecraft minecraft = Minecraft.getInstance(); - final Map map = minecraft.getSkinManager().getInsecureSkinInformation(gameProfileIn); - if (map.containsKey(Type.SKIN)) { - return RenderType.entityTranslucent(minecraft.getSkinManager().registerTexture((MinecraftProfileTexture)map.get(Type.SKIN), Type.SKIN)); - } else { - return RenderType.entityCutoutNoCull(DefaultPlayerSkin.getDefaultSkin(Player.createPlayerUUID(gameProfileIn))); - } + SkinUtil.SkinRenderData skinRenderData = SkinUtil.getSkinRenderData(gameProfileIn); + return RenderType.entityTranslucent(skinRenderData.skinLocation); } } } diff --git a/src/main/java/com/shynieke/statues/entity/PlayerStatue.java b/src/main/java/com/shynieke/statues/entity/PlayerStatue.java index 6d8ed30d..dd39bcce 100644 --- a/src/main/java/com/shynieke/statues/entity/PlayerStatue.java +++ b/src/main/java/com/shynieke/statues/entity/PlayerStatue.java @@ -81,7 +81,7 @@ public class PlayerStatue extends LivingEntity { /** After punching the stand, the cooldown before you can punch it again without breaking it. */ public long punchCooldown; private int disabledSlots; - private boolean isSlim = false; + private SkinUtil.SkinRenderData currentSkinRenderData; private Rotations headRotation = DEFAULT_HEAD_ROTATION; private Rotations bodyRotation = DEFAULT_BODY_ROTATION; private Rotations leftArmRotation = DEFAULT_LEFTARM_ROTATION; @@ -149,7 +149,6 @@ public Optional getGameProfile() { public void setGameProfile(GameProfile playerProfile) { PlayerBlockEntity.updateGameprofile(playerProfile, (profile) -> { entityData.set(GAMEPROFILE, Optional.of(profile)); - this.setSlim(profile != null && profile.getId() != null && SkinUtil.isSlimSkin(profile.getId())); }); } @@ -171,12 +170,8 @@ public void setUnlocked() { this.entityData.set(LOCKED_BY_UUID, Optional.empty()); } - public void setSlim(boolean slim) { - this.isSlim = slim; - } - public boolean isSlim() { - return this.isSlim; + return this.currentSkinRenderData != null && this.currentSkinRenderData.isSlim; } public void setYOffset(float yOffset) { @@ -890,12 +885,7 @@ public void onSyncedDataUpdated(EntityDataAccessor key) { if (this.level.isClientSide) { this.getGameProfile().ifPresent(gameProfile -> { if(gameProfile.isComplete()) { - Minecraft.getInstance().getSkinManager().registerSkins(gameProfile, (textureType, textureLocation, profileTexture) -> { - if (textureType.equals(MinecraftProfileTexture.Type.SKIN)) { - String metadata = profileTexture.getMetadata("model"); - this.setSlim(metadata != null && metadata.equals("slim")); - } - }, true); + this.currentSkinRenderData = SkinUtil.getSkinRenderData(gameProfile); } }); } diff --git a/src/main/java/com/shynieke/statues/tiles/PlayerBlockEntity.java b/src/main/java/com/shynieke/statues/tiles/PlayerBlockEntity.java index c6b9aa44..fe062d3b 100644 --- a/src/main/java/com/shynieke/statues/tiles/PlayerBlockEntity.java +++ b/src/main/java/com/shynieke/statues/tiles/PlayerBlockEntity.java @@ -2,14 +2,13 @@ import com.google.common.collect.Iterables; import com.mojang.authlib.GameProfile; -import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.minecraft.MinecraftSessionService; import com.mojang.authlib.properties.Property; import com.shynieke.statues.blocks.statues.PlayerStatueBlock; import com.shynieke.statues.init.StatueBlockEntities; import com.shynieke.statues.init.StatueRegistry; +import com.shynieke.statues.util.SkinUtil; import net.minecraft.Util; -import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtUtils; @@ -30,6 +29,7 @@ import java.util.function.Consumer; public class PlayerBlockEntity extends BlockEntity implements Nameable { + @Nullable private static GameProfileCache profileCache; @Nullable @@ -38,7 +38,7 @@ public class PlayerBlockEntity extends BlockEntity implements Nameable { private static Executor mainThreadExecutor; private GameProfile playerProfile; - private boolean isSlim = false; + private SkinUtil.SkinRenderData currentSkinRenderData; private boolean comparatorApplied; private boolean onlineChecking; private int checkerCooldown; @@ -123,19 +123,14 @@ public GameProfile getPlayerProfile() { } public boolean isSlim() { - return this.isSlim; + return this.currentSkinRenderData != null && this.currentSkinRenderData.isSlim; } public void setPlayerProfile(@Nullable GameProfile profile) { synchronized(this) { this.playerProfile = profile; - if (this.level != null && this.level.isClientSide && this.playerProfile != null && this.playerProfile.isComplete() ) { - Minecraft.getInstance().getSkinManager().registerSkins(this.playerProfile, (textureType, textureLocation, profileTexture) -> { - if (textureType.equals(MinecraftProfileTexture.Type.SKIN)) { - String metadata = profileTexture.getMetadata("model"); - this.isSlim = metadata != null && metadata.equals("slim"); - } - }, true); + if (this.level != null && this.level.isClientSide && this.playerProfile != null) { + this.currentSkinRenderData = SkinUtil.getSkinRenderData(profile); } } diff --git a/src/main/java/com/shynieke/statues/util/SkinUtil.java b/src/main/java/com/shynieke/statues/util/SkinUtil.java index aa8e42d8..7fe47f73 100644 --- a/src/main/java/com/shynieke/statues/util/SkinUtil.java +++ b/src/main/java/com/shynieke/statues/util/SkinUtil.java @@ -1,8 +1,68 @@ package com.shynieke.statues.util; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.minecraft.MinecraftProfileTexture; +import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.DefaultPlayerSkin; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Player; + +import java.util.HashMap; +import java.util.Map; import java.util.UUID; public class SkinUtil { + + public static class SkinRenderData { + public ResourceLocation skinLocation; + public boolean isSlim = false; + + public SkinRenderData(GameProfile playerProfile) { + UUID tempUUID = Player.createPlayerUUID(playerProfile); + skinLocation = DefaultPlayerSkin.getDefaultSkin(tempUUID); + isSlim = DefaultPlayerSkin.getSkinModelName(tempUUID).equals("slim"); + } + + SkinRenderData(ResourceLocation skinLocation) { + this.skinLocation = skinLocation; + } + } + + private static final SkinRenderData NULL_PROFILE_DATA = new SkinRenderData(DefaultPlayerSkin.getDefaultSkin()); + + private static final Map SKINRENDER_CACHE = new HashMap<>(); + + /** + * Will return defaults until data is retrieved. And will create a request if none has been done before. + * + * As it is a reference for things like entities and tile entities you can keep a copy. + * + * May want to possibly store when the object was created or if the return timed to check when things come online. + * + * @param playerProfile + * @return + */ + public static SkinRenderData getSkinRenderData(GameProfile playerProfile) { + if(playerProfile == null) { + return NULL_PROFILE_DATA; + } + UUID playerId = playerProfile.getId(); + if(!SKINRENDER_CACHE.containsKey(playerId)) { + SkinRenderData newRenderData = new SkinRenderData(playerProfile); + SKINRENDER_CACHE.put(playerId, newRenderData); + Minecraft.getInstance().getSkinManager().registerSkins(playerProfile, (textureType, textureLocation, profileTexture) -> { + if (textureType.equals(MinecraftProfileTexture.Type.SKIN)) { + String metadata = profileTexture.getMetadata("model"); + newRenderData.skinLocation = textureLocation; + newRenderData.isSlim = metadata != null && metadata.equals("slim"); + } + }, true); + return newRenderData; + } else { + return SKINRENDER_CACHE.get(playerId); + } + } + public static boolean isSlimSkin(UUID playerUUID) { return (playerUUID.hashCode() & 1) == 1; }