Merge pull request #8 from BentoBoxWorld/tb-develop

Enables entity setting and config reloading
This commit is contained in:
BONNe 2019-02-02 22:49:59 +02:00 committed by GitHub
commit 7f60f203ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 2239 additions and 2327 deletions

1
.gitignore vendored
View File

@ -21,3 +21,4 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/target/

View File

@ -50,6 +50,7 @@ public class CaveBlock extends GameModeAddon
{
super.onReload();
this.loadSettings();
this.chunkGenerator.reload();
}

View File

@ -1,12 +1,18 @@
package world.bentobox.caveblock;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.entity.EntityType;
import java.util.*;
import world.bentobox.bentobox.api.configuration.ConfigComment;
import world.bentobox.bentobox.api.configuration.ConfigEntry;
@ -26,13 +32,13 @@ import world.bentobox.bentobox.database.objects.adapters.FlagSerializer2;
@StoreAt(filename="config.yml", path="addons/CaveBlock")
@ConfigComment("CaveBlock Configuration [version]")
@ConfigComment("This config file is dynamic and saved when the server is shutdown.")
@ConfigComment("You cannot edit it while the server is running because changes will")
@ConfigComment("be lost! Use in-game settings GUI or edit when server is offline.")
@ConfigComment("If you edit it while the server is running use /cbadmin reload")
@ConfigComment("otherwise your settings will be lost.")
public class Settings implements DataObject, WorldSettings
{
// ---------------------------------------------------------------------
// Section: Getters
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Section: Getters
// ---------------------------------------------------------------------
/**
@ -173,7 +179,7 @@ public class Settings implements DataObject, WorldSettings
@Override
public int getSeaHeight()
{
return seaHeight;
return 0;
}
@ -792,8 +798,8 @@ public class Settings implements DataObject, WorldSettings
}
// ---------------------------------------------------------------------
// Section: Setters
// ---------------------------------------------------------------------
// Section: Setters
// ---------------------------------------------------------------------
/**
@ -927,18 +933,6 @@ public class Settings implements DataObject, WorldSettings
this.useOwnGenerator = useOwnGenerator;
}
/**
* This method sets the seaHeight object value.
* @param seaHeight the seaHeight object new value.
*
*/
public void setSeaHeight(int seaHeight)
{
this.seaHeight = seaHeight;
}
/**
* This method sets the maxIslands object value.
* @param maxIslands the maxIslands object new value.
@ -1556,11 +1550,25 @@ public class Settings implements DataObject, WorldSettings
}
// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
/**
* @return the debug
*/
public boolean isDebug() {
return debug;
}
/**
* @param debug the debug to set
*/
public void setDebug(boolean debug) {
this.debug = debug;
}
// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
/* WORLD */
@ConfigComment("Friendly name for this world. Used in admin commands. Must be a single word")
@ConfigEntry(path = "world.friendly-name")
@ -1576,11 +1584,11 @@ public class Settings implements DataObject, WorldSettings
@ConfigEntry(path = "world.difficulty")
private Difficulty difficulty = Difficulty.NORMAL;
@ConfigComment("Radius of island in blocks. (So distance between islands is twice this)")
@ConfigComment("Radius of cave in blocks. (So distance between caves is twice this)")
@ConfigComment("Will be rounded up to the nearest 16 blocks.")
@ConfigComment("It is the same for every dimension : Overworld, Nether and End.")
@ConfigComment("This value cannot be changed mid-game and the plugin will not start if it is different.")
@ConfigEntry(path = "world.distance-between-islands", needsReset = true)
@ConfigEntry(path = "world.distance-between-caves", needsReset = true)
private int islandDistance = 100;
@ConfigComment("Default protection range radius in blocks. Cannot be larger than distance.")
@ -1605,9 +1613,9 @@ public class Settings implements DataObject, WorldSettings
@ConfigEntry(path = "world.offset-z")
private int islandZOffset;
@ConfigComment("Island height - Lowest is 5.")
@ConfigComment("Cave height - Lowest is 5.")
@ConfigComment("It is the y coordinate of the bedrock block in the schem.")
@ConfigEntry(path = "world.island-height")
@ConfigEntry(path = "world.cave-height")
private int islandHeight = 60;
@ConfigComment("Use your own world generator for this world.")
@ -1615,13 +1623,6 @@ public class Settings implements DataObject, WorldSettings
@ConfigEntry(path = "world.use-own-generator", experimental = true)
private boolean useOwnGenerator = true;
@ConfigComment("Sea height (don't changes this mid-game unless you delete the world)")
@ConfigComment("Minimum is 0, which means you are playing CaveBlock!")
@ConfigComment("If sea height is less than about 10, then players will drop right through it")
@ConfigComment("if it exists. Makes for an interesting variation on caveblock.")
@ConfigEntry(path = "world.sea-height", needsReset = true)
private int seaHeight = 0;
@ConfigComment("Maximum number of islands in the world. Set to -1 or 0 for unlimited.")
@ConfigComment("If the number of islands is greater than this number, it will stop players from creating islands.")
@ConfigEntry(path = "world.max-islands")
@ -1672,7 +1673,7 @@ public class Settings implements DataObject, WorldSettings
@ConfigComment("Entities spawned via generator are not protected from despawing.")
@ConfigComment("Working only with 2 high mobs currently.")
@ConfigComment("Example:")
@ConfigComment("MATERIAL:DIAMOND:100:5 - means there is 100% chace of spawing diamonds")
@ConfigComment("MATERIAL:DIAMOND_ORE:100:5 - means there is 100% chace of spawing diamonds")
@ConfigComment("where max amount in pack are 5 per each subchunk!")
@ConfigEntry(path = "world.normal.blocks", needsReset = true)
private List<String> normalBlocks = new ArrayList<>();
@ -1721,7 +1722,7 @@ public class Settings implements DataObject, WorldSettings
@ConfigComment("Entities spawned via generator are not protected from despawing.")
@ConfigComment("Working only with 2 high mobs currently.")
@ConfigComment("Example:")
@ConfigComment("MATERIAL:DIAMOND:100:5 - means there is 100% chace of spawing diamonds")
@ConfigComment("MATERIAL:DIAMOND_ORE:100:5 - means there is 100% chace of spawing diamonds")
@ConfigComment("where max amount in pack are 5 per each subchunk!")
@ConfigEntry(path = "world.nether.blocks", needsReset = true)
private List<String> netherBlocks = new ArrayList<>();
@ -1755,7 +1756,7 @@ public class Settings implements DataObject, WorldSettings
@ConfigComment("Entities spawned via generator are not protected from despawing.")
@ConfigComment("Working only with 2 high mobs currently.")
@ConfigComment("Example:")
@ConfigComment("MATERIAL:DIAMOND:100:5 - means there is 100% chace of spawing diamonds")
@ConfigComment("MATERIAL:DIAMOND_ORE:100:5 - means there is 100% chace of spawing diamonds")
@ConfigComment("where max amount in pack are 5 per each subchunk!")
@ConfigEntry(path = "world.end.blocks", needsReset = true)
private List<String> endBlocks = new ArrayList<>();
@ -1918,6 +1919,7 @@ public class Settings implements DataObject, WorldSettings
@ConfigComment("These settings should not be edited")
@ConfigEntry(path = "do-not-edit-these-settings.reset-epoch")
private long resetEpoch = 0;
private boolean debug;
private String uniqueId = "config";
}

