aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/MylesAndMore/tumble/api/Generator.java
diff options
context:
space:
mode:
authorMyles <43725835+MylesAndMore@users.noreply.github.com>2022-12-13 14:16:59 -0600
committerGitHub <noreply@github.com>2022-12-13 14:16:59 -0600
commit6739bbb14d03bd215f8c7d72dc14d961b6bc175e (patch)
treee2c680914445931fdfad35169eb17dd0404301f5 /src/main/java/com/MylesAndMore/tumble/api/Generator.java
parentcea002dc786f7826a1a3faef26fb659e3d8e908e (diff)
parentcbafd10bc90273a263d019faeccb356ead442eb1 (diff)
downloadTumble-6739bbb14d03bd215f8c7d72dc14d961b6bc175e.tar.gz
Tumble-6739bbb14d03bd215f8c7d72dc14d961b6bc175e.tar.bz2
Tumble-6739bbb14d03bd215f8c7d72dc14d961b6bc175e.zip
Merge pull request #1 from MylesAndMore/beta
merge beta to main for release
Diffstat (limited to 'src/main/java/com/MylesAndMore/tumble/api/Generator.java')
-rw-r--r--src/main/java/com/MylesAndMore/tumble/api/Generator.java97
1 files changed, 95 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);
+ }
}
}