use of com.github.dirtpowered.dirtmv.data.translator.PacketTranslator in project DirtMultiversion by DirtPowered.
the class ProtocolRelease23To22 method registerTranslators.
@Override
public void registerTranslators() {
// login
addTranslator(0x01, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x01, new TypeHolder[] { // protocol version
set(Type.INT, 22), data.read(1), data.read(2), data.read(4), data.read(5), data.read(6), data.read(7), data.read(8) });
}
});
// login
addTranslator(0x01, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x01, new TypeHolder[] { data.read(0), data.read(1), data.read(2), // world type
set(Type.STRING, "default"), data.read(3), data.read(4), data.read(5), data.read(6), data.read(7) });
}
});
// respawn
addTranslator(0x09, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x09, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3), data.read(4) });
}
});
// respawn
addTranslator(0x09, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x09, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3), data.read(4), // world type
set(Type.STRING, "default") });
}
});
// custom payload
addTranslator(0xFA, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
// cancel packet
return cancel();
}
});
// chat
addTranslator(0x03, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
String filteredMessage = ChatFilter.filterChat(data.read(Type.STRING, 0));
return PacketUtil.createPacket(0x03, new TypeHolder[] { set(Type.STRING, filteredMessage) });
}
});
// creative item get
addTranslator(0x6B, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ItemStack item = data.read(Type.V1_0R_ITEM, 1);
boolean notNull = item != null;
if (notNull && !creativeTab.exists(item.getItemId())) {
// replace all unknown items to stone
item.setItemId(1);
item.setData(0);
}
return PacketUtil.createPacket(0x6B, new TypeHolder[] { data.read(0), set(Type.V1_0R_ITEM, item) });
}
});
}
use of com.github.dirtpowered.dirtmv.data.translator.PacketTranslator in project DirtMultiversion by DirtPowered.
the class ProtocolRelease28To23 method registerTranslators.
@Override
public void registerTranslators() {
// login
addTranslator(0x01, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x01, new TypeHolder[] { set(Type.INT, 23), data.read(1), set(Type.LONG, 0L), data.read(2), data.read(3), set(Type.BYTE, data.read(Type.INT, 4).byteValue()), data.read(5), data.read(6), data.read(7) });
}
});
// login
addTranslator(0x01, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
storage.set(DimensionTracker.class, new DimensionTracker());
// biome data only for < b1.7 for now
if (session.getMain().getConfiguration().getServerVersion().getRegistryId() < 17) {
OldChunkData biomeData = new OldChunkData();
biomeData.initialize(data.read(Type.LONG, 2));
storage.set(OldChunkData.class, biomeData);
}
int dimension = data.read(Type.BYTE, 5).intValue();
DimensionTracker dimensionTracker = storage.get(DimensionTracker.class);
dimensionTracker.setDimension(dimension);
return PacketUtil.createPacket(0x01, new TypeHolder[] { data.read(0), data.read(1), data.read(3), data.read(4), set(Type.INT, dimension), data.read(6), data.read(7), data.read(8) });
}
});
// pre chunk
addTranslator(0x32, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
LoadedChunkTracker chunkTracker = session.getUserData().getProtocolStorage().get(LoadedChunkTracker.class);
int chunkX = data.read(Type.INT, 0);
int chunkZ = data.read(Type.INT, 1);
byte mode = data.read(Type.BYTE, 2);
if (mode == 0) {
chunkTracker.removeChunk(chunkX, chunkZ);
}
return data;
}
});
// chunk
addTranslator(0x33, PacketDirection.TO_CLIENT, new BetaToV1_2ChunkTranslator(blockDataTransformer));
// multi block change
addTranslator(0x34, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
LoadedChunkTracker chunkTracker = session.getUserData().getProtocolStorage().get(LoadedChunkTracker.class);
V1_3BMultiBlockArray blockArray = (V1_3BMultiBlockArray) data.read(2).getObject();
int chunkX = data.read(Type.INT, 0);
int chunkZ = data.read(Type.INT, 1);
int totalDataSize = 4 * blockArray.getSize();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(totalDataSize);
DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
V1_2MultiBlockArray newFormat = null;
try {
for (int i = 0; i < blockArray.getSize(); ++i) {
short coordinate = blockArray.getCoordsArray()[i];
int blockId = blockArray.getTypesArray()[i] & 255;
int blockData = blockArray.getMetadataArray()[i];
Block replacement = blockDataTransformer.replaceBlock(blockId, blockData);
dataOutputStream.writeShort(coordinate);
dataOutputStream.writeShort((short) ((replacement.getBlockId() & 4095) << 4 | replacement.getBlockData() & 15));
}
byte[] b = byteArrayOutputStream.toByteArray();
newFormat = new V1_2MultiBlockArray(blockArray.getSize(), b.length, b);
dataOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
if (!chunkTracker.isChunkLoaded(chunkX, chunkZ)) {
return cancel();
}
return PacketUtil.createPacket(0x34, new TypeHolder[] { data.read(0), data.read(1), set(Type.V1_2MULTIBLOCK_ARRAY, newFormat) });
}
});
// block change
addTranslator(0x35, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
LoadedChunkTracker chunkTracker = session.getUserData().getProtocolStorage().get(LoadedChunkTracker.class);
int chunkX = data.read(Type.INT, 0) >> 4;
int chunkZ = data.read(Type.INT, 2) >> 4;
byte blockId = data.read(Type.BYTE, 3);
byte blockData = data.read(Type.BYTE, 4);
Block replacement = blockDataTransformer.replaceBlock(blockId, blockData);
if (!chunkTracker.isChunkLoaded(chunkX, chunkZ)) {
return cancel();
}
return PacketUtil.createPacket(0x35, new TypeHolder[] { data.read(0), data.read(1), data.read(2), set(Type.BYTE, (byte) replacement.getBlockId()), set(Type.BYTE, (byte) replacement.getBlockData()) });
}
});
// mob spawn
addTranslator(0x18, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x18, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3), data.read(4), data.read(5), data.read(6), // head yaw
set(Type.BYTE, (byte) 0), data.read(7) });
}
});
// respawn
addTranslator(0x09, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x09, new TypeHolder[] { set(Type.INT, (int) data.read(0).getObject()), data.read(1), data.read(2), data.read(3), // seed
set(Type.LONG, 0L), data.read(4) });
}
});
// respawn
addTranslator(0x09, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
int dimension = data.read(Type.BYTE, 0).intValue();
DimensionTracker dimensionTracker = storage.get(DimensionTracker.class);
dimensionTracker.setDimension(dimension);
return PacketUtil.createPacket(0x09, new TypeHolder[] { set(Type.INT, dimension), data.read(1), data.read(2), data.read(3), data.read(5) });
}
});
// entity relative move look
addTranslator(0x21, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
PacketData rotationPacket = PacketUtil.createPacket(0x23, new TypeHolder[] { // entityId
data.read(0), // yaw
data.read(4) });
session.sendPacket(rotationPacket, PacketDirection.TO_CLIENT, getFrom());
return data;
}
});
// entity look
addTranslator(0x20, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
PacketData rotationPacket = PacketUtil.createPacket(0x23, new TypeHolder[] { data.read(0), data.read(1) });
session.sendPacket(rotationPacket, PacketDirection.TO_CLIENT, getFrom());
return data;
}
});
// door change
addTranslator(0x3D, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
int effectId = data.read(Type.INT, 0);
int effectData = data.read(Type.INT, 4);
if (effectId == 2001) {
int blockId = effectData & 255;
int blockData = effectData >> 8 & 255;
effectData = blockId + (blockData << 12);
}
return PacketUtil.createPacket(0x3D, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3), set(Type.INT, effectData) });
}
});
// creative item get
addTranslator(0x6B, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ItemStack item = data.read(Type.V1_0R_ITEM, 1);
boolean notNull = item != null;
if (notNull && !creativeTab.exists(item.getItemId())) {
// replace all unknown items to stone
item.setItemId(1);
item.setData(0);
}
return PacketUtil.createPacket(0x6B, new TypeHolder[] { data.read(0), set(Type.V1_0R_ITEM, item) });
}
});
}
use of com.github.dirtpowered.dirtmv.data.translator.PacketTranslator in project DirtMultiversion by DirtPowered.
the class ServerSession method sendPacket.
/**
* Translates and sends packet to server
*
* @param packet {@link PacketData} Packet
* @param direction {@link PacketDirection} sending direction (client/server)
* @param from Version to start from
*/
public void sendPacket(PacketData packet, PacketDirection direction, MinecraftVersion from) {
MinecraftVersion version = main.getConfiguration().getServerVersion();
if (from != null && from != version) {
version = from;
}
List<ServerProtocol> protocols = main.getTranslatorRegistry().findProtocol(userData, version);
boolean flag = direction == PacketDirection.TO_CLIENT;
if (!flag) {
Collections.reverse(protocols);
}
PacketData target = packet;
for (ServerProtocol protocol : protocols) {
boolean isNetty = userData.getClientVersion().isNettyProtocol();
ProtocolState state = isNetty ? userData.getProtocolState() : ProtocolState.PRE_NETTY;
if (target == null) {
return;
}
// packet queue workaround
state = packet.getNettyState() != null ? packet.getNettyState() : state;
if (!protocol.getFrom().isNettyProtocol()) {
state = ProtocolState.PRE_NETTY;
}
PacketTranslator translator = protocol.getTranslatorFor(target.getOpCode(), state, direction);
if (translator != null) {
if (from == null || from != protocol.getFrom()) {
try {
target = translator.translate(this, target);
} catch (IOException e) {
disconnect(e.getMessage());
return;
}
if (target.getOpCode() == -1) {
return;
}
}
}
}
if (flag) {
sendPacket(target);
} else {
ClientSession clientSession = getClientSession();
if (target.getOpCode() == 2 && /* handshake */
!hasServerPingProtocol()) {
connectToServer();
}
if (clientSession != null && clientSession.getChannel().isActive()) {
clientSession.sendPacket(target);
return;
}
// queued packets are always login packets
target.setNettyState(ProtocolState.LOGIN);
initialPacketQueue.add(target);
}
}
use of com.github.dirtpowered.dirtmv.data.translator.PacketTranslator in project DirtMultiversion by DirtPowered.
the class ProtocolBeta13To11 method registerTranslators.
@Override
public void registerTranslators() {
// login
addTranslator(0x01, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x01, new TypeHolder[] { set(Type.INT, 11), data.read(1), data.read(2), data.read(3) });
}
});
// login
addTranslator(0x01, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x01, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3) });
}
});
// respawn
addTranslator(0x09, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x09, new TypeHolder[0]);
}
});
// respawn
addTranslator(0x09, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x09, new TypeHolder[] { set(Type.BYTE, (byte) 0) });
}
});
// vehicle spawn
addTranslator(0x17, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x17, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3), data.read(4), // to indicate that there's no more data to read
set(Type.MOTION, new Motion(0, (short) 0, (short) 0, (short) 0)) });
}
});
}
use of com.github.dirtpowered.dirtmv.data.translator.PacketTranslator in project DirtMultiversion by DirtPowered.
the class ProtocolRelease51To39 method registerTranslators.
@Override
public void registerTranslators() {
// login
addTranslator(0x01, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
if (!storage.hasObject(DimensionTracker.class)) {
storage.set(DimensionTracker.class, new DimensionTracker());
}
DimensionTracker dimensionTracker = session.getStorage().get(DimensionTracker.class);
dimensionTracker.setDimension(data.read(Type.BYTE, 3));
return data;
}
});
// respawn
addTranslator(0x09, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
DimensionTracker dimensionTracker = session.getStorage().get(DimensionTracker.class);
dimensionTracker.setDimension(data.read(Type.INT, 0));
return data;
}
});
// server ping request
addTranslator(0xFE, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
// empty
return PacketUtil.createPacket(0xFE, new TypeHolder[0]);
}
});
// kick disconnect
addTranslator(0xFF, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
String reason = data.read(Type.STRING, 0);
// TODO: fix issues with detecting protocol state on post-netty versions
if (reason.split("\u00a7").length != 3) {
return data;
}
Configuration configuration = session.getMain().getConfiguration();
// old to new format
return PacketUtil.createPacket(0xFF, new TypeHolder[] { set(Type.STRING, transformMotd(reason, configuration)) });
}
});
// handshake
addTranslator(0x02, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x02, new TypeHolder[] { set(Type.BYTE, (byte) 39), data.read(1), data.read(2), data.read(3) });
}
});
// client settings
addTranslator(0xCC, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0xCC, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3) });
}
});
// map data
addTranslator(0x83, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
byte[] mapData = data.read(Type.BYTE_BYTE_ARRAY, 2);
if (mapData[0] == 1) {
for (int i = 0; i < (mapData.length - 1) / 3; ++i) {
final byte icon = (byte) (mapData[i * 3 + 1] % 16);
final byte centerX = mapData[i * 3 + 2];
final byte centerZ = mapData[i * 3 + 3];
final byte iconRotation = (byte) (mapData[i * 3 + 1] / 16);
mapData[i * 3 + 1] = (byte) (icon << 4 | iconRotation & 15);
mapData[i * 3 + 2] = centerX;
mapData[i * 3 + 3] = centerZ;
}
}
return PacketUtil.createPacket(0x83, new TypeHolder[] { data.read(0), data.read(1), set(Type.UNSIGNED_SHORT_BYTE_ARRAY, mapData) });
}
});
// update time
addTranslator(0x04, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x04, new TypeHolder[] { data.read(0), data.read(0) });
}
});
// vehicle spawn
addTranslator(0x17, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x17, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3), data.read(4), // yaw
set(Type.BYTE, (byte) 0), // pitch
set(Type.BYTE, (byte) 0), data.read(5) });
}
});
// item spawn
addTranslator(0x15, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
PacketData vehicleSpawn = PacketUtil.createPacket(0x17, new TypeHolder[] { data.read(0), set(Type.BYTE, (byte) 2), data.read(4), data.read(5), data.read(6), data.read(7), data.read(8), set(Type.MOTION, new Motion(0, (short) 0, (short) 0, (short) 0)) });
short itemId = data.read(Type.SHORT, 1);
byte amount = data.read(Type.BYTE, 2);
short itemData = data.read(Type.SHORT, 3);
ItemStack itemStack = new ItemStack(itemId, amount, itemData, CompoundBinaryTag.empty());
List<WatchableObject> metadata = Collections.singletonList(new WatchableObject(MetadataType.ITEM, 10, itemStack));
PacketData itemMetadata = PacketUtil.createPacket(0x28, new TypeHolder[] { data.read(0), set(Type.V1_4R_METADATA, metadata.toArray(new WatchableObject[0])) });
session.sendPacket(vehicleSpawn, PacketDirection.TO_CLIENT, getFrom());
session.sendPacket(itemMetadata, PacketDirection.TO_CLIENT, getFrom());
return cancel();
}
});
// mob spawn
addTranslator(0x18, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
session.sendPacket(data, PacketDirection.TO_CLIENT, getFrom());
byte type = data.read(Type.BYTE, 1);
int itemId = 0;
if (type == 51)
// bow
itemId = 261;
if (type == 57)
// golden sword
itemId = 283;
if (itemId > 0) {
ItemStack itemStack = new ItemStack(itemId, 1, 0, null);
PacketData entityEquipment = PacketUtil.createPacket(0x05, new TypeHolder[] { data.read(0), set(Type.SHORT, (short) 0), set(Type.V1_3R_ITEM, itemStack) });
session.sendPacket(entityEquipment, PacketDirection.TO_CLIENT, getFrom());
}
return cancel();
}
});
// custom payload
addTranslator(0xFA, PacketDirection.TO_CLIENT, new PacketTranslator() {
@SneakyThrows
@Override
public PacketData translate(ServerSession session, PacketData data) {
String channel = data.read(Type.STRING, 0);
byte[] payload = data.read(Type.SHORT_BYTE_ARRAY, 1);
if (channel.equals("MC|TrList")) {
// TODO: Custom Payload reader
NettyInputWrapper buf = new NettyInputWrapper(Unpooled.wrappedBuffer(payload));
NettyOutputWrapper fixedPayload = new NettyOutputWrapper(Unpooled.buffer());
fixedPayload.writeInt(buf.readInt());
short size = buf.readUnsignedByte();
fixedPayload.writeByte(size);
for (int i = 0; i < size; i++) {
V1_3_1RProtocol.ITEM.write(set(Type.V1_3R_ITEM, V1_3_1RProtocol.ITEM.read(buf)), fixedPayload);
V1_3_1RProtocol.ITEM.write(set(Type.V1_3R_ITEM, V1_3_1RProtocol.ITEM.read(buf)), fixedPayload);
boolean b = buf.readBoolean();
fixedPayload.writeBoolean(b);
if (b) {
V1_3_1RProtocol.ITEM.write(set(Type.V1_3R_ITEM, V1_3_1RProtocol.ITEM.read(buf)), fixedPayload);
}
fixedPayload.writeBoolean(false);
}
return PacketUtil.createPacket(0xFA, new TypeHolder[] { data.read(0), set(Type.SHORT_BYTE_ARRAY, fixedPayload.array()) });
}
return data;
}
});
// level sound
addTranslator(0x3E, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
String soundName = data.read(Type.STRING, 0);
String newSoundName = soundRemapper.getNewSoundName(soundName);
if (newSoundName.isEmpty())
return cancel();
return PacketUtil.createPacket(0x3E, new TypeHolder[] { set(Type.STRING, newSoundName), data.read(1), data.read(2), data.read(3), data.read(4), data.read(5) });
}
});
// door change
addTranslator(0x3D, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x3D, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3), data.read(4), set(Type.BOOLEAN, false) });
}
});
// chunk bulk
addTranslator(0x38, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
V1_3_4ChunkBulk oldChunk = data.read(Type.V1_3CHUNK_BULK, 0);
DimensionTracker tracker = session.getStorage().get(DimensionTracker.class);
oldChunk.setSkylight(tracker.getDimension() == 0);
return PacketUtil.createPacket(0x38, new TypeHolder[] { set(Type.V1_4CHUNK_BULK, oldChunk) });
}
});
// block place
addTranslator(0x0F, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ItemStack item = data.read(Type.V1_3R_ITEM, 4);
if (item == null)
return data;
int itemId = item.getItemId();
if (itemId >= 298 && itemId <= 317) {
return PacketUtil.createPacket(0x66, new TypeHolder[] { set(Type.BYTE, (byte) 0), set(Type.SHORT, (short) 0), set(Type.BYTE, (byte) 0), set(Type.SHORT, (short) 0), set(Type.BYTE, (byte) 0), // fake item
set(Type.V1_3R_ITEM, new ItemStack(256, 0, 0, null)) });
}
return data;
}
});
// creative item get
addTranslator(0x6B, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ItemStack item = data.read(Type.V1_3R_ITEM, 1);
boolean notNull = item != null;
if (notNull && !creativeTab.exists(item.getItemId())) {
// replace all unknown items to stone
item.setItemId(1);
item.setData(0);
}
return PacketUtil.createPacket(0x6B, new TypeHolder[] { data.read(0), set(Type.V1_3R_ITEM, item) });
}
});
// spawn painting
addTranslator(0x19, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
int direction = data.read(Type.INT, 5);
int correctedDirection = 0;
switch(direction) {
case 0:
correctedDirection = 2;
break;
case 1:
correctedDirection = 1;
break;
case 2:
break;
case 3:
correctedDirection = 3;
break;
}
return PacketUtil.createPacket(0x19, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3), data.read(4), set(Type.INT, correctedDirection) });
}
});
// player look move
addTranslator(0x0D, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
if (!storage.hasObject(BlockStorage.class)) {
return data;
}
double x = data.read(Type.DOUBLE, 0);
double y = data.read(Type.DOUBLE, 1);
double originalStance = data.read(Type.DOUBLE, 2);
double z = data.read(Type.DOUBLE, 3);
MovementTranslator.updateBoundingBox(session, new Location(x, y, z));
Location loc = MovementTranslator.correctPosition(session, x, y, z);
return PacketUtil.createPacket(0x0D, new TypeHolder[] { set(Type.DOUBLE, loc.getX()), set(Type.DOUBLE, loc.getY()), // stance
set(Type.DOUBLE, loc.getY() + (originalStance - y)), set(Type.DOUBLE, loc.getZ()), data.read(4), data.read(5), data.read(6) });
}
});
// player position
addTranslator(0x0B, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
if (!storage.hasObject(BlockStorage.class)) {
return data;
}
double x = data.read(Type.DOUBLE, 0);
double y = data.read(Type.DOUBLE, 1);
double z = data.read(Type.DOUBLE, 3);
MovementTranslator.updateBoundingBox(session, new Location(x, y, z));
Location loc = MovementTranslator.correctPosition(session, x, y, z);
return PacketUtil.createPacket(0x0B, new TypeHolder[] { set(Type.DOUBLE, loc.getX()), set(Type.DOUBLE, loc.getY()), set(Type.DOUBLE, loc.getY() + 1.6200000047683716D), set(Type.DOUBLE, loc.getZ()), data.read(4) });
}
});
}
Aggregations