Skip to content

Commit 28e498e

Browse files
KaupenjoeKaupenjoe
authored andcommitted
custom 3d block model
1 parent 30c1452 commit 28e498e

8 files changed

Lines changed: 183 additions & 0 deletions

File tree

src/main/java/net/kaupenjoe/tutorialmod/block/ModBlocks.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ public int getFireSpreadSpeed(BlockState state, BlockGetter level, BlockPos pos,
130130
() -> new ModSaplingBlock(ModTreeGrowers.BLOODWOOD, BlockBehaviour.Properties.ofFullCopy(Blocks.OAK_SAPLING), () -> Blocks.NETHERRACK));
131131

132132

133+
public static final DeferredBlock<Block> CHAIR = registerBlock("chair",
134+
() -> new ChairBlock(BlockBehaviour.Properties.of().noOcclusion()));
135+
136+
133137
private static <T extends Block> DeferredBlock<T> registerBlock(String name, Supplier<T> block) {
134138
DeferredBlock<T> toReturn = BLOCKS.register(name, block);
135139
registerBlockItem(name, toReturn);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package net.kaupenjoe.tutorialmod.block.custom;
2+
3+
import com.mojang.serialization.MapCodec;
4+
import net.minecraft.core.BlockPos;
5+
import net.minecraft.world.item.context.BlockPlaceContext;
6+
import net.minecraft.world.level.BlockGetter;
7+
import net.minecraft.world.level.block.Block;
8+
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
9+
import net.minecraft.world.level.block.state.BlockState;
10+
import net.minecraft.world.level.block.state.StateDefinition;
11+
import net.minecraft.world.phys.shapes.CollisionContext;
12+
import net.minecraft.world.phys.shapes.VoxelShape;
13+
import org.jetbrains.annotations.Nullable;
14+
15+
public class ChairBlock extends HorizontalDirectionalBlock {
16+
public static final MapCodec<ChairBlock> CODEC = simpleCodec(ChairBlock::new);
17+
private static final VoxelShape SHAPE = Block.box(3.0, 0.0, 3.0, 13.0, 16.0, 13.0);
18+
19+
public ChairBlock(Properties properties) {
20+
super(properties);
21+
}
22+
23+
@Override
24+
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
25+
return SHAPE;
26+
}
27+
28+
@Override
29+
protected MapCodec<? extends HorizontalDirectionalBlock> codec() {
30+
return CODEC;
31+
}
32+
33+
@Nullable
34+
@Override
35+
public BlockState getStateForPlacement(BlockPlaceContext context) {
36+
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
37+
}
38+
39+
@Override
40+
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
41+
builder.add(FACING);
42+
}
43+
}

src/main/java/net/kaupenjoe/tutorialmod/item/ModCreativeModeTabs.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public class ModCreativeModeTabs {
9393

9494
output.accept(ModBlocks.BLOODWOOD_LEAVES.get());
9595

96+
output.accept(ModBlocks.CHAIR.get());
97+
9698
}).build());
9799

98100

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"variants": {
3+
"facing=north": {
4+
"model": "tutorialmod:block/chair"
5+
},
6+
"facing=south": {
7+
"model": "tutorialmod:block/chair",
8+
"y": 180
9+
},
10+
"facing=east": {
11+
"model": "tutorialmod:block/chair",
12+
"y": 90
13+
},
14+
"facing=west": {
15+
"model": "tutorialmod:block/chair",
16+
"y": 270
17+
}
18+
}
19+
}

src/main/resources/assets/tutorialmod/lang/en_us.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"block.tutorialmod.bloodwood_leaves": "Bloodwood Leaves",
7676

7777
"block.tutorialmod.bloodwood_sapling": "Bloodwood Sapling",
78+
"block.tutorialmod.chair": "Chair",
7879

7980

