Search in sources :

Example 1 with LeftClickAirEventMessage

use of com.sk89q.worldedit.forge.net.packet.LeftClickAirEventMessage in project FastAsyncWorldEdit by IntellectualSites.

the class ForgeWorldEdit method onPlayerInteract.

@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event) {
    if (platform == null) {
        return;
    }
    if (!platform.isHookingEvents())
        // We have to be told to catch these events
        return;
    if (event.getWorld().isRemote && event instanceof LeftClickEmpty) {
        // catch LCE, pass it to server
        InternalPacketHandler.getHandler().sendToServer(new LeftClickAirEventMessage());
        return;
    }
    boolean isLeftDeny = event instanceof PlayerInteractEvent.LeftClickBlock && ((PlayerInteractEvent.LeftClickBlock) event).getUseItem() == Event.Result.DENY;
    boolean isRightDeny = event instanceof PlayerInteractEvent.RightClickBlock && ((PlayerInteractEvent.RightClickBlock) event).getUseItem() == Event.Result.DENY;
    if (isLeftDeny || isRightDeny || event.getEntity().world.isRemote || event.getHand() == Hand.OFF_HAND) {
        return;
    }
    WorldEdit we = WorldEdit.getInstance();
    ForgePlayer player = adaptPlayer((ServerPlayerEntity) event.getPlayer());
    ForgeWorld world = getWorld(event.getPlayer().world);
    if (event instanceof PlayerInteractEvent.LeftClickEmpty) {
        // this event cannot be canceled
        we.handleArmSwing(player);
    } else if (event instanceof PlayerInteractEvent.LeftClickBlock) {
        Location pos = new Location(world, event.getPos().getX(), event.getPos().getY(), event.getPos().getZ());
        if (we.handleBlockLeftClick(player, pos)) {
            event.setCanceled(true);
        }
        if (we.handleArmSwing(player)) {
            event.setCanceled(true);
        }
    } else if (event instanceof PlayerInteractEvent.RightClickBlock) {
        Location pos = new Location(world, event.getPos().getX(), event.getPos().getY(), event.getPos().getZ());
        if (we.handleBlockRightClick(player, pos)) {
            event.setCanceled(true);
        }
        if (we.handleRightClick(player)) {
            event.setCanceled(true);
        }
    } else if (event instanceof PlayerInteractEvent.RightClickItem) {
        if (we.handleRightClick(player)) {
            event.setCanceled(true);
        }
    }
}
Also used : WorldEdit(com.sk89q.worldedit.WorldEdit) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent) LeftClickEmpty(net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickEmpty) LeftClickAirEventMessage(com.sk89q.worldedit.forge.net.packet.LeftClickAirEventMessage) Location(com.sk89q.worldedit.util.Location) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

WorldEdit (com.sk89q.worldedit.WorldEdit)1 LeftClickAirEventMessage (com.sk89q.worldedit.forge.net.packet.LeftClickAirEventMessage)1 Location (com.sk89q.worldedit.util.Location)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 PlayerInteractEvent (net.minecraftforge.event.entity.player.PlayerInteractEvent)1 LeftClickEmpty (net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickEmpty)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1