Java Code Examples for net.minecraft.util.EnumActionResult#SUCCESS

The following examples show how to use net.minecraft.util.EnumActionResult#SUCCESS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DynamiteBehaviour.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack itemstack = player.getHeldItem(hand);

    if (!player.capabilities.isCreativeMode) {
        itemstack.shrink(1);
    }

    if (world.isRemote) {
        return new ActionResult<>(EnumActionResult.SUCCESS, itemstack);
    }

    DynamiteEntity entity = new DynamiteEntity(world, player);
    entity.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 0.7F, 1.0F);

    world.spawnEntity(entity);

    return new ActionResult<>(EnumActionResult.SUCCESS, itemstack);
}
 
Example 2
Source File: ItemExpCapsule.java    From Cyberware with MIT License 6 votes vote down vote up
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
	if (!playerIn.capabilities.isCreativeMode)
	{
		--stack.stackSize;
	}
	
	int xp = 0;
	if (stack.hasTagCompound())
	{
		NBTTagCompound c = stack.getTagCompound();
		if (c.hasKey("xp"))
		{
			xp = c.getInteger("xp");
		}
	}
	
	playerIn.addExperience(xp);
	
	return new ActionResult(EnumActionResult.SUCCESS, stack);
}
 
Example 3
Source File: ItemPebble.java    From ExNihiloAdscensio with MIT License 6 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand)
{
    stack.stackSize--;
    
    world.playSound(player, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
    
    if (!world.isRemote)
    {
        ItemStack thrown = stack.copy();
        thrown.stackSize = 1;
        
        ProjectileStone projectile = new ProjectileStone(world, player);
        projectile.setStack(thrown);
        projectile.setHeadingFromThrower(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 0.5F);
        world.spawnEntity(projectile);
    }
    
    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
 
Example 4
Source File: CoverPlaceBehavior.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    TileEntity tileEntity = world.getTileEntity(pos);
    ICoverable coverable = tileEntity == null ? null : tileEntity.getCapability(GregtechTileCapabilities.CAPABILITY_COVERABLE, null);
    if (coverable == null) {
        return EnumActionResult.PASS;
    }
    EnumFacing coverSide = ICoverable.rayTraceCoverableSide(coverable, player);
    if (coverable.getCoverAtSide(coverSide) != null || !coverable.canPlaceCoverOnSide(coverSide)) {
        return EnumActionResult.PASS;
    }
    if (!world.isRemote) {
        ItemStack itemStack = player.getHeldItem(hand);
        boolean result = coverable.placeCoverOnSide(coverSide, itemStack, coverDefinition);
        if (result && !player.capabilities.isCreativeMode) {
            itemStack.shrink(1);
        }
        return result ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
    }
    return EnumActionResult.SUCCESS;
}
 
Example 5
Source File: GTItemDuctTape.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand,
		EnumFacing facing, float hitX, float hitY, float hitZ) {
	TileEntity tileEntity = worldIn.getTileEntity(pos);
	if (player.isSneaking()) {
		return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
	} else if (tileEntity instanceof IInsulationModifieableConductor) {
		IInsulationModifieableConductor wire = (IInsulationModifieableConductor) tileEntity;
		if (wire.tryAddInsulation()) {
			player.getHeldItem(hand).damageItem(1, player);
			IC2.audioManager.playOnce(player, Ic2Sounds.painterUse);
			return EnumActionResult.SUCCESS;
		} else {
			return EnumActionResult.FAIL;
		}
	} else {
		return EnumActionResult.FAIL;
	}
}
 
Example 6
Source File: HandItem.java    From pycode-minecraft with MIT License 6 votes vote down vote up
@Override
public EnumActionResult onItemUse(ItemStack stackIn, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (world.isRemote) {
        return EnumActionResult.PASS;
    }
    if (stackIn.stackSize != 0) {
        float yaw = player.getHorizontalFacing().getHorizontalAngle();
        NBTTagCompound compound = stackIn.getTagCompound();
        HandEntity entity = new HandEntity(world, compound,
                pos.getX() + .5, pos.getY() + 1.0, pos.getZ() + .5, yaw);
        world.spawnEntityInWorld(entity);
        --stackIn.stackSize;
        return EnumActionResult.SUCCESS;
    } else {
        return EnumActionResult.FAIL;
    }
}
 
