gui and text drawing, gui misc

This commit is contained in:
Sen 2025-03-19 21:54:09 +01:00
parent c906760bd4
commit 4ec8affe85
37 changed files with 799 additions and 646 deletions

View file

@ -8,19 +8,6 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import game.block.Block;
import game.entity.Entity;
import game.entity.npc.EntityNPC;
import game.entity.types.EntityLiving;
import game.item.Item;
import game.item.ItemStack;
import game.nbt.NBTTagCompound;
import game.world.BlockPos;
import game.world.State;
import game.world.Vec3;
import game.world.WorldPos;
import game.world.WorldServer;
public class ScriptArgs {
private final String command;
private final Map<String, ScriptArg> arguments;
@ -126,6 +113,9 @@ public class ScriptArgs {
throw new ScriptException("Argument '%s' muss angegeben werden", param.getName());
}
}
else if(param.getParsers().isEmpty()) {
continue;
}
Map<String, Object> params = Maps.newHashMapWithExpectedSize(param.getParsers().size());
for(ArgumentParser parser : param.getParsers()) {
params.put(parser.getName(), parser.getDefault(env));
@ -200,212 +190,222 @@ public class ScriptArgs {
return null;
}
public static String[] parseComplete(ScriptEnvironment env, String[] argv, CachedExecutable cached) {
public static String[] parseComplete(ScriptEnvironment env, String[] argv, CachedExecutable cached, String last) {
String[] comp = getParam(env, argv, cached);
if(comp == null || comp.length == 0) {
Set<String> params = Sets.newTreeSet();
boolean all = last.startsWith("--");
for(String param : cached.getParameters().keySet()) {
params.add(param.length() == 1 ? "-" + param : ("--" + param));
if(all || param.length() == 1)
params.add(param.length() == 1 ? "-" + param : ("--" + param));
}
comp = params.toArray(new String[params.size()]);
}
return comp;
}
public ScriptArg getArg(String name) {
return this.arguments.get(name);
}
// public ScriptArg getArg(String name) {
// return this.arguments.get(name);
// }
public boolean hasArg(String name) {
return this.arguments.containsKey(name);
}
public boolean has(String name, String par) {
return this.arguments.containsKey(name) && this.arguments.get(name).getValues().containsKey(par);
}
// public boolean has(String name, String par) {
// return this.arguments.containsKey(name) && this.arguments.get(name).getValues().containsKey(par);
// }
public boolean has(String name) {
return this.has(name, name);
}
// public boolean has(String name) {
// return this.has(name, name);
// }
public <T> T getDefault(String name, String par, T def) {
// public <T> T getDefault(String name, String par, T def) {
// ScriptArg arg = this.arguments.get(name);
// if(arg == null)
// return def;
// Object value = arg.getValues().get(par);
// return value == null ? def : (T)value;
// }
//
// public <T> T getDefault(String name, T def) {
// return this.getDefault(name, name, def);
// }
//
// public <T> T getUnchecked(String name, String par) {
// return this.getDefault(name, par, null);
// }
public <T> T getUnchecked(String name, String par) {
ScriptArg arg = this.arguments.get(name);
if(arg == null)
return def;
return null;
Object value = arg.getValues().get(par);
return value == null ? def : (T)value;
return value == null ? null : (T)value;
}
public <T> T getDefault(String name, T def) {
return this.getDefault(name, name, def);
}
public <T> T getUnchecked(String name, String par) {
return this.getDefault(name, par, null);
}
public <T> T getUnchecked(String name) {
return this.getDefault(name, null);
}
public boolean getBool(String name, boolean def) {
return this.getDefault(name, def);
}
public boolean getBool(String name) {
return this.getUnchecked(name);
}
public <T extends Enum<?>> T getEnum(String name, T def) {
return this.getDefault(name, def);
}
public <T extends Enum<?>> T getEnum(String name) {
return this.getUnchecked(name);
}
public int getInt(String name, int def) {
return this.getDefault(name, def);
}
public int getInt(String name) {
return this.getUnchecked(name);
}
public long getLong(String name, long def) {
return this.getDefault(name, def);
}
public long getLong(String name) {
return this.getUnchecked(name);
}
public double getDouble(String name, double def) {
return this.getDefault(name, def);
}
public double getDouble(String name) {
return this.getUnchecked(name);
}
public String getString(String name, String def) {
return this.getDefault(name, def);
}
public String getString(String name) {
return this.getUnchecked(name);
}
public String[] getStrings(String name, String[] def) {
return this.getDefault(name, def);
}
public String[] getStrings(String name) {
return this.getUnchecked(name);
}
public Entity getEntity(String name, Entity def) {
return this.getDefault(name, def);
}
public Entity getEntity(String name) {
return this.getUnchecked(name);
}
public EntityLiving getLiving(String name, EntityLiving def) {
return this.getDefault(name, def);
}
public EntityLiving getLiving(String name) {
return this.getUnchecked(name);
}
public EntityNPC getNpc(String name, EntityNPC def) {
return this.getDefault(name, def);
}
public EntityNPC getNpc(String name) {
return this.getUnchecked(name);
}
public Block getBlock(String name, Block def) {
return this.getDefault(name, def);
}
public Block getBlock(String name) {
return this.getUnchecked(name);
}
public State getState(String name, State def) {
return this.getDefault(name, def);
}
public State getState(String name) {
return this.getUnchecked(name);
}
public Item getItem(String name, Item def) {
return this.getDefault(name, def);
}
public Item getItem(String name) {
return this.getUnchecked(name);
}
public ItemStack getStack(String name, ItemStack def) {
return this.getDefault(name, def);
}
public ItemStack getStack(String name) {
return this.getUnchecked(name);
}
public BlockPos getColumnPos(String name, BlockPos def) {
return this.hasArg(name) ? this.getColumnPos(name) : def;
}
public BlockPos getColumnPos(String name) {
return new BlockPos(this.getUnchecked(name, "x"), 0, this.getUnchecked(name, "z"));
}
public BlockPos getBlockPos(String name, BlockPos def) {
return this.hasArg(name) ? this.getBlockPos(name) : def;
}
public BlockPos getBlockPos(String name) {
return new BlockPos(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z"));
}
public WorldPos getWorldPos(String name, WorldPos def) {
return this.hasArg(name) ? this.getWorldPos(name) : def;
}
public WorldPos getWorldPos(String name) {
return new WorldPos(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z"),
this.getUnchecked(name, "dim"));
}
public Vec3 getVector2D(String name, Vec3 def) {
return this.hasArg(name) ? this.getVector2D(name) : def;
}
public Vec3 getVector2D(String name) {
return new Vec3(this.getUnchecked(name, "x"), 0.0, this.getUnchecked(name, "z"));
}
public Vec3 getVector(String name, Vec3 def) {
return this.hasArg(name) ? this.getVector(name) : def;
}
public Vec3 getVector(String name) {
return new Vec3(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z"));
}
public WorldServer getWorld(String name) {
return this.getUnchecked(name);
}
public NBTTagCompound getTag(String name) {
return this.getUnchecked(name);
}
// public <T> T getUnchecked(String name) {
// return this.getDefault(name, null);
// }
//
// public boolean getBool(String name, boolean def) {
// return this.getDefault(name, def);
// }
//
// public boolean getBool(String name) {
// return this.getUnchecked(name);
// }
//
// public <T extends Enum<?>> T getEnum(String name, T def) {
// return this.getDefault(name, def);
// }
//
// public <T extends Enum<?>> T getEnum(String name) {
// return this.getUnchecked(name);
// }
//
// public int getInt(String name, int def) {
// return this.getDefault(name, def);
// }
//
// public int getInt(String name) {
// return this.getUnchecked(name);
// }
//
// public long getLong(String name, long def) {
// return this.getDefault(name, def);
// }
//
// public long getLong(String name) {
// return this.getUnchecked(name);
// }
//
// public double getDouble(String name, double def) {
// return this.getDefault(name, def);
// }
//
// public double getDouble(String name) {
// return this.getUnchecked(name);
// }
//
// public String getString(String name, String def) {
// return this.getDefault(name, def);
// }
//
// public String getString(String name) {
// return this.getUnchecked(name);
// }
//
// public String[] getStrings(String name, String[] def) {
// return this.getDefault(name, def);
// }
//
// public String[] getStrings(String name) {
// return this.getUnchecked(name);
// }
//
// public Entity getEntity(String name, Entity def) {
// return this.getDefault(name, def);
// }
//
// public Entity getEntity(String name) {
// return this.getUnchecked(name);
// }
//
// public EntityLiving getLiving(String name, EntityLiving def) {
// return this.getDefault(name, def);
// }
//
// public EntityLiving getLiving(String name) {
// return this.getUnchecked(name);
// }
//
// public EntityNPC getNpc(String name, EntityNPC def) {
// return this.getDefault(name, def);
// }
//
// public EntityNPC getNpc(String name) {
// return this.getUnchecked(name);
// }
//
// public Block getBlock(String name, Block def) {
// return this.getDefault(name, def);
// }
//
// public Block getBlock(String name) {
// return this.getUnchecked(name);
// }
//
// public State getState(String name, State def) {
// return this.getDefault(name, def);
// }
//
// public State getState(String name) {
// return this.getUnchecked(name);
// }
//
// public Item getItem(String name, Item def) {
// return this.getDefault(name, def);
// }
//
// public Item getItem(String name) {
// return this.getUnchecked(name);
// }
//
// public ItemStack getStack(String name, ItemStack def) {
// return this.getDefault(name, def);
// }
//
// public ItemStack getStack(String name) {
// return this.getUnchecked(name);
// }
//
// public BlockPos getColumnPos(String name, BlockPos def) {
// return this.hasArg(name) ? this.getColumnPos(name) : def;
// }
//
// public BlockPos getColumnPos(String name) {
// return new BlockPos(this.getUnchecked(name, "x"), 0, this.getUnchecked(name, "z"));
// }
//
// public BlockPos getBlockPos(String name, BlockPos def) {
// return this.hasArg(name) ? this.getBlockPos(name) : def;
// }
//
// public BlockPos getBlockPos(String name) {
// return new BlockPos(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z"));
// }
//
// public WorldPos getWorldPos(String name, WorldPos def) {
// return this.hasArg(name) ? this.getWorldPos(name) : def;
// }
//
// public WorldPos getWorldPos(String name) {
// return new WorldPos(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z"),
// this.getUnchecked(name, "dim"));
// }
//
// public Vec3 getVector2D(String name, Vec3 def) {
// return this.hasArg(name) ? this.getVector2D(name) : def;
// }
//
// public Vec3 getVector2D(String name) {
// return new Vec3(this.getUnchecked(name, "x"), 0.0, this.getUnchecked(name, "z"));
// }
//
// public Vec3 getVector(String name, Vec3 def) {
// return this.hasArg(name) ? this.getVector(name) : def;
// }
//
// public Vec3 getVector(String name) {
// return new Vec3(this.getUnchecked(name, "x"), this.getUnchecked(name, "y"), this.getUnchecked(name, "z"));
// }
//
// public WorldServer getWorld(String name) {
// return this.getUnchecked(name);
// }
//
// public NBTTagCompound getTag(String name) {
// return this.getUnchecked(name);
// }
}