Adds skin ears from MinecraftCapes.co.uk + Clientside linked account skins + Elytra textures (#539)

* Added ears geometry support

* Added ear fetching from mc capes

* Added support for deadmau5

* Commented, documented and cleaned code

* Allow bedrock players to see their java skin/cape/ears when joining

* Optimised Imports

* Fix missing else statement

* Moved ears and fixed elytra skins

* Added ears config option

* Fixed cape/elytra transparency

* Fixed slim skin geometry

* Fixed async ears request and added alex skin

* Fixed default elytra not showing with no cape

* Moved to normal Base64 functions

Co-authored-by: James Harrison <james@fasttortoise.co.uk>
This commit is contained in:
rtm516 2020-05-23 22:06:34 +01:00 committed by GitHub
parent 1664221fa9
commit fc6532732d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 838 additions and 43 deletions

View file

@ -116,6 +116,11 @@ public class GeyserBukkitConfiguration implements GeyserConfiguration {
return config.getBoolean("allow-third-party-capes", true); return config.getBoolean("allow-third-party-capes", true);
} }
@Override
public boolean isAllowThirdPartyEars() {
return config.getBoolean("allow-third-party-ears", false);
}
@Override @Override
public String getDefaultLocale() { public String getDefaultLocale() {
return config.getString("default-locale", "en_us"); return config.getString("default-locale", "en_us");

View file

@ -115,6 +115,11 @@ public class GeyserBungeeConfiguration implements GeyserConfiguration {
return config.getBoolean("allow-third-party-capes", true); return config.getBoolean("allow-third-party-capes", true);
} }
@Override
public boolean isAllowThirdPartyEars() {
return config.getBoolean("allow-third-party-ears", false);
}
@Override @Override
public String getDefaultLocale() { public String getDefaultLocale() {
return config.getString("default-locale", "en_us"); return config.getString("default-locale", "en_us");

View file

@ -109,6 +109,11 @@ public class GeyserSpongeConfiguration implements GeyserConfiguration {
return node.getNode("allow-third-party-capes").getBoolean(true); return node.getNode("allow-third-party-capes").getBoolean(true);
} }
@Override
public boolean isAllowThirdPartyEars() {
return node.getNode("allow-third-party-ears").getBoolean(false);
}
@Override @Override
public String getDefaultLocale() { public String getDefaultLocale() {
return node.getNode("default-locale").getString("en_us"); return node.getNode("default-locale").getString("en_us");

View file

@ -65,6 +65,9 @@ public class GeyserStandaloneConfiguration implements GeyserConfiguration {
@JsonProperty("allow-third-party-capes") @JsonProperty("allow-third-party-capes")
private boolean allowThirdPartyCapes; private boolean allowThirdPartyCapes;
@JsonProperty("allow-third-party-ears")
private boolean allowThirdPartyEars;
@JsonProperty("default-locale") @JsonProperty("default-locale")
private String defaultLocale; private String defaultLocale;

View file

@ -70,6 +70,9 @@ public class GeyserVelocityConfiguration implements GeyserConfiguration {
@JsonProperty("allow-third-party-capes") @JsonProperty("allow-third-party-capes")
private boolean allowThirdPartyCapes; private boolean allowThirdPartyCapes;
@JsonProperty("allow-third-party-ears")
private boolean allowThirdPartyEars;
@JsonProperty("default-locale") @JsonProperty("default-locale")
private String defaultLocale; private String defaultLocale;

View file

@ -52,6 +52,8 @@ public interface GeyserConfiguration {
boolean isAllowThirdPartyCapes(); boolean isAllowThirdPartyCapes();
boolean isAllowThirdPartyEars();
String getDefaultLocale(); String getDefaultLocale();
Path getFloodgateKeyFile(); Path getFloodgateKeyFile();

View file

@ -207,6 +207,17 @@ public class GeyserSession implements CommandSender {
upstream.sendPacket(playStatusPacket); upstream.sendPacket(playStatusPacket);
} }
public void fetchOurSkin(PlayerListPacket.Entry entry) {
PlayerSkinPacket playerSkinPacket = new PlayerSkinPacket();
playerSkinPacket.setUuid(authData.getUUID());
playerSkinPacket.setSkin(entry.getSkin());
playerSkinPacket.setOldSkinName("OldName");
playerSkinPacket.setNewSkinName("NewName");
playerSkinPacket.setTrustedSkin(true);
upstream.sendPacket(playerSkinPacket);
getConnector().getLogger().debug("Sending skin for " + playerEntity.getUsername() + " " + authData.getUUID());
}
public void login() { public void login() {
if (connector.getAuthType() != AuthType.ONLINE) { if (connector.getAuthType() != AuthType.ONLINE) {
connector.getLogger().info( connector.getLogger().info(

View file

@ -25,6 +25,7 @@
package org.geysermc.connector.network.translators.java.entity.player; package org.geysermc.connector.network.translators.java.entity.player;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.entity.PlayerEntity;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
@ -51,8 +52,12 @@ public class JavaPlayerListEntryTranslator extends PacketTranslator<ServerPlayer
boolean self = entry.getProfile().getId().equals(session.getPlayerEntity().getUuid()); boolean self = entry.getProfile().getId().equals(session.getPlayerEntity().getUuid());
PlayerEntity playerEntity = session.getPlayerEntity(); PlayerEntity playerEntity = session.getPlayerEntity();
if (self) playerEntity.setProfile(entry.getProfile()); if (self) {
else { playerEntity.setProfile(entry.getProfile());
SkinUtils.requestAndHandleSkinAndCape(playerEntity, session, skinAndCape -> {
GeyserConnector.getInstance().getLogger().debug("Loading Local Bedrock Java Skin Data");
});
} else {
playerEntity = new PlayerEntity( playerEntity = new PlayerEntity(
entry.getProfile(), entry.getProfile(),
-1, -1,

View file

@ -35,10 +35,10 @@ import org.geysermc.connector.GeyserConnector;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.*; import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.Base64; import java.util.Base64;
import java.util.Map; import java.util.Map;
@ -51,6 +51,8 @@ public class SkinProvider {
public static final byte[] STEVE_SKIN = new ProvidedSkin("bedrock/skin/skin_steve.png").getSkin(); public static final byte[] STEVE_SKIN = new ProvidedSkin("bedrock/skin/skin_steve.png").getSkin();
public static final Skin EMPTY_SKIN = new Skin(-1, "steve", STEVE_SKIN); public static final Skin EMPTY_SKIN = new Skin(-1, "steve", STEVE_SKIN);
public static final byte[] ALEX_SKIN = new ProvidedSkin("bedrock/skin/skin_alex.png").getSkin();
public static final Skin EMPTY_SKIN_ALEX = new Skin(-1, "alex", ALEX_SKIN);
private static Map<UUID, Skin> cachedSkins = new ConcurrentHashMap<>(); private static Map<UUID, Skin> cachedSkins = new ConcurrentHashMap<>();
private static Map<UUID, CompletableFuture<Skin>> requestedSkins = new ConcurrentHashMap<>(); private static Map<UUID, CompletableFuture<Skin>> requestedSkins = new ConcurrentHashMap<>();
@ -58,12 +60,49 @@ public class SkinProvider {
private static Map<String, Cape> cachedCapes = new ConcurrentHashMap<>(); private static Map<String, Cape> cachedCapes = new ConcurrentHashMap<>();
private static Map<String, CompletableFuture<Cape>> requestedCapes = new ConcurrentHashMap<>(); private static Map<String, CompletableFuture<Cape>> requestedCapes = new ConcurrentHashMap<>();
public static final SkinGeometry EMPTY_GEOMETRY = SkinProvider.SkinGeometry.getLegacy("geometry.humanoid"); public static final SkinGeometry EMPTY_GEOMETRY = SkinProvider.SkinGeometry.getLegacy(false);
private static Map<UUID, SkinGeometry> cachedGeometry = new ConcurrentHashMap<>(); private static Map<UUID, SkinGeometry> cachedGeometry = new ConcurrentHashMap<>();
public static final boolean ALLOW_THIRD_PARTY_EARS = GeyserConnector.getInstance().getConfig().isAllowThirdPartyEars();
public static String EARS_GEOMETRY;
public static String EARS_GEOMETRY_SLIM;
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
private static final int CACHE_INTERVAL = 8 * 60 * 1000; // 8 minutes private static final int CACHE_INTERVAL = 8 * 60 * 1000; // 8 minutes
static {
/* Load in the normal ears geometry */
InputStream earsStream = Toolbox.getResource("bedrock/skin/geometry.humanoid.ears.json");
StringBuilder earsDataBuilder = new StringBuilder();
try (Reader reader = new BufferedReader(new InputStreamReader(earsStream, Charset.forName(StandardCharsets.UTF_8.name())))) {
int c = 0;
while ((c = reader.read()) != -1) {
earsDataBuilder.append((char) c);
}
} catch (IOException e) {
throw new AssertionError("Unable to load ears geometry", e);
}
EARS_GEOMETRY = earsDataBuilder.toString();
/* Load in the slim ears geometry */
earsStream = Toolbox.getResource("bedrock/skin/geometry.humanoid.earsSlim.json");
earsDataBuilder = new StringBuilder();
try (Reader reader = new BufferedReader(new InputStreamReader(earsStream, Charset.forName(StandardCharsets.UTF_8.name())))) {
int c = 0;
while ((c = reader.read()) != -1) {
earsDataBuilder.append((char) c);
}
} catch (IOException e) {
throw new AssertionError("Unable to load ears geometry", e);
}
EARS_GEOMETRY_SLIM = earsDataBuilder.toString();
}
public static boolean hasSkinCached(UUID uuid) { public static boolean hasSkinCached(UUID uuid) {
return cachedSkins.containsKey(uuid); return cachedSkins.containsKey(uuid);
} }
@ -167,6 +206,43 @@ public class SkinProvider {
return CompletableFuture.completedFuture(officialCape); return CompletableFuture.completedFuture(officialCape);
} }
public static CompletableFuture<Skin> requestEars(String earsUrl, EarsProvider provider, boolean newThread, Skin skin) {
if (earsUrl == null || earsUrl.isEmpty()) return CompletableFuture.completedFuture(skin);
CompletableFuture<Skin> future;
if (newThread) {
future = CompletableFuture.supplyAsync(() -> supplyEars(skin, earsUrl, provider), EXECUTOR_SERVICE)
.whenCompleteAsync((outSkin, throwable) -> { });
} else {
Skin ears = supplyEars(skin, earsUrl, provider); // blocking
future = CompletableFuture.completedFuture(ears);
}
return future;
}
/**
* Try and find an ear texture for a Java player
*
* @param officialSkin The current players skin
* @param playerId The players UUID
* @param username The players username
* @param newThread Should we start in a new thread
* @return The updated skin with ears
*/
public static CompletableFuture<Skin> requestUnofficialEars(Skin officialSkin, UUID playerId, String username, boolean newThread) {
for (EarsProvider provider : EarsProvider.VALUES) {
Skin skin1 = getOrDefault(
requestEars(provider.getUrlFor(playerId, username), provider, newThread, officialSkin),
officialSkin, 4
);
if (skin1.isEars()) {
return CompletableFuture.completedFuture(skin1);
}
}
return CompletableFuture.completedFuture(officialSkin);
}
public static CompletableFuture<Cape> requestBedrockCape(UUID playerID, boolean newThread) { public static CompletableFuture<Cape> requestBedrockCape(UUID playerID, boolean newThread) {
Cape bedrockCape = cachedCapes.getOrDefault(playerID.toString() + ".Bedrock", EMPTY_CAPE); Cape bedrockCape = cachedCapes.getOrDefault(playerID.toString() + ".Bedrock", EMPTY_CAPE);
return CompletableFuture.completedFuture(bedrockCape); return CompletableFuture.completedFuture(bedrockCape);
@ -178,7 +254,7 @@ public class SkinProvider {
} }
public static void storeBedrockSkin(UUID playerID, String skinID, byte[] skinData) { public static void storeBedrockSkin(UUID playerID, String skinID, byte[] skinData) {
Skin skin = new Skin(playerID, skinID, skinData, System.currentTimeMillis(), true); Skin skin = new Skin(playerID, skinID, skinData, System.currentTimeMillis(), true, false);
cachedSkins.put(playerID, skin); cachedSkins.put(playerID, skin);
} }
@ -188,16 +264,36 @@ public class SkinProvider {
} }
public static void storeBedrockGeometry(UUID playerID, byte[] geometryName, byte[] geometryData) { public static void storeBedrockGeometry(UUID playerID, byte[] geometryName, byte[] geometryData) {
SkinGeometry geometry = new SkinGeometry(new String(geometryName), new String(geometryData)); SkinGeometry geometry = new SkinGeometry(new String(geometryName), new String(geometryData), false);
cachedGeometry.put(playerID, geometry); cachedGeometry.put(playerID, geometry);
} }
/**
* Stores the ajusted skin with the ear texture to the cache
*
* @param playerID The UUID to cache it against
* @param skin The skin to cache
*/
public static void storeEarSkin(UUID playerID, Skin skin) {
cachedSkins.put(playerID, skin);
}
/**
* Stores the geometry for a Java player with ears
*
* @param playerID The UUID to cache it against
* @param isSlim If the player is using an slim base
*/
public static void storeEarGeometry(UUID playerID, boolean isSlim) {
cachedGeometry.put(playerID, SkinGeometry.getEars(isSlim));
}
private static Skin supplySkin(UUID uuid, String textureUrl) { private static Skin supplySkin(UUID uuid, String textureUrl) {
byte[] skin = EMPTY_SKIN.getSkinData(); byte[] skin = EMPTY_SKIN.getSkinData();
try { try {
skin = requestImage(textureUrl, null); skin = requestImage(textureUrl, null);
} catch (Exception ignored) {} // just ignore I guess } catch (Exception ignored) {} // just ignore I guess
return new Skin(uuid, textureUrl, skin, System.currentTimeMillis(), false); return new Skin(uuid, textureUrl, skin, System.currentTimeMillis(), false, false);
} }
private static Cape supplyCape(String capeUrl, CapeProvider provider) { private static Cape supplyCape(String capeUrl, CapeProvider provider) {
@ -217,6 +313,48 @@ public class SkinProvider {
); );
} }
/**
* Get the ears texture and place it on the skin from the given URL
*
* @param existingSkin The players current skin
* @param earsUrl The URL to get the ears texture from
* @param provider The ears texture provider
* @return The updated skin with ears
*/
private static Skin supplyEars(Skin existingSkin, String earsUrl, EarsProvider provider) {
try {
// Get the ears texture
BufferedImage ears = ImageIO.read(new URL(earsUrl));
if (ears == null) throw new NullPointerException();
// Convert the skin data to a BufferedImage
int height = (existingSkin.getSkinData().length / 4 / 64);
BufferedImage skinImage = imageDataToBufferedImage(existingSkin.getSkinData(), 64, height);
// Create a new image with the ears texture over it
BufferedImage newSkin = new BufferedImage(skinImage.getWidth(), skinImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D) newSkin.getGraphics();
g.drawImage(skinImage, 0, 0, null);
g.drawImage(ears, 24, 0, null);
// Turn the buffered image back into an array of bytes
byte[] data = bufferedImageToImageData(newSkin);
skinImage.flush();
// Create a new skin object with the new infomation
return new Skin(
existingSkin.getSkinOwner(),
existingSkin.getTextureUrl(),
data,
System.currentTimeMillis(),
true,
true
);
} catch (Exception ignored) {} // just ignore I guess
return existingSkin;
}
private static byte[] requestImage(String imageUrl, CapeProvider provider) throws Exception { private static byte[] requestImage(String imageUrl, CapeProvider provider) throws Exception {
BufferedImage image = downloadImage(imageUrl, provider); BufferedImage image = downloadImage(imageUrl, provider);
GeyserConnector.getInstance().getLogger().debug("Downloaded " + imageUrl); GeyserConnector.getInstance().getLogger().debug("Downloaded " + imageUrl);
@ -226,26 +364,16 @@ public class SkinProvider {
while(image.getWidth() > 64) { while(image.getWidth() > 64) {
image = scale(image); image = scale(image);
} }
BufferedImage newImage = new BufferedImage(64, 32, BufferedImage.TYPE_INT_RGB); BufferedImage newImage = new BufferedImage(64, 32, BufferedImage.TYPE_INT_ARGB);
Graphics g = newImage.createGraphics(); Graphics g = newImage.createGraphics();
g.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null); g.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null);
g.dispose(); g.dispose();
image = newImage; image = newImage;
} }
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(image.getWidth() * 4 + image.getHeight() * 4)) { byte[] data = bufferedImageToImageData(image);
for (int y = 0; y < image.getHeight(); y++) {
for (int x = 0; x < image.getWidth(); x++) {
int rgba = image.getRGB(x, y);
outputStream.write((rgba >> 16) & 0xFF);
outputStream.write((rgba >> 8) & 0xFF);
outputStream.write(rgba & 0xFF);
outputStream.write((rgba >> 24) & 0xFF);
}
}
image.flush(); image.flush();
return outputStream.toByteArray(); return data;
}
} }
private static BufferedImage downloadImage(String imageUrl, CapeProvider provider) throws IOException { private static BufferedImage downloadImage(String imageUrl, CapeProvider provider) throws IOException {
@ -267,7 +395,7 @@ public class SkinProvider {
} }
private static BufferedImage scale(BufferedImage bufferedImage) { private static BufferedImage scale(BufferedImage bufferedImage) {
BufferedImage resized = new BufferedImage(bufferedImage.getWidth() / 2, bufferedImage.getHeight() / 2, BufferedImage.TYPE_INT_RGB); BufferedImage resized = new BufferedImage(bufferedImage.getWidth() / 2, bufferedImage.getHeight() / 2, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = resized.createGraphics(); Graphics2D g2 = resized.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.drawImage(bufferedImage, 0, 0, bufferedImage.getWidth() / 2, bufferedImage.getHeight() / 2, null); g2.drawImage(bufferedImage, 0, 0, bufferedImage.getWidth() / 2, bufferedImage.getHeight() / 2, null);
@ -275,6 +403,60 @@ public class SkinProvider {
return resized; return resized;
} }
/**
* Get the RGBA int for a given index in some image data
*
* @param index Index to get
* @param data Image data to find in
* @return An int representing RGBA
*/
private static int getRGBA(int index, byte[] data) {
return (data[index] & 0xFF) << 16 | (data[index + 1] & 0xFF) << 8 |
data[index + 2] & 0xFF | (data[index + 3] & 0xFF) << 24;
}
/**
* Convert a byte[] to a BufferedImage
*
* @param imageData The byte[] to convert
* @param imageWidth The width of the target image
* @param imageHeight The height of the target image
* @return The converted BufferedImage
*/
public static BufferedImage imageDataToBufferedImage(byte[] imageData, int imageWidth, int imageHeight) {
BufferedImage image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB);
int index = 0;
for (int y = 0; y < imageHeight; y++) {
for (int x = 0; x < imageWidth; x++) {
image.setRGB(x, y, getRGBA(index, imageData));
index += 4;
}
}
return image;
}
/**
* Convert a BufferedImage to a byte[]
*
* @param image The BufferedImage to convert
* @return The converted byte[]
*/
public static byte[] bufferedImageToImageData(BufferedImage image) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(image.getWidth() * 4 + image.getHeight() * 4);
for (int y = 0; y < image.getHeight(); y++) {
for (int x = 0; x < image.getWidth(); x++) {
int rgba = image.getRGB(x, y);
outputStream.write((rgba >> 16) & 0xFF);
outputStream.write((rgba >> 8) & 0xFF);
outputStream.write(rgba & 0xFF);
outputStream.write((rgba >> 24) & 0xFF);
}
}
return outputStream.toByteArray();
}
public static <T> T getOrDefault(CompletableFuture<T> future, T defaultValue, int timeoutInSeconds) { public static <T> T getOrDefault(CompletableFuture<T> future, T defaultValue, int timeoutInSeconds) {
try { try {
return future.get(timeoutInSeconds, TimeUnit.SECONDS); return future.get(timeoutInSeconds, TimeUnit.SECONDS);
@ -297,6 +479,7 @@ public class SkinProvider {
private byte[] skinData; private byte[] skinData;
private long requestedOn; private long requestedOn;
private boolean updated; private boolean updated;
private boolean ears;
private Skin(long requestedOn, String textureUrl, byte[] skinData) { private Skin(long requestedOn, String textureUrl, byte[] skinData) {
this.requestedOn = requestedOn; this.requestedOn = requestedOn;
@ -320,9 +503,26 @@ public class SkinProvider {
public static class SkinGeometry { public static class SkinGeometry {
private String geometryName; private String geometryName;
private String geometryData; private String geometryData;
private boolean failed;
public static SkinGeometry getLegacy(String name) { /**
return new SkinProvider.SkinGeometry("{\"geometry\" :{\"default\" :\"" + name + "\"}}", ""); * Generate generic geometry
*
* @param isSlim Should it be the alex model
* @return The generic geometry object
*/
public static SkinGeometry getLegacy(boolean isSlim) {
return new SkinProvider.SkinGeometry("{\"geometry\" :{\"default\" :\"geometry.humanoid.custom" + (isSlim ? "Slim" : "") + "\"}}", "", true);
}
/**
* Generate basic geometry with ears
*
* @param isSlim Should it be the alex model
* @return The generated geometry for the ears model
*/
public static SkinGeometry getEars(boolean isSlim) {
return new SkinProvider.SkinGeometry("{\"geometry\" :{\"default\" :\"geometry.humanoid.ears" + (isSlim ? "Slim" : "") + "\"}}", (isSlim ? EARS_GEOMETRY_SLIM : EARS_GEOMETRY), false);
} }
} }
@ -365,4 +565,34 @@ public class SkinProvider {
UUID, UUID,
UUID_DASHED UUID_DASHED
} }
/*
* Sorted by 'priority'
*/
@AllArgsConstructor
@NoArgsConstructor
@Getter
public enum EarsProvider {
MINECRAFTCAPES("https://www.minecraftcapes.co.uk/getEars/%s", CapeUrlType.UUID);
public static final EarsProvider[] VALUES = values();
private String url;
private CapeUrlType type;
public String getUrlFor(String type) {
return String.format(url, type);
}
public String getUrlFor(UUID uuid, String username) {
return getUrlFor(toRequestedType(type, uuid, username));
}
public static String toRequestedType(CapeUrlType type, UUID uuid, String username) {
switch (type) {
case UUID: return uuid.toString().replace("-", "");
case UUID_DASHED: return uuid.toString();
default: return username;
}
}
}
} }

View file

@ -53,7 +53,7 @@ public class SkinUtils {
GameProfileData data = GameProfileData.from(profile); GameProfileData data = GameProfileData.from(profile);
SkinProvider.Cape cape = SkinProvider.getCachedCape(data.getCapeUrl()); SkinProvider.Cape cape = SkinProvider.getCachedCape(data.getCapeUrl());
SkinProvider.SkinGeometry geometry = SkinProvider.SkinGeometry.getLegacy("geometry.humanoid.custom" + (data.isAlex() ? "Slim" : "")); SkinProvider.SkinGeometry geometry = SkinProvider.SkinGeometry.getLegacy(data.isAlex());
return buildEntryManually( return buildEntryManually(
profile.getId(), profile.getId(),
@ -88,7 +88,7 @@ public class SkinUtils {
String geometryName, String geometryData) { String geometryName, String geometryData) {
SerializedSkin serializedSkin = SerializedSkin.of( SerializedSkin serializedSkin = SerializedSkin.of(
skinId, geometryName, ImageData.of(skinData), Collections.emptyList(), skinId, geometryName, ImageData.of(skinData), Collections.emptyList(),
ImageData.of(capeData), geometryData, "", true, false, false, capeId, uuid.toString() ImageData.of(capeData), geometryData, "", true, false, !capeId.equals(SkinProvider.EMPTY_CAPE.getCapeId()), capeId, uuid.toString()
); );
PlayerListPacket.Entry entry = new PlayerListPacket.Entry(uuid); PlayerListPacket.Entry entry = new PlayerListPacket.Entry(uuid);
@ -115,6 +115,9 @@ public class SkinUtils {
* @return The built GameProfileData * @return The built GameProfileData
*/ */
public static GameProfileData from(GameProfile profile) { public static GameProfileData from(GameProfile profile) {
// Fallback to the offline mode of working it out
boolean isAlex = ((profile.getId().hashCode() % 2) == 1);
try { try {
GameProfile.Property skinProperty = profile.getProperty("textures"); GameProfile.Property skinProperty = profile.getProperty("textures");
@ -124,7 +127,7 @@ public class SkinUtils {
JsonNode skinTexture = textures.get("SKIN"); JsonNode skinTexture = textures.get("SKIN");
String skinUrl = skinTexture.get("url").asText(); String skinUrl = skinTexture.get("url").asText();
boolean isAlex = skinTexture.has("metadata"); isAlex = skinTexture.has("metadata");
String capeUrl = null; String capeUrl = null;
if (textures.has("CAPE")) { if (textures.has("CAPE")) {
@ -138,7 +141,7 @@ public class SkinUtils {
GeyserConnector.getInstance().getLogger().debug("Got invalid texture data for " + profile.getName() + " " + exception.getMessage()); GeyserConnector.getInstance().getLogger().debug("Got invalid texture data for " + profile.getName() + " " + exception.getMessage());
} }
// return default skin with default cape when texture data is invalid // return default skin with default cape when texture data is invalid
return new GameProfileData(SkinProvider.EMPTY_SKIN.getTextureUrl(), SkinProvider.EMPTY_CAPE.getTextureUrl(), false); return new GameProfileData((isAlex ? SkinProvider.EMPTY_SKIN_ALEX.getTextureUrl() : SkinProvider.EMPTY_SKIN.getTextureUrl()), SkinProvider.EMPTY_CAPE.getTextureUrl(), isAlex);
} }
} }
} }
@ -167,11 +170,38 @@ public class SkinUtils {
), SkinProvider.EMPTY_CAPE, SkinProvider.CapeProvider.VALUES.length * 3); ), SkinProvider.EMPTY_CAPE, SkinProvider.CapeProvider.VALUES.length * 3);
} }
SkinProvider.SkinGeometry geometry = SkinProvider.SkinGeometry.getLegacy("geometry.humanoid.custom" + (data.isAlex() ? "Slim" : "")); SkinProvider.SkinGeometry geometry = SkinProvider.SkinGeometry.getLegacy(data.isAlex());
geometry = SkinProvider.getOrDefault(SkinProvider.requestBedrockGeometry( geometry = SkinProvider.getOrDefault(SkinProvider.requestBedrockGeometry(
geometry, entity.getUuid(), false geometry, entity.getUuid(), false
), geometry, 3); ), geometry, 3);
// Not a bedrock player check for ears
if (geometry.isFailed() && SkinProvider.ALLOW_THIRD_PARTY_EARS) {
boolean isEars = false;
// Its deadmau5, gotta support his skin :)
if (entity.getUuid().toString().equals("1e18d5ff-643d-45c8-b509-43b8461d8614")) {
isEars = true;
} else {
// Get the ears texture for the player
skin = SkinProvider.getOrDefault(SkinProvider.requestUnofficialEars(
skin, entity.getUuid(), entity.getUsername(), false
), skin, 3);
isEars = skin.isEars();
}
// Does the skin have an ears texture
if (isEars) {
// Get the new geometry
geometry = SkinProvider.SkinGeometry.getEars(data.isAlex());
// Store the skin and geometry for the ears
SkinProvider.storeEarSkin(entity.getUuid(), skin);
SkinProvider.storeEarGeometry(entity.getUuid(), data.isAlex());
}
}
if (entity.getLastSkinUpdate() < skin.getRequestedOn()) { if (entity.getLastSkinUpdate() < skin.getRequestedOn()) {
entity.setLastSkinUpdate(skin.getRequestedOn()); entity.setLastSkinUpdate(skin.getRequestedOn());
@ -197,6 +227,10 @@ public class SkinUtils {
playerAddPacket.setAction(PlayerListPacket.Action.ADD); playerAddPacket.setAction(PlayerListPacket.Action.ADD);
playerAddPacket.getEntries().add(updatedEntry); playerAddPacket.getEntries().add(updatedEntry);
session.sendUpstreamPacket(playerAddPacket); session.sendUpstreamPacket(playerAddPacket);
if(entity.getUuid().equals(session.getPlayerEntity().getUuid())) {
session.fetchOurSkin(updatedEntry);
}
} }
} }
} catch (Exception e) { } catch (Exception e) {
@ -217,8 +251,8 @@ public class SkinUtils {
byte[] skinBytes = com.github.steveice10.mc.auth.util.Base64.decode(clientData.getSkinData().getBytes("UTF-8")); byte[] skinBytes = com.github.steveice10.mc.auth.util.Base64.decode(clientData.getSkinData().getBytes("UTF-8"));
byte[] capeBytes = clientData.getCapeData(); byte[] capeBytes = clientData.getCapeData();
byte[] geometryNameBytes = com.github.steveice10.mc.auth.util.Base64.decode(clientData.getGeometryName().getBytes("UTF-8")); byte[] geometryNameBytes = Base64.getDecoder().decode(clientData.getGeometryName().getBytes("UTF-8"));
byte[] geometryBytes = com.github.steveice10.mc.auth.util.Base64.decode(clientData.getGeometryData().getBytes("UTF-8")); byte[] geometryBytes = Base64.getDecoder().decode(clientData.getGeometryData().getBytes("UTF-8"));
if (skinBytes.length <= (128 * 128 * 4) && !clientData.isPersonaSkin()) { if (skinBytes.length <= (128 * 128 * 4) && !clientData.isPersonaSkin()) {
SkinProvider.storeBedrockSkin(playerEntity.getUuid(), data.getSkinUrl(), skinBytes); SkinProvider.storeBedrockSkin(playerEntity.getUuid(), data.getSkinUrl(), skinBytes);
@ -235,14 +269,4 @@ public class SkinUtils {
throw new AssertionError("Failed to cache skin for bedrock user (" + playerEntity.getUsername() + "): ", e); throw new AssertionError("Failed to cache skin for bedrock user (" + playerEntity.getUsername() + "): ", e);
} }
} }
/**
* Create a basic geometry json for the given name
*
* @param geometryName Geometry name to use
* @return Geometry data as a json string
*/
private static String getLegacySkinGeometry(String geometryName) {
return "{\"geometry\" :{\"default\" :\"" + geometryName + "\"}}";
}
} }

View file

@ -0,0 +1,249 @@
{
"format_version": "1.14.0",
"minecraft:geometry": [
{
"bones": [
{
"name" : "root",
"pivot" : [ 0.0, 0.0, 0.0 ]
},
{
"name" : "waist",
"parent" : "root",
"pivot" : [ 0.0, 12.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes" : []
},
{
"name": "body",
"parent" : "waist",
"pivot": [ 0.0, 24.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -4.0, 12.0, -2.0 ],
"size": [ 8, 12, 4 ],
"uv": [ 16, 16 ]
}
]
},
{
"name": "jacket",
"parent" : "body",
"pivot": [ 0.0, 24.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -4.0, 12.0, -2.0 ],
"size": [ 8, 12, 4 ],
"uv": [ 16, 32 ],
"inflate": 0.25
}
]
},
{
"name": "head",
"parent" : "body",
"pivot": [ 0.0, 24.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -4.0, 24.0, -4.0 ],
"size": [ 8, 8, 8 ],
"uv": [ 0, 0 ]
}
]
},
{
"name": "hat",
"parent" : "head",
"pivot": [ 0.0, 24.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -4.0, 24.0, -4.0 ],
"size": [ 8, 8, 8 ],
"uv": [ 32, 0 ],
"inflate": 0.5
}
]
},
{
"name": "leftArm",
"parent" : "body",
"pivot": [ 5.0, 22.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ 4.0, 12.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 32, 48 ]
}
]
},
{
"name": "rightArm",
"parent" : "body",
"pivot": [ -5.0, 22.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -8.0, 12.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 40, 16 ]
}
]
},
{
"name": "leftSleeve",
"parent" : "leftArm",
"pivot": [ 5.0, 22.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ 4.0, 12.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 48, 48 ],
"inflate": 0.25
}
]
},
{
"name": "rightSleeve",
"parent" : "rightArm",
"pivot": [ -5.0, 22.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -8.0, 12.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 40, 32 ],
"inflate": 0.25
}
]
},
{
"name": "leftLeg",
"parent" : "root",
"pivot": [ 1.9, 12.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -0.1, 0.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 0, 16 ]
}
]
},
{
"name": "rightLeg",
"parent" : "root",
"pivot": [ -1.9, 12.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -3.9, 0.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 0, 16 ]
}
]
},
{
"name": "leftPants",
"parent" : "leftLeg",
"pivot": [1.9, 12.0, 0.0],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -0.1, 0.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 0, 48 ],
"inflate": 0.25
}
]
},
{
"name": "rightPants",
"parent" : "rightLeg",
"pivot": [ -1.9, 12.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -3.9, 0.0, -2.0] ,
"size": [ 4, 12, 4 ],
"uv": [ 0, 32],
"inflate": 0.25
}
]
},
{
"name" : "rightItem",
"parent" : "rightArm",
"pivot" : [ -6.0, 15.0, 1.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes" : []
},
{
"name" : "leftItem",
"parent" : "leftArm",
"pivot" : [ 6.0, 15.0, 1.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes" : []
},
{
"name": "leftEar",
"parent" : "head",
"pivot": [ -1.9, 12.0, 0.0 ],
"cubes": [
{
"origin": [ 3.0, 31.0, -0.5 ],
"size": [ 6, 6, 1 ],
"uv": [ 24, 0 ],
"inflate": 0.5
}
]
},
{
"name": "rightEar",
"parent" : "head",
"pivot": [ -1.9, 12.0, 0.0 ],
"cubes": [
{
"origin": [ -9.0, 31.0, -0.5 ],
"size": [ 6, 6, 1 ],
"uv": [ 24, 0 ],
"inflate": 0.5
}
]
}
],
"description": {
"identifier": "geometry.humanoid.ears",
"texture_height": 64,
"texture_width": 64
}
}
]
}

