This commit is contained in:
Nassim Jahnke 2022-04-06 19:07:16 +02:00
parent 596a42e312
commit 4693b95bea
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
12 changed files with 1051 additions and 927 deletions

View File

@ -151,4 +151,6 @@ public interface EntityTracker {
int biomesSent();
void setBiomesSent(int biomesSent);
EntityType playerType();
}

View File

@ -80,7 +80,7 @@ public class ProtocolVersion {
public static final ProtocolVersion v1_17_1 = register(756, "1.17.1");
public static final ProtocolVersion v1_18 = register(757, "1.18/1.18.1", new VersionRange("1.18", 0, 1));
public static final ProtocolVersion v1_18_2 = register(758, "1.18.2");
public static final ProtocolVersion v1_19 = register(759, 76, "1.19");
public static final ProtocolVersion v1_19 = register(759, 78, "1.19");
public static final ProtocolVersion unknown = register(-1, "UNKNOWN");
public static ProtocolVersion register(int version, String name) {

View File

@ -157,4 +157,9 @@ public class EntityTrackerBase implements EntityTracker, ClientEntityIdChangeLis
public void setBiomesSent(int biomesSent) {
this.biomesSent = biomesSent;
}
@Override
public EntityType playerType() {
return playerType;
}
}

View File

@ -23,107 +23,106 @@ public enum ClientboundPackets1_19 implements ClientboundPacketType {
SPAWN_ENTITY, // 0x00
SPAWN_EXPERIENCE_ORB, // 0x01
SPAWN_MOB, // 0x02
SPAWN_PAINTING, // 0x03
SPAWN_PLAYER, // 0x04
ENTITY_ANIMATION, // 0x05
STATISTICS, // 0x06
BLOCK_CHANGED_ACK, // 0x07
BLOCK_BREAK_ANIMATION, // 0x08
BLOCK_ENTITY_DATA, // 0x09
BLOCK_ACTION, // 0x0A
BLOCK_CHANGE, // 0x0B
BOSSBAR, // 0x0C
SERVER_DIFFICULTY, // 0x0D
CHAT_MESSAGE, // 0x0E
CLEAR_TITLES, // 0x0F
TAB_COMPLETE, // 0x10
DECLARE_COMMANDS, // 0x11
CLOSE_WINDOW, // 0x12
WINDOW_ITEMS, // 0x13
WINDOW_PROPERTY, // 0x14
SET_SLOT, // 0x15
COOLDOWN, // 0x16
PLUGIN_MESSAGE, // 0x17
NAMED_SOUND, // 0x18
DISCONNECT, // 0x19
ENTITY_STATUS, // 0x1A
EXPLOSION, // 0x1B
UNLOAD_CHUNK, // 0x1C
GAME_EVENT, // 0x1D
OPEN_HORSE_WINDOW, // 0x1E
WORLD_BORDER_INIT, // 0x1F
KEEP_ALIVE, // 0x20
CHUNK_DATA, // 0x21
EFFECT, // 0x22
SPAWN_PARTICLE, // 0x23
UPDATE_LIGHT, // 0x24
JOIN_GAME, // 0x25
MAP_DATA, // 0x26
TRADE_LIST, // 0x27
ENTITY_POSITION, // 0x28
ENTITY_POSITION_AND_ROTATION, // 0x29
ENTITY_ROTATION, // 0x2A
VEHICLE_MOVE, // 0x2B
OPEN_BOOK, // 0x2C
OPEN_WINDOW, // 0x2D
OPEN_SIGN_EDITOR, // 0x2E
PING, // 0x2F
CRAFT_RECIPE_RESPONSE, // 0x30
PLAYER_ABILITIES, // 0x31
COMBAT_END, // 0x32
COMBAT_ENTER, // 0x33
COMBAT_KILL, // 0x34
PLAYER_INFO, // 0x35
FACE_PLAYER, // 0x36
PLAYER_POSITION, // 0x37
UNLOCK_RECIPES, // 0x38
REMOVE_ENTITIES, // 0x39
REMOVE_ENTITY_EFFECT, // 0x3A
RESOURCE_PACK, // 0x3B
RESPAWN, // 0x3C
ENTITY_HEAD_LOOK, // 0x3D
MULTI_BLOCK_CHANGE, // 0x3E
SELECT_ADVANCEMENTS_TAB, // 0x3F
ACTIONBAR, // 0x40
WORLD_BORDER_CENTER, // 0x41
WORLD_BORDER_LERP_SIZE, // 0x42
WORLD_BORDER_SIZE, // 0x43
WORLD_BORDER_WARNING_DELAY, // 0x44
WORLD_BORDER_WARNING_DISTANCE, // 0x45
CAMERA, // 0x46
HELD_ITEM_CHANGE, // 0x47
UPDATE_VIEW_POSITION, // 0x48
UPDATE_VIEW_DISTANCE, // 0x49
SPAWN_POSITION, // 0x4A
DISPLAY_SCOREBOARD, // 0x4B
ENTITY_METADATA, // 0x4C
ATTACH_ENTITY, // 0x4D
ENTITY_VELOCITY, // 0x4E
ENTITY_EQUIPMENT, // 0x4F
SET_EXPERIENCE, // 0x50
UPDATE_HEALTH, // 0x51
SCOREBOARD_OBJECTIVE, // 0x52
SET_PASSENGERS, // 0x53
TEAMS, // 0x54
UPDATE_SCORE, // 0x55
SET_SIMULATION_DISTANCE, // 0x56
TITLE_SUBTITLE, // 0x57
TIME_UPDATE, // 0x58
TITLE_TEXT, // 0x59
TITLE_TIMES, // 0x5A
ENTITY_SOUND, // 0x5B
SOUND, // 0x5C
STOP_SOUND, // 0x5D
TAB_LIST, // 0x5E
NBT_QUERY, // 0x5F
COLLECT_ITEM, // 0x60
ENTITY_TELEPORT, // 0x61
ADVANCEMENTS, // 0x62
ENTITY_PROPERTIES, // 0x63
ENTITY_EFFECT, // 0x64
DECLARE_RECIPES, // 0x65
TAGS; // 0x66
SPAWN_PAINTING, // 0x02
SPAWN_PLAYER, // 0x03
ENTITY_ANIMATION, // 0x04
STATISTICS, // 0x05
BLOCK_CHANGED_ACK, // 0x06
BLOCK_BREAK_ANIMATION, // 0x07
BLOCK_ENTITY_DATA, // 0x08
BLOCK_ACTION, // 0x09
BLOCK_CHANGE, // 0x0A
BOSSBAR, // 0x0B
SERVER_DIFFICULTY, // 0x0C
CHAT_MESSAGE, // 0x0D
CLEAR_TITLES, // 0x0E
TAB_COMPLETE, // 0x0F
DECLARE_COMMANDS, // 0x10
CLOSE_WINDOW, // 0x11
WINDOW_ITEMS, // 0x12
WINDOW_PROPERTY, // 0x13
SET_SLOT, // 0x14
COOLDOWN, // 0x15
PLUGIN_MESSAGE, // 0x16
NAMED_SOUND, // 0x17
DISCONNECT, // 0x18
ENTITY_STATUS, // 0x19
EXPLOSION, // 0x1A
UNLOAD_CHUNK, // 0x1B
GAME_EVENT, // 0x1C
OPEN_HORSE_WINDOW, // 0x1D
WORLD_BORDER_INIT, // 0x1E
KEEP_ALIVE, // 0x1F
CHUNK_DATA, // 0x20
EFFECT, // 0x21
SPAWN_PARTICLE, // 0x22
UPDATE_LIGHT, // 0x23
JOIN_GAME, // 0x24
MAP_DATA, // 0x25
TRADE_LIST, // 0x26
ENTITY_POSITION, // 0x27
ENTITY_POSITION_AND_ROTATION, // 0x28
ENTITY_ROTATION, // 0x29
VEHICLE_MOVE, // 0x2A
OPEN_BOOK, // 0x2B
OPEN_WINDOW, // 0x2C
OPEN_SIGN_EDITOR, // 0x2D
PING, // 0x2E
CRAFT_RECIPE_RESPONSE, // 0x2F
PLAYER_ABILITIES, // 0x30
COMBAT_END, // 0x31
COMBAT_ENTER, // 0x32
COMBAT_KILL, // 0x33
PLAYER_INFO, // 0x34
FACE_PLAYER, // 0x35
PLAYER_POSITION, // 0x36
UNLOCK_RECIPES, // 0x37
REMOVE_ENTITIES, // 0x38
REMOVE_ENTITY_EFFECT, // 0x39
RESOURCE_PACK, // 0x3A
RESPAWN, // 0x3B
ENTITY_HEAD_LOOK, // 0x3C
MULTI_BLOCK_CHANGE, // 0x3D
SELECT_ADVANCEMENTS_TAB, // 0x3E
ACTIONBAR, // 0x3F
WORLD_BORDER_CENTER, // 0x40
WORLD_BORDER_LERP_SIZE, // 0x41
WORLD_BORDER_SIZE, // 0x42
WORLD_BORDER_WARNING_DELAY, // 0x43
WORLD_BORDER_WARNING_DISTANCE, // 0x44
CAMERA, // 0x45
HELD_ITEM_CHANGE, // 0x46
UPDATE_VIEW_POSITION, // 0x47
UPDATE_VIEW_DISTANCE, // 0x48
SPAWN_POSITION, // 0x49
DISPLAY_SCOREBOARD, // 0x4A
ENTITY_METADATA, // 0x4B
ATTACH_ENTITY, // 0x4C
ENTITY_VELOCITY, // 0x4D
ENTITY_EQUIPMENT, // 0x4E
SET_EXPERIENCE, // 0x4F
UPDATE_HEALTH, // 0x50
SCOREBOARD_OBJECTIVE, // 0x51
SET_PASSENGERS, // 0x52
TEAMS, // 0x53
UPDATE_SCORE, // 0x54
SET_SIMULATION_DISTANCE, // 0x55
TITLE_SUBTITLE, // 0x56
TIME_UPDATE, // 0x57
TITLE_TEXT, // 0x58
TITLE_TIMES, // 0x59
ENTITY_SOUND, // 0x5A
SOUND, // 0x5B
STOP_SOUND, // 0x5C
TAB_LIST, // 0x5D
NBT_QUERY, // 0x5E
COLLECT_ITEM, // 0x5F
ENTITY_TELEPORT, // 0x60
ADVANCEMENTS, // 0x61
ENTITY_PROPERTIES, // 0x62
ENTITY_EFFECT, // 0x63
DECLARE_RECIPES, // 0x64
TAGS; // 0x65
@Override
public int getId() {

View File

@ -62,8 +62,45 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol<ClientboundPack
cancelClientbound(ClientboundPackets1_18.ADD_VIBRATION_SIGNAL);
final SoundRewriter soundRewriter = new SoundRewriter(this);
soundRewriter.registerSound(ClientboundPackets1_18.SOUND);
soundRewriter.registerSound(ClientboundPackets1_18.ENTITY_SOUND);
registerClientbound(ClientboundPackets1_18.SOUND, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // Sound id
map(Type.VAR_INT); // Source
map(Type.INT); // X
map(Type.INT); // Y
map(Type.INT); // Z
map(Type.FLOAT); // Volume
map(Type.FLOAT); // Pitch
create(Type.LONG, 0L); // Seed
handler(soundRewriter.getSoundHandler());
}
});
registerClientbound(ClientboundPackets1_18.ENTITY_SOUND, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // Sound id
map(Type.VAR_INT); // Source
map(Type.VAR_INT); // Entity id
map(Type.FLOAT); // Volume
map(Type.FLOAT); // Pitch
create(Type.LONG, 0L); // Seed
handler(soundRewriter.getSoundHandler());
}
});
registerClientbound(ClientboundPackets1_18.NAMED_SOUND, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.STRING); // Sound name
map(Type.VAR_INT); // Source
map(Type.INT); // X
map(Type.INT); // Y
map(Type.INT); // Z
map(Type.FLOAT); // Volume
map(Type.FLOAT); // Pitch
create(Type.LONG, 0L); // Seed
}
});
final CommandRewriter commandRewriter = new CommandRewriter(this);
registerClientbound(ClientboundPackets1_18.DECLARE_COMMANDS, new PacketRemapper() {

View File

@ -25,6 +25,7 @@ import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_18;
import com.viaversion.viaversion.api.type.types.version.Types1_19;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18;
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ClientboundPackets1_19;
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.Protocol1_19To1_18_2;
import com.viaversion.viaversion.rewriter.EntityRewriter;
@ -37,12 +38,54 @@ public final class EntityPackets extends EntityRewriter<Protocol1_19To1_18_2> {
@Override
public void registerPackets() {
registerTrackerWithData(ClientboundPackets1_18.SPAWN_ENTITY, Entity1_19Types.FALLING_BLOCK);
registerTracker(ClientboundPackets1_18.SPAWN_MOB);
registerTracker(ClientboundPackets1_18.SPAWN_PLAYER, Entity1_19Types.PLAYER);
registerMetadataRewriter(ClientboundPackets1_18.ENTITY_METADATA, Types1_18.METADATA_LIST, Types1_19.METADATA_LIST);
registerRemoveEntities(ClientboundPackets1_18.REMOVE_ENTITIES);
protocol.registerClientbound(ClientboundPackets1_18.SPAWN_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // Entity id
map(Type.UUID); // Entity UUID
map(Type.VAR_INT); // Entity type
map(Type.DOUBLE); // X
map(Type.DOUBLE); // Y
map(Type.DOUBLE); // Z
map(Type.BYTE); // Pitch
map(Type.BYTE); // Yaw
create(Type.BYTE, (byte) 0); // Head yaw (moved over from mob spawn packet)
map(Type.INT, Type.VAR_INT); // Data
handler(trackerHandler());
handler(wrapper -> {
final int entityId = wrapper.get(Type.VAR_INT, 0);
final EntityType entityType = tracker(wrapper.user()).entityType(entityId);
if (entityType == Entity1_19Types.FALLING_BLOCK) {
wrapper.set(Type.VAR_INT, 2, protocol.getMappingData().getNewBlockStateId(wrapper.get(Type.VAR_INT, 2)));
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_18.SPAWN_MOB, ClientboundPackets1_19.SPAWN_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // Entity ID
map(Type.UUID); // Entity UUID
map(Type.VAR_INT); // Entity Type
map(Type.DOUBLE); // X
map(Type.DOUBLE); // Y
map(Type.DOUBLE); // Z
map(Type.BYTE); // Yaw
map(Type.BYTE); // Pitch
map(Type.BYTE); // Head yaw
create(Type.VAR_INT, 0); // Data
map(Type.SHORT); // Velocity x
map(Type.SHORT); // Velocity y
map(Type.SHORT); // Velocity z
handler(trackerHandler());
}
});
protocol.registerClientbound(ClientboundPackets1_18.ENTITY_EFFECT, new PacketRemapper() {
@Override
public void registerMap() {
@ -70,6 +113,7 @@ public final class EntityPackets extends EntityRewriter<Protocol1_19To1_18_2> {
map(Type.VAR_INT); // Max players
map(Type.VAR_INT); // Chunk radius
map(Type.VAR_INT); // Simulation distance
handler(playerTrackerHandler());
handler(worldDataTrackerHandler(1));
handler(biomeSizeTracker());
}
@ -90,11 +134,13 @@ public final class EntityPackets extends EntityRewriter<Protocol1_19To1_18_2> {
registerMetaTypeHandler(Types1_19.META_TYPES.itemType, Types1_19.META_TYPES.blockStateType, Types1_19.META_TYPES.particleType);
filter().filterFamily(Entity1_17Types.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
filter().filterFamily(Entity1_19Types.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
// Convert to new block id
final int data = (int) meta.getValue();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
});
filter().type(Entity1_19Types.PLAYER).addIndex(19); // Last death location
}
@Override

View File

@ -271,6 +271,32 @@ public abstract class EntityRewriter<T extends Protocol> extends RewriterBase<T>
});
}
public void registerTrackerWithData1_19(ClientboundPacketType packetType, EntityType fallingBlockType) {
protocol.registerClientbound(packetType, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // Entity id
map(Type.UUID); // Entity UUID
map(Type.VAR_INT); // Entity type
map(Type.DOUBLE); // X
map(Type.DOUBLE); // Y
map(Type.DOUBLE); // Z
map(Type.BYTE); // Pitch
map(Type.BYTE); // Yaw
map(Type.BYTE); // Head yaw
map(Type.VAR_INT); // Data
handler(trackerHandler());
handler(wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
EntityType entityType = tracker(wrapper.user()).entityType(entityId);
if (entityType == fallingBlockType) {
wrapper.set(Type.VAR_INT, 2, protocol.getMappingData().getNewBlockStateId(wrapper.get(Type.VAR_INT, 2)));
}
});
}
});
}
/**
* Registers an entity tracker for the extra spawn packets like player, painting, or xp orb spawns.
*
@ -364,6 +390,13 @@ public abstract class EntityRewriter<T extends Protocol> extends RewriterBase<T>
return trackerAndRewriterHandler(null);
}
public PacketHandler playerTrackerHandler() {
return wrapper -> {
final EntityTracker tracker = tracker(wrapper.user());
tracker.addEntity(wrapper.get(Type.INT, 0), tracker.playerType());
};
}
/**
* Returns a packet handler storing height, min_y, and name of the current world.
* If the client changes to a new world, the stored entity data will be cleared.

View File

@ -1,5 +1,5 @@
# Project properties - we put these here so they can be modified without causing a recompile of the build scripts
projectVersion=4.3.0-22w13a-SNAPSHOT
projectVersion=4.3.0-22w14a-SNAPSHOT
# Gradle properties
org.gradle.daemon=true

Binary file not shown.

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

10
gradlew vendored
View File

@ -1,7 +1,7 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -32,10 +32,10 @@
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#