Untitled

 avatar
unknown
plain_text
a year ago
2.5 kB
6
Indexable
public class PlayerRiderEvent {

    @SubscribeEvent(priority = EventPriority.HIGH)
    public void onEntityRightClick(PlayerInteractEvent.EntityInteract event) {
        EntityPlayer player = event.getEntityPlayer();
        Entity targetRide = event.getTarget();
        if (player != null) {
            if (targetRide instanceof EntityPlayer || targetRide instanceof EntityMob) {
                if (!targetRide.isRiding()) {
                    Core.LOGGER.info("COMEÇO");
                    PacketHandler.INSTANCE.sendToAll(new CarryInClientPacket(player.getName(), targetRide.getEntityId()));
                }
                event.setCanceled(true);
                event.setCancellationResult(EnumActionResult.SUCCESS);
            }
        }
    }

    @SubscribeEvent
    public void onRightClick(PlayerInteractEvent event) {
        EntityPlayer player = event.getEntityPlayer();
        boolean isCarryingPlayer = player.getEntityData().getBoolean("isCarryingPlayer");

        if (!player.isSneaking()) {
            if (player.isBeingRidden() && isCarryingPlayer) {
                Entity passenger = player.getPassengers().isEmpty() ? null : player.getPassengers().get(0);
                if (passenger instanceof EntityPlayer || passenger instanceof EntityMob) {
                    passenger.dismountRidingEntity();
                    player.getEntityData().setBoolean("isCarryingPlayer", false);
                    Vec3d lookVec = player.getLookVec();
                    double forwardMotion = 1.0;
                    passenger.addVelocity(-Math.sin(Math.toRadians(player.rotationYaw)) * forwardMotion, 0,
                            Math.cos(Math.toRadians(player.rotationYaw)) * forwardMotion);
                    passenger.motionY = 0.5;
                    double pushDistance = 2.0;
                    Vec3d newPos = passenger.getPositionVector().add(lookVec.scale(pushDistance));
                    passenger.setPositionAndUpdate(newPos.x, newPos.y, newPos.z);
                }
            }
        }
    }

    @SubscribeEvent
    public void onPlayerAttack(AttackEntityEvent event) {
        EntityPlayer player = event.getEntityPlayer();
        Entity target = event.getTarget();
        if (target instanceof EntityPlayer || target instanceof EntityMob) {
            if (target.isRiding() && player.getEntityData().getBoolean("isCarryingPlayer")) {
                event.setCanceled(true);
            }
        }
    }
}
Editor is loading...
Leave a Comment