net.minecraft.util.ActionResult Java Examples

The following examples show how to use net.minecraft.util.ActionResult. 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: ItemLooseRock.java    From TFC2 with GNU General Public License v3.0 7 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
	ItemStack itemStackIn = playerIn.getHeldItem(handIn);
	if(itemStackIn.getCount() < 2)
	{
		return new ActionResult(EnumActionResult.FAIL, itemStackIn);
	}

	PlayerInfo pi = PlayerManagerTFC.getInstance().getPlayerInfoFromPlayer(playerIn);

	pi.specialCraftingType = itemStackIn;
	pi.specialCraftingTypeAlternate = null;
	if(!worldIn.isRemote)
		playerIn.openGui(TFC.instance, 0, worldIn, playerIn.getPosition().getX(), playerIn.getPosition().getY(), playerIn.getPosition().getZ());

	return new ActionResult(EnumActionResult.PASS, itemStackIn);
}
 
Example #2
Source File: CarpetDispenserBehaviours.java    From carpet-extra with GNU Lesser General Public License v3.0 7 votes vote down vote up
@Override
protected ItemStack dispenseSilently(BlockPointer source, ItemStack stack) {
    if(!CarpetExtraSettings.dispensersToggleThings) {
        return super.dispenseSilently(source, stack);
    }

    World world = source.getWorld();
    Direction direction = (Direction) source.getBlockState().get(DispenserBlock.FACING);
    BlockPos pos = source.getBlockPos().offset(direction);
    BlockState state = world.getBlockState(pos);  
    if(toggleable.contains(state.getBlock())) {
        ActionResult result = state.onUse(
            world, 
            null,
            Hand.MAIN_HAND,
            new BlockHitResult(
                new Vec3d(new Vec3i(pos.getX(), pos.getY(), pos.getZ())), 
                direction, 
                pos,
                false
            )
        );
        if(result.isAccepted()) return stack; // success or consume
    }
    return super.dispenseSilently(source, stack);
}
 
Example #3
Source File: ItemPortalScaler.java    From enderutilities 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 stack = player.getHeldItem(hand);

    if (EntityUtils.isEntityCollidingWithBlockSpace(world, player, Blocks.PORTAL) == false)
    {
        return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
    }

    if (world.isRemote == false)
    {
        this.usePortalWithPortalScaler(stack, world, player);
    }

    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
 
Example #4
Source File: ItemEnderPart.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand)
{
    ItemStack stack = playerIn.getHeldItem(hand);

    if (worldIn.isRemote == false && this.getModuleType(stack).equals(ModuleType.TYPE_MEMORY_CARD_ITEMS))
    {
        if (playerIn.isSneaking())
        {
            OwnerData.removeOwnerDataFromItem(stack, playerIn);
        }
        else
        {
            OwnerData.togglePrivacyModeOnItem(stack, playerIn);
        }

        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
    }

    return super.onItemRightClick(worldIn, playerIn, hand);
}
 
Example #5
Source File: GTItemFluidTube.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #6
Source File: ItemSakuraDiamond.java    From Sakura_mod with MIT License 6 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, false);

      if (raytraceresult != null && raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK && worldIn.getBlockState(raytraceresult.getBlockPos()).getBlock() == Blocks.END_PORTAL_FRAME) {
          return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
      }
if (worldIn.isRemote) {
    int j = worldIn.rand.nextInt(2) * 2 - 1;
    int k = worldIn.rand.nextInt(2) * 2 - 1;

    double d0 = playerIn.getPosition().getX() + 0.25D * j;
    double d1 = playerIn.getPosition().getY() + 1D;
    double d2 = playerIn.getPosition().getZ() + 0.25D * k;
    double d3 = worldIn.rand.nextFloat() * j * 0.1D;
    double d4 = (worldIn.rand.nextFloat() * 0.055D) + 0.015D;
    double d5 = worldIn.rand.nextFloat() * k * 0.1D;

    SakuraMain.proxy.spawnParticle(SakuraParticleType.LEAVESSAKURA, d0, d1, d2, d3, -d4, d5);
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
  }
 
