use of com.github.dirtpowered.dirtmv.data.translator.PacketTranslator in project DirtMultiversion by DirtPowered.
the class WorldPackets method registerTranslators.
@Override
public void registerTranslators() {
// block change
addTranslator(0x35, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
BlockStorage blockStorage = session.getStorage().get(BlockStorage.class);
if (blockStorage.getVersion() == getTo()) {
int x = data.read(Type.INT, 0);
byte y = data.read(Type.BYTE, 1);
int z = data.read(Type.INT, 2);
int chunkX = x >> 4;
int chunkZ = z >> 4;
short blockId = data.read(Type.SHORT, 3);
if (shouldCache(blockId)) {
blockStorage.setBlockAt(chunkX, chunkZ, x, y, z, blockId);
}
}
return data;
}
});
addTranslator(0x34, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
BlockStorage blockStorage = session.getStorage().get(BlockStorage.class);
if (blockStorage.getVersion() == getTo()) {
int chunkX = data.read(Type.INT, 0);
int chunkZ = data.read(Type.INT, 1);
V1_2MultiBlockArray blocks = data.read(Type.V1_2MULTIBLOCK_ARRAY, 2);
DataInput dis = new DataInputStream(new ByteArrayInputStream(blocks.getData()));
for (int i = 0; i < blocks.getRecordCount(); i++) {
try {
short pos = dis.readShort();
int x = pos >> 12 & 15;
int y = pos & 255;
int z = pos >> 8 & 15;
int xPos = x + (chunkX << 4);
int zPos = z + (chunkZ << 4);
int blockId = dis.readShort() >> 4 & 4095;
if (shouldCache(blockId)) {
blockStorage.setBlockAt(chunkX, chunkZ, xPos, y, zPos, blockId);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
return data;
}
});
// chunk data
addTranslator(0x33, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
BlockStorage blockStorage = session.getStorage().get(BlockStorage.class);
V1_2Chunk chunk = data.read(Type.V1_2_CHUNK, 0);
if (blockStorage.getVersion() == getTo()) {
List<ExtendedBlockStorage> parts = new ArrayList<>();
boolean skyLight = true;
if (session.getStorage().hasObject(DimensionTracker.class)) {
DimensionTracker tracker = session.getStorage().get(DimensionTracker.class);
skyLight = tracker.getDimension() == 0;
}
// create chunk storage
V1_2RChunkStorage storage = new V1_2RChunkStorage(skyLight, true, chunk.getChunkX(), chunk.getChunkZ());
storage.readChunk(chunk.isGroundUp(), chunk.getPrimaryBitmap(), chunk.getUncompressedData());
// cache for later use (r1.8 -> r1.7)
chunk.setStorage(storage);
ExtendedBlockStorage[] columns = storage.getColumnStorage();
for (int i = 0; i < columns.length; ++i) {
ExtendedBlockStorage e = columns[i];
boolean f = e != null && !columns[i].isEmpty();
if (e != null && (chunk.getPrimaryBitmap() & 1 << i) != 0 && (!chunk.isGroundUp() || f)) {
parts.add(e);
}
}
for (int i = 0; i < parts.size(); ++i) {
byte[] blockArray = parts.get(i).getBlockLSBArray();
for (int j = 0; j < blockArray.length; ++j) {
int x = j & 15;
int y = (j >> 8) + i * 16 & 127;
int z = j >> 4 & 15;
int blockId = blockArray[j] & 255;
if (shouldCache(blockId)) {
blockStorage.setBlockAt(chunk.getChunkX(), chunk.getChunkZ(), x, y, z, blockId);
}
}
}
}
return data;
}
});
}
use of com.github.dirtpowered.dirtmv.data.translator.PacketTranslator in project DirtMultiversion by DirtPowered.
the class EntityPackets method registerTranslators.
@Override
public void registerTranslators() {
// spawn mob
addTranslator(0x0F, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
EntityType entityType = EntityType.fromEntityTypeId(data.read(Type.BYTE, 1));
if (storage.hasObject(V1_7EntityTracker.class)) {
V1_7EntityTracker tracker = storage.get(V1_7EntityTracker.class);
int entityId = data.read(Type.VAR_INT, 0);
tracker.addEntity(entityId, entityType);
}
WatchableObject[] oldMeta = data.read(Type.V1_7R_METADATA, 11);
WatchableObject[] newMeta = metadataTransformer.transformMetadata(entityType, oldMeta);
return PacketUtil.createPacket(0x0F, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3), data.read(4), data.read(5), data.read(6), data.read(7), data.read(8), data.read(9), data.read(10), set(Type.V1_8R_METADATA, newMeta) });
}
});
// entity metadata
addTranslator(0x1C, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
SpawnableObject entityObject = null;
int entityId = data.read(Type.INT, 0);
if (storage.hasObject(EntityTracker.class)) {
EntityTracker tracker = storage.get(EntityTracker.class);
entityObject = tracker.getEntityById(entityId);
} else if (storage.hasObject(V1_7EntityTracker.class)) {
V1_7EntityTracker tracker = storage.get(V1_7EntityTracker.class);
entityObject = tracker.getEntityById(entityId);
}
if (entityObject == null)
return cancel();
WatchableObject[] oldMeta = data.read(Type.V1_7R_METADATA, 1);
WatchableObject[] watchableObjects = metadataTransformer.transformMetadata(entityObject, oldMeta);
for (int i = 0; i < watchableObjects.length; i++) {
WatchableObject watchableObject = watchableObjects[i];
if (watchableObject.getType() == MetadataType.ITEM) {
ItemStack obj = (ItemStack) watchableObject.getValue();
if (obj != null) {
obj = InventoryPackets.itemRemapper.replaceItem(obj);
}
watchableObjects[i] = new WatchableObject(MetadataType.ITEM, watchableObject.getIndex(), obj);
}
}
return PacketUtil.createPacket(0x1C, new TypeHolder[] { set(Type.VAR_INT, data.read(Type.INT, 0)), set(Type.V1_8R_METADATA, watchableObjects) });
}
});
// entity velocity
addTranslator(0x12, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x12, new TypeHolder[] { set(Type.VAR_INT, data.read(Type.INT, 0)), data.read(1), data.read(2), data.read(3) });
}
});
// entity destroy
addTranslator(0x13, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
int[] entities = data.read(Type.BYTE_INT_ARRAY, 0);
if (storage.hasObject(V1_7EntityTracker.class)) {
for (int entityId : entities) {
V1_7EntityTracker tracker = storage.get(V1_7EntityTracker.class);
tracker.removeEntity(entityId);
}
}
return PacketUtil.createPacket(0x13, new TypeHolder[] { set(Type.VAR_INT_ARRAY, entities) });
}
});
// spawn player
addTranslator(0x0C, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@SneakyThrows
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
UUID uniqueId = UUID.fromString(data.read(Type.V1_7_STRING, 1));
String username = data.read(Type.V1_7_STRING, 2);
GameProfile profile = GameProfileFetcher.getProfile(username).get();
if (storage.hasObject(V1_7EntityTracker.class)) {
V1_7EntityTracker tracker = storage.get(V1_7EntityTracker.class);
int entityId = data.read(Type.VAR_INT, 0);
tracker.addEntity(entityId, EntityType.HUMAN);
}
WatchableObject[] oldMeta = data.read(Type.V1_7R_METADATA, 10);
WatchableObject[] newMeta = metadataTransformer.transformMetadata(EntityType.HUMAN, oldMeta);
// skin layers
WatchableObject[] layers = new WatchableObject[newMeta.length + 1];
System.arraycopy(newMeta, 0, layers, 0, newMeta.length);
layers[newMeta.length] = new WatchableObject(MetadataType.BYTE, 10, (byte) 127);
newMeta = layers;
PacketData playerSpawn = PacketUtil.createPacket(0x0C, new TypeHolder[] { data.read(0), set(Type.UUID, profile.getId()), data.read(4), data.read(5), data.read(6), data.read(7), data.read(8), data.read(9), set(Type.V1_8R_METADATA, newMeta) });
// create fake profile
// GameProfile profile = new GameProfile(uniqueId, username);
TabListEntry tabAddListEntry = new TabListEntry(TabListAction.ADD_PLAYER, new PlayerListEntry[] { new PlayerListEntry(profile, new Property[0], 0, 0, null) });
PacketData tabEntry = PacketUtil.createPacket(0x38, new TypeHolder[] { set(Type.TAB_LIST_ENTRY, tabAddListEntry) });
// seems that client overwrites old tab packet after sending a new one
session.sendPacket(tabEntry, PacketDirection.TO_CLIENT, getFrom());
// send player spawn (right after tablist packet)
session.sendPacket(playerSpawn, PacketDirection.TO_CLIENT, getFrom());
new Timer().schedule(new TimerTask() {
@Override
public void run() {
TabListEntry tabRemoveListEntry = new TabListEntry(TabListAction.REMOVE_PLAYER, new PlayerListEntry[] { new PlayerListEntry(profile, new Property[0], 0, 0, null) });
PacketData removeTab = PacketUtil.createPacket(0x38, new TypeHolder[] { set(Type.TAB_LIST_ENTRY, tabRemoveListEntry) });
session.sendPacket(removeTab, PacketDirection.TO_CLIENT, getFrom());
}
}, 40L);
return cancel();
}
});
// entity equipment
addTranslator(0x04, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ItemStack originalItem = data.read(Type.V1_3R_ITEM, 2);
if (originalItem != null) {
originalItem = InventoryPackets.itemRemapper.replaceItem(originalItem);
}
return PacketUtil.createPacket(0x04, new TypeHolder[] { set(Type.VAR_INT, data.read(Type.INT, 0)), data.read(1), set(Type.V1_8R_ITEM, originalItem) });
}
});
// update tile entity
addTranslator(0x35, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
int x = data.read(Type.INT, 0);
short y = data.read(Type.SHORT, 1);
int z = data.read(Type.INT, 2);
return PacketUtil.createPacket(0x35, new TypeHolder[] { set(Type.LONG, ProtocolRelease47To5.toBlockPosition(x, y, z)), data.read(3), set(Type.COMPRESSED_COMPOUND_TAG, data.read(Type.COMPOUND_TAG, 4)) });
}
});
// spawn painting
addTranslator(0x10, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
int x = data.read(Type.INT, 2);
int y = data.read(Type.INT, 3);
int z = data.read(Type.INT, 4);
int direction = data.read(Type.INT, 5);
switch(direction) {
case 0:
z += 1;
break;
case 1:
x -= 1;
break;
case 2:
z -= 1;
break;
case 3:
x += 1;
break;
}
return PacketUtil.createPacket(0x10, new TypeHolder[] { data.read(0), data.read(1), set(Type.LONG, ProtocolRelease47To5.toBlockPosition(x, y, z)), set(Type.BYTE, data.read(Type.INT, 5).byteValue()) });
}
});
// entity effect
addTranslator(0x1D, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x1D, new TypeHolder[] { set(Type.VAR_INT, data.read(Type.INT, 0)), data.read(1), data.read(2), set(Type.VAR_INT, data.read(Type.SHORT, 3).intValue()), set(Type.BOOLEAN, false) });
}
});
// remove entity effect
addTranslator(0x1E, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x1E, new TypeHolder[] { set(Type.VAR_INT, data.read(Type.INT, 0)), data.read(1) });
}
});
// spawn object
addTranslator(0x0E, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
int x = data.read(Type.INT, 2);
int y = data.read(Type.INT, 3);
int z = data.read(Type.INT, 4);
byte type = data.read(Type.BYTE, 1);
byte yaw = data.read(Type.BYTE, 6);
Motion motionData = data.read(Type.MOTION, 7);
ObjectType objectType = ObjectType.fromObjectTypeId(type);
switch(objectType) {
case ITEM:
y -= 4;
break;
case TNT_PRIMED:
y -= 16;
break;
case FALLING_OBJECT:
int itemId = motionData.getThrowerId();
int itemData = motionData.getThrowerId() >> 16;
short mX = motionData.getMotionX();
short mY = motionData.getMotionY();
short mZ = motionData.getMotionZ();
y -= 16;
motionData = new Motion(itemId | itemData << 12, mX, mY, mZ);
break;
case ITEM_FRAME:
int rotation = motionData.getThrowerId();
if (rotation == 0) {
z += 32;
yaw = 0;
} else if (rotation == 1) {
x -= 32;
yaw = 64;
} else if (rotation == 2) {
z -= 32;
yaw = -128;
} else if (rotation == 3) {
x += 32;
yaw = -64;
}
break;
}
if (storage.hasObject(V1_7EntityTracker.class)) {
V1_7EntityTracker tracker = storage.get(V1_7EntityTracker.class);
int entityId = data.read(Type.VAR_INT, 0);
tracker.addEntity(entityId, objectType);
}
return PacketUtil.createPacket(0x0E, new TypeHolder[] { data.read(0), set(Type.BYTE, type), set(Type.INT, x), set(Type.INT, y), set(Type.INT, z), data.read(5), set(Type.BYTE, yaw), set(Type.MOTION, motionData) });
}
});
}
use of com.github.dirtpowered.dirtmv.data.translator.PacketTranslator in project DirtMultiversion by DirtPowered.
the class InventoryPackets method registerTranslators.
@Override
public void registerTranslators() {
// set slot
addTranslator(0x2F, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
short windowId = data.read(Type.UNSIGNED_BYTE, 0);
short slot = data.read(Type.SHORT, 1);
int windowType = 0;
if (storage.hasObject(WindowTypeTracker.class)) {
WindowTypeTracker windowTracker = storage.get(WindowTypeTracker.class);
windowType = windowTracker.getWindowType(windowId);
}
ItemStack originalItem = data.read(Type.V1_3R_ITEM, 2);
if (originalItem == null)
return new PacketData(0x2F, data.getObjects());
ItemStack itemStack = itemRemapper.replaceItem(originalItem);
if (windowType == 4) {
if (slot >= 1) {
slot++;
}
}
// quick-bar cache
if (storage.hasObject(QuickBarTracker.class)) {
QuickBarTracker quickBarTracker = storage.get(QuickBarTracker.class);
quickBarTracker.setItem(slot, itemStack);
}
return PacketUtil.createPacket(0x2F, new TypeHolder[] { data.read(0), set(Type.SHORT, slot), set(Type.V1_8R_ITEM, itemStack) });
}
});
// window items
addTranslator(0x30, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
short windowId = data.read(Type.UNSIGNED_BYTE, 0);
ItemStack[] itemArray = data.read(Type.V1_3R_ITEM_ARRAY, 1);
int windowType = 0;
if (storage.hasObject(WindowTypeTracker.class)) {
WindowTypeTracker windowTracker = storage.get(WindowTypeTracker.class);
windowType = windowTracker.getWindowType(windowId);
}
if (windowType == 4) {
ItemStack[] copy = itemArray;
itemArray = new ItemStack[copy.length + 1];
itemArray[0] = copy[0];
int slot = 0;
while (slot < copy.length - 1) {
itemArray[slot + 2] = copy[slot + 1];
slot++;
}
// lapis
itemArray[1] = new ItemStack(351, 3, 4, null);
}
for (int i = 0; i < itemArray.length; i++) {
ItemStack originalItem = itemArray[i];
ItemStack item = originalItem;
if (originalItem != null) {
item = itemRemapper.replaceItem(originalItem);
}
itemArray[i] = item;
// quick-bar cache
if (storage.hasObject(QuickBarTracker.class)) {
QuickBarTracker quickBarTracker = storage.get(QuickBarTracker.class);
quickBarTracker.setItem(i, item);
}
}
return PacketUtil.createPacket(0x30, new TypeHolder[] { data.read(0), set(Type.V1_8R_ITEM_ARRAY, itemArray) });
}
});
// open window
addTranslator(0x2D, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
short windowId = data.read(Type.UNSIGNED_BYTE, 0);
short type = data.read(Type.UNSIGNED_BYTE, 1);
String title = data.read(Type.V1_7_STRING, 2);
short slots = data.read(Type.UNSIGNED_BYTE, 3);
// non storage inventories have always 0 slots
slots = InventoryUtils.isNonStorageInventory(type) ? 0 : slots;
// cache window type (for enchanting tables)
if (storage.hasObject(WindowTypeTracker.class)) {
WindowTypeTracker windowTracker = storage.get(WindowTypeTracker.class);
windowTracker.setWindowTypeFor(windowId, type);
}
return PacketUtil.createPacket(0x2D, new TypeHolder[] { data.read(0), set(Type.V1_7_STRING, InventoryUtils.getNamedTypeFromId(type)), set(Type.V1_7_STRING, InventoryUtils.addTranslateComponent(type == 6 ? "entity.Villager.name" : title)), set(Type.UNSIGNED_BYTE, slots) });
}
});
// window click
addTranslator(0x0E, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
byte windowId = data.read(Type.BYTE, 0);
short slot = data.read(Type.SHORT, 1);
int windowType = 0;
if (storage.hasObject(WindowTypeTracker.class)) {
WindowTypeTracker windowTracker = storage.get(WindowTypeTracker.class);
windowType = windowTracker.getWindowType(windowId);
}
if (windowType == 4) {
if (slot > 1) {
slot--;
}
}
if (storage.hasObject(QuickBarTracker.class)) {
QuickBarTracker cache = storage.get(QuickBarTracker.class);
boolean shiftClick = data.read(Type.BYTE, 4) == 1;
updateLocalInventory(cache, slot, shiftClick);
}
return PacketUtil.createPacket(0x0E, new TypeHolder[] { data.read(0), set(Type.SHORT, slot), data.read(2), data.read(3), data.read(4), set(Type.V1_3R_ITEM, data.read(Type.V1_8R_ITEM, 5)) });
}
});
// creative item get
addTranslator(0x10, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ItemStack item = data.read(Type.V1_8R_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(0x10, new TypeHolder[] { data.read(0), set(Type.V1_3R_ITEM, item) });
}
});
// change held slot
addTranslator(0x09, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
if (storage.hasObject(QuickBarTracker.class)) {
QuickBarTracker quickBarTracker = storage.get(QuickBarTracker.class);
quickBarTracker.setCurrentHotBarSlot(data.read(Type.SHORT, 0));
}
return data;
}
});
// change held slot (server-side)
addTranslator(0x09, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
if (storage.hasObject(QuickBarTracker.class)) {
QuickBarTracker quickBarTracker = storage.get(QuickBarTracker.class);
quickBarTracker.setCurrentHotBarSlot(data.read(Type.BYTE, 0));
}
return data;
}
});
// window property
addTranslator(0x31, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
int property = data.read(Type.SHORT, 1);
switch(property) {
case 0:
property = 2;
PacketData windowProperty = PacketUtil.createPacket(0x31, new TypeHolder[] { data.read(0), set(Type.SHORT, (short) 3), set(Type.SHORT, (short) 200) });
session.sendPacket(windowProperty, PacketDirection.TO_CLIENT, getFrom());
break;
case 1:
property = 0;
break;
case 2:
property = 1;
break;
}
return PacketUtil.createPacket(0x31, new TypeHolder[] { data.read(0), set(Type.SHORT, (short) property), data.read(2) });
}
});
}
use of com.github.dirtpowered.dirtmv.data.translator.PacketTranslator in project DirtMultiversion by DirtPowered.
the class ProtocolRelease60To51 method registerTranslators.
@Override
public void registerTranslators() {
// 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) 51), data.read(1), data.read(2), data.read(3) });
}
});
// open window
addTranslator(0x64, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x64, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3), // use original title
set(Type.BYTE, (byte) 0) });
}
});
// window click
addTranslator(0x66, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
boolean leftClickFlag = false;
boolean startDragging = false;
boolean endDragging = false;
boolean droppingUsingQ = false;
boolean addSlot = false;
short slot = data.read(Type.SHORT, 1);
byte param = data.read(Type.BYTE, 2);
byte inventoryAction = data.read(Type.BYTE, 4);
switch(inventoryAction) {
case 0:
leftClickFlag = param == 0;
break;
case 4:
droppingUsingQ = param + (slot != -999 ? 2 : 0) == 2;
break;
case 5:
startDragging = param == 0;
endDragging = param == 2;
addSlot = param == 1;
break;
}
boolean leftClick = leftClickFlag || startDragging || addSlot || endDragging;
boolean clickingOutside = slot == -999 && inventoryAction != 5;
boolean usingShift = inventoryAction == 1;
int mouseClick = leftClick ? 0 : 1;
if (droppingUsingQ) {
PacketData closeWindow = PacketUtil.createPacket(0x65, new TypeHolder[] { set(Type.BYTE, (byte) 0) });
session.sendPacket(closeWindow, PacketDirection.TO_CLIENT, getFrom());
return cancel();
}
if (slot < 0 && !clickingOutside)
return cancel();
return PacketUtil.createPacket(0x66, new TypeHolder[] { data.read(0), data.read(1), set(Type.BYTE, (byte) mouseClick), data.read(3), set(Type.BYTE, (byte) (usingShift ? 1 : 0)), set(Type.V1_3R_ITEM, new ItemStack(34, 0, 0, null)) });
}
});
// vehicle spawn
addTranslator(0x17, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
Motion motion = data.read(Type.MOTION, 7);
int throwerId = motion.getThrowerId();
byte vehicleType = data.read(Type.BYTE, 1);
byte vehicleFixedType = vehicleType;
switch(vehicleType) {
case // rideable minecart
(byte) 10:
throwerId = 0;
break;
case // chest minecart
(byte) 11:
vehicleFixedType = 10;
throwerId = 1;
break;
case // furnace minecart
(byte) 12:
vehicleFixedType = 10;
throwerId = 2;
break;
}
motion.setThrowerId(throwerId);
return PacketUtil.createPacket(0x17, new TypeHolder[] { data.read(0), set(Type.BYTE, vehicleFixedType), data.read(2), data.read(3), data.read(4), data.read(5), data.read(6), set(Type.MOTION, motion) });
}
});
// 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) });
}
});
}
use of com.github.dirtpowered.dirtmv.data.translator.PacketTranslator in project DirtMultiversion by DirtPowered.
the class ProtocolRelease78To74 method registerTranslators.
@Override
public void registerTranslators() {
// 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) 74), data.read(1), data.read(2), data.read(3) });
}
});
// kick disconnect
addTranslator(0xFF, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
if (session.getUserData().getPreNettyProtocolState() != PreNettyProtocolState.STATUS)
return data;
String reason = data.read(Type.STRING, 0);
ServerMotd pingMessage = ServerMotd.deserialize(reason);
pingMessage.setVersionName("1.6.4");
pingMessage.setProtocol(session.getUserData().getClientVersion().getRegistryId());
return PacketUtil.createPacket(0xFF, new TypeHolder[] { set(Type.STRING, ServerMotd.serialize(pingMessage)) });
}
});
}
Aggregations