128 lines
5.3 KiB
Java
128 lines
5.3 KiB
Java
/*
|
|
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
|
* 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 nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.packets;
|
|
|
|
import nl.matsv.viabackwards.api.rewriters.LegacyEntityRewriter;
|
|
import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1;
|
|
import us.myles.ViaVersion.api.entities.Entity1_11Types;
|
|
import us.myles.ViaVersion.api.entities.EntityType;
|
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
|
import us.myles.ViaVersion.api.type.Type;
|
|
import us.myles.ViaVersion.api.type.types.version.Types1_9;
|
|
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
|
|
|
|
public class EntityPackets1_11_1 extends LegacyEntityRewriter<Protocol1_11To1_11_1> {
|
|
|
|
public EntityPackets1_11_1(Protocol1_11To1_11_1 protocol) {
|
|
super(protocol);
|
|
}
|
|
|
|
@Override
|
|
protected void registerPackets() {
|
|
protocol.registerOutgoing(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketRemapper() {
|
|
@Override
|
|
public void registerMap() {
|
|
map(Type.VAR_INT); // 0 - Entity id
|
|
map(Type.UUID); // 1 - UUID
|
|
map(Type.BYTE); // 2 - Type
|
|
map(Type.DOUBLE); // 3 - x
|
|
map(Type.DOUBLE); // 4 - y
|
|
map(Type.DOUBLE); // 5 - z
|
|
map(Type.BYTE); // 6 - Pitch
|
|
map(Type.BYTE); // 7 - Yaw
|
|
map(Type.INT); // 8 - data
|
|
|
|
// Track Entity
|
|
handler(getObjectTrackerHandler());
|
|
handler(getObjectRewriter(id -> Entity1_11Types.ObjectType.findById(id).orElse(null)));
|
|
}
|
|
});
|
|
|
|
registerExtraTracker(ClientboundPackets1_9_3.SPAWN_EXPERIENCE_ORB, Entity1_11Types.EntityType.EXPERIENCE_ORB);
|
|
registerExtraTracker(ClientboundPackets1_9_3.SPAWN_GLOBAL_ENTITY, Entity1_11Types.EntityType.WEATHER);
|
|
|
|
protocol.registerOutgoing(ClientboundPackets1_9_3.SPAWN_MOB, new PacketRemapper() {
|
|
@Override
|
|
public void registerMap() {
|
|
map(Type.VAR_INT); // 0 - Entity id
|
|
map(Type.UUID); // 1 - UUID
|
|
map(Type.VAR_INT); // 2 - Entity Type
|
|
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
|
|
|
|
// Track entity
|
|
handler(getTrackerHandler());
|
|
|
|
// Rewrite entity type / metadata
|
|
handler(getMobSpawnRewriter(Types1_9.METADATA_LIST));
|
|
}
|
|
});
|
|
|
|
registerExtraTracker(ClientboundPackets1_9_3.SPAWN_PAINTING, Entity1_11Types.EntityType.PAINTING);
|
|
registerJoinGame(ClientboundPackets1_9_3.JOIN_GAME, Entity1_11Types.EntityType.PLAYER);
|
|
registerRespawn(ClientboundPackets1_9_3.RESPAWN);
|
|
|
|
protocol.registerOutgoing(ClientboundPackets1_9_3.SPAWN_PLAYER, new PacketRemapper() {
|
|
@Override
|
|
public void registerMap() {
|
|
map(Type.VAR_INT); // 0 - Entity ID
|
|
map(Type.UUID); // 1 - Player UUID
|
|
map(Type.DOUBLE); // 2 - X
|
|
map(Type.DOUBLE); // 3 - Y
|
|
map(Type.DOUBLE); // 4 - Z
|
|
map(Type.BYTE); // 5 - Yaw
|
|
map(Type.BYTE); // 6 - Pitch
|
|
map(Types1_9.METADATA_LIST); // 7 - Metadata list
|
|
|
|
handler(getTrackerAndMetaHandler(Types1_9.METADATA_LIST, Entity1_11Types.EntityType.PLAYER));
|
|
}
|
|
});
|
|
|
|
registerEntityDestroy(ClientboundPackets1_9_3.DESTROY_ENTITIES);
|
|
registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_9.METADATA_LIST);
|
|
}
|
|
|
|
@Override
|
|
protected void registerRewrites() {
|
|
// Handle non-existing firework metadata (index 7 entity id for boosting)
|
|
registerMetaHandler().filter(Entity1_11Types.EntityType.FIREWORK, 7).removed();
|
|
|
|
// Handle non-existing pig metadata (index 14 - boost time)
|
|
registerMetaHandler().filter(Entity1_11Types.EntityType.PIG, 14).removed();
|
|
}
|
|
|
|
@Override
|
|
protected EntityType getTypeFromId(int typeId) {
|
|
return Entity1_11Types.getTypeFromId(typeId, false);
|
|
}
|
|
|
|
@Override
|
|
protected EntityType getObjectTypeFromId(final int typeId) {
|
|
return Entity1_11Types.getTypeFromId(typeId, true);
|
|
}
|
|
}
|