diff options
author | Myles <mylesandmore9@gmail.com> | 2024-08-02 19:07:09 -0500 |
---|---|---|
committer | Myles <mylesandmore9@gmail.com> | 2024-08-02 19:07:09 -0500 |
commit | b093175bb7fd180163b3c322e5ee9052f10f184e (patch) | |
tree | 64027c6639852cbd5dcd6b8e5668ba1ca945d08b | |
parent | e6f5e922cbecf2ad64193e403631b4f790f49754 (diff) | |
download | Tumble-b093175bb7fd180163b3c322e5ee9052f10f184e.tar.gz Tumble-b093175bb7fd180163b3c322e5ee9052f10f184e.tar.bz2 Tumble-b093175bb7fd180163b3c322e5ee9052f10f184e.zip |
- fix layer weights not being accounted for
- use 1.17+ path material
- update readme with new layer yaml format
- improve clump generation
- join command fix
-rw-r--r-- | README.md | 13 | ||||
-rw-r--r-- | src/main/java/com/MylesAndMore/Tumble/commands/Join.java | 7 | ||||
-rw-r--r-- | src/main/java/com/MylesAndMore/Tumble/config/LayerManager.java | 16 | ||||
-rw-r--r-- | src/main/java/com/MylesAndMore/Tumble/game/Generator.java | 26 | ||||
-rw-r--r-- | src/main/resources/layers.yml | 2 |
5 files changed, 38 insertions, 26 deletions
@@ -108,14 +108,11 @@ Stores data about the layers that will be generated in the game. Layers are stored using the following format: ```yaml ores: # User-specified name of the layer - weight: 5 # Optional integer weight of the layer (1-...), used to determine how often it will be selected - materials: # List of materials (blocks) that will be used to generate the layer - - material: COBBLESTONE - weight: 5 # Optional integer weight of the material (1-...), used to determine how often it will be selected within the layer - - material: COAL_ORE - weight: 3 - - material: IRON_ORE - # No weight specified, defaults to 1 + weight: 5 # Optional integer weight of the layer (1-...), used to determine how often it will be selected + materials: # List of materials (blocks) that will be used to generate the layer + - COBBLESTONE 6 # Optional integer weight of the material (1-...), used to determine how often it will be selected within the layer + - COAL_ORE 3 + - IRON_ORE # No weight specified, defaults to 1 # More materials... ``` 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 |