Package etithespirit.orimod.aos
Class ConnectionHelper
java.lang.Object
etithespirit.orimod.aos.ConnectionHelper
Mostly intended for use in
ConnectableLightTechBlock
, this provides methods associated with testing connections.- Author:
- Eti
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
areNeighbors
(net.minecraft.core.BlockPos alpha, net.minecraft.core.BlockPos bravo) Returns whether or not the givenBlockPos
instances are direct neighbors.static net.minecraft.core.Direction
fromBlockPos
(net.minecraft.core.BlockPos from, net.minecraft.core.BlockPos to, boolean strictAdjacentOnly) Given two instances ofBlockPos
, this will return aDirection
fromfrom
->to
.static net.minecraft.core.BlockPos[]
getDirectionsWithMutualConnections
(net.minecraft.world.level.BlockGetter reader, net.minecraft.core.BlockPos around, boolean anticipateWithAuto) Returns all adjacentBlockPos
instances that represent neighboringConnectableLightTechBlock
s with mutual connections to this block.static boolean
hasMutualConnectionInDirection
(net.minecraft.world.level.BlockGetter reader, net.minecraft.core.BlockPos at, net.minecraft.core.Direction dir, boolean anticipateWithAuto) Similar tohasOutgoingConnectionInDirection(BlockGetter, BlockPos, Direction, boolean)
but this also checks the neighbor to this block.
Consider usinghasMutualConnectionToOther(BlockGetter, BlockPos, BlockPos, boolean)
if you wish to pass in a secondBlockPos
instead of aDirection
.static boolean
hasMutualConnectionToOther
(net.minecraft.world.level.BlockGetter reader, net.minecraft.core.BlockPos at, net.minecraft.core.BlockPos other, boolean anticipateWithAuto) Similar tohasOutgoingConnectionInDirection(BlockGetter, BlockPos, Direction, boolean)
but this also checks the neighbor to this block.static boolean
hasOutgoingConnectionInDirection
(net.minecraft.world.level.BlockGetter reader, net.minecraft.core.BlockPos at, net.minecraft.core.Direction dir, boolean anticipateAuto) Returns whether or not the blockat
is able to establish a connection in the direction ofdir
.
-
Method Details
-
hasOutgoingConnectionInDirection
public static boolean hasOutgoingConnectionInDirection(net.minecraft.world.level.BlockGetter reader, net.minecraft.core.BlockPos at, net.minecraft.core.Direction dir, boolean anticipateAuto) throws ArgumentNullException, IllegalArgumentException Returns whether or not the blockat
is able to establish a connection in the direction ofdir
. This ignores the state or block type of the neighbor in that direction.
Note that if this is called when the block is placed or before all neighbor updates have completed, it may return false despite auto-connecting. This can be partly remedied by settinganticipateAuto
to true if this method is used when the block is placed.- Parameters:
reader
- Something to access the blocks in the world.at
- The location of the block to test.dir
- The face to test.anticipateAuto
- If true, then the automatic state of the block atat
is tested as well (assuming that a block update will occur immediately after this method is called, connecting the two)- Returns:
- Whether or not
at
is able to establish a connection in the direction ofdir
- Throws:
ArgumentNullException
- If any of the three parameters are null.IllegalArgumentException
- if the givenBlockPos
does not correspond to an instance ofConnectableLightTechBlock
.
-
hasMutualConnectionInDirection
public static boolean hasMutualConnectionInDirection(net.minecraft.world.level.BlockGetter reader, net.minecraft.core.BlockPos at, net.minecraft.core.Direction dir, boolean anticipateWithAuto) throws ArgumentNullException, IllegalArgumentException Similar tohasOutgoingConnectionInDirection(BlockGetter, BlockPos, Direction, boolean)
but this also checks the neighbor to this block.
Consider usinghasMutualConnectionToOther(BlockGetter, BlockPos, BlockPos, boolean)
if you wish to pass in a secondBlockPos
instead of aDirection
.- Parameters:
reader
- Something to access the blocks in the world.at
- The location of the block to test.dir
- The face to test.anticipateWithAuto
- If true, then the automatic state of the block atat
is tested as well (assuming that a block update will occur immediately after this method is called, connecting the two)- Returns:
- Whether or not
at
is able to establish a connection in the direction ofdir
, and the block adjacent in that direction can establish a connection to this block, causing a proper connection. - Throws:
ArgumentNullException
- If any of the three parameters are null.IllegalArgumentException
- if the givenBlockPos
or its neighbor in the direction ofdir
does not correspond to an instance ofConnectableLightTechBlock
.
-
hasMutualConnectionToOther
public static boolean hasMutualConnectionToOther(net.minecraft.world.level.BlockGetter reader, net.minecraft.core.BlockPos at, net.minecraft.core.BlockPos other, boolean anticipateWithAuto) throws ArgumentNullException, IllegalArgumentException Similar tohasOutgoingConnectionInDirection(BlockGetter, BlockPos, Direction, boolean)
but this also checks the neighbor to this block.- Parameters:
reader
- Something to access the blocks in the world.at
- The location of the block to test.other
- The location of the other block to test.anticipateWithAuto
- If true, then the automatic state of the block atat
is tested as well (assuming that a block update will occur immediately after this method is called, connecting the two)- Returns:
- Whether or not
at
is able to establish a connection in the direction ofdir
, and the block adjacent in that direction can establish a connection to this block, causing a proper connection. - Throws:
ArgumentNullException
- If any of the three parameters are null.IllegalArgumentException
- if the givenBlockPos
or its neighbor do not correspond to an instance ofConnectableLightTechBlock
, or if the twoBlockPos
instances are not adjacent.
-
fromBlockPos
public static net.minecraft.core.Direction fromBlockPos(net.minecraft.core.BlockPos from, net.minecraft.core.BlockPos to, boolean strictAdjacentOnly) throws IllegalArgumentException Given two instances ofBlockPos
, this will return aDirection
fromfrom
->to
.- Parameters:
from
- The origin.to
- The destination.strictAdjacentOnly
- If true, this will throwIllegalArgumentException
if the givenBlockPos
instances are not neighbors.- Returns:
- A
Direction
representing the way to get from origin to destination. - Throws:
IllegalArgumentException
- IfstrictAdjacentOnly
is true and the twoBlockPos
instances are not neighbors.
-
areNeighbors
public static boolean areNeighbors(net.minecraft.core.BlockPos alpha, net.minecraft.core.BlockPos bravo) Returns whether or not the givenBlockPos
instances are direct neighbors.- Parameters:
alpha
- The first of the two to check.bravo
- The second of the two to check.- Returns:
- True if the distance between these two positions is equal to 1.
-
getDirectionsWithMutualConnections
public static net.minecraft.core.BlockPos[] getDirectionsWithMutualConnections(net.minecraft.world.level.BlockGetter reader, net.minecraft.core.BlockPos around, boolean anticipateWithAuto) Returns all adjacentBlockPos
instances that represent neighboringConnectableLightTechBlock
s with mutual connections to this block.- Parameters:
reader
- TheBlockGetter
used to access the neighboring blocks.around
- The location of this block.anticipateWithAuto
- Whether or not to anticipate connections that will be made on the next block update for neighbors with automatic connections enabled.- Returns:
- A list of up to six
BlockPos
instances representing directions where a mutual connection is made.
-