Search in sources :

Example 21 with ActionResult

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

the class ItemTPPearcel method onItemRightClick.

@Override
public ActionResult onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
    if (!stack.hasTagCompound()) {
        stack.setTagCompound(new NBTTagCompound());
        stack.getTagCompound().setDouble("tpX", player.posX);
        stack.getTagCompound().setDouble("tpY", player.posY);
        stack.getTagCompound().setDouble("tpZ", player.posZ);
        stack.getTagCompound().setInteger("dim", player.dimension);
        stack.getTagCompound().setFloat("yaw", player.rotationYaw);
        stack.getTagCompound().setFloat("pitch", player.rotationPitch);
        stack.getTagCompound().setBoolean("set", true);
    }
    if (player.isSneaking()) {
        stack.getTagCompound().setDouble("tpX", player.posX);
        stack.getTagCompound().setDouble("tpY", player.posY);
        stack.getTagCompound().setDouble("tpZ", player.posZ);
        stack.getTagCompound().setInteger("dim", player.dimension);
        stack.getTagCompound().setFloat("yaw", player.rotationYaw);
        stack.getTagCompound().setFloat("pitch", player.rotationPitch);
        stack.getTagCompound().setBoolean("set", true);
        if (!world.isRemote) {
            player.sendMessage(new TextComponentTranslation(TextFormatting.DARK_GREEN + (Translate.toLocal("chat.tpPearcel.location.set"))));
        }
    } else {
        tpX = stack.getTagCompound().getDouble("tpX");
        tpY = stack.getTagCompound().getDouble("tpY");
        tpZ = stack.getTagCompound().getDouble("tpZ");
        dim = stack.getTagCompound().getInteger("dim");
        yaw = stack.getTagCompound().getFloat("yaw");
        pitch = stack.getTagCompound().getFloat("pitch");
        if (!stack.getTagCompound().getBoolean("set")) {
            if (!world.isRemote) {
                player.sendMessage(new TextComponentTranslation(TextFormatting.RED + (Translate.toLocal("chat.tpPearcel.location.notSet"))));
            }
        } else {
            if (player.dimension == dim) {
                //player.setPositionAndUpdate(tpX, tpY, tpZ);
                player.setLocationAndAngles(tpX, tpY, tpZ, yaw, pitch);
                player.addStat(Achievements.achievement_use_tp_pearcel);
                if (!world.isRemote) {
                    player.sendMessage(new TextComponentTranslation(TextFormatting.GOLD + (Translate.toLocal("chat.tpPearcel.tp"))));
                }
                if (!player.capabilities.isCreativeMode) {
                    if (player.inventory.hasItemStack(new ItemStack(ModItems.pearcel_item))) {
                        player.inventory.deleteStack(new ItemStack(ModItems.pearcel_item, 1));
                    } else {
                        stack.damageItem(1, player);
                    }
                }
            } else {
                if (!world.isRemote) {
                    player.sendMessage(new TextComponentTranslation(TextFormatting.RED + (Translate.toLocal("chat.tpPearcel.wrongDim"))));
                }
            }
        }
    }
    return new ActionResult(EnumActionResult.PASS, stack);
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 22 with ActionResult

use of net.minecraft.util.ActionResult in project ConvenientAdditions by Necr0.

the class ItemLocationModule method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack item = player.getHeldItem(hand);
    if (!world.isRemote) {
        if (!item.hasTagCompound())
            item.setTagCompound(new NBTTagCompound());
        if (player.isSneaking()) {
            item.getTagCompound().removeTag("MODULE_LOCATION");
            player.sendMessage(new TextComponentString(Helper.localize("message." + ModConstants.Mod.MODID + ":locationReset")));
            return new ActionResult<>(EnumActionResult.SUCCESS, item);
        }
    }
    return new ActionResult<>(EnumActionResult.PASS, item);
}
Also used : 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 23 with ActionResult

use of net.minecraft.util.ActionResult in project RecurrentComplex by Ivorforce.

the class ItemBlockSelectorFloating method onItemRightClick.

@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
    ItemStack itemStackIn = playerIn.getHeldItem(hand);
    if (worldIn.isRemote) {
        BlockPos position = getHoveredBlock(playerIn, getSelectionRange(itemStackIn));
        sendClickToServer(itemStackIn, worldIn, playerIn, position);
    }
    return new ActionResult<>(EnumActionResult.SUCCESS, itemStackIn);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 24 with ActionResult

use of net.minecraft.util.ActionResult in project Railcraft by Railcraft.

the class ItemFilterBeeGenome method onItemRightClick.

@Optional.Method(modid = ForestryPlugin.FORESTRY_ID)
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
    NBTTagCompound nbt = InvTools.getItemDataRailcraft(stack, "filter");
    if (nbt != null) {
        try {
            EnumBeeChromosome chromosome = EnumBeeChromosome.SPECIES;
            try {
                chromosome = EnumBeeChromosome.valueOf(nbt.getString("chromosome"));
            } catch (IllegalArgumentException ignored) {
            }
            chromosome = EnumTools.next(chromosome, EnumBeeChromosome.values());
            nbt.setString("chromosome", chromosome.name());
        } catch (Throwable throwable) {
            Game.logErrorAPI(Mod.FORESTRY.modId, throwable, EnumBeeChromosome.class);
        }
    }
    return new ActionResult<>(EnumActionResult.SUCCESS, stack.copy());
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EnumBeeChromosome(forestry.api.apiculture.EnumBeeChromosome)

Example 25 with ActionResult

use of net.minecraft.util.ActionResult in project Railcraft by Railcraft.

the class ItemFluidContainer method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
    RayTraceResult mop = rayTrace(world, player, false);
    //noinspection ConstantConditions
    if (mop != null && mop.typeOfHit == RayTraceResult.Type.BLOCK) {
        BlockPos pos = mop.getBlockPos();
        if (!world.isBlockModifiable(player, pos))
            return new ActionResult<>(EnumActionResult.FAIL, stack);
        pos = pos.offset(mop.sideHit);
        if (!player.canPlayerEdit(pos, mop.sideHit, stack))
            return new ActionResult<>(EnumActionResult.FAIL, stack);
        if (tryPlaceContainedLiquid(world, pos) && !player.capabilities.isCreativeMode) {
            ItemStack empty = getContainerItem(stack);
            if (InvTools.isEmpty(empty)) {
                empty = stack.copy();
                empty.stackSize = 0;
            }
            return new ActionResult<>(EnumActionResult.SUCCESS, empty);
        }
    }
    return new ActionResult<>(EnumActionResult.PASS, stack);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

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