Search in sources :

Example 16 with ActionResult

use of net.minecraft.util.ActionResult in project Pearcel-Mod by MiningMark48.

the class ItemCharmBag method onItemRightClick.

@Override
public ActionResult onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
    if (!player.isSneaking()) {
        if (!world.isRemote) {
            if (!player.isSneaking() && hand == EnumHand.MAIN_HAND) {
                player.openGui(Reference.MOD_ID, GUIs.gui_id_charm_bag, world, 0, 0, 0);
            }
        }
    } else {
        if (!stack.hasTagCompound()) {
            stack.setTagCompound(new NBTTagCompound());
            stack.getTagCompound().setBoolean("active", true);
        }
        NBTTagCompound compound = stack.getTagCompound();
        NBTTagList items = compound.getTagList("ItemInventory", Constants.NBT.TAG_COMPOUND);
        for (int i = 0; i < items.tagCount(); i++) {
            NBTTagCompound item = (NBTTagCompound) items.getCompoundTagAt(i);
            int slot = item.getInteger("Slot");
            ItemStack charmStack = ItemStack.loadItemStackFromNBT(item);
            if (slot >= 0 && slot < InventoryCharmBag.INV_SIZE) {
                if (!stack.getTagCompound().getBoolean("active")) {
                    charmStack.getTagCompound().setBoolean("active", true);
                } else {
                    charmStack.getTagCompound().setBoolean("active", false);
                }
            }
        }
        if (!world.isRemote) {
            if (stack.getTagCompound().getBoolean("active")) {
                player.sendMessage(new TextComponentString(ChatFormatting.RED + Translate.toLocal("chat.item.charmed_pearcel.deactivated")));
                stack.getTagCompound().setBoolean("active", false);
            } else {
                player.sendMessage(new TextComponentString(ChatFormatting.GREEN + Translate.toLocal("chat.item.charmed_pearcel.activated")));
                stack.getTagCompound().setBoolean("active", true);
            }
        }
    }
    return new ActionResult(EnumActionResult.SUCCESS, stack);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 17 with ActionResult

use of net.minecraft.util.ActionResult in project Pearcel-Mod by MiningMark48.

the class ItemCharmedPearcel method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
    if (!stack.hasTagCompound()) {
        stack.setTagCompound(new NBTTagCompound());
    }
    if (player.isSneaking() && !world.isRemote) {
        if (!stack.getTagCompound().getBoolean("active")) {
            stack.getTagCompound().setBoolean("active", true);
            player.sendMessage(new TextComponentString(ChatFormatting.GREEN + Translate.toLocal("chat.item.charmed_pearcel.activated")));
        } else {
            stack.getTagCompound().setBoolean("active", false);
            player.sendMessage(new TextComponentString(ChatFormatting.RED + Translate.toLocal("chat.item.charmed_pearcel.deactivated")));
        }
    }
    return new ActionResult(EnumActionResult.SUCCESS, stack);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 18 with ActionResult

use of net.minecraft.util.ActionResult in project ImmersiveEngineering by BluSunrize.

the class ItemBlockClothDevice method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) {
    if (itemStackIn.getMetadata() != BlockTypes_ClothDevice.BALLOON.getMeta())
        return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand);
    if (playerIn.isSneaking())
        increaseOffset(itemStackIn);
    else {
        Vec3d pos = playerIn.getPositionVector().addVector(0, playerIn.getEyeHeight(), 0).add(playerIn.getLookVec());
        BlockPos bPos = new BlockPos(pos);
        NBTTagCompound nbt = itemStackIn.getTagCompound();
        int offset = nbt == null ? 0 : nbt.getByte("offset");
        bPos = bPos.up(offset);
        if (worldIn.isAirBlock(bPos)) {
            if (!worldIn.isRemote) {
                worldIn.setBlockState(bPos, IEContent.blockClothDevice.getStateFromMeta(BlockTypes_ClothDevice.BALLOON.getMeta()));
                itemStackIn.stackSize--;
                if (itemStackIn.stackSize <= 0)
                    playerIn.setHeldItem(hand, null);
            }
            return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
        }
    }
    return new ActionResult(EnumActionResult.PASS, itemStackIn);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d)

Example 19 with ActionResult

use of net.minecraft.util.ActionResult in project minecolonies by Minecolonies.

the class ItemScepterPermission method onItemRightClick.

/**
     * Handles mid air use.
     *
     * @param worldIn the world
     * @param playerIn the player
     * @param hand the hand
     * @return the result
     */
@Override
@NotNull
public ActionResult<ItemStack> onItemRightClick(final World worldIn, final EntityPlayer playerIn, final EnumHand hand) {
    final ItemStack scepter = playerIn.getHeldItem(hand);
    if (worldIn.isRemote) {
        return new ActionResult<>(EnumActionResult.SUCCESS, scepter);
    }
    if (!scepter.hasTagCompound()) {
        scepter.setTagCompound(new NBTTagCompound());
    }
    final NBTTagCompound compound = scepter.getTagCompound();
    toggleItemMode(playerIn, compound);
    return new ActionResult<>(EnumActionResult.SUCCESS, scepter);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with ActionResult

use of net.minecraft.util.ActionResult in project Pearcel-Mod by MiningMark48.

the class ItemPearcelStaff method onItemRightClick.

@Override
public ActionResult onItemRightClick(ItemStack item, World world, EntityPlayer player, EnumHand hand) {
    if (player.isSneaking()) {
        player.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 5000, 1));
        item.damageItem(50, player);
        return new ActionResult(EnumActionResult.PASS, item);
    } else {
        if (player.posY <= ConfigurationHandler.maxStaffFlyHeight || player.capabilities.isCreativeMode) {
            player.addVelocity(0, 0.5, 0);
        } else {
            if (!world.isRemote) {
                player.sendMessage(new TextComponentTranslation(TextFormatting.DARK_RED + Translate.toLocal("chat.pearcel_staff.weaken")));
                item.damageItem(10, player);
            }
        }
        item.damageItem(1, player);
        return new ActionResult(EnumActionResult.PASS, item);
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) PotionEffect(net.minecraft.potion.PotionEffect)

Aggregations

ActionResult (net.minecraft.util.ActionResult)25 EnumActionResult (net.minecraft.util.EnumActionResult)25 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)16 ItemStack (net.minecraft.item.ItemStack)12 TextComponentString (net.minecraft.util.text.TextComponentString)7 BlockPos (net.minecraft.util.math.BlockPos)4 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)4 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)2 RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)2 RayTraceResult (net.minecraft.util.math.RayTraceResult)2 Vec3d (net.minecraft.util.math.Vec3d)2 Connection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)1 EntityEnderPearcel (com.miningmark48.pearcelmod.entity.EntityEnderPearcel)1 EnumBeeChromosome (forestry.api.apiculture.EnumBeeChromosome)1 Random (java.util.Random)1 Nonnull (javax.annotation.Nonnull)1 DimensionStorage (mcjty.rftoolsdim.dimensions.DimensionStorage)1 EnumGlyphType (mdc.voodoocraft.util.EnumGlyphType)1 Block (net.minecraft.block.Block)1 Entity (net.minecraft.entity.Entity)1