Merge pull request #1683 from Gerrygames/abstraction

Fix skull items
This commit is contained in:
Myles 2020-03-21 13:50:48 +00:00 committed by GitHub
commit 9d343a3f29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,14 +1,20 @@
package us.myles.ViaVersion.protocols.protocol1_16to1_15_2.packets; package us.myles.ViaVersion.protocols.protocol1_16to1_15_2.packets;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.ItemRewriter; import us.myles.ViaVersion.api.rewriters.ItemRewriter;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.UUIDIntArrayType;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.MappingData;
import java.util.UUID;
public class InventoryPackets { public class InventoryPackets {
public static void register(Protocol protocol) { public static void register(Protocol protocol) {
@ -131,12 +137,32 @@ public class InventoryPackets {
public static void toClient(Item item) { public static void toClient(Item item) {
if (item == null) return; if (item == null) return;
if (item.getIdentifier() == 771 && item.getTag() != null) {
CompoundTag tag = item.getTag();
CompoundTag ownerTag = tag.get("SkullOwner");
if (ownerTag != null) {
UUID id = UUID.fromString(((StringTag) ownerTag.get("Id")).getValue());
ownerTag.put(new IntArrayTag("Id", UUIDIntArrayType.uuidToIntArray(id)));
}
}
item.setIdentifier(getNewItemId(item.getIdentifier())); item.setIdentifier(getNewItemId(item.getIdentifier()));
} }
public static void toServer(Item item) { public static void toServer(Item item) {
if (item == null) return; if (item == null) return;
item.setIdentifier(getOldItemId(item.getIdentifier())); item.setIdentifier(getOldItemId(item.getIdentifier()));
if (item.getIdentifier() == 771 && item.getTag() != null) {
CompoundTag tag = item.getTag();
CompoundTag ownerTag = tag.get("SkullOwner");
if (ownerTag != null && ownerTag.contains("Id")) {
UUID id = UUIDIntArrayType.uuidFromIntArray(((IntArrayTag) ownerTag.get("Id")).getValue());
ownerTag.put(new StringTag("Id", id.toString()));
}
}
} }
public static int getNewItemId(int id) { public static int getNewItemId(int id) {