use of com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag in project ViaBackwards by ViaVersion.
the class EntityPackets1_18 method registerPackets.
@Override
protected void registerPackets() {
registerMetadataRewriter(ClientboundPackets1_18.ENTITY_METADATA, Types1_18.METADATA_LIST, Types1_17.METADATA_LIST);
protocol.registerClientbound(ClientboundPackets1_18.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// Entity ID
map(Type.INT);
// Hardcore
map(Type.BOOLEAN);
// Gamemode
map(Type.UNSIGNED_BYTE);
// Previous Gamemode
map(Type.BYTE);
// Worlds
map(Type.STRING_ARRAY);
// Dimension registry
map(Type.NBT);
// Current dimension data
map(Type.NBT);
// World
map(Type.STRING);
// Seed
map(Type.LONG);
// Max players
map(Type.VAR_INT);
// Chunk radius
map(Type.VAR_INT);
// Read simulation distance
read(Type.VAR_INT);
handler(worldDataTrackerHandler(1));
handler(wrapper -> {
final CompoundTag registry = wrapper.get(Type.NBT, 0);
final CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
final ListTag biomes = biomeRegistry.get("value");
for (final Tag biome : biomes.getValue()) {
final CompoundTag biomeCompound = ((CompoundTag) biome).get("element");
final StringTag category = biomeCompound.get("category");
if (category.getValue().equals("mountain")) {
category.setValue("extreme_hills");
}
// The client just needs something
biomeCompound.put("depth", new FloatTag(0.125F));
biomeCompound.put("scale", new FloatTag(0.05F));
}
// Track amount of biomes sent
tracker(wrapper.user()).setBiomesSent(biomes.size());
});
}
});
protocol.registerClientbound(ClientboundPackets1_18.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
// Dimension data
map(Type.NBT);
// World
map(Type.STRING);
handler(worldDataTrackerHandler(0));
}
});
}
use of com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag in project ViaBackwards by ViaVersion.
the class Protocol1_18To1_18_2 method registerPackets.
@Override
protected void registerPackets() {
new CommandRewriter1_18_2(this).registerDeclareCommands(ClientboundPackets1_18.DECLARE_COMMANDS);
final PacketHandler entityEffectIdHandler = wrapper -> {
final int id = wrapper.read(Type.VAR_INT);
if ((byte) id != id) {
if (!Via.getConfig().isSuppressConversionWarnings()) {
ViaBackwards.getPlatform().getLogger().warning("Cannot send entity effect id " + id + " to old client");
}
wrapper.cancel();
return;
}
wrapper.write(Type.BYTE, (byte) id);
};
registerClientbound(ClientboundPackets1_18.ENTITY_EFFECT, new PacketRemapper() {
@Override
public void registerMap() {
// Entity id
map(Type.VAR_INT);
handler(entityEffectIdHandler);
}
});
registerClientbound(ClientboundPackets1_18.REMOVE_ENTITY_EFFECT, new PacketRemapper() {
@Override
public void registerMap() {
// Entity id
map(Type.VAR_INT);
handler(entityEffectIdHandler);
}
});
registerClientbound(ClientboundPackets1_18.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// Entity ID
map(Type.INT);
// Hardcore
map(Type.BOOLEAN);
// Gamemode
map(Type.UNSIGNED_BYTE);
// Previous Gamemode
map(Type.BYTE);
// World List
map(Type.STRING_ARRAY);
// Registry
map(Type.NBT);
// Current dimension data
map(Type.NBT);
handler(wrapper -> {
final CompoundTag registry = wrapper.get(Type.NBT, 0);
final CompoundTag dimensionsHolder = registry.get("minecraft:dimension_type");
final ListTag dimensions = dimensionsHolder.get("value");
for (final Tag dimension : dimensions) {
removeTagPrefix(((CompoundTag) dimension).get("element"));
}
removeTagPrefix(wrapper.get(Type.NBT, 1));
});
}
});
registerClientbound(ClientboundPackets1_18.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> removeTagPrefix(wrapper.passthrough(Type.NBT)));
}
});
}
use of com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag in project ViaBackwards by ViaVersion.
the class Protocol1_18To1_18_2 method removeTagPrefix.
private void removeTagPrefix(CompoundTag tag) {
final Tag infiniburnTag = tag.get("infiniburn");
if (infiniburnTag instanceof StringTag) {
final StringTag infiniburn = (StringTag) infiniburnTag;
infiniburn.setValue(infiniburn.getValue().substring(1));
}
}
use of com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag in project ViaBackwards by ViaVersion.
the class BlockItemPackets1_16_2 method handleBlockEntity.
private void handleBlockEntity(CompoundTag tag) {
StringTag idTag = tag.get("id");
if (idTag == null)
return;
if (idTag.getValue().equals("minecraft:skull")) {
// Workaround an old client bug: MC-68487
Tag skullOwnerTag = tag.get("SkullOwner");
if (!(skullOwnerTag instanceof CompoundTag))
return;
CompoundTag skullOwnerCompoundTag = (CompoundTag) skullOwnerTag;
if (!skullOwnerCompoundTag.contains("Id"))
return;
CompoundTag properties = skullOwnerCompoundTag.get("Properties");
if (properties == null)
return;
ListTag textures = properties.get("textures");
if (textures == null)
return;
CompoundTag first = textures.size() > 0 ? textures.get(0) : null;
if (first == null)
return;
// Make the client cache the skinprofile over this uuid
int hashCode = first.get("Value").getValue().hashCode();
// TODO split texture in 4 for a lower collision chance
int[] uuidIntArray = { hashCode, 0, 0, 0 };
skullOwnerCompoundTag.put("Id", new IntArrayTag(uuidIntArray));
}
}
use of com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag in project ViaBackwards by ViaVersion.
the class BlockItemPackets1_14 method handleItemToClient.
@Override
public Item handleItemToClient(Item item) {
if (item == null)
return null;
super.handleItemToClient(item);
// Lore now uses JSON
CompoundTag tag = item.tag();
CompoundTag display;
if (tag != null && (display = tag.get("display")) != null) {
ListTag lore = display.get("Lore");
if (lore != null) {
saveListTag(display, lore, "Lore");
for (Tag loreEntry : lore) {
if (!(loreEntry instanceof StringTag))
continue;
StringTag loreEntryTag = (StringTag) loreEntry;
String value = loreEntryTag.getValue();
if (value != null && !value.isEmpty()) {
loreEntryTag.setValue(ChatRewriter.jsonToLegacyText(value));
}
}
}
}
enchantmentRewriter.handleToClient(item);
return item;
}
Aggregations