mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-12-23 17:08:15 +01:00
Merge pull request #1568 from KennyTV/abstraction
Merge master into abstraction
This commit is contained in:
commit
dd5c1bb1a4
@ -1,4 +1,4 @@
|
|||||||
# ViaVersion 2.1.3 - Spigot, Sponge, BungeeCord, Velocity
|
# ViaVersion 2.2.0 - Spigot, Sponge, BungeeCord, Velocity
|
||||||
[![Build Status](https://travis-ci.com/ViaVersion/ViaVersion.svg?branch=master)](https://travis-ci.com/ViaVersion/ViaVersion)
|
[![Build Status](https://travis-ci.com/ViaVersion/ViaVersion.svg?branch=master)](https://travis-ci.com/ViaVersion/ViaVersion)
|
||||||
[![Discord](https://img.shields.io/badge/chat-on%20discord-blue.svg)](https://viaversion.com/discord)
|
[![Discord](https://img.shields.io/badge/chat-on%20discord-blue.svg)](https://viaversion.com/discord)
|
||||||
|
|
||||||
|
@ -18,10 +18,7 @@ import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
|||||||
import us.myles.ViaVersion.util.PipelineUtil;
|
import us.myles.ViaVersion.util.PipelineUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class PacketWrapper {
|
public class PacketWrapper {
|
||||||
public static final int PASSTHROUGH_ID = 1000;
|
public static final int PASSTHROUGH_ID = 1000;
|
||||||
@ -326,13 +323,14 @@ public class PacketWrapper {
|
|||||||
// Other way if outgoing
|
// Other way if outgoing
|
||||||
Collections.reverse(protocols);
|
Collections.reverse(protocols);
|
||||||
}
|
}
|
||||||
int index = 0;
|
int index = -1;
|
||||||
for (int i = 0; i < protocols.size(); i++) {
|
for (int i = 0; i < protocols.size(); i++) {
|
||||||
if (protocols.get(i).getClass().equals(packetProtocol)) {
|
if (protocols.get(i).getClass().equals(packetProtocol)) {
|
||||||
index = skipCurrentPipeline ? (i + 1) : (i);
|
index = skipCurrentPipeline ? (i + 1) : (i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (index == -1) throw new NoSuchElementException(packetProtocol.getCanonicalName());
|
||||||
|
|
||||||
// Reset reader before we start
|
// Reset reader before we start
|
||||||
resetReader();
|
resetReader();
|
||||||
|
@ -77,7 +77,7 @@ public class ProtocolVersion {
|
|||||||
register(v1_14_2 = new ProtocolVersion(485, "1.14.2"));
|
register(v1_14_2 = new ProtocolVersion(485, "1.14.2"));
|
||||||
register(v1_14_3 = new ProtocolVersion(490, "1.14.3"));
|
register(v1_14_3 = new ProtocolVersion(490, "1.14.3"));
|
||||||
register(v1_14_4 = new ProtocolVersion(498, "1.14.4"));
|
register(v1_14_4 = new ProtocolVersion(498, "1.14.4"));
|
||||||
register(v1_15 = new ProtocolVersion(571, "1.15"));
|
register(v1_15 = new ProtocolVersion(573, "1.15"));
|
||||||
register(unknown = new ProtocolVersion(-1, "UNKNOWN"));
|
register(unknown = new ProtocolVersion(-1, "UNKNOWN"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,70 +2,73 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentiti
|
|||||||
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import us.myles.ViaVersion.api.Pair;
|
import us.myles.ViaVersion.api.Pair;
|
||||||
import us.myles.ViaVersion.api.Via;
|
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class FlowerPotHandler implements BlockEntityProvider.BlockEntityHandler {
|
public class FlowerPotHandler implements BlockEntityProvider.BlockEntityHandler {
|
||||||
private static final Map<Pair<String, Byte>, Integer> flowers = new HashMap<>();
|
// Object -> string (id without namespace) or byte (numeric id)
|
||||||
private static final Map<Pair<Byte, Byte>, Integer> flowersNumberId = new HashMap<>();
|
private static final Map<Pair<?, Byte>, Integer> flowers = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
register("minecraft:air", (byte) 0, (byte) 0, 5265);
|
register("air", (byte) 0, (byte) 0, 5265);
|
||||||
register("minecraft:sapling", (byte) 6, (byte) 0, 5266);
|
register("sapling", (byte) 6, (byte) 0, 5266);
|
||||||
register("minecraft:sapling", (byte) 6, (byte) 1, 5267);
|
register("sapling", (byte) 6, (byte) 1, 5267);
|
||||||
register("minecraft:sapling", (byte) 6, (byte) 2, 5268);
|
register("sapling", (byte) 6, (byte) 2, 5268);
|
||||||
register("minecraft:sapling", (byte) 6, (byte) 3, 5269);
|
register("sapling", (byte) 6, (byte) 3, 5269);
|
||||||
register("minecraft:sapling", (byte) 6, (byte) 4, 5270);
|
register("sapling", (byte) 6, (byte) 4, 5270);
|
||||||
register("minecraft:sapling", (byte) 6, (byte) 5, 5271);
|
register("sapling", (byte) 6, (byte) 5, 5271);
|
||||||
register("minecraft:tallgrass", (byte) 31, (byte) 2, 5272);
|
register("tallgrass", (byte) 31, (byte) 2, 5272);
|
||||||
register("minecraft:yellow_flower", (byte) 37, (byte) 0, 5273);
|
register("yellow_flower", (byte) 37, (byte) 0, 5273);
|
||||||
register("minecraft:red_flower", (byte) 38, (byte) 0, 5274);
|
register("red_flower", (byte) 38, (byte) 0, 5274);
|
||||||
register("minecraft:red_flower", (byte) 38, (byte) 1, 5275);
|
register("red_flower", (byte) 38, (byte) 1, 5275);
|
||||||
register("minecraft:red_flower", (byte) 38, (byte) 2, 5276);
|
register("red_flower", (byte) 38, (byte) 2, 5276);
|
||||||
register("minecraft:red_flower", (byte) 38, (byte) 3, 5277);
|
register("red_flower", (byte) 38, (byte) 3, 5277);
|
||||||
register("minecraft:red_flower", (byte) 38, (byte) 4, 5278);
|
register("red_flower", (byte) 38, (byte) 4, 5278);
|
||||||
register("minecraft:red_flower", (byte) 38, (byte) 5, 5279);
|
register("red_flower", (byte) 38, (byte) 5, 5279);
|
||||||
register("minecraft:red_flower", (byte) 38, (byte) 6, 5280);
|
register("red_flower", (byte) 38, (byte) 6, 5280);
|
||||||
register("minecraft:red_flower", (byte) 38, (byte) 7, 5281);
|
register("red_flower", (byte) 38, (byte) 7, 5281);
|
||||||
register("minecraft:red_flower", (byte) 38, (byte) 8, 5282);
|
register("red_flower", (byte) 38, (byte) 8, 5282);
|
||||||
register("minecraft:red_mushroom", (byte) 40, (byte) 0, 5283);
|
register("red_mushroom", (byte) 40, (byte) 0, 5283);
|
||||||
register("minecraft:brown_mushroom", (byte) 39, (byte) 0, 5284);
|
register("brown_mushroom", (byte) 39, (byte) 0, 5284);
|
||||||
register("minecraft:deadbush", (byte) 32, (byte) 0, 5285);
|
register("deadbush", (byte) 32, (byte) 0, 5285);
|
||||||
register("minecraft:cactus", (byte) 81, (byte) 0, 5286);
|
register("cactus", (byte) 81, (byte) 0, 5286);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void register(String identifier, byte numbericBlockId, byte blockData, int newId) {
|
public static void register(String identifier, byte numbericBlockId, byte blockData, int newId) {
|
||||||
flowers.put(new Pair<>(identifier, blockData), newId);
|
flowers.put(new Pair<>(identifier, blockData), newId);
|
||||||
flowersNumberId.put(new Pair<>(numbericBlockId, blockData), newId);
|
flowers.put(new Pair<>(numbericBlockId, blockData), newId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int transform(UserConnection user, CompoundTag tag) {
|
public int transform(UserConnection user, CompoundTag tag) {
|
||||||
Object item = tag.get("Item").getValue();
|
Object item = tag.contains("Item") ? tag.get("Item").getValue() : null;
|
||||||
byte data = ((Number) tag.get("Data").getValue()).byteValue();
|
Object data = tag.contains("Data") ? tag.get("Data").getValue() : null;
|
||||||
|
|
||||||
Pair<?, Byte> pair = item instanceof Number
|
// Convert item to String without namespace or to Byte
|
||||||
? new Pair<>(((Number) item).byteValue(), data)
|
if (item instanceof String) {
|
||||||
: new Pair<>((String) item, data);
|
item = ((String) item).replace("minecraft:", "");
|
||||||
|
} else if (item instanceof Number) {
|
||||||
// Return air on empty string
|
item = ((Number) item).byteValue();
|
||||||
if (item instanceof String && ((String) item).isEmpty())
|
|
||||||
return 5265;
|
|
||||||
else if (flowers.containsKey(pair)) {
|
|
||||||
return flowers.get(pair);
|
|
||||||
} else if (flowersNumberId.containsKey(pair)) {
|
|
||||||
return flowersNumberId.get(pair);
|
|
||||||
} else {
|
} else {
|
||||||
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
|
item = (byte) 0;
|
||||||
Via.getPlatform().getLogger().warning("Could not find flowerpot content " + item + " for " + tag);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
// Convert data to Byte
|
||||||
|
if (data instanceof Number) {
|
||||||
|
data = ((Number) data).byteValue();
|
||||||
|
} else {
|
||||||
|
data = (byte) 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer flower = flowers.get(new Pair<>(item, (byte) data));
|
||||||
|
if (flower != null) return flower;
|
||||||
|
flower = flowers.get(new Pair<>(item, (byte) 0));
|
||||||
|
if (flower != null) return flower;
|
||||||
|
|
||||||
|
return 5265; // Fallback to empty pot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -236,9 +236,6 @@ public class Protocol1_15To1_14_4 extends Protocol {
|
|||||||
|
|
||||||
registerOutgoing(State.PLAY, 0x58, 0x59);
|
registerOutgoing(State.PLAY, 0x58, 0x59);
|
||||||
registerOutgoing(State.PLAY, 0x59, 0x5A);
|
registerOutgoing(State.PLAY, 0x59, 0x5A);
|
||||||
|
|
||||||
|
|
||||||
registerOutgoing(State.PLAY, 0x5C, 0x08);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getNewSoundId(int id) {
|
public static int getNewSoundId(int id) {
|
||||||
|
@ -2,6 +2,7 @@ package us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets;
|
|||||||
|
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.entities.Entity1_15Types;
|
import us.myles.ViaVersion.api.entities.Entity1_15Types;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
@ -12,6 +13,7 @@ import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
|
|||||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.metadata.MetadataRewriter1_15To1_14_4;
|
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.metadata.MetadataRewriter1_15To1_14_4;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.storage.EntityTracker1_15;
|
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.storage.EntityTracker1_15;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class EntityPackets {
|
public class EntityPackets {
|
||||||
@ -73,7 +75,6 @@ public class EntityPackets {
|
|||||||
map(Type.SHORT); // 9 - Velocity X
|
map(Type.SHORT); // 9 - Velocity X
|
||||||
map(Type.SHORT); // 10 - Velocity Y
|
map(Type.SHORT); // 10 - Velocity Y
|
||||||
map(Type.SHORT); // 11 - Velocity Z
|
map(Type.SHORT); // 11 - Velocity Z
|
||||||
map(Types1_14.METADATA_LIST, Type.NOTHING); // removed - probably sent in an update packet?
|
|
||||||
|
|
||||||
handler(new PacketHandler() {
|
handler(new PacketHandler() {
|
||||||
@Override
|
@Override
|
||||||
@ -83,6 +84,13 @@ public class EntityPackets {
|
|||||||
Entity1_15Types.EntityType entityType = Entity1_15Types.getTypeFromId(getNewEntityId(typeId));
|
Entity1_15Types.EntityType entityType = Entity1_15Types.getTypeFromId(getNewEntityId(typeId));
|
||||||
wrapper.user().get(EntityTracker1_15.class).addEntity(entityId, entityType);
|
wrapper.user().get(EntityTracker1_15.class).addEntity(entityId, entityType);
|
||||||
wrapper.set(Type.VAR_INT, 1, entityType.getId());
|
wrapper.set(Type.VAR_INT, 1, entityType.getId());
|
||||||
|
|
||||||
|
List<Metadata> metadata = wrapper.read(Types1_14.METADATA_LIST);
|
||||||
|
metadataRewriter.handleMetadata(entityId, metadata, wrapper.user());
|
||||||
|
PacketWrapper metadataUpdate = wrapper.create(0x44);
|
||||||
|
metadataUpdate.write(Type.VAR_INT, entityId);
|
||||||
|
metadataUpdate.write(Types1_14.METADATA_LIST, metadata);
|
||||||
|
metadataUpdate.send(Protocol1_15To1_14_4.class);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -99,15 +107,20 @@ public class EntityPackets {
|
|||||||
map(Type.DOUBLE); // 4 - Z
|
map(Type.DOUBLE); // 4 - Z
|
||||||
map(Type.BYTE); // 5 - Yaw
|
map(Type.BYTE); // 5 - Yaw
|
||||||
map(Type.BYTE); // 6 - Pitch
|
map(Type.BYTE); // 6 - Pitch
|
||||||
map(Types1_14.METADATA_LIST, Type.NOTHING); // removed - probably sent in an update packet?
|
|
||||||
|
|
||||||
handler(new PacketHandler() {
|
handler(new PacketHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||||
|
|
||||||
Entity1_15Types.EntityType entityType = Entity1_15Types.EntityType.PLAYER;
|
Entity1_15Types.EntityType entityType = Entity1_15Types.EntityType.PLAYER;
|
||||||
wrapper.user().get(EntityTracker1_15.class).addEntity(entityId, entityType);
|
wrapper.user().get(EntityTracker1_15.class).addEntity(entityId, entityType);
|
||||||
|
|
||||||
|
List<Metadata> metadata = wrapper.read(Types1_14.METADATA_LIST);
|
||||||
|
metadataRewriter.handleMetadata(entityId, metadata, wrapper.user());
|
||||||
|
PacketWrapper metadataUpdate = wrapper.create(0x44);
|
||||||
|
metadataUpdate.write(Type.VAR_INT, entityId);
|
||||||
|
metadataUpdate.write(Types1_14.METADATA_LIST, metadata);
|
||||||
|
metadataUpdate.send(Protocol1_15To1_14_4.class);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ public class InventoryPackets {
|
|||||||
wrapper.passthrough(Type.INT);
|
wrapper.passthrough(Type.INT);
|
||||||
wrapper.passthrough(Type.INT);
|
wrapper.passthrough(Type.INT);
|
||||||
wrapper.passthrough(Type.FLOAT);
|
wrapper.passthrough(Type.FLOAT);
|
||||||
|
wrapper.passthrough(Type.INT);
|
||||||
}
|
}
|
||||||
|
|
||||||
wrapper.passthrough(Type.VAR_INT);
|
wrapper.passthrough(Type.VAR_INT);
|
||||||
|
@ -9,7 +9,6 @@ import us.myles.ViaVersion.api.remapper.PacketHandler;
|
|||||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.InventoryPackets;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type;
|
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
|
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type;
|
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type;
|
||||||
@ -18,6 +17,22 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
|||||||
public class WorldPackets {
|
public class WorldPackets {
|
||||||
|
|
||||||
public static void register(Protocol protocol) {
|
public static void register(Protocol protocol) {
|
||||||
|
// Acknowledge player digging
|
||||||
|
protocol.registerOutgoing(State.PLAY, 0x5C, 0x08, new PacketRemapper() {
|
||||||
|
@Override
|
||||||
|
public void registerMap() {
|
||||||
|
map(Type.POSITION1_14);
|
||||||
|
map(Type.VAR_INT);
|
||||||
|
handler(new PacketHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
|
int blockState = wrapper.get(Type.VAR_INT, 0);
|
||||||
|
wrapper.set(Type.VAR_INT, 0, Protocol1_15To1_14_4.getNewBlockStateId(blockState));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Block Action
|
// Block Action
|
||||||
protocol.registerOutgoing(State.PLAY, 0x0A, 0x0B, new PacketRemapper() {
|
protocol.registerOutgoing(State.PLAY, 0x0A, 0x0B, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user