introduction of cherry planks & register update

This commit is contained in:
Justin Parsell 2021-02-26 20:01:20 -05:00
parent 0c93573d81
commit 4169f908fc
12 changed files with 97 additions and 56 deletions

View File

@ -1,10 +1,10 @@
package net.parsell.cherry;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.parsell.cherry.core.*;
import net.parsell.cherry.core.CherryBlocks;
import net.parsell.cherry.core.CherryFeatures;
import net.parsell.cherry.core.CherryItems;
public class Cherry implements ModInitializer {
@Override

View File

@ -11,23 +11,34 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
public class CherryBlocks {
public static final Block CHERRYLOG = new PillarBlock(FabricBlockSettings.copyOf(Blocks.OAK_LOG));
public static final Block CHERRYLEAVES = new LeavesBlock(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES));
public static final Block CHERRYLOG = registerPillar("cherry_log", FabricBlockSettings.copyOf(Blocks.OAK_LOG), 5, 5);
public static final Block CHERRYLEAVES = registerLeaves("cherry_leaves", FabricBlockSettings.copyOf(Blocks.OAK_LEAVES), 30, 60, 6649929);
public static final Block CHERRYPLANKS = registerBlock("cherry_planks", FabricBlockSettings.copyOf(Blocks.OAK_PLANKS), 5, 20);
private static void registerBlocks() {
System.out.println("Adding blocks...");
Registry.register(Registry.BLOCK, new Identifier("cherry", "cherry_log"), CHERRYLOG);
Registry.register(Registry.BLOCK, new Identifier("cherry", "cherry_leaves"), CHERRYLEAVES);
System.out.println("Successfully added blocks!");
System.out.println("Setting flammability...");
FlammableBlockRegistry.getDefaultInstance().add(CHERRYLOG, 5, 5);
FlammableBlockRegistry.getDefaultInstance().add(CHERRYLEAVES, 30, 60);
private static Block registerBlock(String blockID, FabricBlockSettings settings, int burnChance, int burnSpread){
Block block = new Block(settings);
Registry.register(Registry.BLOCK, new Identifier("cherry", blockID), block);
FlammableBlockRegistry.getDefaultInstance().add(block, burnChance, burnSpread);
return block;
}
private static Block registerPillar(String blockID, FabricBlockSettings settings, int burnChance, int burnSpread){
Block block = new PillarBlock(settings);
Registry.register(Registry.BLOCK, new Identifier("cherry", blockID), block);
FlammableBlockRegistry.getDefaultInstance().add(block, burnChance, burnSpread);
return block;
}
private static Block registerLeaves(String blockID, FabricBlockSettings settings, int burnChance, int burnSpread, int color){
Block block = new LeavesBlock(settings);
Registry.register(Registry.BLOCK, new Identifier("cherry", blockID), block);
FlammableBlockRegistry.getDefaultInstance().add(block, burnChance, burnSpread);
ColorProviderRegistry.BLOCK.register((state, world, pos, tintIndex) -> {
return 6649929;
}, CHERRYLEAVES);
return color;
}, block);
return block;
}
public static void init(){
registerBlocks();
}
}

View File

@ -2,22 +2,31 @@ package net.parsell.cherry.core;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.minecraft.block.Block;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
public class CherryItems {
public static BlockItem CHERRYLEAVES_I = new BlockItem(CherryBlocks.CHERRYLEAVES, new FabricItemSettings().group(ItemGroup.BUILDING_BLOCKS));
private static void registerBlockItems(){
System.out.println("Adding items...");
Registry.register(Registry.ITEM, new Identifier("cherry", "cherry_log"), new BlockItem(CherryBlocks.CHERRYLOG, new FabricItemSettings().group(ItemGroup.BUILDING_BLOCKS)));
Registry.register(Registry.ITEM, new Identifier("cherry", "cherry_leaves"), CHERRYLEAVES_I);
System.out.println("Successfully added items!");
registerBlockItem("cherry_log", CherryBlocks.CHERRYLOG, ItemGroup.BUILDING_BLOCKS);
registerBlockItem("cherry_leaves", CherryBlocks.CHERRYLEAVES, ItemGroup.BUILDING_BLOCKS, 6649929);
registerBlockItem("cherry_planks", CherryBlocks.CHERRYPLANKS, ItemGroup.BUILDING_BLOCKS);
}
// Register a standard blockItem
private static void registerBlockItem(String itemID, Block block, ItemGroup group){
Registry.register(Registry.ITEM, new Identifier("cherry", itemID), new BlockItem(block, new FabricItemSettings().group(group)));
}
// Register a blockItem that require in-game color (leaves)
private static void registerBlockItem(String itemID, Block block, ItemGroup group, int color){
BlockItem blockItem = new BlockItem(block, new FabricItemSettings().group(group));
Registry.register(Registry.ITEM, new Identifier("cherry", itemID), blockItem);
ColorProviderRegistry.ITEM.register((stack, tintIndex) -> {
return 6649929;
}, CherryBlocks.CHERRYLEAVES
return color;
}, block
);
}

View File

@ -0,0 +1,5 @@
{
"variants": {
"": { "model": "cherry:block/cherry_planks" }
}
}

View File

@ -1,4 +1,5 @@
{
"block.cherry.cherry_log": "Cherry Log",
"block.cherry.cherry_leaves": "Cherry Leaves"
"block.cherry.cherry_leaves": "Cherry Leaves",
"block.cherry.cherry_planks": "Cherry Planks"
}

View File

@ -0,0 +1,6 @@
{
"parent": "block/cube_all",
"textures": {
"all": "cherry:block/cherry_planks"
}
}

View File

@ -0,0 +1,3 @@
{
"parent": "cherry:block/cherry_planks"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -1,6 +1,6 @@
{
"replace": false,
"values": [
"#cherry:cherry_wood"
"#cherry:cherry_logs"
]
}

View File

@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"cherry:cherry_planks"
]
}