Java Code Examples for net.minecraftforge.event.entity.player.PlayerInteractEvent#Action

The following examples show how to use net.minecraftforge.event.entity.player.PlayerInteractEvent#Action . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SegmentBlock.java    From MyTown2 with The Unlicense 6 votes vote down vote up
public boolean shouldInteract(Resident res, BlockPos bp, PlayerInteractEvent.Action action) {
    if(meta != -1 && meta != MinecraftServer.getServer().worldServerForDimension(bp.getDim()).getBlockMetadata(bp.getX(), bp.getY(), bp.getZ())) {
        return true;
    }

    if((action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK && !types.contains(BlockType.LEFT_CLICK)
            || action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK && !types.contains(BlockType.RIGHT_CLICK))
            && !types.contains(BlockType.ANY_CLICK)) {
        return true;
    }

    if (!hasPermissionAtLocation(res, bp.getDim(), bp.getX(), bp.getY(), bp.getZ())) {
        if(clientUpdate != null) {
            clientUpdate.send(bp, (EntityPlayerMP) res.getPlayer());
        }
        return false;
    }

    return true;
}
 
Example 2
Source File: ProtectionManager.java    From MyTown2 with The Unlicense 6 votes vote down vote up
public static void checkBlockInteraction(Resident res, BlockPos bp, PlayerInteractEvent.Action action, Event ev) {
    if(!ev.isCancelable()) {
        return;
    }

    World world = MinecraftServer.getServer().worldServerForDimension(bp.getDim());
    Block block = world.getBlock(bp.getX(), bp.getY(), bp.getZ());

    // Bypass for SellSign
    if (block instanceof BlockSign) {
        TileEntity te = world.getTileEntity(bp.getX(), bp.getY(), bp.getZ());
        if(te instanceof TileEntitySign && SellSign.SellSignType.instance.isTileValid((TileEntitySign) te)) {
            return;
        }
    }

    for(SegmentBlock segment : segmentsBlock.get(block.getClass())) {
        if(!segment.shouldInteract(res, bp, action)) {
            ev.setCanceled(true);
        }
    }
}
 
Example 3
Source File: ProtectionManager.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public static void checkUsage(ItemStack stack, Resident res, PlayerInteractEvent.Action action, BlockPos bp, int face, Event ev) {
    if(!ev.isCancelable()) {
        return;
    }

    for(SegmentItem segment : segmentsItem.get(stack.getItem().getClass())) {
        if(!segment.shouldInteract(stack, res, action, bp, face)) {
            ev.setCanceled(true);
        }
    }
}