Example #7
Source File: ItemHandyBag.java    From enderutilities 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 stack = player.getHeldItem(hand);

    if (world.isRemote == false)
    {
        // These two lines are to fix the UUID being missing the first time the GUI opens,
        // if the item is grabbed from the creative inventory or from JEI or from /give
        NBTUtils.getUUIDFromItemStack(stack, "UUID", true);
        player.openContainer.detectAndSendChanges();

        player.openGui(EnderUtilities.instance, ReferenceGuiIds.GUI_ID_HANDY_BAG_RIGHT_CLICK, world,
                (int)player.posX, (int)player.posY, (int)player.posZ);
    }

    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
 
Example #8
Source File: ItemBomb.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
	ItemStack stack = player.getHeldItem(hand);

	if (!world.isRemote) {
		EntityBomb bomb = new EntityBomb(world, player);
		bomb.setBombItem(stack);
		bomb.setPosition(player.posX, player.posY + player.eyeHeight, player.posZ);
		bomb.shoot(player, player.rotationPitch, player.rotationYaw, 0.0f, 1.5f, 1.0f);
		stack.shrink(1);
		world.spawnEntity(bomb);
		bomb.velocityChanged = true;
	}

	player.getCooldownTracker().setCooldown(this, 20);

	return new ActionResult<>(EnumActionResult.PASS, stack);
}
 
Example #9
Source File: GTItemDestructoPack.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #10
Source File: HallowedLogBlock.java    From the-hallow with MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
	ItemStack stack = player.getStackInHand(hand);
	if (stack.isEmpty() || !(stack.getItem() instanceof MiningToolItem)) {
		return ActionResult.PASS;
	}
	
	MiningToolItem tool = (MiningToolItem) stack.getItem();
	if (stripped != null && (tool.isEffectiveOn(state) || tool.getMiningSpeed(stack, state) > 1.0F)) {
		world.playSound(player, pos, SoundEvents.ITEM_AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F);
		if (!world.isClient) {
			BlockState target = stripped.getDefaultState().with(LogBlock.AXIS, state.get(LogBlock.AXIS));
			world.setBlockState(pos, target);
			stack.damage(1, player, consumedPlayer -> consumedPlayer.sendToolBreakStatus(hand));
		}
		return ActionResult.SUCCESS;
	}
	return ActionResult.PASS;
}
 
Example #11
Source File: HallowedTreasureChestBlock.java    From the-hallow with MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState blockState, World world, BlockPos pos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
	if (hand == Hand.MAIN_HAND) {
		float x = pos.getX() + .49f;
		float y = pos.getY();
		float z = pos.getZ() + .51f;
		
		HallowedTreasureChestEntity entity = new HallowedTreasureChestEntity(world, x, y, z, true, blockState.get(FACING).asRotation());
		entity.updatePosition(x, y, z);
		world.spawnEntity(entity);
		
		return ActionResult.SUCCESS;
	}
	
	return ActionResult.PASS;
}
 
Example #12
Source File: ItemThatMakesYouSayDab.java    From CommunityMod with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
	if(!world.isRemote) {
		String text = Math.random() >= 0.01 ? "Dab" : "Neat (is a mod by Vazkii)";
		world.getMinecraftServer().getPlayerList().sendMessage(new TextComponentTranslation("chat.type.text", player.getName(), text));
		
		if(Dabbbbb.whenUBoppin) {
			for(int i = 0; i < 10; i++) {
				world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.PLAYERS, 1, (i / 10f) + 0.5f);
			}
			player.motionY += 10;
			player.velocityChanged = true;
		}
	}
	return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}
 
Example #13
Source File: GuiItem.java    From LibGui with MIT License 6 votes vote down vote up
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
	if (world.isClient) {
		openScreen(); // In its own method to prevent class loading issues
	}
	
	return new TypedActionResult<ItemStack>(ActionResult.SUCCESS, (hand==Hand.MAIN_HAND) ? player.getMainHandStack() : player.getOffHandStack());
}
 
