mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-22 11:53:29 +01:00
added little pipe legs
This commit is contained in:
parent
50e2285680
commit
046637a1b5
6 changed files with 114 additions and 11 deletions
|
@ -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;
|
||||
|
|
|
@ -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<Direction, EnumProperty<ConnectionType>> 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<ConnectionType> 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())
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -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 |
Loading…
Reference in a new issue