Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Fix player skull item skins
Browse files Browse the repository at this point in the history
  • Loading branch information
Earthcomputer committed Aug 1, 2020
1 parent d697de1 commit 7ec090c
Showing 1 changed file with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import net.earthcomputer.multiconnect.protocols.v1_15_2.mixin.TameableEntityAccessor;
import net.earthcomputer.multiconnect.protocols.v1_15_2.mixin.WolfEntityAccessor;
import net.earthcomputer.multiconnect.protocols.v1_16.Protocol_1_16;
import net.earthcomputer.multiconnect.transformer.ChunkData;
import net.earthcomputer.multiconnect.transformer.Codecked;
import net.earthcomputer.multiconnect.transformer.UnsignedByte;
import net.earthcomputer.multiconnect.transformer.VarInt;
import net.earthcomputer.multiconnect.transformer.*;
import net.minecraft.block.*;
import net.minecraft.block.enums.JigsawOrientation;
import net.minecraft.block.enums.WallShape;
Expand All @@ -30,6 +27,7 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.PersistentProjectileEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.LongArrayTag;
Expand Down Expand Up @@ -227,6 +225,33 @@ public static void registerTranslators() {
buf.pendingRead(Byte.class, (byte)buf.readEnumConstant(EquipmentSlot.class).ordinal()); // slot
buf.applyPendingReads();
});
ProtocolRegistry.registerInboundTranslator(ItemStack.class, new InboundTranslator<ItemStack>() {
@Override
public void onRead(TransformerByteBuf buf) {
}

@Override
public ItemStack translate(ItemStack from) {
if (from.getItem() == Items.PLAYER_HEAD && from.hasTag()) {
CompoundTag tag = from.getTag();
assert tag != null;
if (tag.contains("SkullOwner", 10)) {
CompoundTag skullOwner = tag.getCompound("SkullOwner");
if (skullOwner.contains("Id", 8)) {
try {
UUID uuid = UUID.fromString(skullOwner.getString("Id"));
from = from.copy();
assert from.getTag() != null;
from.getTag().getCompound("SkullOwner").putUuid("Id", uuid);
} catch (IllegalArgumentException e) {
// uuid failed to parse
}
}
}
}
return from;
}
});

ProtocolRegistry.registerOutboundTranslator(PlayerInteractEntityC2SPacket.class, buf -> {
buf.passthroughWrite(VarInt.class); // entity id
Expand Down Expand Up @@ -272,6 +297,29 @@ public static void registerTranslators() {
buf.passthroughWrite(String.class); // final state
buf.skipWrite(String.class); // joint type
});
ProtocolRegistry.registerOutboundTranslator(ItemStack.class, new OutboundTranslator<ItemStack>() {
@Override
public void onWrite(TransformerByteBuf buf) {
}

@Override
public ItemStack translate(ItemStack from) {
if (from.getItem() == Items.PLAYER_HEAD && from.hasTag()) {
CompoundTag tag = from.getTag();
assert tag != null;
if (tag.contains("SkullOwner", 10)) {
CompoundTag skullOwner = tag.getCompound("SkullOwner");
if (skullOwner.containsUuid("Id")) {
UUID uuid = skullOwner.getUuid("Id");
from = from.copy();
assert from.getTag() != null;
from.getTag().getCompound("SkullOwner").putString("Id", uuid.toString());
}
}
}
return from;
}
});
}

private static Identifier dimensionIdToName(int dimensionId) {
Expand Down

0 comments on commit 7ec090c

Please sign in to comment.