Last active
February 3, 2022 02:28
-
-
Save ewized/0e07ca6be1e41013576c to your computer and use it in GitHub Desktop.
Parametric equations for circles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.year4000.ducktape.bukkit.DuckTape | |
import net.year4000.ducktape.bukkit.module.BukkitModule | |
import net.year4000.ducktape.bukkit.module.ModuleListeners | |
import net.year4000.ducktape.module.ModuleInfo | |
import org.bukkit.Bukkit | |
import org.bukkit.event.player.PlayerInteractEvent | |
import org.bukkit.event.EventHandler | |
import org.bukkit.event.Listener | |
import org.bukkit.Material | |
@ModuleInfo( | |
name = "Circles", | |
version = "0.0.1", | |
description = "Parametric equations for circles.", | |
authors = ["ewized"] | |
) | |
@ModuleListeners([Circles.class]) | |
public class Circles extends BukkitModule implements Listener { | |
/** Print out the origin location */ | |
@EventHandler | |
public void onPunch(PlayerInteractEvent event) { | |
int x = event.getPlayer().getLocation().getBlockX() | |
int y = event.getPlayer().getLocation().getBlockY() | |
int z = event.getPlayer().getLocation().getBlockZ() | |
event.getPlayer().sendMessage(String.format("%d, %d, %d", x, y, z)) | |
circle(event, x, z, y, true); | |
} | |
/** Draw a circle and more circles again */ | |
public void circle(PlayerInteractEvent event, int x, int z, int y, boolean first) { | |
Bukkit.getScheduler().runTaskAsynchronously(DuckTape.getInst(), new Runnable() { | |
public void run() { | |
double radius = 16; | |
for (int i = 0 ; i < 90 ; i++) { | |
int xx = x + (radius * Math.cos(i)); | |
int zz = z + (radius * Math.sin(i)); | |
Bukkit.getScheduler().runTask(DuckTape.getInst(), new Runnable() { | |
public void run() { | |
Material material = event.getPlayer().getItemInHand().getType() | |
material = material == null ? Material.AIR : material | |
material = !first ? material : Material.DIAMOND_BLOCK | |
event.getPlayer().getLocation().getWorld().getBlockAt(xx, y, zz).setType(material) | |
} | |
}) | |
// Draw a circle one layer deep | |
if (i % 10 == 0 && first) { | |
circle(event, xx, zz, y, false); | |
} | |
} | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment