Add getComputedBiome API (#5668)
This commit is contained in:
		
					parent
					
						
							
								cbdfcf8338
							
						
					
				
			
			
				commit
				
					
						f94af0f041
					
				
			
		
					 2 changed files with 140 additions and 0 deletions
				
			
		
							
								
								
									
										79
									
								
								patches/api/Add-getComputedBiome-API.patch
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								patches/api/Add-getComputedBiome-API.patch
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,79 @@
 | 
			
		|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 | 
			
		||||
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
 | 
			
		||||
Date: Mon, 14 Mar 2022 22:45:32 -0700
 | 
			
		||||
Subject: [PATCH] Add getComputedBiome API
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
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 @@ public interface RegionAccessor {
 | 
			
		||||
      *
 | 
			
		||||
      * @param location the location of the biome
 | 
			
		||||
      * @return Biome at the given location
 | 
			
		||||
+     * @see #getComputedBiome(int, int, int)
 | 
			
		||||
      */
 | 
			
		||||
     @NotNull
 | 
			
		||||
     Biome getBiome(@NotNull Location location);
 | 
			
		||||
@@ -0,0 +0,0 @@ public interface RegionAccessor {
 | 
			
		||||
      * @param y Y-coordinate of the block
 | 
			
		||||
      * @param z Z-coordinate of the block
 | 
			
		||||
      * @return Biome at the given coordinates
 | 
			
		||||
+     * @see #getComputedBiome(int, int, int)
 | 
			
		||||
      */
 | 
			
		||||
     @NotNull
 | 
			
		||||
     Biome getBiome(int x, int y, int z);
 | 
			
		||||
 
 | 
			
		||||
+    // Paper start
 | 
			
		||||
+    /**
 | 
			
		||||
+     * Gets the computed {@link Biome} at the given coordinates.
 | 
			
		||||
+     *
 | 
			
		||||
+     * <p>The computed Biome is the Biome as seen by clients for rendering
 | 
			
		||||
+     * purposes and in the "F3" debug menu. This is computed by looking at the noise biome
 | 
			
		||||
+     * at this and surrounding quarts and applying complex math operations.</p>
 | 
			
		||||
+     *
 | 
			
		||||
+     * <p>Most other Biome-related methods named getBiome, setBiome, and similar
 | 
			
		||||
+     * operate on the "noise biome", which is stored per-quart, or in other words,
 | 
			
		||||
+     * 1 Biome per 4x4x4 block region. This is how Biomes are currently generated and
 | 
			
		||||
+     * stored on disk.</p>
 | 
			
		||||
+     *
 | 
			
		||||
+     * @param x X-coordinate of the block
 | 
			
		||||
+     * @param y Y-coordinate of the block
 | 
			
		||||
+     * @param z Z-coordinate of the block
 | 
			
		||||
+     * @return Biome at the given coordinates
 | 
			
		||||
+     */
 | 
			
		||||
+    @NotNull
 | 
			
		||||
+    Biome getComputedBiome(int x, int y, int z);
 | 
			
		||||
+    // Paper end
 | 
			
		||||
+
 | 
			
		||||
     /**
 | 
			
		||||
      * Sets the {@link Biome} at the given {@link Location}.
 | 
			
		||||
      *
 | 
			
		||||
diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java
 | 
			
		||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 | 
			
		||||
--- a/src/main/java/org/bukkit/block/Block.java
 | 
			
		||||
+++ b/src/main/java/org/bukkit/block/Block.java
 | 
			
		||||
@@ -0,0 +0,0 @@ public interface Block extends Metadatable, net.kyori.adventure.translation.Tran
 | 
			
		||||
      * Returns the biome that this block resides in
 | 
			
		||||
      *
 | 
			
		||||
      * @return Biome type containing this block
 | 
			
		||||
+     * @see #getComputedBiome()
 | 
			
		||||
      */
 | 
			
		||||
     @NotNull
 | 
			
		||||
     Biome getBiome();
 | 
			
		||||
 
 | 
			
		||||
+    // Paper start
 | 
			
		||||
+    /**
 | 
			
		||||
+     * Gets the computed biome at the location of this Block.
 | 
			
		||||
+     *
 | 
			
		||||
+     * @return computed biome at the location of this Block.
 | 
			
		||||
+     * @see org.bukkit.RegionAccessor#getComputedBiome(int, int, int)
 | 
			
		||||
+     */
 | 
			
		||||
+    @NotNull
 | 
			
		||||
+    Biome getComputedBiome();
 | 
			
		||||
+    // Paper end
 | 
			
		||||
+
 | 
			
		||||
     /**
 | 
			
		||||
      * Sets the biome that this block resides in
 | 
			
		||||
      *
 | 
			
		||||
							
								
								
									
										61
									
								
								patches/server/Implement-getComputedBiome-API.patch
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								patches/server/Implement-getComputedBiome-API.patch
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,61 @@
 | 
			
		|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 | 
			
		||||
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
 | 
			
		||||
Date: Mon, 14 Mar 2022 22:46:05 -0700
 | 
			
		||||
Subject: [PATCH] Implement getComputedBiome 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 {
 | 
			
		||||
         return CraftBlock.biomeBaseToBiome(this.getHandle().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), this.getHandle().getNoiseBiome(x >> 2, y >> 2, z >> 2));
 | 
			
		||||
     }
 | 
			
		||||
 
 | 
			
		||||
+    // Paper start
 | 
			
		||||
+    @Override
 | 
			
		||||
+    public Biome getComputedBiome(int x, int y, int z) {
 | 
			
		||||
+        return CraftBlock.biomeBaseToBiome(this.getHandle().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), this.getHandle().getBiome(new BlockPos(x, y, z)));
 | 
			
		||||
+    }
 | 
			
		||||
+    // Paper end
 | 
			
		||||
+
 | 
			
		||||
     @Override
 | 
			
		||||
     public void setBiome(Location location, Biome biome) {
 | 
			
		||||
         this.setBiome(location.getBlockX(), location.getBlockY(), location.getBlockZ(), biome);
 | 
			
		||||
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
 | 
			
		||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 | 
			
		||||
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
 | 
			
		||||
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
 | 
			
		||||
@@ -0,0 +0,0 @@ public class CraftBlock implements Block {
 | 
			
		||||
         return this.getWorld().getBiome(this.getX(), this.getY(), this.getZ());
 | 
			
		||||
     }
 | 
			
		||||
 
 | 
			
		||||
+    // Paper start
 | 
			
		||||
+    @Override
 | 
			
		||||
+    public Biome getComputedBiome() {
 | 
			
		||||
+        return this.getWorld().getComputedBiome(this.getX(), this.getY(), this.getZ());
 | 
			
		||||
+    }
 | 
			
		||||
+    // Paper end
 | 
			
		||||
+
 | 
			
		||||
     @Override
 | 
			
		||||
     public void setBiome(Biome bio) {
 | 
			
		||||
         this.getWorld().setBiome(this.getX(), this.getY(), this.getZ(), bio);
 | 
			
		||||
diff --git a/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java b/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java
 | 
			
		||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 | 
			
		||||
--- a/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java
 | 
			
		||||
+++ b/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java
 | 
			
		||||
@@ -0,0 +0,0 @@ public class CraftLimitedRegion extends CraftRegionAccessor implements LimitedRe
 | 
			
		||||
         return super.getBiome(x, y, z);
 | 
			
		||||
     }
 | 
			
		||||
 
 | 
			
		||||
+    // Paper start
 | 
			
		||||
+    @Override
 | 
			
		||||
+    public Biome getComputedBiome(int x, int y, int z) {
 | 
			
		||||
+        Preconditions.checkArgument(this.isInRegion(x, y, z), "Coordinates %s, %s, %s are not in the region", x, y, z);
 | 
			
		||||
+        return super.getComputedBiome(x, y, z);
 | 
			
		||||
+    }
 | 
			
		||||
+    // Paper end
 | 
			
		||||
+
 | 
			
		||||
     @Override
 | 
			
		||||
     public void setBiome(int x, int y, int z, Holder<net.minecraft.world.level.biome.Biome> biomeBase) {
 | 
			
		||||
         Preconditions.checkArgument(this.isInRegion(x, y, z), "Coordinates %s, %s, %s are not in the region", x, y, z);
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue