Topic category: Help with Minecraft modding (Java Edition)
There's already some decent tutorials out there for this, but several people have asked at this point, so I wanted to make a bit of a simpler explanation for folks who aren't as familiar with java. It's entirely possible to make custom arrows in MCreator, however it will involve a fair bit of locked code. In Neoforge 1.21.1, here's how you do it:
-
First, create an item, assign textures and whatnot as normal. Then lock the item element, open the java file, and replace the body of the code with the following:
public class JeweledArrowItem extends ArrowItem { public JeweledArrowItem() { super(new Item.Properties().stacksTo(64)); } @Override public AbstractArrow createArrow(Level world, ItemStack stack, LivingEntity shooter, @Nullable ItemStack weapon){ return new JeweledArrowProjectileEntity(FabulousfletchingModEntities.JEWELED_ARROW_PROJECTILE.get(), shooter, world, stack.copyWithCount(1)); } @Override public Projectile asProjectile(Level world, Position pos, ItemStack stack, Direction direction) { JeweledArrowProjectileEntity jeweledarrow = new JeweledArrowProjectileEntity(FabulousfletchingModEntities.JEWELED_ARROW_PROJECTILE.get(), pos.x(), pos.y(), pos.z(), world, stack.copyWithCount(1)); jeweledarrow.pickup = AbstractArrow.Pickup.ALLOWED; return jeweledarrow; } }
- This is just straight from one of my mods- you'll want to replace "fabulousfletching" with your own mod ID, and "JeweledArrowItem" with the name of your item element. This code will define the your item as an 'arrow item,' which can interact with vanilla bows, and will tell it what kind of projectile to create. (You'll need to replace 'JeweledArrowProjectile' with the name of the projectile element you want to link the item to.) You will also need to replace the imports accordingly.
- Next, add the locked item to an element tag; you'll want to use the minecraft:arrows tag. Any items in this tag are allowed to be used as ammunition for bows and crossbows.
- Once you've locked the item and made your projectile entity, (assigning whatever procedures and textures you want to it), lock the code of the projectile entity you've linked the arrow to. If you're creating an arrow, you'll likely want it to remain in the ground when fired. To do this, remove the following bit of code from the projectile entity's java file:
if (this.inGround)
this.discard();
And at this point, you're basically finished. The last thing to do is to get the arrow to drop an item when picked up- in previous versions you could assign the default pickup item pretty easily, but as I'm dumb and can't figure out how to do it in Neoforge, there's a simpler, stupider solution, and it involves making a procedure like this:
The command is just a data merge that overrides the pickup item of the arrow. In this case, /data merge entity @s {item: {count:1, id:"fabulousfletching:cursed_arrow"}} is all you need, using your own mod id and item registry name. I used @e for some reason, but that's the simpler way to do it. Keep in mind you can assign any item to be the pickup item, not just the arrow itself!
You can also use a function like this to change other properties of the arrow, such as its initial speed, (by multiplying or dividing the motion vector), its firing sound effect, particles, etc. If you want to be extra professional and make sure multishot versions of your arrow can't be picked up, you can run a data get command, check if the result contains 'intangible,' (meaning the arrow is an enchanted duplicate), and if it does, do another data merge command, /data merge entity @s {pickup:0b}.
If you're still getting compilation errors, make sure you've correctly updated the imports for your arrow item. Here's what the import section should look like. (You'll need to change the names and mod id, of course.)
I made a mistake with alabaster, where I wrote e instead of a. This has already been fixed, but nothing works
The code you have put inside is likely not valid Java code. I recommend doing some Java tutorials before adjusting the code manually