diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/ConnectionType.java b/src/main/java/de/ellpeck/prettypipes/pipe/ConnectionType.java index 0b4dc24..16172e9 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/ConnectionType.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/ConnectionType.java @@ -7,7 +7,8 @@ import java.util.Locale; public enum ConnectionType implements IStringSerializable { CONNECTED(true), DISCONNECTED(false), - BLOCKED(false); + BLOCKED(false), + LEGS(false); private final String name; private final boolean isConnected; diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java index 25c2f62..fa3fc5c 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlock.java @@ -119,24 +119,25 @@ public class PipeBlock extends ContainerBlock { return shape; } - private BlockState createState(World world, BlockPos pos, BlockState current) { + private BlockState createState(World world, BlockPos pos, BlockState curr) { BlockState state = this.getDefaultState(); - for (Map.Entry> entry : DIRECTIONS.entrySet()) { - ConnectionType type = getConnectionType(world, pos, entry.getKey()); - if (type.isConnected() && current.get(entry.getValue()) == ConnectionType.BLOCKED) - type = ConnectionType.BLOCKED; - state = state.with(entry.getValue(), type); + for (Direction dir : Direction.values()) { + EnumProperty prop = DIRECTIONS.get(dir); + ConnectionType type = getConnectionType(world, pos, dir, state); + // don't reconnect on blocked faces + if (!type.isConnected() || curr.get(prop) != ConnectionType.BLOCKED) + state = state.with(prop, type); } return state; } - private static ConnectionType getConnectionType(World world, BlockPos pos, Direction direction) { + private static ConnectionType getConnectionType(World world, BlockPos pos, Direction direction, BlockState state) { BlockPos offset = pos.offset(direction); if (!world.isBlockLoaded(offset)) return ConnectionType.DISCONNECTED; - BlockState state = world.getBlockState(offset); - if (state.getBlock() instanceof PipeBlock) { - if (state.get(DIRECTIONS.get(direction.getOpposite())) == ConnectionType.BLOCKED) + BlockState offState = world.getBlockState(offset); + if (offState.getBlock() instanceof PipeBlock) { + if (offState.get(DIRECTIONS.get(direction.getOpposite())) == ConnectionType.BLOCKED) return ConnectionType.BLOCKED; return ConnectionType.CONNECTED; } @@ -146,9 +147,21 @@ public class PipeBlock extends ContainerBlock { if (handler != null) return ConnectionType.CONNECTED; } + if (hasLegsTo(world, offState, offset, direction)) { + if (DIRECTIONS.values().stream().noneMatch(d -> state.get(d) == ConnectionType.LEGS)) + return ConnectionType.LEGS; + } return ConnectionType.DISCONNECTED; } + private static boolean hasLegsTo(World world, BlockState state, BlockPos pos, Direction direction) { + if (state.getBlock() instanceof WallBlock || state.getBlock() instanceof FenceBlock) + return direction == Direction.DOWN; + if (state.getMaterial() == Material.ROCK || state.getMaterial() == Material.IRON) + return hasSolidSide(state, world, pos, direction.getOpposite()); + return false; + } + public static void onStateChanged(World world, BlockPos pos, BlockState newState) { PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, world, pos); if (tile != null && !tile.isConnectedInventory()) diff --git a/src/main/resources/assets/prettypipes/blockstates/pipe.json b/src/main/resources/assets/prettypipes/blockstates/pipe.json index e0433a5..7662ce3 100644 --- a/src/main/resources/assets/prettypipes/blockstates/pipe.json +++ b/src/main/resources/assets/prettypipes/blockstates/pipe.json @@ -57,6 +57,62 @@ "model": "prettypipes:block/pipe_end", "x": 270 } + }, + { + "when": { + "north": "legs" + }, + "apply": { + "model": "prettypipes:block/pipe_legs", + "x": 90, + "y": 180 + } + }, + { + "when": { + "south": "legs" + }, + "apply": { + "model": "prettypipes:block/pipe_legs", + "x": 90 + } + }, + { + "when": { + "east": "legs" + }, + "apply": { + "model": "prettypipes:block/pipe_legs", + "x": 90, + "y": 270 + } + }, + { + "when": { + "west": "legs" + }, + "apply": { + "model": "prettypipes:block/pipe_legs", + "x": 90, + "y": 90 + } + }, + { + "when": { + "down": "legs" + }, + "apply": { + "model": "prettypipes:block/pipe_legs" + } + }, + { + "when": { + "up": "legs" + }, + "apply": { + "model": "prettypipes:block/pipe_legs", + "x": 180 + } } ] } \ No newline at end of file diff --git a/src/main/resources/assets/prettypipes/models/block/pipe_legs.json b/src/main/resources/assets/prettypipes/models/block/pipe_legs.json new file mode 100644 index 0000000..73164ee --- /dev/null +++ b/src/main/resources/assets/prettypipes/models/block/pipe_legs.json @@ -0,0 +1,33 @@ +{ + "credit": "Made with Blockbench", + "parent": "block/block", + "textures": { + "1": "prettypipes:block/pipe_legs", + "particle": "prettypipes:block/pipe" + }, + "elements": [ + { + "from": [6, 4, 6], + "to": [10, 5, 10], + "faces": { + "north": {"uv": [0, 7, 4, 8], "texture": "#1"}, + "east": {"uv": [0, 7, 4, 8], "texture": "#1"}, + "south": {"uv": [0, 7, 4, 8], "texture": "#1"}, + "west": {"uv": [0, 7, 4, 8], "texture": "#1"}, + "up": {"uv": [1, 1, 5, 5], "texture": "#1"}, + "down": {"uv": [1, 1, 5, 5], "texture": "#1"} + } + }, + { + "from": [7, 0, 7], + "to": [9, 4, 9], + "faces": { + "north": {"uv": [1, 1, 3, 5], "texture": "#1"}, + "east": {"uv": [1, 1, 3, 5], "texture": "#1"}, + "south": {"uv": [1, 1, 3, 5], "texture": "#1"}, + "west": {"uv": [1, 1, 3, 5], "texture": "#1"}, + "down": {"uv": [1, 1, 3, 3], "texture": "#1"} + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/prettypipes/textures/block/pipe.png b/src/main/resources/assets/prettypipes/textures/block/pipe.png index 185ea6e..37a92a1 100644 Binary files a/src/main/resources/assets/prettypipes/textures/block/pipe.png and b/src/main/resources/assets/prettypipes/textures/block/pipe.png differ diff --git a/src/main/resources/assets/prettypipes/textures/block/pipe_legs.png b/src/main/resources/assets/prettypipes/textures/block/pipe_legs.png new file mode 100644 index 0000000..c477343 Binary files /dev/null and b/src/main/resources/assets/prettypipes/textures/block/pipe_legs.png differ