Dimensions API
  • Setting up
  • Creating an addon
  • Example Addon
  • Reference
    • API Reference
      • CustomPortal
      • CompletePortal
      • PortalGeometry
      • Events
Powered by GitBook
On this page
  • Why would I make a PortalGeometry
  • How do I make a custom PortalGeometry
  1. Reference
  2. API Reference

PortalGeometry

Create your own portal structures

PortalGeometry will change in a future update

Why would I make a PortalGeometry

If you want portals with weird patterns or weird orientation, etc then you need to override the Dimensions PortalGeometry

For example HorizontalPortalsAddon uses its own PortalGeometry

How do I make a custom PortalGeometry

First, you need to create a new class and extend it PortalGeometry

Apart from the constructor, the class requires a few other fields to be overridden in order to function properly:

//Return a new instance of your class
public PortalGeometry createGeometry(Vector min, Vector max)

//Return a new instance of your class
//(this method is used to actually find the portal structure)
public PortalGeometry getPortal(CustomPortal customPortal, Location loc)

//Use this method to check if the player is inside the portal
public boolean isInside(Location location, boolean outside, boolean corner)

//Use this to build an exit portal (not that the newLocation is the bottom corner of the portal)
public void buildPortal(Location newLocation, World destinationWorld, CustomPortal customPortal)

Example:

public class CustomPortalGeometry extends PortalGeometry {
	
	protected CustomPortalGeometry(Vector min, Vector max) {
		super(min, max);
		
		//If you change these min or max Vectors then you MUST update the bounding box with
		//If you dont, entities will teleport using the default bounding box generated by the min/max vectors
		//getBoundingBox().copy(BoundingBox.of(getInsideMin(), getInsideMax()));
	}
	
	//This method is required if you want Dimensiosn to actually use your custom PortalGeometry
	public PortalGeometry createGeometry(Vector min, Vector max) {
		return new CustomPortalGeometry(min, max);
	}
	
	public PortalGeometry getPortal(CustomPortal customPortal, Location loc) {
		 
		//Do some math and some geometry and when you have the min/max of the portal, you can create a new instance of your PortalGeometry
		//Even if your portal is not a rectangle, you will need to provide with a min/max and do some extra checking when a portal is used
		
		return new CustomPortalGeometry(min, max);		 
	}

	//Use this to check if the player is inside the portal
	public boolean isInside(Location location, boolean outside, boolean corner) {
		
		//Do your thing here and return true if the player is inside the portal
		//If outside is true, then you MUST include the frame of the portal or else the plugin might not function properly
		//Same goes for corner
		return false;
	}
	
	@Override
	public void buildPortal(Location newLocation, World destinationWorld, CustomPortal customPortal) {
		
		//Now we need to build an exit portal
		//Do your thing and build a portal but remember that newLocation is the PortalGeometry#min
		//So you need to build the portal moving up and +x or +z (depending on portal Axis)
		
	}
}
PreviousCompletePortalNextEvents

Last updated 2 years ago