跳到主要内容

13楼梯平板和更多

添加方块代码

在ModBlocks类中添加楼梯相关代码

    public static final Block RUBY_ORE = registerBlock("ruby_ore",
new ExperienceDroppingBlock(UniformIntProvider.create(2, 5), FabricBlockSettings.copyOf(Blocks.STONE).strength(2f))); // 红宝石矿石
public static final Block DEEPSLATE_RUBY_ORE = registerBlock("deepslate_ruby_ore",
new ExperienceDroppingBlock(UniformIntProvider.create(2, 5), FabricBlockSettings.copyOf(Blocks.DEEPSLATE).strength(4f))); // 深板岩红宝石矿石
public static final Block NETHER_RUBY_ORE = registerBlock("nether_ruby_ore",
new ExperienceDroppingBlock(UniformIntProvider.create(2, 5), FabricBlockSettings.copyOf(Blocks.NETHERRACK).strength(1.5f))); // 地狱红宝石矿石
public static final Block END_STONE_RUBY_ORE = registerBlock("end_stone_ruby_ore",
new ExperienceDroppingBlock(UniformIntProvider.create(4, 7), FabricBlockSettings.copyOf(Blocks.END_STONE).strength(4f))); // 终界石红宝石矿石

public static final Block SOUND_BLOCK = registerBlock("sound_block", new SoundBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK))); // 声音方块

public static final Block RUBY_STAIRS = registerBlock("ruby_stairs", new StairsBlock(ModBlocks.RUBY_BLOCK.getDefaultState(), FabricBlockSettings.copyOf(Blocks.IRON_BLOCK)));// 红宝石楼梯
public static final Block RUBY_SLAB = registerBlock("ruby_slab", new SlabBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK))); // 红宝石台阶

public static final Block RUBY_BUTTON = registerBlock("ruby_button", new ButtonBlock(BlockSetType.IRON, 10, FabricBlockSettings.copy(Blocks.IRON_BLOCK))); // 红宝石按钮
public static final Block RUBY_PRESSURE_PLATE = registerBlock("ruby_pressure_plate", new PressurePlateBlock(BlockSetType.IRON, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK))); // 红宝石压力板

public static final Block RUBY_FENCE = registerBlock("ruby_fence", new FenceBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK))); // 红宝石围栏
public static final Block RUBY_FENCE_GATE = registerBlock("ruby_fence_gate", new FenceGateBlock(WoodType.ACACIA, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK))); // 红宝石围栏门
public static final Block RUBY_WALL = registerBlock("ruby_wall", new WallBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK))); // 红宝石墙

public static final Block RUBY_DOOR = registerBlock("ruby_door", new DoorBlock(BlockSetType.IRON, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).nonOpaque())); // 红宝石门
public static final Block RUBY_TRAPDOOR = registerBlock("ruby_trapdoor", new TrapdoorBlock(BlockSetType.IRON, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).nonOpaque())); // 红宝石活板门

添加生成器代码

我们需要对这些物品生成对应的json文件:

ModBlockTagProvider中:

getOrCreateTagBuilder(BlockTags.FENCES)
.add(ModBlocks.RUBY_FENCE); // 红宝石围栏
getOrCreateTagBuilder(BlockTags.FENCE_GATES)
.add(ModBlocks.RUBY_FENCE_GATE); // 红宝石围栏门
getOrCreateTagBuilder(BlockTags.WALLS)
.add(ModBlocks.RUBY_WALL); // 红宝石墙

ModLootTableProvider中:

addDrop(ModBlocks.RUBY_STAIRS); // 红宝石楼梯掉落
addDrop(ModBlocks.RUBY_TRAPDOOR); // 红宝石活板门掉落
addDrop(ModBlocks.RUBY_WALL); // 红宝石墙掉落
addDrop(ModBlocks.RUBY_FENCE); // 红宝石围栏掉落
addDrop(ModBlocks.RUBY_FENCE_GATE); // 红宝石围栏门掉落
addDrop(ModBlocks.RUBY_BUTTON); // 红宝石按钮掉落
addDrop(ModBlocks.RUBY_PRESSURE_PLATE); // 红宝石压力板掉落

addDrop(ModBlocks.RUBY_DOOR, doorDrops(ModBlocks.RUBY_DOOR)); // 红宝石门掉落
addDrop(ModBlocks.RUBY_SLAB, slabDrops(ModBlocks.RUBY_SLAB)); // 红宝石台阶掉落

ModModelProvider中:

public void generateBlockStateModels(BlockStateModelGenerator blockStateModelGenerator) {

BlockStateModelGenerator.BlockTexturePool rubyPool = blockStateModelGenerator.registerCubeAllModelTexturePool(ModBlocks.RUBY_BLOCK);
blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.RAW_RUBY_BLOCK);
blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.RUBY_ORE);
blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.DEEPSLATE_RUBY_ORE);
blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.NETHER_RUBY_ORE);
blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.END_STONE_RUBY_ORE);
blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.SOUND_BLOCK);

rubyPool.stairs(ModBlocks.RUBY_STAIRS);
rubyPool.slab(ModBlocks.RUBY_SLAB);
rubyPool.button(ModBlocks.RUBY_BUTTON);
rubyPool.pressurePlate(ModBlocks.RUBY_PRESSURE_PLATE);
rubyPool.fence(ModBlocks.RUBY_FENCE);
rubyPool.fenceGate(ModBlocks.RUBY_FENCE_GATE);
rubyPool.wall(ModBlocks.RUBY_WALL);

blockStateModelGenerator.registerDoor(ModBlocks.RUBY_DOOR);
blockStateModelGenerator.registerTrapdoor(ModBlocks.RUBY_TRAPDOOR);

}

通用操作

添加到物品组中:

ModItemGroups中:

entries.add(ModBlocks.RUBY_STAIRS);
entries.add(ModBlocks.RUBY_SLAB);
entries.add(ModBlocks.RUBY_FENCE);
entries.add(ModBlocks.RUBY_FENCE_GATE);
entries.add(ModBlocks.RUBY_WALL);
entries.add(ModBlocks.RUBY_BUTTON);
entries.add(ModBlocks.RUBY_PRESSURE_PLATE);
entries.add(ModBlocks.RUBY_DOOR);
entries.add(ModBlocks.RUBY_TRAPDOOR);

最后不要忘了在语言中添加:

"block.tutorialmod.ruby_stairs": "Ruby Stairs",
"block.tutorialmod.ruby_slab": "Ruby Slab",
"block.tutorialmod.ruby_button": "Ruby Button",
"block.tutorialmod.ruby_pressure_plate": "Ruby Pressure Plate",
"block.tutorialmod.ruby_fence": "Ruby Fence",
"block.tutorialmod.ruby_fence_gate": "Ruby Fence Gate",
"block.tutorialmod.ruby_wall": "Ruby Wall",
"block.tutorialmod.ruby_door": "Ruby Door",
"block.tutorialmod.ruby_trapdoor": "Ruby Trapdoor",

以及对应的材质图片

效果

先使用生成器生成代码,然后启动测试:

image-20240824153457263