ViaVersion/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/EntityPackets.java

409 lines
20 KiB
Java
Raw Normal View History

/*
* 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/>.
*/
package com.viaversion.viaversion.protocols.protocol1_9to1_8.packets;
2018-08-11 17:31:45 +02:00
import com.google.common.collect.ImmutableList;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
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.ValueTransformer;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_8;
import com.viaversion.viaversion.api.type.types.version.Types1_9;
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
2021-06-01 23:27:33 +02:00
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ServerboundPackets1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata.MetadataRewriter1_9To1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
import com.viaversion.viaversion.util.Pair;
import com.viaversion.viaversion.util.Triple;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class EntityPackets {
2016-09-27 18:31:10 +02:00
public static final ValueTransformer<Byte, Short> toNewShort = new ValueTransformer<Byte, Short>(Type.SHORT) {
@Override
public Short transform(PacketWrapper wrapper, Byte inputValue) {
return (short) (inputValue * 128);
}
};
public static void register(Protocol1_9To1_8 protocol) {
// Attach Entity Packet
protocol.registerClientbound(ClientboundPackets1_8.ATTACH_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Entity ID
map(Type.INT); // 1 - Vehicle
// Leash boolean is removed in new versions
map(Type.BOOLEAN, new ValueTransformer<Boolean, Void>(Type.NOTHING) {
@Override
public Void transform(PacketWrapper wrapper, Boolean inputValue) throws Exception {
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_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
if (!inputValue) {
int passenger = wrapper.get(Type.INT, 0);
int vehicle = wrapper.get(Type.INT, 1);
wrapper.cancel(); // Don't send current packet
2021-06-01 23:27:33 +02:00
PacketWrapper passengerPacket = wrapper.create(ClientboundPackets1_9.SET_PASSENGERS);
if (vehicle == -1) {
if (!tracker.getVehicleMap().containsKey(passenger))
return null; // Cancel
passengerPacket.write(Type.VAR_INT, tracker.getVehicleMap().remove(passenger));
2019-11-02 14:00:27 +01:00
passengerPacket.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[]{});
} else {
passengerPacket.write(Type.VAR_INT, vehicle);
2019-11-02 14:00:27 +01:00
passengerPacket.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[]{passenger});
tracker.getVehicleMap().put(passenger, vehicle);
}
passengerPacket.send(Protocol1_9To1_8.class); // Send the packet
}
return null;
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_8.ENTITY_TELEPORT, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.INT, SpawnPackets.toNewDouble); // 1 - X - Needs to be divide by 32
map(Type.INT, SpawnPackets.toNewDouble); // 2 - Y - Needs to be divide by 32
map(Type.INT, SpawnPackets.toNewDouble); // 3 - Z - Needs to be divide by 32
map(Type.BYTE); // 4 - Pitch
map(Type.BYTE); // 5 - Yaw
map(Type.BOOLEAN); // 6 - On Ground
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_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
if (tracker.getKnownHolograms().contains(entityID)) {
Double newValue = wrapper.get(Type.DOUBLE, 1);
newValue += (Via.getConfig().getHologramYOffset());
wrapper.set(Type.DOUBLE, 1, newValue);
}
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_8.ENTITY_POSITION_AND_ROTATION, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.BYTE, toNewShort); // 1 - X
map(Type.BYTE, toNewShort); // 2 - Y
map(Type.BYTE, toNewShort); // 3 - Z
map(Type.BYTE); // 4 - Yaw
map(Type.BYTE); // 5 - Pitch
map(Type.BOOLEAN); // 6 - On Ground
}
});
protocol.registerClientbound(ClientboundPackets1_8.ENTITY_POSITION, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.BYTE, toNewShort); // 1 - X
map(Type.BYTE, toNewShort); // 2 - Y
map(Type.BYTE, toNewShort); // 3 - Z
map(Type.BOOLEAN); // 4 - On Ground
}
});
protocol.registerClientbound(ClientboundPackets1_8.ENTITY_EQUIPMENT, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
// 1 - Slot ID
map(Type.SHORT, new ValueTransformer<Short, Integer>(Type.VAR_INT) {
@Override
2019-09-19 11:22:06 +02:00
public Integer transform(PacketWrapper wrapper, Short slot) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
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
int receiverId = wrapper.user().getEntityTracker(Protocol1_9To1_8.class).clientEntityId();
2019-09-19 11:22:06 +02:00
// Normally, 0 = hand and 1-4 = armor
// ... but if the sent id is equal to the receiver's id, 0-3 will instead mark the armor slots
// (In 1.9+, every client treats the received the same: 0=hand, 1=offhand, 2-5=armor)
if (entityId == receiverId) {
return slot.intValue() + 2;
}
return slot > 0 ? slot.intValue() + 1 : slot.intValue();
}
});
map(Type.ITEM); // 2 - Item
// Item Rewriter
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item stack = wrapper.get(Type.ITEM, 0);
ItemRewriter.toClient(stack);
}
});
// Blocking
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
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_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
int entityID = wrapper.get(Type.VAR_INT, 0);
Item stack = wrapper.get(Type.ITEM, 0);
if (stack != null) {
if (Protocol1_9To1_8.isSword(stack.identifier())) {
entityTracker.getValidBlocking().add(entityID);
return;
}
}
entityTracker.getValidBlocking().remove(entityID);
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_8.ENTITY_METADATA, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
2016-07-11 15:52:06 +02:00
map(Types1_8.METADATA_LIST, Types1_9.METADATA_LIST); // 1 - Metadata List
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
2016-07-11 15:52:06 +02:00
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
2019-05-09 14:43:48 +02:00
int entityId = wrapper.get(Type.VAR_INT, 0);
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_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
if (tracker.hasEntity(entityId)) {
protocol.get(MetadataRewriter1_9To1_8.class).handleMetadata(entityId, metadataList, wrapper.user());
} else {
// Buffer
2019-05-09 14:43:48 +02:00
tracker.addMetadataToBuffer(entityId, metadataList);
wrapper.cancel();
}
}
});
// Handler for meta data
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
2016-07-11 15:52:06 +02:00
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
int entityID = wrapper.get(Type.VAR_INT, 0);
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_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.handleMetadata(entityID, metadataList);
}
});
// Cancel packet if list empty
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
2016-07-11 15:52:06 +02:00
List<Metadata> metadataList = wrapper.get(Types1_9.METADATA_LIST, 0);
if (metadataList.isEmpty()) {
wrapper.cancel();
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_8.ENTITY_EFFECT, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.BYTE); // 1 - Effect ID
map(Type.BYTE); // 2 - Amplifier
map(Type.VAR_INT); // 3 - Duration
2016-03-23 12:42:03 +01:00
handler(new PacketHandler() { //Handle effect indicator
@Override
public void handle(PacketWrapper wrapper) throws Exception {
boolean showParticles = wrapper.read(Type.BOOLEAN); //In 1.8 = true->Show particles : false->Hide particles
boolean newEffect = Via.getConfig().isNewEffectIndicator();
2016-03-23 12:42:03 +01:00
//0: hide, 1: shown without indictator, 2: shown with indicator, 3: hide with beacon indicator but we don't use it.
wrapper.write(Type.BYTE, (byte) (showParticles ? newEffect ? 2 : 1 : 0));
}
});
}
});
protocol.cancelClientbound(ClientboundPackets1_8.UPDATE_ENTITY_NBT);
protocol.registerClientbound(ClientboundPackets1_8.COMBAT_EVENT, new PacketRemapper() {
2016-04-12 12:18:51 +02:00
@Override
public void registerMap() {
map(Type.VAR_INT); //Event id
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
if (wrapper.get(Type.VAR_INT, 0) == 2) { // entity dead
wrapper.passthrough(Type.VAR_INT); //Player id
wrapper.passthrough(Type.INT); //Entity id
Protocol1_9To1_8.FIX_JSON.write(wrapper, wrapper.read(Type.STRING));
2016-04-12 12:18:51 +02:00
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_8.ENTITY_PROPERTIES, new PacketRemapper() {
2018-08-11 17:31:45 +02:00
@Override
public void registerMap() {
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
if (!Via.getConfig().isMinimizeCooldown()) return;
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_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
if (wrapper.get(Type.VAR_INT, 0) != tracker.getProvidedEntityId()) {
2018-08-11 17:31:45 +02:00
return;
}
int propertiesToRead = wrapper.read(Type.INT);
Map<String, Pair<Double, List<Triple<UUID, Double, Byte>>>> properties = new HashMap<>(propertiesToRead);
for (int i = 0; i < propertiesToRead; i++) {
String key = wrapper.read(Type.STRING);
Double value = wrapper.read(Type.DOUBLE);
int modifiersToRead = wrapper.read(Type.VAR_INT);
List<Triple<UUID, Double, Byte>> modifiers = new ArrayList<>(modifiersToRead);
for (int j = 0; j < modifiersToRead; j++) {
modifiers.add(
new Triple<>(
wrapper.read(Type.UUID),
wrapper.read(Type.DOUBLE), // Amount
wrapper.read(Type.BYTE) // Operation
)
);
}
properties.put(key, new Pair<>(value, modifiers));
}
2018-08-11 17:31:45 +02:00
// == Why 15.9? ==
// Higher values hides the cooldown but it bugs visual animation on hand
// when removing item from hand with inventory gui
properties.put("generic.attackSpeed", new Pair<Double, List<Triple<UUID, Double, Byte>>>(15.9, ImmutableList.of( // Neutralize modifiers
new Triple<>(UUID.fromString("FA233E1C-4180-4865-B01B-BCCE9785ACA3"), 0.0, (byte) 0), // Tool and weapon modifier
new Triple<>(UUID.fromString("AF8B6E3F-3328-4C0A-AA36-5BA2BB9DBEF3"), 0.0, (byte) 2), // Dig speed
new Triple<>(UUID.fromString("55FCED67-E92A-486E-9800-B47F202C4386"), 0.0, (byte) 2) // Dig slow down
)));
wrapper.write(Type.INT, properties.size());
for (Map.Entry<String, Pair<Double, List<Triple<UUID, Double, Byte>>>> entry : properties.entrySet()) {
wrapper.write(Type.STRING, entry.getKey()); // Key
wrapper.write(Type.DOUBLE, entry.getValue().getKey()); // Value
wrapper.write(Type.VAR_INT, entry.getValue().getValue().size());
for (Triple<UUID, Double, Byte> modifier : entry.getValue().getValue()) {
wrapper.write(Type.UUID, modifier.getFirst());
wrapper.write(Type.DOUBLE, modifier.getSecond()); // Amount
wrapper.write(Type.BYTE, modifier.getThird()); // Operation
}
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_8.ENTITY_ANIMATION, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UNSIGNED_BYTE); // 1 - Animation
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 3) {
wrapper.cancel();
}
}
});
}
2018-08-11 17:31:45 +02:00
});
/* Incoming Packets */
protocol.registerServerbound(ServerboundPackets1_9.ENTITY_ACTION, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Player ID
map(Type.VAR_INT); // 1 - Action
map(Type.VAR_INT); // 2 - Jump
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int action = wrapper.get(Type.VAR_INT, 1);
if (action == 6 || action == 8)
wrapper.cancel();
if (action == 7) {
wrapper.set(Type.VAR_INT, 1, 6);
}
}
});
}
});
protocol.registerServerbound(ServerboundPackets1_9.INTERACT_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID (Target)
map(Type.VAR_INT); // 1 - Action Type
// Cancel second hand to prevent double interact
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int type = wrapper.get(Type.VAR_INT, 1);
if (type == 2) {
wrapper.passthrough(Type.FLOAT); // 2 - X
wrapper.passthrough(Type.FLOAT); // 3 - Y
wrapper.passthrough(Type.FLOAT); // 4 - Z
}
if (type == 0 || type == 2) {
int hand = wrapper.read(Type.VAR_INT); // 2/5 - Hand
if (hand == 1)
wrapper.cancel();
}
}
});
}
});
}
}