net.minecraft.world.level.levelgen
This commit is contained in:
@@ -1,52 +0,0 @@
|
||||
--- a/net/minecraft/world/level/levelgen/DensityFunctions.java
|
||||
+++ b/net/minecraft/world/level/levelgen/DensityFunctions.java
|
||||
@@ -509,6 +509,16 @@
|
||||
);
|
||||
private static final float ISLAND_THRESHOLD = -0.9F;
|
||||
private final SimplexNoise islandNoise;
|
||||
+ // Paper start - Perf: Optimize end generation
|
||||
+ private static final class NoiseCache {
|
||||
+ public long[] keys = new long[8192];
|
||||
+ public float[] values = new float[8192];
|
||||
+ public NoiseCache() {
|
||||
+ java.util.Arrays.fill(keys, Long.MIN_VALUE);
|
||||
+ }
|
||||
+ }
|
||||
+ private static final ThreadLocal<java.util.Map<SimplexNoise, NoiseCache>> noiseCache = ThreadLocal.withInitial(java.util.WeakHashMap::new);
|
||||
+ // Paper end - Perf: Optimize end generation
|
||||
|
||||
public EndIslandDensityFunction(long seed) {
|
||||
RandomSource randomSource = new LegacyRandomSource(seed);
|
||||
@@ -521,15 +531,29 @@
|
||||
int j = z / 2;
|
||||
int k = x % 2;
|
||||
int l = z % 2;
|
||||
- float f = 100.0F - Mth.sqrt((float)(x * x + z * z)) * 8.0F;
|
||||
+ float f = 100.0F - Mth.sqrt((long) x * (long) x + (long) z * (long) z) * 8.0F; // Paper - cast ints to long to avoid integer overflow
|
||||
f = Mth.clamp(f, -100.0F, 80.0F);
|
||||
|
||||
+ NoiseCache cache = noiseCache.get().computeIfAbsent(sampler, noiseKey -> new NoiseCache()); // Paper - Perf: Optimize end generation
|
||||
for (int m = -12; m <= 12; m++) {
|
||||
for (int n = -12; n <= 12; n++) {
|
||||
long o = (long)(i + m);
|
||||
long p = (long)(j + n);
|
||||
- if (o * o + p * p > 4096L && sampler.getValue((double)o, (double)p) < -0.9F) {
|
||||
- float g = (Mth.abs((float)o) * 3439.0F + Mth.abs((float)p) * 147.0F) % 13.0F + 9.0F;
|
||||
+ // Paper start - Perf: Optimize end generation by using a noise cache
|
||||
+ long key = net.minecraft.world.level.ChunkPos.asLong((int) o, (int) p);
|
||||
+ int index = (int) it.unimi.dsi.fastutil.HashCommon.mix(key) & 8191;
|
||||
+ float g = Float.MIN_VALUE;
|
||||
+ if (cache.keys[index] == key) {
|
||||
+ g = cache.values[index];
|
||||
+ } else {
|
||||
+ if (o * o + p * p > 4096L && sampler.getValue((double)o, (double)p) < -0.9F) {
|
||||
+ g = (Mth.abs((float)o) * 3439.0F + Mth.abs((float)p) * 147.0F) % 13.0F + 9.0F;
|
||||
+ }
|
||||
+ cache.keys[index] = key;
|
||||
+ cache.values[index] = g;
|
||||
+ }
|
||||
+ if (g != Float.MIN_VALUE) {
|
||||
+ // Paper end - Perf: Optimize end generation
|
||||
float h = (float)(k - m * 2);
|
||||
float q = (float)(l - n * 2);
|
||||
float r = 100.0F - Mth.sqrt(h * h + q * q) * g;
|
||||
@@ -1,38 +0,0 @@
|
||||
--- a/net/minecraft/world/level/levelgen/FlatLevelSource.java
|
||||
+++ b/net/minecraft/world/level/levelgen/FlatLevelSource.java
|
||||
@@ -34,22 +34,28 @@
|
||||
private final FlatLevelGeneratorSettings settings;
|
||||
|
||||
public FlatLevelSource(FlatLevelGeneratorSettings config) {
|
||||
- FixedBiomeSource worldchunkmanagerhell = new FixedBiomeSource(config.getBiome());
|
||||
+ // CraftBukkit start
|
||||
+ // WorldChunkManagerHell worldchunkmanagerhell = new WorldChunkManagerHell(generatorsettingsflat.getBiome());
|
||||
|
||||
- Objects.requireNonNull(config);
|
||||
- super(worldchunkmanagerhell, Util.memoize(config::adjustGenerationSettings));
|
||||
- this.settings = config;
|
||||
+ // Objects.requireNonNull(generatorsettingsflat);
|
||||
+ this(config, new FixedBiomeSource(config.getBiome()));
|
||||
}
|
||||
|
||||
+ public FlatLevelSource(FlatLevelGeneratorSettings generatorsettingsflat, net.minecraft.world.level.biome.BiomeSource worldchunkmanager) {
|
||||
+ super(worldchunkmanager, Util.memoize(generatorsettingsflat::adjustGenerationSettings));
|
||||
+ // CraftBukkit end
|
||||
+ this.settings = generatorsettingsflat;
|
||||
+ }
|
||||
+
|
||||
@Override
|
||||
- public ChunkGeneratorStructureState createState(HolderLookup<StructureSet> structureSetRegistry, RandomState noiseConfig, long seed) {
|
||||
+ public ChunkGeneratorStructureState createState(HolderLookup<StructureSet> holderlookup, RandomState randomstate, long i, org.spigotmc.SpigotWorldConfig conf) { // Spigot
|
||||
Stream<Holder<StructureSet>> stream = (Stream) this.settings.structureOverrides().map(HolderSet::stream).orElseGet(() -> {
|
||||
- return structureSetRegistry.listElements().map((holder_c) -> {
|
||||
+ return holderlookup.listElements().map((holder_c) -> {
|
||||
return holder_c;
|
||||
});
|
||||
});
|
||||
|
||||
- return ChunkGeneratorStructureState.createForFlat(noiseConfig, seed, this.biomeSource, stream);
|
||||
+ return ChunkGeneratorStructureState.createForFlat(randomstate, i, this.biomeSource, stream, conf); // Spigot
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1,7 +0,0 @@
|
||||
--- a/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java
|
||||
+++ b/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java
|
||||
@@ -1,3 +1,4 @@
|
||||
+// keep
|
||||
package net.minecraft.world.level.levelgen;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
@@ -1,79 +0,0 @@
|
||||
--- a/net/minecraft/world/level/levelgen/PatrolSpawner.java
|
||||
+++ b/net/minecraft/world/level/levelgen/PatrolSpawner.java
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
@Override
|
||||
public int tick(ServerLevel world, boolean spawnMonsters, boolean spawnAnimals) {
|
||||
+ if (world.paperConfig().entities.behavior.pillagerPatrols.disable || world.paperConfig().entities.behavior.pillagerPatrols.spawnChance == 0) return 0; // Paper - Add option to disable pillager patrols & Pillager patrol spawn settings and per player options
|
||||
if (!spawnMonsters) {
|
||||
return 0;
|
||||
} else if (!world.getGameRules().getBoolean(GameRules.RULE_DO_PATROL_SPAWNING)) {
|
||||
@@ -31,23 +32,51 @@
|
||||
} else {
|
||||
RandomSource randomsource = world.random;
|
||||
|
||||
- --this.nextTick;
|
||||
- if (this.nextTick > 0) {
|
||||
+ // Paper start - Pillager patrol spawn settings and per player options
|
||||
+ // Random player selection moved up for per player spawning and configuration
|
||||
+ int j = world.players().size();
|
||||
+ if (j < 1) {
|
||||
return 0;
|
||||
+ }
|
||||
+
|
||||
+ net.minecraft.server.level.ServerPlayer entityhuman = world.players().get(randomsource.nextInt(j));
|
||||
+ if (entityhuman.isSpectator()) {
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ int patrolSpawnDelay;
|
||||
+ if (world.paperConfig().entities.behavior.pillagerPatrols.spawnDelay.perPlayer) {
|
||||
+ --entityhuman.patrolSpawnDelay;
|
||||
+ patrolSpawnDelay = entityhuman.patrolSpawnDelay;
|
||||
} else {
|
||||
- this.nextTick += 12000 + randomsource.nextInt(1200);
|
||||
- long i = world.getDayTime() / 24000L;
|
||||
+ this.nextTick--;
|
||||
+ patrolSpawnDelay = this.nextTick;
|
||||
+ }
|
||||
|
||||
- if (i >= 5L && world.isDay()) {
|
||||
- if (randomsource.nextInt(5) != 0) {
|
||||
+ if (patrolSpawnDelay > 0) {
|
||||
+ return 0;
|
||||
+ } else {
|
||||
+ long days;
|
||||
+ if (world.paperConfig().entities.behavior.pillagerPatrols.start.perPlayer) {
|
||||
+ days = entityhuman.getStats().getValue(net.minecraft.stats.Stats.CUSTOM.get(net.minecraft.stats.Stats.PLAY_TIME)) / 24000L; // PLAY_ONE_MINUTE is actually counting in ticks, a misnomer by Mojang
|
||||
+ } else {
|
||||
+ days = world.getDayTime() / 24000L;
|
||||
+ }
|
||||
+ if (world.paperConfig().entities.behavior.pillagerPatrols.spawnDelay.perPlayer) {
|
||||
+ entityhuman.patrolSpawnDelay += world.paperConfig().entities.behavior.pillagerPatrols.spawnDelay.ticks + randomsource.nextInt(1200);
|
||||
+ } else {
|
||||
+ this.nextTick += world.paperConfig().entities.behavior.pillagerPatrols.spawnDelay.ticks + randomsource.nextInt(1200);
|
||||
+ }
|
||||
+
|
||||
+ if (days >= world.paperConfig().entities.behavior.pillagerPatrols.start.day && world.isDay()) {
|
||||
+ if (randomsource.nextDouble() >= world.paperConfig().entities.behavior.pillagerPatrols.spawnChance) {
|
||||
+ // Paper end - Pillager patrol spawn settings and per player options
|
||||
return 0;
|
||||
} else {
|
||||
- int j = world.players().size();
|
||||
|
||||
if (j < 1) {
|
||||
return 0;
|
||||
} else {
|
||||
- Player entityhuman = (Player) world.players().get(randomsource.nextInt(j));
|
||||
|
||||
if (entityhuman.isSpectator()) {
|
||||
return 0;
|
||||
@@ -116,7 +145,7 @@
|
||||
|
||||
entitymonsterpatrolling.setPos((double) pos.getX(), (double) pos.getY(), (double) pos.getZ());
|
||||
entitymonsterpatrolling.finalizeSpawn(world, world.getCurrentDifficultyAt(pos), EntitySpawnReason.PATROL, (SpawnGroupData) null);
|
||||
- world.addFreshEntityWithPassengers(entitymonsterpatrolling);
|
||||
+ world.addFreshEntityWithPassengers(entitymonsterpatrolling, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.PATROL); // CraftBukkit
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -1,68 +0,0 @@
|
||||
--- a/net/minecraft/world/level/levelgen/PhantomSpawner.java
|
||||
+++ b/net/minecraft/world/level/levelgen/PhantomSpawner.java
|
||||
@@ -32,13 +32,22 @@
|
||||
} else if (!world.getGameRules().getBoolean(GameRules.RULE_DOINSOMNIA)) {
|
||||
return 0;
|
||||
} else {
|
||||
+ // Paper start - Ability to control player's insomnia and phantoms
|
||||
+ if (world.paperConfig().entities.behavior.phantomsSpawnAttemptMaxSeconds <= 0) {
|
||||
+ return 0;
|
||||
+ }
|
||||
+ // Paper end - Ability to control player's insomnia and phantoms
|
||||
RandomSource randomsource = world.random;
|
||||
|
||||
--this.nextTick;
|
||||
if (this.nextTick > 0) {
|
||||
return 0;
|
||||
} else {
|
||||
- this.nextTick += (60 + randomsource.nextInt(60)) * 20;
|
||||
+ // Paper start - Ability to control player's insomnia and phantoms
|
||||
+ int spawnAttemptMinSeconds = world.paperConfig().entities.behavior.phantomsSpawnAttemptMinSeconds;
|
||||
+ int spawnAttemptMaxSeconds = world.paperConfig().entities.behavior.phantomsSpawnAttemptMaxSeconds;
|
||||
+ this.nextTick += (spawnAttemptMinSeconds + randomsource.nextInt(spawnAttemptMaxSeconds - spawnAttemptMinSeconds + 1)) * 20;
|
||||
+ // Paper end - Ability to control player's insomnia and phantoms
|
||||
if (world.getSkyDarken() < 5 && world.dimensionType().hasSkyLight()) {
|
||||
return 0;
|
||||
} else {
|
||||
@@ -48,7 +57,7 @@
|
||||
while (iterator.hasNext()) {
|
||||
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
|
||||
|
||||
- if (!entityplayer.isSpectator()) {
|
||||
+ if (!entityplayer.isSpectator() && (!world.paperConfig().entities.behavior.phantomsDoNotSpawnOnCreativePlayers || !entityplayer.isCreative())) { // Paper - Add phantom creative and insomniac controls
|
||||
BlockPos blockposition = entityplayer.blockPosition();
|
||||
|
||||
if (!world.dimensionType().hasSkyLight() || blockposition.getY() >= world.getSeaLevel() && world.canSeeSky(blockposition)) {
|
||||
@@ -59,7 +68,7 @@
|
||||
int j = Mth.clamp(serverstatisticmanager.getValue(Stats.CUSTOM.get(Stats.TIME_SINCE_REST)), 1, Integer.MAX_VALUE);
|
||||
boolean flag2 = true;
|
||||
|
||||
- if (randomsource.nextInt(j) >= 72000) {
|
||||
+ if (randomsource.nextInt(j) >= world.paperConfig().entities.behavior.playerInsomniaStartTicks) { // Paper - Ability to control player's insomnia and phantoms
|
||||
BlockPos blockposition1 = blockposition.above(20 + randomsource.nextInt(15)).east(-10 + randomsource.nextInt(21)).south(-10 + randomsource.nextInt(21));
|
||||
BlockState iblockdata = world.getBlockState(blockposition1);
|
||||
FluidState fluid = world.getFluidState(blockposition1);
|
||||
@@ -69,12 +78,22 @@
|
||||
int k = 1 + randomsource.nextInt(difficultydamagescaler.getDifficulty().getId() + 1);
|
||||
|
||||
for (int l = 0; l < k; ++l) {
|
||||
+ // Paper start - PhantomPreSpawnEvent
|
||||
+ com.destroystokyo.paper.event.entity.PhantomPreSpawnEvent event = new com.destroystokyo.paper.event.entity.PhantomPreSpawnEvent(io.papermc.paper.util.MCUtil.toLocation(world, blockposition1), entityplayer.getBukkitEntity(), org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL);
|
||||
+ if (!event.callEvent()) {
|
||||
+ if (event.shouldAbortSpawn()) {
|
||||
+ break;
|
||||
+ }
|
||||
+ continue;
|
||||
+ }
|
||||
+ // Paper end - PhantomPreSpawnEvent
|
||||
Phantom entityphantom = (Phantom) EntityType.PHANTOM.create(world, EntitySpawnReason.NATURAL);
|
||||
|
||||
if (entityphantom != null) {
|
||||
+ entityphantom.setSpawningEntity(entityplayer.getUUID()); // Paper - PhantomPreSpawnEvent
|
||||
entityphantom.moveTo(blockposition1, 0.0F, 0.0F);
|
||||
groupdataentity = entityphantom.finalizeSpawn(world, difficultydamagescaler, EntitySpawnReason.NATURAL, groupdataentity);
|
||||
- world.addFreshEntityWithPassengers(entityphantom);
|
||||
+ world.addFreshEntityWithPassengers(entityphantom, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL); // CraftBukkit
|
||||
++i;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user