View File

@ -1,11 +1,14 @@
package world.bentobox.caveblock.generators;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import java.util.*;
import world.bentobox.caveblock.CaveBlock;
import world.bentobox.caveblock.Settings;
@ -21,9 +24,9 @@ import world.bentobox.caveblock.generators.populators.MaterialPopulator;
*/
public class ChunkGeneratorWorld extends ChunkGenerator
{
// ---------------------------------------------------------------------
// Section: Constructor
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Section: Constructor
// ---------------------------------------------------------------------
/**
@ -35,16 +38,13 @@ public class ChunkGeneratorWorld extends ChunkGenerator
this.addon = addon;
this.settings = addon.getSettings();
this.blockPopulators = new ArrayList<>(1);
this.blockPopulators.add(new MaterialPopulator(this.addon));
this.blockPopulators.add(new EntitiesPopulator(this.addon));
reload();
}
// ---------------------------------------------------------------------
// Section: Methods
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Section: Methods
// ---------------------------------------------------------------------
@ -187,10 +187,20 @@ public class ChunkGeneratorWorld extends ChunkGenerator
return this.blockPopulators;
}
/**
* Called when config is reloaded
*/
public void reload() {
this.blockPopulators = new ArrayList<>(2);
// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
this.blockPopulators.add(new MaterialPopulator(this.addon));
this.blockPopulators.add(new EntitiesPopulator(this.addon));
}
// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
/**
@ -207,4 +217,6 @@ public class ChunkGeneratorWorld extends ChunkGenerator
* This list contains block populators that will be applied after chunk is generated.
*/
private List<BlockPopulator> blockPopulators;
}

