Java Code Examples for net.minecraft.util.ActionResult#newResult()
The following examples show how to use
net.minecraft.util.ActionResult#newResult() .
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: GTItemDestructoPack.java From GT-Classic with GNU Lesser General Public License v3.0 | 6 votes |
@Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { if (playerIn.isSneaking() && playerIn.isCreative()) { for (int i = 0; i < playerIn.inventory.getSizeInventory(); i++) { Item item = playerIn.inventory.getStackInSlot(i).getItem(); if (!(item instanceof GTItemDestructoPack || item instanceof GTItemCreativeScanner || item instanceof GTItemSurvivalScanner || item instanceof GTItemMagnifyingGlass)) { playerIn.inventory.setInventorySlotContents(i, ItemStack.EMPTY); } } return ActionResult.newResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); } if (IC2.platform.isSimulating()) { IC2.platform.launchGui(playerIn, this.getInventory(playerIn, handIn, playerIn.getHeldItem(handIn)), handIn); } return ActionResult.newResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); }
Example 2
Source File: GTItemFluidTube.java From GT-Classic with GNU Lesser General Public License v3.0 | 6 votes |
public ActionResult<ItemStack> tryPickUpFluid(@Nonnull World world, @Nonnull EntityPlayer player, @Nonnull EnumHand hand, ItemStack itemstack, FluidStack fluidStack) { RayTraceResult mop = this.rayTrace(world, player, true); ActionResult<ItemStack> ret = ForgeEventFactory.onBucketUse(player, world, itemstack, mop); if (ret != null) return ret; if (mop == null) { return ActionResult.newResult(EnumActionResult.PASS, itemstack); } BlockPos clickPos = mop.getBlockPos(); if (world.isBlockModifiable(player, clickPos)) { FluidActionResult result = FluidUtil.tryPickUpFluid(itemstack, player, world, clickPos, mop.sideHit); if (result.isSuccess()) { ItemHandlerHelper.giveItemToPlayer(player, result.getResult()); itemstack.shrink(1); return ActionResult.newResult(EnumActionResult.SUCCESS, itemstack); } } return ActionResult.newResult(EnumActionResult.FAIL, itemstack); }
Example 3
Source File: GTItemSprayCan.java From GT-Classic with GNU Lesser General Public License v3.0 | 6 votes |
@Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { if (playerIn.isSneaking() && handIn == EnumHand.MAIN_HAND) { ItemStack playerStack = playerIn.getHeldItemMainhand(); NBTTagCompound nbt = StackUtil.getOrCreateNbtData(playerStack); if (nbt.hasKey(COLOR)) { int i = nbt.getInteger(COLOR); if (i + 1 > 15) { nbt.setInteger(COLOR, 0); } else { nbt.setInteger(COLOR, i + 1); } } else { nbt.setInteger(COLOR, 0); } if (!IC2.platform.isSimulating()) { IC2.audioManager.playOnce(playerIn, Ic2Sounds.cutterUse); } return ActionResult.newResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); } return ActionResult.newResult(EnumActionResult.PASS, playerIn.getHeldItem(handIn)); }
Example 4
Source File: ThrowableUranium238Handler.java From Production-Line with MIT License | 6 votes |
@Override public ActionResult<ItemStack> onRightClick(ItemStack itemStack, EntityPlayer entityPlayer, EnumHand hand) { ItemStack target = IC2Items.getItem("nuclear", "uranium_238"); if (itemStack.isItemEqual(target)) { if (PLConfig.instance.throwableUran238) { if (!entityPlayer.capabilities.isCreativeMode) { --itemStack.stackSize; } entityPlayer.world.playSound(entityPlayer, entityPlayer.getPosition(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 0.5F, 0.4F / (new Random().nextFloat() * 0.4F + 0.8F)); if (!entityPlayer.world.isRemote) { entityPlayer.world.spawnEntity(new EntityThrownItem(entityPlayer.world, entityPlayer, itemStack)); } } return ActionResult.newResult(EnumActionResult.SUCCESS, itemStack); } return ActionResult.newResult(EnumActionResult.PASS, itemStack); }
Example 5
Source File: ElectricStats.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { ItemStack itemStack = player.getHeldItem(hand); IElectricItem electricItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null); if(electricItem != null && electricItem.canProvideChargeExternally() && player.isSneaking()) { if(!world.isRemote) { boolean isInDischargeMode = isInDishargeMode(itemStack); String locale = "metaitem.electric.discharge_mode." + (isInDischargeMode ? "disabled" : "enabled"); player.sendStatusMessage(new TextComponentTranslation(locale), true); setInDischargeMode(itemStack, !isInDischargeMode); } return ActionResult.newResult(EnumActionResult.SUCCESS, itemStack); } return ActionResult.newResult(EnumActionResult.PASS, itemStack); }
Example 6
Source File: ToggleEnergyConsumerBehavior.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { ItemStack itemStack = player.getHeldItem(hand); if(player.isSneaking()) { IElectricItem electricItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null); boolean isItemActive = isItemActive(itemStack); if(isItemActive) { setItemActive(itemStack, false); } else if(electricItem != null && drainActivationEnergy(electricItem, true)) { setItemActive(itemStack, true); } } return ActionResult.newResult(EnumActionResult.PASS, itemStack); }
Example 7
Source File: IntCircuitBehaviour.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { ItemStack heldItem = player.getHeldItem(hand); if (!world.isRemote) { PlayerInventoryHolder holder = new PlayerInventoryHolder(player, hand); holder.openUI(); } return ActionResult.newResult(EnumActionResult.SUCCESS, heldItem); }
Example 8
Source File: ModeSwitchBehavior.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { ItemStack itemStack = player.getHeldItem(hand); if(player.isSneaking()) { T currentMode = getModeFromItemStack(itemStack); int currentModeIndex = ArrayUtils.indexOf(enumConstants, currentMode); T nextMode = enumConstants[(currentModeIndex + 1) % enumConstants.length]; setModeForItemStack(itemStack, nextMode); ITextComponent newModeComponent = new TextComponentTranslation(nextMode.getUnlocalizedName()); ITextComponent textComponent = new TextComponentTranslation("metaitem.behavior.mode_switch.mode_switched", newModeComponent); player.sendStatusMessage(textComponent, true); return ActionResult.newResult(EnumActionResult.SUCCESS, itemStack); } return ActionResult.newResult(EnumActionResult.PASS, itemStack); }
Example 9
Source File: GTItemBaseToggleItem.java From GT-Classic with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { IC2.audioManager.playOnce(playerIn, toggleSound); if (IC2.platform.isSimulating()) { NBTTagCompound nbt = StackUtil.getOrCreateNbtData(playerIn.getHeldItem(handIn)); boolean result = !nbt.getBoolean(ACTIVE); nbt.setBoolean(ACTIVE, result); } return ActionResult.newResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); }
Example 10
Source File: GTItemElectromagnet.java From GT-Classic with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { IC2.audioManager.playOnce(playerIn, Ic2Sounds.forceFieldOp); if (IC2.platform.isSimulating()) { NBTTagCompound nbt = StackUtil.getOrCreateNbtData(playerIn.getHeldItem(handIn)); boolean result = !nbt.getBoolean(ACTIVE); nbt.setBoolean(ACTIVE, result); } return ActionResult.newResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn)); }
Example 11
Source File: GTItemFluidTube.java From GT-Classic with GNU Lesser General Public License v3.0 | 5 votes |
public ActionResult<ItemStack> tryPlaceFluid(@Nonnull World world, @Nonnull EntityPlayer player, @Nonnull EnumHand hand, ItemStack itemstack, FluidStack fluidStack) { RayTraceResult mop = this.rayTrace(world, player, false); ActionResult<ItemStack> ret = ForgeEventFactory.onBucketUse(player, world, itemstack, mop); if (ret != null) return ret; if (mop == null || mop.typeOfHit != RayTraceResult.Type.BLOCK) { return ActionResult.newResult(EnumActionResult.PASS, itemstack); } BlockPos clickPos = mop.getBlockPos(); if (world.isBlockModifiable(player, clickPos)) { BlockPos targetPos = clickPos.offset(mop.sideHit); if (player.canPlayerEdit(targetPos, mop.sideHit, itemstack)) { FluidActionResult result = FluidUtil.tryPlaceFluid(player, world, targetPos, itemstack, fluidStack); if (result.isSuccess() && !player.capabilities.isCreativeMode) { player.addStat(StatList.getObjectUseStats(this)); itemstack.shrink(1); ItemStack emptyStack = new ItemStack(GTItems.testTube); if (itemstack.isEmpty()) { return ActionResult.newResult(EnumActionResult.SUCCESS, emptyStack); } else { ItemHandlerHelper.giveItemToPlayer(player, emptyStack); return ActionResult.newResult(EnumActionResult.SUCCESS, itemstack); } } } } return ActionResult.newResult(EnumActionResult.FAIL, itemstack); }
Example 12
Source File: ItemGeneric.java From OpenModsLib with MIT License | 5 votes |
@Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { final ItemStack itemStack = player.getHeldItem(hand); IMetaItem meta = getMeta(itemStack.getMetadata()); return meta != null ? meta.onItemRightClick(itemStack, world, player, hand) : ActionResult.newResult(EnumActionResult.PASS, itemStack); }
Example 13
Source File: IItemBehaviour.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
default ActionResult<ItemStack> onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { return ActionResult.newResult(EnumActionResult.PASS, player.getHeldItem(hand)); }
Example 14
Source File: IItemBehaviour.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
default ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { return ActionResult.newResult(EnumActionResult.PASS, player.getHeldItem(hand)); }
Example 15
Source File: GTItemCreativeScanner.java From GT-Classic with GNU Lesser General Public License v3.0 | 4 votes |
@Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { return ActionResult.newResult(EnumActionResult.FAIL, playerIn.getHeldItem(handIn)); }
Example 16
Source File: MetaGeneric.java From OpenModsLib with MIT License | 4 votes |
@Override public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack itemStack, World world, EntityPlayer player, EnumHand hand) { return ActionResult.newResult(EnumActionResult.PASS, itemStack); }