net.minecraft.util.ActionResultType Java Examples

The following examples show how to use net.minecraft.util.ActionResultType. 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: ItemEnderPouch.java    From EnderStorage with MIT License 6 votes vote down vote up
@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
    World world = context.getWorld();
    if (world.isRemote()) {
        return ActionResultType.PASS;
    }

    TileEntity tile = world.getTileEntity(context.getPos());
    if (tile instanceof TileEnderChest && context.getPlayer().isShiftKeyDown()) {
        TileEnderChest chest = (TileEnderChest) tile;
        Frequency frequency = chest.getFrequency().copy();
        if (EnderStorageConfig.anarchyMode && !(frequency.owner != null && frequency.owner.equals(context.getPlayer().getUniqueID()))) {
            frequency.setOwner(null);
        }

        frequency.writeToStack(stack);

        return ActionResultType.SUCCESS;
    }
    return ActionResultType.PASS;
}
 
Example #2
Source File: ModificationTable.java    From MiningGadgets with MIT License 5 votes vote down vote up
@Override
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult result) {
    if (!world.isRemote) {
        TileEntity tileEntity = world.getTileEntity(pos);
        if (tileEntity instanceof INamedContainerProvider) {
            NetworkHooks.openGui((ServerPlayerEntity) player, (INamedContainerProvider) tileEntity, tileEntity.getPos());
        } else {
            throw new IllegalStateException("Our named container provider is missing!");
        }
        return ActionResultType.SUCCESS;
    }
    return ActionResultType.SUCCESS;
}
 
Example #3
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 #4
Source File: DryingRackBlock.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Deprecated
@Override
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult blockRayTraceResult)
{
    if (worldIn.isRemote)
        return ActionResultType.SUCCESS;

    TileEntity tileEntity = worldIn.getTileEntity(pos);
    if (!(tileEntity instanceof INamedContainerProvider))
        return ActionResultType.FAIL;

    NetworkHooks.openGui((ServerPlayerEntity) player, (INamedContainerProvider) tileEntity);

    return ActionResultType.SUCCESS;
}
 
Example #5
Source File: ChoppingBlock.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Deprecated
@Override
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult blockRayTraceResult)
{
    ItemStack heldItem = player.getHeldItem(hand);

    if (worldIn.isRemote)
    {
        return (heldItem.getCount() <= 0) || ChoppingRecipe.getRecipe(worldIn, heldItem).isPresent() ?
                ActionResultType.SUCCESS : ActionResultType.PASS;
    }

    TileEntity tileEntity = worldIn.getTileEntity(pos);

    if (!(tileEntity instanceof ChoppingBlockTileEntity) || player.isSneaking())
        return ActionResultType.PASS;

    ChoppingBlockTileEntity chopper = (ChoppingBlockTileEntity) tileEntity;

    if (heldItem.getCount() <= 0)
    {
        ItemStack extracted = chopper.getSlotInventory().extractItem(0, 1, false);
        if (extracted.getCount() > 0)
        {
            ItemHandlerHelper.giveItemToPlayer(player, extracted);
            return ActionResultType.SUCCESS;
        }

        return ActionResultType.PASS;
    }

    if (ChoppingRecipe.getRecipe(worldIn, heldItem)
            .isPresent())
    {
        ItemStack remaining = chopper.getSlotInventory().insertItem(0, heldItem, false);
        if (!player.isCreative())
        {
            if (remaining.getCount() > 0)
            {
                player.setHeldItem(hand, remaining);
            }
            else
            {
                player.setHeldItem(hand, ItemStack.EMPTY);
            }
        }
        return remaining.getCount() < heldItem.getCount() ?
                ActionResultType.SUCCESS : ActionResultType.PASS;
    }

    return ActionResultType.PASS;
}
 
Example #6
Source File: ChoppingBlock.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private boolean interceptClick(World worldIn, BlockPos pos, BlockState state, PlayerEntity playerIn)
{
    TileEntity tileentity = worldIn.getTileEntity(pos);

    if (!(tileentity instanceof ChoppingBlockTileEntity))
        return false;

    ChoppingBlockTileEntity chopper = (ChoppingBlockTileEntity) tileentity;
    if (chopper.getSlotInventory().getStackInSlot(0).getCount() <= 0)
        return false;

    if (worldIn.isRemote)
        return true;

    ItemStack heldItem = playerIn.getHeldItem(Hand.MAIN_HAND);

    int harvestLevel = heldItem.getItem().getHarvestLevel(heldItem, ToolType.AXE, playerIn, null);
    ActionResult<ItemStack> result = chopper.chop(playerIn, harvestLevel, EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, heldItem));
    if (result.getType() == ActionResultType.SUCCESS)
    {
        if (worldIn.rand.nextFloat() < ConfigManager.SERVER.choppingDegradeChance.get())
        {
            worldIn.setBlockState(pos, breaksInto.get());
        }

        if (ConfigManager.SERVER.choppingExhaustion.get() > 0)
            playerIn.addExhaustion(ConfigManager.SERVER.choppingExhaustion.get().floatValue());

        if (heldItem.getCount() > 0 && !playerIn.abilities.isCreativeMode)
        {
            heldItem.damageItem(1, playerIn, (stack) -> {
                stack.sendBreakAnimation(Hand.MAIN_HAND);
            });
        }
    }
    if (result.getType() != ActionResultType.PASS)
    {
        ((ServerWorld) worldIn).spawnParticle(new ItemParticleData(ParticleTypes.ITEM, result.getResult()),
                pos.getX() + 0.5, pos.getY() + 0.6, pos.getZ() + 0.5, 8,
                0, 0.1, 0, 0.02);
    }

    return true;
}