Java Code Examples for net.minecraft.entity.player.EntityPlayer.canUseCommandBlock()

The following are Jave code examples for showing how to use canUseCommandBlock() of the net.minecraft.entity.player.EntityPlayer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Backmemed   File: TileEntityStructure.java   View Source Code Vote up 6 votes
public boolean usedBy(EntityPlayer player)
{
    if (!player.canUseCommandBlock())
    {
        return false;
    }
    else
    {
        if (player.getEntityWorld().isRemote)
        {
            player.openEditStructure(this);
        }

        return true;
    }
}
 
Example 2
Project: Backmemed   File: CommandBlockBaseLogic.java   View Source Code Vote up 6 votes
public boolean tryOpenEditCommandBlock(EntityPlayer playerIn)
{
    if (!playerIn.canUseCommandBlock())
    {
        return false;
    }
    else
    {
        if (playerIn.getEntityWorld().isRemote)
        {
            playerIn.displayGuiEditCommandCart(this);
        }

        return true;
    }
}
 
Example 3
Project: CustomWorldGen   File: TileEntityStructure.java   View Source Code Vote up 6 votes
public boolean usedBy(EntityPlayer player)
{
    if (!player.canUseCommandBlock())
    {
        return false;
    }
    else
    {
        if (player.getEntityWorld().isRemote)
        {
            player.openEditStructure(this);
        }

        return true;
    }
}
 
Example 4
Project: CustomWorldGen   File: CommandBlockBaseLogic.java   View Source Code Vote up 6 votes
public boolean tryOpenEditCommandBlock(EntityPlayer playerIn)
{
    if (!playerIn.canUseCommandBlock())
    {
        return false;
    }
    else
    {
        if (playerIn.getEntityWorld().isRemote)
        {
            playerIn.displayGuiEditCommandCart(this);
        }

        return true;
    }
}
 
Example 5
Project: Scripty   File: ScriptyBlock.java   View Source Code Vote up 5 votes
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (worldIn.isRemote) {
        return true;
    }
    if (!playerIn.canUseCommandBlock()) {
        return false;
    }
    ScriptyNetworkHandler.handleOpenRequest(pos, (EntityPlayerMP) playerIn);
    return true;
}
 