Example 7
Source File: SoftHammerBehaviour.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    if (world.isRemote || world.isAirBlock(pos)) {
        return EnumActionResult.PASS;
    }
    ItemStack stack = player.getHeldItem(hand);

    TileEntity tileEntity = world.getTileEntity(pos);
    if (tileEntity != null) {
        IControllable controllable = tileEntity.getCapability(GregtechTileCapabilities.CAPABILITY_CONTROLLABLE, side);
        if (controllable != null) {
            if (controllable.isWorkingEnabled()) {
                controllable.setWorkingEnabled(false);
            } else {
                controllable.setWorkingEnabled(true);
            }
            GTUtility.doDamageItem(stack, cost, false);
            return EnumActionResult.SUCCESS;
        }
    }
    return EnumActionResult.PASS;
}
 
Example 8
Source File: ItemTofuHoe.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack itemstack = player.getHeldItem(hand);

    if (!player.canPlayerEdit(pos.offset(facing), facing, itemstack)) {
        return EnumActionResult.FAIL;
    } else {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();
        if (block == BlockLoader.MOMENTOFU || block == BlockLoader.tofuTerrain) {
            this.setBlock(itemstack, player, worldIn, pos, BlockLoader.TOFUFARMLAND.getDefaultState());
            return EnumActionResult.SUCCESS;
        }

        return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
    }
}
 
Example 9
Source File: ColorSprayBehaviour.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    if (!player.canPlayerEdit(pos, side, stack)) {
        return EnumActionResult.FAIL;
    }
    if (!tryPaintBlock(world, pos, side)) {
        return EnumActionResult.PASS;
    }
    useItemDurability(player, hand, stack, empty.copy());
    return EnumActionResult.SUCCESS;
}
 
Example 10
Source File: ItemBugle.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
    ItemStack stack = playerIn.getHeldItem(handIn);

    playerIn.getCooldownTracker().setCooldown(stack.getItem(), 100);

    playerIn.playSound(TofuSounds.TOFUBUGLE, 20.0F, 1.0F);
    playerIn.addStat(StatList.getObjectUseStats(this));
    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
 
Example 11
Source File: LighterBehaviour.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    if (!player.canPlayerEdit(pos, side, stack)) {
        return EnumActionResult.FAIL;
    }
    if (!tryIgniteBlock(world, pos.offset(side))) {
        return EnumActionResult.PASS;
    }
    useItemDurability(player, hand, stack, ItemStack.EMPTY);
    return EnumActionResult.SUCCESS;
}
 
Example 12
Source File: ItemFood.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
    ItemStack stack = playerIn.getHeldItem(handIn);

    if (playerIn.canEat(content.alwaysEdible.get(stack.getMetadata()).orElse(false)))
    {
        playerIn.setActiveHand(handIn);
        return new ActionResult<>(EnumActionResult.SUCCESS, stack);
    } else
    {
        return new ActionResult<>(EnumActionResult.FAIL, stack);
    }
}
 
Example 13
Source File: ItemTraverseWoodDoor.java    From Traverse-Legacy-1-12-2 with MIT License 5 votes vote down vote up
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (facing != EnumFacing.UP) {
        return EnumActionResult.FAIL;
    } else {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();

        if (!block.isReplaceable(worldIn, pos)) {
            pos = pos.offset(facing);
        }

        ItemStack itemstack = player.getHeldItem(hand);

        if (player.canPlayerEdit(pos, facing, itemstack) && this.block.canPlaceBlockAt(worldIn, pos)) {
            EnumFacing enumfacing = EnumFacing.fromAngle((double) player.rotationYaw);
            int i = enumfacing.getFrontOffsetX();
            int j = enumfacing.getFrontOffsetZ();
            boolean flag = i < 0 && hitZ < 0.5F || i > 0 && hitZ > 0.5F || j < 0 && hitX > 0.5F || j > 0 && hitX < 0.5F;
            placeDoor(worldIn, pos, enumfacing, this.block, flag);
            SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), worldIn, pos, player);
            worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
            itemstack.shrink(1);
            return EnumActionResult.SUCCESS;
        } else {
            return EnumActionResult.FAIL;
        }
    }
}
 
Example 14
Source File: ItemFairyDust.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer entityPlayer, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	if (world.isRemote) return EnumActionResult.SUCCESS;
	EntityJumpPad pad = new EntityJumpPad(world);
	pad.setPosition(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5);
	world.spawnEntity(pad);
	entityPlayer.getHeldItem(hand).setCount(entityPlayer.getHeldItem(hand).getCount() - 1);
	return EnumActionResult.SUCCESS;
}
 
