@@ -198,13 +198,13 @@ public final MethodResult distanceToPoint(String name) {
198198 * facing = "north", -- where will the turtle face after teleport
199199 * costs = 10000, -- the costs to cross the portal
200200 * canSpawn = true, -- if the target position is not blocked and turtle are able to spawn there
201- * shipId = "xxx", -- the random id used for ship the portal. You have to call portalShipActive(shipId ) if needed.
201+ * warpId = "xxx", -- the random id used for ship the portal. You have to call activePortalWarp(warpId ) if needed.
202202 * }
203203 * </code>
204204 * </pre>
205205 */
206206 @ LuaFunction
207- public final MethodResult portalShipPrepare (IArguments arguments ) throws LuaException {
207+ public final MethodResult preparePortalWarp (IArguments arguments ) throws LuaException {
208208 Direction direction ;
209209 switch (arguments .optString (0 ).orElse ("" ).toLowerCase (Locale .ROOT )) {
210210 case "up" , "top" -> direction = Direction .UP ;
@@ -218,20 +218,20 @@ public final MethodResult portalShipPrepare(IArguments arguments) throws LuaExce
218218 TurtlePeripheralOwner owner = automataCore .getPeripheralOwner ();
219219 ITurtleAccess turtle = owner .getTurtle ();
220220 TurtleEnderPearl shipPearl = new TurtleEnderPearl (turtle , direction );
221- String shipId = shipPearl .getStringUUID ();
221+ String warpId = shipPearl .getStringUUID ();
222222 ServerWorker .add (() -> {
223223 MethodResult res ;
224224 try {
225225 res = automataCore .withOperation (PREPARE_PORTAL , new SingleOperationContext (1 , 1 ), context -> {
226- shipPearl .setCallback (pearl -> {
226+ shipPearl .setCallbacks (pearl -> {
227227 if (pearl == null || pearl .isRemoved ()) {
228- automataCore .queueEvent (PortalPrepareCallback .FAILED_EVENT_ID , shipId , "PEARL_GONE" );
229- shipPearls .remove (shipId );
228+ automataCore .queueEvent (PortalPrepareCallback .FAILED_EVENT_ID , warpId , "PEARL_GONE" );
229+ shipPearls .remove (warpId );
230230 return ;
231231 }
232232 Level level = pearl .level ();
233233 if (level == turtle .getLevel ()) {
234- automataCore .queueEvent (PortalPrepareCallback .FAILED_EVENT_ID , shipId , "NO_PORTAL_FOUND" );
234+ automataCore .queueEvent (PortalPrepareCallback .FAILED_EVENT_ID , warpId , "NO_PORTAL_FOUND" );
235235 pearl .discard ();
236236 return ;
237237 }
@@ -242,11 +242,12 @@ public final MethodResult portalShipPrepare(IArguments arguments) throws LuaExce
242242 "facing" , pearl .getDirection ().getName (),
243243 "costs" , getCostsToLevel (level .dimension ()),
244244 "canSpawn" , owner .isMovementPossible (level , pos ),
245- "shipId " , shipId
245+ "warpId " , warpId
246246 );
247- shipPearls .put (shipId , pearl );
247+ shipPearls .values ().removeIf (TurtleEnderPearl ::isRemoved );
248+ shipPearls .put (warpId , pearl );
248249 automataCore .queueEvent (PortalPrepareCallback .EVENT_ID , data );
249- });
250+ }, shipPearls :: remove );
250251 turtle .getLevel ().addFreshEntity (shipPearl );
251252 return null ;
252253 }, null );
@@ -255,18 +256,18 @@ public final MethodResult portalShipPrepare(IArguments arguments) throws LuaExce
255256 }
256257 if (res != null ) {
257258 Object err = res .getResult ()[1 ];
258- automataCore .queueEvent (PortalPrepareCallback .FAILED_EVENT_ID , shipId , err );
259+ automataCore .queueEvent (PortalPrepareCallback .FAILED_EVENT_ID , warpId , err );
259260 }
260261 });
261- return new PortalPrepareCallback (shipId ).pull ;
262+ return new PortalPrepareCallback (warpId ).pull ;
262263 }
263264
264265 /**
265- * @param id the random shipId, one of the result from portalShipPrepare ()
266+ * @param id the random warpId from the result of preparePortalWarp ()
266267 * @return true | nil, string
267268 */
268269 @ LuaFunction (mainThread = true )
269- public final MethodResult portalShipActive (String id ) throws LuaException {
270+ public final MethodResult activePortalWarp (String id ) throws LuaException {
270271 TurtlePeripheralOwner owner = automataCore .getPeripheralOwner ();
271272 TurtleEnderPearl shipPearl = shipPearls .get (id );
272273 if (shipPearl == null ) {
@@ -279,12 +280,12 @@ public final MethodResult portalShipActive(String id) throws LuaException {
279280 Level level = shipPearl .level ();
280281 BlockPos newPosition = shipPearl .blockPosition ();
281282 return automataCore .withOperation (ACTIVE_PORTAL , new SingleOperationContext (getCostsToLevel (level .dimension ()), 1 ), context -> {
283+ shipPearls .remove (id );
282284 shipPearl .discard ();
283285 boolean result = owner .move (level , newPosition );
284286 if (!result ) {
285287 return MethodResult .of (null , "Cannot teleport to location" );
286288 }
287- shipPearls .remove (id );
288289 return MethodResult .of (true );
289290 }, context -> {
290291 if (!owner .isMovementPossible (level , newPosition )) {
@@ -330,7 +331,7 @@ public MethodResult resume(Object[] datas) {
330331 if (!EVENT_ID .equals (datas [0 ]) || datas .length != 2 ) {
331332 return pull ;
332333 }
333- if (!(datas [1 ] instanceof Map <?, ?> data ) || !id .equals (data .get ("shipId " ))) {
334+ if (!(datas [1 ] instanceof Map <?, ?> data ) || !id .equals (data .get ("warpId " ))) {
334335 return pull ;
335336 }
336337 return MethodResult .of (data );
0 commit comments