aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/MylesAndMore/tumble/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/MylesAndMore/tumble/api')
-rw-r--r--src/main/java/com/MylesAndMore/tumble/api/Generator.java97
-rw-r--r--src/main/java/com/MylesAndMore/tumble/api/Layers.java300
2 files changed, 395 insertions, 2 deletions
diff --git a/src/main/java/com/MylesAndMore/tumble/api/Generator.java b/src/main/java/com/MylesAndMore/tumble/api/Generator.java
index 632627d..db8bacc 100644
--- a/src/main/java/com/MylesAndMore/tumble/api/Generator.java
+++ b/src/main/java/com/MylesAndMore/tumble/api/Generator.java
@@ -3,13 +3,34 @@ package com.MylesAndMore.tumble.api;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+
+/**
+ * This class holds the methods that generate blocks in-game such as cylinders, cubiods, and clump logic.
+ */
public class Generator {
- public static void generateLayer(Location center, int radius, int height, Material material) {
+ /**
+ * Generates a layer (bascally just a cylinder) as best as it can w/ blocks
+ *
+ * @return A list of Blocks containing all the blocks it just changed
+ *
+ * @param center The center of the layer (Location)
+ * @param radius The whole number radius of the circle
+ * @param height The whole number height of the circle (1 for a flat layer)
+ * @param material The Material to use for generation
+ */
+ public static List<Block> generateLayer(Location center, int radius, int height, Material material) {
int Cx = center.getBlockX();
int Cy = center.getBlockY();
int Cz = center.getBlockZ();
World world = center.getWorld();
+ List<Block> blocks = new ArrayList<>();
int rSq = radius * radius;
@@ -17,11 +38,83 @@ public class Generator {
for (int x = Cx - radius; x <= Cx + radius; x++) {
for (int z = Cz - radius; z <= Cz + radius; z++) {
if ((Cx - x) * (Cx - x) + (Cz - z) * (Cz - z) <= rSq) {
- Location block = new Location(world, x, y, z);
world.getBlockAt(x, y, z).setType(material);
+ blocks.add(world.getBlockAt(x, y, z));
}
}
}
}
+ return blocks;
+ }
+
+ /**
+ * Generates a cubiod (literally just a ripoff fill command)
+ * @param firstPos The first Location to fill (first three coords in a fill command)
+ * @param secondPos The second Location to fill to (second three coords)
+ * @param material The Material to fill
+ */
+ public static List<Block> generateCuboid(Location firstPos, Location secondPos, Material material) {
+ World world = firstPos.getWorld();
+ List<Block> blocks = new ArrayList<>();
+ int fX = firstPos.getBlockX();
+ int fY = firstPos.getBlockY();
+ int fZ = firstPos.getBlockZ();
+ int sX = secondPos.getBlockX();
+ int sY = secondPos.getBlockY();
+ int sZ = secondPos.getBlockZ();
+
+ for (int x = fX; x <= sX; x++) {
+ for (int y = fY; y <= sY; y++) {
+ for (int z = fZ; z <= sZ; z++) {
+ world.getBlockAt(x, y, z).setType(material);
+ blocks.add(world.getBlockAt(x, y, z));
+ }
+ }
+ }
+ return blocks;
+ }
+
+ /**
+ * Generates clumps in a pre-generated layer.
+ * @param blockList A list of block Locations that this method is allowed to edit
+ * @param materialList A list of Materials for the generator to randomly choose from.
+ * Keep in mind that not all Materials may be used, the amount used depends on the size of the layer.
+ * More Materials = more randomization
+ */
+ public static void generateClumps(List<Block> blockList, List<Material> materialList) {
+ // Define random class
+ Random random = new Random();
+ // Define new blocks list so we can manipulate it
+ List<Block> blocks = new ArrayList<>(blockList);
+ // Define new shuffled Materials list
+ List<Material> materials = new ArrayList<>(materialList);
+ Collections.shuffle(materials);
+ // This loop will run until there are no blocks left to change
+ while (blocks.size() > 0) {
+ // Get a random Material from the provided materials list
+ Material randomMaterial = materials.get(random.nextInt(materials.size()));
+ // Gets the first Block from the list, to modify
+ Block aBlock = blocks.get(0);
+ // Modifies the block
+ aBlock.setType(randomMaterial);
+ // Get the blocks around that and change it to that same material
+ if (blocks.contains(aBlock.getRelative(BlockFace.NORTH))) {
+ aBlock.getRelative(BlockFace.NORTH).setType(randomMaterial);
+ blocks.remove(aBlock.getRelative(BlockFace.NORTH));
+ }
+ if (blocks.contains(aBlock.getRelative(BlockFace.SOUTH))) {
+ aBlock.getRelative(BlockFace.SOUTH).setType(randomMaterial);
+ blocks.remove(aBlock.getRelative(BlockFace.SOUTH));
+ }
+ if (blocks.contains(aBlock.getRelative(BlockFace.EAST))) {
+ aBlock.getRelative(BlockFace.EAST).setType(randomMaterial);
+ blocks.remove(aBlock.getRelative(BlockFace.EAST));
+ }
+ if (blocks.contains(aBlock.getRelative(BlockFace.WEST))) {
+ aBlock.getRelative(BlockFace.WEST).setType(randomMaterial);
+ blocks.remove(aBlock.getRelative(BlockFace.WEST));
+ }
+ blocks.remove(aBlock);
+ }
}
}
diff --git a/src/main/java/com/MylesAndMore/tumble/api/Layers.java b/src/main/java/com/MylesAndMore/tumble/api/Layers.java
new file mode 100644
index 0000000..8818631
--- /dev/null
+++ b/src/main/java/com/MylesAndMore/tumble/api/Layers.java
@@ -0,0 +1,300 @@
+package com.MylesAndMore.tumble.api;
+
+import org.bukkit.Material;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+/**
+ * This class is dedicated to storing the different types of layers that can be generated.
+ */
+public class Layers {
+
+ public Layers(){
+ // Make the other layers more common than the glass layer
+ for (int i = 0; i < 10; i++) {
+ matList.add(gen0);
+ matList.add(gen1);
+ matList.add(gen2);
+ matList.add(gen3);
+ matList.add(gen4);
+ matList.add(gen5);
+ matList.add(gen6);
+ matList.add(gen7);
+ matList.add(gen8);
+ matList.add(gen9);
+ matList.add(gen10);
+ matList.add(gen12);
+ matList.add(gen15);
+ matList.add(gen16);
+ }
+ // Glass layer
+ matList.add(gen11);
+ }
+
+ // Define Random class
+ Random random = new Random();
+ /**
+ * @return A random predefined List of Materials that are okay to use in the clump generator
+ */
+ public List<Material> getMaterialList() {
+ return matList.get(random.nextInt(matList.size()));
+ }
+
+ // Define the list that will store the material lists
+ private final List<List<Material>> matList = new ArrayList<>();
+
+
+ // Begin lists
+
+ // private final List<Material> gen = new ArrayList<>() {{
+ // add(Material.
+ // }};
+
+ private final List<Material> gen0 = new ArrayList<>() {{
+ add(Material.COAL_ORE);
+ add(Material.COAL_ORE);
+ add(Material.COAL_ORE);
+ add(Material.COAL_ORE);
+ add(Material.COAL_ORE);
+ add(Material.IRON_ORE);
+ add(Material.REDSTONE_ORE);
+ add(Material.EMERALD_ORE);
+ add(Material.GOLD_ORE);
+ add(Material.LAPIS_ORE);
+ add(Material.DIAMOND_ORE);
+ add(Material.GRASS_BLOCK);
+ add(Material.GRASS_BLOCK);
+ add(Material.GRASS_BLOCK);
+ add(Material.GRASS_BLOCK);
+ // add(Material.COBWEB);
+ }};
+
+ private final List<Material> gen1 = new ArrayList<>() {{
+ add(Material.YELLOW_GLAZED_TERRACOTTA);
+ add(Material.LIGHT_BLUE_GLAZED_TERRACOTTA);
+ add(Material.GRAY_GLAZED_TERRACOTTA);
+ add(Material.PODZOL);
+ add(Material.PODZOL);
+ add(Material.PODZOL);
+ add(Material.ORANGE_GLAZED_TERRACOTTA);
+ }};
+
+ private final List<Material> gen2 = new ArrayList<>() {{
+ add(Material.PINK_TERRACOTTA);
+ add(Material.PURPLE_TERRACOTTA);
+ add(Material.GRAY_TERRACOTTA);
+ add(Material.BLUE_TERRACOTTA);
+ add(Material.LIGHT_BLUE_TERRACOTTA);
+ add(Material.WHITE_TERRACOTTA);
+ add(Material.BROWN_TERRACOTTA);
+ add(Material.GREEN_TERRACOTTA);
+ add(Material.YELLOW_TERRACOTTA);
+ add(Material.PINK_TERRACOTTA);
+ add(Material.PURPLE_TERRACOTTA);
+ add(Material.GRAY_TERRACOTTA);
+ add(Material.BLUE_TERRACOTTA);
+ add(Material.LIGHT_BLUE_TERRACOTTA);
+ add(Material.WHITE_TERRACOTTA);
+ add(Material.BROWN_TERRACOTTA);
+ add(Material.GREEN_TERRACOTTA);
+ add(Material.YELLOW_TERRACOTTA);
+ add(Material.WHITE_STAINED_GLASS);
+ add(Material.HONEYCOMB_BLOCK);
+ add(Material.HONEYCOMB_BLOCK);
+ }};
+
+ private final List<Material> gen3 = new ArrayList<>() {{
+ add(Material.PACKED_ICE);
+ add(Material.PACKED_ICE);
+ add(Material.NOTE_BLOCK);
+ add(Material.TNT);
+ add(Material.LIGHT_BLUE_CONCRETE);
+ add(Material.GLASS);
+ add(Material.PACKED_ICE);
+ add(Material.PACKED_ICE);
+ add(Material.NOTE_BLOCK);
+ add(Material.TNT);
+ add(Material.LIGHT_BLUE_CONCRETE);
+ add(Material.GLASS);
+ add(Material.SOUL_SAND);
+ }};
+
+ private final List<Material> gen4 = new ArrayList<>() {{
+ add(Material.DIAMOND_BLOCK);
+ add(Material.GOLD_BLOCK);
+ add(Material.REDSTONE_BLOCK);
+ add(Material.REDSTONE_BLOCK);
+ add(Material.LAPIS_BLOCK);
+ add(Material.LAPIS_BLOCK);
+ add(Material.IRON_BLOCK);
+ add(Material.COAL_BLOCK);
+ add(Material.IRON_BLOCK);
+ add(Material.COAL_BLOCK);
+ add(Material.IRON_BLOCK);
+ add(Material.COAL_BLOCK);
+ add(Material.COAL_BLOCK);
+ }};
+
+ private final List<Material> gen5 = new ArrayList<>() {{
+ add(Material.WHITE_TERRACOTTA);
+ add(Material.BLUE_ICE);
+ add(Material.SOUL_SAND);
+ add(Material.STONE_SLAB);
+ add(Material.WHITE_TERRACOTTA);
+ add(Material.BLUE_ICE);
+ add(Material.SOUL_SAND);
+ add(Material.STONE_SLAB);
+ add(Material.WHITE_TERRACOTTA);
+ add(Material.BLUE_ICE);
+ add(Material.SOUL_SAND);
+ add(Material.STONE_SLAB);
+ add(Material.GLOWSTONE);
+ add(Material.GLOWSTONE);
+ add(Material.HONEY_BLOCK);
+ add(Material.SLIME_BLOCK);
+ }};
+
+ private final List<Material> gen6 = new ArrayList<>() {{
+ add(Material.NETHERRACK);
+ add(Material.NETHERRACK);
+ add(Material.NETHERRACK);
+ add(Material.NETHER_BRICKS);
+ add(Material.NETHER_BRICKS);
+ add(Material.NETHERRACK);
+ add(Material.NETHERRACK);
+ add(Material.NETHERRACK);
+ add(Material.NETHER_BRICKS);
+ add(Material.NETHER_BRICKS);
+ add(Material.NETHER_GOLD_ORE);
+ add(Material.NETHER_GOLD_ORE);
+ add(Material.CRIMSON_NYLIUM);
+ add(Material.WARPED_NYLIUM);
+ add(Material.SOUL_SOIL);
+ add(Material.CRACKED_NETHER_BRICKS);
+ add(Material.RED_NETHER_BRICKS);
+ add(Material.NETHER_WART_BLOCK);
+ add(Material.CRYING_OBSIDIAN);
+ add(Material.MAGMA_BLOCK);
+ }};
+
+ private final List<Material> gen7 = new ArrayList<>() {{
+ add(Material.END_STONE);
+ add(Material.END_STONE_BRICKS);
+ add(Material.END_STONE);
+ add(Material.END_STONE_BRICKS);
+ add(Material.END_STONE);
+ add(Material.END_STONE_BRICKS);
+ add(Material.END_STONE);
+ add(Material.END_STONE_BRICKS);
+ add(Material.OBSIDIAN);
+ add(Material.PURPUR_BLOCK);
+ add(Material.PURPUR_PILLAR);
+ add(Material.COBBLESTONE);
+ }};
+
+ private final List<Material> gen8 = new ArrayList<>() {{
+ add(Material.REDSTONE_BLOCK);
+ add(Material.REDSTONE_BLOCK);
+ add(Material.REDSTONE_LAMP);
+ add(Material.TARGET);
+ add(Material.DAYLIGHT_DETECTOR);
+ add(Material.PISTON);
+ add(Material.STICKY_PISTON);
+ add(Material.SLIME_BLOCK);
+ add(Material.OBSERVER);
+ add(Material.HOPPER);
+ }};
+
+ private final List<Material> gen9 = new ArrayList<>() {{
+ add(Material.PRISMARINE);
+ add(Material.DARK_PRISMARINE);
+ add(Material.BLUE_STAINED_GLASS);
+ add(Material.WET_SPONGE);
+ add(Material.PRISMARINE_BRICKS);
+ add(Material.PRISMARINE_BRICK_SLAB);
+ add(Material.DARK_PRISMARINE);
+ add(Material.SEA_LANTERN);
+ add(Material.TUBE_CORAL_BLOCK);
+ add(Material.BRAIN_CORAL_BLOCK);
+ add(Material.BUBBLE_CORAL_BLOCK);
+ }};
+
+ private final List<Material> gen10 = new ArrayList<>() {{
+ add(Material.OAK_LOG);
+ add(Material.SPRUCE_LOG);
+ add(Material.ACACIA_LOG);
+ add(Material.STRIPPED_OAK_LOG);
+ add(Material.STRIPPED_SPRUCE_LOG);
+ add(Material.STRIPPED_ACACIA_LOG);
+ add(Material.OAK_WOOD);
+ add(Material.SPRUCE_WOOD);
+ add(Material.ACACIA_WOOD);
+ add(Material.OAK_LEAVES);
+ add(Material.SPRUCE_LEAVES);
+ add(Material.ACACIA_LEAVES);
+ add(Material.OAK_LEAVES);
+ add(Material.SPRUCE_LEAVES);
+ add(Material.ACACIA_LEAVES);
+ }};
+
+ private final List<Material> gen11 = new ArrayList<>() {{
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.GLASS);
+ add(Material.WHITE_STAINED_GLASS);
+ }};
+
+ private final List<Material> gen12 = new ArrayList<>() {{
+ add(Material.DIRT);
+ add(Material.DIRT_PATH);
+ add(Material.GRASS_BLOCK);
+ add(Material.OAK_SLAB);
+ add(Material.BRICK_WALL);
+ add(Material.BRICK_STAIRS);
+ }};
+
+ private final List<Material> gen15 = new ArrayList<>() {{
+ add(Material.SANDSTONE);
+ add(Material.SANDSTONE_SLAB);
+ add(Material.RED_SANDSTONE);
+ add(Material.RED_SANDSTONE_SLAB);
+ add(Material.RED_TERRACOTTA);
+ add(Material.TERRACOTTA);
+ add(Material.YELLOW_TERRACOTTA);
+ }};
+
+ private final List<Material> gen16 = new ArrayList<>() {{
+ add(Material.JUNGLE_LOG);
+ add(Material.STRIPPED_JUNGLE_LOG);
+ add(Material.JUNGLE_WOOD);
+ add(Material.STRIPPED_JUNGLE_WOOD);
+ add(Material.MOSSY_COBBLESTONE);
+ add(Material.MOSSY_COBBLESTONE);
+ add(Material.MOSSY_COBBLESTONE);
+ add(Material.JUNGLE_LEAVES);
+ add(Material.JUNGLE_SLAB);
+ add(Material.JUNGLE_TRAPDOOR);
+ }};
+
+}