Example #14
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 #15
Source File: ItemLocationBound.java    From enderutilities 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 stack = player.getHeldItem(hand);

    if (player.isSneaking())
    {
        if (world.isRemote == false)
        {
            this.setTarget(stack, player, true);
        }

        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
    }

    return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
}
 
Example #16
Source File: WrappingUtil.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static ActionResult convert(InteractionResult result) {
    switch (result) {
        case SUCCESS:
            return ActionResult.SUCCESS;
        case CONSUME:
            return ActionResult.CONSUME;
        case FAILURE:
            return ActionResult.FAIL;
        default:
        case IGNORE:
            return ActionResult.PASS;
    }
}
 
Example #17
Source File: BlockWrapper.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static ActionResult statisOnUse(org.sandboxpowered.sandbox.api.state.BlockState blockState_1, org.sandboxpowered.sandbox.api.world.World world_1, Position blockPos_1, PlayerEntity playerEntity_1, Hand hand_1, BlockHitResult blockHitResult_1, Block block) {
    InteractionResult result = block.onBlockUsed(
            world_1,
            blockPos_1,
            blockState_1,
            playerEntity_1,
            hand_1 == Hand.MAIN_HAND ? org.sandboxpowered.sandbox.api.entity.player.Hand.MAIN_HAND : org.sandboxpowered.sandbox.api.entity.player.Hand.OFF_HAND,
            WrappingUtil.convert(blockHitResult_1.getSide()),
            (Vec3f) (Object) new Vector3f(blockHitResult_1.getPos())
    );
    return WrappingUtil.convert(result);
}
 
Example #18
Source File: ItemLinkCrystal.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
    ItemStack stack = player.getHeldItem(hand);

    if (stack.getMetadata() == TYPE_PORTAL)
    {
        return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
    }

    return super.onItemRightClick(world, player, hand);
}
 
Example #19
Source File: ItemSyringe.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
	ItemStack stack = player.getHeldItem(hand);
	if (getItemUseAction(stack) == EnumAction.BOW) {
		if (world.isRemote && (Minecraft.getMinecraft().currentScreen != null)) {
			return new ActionResult<>(EnumActionResult.FAIL, stack);
		} else {
			player.setActiveHand(hand);
			return new ActionResult<>(EnumActionResult.PASS, stack);
		}
	} else return new ActionResult<>(EnumActionResult.FAIL, stack);
}
 
Example #20
Source File: ItemEnderBucket.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
    ItemStack stack = player.getHeldItem(hand);

    // Do nothing on the client side
    if (world.isRemote || (LinkMode.fromStack(stack) == LinkMode.ENABLED &&
        OwnerData.canAccessSelectedModule(stack, ModuleType.TYPE_LINKCRYSTAL, player) == false))
    {
        return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
    }

    EnumActionResult result = this.useBucketOnFluidBlock(world, player, stack);
    return new ActionResult<ItemStack>(result, stack);
}
 
Example #21
Source File: ItemOwlEgg.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
  ItemStack itemStackIn = playerIn.getHeldItem(hand);
  if (!playerIn.capabilities.isCreativeMode) {
    itemStackIn.shrink(1);
  }
  worldIn.playSound(playerIn, playerIn.getPosition(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.BLOCKS, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
  if (!worldIn.isRemote) {    
    EntityOwlEgg entityEgg = new EntityOwlEgg(worldIn, playerIn);
    //without setHeading the egg just falls to the players feet
    entityEgg.setHeadingFromThrower(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, PITCHOFFSET, VELOCITY_DEFAULT, INACCURACY_DEFAULT);
    worldIn.spawnEntity(entityEgg);
  }
  return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemStackIn);
}
 
