Search in sources :

Example 1 with BlockPosContext

use of net.minecraftforge.server.permission.context.BlockPosContext in project EnderIO by SleepyTrousers.

the class ItemSoulVial method onItemUse.

@Override
@Nonnull
public EnumActionResult onItemUse(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumHand hand, @Nonnull EnumFacing side, float hitX, float hitY, float hitZ) {
    if (world.isRemote) {
        return EnumActionResult.PASS;
    }
    ItemStack itemstack = player.getHeldItem(hand);
    CapturedMob capturedMob = CapturedMob.create(itemstack);
    if (capturedMob == null) {
        return EnumActionResult.SUCCESS;
    }
    if (!PermissionAPI.hasPermission(player.getGameProfile(), permissionPlace, new BlockPosContext(player, pos, null, side))) {
        player.sendMessage(Lang.SOUL_VIAL_DENIED.toChatServer());
        return EnumActionResult.SUCCESS;
    }
    if (!capturedMob.spawn(world, pos, side, true)) {
        return EnumActionResult.SUCCESS;
    }
    if (!player.capabilities.isCreativeMode) {
        itemstack.shrink(1);
        final ItemStack emptyVial = new ItemStack(this);
        if (Prep.isInvalid(itemstack)) {
            player.setHeldItem(hand, emptyVial);
        } else if (!player.inventory.addItemStackToInventory(emptyVial)) {
            player.dropItem(emptyVial, false);
        }
        player.inventoryContainer.detectAndSendChanges();
    }
    return EnumActionResult.SUCCESS;
}
Also used : CapturedMob(crazypants.enderio.util.CapturedMob) BlockPosContext(net.minecraftforge.server.permission.context.BlockPosContext) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 2 with BlockPosContext

use of net.minecraftforge.server.permission.context.BlockPosContext in project EnderIO by SleepyTrousers.

the class ToolUtil method breakBlockWithTool.

public static boolean breakBlockWithTool(@Nonnull Block block, @Nonnull World world, @Nonnull BlockPos pos, @Nullable EnumFacing side, @Nonnull EntityPlayer entityPlayer, @Nonnull EnumHand hand, @Nonnull String permissionNode) {
    ItemStack heldItem = entityPlayer.getHeldItem(hand);
    ITool tool = ToolUtil.getToolFromStack(heldItem);
    if (tool != null && entityPlayer.isSneaking() && tool.canUse(hand, entityPlayer, pos)) {
        IBlockState bs = world.getBlockState(pos);
        if (!PermissionAPI.hasPermission(entityPlayer.getGameProfile(), permissionNode, new BlockPosContext(entityPlayer, pos, bs, side))) {
            entityPlayer.sendMessage(Lang.WRENCH_DENIED.toChatServer());
            return false;
        }
        BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, bs, entityPlayer);
        event.setExpToDrop(0);
        if (MinecraftForge.EVENT_BUS.post(event)) {
            return false;
        }
        if (block.removedByPlayer(bs, world, pos, entityPlayer, true)) {
            block.harvestBlock(world, entityPlayer, pos, world.getBlockState(pos), world.getTileEntity(pos), heldItem);
        }
        tool.used(hand, entityPlayer, pos);
        return true;
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPosContext(net.minecraftforge.server.permission.context.BlockPosContext) ItemStack(net.minecraft.item.ItemStack) ITool(crazypants.enderio.api.tool.ITool) BlockEvent(net.minecraftforge.event.world.BlockEvent)

Example 3 with BlockPosContext

use of net.minecraftforge.server.permission.context.BlockPosContext in project EnderIO by SleepyTrousers.

the class TileFarmStation method doTick.

protected void doTick() {
    IFarmer farmer = getFarmer();
    BlockPos farmingPos = null;
    IBlockState bs = null;
    int infiniteLoop = 20;
    while (farmingPos == null || bs == null || farmingPos.equals(getPos()) || !world.isBlockLoaded(farmingPos) || !PermissionAPI.hasPermission(getOwner().getAsGameProfile(), BlockFarmStation.permissionFarming, new BlockPosContext(farmer.getFakePlayer(), farmingPos, bs, null))) {
        if (infiniteLoop-- <= 0) {
            return;
        }
        farmingPos = getNextCoord();
        bs = world.getBlockState(farmingPos);
    }
    Block block = bs.getBlock();
    if (isOpen(farmingPos, block)) {
        Commune.instance.prepareBlock(farmer, farmingPos, block, bs);
        bs = world.getBlockState(farmingPos);
        block = bs.getBlock();
    }
    if (!isOpen(farmingPos, block)) {
        if (!executeHarvest(farmer, farmingPos, bs, block)) {
            executeBonemeal(farmer, farmingPos, block);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) EnumSkyBlock(net.minecraft.world.EnumSkyBlock) IFarmer(crazypants.enderio.api.farm.IFarmer) BlockPos(net.minecraft.util.math.BlockPos) BlockPosContext(net.minecraftforge.server.permission.context.BlockPosContext)

Example 4 with BlockPosContext

use of net.minecraftforge.server.permission.context.BlockPosContext in project EnderIO by SleepyTrousers.

the class BlockConduitBundle method handleWrenchClick.

private boolean handleWrenchClick(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer player, @Nonnull EnumHand hand) {
    ITool tool = ToolUtil.getEquippedTool(player, hand);
    if (tool != null) {
        if (tool.canUse(hand, player, pos)) {
            if (!world.isRemote) {
                IBlockState bs = world.getBlockState(pos);
                if (!PermissionAPI.hasPermission(player.getGameProfile(), permissionNodeWrenching, new BlockPosContext(player, pos, bs, null))) {
                    player.sendMessage(new TextComponentString(EnderIO.lang.localize("wrench.permission.denied")));
                    return false;
                }
                BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, bs, player);
                event.setExpToDrop(0);
                if (MinecraftForge.EVENT_BUS.post(event)) {
                    return false;
                }
                removedByPlayer(bs, world, pos, player, true);
                tool.used(hand, player, pos);
            }
            return true;
        }
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPosContext(net.minecraftforge.server.permission.context.BlockPosContext) ITool(crazypants.enderio.api.tool.ITool) BlockEvent(net.minecraftforge.event.world.BlockEvent) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

BlockPosContext (net.minecraftforge.server.permission.context.BlockPosContext)4 IBlockState (net.minecraft.block.state.IBlockState)3 ITool (crazypants.enderio.api.tool.ITool)2 ItemStack (net.minecraft.item.ItemStack)2 BlockEvent (net.minecraftforge.event.world.BlockEvent)2 IFarmer (crazypants.enderio.api.farm.IFarmer)1 CapturedMob (crazypants.enderio.util.CapturedMob)1 Nonnull (javax.annotation.Nonnull)1 Block (net.minecraft.block.Block)1 BlockPos (net.minecraft.util.math.BlockPos)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 EnumSkyBlock (net.minecraft.world.EnumSkyBlock)1