mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-04 00:45:57 +00:00
implement BukkitChunkGeneratorWrapper#getFixedSpawnLocation
This commit is contained in:
parent
ef1f1c0af0
commit
f2d9511f01
@ -17,7 +17,11 @@
|
||||
|
||||
package com.dfsek.terra.bukkit.generator;
|
||||
|
||||
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.generator.BiomeProvider;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.LimitedRegion;
|
||||
@ -36,8 +40,12 @@ import com.dfsek.terra.api.world.chunk.generation.util.GeneratorWrapper;
|
||||
import com.dfsek.terra.bukkit.world.BukkitProtoWorld;
|
||||
import com.dfsek.terra.bukkit.world.BukkitWorldProperties;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGenerator implements GeneratorWrapper {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(BukkitChunkGeneratorWrapper.class);
|
||||
private final BlockState air;
|
||||
private ChunkGenerator delegate;
|
||||
private ConfigPack pack;
|
||||
@ -89,6 +97,31 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
|
||||
//return pack.vanillaFlora();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Location getFixedSpawnLocation(@NotNull World world, @NotNull Random random) {
|
||||
LOGGER.info("Getting spawn location...");
|
||||
int x = random.nextInt(-500, 500);
|
||||
int z = random.nextInt(-500, 500);
|
||||
int y = world.getMaxHeight() - 1;
|
||||
|
||||
int max = 500;
|
||||
for(int i = 0; i < max; i++) { // 50 attempts.
|
||||
BukkitWorldProperties properties = new BukkitWorldProperties(world);
|
||||
while(y > world.getMinHeight() && delegate.getBlock(properties, x, y, z, pack.getBiomeProvider()).isAir()) y--;
|
||||
|
||||
if(((BlockData) delegate.getBlock(properties, x, y, z, pack.getBiomeProvider()).getHandle()).getMaterial().isSolid()){
|
||||
break;
|
||||
} else {
|
||||
x = random.nextInt(-500, 500);
|
||||
z = random.nextInt(-500, 500);
|
||||
y = world.getMaxHeight() - 1;
|
||||
if(i % 25 == 0) LOGGER.info("Spawn finding attempt {}/{} failed. Retrying...", i, max);
|
||||
}
|
||||
}
|
||||
|
||||
return new Location(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateMobs() {
|
||||
return true;
|
||||
|
@ -15,6 +15,7 @@ import net.minecraft.world.level.GeneratorAccessSeed;
|
||||
import net.minecraft.world.level.LevelHeightAccessor;
|
||||
import net.minecraft.world.level.StructureManager;
|
||||
import net.minecraft.world.level.biome.BiomeManager;
|
||||
import net.minecraft.world.level.biome.Climate;
|
||||
import net.minecraft.world.level.biome.Climate.Sampler;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.chunk.IChunkAccess;
|
||||
@ -68,7 +69,6 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator {
|
||||
}
|
||||
|
||||
|
||||
// @SuppressWarnings("unchecked")
|
||||
@Override //buildSurface. Used to be buildBase
|
||||
public void a(RegionLimitedWorldAccess regionlimitedworldaccess, StructureManager structuremanager, IChunkAccess ichunkaccess) {
|
||||
|
||||
@ -106,7 +106,7 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator {
|
||||
|
||||
// climateSampler
|
||||
public Sampler d() {
|
||||
return vanilla.d();
|
||||
return Climate.a();
|
||||
}
|
||||
|
||||
//getMinY
|
||||
|
Loading…
x
Reference in New Issue
Block a user