Example #22
Source File: BasicSolarPanelPartBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public ActionResult onUse(BlockState blockState_1, World world_1, BlockPos blockPos_1, PlayerEntity playerEntity_1, Hand hand_1, BlockHitResult blockHitResult_1) {
    BlockEntity partEntity = world_1.getBlockEntity(blockPos_1);
    if (world_1.isAir(blockPos_1) || !(partEntity instanceof BasicSolarPanelPartBlockEntity)) {
        return ActionResult.SUCCESS;
    }

    if (world_1.isClient) return ActionResult.SUCCESS;

    BlockPos basePos = ((BasicSolarPanelPartBlockEntity) partEntity).basePos;

    BlockState base = world_1.getBlockState(basePos);
    Block baseBlock = base.getBlock();
    return ((BasicSolarPanelBlock) baseBlock).onUse(base, world_1, basePos, playerEntity_1, hand_1, blockHitResult_1);
}
 
Example #23
Source File: MixinFlowerPotBlock.java    From multiconnect with MIT License 5 votes vote down vote up
@Inject(method = "onUse", at = @At(value = "FIELD", target = "Lnet/minecraft/block/FlowerPotBlock;content:Lnet/minecraft/block/Block;", ordinal = 0), cancellable = true)
private void cancelEmptyingFlowerPot(CallbackInfoReturnable<ActionResult> ci) {
    // TODO: this doesn't fully work, WTF?!
    if (ConnectionInfo.protocolVersion <= Protocols.V1_10 && content != Blocks.AIR) {
        ci.setReturnValue(ActionResult.CONSUME);
    }
}
 
Example #24
Source File: MixinCauldronBlock.java    From multiconnect with MIT License 5 votes vote down vote up
@Inject(method = "onUse",
        slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/potion/PotionUtil;getPotion(Lnet/minecraft/item/ItemStack;)Lnet/minecraft/potion/Potion;")),
        at = @At(value = "RETURN", ordinal = 0),
        cancellable = true)
private void cancelWaterBottleUse(CallbackInfoReturnable<ActionResult> ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_10) {
        ci.setReturnValue(ActionResult.PASS);
    }
}
 
Example #25
Source File: ToggleEnergyConsumerBehavior.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #26
Source File: ItemBBagBase.java    From BetterChests with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
	ItemStack stack = player.getHeldItem(hand);

	if (world.isRemote) {
		return new ActionResult<>(EnumActionResult.SUCCESS, stack);
	}
	for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
		if (player.inventory.getStackInSlot(i) == stack) {
			ContainerHelper.openGui(player, i, (short) (player.isSneaking() ? 1 : 0));
			return new ActionResult<>(EnumActionResult.SUCCESS, stack);
		}
	}
	return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
 
Example #27
Source File: ItemEnderPouch.java    From EnderStorage with MIT License 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
    ItemStack stack = player.getHeldItem(hand);
    if (player.isShiftKeyDown()) {
        return new ActionResult<>(ActionResultType.PASS, stack);
    }
    if (!world.isRemote) {
        Frequency frequency = Frequency.readFromStack(stack);
        EnderStorageManager.instance(world.isRemote).getStorage(frequency, EnderItemStorage.TYPE).openContainer((ServerPlayerEntity) player, new TranslationTextComponent(stack.getTranslationKey()));
    }
    return new ActionResult<>(ActionResultType.SUCCESS, stack);
}
 
Example #28
Source File: ModeSwitchBehavior.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #29
Source File: ItemPLFood.java    From Production-Line with MIT License 5 votes vote down vote up
@Nonnull
public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack stack, World worldIn, EntityPlayer playerIn, EnumHand hand) {
    if (playerIn.canEat(this.alwaysEdible)) {
        playerIn.setActiveHand(hand);
        return new ActionResult<>(EnumActionResult.SUCCESS, stack);
    } else {
        return new ActionResult<>(EnumActionResult.FAIL, stack);
    }
}
 
Example #30
Source File: UnlitTorchBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
    if (player.getStackInHand(hand).getItem() instanceof FlintAndSteelItem) {
        world.setBlockState(pos, Blocks.TORCH.getDefaultState());
        ItemStack stack = player.getStackInHand(hand).copy();
        stack.damage(1, player, (playerEntity -> {
        }));
        player.setStackInHand(hand, stack);
    }
    return super.onUse(state, world, pos, player, hand, hit);
}