aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/MylesAndMore/tumble/api/Generator.java
diff options
context:
space:
mode:
authorMyles <43725835+MylesAndMore@users.noreply.github.com>2023-06-17 20:48:51 +0200
committerGitHub <noreply@github.com>2023-06-17 20:48:51 +0200
commitee11892063a796c602948676be4de22d3f717131 (patch)
treeb15435cb788f0a221a7393739908b4c84baa51ad /src/main/java/com/MylesAndMore/tumble/api/Generator.java
parent3c48bd3f9587ae9459d789f70ba1ebaaf691209b (diff)
parent19d8ffbc6659c7de13b81a587dae7081078649c6 (diff)
downloadTumble-ee11892063a796c602948676be4de22d3f717131.tar.gz
Tumble-ee11892063a796c602948676be4de22d3f717131.tar.bz2
Tumble-ee11892063a796c602948676be4de22d3f717131.zip
Merge pull request #7 from MylesAndMore/dev
refactoring!
Diffstat (limited to 'src/main/java/com/MylesAndMore/tumble/api/Generator.java')
-rw-r--r--src/main/java/com/MylesAndMore/tumble/api/Generator.java120
1 files changed, 0 insertions, 120 deletions
diff --git a/src/main/java/com/MylesAndMore/tumble/api/Generator.java b/src/main/java/com/MylesAndMore/tumble/api/Generator.java
deleted file mode 100644
index db8bacc..0000000
--- a/src/main/java/com/MylesAndMore/tumble/api/Generator.java
+++ /dev/null
@@ -1,120 +0,0 @@
-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 {
- /**
- * 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;
-
- for (int y = Cy; y < Cy + height; y++) {
- 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) {
- 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);
- }
- }
-}