View file

@ -0,0 +1,249 @@
{
"format_version": "1.14.0",
"minecraft:geometry": [
{
"bones": [
{
"name" : "root",
"pivot" : [ 0.0, 0.0, 0.0 ]
},
{
"name" : "waist",
"parent" : "root",
"pivot" : [ 0.0, 12.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes" : []
},
{
"name": "body",
"parent" : "waist",
"pivot": [ 0.0, 24.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -4.0, 12.0, -2.0 ],
"size": [ 8, 12, 4 ],
"uv": [ 16, 16 ]
}
]
},
{
"name": "jacket",
"parent" : "body",
"pivot": [ 0.0, 24.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -4.0, 12.0, -2.0 ],
"size": [ 8, 12, 4 ],
"uv": [ 16, 32 ],
"inflate": 0.25
}
]
},
{
"name": "head",
"parent" : "body",
"pivot": [ 0.0, 24.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -4.0, 24.0, -4.0 ],
"size": [ 8, 8, 8 ],
"uv": [ 0, 0 ]
}
]
},
{
"name": "hat",
"parent" : "head",
"pivot": [ 0.0, 24.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -4.0, 24.0, -4.0 ],
"size": [ 8, 8, 8 ],
"uv": [ 32, 0 ],
"inflate": 0.5
}
]
},
{
"name": "leftArm",
"parent" : "body",
"pivot": [ 5.0, 21.5, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ 4.0, 12, -2.0 ],
"size": [ 3, 12, 4 ],
"uv": [ 32, 48 ]
}
]
},
{
"name": "rightArm",
"parent" : "body",
"pivot": [ -5.0, 21.5, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -7.0, 12, -2.0 ],
"size": [ 3, 12, 4 ],
"uv": [ 40, 16 ]
}
]
},
{
"name": "leftSleeve",
"parent" : "leftArm",
"pivot": [ 5.0, 21.5, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ 4.0, 11.5, -2.0 ],
"size": [ 3, 12, 4 ],
"uv": [ 48, 48 ],
"inflate": 0.25
}
]
},
{
"name": "rightSleeve",
"parent" : "rightArm",
"pivot": [ -5.0, 21.5, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -7.0, 11.5, -2.0 ],
"size": [ 3, 12, 4 ],
"uv": [ 40, 32 ],
"inflate": 0.25
}
]
},
{
"name": "leftLeg",
"parent" : "root",
"pivot": [ 1.9, 12.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -0.1, 0.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 0, 16 ]
}
]
},
{
"name": "rightLeg",
"parent" : "root",
"pivot": [ -1.9, 12.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -3.9, 0.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 0, 16 ]
}
]
},
{
"name": "leftPants",
"parent" : "leftLeg",
"pivot": [1.9, 12.0, 0.0],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -0.1, 0.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 0, 48 ],
"inflate": 0.25
}
]
},
{
"name": "rightPants",
"parent" : "rightLeg",
"pivot": [ -1.9, 12.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -3.9, 0.0, -2.0] ,
"size": [ 4, 12, 4 ],
"uv": [ 0, 32],
"inflate": 0.25
}
]
},
{
"name" : "rightItem",
"parent" : "rightArm",
"pivot" : [ -6.0, 15.0, 1.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes" : []
},
{
"name" : "leftItem",
"parent" : "leftArm",
"pivot" : [ 6.0, 15.0, 1.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes" : []
},
{
"name": "leftEar",
"parent" : "head",
"pivot": [ -1.9, 12.0, 0.0 ],
"cubes": [
{
"origin": [ 3.0, 31.0, -0.5 ],
"size": [ 6, 6, 1 ],
"uv": [ 24, 0 ],
"inflate": 0.5
}
]
},
{
"name": "rightEar",
"parent" : "head",
"pivot": [ -1.9, 12.0, 0.0 ],
"cubes": [
{
"origin": [ -9.0, 31.0, -0.5 ],
"size": [ 6, 6, 1 ],
"uv": [ 24, 0 ],
"inflate": 0.5
}
]
}
],
"description": {
"identifier": "geometry.humanoid.earsSlim",
"texture_height": 64,
"texture_width": 64
}
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

@ -61,6 +61,10 @@ general-thread-pool: 32
# OptiFine capes, LabyMod capes, 5Zig capes and MinecraftCapes # OptiFine capes, LabyMod capes, 5Zig capes and MinecraftCapes
allow-third-party-capes: true allow-third-party-capes: true
# Allow third party deadmau5 ears to be visible. Currently allowing:
# MinecraftCapes
allow-third-party-ears: false
# The default locale if we dont have the one the client requested # The default locale if we dont have the one the client requested
default-locale: en_us default-locale: en_us