Skip to content
Matias Bjarland edited this page Dec 6, 2017 · 4 revisions

Adding an Item

Requirements

  • A working common proxy.

Instructions

  • Adding an Item is very similar to adding a block.

  • I'd recommend creating a new namespace for your items, to keep it separate from the blocks. Refer to the previous tutorials to do this.

  • Now you'll want to make sure to refer the defitem macro from forge-clj.items. This works very similarly to defblock, except that the names of certain methods are different on items then on blocks. You'll also need to import CreativeTabs here as well, until you make your own tab. An example of including this is:

(ns <yourusername>.<yourmodname>.items
  (:require
    [forge-clj.items :refer [defitem]])
  (:import
    [net.minecraft.creativetab CreativeTabs]))
  • There are actually a rather large variety of items that you can add, that will be gone over in future tutorials. For now, let's create a basic, generic item that doesn't do anything:
(defitem test-item
  :unlocalized-name "test-item"
  :creative-tab CreativeTabs/tabMisc)
  • Now let's go over each part:

  • The first argument is the name of this item in the code (in other words, the final item is put into a def of this name).

  • :unlocalized-name is equivalent to setUnlocalizedName in java, and basically the same as :block-name in blocks. It's what Minecraft will refer to this item by, and what to use in language files.

  • :creative-tab is basically exactly the same as what it was with blocks (and the same as setCreativeTab). It just says which creative tab in Minecraft's creative menu this item should be placed in.

  • And that's it! It's actually a lot simpler than adding a block. But before you run minecraft, be sure to register the item first! This is done the same way when adding a block, just be sure to refer to your item, and call the register function:

(ns <yourusername>.<yourmodname>.common
  (:require
    [forge-clj.registry :refer [register]]
    [<yourusername>.<yourmodname>.items :refer [test-item]]))

(defn common-init [this event]
  (register test-item "test-item"))
  • Minecraft should run now! Go ahead and run the client, and look inside of the Misc tab for your item (it'll probably be near the bottom). It will have a purple/black square texture (because we never added a texture to our item, we'll do that latter), and will have a weird looking name (something along "item.test-item.name"), which is because we haven't specified what the localized name should be (we'll also do that latter).

  • Finally, here's a full version containing everything, with the name being "yoshiquest", and the mod name being "test-mod":

core.clj:

(ns yoshiquest.test-mod.core
  (:require
    [forge-clj.core :refer [defmod]]))

(defmod yoshiquest.test-mod.core test-mod "0.0.1"
  :common {:init yoshiquest.test-mod.common/common-init})

common.clj:

(ns yoshiquest.test-mod.common
  (:require
    [forge-clj.registry :refer [register]]
    [yoshiquest.test-mod.items :refer [test-item]]))

(defn common-init [this event]
  (register test-item "test-item"))

items.clj:

(ns yoshiquest.test-mod.items
  (:require
    [forge-clj.items :refer [defitem]])
  (:import
    [net.minecraft.creativetab CreativeTabs]))

(defitem test-item
  :unlocalized-name "test-item"
  :creative-tab CreativeTabs/tabMisc)

Clone this wiki locally