Skip to content

Commit

Permalink
custom 3d block model
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaupenjoe committed Jan 2, 2025
1 parent 30c1452 commit 28e498e
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/net/kaupenjoe/tutorialmod/block/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ public int getFireSpreadSpeed(BlockState state, BlockGetter level, BlockPos pos,
() -> new ModSaplingBlock(ModTreeGrowers.BLOODWOOD, BlockBehaviour.Properties.ofFullCopy(Blocks.OAK_SAPLING), () -> Blocks.NETHERRACK));


public static final DeferredBlock<Block> CHAIR = registerBlock("chair",
() -> new ChairBlock(BlockBehaviour.Properties.of().noOcclusion()));


private static <T extends Block> DeferredBlock<T> registerBlock(String name, Supplier<T> block) {
DeferredBlock<T> toReturn = BLOCKS.register(name, block);
registerBlockItem(name, toReturn);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.kaupenjoe.tutorialmod.block.custom;

import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;

public class ChairBlock extends HorizontalDirectionalBlock {
public static final MapCodec<ChairBlock> CODEC = simpleCodec(ChairBlock::new);
private static final VoxelShape SHAPE = Block.box(3.0, 0.0, 3.0, 13.0, 16.0, 13.0);

public ChairBlock(Properties properties) {
super(properties);
}

@Override
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return SHAPE;
}

@Override
protected MapCodec<? extends HorizontalDirectionalBlock> codec() {
return CODEC;
}

@Nullable
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public class ModCreativeModeTabs {

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

output.accept(ModBlocks.CHAIR.get());

}).build());


Expand Down
19 changes: 19 additions & 0 deletions src/main/resources/assets/tutorialmod/blockstates/chair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"variants": {
"facing=north": {
"model": "tutorialmod:block/chair"
},
"facing=south": {
"model": "tutorialmod:block/chair",
"y": 180
},
"facing=east": {
"model": "tutorialmod:block/chair",
"y": 90
},
"facing=west": {
"model": "tutorialmod:block/chair",
"y": 270
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/tutorialmod/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"block.tutorialmod.bloodwood_leaves": "Bloodwood Leaves",

"block.tutorialmod.bloodwood_sapling": "Bloodwood Sapling",
"block.tutorialmod.chair": "Chair",


"creativetab.tutorialmod.bismuth_items": "Bismuth Items",
Expand Down
111 changes: 111 additions & 0 deletions src/main/resources/assets/tutorialmod/models/block/chair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"credit": "Made with Blockbench",
"texture_size": [64, 64],
"textures": {
"0": "tutorialmod:block/chair",
"particle": "tutorialmod:block/chair"
},
"elements": [
{
"from": [3, 0, 11],
"to": [5, 7, 13],
"faces": {
"north": {"uv": [5.5, 0.5, 6, 2.25], "texture": "#0"},
"east": {"uv": [5.5, 2.25, 6, 4], "texture": "#0"},
"south": {"uv": [2.5, 5.5, 3, 7.25], "texture": "#0"},
"west": {"uv": [3, 5.5, 3.5, 7.25], "texture": "#0"},
"up": {"uv": [6.5, 3.75, 6, 3.25], "texture": "#0"},
"down": {"uv": [6.5, 3.75, 6, 4.25], "texture": "#0"}
}
},
{
"from": [11, 0, 11],
"to": [13, 7, 13],
"faces": {
"north": {"uv": [3.5, 5.5, 4, 7.25], "texture": "#0"},
"east": {"uv": [4, 5.5, 4.5, 7.25], "texture": "#0"},
"south": {"uv": [5.5, 4, 6, 5.75], "texture": "#0"},
"west": {"uv": [4.5, 5.5, 5, 7.25], "texture": "#0"},
"up": {"uv": [6.5, 4.75, 6, 4.25], "texture": "#0"},
"down": {"uv": [6.5, 4.75, 6, 5.25], "texture": "#0"}
}
},
{
"from": [11, 0, 3],
"to": [13, 7, 5],
"faces": {
"north": {"uv": [5, 5.5, 5.5, 7.25], "texture": "#0"},
"east": {"uv": [5.5, 5.75, 6, 7.5], "texture": "#0"},
"south": {"uv": [0, 6, 0.5, 7.75], "texture": "#0"},
"west": {"uv": [0.5, 6, 1, 7.75], "texture": "#0"},
"up": {"uv": [6.5, 5.75, 6, 5.25], "texture": "#0"},
"down": {"uv": [6.5, 5.75, 6, 6.25], "texture": "#0"}
}
},
{
"from": [3, 0, 3],
"to": [5, 7, 5],
"faces": {
"north": {"uv": [6, 0.5, 6.5, 2.25], "texture": "#0"},
"east": {"uv": [1, 6, 1.5, 7.75], "texture": "#0"},
"south": {"uv": [1.5, 6, 2, 7.75], "texture": "#0"},
"west": {"uv": [2, 6, 2.5, 7.75], "texture": "#0"},
"up": {"uv": [6.5, 6.75, 6, 6.25], "texture": "#0"},
"down": {"uv": [7, 0.5, 6.5, 1], "texture": "#0"}
}
},
{
"from": [2.9, 7, 2.5],
"to": [13.1, 8, 13],
"faces": {
"north": {"uv": [6, 2.75, 8.5, 3], "texture": "#0"},
"east": {"uv": [6, 2.25, 8.75, 2.5], "texture": "#0"},
"south": {"uv": [6, 3, 8.5, 3.25], "texture": "#0"},
"west": {"uv": [6, 2.5, 8.75, 2.75], "texture": "#0"},
"up": {"uv": [2.5, 2.75, 0, 0], "texture": "#0"},
"down": {"uv": [5, 0, 2.5, 2.75], "texture": "#0"}
}
},
{
"from": [3, 8, 11.5],
"to": [13, 19, 13],
"faces": {
"north": {"uv": [0, 2.75, 2.5, 5.5], "texture": "#0"},
"east": {"uv": [5, 0, 5.5, 2.75], "texture": "#0"},
"south": {"uv": [2.5, 2.75, 5, 5.5], "texture": "#0"},
"west": {"uv": [5, 2.75, 5.5, 5.5], "texture": "#0"},
"up": {"uv": [2.5, 6, 0, 5.5], "texture": "#0"},
"down": {"uv": [8, 0, 5.5, 0.5], "texture": "#0"}
}
}
],
"display": {
"thirdperson_righthand": {
"translation": [0, -0.75, 0],
"scale": [0.5, 0.5, 0.5]
},
"thirdperson_lefthand": {
"translation": [0, -0.75, 0],
"scale": [0.5, 0.5, 0.5]
},
"firstperson_righthand": {
"scale": [0.85, 0.85, 0.85]
},
"firstperson_lefthand": {
"scale": [0.85, 0.85, 0.85]
},
"ground": {
"scale": [0.85, 0.85, 0.85]
},
"gui": {
"rotation": [-165, -50, -180],
"translation": [0.25, -1, 0],
"scale": [0.65, 0.65, 0.65]
},
"fixed": {
"rotation": [-25.35, 59.42, 2.14],
"translation": [0, -1.25, 0.25],
"scale": [0.85, 0.85, 0.85]
}
}
}
3 changes: 3 additions & 0 deletions src/main/resources/assets/tutorialmod/models/item/chair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "tutorialmod:block/chair"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 28e498e

Please sign in to comment.