Class ConnectionHelper

java.lang.Object
etithespirit.orimod.aos.ConnectionHelper

public final class ConnectionHelper extends Object
Mostly intended for use in ConnectableLightTechBlock, this provides methods associated with testing connections.
Author:
Eti
  • 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 block at is able to establish a connection in the direction of dir. 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 setting anticipateAuto 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 at at 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 of dir
      Throws:
      ArgumentNullException - If any of the three parameters are null.
      IllegalArgumentException - if the given BlockPos does not correspond to an instance of ConnectableLightTechBlock.
    • 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 to hasOutgoingConnectionInDirection(BlockGetter, BlockPos, Direction, boolean) but this also checks the neighbor to this block.
      Consider using hasMutualConnectionToOther(BlockGetter, BlockPos, BlockPos, boolean) if you wish to pass in a second BlockPos instead of a Direction.
      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 at at 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 of dir, 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 given BlockPos or its neighbor in the direction of dir does not correspond to an instance of ConnectableLightTechBlock.
    • 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 to hasOutgoingConnectionInDirection(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 at at 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 of dir, 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 given BlockPos or its neighbor do not correspond to an instance of ConnectableLightTechBlock, or if the two BlockPos 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 of BlockPos, this will return a Direction from from -> to.
      Parameters:
      from - The origin.
      to - The destination.
      strictAdjacentOnly - If true, this will throw IllegalArgumentException if the given BlockPos instances are not neighbors.
      Returns:
      A Direction representing the way to get from origin to destination.
      Throws:
      IllegalArgumentException - If strictAdjacentOnly is true and the two BlockPos instances are not neighbors.
    • areNeighbors

      public static boolean areNeighbors(net.minecraft.core.BlockPos alpha, net.minecraft.core.BlockPos bravo)
      Returns whether or not the given BlockPos 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 adjacent BlockPos instances that represent neighboring ConnectableLightTechBlocks with mutual connections to this block.
      Parameters:
      reader - The BlockGetter 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.