Ships is brand new to Sponge and with Sponge's many advantages Ships 6 was announced.

Ships 6 works in a slightly different way to ships 5. In Ships 4, vessels data was changed in the file only, this meant the data in Ships 4 was always accurate for if the server crashed. Ships 5 stored the Vessel data into RAM and changed the file when needed, this boasts speed, however could cause issues if the server crashed, not only that but filled up RAM with vessel data that may not even be touched. Ships 6 is a hybrid of the two options where the vessel data is only stored in RAM where if a vessel has been used recently but then removed from RAM if it is not touched for a while. This leads to data being more accurate for loading vessels (due to the fact the vessels save the RAM data when removed from RAM) but maintains the speed that Ships 5 has (I mean, it will be slow on first move but oh well).

Ships 6 also stores the block locations in the file as well as RAM, something that Ships 1-5 didnt do, this means addons can take advantage of previous structures the ship was in.

Getting Vessel data

Vessel data is stored in a "ShipData" object. These hold the basic information all Ships have in common. However these are not actual in game ships. The actual in game ship, is stored in a "LoadableShip" object. So whats the difference method wise? Actually a lot more then you think. Due to the fact just the data is not a actual ship, there is no way to move a ship in game with just that data, this is where the "LoadableShip" data comes into play. However, as it states above, Ships are not stored in RAM at all times now meaning there needs to be a way to load a vessel object and there are a few ways.

Optional<LoadableShip> opShip = LoadableShip.getShip("Name of ship");
Optional<LoadableShip> opShip = LoadableShip.getShip(Text.of("Name of ship"));
Optional<LoadableShip> opShip = LoadableShip.getShip(Location<? extends Extent> locationOfBlockOnShip, boolean updateStructure);
List<LoadableShip> ships = LoadableShip.getShips(); //this will get all ships
List<LoadableShip> ships = LoadableShip.getRecentlyUsedShips(); //this will get all ships in RAM
List<LoadableShip> ships = LoadableShip.getShips(StaticShipType shipType); //this will get all the ships of the specified type
List<LoadableShip> ships = LoadableShip.getShips(Class<ShipRequirement>... requirement) //this will get all ships that need the specified thing

Thats just some of the ways, however here are some of the ways for more advanced users, be warned, you must use these correctly as they can duplicate data and even corrupt files.

The following ways are bypassing the RAM check and creating a new object for the Ship.

Optional<LoadableShip> opShip = ShipLoader.loadShip("name of ship");
Optional<LoadableShip> opShip = ShipLoader.loadShip(File vesseldata);

Ships 6 also has error checking for corrupt files open to the public. This maybe usful to the developers who wish to bypass the RAM checking.

ShipLoadingError error = ShipLoader.getError("name of ship");
ShipLoadingError error = ShipLoader.getError(File file);

Working with a Ship object

In this tutorial, we will be focusing on the "LoadableShip" object however will talk about other parts of the ships object.

Ships 6 attempts to remove as many classes as possible, but keep the functionality of ShipsAPI. Ships 5 had 4 classes for just the Ship object (BaseVessel, ProtectedVessel, MovableVessel, Vessel), in Ships 6 It has been cut down to 3 (ShipsData - storing the basic information of a ship, but can be treated as a virtual ship too, LoadableShip - the actual ship object, <ship type object name> - this is the ShipType, need I say more). These 3 classes are cast able to one and another.

ShipData data;
if(data instanceof LoadableShip){
//is not virtual
if(data instanceof Airship){
//is a airship

Moving a ship

Ships 5 used Vectors to move the ship (with rotation being the exception). Ships 6 is non different only now you can store a movement for later using the "StoredMovement" builder. The example below shows me rotating the ship left and moving forward under a single command (please note that the blocks teleport/move first and it is truly a single command, as in the ship will not request each move separably)

StoredMovement.Builder builder = new StoredMovement.Builder();
StoredMovement movement = builder.build();

LoadableShip ship;
//please note that it will not teleport the ship if you did not specific a teleport, it is just the method name

Working with Auto Pilot

Saving and storing custom data to ships

Creating your own Ship Type

Working with algorithms

Movement algorithms

Block detection algorithm

Working with events

About To Create Ship

Create Ship





Posts Quoted:
Clear All Quotes