added little pipe legs

This commit is contained in:
Ellpeck 2020-04-16 19:47:09 +02:00
parent 50e2285680
commit 046637a1b5
6 changed files with 114 additions and 11 deletions

View file

@ -7,7 +7,8 @@ import java.util.Locale;
public enum ConnectionType implements IStringSerializable { public enum ConnectionType implements IStringSerializable {
CONNECTED(true), CONNECTED(true),
DISCONNECTED(false), DISCONNECTED(false),
BLOCKED(false); BLOCKED(false),
LEGS(false);
private final String name; private final String name;
private final boolean isConnected; private final boolean isConnected;

View file

@ -119,24 +119,25 @@ public class PipeBlock extends ContainerBlock {
return shape; return shape;
} }
private BlockState createState(World world, BlockPos pos, BlockState current) { private BlockState createState(World world, BlockPos pos, BlockState curr) {
BlockState state = this.getDefaultState(); BlockState state = this.getDefaultState();
for (Map.Entry<Direction, EnumProperty<ConnectionType>> entry : DIRECTIONS.entrySet()) { for (Direction dir : Direction.values()) {
ConnectionType type = getConnectionType(world, pos, entry.getKey()); EnumProperty<ConnectionType> prop = DIRECTIONS.get(dir);
if (type.isConnected() && current.get(entry.getValue()) == ConnectionType.BLOCKED) ConnectionType type = getConnectionType(world, pos, dir, state);
type = ConnectionType.BLOCKED; // don't reconnect on blocked faces
state = state.with(entry.getValue(), type); if (!type.isConnected() || curr.get(prop) != ConnectionType.BLOCKED)
state = state.with(prop, type);
} }
return state; 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); BlockPos offset = pos.offset(direction);
if (!world.isBlockLoaded(offset)) if (!world.isBlockLoaded(offset))
return ConnectionType.DISCONNECTED; return ConnectionType.DISCONNECTED;
BlockState state = world.getBlockState(offset); BlockState offState = world.getBlockState(offset);
if (state.getBlock() instanceof PipeBlock) { if (offState.getBlock() instanceof PipeBlock) {
if (state.get(DIRECTIONS.get(direction.getOpposite())) == ConnectionType.BLOCKED) if (offState.get(DIRECTIONS.get(direction.getOpposite())) == ConnectionType.BLOCKED)
return ConnectionType.BLOCKED; return ConnectionType.BLOCKED;
return ConnectionType.CONNECTED; return ConnectionType.CONNECTED;
} }
@ -146,9 +147,21 @@ public class PipeBlock extends ContainerBlock {
if (handler != null) if (handler != null)
return ConnectionType.CONNECTED; 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; 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) { public static void onStateChanged(World world, BlockPos pos, BlockState newState) {
PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, world, pos); PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, world, pos);
if (tile != null && !tile.isConnectedInventory()) if (tile != null && !tile.isConnectedInventory())

View file

@ -57,6 +57,62 @@
"model": "prettypipes:block/pipe_end", "model": "prettypipes:block/pipe_end",
"x": 270 "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
}
} }
] ]
} }

View file

@ -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"}
}
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 182 B

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 B