use of com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag in project ViaBackwards by ViaVersion.
the class EntityPackets1_17 method registerPackets.
@Override
protected void registerPackets() {
registerTrackerWithData(ClientboundPackets1_17.SPAWN_ENTITY, Entity1_17Types.FALLING_BLOCK);
registerSpawnTracker(ClientboundPackets1_17.SPAWN_MOB);
registerTracker(ClientboundPackets1_17.SPAWN_EXPERIENCE_ORB, Entity1_17Types.EXPERIENCE_ORB);
registerTracker(ClientboundPackets1_17.SPAWN_PAINTING, Entity1_17Types.PAINTING);
registerTracker(ClientboundPackets1_17.SPAWN_PLAYER, Entity1_17Types.PLAYER);
registerMetadataRewriter(ClientboundPackets1_17.ENTITY_METADATA, Types1_17.METADATA_LIST, Types1_16.METADATA_LIST);
protocol.registerClientbound(ClientboundPackets1_17.REMOVE_ENTITY, ClientboundPackets1_16_2.DESTROY_ENTITIES, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int entityId = wrapper.read(Type.VAR_INT);
tracker(wrapper.user()).removeEntity(entityId);
// Write into single value array
int[] array = { entityId };
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, array);
});
}
});
protocol.registerClientbound(ClientboundPackets1_17.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);
handler(wrapper -> {
byte previousGamemode = wrapper.get(Type.BYTE, 0);
if (previousGamemode == -1) {
// "Unset" gamemode removed
wrapper.set(Type.BYTE, 0, (byte) 0);
}
});
handler(getTrackerHandler(Entity1_17Types.PLAYER, Type.INT));
handler(worldDataTrackerHandler(1));
handler(wrapper -> {
CompoundTag registry = wrapper.get(Type.NBT, 0);
CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
ListTag biomes = biomeRegistry.get("value");
for (Tag biome : biomes) {
CompoundTag biomeCompound = ((CompoundTag) biome).get("element");
StringTag category = biomeCompound.get("category");
if (category.getValue().equalsIgnoreCase("underground")) {
category.setValue("none");
}
}
CompoundTag dimensionRegistry = registry.get("minecraft:dimension_type");
ListTag dimensions = dimensionRegistry.get("value");
for (Tag dimension : dimensions) {
CompoundTag dimensionCompound = ((CompoundTag) dimension).get("element");
reduceExtendedHeight(dimensionCompound, false);
}
reduceExtendedHeight(wrapper.get(Type.NBT, 1), true);
});
}
});
protocol.registerClientbound(ClientboundPackets1_17.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
// Dimension data
map(Type.NBT);
// World
map(Type.STRING);
handler(worldDataTrackerHandler(0));
handler(wrapper -> reduceExtendedHeight(wrapper.get(Type.NBT, 0), true));
}
});
protocol.registerClientbound(ClientboundPackets1_17.PLAYER_POSITION, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.DOUBLE);
map(Type.DOUBLE);
map(Type.DOUBLE);
map(Type.FLOAT);
map(Type.FLOAT);
map(Type.BYTE);
map(Type.VAR_INT);
handler(wrapper -> {
// Dismount vehicle ¯\_(ツ)_/¯
wrapper.read(Type.BOOLEAN);
});
}
});
protocol.registerClientbound(ClientboundPackets1_17.ENTITY_PROPERTIES, new PacketRemapper() {
@Override
public void registerMap() {
// Entity id
map(Type.VAR_INT);
handler(wrapper -> {
// Collection length
wrapper.write(Type.INT, wrapper.read(Type.VAR_INT));
});
}
});
// TODO translatables
protocol.mergePacket(ClientboundPackets1_17.COMBAT_ENTER, ClientboundPackets1_16_2.COMBAT_EVENT, 0);
protocol.mergePacket(ClientboundPackets1_17.COMBAT_END, ClientboundPackets1_16_2.COMBAT_EVENT, 1);
protocol.mergePacket(ClientboundPackets1_17.COMBAT_KILL, ClientboundPackets1_16_2.COMBAT_EVENT, 2);
}
use of com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag in project ViaBackwards by ViaVersion.
the class BlockItemPackets1_18 method registerPackets.
@Override
protected void registerPackets() {
new RecipeRewriter1_16(protocol).registerDefaultHandler(ClientboundPackets1_18.DECLARE_RECIPES);
registerSetCooldown(ClientboundPackets1_18.COOLDOWN);
registerWindowItems1_17_1(ClientboundPackets1_18.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, Type.FLAT_VAR_INT_ITEM);
registerSetSlot1_17_1(ClientboundPackets1_18.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
registerEntityEquipmentArray(ClientboundPackets1_18.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
registerTradeList(ClientboundPackets1_18.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
registerAdvancements(ClientboundPackets1_18.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
registerClickWindow1_17_1(ServerboundPackets1_17.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
protocol.registerClientbound(ClientboundPackets1_18.EFFECT, new PacketRemapper() {
@Override
public void registerMap() {
// Effect id
map(Type.INT);
// Location
map(Type.POSITION1_14);
// Data
map(Type.INT);
handler(wrapper -> {
int id = wrapper.get(Type.INT, 0);
int data = wrapper.get(Type.INT, 1);
if (id == 1010) {
// Play record
wrapper.set(Type.INT, 1, protocol.getMappingData().getNewItemId(data));
}
});
}
});
registerCreativeInvAction(ServerboundPackets1_17.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
protocol.registerClientbound(ClientboundPackets1_18.SPAWN_PARTICLE, new PacketRemapper() {
@Override
public void registerMap() {
// Particle id
map(Type.INT);
// Override limiter
map(Type.BOOLEAN);
// X
map(Type.DOUBLE);
// Y
map(Type.DOUBLE);
// Z
map(Type.DOUBLE);
// Offset X
map(Type.FLOAT);
// Offset Y
map(Type.FLOAT);
// Offset Z
map(Type.FLOAT);
// Max speed
map(Type.FLOAT);
// Particle Count
map(Type.INT);
handler(wrapper -> {
int id = wrapper.get(Type.INT, 0);
if (id == 3) {
// Block marker
int blockState = wrapper.read(Type.VAR_INT);
if (blockState == 7786) {
// Light block
wrapper.set(Type.INT, 0, 3);
} else {
// Else assume barrier block
wrapper.set(Type.INT, 0, 2);
}
return;
}
ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
if (mappings.isBlockParticle(id)) {
int data = wrapper.passthrough(Type.VAR_INT);
wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
} else if (mappings.isItemParticle(id)) {
handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
}
int newId = protocol.getMappingData().getNewParticleId(id);
if (newId != id) {
wrapper.set(Type.INT, 0, newId);
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_18.BLOCK_ENTITY_DATA, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION1_14);
handler(wrapper -> {
final int id = wrapper.read(Type.VAR_INT);
final CompoundTag tag = wrapper.read(Type.NBT);
final int mappedId = BlockEntityIds.mappedId(id);
if (mappedId == -1) {
wrapper.cancel();
return;
}
final String identifier = protocol.getMappingData().blockEntities().get(id);
if (identifier == null) {
wrapper.cancel();
return;
}
// The 1.18 server doesn't include the id and positions (x, y, z) in the NBT anymore
// If those were the only fields on the block entity (e.g.: skull, bed), we'll receive a null NBT
// We initialize one and add the missing fields, so it can be handled correctly down the line
final CompoundTag newTag = tag == null ? new CompoundTag() : tag;
final Position pos = wrapper.get(Type.POSITION1_14, 0);
// The protocol converters downstream rely on this field, let's add it back
newTag.put("id", new StringTag("minecraft:" + identifier));
// Weird glitches happen with the 1.17 client and below if these fields are missing
// Some examples are block entity models becoming invisible (e.g.: signs, banners)
newTag.put("x", new IntTag(pos.x()));
newTag.put("y", new IntTag(pos.y()));
newTag.put("z", new IntTag(pos.z()));
handleSpawner(id, newTag);
wrapper.write(Type.UNSIGNED_BYTE, (short) mappedId);
wrapper.write(Type.NBT, newTag);
});
}
});
protocol.registerClientbound(ClientboundPackets1_18.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
final EntityTracker tracker = protocol.getEntityRewriter().tracker(wrapper.user());
final Chunk1_18Type chunkType = new Chunk1_18Type(tracker.currentWorldSectionHeight(), MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().size()), MathUtil.ceilLog2(tracker.biomesSent()));
final Chunk oldChunk = wrapper.read(chunkType);
final ChunkSection[] sections = oldChunk.getSections();
final BitSet mask = new BitSet(oldChunk.getSections().length);
final int[] biomeData = new int[sections.length * ChunkSection.BIOME_SIZE];
int biomeIndex = 0;
for (int j = 0; j < sections.length; j++) {
final ChunkSection section = sections[j];
// Write biome palette into biome array
final DataPalette biomePalette = section.palette(PaletteType.BIOMES);
for (int i = 0; i < ChunkSection.BIOME_SIZE; i++) {
biomeData[biomeIndex++] = biomePalette.idAt(i);
}
// Rewrite to empty section
if (section.getNonAirBlocksCount() == 0) {
sections[j] = null;
} else {
mask.set(j);
}
}
final List<CompoundTag> blockEntityTags = new ArrayList<>(oldChunk.blockEntities().size());
for (final BlockEntity blockEntity : oldChunk.blockEntities()) {
final String id = protocol.getMappingData().blockEntities().get(blockEntity.typeId());
if (id == null) {
// Shrug
continue;
}
final CompoundTag tag;
if (blockEntity.tag() != null) {
tag = blockEntity.tag();
handleSpawner(blockEntity.typeId(), tag);
} else {
tag = new CompoundTag();
}
blockEntityTags.add(tag);
tag.put("x", new IntTag((oldChunk.getX() << 4) + blockEntity.sectionX()));
tag.put("y", new IntTag(blockEntity.y()));
tag.put("z", new IntTag((oldChunk.getZ() << 4) + blockEntity.sectionZ()));
tag.put("id", new StringTag("minecraft:" + id));
}
final Chunk chunk = new BaseChunk(oldChunk.getX(), oldChunk.getZ(), true, false, mask, oldChunk.getSections(), biomeData, oldChunk.getHeightMap(), blockEntityTags);
wrapper.write(new Chunk1_17Type(tracker.currentWorldSectionHeight()), chunk);
// Create and send light packet first
final PacketWrapper lightPacket = wrapper.create(ClientboundPackets1_17_1.UPDATE_LIGHT);
lightPacket.write(Type.VAR_INT, chunk.getX());
lightPacket.write(Type.VAR_INT, chunk.getZ());
// Trust edges
lightPacket.write(Type.BOOLEAN, wrapper.read(Type.BOOLEAN));
// Sky light mask
lightPacket.write(Type.LONG_ARRAY_PRIMITIVE, wrapper.read(Type.LONG_ARRAY_PRIMITIVE));
// Block light mask
lightPacket.write(Type.LONG_ARRAY_PRIMITIVE, wrapper.read(Type.LONG_ARRAY_PRIMITIVE));
// Empty sky light mask
lightPacket.write(Type.LONG_ARRAY_PRIMITIVE, wrapper.read(Type.LONG_ARRAY_PRIMITIVE));
// Empty block light mask
lightPacket.write(Type.LONG_ARRAY_PRIMITIVE, wrapper.read(Type.LONG_ARRAY_PRIMITIVE));
final int skyLightLength = wrapper.read(Type.VAR_INT);
lightPacket.write(Type.VAR_INT, skyLightLength);
for (int i = 0; i < skyLightLength; i++) {
lightPacket.write(Type.BYTE_ARRAY_PRIMITIVE, wrapper.read(Type.BYTE_ARRAY_PRIMITIVE));
}
final int blockLightLength = wrapper.read(Type.VAR_INT);
lightPacket.write(Type.VAR_INT, blockLightLength);
for (int i = 0; i < blockLightLength; i++) {
lightPacket.write(Type.BYTE_ARRAY_PRIMITIVE, wrapper.read(Type.BYTE_ARRAY_PRIMITIVE));
}
lightPacket.send(Protocol1_17_1To1_18.class);
});
}
});
protocol.cancelClientbound(ClientboundPackets1_18.SET_SIMULATION_DISTANCE);
}
use of com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag in project ViaBackwards by ViaVersion.
the class BlockItemPackets1_18 method handleSpawner.
private void handleSpawner(final int typeId, final CompoundTag tag) {
if (typeId == 8) {
final CompoundTag spawnData = tag.get("SpawnData");
final CompoundTag entity;
if (spawnData != null && (entity = spawnData.get("entity")) != null) {
tag.put("SpawnData", entity);
}
}
}
use of com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag 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.CompoundTag 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)));
}
});
}
Aggregations