use of com.viaversion.viaversion.api.protocol.Protocol in project ViaVersion by ViaVersion.
the class VersionedPacketTransformerImpl method transformPacket.
private void transformPacket(PacketWrapper packet) throws Exception {
// If clientbound: Constructor given inputProtocolVersion → Client version
// If serverbound: Constructor given inputProtocolVersion → Server version
PacketType packetType = packet.getPacketType();
UserConnection connection = packet.user();
boolean clientbound = packetType.direction() == Direction.CLIENTBOUND;
int serverProtocolVersion = clientbound ? this.inputProtocolVersion : connection.getProtocolInfo().getServerProtocolVersion();
int clientProtocolVersion = clientbound ? connection.getProtocolInfo().getProtocolVersion() : this.inputProtocolVersion;
// Construct protocol pipeline
List<ProtocolPathEntry> path = Via.getManager().getProtocolManager().getProtocolPath(clientProtocolVersion, serverProtocolVersion);
List<Protocol> protocolList = null;
if (path != null) {
protocolList = new ArrayList<>(path.size());
for (ProtocolPathEntry entry : path) {
protocolList.add(entry.protocol());
}
} else if (serverProtocolVersion != clientProtocolVersion) {
throw new RuntimeException("No protocol path between client version " + clientProtocolVersion + " and server version " + serverProtocolVersion);
}
if (protocolList != null) {
// Reset reader and apply pipeline
packet.resetReader();
try {
packet.apply(packetType.direction(), State.PLAY, 0, protocolList, clientbound);
} catch (Exception e) {
throw new Exception("Exception trying to transform packet between client version " + clientProtocolVersion + " and server version " + serverProtocolVersion + ". Are you sure you used the correct input version and packet write types?", e);
}
}
}
use of com.viaversion.viaversion.api.protocol.Protocol in project ViaVersion by ViaVersion.
the class WorldPackets method register.
public static void register(Protocol protocol) {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION);
protocol.registerClientbound(ClientboundPackets1_13.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk chunk = wrapper.passthrough(new Chunk1_13Type(clientWorld));
for (ChunkSection section : chunk.getSections()) {
if (section == null)
continue;
for (int i = 0; i < section.getPaletteSize(); i++) {
section.setPaletteEntry(i, protocol.getMappingData().getNewBlockStateId(section.getPaletteEntry(i)));
}
}
}
});
}
});
blockRewriter.registerBlockAction(ClientboundPackets1_13.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_13.BLOCK_CHANGE);
blockRewriter.registerMultiBlockChange(ClientboundPackets1_13.MULTI_BLOCK_CHANGE);
protocol.registerClientbound(ClientboundPackets1_13.EFFECT, new PacketRemapper() {
@Override
public void registerMap() {
// Effect Id
map(Type.INT);
// Location
map(Type.POSITION);
// Data
map(Type.INT);
handler(wrapper -> {
int id = wrapper.get(Type.INT, 0);
if (id == 2000) {
// Smoke
int data = wrapper.get(Type.INT, 1);
switch(data) {
case // North
1:
// North
wrapper.set(Type.INT, 1, 2);
break;
// North-West
case 0:
// West
case 3:
case // South-West
6:
// West
wrapper.set(Type.INT, 1, 4);
break;
// North-East
case 2:
// East
case 5:
case // South-East
8:
// East
wrapper.set(Type.INT, 1, 5);
break;
case // South
7:
// South
wrapper.set(Type.INT, 1, 3);
break;
default:
// Self and other directions
// Down
wrapper.set(Type.INT, 1, 0);
break;
}
} else if (id == 1010) {
// Play record
wrapper.set(Type.INT, 1, protocol.getMappingData().getNewItemId(wrapper.get(Type.INT, 1)));
} else if (id == 2001) {
// Block break + block break sound
wrapper.set(Type.INT, 1, protocol.getMappingData().getNewBlockStateId(wrapper.get(Type.INT, 1)));
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_13.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.INT);
// 1 - Gamemode
map(Type.UNSIGNED_BYTE);
// 2 - Dimension
map(Type.INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// Store the player
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 1);
clientChunks.setEnvironment(dimensionId);
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_13.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Dimension ID
map(Type.INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 0);
clientWorld.setEnvironment(dimensionId);
}
});
}
});
}
use of com.viaversion.viaversion.api.protocol.Protocol in project ViaVersion by ViaVersion.
the class WorldPackets method register.
public static void register(Protocol protocol) {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
blockRewriter.registerBlockAction(ClientboundPackets1_16.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_16.BLOCK_CHANGE);
blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16.ACKNOWLEDGE_PLAYER_DIGGING);
protocol.registerClientbound(ClientboundPackets1_16.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
Chunk chunk = wrapper.read(new Chunk1_16Type());
wrapper.write(new Chunk1_16_2Type(), chunk);
for (int s = 0; s < chunk.getSections().length; s++) {
ChunkSection section = chunk.getSections()[s];
if (section == null)
continue;
for (int i = 0; i < section.getPaletteSize(); i++) {
int old = section.getPaletteEntry(i);
section.setPaletteEntry(i, protocol.getMappingData().getNewBlockStateId(old));
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_16.MULTI_BLOCK_CHANGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.cancel();
int chunkX = wrapper.read(Type.INT);
int chunkZ = wrapper.read(Type.INT);
long chunkPosition = 0;
chunkPosition |= (chunkX & 0x3FFFFFL) << 42;
chunkPosition |= (chunkZ & 0x3FFFFFL) << 20;
List<BlockChangeRecord>[] sectionRecords = new List[16];
BlockChangeRecord[] blockChangeRecord = wrapper.read(Type.BLOCK_CHANGE_RECORD_ARRAY);
for (BlockChangeRecord record : blockChangeRecord) {
int chunkY = record.getY() >> 4;
List<BlockChangeRecord> list = sectionRecords[chunkY];
if (list == null) {
sectionRecords[chunkY] = (list = new ArrayList<>());
}
// Absolute y -> relative chunk section y
int blockId = protocol.getMappingData().getNewBlockStateId(record.getBlockId());
list.add(new BlockChangeRecord1_16_2(record.getSectionX(), record.getSectionY(), record.getSectionZ(), blockId));
}
// Now send separate packets for the different chunk sections
for (int chunkY = 0; chunkY < sectionRecords.length; chunkY++) {
List<BlockChangeRecord> sectionRecord = sectionRecords[chunkY];
if (sectionRecord == null)
continue;
PacketWrapper newPacket = wrapper.create(ClientboundPackets1_16_2.MULTI_BLOCK_CHANGE);
newPacket.write(Type.LONG, chunkPosition | (chunkY & 0xFFFFFL));
// Ignore light updates
newPacket.write(Type.BOOLEAN, false);
newPacket.write(Type.VAR_LONG_BLOCK_CHANGE_RECORD_ARRAY, sectionRecord.toArray(EMPTY_RECORDS));
newPacket.send(Protocol1_16_2To1_16_1.class);
}
});
}
});
blockRewriter.registerEffect(ClientboundPackets1_16.EFFECT, 1010, 2001);
}
use of com.viaversion.viaversion.api.protocol.Protocol in project ViaVersion by ViaVersion.
the class PlayerPackets method register.
public static void register(Protocol protocol) {
protocol.registerClientbound(ClientboundPackets1_14.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT);
// Level Seed
handler(wrapper -> wrapper.write(Type.LONG, 0L));
}
});
protocol.registerClientbound(ClientboundPackets1_14.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.INT);
// 1 - Gamemode
map(Type.UNSIGNED_BYTE);
// 2 - Dimension
map(Type.INT);
handler(wrapper -> {
// Register Type ID
EntityTracker tracker = wrapper.user().getEntityTracker(Protocol1_15To1_14_4.class);
int entityId = wrapper.get(Type.INT, 0);
tracker.addEntity(entityId, Entity1_15Types.PLAYER);
});
// Level Seed
handler(wrapper -> wrapper.write(Type.LONG, 0L));
// 3 - Max Players
map(Type.UNSIGNED_BYTE);
// 4 - Level Type
map(Type.STRING);
// 5 - View Distance
map(Type.VAR_INT);
// 6 - Reduce Debug Info
map(Type.BOOLEAN);
// Show Death Screen
handler(wrapper -> wrapper.write(Type.BOOLEAN, !Via.getConfig().is1_15InstantRespawn()));
}
});
}
use of com.viaversion.viaversion.api.protocol.Protocol in project ViaVersion by ViaVersion.
the class WorldPackets method register.
public static void register(Protocol protocol) {
protocol.registerClientbound(ClientboundPackets1_8.UPDATE_SIGN, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Sign Position
map(Type.POSITION);
// 1 - Sign Line (json)
map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
// 2 - Sign Line (json)
map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
// 3 - Sign Line (json)
map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
// 4 - Sign Line (json)
map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
}
});
protocol.registerClientbound(ClientboundPackets1_8.EFFECT, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Effect ID
map(Type.INT);
// 1 - Position
map(Type.POSITION);
// 2 - Data
map(Type.INT);
// 3 - Disable relative volume
map(Type.BOOLEAN);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.INT, 0);
id = Effect.getNewId(id);
wrapper.set(Type.INT, 0, id);
}
});
// Rewrite potion effect as it changed to use a dynamic registry
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.INT, 0);
if (id == 2002) {
int data = wrapper.get(Type.INT, 1);
int newData = ItemRewriter.getNewEffectID(data);
wrapper.set(Type.INT, 1, newData);
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_8.NAMED_SOUND, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Sound Name
map(Type.STRING);
// 1 - Sound Category ID
// Everything else get's written through
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
String name = wrapper.get(Type.STRING, 0);
SoundEffect effect = SoundEffect.getByName(name);
int catid = 0;
String newname = name;
if (effect != null) {
catid = effect.getCategory().getId();
newname = effect.getNewName();
}
wrapper.set(Type.STRING, 0, newname);
// Write Category ID
wrapper.write(Type.VAR_INT, catid);
if (effect != null && effect.isBreaksound()) {
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
// Position X
int x = wrapper.passthrough(Type.INT);
// Position Y
int y = wrapper.passthrough(Type.INT);
// Position Z
int z = wrapper.passthrough(Type.INT);
if (tracker.interactedBlockRecently((int) Math.floor(x / 8.0), (int) Math.floor(y / 8.0), (int) Math.floor(z / 8.0))) {
wrapper.cancel();
}
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_8.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
ClientChunks clientChunks = wrapper.user().get(ClientChunks.class);
Chunk chunk = wrapper.read(new Chunk1_8Type(clientWorld));
long chunkHash = ClientChunks.toLong(chunk.getX(), chunk.getZ());
// Check if the chunk should be handled as an unload packet
if (chunk.isFullChunk() && chunk.getBitmask() == 0) {
wrapper.setPacketType(ClientboundPackets1_9.UNLOAD_CHUNK);
wrapper.write(Type.INT, chunk.getX());
wrapper.write(Type.INT, chunk.getZ());
// Remove commandBlocks on chunk unload
CommandBlockProvider provider = Via.getManager().getProviders().get(CommandBlockProvider.class);
provider.unloadChunk(wrapper.user(), chunk.getX(), chunk.getZ());
clientChunks.getLoadedChunks().remove(chunkHash);
// Unload the empty chunks
if (Via.getConfig().isChunkBorderFix()) {
for (BlockFace face : BlockFace.HORIZONTAL) {
int chunkX = chunk.getX() + face.modX();
int chunkZ = chunk.getZ() + face.modZ();
if (!clientChunks.getLoadedChunks().contains(ClientChunks.toLong(chunkX, chunkZ))) {
PacketWrapper unloadChunk = wrapper.create(ClientboundPackets1_9.UNLOAD_CHUNK);
unloadChunk.write(Type.INT, chunkX);
unloadChunk.write(Type.INT, chunkZ);
unloadChunk.send(Protocol1_9To1_8.class);
}
}
}
} else {
Type<Chunk> chunkType = new Chunk1_9_1_2Type(clientWorld);
wrapper.write(chunkType, chunk);
clientChunks.getLoadedChunks().add(chunkHash);
// Send empty chunks surrounding the loaded chunk to force 1.9+ clients to render the new chunk
if (Via.getConfig().isChunkBorderFix()) {
for (BlockFace face : BlockFace.HORIZONTAL) {
int chunkX = chunk.getX() + face.modX();
int chunkZ = chunk.getZ() + face.modZ();
if (!clientChunks.getLoadedChunks().contains(ClientChunks.toLong(chunkX, chunkZ))) {
PacketWrapper emptyChunk = wrapper.create(ClientboundPackets1_9.CHUNK_DATA);
Chunk c = new BaseChunk(chunkX, chunkZ, true, false, 0, new ChunkSection[16], new int[256], new ArrayList<>());
emptyChunk.write(chunkType, c);
emptyChunk.send(Protocol1_9To1_8.class);
}
}
}
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_8.MAP_BULK_CHUNK, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// Cancel the packet from being sent
wrapper.cancel();
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
ClientChunks clientChunks = wrapper.user().get(ClientChunks.class);
Chunk[] chunks = wrapper.read(new ChunkBulk1_8Type(clientWorld));
Type<Chunk> chunkType = new Chunk1_9_1_2Type(clientWorld);
// Split into multiple chunk packets
for (Chunk chunk : chunks) {
PacketWrapper chunkData = wrapper.create(ClientboundPackets1_9.CHUNK_DATA);
chunkData.write(chunkType, chunk);
chunkData.send(Protocol1_9To1_8.class);
clientChunks.getLoadedChunks().add(ClientChunks.toLong(chunk.getX(), chunk.getZ()));
// Send empty chunks surrounding the loaded chunk to force 1.9+ clients to render the new chunk
if (Via.getConfig().isChunkBorderFix()) {
for (BlockFace face : BlockFace.HORIZONTAL) {
int chunkX = chunk.getX() + face.modX();
int chunkZ = chunk.getZ() + face.modZ();
if (!clientChunks.getLoadedChunks().contains(ClientChunks.toLong(chunkX, chunkZ))) {
PacketWrapper emptyChunk = wrapper.create(ClientboundPackets1_9.CHUNK_DATA);
Chunk c = new BaseChunk(chunkX, chunkZ, true, false, 0, new ChunkSection[16], new int[256], new ArrayList<>());
emptyChunk.write(chunkType, c);
emptyChunk.send(Protocol1_9To1_8.class);
}
}
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_8.BLOCK_ENTITY_DATA, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Block Position
map(Type.POSITION);
// 1 - Action
map(Type.UNSIGNED_BYTE);
// 2 - NBT (Might not be present)
map(Type.NBT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int action = wrapper.get(Type.UNSIGNED_BYTE, 0);
if (action == 1) {
// Update Spawner
CompoundTag tag = wrapper.get(Type.NBT, 0);
if (tag != null) {
if (tag.contains("EntityId")) {
String entity = (String) tag.get("EntityId").getValue();
CompoundTag spawn = new CompoundTag();
spawn.put("id", new StringTag(entity));
tag.put("SpawnData", spawn);
} else {
// EntityID does not exist
CompoundTag spawn = new CompoundTag();
// Make spawners show up as empty when no EntityId is given.
spawn.put("id", new StringTag("AreaEffectCloud"));
tag.put("SpawnData", spawn);
}
}
}
if (action == 2) {
// Update Command Block
CommandBlockProvider provider = Via.getManager().getProviders().get(CommandBlockProvider.class);
provider.addOrUpdateBlock(wrapper.user(), wrapper.get(Type.POSITION, 0), wrapper.get(Type.NBT, 0));
// To prevent window issues don't send updates
wrapper.cancel();
}
}
});
}
});
/* Incoming Packets */
protocol.registerServerbound(ServerboundPackets1_9.UPDATE_SIGN, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Sign Position
map(Type.POSITION);
// 1 - Sign Line (json)
map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
// 2 - Sign Line (json)
map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
// 3 - Sign Line (json)
map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
// 4 - Sign Line (json)
map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
}
});
protocol.registerServerbound(ServerboundPackets1_9.PLAYER_DIGGING, new PacketRemapper() {
@Override
public void registerMap() {
// Action
map(Type.VAR_INT);
// Position
map(Type.POSITION);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int status = wrapper.get(Type.VAR_INT, 0);
if (status == 6)
wrapper.cancel();
}
});
// Blocking
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int status = wrapper.get(Type.VAR_INT, 0);
if (status == 5 || status == 4 || status == 3) {
EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
if (entityTracker.isBlocking()) {
entityTracker.setBlocking(false);
if (!Via.getConfig().isShowShieldWhenSwordInHand()) {
entityTracker.setSecondHand(null);
}
}
}
}
});
}
});
protocol.registerServerbound(ServerboundPackets1_9.USE_ITEM, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int hand = wrapper.read(Type.VAR_INT);
// Wipe the input buffer
wrapper.clearInputBuffer();
// First set this packet ID to Block placement
wrapper.setId(0x08);
wrapper.write(Type.POSITION, new Position(-1, (short) -1, -1));
wrapper.write(Type.UNSIGNED_BYTE, (short) 255);
// Write item in hand
Item item = Protocol1_9To1_8.getHandItem(wrapper.user());
// Blocking patch
if (Via.getConfig().isShieldBlocking()) {
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
// Check if the shield is already there or if we have to give it here
boolean showShieldWhenSwordInHand = Via.getConfig().isShowShieldWhenSwordInHand();
// Method to identify the sword in hand
boolean isSword = showShieldWhenSwordInHand ? tracker.hasSwordInHand() : item != null && Protocol1_9To1_8.isSword(item.identifier());
if (isSword) {
if (hand == 0) {
if (!tracker.isBlocking()) {
tracker.setBlocking(true);
// Check if the shield is already in the offhand
if (!showShieldWhenSwordInHand && tracker.getItemInSecondHand() == null) {
// Set shield in offhand when interacting with main hand
Item shield = new DataItem(442, (byte) 1, (short) 0, null);
tracker.setSecondHand(shield);
}
}
}
// Use the main hand to trigger the blocking
boolean blockUsingMainHand = Via.getConfig().isNoDelayShieldBlocking() && !showShieldWhenSwordInHand;
if (blockUsingMainHand && hand == 1 || !blockUsingMainHand && hand == 0) {
wrapper.cancel();
}
} else {
if (!showShieldWhenSwordInHand) {
// Remove the shield from the offhand
tracker.setSecondHand(null);
}
tracker.setBlocking(false);
}
}
wrapper.write(Type.ITEM, item);
wrapper.write(Type.UNSIGNED_BYTE, (short) 0);
wrapper.write(Type.UNSIGNED_BYTE, (short) 0);
wrapper.write(Type.UNSIGNED_BYTE, (short) 0);
}
});
}
});
protocol.registerServerbound(ServerboundPackets1_9.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Position
map(Type.POSITION);
// 1 - Block Face
map(Type.VAR_INT, Type.UNSIGNED_BYTE);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// 2 - Hand
final int hand = wrapper.read(Type.VAR_INT);
if (hand != 0)
wrapper.cancel();
}
});
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Item item = Protocol1_9To1_8.getHandItem(wrapper.user());
// 3 - Item
wrapper.write(Type.ITEM, item);
}
});
// 4 - X
map(Type.UNSIGNED_BYTE);
// 5 - Y
map(Type.UNSIGNED_BYTE);
// 6 - Z
map(Type.UNSIGNED_BYTE);
// Register block place to fix sounds
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int face = wrapper.get(Type.UNSIGNED_BYTE, 0);
if (face == 255)
return;
Position p = wrapper.get(Type.POSITION, 0);
int x = p.x();
int y = p.y();
int z = p.z();
switch(face) {
case 0:
y--;
break;
case 1:
y++;
break;
case 2:
z--;
break;
case 3:
z++;
break;
case 4:
x--;
break;
case 5:
x++;
break;
}
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.addBlockInteraction(new Position(x, y, z));
}
});
// Handle CommandBlocks
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
CommandBlockProvider provider = Via.getManager().getProviders().get(CommandBlockProvider.class);
Position pos = wrapper.get(Type.POSITION, 0);
Optional<CompoundTag> tag = provider.get(wrapper.user(), pos);
// Send the Update Block Entity packet if present
if (tag.isPresent()) {
PacketWrapper updateBlockEntity = PacketWrapper.create(ClientboundPackets1_9.BLOCK_ENTITY_DATA, null, wrapper.user());
updateBlockEntity.write(Type.POSITION, pos);
updateBlockEntity.write(Type.UNSIGNED_BYTE, (short) 2);
updateBlockEntity.write(Type.NBT, tag.get());
updateBlockEntity.scheduleSend(Protocol1_9To1_8.class);
}
}
});
}
});
}
Aggregations