Example 15
Source File: PlungerBehaviour.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    TileEntity tileEntity = world.getTileEntity(pos);
    if (tileEntity == null) {
        return EnumActionResult.PASS;
    }
    IFluidHandler fluidHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
    if (fluidHandler == null) {
        return EnumActionResult.PASS;
    }
    ItemStack toolStack = player.getHeldItem(hand);
    boolean isShiftClick = player.isSneaking();
    IFluidHandler handlerToRemoveFrom = isShiftClick ?
        (fluidHandler instanceof FluidHandlerProxy ? ((FluidHandlerProxy) fluidHandler).input : null) :
        (fluidHandler instanceof FluidHandlerProxy ? ((FluidHandlerProxy) fluidHandler).output : fluidHandler);

    if (handlerToRemoveFrom != null && GTUtility.doDamageItem(toolStack, cost, false)) {
        if (!world.isRemote) {
            FluidStack drainStack = handlerToRemoveFrom.drain(1000, true);
            int amountOfFluid = drainStack == null ? 0 : drainStack.amount;
            if (amountOfFluid > 0) {
                player.playSound(SoundEvents.ENTITY_SLIME_SQUISH, 1.0f, amountOfFluid / 1000.0f);
            }
        }
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.PASS;
}
 
Example 16
Source File: CoverItemFilter.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public EnumActionResult onScrewdriverClick(EntityPlayer playerIn, EnumHand hand, CuboidRayTraceResult hitResult) {
    if (!playerIn.world.isRemote) {
        openUI((EntityPlayerMP) playerIn);
    }
    return EnumActionResult.SUCCESS;
}
 
Example 17
Source File: PythonBookItem.java    From pycode-minecraft with MIT License 5 votes vote down vote up
@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack itemstack, World world, EntityPlayer playerIn, EnumHand hand) {
    FMLLog.info("Book onItemRightClick stack=%s, hand=%s", itemstack, hand);
    // don't activate the GUI if in offhand; don't do *anything*
    if (hand == EnumHand.OFF_HAND) return new ActionResult(EnumActionResult.FAIL, itemstack);

    PyCode.proxy.openBook(playerIn, itemstack);
    return new ActionResult(EnumActionResult.SUCCESS, itemstack);
}
 
Example 18
Source File: ItemRiceSeeds.java    From Sakura_mod with MIT License 4 votes vote down vote up
@Override
  public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
      ItemStack itemstack = playerIn.getHeldItem(handIn);
      RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, true);

      if (raytraceresult == null) {
          return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
      }
if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK) {
    BlockPos blockpos = raytraceresult.getBlockPos();

    if (!worldIn.isBlockModifiable(playerIn, blockpos) || !playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemstack)) {
        return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
    }

    BlockPos blockpos1 = blockpos.up();
    IBlockState iblockstate = worldIn.getBlockState(blockpos);

    if (iblockstate.getMaterial() == Material.WATER && iblockstate.getValue(BlockLiquid.LEVEL).intValue() == 0 && worldIn.isAirBlock(blockpos1)) {
        // special case for handling block placement with water lilies
        net.minecraftforge.common.util.BlockSnapshot blocksnapshot = net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(worldIn, blockpos1);
        worldIn.setBlockState(blockpos1, BlockLoader.RICECROP.getDefaultState());
        if (net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(playerIn, blocksnapshot, net.minecraft.util.EnumFacing.UP, handIn).isCanceled()) {
            blocksnapshot.restore(true, false);
            return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
        }

        worldIn.setBlockState(blockpos1, BlockLoader.RICECROP.getDefaultState(), 11);

        if (playerIn instanceof EntityPlayerMP) {
            CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) playerIn, blockpos1, itemstack);
        }

        if (!playerIn.capabilities.isCreativeMode) {
            itemstack.shrink(1);
        }

        playerIn.addStat(StatList.getObjectUseStats(this));
        worldIn.playSound(playerIn, blockpos, SoundEvents.BLOCK_WATERLILY_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
    }
}

return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
  }
 
