O
O
OneDeus2022-04-13 22:09:45
Java
OneDeus, 2022-04-13 22:09:45

How to call the use function in the inventoryTick function?

Can you please tell me how can I call the use function in inventoryTick?

public class Teleport extends Item {
    public Teleport(Settings settings) {
        super(settings);
    }

    public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
        ItemStack itemStack = user.getStackInHand(hand);
        user.getItemCooldownManager().set(this, 200);
        user.sendMessage(new TranslatableText("Hi"), false);
        return TypedActionResult.success(itemStack, world.isClient());
    }

    @Override
    public void inventoryTick(ItemStack stack, World world, Entity player, int slot, boolean selected) {
        if (Screen.hasControlDown() && !player.world.isClient()) {
            Vec3d newPosition = player.getRotationVec(1f).multiply(5).add(player.getX(), player.getY(), player.getZ());
            player.refreshPositionAfterTeleport(newPosition);
        }
        super.inventoryTick(stack, world, player, slot, selected);
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Roo, 2022-04-14
@xez

this.use( .... );

M
Michael, 2022-04-14
@Akela_wolf

The question is difficult. Because the use function takes parameters World, PlayerEntity, Hand
World inside inventoryTick is.
Entity (but not PlayerEntity) is. Perhaps "bringing up" is required, which is not very good.
Hand no. And where to take - it is not clear.
In general, this is like an XY problem , since you are not asking a question about a problem that you have (in this case, a misunderstanding of how to implement some function in the game), but about a solution that you came up with and which, probably, erroneously.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question