-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
577f634
commit b838251
Showing
10 changed files
with
420 additions
and
0 deletions.
There are no files selected for viewing
165 changes: 165 additions & 0 deletions
165
src/main/java/com/redblueflame/herbocraft/blocks/cables/AbstractCableBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
package com.redblueflame.herbocraft.blocks.cables; | ||
|
||
import com.redblueflame.herbocraft.blocks.AbstractProgressBlock; | ||
import com.redblueflame.herbocraft.transport.CableConnection; | ||
import net.minecraft.block.*; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.item.ItemPlacementContext; | ||
import net.minecraft.state.StateManager; | ||
import net.minecraft.state.property.EnumProperty; | ||
import net.minecraft.state.property.Property; | ||
import net.minecraft.util.function.BooleanBiFunction; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.util.shape.VoxelShape; | ||
import net.minecraft.util.shape.VoxelShapes; | ||
import net.minecraft.world.BlockView; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.WorldAccess; | ||
|
||
public abstract class AbstractCableBlock extends Block implements BlockEntityProvider { | ||
public static final EnumProperty<CableConnection> NORTH = EnumProperty.of("north", CableConnection.class); | ||
public static final EnumProperty<CableConnection> EAST = EnumProperty.of("east", CableConnection.class); | ||
public static final EnumProperty<CableConnection> SOUTH = EnumProperty.of("south", CableConnection.class); | ||
public static final EnumProperty<CableConnection> WEST = EnumProperty.of("west", CableConnection.class); | ||
public static final EnumProperty<CableConnection> UP = EnumProperty.of("up", CableConnection.class); | ||
public static final EnumProperty<CableConnection> DOWN = EnumProperty.of("down", CableConnection.class); | ||
|
||
public AbstractCableBlock(Settings settings) { | ||
super(settings); | ||
setDefaultState(this.getStateManager().getDefaultState() | ||
.with(NORTH, CableConnection.DISCONNECTED) | ||
.with(EAST, CableConnection.DISCONNECTED) | ||
.with(SOUTH, CableConnection.DISCONNECTED) | ||
.with(WEST, CableConnection.DISCONNECTED) | ||
.with(UP, CableConnection.DISCONNECTED) | ||
.with(DOWN, CableConnection.DISCONNECTED) | ||
); | ||
} | ||
|
||
@Override | ||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { | ||
builder.add(NORTH); | ||
builder.add(EAST); | ||
builder.add(SOUTH); | ||
builder.add(WEST); | ||
builder.add(UP); | ||
builder.add(DOWN); | ||
} | ||
|
||
private static Property<CableConnection> directionToProperty(Direction dir) { | ||
switch (dir) { | ||
case NORTH: | ||
return NORTH; | ||
case EAST: | ||
return EAST; | ||
case SOUTH: | ||
return SOUTH; | ||
case WEST: | ||
return WEST; | ||
case UP: | ||
return UP; | ||
case DOWN: | ||
return DOWN; | ||
} | ||
return null; | ||
} | ||
|
||
private static class CursedShapeHolder { | ||
private final VoxelShape connected; | ||
private final VoxelShape blockConnected; | ||
private final Property<CableConnection> prop; | ||
|
||
public CursedShapeHolder(Property<CableConnection> prop, VoxelShape connected, VoxelShape blockConnected1, VoxelShape blockConnected2) { | ||
this.connected = connected; | ||
this.blockConnected = VoxelShapes.combineAndSimplify(blockConnected1, blockConnected2, BooleanBiFunction.OR); | ||
this.prop = prop; | ||
} | ||
|
||
public VoxelShape get(BlockState state, VoxelShape shape) { | ||
switch (state.get(prop)) { | ||
case CONNECTED: | ||
return VoxelShapes.union(shape, connected); | ||
case BLOCK_CONNECTED: | ||
return VoxelShapes.union(shape, blockConnected); | ||
} | ||
return shape; | ||
} | ||
} | ||
|
||
private static final CursedShapeHolder NORTH_SHAPE = new CursedShapeHolder(NORTH, | ||
Block.createCuboidShape(4, 4, 0, 12, 12, 4), | ||
Block.createCuboidShape(4, 4, 1, 12, 12, 4), | ||
Block.createCuboidShape(3, 3, 0, 13, 13, 1)); | ||
|
||
private static final CursedShapeHolder EAST_SHAPE = new CursedShapeHolder(EAST, | ||
Block.createCuboidShape(12, 4, 4, 16, 12, 12), | ||
Block.createCuboidShape(12, 4, 4, 15, 12, 12), | ||
Block.createCuboidShape(15, 3, 3, 16, 13, 13)); | ||
|
||
private static final CursedShapeHolder SOUTH_SHAPE = new CursedShapeHolder(SOUTH, | ||
Block.createCuboidShape(4, 4, 12, 12, 12, 16), | ||
Block.createCuboidShape(4, 4, 12, 12, 12, 15), | ||
Block.createCuboidShape(3, 3, 15, 13, 13, 16)); | ||
|
||
private static final CursedShapeHolder WEST_SHAPE = new CursedShapeHolder(WEST, | ||
Block.createCuboidShape(0, 4, 4, 4, 12, 12), | ||
Block.createCuboidShape(1, 4, 4, 4, 12, 12), | ||
Block.createCuboidShape(0, 3, 3, 1, 13, 13)); | ||
|
||
private static final CursedShapeHolder UP_SHAPE = new CursedShapeHolder(UP, | ||
Block.createCuboidShape(4, 12, 4, 12, 16, 12), | ||
Block.createCuboidShape(4, 12, 4, 12, 15, 12), | ||
Block.createCuboidShape(3, 15, 3, 13, 16, 13)); | ||
|
||
private static final CursedShapeHolder DOWN_SHAPE = new CursedShapeHolder(DOWN, | ||
Block.createCuboidShape(4, 0, 4, 12, 4, 12), | ||
Block.createCuboidShape(4, 1, 4, 12, 4, 12), | ||
Block.createCuboidShape(3, 0, 3, 13, 1, 13)); | ||
|
||
@Override | ||
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) { | ||
VoxelShape shape = Block.createCuboidShape(4, 4, 4, 12, 12, 12); | ||
shape = NORTH_SHAPE.get(state, shape); | ||
shape = EAST_SHAPE.get(state, shape); | ||
shape = SOUTH_SHAPE.get(state, shape); | ||
shape = WEST_SHAPE.get(state, shape); | ||
shape = UP_SHAPE.get(state, shape); | ||
shape = DOWN_SHAPE.get(state, shape); | ||
return shape; | ||
} | ||
|
||
@Override | ||
public BlockState getPlacementState(ItemPlacementContext ctx) { | ||
BlockView world = ctx.getWorld(); | ||
BlockPos pos = ctx.getBlockPos(); | ||
BlockState state = getDefaultState(); | ||
// TODO: check fluid, check for component rather than side solid | ||
for (Direction dir : Direction.values()) { | ||
BlockPos neighborPos = pos.offset(dir); | ||
BlockState neighborState = world.getBlockState(neighborPos); | ||
if (neighborState.getBlock() instanceof AbstractCableBlock) { | ||
state = state.with(directionToProperty(dir), CableConnection.CONNECTED); | ||
} else if (neighborState.getBlock() instanceof AbstractProgressBlock) { | ||
state = state.with(directionToProperty(dir), CableConnection.BLOCK_CONNECTED); | ||
} | ||
} | ||
return state; | ||
} | ||
|
||
@Override | ||
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) { | ||
// TODO: check fluid, check for component rather than side solid | ||
if (neighborState.getBlock() instanceof AbstractCableBlock) { | ||
return state.with(directionToProperty(facing), CableConnection.CONNECTED); | ||
} else if (neighborState.getBlock() instanceof AbstractProgressBlock) { | ||
return state.with(directionToProperty(facing), CableConnection.BLOCK_CONNECTED); | ||
} | ||
return state.with(directionToProperty(facing), CableConnection.DISCONNECTED); | ||
} | ||
|
||
@Override | ||
public BlockRenderType getRenderType(BlockState blockState) { | ||
return BlockRenderType.MODEL; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/redblueflame/herbocraft/blocks/cables/AbstractCableBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.redblueflame.herbocraft.blocks.cables; | ||
|
||
public abstract class AbstractCableBlockEntity { | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/redblueflame/herbocraft/blocks/cables/CellulosePipe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.redblueflame.herbocraft.blocks.cables; | ||
|
||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.world.BlockView; | ||
|
||
public class CellulosePipe extends AbstractCableBlock { | ||
public CellulosePipe(Settings settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
public BlockEntity createBlockEntity(BlockView world) { | ||
return null; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/redblueflame/herbocraft/transport/CableConnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.redblueflame.herbocraft.transport; | ||
|
||
import net.minecraft.util.StringIdentifiable; | ||
|
||
public enum CableConnection implements StringIdentifiable { | ||
DISCONNECTED("disconnected"), | ||
CONNECTED("connected"), | ||
BLOCK_CONNECTED("block_connected"); | ||
|
||
private final String name; | ||
|
||
CableConnection(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String asString() { | ||
return name; | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
src/main/resources/assets/herbocraft/blockstates/cellulose_pipe.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
{ | ||
"multipart": [ | ||
{ | ||
"apply": { | ||
"model": "herbocraft:block/pipes/cellulose_core" | ||
} | ||
}, | ||
{ | ||
"when": { | ||
"north": "connected" | ||
}, | ||
"apply": { | ||
"model": "herbocraft:block/pipes/cellulose_tube" | ||
} | ||
}, | ||
{ | ||
"when": { | ||
"east": "connected" | ||
}, | ||
"apply": { | ||
"model": "herbocraft:block/pipes/cellulose_tube", | ||
"y": 90 | ||
} | ||
}, | ||
{ | ||
"when": { | ||
"south": "connected" | ||
}, | ||
"apply": { | ||
"model": "herbocraft:block/pipes/cellulose_tube", | ||
"y": 180 | ||
} | ||
}, | ||
{ | ||
"when": { | ||
"west": "connected" | ||
}, | ||
"apply": { | ||
"model": "herbocraft:block/pipes/cellulose_tube", | ||
"y": 270 | ||
} | ||
}, | ||
{ | ||
"when": { | ||
"up": "connected" | ||
}, | ||
"apply": { | ||
"model": "herbocraft:block/pipes/cellulose_tube", | ||
"x": 270 | ||
} | ||
}, | ||
{ | ||
"when": { | ||
"down": "connected" | ||
}, | ||
"apply": { | ||
"model": "herbocraft:block/pipes/cellulose_tube", | ||
"x": 90 | ||
} | ||
}, | ||
{ | ||
"when": { | ||
"north": "block_connected" | ||
}, | ||
"apply": { | ||
"model": "herbocraft:block/pipes/cellulose_connect" | ||
} | ||
}, | ||
{ | ||
"when": { | ||
"east": "block_connected" | ||
}, | ||
"apply": { | ||
"model": "herbocraft:block/pipes/cellulose_connect", | ||
"y": 90 | ||
} | ||
}, | ||
{ | ||
"when": { | ||
"south": "block_connected" | ||
}, | ||
"apply": { | ||
"model": "herbocraft:block/pipes/cellulose_connect", | ||
"y": 180 | ||
} | ||
}, | ||
{ | ||
"when": { | ||
"west": "block_connected" | ||
}, | ||
"apply": { | ||
"model": "herbocraft:block/pipes/cellulose_connect", | ||
"y": 270 | ||
} | ||
}, | ||
{ | ||
"when": { | ||
"up": "block_connected" | ||
}, | ||
"apply": { | ||
"model": "herbocraft:block/pipes/cellulose_connect", | ||
"x": 270 | ||
} | ||
}, | ||
{ | ||
"when": { | ||
"down": "block_connected" | ||
}, | ||
"apply": { | ||
"model": "herbocraft:block/pipes/cellulose_connect", | ||
"x": 90 | ||
} | ||
} | ||
] | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/resources/assets/herbocraft/models/block/pipes/cellulose_connect.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"credit": "Made with Blockbench", | ||
"texture_size": [32, 32], | ||
"textures": { | ||
"0": "herbocraft:block/cellulose_core", | ||
"particle": "herbocraft:block/cellulose_core" | ||
}, | ||
"elements": [ | ||
{ | ||
"name": "pipe_connect", | ||
"from": [6.5, 6.5, 2], | ||
"to": [9.5, 9.5, 6], | ||
"rotation": {"angle": 0, "axis": "y", "origin": [8, 8, 4]}, | ||
"faces": { | ||
"north": {"uv": [8, 0, 9.5, 3], "texture": "#0"}, | ||
"east": {"uv": [8, 0, 9.5, 3], "rotation": 90, "texture": "#0"}, | ||
"south": {"uv": [8, 0, 9.5, 3], "texture": "#0"}, | ||
"west": {"uv": [8, 0, 9.5, 3], "rotation": 270, "texture": "#0"}, | ||
"up": {"uv": [8, 0, 9.5, 3], "texture": "#0"}, | ||
"down": {"uv": [8, 0, 9.5, 3.1575], "texture": "#0"} | ||
} | ||
}, | ||
{ | ||
"from": [2, 2, 0], | ||
"to": [14, 14, 1], | ||
"rotation": {"angle": 0, "axis": "y", "origin": [15, 15, 8]}, | ||
"faces": { | ||
"north": {"uv": [0, 8, 6, 14], "texture": "#0"}, | ||
"east": {"uv": [9.5, 0, 10, 4], "texture": "#0"}, | ||
"south": {"uv": [0, 8, 6, 14], "texture": "#0"}, | ||
"west": {"uv": [9.5, 0, 10, 4], "texture": "#0"}, | ||
"up": {"uv": [12, 15.5, 16, 16], "texture": "#0"}, | ||
"down": {"uv": [12, 15.5, 16, 16], "texture": "#0"} | ||
} | ||
}, | ||
{ | ||
"from": [4, 4, 1], | ||
"to": [12, 12, 2], | ||
"rotation": {"angle": 0, "axis": "y", "origin": [8, 8, 1.5]}, | ||
"faces": { | ||
"north": {"uv": [0, 8, 6, 14], "texture": "#0"}, | ||
"east": {"uv": [10.5, 0, 11, 4], "texture": "#0"}, | ||
"south": {"uv": [0, 8, 6, 14], "texture": "#0"}, | ||
"west": {"uv": [10.5, 0, 11, 4], "texture": "#0"}, | ||
"up": {"uv": [12, 15, 16, 15.5], "texture": "#0"}, | ||
"down": {"uv": [12, 15, 16, 15.5], "texture": "#0"} | ||
} | ||
} | ||
] | ||
} |
Oops, something went wrong.