View File

@ -13,27 +13,23 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.util.BoundingBox;
import world.bentobox.bentobox.util.Pair;
import world.bentobox.caveblock.CaveBlock;
import world.bentobox.caveblock.Settings;
/**
* This class populates generated chunk with enitites by random chance.
* This class populates generated chunk with entites by random chance.
*/
public class EntitiesPopulator extends BlockPopulator
{
private Map<Environment, Chances> chances;
private final int generationTry;
private int worldHeight;
/**
* This is default constructor
* @param addon CaveBlock addon.
@ -41,18 +37,21 @@ public class EntitiesPopulator extends BlockPopulator
public EntitiesPopulator(CaveBlock addon)
{
this.addon = addon;
this.settings = addon.getSettings();
loadSettings();
}
public void loadSettings() {
// Set up chances
chances = new HashMap<>();
// Normal
chances.put(Environment.NORMAL, new Chances(this.getEntityMap(this.settings.getNormalBlocks()), this.settings.getNormalMainBlock()));
chances.put(Environment.NORMAL, new Chances(this.getEntityMap(addon.getSettings().getNormalBlocks()), addon.getSettings().getNormalMainBlock()));
// Nether
chances.put(Environment.NETHER, new Chances(this.getEntityMap(this.settings.getNetherBlocks()), this.settings.getNetherMainBlock()));
chances.put(Environment.NETHER, new Chances(this.getEntityMap(addon.getSettings().getNetherBlocks()), addon.getSettings().getNetherMainBlock()));
// End
chances.put(Environment.THE_END, new Chances(this.getEntityMap(this.settings.getEndBlocks()), this.settings.getEndMainBlock()));
chances.put(Environment.THE_END, new Chances(this.getEntityMap(addon.getSettings().getEndBlocks()), addon.getSettings().getEndMainBlock()));
// Other settings
generationTry = this.settings.getNumberOfBlockGenerationTries();
worldHeight = this.settings.getWorldDepth() - 1;
worldHeight = addon.getSettings().getWorldDepth() - 1;
}
@ -65,20 +64,16 @@ public class EntitiesPopulator extends BlockPopulator
@Override
public void populate(World world, Random random, Chunk chunk)
{
for (Map.Entry<EntityType, Pair<Integer, Integer>> entry : chances.get(world.getEnvironment()).entityChanceMap.entrySet())
for (Map.Entry<EntityType, Pair<Double, Integer>> entry : chances.get(world.getEnvironment()).entityChanceMap.entrySet())
{
for (int subY = 0; subY < worldHeight; subY += 16)
{
for (int tries = 0; tries < generationTry; tries++)
// Use double so chance can be < 1
if (random.nextDouble() * 100 < entry.getValue().x)
{
if (random.nextInt(100) < entry.getValue().x)
{
int x = random.nextInt(15);
int z = random.nextInt(15);
int y = Math.min(worldHeight - 2, subY + random.nextInt(15));
this.tryToPlaceEntity(world, chunk.getBlock(x, y, z), entry.getKey(), x, z, chances.get(world.getEnvironment()).mainMaterial);
}
// Spawn only in middle of chunk because bounding box will grow out from here
this.tryToPlaceEntity(world, chunk.getBlock(7, y, 7), entry.getKey(), chances.get(world.getEnvironment()).mainMaterial);
}
}
}
@ -90,9 +85,9 @@ public class EntitiesPopulator extends BlockPopulator
* @param objectList List with objects that contains data.
* @return Map that contains entity, its rarity and pack size.
*/
private Map<EntityType, Pair<Integer, Integer>> getEntityMap(List<String> objectList)
private Map<EntityType, Pair<Double, Integer>> getEntityMap(List<String> objectList)
{
Map<EntityType, Pair<Integer, Integer>> entityMap = new HashMap<>(objectList.size());
Map<EntityType, Pair<Double, Integer>> entityMap = new HashMap<>(objectList.size());
Map<String, EntityType> entityTypeMap = Arrays.stream(EntityType.values()).
collect(Collectors.toMap(Enum::name,
@ -111,148 +106,53 @@ public class EntitiesPopulator extends BlockPopulator
if (entity != null)
{
entityMap.put(entity,
new Pair<>(Integer.parseInt(splitString[2]), Integer.parseInt(splitString[3])));
new Pair<>(Double.parseDouble(splitString[2]), Integer.parseInt(splitString[3])));
}
});
return entityMap;
}
/**
* This method checks if all chunks around given block is generated.
* @param world World in which block is located
* @param block Block that must be checked.
* @param x Block x-index in chunk
* @param z Block z-index in chunk
* @return true, if all chunks around given block are generated.
*/
private boolean isValidBlock(World world, Block block, int x, int z)
{
return x > 0 && x < 15 && z > 0 && z < 15 ||
world.isChunkGenerated(block.getX() + 1, block.getZ()) &&
world.isChunkGenerated(block.getX() - 1, block.getZ()) &&
world.isChunkGenerated(block.getX(), block.getZ() - 1) &&
world.isChunkGenerated(block.getX(), block.getZ() + 1);
}
/**
* This method is not completed. It must reserve space for entities to spawn, but
* current implementation just allows to spawn 2 high mobs that can be in single
* place.
* Places entities if there is room for them.
* @param world - World were mob must be spawned.
* @param block - Block that was choosed by random.
* @param block - Block that was chosen by random.
* @param entity - Entity that must be spawned.
* @param x - ChunkX coordinate.
* @param z - ChunkY coordinate.
* @param originalMaterial - replacement manterial.
* @param originalMaterial - replacement material.
*/
private void tryToPlaceEntity(World world, Block block, EntityType entity, int x, int z, Material originalMaterial)
private void tryToPlaceEntity(World world, Block block, EntityType entity, Material originalMaterial)
{
if (this.isValidBlock(world, block, x, z) && block.getType().equals(originalMaterial))
{
if (entity.isAlive())
{
int height = 0;
int width = 0;
int length = 0;
boolean water = false;
switch (entity)
{
case SPIDER:
width = 1;
length = 1;
break;
case SLIME:
case ELDER_GUARDIAN:
case GHAST:
case MAGMA_CUBE:
case WITHER:
height = 2;
width = 2;
length = 2;
break;
case ENDERMAN:
case IRON_GOLEM:
height = 2;
break;
case WITHER_SKELETON:
case STRAY:
case HUSK:
case ZOMBIE_VILLAGER:
case EVOKER:
case VINDICATOR:
case ILLUSIONER:
case CREEPER:
case SKELETON:
case ZOMBIE:
case BLAZE:
case SNOWMAN:
case VILLAGER:
case PIG_ZOMBIE:
case WITCH:
case SHULKER:
case SHEEP:
case COW:
case MUSHROOM_COW:
height = 12;
break;
case SKELETON_HORSE:
case ZOMBIE_HORSE:
case DONKEY:
case MULE:
case HORSE:
case POLAR_BEAR:
case LLAMA:
height = 1;
width = 1;
break;
case GUARDIAN:
case SQUID:
case COD:
case SALMON:
case PUFFERFISH:
case TROPICAL_FISH:
water = true;
break;
case DROWNED:
case DOLPHIN:
water = true;
height = 1;
break;
default:
break;
if (block.getType().equals(originalMaterial)) {
// Spawn entity
Entity e = world.spawnEntity(block.getLocation().add(0.5, 0, 0.5), entity);
if (e instanceof LivingEntity) {
// Do not despawn
((LivingEntity)e).setRemoveWhenFarAway(false);
}
Block otherBlock = world.getBlockAt(block.getX(), block.getY() + 1, block.getZ());
if (!otherBlock.getType().equals(originalMaterial))
{
otherBlock = world.getBlockAt(block.getX(), block.getY() - 1, block.getZ());
// Make space for entity based on the entity's size
BoundingBox bb = e.getBoundingBox();
for (int x = (int) bb.getMinX(); x < bb.getMaxX(); x++) {
for (int z = (int) bb.getMinZ(); z < bb.getMaxZ(); z++) {
int y = (int) bb.getMinY();
Block b = world.getBlockAt(x, y, z);
for (; y < bb.getMaxY(); y++) {
if (addon.getSettings().isDebug()) {
addon.log("DEBUG: Entity spawn: " + world.getName() + " " + x + " " + y + " " + z + " " + e.getType());
}
if (otherBlock.getType().equals(originalMaterial))
{
block.setType(Material.CAVE_AIR);
otherBlock.setType(Material.CAVE_AIR);
if (otherBlock.getY() < block.getY())
{
world.spawnEntity(otherBlock.getLocation(), entity);
b = world.getBlockAt(x, y, z);
if (!b.getType().equals(originalMaterial)) {
// Cannot place entity
e.remove();
return;
}
else
{
world.spawnEntity(block.getLocation(), entity);
b.setType(WATER_ENTITIES.contains(entity) ? Material.WATER : Material.CAVE_AIR);
}
// Add air block on top for all water entities (required for dolphin, okay for others)
if (WATER_ENTITIES.contains(entity) && b.getRelative(BlockFace.UP).getType().equals(originalMaterial)) {
b.getRelative(BlockFace.UP).setType(Material.CAVE_AIR);
}
}
}
else
{
block.setType(Material.CAVE_AIR);
world.spawnEntity(block.getLocation(), entity);
}
}
}
@ -267,24 +167,32 @@ public class EntitiesPopulator extends BlockPopulator
*/
private CaveBlock addon;
/**
* CaveBlock settings.
*/
private Settings settings;
private Map<Environment, Chances> chances;
private int worldHeight;
private final static List<EntityType> WATER_ENTITIES = Arrays.asList(EntityType.GUARDIAN,
EntityType.SQUID,
EntityType.COD,
EntityType.SALMON,
EntityType.PUFFERFISH,
EntityType.TROPICAL_FISH,
EntityType.DROWNED,
EntityType.DOLPHIN);
/**
* Chances class to store chances for environments and main material
*
*/
private class Chances {
final Map<EntityType, Pair<Integer, Integer>> entityChanceMap;
final Map<EntityType, Pair<Double, Integer>> entityChanceMap;
final Material mainMaterial;
/**
* @param materialChanceMap
* @param mainMaterial
*/
public Chances(Map<EntityType, Pair<Integer, Integer>> entityChanceMap, Material mainMaterial) {
public Chances(Map<EntityType, Pair<Double, Integer>> entityChanceMap, Material mainMaterial) {
this.entityChanceMap = entityChanceMap;
this.mainMaterial = mainMaterial;
}

View File

@ -16,7 +16,6 @@ import org.bukkit.generator.BlockPopulator;
import world.bentobox.bentobox.util.Pair;
import world.bentobox.caveblock.CaveBlock;
import world.bentobox.caveblock.Settings;
/**
@ -24,11 +23,6 @@ import world.bentobox.caveblock.Settings;
*/
public class MaterialPopulator extends BlockPopulator
{
private Map<Environment, Chances> chances;
private final int generationTry;
private int worldHeight;
/**
* This is default constructor
@ -37,19 +31,25 @@ public class MaterialPopulator extends BlockPopulator
public MaterialPopulator(CaveBlock addon)
{
this.addon = addon;
this.settings = addon.getSettings();
// Load settings
loadSettings();
}
/**
* Loads chances for Material Populator
*/
public void loadSettings() {
// Set up chances
chances = new HashMap<>();
// Normal
chances.put(Environment.NORMAL, new Chances(this.getMaterialMap(this.settings.getNormalBlocks()), this.settings.getNormalMainBlock()));
chances.put(Environment.NORMAL, new Chances(this.getMaterialMap(addon.getSettings().getNormalBlocks()), addon.getSettings().getNormalMainBlock()));
// Nether
chances.put(Environment.NETHER, new Chances(this.getMaterialMap(this.settings.getNetherBlocks()), this.settings.getNetherMainBlock()));
chances.put(Environment.NETHER, new Chances(this.getMaterialMap(addon.getSettings().getNetherBlocks()), addon.getSettings().getNetherMainBlock()));
// End
chances.put(Environment.THE_END, new Chances(this.getMaterialMap(this.settings.getEndBlocks()), this.settings.getEndMainBlock()));
chances.put(Environment.THE_END, new Chances(this.getMaterialMap(addon.getSettings().getEndBlocks()), addon.getSettings().getEndMainBlock()));
// Other settings
generationTry = this.settings.getNumberOfBlockGenerationTries();
worldHeight = this.settings.getWorldDepth() - 1;
worldHeight = addon.getSettings().getWorldDepth() - 1;
}
@ -62,22 +62,26 @@ public class MaterialPopulator extends BlockPopulator
@Override
public void populate(World world, Random random, Chunk chunk)
{
for (Map.Entry<Material, Pair<Integer, Integer>> entry : chances.get(world.getEnvironment()).materialChanceMap.entrySet())
for (Map.Entry<Material, Pair<Double, Integer>> entry : chances.get(world.getEnvironment()).materialChanceMap.entrySet())
{
for (int subY = 0; subY < worldHeight; subY += 16)
for (int subY = 1; subY < worldHeight; subY += 16)
{
for (int tries = 0; tries < generationTry; tries++)
if (random.nextDouble() * 100 < entry.getValue().x)
{
if (random.nextInt(100) < entry.getValue().x)
{
int x = random.nextInt(15);
int z = random.nextInt(15);
int y = Math.min(worldHeight - 2, subY + random.nextInt(15));
// Blocks must be 1 away from edge to avoid adjacent chunk loading
int x = random.nextInt(13) + 1;
int z = random.nextInt(13) + 1;
int y = Math.min(worldHeight - 2, subY + random.nextInt(15));
/*
* TODO: remove
if (addon.getSettings().isDebug()) {
addon.log("DEBUG: Material: " + world.getName() + " " + x + " " + y + " " + z + " " + entry.getKey());
}
*/
Block block = chunk.getBlock(x, y, z);
if (block.getType().equals(chances.get(world.getEnvironment()).mainMaterial) &&
this.isValidBlock(world, block, x, z))
if (block.getType().equals(chances.get(world.getEnvironment()).mainMaterial))
{
int packSize = random.nextInt(entry.getValue().z);
@ -116,8 +120,7 @@ public class MaterialPopulator extends BlockPopulator
block = chunk.getBlock(x, y, z);
continuePlacing = this.isValidBlock(world, block, x, z) &&
packSize > 0 &&
continuePlacing = packSize > 0 &&
(block.getType().equals(chances.get(world.getEnvironment()).mainMaterial) ||
block.getType().equals(entry.getKey()));
}
@ -126,35 +129,15 @@ public class MaterialPopulator extends BlockPopulator
}
}
}
}
/**
* This method checks if all chunks around given block is generated.
* @param world World in which block is located
* @param block Block that must be checked.
* @param x Block x-index in chunk
* @param z Block z-index in chunk
* @return true, if all chunks around given block are generated.
*/
private boolean isValidBlock(World world, Block block, int x, int z)
{
return x > 0 && x < 15 && z > 0 && z < 15 ||
world.isChunkGenerated(block.getX() + 1, block.getZ()) &&
world.isChunkGenerated(block.getX() - 1, block.getZ()) &&
world.isChunkGenerated(block.getX(), block.getZ() - 1) &&
world.isChunkGenerated(block.getX(), block.getZ() + 1);
}
/**
* This method returns material frequently and pack size map.
* @param objectList List with objects that contains data.
* @return Map that contains material, its rarity and pack size.
*/
private Map<Material, Pair<Integer, Integer>> getMaterialMap(List<String> objectList)
private Map<Material, Pair<Double, Integer>> getMaterialMap(List<String> objectList)
{
Map<Material, Pair<Integer, Integer>> materialMap = new HashMap<>(objectList.size());
Map<Material, Pair<Double, Integer>> materialMap = new HashMap<>(objectList.size());
// wrong material object.
objectList.stream().
@ -167,7 +150,7 @@ public class MaterialPopulator extends BlockPopulator
if (material != null)
{
materialMap.put(material,
new Pair<>(Integer.parseInt(splitString[2]), Integer.parseInt(splitString[3])));
new Pair<>(Double.parseDouble(splitString[2]), Integer.parseInt(splitString[3])));
}
});
@ -185,25 +168,23 @@ public class MaterialPopulator extends BlockPopulator
*/
private CaveBlock addon;
/**
* CaveBlock settings.
*/
private Settings settings;
private Map<Environment, Chances> chances;
private int worldHeight;
/**
* Chances class to store chances for environments and main material
*
*/
private class Chances {
final Map<Material, Pair<Integer, Integer>> materialChanceMap;
final Map<Material, Pair<Double, Integer>> materialChanceMap;
final Material mainMaterial;
/**
* @param materialChanceMap
* @param mainMaterial
*/
public Chances(Map<Material, Pair<Integer, Integer>> materialChanceMap, Material mainMaterial) {
public Chances(Map<Material, Pair<Double, Integer>> materialChanceMap, Material mainMaterial) {
this.materialChanceMap = materialChanceMap;
this.mainMaterial = mainMaterial;
}

View File

@ -11,11 +11,11 @@ world:
# World difficulty setting - PEACEFUL, EASY, NORMAL, HARD
# Other plugins may override this setting
difficulty: NORMAL
# Radius of island in blocks. (So distance between islands is twice this)
# Radius of cave in blocks. (So distance between caves is twice this)
# Will be rounded up to the nearest 16 blocks.
# It is the same for every dimension : Overworld, Nether and End.
# This value cannot be changed mid-game and the plugin will not start if it is different.
distance-between-islands: 64
distance-between-caves: 64
# Default protection range radius in blocks. Cannot be larger than distance.
# Admins can change protection sizes for players individually using /cbadmin range set <player> <new range>
# or set this permission: caveblock.island.range.<number>
@ -29,18 +29,13 @@ world:
start-z: 0
offset-x: 0
offset-z: 0
# Island height - Lowest is 5.
# Cave height - Lowest is 5.
# It is the y coordinate of the bedrock block in the schem.
island-height: 60
cave-height: 60
# Use your own world generator for this world.
# In this case, the plugin will not generate anything.
# /!\ This feature is experimental and might not work as expected or might not work at all.
use-own-generator: true
# Sea height (don't changes this mid-game unless you delete the world)
# Minimum is 0, which means you are playing CaveBlock!
# If sea height is less than about 10, then players will drop right through it
# if it exists. Makes for an interesting variation on caveblock.
sea-height: 0
# Maximum number of islands in the world. Set to -1 or 0 for unlimited.
# If the number of islands is greater than this number, it will stop players from creating islands.
max-islands: 0
@ -74,11 +69,11 @@ world:
# Entities spawned via generator are not protected from despawing.
# Working only with 2 high mobs currently.
# Example:
# MATERIAL:DIAMOND:100:5 - means there is 100% chace of spawing diamonds
# MATERIAL:DIAMOND_ORE:100:5 - means there is 100% chace of spawing diamonds
# where max amount in pack are 5 per each subchunk!
blocks:
- MATERIAL:DIAMOND_ORE:1:3
- MATERIAL:GOLD_ORE:5:4
- MATERIAL:DIAMOND_ORE:1:5
- MATERIAL:GOLD_ORE:1:4
- MATERIAL:IRON_ORE:5:4
- MATERIAL:COAL_ORE:10:6
- MATERIAL:EMERALD_ORE:1:1
@ -88,6 +83,9 @@ world:
- MATERIAL:GRANITE:20:10
- MATERIAL:ANDESITE:20:10
- MATERIAL:DIORITE:30:8
- ENTITY:ZOMBIE:1:1
- ENTITY:DOLPHIN:0.1:1
- ENTITY:CAVE_SPIDER:1:1
nether:
# Generate Nether - if this is false, the nether world will not be made and access to
# the nether will not occur. Other plugins may still enable portal usage.
@ -118,14 +116,19 @@ world:
# Entities spawned via generator are not protected from despawing.
# Working only with 2 high mobs currently.
# Example:
# MATERIAL:DIAMOND:100:5 - means there is 100% chace of spawing diamonds
# MATERIAL:DIAMOND_ORE:100:5 - means there is 100% chace of spawing diamonds
# where max amount in pack are 5 per each subchunk!
blocks:
- MATERIAL:QUARTZ_ORE:30:5
- MATERIAL:SOUL_SAND:40:10
- MATERIAL:MAGMA_BLOCK:10:3
- MATERIAL:GLOWSTONE:20:8
- MATERIAL:NETHER_BRICK:10:5
- MATERIAL:LAVA:10:1
- ENTITY:MAGMA_CUBE:0.5:1
- ENTITY:GHAST:0.1:1
- ENTITY:WITHER_SKELETON:0.1:1
- MATERIAL:FIRE:10:1
end:
generate: true
islands: true
@ -144,14 +147,16 @@ world:
# Entities spawned via generator are not protected from despawing.
# Working only with 2 high mobs currently.
# Example:
# MATERIAL:DIAMOND:100:5 - means there is 100% chace of spawing diamonds
# MATERIAL:DIAMOND_ORE:100:5 - means there is 100% chace of spawing diamonds
# where max amount in pack are 5 per each subchunk!
blocks:
- ENTITY:SHULKER:1:1
- ENTITY:SHULKER:0.2:1
- MATERIAL:OBSIDIAN:1:1
- MATERIAL:CHORUS_FRUIT:1:3
# Mob white list - these mobs will NOT be removed when logging in or doing /cave
remove-mobs-whitelist:
- ZOMBIE_VILLAGER
- WITHER
- ZOMBIE_VILLAGER
- PIG_ZOMBIE
- ENDERMAN
# World flags. These are boolean settings for various flags for this world
@ -193,8 +198,8 @@ world:
FROST_WALKER: 500
COLLECT_LAVA: 500
LEVER: 500
HURT_MONSTERS: 0
RIDING: 500
HURT_MONSTERS: 0
NAME_TAG: 500
ARMOR_STAND: 500
TRADING: 0
@ -202,8 +207,8 @@ world:
ITEM_DROP: 0
NOTE_BLOCK: 0
NETHER_PORTAL: 500
ITEM_PICKUP: 0
CROP_TRAMPLE: 500
ITEM_PICKUP: 0
BREWING: 500
DROPPER: 500
COLLECT_WATER: 500
@ -215,26 +220,27 @@ world:
PLACE_BLOCKS: 500
ITEM_FRAME: 500
CRAFTING: 0
SHEARING: 500
ENCHANTING: 0
SPAWN_EGGS: 500
SHEARING: 500
BED: 500
SPAWN_EGGS: 500
MILKING: 0
DISPENSER: 500
GATE: 0
EXPERIENCE_PICKUP: 500
HOPPER: 500
LEASH: 500
MOUNT_INVENTORY: 500
BREAK_BLOCKS: 500
MOUNT_INVENTORY: 500
CHORUS_FRUIT: 500
CONTAINER: 500
POTION_THROWING: 500
JUKEBOX: 500
# These are the default settings for new islands
default-island-settings:
PVP_END: false
ANIMAL_SPAWN: true
PVP_NETHER: false
ANIMAL_SPAWN: true
MONSTER_SPAWN: true
FIRE_SPREAD: true
PVP_OVERWORLD: false
@ -350,4 +356,5 @@ panel:
do-not-edit-these-settings:
# These settings should not be edited
reset-epoch: 0
debug: false
uniqueId: config