2021-03-22 23:06:40 +01:00
|
|
|
/*
|
|
|
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
2024-01-01 12:39:45 +01:00
|
|
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
2021-03-22 23:06:40 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-04-26 20:52:34 +02:00
|
|
|
package com.viaversion.viaversion.protocols.protocol1_11to1_10;
|
2016-08-10 14:51:32 +02:00
|
|
|
|
2017-05-14 16:02:04 +02:00
|
|
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
|
|
|
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
2021-04-26 20:52:34 +02:00
|
|
|
import com.viaversion.viaversion.api.Via;
|
2021-04-26 21:35:29 +02:00
|
|
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
2021-04-26 20:52:34 +02:00
|
|
|
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
2023-10-19 01:28:12 +02:00
|
|
|
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11;
|
2021-04-27 18:21:51 +02:00
|
|
|
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
2021-04-27 13:41:39 +02:00
|
|
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
2023-02-12 10:54:47 +01:00
|
|
|
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
2021-04-26 21:16:10 +02:00
|
|
|
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
|
2021-04-26 20:52:34 +02:00
|
|
|
import com.viaversion.viaversion.api.type.Type;
|
|
|
|
import com.viaversion.viaversion.api.type.types.version.Types1_9;
|
|
|
|
import com.viaversion.viaversion.protocols.protocol1_11to1_10.data.PotionColorMapping;
|
|
|
|
import com.viaversion.viaversion.protocols.protocol1_11to1_10.metadata.MetadataRewriter1_11To1_10;
|
|
|
|
import com.viaversion.viaversion.protocols.protocol1_11to1_10.packets.InventoryPackets;
|
|
|
|
import com.viaversion.viaversion.protocols.protocol1_11to1_10.storage.EntityTracker1_11;
|
|
|
|
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
|
|
|
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
|
2023-10-19 13:03:00 +02:00
|
|
|
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3;
|
|
|
|
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
2021-04-27 13:41:39 +02:00
|
|
|
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
|
|
|
import com.viaversion.viaversion.util.Pair;
|
2016-08-10 14:51:32 +02:00
|
|
|
|
2021-04-27 18:21:51 +02:00
|
|
|
public class Protocol1_11To1_10 extends AbstractProtocol<ClientboundPackets1_9_3, ClientboundPackets1_9_3, ServerboundPackets1_9_3, ServerboundPackets1_9_3> {
|
2016-09-30 17:14:14 +02:00
|
|
|
private static final ValueTransformer<Float, Short> toOldByte = new ValueTransformer<Float, Short>(Type.UNSIGNED_BYTE) {
|
|
|
|
@Override
|
|
|
|
public Short transform(PacketWrapper wrapper, Float inputValue) throws Exception {
|
|
|
|
return (short) (inputValue * 16);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-04 18:29:22 +01:00
|
|
|
private final MetadataRewriter1_11To1_10 entityRewriter = new MetadataRewriter1_11To1_10(this);
|
|
|
|
private final InventoryPackets itemRewriter = new InventoryPackets(this);
|
2021-06-03 17:15:24 +02:00
|
|
|
|
2020-06-06 09:45:43 +02:00
|
|
|
public Protocol1_11To1_10() {
|
|
|
|
super(ClientboundPackets1_9_3.class, ClientboundPackets1_9_3.class, ServerboundPackets1_9_3.class, ServerboundPackets1_9_3.class);
|
|
|
|
}
|
|
|
|
|
2016-08-10 14:51:32 +02:00
|
|
|
@Override
|
|
|
|
protected void registerPackets() {
|
2024-01-09 20:43:43 +01:00
|
|
|
super.registerPackets();
|
2016-08-10 20:12:27 +02:00
|
|
|
|
2023-02-12 10:54:47 +01:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketHandlers() {
|
2016-09-30 20:08:39 +02:00
|
|
|
@Override
|
2023-02-12 10:54:47 +01:00
|
|
|
public void register() {
|
2016-09-30 20:08:39 +02:00
|
|
|
map(Type.VAR_INT); // 0 - Entity id
|
|
|
|
map(Type.UUID); // 1 - UUID
|
|
|
|
map(Type.BYTE); // 2 - Type
|
|
|
|
|
|
|
|
// Track Entity
|
2021-06-03 17:15:24 +02:00
|
|
|
handler(entityRewriter.objectTrackerHandler());
|
2016-09-30 20:08:39 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-02-12 10:54:47 +01:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.SPAWN_MOB, new PacketHandlers() {
|
2016-08-10 15:59:13 +02:00
|
|
|
@Override
|
2023-02-12 10:54:47 +01:00
|
|
|
public void register() {
|
2016-08-10 15:59:13 +02:00
|
|
|
map(Type.VAR_INT); // 0 - Entity ID
|
|
|
|
map(Type.UUID); // 1 - Entity UUID
|
|
|
|
map(Type.UNSIGNED_BYTE, Type.VAR_INT); // 2 - Entity Type
|
2016-08-10 19:54:56 +02:00
|
|
|
map(Type.DOUBLE); // 3 - X
|
|
|
|
map(Type.DOUBLE); // 4 - Y
|
|
|
|
map(Type.DOUBLE); // 5 - Z
|
|
|
|
map(Type.BYTE); // 6 - Yaw
|
|
|
|
map(Type.BYTE); // 7 - Pitch
|
|
|
|
map(Type.BYTE); // 8 - Head Pitch
|
|
|
|
map(Type.SHORT); // 9 - Velocity X
|
|
|
|
map(Type.SHORT); // 10 - Velocity Y
|
|
|
|
map(Type.SHORT); // 11 - Velocity Z
|
|
|
|
map(Types1_9.METADATA_LIST); // 12 - Metadata
|
2016-08-10 14:51:32 +02:00
|
|
|
|
2023-02-12 11:44:25 +01:00
|
|
|
handler(wrapper -> {
|
|
|
|
int entityId = wrapper.get(Type.VAR_INT, 0);
|
|
|
|
// Change Type :)
|
|
|
|
int type = wrapper.get(Type.VAR_INT, 1);
|
2016-09-30 20:08:39 +02:00
|
|
|
|
2023-10-19 01:28:12 +02:00
|
|
|
EntityTypes1_11.EntityType entType = MetadataRewriter1_11To1_10.rewriteEntityType(type, wrapper.get(Types1_9.METADATA_LIST, 0));
|
2023-02-12 11:44:25 +01:00
|
|
|
if (entType != null) {
|
|
|
|
wrapper.set(Type.VAR_INT, 1, entType.getId());
|
2016-09-30 20:08:39 +02:00
|
|
|
|
2023-02-12 11:44:25 +01:00
|
|
|
// Register Type ID
|
|
|
|
wrapper.user().getEntityTracker(Protocol1_11To1_10.class).addEntity(entityId, entType);
|
|
|
|
entityRewriter.handleMetadata(entityId, wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user());
|
2016-08-10 19:54:56 +02:00
|
|
|
}
|
|
|
|
});
|
2016-08-10 15:59:13 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-02-04 18:29:22 +01:00
|
|
|
new SoundRewriter<>(this, this::getNewSoundId).registerSound(ClientboundPackets1_9_3.SOUND);
|
2016-10-04 19:35:20 +02:00
|
|
|
|
2023-02-12 10:54:47 +01:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.COLLECT_ITEM, new PacketHandlers() {
|
2016-08-10 15:59:13 +02:00
|
|
|
@Override
|
2023-02-12 10:54:47 +01:00
|
|
|
public void register() {
|
2016-08-10 15:59:13 +02:00
|
|
|
map(Type.VAR_INT); // 0 - Collected entity id
|
|
|
|
map(Type.VAR_INT); // 1 - Collector entity id
|
|
|
|
|
2023-02-12 11:44:25 +01:00
|
|
|
handler(wrapper -> {
|
|
|
|
wrapper.write(Type.VAR_INT, 1); // 2 - Pickup Count
|
2016-08-10 15:59:13 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2016-08-10 19:54:56 +02:00
|
|
|
|
2021-06-03 17:15:24 +02:00
|
|
|
entityRewriter.registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_9.METADATA_LIST);
|
2016-09-30 20:08:39 +02:00
|
|
|
|
2023-02-12 10:54:47 +01:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.ENTITY_TELEPORT, new PacketHandlers() {
|
2016-09-30 20:08:39 +02:00
|
|
|
@Override
|
2023-02-12 10:54:47 +01:00
|
|
|
public void register() {
|
2016-09-30 20:08:39 +02:00
|
|
|
map(Type.VAR_INT); // 0 - Entity id
|
|
|
|
map(Type.DOUBLE); // 1 - x
|
|
|
|
map(Type.DOUBLE); // 2 - y
|
|
|
|
map(Type.DOUBLE); // 3 - z
|
|
|
|
map(Type.BYTE); // 4 - yaw
|
|
|
|
map(Type.BYTE); // 5 - pitch
|
|
|
|
map(Type.BOOLEAN); // 6 - onGround
|
|
|
|
|
2023-02-12 11:44:25 +01:00
|
|
|
handler(wrapper -> {
|
|
|
|
int entityID = wrapper.get(Type.VAR_INT, 0);
|
|
|
|
if (Via.getConfig().isHologramPatch()) {
|
|
|
|
EntityTracker1_11 tracker = wrapper.user().getEntityTracker(Protocol1_11To1_10.class);
|
|
|
|
if (tracker.isHologram(entityID)) {
|
|
|
|
Double newValue = wrapper.get(Type.DOUBLE, 1);
|
|
|
|
newValue -= (Via.getConfig().getHologramYOffset());
|
|
|
|
wrapper.set(Type.DOUBLE, 1, newValue);
|
2016-08-10 21:23:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-08-10 19:54:56 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-06-03 17:15:24 +02:00
|
|
|
entityRewriter.registerRemoveEntities(ClientboundPackets1_9_3.DESTROY_ENTITIES);
|
2016-09-30 17:14:14 +02:00
|
|
|
|
2023-02-12 10:54:47 +01:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.TITLE, new PacketHandlers() {
|
2016-11-06 10:37:26 +01:00
|
|
|
@Override
|
2023-02-12 10:54:47 +01:00
|
|
|
public void register() {
|
2016-11-06 10:37:26 +01:00
|
|
|
map(Type.VAR_INT); // 0 - Action
|
|
|
|
|
2023-02-12 11:44:25 +01:00
|
|
|
handler(wrapper -> {
|
|
|
|
int action = wrapper.get(Type.VAR_INT, 0);
|
2016-11-06 10:37:26 +01:00
|
|
|
|
2023-02-12 11:44:25 +01:00
|
|
|
// Handle the new ActionBar
|
|
|
|
if (action >= 2) {
|
|
|
|
wrapper.set(Type.VAR_INT, 0, action + 1);
|
2016-11-06 10:37:26 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-02-12 10:54:47 +01:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.BLOCK_ACTION, new PacketHandlers() {
|
2016-12-15 16:32:54 +01:00
|
|
|
@Override
|
2023-02-12 10:54:47 +01:00
|
|
|
public void register() {
|
2023-10-19 13:15:26 +02:00
|
|
|
map(Type.POSITION1_8); // 0 - Position
|
2016-12-15 16:32:54 +01:00
|
|
|
map(Type.UNSIGNED_BYTE); // 1 - Action ID
|
|
|
|
map(Type.UNSIGNED_BYTE); // 2 - Action Param
|
|
|
|
map(Type.VAR_INT); // 3 - Block Type
|
|
|
|
|
|
|
|
// Cheap hack to ensure it's always right block
|
2023-02-12 11:44:25 +01:00
|
|
|
handler(actionWrapper -> {
|
|
|
|
if (Via.getConfig().isPistonAnimationPatch()) {
|
|
|
|
int id = actionWrapper.get(Type.VAR_INT, 0);
|
|
|
|
if (id == 33 || id == 29) {
|
|
|
|
actionWrapper.cancel();
|
2016-12-15 16:32:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-02-12 10:54:47 +01:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.BLOCK_ENTITY_DATA, new PacketHandlers() {
|
2017-05-14 16:02:04 +02:00
|
|
|
@Override
|
2023-02-12 10:54:47 +01:00
|
|
|
public void register() {
|
2023-10-19 13:15:26 +02:00
|
|
|
map(Type.POSITION1_8); // 0 - Position
|
2017-05-14 16:02:04 +02:00
|
|
|
map(Type.UNSIGNED_BYTE); // 1 - Action
|
2023-10-06 13:37:52 +02:00
|
|
|
map(Type.NAMED_COMPOUND_TAG); // 2 - NBT data
|
2017-05-14 16:02:04 +02:00
|
|
|
|
2023-02-12 11:44:25 +01:00
|
|
|
handler(wrapper -> {
|
2023-10-06 13:37:52 +02:00
|
|
|
CompoundTag tag = wrapper.get(Type.NAMED_COMPOUND_TAG, 0);
|
2023-02-12 11:44:25 +01:00
|
|
|
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 1)
|
|
|
|
EntityIdRewriter.toClientSpawner(tag);
|
2018-04-07 18:00:18 +02:00
|
|
|
|
2023-02-12 11:44:25 +01:00
|
|
|
if (tag.contains("id"))
|
|
|
|
// Handle new identifier
|
|
|
|
((StringTag) tag.get("id")).setValue(BlockEntityRewriter.toNewIdentifier((String) tag.get("id").getValue()));
|
2018-04-07 18:00:18 +02:00
|
|
|
|
2017-05-14 16:02:04 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-02-12 11:44:25 +01:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, wrapper -> {
|
|
|
|
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
|
|
|
|
2023-10-20 04:30:03 +02:00
|
|
|
Chunk chunk = wrapper.passthrough(ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()));
|
2023-02-12 11:44:25 +01:00
|
|
|
|
|
|
|
if (chunk.getBlockEntities() == null) return;
|
|
|
|
for (CompoundTag tag : chunk.getBlockEntities()) {
|
|
|
|
if (tag.contains("id")) {
|
|
|
|
String identifier = ((StringTag) tag.get("id")).getValue();
|
|
|
|
if (identifier.equals("MobSpawner")) {
|
|
|
|
EntityIdRewriter.toClientSpawner(tag);
|
2017-05-14 16:02:04 +02:00
|
|
|
}
|
2023-02-12 11:44:25 +01:00
|
|
|
|
|
|
|
// Handle new identifier
|
|
|
|
((StringTag) tag.get("id")).setValue(BlockEntityRewriter.toNewIdentifier(identifier));
|
|
|
|
}
|
2017-05-14 16:02:04 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-02-12 10:54:47 +01:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.JOIN_GAME, new PacketHandlers() {
|
2020-08-10 21:22:01 +02:00
|
|
|
@Override
|
2023-02-12 10:54:47 +01:00
|
|
|
public void register() {
|
2020-08-10 21:22:01 +02:00
|
|
|
map(Type.INT); // 0 - Entity ID
|
|
|
|
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
|
|
|
|
map(Type.INT); // 2 - Dimension
|
|
|
|
handler(wrapper -> {
|
|
|
|
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
|
|
|
|
int dimensionId = wrapper.get(Type.INT, 1);
|
|
|
|
clientChunks.setEnvironment(dimensionId);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2023-02-12 10:54:47 +01:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.RESPAWN, new PacketHandlers() {
|
2020-08-10 21:22:01 +02:00
|
|
|
@Override
|
2023-02-12 10:54:47 +01:00
|
|
|
public void register() {
|
2020-08-10 21:22:01 +02:00
|
|
|
map(Type.INT);
|
|
|
|
handler(wrapper -> {
|
|
|
|
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
|
|
|
int dimensionId = wrapper.get(Type.INT, 0);
|
|
|
|
clientWorld.setEnvironment(dimensionId);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2017-05-14 16:02:04 +02:00
|
|
|
|
2023-02-12 10:54:47 +01:00
|
|
|
this.registerClientbound(ClientboundPackets1_9_3.EFFECT, new PacketHandlers() {
|
2020-08-10 22:17:31 +02:00
|
|
|
@Override
|
2023-02-12 10:54:47 +01:00
|
|
|
public void register() {
|
2020-08-10 22:17:31 +02:00
|
|
|
this.map(Type.INT); //effectID
|
2023-10-19 13:15:26 +02:00
|
|
|
this.map(Type.POSITION1_8); //pos
|
2020-08-10 22:17:31 +02:00
|
|
|
this.map(Type.INT); //effectData
|
|
|
|
this.map(Type.BOOLEAN); //serverwide / global
|
|
|
|
handler(packetWrapper -> {
|
2020-08-10 22:28:40 +02:00
|
|
|
int effectID = packetWrapper.get(Type.INT, 0);
|
2020-08-10 22:17:31 +02:00
|
|
|
if (effectID == 2002) {
|
|
|
|
int data = packetWrapper.get(Type.INT, 1);
|
2020-08-10 22:28:40 +02:00
|
|
|
boolean isInstant = false;
|
|
|
|
Pair<Integer, Boolean> newData = PotionColorMapping.getNewData(data);
|
|
|
|
if (newData == null) {
|
2020-08-10 22:17:31 +02:00
|
|
|
Via.getPlatform().getLogger().warning("Received unknown 1.11 -> 1.10.2 potion data (" + data + ")");
|
|
|
|
data = 0;
|
|
|
|
} else {
|
2021-09-14 11:13:39 +02:00
|
|
|
data = newData.key();
|
|
|
|
isInstant = newData.value();
|
2020-08-10 22:17:31 +02:00
|
|
|
}
|
2020-08-10 22:28:40 +02:00
|
|
|
if (isInstant) {
|
2020-08-10 22:17:31 +02:00
|
|
|
packetWrapper.set(Type.INT, 0, 2007);
|
|
|
|
}
|
|
|
|
packetWrapper.set(Type.INT, 1, data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-09-30 17:14:14 +02:00
|
|
|
/*
|
|
|
|
INCOMING PACKETS
|
2020-06-06 09:45:43 +02:00
|
|
|
*/
|
2016-09-30 17:14:14 +02:00
|
|
|
|
2023-02-12 10:54:47 +01:00
|
|
|
registerServerbound(ServerboundPackets1_9_3.PLAYER_BLOCK_PLACEMENT, new PacketHandlers() {
|
2016-09-30 17:14:14 +02:00
|
|
|
@Override
|
2023-02-12 10:54:47 +01:00
|
|
|
public void register() {
|
2023-10-19 13:15:26 +02:00
|
|
|
map(Type.POSITION1_8); // 0 - Location
|
2016-09-30 17:14:14 +02:00
|
|
|
map(Type.VAR_INT); // 1 - Face
|
|
|
|
map(Type.VAR_INT); // 2 - Hand
|
|
|
|
|
|
|
|
map(Type.FLOAT, toOldByte);
|
|
|
|
map(Type.FLOAT, toOldByte);
|
|
|
|
map(Type.FLOAT, toOldByte);
|
|
|
|
}
|
|
|
|
});
|
2016-11-14 19:14:49 +01:00
|
|
|
|
2023-02-12 10:54:47 +01:00
|
|
|
registerServerbound(ServerboundPackets1_9_3.CHAT_MESSAGE, new PacketHandlers() {
|
2016-11-14 19:14:49 +01:00
|
|
|
@Override
|
2023-02-12 10:54:47 +01:00
|
|
|
public void register() {
|
2016-11-14 19:14:49 +01:00
|
|
|
map(Type.STRING); // 0 - Message
|
2023-02-12 11:44:25 +01:00
|
|
|
handler(wrapper -> {
|
|
|
|
// 100 character limit on older servers
|
|
|
|
String msg = wrapper.get(Type.STRING, 0);
|
|
|
|
if (msg.length() > 100) {
|
|
|
|
wrapper.set(Type.STRING, 0, msg.substring(0, 100));
|
2016-11-14 19:14:49 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2016-08-10 14:51:32 +02:00
|
|
|
}
|
|
|
|
|
2019-09-26 20:46:48 +02:00
|
|
|
private int getNewSoundId(int id) {
|
2016-10-04 19:35:20 +02:00
|
|
|
if (id == 196) // Experience orb sound got removed
|
|
|
|
return -1;
|
|
|
|
|
2019-09-26 20:46:48 +02:00
|
|
|
if (id >= 85) // Shulker boxes
|
|
|
|
id += 2;
|
|
|
|
if (id >= 176) // Guardian flop
|
|
|
|
id += 1;
|
|
|
|
if (id >= 197) // evocation things
|
|
|
|
id += 8;
|
2020-11-01 14:51:34 +01:00
|
|
|
if (id >= 207) // Rip the Experience orb touch sound :'(
|
2019-09-26 20:46:48 +02:00
|
|
|
id -= 1;
|
|
|
|
if (id >= 279) // Liama's
|
|
|
|
id += 9;
|
|
|
|
if (id >= 296) // Mule chest
|
|
|
|
id += 1;
|
|
|
|
if (id >= 390) // Vex
|
|
|
|
id += 4;
|
|
|
|
if (id >= 400) // vindication
|
|
|
|
id += 3;
|
|
|
|
if (id >= 450) // Elytra
|
|
|
|
id += 1;
|
|
|
|
if (id >= 455) // Empty bottle
|
|
|
|
id += 1;
|
|
|
|
if (id >= 470) // Totem use
|
|
|
|
id += 1;
|
|
|
|
return id;
|
2016-10-04 19:35:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-10 14:51:32 +02:00
|
|
|
@Override
|
|
|
|
public void init(UserConnection userConnection) {
|
2019-09-27 20:25:18 +02:00
|
|
|
// Entity tracker
|
Refactor entity tracking and meta handling
This essentially merges the two approaches to the metadata handling from ViaVersion and ViaBackwards and improves on both designs.
ViaVersion did not track every single entity, but only those needed (at least in theory) and can work with untracked entities' metadata. It had a very simple method overridden by metadata rewriter implementations, directly operating on the full metadata list and manually handling meta index changes as well as item/block/particle id changes.
ViaBackwards on the other hand had to track *every single* entity and threw warnings otherwise - while less prone to errors due to giving obvious warnings in the console, it unnecessarily tracks a lot of entities, and those warnings also annoys users when encountering virtual entity plugins (operating asynchronously and sending update packets while already untracked or not yet tracked). Dedicated MetaHandlers made id changes and filtering a lot easier to read and write. However, the actual metadata list handling and its distribution to handlers was not very well implemented and required a lot of list copying and creation as well as exception throws to cancel individual metadata entries.
This version has MetaFilters built with a Builder containing multiple helper functions, and the entity tracking is properly given its own map, hashed by a Protocol's class, to be easily and generically accessible from anywhere with only a Protocol class from the UserConnection, along with more optimized metadata list iteration. The entity tracking is largely unchanged, keeping ViaVersion's approach to not having to track *all* entities (and being able to handle null types in meta handlers).
All of this is by no means absolutely perfect, but is much less prone to errors than both previous systems and takes a lot less effort to actually write. A last possible change would be to use a primitive int to object map that is built to be concurrency save for the EntityTracker, tho that would have to be chosen carefully.
2021-05-24 23:24:50 +02:00
|
|
|
userConnection.addEntityTracker(this.getClass(), new EntityTracker1_11(userConnection));
|
2019-09-27 20:25:18 +02:00
|
|
|
|
2017-05-14 16:02:04 +02:00
|
|
|
if (!userConnection.has(ClientWorld.class))
|
2023-10-20 04:30:03 +02:00
|
|
|
userConnection.put(new ClientWorld());
|
2016-08-10 14:51:32 +02:00
|
|
|
}
|
2021-06-03 17:15:24 +02:00
|
|
|
|
|
|
|
@Override
|
2023-02-04 18:29:22 +01:00
|
|
|
public MetadataRewriter1_11To1_10 getEntityRewriter() {
|
2021-06-03 17:15:24 +02:00
|
|
|
return entityRewriter;
|
|
|
|
}
|
2021-06-04 12:15:14 +02:00
|
|
|
|
|
|
|
@Override
|
2023-02-04 18:29:22 +01:00
|
|
|
public InventoryPackets getItemRewriter() {
|
2021-06-04 12:15:14 +02:00
|
|
|
return itemRewriter;
|
|
|
|
}
|
2016-08-10 14:51:32 +02:00
|
|
|
}
|