2019-08-10 00:15:06 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 GeyserMC. http://geysermc.org
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.geysermc.connector.network.translators.bedrock;
|
|
|
|
|
2019-09-14 01:12:36 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
2019-09-27 20:50:48 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
|
2019-09-14 01:12:36 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
|
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerState;
|
|
|
|
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
|
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket;
|
2019-09-27 20:50:48 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPlaceBlockPacket;
|
2019-09-14 01:12:36 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket;
|
2019-10-09 18:39:38 +00:00
|
|
|
import com.nukkitx.math.vector.Vector3i;
|
2019-08-10 00:15:06 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.packet.PlayerActionPacket;
|
2019-09-14 01:12:36 +00:00
|
|
|
import org.geysermc.connector.entity.Entity;
|
2019-08-10 00:15:06 +00:00
|
|
|
import org.geysermc.connector.network.session.GeyserSession;
|
|
|
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
|
|
|
|
|
|
|
public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket> {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void translate(PlayerActionPacket packet, GeyserSession session) {
|
2019-10-16 20:32:53 +00:00
|
|
|
Entity entity = session.getEntityCache().getEntityByGeyserId(packet.getRuntimeEntityId());
|
2019-09-14 01:12:36 +00:00
|
|
|
if (entity == null)
|
|
|
|
return;
|
|
|
|
|
2019-09-27 20:50:48 +00:00
|
|
|
Vector3i vector = packet.getBlockPosition();
|
|
|
|
Position position = new Position(vector.getX(), vector.getY(), vector.getZ());
|
|
|
|
|
2019-08-10 00:15:06 +00:00
|
|
|
switch (packet.getAction()) {
|
|
|
|
case RESPAWN:
|
|
|
|
// Don't put anything here as respawn is already handled
|
|
|
|
// in JavaPlayerSetHealthTranslator
|
|
|
|
break;
|
2019-09-14 01:12:36 +00:00
|
|
|
case START_GLIDE:
|
|
|
|
case STOP_GLIDE:
|
2019-10-16 20:32:53 +00:00
|
|
|
ClientPlayerStatePacket glidePacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_ELYTRA_FLYING);
|
2019-09-14 01:12:36 +00:00
|
|
|
session.getDownstream().getSession().send(glidePacket);
|
|
|
|
break;
|
|
|
|
case START_SNEAK:
|
2019-10-16 20:32:53 +00:00
|
|
|
ClientPlayerStatePacket startSneakPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SNEAKING);
|
2019-09-14 01:12:36 +00:00
|
|
|
session.getDownstream().getSession().send(startSneakPacket);
|
|
|
|
break;
|
|
|
|
case STOP_SNEAK:
|
2019-10-16 20:32:53 +00:00
|
|
|
ClientPlayerStatePacket stopSneakPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SNEAKING);
|
2019-09-14 01:12:36 +00:00
|
|
|
session.getDownstream().getSession().send(stopSneakPacket);
|
|
|
|
break;
|
|
|
|
case START_SPRINT:
|
2019-10-16 20:32:53 +00:00
|
|
|
ClientPlayerStatePacket startSprintPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SPRINTING);
|
|
|
|
session.getDownstream().getSession().send(startSprintPacket);
|
2019-09-14 01:12:36 +00:00
|
|
|
break;
|
|
|
|
case STOP_SPRINT:
|
2019-10-16 20:32:53 +00:00
|
|
|
ClientPlayerStatePacket stopSprintPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SPRINTING);
|
|
|
|
session.getDownstream().getSession().send(stopSprintPacket);
|
2019-09-14 01:12:36 +00:00
|
|
|
break;
|
|
|
|
case DROP_ITEM:
|
2019-09-27 20:50:48 +00:00
|
|
|
ClientPlayerActionPacket dropItemPacket = new ClientPlayerActionPacket(PlayerAction.DROP_ITEM, position, BlockFace.values()[packet.getFace()]);
|
2019-09-14 01:12:36 +00:00
|
|
|
session.getDownstream().getSession().send(dropItemPacket);
|
|
|
|
break;
|
|
|
|
case STOP_SLEEP:
|
2019-10-16 20:32:53 +00:00
|
|
|
ClientPlayerStatePacket stopSleepingPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.LEAVE_BED);
|
2019-09-14 01:12:36 +00:00
|
|
|
session.getDownstream().getSession().send(stopSleepingPacket);
|
|
|
|
break;
|
2019-09-27 20:50:48 +00:00
|
|
|
case BLOCK_INTERACT:
|
|
|
|
ClientPlayerPlaceBlockPacket blockPacket = new ClientPlayerPlaceBlockPacket(position,
|
|
|
|
BlockFace.values()[packet.getFace()],
|
|
|
|
Hand.MAIN_HAND, 0, 0, 0, false);
|
|
|
|
session.getDownstream().getSession().send(blockPacket);
|
2019-09-27 23:04:58 +00:00
|
|
|
break;
|
2019-09-27 21:38:52 +00:00
|
|
|
case START_BREAK:
|
2019-09-30 22:17:36 +00:00
|
|
|
ClientPlayerActionPacket startBreakingPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, new Position(packet.getBlockPosition().getX(),
|
|
|
|
packet.getBlockPosition().getY(), packet.getBlockPosition().getZ()), BlockFace.values()[packet.getFace()]);
|
|
|
|
session.setBlockDiggingPos(packet.getBlockPosition());
|
|
|
|
session.setBlockDiggingFace(BlockFace.values()[packet.getFace()]);
|
|
|
|
session.getDownstream().getSession().send(startBreakingPacket);
|
|
|
|
break;
|
|
|
|
case CONTINUE_BREAK:
|
|
|
|
session.setBlockDiggingFace(BlockFace.values()[packet.getFace()]);
|
2019-09-27 23:04:58 +00:00
|
|
|
break;
|
2019-09-27 21:38:52 +00:00
|
|
|
case ABORT_BREAK:
|
2019-09-30 22:17:36 +00:00
|
|
|
ClientPlayerActionPacket abortBreakingPacket = new ClientPlayerActionPacket(PlayerAction.CANCEL_DIGGING, new Position(packet.getBlockPosition().getX(),
|
|
|
|
packet.getBlockPosition().getY(), packet.getBlockPosition().getZ()), BlockFace.DOWN);
|
|
|
|
session.getDownstream().getSession().send(abortBreakingPacket);
|
2019-09-27 23:04:58 +00:00
|
|
|
break;
|
2019-09-30 22:17:36 +00:00
|
|
|
case STOP_BREAK:
|
|
|
|
Vector3i pos = session.getBlockDiggingPos();
|
|
|
|
ClientPlayerActionPacket stopBreakingPacket = new ClientPlayerActionPacket(PlayerAction.FINISH_DIGGING, new Position(pos.getX(),
|
|
|
|
pos.getY(), pos.getZ()), session.getBlockDiggingFace());
|
|
|
|
session.getDownstream().getSession().send(stopBreakingPacket);
|
2019-09-27 23:04:58 +00:00
|
|
|
break;
|
2019-08-10 00:15:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|