Custom bow tutorial(code) Forge 1.18.2 and 1.19.

Started by ImOd102 on

Topic category: User side tutorials

Last seen on 13:56, 19. Dec 2022
Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Custom bow tutorial(code) Forge 1.18.2 and 1.19.
Wed, 10/19/2022 - 19:30 (edited)

This tutorial will let you make a custom bow, that works like the vanilla one.

Before you start you will want to have:
- 4 bow textures, 1 base texture, and 3 different pulling ones.
- Maybe, possibly some java or coding knowledge(If you want to understand the tutorial) and knowledge on how to use mcreator.

We'll start with the bow tutorial. First, make a normal item(not a ranged item).  Then you can add texture, name and special information/lore(optional), but make sure to change the stack size to 1 and set the durability to whatever you want. Lock the code and enter the code editor. Now delete all the methods(like "getUseAnimation") except for "appendHoverText"(if you added lore this should appear). Look for the starting point of the code that says public class (item name)Item. Between that and the brackets add: "extends BowItem". Your code should look something like this https://imgur.com/LyWT1bh(click for image). Now reformat(ctrl/command + w) and save your code. Go to your workspace settings go to the 3rd tab labeled Advanced Setting and check "Lock base mod files" and save changes. Now create a custom code element called ModItemProperties and add this code to it:
 

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModItemProperties {
    public static void addCustomItemProperties() {
        makeBow(TutorialModItems.IRON_BOW.get());
    }

    private static void makeBow(Item item) {
        ItemProperties.register(item, new ResourceLocation("pull"), (p_174635_, p_174636_, p_174637_, p_174638_) -> {
            if (p_174637_ == null) {
                return 0.0f;
            } else {
                return p_174637_.getUseItem() != p_174635_
                        ? 0.0f
                        : (float) (p_174635_.getUseDuration() - p_174637_.getUseItemRemainingTicks()) / 20.0f;
            }
        });
        ItemProperties.register(item, new ResourceLocation("pulling"), (p_174630_, p_174631_, p_174632_, p_174633_) -> {
            return p_174632_ != null && p_174632_.isUsingItem() && p_174632_.getUseItem() == p_174630_ ? 1.0f : 0.0f;
        });
    }
}

Change Aetheriamodck in AetheriamodckModItems to your mod name,(example: Mod name: TutorialExample = TutorialExampleModItems) And IRON_BOW to your item's id(in ALL CAPS). That line can be added as many times as you want for each bow, just change the id. Reformat and save. Now go to your main mod file(which should be located in source/net/mod_name/). Look for the method that has stuff like REGISTRY and add to the bottom: bus.addListener(this::clientSetup); Then above the last method(addNetworkMessage) add this code:

private void clientSetup(final FMLClientSetupEvent event) {
    ModItemProperties.addCustomItemProperties();
}

Reformat and save again. Now go to the left side of the window and search up your item id(example: iron_bow). Right click on the json file you find and click show in explorer. Now copy paste that json file 3 times. You should now have 4 different copies. Keep the regular one, don't give it a new name. For the other ones get your item id and add "_pulling_0", "_pulling_1", and "_pulling_2". Now go to your item's main json file in mcreator. Put this code in:

  {
  "parent": "item/bow",
  "textures": {
    "layer0": "mod_id:items/iron_bow"
  },
  "overrides": [
    {
      "predicate": {
        "minecraft:pulling": 1
      },
      "model": "mod_id:item/iron_bow_pulling_0"
    },
    {
      "predicate": {
        "minecraft:pulling": 1,
        "minecraft:pull": 0.65
      },
      "model": "mod_id:item/iron_bow_pulling_1"
    },
    {
      "predicate": {
        "minecraft:pulling": 1,
        "minecraft:pull": 0.9
      },
      "model": "mod_id:item/iron_bow_pulling_2"
    }
  ]
}

 

The three strings near the bottom that start with "model" must be changed to your names for each of the pulling json files. Change all the mod ids. The top is your texture file path. Reformat and save. Now go to each of your pulling files. You'll want each of your files to look something like this:

{
    "parent": "mod_id:item/bow_id",
    "textures": 
    {
        "layer0": "mod_id:items/iron_bow_pulling_0"
    }
}