Example 19
Source File: ItemWrench.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos,
    EnumHand hand,
    EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (worldIn.isRemote) {
        return EnumActionResult.SUCCESS;
    }

    if (player.isSneaking() && !VSConfig.wrenchModeless) {
        this.mode = EnumWrenchMode.values()[(this.mode.ordinal() + 1) % EnumWrenchMode.values().length]; // Switch to the next mode
        player.sendMessage(new TextComponentString(
            TextFormatting.BLUE + I18n.format("tooltip.vs_control.wrench_switched", this.mode.toString()))); // Say in chat
        return EnumActionResult.SUCCESS;
    }

    TileEntity blockTile = worldIn.getTileEntity(pos);
    boolean shouldConstruct = this.mode == EnumWrenchMode.CONSTRUCT || VSConfig.wrenchModeless;
    boolean shouldDeconstruct = this.mode == EnumWrenchMode.DECONSTRUCT || VSConfig.wrenchModeless;
    if (blockTile instanceof ITileEntityMultiblockPart) {
        ITileEntityMultiblockPart part = (ITileEntityMultiblockPart) blockTile;
        shouldConstruct = shouldConstruct && !part.isPartOfAssembledMultiblock();
        shouldDeconstruct = shouldDeconstruct && part.isPartOfAssembledMultiblock();
    } else if (blockTile instanceof TileEntityGearbox) {
        shouldConstruct = true;
    } else {
        return EnumActionResult.PASS;
    }
    if (shouldConstruct) {
        if (blockTile instanceof ITileEntityMultiblockPart) {
            if (((ITileEntityMultiblockPart) blockTile).attemptToAssembleMultiblock(worldIn, pos, facing)) {
                return EnumActionResult.SUCCESS;
            }
        } else if (blockTile instanceof TileEntityGearbox) {
            ((TileEntityGearbox) blockTile).setInputFacing(
                player.isSneaking() ? facing.getOpposite() : facing);
        }
    } else if (shouldDeconstruct) {
        ((ITileEntityMultiblockPart) blockTile).disassembleMultiblock();
        return EnumActionResult.SUCCESS;
    }

    return EnumActionResult.PASS;
}
 
Example 20
Source File: GTItemMagnifyingGlass.java    From GT-Classic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX,
		float hitY, float hitZ, EnumHand hand) {
	Block block = world.getBlockState(pos).getBlock();
	if (player.isSneaking() || hand == EnumHand.OFF_HAND) {
		return EnumActionResult.PASS;
	}
	if (IC2.platform.isRendering()) {
		return EnumActionResult.SUCCESS;
	}
	TileEntity tileEntity = world.getTileEntity(pos);
	if (GTConfig.general.enableMagnifyingGlassGivesEUTooltips && tileEntity instanceof IEnergySink) {
		IEnergySink euSink = (IEnergySink) tileEntity;
		IC2.platform.messagePlayer(player, "Input Tier: " + euSink.getSinkTier());
		IC2.platform.messagePlayer(player, "Input Max: " + EnergyNet.instance.getPowerFromTier(euSink.getSinkTier())
				+ " EU");
	}
	if (tileEntity instanceof IProgressMachine) {
		IProgressMachine progress = (IProgressMachine) tileEntity;
		IC2.platform.messagePlayer(player, "Progress: "
				+ +(Math.round((progress.getProgress() / progress.getMaxProgress()) * 100)) + "%");
	}
	if (tileEntity instanceof IGTMultiTileStatus) {
		IGTMultiTileStatus multi = (IGTMultiTileStatus) tileEntity;
		IC2.platform.messagePlayer(player, "Correct Strucuture: " + multi.getStructureValid());
	}
	if (tileEntity instanceof IGTDebuggableTile) {
		LinkedHashMap<String, Boolean> data = new LinkedHashMap<>();
		IGTDebuggableTile debug = (IGTDebuggableTile) tileEntity;
		debug.getData(data);
		for (Map.Entry<String, Boolean> entry : data.entrySet()) {
			if (!entry.getValue()) {
				IC2.platform.messagePlayer(player, entry.getKey());
			}
		}
	}
	if (GTBedrockOreHandler.isBedrockOre(block)) {
		ItemStack resource = GTBedrockOreHandler.getResource(block);
		String amount = resource.getCount() > 1 ? " x " + resource.getCount() : "";
		IC2.platform.messagePlayer(player, "Contains: " + GTBedrockOreHandler.getResource(block).getDisplayName()
				+ amount);
	}
	world.playSound(null, player.getPosition(), SoundEvents.ENTITY_VILLAGER_AMBIENT, SoundCategory.PLAYERS, 1.0F, 1.0F);
	return EnumActionResult.SUCCESS;
}