(This article is one of a series of commentary articles)
First article: Introduction Previous article: Add Item Next article:
Add a block. I changed the writing style a little from 1.14.4 (it does not mean that the implementation method has changed due to the version upgrade).
\src\main\java\jp\koteko\liveinwater\
├ block
│ └ Blocks.java
├ item
└ LiveInWater.java
Blocks.java
package jp.koteko.liveinwater.block;
import jp.koteko.liveinwater.LiveInWater;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import java.util.ArrayList;
import java.util.List;
@Mod.EventBusSubscriber(modid = LiveInWater.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class Blocks {
public static List<Block> blockList = new ArrayList<Block>();
public static Block WATERTREE_ROOT_BLOCK = register("watertree_root_block", new Block(AbstractBlock.Properties.create(Material.WOOD).hardnessAndResistance(2.5F).sound(SoundType.WOOD)));
private static Block register(String key, Block blockIn){
blockList.add(blockIn);
return blockIn.setRegistryName(LiveInWater.MOD_ID, key);
}
@SubscribeEvent
public static void registerBlocks(RegistryEvent.Register<Block> event) {
for (Block block : blockList) {
event.getRegistry().register(block);
}
}
}
Do the same for blocking as the item registration in Last time.
Add items to List
at the same time as declaration / initialization, andregister ()
all items in the list with a for loop.
If it is just a non-functional block, it will be an instance of the Block
class. An instance of ʻAbstractBlock.Properties` is given as an argument of the constructor.
\src\main\java\jp\koteko\liveinwater\
├ block
├ item
│ └ Items.java
└ LiveInWater.java
Items.java
package jp.koteko.liveinwater.item;
import jp.koteko.liveinwater.LiveInWater;
import jp.koteko.liveinwater.block.Blocks;
import net.minecraft.block.Block;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import java.util.ArrayList;
import java.util.List;
@Mod.EventBusSubscriber(modid = LiveInWater.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class Items {
public static List<Item> itemList = new ArrayList<Item>();
public static final Item WATERTREE_ROOT = register("watertree_root", new Item((new Item.Properties()).group(ItemGroup.MATERIALS)));
public static final Item WATERTREE_ROOT_BLOCK = register("watertree_root_block", Blocks.WATERTREE_ROOT_BLOCK, ItemGroup.BUILDING_BLOCKS);
private static Item register(String key, Item itemIn) {
itemList.add(itemIn);
return itemIn.setRegistryName(LiveInWater.MOD_ID, key);
}
private static Item register(String key, Block blockIn, ItemGroup itemGroupIn) {
return register(key, new BlockItem(blockIn, (new Item.Properties()).group(itemGroupIn)));
}
@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event) {
for (Item item : itemList) {
event.getRegistry().register(item);
}
}
}
Since the block also exists as an item at the same time, register the item as well.
Overloaded the register
method (defining a method with the same name with different arguments) to make it easier to register block items. If you pass the registered name, block, and item group, it will create a BlockItem
with the group set in it and throw it to the item's register
.
BlockItem
is a subclass of ʻItem`, and the block as an item is an instance of this class.
\src\main\resources
└ assets
└ liveinwater
├ blockstates
│ └ watertree_root_block.json
├ lang
│ └ en_us.json
│ └ ja_jp.json
├ models
│ ├ block
│ │ └ watertree_root_block.json
│ └ item
│ └ watertree_root_block.json
└ textures
├ block
│ └ watertree_root_block.png
└ item
lang\en_us.json
{
"item.liveinwater.watertree_root_block": "WaterTree Root"
}
lang\ja_jp.json
{
"item.liveinwater.watertree_root_block": "Water tree root"
}
blockstates\watertree_root_block.json
{
"variants": {
"": { "model": "liveinwater:block/watertree_root_block" }
}
}
" model ":" [MOD_ID] / [model file path] "
If you want to change the model depending on the state of the block (for example, a block with a direction or a connecting block such as a fence), edit this file, but if you do not need it, it looks like this.
models\block\watertree_root_block.json
{
"parent": "block/cube_all",
"textures": {
"all": "liveinwater:block/watertree_root_block"
}
}
[MOD_ID]: [texture file path]
parent
specifies block / cube_all
.
This is a simple cube model that reflects the same texture over the entire surface.
models\item\watertree_root_block.json
{
"parent": "liveinwater:block/watertree_root_block"
}
For the block item, specify the model file of the block in parent
.
watertree_root_block.png Create and place a texture.
In Minecraft 1.9 and later, the route table was introduced as a mechanism to manage drops. Block drops are also set using this.
\src\main\resources
├ assets
└ data
└ liveinwater
└ loot_tables
└ blocks
└ watertree_root_block.json
Place blocks \ watertree_root_block.json
in the data \ liveinwater
folder prepared in Previous article.
watertree_root_block.json
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"conditions": [
{
"condition": "minecraft:match_tool",
"predicate": {
"enchantments": [
{
"enchantment": "minecraft:silk_touch",
"levels": {
"min": 1
}
}
]
}
}
],
"entries": [
{
"type": "minecraft:item",
"name": "liveinwater:watertree_root_block"
}
]
},
{
"rolls": 1,
"conditions": [
{
"condition": "minecraft:inverted",
"term": {
"condition": "minecraft:match_tool",
"predicate": {
"enchantments": [
{
"enchantment": "minecraft:silk_touch",
"levels": {
"min": 1
}
}
]
}
}
}
],
"entries": [
{
"type": "minecraft:item",
"functions": [
{
"function": "minecraft:apply_bonus",
"enchantment": "minecraft:fortune",
"formula": "minecraft:binomial_with_bonus_count",
"parameters": {
"extra": 3,
"probability": 0.5714286
}
}
],
"name": "liveinwater:watertree_root"
}
]
},
{
"rolls": 1,
"conditions": [
{
"condition": "minecraft:inverted",
"term": {
"condition": "minecraft:match_tool",
"predicate": {
"enchantments": [
{
"enchantment": "minecraft:silk_touch",
"levels": {
"min": 1
}
}
]
}
}
}
],
"entries": [
{
"type": "minecraft:item",
"name": "minecraft:dirt"
}
]
}
]
}
An example is "If you destroy it with the Silk Touch tool, drop the block itself ( watertree_root_block
), otherwise drop one soil block (dirt
) and an item ( watertree_root
) at random. " Detailed explanation will be given on the reference page.
(I tried various things, but there is a duplicate description and it may be redundant.)
Minimum configuration route table to drop the block itself
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "[MOD_ID]:[ITEM_NAME]"
}
]
}
]
}
type
selects what the route table is about. Each pool given to pools
is applied in sequence, and the result is selected from each entry given to ʻentries by the lottery of
rollstimes. Specified to return
name of
type` in the entry.
Start the game and check. It was confirmed that the block and its item could be added, the display was correct, and the block itself was dropped with silk touch and the soil and item were dropped with non-silk touch.
[Java] Let's create a mod for Minecraft 1.14.4 [2. Add a block] Creating Minecraft 1.14.4 Forge Mod Part 4 [Adding Blocks] [Route Table --Minecraft Wiki](https://minecraft-ja.gamepedia.com/%E3%83%AB%E3%83%BC%E3%83%88%E3%83%86%E3%83%BC % E3% 83% 96% E3% 83% AB) loot_tables_1.14.md · GitHub