mirror of
https://github.com/PaperMC/Paper.git
synced 2025-02-06 15:41:38 +01:00
Move some methods to RegionAccessor (#7635)
This commit is contained in:
parent
bcde5dbffe
commit
943212b776
@ -8,7 +8,7 @@ diff --git a/src/main/java/org/bukkit/RegionAccessor.java b/src/main/java/org/bu
|
|||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/org/bukkit/RegionAccessor.java
|
--- a/src/main/java/org/bukkit/RegionAccessor.java
|
||||||
+++ b/src/main/java/org/bukkit/RegionAccessor.java
|
+++ b/src/main/java/org/bukkit/RegionAccessor.java
|
||||||
@@ -0,0 +0,0 @@ public interface RegionAccessor {
|
@@ -0,0 +0,0 @@ public interface RegionAccessor extends Keyed { // Paper
|
||||||
*
|
*
|
||||||
* @param location the location of the biome
|
* @param location the location of the biome
|
||||||
* @return Biome at the given location
|
* @return Biome at the given location
|
||||||
@ -16,7 +16,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
Biome getBiome(@NotNull Location location);
|
Biome getBiome(@NotNull Location location);
|
||||||
@@ -0,0 +0,0 @@ public interface RegionAccessor {
|
@@ -0,0 +0,0 @@ public interface RegionAccessor extends Keyed { // Paper
|
||||||
* @param y Y-coordinate of the block
|
* @param y Y-coordinate of the block
|
||||||
* @param z Z-coordinate of the block
|
* @param z Z-coordinate of the block
|
||||||
* @return Biome at the given coordinates
|
* @return Biome at the given coordinates
|
||||||
|
@ -46,20 +46,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ return BY_DAY.get(day % 8L);
|
+ return BY_DAY.get(day % 8L);
|
||||||
+ }
|
+ }
|
||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
|
diff --git a/src/main/java/org/bukkit/RegionAccessor.java b/src/main/java/org/bukkit/RegionAccessor.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/org/bukkit/World.java
|
--- a/src/main/java/org/bukkit/RegionAccessor.java
|
||||||
+++ b/src/main/java/org/bukkit/World.java
|
+++ b/src/main/java/org/bukkit/RegionAccessor.java
|
||||||
@@ -0,0 +0,0 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
@@ -0,0 +0,0 @@ public interface RegionAccessor {
|
||||||
* @return The amount of Players in this world
|
|
||||||
*/
|
*/
|
||||||
int getPlayerCount();
|
@NotNull
|
||||||
|
public <T extends Entity> T spawn(@NotNull Location location, @NotNull Class<T> clazz, boolean randomizeData, @Nullable Consumer<T> function) throws IllegalArgumentException;
|
||||||
+
|
+
|
||||||
|
+ // Paper start
|
||||||
+ /**
|
+ /**
|
||||||
+ * @return the current moon phase at the current time in the world
|
+ * @return the current moon phase at the current time in the world
|
||||||
+ */
|
+ */
|
||||||
+ @NotNull
|
+ @NotNull
|
||||||
+ io.papermc.paper.world.MoonPhase getMoonPhase();
|
+ io.papermc.paper.world.MoonPhase getMoonPhase();
|
||||||
// Paper end
|
+ // Paper end
|
||||||
|
}
|
||||||
/**
|
|
||||||
|
@ -4,14 +4,14 @@ Date: Sat, 29 May 2021 14:33:18 -0500
|
|||||||
Subject: [PATCH] Add more line of sight methods
|
Subject: [PATCH] Add more line of sight methods
|
||||||
|
|
||||||
|
|
||||||
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
|
diff --git a/src/main/java/org/bukkit/RegionAccessor.java b/src/main/java/org/bukkit/RegionAccessor.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/org/bukkit/World.java
|
--- a/src/main/java/org/bukkit/RegionAccessor.java
|
||||||
+++ b/src/main/java/org/bukkit/World.java
|
+++ b/src/main/java/org/bukkit/RegionAccessor.java
|
||||||
@@ -0,0 +0,0 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
@@ -0,0 +0,0 @@ public interface RegionAccessor extends Keyed { // Paper
|
||||||
*/
|
|
||||||
@NotNull
|
@NotNull
|
||||||
io.papermc.paper.world.MoonPhase getMoonPhase();
|
@Override
|
||||||
|
NamespacedKey getKey();
|
||||||
+
|
+
|
||||||
+ /**
|
+ /**
|
||||||
+ * Tell whether a line of sight exists between the given locations
|
+ * Tell whether a line of sight exists between the given locations
|
||||||
@ -21,8 +21,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ */
|
+ */
|
||||||
+ public boolean lineOfSightExists(@NotNull Location from, @NotNull Location to);
|
+ public boolean lineOfSightExists(@NotNull Location from, @NotNull Location to);
|
||||||
// Paper end
|
// Paper end
|
||||||
|
}
|
||||||
/**
|
|
||||||
diff --git a/src/main/java/org/bukkit/entity/LivingEntity.java b/src/main/java/org/bukkit/entity/LivingEntity.java
|
diff --git a/src/main/java/org/bukkit/entity/LivingEntity.java b/src/main/java/org/bukkit/entity/LivingEntity.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/org/bukkit/entity/LivingEntity.java
|
--- a/src/main/java/org/bukkit/entity/LivingEntity.java
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||||
Date: Wed, 6 Jan 2021 00:34:10 -0800
|
Date: Wed, 6 Jan 2021 00:34:10 -0800
|
||||||
Subject: [PATCH] Add methods to get world by key
|
Subject: [PATCH] Expand world key API
|
||||||
|
|
||||||
|
|
||||||
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
|
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
|
||||||
@ -27,6 +27,34 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new virtual {@link WorldBorder}.
|
* Create a new virtual {@link WorldBorder}.
|
||||||
|
diff --git a/src/main/java/org/bukkit/RegionAccessor.java b/src/main/java/org/bukkit/RegionAccessor.java
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/org/bukkit/RegionAccessor.java
|
||||||
|
+++ b/src/main/java/org/bukkit/RegionAccessor.java
|
||||||
|
@@ -0,0 +0,0 @@ import org.jetbrains.annotations.Nullable;
|
||||||
|
* A RegionAccessor gives access to getting, modifying and spawning {@link Biome}, {@link BlockState} and {@link Entity},
|
||||||
|
* as well as generating some basic structures.
|
||||||
|
*/
|
||||||
|
-public interface RegionAccessor {
|
||||||
|
+public interface RegionAccessor extends Keyed { // Paper
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@link Biome} at the given {@link Location}.
|
||||||
|
@@ -0,0 +0,0 @@ public interface RegionAccessor {
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
io.papermc.paper.world.MoonPhase getMoonPhase();
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Get the world's key
|
||||||
|
+ *
|
||||||
|
+ * @return the world's key
|
||||||
|
+ */
|
||||||
|
+ @NotNull
|
||||||
|
+ @Override
|
||||||
|
+ NamespacedKey getKey();
|
||||||
|
// Paper end
|
||||||
|
}
|
||||||
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
|
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/org/bukkit/Server.java
|
--- a/src/main/java/org/bukkit/Server.java
|
@ -4,19 +4,19 @@ Date: Sun, 23 Aug 2020 16:32:11 +0200
|
|||||||
Subject: [PATCH] Add moon phase API
|
Subject: [PATCH] Add moon phase API
|
||||||
|
|
||||||
|
|
||||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
|
||||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
|
||||||
@@ -0,0 +0,0 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
@@ -0,0 +0,0 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
|
||||||
public int getPlayerCount() {
|
|
||||||
return world.players().size();
|
throw new IllegalArgumentException("Cannot spawn an entity for " + clazz.getName());
|
||||||
}
|
}
|
||||||
+
|
+
|
||||||
|
+ // Paper start
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public io.papermc.paper.world.MoonPhase getMoonPhase() {
|
+ public io.papermc.paper.world.MoonPhase getMoonPhase() {
|
||||||
+ return io.papermc.paper.world.MoonPhase.getPhase(getFullTime() / 24000L);
|
+ return io.papermc.paper.world.MoonPhase.getPhase(this.getHandle().dayTime() / 24000L);
|
||||||
+ }
|
+ }
|
||||||
// Paper end
|
+ // Paper end
|
||||||
|
}
|
||||||
private static final Random rand = new Random();
|
|
||||||
|
@ -1,9 +1,24 @@
|
|||||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||||
Date: Wed, 6 Jan 2021 00:34:04 -0800
|
Date: Wed, 6 Jan 2021 00:34:04 -0800
|
||||||
Subject: [PATCH] Add methods to get world by key
|
Subject: [PATCH] Expand world key API
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
|
||||||
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
|
||||||
|
@@ -0,0 +0,0 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
|
||||||
|
public io.papermc.paper.world.MoonPhase getMoonPhase() {
|
||||||
|
return io.papermc.paper.world.MoonPhase.getPhase(this.getHandle().dayTime() / 24000L);
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public org.bukkit.NamespacedKey getKey() {
|
||||||
|
+ return org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(this.getHandle().getLevel().dimension().location());
|
||||||
|
+ }
|
||||||
|
// Paper end
|
||||||
|
}
|
||||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
@ -35,8 +35,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||||
@@ -0,0 +0,0 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
@@ -0,0 +0,0 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||||
|
public int getPlayerCount() {
|
||||||
return this.getHandle().clip(new ClipContext(vec3d, vec3d1, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null)).getType() == HitResult.Type.MISS;
|
return world.players().size();
|
||||||
}
|
}
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
|
@ -18,29 +18,27 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
|
||||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
|
||||||
@@ -0,0 +0,0 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
@@ -0,0 +0,0 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
|
||||||
public io.papermc.paper.world.MoonPhase getMoonPhase() {
|
public org.bukkit.NamespacedKey getKey() {
|
||||||
return io.papermc.paper.world.MoonPhase.getPhase(getFullTime() / 24000L);
|
return org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(this.getHandle().getLevel().dimension().location());
|
||||||
}
|
}
|
||||||
+
|
+
|
||||||
+ @Override
|
|
||||||
+ public boolean lineOfSightExists(Location from, Location to) {
|
+ public boolean lineOfSightExists(Location from, Location to) {
|
||||||
+ Validate.notNull(from, "from parameter in lineOfSightExists cannot be null");
|
+ Preconditions.checkArgument(from != null, "from parameter in lineOfSightExists cannot be null");
|
||||||
+ Validate.notNull(to, "to parameter in lineOfSightExists cannot be null");
|
+ Preconditions.checkArgument(to != null, "to parameter in lineOfSightExists cannot be null");
|
||||||
+ if (from.getWorld() != to.getWorld()) return false;
|
+ if (from.getWorld() != to.getWorld()) return false;
|
||||||
+ Vec3 vec3d = new Vec3(from.getX(), from.getY(), from.getZ());
|
+ net.minecraft.world.phys.Vec3 vec3d = new net.minecraft.world.phys.Vec3(from.getX(), from.getY(), from.getZ());
|
||||||
+ Vec3 vec3d1 = new Vec3(to.getX(), to.getY(), to.getZ());
|
+ net.minecraft.world.phys.Vec3 vec3d1 = new net.minecraft.world.phys.Vec3(to.getX(), to.getY(), to.getZ());
|
||||||
+ if (vec3d1.distanceToSqr(vec3d) > 128D * 128D) return false; //Return early if the distance is greater than 128 blocks
|
+ if (vec3d1.distanceToSqr(vec3d) > 128D * 128D) return false; //Return early if the distance is greater than 128 blocks
|
||||||
+
|
+
|
||||||
+ return this.getHandle().clip(new ClipContext(vec3d, vec3d1, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null)).getType() == HitResult.Type.MISS;
|
+ return this.getHandle().clip(new net.minecraft.world.level.ClipContext(vec3d, vec3d1, net.minecraft.world.level.ClipContext.Block.COLLIDER, net.minecraft.world.level.ClipContext.Fluid.NONE, null)).getType() == net.minecraft.world.phys.HitResult.Type.MISS;
|
||||||
+ }
|
+ }
|
||||||
// Paper end
|
// Paper end
|
||||||
|
}
|
||||||
private static final Random rand = new Random();
|
|
||||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
||||||
|
Loading…
Reference in New Issue
Block a user