|
24 | 24 | import net.countercraft.movecraft.async.rotation.RotationTask; |
25 | 25 | import net.countercraft.movecraft.async.translation.TranslationTask; |
26 | 26 | import net.countercraft.movecraft.config.Settings; |
27 | | -import net.countercraft.movecraft.craft.Craft; |
28 | | -import net.countercraft.movecraft.craft.CraftManager; |
29 | | -import net.countercraft.movecraft.craft.CraftStatus; |
30 | | -import net.countercraft.movecraft.craft.PilotedCraft; |
31 | | -import net.countercraft.movecraft.craft.PlayerCraft; |
32 | | -import net.countercraft.movecraft.craft.SinkingCraft; |
| 27 | +import net.countercraft.movecraft.craft.*; |
33 | 28 | import net.countercraft.movecraft.craft.type.CraftType; |
34 | | -import net.countercraft.movecraft.craft.type.RequiredBlockEntry; |
35 | 29 | import net.countercraft.movecraft.events.CraftReleaseEvent; |
36 | | -import net.countercraft.movecraft.exception.EmptyHitBoxException; |
37 | | -import net.countercraft.movecraft.localisation.I18nSupport; |
38 | 30 | import net.countercraft.movecraft.mapUpdater.MapUpdateManager; |
39 | 31 | import net.countercraft.movecraft.mapUpdater.update.BlockCreateCommand; |
40 | 32 | import net.countercraft.movecraft.mapUpdater.update.UpdateCommand; |
41 | | -import net.countercraft.movecraft.util.Counter; |
42 | | -import net.countercraft.movecraft.util.Tags; |
43 | 33 | import net.countercraft.movecraft.util.hitboxes.HitBox; |
44 | | -import net.kyori.adventure.key.Key; |
45 | | -import net.kyori.adventure.sound.Sound; |
46 | 34 | import net.kyori.adventure.text.Component; |
47 | | -import org.bukkit.Bukkit; |
48 | 35 | import org.bukkit.Location; |
49 | 36 | import org.bukkit.Material; |
50 | 37 | import org.bukkit.World; |
51 | 38 | import org.bukkit.block.data.BlockData; |
52 | 39 | import org.bukkit.entity.Player; |
53 | | -import org.bukkit.inventory.InventoryHolder; |
54 | | -import org.bukkit.inventory.ItemStack; |
55 | 40 | import org.bukkit.scheduler.BukkitRunnable; |
56 | 41 | import org.jetbrains.annotations.NotNull; |
57 | 42 |
|
58 | | -import java.util.ArrayList; |
59 | | -import java.util.HashMap; |
60 | | -import java.util.HashSet; |
61 | | -import java.util.List; |
62 | | -import java.util.Map; |
63 | | -import java.util.Set; |
64 | | -import java.util.WeakHashMap; |
| 43 | +import java.util.*; |
65 | 44 | import java.util.concurrent.BlockingQueue; |
66 | 45 | import java.util.concurrent.LinkedBlockingQueue; |
67 | 46 |
|
@@ -319,40 +298,6 @@ else if (dive) { |
319 | 298 | } |
320 | 299 | } |
321 | 300 |
|
322 | | - private void detectSinking(){ |
323 | | - for(Craft craft : CraftManager.getInstance()) { |
324 | | - if (craft instanceof SinkingCraft) |
325 | | - continue; |
326 | | - if (craft.getType().getDoubleProperty(CraftType.SINK_PERCENT) == 0.0 || !craft.isNotProcessing()) |
327 | | - continue; |
328 | | - long ticksElapsed = (System.currentTimeMillis() - craft.getLastBlockCheck()) / 50; |
329 | | - |
330 | | - if (ticksElapsed <= Settings.SinkCheckTicks) |
331 | | - continue; |
332 | | - |
333 | | - CraftStatus status = checkCraftStatus(craft); |
334 | | - //If the craft is disabled, play a sound and disable it. |
335 | | - //Only do this if the craft isn't already disabled. |
336 | | - if (status.isDisabled() && craft.isNotProcessing() && !craft.getDisabled()) { |
337 | | - craft.setDisabled(true); |
338 | | - craft.getAudience().playSound(Sound.sound(Key.key("entity.iron_golem.death"), Sound.Source.NEUTRAL, 5.0f, 5.0f)); |
339 | | - } |
340 | | - |
341 | | - |
342 | | - // if the craft is sinking, let the player |
343 | | - // know and release the craft. Otherwise |
344 | | - // update the time for the next check |
345 | | - if (status.isSinking() && craft.isNotProcessing()) { |
346 | | - craft.getAudience().sendMessage(I18nSupport.getInternationalisedComponent("Player - Craft is sinking")); |
347 | | - craft.setCruising(false); |
348 | | - CraftManager.getInstance().sink(craft); |
349 | | - } |
350 | | - else { |
351 | | - craft.setLastBlockCheck(System.currentTimeMillis()); |
352 | | - } |
353 | | - } |
354 | | - } |
355 | | - |
356 | 301 | //Controls sinking crafts |
357 | 302 | private void processSinking() { |
358 | 303 | //copy the crafts before iteration to prevent concurrent modifications |
@@ -440,7 +385,6 @@ public void run() { |
440 | 385 | clearAll(); |
441 | 386 |
|
442 | 387 | processCruise(); |
443 | | - detectSinking(); |
444 | 388 | processSinking(); |
445 | 389 | processFadingBlocks(); |
446 | 390 | processAlgorithmQueue(); |
@@ -472,95 +416,4 @@ private void clearAll() { |
472 | 416 |
|
473 | 417 | clearanceSet.clear(); |
474 | 418 | } |
475 | | - |
476 | | - public CraftStatus checkCraftStatus(@NotNull Craft craft) { |
477 | | - boolean isSinking = false; |
478 | | - boolean isDisabled = false; |
479 | | - |
480 | | - // Create counters and populate with required block entries |
481 | | - Counter<RequiredBlockEntry> flyBlocks = new Counter<>(); |
482 | | - flyBlocks.putAll(craft.getType().getRequiredBlockProperty(CraftType.FLY_BLOCKS)); |
483 | | - Counter<RequiredBlockEntry> moveBlocks = new Counter<>(); |
484 | | - moveBlocks.putAll(craft.getType().getRequiredBlockProperty(CraftType.MOVE_BLOCKS)); |
485 | | - |
486 | | - Counter<Material> materials = new Counter<>(); |
487 | | - var v = craft.getType().getObjectProperty(CraftType.FUEL_TYPES); |
488 | | - if(!(v instanceof Map<?, ?>)) |
489 | | - throw new IllegalStateException("FUEL_TYPES must be of type Map"); |
490 | | - var fuelTypes = (Map<?, ?>) v; |
491 | | - for(var e : fuelTypes.entrySet()) { |
492 | | - if(!(e.getKey() instanceof Material)) |
493 | | - throw new IllegalStateException("Keys in FUEL_TYPES must be of type Material"); |
494 | | - if(!(e.getValue() instanceof Double)) |
495 | | - throw new IllegalStateException("Values in FUEL_TYPES must be of type Double"); |
496 | | - } |
497 | | - |
498 | | - // go through each block in the HitBox, and if it's in the FlyBlocks or MoveBlocks, increment the counter |
499 | | - int totalNonNegligibleBlocks = 0; |
500 | | - int totalNonNegligibleWaterBlocks = 0; |
501 | | - double fuel = 0; |
502 | | - for (MovecraftLocation l : craft.getHitBox()) { |
503 | | - Material type = craft.getWorld().getBlockAt(l.getX(), l.getY(), l.getZ()).getType(); |
504 | | - for(RequiredBlockEntry entry : flyBlocks.getKeySet()) { |
505 | | - if(entry.contains(type)) |
506 | | - flyBlocks.add(entry); |
507 | | - } |
508 | | - for(RequiredBlockEntry entry : moveBlocks.getKeySet()) { |
509 | | - if(entry.contains(type)) |
510 | | - moveBlocks.add(entry); |
511 | | - } |
512 | | - materials.add(type); |
513 | | - |
514 | | - if (type != Material.FIRE && !type.isAir()) { |
515 | | - totalNonNegligibleBlocks++; |
516 | | - } |
517 | | - if (type != Material.FIRE && !type.isAir() && !Tags.FLUID.contains(type)) { |
518 | | - totalNonNegligibleWaterBlocks++; |
519 | | - } |
520 | | - |
521 | | - if(Tags.FURNACES.contains(type)) { |
522 | | - InventoryHolder inventoryHolder = (InventoryHolder) craft.getWorld().getBlockAt(l.getX(), l.getY(), l.getZ()).getState(); |
523 | | - for (ItemStack iStack : inventoryHolder.getInventory()) { |
524 | | - if (iStack == null || !fuelTypes.containsKey(iStack.getType())) |
525 | | - continue; |
526 | | - fuel += iStack.getAmount() * (double) fuelTypes.get(iStack.getType()); |
527 | | - } |
528 | | - } |
529 | | - } |
530 | | - |
531 | | - // now see if any of the resulting percentages |
532 | | - // are below the threshold specified in sinkPercent |
533 | | - double sinkPercent = craft.getType().getDoubleProperty(CraftType.SINK_PERCENT) / 100.0; |
534 | | - for(RequiredBlockEntry entry : flyBlocks.getKeySet()) { |
535 | | - if(!entry.check(flyBlocks.get(entry), totalNonNegligibleBlocks, sinkPercent)) |
536 | | - isSinking = true; |
537 | | - } |
538 | | - for(RequiredBlockEntry entry : moveBlocks.getKeySet()) { |
539 | | - if(!entry.check(moveBlocks.get(entry), totalNonNegligibleBlocks, sinkPercent)) |
540 | | - isDisabled = !craft.getDisabled() && craft.isNotProcessing(); |
541 | | - } |
542 | | - |
543 | | - // And check the OverallSinkPercent |
544 | | - if (craft.getType().getDoubleProperty(CraftType.OVERALL_SINK_PERCENT) != 0.0) { |
545 | | - double percent; |
546 | | - if (craft.getType().getBoolProperty(CraftType.BLOCKED_BY_WATER)) { |
547 | | - percent = (double) totalNonNegligibleBlocks |
548 | | - / (double) craft.getOrigBlockCount(); |
549 | | - } |
550 | | - else { |
551 | | - percent = (double) totalNonNegligibleWaterBlocks |
552 | | - / (double) craft.getOrigBlockCount(); |
553 | | - } |
554 | | - if (percent * 100.0 < craft.getType().getDoubleProperty(CraftType.OVERALL_SINK_PERCENT)) |
555 | | - isSinking = true; |
556 | | - } |
557 | | - |
558 | | - if (totalNonNegligibleBlocks == 0) |
559 | | - isSinking = true; |
560 | | - |
561 | | - craft.updateMaterials(materials); |
562 | | - craft.setTotalFuel(fuel); |
563 | | - |
564 | | - return CraftStatus.of(isSinking, isDisabled); |
565 | | - } |
566 | 419 | } |
0 commit comments