From 5c623282d14e18fe91ebb1982f07b2ee4e506e91 Mon Sep 17 00:00:00 2001 From: Intybyte Date: Wed, 7 Aug 2024 13:04:23 +0200 Subject: [PATCH 01/13] Remove useless if statements --- .../movecraft/async/translation/TranslationTask.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java index 068f5d474..c763d6f10 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java @@ -111,12 +111,11 @@ protected void execute() throws InterruptedException, ExecutionException { fail(preTranslateEvent.getFailMessage(), preTranslateEvent.isPlayingFailSound()); return; } - if (dx != preTranslateEvent.getDx()) - dx = preTranslateEvent.getDx(); - if (dy != preTranslateEvent.getDy()) - dy = preTranslateEvent.getDy(); - if (dz != preTranslateEvent.getDz()) - dz = preTranslateEvent.getDz(); + + dx = preTranslateEvent.getDx(); + dy = preTranslateEvent.getDy(); + dz = preTranslateEvent.getDz(); + world = preTranslateEvent.getWorld(); final int minY = oldHitBox.getMinY(); From b759c9a1901a1ff1e40c6668ead1ba7f389c4ccc Mon Sep 17 00:00:00 2001 From: Intybyte Date: Wed, 7 Aug 2024 13:08:09 +0200 Subject: [PATCH 02/13] Extract Process all nether portals --- .../async/translation/TranslationTask.java | 63 ++++++++++--------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java index c763d6f10..5b8bb30ed 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java @@ -3,7 +3,6 @@ import net.countercraft.movecraft.Movecraft; import net.countercraft.movecraft.MovecraftChunk; import net.countercraft.movecraft.MovecraftLocation; -import net.countercraft.movecraft.TrackedLocation; import net.countercraft.movecraft.async.AsyncTask; import net.countercraft.movecraft.config.Settings; import net.countercraft.movecraft.craft.ChunkManager; @@ -58,7 +57,6 @@ import java.util.Collection; import java.util.EnumSet; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.concurrent.ExecutionException; @@ -122,33 +120,7 @@ protected void execute() throws InterruptedException, ExecutionException { final int maxY = oldHitBox.getMaxY(); // proccess nether portals - if (Settings.CraftsUseNetherPortals && craft.getWorld().getEnvironment() != Environment.THE_END - && world.equals(craft.getWorld())) { - - // ensure chunks are loaded for portal checking only if change in location is - // large - Set chunksToLoad = ChunkManager.getChunks(oldHitBox, world, dx, dy, dz); - MovecraftChunk.addSurroundingChunks(chunksToLoad, 2); - ChunkManager.checkChunks(chunksToLoad); - if (!chunksToLoad.isEmpty()) - ChunkManager.syncLoadChunks(chunksToLoad).get(); - - for (MovecraftLocation oldLocation : oldHitBox) { - - Location location = oldLocation.translate(dx, dy, dz).toBukkit(craft.getWorld()); - Block block = craft.getWorld().getBlockAt(location); - if (block.getType() == Material.NETHER_PORTAL) { - if (processNetherPortal(block)) { - sound = Sound.BLOCK_PORTAL_TRAVEL; - volume = 0.25f; - break; - } - - } - - } - - } + processAllNetherPortals(); // ensure chunks are loaded only if world is different or change in location is // large @@ -455,6 +427,39 @@ else if (world.equals(craft.getWorld()) captureYield(harvestedBlocks); } + private void processAllNetherPortals() throws ExecutionException, InterruptedException { + // proccess nether portals + if (!Settings.CraftsUseNetherPortals + || craft.getWorld().getEnvironment() == Environment.THE_END + || !world.equals(craft.getWorld())) { + return; + } + + // ensure chunks are loaded for portal checking only if change in location is + // large + Set chunksToLoad = ChunkManager.getChunks(oldHitBox, world, dx, dy, dz); + MovecraftChunk.addSurroundingChunks(chunksToLoad, 2); + ChunkManager.checkChunks(chunksToLoad); + if (!chunksToLoad.isEmpty()) + ChunkManager.syncLoadChunks(chunksToLoad).get(); + + for (MovecraftLocation oldLocation : oldHitBox) { + Location location = oldLocation.translate(dx, dy, dz).toBukkit(craft.getWorld()); + Block block = craft.getWorld().getBlockAt(location); + + if (block.getType() != Material.NETHER_PORTAL) { + continue; + } + + if (processNetherPortal(block)) { + sound = Sound.BLOCK_PORTAL_TRAVEL; + volume = 0.25f; + break; + } + + } + } + private void fail(@NotNull String failMessage) { fail(failMessage, true); } From 2ab2f48858805d71040a3dd585852fa266c84750 Mon Sep 17 00:00:00 2001 From: Intybyte Date: Wed, 7 Aug 2024 13:16:01 +0200 Subject: [PATCH 03/13] Extract Process High Craft --- .../async/translation/TranslationTask.java | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java index 5b8bb30ed..a3fc4990d 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java @@ -133,24 +133,7 @@ protected void execute() throws InterruptedException, ExecutionException { // Only modify dy when not switching worlds //Check if the craft is too high - if (world.equals(craft.getWorld()) - && (int) craft.getType().getPerWorldProperty(CraftType.PER_WORLD_MAX_HEIGHT_LIMIT, craft.getWorld()) - < craft.getHitBox().getMinY()) - dy = Math.min(dy, -1); - else if (world.equals(craft.getWorld()) - && (int) craft.getType().getPerWorldProperty(CraftType.PER_WORLD_MAX_HEIGHT_ABOVE_GROUND, - craft.getWorld()) > 0) { - final MovecraftLocation middle = oldHitBox.getMidPoint(); - int testY = minY; - while (testY > 0) { - testY--; - if (!craft.getWorld().getBlockAt(middle.getX(), testY, middle.getZ()).getType().isAir()) - break; - } - if (maxY - testY - > (int) craft.getType().getPerWorldProperty(CraftType.PER_WORLD_MAX_HEIGHT_ABOVE_GROUND, world)) - dy = Math.min(dy, -1); - } + processHighCraft(minY, maxY); //Process gravity if (world.equals(craft.getWorld()) && craft.getType().getBoolProperty(CraftType.USE_GRAVITY) && !(craft instanceof SinkingCraft)) { @@ -460,6 +443,34 @@ private void processAllNetherPortals() throws ExecutionException, InterruptedExc } } + private void processHighCraft(int minY, int maxY) { + // Only modify dy when not switching worlds + //Check if the craft is too high + boolean sameWorld = world.equals(craft.getWorld()); + CraftType craftType = craft.getType(); + if (!sameWorld) { + return; + } + + if ((int) craftType.getPerWorldProperty(CraftType.PER_WORLD_MAX_HEIGHT_LIMIT, craft.getWorld()) < craft.getHitBox().getMinY()) { + dy = Math.min(dy, -1); + return; + } + final int perWorldMaxHeigh = (int) craftType.getPerWorldProperty(CraftType.PER_WORLD_MAX_HEIGHT_ABOVE_GROUND, world); + // world == craft.world + if (perWorldMaxHeigh > 0) { + final MovecraftLocation middle = oldHitBox.getMidPoint(); + int testY = minY; + while (testY > 0) { + testY--; + if (!craft.getWorld().getBlockAt(middle.getX(), testY, middle.getZ()).getType().isAir()) + break; + } + if (maxY - testY > perWorldMaxHeigh) + dy = Math.min(dy, -1); + } + } + private void fail(@NotNull String failMessage) { fail(failMessage, true); } From 2c009d38041d7ea6a74e2bd2c459dbd2394367df Mon Sep 17 00:00:00 2001 From: Intybyte Date: Wed, 7 Aug 2024 13:22:00 +0200 Subject: [PATCH 04/13] Extract Process Gravity --- .../async/translation/TranslationTask.java | 80 ++++++++++++------- 1 file changed, 52 insertions(+), 28 deletions(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java index a3fc4990d..19a0b9a97 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java @@ -134,34 +134,9 @@ protected void execute() throws InterruptedException, ExecutionException { // Only modify dy when not switching worlds //Check if the craft is too high processHighCraft(minY, maxY); - //Process gravity - if (world.equals(craft.getWorld()) && craft.getType().getBoolProperty(CraftType.USE_GRAVITY) - && !(craft instanceof SinkingCraft)) { - int incline = inclineCraft(oldHitBox); - if (incline > 0) { - boolean tooSteep = craft.getType().getIntProperty(CraftType.GRAVITY_INCLINE_DISTANCE) > -1 - && incline > craft.getType().getIntProperty(CraftType.GRAVITY_INCLINE_DISTANCE); - if (tooSteep && craft.getType().getFloatProperty(CraftType.COLLISION_EXPLOSION) <= 0F) { - fail(I18nSupport.getInternationalisedString("Translation - Failed Incline too steep")); - return; - } - dy = tooSteep ? 0 : incline; - } else if (!isOnGround(oldHitBox) && craft.getType().getBoolProperty(CraftType.CAN_HOVER)) { - MovecraftLocation midPoint = oldHitBox.getMidPoint(); - int centreMinY = oldHitBox.getMinYAt(midPoint.getX(), midPoint.getZ()); - int groundY = centreMinY; - World w = craft.getWorld(); - while (groundY - 1 >= w.getMinHeight() - && (w.getBlockAt(midPoint.getX(), groundY - 1, midPoint.getZ()).getType().isAir() - || craft.getType().getMaterialSetProperty(CraftType.PASSTHROUGH_BLOCKS).contains( - w.getBlockAt(midPoint.getX(), groundY - 1, midPoint.getZ()).getType()))) { - groundY--; - } - if (centreMinY - groundY > craft.getType().getIntProperty(CraftType.HOVER_LIMIT)) - dy = -1; - } else if (!isOnGround(oldHitBox)) - dy = dropDistance(oldHitBox); - } + //Process gravity (must be same world too) + if (processGravity()) + return; //Fail the movement if the craft is too high and if the craft is not explosive int maxHeightLimit = (int) craft.getType().getPerWorldProperty(CraftType.PER_WORLD_MAX_HEIGHT_LIMIT, world); int minHeightLimit = (int) craft.getType().getPerWorldProperty(CraftType.PER_WORLD_MIN_HEIGHT_LIMIT, world); @@ -410,6 +385,55 @@ protected void execute() throws InterruptedException, ExecutionException { captureYield(harvestedBlocks); } + /** + * + * @return True if failed, false otherwise + */ + private boolean processGravity() { + //Process gravity (must be same world too) + if (!world.equals(craft.getWorld()) || !craft.getType().getBoolProperty(CraftType.USE_GRAVITY) + || craft instanceof SinkingCraft) { + return false; + } + + int incline = inclineCraft(oldHitBox); + if (incline > 0) { + boolean tooSteep = craft.getType().getIntProperty(CraftType.GRAVITY_INCLINE_DISTANCE) > -1 + && incline > craft.getType().getIntProperty(CraftType.GRAVITY_INCLINE_DISTANCE); + if (tooSteep && craft.getType().getFloatProperty(CraftType.COLLISION_EXPLOSION) <= 0F) { + fail(I18nSupport.getInternationalisedString("Translation - Failed Incline too steep")); + return true; + } + dy = tooSteep ? 0 : incline; + return false; + } + + if (isOnGround(oldHitBox)) { + return false; + } + + if (craft.getType().getBoolProperty(CraftType.CAN_HOVER)) { + MovecraftLocation midPoint = oldHitBox.getMidPoint(); + int centreMinY = oldHitBox.getMinYAt(midPoint.getX(), midPoint.getZ()); + int groundY = centreMinY; + World w = craft.getWorld(); + + while (groundY - 1 >= w.getMinHeight() + && (w.getBlockAt(midPoint.getX(), groundY - 1, midPoint.getZ()).getType().isAir() + || craft.getType().getMaterialSetProperty(CraftType.PASSTHROUGH_BLOCKS).contains( + w.getBlockAt(midPoint.getX(), groundY - 1, midPoint.getZ()).getType()))) { + groundY--; + } + + if (centreMinY - groundY > craft.getType().getIntProperty(CraftType.HOVER_LIMIT)) + dy = -1; + return false; + } + + dy = dropDistance(oldHitBox); + return false; + } + private void processAllNetherPortals() throws ExecutionException, InterruptedException { // proccess nether portals if (!Settings.CraftsUseNetherPortals From 9a6960b2a14f7690ec27dbdb514e507f293aab77 Mon Sep 17 00:00:00 2001 From: Intybyte Date: Wed, 7 Aug 2024 13:29:17 +0200 Subject: [PATCH 05/13] Extract preventsTorpedoRocketsPilots --- .../async/translation/TranslationTask.java | 105 ++++++++++-------- 1 file changed, 59 insertions(+), 46 deletions(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java index 19a0b9a97..0c05dfeb4 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java @@ -137,6 +137,7 @@ protected void execute() throws InterruptedException, ExecutionException { //Process gravity (must be same world too) if (processGravity()) return; + //Fail the movement if the craft is too high and if the craft is not explosive int maxHeightLimit = (int) craft.getType().getPerWorldProperty(CraftType.PER_WORLD_MAX_HEIGHT_LIMIT, world); int minHeightLimit = (int) craft.getType().getPerWorldProperty(CraftType.PER_WORLD_MIN_HEIGHT_LIMIT, world); @@ -329,60 +330,72 @@ protected void execute() throws InterruptedException, ExecutionException { updates.add(new CraftTranslateCommand(craft, new MovecraftLocation(dx, dy, dz), world)); //prevents torpedo and rocket pilots - if (!(craft instanceof SinkingCraft && craft.getType().getBoolProperty(CraftType.ONLY_MOVE_PLAYERS)) - && craft.getType().getBoolProperty(CraftType.MOVE_ENTITIES)) { - Location midpoint = new Location( - craft.getWorld(), - (oldHitBox.getMaxX() + oldHitBox.getMinX()) / 2.0, - (oldHitBox.getMaxY() + oldHitBox.getMinY()) / 2.0, - (oldHitBox.getMaxZ() + oldHitBox.getMinZ()) / 2.0); - for (Entity entity : craft.getWorld().getNearbyEntities(midpoint, - oldHitBox.getXLength() / 2.0 + 1, - oldHitBox.getYLength() / 2.0 + 2, - oldHitBox.getZLength() / 2.0 + 1 - )) { - - if (entity instanceof HumanEntity) { - InventoryView inventoryView = ((HumanEntity) entity).getOpenInventory(); - if (inventoryView.getType() != InventoryType.CRAFTING) { - Location l = Movecraft.getInstance().getWorldHandler().getAccessLocation(inventoryView); - if (l != null) { - MovecraftLocation location = new MovecraftLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ()); - if (oldHitBox.contains(location)) { - location = location.translate(dx, dy, dz); - updates.add(new AccessLocationUpdateCommand(inventoryView, location.toBukkit(world))); - } + preventsTorpedoRocketsPilots(); + captureYield(harvestedBlocks); + } + + //this part looks similar to rotationTask? + private void preventsTorpedoRocketsPilots() { + if (craft instanceof SinkingCraft + && craft.getType().getBoolProperty(CraftType.ONLY_MOVE_PLAYERS) + || !craft.getType().getBoolProperty(CraftType.MOVE_ENTITIES)) { + // add releaseTask without playermove to manager + if (!craft.getType().getBoolProperty(CraftType.CRUISE_ON_PILOT) && !(craft instanceof SinkingCraft)) + // not necessary to release cruiseonpilot crafts, because they will already be released + CraftManager.getInstance().addReleaseTask(craft); + return; + } + + Location midpoint = new Location( + craft.getWorld(), + (oldHitBox.getMaxX() + oldHitBox.getMinX()) / 2.0, + (oldHitBox.getMaxY() + oldHitBox.getMinY()) / 2.0, + (oldHitBox.getMaxZ() + oldHitBox.getMinZ()) / 2.0); + for (Entity entity : craft.getWorld().getNearbyEntities(midpoint, + oldHitBox.getXLength() / 2.0 + 1, + oldHitBox.getYLength() / 2.0 + 2, + oldHitBox.getZLength() / 2.0 + 1 + )) { + + if (entity instanceof HumanEntity) { + InventoryView inventoryView = ((HumanEntity) entity).getOpenInventory(); + if (inventoryView.getType() != InventoryType.CRAFTING) { + Location l = Movecraft.getInstance().getWorldHandler().getAccessLocation(inventoryView); + if (l != null) { + MovecraftLocation location = new MovecraftLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ()); + if (oldHitBox.contains(location)) { + location = location.translate(dx, dy, dz); + updates.add(new AccessLocationUpdateCommand(inventoryView, location.toBukkit(world))); } } } + } - if ((entity.getType() == EntityType.PLAYER && !(craft instanceof SinkingCraft))) { - CraftTeleportEntityEvent e = new CraftTeleportEntityEvent(craft, entity); - Bukkit.getServer().getPluginManager().callEvent(e); - if (e.isCancelled()) - continue; + if ((entity.getType() == EntityType.PLAYER && !(craft instanceof SinkingCraft))) { + CraftTeleportEntityEvent e = new CraftTeleportEntityEvent(craft, entity); + Bukkit.getServer().getPluginManager().callEvent(e); + if (e.isCancelled()) + continue; - EntityUpdateCommand eUp = new EntityUpdateCommand(entity, dx, dy, dz, 0, 0, - world, sound, volume); - updates.add(eUp); - } else if (!craft.getType().getBoolProperty(CraftType.ONLY_MOVE_PLAYERS) - || entity.getType() == EntityType.PRIMED_TNT) { - CraftTeleportEntityEvent e = new CraftTeleportEntityEvent(craft, entity); - Bukkit.getServer().getPluginManager().callEvent(e); - if (e.isCancelled()) - continue; + EntityUpdateCommand eUp = new EntityUpdateCommand(entity, dx, dy, dz, 0, 0, + world, sound, volume); + updates.add(eUp); + continue; + } - EntityUpdateCommand eUp = new EntityUpdateCommand(entity, dx, dy, dz, 0, 0, world); - updates.add(eUp); - } + if (craft.getType().getBoolProperty(CraftType.ONLY_MOVE_PLAYERS) + && entity.getType() != EntityType.PRIMED_TNT) { + continue; } - } else { - // add releaseTask without playermove to manager - if (!craft.getType().getBoolProperty(CraftType.CRUISE_ON_PILOT) && !(craft instanceof SinkingCraft)) - // not necessary to release cruiseonpilot crafts, because they will already be released - CraftManager.getInstance().addReleaseTask(craft); + + CraftTeleportEntityEvent e = new CraftTeleportEntityEvent(craft, entity); + Bukkit.getServer().getPluginManager().callEvent(e); + if (e.isCancelled()) + continue; + + EntityUpdateCommand eUp = new EntityUpdateCommand(entity, dx, dy, dz, 0, 0, world); + updates.add(eUp); } - captureYield(harvestedBlocks); } /** From e12981513fa80a1224a06239cd2af8451471483b Mon Sep 17 00:00:00 2001 From: Intybyte Date: Wed, 7 Aug 2024 13:30:56 +0200 Subject: [PATCH 06/13] Extract processHumanEntity --- .../async/translation/TranslationTask.java | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java index 0c05dfeb4..e353dedb5 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java @@ -334,7 +334,6 @@ protected void execute() throws InterruptedException, ExecutionException { captureYield(harvestedBlocks); } - //this part looks similar to rotationTask? private void preventsTorpedoRocketsPilots() { if (craft instanceof SinkingCraft && craft.getType().getBoolProperty(CraftType.ONLY_MOVE_PLAYERS) @@ -357,19 +356,7 @@ private void preventsTorpedoRocketsPilots() { oldHitBox.getZLength() / 2.0 + 1 )) { - if (entity instanceof HumanEntity) { - InventoryView inventoryView = ((HumanEntity) entity).getOpenInventory(); - if (inventoryView.getType() != InventoryType.CRAFTING) { - Location l = Movecraft.getInstance().getWorldHandler().getAccessLocation(inventoryView); - if (l != null) { - MovecraftLocation location = new MovecraftLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ()); - if (oldHitBox.contains(location)) { - location = location.translate(dx, dy, dz); - updates.add(new AccessLocationUpdateCommand(inventoryView, location.toBukkit(world))); - } - } - } - } + processHumanEntity(entity); if ((entity.getType() == EntityType.PLAYER && !(craft instanceof SinkingCraft))) { CraftTeleportEntityEvent e = new CraftTeleportEntityEvent(craft, entity); @@ -398,6 +385,30 @@ private void preventsTorpedoRocketsPilots() { } } + //this part looks similar to rotationTask + //maybe can be thrown in a util class? + private void processHumanEntity(Entity entity) { + if (!(entity instanceof HumanEntity)) { + return; + } + + InventoryView inventoryView = ((HumanEntity) entity).getOpenInventory(); + if (inventoryView.getType() == InventoryType.CRAFTING) { + return; + } + + Location l = Movecraft.getInstance().getWorldHandler().getAccessLocation(inventoryView); + if (l == null) { + return; + } + + MovecraftLocation location = new MovecraftLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ()); + if (oldHitBox.contains(location)) { + location = location.translate(dx, dy, dz); + updates.add(new AccessLocationUpdateCommand(inventoryView, location.toBukkit(world))); + } + } + /** * * @return True if failed, false otherwise From face4ea44dbf468a4bfb501f28e44d3d4c3f0261 Mon Sep 17 00:00:00 2001 From: Intybyte Date: Wed, 7 Aug 2024 13:33:50 +0200 Subject: [PATCH 07/13] Small changes --- .../movecraft/async/translation/TranslationTask.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java index e353dedb5..dadac8e46 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java @@ -288,7 +288,8 @@ protected void execute() throws InterruptedException, ExecutionException { && System.currentTimeMillis() - craft.getOrigPilotTime() > craft.getType().getIntProperty(CraftType.EXPLOSION_ARMING_TIME)) { for (MovecraftLocation location : collisionBox) { float explosionForce = craft.getType().getFloatProperty(CraftType.COLLISION_EXPLOSION); - if (craft.getType().getBoolProperty(CraftType.FOCUSED_EXPLOSION)) { + final boolean focused_explosion = craft.getType().getBoolProperty(CraftType.FOCUSED_EXPLOSION); + if (focused_explosion) { explosionForce *= Math.min(oldHitBox.size(), craft.getType().getIntProperty(CraftType.MAX_SIZE)); } //TODO: Account for underwater explosions @@ -306,7 +307,8 @@ protected void execute() throws InterruptedException, ExecutionException { collisionExplosion = true; } } - if (craft.getType().getBoolProperty(CraftType.FOCUSED_EXPLOSION)) { + + if (focused_explosion) { // don't handle any further collisions if it is set to focusedexplosion break; } From b71db5e4aa43b2218c9fba4230c92607e1c310e4 Mon Sep 17 00:00:00 2001 From: Intybyte Date: Sat, 17 Aug 2024 19:44:54 +0200 Subject: [PATCH 08/13] Fix WorldHeight check + Small refactor --- .../async/translation/TranslationTask.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java index dadac8e46..1f5f91f1c 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java @@ -69,13 +69,13 @@ public class TranslationTask extends AsyncTask { private World world; private int dx, dy, dz; private SetHitBox newHitBox; - private HitBox oldHitBox; - private SetHitBox oldFluidList; - private SetHitBox newFluidList; + private final HitBox oldHitBox; + private final SetHitBox oldFluidList; + private final SetHitBox newFluidList; private boolean failed; private boolean collisionExplosion = false; private String failMessage; - private Collection updates = new HashSet<>(); + private final Collection updates = new HashSet<>(); private Sound sound = null; private float volume = 0.0f; @@ -495,7 +495,7 @@ private void processAllNetherPortals() throws ExecutionException, InterruptedExc private void processHighCraft(int minY, int maxY) { // Only modify dy when not switching worlds - //Check if the craft is too high + // Check if the craft is too high boolean sameWorld = world.equals(craft.getWorld()); CraftType craftType = craft.getType(); if (!sameWorld) { @@ -508,17 +508,21 @@ private void processHighCraft(int minY, int maxY) { } final int perWorldMaxHeigh = (int) craftType.getPerWorldProperty(CraftType.PER_WORLD_MAX_HEIGHT_ABOVE_GROUND, world); // world == craft.world - if (perWorldMaxHeigh > 0) { - final MovecraftLocation middle = oldHitBox.getMidPoint(); - int testY = minY; - while (testY > 0) { - testY--; - if (!craft.getWorld().getBlockAt(middle.getX(), testY, middle.getZ()).getType().isAir()) - break; + if (perWorldMaxHeigh <= world.getMinHeight()) { + return; + } + + final MovecraftLocation middle = oldHitBox.getMidPoint(); + int testY; + + for (testY = minY; testY > 0; testY--) { + if (!craft.getWorld().getBlockAt(middle.getX(), testY - 1, middle.getZ()).getType().isAir()) { + break; } - if (maxY - testY > perWorldMaxHeigh) - dy = Math.min(dy, -1); } + + if (maxY - testY > perWorldMaxHeigh) + dy = Math.min(dy, -1); } private void fail(@NotNull String failMessage) { From cc134cad1385193ffb9004e99623a1d420707c0b Mon Sep 17 00:00:00 2001 From: Intybyte Date: Sat, 17 Aug 2024 19:49:32 +0200 Subject: [PATCH 09/13] Fix Check --- .../movecraft/async/translation/TranslationTask.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java index 1f5f91f1c..263a0a5ee 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java @@ -337,9 +337,9 @@ protected void execute() throws InterruptedException, ExecutionException { } private void preventsTorpedoRocketsPilots() { - if (craft instanceof SinkingCraft - && craft.getType().getBoolProperty(CraftType.ONLY_MOVE_PLAYERS) - || !craft.getType().getBoolProperty(CraftType.MOVE_ENTITIES)) { + if (!craft.getType().getBoolProperty(CraftType.MOVE_ENTITIES) || + (craft instanceof SinkingCraft + && craft.getType().getBoolProperty(CraftType.ONLY_MOVE_PLAYERS))) { // add releaseTask without playermove to manager if (!craft.getType().getBoolProperty(CraftType.CRUISE_ON_PILOT) && !(craft instanceof SinkingCraft)) // not necessary to release cruiseonpilot crafts, because they will already be released From 78828ee0c66df015859674ba1ac796b288daf616 Mon Sep 17 00:00:00 2001 From: Intybyte Date: Sat, 17 Aug 2024 20:27:33 +0200 Subject: [PATCH 10/13] 4 cycle --- .../movecraft/async/translation/TranslationTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java index 263a0a5ee..06e57be77 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java @@ -515,7 +515,7 @@ private void processHighCraft(int minY, int maxY) { final MovecraftLocation middle = oldHitBox.getMidPoint(); int testY; - for (testY = minY; testY > 0; testY--) { + for (testY = minY; testY > world.getMinHeight(); testY--) { if (!craft.getWorld().getBlockAt(middle.getX(), testY - 1, middle.getZ()).getType().isAir()) { break; } From 7732fdc091d1fbdc1c72c5cd8e006445054f0dd2 Mon Sep 17 00:00:00 2001 From: Intybyte Date: Sun, 18 Aug 2024 17:40:11 +0200 Subject: [PATCH 11/13] Incendiary Fix + Remove unused imports --- .../movecraft/async/translation/TranslationTask.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java index 1a59b8ec0..b59784e0f 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java @@ -3,7 +3,6 @@ import net.countercraft.movecraft.Movecraft; import net.countercraft.movecraft.MovecraftChunk; import net.countercraft.movecraft.MovecraftLocation; -import net.countercraft.movecraft.TrackedLocation; import net.countercraft.movecraft.async.AsyncTask; import net.countercraft.movecraft.config.Settings; import net.countercraft.movecraft.craft.*; @@ -55,7 +54,6 @@ import java.util.Collection; import java.util.EnumSet; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.concurrent.ExecutionException; @@ -270,7 +268,8 @@ protected void execute() throws InterruptedException, ExecutionException { Location loc = location.toBukkit(craft.getWorld()); if (!loc.getBlock().getType().isAir() && ThreadLocalRandom.current().nextDouble(1) < .05) { updates.add(new ExplosionUpdateCommand(loc, - craft.getType().getFloatProperty(CraftType.EXPLODE_ON_CRASH))); + craft.getType().getFloatProperty(CraftType.EXPLODE_ON_CRASH), + craft.getType().getBoolProperty(CraftType.INCENDIARY_ON_CRASH))); collisionExplosion = true; } } From 2d70bb57b7f68adda3d078e2d6cfad891be3e7ea Mon Sep 17 00:00:00 2001 From: Intybyte Date: Tue, 20 Aug 2024 09:07:03 +0200 Subject: [PATCH 12/13] Fix processHighCraft --- .../movecraft/async/translation/TranslationTask.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java index b59784e0f..c2807a30a 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java @@ -514,22 +514,22 @@ private void processHighCraft(int minY, int maxY) { dy = Math.min(dy, -1); return; } - final int perWorldMaxHeigh = (int) craftType.getPerWorldProperty(CraftType.PER_WORLD_MAX_HEIGHT_ABOVE_GROUND, world); + final int perWorldMaxHeighAboveGround = (int) craftType.getPerWorldProperty(CraftType.PER_WORLD_MAX_HEIGHT_ABOVE_GROUND, world); // world == craft.world - if (perWorldMaxHeigh <= world.getMinHeight()) { + if (perWorldMaxHeighAboveGround <= 0) { return; } final MovecraftLocation middle = oldHitBox.getMidPoint(); int testY; - for (testY = minY; testY > world.getMinHeight(); testY--) { + for (testY = minY; testY > 0; testY--) { if (!craft.getWorld().getBlockAt(middle.getX(), testY - 1, middle.getZ()).getType().isAir()) { break; } } - if (maxY - testY > perWorldMaxHeigh) + if (maxY - testY > perWorldMaxHeighAboveGround) dy = Math.min(dy, -1); } From 4aca7043093be72a002481ce980956b48a376862 Mon Sep 17 00:00:00 2001 From: Intybyte Date: Tue, 20 Aug 2024 16:10:20 +0200 Subject: [PATCH 13/13] Use minHeight instead --- .../movecraft/async/translation/TranslationTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java index c2807a30a..d1d23459f 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java @@ -523,7 +523,7 @@ private void processHighCraft(int minY, int maxY) { final MovecraftLocation middle = oldHitBox.getMidPoint(); int testY; - for (testY = minY; testY > 0; testY--) { + for (testY = minY; testY > world.getMinHeight(); testY--) { if (!craft.getWorld().getBlockAt(middle.getX(), testY - 1, middle.getZ()).getType().isAir()) { break; }