[1.17.x] implements canConnectRedstone(), Redstone dust now defers to the blockstate for determining connectivity (#8014)

This commit is contained in:
Rikka0_0小六花 authored and GitHub committed 2021-09-27 12:26:17 -07:00
1 parent 347a0b3c0d
commit cd67762bee
9 files changed
+216

No files matched your search

@@ -719,4 +719,54 @@ public interface IForgeBlock
{
return state.is(Blocks.SCAFFOLDING);
}
/**
* Whether redstone dust should visually connect to this block on a given side
* <p>
* The default implementation is identical to
* {@link RedStoneWireBlock#shouldConnectTo(BlockState, Direction)}
*
* <p>
* {@link RedStoneWireBlock} updates its visual connection when
* {@link BlockState#updateShape(Direction, BlockState, LevelAccessor, BlockPos, BlockPos)}
* is called, this callback is used during the evaluation of its new shape.
*
* @param state The current state
* @param world The world
* @param pos The block position in world
* @param direction The coming direction of the redstone dust connection (with respect to the block at pos)
* @return True if redstone dust should visually connect on the side passed
* <p>
* If the return value is evaluated based on world and pos (e.g. from BlockEntity), then the implementation of
* this block should notify its neighbors to update their shapes when necessary. Consider using
* {@link BlockState#updateNeighbourShapes(LevelAccessor, BlockPos, int, int)} or
* {@link BlockState#updateShape(Direction, BlockState, LevelAccessor, BlockPos, BlockPos)}.
* <p>
* Example:
* <p>
* 1. {@code yourBlockState.updateNeighbourShapes(world, yourBlockPos, UPDATE_ALL);}
* <p>
* 2. {@code neighborState.updateShape(fromDirection, stateOfYourBlock, world, neighborBlockPos, yourBlockPos)},
* where {@code fromDirection} is defined from the neighbor block's point of view.
*/
default boolean canConnectRedstone(BlockState state, BlockGetter world, BlockPos pos, @Nullable Direction direction)
{
if (state.is(Blocks.REDSTONE_WIRE))
{
return true;
}
else if (state.is(Blocks.REPEATER))
{
Direction facing = state.getValue(RepeaterBlock.FACING);
return facing == direction || facing.getOpposite() == direction;
}
else if (state.is(Blocks.OBSERVER))
{
return direction == state.getValue(ObserverBlock.FACING);
}
else
{
return state.isSignalSource() && direction != null;
}
}
}
@@ -641,4 +641,19 @@ public interface IForgeBlockState
{
return self().getBlock().isScaffolding(self(), entity.level, entity.blockPosition(), entity);
}
/**
* Whether redstone dust should visually connect to this block on a side.
* <p>
* Modded redstone wire blocks should call this function to determine visual connections.
*
* @param world The world
* @param pos The block position in world
* @param direction The coming direction of the redstone dust connection (with respect to the block at pos)
* @return True if redstone dust should visually connect on the side passed
*/
default boolean canRedstoneConnectTo(BlockGetter world, BlockPos pos, @Nullable Direction direction)
{
return self().getBlock().canConnectRedstone(self(), world, pos, direction);
}
}