From 936a87a1ba08f042d4f348606f3f7cea0966b8b2 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Tue, 10 Sep 2024 21:01:53 -0500 Subject: [PATCH] Drop 1.18.2 support (#711) * Remove v1_18 module * Fix build * Remove unneeded API * Refactor SupportUtils * Further clean up of SupportUtils * Move SupportUtils * Update SupportUtils.java * Update SupportUtils.java --- Movecraft/build.gradle.kts | 6 +- .../async/rotation/RotationTask.java | 33 +- .../async/translation/TranslationTask.java | 33 +- .../update/AccessLocationUpdateCommand.java | 48 --- .../update/ParticleUpdateCommand.java | 2 +- .../tasks/detection/DetectionTask.java | 15 +- .../tasks/detection/SupportUtils.java | 47 --- .../effects/TeleportationEffect.java | 2 +- api/build.gradle.kts | 2 +- .../countercraft/movecraft/WorldHandler.java | 4 - .../movecraft/support/AsyncChunk.java | 2 +- .../movecraft/support/MovecraftState.java | 19 + .../movecraft/util/SupportUtils.java | 31 ++ .../net/countercraft/movecraft/util/Tags.java | 2 +- gradle/libs.versions.toml | 2 +- settings.gradle.kts | 2 - v1_18/build.gradle.kts | 18 - .../movecraft/compat/v1_18/IWorldHandler.java | 350 ------------------ .../compat/v1_18/NextTickProvider.java | 39 -- .../movecraft/support/v1_18/IAsyncChunk.java | 61 --- .../support/v1_18/ISmoothTeleport.java | 102 ----- .../movecraft/compat/v1_20/IWorldHandler.java | 11 - .../movecraft/compat/v1_21/IWorldHandler.java | 11 - 23 files changed, 68 insertions(+), 774 deletions(-) delete mode 100644 Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/AccessLocationUpdateCommand.java delete mode 100644 Movecraft/src/main/java/net/countercraft/movecraft/processing/tasks/detection/SupportUtils.java create mode 100644 api/src/main/java/net/countercraft/movecraft/util/SupportUtils.java delete mode 100644 v1_18/build.gradle.kts delete mode 100644 v1_18/src/main/java/net/countercraft/movecraft/compat/v1_18/IWorldHandler.java delete mode 100644 v1_18/src/main/java/net/countercraft/movecraft/compat/v1_18/NextTickProvider.java delete mode 100644 v1_18/src/main/java/net/countercraft/movecraft/support/v1_18/IAsyncChunk.java delete mode 100644 v1_18/src/main/java/net/countercraft/movecraft/support/v1_18/ISmoothTeleport.java diff --git a/Movecraft/build.gradle.kts b/Movecraft/build.gradle.kts index 683722e23..3574d461f 100644 --- a/Movecraft/build.gradle.kts +++ b/Movecraft/build.gradle.kts @@ -5,10 +5,9 @@ plugins { id("io.papermc.hangar-publish-plugin") version "0.1.2" } -java.toolchain.languageVersion = JavaLanguageVersion.of(17) +java.toolchain.languageVersion = JavaLanguageVersion.of(21) dependencies { - runtimeOnly(project(":movecraft-v1_18", "reobf")) runtimeOnly(project(":movecraft-v1_20", "reobf")) runtimeOnly(project(":movecraft-v1_21", "reobf")) implementation(project(":movecraft-api")) @@ -22,7 +21,6 @@ tasks.shadowJar { dependencies { include(project(":movecraft-api")) - include(project(":movecraft-v1_18")) include(project(":movecraft-v1_20")) include(project(":movecraft-v1_21")) } @@ -68,7 +66,7 @@ hangarPublish { platforms { register(io.papermc.hangarpublishplugin.model.Platforms.PAPER) { jar.set(tasks.shadowJar.flatMap { it.archiveFile }) - platformVersions.set(listOf("1.18.2", "1.20.6", "1.21.1")) + platformVersions.set(listOf("1.20.6", "1.21.1")) } } } diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java b/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java index 327e9e86c..5c7711797 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java @@ -18,7 +18,6 @@ package net.countercraft.movecraft.async.rotation; import net.countercraft.movecraft.CruiseDirection; -import net.countercraft.movecraft.Movecraft; import net.countercraft.movecraft.MovecraftLocation; import net.countercraft.movecraft.MovecraftRotation; import net.countercraft.movecraft.TrackedLocation; @@ -32,7 +31,6 @@ import net.countercraft.movecraft.events.CraftRotateEvent; import net.countercraft.movecraft.events.CraftTeleportEntityEvent; import net.countercraft.movecraft.localisation.I18nSupport; -import net.countercraft.movecraft.mapUpdater.update.AccessLocationUpdateCommand; import net.countercraft.movecraft.mapUpdater.update.CraftRotateCommand; import net.countercraft.movecraft.mapUpdater.update.EntityUpdateCommand; import net.countercraft.movecraft.mapUpdater.update.UpdateCommand; @@ -47,9 +45,6 @@ import org.bukkit.World; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; -import org.bukkit.entity.HumanEntity; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.inventory.InventoryView; import java.util.HashSet; import java.util.List; @@ -270,14 +265,12 @@ private void rotateEntitiesOnCraft(Location tOP) { (oldHitBox.getMaxY() + oldHitBox.getMinY())/2.0, (oldHitBox.getMaxZ() + oldHitBox.getMinZ())/2.0); - List entityList = List.of(EntityType.PLAYER, EntityType.PRIMED_TNT); + List entityList = List.of(EntityType.PLAYER, EntityType.TNT); for(Entity entity : craft.getWorld().getNearbyEntities(midpoint, oldHitBox.getXLength() / 2.0 + 1, oldHitBox.getYLength() / 2.0 + 2, oldHitBox.getZLength() / 2.0 + 1)) { - rotateHumanEntity(entity); - if (craft.getType().getBoolProperty(CraftType.ONLY_MOVE_PLAYERS) && (!entityList.contains(entity.getType()) || craft instanceof SinkingCraft)) { @@ -308,30 +301,6 @@ private void rotateEntitiesOnCraft(Location tOP) { } } - private void rotateHumanEntity(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)) { - return; - } - - location = MathUtils.rotateVec(rotation, location.subtract(originPoint)).add(originPoint); - updates.add(new AccessLocationUpdateCommand(inventoryView, location.toBukkit(w))); - } - public MovecraftLocation getOriginPoint() { return originPoint; } 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 d1d23459f..936da69ac 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 @@ -15,7 +15,6 @@ import net.countercraft.movecraft.events.CraftTranslateEvent; import net.countercraft.movecraft.events.ItemHarvestEvent; import net.countercraft.movecraft.localisation.I18nSupport; -import net.countercraft.movecraft.mapUpdater.update.AccessLocationUpdateCommand; import net.countercraft.movecraft.mapUpdater.update.BlockCreateCommand; import net.countercraft.movecraft.mapUpdater.update.CraftTranslateCommand; import net.countercraft.movecraft.mapUpdater.update.EntityUpdateCommand; @@ -41,11 +40,8 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; -import org.bukkit.entity.HumanEntity; -import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -365,9 +361,6 @@ private void preventsTorpedoRocketsPilots() { oldHitBox.getYLength() / 2.0 + 2, oldHitBox.getZLength() / 2.0 + 1 )) { - - processHumanEntity(entity); - if ((entity.getType() == EntityType.PLAYER && !(craft instanceof SinkingCraft))) { CraftTeleportEntityEvent e = new CraftTeleportEntityEvent(craft, entity); Bukkit.getServer().getPluginManager().callEvent(e); @@ -381,7 +374,7 @@ private void preventsTorpedoRocketsPilots() { } if (craft.getType().getBoolProperty(CraftType.ONLY_MOVE_PLAYERS) - && entity.getType() != EntityType.PRIMED_TNT) { + && entity.getType() != EntityType.TNT) { continue; } @@ -395,30 +388,6 @@ 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 diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/AccessLocationUpdateCommand.java b/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/AccessLocationUpdateCommand.java deleted file mode 100644 index 73491e8b9..000000000 --- a/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/AccessLocationUpdateCommand.java +++ /dev/null @@ -1,48 +0,0 @@ -package net.countercraft.movecraft.mapUpdater.update; - -import net.countercraft.movecraft.Movecraft; -import org.bukkit.Location; -import org.bukkit.inventory.InventoryView; -import org.jetbrains.annotations.NotNull; - -import java.util.Objects; - -public class AccessLocationUpdateCommand extends UpdateCommand { - - private final @NotNull InventoryView inventoryView; - private final @NotNull Location newAccessLocation; - - public AccessLocationUpdateCommand(@NotNull InventoryView inventoryView, @NotNull Location newAccessLocation) { - this.inventoryView = inventoryView; - this.newAccessLocation = newAccessLocation; - } - - public @NotNull InventoryView getInventoryView() { - return inventoryView; - } - - public @NotNull Location getNewAccessLocation() { - return newAccessLocation; - } - - @Override - public void doUpdate() { - Movecraft.getInstance().getWorldHandler().setAccessLocation(inventoryView, newAccessLocation); - } - - @Override - public boolean equals(Object obj) { - if(!(obj instanceof AccessLocationUpdateCommand)) { - return false; - } - AccessLocationUpdateCommand other = (AccessLocationUpdateCommand) obj; - return other.inventoryView.equals(this.inventoryView) && - other.newAccessLocation.equals(this.newAccessLocation); - } - - @Override - public int hashCode() { - return Objects.hash(inventoryView, newAccessLocation); - } - -} diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/ParticleUpdateCommand.java b/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/ParticleUpdateCommand.java index b4f4e7393..4005c9bda 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/ParticleUpdateCommand.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/ParticleUpdateCommand.java @@ -38,7 +38,7 @@ private boolean sendSilhouetteToPlayers() { for (Player p : location.getWorld().getPlayers()) { // this is necessary because signs do not get updated client side correctly without refreshing the chunks, which causes a memory leak in the clients double distSquared = location.distanceSquared(p.getLocation()); if ((distSquared < Settings.SilhouetteViewDistance * Settings.SilhouetteViewDistance) && (distSquared > 32 * 32)) { - p.spawnParticle(Particle.VILLAGER_HAPPY, location, 9); + p.spawnParticle(Particle.HAPPY_VILLAGER, location, 9); } } return true; diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/processing/tasks/detection/DetectionTask.java b/Movecraft/src/main/java/net/countercraft/movecraft/processing/tasks/detection/DetectionTask.java index 1cf1eff8c..99c4229f7 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/processing/tasks/detection/DetectionTask.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/processing/tasks/detection/DetectionTask.java @@ -28,6 +28,7 @@ import net.countercraft.movecraft.processing.tasks.detection.validators.WaterContactValidator; import net.countercraft.movecraft.util.AtomicLocationSet; import net.countercraft.movecraft.util.CollectionUtils; +import net.countercraft.movecraft.util.SupportUtils; import net.countercraft.movecraft.util.Tags; import net.countercraft.movecraft.util.hitboxes.BitmapHitBox; import net.countercraft.movecraft.util.hitboxes.HitBox; @@ -54,7 +55,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Queue; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -356,13 +356,14 @@ public void run() { BlockData blockData = movecraftWorld.getData(probe); Material material = blockData.getMaterial(); - Optional blockDataOptional = SupportUtils.getSupportFace(blockData, directionalDependent); - if (blockDataOptional.isPresent()) { - BlockFace facing = blockDataOptional.get(); - MovecraftLocation relativeLoc = probe.getRelative(facing); + if (directionalDependent.contains(material)) { + BlockFace supportFace = SupportUtils.getSupportFace(blockData); + if (supportFace != null) { + MovecraftLocation relativeLoc = probe.getRelative(supportFace); - if (!legal.contains(relativeLoc)) - continue; + if (!legal.contains(relativeLoc)) + continue; + } } if(!visited.add(probe)) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/processing/tasks/detection/SupportUtils.java b/Movecraft/src/main/java/net/countercraft/movecraft/processing/tasks/detection/SupportUtils.java deleted file mode 100644 index af2decf2e..000000000 --- a/Movecraft/src/main/java/net/countercraft/movecraft/processing/tasks/detection/SupportUtils.java +++ /dev/null @@ -1,47 +0,0 @@ -package net.countercraft.movecraft.processing.tasks.detection; - -import org.bukkit.Material; -import org.bukkit.block.BlockFace; -import org.bukkit.block.data.BlockData; -import org.bukkit.block.data.Directional; -import org.bukkit.block.data.FaceAttachable; -import org.bukkit.block.data.type.Lantern; - -import java.util.EnumSet; -import java.util.Optional; - -/** - * @author Intybyte/Vaan1310 - * An util craft that uses block data to get its supporting block - */ - -public class SupportUtils { - public static Optional getSupportFace(BlockData data, EnumSet directionalDependent) { - - Material material = data.getMaterial(); - if (!directionalDependent.contains(material)) { - return Optional.empty(); - } - - //TODO: Use pattern matched switch statements once we update do Java 21 - //TODO: This should become Hangable instead when we drop support for 1.18 - if (data instanceof Lantern lantern) - return Optional.of(lantern.isHanging() ? BlockFace.UP : BlockFace.DOWN); - - if (data instanceof Directional directional) { - BlockFace normalCase = directional.getFacing().getOppositeFace(); - - if (data instanceof FaceAttachable faceAttachable) { - return switch (faceAttachable.getAttachedFace()) { - case FLOOR -> Optional.of(BlockFace.DOWN); - case WALL -> Optional.of(normalCase); - case CEILING -> Optional.of(BlockFace.UP); - }; - } - - return Optional.of(normalCase); - } - - return Optional.empty(); - } -} diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/processing/tasks/translation/effects/TeleportationEffect.java b/Movecraft/src/main/java/net/countercraft/movecraft/processing/tasks/translation/effects/TeleportationEffect.java index cfc660de0..85c67d332 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/processing/tasks/translation/effects/TeleportationEffect.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/processing/tasks/translation/effects/TeleportationEffect.java @@ -47,7 +47,7 @@ public void run() { eUp.doUpdate(); } else if (!craft.getType().getBoolProperty(CraftType.ONLY_MOVE_PLAYERS) - || entity.getType() == EntityType.PRIMED_TNT) { + || entity.getType() == EntityType.TNT) { CraftTeleportEntityEvent e = new CraftTeleportEntityEvent(craft, entity); Bukkit.getServer().getPluginManager().callEvent(e); if (e.isCancelled()) diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 9c72f6524..77042e3d8 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -6,7 +6,7 @@ plugins { id("buildlogic.java-conventions") } -java.toolchain.languageVersion = JavaLanguageVersion.of(17) +java.toolchain.languageVersion = JavaLanguageVersion.of(21) dependencies { api(libs.io.papermc.paper.paper.api) diff --git a/api/src/main/java/net/countercraft/movecraft/WorldHandler.java b/api/src/main/java/net/countercraft/movecraft/WorldHandler.java index 3b72e569f..e0d19564c 100644 --- a/api/src/main/java/net/countercraft/movecraft/WorldHandler.java +++ b/api/src/main/java/net/countercraft/movecraft/WorldHandler.java @@ -15,10 +15,6 @@ public abstract class WorldHandler { public abstract void translateCraft(@NotNull Craft craft, @NotNull MovecraftLocation newLocation, @NotNull World world); public abstract void setBlockFast(@NotNull Location location, @NotNull BlockData data); public abstract void setBlockFast(@NotNull Location location, @NotNull MovecraftRotation rotation, @NotNull BlockData data); - @Deprecated(forRemoval = true) - public abstract @Nullable Location getAccessLocation(@NotNull InventoryView inventoryView); // Not needed for 1.20+, remove when dropping support for 1.18.2 - @Deprecated(forRemoval = true) - public abstract void setAccessLocation(@NotNull InventoryView inventoryView, @NotNull Location location); // Not needed for 1.20+, remove when dropping support for 1.18.2 public static @NotNull String getPackageName(@NotNull String minecraftVersion) { String[] parts = minecraftVersion.split("\\."); diff --git a/api/src/main/java/net/countercraft/movecraft/support/AsyncChunk.java b/api/src/main/java/net/countercraft/movecraft/support/AsyncChunk.java index 31d411cb2..b82aaa860 100644 --- a/api/src/main/java/net/countercraft/movecraft/support/AsyncChunk.java +++ b/api/src/main/java/net/countercraft/movecraft/support/AsyncChunk.java @@ -18,7 +18,7 @@ public abstract class AsyncChunk { static { Constructor temp = null; try { - Class.forName("net.countercraft.movecraft.support.v1_18.IAsyncChunk"); + Class.forName("net.countercraft.movecraft.support.v1_20.IAsyncChunk"); final Class clazz = Class.forName("net.countercraft.movecraft.support." + WorldHandler.getPackageName(Bukkit.getServer().getMinecraftVersion()) + ".IAsyncChunk"); if (AsyncChunk.class.isAssignableFrom(clazz)) { temp = clazz.getConstructor(Chunk.class); diff --git a/api/src/main/java/net/countercraft/movecraft/support/MovecraftState.java b/api/src/main/java/net/countercraft/movecraft/support/MovecraftState.java index 4bd39a924..b89235665 100644 --- a/api/src/main/java/net/countercraft/movecraft/support/MovecraftState.java +++ b/api/src/main/java/net/countercraft/movecraft/support/MovecraftState.java @@ -8,12 +8,16 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Entity; +import org.bukkit.inventory.ItemStack; import org.bukkit.material.MaterialData; import org.bukkit.metadata.MetadataValue; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; +import java.util.Collection; import java.util.List; public class MovecraftState implements BlockState { @@ -48,6 +52,16 @@ public BlockData getBlockData() { return data; } + @Override + public @NotNull BlockState copy() { + throw new UnsupportedOperationException(); + } + + @Override + public @NotNull BlockState copy(@NotNull Location location) { + throw new UnsupportedOperationException(); + } + @NotNull @Override public Material getType() { @@ -156,6 +170,11 @@ public boolean isCollidable() { throw new UnsupportedOperationException(); } + @Override + public @Unmodifiable @NotNull Collection getDrops(@Nullable ItemStack tool, @Nullable Entity entity) { + throw new UnsupportedOperationException(); + } + @Override public void setMetadata(@NotNull String s, @NotNull MetadataValue metadataValue) { throw new UnsupportedOperationException(); diff --git a/api/src/main/java/net/countercraft/movecraft/util/SupportUtils.java b/api/src/main/java/net/countercraft/movecraft/util/SupportUtils.java new file mode 100644 index 000000000..878407097 --- /dev/null +++ b/api/src/main/java/net/countercraft/movecraft/util/SupportUtils.java @@ -0,0 +1,31 @@ +package net.countercraft.movecraft.util; + +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Directional; +import org.bukkit.block.data.FaceAttachable; +import org.bukkit.block.data.type.Lantern; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class SupportUtils { + @Nullable + public static BlockFace getSupportFace(@NotNull BlockData data) { + if (data instanceof Lantern lantern) + return lantern.isHanging() ? BlockFace.UP : BlockFace.DOWN; + + if (data instanceof Directional directional) { + BlockFace normalCase = directional.getFacing().getOppositeFace(); + + if (data instanceof FaceAttachable faceAttachable) { + return switch (faceAttachable.getAttachedFace()) { + case FLOOR -> BlockFace.DOWN; + case WALL -> normalCase; + case CEILING -> BlockFace.UP; + }; + } + return normalCase; + } + return null; + } +} diff --git a/api/src/main/java/net/countercraft/movecraft/util/Tags.java b/api/src/main/java/net/countercraft/movecraft/util/Tags.java index 399ebb92a..b2d2dc5a5 100644 --- a/api/src/main/java/net/countercraft/movecraft/util/Tags.java +++ b/api/src/main/java/net/countercraft/movecraft/util/Tags.java @@ -15,7 +15,7 @@ public class Tags { public static final EnumSet FLUID = EnumSet.of(Material.WATER, Material.BUBBLE_COLUMN, Material.LAVA); public static final EnumSet CHESTS = EnumSet.of(Material.CHEST, Material.TRAPPED_CHEST, Material.BARREL); public static final EnumSet FURNACES = EnumSet.of(Material.FURNACE, Material.BLAST_FURNACE, Material.SMOKER); - public static final EnumSet SINKING_PASSTHROUGH = EnumSet.of(Material.TALL_GRASS, Material.GRASS); + public static final EnumSet SINKING_PASSTHROUGH = EnumSet.of(Material.TALL_GRASS, Material.SHORT_GRASS); public static final EnumSet FRAGILE_MATERIALS = EnumSet.noneOf(Material.class); public static final EnumSet FALL_THROUGH_BLOCKS = EnumSet.noneOf(Material.class); public static final EnumSet BUCKETS = EnumSet.of(Material.LAVA_BUCKET, Material.WATER_BUCKET, Material.MILK_BUCKET, Material.COD_BUCKET, Material.PUFFERFISH_BUCKET, Material.SALMON_BUCKET, Material.TROPICAL_FISH_BUCKET); diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8ab52af61..6d65f94ec 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ # https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format [versions] -io-papermc-paper-paper-api = "1.18.2-R0.1-SNAPSHOT" +io-papermc-paper-paper-api = "1.20.6-R0.1-SNAPSHOT" it-unimi-dsi-fastutil = "8.5.13" junit-junit = "4.13.2" net-kyori-adventure-api = "4.17.0" diff --git a/settings.gradle.kts b/settings.gradle.kts index 5a43a493e..074b11de7 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -3,13 +3,11 @@ */ rootProject.name = "movecraft-parent" -include(":movecraft-v1_18") include(":movecraft-v1_20") include(":movecraft-v1_21") include(":movecraft-api") include(":movecraft-datapack") include(":movecraft") -project(":movecraft-v1_18").projectDir = file("v1_18") project(":movecraft-v1_20").projectDir = file("v1_20") project(":movecraft-v1_21").projectDir = file("v1_21") project(":movecraft-api").projectDir = file("api") diff --git a/v1_18/build.gradle.kts b/v1_18/build.gradle.kts deleted file mode 100644 index 684c553a1..000000000 --- a/v1_18/build.gradle.kts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * This file was generated by the Gradle 'init' task. - */ - -plugins { - id("buildlogic.java-conventions") - id("io.papermc.paperweight.userdev") -} - -java.toolchain.languageVersion = JavaLanguageVersion.of(17) - -dependencies { - api(project(":movecraft-api")) - paperweight.paperDevBundle("1.18.2-R0.1-SNAPSHOT") -} - -description = "Movecraft-v1_18" -paperweight.reobfArtifactConfiguration = io.papermc.paperweight.userdev.ReobfArtifactConfiguration.REOBF_PRODUCTION diff --git a/v1_18/src/main/java/net/countercraft/movecraft/compat/v1_18/IWorldHandler.java b/v1_18/src/main/java/net/countercraft/movecraft/compat/v1_18/IWorldHandler.java deleted file mode 100644 index 5babf0fe9..000000000 --- a/v1_18/src/main/java/net/countercraft/movecraft/compat/v1_18/IWorldHandler.java +++ /dev/null @@ -1,350 +0,0 @@ -package net.countercraft.movecraft.compat.v1_18; - -import net.countercraft.movecraft.MovecraftLocation; -import net.countercraft.movecraft.MovecraftRotation; -import net.countercraft.movecraft.WorldHandler; -import net.countercraft.movecraft.craft.Craft; -import net.countercraft.movecraft.util.CollectionUtils; -import net.countercraft.movecraft.util.MathUtils; -import net.countercraft.movecraft.util.UnsafeUtils; -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.inventory.ContainerLevelAccess; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.Rotation; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.chunk.LevelChunk; -import net.minecraft.world.level.chunk.LevelChunkSection; -import net.minecraft.world.ticks.LevelChunkTicks; -import net.minecraft.world.ticks.ScheduledTick; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.block.data.BlockData; -import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryView; -import org.bukkit.inventory.InventoryView; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.*; -import java.util.function.Predicate; - -@SuppressWarnings("unused") -public class IWorldHandler extends WorldHandler { - private static final Rotation ROTATION[]; - - static { - ROTATION = new Rotation[3]; - ROTATION[MovecraftRotation.NONE.ordinal()] = Rotation.NONE; - ROTATION[MovecraftRotation.CLOCKWISE.ordinal()] = Rotation.CLOCKWISE_90; - ROTATION[MovecraftRotation.ANTICLOCKWISE.ordinal()] = Rotation.COUNTERCLOCKWISE_90; - } - - private final NextTickProvider tickProvider = new NextTickProvider(); - - public IWorldHandler() { - String version = Bukkit.getServer().getMinecraftVersion(); - if (!version.equals("1.18.2")) - throw new IllegalStateException("Movecraft is not compatible with this version of Minecraft: " + version); - } - - @Override - public void rotateCraft(@NotNull Craft craft, @NotNull MovecraftLocation originPoint, @NotNull MovecraftRotation rotation) { - //******************************************* - //* Step one: Convert to Positions * - //******************************************* - HashMap rotatedPositions = new HashMap<>(); - MovecraftRotation counterRotation = rotation == MovecraftRotation.CLOCKWISE ? MovecraftRotation.ANTICLOCKWISE : MovecraftRotation.CLOCKWISE; - for (MovecraftLocation newLocation : craft.getHitBox()) { - rotatedPositions.put(locationToPosition(MathUtils.rotateVec(counterRotation, newLocation.subtract(originPoint)).add(originPoint)), locationToPosition(newLocation)); - } - //******************************************* - //* Step two: Get the tiles * - //******************************************* - ServerLevel nativeWorld = ((CraftWorld) craft.getWorld()).getHandle(); - List tiles = new ArrayList<>(); - List ticks = new ArrayList<>(); - - //get the tiles - for (BlockPos position : rotatedPositions.keySet()) { - - BlockEntity tile = removeBlockEntity(nativeWorld, position); - if (tile != null) - tiles.add(new TileHolder(tile, position)); - - //get the nextTick to move with the tile - ScheduledTick tickHere = tickProvider.getNextTick(nativeWorld, position); - if (tickHere != null) { - ((LevelChunkTicks) nativeWorld.getChunkAt(position).getBlockTicks()).removeIf( - (Predicate) scheduledTick -> scheduledTick.equals(tickHere)); - ticks.add(new TickHolder(tickHere, position)); - } - } - - //******************************************* - //* Step three: Translate all the blocks * - //******************************************* - // blockedByWater=false means an ocean-going vessel - //TODO: Simplify - //TODO: go by chunks - //TODO: Don't move unnecessary blocks - //get the blocks and rotate them - HashMap blockData = new HashMap<>(); - for (BlockPos position : rotatedPositions.keySet()) { - blockData.put(position, nativeWorld.getBlockState(position).rotate(ROTATION[rotation.ordinal()])); - } - //create the new block - for (Map.Entry entry : blockData.entrySet()) { - setBlockFast(nativeWorld, rotatedPositions.get(entry.getKey()), entry.getValue()); - } - - - //******************************************* - //* Step four: replace all the tiles * - //******************************************* - //TODO: go by chunks - for (TileHolder tileHolder : tiles) { - moveBlockEntity(nativeWorld, rotatedPositions.get(tileHolder.getTilePosition()), tileHolder.getTile()); - } - for (TickHolder tickHolder : ticks) { - final long currentTime = nativeWorld.serverLevelData.getGameTime(); - nativeWorld.getBlockTicks().schedule(new ScheduledTick<>((Block) tickHolder.getTick().type(), rotatedPositions.get(tickHolder.getTick().pos()), tickHolder.getTick().triggerTick() - currentTime, tickHolder.getTick().priority(), tickHolder.getTick().subTickOrder())); - } - - //******************************************* - //* Step five: Destroy the leftovers * - //******************************************* - //TODO: add support for pass-through - Collection deletePositions = CollectionUtils.filter(rotatedPositions.keySet(), rotatedPositions.values()); - for (BlockPos position : deletePositions) { - setBlockFast(nativeWorld, position, Blocks.AIR.defaultBlockState()); - } - } - - @Override - public void translateCraft(@NotNull Craft craft, @NotNull MovecraftLocation displacement, @NotNull org.bukkit.World world) { - //TODO: Add support for rotations - //A craftTranslateCommand should only occur if the craft is moving to a valid position - //******************************************* - //* Step one: Convert to Positions * - //******************************************* - BlockPos translateVector = locationToPosition(displacement); - List positions = new ArrayList<>(craft.getHitBox().size()); - craft.getHitBox().forEach((movecraftLocation) -> positions.add(locationToPosition((movecraftLocation)).subtract(translateVector))); - ServerLevel oldNativeWorld = ((CraftWorld) craft.getWorld()).getHandle(); - ServerLevel nativeWorld = ((CraftWorld) world).getHandle(); - //******************************************* - //* Step two: Get the tiles * - //******************************************* - List tiles = new ArrayList<>(); - List ticks = new ArrayList<>(); - //get the tiles - for (int i = 0, positionsSize = positions.size(); i < positionsSize; i++) { - BlockPos position = positions.get(i); - if (oldNativeWorld.getBlockState(position) == Blocks.AIR.defaultBlockState()) - continue; - //BlockEntity tile = nativeWorld.removeBlockEntity(position); - BlockEntity tile = removeBlockEntity(oldNativeWorld, position); - if (tile != null) - tiles.add(new TileHolder(tile, position)); - - //get the nextTick to move with the tile - ScheduledTick tickHere = tickProvider.getNextTick(oldNativeWorld, position); - if (tickHere != null) { - ((LevelChunkTicks) nativeWorld.getChunkAt(position).getBlockTicks()).removeIf( - (Predicate) scheduledTick -> scheduledTick.equals(tickHere)); - ticks.add(new TickHolder(tickHere, position)); - } - - } - //******************************************* - //* Step three: Translate all the blocks * - //******************************************* - // blockedByWater=false means an ocean-going vessel - //TODO: Simplify - //TODO: go by chunks - //TODO: Don't move unnecessary blocks - //get the blocks and translate the positions - List blockData = new ArrayList<>(); - List newPositions = new ArrayList<>(); - for (int i = 0, positionsSize = positions.size(); i < positionsSize; i++) { - BlockPos position = positions.get(i); - blockData.add(oldNativeWorld.getBlockState(position)); - newPositions.add(position.offset(translateVector)); - } - //create the new block - for (int i = 0, positionSize = newPositions.size(); i < positionSize; i++) { - setBlockFast(nativeWorld, newPositions.get(i), blockData.get(i)); - } - //******************************************* - //* Step four: replace all the tiles * - //******************************************* - //TODO: go by chunks - for (int i = 0, tilesSize = tiles.size(); i < tilesSize; i++) { - TileHolder tileHolder = tiles.get(i); - moveBlockEntity(nativeWorld, tileHolder.getTilePosition().offset(translateVector), tileHolder.getTile()); - } - for (int i = 0, tickSize = ticks.size(); i < tickSize; i++) { - TickHolder tickHolder = ticks.get(i); - final long currentTime = nativeWorld.getGameTime(); - nativeWorld.getBlockTicks().schedule(new ScheduledTick<>((Block) tickHolder.getTick().type(), tickHolder.getTickPosition().offset(translateVector), tickHolder.getTick().triggerTick() - currentTime, tickHolder.getTick().priority(), tickHolder.getTick().subTickOrder())); - } - //******************************************* - //* Step five: Destroy the leftovers * - //******************************************* - List deletePositions = positions; - if (oldNativeWorld == nativeWorld) - deletePositions = CollectionUtils.filter(positions, newPositions); - for (int i = 0, deletePositionsSize = deletePositions.size(); i < deletePositionsSize; i++) { - BlockPos position = deletePositions.get(i); - setBlockFast(oldNativeWorld, position, Blocks.AIR.defaultBlockState()); - } - } - - @Nullable - private BlockEntity removeBlockEntity(@NotNull Level world, @NotNull BlockPos position) { - return world.getChunkAt(position).blockEntities.remove(position); - } - - @NotNull - private BlockPos locationToPosition(@NotNull MovecraftLocation loc) { - return new BlockPos(loc.getX(), loc.getY(), loc.getZ()); - } - - private void setBlockFast(@NotNull Level world, @NotNull BlockPos position, @NotNull BlockState data) { - LevelChunk chunk = world.getChunkAt(position); - int chunkSection = (position.getY() >> 4) - chunk.getMinSection(); - LevelChunkSection section = chunk.getSections()[chunkSection]; - if (section == null) { - // Put a GLASS block to initialize the section. It will be replaced next with the real block. - chunk.setBlockState(position, Blocks.GLASS.defaultBlockState(), false); - section = chunk.getSections()[chunkSection]; - } - if (section.getBlockState(position.getX() & 15, position.getY() & 15, position.getZ() & 15).equals(data)) { - //Block is already of correct type and data, don't overwrite - return; - } - section.setBlockState(position.getX() & 15, position.getY() & 15, position.getZ() & 15, data); - world.sendBlockUpdated(position, data, data, 3); - world.getLightEngine().checkBlock(position); // boolean corresponds to if chunk section empty - chunk.setUnsaved(true); - } - - @Override - public void setBlockFast(@NotNull Location location, @NotNull BlockData data) { - setBlockFast(location, MovecraftRotation.NONE, data); - } - - @Override - public void setBlockFast(@NotNull Location location, @NotNull MovecraftRotation rotation, @NotNull BlockData data) { - BlockState blockData; - if (data instanceof CraftBlockData) { - blockData = ((CraftBlockData) data).getState(); - } - else { - blockData = (BlockState) data; - } - blockData = blockData.rotate(ROTATION[rotation.ordinal()]); - Level world = ((CraftWorld) (location.getWorld())).getHandle(); - BlockPos BlockPos = locationToPosition(MathUtils.bukkit2MovecraftLoc(location)); - setBlockFast(world, BlockPos, blockData); - } - - @Override - public @Nullable Location getAccessLocation(@NotNull InventoryView inventoryView) { - AbstractContainerMenu menu = ((CraftInventoryView) inventoryView).getHandle(); - Field field = UnsafeUtils.getFieldOfType(ContainerLevelAccess.class, menu.getClass()); - if (field != null) { - try { - field.setAccessible(true); - return ((ContainerLevelAccess) field.get(menu)).getLocation(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - return null; - } - - @Override - public void setAccessLocation(@NotNull InventoryView inventoryView, @NotNull Location location) { - if (location.getWorld() == null) - return; - ServerLevel level = ((CraftWorld) location.getWorld()).getHandle(); - BlockPos position = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()); - ContainerLevelAccess access = ContainerLevelAccess.create(level, position); - - AbstractContainerMenu menu = ((CraftInventoryView) inventoryView).getHandle(); - UnsafeUtils.trySetFieldOfType(ContainerLevelAccess.class, menu, access); - } - - private void moveBlockEntity(@NotNull Level nativeWorld, @NotNull BlockPos newPosition, @NotNull BlockEntity tile) { - LevelChunk chunk = nativeWorld.getChunkAt(newPosition); - try { - var positionField = BlockEntity.class.getDeclaredField("o"); // o is obfuscated worldPosition - UnsafeUtils.setField(positionField, tile, newPosition); - } - catch (NoSuchFieldException e) { - e.printStackTrace(); - } - tile.setLevel(nativeWorld); - tile.clearRemoved(); - if (nativeWorld.captureBlockStates) { - nativeWorld.capturedTileEntities.put(newPosition, tile); - return; - } - chunk.setBlockEntity(tile); - chunk.blockEntities.put(newPosition, tile); - } - - private static class TileHolder { - @NotNull - private final BlockEntity tile; - @NotNull - private final BlockPos tilePosition; - - public TileHolder(@NotNull BlockEntity tile, @NotNull BlockPos tilePosition) { - this.tile = tile; - this.tilePosition = tilePosition; - } - - - @NotNull - public BlockEntity getTile() { - return tile; - } - - @NotNull - public BlockPos getTilePosition() { - return tilePosition; - } - } - - private static class TickHolder { - @NotNull - private final ScheduledTick tick; - @NotNull - private final BlockPos tickPosition; - - public TickHolder(@NotNull ScheduledTick tick, @NotNull BlockPos tilePosition) { - this.tick = tick; - this.tickPosition = tilePosition; - } - - - @NotNull - public ScheduledTick getTick() { - return tick; - } - - @NotNull - public BlockPos getTickPosition() { - return tickPosition; - } - } -} \ No newline at end of file diff --git a/v1_18/src/main/java/net/countercraft/movecraft/compat/v1_18/NextTickProvider.java b/v1_18/src/main/java/net/countercraft/movecraft/compat/v1_18/NextTickProvider.java deleted file mode 100644 index 6f06f05ee..000000000 --- a/v1_18/src/main/java/net/countercraft/movecraft/compat/v1_18/NextTickProvider.java +++ /dev/null @@ -1,39 +0,0 @@ -package net.countercraft.movecraft.compat.v1_18; - -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.levelgen.structure.BoundingBox; -import net.minecraft.world.ticks.LevelChunkTicks; -import net.minecraft.world.ticks.ScheduledTick; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; -import java.util.stream.Stream; - -public class NextTickProvider { - - @Nullable - public ScheduledTick getNextTick(@NotNull ServerLevel world, @NotNull BlockPos position){ - LevelChunkTicks tickList = (LevelChunkTicks) world - .getChunk(position) - .getBlockTicks(); - - var box = BoundingBox.encapsulatingPositions(List.of(position)); - if(box.isEmpty()) { - return null; - } - - Stream> ticks = tickList.getAll(); - - for (var iter = ticks.iterator(); iter.hasNext(); ) { - var next = iter.next(); - if (!next.pos().equals(position)) { - continue; - } - return next; - } - return null; - } -} diff --git a/v1_18/src/main/java/net/countercraft/movecraft/support/v1_18/IAsyncChunk.java b/v1_18/src/main/java/net/countercraft/movecraft/support/v1_18/IAsyncChunk.java deleted file mode 100644 index 2cf850445..000000000 --- a/v1_18/src/main/java/net/countercraft/movecraft/support/v1_18/IAsyncChunk.java +++ /dev/null @@ -1,61 +0,0 @@ -package net.countercraft.movecraft.support.v1_18; - -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import net.countercraft.movecraft.MovecraftLocation; -import net.countercraft.movecraft.processing.WorldManager; -import net.countercraft.movecraft.support.AsyncChunk; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.chunk.ChunkAccess; -import org.bukkit.Chunk; -import org.bukkit.Material; -import org.bukkit.block.BlockState; -import org.bukkit.block.data.BlockData; -import org.bukkit.craftbukkit.v1_18_R2.CraftChunk; -import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData; -import org.jetbrains.annotations.NotNull; - -@SuppressWarnings("unused") -public class IAsyncChunk extends AsyncChunk { - - private final @NotNull LoadingCache stateCache = CacheBuilder.newBuilder().maximumSize(1000).build(new CacheLoader<>() { - @Override - public BlockState load(@NotNull MovecraftLocation movecraftLocation) { - var block = chunk.getBlock(movecraftLocation.getX(), movecraftLocation.getY(), movecraftLocation.getZ()); - return WorldManager.INSTANCE.executeMain(() -> block.getState()); - } - }); - - private final ChunkAccess handle; - - public IAsyncChunk(@NotNull Chunk chunk) { - super(chunk); - handle = this.chunk.getHandle(); - } - - @NotNull - @Override - protected CraftChunk adapt(@NotNull org.bukkit.Chunk chunk) { - return (CraftChunk) chunk; - } - - @NotNull - @Override - public BlockState getState(@NotNull MovecraftLocation location) { - return stateCache.getUnchecked(location); - } - - @Override - @NotNull - public Material getType(@NotNull MovecraftLocation location){ - return this.getData(location).getMaterial(); - } - - @Override - @NotNull - public BlockData getData(@NotNull MovecraftLocation location){ - return CraftBlockData.fromData(handle.getBlockState(new BlockPos(location.getX(), location.getY(), location.getZ()))); - } - -} diff --git a/v1_18/src/main/java/net/countercraft/movecraft/support/v1_18/ISmoothTeleport.java b/v1_18/src/main/java/net/countercraft/movecraft/support/v1_18/ISmoothTeleport.java deleted file mode 100644 index be1b7b0be..000000000 --- a/v1_18/src/main/java/net/countercraft/movecraft/support/v1_18/ISmoothTeleport.java +++ /dev/null @@ -1,102 +0,0 @@ -package net.countercraft.movecraft.support.v1_18; - -import net.countercraft.movecraft.SmoothTeleport; -import net.countercraft.movecraft.util.ReflectUtils; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Set; - -/** - * Code derived from code taken with permission from MicleBrick - * https://www.spigotmc.org/threads/teleport-player-smoothly.317416/ - * Used for 1.18.2 - */ -public class ISmoothTeleport extends SmoothTeleport { - private final Set teleportFlags; - - private final Method positionMethod; - private final Method sendMethod; - - private final Constructor vec3Constructor; - private final Constructor packetConstructor; - - private final Field connectionField; - private final Field teleportPosField; - private final Field teleportAwaitField; - private final Field awaitingTeleportTimeField; - private final Field tickCountField; - private final Field yawField; - private final Field pitchField; - - private static @NotNull Class getNmClass(String name) throws ClassNotFoundException { - return Class.forName("net.minecraft." + name); - } - - private void sendPacket(Object packet, Player p) { - try { - Object handle = ReflectUtils.getHandle(p); - Object pConnection = connectionField.get(handle); - sendMethod.invoke(pConnection, packet); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - public ISmoothTeleport() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException { - Class packetClass = getNmClass("network.protocol.Packet"); - Class positionPacketClass = getNmClass("network.protocol.game.PacketPlayOutPosition"); // ClientboundPlayerPositionPacket - Class entityClass = getNmClass("world.entity.Entity"); - Class playerClass = getNmClass("server.level.EntityPlayer"); // ServerPlayer - Class connectionClass = getNmClass("server.network.PlayerConnection"); // ServerGamePacketListenerImpl - Class vectorClass = getNmClass("world.phys.Vec3D"); // Vec3 - - Object[] flags = getNmClass("network.protocol.game.PacketPlayOutPosition$EnumPlayerTeleportFlags").getEnumConstants(); // $RelativeArgument - teleportFlags = Set.of(flags[4], flags[3]); // X_ROT, Y_ROT - - positionMethod = entityClass.getDeclaredMethod("a", Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE); // absMoveTo - sendMethod = connectionClass.getMethod("a", packetClass); // send - - vec3Constructor = vectorClass.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE); - packetConstructor = positionPacketClass.getConstructor(Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE, Set.class, Integer.TYPE, Boolean.TYPE); - - connectionField = ReflectUtils.getField(playerClass, "b"); // connection - teleportPosField = ReflectUtils.getField(connectionClass, "y"); // awaitingPositionFromClient - teleportAwaitField = ReflectUtils.getField(connectionClass, "z"); // awaitingTeleport - awaitingTeleportTimeField = ReflectUtils.getField(connectionClass, "A"); // awaitingTeleportTime - tickCountField = ReflectUtils.getField(connectionClass, "f"); // tickCount - yawField = ReflectUtils.getField(entityClass, "aB"); // xRot - pitchField = ReflectUtils.getField(entityClass, "aA"); // yRot - } - - public void teleport(@NotNull Player player, @NotNull Location location) { - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yawChange = location.getYaw() - player.getLocation().getYaw(); - float pitchChange = player.getLocation().getPitch() - location.getPitch(); - Object handle = ReflectUtils.getHandle(player); - try { - positionMethod.invoke(handle, x, y, z, yawField.get(handle), pitchField.get(handle)); - Object connection = connectionField.get(handle); - teleportPosField.set(connection, vec3Constructor.newInstance(x, y, z)); - int teleportAwait = teleportAwaitField.getInt(connection) + 1; - if (teleportAwait == Integer.MAX_VALUE) - teleportAwait = 0; - teleportAwaitField.setInt(connection, teleportAwait); - awaitingTeleportTimeField.set(connection, tickCountField.get(connection)); - - Object packet = packetConstructor.newInstance(x, y, z, yawChange, pitchChange, teleportFlags, teleportAwait, false); - sendPacket(packet, player); - } - catch (IllegalAccessException | InvocationTargetException | InstantiationException e) { - e.printStackTrace(); - } - } -} diff --git a/v1_20/src/main/java/net/countercraft/movecraft/compat/v1_20/IWorldHandler.java b/v1_20/src/main/java/net/countercraft/movecraft/compat/v1_20/IWorldHandler.java index cd2a5565a..74ab3bdf8 100644 --- a/v1_20/src/main/java/net/countercraft/movecraft/compat/v1_20/IWorldHandler.java +++ b/v1_20/src/main/java/net/countercraft/movecraft/compat/v1_20/IWorldHandler.java @@ -260,17 +260,6 @@ public void setBlockFast(@NotNull Location location, @NotNull MovecraftRotation setBlockFast(world, BlockPos, blockData); } - @Override - public @Nullable Location getAccessLocation(@NotNull InventoryView inventoryView) { - // Not needed for 1.20+, remove when dropping support for 1.18.2 - return null; - } - - @Override - public void setAccessLocation(@NotNull InventoryView inventoryView, @NotNull Location location) { - // Not needed for 1.20+, remove when dropping support for 1.18.2 - } - private void moveBlockEntity(@NotNull Level nativeWorld, @NotNull BlockPos newPosition, @NotNull BlockEntity tile) { LevelChunk chunk = nativeWorld.getChunkAt(newPosition); try { diff --git a/v1_21/src/main/java/net/countercraft/movecraft/compat/v1_21/IWorldHandler.java b/v1_21/src/main/java/net/countercraft/movecraft/compat/v1_21/IWorldHandler.java index 30f1e8182..3a5321ffb 100644 --- a/v1_21/src/main/java/net/countercraft/movecraft/compat/v1_21/IWorldHandler.java +++ b/v1_21/src/main/java/net/countercraft/movecraft/compat/v1_21/IWorldHandler.java @@ -255,17 +255,6 @@ public void setBlockFast(@NotNull Location location, @NotNull MovecraftRotation setBlockFast(world, BlockPos, blockData); } - @Override - public @Nullable Location getAccessLocation(@NotNull InventoryView inventoryView) { - // Not needed for 1.20+, remove when dropping support for 1.18.2 - return null; - } - - @Override - public void setAccessLocation(@NotNull InventoryView inventoryView, @NotNull Location location) { - // Not needed for 1.20+, remove when dropping support for 1.18.2 - } - private void moveBlockEntity(@NotNull Level nativeWorld, @NotNull BlockPos newPosition, @NotNull BlockEntity tile) { LevelChunk chunk = nativeWorld.getChunkAt(newPosition); try {