Posted February 15, 20232 yr 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
February 15, 20232 yr dont overwrite stick functionality. i beg you Edited February 15, 20232 yr by cocicocyn grammar
February 15, 20232 yr 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 February 15, 20232 yr by cocicocyn
February 15, 20232 yr 5 minutes ago, Rex_Technology said: And there's no other way? afaik no (someone correct me if im wrong). try something else that doesn't include modifying a stick Edited February 15, 20232 yr by cocicocyn
February 15, 20232 yr 1 hour ago, Rex_Technology said: but Can I modify a sick in other modloaders?(like fabric or spigot) please research it yourself
February 15, 20232 yr 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.
February 16, 20232 yr Author I just found a tutorial for events for forge 1.19, Thank you, my problem is solved Edited February 16, 20232 yr by Rex_Technology
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.