You're done! Thanks again to Kid Justice Gaming.

Edited by ImOd102 on Wed, 10/19/2022 - 19:30
Last seen on 13:56, 19. Dec 2022
Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It might not fix the error…
Sat, 11/05/2022 - 22:14

It might not fix the error but in "iron_bow.json" the "item/generated" should be replaced "item/bow".

Last seen on 03:37, 10. Dec 2022
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I changed that & the results…
Sun, 11/06/2022 - 02:34

I changed that & the results didn't change as well as the same errors were outputted. Does the iron_bow.json have to have it's own model as well as a texture? I see a pull back animation but just no sequence of textures from the 3 pulling textures. That's my only thought because it says "unable to load model" & I've only used 4 textures including iron_bow.json. However unless i'm mistaken this tutorial doesn't call for that correct?

Last seen on 13:56, 19. Dec 2022
Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
BudTheGod, are you sure you…
Sat, 11/12/2022 - 14:32

BudTheGod, are you sure you did this part?

 

private void clientSetup(final FMLClientSetupEvent event) {
    ModItemProperties.addCustomItemProperties();
}
Last seen on 01:13, 4. Mar 2023
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Excuse me for being…
Fri, 11/25/2022 - 00:38

Excuse me for being uneducated, but I'm really confused with the whole "Now delete all the methods(like "getUseAnimation") except for "appendHoverText"(if you added lore this should appear)." thing, I don't know what a method is really and searching it up isn't helping all too much. Any guidance? Am I probably going to never manage to finish this tutorial? 😫 

Last seen on 01:13, 4. Mar 2023
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Alright scratch my last…
Fri, 11/25/2022 - 00:53

Alright scratch my last message I figured that one out, now I'm just stumped on what "Change Aetheriamodck in AetheriamodckModItems to your mod name,(example: Mod name: TutorialExample = TutorialExampleModItems) And IRON_BOW to your item's id(in ALL CAPS)." means? I couldn't find "Aetheriamodck" in the Custom Element script?

Last seen on 01:13, 4. Mar 2023
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I believe I did everything…
Fri, 11/25/2022 - 01:27

I believe I did everything correctly besides what I last messaged about however I'm getting this error: https://imgur.com/a/yKdkyiO

Last seen on 01:13, 4. Mar 2023
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I'm sorry I've been…
Fri, 11/25/2022 - 17:27

I'm sorry I've been messaging here like crazy lol, but I actually managed to get it working completely fine after comparing the workspace you sent over to mine, the only thing is now that I can't figure out how to change the bow's attributes like the arrow damage, arrow speed, stuff like that.

Last seen on 13:56, 19. Dec 2022
Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Hello @rubenquent, I'm…
Fri, 11/25/2022 - 22:50

Hello @rubenquent, I'm thankful you can have solved the problems with your code. At the moment I do not know how to change the damage and speed(actually power), I will look into it though and will see if I can give you a solution.

Last seen on 01:13, 4. Mar 2023
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thank you so much for just…
Sat, 11/26/2022 - 00:21

Thank you so much for just even trying. This guide was a life saver, everywhere else I looked either didn't work or just didn't make sense to me lol.

Last seen on 01:30, 29. Nov 2023
Joined Apr 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
is there a way to make this…
Tue, 03/21/2023 - 01:18

is there a way to make this bow shoot custom arrows? 

Last seen on 20:24, 18. Mar 2024
Joined Mar 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I don't know what I did…
Fri, 04/14/2023 - 01:04

I don't know what I did wrong, but the animation doesn't work for me. Everything compiles perfectly, but it is not clear what is happening with the animation. I can give link for my project if someone want to help me, there is only a bow and that script for properties.
https://drive.google.com/file/d/1oiU5_nyWr2HbQp2C-8rE17yCCXKZW8qF/view?…

Last seen on 19:28, 9. Jan 2024
Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
"Look for the method that…
Tue, 05/30/2023 - 14:41

"Look for the method that has stuff like REGISTRY and add to the bottom: bus.addListener(this::clientSetup); Then above the last method(addNetworkMessage) add this code:" 

Where do I find the method with REGISTRY?

Last seen on 19:28, 9. Jan 2024
Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
nvm I found it
Tue, 05/30/2023 - 15:18

nvm I found it