Modding Snippets

From Necesse Wiki
Jump to navigation Jump to search


For Modders who want to share their work[edit]

Please help us build the Modding community by sharing some of your examples. Feel free to update this page via the wiki editor!

When adding code snippets to the wiki, follow this example:

<pre>
// here is some code!
System.out.println("Necesse is cool");
</pre>


Utilities[edit]

Post your Utilities examples here.

Getting All Textures - Author: Kamikaze[edit]

Put this loop into the postInit() function. run buildModJar and then runClient from the gradle tray. The resource folder will output to your project directory.

for (Map.Entry<String, GameTexture> tex : GameTexture.getLoadedTextures()) {
    tex.getValue().saveTextureImage("resources/" + tex.getKey());
}

Equipment[edit]

Post your Equipment examples here.


Adding a sword - Author: Quack

To get started start by placing the texture of your sword in /resources/player/weapons/ as well as /resources/items/. Be sure that the name of the image is the same as it's itemStringID. The item icon placed in the items folder should be 32x32 but the actual texture of the sword places in weapons can be bigger.

Within your mod folder (in this example it's named examplemod) create a new folder or "Package". Within this new folder create a new Java class and name it after the weapon. In this case the weapon class is within a package called "tests" and the class itself is named TestSword.java.

The following code is all that it needed to set the properties of you sword. There are also things like attackXOffset and attackYOffset which can be set if the texture doesn't fit in the character's hand quite right.

package examplemod.tests; // Change this to the package name where you have your weapon class

import necesse.inventory.item.Item;
import necesse.inventory.item.toolItem.swordToolItem.SwordToolItem;

// Extends SwordToolItem
public class TestSword extends SwordToolItem {

    // Weapon attack textures are loaded from resources/player/weapons/<itemStringID>
    public TestSword() {
        super(400);
        rarity = Item.Rarity.COMMON;
        attackAnimTime.setBaseValue(300); // attack time
        attackDamage.setBaseValue(20) // Base sword damage
                .setUpgradedValue(1, 95); // Upgraded tier 1 damage
        attackRange.setBaseValue(60); // range
        knockback.setBaseValue(100); // knockback
    }
}

In the example above the weapon class is located in /examplemod/tests/TestSword.java.


Now within the main mod java file you want to include three new lines. The first one at the very top to import the newly created weapon class:

import examplemod.tests.*; // Change this to fit your package name 

Then in the init() function we need to add:

public void init() {
        ItemRegistry.registerItem("testsword", new TestSword(), 20, true);
    }

This registers the weapon in the item registry and sets it's barter value.

Lastly in the postInit() function we need to add:

public void postInit() {
        Recipes.registerModRecipe(new Recipe("testsword",
                1,
                RecipeTechRegistry.NONE, // Here you define the crafting technology needed to craft
                new Ingredient[]{
                        new Ingredient("anylog", 5),
                        new Ingredient("anystone", 5) // Here you define which ingredients are needded to craft
                }).showAfter("woodboat")); // Change this to which item you want it to show after in the menu
    }

In this example we have added the test sword as an item which is craftable everywhere for just 5 logs and 5 stones. And it shows after the wood boat item.

NPCs[edit]

Post your NPC examples here.

Mobs[edit]

Post your Mob examples here.