Class PortalFrameTester

java.lang.Object
tech.anonymoushacker1279.openportals.portal.frame.PortalFrameTester
All Implemented Interfaces:
PortalBuilder, PortalTeleporter, PortalValidator
Direct Known Subclasses:
FlatPortalFrameTester, VerticalPortalFrameTester

public abstract class PortalFrameTester extends Object implements PortalValidator, PortalBuilder, PortalTeleporter
Abstract base class for portal frame testing and manipulation.

Subclasses should implement the specific portal shape logic (vertical, horizontal, etc.).

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
     
    protected net.minecraft.world.level.LevelAccessor
     
    @Nullable net.minecraft.core.BlockPos
     
    protected HashSet<net.minecraft.world.level.block.Block>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected net.minecraft.world.level.block.state.BlockState
    blockWithAxis(net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.Direction.Axis axis)
     
    protected boolean
    checkForValidFrame(net.minecraft.core.Direction.Axis axis1, net.minecraft.core.Direction.Axis axis2, int size1, int size2)
     
    protected void
    countExistingPortalBlocks(net.minecraft.core.Direction.Axis axis1, net.minecraft.core.Direction.Axis axis2, int size1, int size2)
     
    abstract void
    createPortal(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState frameBlock, net.minecraft.core.Direction.Axis axis)
    Create a complete portal structure at the given position.
    abstract @Nullable net.minecraft.core.BlockPos
    doesPortalFitAt(net.minecraft.world.level.LevelAccessor level, net.minecraft.core.BlockPos attemptPos, net.minecraft.core.Direction.Axis axis)
    Check if a portal of the appropriate size can fit at the given position.
    protected void
    fillAirAroundPortal(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
    Fills air around the portal if the block is solid.
    abstract net.minecraft.world.phys.Vec3
    getEntityOffsetInPortal(net.minecraft.util.BlockUtil.FoundRectangle arg, net.minecraft.world.entity.Entity entity)
    Calculate the entity's offset within the source portal.
    protected @Nullable net.minecraft.core.BlockPos
    getLimitForAxis(@Nullable net.minecraft.core.BlockPos blockPos, net.minecraft.core.Direction.Axis axis)
     
    protected @Nullable net.minecraft.core.BlockPos
    getLowerCorner(net.minecraft.core.BlockPos blockPos, net.minecraft.core.Direction.Axis axis1, net.minecraft.core.Direction.Axis axis2)
     
    abstract @Nullable PortalValidator
    getNewPortal(net.minecraft.world.level.LevelAccessor level, net.minecraft.core.BlockPos blockPos, net.minecraft.core.Direction.Axis axis, net.minecraft.world.level.block.Block... foundations)
    Try to find a new, unlit portal frame at the given position.
    abstract @Nullable PortalValidator
    getOrEmpty(net.minecraft.world.level.LevelAccessor level, net.minecraft.core.BlockPos blockPos, Predicate<PortalFrameTester> predicate, net.minecraft.core.Direction.Axis axis, net.minecraft.world.level.block.Block... foundations)
    Try to find a portal frame matching the given predicate.
    abstract net.minecraft.util.BlockUtil.FoundRectangle
    Get the rectangular bounds of the validated portal frame.
    protected int
    getSize(net.minecraft.core.Direction.Axis axis, int minSize, int maxSize)
     
    abstract net.minecraft.world.level.portal.TeleportTransition
    getTeleportTargetInPortal(net.minecraft.server.level.ServerLevel serverLevel, net.minecraft.util.BlockUtil.FoundRectangle portalRect, net.minecraft.core.Direction.Axis portalAxis, net.minecraft.world.phys.Vec3 prevOffset, net.minecraft.world.entity.Entity entity, PortalLink link)
    Calculate the teleportation target within the destination portal.
    init(net.minecraft.world.level.LevelAccessor level, net.minecraft.core.BlockPos blockPos, net.minecraft.core.Direction.Axis axis, net.minecraft.world.level.block.Block... foundations)
    Initialize the validator with the given parameters and scan for a valid portal frame.
    abstract boolean
    Check if the portal frame is already lit (contains portal blocks).
    abstract boolean
    isRequestedSize(int attemptWidth, int attemptHeight)
    Check if the portal frame matches the requested size constraints.
    abstract boolean
    Check if the current portal frame structure is valid.
    abstract void
    lightPortal(net.minecraft.world.level.block.Block frameBlock)
    Light the portal by filling it with portal blocks.
    protected void
    placeLandingPad(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState frameBlock)
    Places a landing pad block if the current block is not solid.
    static boolean
    validStateInsidePortal(net.minecraft.world.level.block.state.BlockState blockState, HashSet<net.minecraft.world.level.block.Block> foundations)
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • lowerCorner

      @Nullable public @Nullable net.minecraft.core.BlockPos lowerCorner
    • VALID_FRAME

      protected HashSet<net.minecraft.world.level.block.Block> VALID_FRAME
    • foundPortalBlocks

      protected int foundPortalBlocks
    • levelAccessor

      protected net.minecraft.world.level.LevelAccessor levelAccessor
  • Constructor Details

    • PortalFrameTester

      public PortalFrameTester()
  • Method Details

    • validStateInsidePortal

      public static boolean validStateInsidePortal(net.minecraft.world.level.block.state.BlockState blockState, HashSet<net.minecraft.world.level.block.Block> foundations)
    • init

      public abstract PortalValidator init(net.minecraft.world.level.LevelAccessor level, net.minecraft.core.BlockPos blockPos, net.minecraft.core.Direction.Axis axis, net.minecraft.world.level.block.Block... foundations)
      Description copied from interface: PortalValidator
      Initialize the validator with the given parameters and scan for a valid portal frame.
      Specified by:
      init in interface PortalValidator
      Parameters:
      level - the level to scan in
      blockPos - the starting position to check
      axis - the axis along which the portal is oriented
      foundations - the blocks that can serve as portal frame blocks
      Returns:
      this validator instance for method chaining
    • getNewPortal

      @Nullable public abstract @Nullable PortalValidator getNewPortal(net.minecraft.world.level.LevelAccessor level, net.minecraft.core.BlockPos blockPos, net.minecraft.core.Direction.Axis axis, net.minecraft.world.level.block.Block... foundations)
      Try to find a new, unlit portal frame at the given position.
      Returns:
      this validator if a valid unlit portal is found, null otherwise
    • getOrEmpty

      @Nullable public abstract @Nullable PortalValidator getOrEmpty(net.minecraft.world.level.LevelAccessor level, net.minecraft.core.BlockPos blockPos, Predicate<PortalFrameTester> predicate, net.minecraft.core.Direction.Axis axis, net.minecraft.world.level.block.Block... foundations)
      Try to find a portal frame matching the given predicate.
      Returns:
      this validator if a matching portal is found, null otherwise
    • isAlreadyLitPortalFrame

      public abstract boolean isAlreadyLitPortalFrame()
      Description copied from interface: PortalValidator
      Check if the portal frame is already lit (contains portal blocks).
      Specified by:
      isAlreadyLitPortalFrame in interface PortalValidator
      Returns:
      true if the portal is already lit
    • isValidFrame

      public abstract boolean isValidFrame()
      Description copied from interface: PortalValidator
      Check if the current portal frame structure is valid.
      Specified by:
      isValidFrame in interface PortalValidator
      Returns:
      true if the frame is valid
    • isRequestedSize

      public abstract boolean isRequestedSize(int attemptWidth, int attemptHeight)
      Description copied from interface: PortalValidator
      Check if the portal frame matches the requested size constraints.
      Specified by:
      isRequestedSize in interface PortalValidator
      Parameters:
      attemptWidth - the required width (0 for no constraint)
      attemptHeight - the required height (0 for no constraint)
      Returns:
      true if the size matches the constraints
    • getRectangle

      @Nullable public abstract net.minecraft.util.BlockUtil.FoundRectangle getRectangle()
      Description copied from interface: PortalValidator
      Get the rectangular bounds of the validated portal frame.
      Specified by:
      getRectangle in interface PortalValidator
      Returns:
      the portal rectangle, or null if no valid frame was found
    • doesPortalFitAt

      @Nullable public abstract @Nullable net.minecraft.core.BlockPos doesPortalFitAt(net.minecraft.world.level.LevelAccessor level, net.minecraft.core.BlockPos attemptPos, net.minecraft.core.Direction.Axis axis)
      Description copied from interface: PortalValidator
      Check if a portal of the appropriate size can fit at the given position.
      Specified by:
      doesPortalFitAt in interface PortalValidator
      Parameters:
      level - the level to check in
      attemptPos - the position to attempt portal placement
      axis - the axis along which the portal should be oriented
      Returns:
      the position where the portal can fit, or null if it cannot
    • lightPortal

      public abstract void lightPortal(net.minecraft.world.level.block.Block frameBlock)
      Description copied from interface: PortalBuilder
      Light the portal by filling it with portal blocks.
      Specified by:
      lightPortal in interface PortalBuilder
      Parameters:
      frameBlock - the block that serves as the portal frame
    • createPortal

      public abstract void createPortal(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState frameBlock, net.minecraft.core.Direction.Axis axis)
      Description copied from interface: PortalBuilder
      Create a complete portal structure at the given position. This includes placing the frame and portal blocks.
      Specified by:
      createPortal in interface PortalBuilder
      Parameters:
      level - the level to create the portal in
      pos - the position to create the portal at
      frameBlock - the block state to use for the frame
      axis - the axis along which the portal should be oriented
    • getEntityOffsetInPortal

      public abstract net.minecraft.world.phys.Vec3 getEntityOffsetInPortal(net.minecraft.util.BlockUtil.FoundRectangle arg, net.minecraft.world.entity.Entity entity)
      Description copied from interface: PortalTeleporter
      Calculate the entity's offset within the source portal. This is used to preserve relative position when teleporting.
      Specified by:
      getEntityOffsetInPortal in interface PortalTeleporter
      Parameters:
      arg - the rectangular bounds of the portal
      entity - the entity entering the portal
      Returns:
      the entity's offset within the portal
    • getTeleportTargetInPortal

      public abstract net.minecraft.world.level.portal.TeleportTransition getTeleportTargetInPortal(net.minecraft.server.level.ServerLevel serverLevel, net.minecraft.util.BlockUtil.FoundRectangle portalRect, net.minecraft.core.Direction.Axis portalAxis, net.minecraft.world.phys.Vec3 prevOffset, net.minecraft.world.entity.Entity entity, PortalLink link)
      Description copied from interface: PortalTeleporter
      Calculate the teleportation target within the destination portal.
      Specified by:
      getTeleportTargetInPortal in interface PortalTeleporter
      Parameters:
      serverLevel - the destination level
      portalRect - the rectangular bounds of the destination portal
      portalAxis - the axis of the portal
      prevOffset - the entity's offset from the source portal
      entity - the entity being teleported
      link - the portal configuration link
      Returns:
      the teleport transition describing the destination
    • getLowerCorner

      @Nullable protected @Nullable net.minecraft.core.BlockPos getLowerCorner(net.minecraft.core.BlockPos blockPos, net.minecraft.core.Direction.Axis axis1, net.minecraft.core.Direction.Axis axis2)
    • getLimitForAxis

      @Nullable protected @Nullable net.minecraft.core.BlockPos getLimitForAxis(@Nullable @Nullable net.minecraft.core.BlockPos blockPos, @Nullable net.minecraft.core.Direction.Axis axis)
    • getSize

      protected int getSize(net.minecraft.core.Direction.Axis axis, int minSize, int maxSize)
    • checkForValidFrame

      protected boolean checkForValidFrame(net.minecraft.core.Direction.Axis axis1, net.minecraft.core.Direction.Axis axis2, int size1, int size2)
    • countExistingPortalBlocks

      protected void countExistingPortalBlocks(net.minecraft.core.Direction.Axis axis1, net.minecraft.core.Direction.Axis axis2, int size1, int size2)
    • blockWithAxis

      protected net.minecraft.world.level.block.state.BlockState blockWithAxis(net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.Direction.Axis axis)
    • fillAirAroundPortal

      protected void fillAirAroundPortal(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
      Fills air around the portal if the block is solid.
      Parameters:
      level - the level to modify
      pos - the position to check and potentially fill with air
    • placeLandingPad

      protected void placeLandingPad(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState frameBlock)
      Places a landing pad block if the current block is not solid.
      Parameters:
      level - the level to modify
      pos - the position to place the landing pad
      frameBlock - the frame block to use as landing pad