|
1 | 1 | package turniplabs.examplemod;
|
2 | 2 |
|
3 | 3 | import net.fabricmc.api.ModInitializer;
|
4 |
| -import net.minecraft.client.render.block.model.BlockModelRenderBlocks; |
| 4 | +import net.minecraft.client.render.block.model.BlockModelStandard; |
| 5 | +import net.minecraft.client.render.block.model.BlockModelTorch; |
5 | 6 | import net.minecraft.core.block.Block;
|
6 | 7 | import net.minecraft.core.block.BlockTorch;
|
7 | 8 | import net.minecraft.core.block.material.Material;
|
8 |
| -import net.minecraft.core.item.block.ItemBlock; |
9 | 9 | import org.slf4j.Logger;
|
10 | 10 | import org.slf4j.LoggerFactory;
|
11 | 11 | import turniplabs.halplibe.helper.BlockBuilder;
|
12 | 12 | import turniplabs.halplibe.util.GameStartEntrypoint;
|
13 |
| -import turniplabs.halplibe.util.RecipeEntrypoint; |
14 | 13 |
|
15 | 14 |
|
16 | 15 | public class ExampleMod implements ModInitializer, GameStartEntrypoint {
|
17 | 16 | public static final String MOD_ID = "examplemod";
|
18 | 17 | public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
19 | 18 | public static BlockBuilder standardBlockBuilder = new BlockBuilder(MOD_ID)
|
20 |
| - .setNorthTexture(16, 8) // the coordinates of the blue N texture from the terrain atlas |
21 |
| - .setSouthTexture(17, 8) // the coordinates of the green S texture from the terrain atlas |
22 |
| - .setBottomTexture(18, 8) // the coordinates of the purple D texture from the terrain atlas |
23 |
| - .setEastTexture(16, 9) // the coordinates of the red E texture from the terrain atlas |
24 |
| - .setWestTexture(17, 9) // the coordinates of the yellow W texture from the terrain atlas |
25 |
| - .setTopTexture(18, 9) // the coordinates of the orange U texture from the terrain atlas |
26 | 19 | .setHardness(5f); // Sets the hardness which affects the time to mine the blocks
|
27 | 20 | public static Block directionCube;
|
28 | 21 | public static Block grassTop;
|
29 | 22 | public static Block stoneSide;
|
30 | 23 | public static Block customBlockItem;
|
31 | 24 | public static Block customBlockModel;
|
| 25 | + public static Block customBlockModel2; |
32 | 26 | @Override
|
33 | 27 | public void onInitialize() {
|
34 | 28 | LOGGER.info("ExampleMod initialized.");
|
35 | 29 | }
|
36 | 30 |
|
37 | 31 | @Override
|
38 | 32 | public void beforeGameStart() {
|
39 |
| - // Vanilla BTA blocks range from 0 to about 1000, |
| 33 | + // Vanilla BTA blocks range from 0 to about 1100, |
40 | 34 | // and block ids can only exist within the 0 to 16000 range
|
41 | 35 | // you need to make sure to pick ids that aren't being used by the vanilla game
|
42 | 36 | // or other mods, a good way to deal with the potential of conflicting ids
|
43 | 37 | // is to make your ids user configurable
|
44 | 38 | int startingBlockId = 2000;
|
45 | 39 |
|
46 | 40 | // Creates and assigns directionCube a new block with the language key 'tile.examplemod.direction' with an id of 2000
|
47 |
| - directionCube = standardBlockBuilder.build(new Block("direction", startingBlockId++, Material.stone)); |
| 41 | + directionCube = standardBlockBuilder |
| 42 | + .setBlockModel(block -> new BlockModelStandard<>(block).withTextures( |
| 43 | + "examplemod:block/up", // Set top texture to up.png |
| 44 | + "examplemod:block/down", // Set down texture to down.png |
| 45 | + "examplemod:block/north", // Set north texture to north.png |
| 46 | + "examplemod:block/east", // Set east texture to east.png |
| 47 | + "examplemod:block/south", // Set south texture to south.png |
| 48 | + "examplemod:block/west")) // Set west texture to west.png |
| 49 | + .build(new Block("direction", startingBlockId++, Material.stone)); |
48 | 50 |
|
49 | 51 | // Creates and assigns grassTop a new block with the language key 'tile.examplemod.grassTop' with an id of 2001 with the top texture changed to grass
|
50 |
| - grassTop = standardBlockBuilder.setTopTexture(8, 1).build(new Block("grassTop", startingBlockId++, Material.grass)); |
| 52 | + grassTop = standardBlockBuilder |
| 53 | + .setBlockModel(block -> new BlockModelStandard<>(block).withTextures( |
| 54 | + "minecraft:block/grass_top", |
| 55 | + "examplemod:block/down", |
| 56 | + "examplemod:block/north", |
| 57 | + "examplemod:block/east", |
| 58 | + "examplemod:block/south", |
| 59 | + "examplemod:block/west")) |
| 60 | + .build(new Block("grassTop", startingBlockId++, Material.grass)); |
51 | 61 |
|
52 | 62 | // Creates and assigns stoneSide a new block with the language key 'tile.examplemod.stoneSide' with an id of 2002 with the side textures changed to stone
|
53 |
| - stoneSide = standardBlockBuilder.setSideTextures(0, 1).build(new Block("stoneSide", startingBlockId++, Material.grass)); |
| 63 | + stoneSide = standardBlockBuilder |
| 64 | + .setBlockModel(block -> new BlockModelStandard<>(block).withTextures( |
| 65 | + "examplemod:block/up", |
| 66 | + "examplemod:block/down", |
| 67 | + "minecraft:block/stone")) |
| 68 | + .build(new Block("stoneSide", startingBlockId++, Material.grass)); |
54 | 69 |
|
55 | 70 | // Creates and assigns customBlockItem a new block with the language key 'tile.examplemod.customItem' with an id of 2003 with a custom Item class
|
56 | 71 | customBlockItem = standardBlockBuilder
|
57 |
| - .setSideTextures(6, 3) // Grass side texture |
58 |
| - .setTopTexture(8, 1) // Grass Top texture |
59 |
| - .setBottomTexture(2, 0) // Dirt texture |
| 72 | + .setBlockModel(block -> new BlockModelStandard<>(block).withTextures( |
| 73 | + "minecraft:block/grass_top", |
| 74 | + "minecraft:block/dirt", |
| 75 | + "minecraft:block/grass_side")) |
60 | 76 | .setItemBlock((Block b) -> new CustomItemBlockExample(b)) // Sets the item version of the block to our custom class
|
61 | 77 | .build(new Block("customItem", startingBlockId++, Material.dirt));
|
62 | 78 |
|
63 |
| - // renderType ids, the vanilla game uses id numbers to specify the model a block should render with |
64 |
| - // type | Model |
65 |
| - // 0 | Standard Block |
66 |
| - // 1 | Cross block (like flowers and sugarcane) |
67 |
| - // 2 | Torch |
68 |
| - // 3 | Fire |
69 |
| - // 4 | Fluids |
70 |
| - // 5 | Redstone wire |
71 |
| - // 6 | Crops (like wheat) |
72 |
| - // 7 | Door Block |
73 |
| - // 8 | Ladder |
74 |
| - // 9 | Minecart Rail |
75 |
| - // 10 | Stairs |
76 |
| - // 11 | Fence |
77 |
| - // 12 | Lever |
78 |
| - // 13 | Cactus?? |
79 |
| - // 14 | Block Bed |
80 |
| - // 15 | Redstone repeater |
81 |
| - // 16 | Piston Base |
82 |
| - // 17 | Piston Head |
83 |
| - // 18 | Fence Gate |
84 |
| - // 19 | Spikes |
85 |
| - // 20 | Standard Block again (might do something special but is currently not used by anything) |
86 |
| - // 21 | Mossy Stone |
87 |
| - // 22 | Legacy Painted Chest model (unused as of 7.1) |
88 |
| - // 23 | Flowering Cherry Leaves |
89 |
| - // 24 | Algae |
90 |
| - // 25 | Candle (For the currently implemented soulwax candle) |
91 |
| - // 26 | Firefly lanterns |
92 |
| - // 27 | Axis aligned (Used by logs and the marble pillar etc) |
93 |
| - // 28 | Basket |
94 |
| - // 29 | Pebbles |
95 |
| - // 30 | Trapdoors |
96 |
| - // 31 | Chainlink Fence |
97 |
| - // 32 | Crops Pumpkin |
98 |
| - // 33 | Cacao Leaves |
99 |
| - // 34 | Flower Jar (rendering is split between the block and the tile entity) |
100 |
| - // 35 | Seat |
101 |
| - |
102 | 79 | // Creates and assigns customBlockModel a new block with the language key 'tile.examplemod.customModel' with an id of 2004 with a custom texture and the torch model
|
103 | 80 | customBlockModel = new BlockBuilder(MOD_ID)
|
104 |
| - .setTextures("customTorchTexture.png") // Sets the block texture to the one stored in '/assets/examplemod/block/customTorchTexture.png' |
105 |
| - .setBlockModel(new BlockModelRenderBlocks(2)) |
106 |
| - .setLuminance(14) // Sets the block light output of the block, range from [0 - 15] its converted to a float internally by dividing the value by 15f |
| 81 | + .setBlockModel( |
| 82 | + block -> new BlockModelTorch<>(block) |
| 83 | + .withTextures("examplemod:block/customTorchTexture")) // Sets the block texture to the one stored in '/assets/examplemod/textures/block/customTorchTexture.png' |
| 84 | + .setLuminance(14) // Sets the block light output of the block, range from [0 - 15] it's converted to a float internally by dividing the value by 15f |
107 | 85 | .build(new BlockTorch("customModel", startingBlockId++));
|
108 | 86 |
|
| 87 | + // Creates and assigns customBlockModel a new block with the language key 'tile.examplemod.customModel2' with an id of 2006 with a custom texture and the model we created CustomBlockModel |
| 88 | + customBlockModel2 = new BlockBuilder(MOD_ID) |
| 89 | + .setBlockModel( |
| 90 | + block -> new CustomBlockModel<>(block) // Assing our custom model to the block |
| 91 | + .withTextures("minecraft:block/sponge")) // Sets the block texture to sponge |
| 92 | + .build(new BlockCustomShape("customModel2", startingBlockId++, Material.sponge)) // Set out custom block that goes with our custom model |
| 93 | + .withLitInteriorSurface(true); // Makes it sample light from within itself rather than from neighboring blocks |
| 94 | + |
109 | 95 | // Make sure to assign names and descriptions to your blocks in your mods .lang file
|
110 | 96 |
|
111 | 97 | // everytime you set parameters on the blockbuilder it returns a new blockbuilder object, this prevents later modifications to the builder from
|
|
0 commit comments