2021-03-22 23:06:40 +01:00
|
|
|
/*
|
|
|
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
|
|
|
* Copyright (C) 2016-2021 ViaVersion and contributors
|
|
|
|
*
|
|
|
|
* 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;
|
2021-04-27 13:41:39 +02:00
|
|
|
import com.viaversion.viaversion.api.minecraft.entities.Entity1_11Types;
|
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;
|
2021-04-26 21:16:10 +02:00
|
|
|
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
|
|
|
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
|
|
|
import com.viaversion.viaversion.api.protocol.remapper.ValueCreator;
|
|
|
|
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_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
|
|
|
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;
|
|
|
|
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
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
|
|
|
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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() {
|
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
|
|
|
EntityRewriter metadataRewriter = new MetadataRewriter1_11To1_10(this);
|
|
|
|
metadataRewriter.register();
|
2019-05-09 14:43:48 +02:00
|
|
|
|
2016-08-10 20:12:27 +02:00
|
|
|
InventoryPackets.register(this);
|
|
|
|
|
2021-04-28 12:59:37 +02:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketRemapper() {
|
2016-09-30 20:08:39 +02:00
|
|
|
@Override
|
|
|
|
public void registerMap() {
|
|
|
|
map(Type.VAR_INT); // 0 - Entity id
|
|
|
|
map(Type.UUID); // 1 - UUID
|
|
|
|
map(Type.BYTE); // 2 - Type
|
|
|
|
|
|
|
|
// Track Entity
|
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
|
|
|
handler(metadataRewriter.objectTrackerHandler());
|
2016-09-30 20:08:39 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-28 12:59:37 +02:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.SPAWN_MOB, new PacketRemapper() {
|
2016-08-10 15:59:13 +02:00
|
|
|
@Override
|
|
|
|
public void registerMap() {
|
|
|
|
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
|
|
|
|
2016-08-10 19:54:56 +02:00
|
|
|
handler(new PacketHandler() {
|
|
|
|
@Override
|
|
|
|
public void handle(PacketWrapper wrapper) throws Exception {
|
2016-09-30 20:08:39 +02:00
|
|
|
int entityId = wrapper.get(Type.VAR_INT, 0);
|
2016-08-10 20:38:59 +02:00
|
|
|
// Change Type :)
|
|
|
|
int type = wrapper.get(Type.VAR_INT, 1);
|
2016-09-30 20:08:39 +02:00
|
|
|
|
2019-05-09 14:43:48 +02:00
|
|
|
Entity1_11Types.EntityType entType = MetadataRewriter1_11To1_10.rewriteEntityType(type, wrapper.get(Types1_9.METADATA_LIST, 0));
|
2019-05-27 18:50:08 +02:00
|
|
|
if (entType != null) {
|
2016-09-30 20:08:39 +02:00
|
|
|
wrapper.set(Type.VAR_INT, 1, entType.getId());
|
|
|
|
|
2019-05-27 18:50:08 +02:00
|
|
|
// Register Type ID
|
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
|
|
|
wrapper.user().getEntityTracker(Protocol1_11To1_10.class).addEntity(entityId, entType);
|
2019-09-27 20:25:18 +02:00
|
|
|
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user());
|
2019-05-27 18:50:08 +02:00
|
|
|
}
|
2016-08-10 19:54:56 +02:00
|
|
|
}
|
|
|
|
});
|
2016-08-10 15:59:13 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-06 09:45:43 +02:00
|
|
|
new SoundRewriter(this, this::getNewSoundId).registerSound(ClientboundPackets1_9_3.SOUND);
|
2016-10-04 19:35:20 +02:00
|
|
|
|
2021-04-28 12:59:37 +02:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.COLLECT_ITEM, new PacketRemapper() {
|
2016-08-10 15:59:13 +02:00
|
|
|
@Override
|
|
|
|
public void registerMap() {
|
|
|
|
map(Type.VAR_INT); // 0 - Collected entity id
|
|
|
|
map(Type.VAR_INT); // 1 - Collector entity id
|
|
|
|
|
|
|
|
create(new ValueCreator() {
|
|
|
|
@Override
|
|
|
|
public void write(PacketWrapper wrapper) throws Exception {
|
2016-08-10 17:11:39 +02:00
|
|
|
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
|
|
|
|
2020-06-06 09:45:43 +02:00
|
|
|
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_9.METADATA_LIST);
|
2016-09-30 20:08:39 +02:00
|
|
|
|
2021-04-28 12:59:37 +02:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.ENTITY_TELEPORT, new PacketRemapper() {
|
2016-09-30 20:08:39 +02:00
|
|
|
@Override
|
|
|
|
public void registerMap() {
|
|
|
|
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
|
|
|
|
|
|
|
|
handler(new PacketHandler() {
|
|
|
|
@Override
|
|
|
|
public void handle(PacketWrapper wrapper) throws Exception {
|
|
|
|
int entityID = wrapper.get(Type.VAR_INT, 0);
|
|
|
|
if (Via.getConfig().isHologramPatch()) {
|
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
|
|
|
EntityTracker1_11 tracker = wrapper.user().getEntityTracker(Protocol1_11To1_10.class);
|
2016-09-30 20:08:39 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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
|
|
|
metadataRewriter.registerRemoveEntities(ClientboundPackets1_9_3.DESTROY_ENTITIES);
|
2016-09-30 17:14:14 +02:00
|
|
|
|
2021-04-28 12:59:37 +02:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.TITLE, new PacketRemapper() {
|
2016-11-06 10:37:26 +01:00
|
|
|
@Override
|
|
|
|
public void registerMap() {
|
|
|
|
map(Type.VAR_INT); // 0 - Action
|
|
|
|
|
|
|
|
handler(new PacketHandler() {
|
|
|
|
@Override
|
|
|
|
public void handle(PacketWrapper wrapper) throws Exception {
|
|
|
|
int action = wrapper.get(Type.VAR_INT, 0);
|
|
|
|
|
|
|
|
// Handle the new ActionBar
|
2020-06-25 16:22:53 +02:00
|
|
|
if (action >= 2) {
|
2016-11-06 10:37:26 +01:00
|
|
|
wrapper.set(Type.VAR_INT, 0, action + 1);
|
2020-06-25 16:22:53 +02:00
|
|
|
}
|
2016-11-06 10:37:26 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-28 12:59:37 +02:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.BLOCK_ACTION, new PacketRemapper() {
|
2016-12-15 16:32:54 +01:00
|
|
|
@Override
|
|
|
|
public void registerMap() {
|
|
|
|
map(Type.POSITION); // 0 - Position
|
|
|
|
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
|
|
|
|
handler(new PacketHandler() {
|
|
|
|
@Override
|
|
|
|
public void handle(final PacketWrapper actionWrapper) throws Exception {
|
|
|
|
if (Via.getConfig().isPistonAnimationPatch()) {
|
|
|
|
int id = actionWrapper.get(Type.VAR_INT, 0);
|
|
|
|
if (id == 33 || id == 29) {
|
|
|
|
actionWrapper.cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-28 12:59:37 +02:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.BLOCK_ENTITY_DATA, new PacketRemapper() {
|
2017-05-14 16:02:04 +02:00
|
|
|
@Override
|
|
|
|
public void registerMap() {
|
|
|
|
map(Type.POSITION); // 0 - Position
|
|
|
|
map(Type.UNSIGNED_BYTE); // 1 - Action
|
|
|
|
map(Type.NBT); // 2 - NBT data
|
|
|
|
|
|
|
|
handler(new PacketHandler() {
|
|
|
|
@Override
|
|
|
|
public void handle(PacketWrapper wrapper) throws Exception {
|
2018-04-07 18:00:18 +02:00
|
|
|
CompoundTag tag = wrapper.get(Type.NBT, 0);
|
|
|
|
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 1)
|
2017-05-14 16:02:04 +02:00
|
|
|
EntityIdRewriter.toClientSpawner(tag);
|
2018-04-07 18:00:18 +02:00
|
|
|
|
|
|
|
if (tag.contains("id"))
|
|
|
|
// Handle new identifier
|
|
|
|
((StringTag) tag.get("id")).setValue(BlockEntityRewriter.toNewIdentifier((String) tag.get("id").getValue()));
|
|
|
|
|
2017-05-14 16:02:04 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-28 12:59:37 +02:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, new PacketRemapper() {
|
2017-05-14 16:02:04 +02:00
|
|
|
@Override
|
|
|
|
public void registerMap() {
|
|
|
|
handler(new PacketHandler() {
|
|
|
|
@Override
|
|
|
|
public void handle(PacketWrapper wrapper) throws Exception {
|
|
|
|
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
|
|
|
|
2017-05-14 16:15:21 +02:00
|
|
|
Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld);
|
2017-05-14 16:02:04 +02:00
|
|
|
Chunk chunk = wrapper.passthrough(type);
|
|
|
|
|
2017-05-17 19:15:52 +02:00
|
|
|
// Clear any other bytes (This is a workaround for a issue with 1.9.2 encoder adding nbt list)
|
|
|
|
wrapper.clearInputBuffer();
|
|
|
|
|
2017-05-14 16:02:04 +02:00
|
|
|
if (chunk.getBlockEntities() == null) return;
|
|
|
|
for (CompoundTag tag : chunk.getBlockEntities()) {
|
2018-04-07 18:00:18 +02:00
|
|
|
if (tag.contains("id")) {
|
|
|
|
String identifier = ((StringTag) tag.get("id")).getValue();
|
2020-06-25 11:18:07 +02:00
|
|
|
if (identifier.equals("MobSpawner")) {
|
2018-04-07 18:00:18 +02:00
|
|
|
EntityIdRewriter.toClientSpawner(tag);
|
2020-06-25 11:18:07 +02:00
|
|
|
}
|
2018-04-07 18:00:18 +02:00
|
|
|
|
|
|
|
// Handle new identifier
|
|
|
|
((StringTag) tag.get("id")).setValue(BlockEntityRewriter.toNewIdentifier(identifier));
|
2017-05-14 16:02:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-28 12:59:37 +02:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.JOIN_GAME, new PacketRemapper() {
|
2020-08-10 21:22:01 +02:00
|
|
|
@Override
|
|
|
|
public void registerMap() {
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2021-04-28 12:59:37 +02:00
|
|
|
registerClientbound(ClientboundPackets1_9_3.RESPAWN, new PacketRemapper() {
|
2020-08-10 21:22:01 +02:00
|
|
|
@Override
|
|
|
|
public void registerMap() {
|
|
|
|
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
|
|
|
|
2021-04-28 12:59:37 +02:00
|
|
|
this.registerClientbound(ClientboundPackets1_9_3.EFFECT, new PacketRemapper() {
|
2020-08-10 22:17:31 +02:00
|
|
|
@Override
|
|
|
|
public void registerMap() {
|
|
|
|
this.map(Type.INT); //effectID
|
|
|
|
this.map(Type.POSITION); //pos
|
|
|
|
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 {
|
|
|
|
data = newData.getKey();
|
2020-08-10 22:28:40 +02:00
|
|
|
isInstant = newData.getValue();
|
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
|
|
|
|
2021-04-28 12:59:37 +02:00
|
|
|
registerServerbound(ServerboundPackets1_9_3.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() {
|
2016-09-30 17:14:14 +02:00
|
|
|
@Override
|
|
|
|
public void registerMap() {
|
|
|
|
map(Type.POSITION); // 0 - Location
|
|
|
|
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
|
|
|
|
2021-04-28 12:59:37 +02:00
|
|
|
registerServerbound(ServerboundPackets1_9_3.CHAT_MESSAGE, new PacketRemapper() {
|
2016-11-14 19:14:49 +01:00
|
|
|
@Override
|
|
|
|
public void registerMap() {
|
|
|
|
map(Type.STRING); // 0 - Message
|
|
|
|
handler(new PacketHandler() {
|
|
|
|
@Override
|
|
|
|
public void handle(PacketWrapper wrapper) throws Exception {
|
|
|
|
// 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-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))
|
|
|
|
userConnection.put(new ClientWorld(userConnection));
|
2016-08-10 14:51:32 +02:00
|
|
|
}
|
|
|
|
}
|