-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split Position from Location type hierarchy
- Loading branch information
1 parent
77180b3
commit d75b6c5
Showing
6 changed files
with
273 additions
and
2 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
patches/api/0449-Split-Position-from-Location-type-hierarchy.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Jake Potrebic <[email protected]> | ||
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 9bbd928f7d513ca317cd27beffa61e5111f5ffb0..f42663b3b61c8346029b855eec51694581671b48 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Jake Potrebic <[email protected]> | ||
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 4342b162f69b6509503e9772ddd2c5ac6659545a..fdb2944f75728d8dcb6a5085db14e1c0cadd2f6b 100644 | ||
--- a/src/main/java/io/papermc/paper/event/world/StructuresLocateEvent.java | ||
+++ b/src/main/java/io/papermc/paper/event/world/StructuresLocateEvent.java | ||
@@ -193,7 +193,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/block/Sign.java b/src/main/java/org/bukkit/block/Sign.java | ||
index 94e8f319fe0413a10496d7e5bba70633054765f4..5de0959c9b554c821ef6cccdfe6f7350713ccdf0 100644 | ||
--- a/src/main/java/org/bukkit/block/Sign.java | ||
+++ b/src/main/java/org/bukkit/block/Sign.java | ||
@@ -176,7 +176,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()); | ||
} | ||
|
||
/** |
105 changes: 105 additions & 0 deletions
105
patches/server/1053-Split-Position-from-Location-type-hierarchy.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Jake Potrebic <[email protected]> | ||
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 7e4b3c16fac04e9bbd60a070e1ef0888686a0ca3..a4076d6e7bd6174599c1a923407beabecc36f2e3 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; | ||
@@ -14,6 +15,7 @@ import org.objectweb.asm.Opcodes; | ||
public class PaperClassloaderBytecodeModifier implements ClassloaderBytecodeModifier { | ||
|
||
static final Map<String, List<ModifierFactory>> MODIFIERS = Util.make(new LinkedHashMap<>(), map -> { | ||
+ map.put("1.20.4", List.of(API_1_20_4::new)); | ||
}); | ||
|
||
@Override | ||
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..4f5582274fb10342f1229fb98636b42e9f01829f | ||
--- /dev/null | ||
+++ b/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/bytecode/versions/API_1_20_4.java | ||
@@ -0,0 +1,73 @@ | ||
+package io.papermc.paper.plugin.entrypoint.classloader.bytecode.versions; | ||
+ | ||
+import com.google.common.base.Suppliers; | ||
+import io.papermc.paper.event.world.StructuresLocateEvent; | ||
+import io.papermc.paper.math.Position; | ||
+import io.papermc.paper.plugin.entrypoint.classloader.bytecode.VersionedClassloaderBytecodeModifier; | ||
+import io.papermc.paper.plugin.entrypoint.classloader.bytecode.rules.RewriteRule; | ||
+import io.papermc.paper.plugin.entrypoint.classloader.bytecode.rules.builder.RuleFactory; | ||
+import java.lang.constant.ClassDesc; | ||
+import java.lang.reflect.Method; | ||
+import java.util.Set; | ||
+import java.util.function.Consumer; | ||
+import java.util.function.Supplier; | ||
+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.paper.plugin.entrypoint.classloader.bytecode.rules.RewriteRule.chain; | ||
+import static io.papermc.paper.plugin.entrypoint.classloader.bytecode.rules.RewriteRule.forOwner; | ||
+import static io.papermc.paper.plugin.entrypoint.classloader.bytecode.rules.RewriteRule.forOwners; | ||
+ | ||
+public class API_1_20_4 extends VersionedClassloaderBytecodeModifier { | ||
+ | ||
+ private static final ClassDesc POSITION = ClassDesc.of(Position.class.getName()); | ||
+ | ||
+ 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); | ||
+ } | ||
+ } | ||
+ | ||
+ private static final Supplier<Class<?>> API_1_20_4_DELEGATES = Suppliers.memoize(() -> defineGeneratedDelegates(API_1_20_4.class, API_1_20_4.FINAL_RULE)); | ||
+ private static final RewriteRule FINAL_RULE = chain(createSplitRule()); | ||
+ | ||
+ // for removing FinePosition from superclasses of Location | ||
+ private static Consumer<RuleFactory> locationSplit(final String...methods) { | ||
+ return r -> r.changeParamFuzzy(API_1_20_4_DELEGATES, Position.class, POSITION_FUZZY_HANDLER, m -> m.names(methods).containsParam(POSITION)); | ||
+ } | ||
+ | ||
+ public API_1_20_4(final int api) { | ||
+ super(api); | ||
+ } | ||
+ | ||
+ @Override | ||
+ protected RewriteRule rootRule() { | ||
+ return FINAL_RULE; | ||
+ } | ||
+ | ||
+ private static RewriteRule createSplitRule() { | ||
+ // For all methods with Position parameters prior to the removal of Position from Location type hierarchy | ||
+ return chain( | ||
+ forOwners(Set.of(Bukkit.class, Server.class), locationSplit("isOwnedByCurrentRegion")), | ||
+ forOwner(World.class, locationSplit("rayTraceEntities", "rayTraceBlocks", "rayTrace")), | ||
+ forOwner(SculkCatalyst.class, locationSplit("bloom")), | ||
+ forOwner(Sign.class, locationSplit("getInteractableSideFor")), | ||
+ forOwner(DragonBattle.class, locationSplit("spawnNewGateway")), | ||
+ forOwner(Player.class, locationSplit("lookAt")), | ||
+ 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; | ||
+ } | ||
+} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Jake Potrebic <[email protected]> | ||
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/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java | ||
index e1fad381b861471a17529c246bb8a4a9c7646420..401ad3bd8b33a6821368d15503bb709175ede47e 100644 | ||
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java | ||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java | ||
@@ -1191,7 +1191,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { | ||
@Override | ||
public RayTraceResult rayTraceBlocks(Location start, Vector direction, double maxDistance, FluidCollisionMode fluidCollisionMode, boolean ignorePassableBlocks) { | ||
// Paper start | ||
- return this.rayTraceBlocks(start, direction, maxDistance, fluidCollisionMode, ignorePassableBlocks, null); | ||
+ return this.rayTraceBlocks(start.asPosition(), direction, maxDistance, fluidCollisionMode, ignorePassableBlocks, null); | ||
} | ||
|
||
@Override | ||
@@ -1222,7 +1222,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 | ||
- 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 6eae6efa35a1ccc224e2f311e25ecf13e8647ec8..049adcf0dd7df6616965b035b40b216bd0cf7944 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 | ||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java | ||
index 3be5e4df190bff0087c8450b16e4e37b07169040..8b9cda921d8e7879ea97865b1eb25e7d0b26499f 100644 | ||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java | ||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java | ||
@@ -1263,7 +1263,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 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
test-plugin/src/main/java/io/papermc/testplugin/TestPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,34 @@ | ||
package io.papermc.testplugin; | ||
|
||
import io.papermc.paper.event.player.ChatEvent; | ||
import io.papermc.paper.event.world.StructuresLocateEvent; | ||
import io.papermc.paper.math.Position; | ||
import java.util.function.BiFunction; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.Chunk; | ||
import org.bukkit.FluidCollisionMode; | ||
import org.bukkit.Location; | ||
import org.bukkit.World; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.generator.structure.Structure; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.bukkit.util.Vector; | ||
|
||
public final class TestPlugin extends JavaPlugin implements Listener { | ||
|
||
@Override | ||
public void onEnable() { | ||
this.getServer().getPluginManager().registerEvents(this, this); | ||
} | ||
|
||
@EventHandler | ||
public void onChat(ChatEvent event) { | ||
final BiFunction<Location, Structure, StructuresLocateEvent.Result> biFunction = StructuresLocateEvent.Result::new; | ||
final StructuresLocateEvent.Result resultByConstructor = new StructuresLocateEvent.Result(event.getPlayer().getLocation(), Structure.FORTRESS); | ||
System.out.println(resultByConstructor.position()); | ||
final StructuresLocateEvent.Result result = biFunction.apply(event.getPlayer().getLocation(), Structure.FORTRESS); | ||
System.out.println(result.position()); | ||
} | ||
} |