use of com.github.dirtpowered.dirtmv.data.protocol.objects.Motion 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) });
}
});
}
Aggregations