Search in sources :

Example 1 with ActionResult

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

the class ItemPlayerChannelModule 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());
        NBTTagCompound t = item.getTagCompound();
        if (!player.isSneaking()) {
            t.setString("MATCHER_PLAYER_ID", player.getUniqueID().toString());
            t.setString("MATCHER_PLAYER_NAME", player.getDisplayNameString());
            player.sendMessage(new TextComponentString(Helper.localize("message." + ModConstants.Mod.MODID + ":playerSetTo", player.getDisplayNameString())));
            new ActionResult<>(EnumActionResult.SUCCESS, item);
        } else {
            t.removeTag("MATCHER_PLAYER_ID");
            t.removeTag("MATCHER_PLAYER_NAME");
            player.sendMessage(new TextComponentString(Helper.localize("message." + ModConstants.Mod.MODID + ":playerReset")));
            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 2 with ActionResult

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

the class ItemEnderPlate method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack itemStack = player.getHeldItem(hand);
    int dmg = itemStack.getItemDamage();
    if (!world.isRemote)
        if (dmg == 0) {
            itemStack.setItemDamage(1);
        } else
            itemStack.setItemDamage(0);
    return new ActionResult<>(EnumActionResult.SUCCESS, itemStack);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ActionResult

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

the class ItemSunstone method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack itemStack = player.getHeldItem(hand);
    int dmg = itemStack.getItemDamage();
    if (!world.isRemote)
        if (dmg == 0) {
            itemStack.setItemDamage(1);
        } else
            itemStack.setItemDamage(0);
    return new ActionResult<>(EnumActionResult.SUCCESS, itemStack);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ItemStack(net.minecraft.item.ItemStack)

Example 4 with ActionResult

use of net.minecraft.util.ActionResult in project VoodooCraft by Mod-DevCafeTeam.

the class ItemChalk method onItemRightClick.

/**
	 * Changes glyphtype NBT, cycles through all in the {@link EnumGlyphType}
	 */
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) {
    if (playerIn.isSneaking()) {
        NBTTagCompound nbt = NBTHelper.getTagCompound(itemStackIn);
        EnumGlyphType newtype = EnumGlyphType.byIndex(nbt.getInteger(KEY_GLYPH)).next();
        nbt.setInteger(KEY_GLYPH, newtype.ordinal());
        itemStackIn.setTagCompound(nbt);
        return new ActionResult<>(EnumActionResult.SUCCESS, itemStackIn);
    }
    return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EnumGlyphType(mdc.voodoocraft.util.EnumGlyphType)

Example 5 with ActionResult

use of net.minecraft.util.ActionResult in project NetherEx by LogicTechCorp.

the class ItemObsidianBoat method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    float f1 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * 1.0F;
    float f2 = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * 1.0F;
    double d0 = player.prevPosX + (player.posX - player.prevPosX) * 1.0D;
    double d1 = player.prevPosY + (player.posY - player.prevPosY) * 1.0D + (double) player.getEyeHeight();
    double d2 = player.prevPosZ + (player.posZ - player.prevPosZ) * 1.0D;
    Vec3d vec3d = new Vec3d(d0, d1, d2);
    float f3 = MathHelper.cos(-f2 * 0.017453292F - (float) Math.PI);
    float f4 = MathHelper.sin(-f2 * 0.017453292F - (float) Math.PI);
    float f5 = -MathHelper.cos(-f1 * 0.017453292F);
    float f6 = MathHelper.sin(-f1 * 0.017453292F);
    float f7 = f4 * f5;
    float f8 = f3 * f5;
    Vec3d vec3d1 = vec3d.addVector((double) f7 * 5.0D, (double) f6 * 5.0D, (double) f8 * 5.0D);
    RayTraceResult raytraceresult = world.rayTraceBlocks(vec3d, vec3d1, true);
    if (raytraceresult == null) {
        return new ActionResult(EnumActionResult.PASS, stack);
    } else {
        Vec3d vec3d2 = player.getLook(1.0F);
        boolean flag = false;
        List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(player, player.getEntityBoundingBox().addCoord(vec3d2.xCoord * 5.0D, vec3d2.yCoord * 5.0D, vec3d2.zCoord * 5.0D).expandXyz(1.0D));
        for (Entity entity : entities) {
            if (entity.canBeCollidedWith()) {
                AxisAlignedBB axisalignedbb = entity.getEntityBoundingBox().expandXyz((double) entity.getCollisionBorderSize());
                if (axisalignedbb.isVecInside(vec3d)) {
                    flag = true;
                }
            }
        }
        if (flag) {
            return new ActionResult(EnumActionResult.PASS, stack);
        } else if (raytraceresult.typeOfHit != RayTraceResult.Type.BLOCK) {
            return new ActionResult(EnumActionResult.PASS, stack);
        } else {
            Block block = world.getBlockState(raytraceresult.getBlockPos()).getBlock();
            boolean flag1 = block == Blocks.WATER || block == Blocks.FLOWING_WATER;
            EntityObsidianBoat boat = new EntityObsidianBoat(world, raytraceresult.hitVec.xCoord, flag1 ? raytraceresult.hitVec.yCoord - 0.12D : raytraceresult.hitVec.yCoord, raytraceresult.hitVec.zCoord);
            boat.rotationYaw = player.rotationYaw;
            if (!world.getCollisionBoxes(boat, boat.getEntityBoundingBox().expandXyz(-0.1D)).isEmpty()) {
                return new ActionResult(EnumActionResult.FAIL, stack);
            } else {
                if (!world.isRemote) {
                    world.spawnEntity(boat);
                }
                if (!player.capabilities.isCreativeMode) {
                    stack.shrink(1);
                }
                return new ActionResult(EnumActionResult.SUCCESS, stack);
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) EntityObsidianBoat(nex.entity.item.EntityObsidianBoat) RayTraceResult(net.minecraft.util.math.RayTraceResult) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

ActionResult (net.minecraft.util.ActionResult)148 EnumActionResult (net.minecraft.util.EnumActionResult)147 ItemStack (net.minecraft.item.ItemStack)124 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)39 BlockPos (net.minecraft.util.math.BlockPos)31 RayTraceResult (net.minecraft.util.math.RayTraceResult)25 Nonnull (javax.annotation.Nonnull)15 Vec3d (net.minecraft.util.math.Vec3d)14 IBlockState (net.minecraft.block.state.IBlockState)12 TextComponentString (net.minecraft.util.text.TextComponentString)12 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)11 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)8 Entity (net.minecraft.entity.Entity)7 Block (net.minecraft.block.Block)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 TileEntity (net.minecraft.tileentity.TileEntity)4 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)3 RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)3 FluidStack (net.minecraftforge.fluids.FluidStack)3