Example 6
Project: Backmemed   File: BlockCommandBlock.java   View Source Code Vote up 5 votes
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing heldItem, float side, float hitX, float hitY)
{
    TileEntity tileentity = worldIn.getTileEntity(pos);

    if (tileentity instanceof TileEntityCommandBlock && playerIn.canUseCommandBlock())
    {
        playerIn.displayGuiCommandBlock((TileEntityCommandBlock)tileentity);
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 7
Project: CustomWorldGen   File: BlockCommandBlock.java   View Source Code Vote up 5 votes
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
{
    TileEntity tileentity = worldIn.getTileEntity(pos);

    if (tileentity instanceof TileEntityCommandBlock && playerIn.canUseCommandBlock())
    {
        playerIn.displayGuiCommandBlock((TileEntityCommandBlock)tileentity);
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 8
Project: pnc-repressurized   File: DroneAIBlockInteract.java   View Source Code Vote up 4 votes
private boolean rightClick(BlockPos pos) {
    EnumFacing faceDir = ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides());
    EntityPlayer player = drone.getFakePlayer();
    World world = drone.world();
    ItemStack stack = player.getHeldItemMainhand();

    player.setPosition(pos.getX() + 0.5, pos.getY() + 0.5 - player.eyeHeight, pos.getZ() + 0.5);
    player.rotationPitch = faceDir.getFrontOffsetY() * -90;
    player.rotationYaw = PneumaticCraftUtils.getYawFromFacing(faceDir);

    float hitX = (float)(player.posX - pos.getX());
    float hitY = (float)(player.posY - pos.getY());
    float hitZ = (float)(player.posZ - pos.getZ());

    // this is adapted from PlayerInteractionManager#processRightClickBlock()
    try {
        PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(player, EnumHand.MAIN_HAND, pos, faceDir.getOpposite(),  ForgeHooks.rayTraceEyeHitVec(player, 2.0D));
        if (event.isCanceled() || event.getUseItem() == Event.Result.DENY) {
            return false;
        }

        EnumActionResult ret = stack.onItemUseFirst(player, world, pos, EnumHand.MAIN_HAND, faceDir, hitX, hitY, hitZ);
        if (ret != EnumActionResult.PASS) return false;

        boolean bypass = player.getHeldItemMainhand().doesSneakBypassUse(world, pos, player);
        EnumActionResult result = EnumActionResult.PASS;

        if (!player.isSneaking() || bypass || event.getUseBlock() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW) {
            IBlockState iblockstate = world.getBlockState(pos);
            if(event.getUseBlock() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY)
                if (iblockstate.getBlock().onBlockActivated(world, pos, iblockstate, player, EnumHand.MAIN_HAND, faceDir, hitX, hitY, hitZ)) {
                    result = EnumActionResult.SUCCESS;
                }
        }

        if (stack.isEmpty() || player.getCooldownTracker().hasCooldown(stack.getItem())) {
            return false;
        }

        if (stack.getItem() instanceof ItemBlock && !player.canUseCommandBlock()) {
            Block block = ((ItemBlock)stack.getItem()).getBlock();
            if (block instanceof BlockCommandBlock || block instanceof BlockStructure) {
                return false;
            }
        }

        if (result != EnumActionResult.SUCCESS && event.getUseItem() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY
                || result == EnumActionResult.SUCCESS && event.getUseItem() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW) {
            ItemStack copyBeforeUse = stack.copy();
            result = stack.onItemUse(player, world, pos, EnumHand.MAIN_HAND, faceDir, hitX, hitY, hitZ);
            if (result == EnumActionResult.PASS) {
                ActionResult<ItemStack> rightClickResult = stack.getItem().onItemRightClick(world, player, EnumHand.MAIN_HAND);
                player.setHeldItem(EnumHand.MAIN_HAND, rightClickResult.getResult());
            }
            if (player.getHeldItem(EnumHand.MAIN_HAND).isEmpty()) {
                net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, copyBeforeUse, EnumHand.MAIN_HAND);
            }
        }

        return false;
    } catch (Throwable e) {
        Log.error("DroneAIBlockInteract crashed! Stacktrace: ");
        e.printStackTrace();
        return false;
    }
}
 
Example 9
Project: Backmemed   File: ItemBlock.java   View Source Code Vote up 4 votes
public static boolean setTileEntityNBT(World worldIn, @Nullable EntityPlayer player, BlockPos pos, ItemStack stackIn)
{
    MinecraftServer minecraftserver = worldIn.getMinecraftServer();

    if (minecraftserver == null)
    {
        return false;
    }
    else
    {
        NBTTagCompound nbttagcompound = stackIn.getSubCompound("BlockEntityTag");

        if (nbttagcompound != null)
        {
            TileEntity tileentity = worldIn.getTileEntity(pos);

            if (tileentity != null)
            {
                if (!worldIn.isRemote && tileentity.onlyOpsCanSetNbt() && (player == null || !player.canUseCommandBlock()))
                {
                    return false;
                }

                NBTTagCompound nbttagcompound1 = tileentity.writeToNBT(new NBTTagCompound());
                NBTTagCompound nbttagcompound2 = nbttagcompound1.copy();
                nbttagcompound1.merge(nbttagcompound);
                nbttagcompound1.setInteger("x", pos.getX());
                nbttagcompound1.setInteger("y", pos.getY());
                nbttagcompound1.setInteger("z", pos.getZ());

                if (!nbttagcompound1.equals(nbttagcompound2))
                {
                    tileentity.readFromNBT(nbttagcompound1);
                    tileentity.markDirty();
                    return true;
                }
            }
        }

        return false;
    }
}
 
Example 10
Project: Backmemed   File: PlayerInteractionManager.java   View Source Code Vote up 4 votes
public EnumActionResult processRightClickBlock(EntityPlayer player, World worldIn, ItemStack stack, EnumHand hand, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    if (this.gameType == GameType.SPECTATOR)
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof ILockableContainer)
        {
            Block block1 = worldIn.getBlockState(pos).getBlock();
            ILockableContainer ilockablecontainer = (ILockableContainer)tileentity;

            if (ilockablecontainer instanceof TileEntityChest && block1 instanceof BlockChest)
            {
                ilockablecontainer = ((BlockChest)block1).getLockableContainer(worldIn, pos);
            }

            if (ilockablecontainer != null)
            {
                player.displayGUIChest(ilockablecontainer);
                return EnumActionResult.SUCCESS;
            }
        }
        else if (tileentity instanceof IInventory)
        {
            player.displayGUIChest((IInventory)tileentity);
            return EnumActionResult.SUCCESS;
        }

        return EnumActionResult.PASS;
    }
    else
    {
        if (!player.isSneaking() || player.getHeldItemMainhand().func_190926_b() && player.getHeldItemOffhand().func_190926_b())
        {
            IBlockState iblockstate = worldIn.getBlockState(pos);

            if (iblockstate.getBlock().onBlockActivated(worldIn, pos, iblockstate, player, hand, facing, hitX, hitY, hitZ))
            {
                return EnumActionResult.SUCCESS;
            }
        }

        if (stack.func_190926_b())
        {
            return EnumActionResult.PASS;
        }
        else if (player.getCooldownTracker().hasCooldown(stack.getItem()))
        {
            return EnumActionResult.PASS;
        }
        else
        {
            if (stack.getItem() instanceof ItemBlock && !player.canUseCommandBlock())
            {
                Block block = ((ItemBlock)stack.getItem()).getBlock();

                if (block instanceof BlockCommandBlock || block instanceof BlockStructure)
                {
                    return EnumActionResult.FAIL;
                }
            }

            if (this.isCreative())
            {
                int j = stack.getMetadata();
                int i = stack.func_190916_E();
                EnumActionResult enumactionresult = stack.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
                stack.setItemDamage(j);
                stack.func_190920_e(i);
                return enumactionresult;
            }
            else
            {
                return stack.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
            }
        }
    }
}
 
