From 8d81724bd4389afbe660c0c5e6885c10474c697a Mon Sep 17 00:00:00 2001 From: Leo dev Date: Wed, 12 Nov 2025 20:05:45 +0100 Subject: [PATCH] Simple directional cable model --- .../dev/kleo/redstonerewired/CableBlock.java | 66 +++++++++++++++++++ .../dev/kleo/redstonerewired/ModBlocks.java | 2 +- .../redstone-rewired/blockstates/cable.json | 11 +++- .../models/block/cable_core.json | 23 +++++++ .../models/block/cable_east.json | 36 ++++++++++ .../models/block/cable_north.json | 23 +++++++ .../models/block/cable_south.json | 23 +++++++ .../models/block/cable_west.json | 24 +++++++ 8 files changed, 204 insertions(+), 4 deletions(-) create mode 100644 src/main/java/dev/kleo/redstonerewired/CableBlock.java create mode 100644 src/main/resources/assets/redstone-rewired/models/block/cable_core.json create mode 100644 src/main/resources/assets/redstone-rewired/models/block/cable_east.json create mode 100644 src/main/resources/assets/redstone-rewired/models/block/cable_north.json create mode 100644 src/main/resources/assets/redstone-rewired/models/block/cable_south.json create mode 100644 src/main/resources/assets/redstone-rewired/models/block/cable_west.json diff --git a/src/main/java/dev/kleo/redstonerewired/CableBlock.java b/src/main/java/dev/kleo/redstonerewired/CableBlock.java new file mode 100644 index 0000000..8e7b4da --- /dev/null +++ b/src/main/java/dev/kleo/redstonerewired/CableBlock.java @@ -0,0 +1,66 @@ +package dev.kleo.redstonerewired; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.ShapeContext; +import net.minecraft.block.AbstractBlock; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import net.minecraft.world.block.WireOrientation; +import net.minecraft.state.StateManager; +import net.minecraft.state.property.BooleanProperty; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; + +public class CableBlock extends Block { + + public static final BooleanProperty NORTH = BooleanProperty.of("north"); + public static final BooleanProperty SOUTH = BooleanProperty.of("south"); + public static final BooleanProperty EAST = BooleanProperty.of("east"); + public static final BooleanProperty WEST = BooleanProperty.of("west"); + + public CableBlock(AbstractBlock.Settings settings) { + super(settings); + this.setDefaultState(this.stateManager.getDefaultState() + .with(NORTH, false) + .with(SOUTH, false) + .with(EAST, false) + .with(WEST, false)); + } + + @Override + protected void appendProperties(StateManager.Builder builder) { + builder.add(NORTH, SOUTH, EAST, WEST); + } + + @Override + protected void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, + WireOrientation wireOrientation, boolean notify) { + boolean north = world.getBlockState(pos.north()).getBlock() instanceof CableBlock; + boolean south = world.getBlockState(pos.south()).getBlock() instanceof CableBlock; + boolean east = world.getBlockState(pos.east()).getBlock() instanceof CableBlock; + boolean west = world.getBlockState(pos.west()).getBlock() instanceof CableBlock; + + world.setBlockState(pos, state.with(NORTH, north) + .with(SOUTH, south) + .with(EAST, east) + .with(WEST, west), 2); + } + + @Override + protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + VoxelShape shape = Block.createCuboidShape(6, 0, 6, 10, 1, 10); // center post + + if (state.get(NORTH)) + shape = VoxelShapes.union(shape, Block.createCuboidShape(6, 0, 0, 10, 1, 6)); + if (state.get(SOUTH)) + shape = VoxelShapes.union(shape, Block.createCuboidShape(6, 0, 10, 10, 1, 16)); + if (state.get(EAST)) + shape = VoxelShapes.union(shape, Block.createCuboidShape(10, 0, 6, 16, 1, 10)); + if (state.get(WEST)) + shape = VoxelShapes.union(shape, Block.createCuboidShape(0, 0, 6, 6, 1, 10)); + + return shape; + } +} diff --git a/src/main/java/dev/kleo/redstonerewired/ModBlocks.java b/src/main/java/dev/kleo/redstonerewired/ModBlocks.java index 33bdaee..78f2a12 100644 --- a/src/main/java/dev/kleo/redstonerewired/ModBlocks.java +++ b/src/main/java/dev/kleo/redstonerewired/ModBlocks.java @@ -42,7 +42,7 @@ public class ModBlocks { public static final Block CABLE = register( "cable", - Block::new, + CableBlock::new, AbstractBlock.Settings.create().sounds(BlockSoundGroup.COPPER), true); diff --git a/src/main/resources/assets/redstone-rewired/blockstates/cable.json b/src/main/resources/assets/redstone-rewired/blockstates/cable.json index f5ef581..b174d2a 100644 --- a/src/main/resources/assets/redstone-rewired/blockstates/cable.json +++ b/src/main/resources/assets/redstone-rewired/blockstates/cable.json @@ -1,5 +1,10 @@ { - "variants": { - "": { "model": "redstone-rewired:block/cable" } - } + "multipart": [ + { "apply": { "model": "redstone-rewired:block/cable_core" } }, + + { "when": { "north": "true" }, "apply": { "model": "redstone-rewired:block/cable_north" } }, + { "when": { "south": "true" }, "apply": { "model": "redstone-rewired:block/cable_south" } }, + { "when": { "east": "true" }, "apply": { "model": "redstone-rewired:block/cable_east" } }, + { "when": { "west": "true" }, "apply": { "model": "redstone-rewired:block/cable_west" } } + ] } diff --git a/src/main/resources/assets/redstone-rewired/models/block/cable_core.json b/src/main/resources/assets/redstone-rewired/models/block/cable_core.json new file mode 100644 index 0000000..da7bb0a --- /dev/null +++ b/src/main/resources/assets/redstone-rewired/models/block/cable_core.json @@ -0,0 +1,23 @@ +{ + "format_version": "1.21.6", + "credit": "Made with Blockbench", + "texture_size": [32, 32], + "textures": { + "0": "redstone-rewired:block/cable", + "particle": "redstone-rewired:block/cable" + }, + "elements": [ + { + "from": [6.75, 6.75, 6.75], + "to": [9.25, 9.25, 9.25], + "faces": { + "north": {"uv": [3, 1.5, 4.5, 3], "texture": "#0"}, + "east": {"uv": [0, 0, 8, 1.5], "texture": "#0"}, + "south": {"uv": [3, 0, 4.5, 1.5], "texture": "#0"}, + "west": {"uv": [0, 1.5, 8, 3], "texture": "#0"}, + "up": {"uv": [1.5, 11, 0, 3], "texture": "#0"}, + "down": {"uv": [3, 3, 1.5, 11], "texture": "#0"} + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/redstone-rewired/models/block/cable_east.json b/src/main/resources/assets/redstone-rewired/models/block/cable_east.json new file mode 100644 index 0000000..b24ed39 --- /dev/null +++ b/src/main/resources/assets/redstone-rewired/models/block/cable_east.json @@ -0,0 +1,36 @@ +{ + "format_version": "1.21.6", + "credit": "Made with Blockbench", + "texture_size": [32, 32], + "textures": { + "0": "redstone-rewired:block/cable", + "particle": "redstone-rewired:block/cable" + }, + "elements": [ + { + "from": [9.25, 6.75, 6.75], + "to": [16, 9.25, 9.25], + "rotation": {"angle": 0, "axis": "y", "origin": [6.75, 6.75, 6.75]}, + "faces": { + "north": {"uv": [0, 0, 8, 1.5], "texture": "#0"}, + "east": {"uv": [3, 4.5, 4.5, 6], "texture": "#0"}, + "south": {"uv": [0, 1.5, 8, 3], "texture": "#0"}, + "west": {"uv": [3, 3, 4.5, 4.5], "texture": "#0"}, + "up": {"uv": [1.5, 11, 0, 3], "rotation": 270, "texture": "#0"}, + "down": {"uv": [3, 3, 1.5, 11], "rotation": 90, "texture": "#0"} + } + }, + { + "from": [6.75, 6.75, 6.75], + "to": [9.25, 9.25, 9.25], + "faces": { + "north": {"uv": [3, 1.5, 4.5, 3], "texture": "#missing"}, + "east": {"uv": [0, 0, 8, 1.5], "texture": "#missing"}, + "south": {"uv": [3, 0, 4.5, 1.5], "texture": "#missing"}, + "west": {"uv": [0, 1.5, 8, 3], "texture": "#missing"}, + "up": {"uv": [1.5, 11, 0, 3], "texture": "#missing"}, + "down": {"uv": [3, 3, 1.5, 11], "texture": "#missing"} + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/redstone-rewired/models/block/cable_north.json b/src/main/resources/assets/redstone-rewired/models/block/cable_north.json new file mode 100644 index 0000000..7014378 --- /dev/null +++ b/src/main/resources/assets/redstone-rewired/models/block/cable_north.json @@ -0,0 +1,23 @@ +{ + "format_version": "1.21.6", + "credit": "Made with Blockbench", + "texture_size": [32, 32], + "textures": { + "0": "redstone-rewired:block/cable", + "particle": "redstone-rewired:block/cable" + }, + "elements": [ + { + "from": [6.75, 6.75, 0], + "to": [9.25, 9.25, 6.75], + "faces": { + "north": {"uv": [3, 3, 4.5, 4.5], "texture": "#0"}, + "east": {"uv": [0, 0, 8, 1.5], "texture": "#0"}, + "south": {"uv": [3, 4.5, 4.5, 6], "texture": "#0"}, + "west": {"uv": [0, 1.5, 8, 3], "texture": "#0"}, + "up": {"uv": [1.5, 11, 0, 3], "texture": "#0"}, + "down": {"uv": [3, 3, 1.5, 11], "texture": "#0"} + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/redstone-rewired/models/block/cable_south.json b/src/main/resources/assets/redstone-rewired/models/block/cable_south.json new file mode 100644 index 0000000..81189a9 --- /dev/null +++ b/src/main/resources/assets/redstone-rewired/models/block/cable_south.json @@ -0,0 +1,23 @@ +{ + "format_version": "1.21.6", + "credit": "Made with Blockbench", + "texture_size": [32, 32], + "textures": { + "0": "redstone-rewired:block/cable", + "particle": "redstone-rewired:block/cable" + }, + "elements": [ + { + "from": [6.75, 6.75, 9.25], + "to": [9.25, 9.25, 16], + "faces": { + "north": {"uv": [3, 3, 4.5, 4.5], "texture": "#0"}, + "east": {"uv": [0, 0, 8, 1.5], "texture": "#0"}, + "south": {"uv": [3, 4.5, 4.5, 6], "texture": "#0"}, + "west": {"uv": [0, 1.5, 8, 3], "texture": "#0"}, + "up": {"uv": [1.5, 11, 0, 3], "texture": "#0"}, + "down": {"uv": [3, 3, 1.5, 11], "texture": "#0"} + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/redstone-rewired/models/block/cable_west.json b/src/main/resources/assets/redstone-rewired/models/block/cable_west.json new file mode 100644 index 0000000..97a99af --- /dev/null +++ b/src/main/resources/assets/redstone-rewired/models/block/cable_west.json @@ -0,0 +1,24 @@ +{ + "format_version": "1.21.6", + "credit": "Made with Blockbench", + "texture_size": [32, 32], + "textures": { + "0": "redstone-rewired:block/cable", + "particle": "redstone-rewired:block/cable" + }, + "elements": [ + { + "from": [0, 6.75, 6.75], + "to": [6.75, 9.25, 9.25], + "rotation": {"angle": 0, "axis": "y", "origin": [6.75, 6.75, 6.75]}, + "faces": { + "north": {"uv": [0, 0, 8, 1.5], "texture": "#0"}, + "east": {"uv": [3, 4.5, 4.5, 6], "texture": "#0"}, + "south": {"uv": [0, 1.5, 8, 3], "texture": "#0"}, + "west": {"uv": [3, 3, 4.5, 4.5], "texture": "#0"}, + "up": {"uv": [1.5, 11, 0, 3], "rotation": 270, "texture": "#0"}, + "down": {"uv": [3, 3, 1.5, 11], "rotation": 90, "texture": "#0"} + } + } + ] +} \ No newline at end of file