Improved model structure
This commit is contained in:
@@ -45,10 +45,16 @@ public class ModBlocks {
|
||||
CableBlock::new,
|
||||
AbstractBlock.Settings.create().sounds(BlockSoundGroup.COPPER),
|
||||
true);
|
||||
public static final Block QUAD_CABLE = register(
|
||||
"quad_cable",
|
||||
QuadCableBlock::new,
|
||||
AbstractBlock.Settings.create().sounds(BlockSoundGroup.COPPER),
|
||||
true);
|
||||
|
||||
public static void initialize() {
|
||||
ItemGroupEvents.modifyEntriesEvent(ItemGroups.REDSTONE).register((itemGroup) -> {
|
||||
itemGroup.add(CABLE.asItem());
|
||||
itemGroup.add(QUAD_CABLE.asItem());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package dev.kleo.redstonerewired;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
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 QuadCableBlock 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 static final BooleanProperty UP = BooleanProperty.of("up");
|
||||
public static final BooleanProperty DOWN = BooleanProperty.of("down");
|
||||
|
||||
public QuadCableBlock(AbstractBlock.Settings settings) {
|
||||
super(settings);
|
||||
this.setDefaultState(this.stateManager.getDefaultState()
|
||||
.with(NORTH, false)
|
||||
.with(SOUTH, false)
|
||||
.with(EAST, false)
|
||||
.with(WEST, false)
|
||||
.with(UP, false)
|
||||
.with(DOWN, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
builder.add(NORTH, SOUTH, EAST, WEST, UP, DOWN);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock,
|
||||
WireOrientation wireOrientation, boolean notify) {
|
||||
updateStates(world, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
|
||||
updateStates(world, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
VoxelShape shape = Block.createCuboidShape(6, 6, 6, 10, 10, 10);
|
||||
|
||||
if (state.get(NORTH))
|
||||
shape = VoxelShapes.union(shape, Block.createCuboidShape(6, 6, 0, 10, 10, 6));
|
||||
if (state.get(SOUTH))
|
||||
shape = VoxelShapes.union(shape, Block.createCuboidShape(6, 6, 10, 10, 10, 16));
|
||||
if (state.get(EAST))
|
||||
shape = VoxelShapes.union(shape, Block.createCuboidShape(10, 6, 6, 16, 10, 10));
|
||||
if (state.get(WEST))
|
||||
shape = VoxelShapes.union(shape, Block.createCuboidShape(0, 6, 6, 6, 10, 10));
|
||||
if (state.get(UP))
|
||||
shape = VoxelShapes.union(shape, Block.createCuboidShape(6, 6, 6, 10, 16, 10));
|
||||
if (state.get(DOWN))
|
||||
shape = VoxelShapes.union(shape, Block.createCuboidShape(6, 0, 6, 10, 6, 10));
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
private void updateStates(World world, BlockPos pos, BlockState state) {
|
||||
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;
|
||||
boolean up = world.getBlockState(pos.up()).getBlock() instanceof CableBlock;
|
||||
boolean down = world.getBlockState(pos.down()).getBlock() instanceof CableBlock;
|
||||
|
||||
world.setBlockState(pos, state
|
||||
.with(NORTH, north || (south && !east && !west && !up && !down))
|
||||
.with(SOUTH, south || (north && !east && !west && !up && !down))
|
||||
.with(EAST, east || (!north && !south && west && !up && !down))
|
||||
.with(WEST, west || (!north && !south && east && !up && !down))
|
||||
.with(UP, up || (down && !north && !south && !east && !west))
|
||||
.with(DOWN, down || (up && !north && !south && !east && !west)), 2);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"multipart": [
|
||||
{ "apply": { "model": "redstone-rewired:block/cable_core" } },
|
||||
{ "apply": { "model": "redstone-rewired:block/cable/core" } },
|
||||
|
||||
{ "when": { "up": "true" }, "apply": { "model": "redstone-rewired:block/cable_up" } },
|
||||
{ "when": { "down": "true" }, "apply": { "model": "redstone-rewired:block/cable_down" } },
|
||||
{ "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" } }
|
||||
{ "when": { "up": "true" }, "apply": { "model": "redstone-rewired:block/cable/up" } },
|
||||
{ "when": { "down": "true" }, "apply": { "model": "redstone-rewired:block/cable/down" } },
|
||||
{ "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" } }
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user