首發於Enaium的我的博客json
public class ExampleMod implements ModInitializer { private static final Item END_HEART = new Item(new Item.Settings().group(ItemGroup.COMBAT).maxCount(32)); [...] }
ItemGroup.COMBAT //分類爲COMBATide
maxCount(32) //一組最大堆疊數 一組最大隻能疊32個物品spa
public class ExampleMod implements ModInitializer { private static final Item END_HEART = new Item(new Item.Settings().group(ItemGroup.COMBAT).maxCount(32)); @Override public void onInitialize() { Registry.register(Registry.ITEM, new Identifier("endarmor", "end_heart"), END_HEART); } }
Registry.ITEM //類別是物品code
new Identifier("endarmor", "end_heart") //第一個參數是MOD ID 第二個參數是 物品的名字blog
END_HEART //要註冊的物品的變量名rem
運行看看get
發現是一個紫色方塊 並且 名字是 item.endarmor.end_heart 紫色方塊是沒用紋理(材質)博客
接下來要添加紋理
須要的文件it
Item model: .../resources/assets/endarmor/models/item/end_heart.json Item texture: .../resources/assets/endarmor/textures/item/end_heart.png
end_heart.json 內容io
{ "parent": "item/generated", "textures": { "layer0": "endarmor:item/end_heart" } }
end_heart.png 就是紋理
public EndHeart(Settings settings) { super(settings); }
這是一個使用物品而後發出聲音的例子
public class FabricItem extends Item { public FabricItem(Settings settings) { super(settings); } @Override public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) { playerEntity.playSound(SoundEvents.BLOCK_WOOL_BREAK, 1.0F, 1.0F); return new TypedActionResult<>(ActionResult.SUCCESS, playerEntity.getStackInHand(hand)); } }
替換
private static final EndHeart END_HEART = new EndHeart(new Item.Settings().group(ItemGroup.COMBAT).maxCount(32));