Example 11
Project: CustomWorldGen   File: ItemBlock.java   View Source Code Vote up 4 votes
public static boolean setTileEntityNBT(World worldIn, @Nullable EntityPlayer player, BlockPos pos, ItemStack stackIn)
{
    MinecraftServer minecraftserver = worldIn.getMinecraftServer();

    if (minecraftserver == null)
    {
        return false;
    }
    else
    {
        if (stackIn.hasTagCompound() && stackIn.getTagCompound().hasKey("BlockEntityTag", 10))
        {
            TileEntity tileentity = worldIn.getTileEntity(pos);

            if (tileentity != null)
            {
                if (!worldIn.isRemote && tileentity.onlyOpsCanSetNbt() && (player == null || !player.canUseCommandBlock()))
                {
                    return false;
                }

                NBTTagCompound nbttagcompound = tileentity.writeToNBT(new NBTTagCompound());
                NBTTagCompound nbttagcompound1 = nbttagcompound.copy();
                NBTTagCompound nbttagcompound2 = (NBTTagCompound)stackIn.getTagCompound().getTag("BlockEntityTag");
                nbttagcompound.merge(nbttagcompound2);
                nbttagcompound.setInteger("x", pos.getX());
                nbttagcompound.setInteger("y", pos.getY());
                nbttagcompound.setInteger("z", pos.getZ());

                if (!nbttagcompound.equals(nbttagcompound1))
                {
                    tileentity.readFromNBT(nbttagcompound);
                    tileentity.markDirty();
                    return true;
                }
            }
        }

        return false;
    }
}