8081
"creativetab.tutorialmod.bismuth_items": "Bismuth Items",
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
{
2+
"credit": "Made with Blockbench",
3+
"texture_size": [64, 64],
4+
"textures": {
5+
"0": "tutorialmod:block/chair",
6+
"particle": "tutorialmod:block/chair"
7+
},
8+
"elements": [
9+
{
10+
"from": [3, 0, 11],
11+
"to": [5, 7, 13],
12+
"faces": {
13+
"north": {"uv": [5.5, 0.5, 6, 2.25], "texture": "#0"},
14+
"east": {"uv": [5.5, 2.25, 6, 4], "texture": "#0"},
15+
"south": {"uv": [2.5, 5.5, 3, 7.25], "texture": "#0"},
16+
"west": {"uv": [3, 5.5, 3.5, 7.25], "texture": "#0"},
17+
"up": {"uv": [6.5, 3.75, 6, 3.25], "texture": "#0"},
18+
"down": {"uv": [6.5, 3.75, 6, 4.25], "texture": "#0"}
19+
}
20+
},
21+
{
22+
"from": [11, 0, 11],
23+
"to": [13, 7, 13],
24+
"faces": {
25+
"north": {"uv": [3.5, 5.5, 4, 7.25], "texture": "#0"},
26+
"east": {"uv": [4, 5.5, 4.5, 7.25], "texture": "#0"},
27+
"south": {"uv": [5.5, 4, 6, 5.75], "texture": "#0"},
28+
"west": {"uv": [4.5, 5.5, 5, 7.25], "texture": "#0"},
29+
"up": {"uv": [6.5, 4.75, 6, 4.25], "texture": "#0"},
30+
"down": {"uv": [6.5, 4.75, 6, 5.25], "texture": "#0"}
31+
}
32+
},
33+
{
34+
"from": [11, 0, 3],
35+
"to": [13, 7, 5],
36+
"faces": {
37+
"north": {"uv": [5, 5.5, 5.5, 7.25], "texture": "#0"},
38+
"east": {"uv": [5.5, 5.75, 6, 7.5], "texture": "#0"},
39+
"south": {"uv": [0, 6, 0.5, 7.75], "texture": "#0"},
40+
"west": {"uv": [0.5, 6, 1, 7.75], "texture": "#0"},
41+
"up": {"uv": [6.5, 5.75, 6, 5.25], "texture": "#0"},
42+
"down": {"uv": [6.5, 5.75, 6, 6.25], "texture": "#0"}
43+
}
44+
},
45+
{
46+
"from": [3, 0, 3],
47+
"to": [5, 7, 5],
48+
"faces": {
49+
"north": {"uv": [6, 0.5, 6.5, 2.25], "texture": "#0"},
50+
"east": {"uv": [1, 6, 1.5, 7.75], "texture": "#0"},
51+
"south": {"uv": [1.5, 6, 2, 7.75], "texture": "#0"},
52+
"west": {"uv": [2, 6, 2.5, 7.75], "texture": "#0"},
53+
"up": {"uv": [6.5, 6.75, 6, 6.25], "texture": "#0"},
54+
"down": {"uv": [7, 0.5, 6.5, 1], "texture": "#0"}
55+
}
56+
},
57+
{
58+
"from": [2.9, 7, 2.5],
59+
"to": [13.1, 8, 13],
60+
"faces": {
61+
"north": {"uv": [6, 2.75, 8.5, 3], "texture": "#0"},
62+
"east": {"uv": [6, 2.25, 8.75, 2.5], "texture": "#0"},
63+
"south": {"uv": [6, 3, 8.5, 3.25], "texture": "#0"},
64+
"west": {"uv": [6, 2.5, 8.75, 2.75], "texture": "#0"},
65+
"up": {"uv": [2.5, 2.75, 0, 0], "texture": "#0"},
66+
"down": {"uv": [5, 0, 2.5, 2.75], "texture": "#0"}
67+
}
68+
},
69+
{
70+
"from": [3, 8, 11.5],
71+
"to": [13, 19, 13],
72+
"faces": {
73+
"north": {"uv": [0, 2.75, 2.5, 5.5], "texture": "#0"},
74+
"east": {"uv": [5, 0, 5.5, 2.75], "texture": "#0"},
75+
"south": {"uv": [2.5, 2.75, 5, 5.5], "texture": "#0"},
76+
"west": {"uv": [5, 2.75, 5.5, 5.5], "texture": "#0"},
77+
"up": {"uv": [2.5, 6, 0, 5.5], "texture": "#0"},
78+
"down": {"uv": [8, 0, 5.5, 0.5], "texture": "#0"}
79+
}
80+
}
81+
],
82+
"display": {
83+
"thirdperson_righthand": {
84+
"translation": [0, -0.75, 0],
85+
"scale": [0.5, 0.5, 0.5]
86+
},
87+
"thirdperson_lefthand": {
88+
"translation": [0, -0.75, 0],
89+
"scale": [0.5, 0.5, 0.5]
90+
},
91+
"firstperson_righthand": {
92+
"scale": [0.85, 0.85, 0.85]
93+
},
94+
"firstperson_lefthand": {
95+
"scale": [0.85, 0.85, 0.85]
96+
},
97+
"ground": {
98+
"scale": [0.85, 0.85, 0.85]
99+
},
100+
"gui": {
101+
"rotation": [-165, -50, -180],
102+
"translation": [0.25, -1, 0],
103+
"scale": [0.65, 0.65, 0.65]
104+
},
105+
"fixed": {
106+
"rotation": [-25.35, 59.42, 2.14],
107+
"translation": [0, -1.25, 0.25],
108+
"scale": [0.85, 0.85, 0.85]
109+
}
110+
}
111+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"parent": "tutorialmod:block/chair"
3+
}
861 Bytes
Loading

0 commit comments

Comments
 (0)