mirror of
https://github.com/BentoBoxWorld/AcidIsland.git
synced 2024-11-25 20:25:37 +01:00
Version that has an ocen floor and uses new generator methods
This commit is contained in:
parent
f51ff4165b
commit
ea16a45114
@ -5,8 +5,10 @@ import java.util.Objects;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.entity.SpawnCategory;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.generator.BiomeProvider;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
@ -14,6 +16,7 @@ import org.eclipse.jdt.annotation.Nullable;
|
||||
import world.bentobox.acidisland.commands.IslandAboutCommand;
|
||||
import world.bentobox.acidisland.listeners.AcidEffect;
|
||||
import world.bentobox.acidisland.listeners.LavaCheck;
|
||||
import world.bentobox.acidisland.world.AcidBiomeProvider;
|
||||
import world.bentobox.acidisland.world.AcidTask;
|
||||
import world.bentobox.acidisland.world.ChunkGeneratorWorld;
|
||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
@ -34,6 +37,7 @@ public class AcidIsland extends GameModeAddon {
|
||||
private @Nullable AcidTask acidTask;
|
||||
private @Nullable ChunkGenerator chunkGenerator;
|
||||
private final Config<AISettings> config = new Config<>(this, AISettings.class);
|
||||
private BiomeProvider biomeProvider;
|
||||
|
||||
private static final String NETHER = "_nether";
|
||||
private static final String THE_END = "_the_end";
|
||||
@ -44,10 +48,11 @@ public class AcidIsland extends GameModeAddon {
|
||||
saveDefaultConfig();
|
||||
// Load settings from config.yml. This will check if there are any issues with it too.
|
||||
loadSettings();
|
||||
// Make the biome provider
|
||||
this.biomeProvider = new AcidBiomeProvider(this);
|
||||
// Chunk generator
|
||||
chunkGenerator = settings.isUseOwnGenerator() ? null : new ChunkGeneratorWorld(this);
|
||||
// Register commands
|
||||
// Register commands
|
||||
playerCommand = new DefaultPlayerCommand(this)
|
||||
|
||||
{
|
||||
@ -72,6 +77,7 @@ public class AcidIsland extends GameModeAddon {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -147,22 +153,22 @@ public class AcidIsland extends GameModeAddon {
|
||||
// Set spawn rates
|
||||
if (w != null && getSettings() != null) {
|
||||
if (getSettings().getSpawnLimitMonsters() > 0) {
|
||||
w.setMonsterSpawnLimit(getSettings().getSpawnLimitMonsters());
|
||||
w.setSpawnLimit(SpawnCategory.MONSTER, getSettings().getSpawnLimitMonsters());
|
||||
}
|
||||
if (getSettings().getSpawnLimitAmbient() > 0) {
|
||||
w.setAmbientSpawnLimit(getSettings().getSpawnLimitAmbient());
|
||||
w.setSpawnLimit(SpawnCategory.AMBIENT, getSettings().getSpawnLimitAmbient());
|
||||
}
|
||||
if (getSettings().getSpawnLimitAnimals() > 0) {
|
||||
w.setAnimalSpawnLimit(getSettings().getSpawnLimitAnimals());
|
||||
w.setSpawnLimit(SpawnCategory.ANIMAL, getSettings().getSpawnLimitAnimals());
|
||||
}
|
||||
if (getSettings().getSpawnLimitWaterAnimals() > 0) {
|
||||
w.setWaterAnimalSpawnLimit(getSettings().getSpawnLimitWaterAnimals());
|
||||
w.setSpawnLimit(SpawnCategory.WATER_ANIMAL, getSettings().getSpawnLimitWaterAnimals());
|
||||
}
|
||||
if (getSettings().getTicksPerAnimalSpawns() > 0) {
|
||||
w.setTicksPerAnimalSpawns(getSettings().getTicksPerAnimalSpawns());
|
||||
w.setTicksPerSpawns(SpawnCategory.ANIMAL, getSettings().getTicksPerAnimalSpawns());
|
||||
}
|
||||
if (getSettings().getTicksPerMonsterSpawns() > 0) {
|
||||
w.setTicksPerMonsterSpawns(getSettings().getTicksPerMonsterSpawns());
|
||||
w.setTicksPerSpawns(SpawnCategory.MONSTER, getSettings().getTicksPerMonsterSpawns());
|
||||
}
|
||||
}
|
||||
return w;
|
||||
@ -201,4 +207,8 @@ public class AcidIsland extends GameModeAddon {
|
||||
// Save settings. This will occur after all addons have loaded
|
||||
this.saveWorldSettings();
|
||||
}
|
||||
|
||||
public BiomeProvider getBiomeProvider() {
|
||||
return this.biomeProvider;
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ public class AcidEffect implements Listener {
|
||||
public void onSeaBounce(PlayerMoveEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
if (!player.getGameMode().equals(GameMode.CREATIVE) && !player.getGameMode().equals(GameMode.SPECTATOR)
|
||||
&& player.getWorld().equals(addon.getOverWorld()) && player.getLocation().getBlockY() < 1) {
|
||||
&& player.getWorld().equals(addon.getOverWorld()) && player.getLocation().getBlockY() < player.getWorld().getMinHeight()) {
|
||||
player.setVelocity(new Vector(player.getVelocity().getX(), 1D, player.getVelocity().getZ()));
|
||||
}
|
||||
}
|
||||
@ -326,7 +326,7 @@ public class AcidEffect implements Listener {
|
||||
|
||||
if (im instanceof Damageable d) {
|
||||
d.setDamage(d.getDamage() + 1);
|
||||
item.setItemMeta((ItemMeta) d);
|
||||
item.setItemMeta(d);
|
||||
return d.getDamage() >= item.getType().getMaxDurability();
|
||||
}
|
||||
return false;
|
||||
|
@ -0,0 +1,45 @@
|
||||
package world.bentobox.acidisland.world;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.BiomeProvider;
|
||||
import org.bukkit.generator.WorldInfo;
|
||||
|
||||
import world.bentobox.acidisland.AcidIsland;
|
||||
|
||||
/**
|
||||
* Biome provider for AcidIsland
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class AcidBiomeProvider extends BiomeProvider {
|
||||
|
||||
private final AcidIsland addon;
|
||||
|
||||
/**
|
||||
* @param addon Addon
|
||||
*/
|
||||
public AcidBiomeProvider(AcidIsland addon) {
|
||||
this.addon = addon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(WorldInfo worldInfo, int x, int y, int z) {
|
||||
return switch(worldInfo.getEnvironment()) {
|
||||
default -> addon.getSettings().getDefaultBiome();
|
||||
case NETHER -> addon.getSettings().getDefaultNetherBiome();
|
||||
case THE_END -> addon.getSettings().getDefaultEndBiome();
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Biome> getBiomes(WorldInfo worldInfo) {
|
||||
return switch(worldInfo.getEnvironment()) {
|
||||
default -> List.of(addon.getSettings().getDefaultBiome());
|
||||
case NETHER -> List.of(addon.getSettings().getDefaultNetherBiome());
|
||||
case THE_END -> List.of(addon.getSettings().getDefaultEndBiome());
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@ -10,11 +10,13 @@ import java.util.Random;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.BiomeProvider;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.generator.WorldInfo;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.bukkit.util.noise.PerlinOctaveGenerator;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
||||
import world.bentobox.acidisland.AcidIsland;
|
||||
|
||||
@ -29,7 +31,8 @@ public class ChunkGeneratorWorld extends ChunkGenerator {
|
||||
private final Random rand = new Random();
|
||||
private final Map<Environment, WorldConfig> seaHeight = new EnumMap<>(Environment.class);
|
||||
private final Map<Vector, Material> roofChunk = new HashMap<>();
|
||||
|
||||
private PerlinOctaveGenerator gen;
|
||||
|
||||
private record WorldConfig(int seaHeight, Material waterBlock) {}
|
||||
|
||||
/**
|
||||
@ -41,38 +44,69 @@ public class ChunkGeneratorWorld extends ChunkGenerator {
|
||||
seaHeight.put(Environment.NORMAL, new WorldConfig(addon.getSettings().getSeaHeight(), addon.getSettings().getWaterBlock()));
|
||||
seaHeight.put(Environment.NETHER, new WorldConfig(addon.getSettings().getNetherSeaHeight(), addon.getSettings().getNetherWaterBlock()));
|
||||
seaHeight.put(Environment.THE_END, new WorldConfig(addon.getSettings().getEndSeaHeight(), addon.getSettings().getEndWaterBlock()));
|
||||
rand.setSeed(System.currentTimeMillis());
|
||||
gen = new PerlinOctaveGenerator((long) (rand.nextLong() * rand.nextGaussian()), 8);
|
||||
gen.setScale(1.0/30.0);
|
||||
makeNetherRoof();
|
||||
}
|
||||
|
||||
public ChunkData generateChunks(World world) {
|
||||
ChunkData result = createChunkData(world);
|
||||
WorldConfig wc = seaHeight.get(world.getEnvironment());
|
||||
int sh = wc.seaHeight();
|
||||
if (sh > world.getMinHeight()) {
|
||||
result.setRegion(0, world.getMinHeight(), 0, 16, sh + 1, 16, wc.waterBlock());
|
||||
}
|
||||
if (world.getEnvironment().equals(Environment.NETHER) && addon.getSettings().isNetherRoof()) {
|
||||
roofChunk.forEach((k,v) -> result.setBlock(k.getBlockX(), world.getMaxHeight() + k.getBlockY(), k.getBlockZ(), v));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, BiomeGrid biomeGrid) {
|
||||
setBiome(world, biomeGrid);
|
||||
return generateChunks(world);
|
||||
}
|
||||
|
||||
private void setBiome(World world, BiomeGrid biomeGrid) {
|
||||
Biome biome = world.getEnvironment() == Environment.NORMAL ? addon.getSettings().getDefaultBiome() :
|
||||
world.getEnvironment() == Environment.NETHER ? addon.getSettings().getDefaultNetherBiome() : addon.getSettings().getDefaultEndBiome();
|
||||
for (int x = 0; x < 16; x+=4) {
|
||||
for (int z = 0; z < 16; z+=4) {
|
||||
for (int y = world.getMinHeight(); y < world.getMaxHeight(); y+=4) {
|
||||
biomeGrid.setBiome(x, y, z, biome);
|
||||
public void generateNoise(@NonNull WorldInfo worldInfo, @NonNull Random random, int chunkX, int chunkZ, @NonNull ChunkData chunkData) {
|
||||
WorldConfig wc = seaHeight.get(worldInfo.getEnvironment());
|
||||
int sh = wc.seaHeight();
|
||||
if (sh > worldInfo.getMinHeight()) {
|
||||
chunkData.setRegion(0, worldInfo.getMinHeight(), 0, 16, worldInfo.getMinHeight() + 1, 16, Material.BEDROCK);
|
||||
chunkData.setRegion(0, worldInfo.getMinHeight() + 1, 0, 16, sh + 1, 16, wc.waterBlock());
|
||||
// Add some noise
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
int n = (int)(25 * gen.noise((chunkX << 4) + x, (chunkZ << 4) + z, 0.5, 0.5, true));
|
||||
for (int y = worldInfo.getMinHeight(); y < 25 + n; y++) {
|
||||
chunkData.setBlock(x, y, z, rand.nextBoolean() ? Material.SAND : Material.SANDSTONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if (worldInfo.getEnvironment().equals(Environment.NETHER) && addon.getSettings().isNetherRoof()) {
|
||||
roofChunk.forEach((k,v) -> chunkData.setBlock(k.getBlockX(), worldInfo.getMaxHeight() + k.getBlockY(), k.getBlockZ(), v));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateBedrock() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateNoise() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean shouldGenerateSurface() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean shouldGenerateCaves() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean shouldGenerateDecorations() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean shouldGenerateMobs() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean shouldGenerateStructures() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeProvider getDefaultBiomeProvider(WorldInfo worldInfo) {
|
||||
return addon.getBiomeProvider();
|
||||
}
|
||||
|
||||
// This needs to be set to return true to override minecraft's default
|
||||
@ -91,8 +125,6 @@ public class ChunkGeneratorWorld extends ChunkGenerator {
|
||||
* Nether Section
|
||||
*/
|
||||
private void makeNetherRoof() {
|
||||
rand.setSeed(System.currentTimeMillis());
|
||||
PerlinOctaveGenerator gen = new PerlinOctaveGenerator((long) (rand.nextLong() * rand.nextGaussian()), 8);
|
||||
|
||||
// Make the roof - common across the world
|
||||
for (int x = 0; x < 16; x++) {
|
||||
@ -161,4 +193,5 @@ public class ChunkGeneratorWorld extends ChunkGenerator {
|
||||
private void setBlock(int x, int y, int z, Material m) {
|
||||
roofChunk.put(new Vector(x, y, z), m);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user