From 28e498eecac41ff5e8859630ffce7b8d0cf0a18b Mon Sep 17 00:00:00 2001 From: Kaupenjoe Date: Thu, 2 Jan 2025 13:21:43 +0100 Subject: [PATCH] custom 3d block model --- .../tutorialmod/block/ModBlocks.java | 4 + .../tutorialmod/block/custom/ChairBlock.java | 43 +++++++ .../tutorialmod/item/ModCreativeModeTabs.java | 2 + .../assets/tutorialmod/blockstates/chair.json | 19 +++ .../assets/tutorialmod/lang/en_us.json | 1 + .../tutorialmod/models/block/chair.json | 111 ++++++++++++++++++ .../assets/tutorialmod/models/item/chair.json | 3 + .../tutorialmod/textures/block/chair.png | Bin 0 -> 861 bytes 8 files changed, 183 insertions(+) create mode 100644 src/main/java/net/kaupenjoe/tutorialmod/block/custom/ChairBlock.java create mode 100644 src/main/resources/assets/tutorialmod/blockstates/chair.json create mode 100644 src/main/resources/assets/tutorialmod/models/block/chair.json create mode 100644 src/main/resources/assets/tutorialmod/models/item/chair.json create mode 100644 src/main/resources/assets/tutorialmod/textures/block/chair.png diff --git a/src/main/java/net/kaupenjoe/tutorialmod/block/ModBlocks.java b/src/main/java/net/kaupenjoe/tutorialmod/block/ModBlocks.java index 736dc4f..54e8a85 100644 --- a/src/main/java/net/kaupenjoe/tutorialmod/block/ModBlocks.java +++ b/src/main/java/net/kaupenjoe/tutorialmod/block/ModBlocks.java @@ -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 CHAIR = registerBlock("chair", + () -> new ChairBlock(BlockBehaviour.Properties.of().noOcclusion())); + + private static DeferredBlock registerBlock(String name, Supplier block) { DeferredBlock toReturn = BLOCKS.register(name, block); registerBlockItem(name, toReturn); diff --git a/src/main/java/net/kaupenjoe/tutorialmod/block/custom/ChairBlock.java b/src/main/java/net/kaupenjoe/tutorialmod/block/custom/ChairBlock.java new file mode 100644 index 0000000..53c75ee --- /dev/null +++ b/src/main/java/net/kaupenjoe/tutorialmod/block/custom/ChairBlock.java @@ -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 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 codec() { + return CODEC; + } + + @Nullable + @Override + public BlockState getStateForPlacement(BlockPlaceContext context) { + return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()); + } + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + builder.add(FACING); + } +} diff --git a/src/main/java/net/kaupenjoe/tutorialmod/item/ModCreativeModeTabs.java b/src/main/java/net/kaupenjoe/tutorialmod/item/ModCreativeModeTabs.java index 0747a39..55a57ca 100644 --- a/src/main/java/net/kaupenjoe/tutorialmod/item/ModCreativeModeTabs.java +++ b/src/main/java/net/kaupenjoe/tutorialmod/item/ModCreativeModeTabs.java @@ -93,6 +93,8 @@ public class ModCreativeModeTabs { output.accept(ModBlocks.BLOODWOOD_LEAVES.get()); + output.accept(ModBlocks.CHAIR.get()); + }).build()); diff --git a/src/main/resources/assets/tutorialmod/blockstates/chair.json b/src/main/resources/assets/tutorialmod/blockstates/chair.json new file mode 100644 index 0000000..ad141fe --- /dev/null +++ b/src/main/resources/assets/tutorialmod/blockstates/chair.json @@ -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 + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/tutorialmod/lang/en_us.json b/src/main/resources/assets/tutorialmod/lang/en_us.json index 38678da..9465008 100644 --- a/src/main/resources/assets/tutorialmod/lang/en_us.json +++ b/src/main/resources/assets/tutorialmod/lang/en_us.json @@ -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", diff --git a/src/main/resources/assets/tutorialmod/models/block/chair.json b/src/main/resources/assets/tutorialmod/models/block/chair.json new file mode 100644 index 0000000..8b91972 --- /dev/null +++ b/src/main/resources/assets/tutorialmod/models/block/chair.json @@ -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] + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/tutorialmod/models/item/chair.json b/src/main/resources/assets/tutorialmod/models/item/chair.json new file mode 100644 index 0000000..6455625 --- /dev/null +++ b/src/main/resources/assets/tutorialmod/models/item/chair.json @@ -0,0 +1,3 @@ +{ + "parent": "tutorialmod:block/chair" +} \ No newline at end of file diff --git a/src/main/resources/assets/tutorialmod/textures/block/chair.png b/src/main/resources/assets/tutorialmod/textures/block/chair.png new file mode 100644 index 0000000000000000000000000000000000000000..21a3c784f5fcb7ad23783fa89be600e1a984e983 GIT binary patch literal 861 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7T#lEU{>*TaSW-L^LEDWyekeOZTlN_ zH@!X^)g|gU%j0#MTAqiyxXOwZ!3qbtKQQcJTF4$4yu?BC<%9}mt@TQmA~ZC8rj$NB zd&|>YU?p{{d5C~4IYux%=?ZP`iQu0 zxyrnDYoW~NN0&Qyeflu(3q#F)_4CD_Y@UDkAaMROM-#*S@7m3k^OB!2sdzR$uk`qm zD8ZFG-{X7#ufGphn$`16k5@Tgyh$h9hp%bD#t9aEk@4}%*WNpmoBjLg^OZN4uk@F% z{`KXH$kLFnuFpSPx>oWvm`5-z&^Z5*&Aa#GBAe$Q7l+<@HGTT@=S z@~|xo^V~Bd4i&9;&d(TYEjK zJLmBH+vVl#RScQ4jHG%4yh7K_SeAMC?wOk=`_nE8{jIPOyDhe#;r!J-=Imm&=YJgZxltc}as%`H`apmd{z-lKJv)eetu9%dKc4|KHd1y8vJY4Pzd zPo@MNP1$kg@?@3FBT2%u#fwWi;}*&8{i|2c$ZkDbYF4G$1&e$&nXAE9T~&T)IMmA!_-{k}m#BCLTTq1-$4*shCL$M1FF{_y6p{7>#1cim=NME9RQ{BXmplt+2{ z@9!5{eD=?_s?KfQHV!x6u$P2h_TF%d|HZ0h(-XGJUkLTpUszsJa^&B?e{-`wJ%0RH z+jM7;*OKkMU+WyiP4}|A{@b9Jv=c}%+>Ut9ULtr}HR3H6GY)3iGwfRVQWc~o@Ur)d zrI}GXUp_rr@^V*NaoQOb*E_d%=Ym59d$y|WU%4!QHOQ8Rw>AeJ7Ffve hwI9Yp9shsczIo660?&n!?!aur;OXk;vd$@?2>^?3qA~yg literal 0 HcmV?d00001