Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-11-04 23:30:25 +01:00
Also apply MC-68487 workaround to items
Dieser Commit ist enthalten in:
Ursprung
a786152dfc
Commit
993608b4b4
@ -30,6 +30,7 @@ import com.viaversion.viaversion.api.minecraft.BlockPosition;
|
||||
import com.viaversion.viaversion.api.platform.providers.Provider;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -37,12 +38,12 @@ public class BackwardsBlockEntityProvider implements Provider {
|
||||
private final Map<String, BackwardsBlockEntityProvider.BackwardsBlockEntityHandler> handlers = new HashMap<>();
|
||||
|
||||
public BackwardsBlockEntityProvider() {
|
||||
handlers.put("minecraft:flower_pot", new FlowerPotHandler()); // TODO requires special treatment, manually send
|
||||
handlers.put("minecraft:bed", new BedHandler());
|
||||
handlers.put("minecraft:banner", new BannerHandler());
|
||||
handlers.put("minecraft:skull", new SkullHandler());
|
||||
handlers.put("minecraft:mob_spawner", new SpawnerHandler());
|
||||
handlers.put("minecraft:piston", new PistonHandler());
|
||||
handlers.put("flower_pot", new FlowerPotHandler()); // TODO requires special treatment, manually send
|
||||
handlers.put("bed", new BedHandler());
|
||||
handlers.put("banner", new BannerHandler());
|
||||
handlers.put("skull", new SkullHandler());
|
||||
handlers.put("mob_spawner", new SpawnerHandler());
|
||||
handlers.put("piston", new PistonHandler());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,7 +53,7 @@ public class BackwardsBlockEntityProvider implements Provider {
|
||||
* @return true if present
|
||||
*/
|
||||
public boolean isHandled(String key) {
|
||||
return handlers.containsKey(key);
|
||||
return handlers.containsKey(Key.stripMinecraftNamespace(key));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,7 +70,7 @@ public class BackwardsBlockEntityProvider implements Provider {
|
||||
}
|
||||
|
||||
String id = idTag.getValue();
|
||||
BackwardsBlockEntityHandler handler = handlers.get(id);
|
||||
BackwardsBlockEntityHandler handler = handlers.get(Key.stripMinecraftNamespace(id));
|
||||
if (handler == null) {
|
||||
return tag;
|
||||
}
|
||||
|
@ -17,23 +17,26 @@
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.v1_16_2to1_16_1.rewriter;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.IntArrayTag;
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_16_2to1_16_1.Protocol1_16_2To1_16_1;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_16;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_16_2;
|
||||
import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ClientboundPackets1_16;
|
||||
import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ServerboundPackets1_16;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.IntArrayTag;
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.packet.ClientboundPackets1_16_2;
|
||||
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
||||
import com.viaversion.viaversion.rewriter.RecipeRewriter;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class BlockItemPacketRewriter1_16_2 extends BackwardsItemRewriter<ClientboundPackets1_16_2, ServerboundPackets1_16, Protocol1_16_2To1_16_1> {
|
||||
|
||||
@ -118,29 +121,40 @@ public class BlockItemPacketRewriter1_16_2 extends BackwardsItemRewriter<Clientb
|
||||
protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.user(), wrapper.passthrough(Types.ITEM1_13_2)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToClient(final UserConnection connection, @Nullable final Item item) {
|
||||
if (item != null && item.tag() != null) {
|
||||
addValueHashAsId(item.tag());
|
||||
}
|
||||
return super.handleItemToClient(connection, item);
|
||||
}
|
||||
|
||||
private void handleBlockEntity(CompoundTag tag) {
|
||||
StringTag idTag = tag.getStringTag("id");
|
||||
if (idTag == null) return;
|
||||
if (idTag.getValue().equals("minecraft:skull")) {
|
||||
// Workaround an old client bug: MC-68487
|
||||
CompoundTag skullOwnerTag = tag.getCompoundTag("SkullOwner");
|
||||
if (skullOwnerTag == null) return;
|
||||
|
||||
if (!skullOwnerTag.contains("Id")) return;
|
||||
|
||||
CompoundTag properties = skullOwnerTag.getCompoundTag("Properties");
|
||||
if (properties == null) return;
|
||||
|
||||
ListTag<CompoundTag> textures = properties.getListTag("textures", CompoundTag.class);
|
||||
if (textures == null) return;
|
||||
|
||||
CompoundTag first = !textures.isEmpty() ? textures.get(0) : null;
|
||||
if (first == null) return;
|
||||
|
||||
// Make the client cache the skinprofile over this uuid
|
||||
int hashCode = first.get("Value").getValue().hashCode();
|
||||
int[] uuidIntArray = {hashCode, 0, 0, 0}; //TODO split texture in 4 for a lower collision chance
|
||||
skullOwnerTag.put("Id", new IntArrayTag(uuidIntArray));
|
||||
String id = tag.getString("id");
|
||||
if (id != null && Key.stripMinecraftNamespace(id).equals("skull")) {
|
||||
addValueHashAsId(tag);
|
||||
}
|
||||
}
|
||||
|
||||
private void addValueHashAsId(CompoundTag tag) {
|
||||
// Workaround an old client bug: MC-68487
|
||||
CompoundTag skullOwnerTag = tag.getCompoundTag("SkullOwner");
|
||||
if (skullOwnerTag == null) return;
|
||||
|
||||
if (!skullOwnerTag.contains("Id")) return;
|
||||
|
||||
CompoundTag properties = skullOwnerTag.getCompoundTag("Properties");
|
||||
if (properties == null) return;
|
||||
|
||||
ListTag<CompoundTag> textures = properties.getListTag("textures", CompoundTag.class);
|
||||
if (textures == null) return;
|
||||
|
||||
CompoundTag first = !textures.isEmpty() ? textures.get(0) : null;
|
||||
if (first == null) return;
|
||||
|
||||
// Make the client cache the skinprofile over this uuid
|
||||
int hashCode = first.get("Value").getValue().hashCode();
|
||||
int[] uuidIntArray = {hashCode, 0, 0, 0};
|
||||
skullOwnerTag.put("Id", new IntArrayTag(uuidIntArray));
|
||||
}
|
||||
}
|
||||
|
@ -226,10 +226,10 @@ public class BlockItemPacketRewriter1_16 extends BackwardsItemRewriter<Clientbou
|
||||
}
|
||||
|
||||
private void handleBlockEntity(CompoundTag tag) {
|
||||
StringTag idTag = tag.getStringTag("id");
|
||||
if (idTag == null) return;
|
||||
String id = tag.getString("id");
|
||||
if (id == null) return;
|
||||
|
||||
String id = idTag.getValue();
|
||||
id = Key.namespaced(id);
|
||||
if (id.equals("minecraft:conduit")) {
|
||||
Tag targetUuidTag = tag.remove("Target");
|
||||
if (!(targetUuidTag instanceof IntArrayTag)) return;
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren