Skip to content

Z4OLLIEZ4/Space-API-Example

Repository files navigation

Space-API-Example

A basic example on the functionality of the Space API.

Getting started

In order to intialise the Space API you'll need to create an instance of the SpaceAPI class

SpaceAPI spaceAPI = new SpaceAPI();

From there, the SpaceAPI class has a few powerful methods that are capable of creating machines that can work with any other plugin using the Space API (Or space itself), getting a list of items that Space uses, or getting the Space world manager so that you can edit attributes of the planets space has.

Methods included:

Items

spaceAPI.getItems();

Provides a class containing all of the items space uses

Categories

Space Guide + Space Cheat Guide

// Create a category in both the space guide, and space cheat guide
Category customCategory = new Category(ItemStack icon);
// Add items to the category
customCategory.add(ItemStack item);
// Register category with the space guide
CategoryManager.registerCategory(customCategory);

Space Cheat Guide Only

// Create a category in the space cheat guide
CreativeCategory customCategory = new CreativeCategory(ItemStack icon);
// Add items to the category
customCategory.add(ItemStack item);
// Register category with the space guide
CategoryManager.registerCategory(customCategory);

The Category API is to display custom items within the space guide easily, under automatically paged and sorted GUI's

World Management

WorldManager worldManager = spaceAPI.getWorldManager();

Provides a class with arrays of both all of the planets space manages, and the planets that can be displayed in a rocket. You can also get a planet by it's display name, location, test whether a world is a space world or test whether or not a player is in a space world

worldManager.getPlanets();
worldManager.getPlanetsToDisplay();
worldManager.getPlanetByName(String name);
worldManager.getPlanetByLocation(Location location);
worldManager.isInSpaceWorld(Player player);
worldManager.isPlanet(World world);

It is also possible to get the last rocket takeoff location of a player from a planet.

spaceAPI.getLastLocation(Player player, Planet planet);
  • If the player has not visited the planet, it will return the world's spawn location
  • If the world relevant to the planet is not present, it will return null

Energy networks and machines

// Must be called in order to register an ItemStack as a placable machine. Stores an nbtIdentifier within the item to test for later.
spaceAPI.registerAsMachine(ItemStack stack, String nbtIdentifier);
// Attempt to place a machine. Should only be called after testing if isMachine() is true for the held ItemStack
spaceAPI.attemptPlaceMachine(ItemStack stack, BlockPlaceEvent event, String nbtIdentifier);
// Tests whether or not a given ItemStack is a machine with a stored nbtIdentifier
boolean isMachine = spaceAPI.isMachine(ItemStack stack, String nbtIdentifier);
// Forcefully removes and terminates all energy networks in the given planet. This action is irreversible.
spaceAPI.discardEnergyNetworks(Planet planet);
// Gets the machine in the location a block is, or returns null if one is not present
Machine machine = spaceAPI.getMachineByBlock(Block b);
// Gets the energy network in the location a block is, or returns null if one is not present
EnergyNetwork network = spaceAPI.getNetworkByBlock(Block b);
// Returns an integer of the current energy network tick speed loaded into space. Will auto-throttle for performance
int speed = spaceAPI.getNetworkSpeed();
// Returns an integer of the current energy density loaded into space. Will auto-throttle for performance
int density = spaceAPI.getNetworkEnergyDensity();

Provides a general interface for creating machines. Please see the coded example for more understanding. These methods are quite simple and user friendly.

Vehicles

Capability moved to Interface4

Things to note:

  • The API automatically manages breaking, clicking and all inventory-related matters for machines. The only thing required of you to do is to manage placing machines as shown in the example code here, and any auxiliary functions you want your machine to have.
  • Any ItemStack provided to the registerAsMachine() method will have specialised NBT added to it. As a result it is important you test for your machine using the isMachine() method and so remembering your nbt identifier you give the item is important (Supplied as a parameter to the registerAsMachine() method)

Any recommended plugins using the Space API will be listed here as time goes on.

About

A basic example on the functionality of the Space API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages