类net.minecraft.util.ActionResult源码实例Demo

下面列出了怎么用net.minecraft.util.ActionResult的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: TFC2   文件: ItemLooseRock.java
@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);
}
 
源代码2 项目: carpet-extra   文件: CarpetDispenserBehaviours.java
@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);
}
 
源代码3 项目: enderutilities   文件: ItemEnderPart.java
@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);
}
 
源代码4 项目: Sakura_mod   文件: ItemSakuraDiamond.java
@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);
  }
 
源代码5 项目: Wizardry   文件: ItemBomb.java
@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);
}
 
源代码6 项目: the-hallow   文件: HallowedLogBlock.java
@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;
}
 
源代码7 项目: the-hallow   文件: HallowedTreasureChestBlock.java
@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;
}
 
源代码8 项目: CommunityMod   文件: ItemThatMakesYouSayDab.java
@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));
}
 
源代码9 项目: enderutilities   文件: ItemPortalScaler.java
@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);
}
 
源代码10 项目: enderutilities   文件: ItemLocationBound.java
@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);
}
 
源代码11 项目: ExNihiloAdscensio   文件: ItemPebble.java
@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);
}
 
源代码12 项目: GT-Classic   文件: GTItemDestructoPack.java
@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));
}
 
源代码13 项目: enderutilities   文件: ItemHandyBag.java
@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);
}
 
源代码14 项目: GT-Classic   文件: GTItemFluidTube.java
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);
}
 
源代码15 项目: Galacticraft-Rewoven   文件: WireBlock.java
@Override
@Deprecated
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
    if (!world.isClient() && Galacticraft.configManager.get().isDebugLogEnabled()) {
        Galacticraft.logger.info(((ServerWorldAccessor) world).getNetworkManager().getNetwork(pos));
    }
    return super.onUse(state, world, pos, player, hand, hit);
}
 
源代码16 项目: AgriCraft   文件: ItemJournal.java
@Override
@Nonnull
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    if (world.isRemote) {
        player.openGui(AgriCraft.instance, GuiHandler.JOURNAL_GUI_ID, world, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ());
    }
    return new ActionResult<>(EnumActionResult.PASS, player.getHeldItem(hand));
}
 
源代码17 项目: Galacticraft-Rewoven   文件: UnlitTorchBlock.java
@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);
}
 
源代码18 项目: enderutilities   文件: ItemEnderBucket.java
@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);
}
 
@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);
}
 
源代码20 项目: Production-Line   文件: ItemPLFood.java
@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);
    }
}
 
源代码21 项目: Galacticraft-Rewoven   文件: OxygenGearItem.java
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
    if (((GCPlayerAccessor) user).getGearInventory().getStack(5).isEmpty()) {
        ((GCPlayerAccessor) user).getGearInventory().setStack(5, user.getStackInHand(hand));
        return new TypedActionResult<>(ActionResult.SUCCESS, ItemStack.EMPTY);
    }
    return super.use(world, user, hand);
}
 
源代码22 项目: Galacticraft-Rewoven   文件: OxygenTankItem.java
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) { //should sync with server
    if (((GCPlayerAccessor) player).getGearInventory().getStack(6).isEmpty()) {
        ((GCPlayerAccessor) player).getGearInventory().setStack(6, player.getStackInHand(hand).copy());
        return new TypedActionResult<>(ActionResult.SUCCESS, ItemStack.EMPTY);
    } else if (((GCPlayerAccessor) player).getGearInventory().getStack(7).isEmpty()) {
        ((GCPlayerAccessor) player).getGearInventory().setStack(7, player.getStackInHand(hand).copy());
        return new TypedActionResult<>(ActionResult.SUCCESS, ItemStack.EMPTY);
    }
    return new TypedActionResult<>(ActionResult.PASS, player.getStackInHand(hand));
}
 
源代码23 项目: Galacticraft-Rewoven   文件: StandardWrenchItem.java
public ActionResult useOnBlock(ItemUsageContext itemUsageContext_1) {
    PlayerEntity player = itemUsageContext_1.getPlayer();
    World world_1 = itemUsageContext_1.getWorld();
    if (!world_1.isClient && player != null) {
        BlockPos pos = itemUsageContext_1.getBlockPos();
        this.use(player, world_1.getBlockState(pos), world_1, pos, itemUsageContext_1.getStack());
    }

    return ActionResult.SUCCESS;
}
 
源代码24 项目: TofuCraftReload   文件: DrinkSoymilkRamune.java
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
    ItemStack itemstack = playerIn.getHeldItem(handIn);

    if (playerIn.canEat(true)||playerIn.isCreative())
    {
        playerIn.setActiveHand(handIn);
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
    }
    else
    {
        return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
    }
}
 
源代码25 项目: AdvancedRocketry   文件: ItemOreScanner.java
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
	ItemStack stack = playerIn.getHeldItem(hand);
	if(!playerIn.world.isRemote && stack != null)
		playerIn.openGui(AdvancedRocketry.instance, GuiHandler.guiId.OreMappingSatellite.ordinal(), worldIn, (int)playerIn.getPosition().getX(), (int)getSatelliteID(stack), (int)playerIn.getPosition().getZ());

	return super.onItemRightClick(worldIn, playerIn, hand);
}
 
源代码26 项目: TofuCraftReload   文件: ItemBugle.java
@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);
}
 
源代码27 项目: pycode-minecraft   文件: PythonBookItem.java
@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);
}
 
源代码28 项目: the-hallow   文件: TinyPumpkinBlock.java
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
	BlockEntity be = world.getBlockEntity(pos);
	if (be instanceof TinyPumpkinBlockEntity) {
		return ((TinyPumpkinBlockEntity) be).use(player, hand, hit);
	}
	return ActionResult.PASS;
}
 
源代码29 项目: the-hallow   文件: TinyPumpkinBlockEntity.java
public ActionResult use(PlayerEntity player, Hand hand, BlockHitResult hit) {
	Direction facing = getCachedState().get(HorizontalFacingBlock.FACING);
	Direction hitSide = hit.getSide();
	if (hitSide != facing.rotateYClockwise() && hitSide != facing.rotateYCounterclockwise()) {
		return ActionResult.PASS;
	}
	
	if (!world.isClient) {
		ItemStack handStack = player.getStackInHand(hand);
		boolean isLeft = hitSide == facing.rotateYCounterclockwise();
		ItemStack heldItem = isLeft ? leftItem : rightItem;
		if (!heldItem.isEmpty()) {
			ItemScatterer.spawn(world, pos, DefaultedList.copyOf(ItemStack.EMPTY, heldItem));
			if (isLeft) {
				leftItem = ItemStack.EMPTY;
			} else {
				rightItem = ItemStack.EMPTY;
			}
			sync();
			markDirty();
		} else if (!handStack.isEmpty()) {
			if (isLeft) {
				leftItem = handStack.copy();
				leftItem.setCount(1);
			} else {
				rightItem = handStack.copy();
				rightItem.setCount(1);
			}
			handStack.decrement(1);
			sync();
			markDirty();
		}
	}
	
	return ActionResult.SUCCESS;
}
 
源代码30 项目: the-hallow   文件: PumpkinPieBlock.java
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hitResult) {
	if (!world.isClient) {
		return this.tryEat(world, pos, state, player);
	}
	ItemStack stack = player.getStackInHand(hand);
	if(stack.isEmpty()) {
		return ActionResult.PASS;
	}
	return this.tryEat(world, pos, state, player);
}
 
 类所在包
 同包方法