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
FieldsModifier and TypeFieldDescriptionprotected intprotected net.minecraft.world.level.LevelAccessor@Nullable net.minecraft.core.BlockPosprotected HashSet<net.minecraft.world.level.block.Block> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected net.minecraft.world.level.block.state.BlockStateblockWithAxis(net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.Direction.Axis axis) protected booleancheckForValidFrame(net.minecraft.core.Direction.Axis axis1, net.minecraft.core.Direction.Axis axis2, int size1, int size2) protected voidcountExistingPortalBlocks(net.minecraft.core.Direction.Axis axis1, net.minecraft.core.Direction.Axis axis2, int size1, int size2) abstract voidcreatePortal(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.BlockPosdoesPortalFitAt(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 voidfillAirAroundPortal(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.Vec3getEntityOffsetInPortal(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.BlockPosgetLimitForAxis(@Nullable net.minecraft.core.BlockPos blockPos, net.minecraft.core.Direction.Axis axis) protected @Nullable net.minecraft.core.BlockPosgetLowerCorner(net.minecraft.core.BlockPos blockPos, net.minecraft.core.Direction.Axis axis1, net.minecraft.core.Direction.Axis axis2) abstract @Nullable PortalValidatorgetNewPortal(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 PortalValidatorgetOrEmpty(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.FoundRectangleGet the rectangular bounds of the validated portal frame.protected intgetSize(net.minecraft.core.Direction.Axis axis, int minSize, int maxSize) abstract net.minecraft.world.level.portal.TeleportTransitiongetTeleportTargetInPortal(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.abstract PortalValidatorinit(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 booleanCheck if the portal frame is already lit (contains portal blocks).abstract booleanisRequestedSize(int attemptWidth, int attemptHeight) Check if the portal frame matches the requested size constraints.abstract booleanCheck if the current portal frame structure is valid.abstract voidlightPortal(net.minecraft.world.level.block.Block frameBlock) Light the portal by filling it with portal blocks.protected voidplaceLandingPad(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 booleanvalidStateInsidePortal(net.minecraft.world.level.block.state.BlockState blockState, HashSet<net.minecraft.world.level.block.Block> foundations)
-
Field Details
-
lowerCorner
@Nullable public @Nullable net.minecraft.core.BlockPos lowerCorner -
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:PortalValidatorInitialize the validator with the given parameters and scan for a valid portal frame.- Specified by:
initin interfacePortalValidator- Parameters:
level- the level to scan inblockPos- the starting position to checkaxis- the axis along which the portal is orientedfoundations- 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:PortalValidatorCheck if the portal frame is already lit (contains portal blocks).- Specified by:
isAlreadyLitPortalFramein interfacePortalValidator- Returns:
- true if the portal is already lit
-
isValidFrame
public abstract boolean isValidFrame()Description copied from interface:PortalValidatorCheck if the current portal frame structure is valid.- Specified by:
isValidFramein interfacePortalValidator- Returns:
- true if the frame is valid
-
isRequestedSize
public abstract boolean isRequestedSize(int attemptWidth, int attemptHeight) Description copied from interface:PortalValidatorCheck if the portal frame matches the requested size constraints.- Specified by:
isRequestedSizein interfacePortalValidator- 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:PortalValidatorGet the rectangular bounds of the validated portal frame.- Specified by:
getRectanglein interfacePortalValidator- 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:PortalValidatorCheck if a portal of the appropriate size can fit at the given position.- Specified by:
doesPortalFitAtin interfacePortalValidator- Parameters:
level- the level to check inattemptPos- the position to attempt portal placementaxis- 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:PortalBuilderLight the portal by filling it with portal blocks.- Specified by:
lightPortalin interfacePortalBuilder- 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:PortalBuilderCreate a complete portal structure at the given position. This includes placing the frame and portal blocks.- Specified by:
createPortalin interfacePortalBuilder- Parameters:
level- the level to create the portal inpos- the position to create the portal atframeBlock- the block state to use for the frameaxis- 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:PortalTeleporterCalculate the entity's offset within the source portal. This is used to preserve relative position when teleporting.- Specified by:
getEntityOffsetInPortalin interfacePortalTeleporter- Parameters:
arg- the rectangular bounds of the portalentity- 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:PortalTeleporterCalculate the teleportation target within the destination portal.- Specified by:
getTeleportTargetInPortalin interfacePortalTeleporter- Parameters:
serverLevel- the destination levelportalRect- the rectangular bounds of the destination portalportalAxis- the axis of the portalprevOffset- the entity's offset from the source portalentity- the entity being teleportedlink- 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 modifypos- 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 modifypos- the position to place the landing padframeBlock- the frame block to use as landing pad
-