diff options
Diffstat (limited to 'src/main')
4 files changed, 33 insertions, 18 deletions
| diff --git a/src/main/java/com/MylesAndMore/Tumble/commands/Join.java b/src/main/java/com/MylesAndMore/Tumble/commands/Join.java index f26d4e5..8d14ed3 100644 --- a/src/main/java/com/MylesAndMore/Tumble/commands/Join.java +++ b/src/main/java/com/MylesAndMore/Tumble/commands/Join.java @@ -96,11 +96,10 @@ public class Join implements SubCommand, CommandExecutor, TabCompleter {                  // A game is taking place in this arena, check that it is the right type                  if (arena.game.type == type) {                      game = arena.game; -                } -                else { +                } else {                      sender.sendMessage(LanguageManager.fromKey("another-type-in-arena") -                            .replace("%type%",type.toString()) -                            .replace("%arena%",arenaName)); +                            .replace("%type%", arena.game.type.toString()) +                            .replace("%arena%", arenaName));                      return false;                  }              } diff --git a/src/main/java/com/MylesAndMore/Tumble/config/LayerManager.java b/src/main/java/com/MylesAndMore/Tumble/config/LayerManager.java index f20df6e..442f3b0 100644 --- a/src/main/java/com/MylesAndMore/Tumble/config/LayerManager.java +++ b/src/main/java/com/MylesAndMore/Tumble/config/LayerManager.java @@ -10,17 +10,19 @@ import java.util.*;  import static com.MylesAndMore.Tumble.Main.plugin;  public class LayerManager { -    public static List<List<Material>> layers = new ArrayList<>(); +    public static List<List<Material>> layers; +    private static int layerCount;      private static final CustomConfig layersYml = new CustomConfig("layers.yml");      private static final Configuration config = layersYml.getConfig();      private static final Configuration defaultConfig = Objects.requireNonNull(config.getDefaults()); -    private static int layerCount = 0;      /**       * Read layers from layers.yml and populate this.layers       */      public static void readConfig() { +        layers = new ArrayList<>(); +        layerCount = 0;          layersYml.saveDefaultConfig();          readLayers(config.getConfigurationSection("layers")); @@ -33,8 +35,11 @@ public class LayerManager {          plugin.getLogger().info("layers.yml: Loaded " + layerCount + (layerCount == 1 ? " layer" : " layers"));      } +    /** +     * Read the layers from the layers.yml file +     * @param section The 'layers' section of the config +     */      public static void readLayers(ConfigurationSection section) { -          if (section == null) {              plugin.getLogger().warning("layers.yml is missing section 'layers', using defaults");              return; @@ -52,7 +57,7 @@ public class LayerManager {                  continue;              } -            int weight = layerSection.getInt("layers." + layerPath + ".weight", 1); +            int weight = layerSection.getInt("weight", 1);              layerCount++;              for (int i = 0; i < weight; i++) {                  layers.add(layer); @@ -61,12 +66,11 @@ public class LayerManager {      }      /** -     * Read the list of materials for a layer. +     * Read the list of materials for a layer       * @param section The path of the layer in the config       * @return The list of materials for the layer to be composed of       */      public static List<Material> readLayer(ConfigurationSection section) { -          List<String> materialsList = section.getStringList("materials");          if (materialsList.isEmpty()) {              plugin.getLogger().warning("layers.yml: Layer '" + section.getCurrentPath() + "' is missing section 'materials'"); diff --git a/src/main/java/com/MylesAndMore/Tumble/game/Generator.java b/src/main/java/com/MylesAndMore/Tumble/game/Generator.java index c678082..51cb0a7 100644 --- a/src/main/java/com/MylesAndMore/Tumble/game/Generator.java +++ b/src/main/java/com/MylesAndMore/Tumble/game/Generator.java @@ -108,34 +108,46 @@ public class Generator {       */      private static void generateClumps(List<Block> blockList, List<Material> materialList) {          Random random = new Random(); -        // Make new lists so we can manipulate them          List<Block> blocks = new ArrayList<>(blockList);          List<Material> materials = new ArrayList<>(materialList);          Collections.shuffle(materials); +          while (!blocks.isEmpty()) {              Material randomMaterial = materials.get(random.nextInt(materials.size()));              Block block = blocks.get(random.nextInt(blocks.size()));              block.setType(randomMaterial); -            setRelativeBlocks(blocks, block); +            List<Block> modifiedBlocks = setRelativeBlocks(blocks, block); +            blocks.removeAll(modifiedBlocks); +            // There is a 50% (then 25%, 12.5%, ...) chance to continue modifying blocks aka growing the clump +            double probability = 0.5; +            while (!modifiedBlocks.isEmpty() && random.nextDouble() < probability) { +                Block nextBlock = modifiedBlocks.get(random.nextInt(modifiedBlocks.size())); +                nextBlock.setType(randomMaterial); +                modifiedBlocks = setRelativeBlocks(blocks, nextBlock); +                blocks.removeAll(modifiedBlocks); +                probability /= 2; +            }          }      }      /** -     * Sets all Blocks adjacent to `block` in `blocks` to the same Material as `block`. -     * All modified blocks are removed from `blocks`. +     * Sets all Blocks adjacent to `block` in `blocks` to the same Material as `block`       * @param blocks The list of blocks to modify       * @param block The reference block +     * @return A list of all modified blocks, including `block`       */ -    private static void setRelativeBlocks(List<Block> blocks, Block block) { +    private static List<Block> setRelativeBlocks(List<Block> blocks, Block block) { +        List<Block> modifiedBlocks = new ArrayList<>();          BlockFace[] faces = {BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST};          for (BlockFace face : faces) {              Block relativeBlock = block.getRelative(face);              if (blocks.contains(relativeBlock)) {                  relativeBlock.setType(block.getBlockData().getMaterial()); -                blocks.remove(relativeBlock); +                modifiedBlocks.add(relativeBlock);              }          } -        blocks.remove(block); +        modifiedBlocks.add(block); +        return modifiedBlocks;      }      /** diff --git a/src/main/resources/layers.yml b/src/main/resources/layers.yml index d388759..1d39527 100644 --- a/src/main/resources/layers.yml +++ b/src/main/resources/layers.yml @@ -116,7 +116,7 @@ layers:        - DIRT        - COARSE_DIRT        - GRASS_BLOCK -      - GRASS_PATH +      - DIRT_PATH # On 1.16.x this must be changed to GRASS_PATH        - MYCELIUM        - PODZOL        - OAK_SLAB | 
