Hi there!
I've written a little script for building or removing bigger things with one click.
I wrote it fast and copy&pasted a bit, so it doesn't look nice and probably it could have been done better. But I did this mainly for my fun and to practice Groovy and the (known) Mythruna-API. But if you have suggestions to improve the script, I would be happy.
The problem at the moment is that i have no environment to test it with multiple people online. I'm not sure, but I think the size-variables are global, so each player has the same.
Is this right? And if yes, how could I fix this?
Thanks, Toboi
import mythruna.*;
import mythruna.db.tree.*;
import mythruna.es.*;
import mythruna.script.*;
int size_xl = 0;
int size_yl = 0;
int size_zl = 0;
int size_xh = 0;
int size_yh = 0;
int size_zh = 0;
int type_block = 0;
int size_remove_cubel = 0;
int size_remove_cubeh = 0;
action( group:"Remove", name:"Remove cube3", type:ActionType.Block ) {
loc = it.getBlock();
for (i in (-1..<2)) {
for (j in (-1..<2)) {
for (k in (-1..<2)) {
setCellType(loc.x + i, loc.y + j, loc.z + k, 0);
}}
}
}
action( group:"Remove", name:"Remove cube5", type:ActionType.Block ) {
loc = it.getBlock();
for (i in (-2..<3)) {
for (j in (-2..<3)) {
for (k in (-2..<3)) {
setCellType(loc.x + i, loc.y + j, loc.z + k, 0);
}}
}
}
action( group:"Remove", name:"Remove cube7", type:ActionType.Block ) {
loc = it.getBlock();
for (i in (-3..<4)) {
for (j in (-3..<4)) {
for (k in (-3..<4)) {
setCellType(loc.x + i, loc.y + j, loc.z + k, 0);
}}
}
}
action( group:"Remove", name:"Remove cube with own size", type:ActionType.Block ) {
loc = it.getBlock();
for (i in (-size_remove_cubel..<size_remove_cubeh)) {
for (j in (-size_remove_cubel..<size_remove_cubeh)) {
for (k in (-size_remove_cubel..<size_remove_cubeh)) {
setCellType(loc.x + i, loc.y + j, loc.z + k, 0);
}}
}
}
action( group:"Big", name:"Water3x3x3", type:ActionType.Block ) {
loc = it.getBlock();
for (i in (-1..<2)) {
for (j in (-1..<2)) {
for (k in (-1..<2)) {
if(getCellType(loc.x + i, loc.y + j, loc.z + k) == 0){
setCellType(loc.x + i, loc.y + j, loc.z + k, 7);
}
}
}
}
}
action( group:"Big", name:"Water5x5x5", type:ActionType.Block ) {
loc = it.getBlock();
for (i in (-2..<3)) {
for (j in (-2..<3)) {
for (k in (-2..<3)) {
if(getCellType(loc.x + i, loc.y + j, loc.z + k) == 0){
setCellType(loc.x + i, loc.y + j, loc.z + k, 7);
}
}
}
}
}
action( group:"Big", name:"Water7x7x7", type:ActionType.Block ) {
loc = it.getBlock();
for (i in (-3..<4)) {
for (j in (-3..<4)) {
for (k in (-3..<4)) {
if(getCellType(loc.x + i, loc.y + j, loc.z + k) == 0){
setCellType(loc.x + i, loc.y + j, loc.z + k, 7);
}
}
}
}
}
action( group:"Big", name:"Own", type:ActionType.Block ) {
loc = it.getBlock();
for (i in (-size_xl..<size_xh)) {
for (j in (-size_yl..<size_yh)) {
for (k in (-size_zl..<size_zh)) {
setCellType(loc.x + i, loc.y + j, loc.z + k, type_block);
}
}
}
}
action( group:"Big", name:"Own if free", type:ActionType.Block ) {
loc = it.getBlock();
for (i in (-size_xl..<size_xh)) {
for (j in (-size_yl..<size_yh)) {
for (k in (-size_zl..<size_zh)) {
if(getCellType(loc.x + i, loc.y + j, loc.z + k) == 0){
setCellType(loc.x + i, loc.y + j, loc.z + k, type_block);
}
}
}
}
}
on( [playerJoined] ) {
type, event ->
conn = connection;
p = conn.getAttribute( "player" );
println( "Adding removing tools to player:" + player );
refs = []
ToolActions existing = player[ToolActions.class];
if( playerData != null ) {
refs += actions.getRef( "Remove", "Remove cube3" );
refs += actions.getRef( "Remove", "Remove cube5" );
refs += actions.getRef( "Remove", "Remove cube7" );
refs += actions.getRef( "Remove", "Remove cube with own size" );
refs += actions.getRef( "Big", "Own big block" );
refs += actions.getRef( "Big", "Own big block if free" );
refs += actions.getRef( "Big", "Water3x3x3" );
refs += actions.getRef( "Big", "Water5x5x5" );
refs += actions.getRef( "Big", "Water7x7x7" );
}
println "Refs:" + refs;
player << new ToolActions(refs, existing)
p.set( "big.size", 2 );
addShellCommand( shell, "insertsize", "Sets the size of the mass-insert block.", null ) {
String[] parms = it.split( " " );
if( it.length() == 0 || !parms.length == 4 ) {
console.echo( "Usage: ~insertsize x y z blocktype / Build with Blocktype 'Own' to override or 'Own if free' to fill out" );
}else{
size_xl = (parms[0].toInteger()) / 2;
size_yl = (parms[1].toInteger()) / 2;
size_zl = (parms[2].toInteger()) / 2;
size_xh = (parms[0].toInteger() + 1) / 2;
size_yh = (parms[1].toInteger() + 1) / 2;
size_zh = (parms[2].toInteger() + 1) / 2;
type_block = parms[3].toInteger();
}
}
addShellCommand( shell, "removesize", "Sets the size of the mass-removal block.", null ) {
String[] parms = it.split( " " );
if( it.length() == 0 || !parms.length == 1 ) {
console.echo( "Usage: ~removesize size / Remove with Blocktype 'Remove cube with own size'" );
}else{
size_remove_cubel = (parms[0].toInteger()) / 2;
size_remove_cubeh = (parms[0].toInteger() + 1) / 2;
}
}}