mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-05 10:20:53 +01:00
Implemented helper methods + new biome methods
This commit is contained in:
parent
7f6e7060d7
commit
3d28c67c08
121
src/main/java/net/minecraft/server/WorldChunkManager.java
Normal file
121
src/main/java/net/minecraft/server/WorldChunkManager.java
Normal file
@ -0,0 +1,121 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class WorldChunkManager {
|
||||
|
||||
private NoiseGeneratorOctaves2 e;
|
||||
private NoiseGeneratorOctaves2 f;
|
||||
private NoiseGeneratorOctaves2 g;
|
||||
public double[] temperature;
|
||||
public double[] rain;
|
||||
public double[] c;
|
||||
public BiomeBase[] d;
|
||||
|
||||
protected WorldChunkManager() {}
|
||||
|
||||
public WorldChunkManager(World world) {
|
||||
this.e = new NoiseGeneratorOctaves2(new Random(world.getSeed() * 9871L), 4);
|
||||
this.f = new NoiseGeneratorOctaves2(new Random(world.getSeed() * 39811L), 4);
|
||||
this.g = new NoiseGeneratorOctaves2(new Random(world.getSeed() * 543321L), 2);
|
||||
}
|
||||
|
||||
public BiomeBase a(ChunkCoordIntPair chunkcoordintpair) {
|
||||
return this.getBiome(chunkcoordintpair.x << 4, chunkcoordintpair.z << 4);
|
||||
}
|
||||
|
||||
public BiomeBase getBiome(int i, int j) {
|
||||
return this.getBiomeData(i, j, 1, 1)[0];
|
||||
}
|
||||
|
||||
public BiomeBase[] getBiomeData(int i, int j, int k, int l) {
|
||||
this.d = this.a(this.d, i, j, k, l);
|
||||
return this.d;
|
||||
}
|
||||
|
||||
public double[] a(double[] adouble, int i, int j, int k, int l) {
|
||||
if (adouble == null || adouble.length < k * l) {
|
||||
adouble = new double[k * l];
|
||||
}
|
||||
|
||||
adouble = this.e.a(adouble, (double) i, (double) j, k, l, 0.02500000037252903D, 0.02500000037252903D, 0.25D);
|
||||
this.c = this.g.a(this.c, (double) i, (double) j, k, l, 0.25D, 0.25D, 0.5882352941176471D);
|
||||
int i1 = 0;
|
||||
|
||||
for (int j1 = 0; j1 < k; ++j1) {
|
||||
for (int k1 = 0; k1 < l; ++k1) {
|
||||
double d0 = this.c[i1] * 1.1D + 0.5D;
|
||||
double d1 = 0.01D;
|
||||
double d2 = 1.0D - d1;
|
||||
double d3 = (adouble[i1] * 0.15D + 0.7D) * d2 + d0 * d1;
|
||||
|
||||
d3 = 1.0D - (1.0D - d3) * (1.0D - d3);
|
||||
if (d3 < 0.0D) {
|
||||
d3 = 0.0D;
|
||||
}
|
||||
|
||||
if (d3 > 1.0D) {
|
||||
d3 = 1.0D;
|
||||
}
|
||||
|
||||
adouble[i1] = d3;
|
||||
++i1;
|
||||
}
|
||||
}
|
||||
|
||||
return adouble;
|
||||
}
|
||||
|
||||
public BiomeBase[] a(BiomeBase[] abiomebase, int i, int j, int k, int l) {
|
||||
if (abiomebase == null || abiomebase.length < k * l) {
|
||||
abiomebase = new BiomeBase[k * l];
|
||||
}
|
||||
|
||||
this.temperature = this.e.a(this.temperature, (double) i, (double) j, k, k, 0.02500000037252903D, 0.02500000037252903D, 0.25D);
|
||||
this.rain = this.f.a(this.rain, (double) i, (double) j, k, k, 0.05000000074505806D, 0.05000000074505806D, 0.3333333333333333D);
|
||||
this.c = this.g.a(this.c, (double) i, (double) j, k, k, 0.25D, 0.25D, 0.5882352941176471D);
|
||||
int i1 = 0;
|
||||
|
||||
for (int j1 = 0; j1 < k; ++j1) {
|
||||
for (int k1 = 0; k1 < l; ++k1) {
|
||||
double d0 = this.c[i1] * 1.1D + 0.5D;
|
||||
double d1 = 0.01D;
|
||||
double d2 = 1.0D - d1;
|
||||
double d3 = (this.temperature[i1] * 0.15D + 0.7D) * d2 + d0 * d1;
|
||||
|
||||
d1 = 0.0020D;
|
||||
d2 = 1.0D - d1;
|
||||
double d4 = (this.rain[i1] * 0.15D + 0.5D) * d2 + d0 * d1;
|
||||
|
||||
d3 = 1.0D - (1.0D - d3) * (1.0D - d3);
|
||||
if (d3 < 0.0D) {
|
||||
d3 = 0.0D;
|
||||
}
|
||||
|
||||
if (d4 < 0.0D) {
|
||||
d4 = 0.0D;
|
||||
}
|
||||
|
||||
if (d3 > 1.0D) {
|
||||
d3 = 1.0D;
|
||||
}
|
||||
|
||||
if (d4 > 1.0D) {
|
||||
d4 = 1.0D;
|
||||
}
|
||||
|
||||
this.temperature[i1] = d3;
|
||||
this.rain[i1] = d4;
|
||||
abiomebase[i1++] = BiomeBase.a(d3, d4);
|
||||
}
|
||||
}
|
||||
|
||||
return abiomebase;
|
||||
}
|
||||
|
||||
// CraftBukkit start
|
||||
public double getHumidity(int x, int z) {
|
||||
return this.f.a(this.rain, (double)x, (double)z, 1, 1, 0.05000000074505806D, 0.05000000074505806D, 0.3333333333333333D)[0];
|
||||
}
|
||||
// CraftBukkit end
|
||||
}
|
@ -30,6 +30,7 @@ import org.bukkit.ChunkSnapshot;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.TreeType;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
|
||||
public class CraftWorld implements World {
|
||||
@ -488,6 +489,56 @@ public class CraftWorld implements World {
|
||||
return populators;
|
||||
}
|
||||
|
||||
public Block getHighestBlockAt(int x, int z) {
|
||||
return getBlockAt(x, getHighestBlockYAt(x, z), z);
|
||||
}
|
||||
|
||||
public Block getHighestBlockAt(Location location) {
|
||||
return getHighestBlockAt(location.getBlockX(), location.getBlockZ());
|
||||
}
|
||||
|
||||
public Biome getBiome(int x, int z) {
|
||||
BiomeBase base = getHandle().getWorldChunkManager().getBiome(x, z);
|
||||
|
||||
if (base == BiomeBase.RAINFOREST) {
|
||||
return Biome.RAINFOREST;
|
||||
} else if (base == BiomeBase.SWAMPLAND) {
|
||||
return Biome.SWAMPLAND;
|
||||
} else if (base == BiomeBase.SEASONAL_FOREST) {
|
||||
return Biome.SEASONAL_FOREST;
|
||||
} else if (base == BiomeBase.FOREST) {
|
||||
return Biome.FOREST;
|
||||
} else if (base == BiomeBase.SAVANNA) {
|
||||
return Biome.SAVANNA;
|
||||
} else if (base == BiomeBase.SHRUBLAND) {
|
||||
return Biome.SHRUBLAND;
|
||||
} else if (base == BiomeBase.TAIGA) {
|
||||
return Biome.TAIGA;
|
||||
} else if (base == BiomeBase.DESERT) {
|
||||
return Biome.DESERT;
|
||||
} else if (base == BiomeBase.PLAINS) {
|
||||
return Biome.PLAINS;
|
||||
} else if (base == BiomeBase.ICE_DESERT) {
|
||||
return Biome.ICE_DESERT;
|
||||
} else if (base == BiomeBase.TUNDRA) {
|
||||
return Biome.TUNDRA;
|
||||
} else if (base == BiomeBase.HELL) {
|
||||
return Biome.HELL;
|
||||
} else if (base == BiomeBase.SKY) {
|
||||
return Biome.SKY;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public double getTemperature(int x, int z) {
|
||||
return getHandle().getWorldChunkManager().a((double[])null, x, z, 1, 1)[0];
|
||||
}
|
||||
|
||||
public double getHumidity(int x, int z) {
|
||||
return getHandle().getWorldChunkManager().getHumidity(x, z);
|
||||
}
|
||||
|
||||
private final class ChunkCoordinate {
|
||||
public final int x;
|
||||
public final int z;
|
||||
|
@ -330,37 +330,15 @@ public class CraftBlock implements Block {
|
||||
}
|
||||
|
||||
public Biome getBiome() {
|
||||
BiomeBase base = chunk.getHandle().world.getWorldChunkManager().getBiome(x, z);
|
||||
return getWorld().getBiome(x, z);
|
||||
}
|
||||
|
||||
if (base == BiomeBase.RAINFOREST) {
|
||||
return Biome.RAINFOREST;
|
||||
} else if (base == BiomeBase.SWAMPLAND) {
|
||||
return Biome.SWAMPLAND;
|
||||
} else if (base == BiomeBase.SEASONAL_FOREST) {
|
||||
return Biome.SEASONAL_FOREST;
|
||||
} else if (base == BiomeBase.FOREST) {
|
||||
return Biome.FOREST;
|
||||
} else if (base == BiomeBase.SAVANNA) {
|
||||
return Biome.SAVANNA;
|
||||
} else if (base == BiomeBase.SHRUBLAND) {
|
||||
return Biome.SHRUBLAND;
|
||||
} else if (base == BiomeBase.TAIGA) {
|
||||
return Biome.TAIGA;
|
||||
} else if (base == BiomeBase.DESERT) {
|
||||
return Biome.DESERT;
|
||||
} else if (base == BiomeBase.PLAINS) {
|
||||
return Biome.PLAINS;
|
||||
} else if (base == BiomeBase.ICE_DESERT) {
|
||||
return Biome.ICE_DESERT;
|
||||
} else if (base == BiomeBase.TUNDRA) {
|
||||
return Biome.TUNDRA;
|
||||
} else if (base == BiomeBase.HELL) {
|
||||
return Biome.HELL;
|
||||
} else if (base == BiomeBase.SKY) {
|
||||
return Biome.SKY;
|
||||
}
|
||||
public double getTemperature() {
|
||||
return getWorld().getTemperature(x, z);
|
||||
}
|
||||
|
||||
return null;
|
||||
public double getHumidity() {
|
||||
return getWorld().getHumidity(x, z);
|
||||
}
|
||||
|
||||
public boolean isBlockPowered() {
|
||||
@ -400,4 +378,12 @@ public class CraftBlock implements Block {
|
||||
public int getBlockPower() {
|
||||
return getBlockPower(BlockFace.SELF);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return getType() == Material.AIR;
|
||||
}
|
||||
|
||||
public boolean isLiquid() {
|
||||
return (getType() == Material.WATER) || (getType() == Material.STATIONARY_WATER) || (getType() == Material.LAVA) || (getType() == Material.STATIONARY_LAVA);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user