Jump to content

Changing a vannila item


Rex_Technology

Recommended Posts

So, I'm trying to make a harry potter mod where when you shift + right click a stick it transforms into a wand(a custom item). I've created a class for what should the vannila stick do:

package com.rextechnology.rexmod.item.custom;

import com.rextechnology.rexmod.item.ModItems;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class StickItem extends Item {
    public StickItem(Properties pProperties) {
        super(pProperties);
    }

    @Override
    public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> pTooltipComponents, TooltipFlag pIsAdvanced) {
        pTooltipComponents.add(Component.literal("§6Shift §6+ §6click to convert to a wand"));
        super.appendHoverText(pStack, pLevel, pTooltipComponents, pIsAdvanced);
    }

    @Override
    public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) {
        if (pPlayer.isShiftKeyDown()) {
            pPlayer.setItemInHand(pUsedHand, new ItemStack(ModItems.WAND.get()));
        }
        return super.use(pLevel, pPlayer, pUsedHand);
    }
}

but I dont know how to make this class be used by the vannila stick

Link to comment
Share on other sites

if you are interested in making things the painful way you need to implement a mixin. you edit a build.gradle file (to depend from mixin plugin), write a mixin class, configure everything, and so on. and i had several severe headaches already trying to make mixins work. the less code you write and the less complex things are the better (in general. your situation is not the exception by any means). if you aren't scared of that read a mixin wiki (google it yourself). but i suggest you to come up with a better (easier) way to do it. as it's not only an "implementation difficulty" issue. not to mention that stick item doesn't have separate class and you will need to modify a constant in items class yeah good luck with not catching any compatibility issues and actually achieving anything

Edited by cocicocyn
Link to comment
Share on other sites

You should be using events, there is an event for "Player right clicked with an item" (PlayerUseEvent or InteractEvent or something along those lines), and an event to add text to existing item tooltips, although I can't remember what the events actually are off the top of my head.

In your event handler, you need to check that the item is a stick, then perform your logic. It means that you don't have to replace the vanilla stick.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.