Created
December 8, 2014 18:08
-
-
Save Brianetta/4b29cf701f2bfc65478c to your computer and use it in GitHub Desktop.
Command block command generator for Minecraft vanilla server
This file contains hidden or 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
# Generator for Minecraft commandblock commands | |
# List of hostile mobs | |
hostileMobs=["Zombie","Skeleton","Creeper","Spider","Endermite","Witch","Enderman","Silverfish"] | |
# Text for when a player sets their spawn point | |
spawnPointSet='{"text":"","extra":[{"text":"Spawn point set","color":"green"}]}' | |
# Welcome text | |
welcomeText='{"text":"Welcome to Brianetta\'s test server","color":"green"}' | |
# Set this to around number for legibility. | |
# 1xmaxRegionCount is added to a region score | |
# to flag a player as entering a region, and | |
# 2xmaxRegionCount is added to a region score | |
# to flag a player as leaving a region. | |
maxRegionCount=100 | |
class Region: | |
score=0 # Region identifier, kept as a player score | |
joinText='' # Text to show player as they join region | |
leaveText='' # Text to show player as they part region | |
x=0 # X origin of region | |
y=0 # Y origin of region | |
z=0 # Z origin of region | |
r=0 # Radius of region about origin | |
x2=0 # Greater X corner of region | |
y2=0 # Greater Y corner of region | |
z2=0 # Greater Z corner of region | |
def sphereSelector(this): | |
# Return a Minecraft command selector for a spherical region | |
return("x="+str(this.x)+",y="+str(this.y)+",z="+str(this.z)+",r="+str(this.r)) | |
def cuboidSelector(this): | |
# Return a Minecraft selector for a cuboidal region | |
return("x="+str(this.x)+",y="+str(this.y)+",z="+str(this.z)+",dx="+str(this.x2-this.x)+",dy="+str(this.y2-this.y)+",dz="+str(this.z2-this.z)) | |
def selector(this): | |
# If the radius is zero, assume a cuboid | |
if(this.r==0): | |
return this.cuboidSelector() | |
else: | |
return this.sphereSelector() | |
class Warp: | |
score=0 # Warp identifier. Used for /trigger warp set <n> | |
text='' # Optional text to show in chat | |
x=0.0 # Destination X | |
y=0.0 # Destination Y | |
z=0.0 # Destination Z | |
yaw=0 # Look around | |
pitch=0 # Look up/down | |
def command(this): | |
print("tp @a[score_warp_min="+str(this.score)+",score_warp="+str(this.score)+"] "+str(this.x)+" "+str(this.y)+" "+str(this.z)+" "+str(this.yaw)+" "+str(this.pitch)) | |
if this.text != '': | |
print("tellraw @a[score_warp_min="+str(this.score)+",score_warp="+str(this.score)+"] "+this.text) | |
def fillClock(length,width): | |
print("fill ~ ~+1 ~ ~"+str(length) +" ~+1 ~"+str(width)+" minecraft:lapis_block") | |
print("fill ~ ~-1 ~ ~"+str(length)+" ~-1 ~"+str(length)+" minecraft:redstone_block") | |
def killMobs(region): | |
for mob in hostileMobs: | |
print("kill @e["+region.selector()+",type="+mob+"]") | |
def regionChain(region): | |
if region.score==0: | |
return | |
print('scoreboard players set @a[score_region='+str(region.score)+ | |
',score_region_min='+str(region.score)+ | |
'] region '+str(region.score+maxRegionCount+maxRegionCount)) | |
print('scoreboard players set @a['+region.selector()+ | |
',score_region='+str(region.score+maxRegionCount+maxRegionCount)+ | |
',score_region_min='+str(region.score+maxRegionCount+maxRegionCount)+ | |
'] region '+str(region.score)) | |
print('scoreboard players set @a['+region.selector()+ | |
',score_region=0,score_region_min=0] region '+str(region.score+maxRegionCount)) | |
if region.joinText!='': | |
print('tellraw @a[score_region='+str(region.score+maxRegionCount)+ | |
',score_region_min='+str(region.score+maxRegionCount)+ | |
'] '+region.joinText) | |
print('scoreboard players set @a[score_region='+str(region.score+maxRegionCount)+ | |
',score_region_min='+str(region.score+maxRegionCount)+ | |
'] region '+str(region.score)) | |
if region.leaveText!='': | |
print('tellraw @a[score_region='+str(region.score+maxRegionCount+maxRegionCount)+ | |
',score_region_min='+str(region.score+maxRegionCount+maxRegionCount)+ | |
'] '+region.leaveText) | |
region={} | |
region["mobfree"]=Region() | |
region["mobfree"].x=-158 | |
region["mobfree"].y=74 | |
region["mobfree"].z=-28 | |
region["mobfree"].r=50 | |
region["spawn"]=Region() | |
region["spawn"].score=1 | |
region["spawn"].joinText='{"text":"","extra":[{"text":"Welcome to region["spawn"]!","color":"green"}]}' | |
region["spawn"].leaveText='{"text":"","extra":[{"text":"You are now leaving region["spawn"]!","color":"red"}]}' | |
region["spawn"].x=-163 | |
region["spawn"].y=75 | |
region["spawn"].z=-33 | |
region["spawn"].x2=-152 | |
region["spawn"].y2=78 | |
region["spawn"].z2=-22 | |
region["clockroom"]=Region() | |
region["clockroom"].score=2 | |
region["clockroom"].joinText='{"text":"","extra":[{"text":"Clock room - staff only","color":"red"}]}' | |
region["clockroom"].x=-162 | |
region["clockroom"].y=1 | |
region["clockroom"].z=-32 | |
region["clockroom"].x2=-138 | |
region["clockroom"].y2=9 | |
region["clockroom"].z2=-23 | |
region["promotion chamber"]=Region() | |
region["promotion chamber"].score=3 | |
region["promotion chamber"].joinText='{"text":"","extra":[{"text":"PROMOTION BOOTH","color":"yellow"}]}' | |
region["promotion chamber"].x=-154 | |
region["promotion chamber"].y=75 | |
region["promotion chamber"].z=-45 | |
region["promotion chamber"].x2=-152 | |
region["promotion chamber"].y2=77 | |
region["promotion chamber"].z2=-43 | |
region["promotion controls"]=Region() | |
region["promotion controls"].score=4 | |
region["promotion controls"].joinText='{"text":"","extra":[{"text":"PROMOTION BOOTH","color":"yellow"}]}' | |
region["promotion controls"].x=-150 | |
region["promotion controls"].y=75 | |
region["promotion controls"].z=-45 | |
region["promotion controls"].x2=-148 | |
region["promotion controls"].y2=77 | |
region["promotion controls"].z2=-43 | |
warp={} | |
warp["spawn"]=Warp() | |
warp["spawn"].score=1 | |
warp["spawn"].text='{"text":"","extra":[{"text":"Traveled to Spawn","color":"blue"}' | |
warp["spawn"].x=-157.0 | |
warp["spawn"].y=75 | |
warp["spawn"].z=27.0 | |
warp["spawn"].yaw=90 | |
warp["spawn"].pitch=0 | |
warp["clock room"]=Warp() | |
warp["clock room"].score=2 | |
warp["clock room"].x=-160 | |
warp["clock room"].y=1 | |
warp["clock room"].z=-23 | |
warp["clock room"].yaw=90 | |
warp["clock room"].pitch=0 | |
warp["promotion control"]=Warp() | |
warp["promotion control"].score=3 | |
warp["promotion control"].x=-149 | |
warp["promotion control"].y=75 | |
warp["promotion control"].z=-44 | |
warp["promotion control"].yaw=90 | |
warp["promotion control"].pitch=0 | |
# Length and width of standard fill clock | |
clocklength = 6 | |
clockwidth = 1 | |
print("-- Console set-up comands (run once)") | |
# Three teams with three colours | |
print("\n-- Teams") | |
print("scoreboard teams add player Visitor") | |
print("scoreboard teams add player Player") | |
print("scoreboard teams add staff Staff") | |
print("scoreboard teams option visitor color light_purple") | |
print("scoreboard teams option player color green") | |
print("scoreboard teams option staff color gold") | |
# Regions | |
print("\n-- Regions") | |
print("scoreboard objectives add region dummy Region") | |
# In-game commands for players | |
print("\n-- Player triggers") | |
print("scoreboard objectives add home trigger Home") | |
print("scoreboard objectives add warp trigger Warp") | |
print("scoreboard objectives add mode trigger Game mode") | |
# Welcome un-teamed players, team them up and set a region | |
print("\n-- New player defaults") | |
print('title @a[team=] title '+welcomeText) | |
print('scoreboard players set @a[team=] region 0') | |
print('scoreboard teams join Player @p[team=]') | |
# Could print a couple of these, for convenience | |
print("\n-- Reusable fill clock - second line in block at y+2 from first line") | |
fillClock(clocklength,clockwidth) | |
print("\n-- Command Block chain commands - attach each chain in strict X sequence to one fill clock's output") | |
# Each region in turn | |
for name,instance in region.items(): | |
print("\n-- Region definition: "+name) | |
regionChain(instance) | |
# Command chain for setting player spawn point | |
print("\n-- Spawn point setting") | |
print('tellraw @a[score_home_min=1] '+spawnPointSet) | |
print('execute @a[score_home_min=1] ~ ~ ~ spawnpoint @p ~ ~ ~') | |
print('scoreboard players set @a[score_home_min=1] home 0') | |
print('scoreboard players enable @a home') | |
# Warp chain | |
print("\n-- Warps") | |
for name, instance in warp.items(): | |
instance.command() | |
print('scoreboard players set @a[score_home_min=1] warp 0') | |
print('scoreboard players enable @a warp') | |
# Mode chain | |
print("\n-- Mode changes") | |
print('gamemode 1 @a[score_mode_min=1,score_mode=1,team=Staff]') | |
print('gamemode 2 @a[score_mode_min=2,score_mode=2,team=Staff]') | |
print('gamemode 3 @a[score_mode_min=3,score_mode=3,team=Staff]') | |
print('gamemode 0 @a[score_mode_min=0,score_mode=0,team=Staff]') | |
print('scoreboard players set @a mode 4') | |
print('scoreboard players enable @a[team=Staff] mod') | |
#Solitary commands | |
print("\n-- Solitary commands - can be attached to any fill clock output") | |
print("\n-- Kill mobs in mobfree region") | |
killMobs(region["mobfree"]) | |
print("\n-- Region tasks") | |
# Adventure mode within Spawn | |
print("gamemode 2 @a[score_region="+str(region["spawn"].score)+",score_region_min="+str(region["spawn"].score)+",m=0]") | |
# Feed players within Spawn | |
print("effect 2 @e[score_region="+str(region["spawn"].score)+",score_region_min="+str(region["spawn"].score)+"] minecraft:saturation 1 1 true") | |
# Set survival mode to Adventure players in the wider world | |
print("gamemode 1 @a[score_region=0,score_region_min=0,m=2]") | |
# Set survival mode to non-staff Creative players in the wider world | |
print("gamemode 1 @a[score_region=0,score_region_min=0,m=1,team=!staff]") | |
# Teleport players up and out of the staff control booth | |
print("execute @a[score_region="+str(region["promotion controls"].score)+",score_region_min="+str(region["promotion controls"].score)+",team=!Staff] ~ ~ ~ tp ~ ~4 ~") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment