use of com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag 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.CompoundTag in project ViaBackwards by ViaVersion.
the class BlockItemPackets1_16_2 method registerPackets.
@Override
protected void registerPackets() {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
new RecipeRewriter1_16(protocol).registerDefaultHandler(ClientboundPackets1_16_2.DECLARE_RECIPES);
registerSetCooldown(ClientboundPackets1_16_2.COOLDOWN);
registerWindowItems(ClientboundPackets1_16_2.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
registerSetSlot(ClientboundPackets1_16_2.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
registerEntityEquipmentArray(ClientboundPackets1_16_2.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
registerTradeList(ClientboundPackets1_16_2.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
registerAdvancements(ClientboundPackets1_16_2.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
protocol.registerClientbound(ClientboundPackets1_16_2.UNLOCK_RECIPES, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.passthrough(Type.VAR_INT);
// Open
wrapper.passthrough(Type.BOOLEAN);
// Filter
wrapper.passthrough(Type.BOOLEAN);
// Furnace Open
wrapper.passthrough(Type.BOOLEAN);
// Filter furnace
wrapper.passthrough(Type.BOOLEAN);
// Blast furnace / smoker
wrapper.read(Type.BOOLEAN);
wrapper.read(Type.BOOLEAN);
wrapper.read(Type.BOOLEAN);
wrapper.read(Type.BOOLEAN);
});
}
});
blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16_2.ACKNOWLEDGE_PLAYER_DIGGING);
blockRewriter.registerBlockAction(ClientboundPackets1_16_2.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_16_2.BLOCK_CHANGE);
protocol.registerClientbound(ClientboundPackets1_16_2.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
Chunk chunk = wrapper.read(new Chunk1_16_2Type());
wrapper.write(new Chunk1_16Type(), chunk);
chunk.setIgnoreOldLightData(true);
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null)
continue;
for (int j = 0; j < section.getPaletteSize(); j++) {
int old = section.getPaletteEntry(j);
section.setPaletteEntry(j, protocol.getMappingData().getNewBlockStateId(old));
}
}
for (CompoundTag blockEntity : chunk.getBlockEntities()) {
if (blockEntity != null) {
handleBlockEntity(blockEntity);
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_16_2.BLOCK_ENTITY_DATA, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION1_14);
map(Type.UNSIGNED_BYTE);
handler(wrapper -> {
handleBlockEntity(wrapper.passthrough(Type.NBT));
});
}
});
protocol.registerClientbound(ClientboundPackets1_16_2.MULTI_BLOCK_CHANGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
long chunkPosition = wrapper.read(Type.LONG);
// Ignore old light data
wrapper.read(Type.BOOLEAN);
int chunkX = (int) (chunkPosition >> 42);
int chunkY = (int) (chunkPosition << 44 >> 44);
int chunkZ = (int) (chunkPosition << 22 >> 42);
wrapper.write(Type.INT, chunkX);
wrapper.write(Type.INT, chunkZ);
BlockChangeRecord[] blockChangeRecord = wrapper.read(Type.VAR_LONG_BLOCK_CHANGE_RECORD_ARRAY);
wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, blockChangeRecord);
for (int i = 0; i < blockChangeRecord.length; i++) {
BlockChangeRecord record = blockChangeRecord[i];
int blockId = protocol.getMappingData().getNewBlockStateId(record.getBlockId());
// Relative y -> absolute y
blockChangeRecord[i] = new BlockChangeRecord1_8(record.getSectionX(), record.getY(chunkY), record.getSectionZ(), blockId);
}
});
}
});
blockRewriter.registerEffect(ClientboundPackets1_16_2.EFFECT, 1010, 2001);
registerSpawnParticle(ClientboundPackets1_16_2.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
}
});
}
use of com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag 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.CompoundTag in project ViaBackwards by ViaVersion.
the class EntityPackets1_16_2 method registerPackets.
@Override
protected void registerPackets() {
registerTrackerWithData(ClientboundPackets1_16_2.SPAWN_ENTITY, Entity1_16_2Types.FALLING_BLOCK);
registerSpawnTracker(ClientboundPackets1_16_2.SPAWN_MOB);
registerTracker(ClientboundPackets1_16_2.SPAWN_EXPERIENCE_ORB, Entity1_16_2Types.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_16_2.SPAWN_PAINTING, Entity1_16_2Types.PAINTING);
registerTracker(ClientboundPackets1_16_2.SPAWN_PLAYER, Entity1_16_2Types.PLAYER);
registerRemoveEntities(ClientboundPackets1_16_2.DESTROY_ENTITIES);
registerMetadataRewriter(ClientboundPackets1_16_2.ENTITY_METADATA, Types1_16.METADATA_LIST);
protocol.registerClientbound(ClientboundPackets1_16_2.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// Entity ID
map(Type.INT);
handler(wrapper -> {
boolean hardcore = wrapper.read(Type.BOOLEAN);
short gamemode = wrapper.read(Type.UNSIGNED_BYTE);
if (hardcore) {
gamemode |= 0x08;
}
wrapper.write(Type.UNSIGNED_BYTE, gamemode);
});
// Previous Gamemode
map(Type.BYTE);
// World List
map(Type.STRING_ARRAY);
handler(wrapper -> {
// Just screw the registry and write the defaults for 1.16 and 1.16.1 clients
wrapper.read(Type.NBT);
wrapper.write(Type.NBT, EntityPackets.DIMENSIONS_TAG);
CompoundTag dimensionData = wrapper.read(Type.NBT);
wrapper.write(Type.STRING, getDimensionFromData(dimensionData));
});
// Dimension
map(Type.STRING);
// Seed
map(Type.LONG);
handler(wrapper -> {
int maxPlayers = wrapper.read(Type.VAR_INT);
wrapper.write(Type.UNSIGNED_BYTE, (short) Math.max(maxPlayers, 255));
});
// ...
handler(getTrackerHandler(Entity1_16_2Types.PLAYER, Type.INT));
}
});
protocol.registerClientbound(ClientboundPackets1_16_2.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
CompoundTag dimensionData = wrapper.read(Type.NBT);
wrapper.write(Type.STRING, getDimensionFromData(dimensionData));
});
}
});
}
use of com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag 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