-
-
Notifications
You must be signed in to change notification settings - Fork 928
Description
The Problem
Hard to make regular polygon shapes with similar functionality to //cyl or //hcyl
A Solution
//poly or //hpoly that takes a pattern, sides, radius, and optional fill.
Example python code:
angle_step = 360 / sides
angle = 180 / sides # Start angle to center the polygon
for i in range(sides):
x = int(radius * math.cos(math.radians(angle)))
z = int(radius * math.sin(math.radians(angle)))
"""
if i == 0:
f"//pos1 ~{x},~,~{z}" # relative to player
else:
f"//pos2 ~{x},~,~{z}" # relative to player
"""
angle += 360 / sides
Alternatives
Seperate commands for octagon, hexagon, pentagon would be too much of a hassle in my opinion.
Anything Else?
I am currently using minescript to make a custom poly command but I would like to see this implemented in the official worldedit and believe it would be fairly useful to most.
Here is my full minescript file if anyone is interested:
import minescript as m
# import system.pyj.minescript as m
import sys
import math
def usage():
m.echo("Usage: poly.py [fill]")
m.echo(" : Block pattern to use")
m.echo(" : Number of sides for the polygon")
m.echo(" : Radius of the polygon")
m.echo(" [fill]: Optional; if provided, the polygon will be filled")
sys.exit(1)
args = sys.argv
args.pop(0) # Remove script name
if len(args) == 0:
usage()
if args[0] in ("-h", "--help", "help"):
usage()
pattern = args[0]
sides = int(args[1])
radius = float(args[2])
fill = len(args) > 3 and args[3] is not None
m.execute("//sel cuboid") # Reset selection
m.execute("//sel poly")
pos = [math.floor(i) for i in m.player_position()]
# Compute angle increment
angle_step = 360 / sides
angle = 180 / sides # Start angle to center the polygon
for i in range(sides):
x = int(radius * math.cos(math.radians(angle)))
z = int(radius * math.sin(math.radians(angle)))
if i == 0:
m.execute(f"//pos1 {x + pos[0]},{pos[1]},{z + pos[2]}")
else:
m.execute(f"//pos2 {x + pos[0]},{pos[1]},{z + pos[2]}")
angle += angle_step
if fill:
m.execute(f"//set {pattern}")
else:
m.execute(f"//walls {pattern}")