mirror of https://github.com/PaperMC/Paper.git
Split Position from Location type hierarchy
This commit is contained in:
parent
33039cd82c
commit
5d35f622db
|
@ -0,0 +1,51 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||
Date: Tue, 19 Dec 2023 23:39:49 -0800
|
||||
Subject: [PATCH] Split Position from Location type hierarchy
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/Location.java b/src/main/java/org/bukkit/Location.java
|
||||
index c6049747fc286acb4e8053901fcc517e5170afa2..4c86700438276c56f75d1904d687e3fdf83ef2d4 100644
|
||||
--- a/src/main/java/org/bukkit/Location.java
|
||||
+++ b/src/main/java/org/bukkit/Location.java
|
||||
@@ -30,7 +30,7 @@ import org.bukkit.entity.Player;
|
||||
* magnitude than 360 are valid, but may be normalized to any other equivalent
|
||||
* representation by the implementation.
|
||||
*/
|
||||
-public class Location implements Cloneable, ConfigurationSerializable, io.papermc.paper.math.FinePosition { // Paper
|
||||
+public class Location implements Cloneable, ConfigurationSerializable/*, io.papermc.paper.math.FinePosition*/ { // Paper
|
||||
private Reference<World> world;
|
||||
private double x;
|
||||
private double y;
|
||||
@@ -1172,29 +1172,8 @@ public class Location implements Cloneable, ConfigurationSerializable, io.paperm
|
||||
}
|
||||
|
||||
// Paper - add Position
|
||||
- @Override
|
||||
- public double x() {
|
||||
- return this.getX();
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public double y() {
|
||||
- return this.getY();
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public double z() {
|
||||
- return this.getZ();
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public boolean isFinite() {
|
||||
- return io.papermc.paper.math.FinePosition.super.isFinite() && Float.isFinite(this.getYaw()) && Float.isFinite(this.getPitch());
|
||||
- }
|
||||
-
|
||||
- @Override
|
||||
- public @NotNull Location toLocation(@NotNull World world) {
|
||||
- return new Location(world, this.x(), this.y(), this.z(), this.getYaw(), this.getPitch());
|
||||
+ public io.papermc.paper.math.@NotNull Position asPosition() {
|
||||
+ return io.papermc.paper.math.Position.fine(this);
|
||||
}
|
||||
// Paper end
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||
Date: Thu, 21 Dec 2023 19:11:23 -0800
|
||||
Subject: [PATCH] adapt to Position change
|
||||
|
||||
will be squashed into original patches
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/event/world/StructuresLocateEvent.java b/src/main/java/io/papermc/paper/event/world/StructuresLocateEvent.java
|
||||
index 582af444b058708638683e7d6f9b79685c04c061..1008362e679341b00db546798feed8f673860d6c 100644
|
||||
--- a/src/main/java/io/papermc/paper/event/world/StructuresLocateEvent.java
|
||||
+++ b/src/main/java/io/papermc/paper/event/world/StructuresLocateEvent.java
|
||||
@@ -196,7 +196,7 @@ public class StructuresLocateEvent extends WorldEvent implements Cancellable {
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public Result(final @NotNull Location position, @NotNull ConfiguredStructure configuredStructure) {
|
||||
- this(position, configuredStructure.toModern());
|
||||
+ this(position.asPosition(), configuredStructure.toModern());
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
diff --git a/src/main/java/org/bukkit/RegionAccessor.java b/src/main/java/org/bukkit/RegionAccessor.java
|
||||
index eb33e8e671972aa308ad75a7ce9aa9ac526f470f..292f40d4ab849f786d9034dd4d8e4f829e439f97 100644
|
||||
--- a/src/main/java/org/bukkit/RegionAccessor.java
|
||||
+++ b/src/main/java/org/bukkit/RegionAccessor.java
|
||||
@@ -133,7 +133,7 @@ public interface RegionAccessor extends Keyed { // Paper
|
||||
*/
|
||||
@NotNull
|
||||
default io.papermc.paper.block.fluid.FluidData getFluidData(@NotNull Location location) {
|
||||
- return getFluidData(location.blockX(), location.blockY(), location.blockZ());
|
||||
+ return getFluidData(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
}
|
||||
// Paper end
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/block/Sign.java b/src/main/java/org/bukkit/block/Sign.java
|
||||
index 7983ccb54f5f358dea1ffb530b9cc5bd716fb9b1..4f1139bd7cd82dc0689fdfda1b817458ca36b2f3 100644
|
||||
--- a/src/main/java/org/bukkit/block/Sign.java
|
||||
+++ b/src/main/java/org/bukkit/block/Sign.java
|
||||
@@ -195,7 +195,7 @@ public interface Sign extends TileState, Colorable {
|
||||
* @return the side it is facing
|
||||
*/
|
||||
default @NotNull Side getInteractableSideFor(org.bukkit.entity.@NotNull Entity entity) {
|
||||
- return this.getInteractableSideFor(entity.getLocation());
|
||||
+ return this.getInteractableSideFor(entity.getLocation().asPosition());
|
||||
}
|
||||
|
||||
/**
|
|
@ -0,0 +1,101 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||
Date: Tue, 19 Dec 2023 23:40:01 -0800
|
||||
Subject: [PATCH] Split Position from Location type hierarchy
|
||||
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/PaperClassloaderBytecodeModifier.java b/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/PaperClassloaderBytecodeModifier.java
|
||||
index 9bd330f3a3afcb8f693920517a5ad29c3c18098b..bde91e90f0b55a9de5d3557f72e4ba55276d4aeb 100644
|
||||
--- a/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/PaperClassloaderBytecodeModifier.java
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/PaperClassloaderBytecodeModifier.java
|
||||
@@ -3,6 +3,7 @@ package io.papermc.paper.plugin.entrypoint.classloader.bytecode;
|
||||
import com.google.common.collect.Iterators;
|
||||
import io.papermc.paper.plugin.configuration.PluginMeta;
|
||||
import io.papermc.paper.plugin.entrypoint.classloader.ClassloaderBytecodeModifier;
|
||||
+import io.papermc.paper.plugin.entrypoint.classloader.bytecode.versions.API_1_20_4;
|
||||
import io.papermc.paper.plugin.provider.configuration.serializer.constraints.PluginConfigConstraints;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -15,6 +16,7 @@ import org.objectweb.asm.Opcodes;
|
||||
public class PaperClassloaderBytecodeModifier implements ClassloaderBytecodeModifier {
|
||||
|
||||
private static final Map<String, List<ModifierFactory>> MODIFIERS = Util.make(new LinkedHashMap<>(), map -> {
|
||||
+ map.put("1.20.4", List.of(API_1_20_4::new));
|
||||
});
|
||||
|
||||
private final Map<String, List<VersionedClassloaderBytecodeModifier>> constructedModifiers = MODIFIERS.entrySet().stream()
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/versions/API_1_20_4.java b/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/versions/API_1_20_4.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..4e5bdeede4859fd3a15db367d90a246239f21ede
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/versions/API_1_20_4.java
|
||||
@@ -0,0 +1,69 @@
|
||||
+package io.papermc.paper.plugin.entrypoint.classloader.bytecode.versions;
|
||||
+
|
||||
+import io.papermc.asm.rules.RewriteRule;
|
||||
+import io.papermc.asm.rules.builder.ConfiguredRuleFactory;
|
||||
+import io.papermc.paper.event.world.StructuresLocateEvent;
|
||||
+import io.papermc.paper.math.Position;
|
||||
+import io.papermc.paper.plugin.entrypoint.classloader.bytecode.VersionedClassloaderBytecodeModifier;
|
||||
+import java.lang.constant.ClassDesc;
|
||||
+import java.lang.reflect.Method;
|
||||
+import java.util.Set;
|
||||
+import org.bukkit.Bukkit;
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.Server;
|
||||
+import org.bukkit.World;
|
||||
+import org.bukkit.block.SculkCatalyst;
|
||||
+import org.bukkit.block.Sign;
|
||||
+import org.bukkit.boss.DragonBattle;
|
||||
+import org.bukkit.entity.Player;
|
||||
+
|
||||
+import static io.papermc.asm.rules.RewriteRule.chain;
|
||||
+import static io.papermc.asm.util.DescriptorUtils.desc;
|
||||
+
|
||||
+public class API_1_20_4 extends VersionedClassloaderBytecodeModifier {
|
||||
+
|
||||
+ private static final ClassDesc POSITION = desc(Position.class);
|
||||
+
|
||||
+ private static final Method POSITION_FUZZY_HANDLER;
|
||||
+
|
||||
+ static {
|
||||
+ try {
|
||||
+ POSITION_FUZZY_HANDLER = API_1_20_4.class.getDeclaredMethod("toPos", Object.class);
|
||||
+ } catch (final NoSuchMethodException throwable) {
|
||||
+ throw new RuntimeException(throwable);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ // for removing FinePosition from superclasses of Location
|
||||
+ private static ConfiguredRuleFactory.Factory locationSplit(final String... methods) {
|
||||
+ return r -> r.changeParamFuzzy(Position.class, POSITION_FUZZY_HANDLER, m -> m.names(methods).containsParam(POSITION));
|
||||
+ }
|
||||
+
|
||||
+ public API_1_20_4(final int api) {
|
||||
+ super(api);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ protected RewriteRule createRule() {
|
||||
+ return chain(
|
||||
+ this.createSplitRule()
|
||||
+ );
|
||||
+ }
|
||||
+
|
||||
+ private RewriteRule createSplitRule() {
|
||||
+ // For all methods with Position parameters prior to the removal of Position from Location type hierarchy
|
||||
+ return chain(
|
||||
+ this.forOwners(Set.of(Bukkit.class, Server.class), locationSplit("isOwnedByCurrentRegion")),
|
||||
+ this.forOwner(World.class, locationSplit("hasStructureAt", "isPositionLoaded", "rayTraceEntities", "rayTraceBlocks", "rayTrace")),
|
||||
+ this.forOwner(SculkCatalyst.class, locationSplit("bloom")),
|
||||
+ this.forOwner(Sign.class, locationSplit("getInteractableSideFor")),
|
||||
+ this.forOwner(DragonBattle.class, locationSplit("spawnNewGateway")),
|
||||
+ this.forOwner(Player.class, locationSplit("lookAt")),
|
||||
+ this.forOwner(StructuresLocateEvent.Result.class, locationSplit("<init>"))
|
||||
+ );
|
||||
+ }
|
||||
+
|
||||
+ public static Position toPos(final Object object) { // for split rule
|
||||
+ return object instanceof final Location loc ? loc.asPosition() : (Position) object;
|
||||
+ }
|
||||
+}
|
|
@ -0,0 +1,68 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||
Date: Thu, 21 Dec 2023 19:11:06 -0800
|
||||
Subject: [PATCH] adapt to Position change
|
||||
|
||||
will be squashed into original patches
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/block/fluid/PaperFluidData.java b/src/main/java/io/papermc/paper/block/fluid/PaperFluidData.java
|
||||
index 479bc32241ebadf8bbc1080b601f61391ad37fa4..8830b6a8b10845a8bc4f751d7ec6d2987b0fa580 100644
|
||||
--- a/src/main/java/io/papermc/paper/block/fluid/PaperFluidData.java
|
||||
+++ b/src/main/java/io/papermc/paper/block/fluid/PaperFluidData.java
|
||||
@@ -65,7 +65,7 @@ public class PaperFluidData implements FluidData {
|
||||
@Override
|
||||
public float computeHeight(@NotNull final Location location) {
|
||||
Preconditions.checkArgument(location.getWorld() != null, "Cannot compute height on world-less location");
|
||||
- return this.state.getHeight(((CraftWorld) location.getWorld()).getHandle(), MCUtil.toBlockPos(location));
|
||||
+ return this.state.getHeight(((CraftWorld) location.getWorld()).getHandle(), MCUtil.toBlockPosition(location));
|
||||
}
|
||||
|
||||
@Override
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||
index bfb178c69026e9759e9afaebb9da141b62d1f144..82bab25ae81078574bad2b259cdee7a4f3423727 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||
@@ -1202,7 +1202,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
@Override
|
||||
public RayTraceResult rayTraceBlocks(Location start, Vector direction, double maxDistance, FluidCollisionMode fluidCollisionMode, boolean ignorePassableBlocks) {
|
||||
// Paper start - Add predicate for blocks when raytracing
|
||||
- return this.rayTraceBlocks(start, direction, maxDistance, fluidCollisionMode, ignorePassableBlocks, null);
|
||||
+ return this.rayTraceBlocks(start.asPosition(), direction, maxDistance, fluidCollisionMode, ignorePassableBlocks, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1233,7 +1233,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
@Override
|
||||
public RayTraceResult rayTrace(Location start, Vector direction, double maxDistance, FluidCollisionMode fluidCollisionMode, boolean ignorePassableBlocks, double raySize, Predicate<? super Entity> filter) {
|
||||
// Paper start - Add predicate for blocks when raytracing
|
||||
- return this.rayTrace(start, direction, maxDistance, fluidCollisionMode, ignorePassableBlocks, raySize, filter, null);
|
||||
+ return this.rayTrace(start.asPosition(), direction, maxDistance, fluidCollisionMode, ignorePassableBlocks, raySize, filter, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderDragon.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderDragon.java
|
||||
index 7b7b89e67d53ed70efae714192c5fa32977f3d9c..594fdeb10d384b0fbe967693b93e83c5c3847e09 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderDragon.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEnderDragon.java
|
||||
@@ -87,7 +87,7 @@ public class CraftEnderDragon extends CraftMob implements EnderDragon, CraftEnem
|
||||
this.getHandle().setPodium(null);
|
||||
} else {
|
||||
org.apache.commons.lang.Validate.isTrue(location.getWorld() == null || location.getWorld().equals(getWorld()), "You cannot set a podium in a different world to where the dragon is");
|
||||
- this.getHandle().setPodium(io.papermc.paper.util.MCUtil.toBlockPos(location));
|
||||
+ this.getHandle().setPodium(io.papermc.paper.util.MCUtil.toBlockPos(location.asPosition()));
|
||||
}
|
||||
}
|
||||
// Paper end - Allow changing the EnderDragon podium
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||||
index 616d2e479d91673695ade0db151a0099b568904f..a3c5a97635776951a709afa833f2498ddaf8931c 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||||
@@ -1251,7 +1251,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
org.bukkit.util.Vector direction = targetLocation.getDirection();
|
||||
direction.multiply(9999999); // We need to move the target block.. FAR out
|
||||
targetLocation.add(direction);
|
||||
- this.lookAt(targetLocation, io.papermc.paper.entity.LookAnchor.EYES);
|
||||
+ this.lookAt(targetLocation.asPosition(), io.papermc.paper.entity.LookAnchor.EYES);
|
||||
// Paper end
|
||||
}
|
||||
|
|
@ -1,8 +1,13 @@
|
|||
version = "1.0.0-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":paper-api"))
|
||||
compileOnly(project(":paper-mojangapi"))
|
||||
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
|
||||
// compileOnly(project(":paper-api"))
|
||||
// compileOnly(project(":paper-mojangapi"))
|
||||
}
|
||||
|
||||
tasks.processResources {
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
package io.papermc.testplugin;
|
||||
|
||||
import io.papermc.paper.event.player.ChatEvent;
|
||||
import io.papermc.paper.event.world.StructuresLocateEvent;
|
||||
import java.util.function.BiFunction;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.generator.structure.Structure;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class TestPlugin extends JavaPlugin implements Listener {
|
||||
|
@ -8,5 +15,19 @@ public final class TestPlugin extends JavaPlugin implements Listener {
|
|||
@Override
|
||||
public void onEnable() {
|
||||
this.getServer().getPluginManager().registerEvents(this, this);
|
||||
this.test(new Location(null, 0, 0, 0));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChat(ChatEvent event) {
|
||||
this.test(event.getPlayer().getLocation());
|
||||
}
|
||||
|
||||
private void test(Location loc) {
|
||||
final BiFunction<Location, Structure, StructuresLocateEvent.Result> biFunction = StructuresLocateEvent.Result::new;
|
||||
final StructuresLocateEvent.Result resultByConstructor = new StructuresLocateEvent.Result(loc, Structure.FORTRESS);
|
||||
System.out.println(resultByConstructor.position());
|
||||
final StructuresLocateEvent.Result result = biFunction.apply(loc, Structure.FORTRESS);
|
||||
System.out.println(result.position());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue