Add custom usercontent loading from json and javascript files alongside bugfixes for page list, refactorings and documentation
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -5,6 +5,8 @@
|
||||
|
||||
!/src/
|
||||
!/gradle/
|
||||
!/run/config/worldhandler/usercontent/
|
||||
!/usercontent/
|
||||
!build.gradle
|
||||
!curseforge.html
|
||||
!gradlew
|
||||
|
||||
10
README.md
10
README.md
@@ -6,10 +6,11 @@ It lets you create powerful and complex sub-commands alongside NBT-structures wi
|
||||
# Features #
|
||||
|
||||
* GUI for commands
|
||||
* World and player information
|
||||
* /wh for a simplified /fill and /clone
|
||||
* Client Commands: advancement, blockdata, clear, clone, difficulty, effect, enchant, fill, gamemode, gamerule, give, kill, recipe, scoreboard, setworldspawn, spawnpoint, summon, tag, team, time, trigger, weather, xp
|
||||
* Server Commands: ban, deop, kick, op, pardon, save-all, save-off, save-on, whitelist
|
||||
* World and player information
|
||||
* /wh for a simplified /fill and /clone
|
||||
* Expandable GUI with json files and child mods
|
||||
* Client-side only
|
||||
|
||||
# Download #
|
||||
@@ -55,6 +56,11 @@ Download World Handler or build from source
|
||||
2. Copy all files of the `World_Handler_GUI_[VERSION].zip` into the `1.6.2ML.jar`
|
||||
3. Run Minecraft
|
||||
|
||||
# Expansion #
|
||||
|
||||
The World Handler GUI can also be expanded with custom tabs configured with json and javascript files or as a separate child mod in java.
|
||||
A description on how to implement a custom json and javascript file can be found [here](https://github.com/Exopandora/WorldHandler/blob/master/README.md) and an example child mod can be found [here](https://github.com/Exopandora/WorldHandlerPlugin).
|
||||
|
||||
# FAQ #
|
||||
|
||||
**Q:** Is this client-side only ?
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
<li>
|
||||
GUI for commands
|
||||
</li>
|
||||
<li>
|
||||
Client Commands: advancement, blockdata, clear, clone, difficulty, effect, enchant, fill, gamemode, gamerule, give, kill, recipe, scoreboard, setworldspawn, spawnpoint, summon, tag, team, time, trigger, weather, xp
|
||||
</li>
|
||||
<li>
|
||||
Server Commands: ban, deop, kick, op, pardon, save-all, save-off, save-on, whitelist
|
||||
</li>
|
||||
<li>
|
||||
World and player information
|
||||
</li>
|
||||
@@ -16,10 +22,7 @@
|
||||
/wh for a simplified /fill and /clone
|
||||
</li>
|
||||
<li>
|
||||
Client Commands: advancement, blockdata, clear, clone, difficulty, effect, enchant, fill, gamemode, gamerule, give, kill, recipe, scoreboard, setworldspawn, spawnpoint, summon, tag, team, time, trigger, weather, xp
|
||||
</li>
|
||||
<li>
|
||||
Server Commands: ban, deop, kick, op, pardon, save-all, save-off, save-on, whitelist
|
||||
Expandable GUI with json files and child mods
|
||||
</li>
|
||||
<li>
|
||||
Client-side only
|
||||
@@ -103,6 +106,11 @@
|
||||
3. Run Minecraft
|
||||
</li>
|
||||
</ol>
|
||||
<h2><strong>Expansion</strong></h2>
|
||||
<p>
|
||||
The World Handler GUI can also be expanded with custom tabs configured with json and javascript files or as a separate child mod written in java.
|
||||
A description on how to implement a custom json and javascript file can be found <a href="https://github.com/Exopandora/WorldHandler/blob/master/README.md">here</a> and an example child mod can be found <a href="https://github.com/Exopandora/WorldHandlerPlugin">here</a>.
|
||||
</p>
|
||||
<h2><strong>FAQ</strong></h2>
|
||||
<ol>
|
||||
<li>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package exopandora.worldhandler;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -10,6 +12,7 @@ import exopandora.worldhandler.gui.category.Category;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.helper.AdvancementHelper;
|
||||
import exopandora.worldhandler.helper.CommandHelper;
|
||||
import exopandora.worldhandler.usercontent.UsercontentLoader;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.resources.SimpleReloadableResourceManager;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
@@ -24,11 +27,13 @@ import net.minecraftforge.fml.config.ModConfig.Type;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
|
||||
@Mod(Main.MODID)
|
||||
public class WorldHandler
|
||||
{
|
||||
public static final Logger LOGGER = LogManager.getLogger();
|
||||
public static final Path USERCONTENT_PATH = FMLPaths.CONFIGDIR.get().resolve(Main.MODID).resolve("usercontent");
|
||||
|
||||
public WorldHandler()
|
||||
{
|
||||
@@ -39,7 +44,9 @@ public class WorldHandler
|
||||
{
|
||||
SimpleReloadableResourceManager manager = (SimpleReloadableResourceManager) Minecraft.getInstance().getResourceManager();
|
||||
manager.addReloadListener(AdvancementHelper.getInstance());
|
||||
ModLoadingContext.get().registerConfig(Type.CLIENT, Config.CLIENT_SPEC, Main.MODID + ".toml");
|
||||
Config.setupDirectories(WorldHandler.USERCONTENT_PATH);
|
||||
ModLoadingContext.get().registerConfig(Type.CLIENT, Config.CLIENT_SPEC, Main.MODID + "/" + Main.MODID + ".toml");
|
||||
UsercontentLoader.load(WorldHandler.USERCONTENT_PATH);
|
||||
modEventBus.register(Config.class);
|
||||
modEventBus.addListener(Content::createRegistry);
|
||||
modEventBus.addListener(Category::createRegistry);
|
||||
|
||||
@@ -8,14 +8,14 @@ import java.util.stream.Collectors;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.WorldHandler;
|
||||
import exopandora.worldhandler.builder.Syntax.SyntaxEntry;
|
||||
import exopandora.worldhandler.builder.CommandSyntax.Argument;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import exopandora.worldhandler.builder.types.BlockResourceLocation;
|
||||
import exopandora.worldhandler.builder.types.CoordinateDouble;
|
||||
import exopandora.worldhandler.builder.types.CoordinateInt;
|
||||
import exopandora.worldhandler.builder.types.GreedyString;
|
||||
import exopandora.worldhandler.builder.types.ItemResourceLocation;
|
||||
import exopandora.worldhandler.builder.types.TargetSelector;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
@@ -24,7 +24,7 @@ import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public abstract class CommandBuilder implements ICommandBuilderSyntax
|
||||
{
|
||||
private List<Entry<SyntaxEntry, String>> command;
|
||||
private List<Entry<Argument, String>> command;
|
||||
|
||||
public CommandBuilder()
|
||||
{
|
||||
@@ -33,93 +33,98 @@ public abstract class CommandBuilder implements ICommandBuilderSyntax
|
||||
|
||||
protected void setNode(int index, String node)
|
||||
{
|
||||
this.set(index, node != null ? (node.isEmpty() ? null : node) : null, Type.STRING);
|
||||
this.set(index, node != null ? (node.isEmpty() ? null : node) : null, ArgumentType.STRING);
|
||||
}
|
||||
|
||||
protected void setNode(int index, GreedyString node)
|
||||
{
|
||||
this.set(index, node != null ? (node.isEmpty() ? null : node) : null, Type.GREEDY_STRING);
|
||||
this.set(index, node != null ? (node.isEmpty() ? null : node) : null, ArgumentType.GREEDY_STRING);
|
||||
}
|
||||
|
||||
protected void setNode(int index, boolean node)
|
||||
{
|
||||
this.set(index, node, Type.BOOLEAN);
|
||||
this.set(index, node, ArgumentType.BOOLEAN);
|
||||
}
|
||||
|
||||
protected void setNode(int index, short node)
|
||||
{
|
||||
this.set(index, node, Type.SHORT);
|
||||
this.set(index, node, ArgumentType.SHORT);
|
||||
}
|
||||
|
||||
protected void setNode(int index, byte node)
|
||||
{
|
||||
this.set(index, node, Type.BYTE);
|
||||
this.set(index, node, ArgumentType.BYTE);
|
||||
}
|
||||
|
||||
protected void setNode(int index, int node)
|
||||
{
|
||||
this.set(index, node, Type.INT);
|
||||
this.set(index, node, ArgumentType.INT);
|
||||
}
|
||||
|
||||
protected void setNode(int index, float node)
|
||||
{
|
||||
this.set(index, node, Type.FLOAT);
|
||||
this.set(index, node, ArgumentType.FLOAT);
|
||||
}
|
||||
|
||||
protected void setNode(int index, double node)
|
||||
{
|
||||
this.set(index, node, Type.DOUBLE);
|
||||
this.set(index, node, ArgumentType.DOUBLE);
|
||||
}
|
||||
|
||||
protected void setNode(int index, long node)
|
||||
{
|
||||
this.set(index, node, Type.LONG);
|
||||
this.set(index, node, ArgumentType.LONG);
|
||||
}
|
||||
|
||||
protected void setNode(int index, ResourceLocation node)
|
||||
{
|
||||
this.set(index, node, Type.RESOURCE_LOCATION);
|
||||
this.set(index, node, ArgumentType.RESOURCE_LOCATION);
|
||||
}
|
||||
|
||||
protected void setNode(int index, CoordinateInt coordinate)
|
||||
{
|
||||
this.set(index, coordinate, Type.COORDINATE_INT);
|
||||
this.set(index, coordinate, ArgumentType.COORDINATE_INT);
|
||||
}
|
||||
|
||||
protected void setNode(int index, CoordinateDouble coordinate)
|
||||
{
|
||||
this.set(index, coordinate, Type.COORDINATE_DOUBLE);
|
||||
this.set(index, coordinate, ArgumentType.COORDINATE_DOUBLE);
|
||||
}
|
||||
|
||||
protected void setNode(int index, TargetSelector target)
|
||||
{
|
||||
this.set(index, target, Type.TARGET_SELECTOR);
|
||||
this.set(index, target, ArgumentType.TARGET_SELECTOR);
|
||||
}
|
||||
|
||||
protected void setNode(int index, ItemResourceLocation resource)
|
||||
{
|
||||
this.set(index, resource != null ? resource.get() : null, Type.ITEM_RESOURCE_LOCATION);
|
||||
this.set(index, resource != null ? resource.get() : null, ArgumentType.ITEM_RESOURCE_LOCATION);
|
||||
}
|
||||
|
||||
protected void setNode(int index, BlockResourceLocation resource)
|
||||
{
|
||||
this.set(index, resource != null ? resource.get() : null, Type.BLOCK_RESOURCE_LOCATION);
|
||||
this.set(index, resource != null ? resource.get() : null, ArgumentType.BLOCK_RESOURCE_LOCATION);
|
||||
}
|
||||
|
||||
protected void setNode(int index, CompoundNBT nbt)
|
||||
{
|
||||
this.set(index, nbt, Type.NBT);
|
||||
this.set(index, nbt, ArgumentType.NBT);
|
||||
}
|
||||
|
||||
private void set(int index, Object value, Type type)
|
||||
protected void setPlayerName(int index, String username)
|
||||
{
|
||||
this.set(index, username, ArgumentType.PLAYER);
|
||||
}
|
||||
|
||||
private void set(int index, Object value, ArgumentType type)
|
||||
{
|
||||
if(index < this.command.size())
|
||||
{
|
||||
SyntaxEntry entry = this.command.get(index).getKey();
|
||||
Type expected = entry.getType();
|
||||
boolean flag = expected.equals(type);
|
||||
Argument entry = this.command.get(index).getKey();
|
||||
ArgumentType expectedType = entry.getType();
|
||||
boolean typeMatch = expectedType.equals(type);
|
||||
|
||||
if(value != null && flag)
|
||||
if(value != null && typeMatch)
|
||||
{
|
||||
this.command.get(index).setValue(value.toString());
|
||||
}
|
||||
@@ -127,9 +132,9 @@ public abstract class CommandBuilder implements ICommandBuilderSyntax
|
||||
{
|
||||
this.command.get(index).setValue(entry.toString());
|
||||
|
||||
if(!flag)
|
||||
if(!typeMatch)
|
||||
{
|
||||
this.warn("set", expected, type, index);
|
||||
this.warn("set", expectedType, type, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,96 +147,96 @@ public abstract class CommandBuilder implements ICommandBuilderSyntax
|
||||
@Nullable
|
||||
protected String getNodeAsString(int index)
|
||||
{
|
||||
return this.get(index, Type.STRING);
|
||||
return this.get(index, ArgumentType.STRING);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected String getNodeAsGreedyString(int index)
|
||||
{
|
||||
return this.get(index, Type.GREEDY_STRING);
|
||||
return this.get(index, ArgumentType.GREEDY_STRING);
|
||||
}
|
||||
|
||||
protected boolean getNodeAsBoolean(int index)
|
||||
{
|
||||
return this.get(index, Type.BOOLEAN);
|
||||
return this.get(index, ArgumentType.BOOLEAN);
|
||||
}
|
||||
|
||||
protected short getNodeAsShort(int index)
|
||||
{
|
||||
return this.get(index, Type.SHORT);
|
||||
return this.get(index, ArgumentType.SHORT);
|
||||
}
|
||||
|
||||
protected byte getNodeAsByte(int index)
|
||||
{
|
||||
return this.get(index, Type.BYTE);
|
||||
return this.get(index, ArgumentType.BYTE);
|
||||
}
|
||||
|
||||
protected int getNodeAsInt(int index)
|
||||
{
|
||||
return this.get(index, Type.INT);
|
||||
return this.get(index, ArgumentType.INT);
|
||||
}
|
||||
|
||||
protected float getNodeAsFloat(int index)
|
||||
{
|
||||
return this.get(index, Type.FLOAT);
|
||||
return this.get(index, ArgumentType.FLOAT);
|
||||
}
|
||||
|
||||
protected double getNodeAsDouble(int index)
|
||||
{
|
||||
return this.get(index, Type.DOUBLE);
|
||||
return this.get(index, ArgumentType.DOUBLE);
|
||||
}
|
||||
|
||||
protected long getNodeAsLong(int index)
|
||||
{
|
||||
return this.get(index, Type.LONG);
|
||||
return this.get(index, ArgumentType.LONG);
|
||||
}
|
||||
|
||||
protected CoordinateInt getNodeAsCoordinateInt(int index)
|
||||
{
|
||||
return this.get(index, Type.COORDINATE_INT);
|
||||
return this.get(index, ArgumentType.COORDINATE_INT);
|
||||
}
|
||||
|
||||
protected CoordinateDouble getNodeAsCoordinateDouble(int index)
|
||||
{
|
||||
return this.get(index, Type.COORDINATE_DOUBLE);
|
||||
return this.get(index, ArgumentType.COORDINATE_DOUBLE);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected ResourceLocation getNodeAsResourceLocation(int index)
|
||||
{
|
||||
return this.get(index, Type.RESOURCE_LOCATION);
|
||||
return this.get(index, ArgumentType.RESOURCE_LOCATION);
|
||||
}
|
||||
|
||||
protected TargetSelector getNodeAsTargetSelector(int index)
|
||||
{
|
||||
return this.get(index, Type.TARGET_SELECTOR);
|
||||
return this.get(index, ArgumentType.TARGET_SELECTOR);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected ItemResourceLocation getNodeAsItemResourceLocation(int index)
|
||||
{
|
||||
return this.get(index, Type.ITEM_RESOURCE_LOCATION);
|
||||
return this.get(index, ArgumentType.ITEM_RESOURCE_LOCATION);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected BlockResourceLocation getNodeAsBlockResourceLocation(int index)
|
||||
{
|
||||
return this.get(index, Type.BLOCK_RESOURCE_LOCATION);
|
||||
return this.get(index, ArgumentType.BLOCK_RESOURCE_LOCATION);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected CompoundNBT getNodeAsNBT(int index)
|
||||
{
|
||||
return this.get(index, Type.NBT);
|
||||
return this.get(index, ArgumentType.NBT);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private <T> T get(int index, Type type)
|
||||
private <T> T get(int index, ArgumentType type)
|
||||
{
|
||||
if(index < this.command.size())
|
||||
{
|
||||
Entry<SyntaxEntry, String> entry = this.command.get(index);
|
||||
Type expected = entry.getKey().getType();
|
||||
Entry<Argument, String> entry = this.command.get(index);
|
||||
ArgumentType expected = entry.getKey().getType();
|
||||
String value = entry.getValue();
|
||||
|
||||
if(expected.equals(type))
|
||||
@@ -252,21 +257,21 @@ public abstract class CommandBuilder implements ICommandBuilderSyntax
|
||||
return null;
|
||||
}
|
||||
|
||||
private void warn(String function, Type expected, Type type, int index)
|
||||
private void warn(String function, ArgumentType expected, ArgumentType type, int index)
|
||||
{
|
||||
WorldHandler.LOGGER.warn("[" + function.toUpperCase() + "] Expected \"" + expected + "\" instead of \"" + type + "\" at index \"" + index + "\" for command \"" + this.getCommandName() + "\"");
|
||||
}
|
||||
|
||||
private boolean isDefaultEntry(Entry<SyntaxEntry, String> entry)
|
||||
private boolean isDefaultEntry(Entry<Argument, String> entry)
|
||||
{
|
||||
return entry.getKey().getDefault() != null ? entry.getValue().equals(entry.getKey().getDefault().toString()) : false;
|
||||
}
|
||||
|
||||
protected void updateSyntax(Syntax syntax)
|
||||
protected void updateSyntax(CommandSyntax syntax)
|
||||
{
|
||||
if(syntax != null)
|
||||
{
|
||||
this.command = syntax.getSyntaxEntries().stream().map(entry -> new SimpleEntry<SyntaxEntry, String>(entry, entry.toString())).collect(Collectors.toList());
|
||||
this.command = syntax.getArguments().stream().map(entry -> new SimpleEntry<Argument, String>(entry, entry.toString())).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,7 +280,7 @@ public abstract class CommandBuilder implements ICommandBuilderSyntax
|
||||
{
|
||||
CommandString command = new CommandString(this.getCommandName());
|
||||
|
||||
for(Entry<SyntaxEntry, String> entry : this.command)
|
||||
for(Entry<Argument, String> entry : this.command)
|
||||
{
|
||||
if(this.isDefaultEntry(entry))
|
||||
{
|
||||
@@ -295,14 +300,21 @@ public abstract class CommandBuilder implements ICommandBuilderSyntax
|
||||
{
|
||||
CommandString command = new CommandString(this.getCommandName());
|
||||
|
||||
for(Entry<SyntaxEntry, String> entry : this.command)
|
||||
for(Entry<Argument, String> entry : this.command)
|
||||
{
|
||||
if(!entry.getKey().isRequired() && (entry.getKey().toString().equals(entry.getValue()) || this.isDefaultEntry(entry)))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
command.append(entry.getValue());
|
||||
if(entry.getKey().isRequired() && entry.getKey().toString().equals(entry.getValue()) && entry.getKey().getDefault() != null)
|
||||
{
|
||||
command.append(entry.getKey().getDefault().toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
command.append(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return command.toString();
|
||||
|
||||
112
src/main/java/exopandora/worldhandler/builder/CommandSyntax.java
Normal file
112
src/main/java/exopandora/worldhandler/builder/CommandSyntax.java
Normal file
@@ -0,0 +1,112 @@
|
||||
package exopandora.worldhandler.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class CommandSyntax
|
||||
{
|
||||
private List<Argument> syntax = new ArrayList<Argument>();
|
||||
|
||||
public CommandSyntax()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public CommandSyntax(List<Argument> syntax)
|
||||
{
|
||||
this.syntax = syntax;
|
||||
}
|
||||
|
||||
public CommandSyntax addRequired(String key, ArgumentType type)
|
||||
{
|
||||
this.syntax.add(new Argument(key, type, true, null));
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandSyntax addRequired(String key, ArgumentType type, Object def)
|
||||
{
|
||||
this.syntax.add(new Argument(key, type, true, def));
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandSyntax addOptional(String key, ArgumentType type)
|
||||
{
|
||||
this.syntax.add(new Argument(key, type, false, null));
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandSyntax addOptional(String key, ArgumentType type, Object def)
|
||||
{
|
||||
this.syntax.add(new Argument(key, type, false, def));
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<Argument> getArguments()
|
||||
{
|
||||
return this.syntax;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static class Argument
|
||||
{
|
||||
@SerializedName("name")
|
||||
private final String key;
|
||||
|
||||
@SerializedName("type")
|
||||
private final ArgumentType type;
|
||||
|
||||
@SerializedName("required")
|
||||
private final boolean required;
|
||||
|
||||
@SerializedName("default")
|
||||
private final Object def;
|
||||
|
||||
public Argument(String key, ArgumentType type, boolean required, Object def)
|
||||
{
|
||||
this.key = key;
|
||||
this.type = type;
|
||||
this.required = required;
|
||||
this.def = def;
|
||||
}
|
||||
|
||||
public String getKey()
|
||||
{
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public ArgumentType getType()
|
||||
{
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public boolean isRequired()
|
||||
{
|
||||
return this.required;
|
||||
}
|
||||
|
||||
public Object getDefault()
|
||||
{
|
||||
return this.def;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if(this.required)
|
||||
{
|
||||
return "<" + this.key + ">";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "[" + this.key + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ public interface ICommandBuilderSyntax extends ICommandBuilder
|
||||
{
|
||||
String getCommandName();
|
||||
String toActualCommand();
|
||||
Syntax getSyntax();
|
||||
CommandSyntax getSyntax();
|
||||
|
||||
@Override
|
||||
default boolean needsCommandBlock()
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
package exopandora.worldhandler.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class Syntax
|
||||
{
|
||||
private List<SyntaxEntry> syntax = new ArrayList<SyntaxEntry>();
|
||||
|
||||
public Syntax addRequired(String key, Type type)
|
||||
{
|
||||
this.syntax.add(new SyntaxEntry(key, type, true, null));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Syntax addRequired(String key, Type type, Object def)
|
||||
{
|
||||
this.syntax.add(new SyntaxEntry(key, type, true, def));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Syntax addOptional(String key, Type type)
|
||||
{
|
||||
this.syntax.add(new SyntaxEntry(key, type, false, null));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Syntax addOptional(String key, Type type, Object def)
|
||||
{
|
||||
this.syntax.add(new SyntaxEntry(key, type, false, def));
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<SyntaxEntry> getSyntaxEntries()
|
||||
{
|
||||
return this.syntax;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static class SyntaxEntry
|
||||
{
|
||||
private final String key;
|
||||
private final Type type;
|
||||
private final boolean required;
|
||||
private final Object def;
|
||||
|
||||
public SyntaxEntry(String key, Type type, boolean required, Object def)
|
||||
{
|
||||
this.key = key;
|
||||
this.type = type;
|
||||
this.required = required;
|
||||
this.def = def;
|
||||
}
|
||||
|
||||
public String getKey()
|
||||
{
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public Type getType()
|
||||
{
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public boolean isRequired()
|
||||
{
|
||||
return this.required;
|
||||
}
|
||||
|
||||
public Object getDefault()
|
||||
{
|
||||
return this.def;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if(this.required)
|
||||
{
|
||||
return "<" + this.key + ">";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "[" + this.key + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package exopandora.worldhandler.builder.component.abstr;
|
||||
package exopandora.worldhandler.builder.component.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -6,7 +6,7 @@ import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import exopandora.worldhandler.builder.component.IBuilderComponent;
|
||||
import exopandora.worldhandler.builder.impl.abstr.EnumAttributes;
|
||||
import exopandora.worldhandler.builder.impl.EnumAttributes;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -6,8 +6,7 @@ import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.component.abstr.ComponentAttribute;
|
||||
import exopandora.worldhandler.builder.impl.abstr.EnumAttributes;
|
||||
import exopandora.worldhandler.builder.impl.EnumAttributes;
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
|
||||
@@ -5,8 +5,7 @@ import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.component.abstr.ComponentAttribute;
|
||||
import exopandora.worldhandler.builder.impl.abstr.EnumAttributes;
|
||||
import exopandora.worldhandler.builder.impl.EnumAttributes;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package exopandora.worldhandler.builder.component.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.component.IBuilderComponent;
|
||||
import exopandora.worldhandler.text.MutableStringTextComponent;
|
||||
import exopandora.worldhandler.util.MutableStringTextComponent;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package exopandora.worldhandler.builder.component.abstr;
|
||||
package exopandora.worldhandler.builder.component.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -1,6 +1,5 @@
|
||||
package exopandora.worldhandler.builder.component.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.component.abstr.ComponentPotion;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package exopandora.worldhandler.builder.component.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.component.abstr.ComponentPotion;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package exopandora.worldhandler.builder.component.abstr;
|
||||
package exopandora.worldhandler.builder.component.impl;
|
||||
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
@@ -3,8 +3,8 @@ package exopandora.worldhandler.builder.impl;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import exopandora.worldhandler.helper.EnumHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
@@ -87,14 +87,14 @@ public class BuilderAdvancement extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("grant|revoke|test", Type.STRING);
|
||||
syntax.addRequired("player", Type.STRING);
|
||||
syntax.addRequired("only|until|from|through|everything", Type.STRING);
|
||||
syntax.addOptional("advancement", Type.RESOURCE_LOCATION);
|
||||
syntax.addRequired("grant|revoke|test", ArgumentType.STRING);
|
||||
syntax.addRequired("player", ArgumentType.STRING);
|
||||
syntax.addRequired("only|until|from|through|everything", ArgumentType.STRING);
|
||||
syntax.addOptional("advancement", ArgumentType.RESOURCE_LOCATION);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package exopandora.worldhandler.builder.impl.abstr;
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilderNBT;
|
||||
import exopandora.worldhandler.builder.types.CoordinateInt;
|
||||
@@ -3,9 +3,9 @@ package exopandora.worldhandler.builder.impl;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.TargetSelector;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
@@ -70,11 +70,11 @@ public class BuilderButcher extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public Syntax getSyntax()
|
||||
public CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("entity_name", Type.TARGET_SELECTOR);
|
||||
syntax.addRequired("entity_name", ArgumentType.TARGET_SELECTOR);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -2,11 +2,10 @@ package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.impl.abstr.BuilderDoubleBlockPos;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.Coordinate.CoordinateType;
|
||||
import exopandora.worldhandler.builder.types.CoordinateInt;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import exopandora.worldhandler.helper.EnumHelper;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
@@ -133,21 +132,21 @@ public class BuilderClone extends BuilderDoubleBlockPos
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("x1", Type.COORDINATE_INT);
|
||||
syntax.addRequired("y1", Type.COORDINATE_INT);
|
||||
syntax.addRequired("z1", Type.COORDINATE_INT);
|
||||
syntax.addRequired("x2", Type.COORDINATE_INT);
|
||||
syntax.addRequired("y2", Type.COORDINATE_INT);
|
||||
syntax.addRequired("z2", Type.COORDINATE_INT);
|
||||
syntax.addRequired("x", Type.COORDINATE_INT);
|
||||
syntax.addRequired("y", Type.COORDINATE_INT);
|
||||
syntax.addRequired("z", Type.COORDINATE_INT);
|
||||
syntax.addOptional("mask", Type.STRING);
|
||||
syntax.addOptional("filter", Type.STRING);
|
||||
syntax.addRequired("x1", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("y1", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("z1", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("x2", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("y2", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("z2", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("x", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("y", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("z", ArgumentType.COORDINATE_INT);
|
||||
syntax.addOptional("mask", ArgumentType.STRING);
|
||||
syntax.addOptional("filter", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -5,9 +5,8 @@ import java.util.Set;
|
||||
import exopandora.worldhandler.builder.component.impl.ComponentAttributeItem;
|
||||
import exopandora.worldhandler.builder.component.impl.ComponentDisplay;
|
||||
import exopandora.worldhandler.builder.component.impl.ComponentEnchantment;
|
||||
import exopandora.worldhandler.builder.impl.abstr.EnumAttributes;
|
||||
import exopandora.worldhandler.builder.impl.abstr.EnumAttributes.Applyable;
|
||||
import exopandora.worldhandler.text.MutableStringTextComponent;
|
||||
import exopandora.worldhandler.builder.impl.EnumAttributes.Applyable;
|
||||
import exopandora.worldhandler.util.MutableStringTextComponent;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
|
||||
@@ -3,11 +3,10 @@ package exopandora.worldhandler.builder.impl;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.impl.abstr.BuilderBlockPos;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.CoordinateInt;
|
||||
import exopandora.worldhandler.builder.types.TargetSelector;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import exopandora.worldhandler.helper.EnumHelper;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -180,24 +179,24 @@ public class BuilderData extends BuilderBlockPos
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private final Syntax getSyntax(EnumMode mode, EnumTarget target)
|
||||
private final CommandSyntax getSyntax(EnumMode mode, EnumTarget target)
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired(mode != null ? mode.toString() : "mode", Type.STRING);
|
||||
syntax.addRequired(target != null ? target.toString() : "target", Type.STRING);
|
||||
syntax.addRequired(mode != null ? mode.toString() : "mode", ArgumentType.STRING);
|
||||
syntax.addRequired(target != null ? target.toString() : "target", ArgumentType.STRING);
|
||||
|
||||
if(target != null)
|
||||
{
|
||||
switch(target)
|
||||
{
|
||||
case BLOCK:
|
||||
syntax.addRequired("x", Type.COORDINATE_INT);
|
||||
syntax.addRequired("y", Type.COORDINATE_INT);
|
||||
syntax.addRequired("z", Type.COORDINATE_INT);
|
||||
syntax.addRequired("x", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("y", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("z", ArgumentType.COORDINATE_INT);
|
||||
break;
|
||||
case ENTITY:
|
||||
syntax.addRequired("entity", Type.TARGET_SELECTOR);
|
||||
syntax.addRequired("entity", ArgumentType.TARGET_SELECTOR);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -208,10 +207,10 @@ public class BuilderData extends BuilderBlockPos
|
||||
case GET:
|
||||
break;
|
||||
case MERGE:
|
||||
syntax.addRequired("nbt", Type.NBT);
|
||||
syntax.addRequired("nbt", ArgumentType.NBT);
|
||||
break;
|
||||
case REMOVE:
|
||||
syntax.addRequired("path", Type.STRING);
|
||||
syntax.addRequired("path", ArgumentType.STRING);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -219,7 +218,7 @@ public class BuilderData extends BuilderBlockPos
|
||||
}
|
||||
else
|
||||
{
|
||||
syntax.addOptional("...", Type.STRING);
|
||||
syntax.addOptional("...", ArgumentType.STRING);
|
||||
}
|
||||
|
||||
return syntax;
|
||||
@@ -283,13 +282,13 @@ public class BuilderData extends BuilderBlockPos
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("get|merge|remove", Type.STRING);
|
||||
syntax.addRequired("block|entity", Type.STRING);
|
||||
syntax.addOptional("...", Type.STRING);
|
||||
syntax.addRequired("get|merge|remove", ArgumentType.STRING);
|
||||
syntax.addRequired("block|entity", ArgumentType.STRING);
|
||||
syntax.addOptional("...", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraft.world.Difficulty;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
@@ -35,11 +35,11 @@ public class BuilderDifficulty extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("peaceful|easy|normal|hard", Type.STRING);
|
||||
syntax.addRequired("peaceful|easy|normal|hard", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package exopandora.worldhandler.builder.impl.abstr;
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.types.CoordinateInt;
|
||||
@@ -1,8 +1,8 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
@@ -53,13 +53,13 @@ public class BuilderEnchantment extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public Syntax getSyntax()
|
||||
public CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("player", Type.STRING);
|
||||
syntax.addRequired("enchantment", Type.RESOURCE_LOCATION);
|
||||
syntax.addOptional("level", Type.INT, 1);
|
||||
syntax.addRequired("player", ArgumentType.STRING);
|
||||
syntax.addRequired("enchantment", ArgumentType.RESOURCE_LOCATION);
|
||||
syntax.addOptional("level", ArgumentType.INT, 1);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package exopandora.worldhandler.builder.impl;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import exopandora.worldhandler.helper.EnumHelper;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
@@ -74,14 +74,14 @@ public class BuilderExperience extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public Syntax getSyntax()
|
||||
public CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("add|set|query", Type.STRING);
|
||||
syntax.addRequired("player", Type.STRING);
|
||||
syntax.addRequired("amount", Type.INT);
|
||||
syntax.addOptional("levels|points", Type.STRING);
|
||||
syntax.addRequired("add|set|query", ArgumentType.STRING);
|
||||
syntax.addRequired("player", ArgumentType.STRING);
|
||||
syntax.addRequired("amount", ArgumentType.INT);
|
||||
syntax.addOptional("levels|points", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -2,11 +2,10 @@ package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.impl.abstr.BuilderDoubleBlockPos;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.BlockResourceLocation;
|
||||
import exopandora.worldhandler.builder.types.CoordinateInt;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import exopandora.worldhandler.helper.BlockHelper;
|
||||
import exopandora.worldhandler.helper.EnumHelper;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -106,19 +105,19 @@ public class BuilderFill extends BuilderDoubleBlockPos
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("x1", Type.COORDINATE_INT);
|
||||
syntax.addRequired("y1", Type.COORDINATE_INT);
|
||||
syntax.addRequired("z1", Type.COORDINATE_INT);
|
||||
syntax.addRequired("x2", Type.COORDINATE_INT);
|
||||
syntax.addRequired("y2", Type.COORDINATE_INT);
|
||||
syntax.addRequired("z2", Type.COORDINATE_INT);
|
||||
syntax.addRequired("block", Type.BLOCK_RESOURCE_LOCATION);
|
||||
syntax.addOptional("filter", Type.STRING);
|
||||
syntax.addOptional("block", Type.BLOCK_RESOURCE_LOCATION, "block");
|
||||
syntax.addRequired("x1", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("y1", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("z1", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("x2", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("y2", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("z2", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("block", ArgumentType.BLOCK_RESOURCE_LOCATION);
|
||||
syntax.addOptional("filter", ArgumentType.STRING);
|
||||
syntax.addOptional("block", ArgumentType.BLOCK_RESOURCE_LOCATION, "block");
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -42,12 +42,12 @@ public class BuilderGamemode extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("mode", Type.STRING);
|
||||
syntax.addOptional("player", Type.STRING);
|
||||
syntax.addRequired("mode", ArgumentType.STRING);
|
||||
syntax.addOptional("player", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -52,12 +52,12 @@ public class BuilderGamerule extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addOptional("rule", Type.STRING);
|
||||
syntax.addOptional("true|false|value", Type.STRING);
|
||||
syntax.addOptional("rule", ArgumentType.STRING);
|
||||
syntax.addOptional("true|false|value", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ package exopandora.worldhandler.builder.impl;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilderNBT;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.ItemResourceLocation;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import exopandora.worldhandler.helper.ResourceHelper;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -86,13 +86,13 @@ public class BuilderGive extends CommandBuilderNBT
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("player", Type.STRING);
|
||||
syntax.addRequired("item", Type.ITEM_RESOURCE_LOCATION);
|
||||
syntax.addRequired("count", Type.INT);
|
||||
syntax.addRequired("player", ArgumentType.STRING);
|
||||
syntax.addRequired("item", ArgumentType.ITEM_RESOURCE_LOCATION);
|
||||
syntax.addRequired("count", ArgumentType.INT);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ public class BuilderMultiCommand implements ICommandBuilder
|
||||
{
|
||||
private final ICommandBuilder[] builders;
|
||||
|
||||
public BuilderMultiCommand(ICommandBuilder... builder)
|
||||
public BuilderMultiCommand(ICommandBuilder... builders)
|
||||
{
|
||||
this.builders = builder;
|
||||
this.builders = builders;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -33,11 +33,11 @@ public class BuilderPlayer extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("player", Type.STRING);
|
||||
syntax.addRequired("player", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -43,12 +43,12 @@ public class BuilderPlayerReason extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("player", Type.STRING);
|
||||
syntax.addOptional("reason", Type.STRING);
|
||||
syntax.addRequired("player", ArgumentType.STRING);
|
||||
syntax.addOptional("reason", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ package exopandora.worldhandler.builder.impl;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.component.abstr.EffectData;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.component.impl.EffectData;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraft.potion.Effect;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
@@ -170,16 +170,16 @@ public class BuilderPotionEffect extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("give|clear", Type.STRING);
|
||||
syntax.addRequired("player", Type.STRING);
|
||||
syntax.addRequired("effect", Type.RESOURCE_LOCATION);
|
||||
syntax.addOptional("seconds", Type.INT, 0);
|
||||
syntax.addOptional("amplifier", Type.BYTE, (byte) -1);
|
||||
syntax.addOptional("hideParticles", Type.BOOLEAN, false);
|
||||
syntax.addRequired("give|clear", ArgumentType.STRING);
|
||||
syntax.addRequired("player", ArgumentType.STRING);
|
||||
syntax.addRequired("effect", ArgumentType.RESOURCE_LOCATION);
|
||||
syntax.addOptional("seconds", ArgumentType.INT, 0);
|
||||
syntax.addOptional("amplifier", ArgumentType.BYTE, (byte) -1);
|
||||
syntax.addOptional("hideParticles", ArgumentType.BOOLEAN, false);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package exopandora.worldhandler.builder.impl;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import exopandora.worldhandler.helper.EnumHelper;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -76,13 +76,13 @@ public class BuilderRecipe extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public Syntax getSyntax()
|
||||
public CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("give|take", Type.STRING);
|
||||
syntax.addOptional("player", Type.STRING);
|
||||
syntax.addOptional("recipe", Type.RESOURCE_LOCATION);
|
||||
syntax.addRequired("give|take", ArgumentType.STRING);
|
||||
syntax.addOptional("player", ArgumentType.STRING);
|
||||
syntax.addOptional("recipe", ArgumentType.RESOURCE_LOCATION);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package exopandora.worldhandler.builder.impl.abstr;
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
@@ -2,10 +2,9 @@ package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.impl.abstr.BuilderScoreboard;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.GreedyString;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import exopandora.worldhandler.helper.EnumHelper;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
@@ -120,29 +119,29 @@ public class BuilderScoreboardObjectives extends BuilderScoreboard
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Syntax getSyntax(EnumMode mode)
|
||||
private CommandSyntax getSyntax(EnumMode mode)
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
case ADD:
|
||||
syntax.addRequired("objectives", Type.STRING);
|
||||
syntax.addRequired("add", Type.STRING);
|
||||
syntax.addRequired("name", Type.STRING);
|
||||
syntax.addRequired("criteria_type", Type.STRING);
|
||||
syntax.addOptional("display_name...", Type.GREEDY_STRING);
|
||||
syntax.addRequired("objectives", ArgumentType.STRING);
|
||||
syntax.addRequired("add", ArgumentType.STRING);
|
||||
syntax.addRequired("name", ArgumentType.STRING);
|
||||
syntax.addRequired("criteria_type", ArgumentType.STRING);
|
||||
syntax.addOptional("display_name...", ArgumentType.GREEDY_STRING);
|
||||
return syntax;
|
||||
case REMOVE:
|
||||
syntax.addRequired("objectives", Type.STRING);
|
||||
syntax.addRequired("remove", Type.STRING);
|
||||
syntax.addRequired("name", Type.STRING);
|
||||
syntax.addRequired("objectives", ArgumentType.STRING);
|
||||
syntax.addRequired("remove", ArgumentType.STRING);
|
||||
syntax.addRequired("name", ArgumentType.STRING);
|
||||
return syntax;
|
||||
case SETDISPLAY:
|
||||
syntax.addRequired("objectives", Type.STRING);
|
||||
syntax.addRequired("setdisplay", Type.STRING);
|
||||
syntax.addRequired("slot", Type.STRING);
|
||||
syntax.addOptional("objective", Type.STRING);
|
||||
syntax.addRequired("objectives", ArgumentType.STRING);
|
||||
syntax.addRequired("setdisplay", ArgumentType.STRING);
|
||||
syntax.addRequired("slot", ArgumentType.STRING);
|
||||
syntax.addOptional("objective", ArgumentType.STRING);
|
||||
return syntax;
|
||||
default:
|
||||
return null;
|
||||
@@ -150,13 +149,13 @@ public class BuilderScoreboardObjectives extends BuilderScoreboard
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("objectives", Type.STRING);
|
||||
syntax.addRequired("list|add|remove|setdisplay", Type.STRING);
|
||||
syntax.addOptional("...", Type.STRING);
|
||||
syntax.addRequired("objectives", ArgumentType.STRING);
|
||||
syntax.addRequired("list|add|remove|setdisplay", ArgumentType.STRING);
|
||||
syntax.addOptional("...", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.impl.abstr.BuilderScoreboard;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -91,25 +90,25 @@ public class BuilderScoreboardPlayers extends BuilderScoreboard
|
||||
return 0;
|
||||
}
|
||||
|
||||
private Syntax getSyntax(String mode)
|
||||
private CommandSyntax getSyntax(String mode)
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
if(mode.equals("enable"))
|
||||
{
|
||||
syntax.addRequired("players", Type.STRING);
|
||||
syntax.addRequired("enable", Type.STRING);
|
||||
syntax.addRequired("player", Type.STRING);
|
||||
syntax.addRequired("objective", Type.STRING);
|
||||
syntax.addRequired("players", ArgumentType.STRING);
|
||||
syntax.addRequired("enable", ArgumentType.STRING);
|
||||
syntax.addRequired("player", ArgumentType.STRING);
|
||||
syntax.addRequired("objective", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
syntax.addRequired("players", Type.STRING);
|
||||
syntax.addRequired("add|set|remove", Type.STRING, "add|set|remove");
|
||||
syntax.addRequired("player", Type.STRING);
|
||||
syntax.addRequired("objective", Type.STRING);
|
||||
syntax.addRequired("score", Type.INT, 0);
|
||||
syntax.addRequired("players", ArgumentType.STRING);
|
||||
syntax.addRequired("add|set|remove", ArgumentType.STRING, "add|set|remove");
|
||||
syntax.addRequired("player", ArgumentType.STRING);
|
||||
syntax.addRequired("objective", ArgumentType.STRING);
|
||||
syntax.addRequired("score", ArgumentType.INT, 0);
|
||||
|
||||
return syntax;
|
||||
|
||||
@@ -144,13 +143,13 @@ public class BuilderScoreboardPlayers extends BuilderScoreboard
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("players", Type.STRING);
|
||||
syntax.addRequired("add|enable|get|list|operation|remove|reset|set", Type.STRING);
|
||||
syntax.addOptional("...", Type.STRING);
|
||||
syntax.addRequired("players", ArgumentType.STRING);
|
||||
syntax.addRequired("add|enable|get|list|operation|remove|reset|set", ArgumentType.STRING);
|
||||
syntax.addOptional("...", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.impl.abstr.BuilderBlockPos;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.BlockResourceLocation;
|
||||
import exopandora.worldhandler.builder.types.CoordinateInt;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.state.IProperty;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -71,15 +70,15 @@ public class BuilderSetBlock extends BuilderBlockPos
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("x", Type.COORDINATE_INT);
|
||||
syntax.addRequired("y", Type.COORDINATE_INT);
|
||||
syntax.addRequired("z", Type.COORDINATE_INT);
|
||||
syntax.addRequired("block", Type.BLOCK_RESOURCE_LOCATION);
|
||||
syntax.addOptional("mode", Type.STRING);
|
||||
syntax.addRequired("x", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("y", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("z", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("block", ArgumentType.BLOCK_RESOURCE_LOCATION);
|
||||
syntax.addOptional("mode", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package exopandora.worldhandler.builder.impl;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.component.impl.ComponentTag;
|
||||
import exopandora.worldhandler.text.MutableStringTextComponent;
|
||||
import exopandora.worldhandler.text.SignText;
|
||||
import exopandora.worldhandler.util.MutableStringTextComponent;
|
||||
import exopandora.worldhandler.util.SignText;
|
||||
import net.minecraft.nbt.StringNBT;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.Coordinate.CoordinateType;
|
||||
import exopandora.worldhandler.builder.types.CoordinateInt;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -45,14 +45,14 @@ public class BuilderSpawnpoint extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("player", Type.STRING);
|
||||
syntax.addRequired("x", Type.COORDINATE_INT);
|
||||
syntax.addRequired("y", Type.COORDINATE_INT);
|
||||
syntax.addRequired("z", Type.COORDINATE_INT);
|
||||
syntax.addRequired("player", ArgumentType.STRING);
|
||||
syntax.addRequired("x", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("y", ArgumentType.COORDINATE_INT);
|
||||
syntax.addRequired("z", ArgumentType.COORDINATE_INT);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -7,17 +7,16 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilderNBT;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.component.impl.ComponentAttributeMob;
|
||||
import exopandora.worldhandler.builder.component.impl.ComponentPotionMob;
|
||||
import exopandora.worldhandler.builder.component.impl.ComponentSummon;
|
||||
import exopandora.worldhandler.builder.component.impl.ComponentTag;
|
||||
import exopandora.worldhandler.builder.impl.abstr.EnumAttributes;
|
||||
import exopandora.worldhandler.builder.impl.abstr.EnumAttributes.Applyable;
|
||||
import exopandora.worldhandler.builder.impl.EnumAttributes.Applyable;
|
||||
import exopandora.worldhandler.builder.types.Coordinate.CoordinateType;
|
||||
import exopandora.worldhandler.text.MutableStringTextComponent;
|
||||
import exopandora.worldhandler.util.MutableStringTextComponent;
|
||||
import exopandora.worldhandler.builder.types.CoordinateDouble;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -369,15 +368,15 @@ public class BuilderSummon extends CommandBuilderNBT
|
||||
}
|
||||
|
||||
@Override
|
||||
public Syntax getSyntax()
|
||||
public CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("entity_name", Type.RESOURCE_LOCATION);
|
||||
syntax.addOptional("x", Type.COORDINATE_DOUBLE);
|
||||
syntax.addOptional("y", Type.COORDINATE_DOUBLE);
|
||||
syntax.addOptional("z", Type.COORDINATE_DOUBLE);
|
||||
syntax.addOptional("nbt", Type.NBT);
|
||||
syntax.addRequired("entity_name", ArgumentType.RESOURCE_LOCATION);
|
||||
syntax.addOptional("x", ArgumentType.COORDINATE_DOUBLE);
|
||||
syntax.addOptional("y", ArgumentType.COORDINATE_DOUBLE);
|
||||
syntax.addOptional("z", ArgumentType.COORDINATE_DOUBLE);
|
||||
syntax.addOptional("nbt", ArgumentType.NBT);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -56,13 +56,13 @@ public class BuilderTag extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public Syntax getSyntax()
|
||||
public CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("player", Type.STRING);
|
||||
syntax.addRequired("add|list|remove", Type.STRING);
|
||||
syntax.addRequired("name", Type.STRING);
|
||||
syntax.addRequired("player", ArgumentType.STRING);
|
||||
syntax.addRequired("add|list|remove", ArgumentType.STRING);
|
||||
syntax.addRequired("name", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ package exopandora.worldhandler.builder.impl;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.GreedyString;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -131,45 +131,45 @@ public class BuilderTeams extends CommandBuilder
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Syntax getSyntax(String mode)
|
||||
private CommandSyntax getSyntax(String mode)
|
||||
{
|
||||
if(mode.equals("add"))
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("add", Type.STRING);
|
||||
syntax.addRequired("name", Type.STRING);
|
||||
syntax.addOptional("display_name...", Type.GREEDY_STRING);
|
||||
syntax.addRequired("add", ArgumentType.STRING);
|
||||
syntax.addRequired("name", ArgumentType.STRING);
|
||||
syntax.addOptional("display_name...", ArgumentType.GREEDY_STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
else if(mode.equals("remove|empty"))
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("remove|empty", Type.STRING, "remove|empty");
|
||||
syntax.addRequired("name", Type.STRING);
|
||||
syntax.addRequired("remove|empty", ArgumentType.STRING, "remove|empty");
|
||||
syntax.addRequired("name", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
else if(mode.equals("join|leave"))
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("join|leave", Type.STRING, "join|leave");
|
||||
syntax.addRequired("name", Type.STRING);
|
||||
syntax.addOptional("player", Type.STRING);
|
||||
syntax.addRequired("join|leave", ArgumentType.STRING, "join|leave");
|
||||
syntax.addRequired("name", ArgumentType.STRING);
|
||||
syntax.addOptional("player", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
else if(mode.equals("modify"))
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("modify", Type.STRING);
|
||||
syntax.addRequired("team", Type.STRING);
|
||||
syntax.addRequired("friendlyfire|color|seeFriendlyInvisibles|nametagVisibility|deathMessageVisibility|collisionRule", Type.STRING);
|
||||
syntax.addRequired("value", Type.STRING);
|
||||
syntax.addRequired("modify", ArgumentType.STRING);
|
||||
syntax.addRequired("team", ArgumentType.STRING);
|
||||
syntax.addRequired("friendlyfire|color|seeFriendlyInvisibles|nametagVisibility|deathMessageVisibility|collisionRule", ArgumentType.STRING);
|
||||
syntax.addRequired("value", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
@@ -212,12 +212,12 @@ public class BuilderTeams extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("list|add|remove|empty|join|leave|modify", Type.STRING);
|
||||
syntax.addOptional("...", Type.STRING);
|
||||
syntax.addRequired("list|add|remove|empty|join|leave|modify", ArgumentType.STRING);
|
||||
syntax.addOptional("...", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -42,12 +42,12 @@ public class BuilderTime extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("set|add|query", Type.STRING);
|
||||
syntax.addOptional("value", Type.INT);
|
||||
syntax.addRequired("set|add|query", ArgumentType.STRING);
|
||||
syntax.addOptional("value", ArgumentType.INT);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import exopandora.worldhandler.helper.EnumHelper;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
@@ -62,13 +62,13 @@ public class BuilderTrigger extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public Syntax getSyntax()
|
||||
public CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("objective", Type.STRING);
|
||||
syntax.addRequired("add|set", Type.STRING);
|
||||
syntax.addRequired("value", Type.INT);
|
||||
syntax.addRequired("objective", ArgumentType.STRING);
|
||||
syntax.addRequired("add|set", ArgumentType.STRING);
|
||||
syntax.addRequired("value", ArgumentType.INT);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.CommandSyntax.Argument;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import exopandora.worldhandler.builder.types.BlockResourceLocation;
|
||||
import exopandora.worldhandler.builder.types.CoordinateDouble;
|
||||
import exopandora.worldhandler.builder.types.CoordinateInt;
|
||||
import exopandora.worldhandler.builder.types.GreedyString;
|
||||
import exopandora.worldhandler.builder.types.ItemResourceLocation;
|
||||
import exopandora.worldhandler.builder.types.TargetSelector;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class BuilderUsercontent extends CommandBuilder
|
||||
{
|
||||
private final String name;
|
||||
private final CommandSyntax syntax;
|
||||
|
||||
public BuilderUsercontent(String name, CommandSyntax syntax)
|
||||
{
|
||||
this.name = name;
|
||||
this.syntax = syntax;
|
||||
this.updateSyntax(this.syntax);
|
||||
}
|
||||
|
||||
public void set(int index, String object)
|
||||
{
|
||||
if(index < this.syntax.getArguments().size() && index >= 0)
|
||||
{
|
||||
Argument argument = this.syntax.getArguments().get(index);
|
||||
ArgumentType type = argument.getType();
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case STRING:
|
||||
this.setNode(index, type.<String>parseOfDefault(object, (String) argument.getDefault()));
|
||||
break;
|
||||
case BLOCK_RESOURCE_LOCATION:
|
||||
this.setNode(index, type.<BlockResourceLocation>parseOfDefault(object, type.parse((String) argument.getDefault())));
|
||||
break;
|
||||
case BOOLEAN:
|
||||
this.setNode(index, type.<Boolean>parseOfDefault(object, (Boolean) argument.getDefault()));
|
||||
break;
|
||||
case BYTE:
|
||||
this.setNode(index, type.<Byte>parseOfDefault(object, ((Double) argument.getDefault()).byteValue()));
|
||||
break;
|
||||
case COORDINATE_DOUBLE:
|
||||
this.setNode(index, type.<CoordinateDouble>parseOfDefault(object, type.parse((String) argument.getDefault())));
|
||||
break;
|
||||
case COORDINATE_INT:
|
||||
this.setNode(index, type.<CoordinateInt>parseOfDefault(object, type.parse((String) argument.getDefault())));
|
||||
break;
|
||||
case DOUBLE:
|
||||
this.setNode(index, type.<Double>parseOfDefault(object, (Double) argument.getDefault()));
|
||||
break;
|
||||
case FLOAT:
|
||||
this.setNode(index, type.<Float>parseOfDefault(object, ((Double) argument.getDefault()).floatValue()));
|
||||
break;
|
||||
case GREEDY_STRING:
|
||||
this.setNode(index, type.<GreedyString>parseOfDefault(object, type.parse((String) argument.getDefault())));
|
||||
break;
|
||||
case INT:
|
||||
this.setNode(index, type.<Integer>parseOfDefault(object, ((Double) argument.getDefault()).intValue()));
|
||||
break;
|
||||
case ITEM_RESOURCE_LOCATION:
|
||||
this.setNode(index, type.<ItemResourceLocation>parseOfDefault(object, type.parse((String) argument.getDefault())));
|
||||
break;
|
||||
case LONG:
|
||||
this.setNode(index, type.<Long>parseOfDefault(object, ((Double) argument.getDefault()).longValue()));
|
||||
break;
|
||||
case NBT:
|
||||
this.setNode(index, type.<CompoundNBT>parseOfDefault(object, type.parse((String) argument.getDefault())));
|
||||
break;
|
||||
case RESOURCE_LOCATION:
|
||||
this.setNode(index, type.<ResourceLocation>parseOfDefault(object, type.parse((String) argument.getDefault())));
|
||||
break;
|
||||
case SHORT:
|
||||
this.setNode(index, type.<Short>parseOfDefault(object, ((Double) argument.getDefault()).shortValue()));
|
||||
break;
|
||||
case TARGET_SELECTOR:
|
||||
this.setNode(index, type.<TargetSelector>parseOfDefault(object, type.<TargetSelector>parse((String) argument.getDefault())));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String get(int index)
|
||||
{
|
||||
if(index < this.syntax.getArguments().size() && index >= 0)
|
||||
{
|
||||
Argument argument = this.syntax.getArguments().get(index);
|
||||
|
||||
switch(argument.getType())
|
||||
{
|
||||
case BLOCK_RESOURCE_LOCATION:
|
||||
return this.getNodeAsBlockResourceLocation(index).toString();
|
||||
case BOOLEAN:
|
||||
return String.valueOf(this.getNodeAsBoolean(index));
|
||||
case BYTE:
|
||||
return String.valueOf(this.getNodeAsByte(index));
|
||||
case COORDINATE_DOUBLE:
|
||||
return this.getNodeAsCoordinateDouble(index).toString();
|
||||
case COORDINATE_INT:
|
||||
return this.getNodeAsCoordinateInt(index).toString();
|
||||
case DOUBLE:
|
||||
return String.valueOf(this.getNodeAsDouble(index));
|
||||
case FLOAT:
|
||||
return String.valueOf(this.getNodeAsFloat(index));
|
||||
case GREEDY_STRING:
|
||||
return this.getNodeAsGreedyString(index);
|
||||
case INT:
|
||||
return String.valueOf(this.getNodeAsInt(index));
|
||||
case ITEM_RESOURCE_LOCATION:
|
||||
return this.getNodeAsItemResourceLocation(index).toString();
|
||||
case LONG:
|
||||
return String.valueOf(this.getNodeAsLong(index));
|
||||
case NBT:
|
||||
return this.getNodeAsNBT(index).toString();
|
||||
case RESOURCE_LOCATION:
|
||||
return this.getNodeAsResourceLocation(index).toString();
|
||||
case SHORT:
|
||||
return String.valueOf(this.getNodeAsShort(index));
|
||||
case STRING:
|
||||
return this.getNodeAsString(index);
|
||||
case TARGET_SELECTOR:
|
||||
return this.getNodeAsTargetSelector(index).toString();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setPlayerName(String username)
|
||||
{
|
||||
for(int x = 0; x < this.syntax.getArguments().size(); x++)
|
||||
{
|
||||
if(ArgumentType.PLAYER.equals(this.syntax.getArguments().get(x).getType()))
|
||||
{
|
||||
this.setPlayerName(x, username);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandSyntax getSyntax()
|
||||
{
|
||||
return this.syntax;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -16,11 +16,11 @@ public class BuilderWH extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public Syntax getSyntax()
|
||||
public CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("pos1|pos2|fill|replace", Type.STRING);
|
||||
syntax.addRequired("pos1|pos2|fill|replace", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -42,12 +42,12 @@ public class BuilderWeather extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("clear|rain|thunde", Type.STRING);
|
||||
syntax.addOptional("duration", Type.INT);
|
||||
syntax.addRequired("clear|rain|thunde", ArgumentType.STRING);
|
||||
syntax.addOptional("duration", ArgumentType.INT);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package exopandora.worldhandler.builder.impl;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -66,12 +66,12 @@ public class BuilderWhitelist extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("add|remove|reload|on|off", Type.STRING);
|
||||
syntax.addOptional("player", Type.STRING);
|
||||
syntax.addRequired("add|remove|reload|on|off", ArgumentType.STRING);
|
||||
syntax.addOptional("player", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -16,11 +16,11 @@ public class BuilderWorldHandler extends CommandBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Syntax getSyntax()
|
||||
public final CommandSyntax getSyntax()
|
||||
{
|
||||
Syntax syntax = new Syntax();
|
||||
CommandSyntax syntax = new CommandSyntax();
|
||||
|
||||
syntax.addRequired("help|display|version", Type.STRING);
|
||||
syntax.addRequired("help|display|version", ArgumentType.STRING);
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package exopandora.worldhandler.builder.impl.abstr;
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -2,6 +2,7 @@ package exopandora.worldhandler.builder.types;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
@@ -13,7 +14,7 @@ import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public enum Type
|
||||
public enum ArgumentType
|
||||
{
|
||||
SHORT(Short::valueOf),
|
||||
BYTE(Byte::valueOf),
|
||||
@@ -24,17 +25,18 @@ public enum Type
|
||||
BOOLEAN(Boolean::valueOf),
|
||||
STRING(String::valueOf),
|
||||
GREEDY_STRING(GreedyString::valueOf),
|
||||
RESOURCE_LOCATION(Type::parseResourceLocation),
|
||||
RESOURCE_LOCATION(ArgumentType::parseResourceLocation),
|
||||
ITEM_RESOURCE_LOCATION(ItemResourceLocation::valueOf),
|
||||
BLOCK_RESOURCE_LOCATION(BlockResourceLocation::valueOf),
|
||||
NBT(Type::parseCompoundNBT),
|
||||
NBT(ArgumentType::parseCompoundNBT),
|
||||
COORDINATE_INT(CoordinateInt::valueOf),
|
||||
COORDINATE_DOUBLE(CoordinateDouble::valueOf),
|
||||
TARGET_SELECTOR(TargetSelector::valueOf);
|
||||
TARGET_SELECTOR(TargetSelector::valueOf),
|
||||
PLAYER(String::valueOf);
|
||||
|
||||
private final Function<String, Object> parser;
|
||||
|
||||
private Type(Function<String, Object> parser)
|
||||
private ArgumentType(Function<String, Object> parser)
|
||||
{
|
||||
this.parser = parser;
|
||||
}
|
||||
@@ -46,10 +48,23 @@ public enum Type
|
||||
return (T) this.parser.apply(object);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public <T> T parseOfDefault(String object, T def)
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.<T>parse(object);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ResourceLocation parseResourceLocation(String value)
|
||||
{
|
||||
return value != null ? new ResourceLocation(value) : null;
|
||||
return value != null && !value.isEmpty() ? new ResourceLocation(value) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -1,5 +1,8 @@
|
||||
package exopandora.worldhandler.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
@@ -124,4 +127,19 @@ public class Config
|
||||
KeyHandler.updatePosKeys();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setupDirectories(Path path)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(!Files.exists(path))
|
||||
{
|
||||
Files.createDirectories(path);
|
||||
}
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class GuiButtonIcon extends GuiButtonTooltip
|
||||
{
|
||||
private EnumIcon icon;
|
||||
private final EnumIcon icon;
|
||||
|
||||
public GuiButtonIcon(int x, int y, int widthIn, int heightIn, EnumIcon icon, String tooltip, ActionHandler actionHandler)
|
||||
{
|
||||
|
||||
@@ -24,6 +24,12 @@ public class GuiButtonList<T> extends GuiButtonTooltip
|
||||
this.items = items;
|
||||
this.logic = logic;
|
||||
this.persistence = container.getContent().getPersistence(this.logic.getId(), Persistence::new);
|
||||
this.init();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
this.logic.onInit(this.items.get(this.persistence.getIndex()));
|
||||
this.updateMessage();
|
||||
}
|
||||
|
||||
@@ -43,7 +49,7 @@ public class GuiButtonList<T> extends GuiButtonTooltip
|
||||
int maxWidth = Math.max(0, this.width - fontRenderer.getStringWidth("< >"));
|
||||
int spaceWidth = fontRenderer.getStringWidth(" ");
|
||||
|
||||
String display = exopandora.worldhandler.text.TextFormatting.shortenString(this.getMessage(), maxWidth, fontRenderer);
|
||||
String display = exopandora.worldhandler.util.TextFormatting.shortenString(this.getMessage(), maxWidth, fontRenderer);
|
||||
int yPos = this.y + (this.height - 8) / 2;
|
||||
|
||||
this.drawCenteredString(fontRenderer, display, this.x + this.width / 2, yPos, this.getFGColor());
|
||||
@@ -71,7 +77,7 @@ public class GuiButtonList<T> extends GuiButtonTooltip
|
||||
{
|
||||
if(index < 10)
|
||||
{
|
||||
this.persistence.setIndex(max - (9 - index));
|
||||
this.persistence.setIndex((index - 9 + max) % max);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -96,7 +102,7 @@ public class GuiButtonList<T> extends GuiButtonTooltip
|
||||
{
|
||||
if(index > max - 10)
|
||||
{
|
||||
this.persistence.setIndex(9 - (max - index));
|
||||
this.persistence.setIndex((index + 9 - max) % max);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ public class GuiButtonTooltip extends GuiButtonBase
|
||||
|
||||
public void renderTooltip(int mouseX, int mouseY)
|
||||
{
|
||||
if(this.isHovered() && this.tooltip != null)
|
||||
if(this.isHovered() && this.tooltip != null && !this.tooltip.isEmpty())
|
||||
{
|
||||
List<String> list = Arrays.asList(this.tooltip.split("\n"));
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import exopandora.worldhandler.config.Config;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.logic.ILogic;
|
||||
import exopandora.worldhandler.text.TextFormatting;
|
||||
import exopandora.worldhandler.util.TextFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
|
||||
@@ -27,15 +27,20 @@ public class Categories
|
||||
SCOREBOARD = Categories.getRegisteredCategory("scoreboard");
|
||||
}
|
||||
|
||||
private static Category getRegisteredCategory(String name)
|
||||
public static Category getRegisteredCategory(String name)
|
||||
{
|
||||
Category category = Category.REGISTRY.getValue(new ResourceLocation(Main.MODID, name));
|
||||
|
||||
if(category == null)
|
||||
{
|
||||
throw new IllegalStateException("Invalid Category requested: " + name);
|
||||
throw new IllegalStateException("Requested missing category: " + name);
|
||||
}
|
||||
|
||||
return category;
|
||||
}
|
||||
|
||||
public static boolean isRegistered(String name)
|
||||
{
|
||||
return Category.REGISTRY.containsKey(new ResourceLocation(Main.MODID, name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ import com.google.common.collect.Lists;
|
||||
import exopandora.worldhandler.Main;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.helper.RegistryHelper;
|
||||
import exopandora.worldhandler.usercontent.UsercontentConfig;
|
||||
import exopandora.worldhandler.usercontent.UsercontentLoader;
|
||||
import exopandora.worldhandler.usercontent.model.JsonTab;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
@@ -48,15 +51,15 @@ public class Category extends ForgeRegistryEntry<Category>
|
||||
this(Arrays.stream(keys).map(key -> new ResourceLocation(Main.MODID, key)).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
public Category add(ResourceLocation content)
|
||||
public Category add(int index, ResourceLocation content)
|
||||
{
|
||||
this.contents.add(content);
|
||||
this.contents.add(Math.min(index, this.getSize()), content);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Category add(String key)
|
||||
public Category add(int index, String key)
|
||||
{
|
||||
return this.add(new ResourceLocation(Main.MODID, key));
|
||||
return this.add(index, new ResourceLocation(Main.MODID, key));
|
||||
}
|
||||
|
||||
public List<ResourceLocation> getContents()
|
||||
@@ -96,5 +99,28 @@ public class Category extends ForgeRegistryEntry<Category>
|
||||
RegistryHelper.register(event.getRegistry(), "world", new Category("world", "gamerules"));
|
||||
RegistryHelper.register(event.getRegistry(), "player", new Category("player", "experience", "advancements"));
|
||||
RegistryHelper.register(event.getRegistry(), "scoreboard", new Category("scoreboard_objectives", "scoreboard_teams", "scoreboard_players"));
|
||||
|
||||
for(UsercontentConfig config : UsercontentLoader.CONFIGS)
|
||||
{
|
||||
if(config.getContent().getGui() != null && config.getContent().getGui().getTab() != null)
|
||||
{
|
||||
Category.registerCategory(event.getRegistry(), config.getId(), config.getContent().getGui().getTab());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void registerCategory(IForgeRegistry<Category> registry, String id, JsonTab tab)
|
||||
{
|
||||
if(tab.getCategory() != null && !tab.getCategory().isEmpty())
|
||||
{
|
||||
if(!Categories.isRegistered(tab.getCategory()))
|
||||
{
|
||||
RegistryHelper.register(registry, tab.getCategory(), new Category(id));
|
||||
}
|
||||
else
|
||||
{
|
||||
Categories.getRegisteredCategory(tab.getCategory()).add(tab.getCategoryIndex(), id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package exopandora.worldhandler.gui.container;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import exopandora.worldhandler.gui.content.element.Element;
|
||||
import exopandora.worldhandler.gui.content.element.IElement;
|
||||
import exopandora.worldhandler.gui.element.Element;
|
||||
import exopandora.worldhandler.gui.element.IElement;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package exopandora.worldhandler.gui.container;
|
||||
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.gui.content.element.Element;
|
||||
import exopandora.worldhandler.gui.element.Element;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -23,10 +23,10 @@ import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.gui.content.IContent;
|
||||
import exopandora.worldhandler.gui.content.element.IElement;
|
||||
import exopandora.worldhandler.gui.element.IElement;
|
||||
import exopandora.worldhandler.helper.ActionHelper;
|
||||
import exopandora.worldhandler.helper.ResourceHelper;
|
||||
import exopandora.worldhandler.text.TextFormatting;
|
||||
import exopandora.worldhandler.util.TextFormatting;
|
||||
import exopandora.worldhandler.util.UtilRender;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
@@ -139,32 +139,33 @@ public class GuiWorldHandler extends Container
|
||||
});
|
||||
this.updateNameField();
|
||||
|
||||
final int backgroundX = this.getBackgroundX();
|
||||
final int backgroundY = this.getBackgroundY();
|
||||
|
||||
this.forEachTab((index, xOffset) ->
|
||||
{
|
||||
IContent tab = this.content.getCategory().getContent(index);
|
||||
|
||||
if(!this.content.getActiveContent().equals(tab))
|
||||
{
|
||||
this.finalButtons.add(new GuiButtonTab((int) (backgroundX + xOffset), backgroundY - 20, (int) this.tabWidth + (int) Math.ceil(this.tabEpsilon / this.tabSize), 21, tab.getTabTitle())
|
||||
{
|
||||
@Override
|
||||
public void onPress()
|
||||
{
|
||||
ActionHelper.changeTab(GuiWorldHandler.this.content, index);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//BUTTONS
|
||||
|
||||
this.forEachTab(this::addTabButtons);
|
||||
this.initButtons();
|
||||
});
|
||||
}
|
||||
|
||||
private void addTabButtons(int index, double xOffset)
|
||||
{
|
||||
final int backgroundX = this.getBackgroundX();
|
||||
final int backgroundY = this.getBackgroundY();
|
||||
|
||||
IContent tab = this.content.getCategory().getContent(index);
|
||||
|
||||
if(!tab.equals(this.content.getActiveContent()))
|
||||
{
|
||||
this.finalButtons.add(new GuiButtonTab((int) (backgroundX + xOffset), backgroundY - 20, (int) this.tabWidth + (int) Math.ceil(this.tabEpsilon / this.tabSize), 21, tab.getTabTitle())
|
||||
{
|
||||
@Override
|
||||
public void onPress()
|
||||
{
|
||||
ActionHelper.changeTab(GuiWorldHandler.this.content, index);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void initButtons()
|
||||
{
|
||||
this.buttons.clear();
|
||||
@@ -374,118 +375,7 @@ public class GuiWorldHandler extends Container
|
||||
|
||||
//TABS
|
||||
|
||||
this.forEachTab((index, xOffset) ->
|
||||
{
|
||||
IContent tab = this.content.getCategory().getContent(index);
|
||||
int yOffset;
|
||||
int fHeight;
|
||||
int color;
|
||||
|
||||
if(this.content.getActiveContent().equals(tab))
|
||||
{
|
||||
yOffset = -22;
|
||||
fHeight = 25;
|
||||
color = 0xFFFFFF;
|
||||
this.defaultColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
yOffset = -20;
|
||||
fHeight = 20;
|
||||
color = 0xE0E0E0;
|
||||
this.darkColor();
|
||||
}
|
||||
|
||||
this.bindBackground();
|
||||
this.blit((int) (backgroundX + xOffset), (int) (backgroundY + yOffset), 0, 0, (int) Math.ceil(this.tabHalf), fHeight);
|
||||
this.blit((int) (backgroundX + this.tabHalf + xOffset), (int) (backgroundY + yOffset), this.bgTextureWidth - (int) Math.ceil(this.tabHalf), 0, (int) Math.ceil(this.tabHalf), fHeight);
|
||||
|
||||
if(!Config.getSkin().sharpEdges())
|
||||
{
|
||||
if(this.content.getActiveContent().equals(tab))
|
||||
{
|
||||
//RIGHT TAB CURVATURE
|
||||
|
||||
if(index < this.tabSize - 1 || this.tabSize == 1)
|
||||
{
|
||||
int factor = 2;
|
||||
|
||||
for(int x = 0; x < factor; x++)
|
||||
{
|
||||
this.blit((int) (backgroundX + this.tabWidth + xOffset - x - 1), (int) (backgroundY + x + 1), (int) (this.tabWidth - x - 1), x + 1, x + 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
//LEFT TAB CURVATURE
|
||||
|
||||
if(index > 0)
|
||||
{
|
||||
int factor = 2;
|
||||
|
||||
for(int x = 0; x < factor; x++)
|
||||
{
|
||||
this.blit((int) (backgroundX + xOffset), (int) (backgroundY + x + 1), xOffset.intValue(), x + 1, x + 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
int width = (int)(this.tabWidth - 3);
|
||||
int interval = 5;
|
||||
|
||||
//LEFT GRADIENT
|
||||
|
||||
if(index == 0)
|
||||
{
|
||||
for(int x = 0; x < width; x += interval)
|
||||
{
|
||||
this.defaultColor(1.0F - (x / (width + 5.0F * interval)));
|
||||
this.blit((int) (backgroundX + xOffset), (int) (backgroundY + yOffset + fHeight + x / interval), 0, fHeight, width - x, 1);
|
||||
}
|
||||
}
|
||||
|
||||
//RIGHT GRADIENT
|
||||
|
||||
if(index == this.tabSize - 1 && this.tabSize > 1)
|
||||
{
|
||||
int offset = 3;
|
||||
|
||||
for(int x = 0; x < width; x += interval)
|
||||
{
|
||||
this.defaultColor(1.0F - (x / (width + 5.0F * interval)));
|
||||
this.blit((int) (backgroundX + Math.ceil(xOffset) + x + offset), (int) (backgroundY + yOffset + fHeight + x / interval), this.bgTextureWidth - width + x, fHeight, width - x, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//LEFT CORNER FILLER
|
||||
|
||||
if(index == 0)
|
||||
{
|
||||
int factor = 2;
|
||||
|
||||
for(int x = 0; x < factor; x++)
|
||||
{
|
||||
this.blit(backgroundX, backgroundY + x, 0, fHeight, factor - x, 1);
|
||||
}
|
||||
}
|
||||
|
||||
//RIGHT CORNER FILLER
|
||||
|
||||
if(index == this.tabSize - 1)
|
||||
{
|
||||
int factor = 3;
|
||||
|
||||
for(int x = 0; x < factor + 1; x++)
|
||||
{
|
||||
this.blit(backgroundX + this.bgTextureWidth - x, backgroundY + factor - x, this.bgTextureWidth - x, fHeight, x, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.drawCenteredString(this.font, net.minecraft.util.text.TextFormatting.UNDERLINE + tab.getTabTitle(), (int) (backgroundX + this.tabHalf + xOffset), (int) (backgroundY - 13), color);
|
||||
});
|
||||
|
||||
this.forEachTab(this::drawTab);
|
||||
this.defaultColor();
|
||||
|
||||
//VERSION LABEL
|
||||
@@ -608,6 +498,122 @@ public class GuiWorldHandler extends Container
|
||||
});
|
||||
}
|
||||
|
||||
private void drawTab(int index, Double xOffset)
|
||||
{
|
||||
final IContent tab = this.content.getCategory().getContent(index);
|
||||
|
||||
final int backgroundX = this.getBackgroundX();
|
||||
final int backgroundY = this.getBackgroundY();
|
||||
|
||||
int yOffset;
|
||||
int fHeight;
|
||||
int color;
|
||||
|
||||
if(this.content.getActiveContent().equals(tab))
|
||||
{
|
||||
yOffset = -22;
|
||||
fHeight = 25;
|
||||
color = 0xFFFFFF;
|
||||
this.defaultColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
yOffset = -20;
|
||||
fHeight = 20;
|
||||
color = 0xE0E0E0;
|
||||
this.darkColor();
|
||||
}
|
||||
|
||||
this.bindBackground();
|
||||
this.blit((int) (backgroundX + xOffset), (int) (backgroundY + yOffset), 0, 0, (int) Math.ceil(this.tabHalf), fHeight);
|
||||
this.blit((int) (backgroundX + this.tabHalf + xOffset), (int) (backgroundY + yOffset), this.bgTextureWidth - (int) Math.floor(this.tabHalf + 1), 0, (int) Math.floor(this.tabHalf + 1), fHeight);
|
||||
|
||||
if(!Config.getSkin().sharpEdges())
|
||||
{
|
||||
if(this.content.getActiveContent().equals(tab))
|
||||
{
|
||||
//RIGHT TAB CURVATURE
|
||||
|
||||
if(index < this.tabSize - 1 || this.tabSize == 1)
|
||||
{
|
||||
int factor = 2;
|
||||
|
||||
for(int x = 0; x < factor; x++)
|
||||
{
|
||||
this.blit((int) (backgroundX + xOffset - x - 1 + Math.floor(this.tabHalf + 1) + this.tabHalf), (int) (backgroundY + x + 1), (int) (this.tabWidth - x - 1), x + 1, x + 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
//LEFT TAB CURVATURE
|
||||
|
||||
if(index > 0)
|
||||
{
|
||||
int factor = 2;
|
||||
|
||||
for(int x = 0; x < factor; x++)
|
||||
{
|
||||
this.blit((int) (backgroundX + xOffset), (int) (backgroundY + x + 1), xOffset.intValue(), x + 1, x + 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
int width = (int)(this.tabWidth - 3);
|
||||
int interval = 5;
|
||||
|
||||
//LEFT GRADIENT
|
||||
|
||||
if(index == 0)
|
||||
{
|
||||
for(int x = 0; x < width; x += interval)
|
||||
{
|
||||
this.defaultColor(1.0F - (x / (width + 5.0F * interval)));
|
||||
this.blit((int) (backgroundX + xOffset), (int) (backgroundY + yOffset + fHeight + x / interval), 0, fHeight, width - x, 1);
|
||||
}
|
||||
}
|
||||
|
||||
//RIGHT GRADIENT
|
||||
|
||||
if(index == this.tabSize - 1 && this.tabSize > 1)
|
||||
{
|
||||
int offset = 3;
|
||||
|
||||
for(int x = 0; x < width; x += interval)
|
||||
{
|
||||
this.defaultColor(1.0F - (x / (width + 5.0F * interval)));
|
||||
this.blit((int) (backgroundX + Math.ceil(xOffset) + x + offset), (int) (backgroundY + yOffset + fHeight + x / interval), this.bgTextureWidth - width + x, fHeight, width - x, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//LEFT CORNER FILLER
|
||||
|
||||
if(index == 0)
|
||||
{
|
||||
int factor = 2;
|
||||
|
||||
for(int x = 0; x < factor; x++)
|
||||
{
|
||||
this.blit(backgroundX, backgroundY + x, 0, fHeight, factor - x, 1);
|
||||
}
|
||||
}
|
||||
|
||||
//RIGHT CORNER FILLER
|
||||
|
||||
if(index == this.tabSize - 1)
|
||||
{
|
||||
int factor = 3;
|
||||
|
||||
for(int x = 0; x < factor + 1; x++)
|
||||
{
|
||||
this.blit(backgroundX + this.bgTextureWidth - x, backgroundY + factor - x, this.bgTextureWidth - x, fHeight, x, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.drawCenteredString(this.font, TextFormatting.shortenString(net.minecraft.util.text.TextFormatting.UNDERLINE + tab.getTabTitle(), (int) this.tabWidth, this.font), (int) (backgroundX + this.tabHalf + xOffset), (int) (backgroundY - 13), color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char charTyped, int keyCode)
|
||||
{
|
||||
|
||||
@@ -28,8 +28,11 @@ import exopandora.worldhandler.gui.content.impl.ContentScoreboardTeams;
|
||||
import exopandora.worldhandler.gui.content.impl.ContentSettings;
|
||||
import exopandora.worldhandler.gui.content.impl.ContentSignEditor;
|
||||
import exopandora.worldhandler.gui.content.impl.ContentSummon;
|
||||
import exopandora.worldhandler.gui.content.impl.ContentUsercontent;
|
||||
import exopandora.worldhandler.gui.content.impl.ContentWorldInfo;
|
||||
import exopandora.worldhandler.helper.RegistryHelper;
|
||||
import exopandora.worldhandler.usercontent.UsercontentConfig;
|
||||
import exopandora.worldhandler.usercontent.UsercontentLoader;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
@@ -100,6 +103,21 @@ public abstract class Content extends ForgeRegistryEntry<Content> implements ICo
|
||||
RegistryHelper.register(event.getRegistry(), "butcher", new ContentButcher());
|
||||
RegistryHelper.register(event.getRegistry(), "butcher_settings", new ContentButcherSettings());
|
||||
RegistryHelper.register(event.getRegistry(), "settings", new ContentSettings());
|
||||
|
||||
//USERCONTENT
|
||||
UsercontentLoader.CONFIGS.forEach(config -> Content.registerContent(event.getRegistry(), config));
|
||||
}
|
||||
|
||||
private static void registerContent(IForgeRegistry<Content> registry, UsercontentConfig config)
|
||||
{
|
||||
try
|
||||
{
|
||||
RegistryHelper.register(registry, config.getId(), new ContentUsercontent(config));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new RuntimeException("Error loading js for usercontent: " + config.getId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> persistence;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package exopandora.worldhandler.gui.content;
|
||||
|
||||
import exopandora.worldhandler.Main;
|
||||
import exopandora.worldhandler.gui.content.impl.ContentChild;
|
||||
import exopandora.worldhandler.gui.content.impl.ContentContinue;
|
||||
import exopandora.worldhandler.gui.content.impl.abstr.ContentChild;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
@@ -79,15 +79,20 @@ public class Contents
|
||||
SETTINGS = (ContentChild) Contents.getRegisteredContent("settings");
|
||||
}
|
||||
|
||||
private static Content getRegisteredContent(String name)
|
||||
public static Content getRegisteredContent(String name)
|
||||
{
|
||||
Content content = Content.REGISTRY.getValue(new ResourceLocation(Main.MODID, name));
|
||||
|
||||
if(content == null)
|
||||
{
|
||||
throw new IllegalStateException("Invalid Content requested: " + name);
|
||||
throw new IllegalStateException("Requested missing content: " + name);
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
public static boolean isRegistered(String name)
|
||||
{
|
||||
return Content.REGISTRY.containsKey(new ResourceLocation(Main.MODID, name));
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.container.impl.GuiWorldHandler;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.gui.content.Contents;
|
||||
import exopandora.worldhandler.gui.content.element.impl.ElementPageList;
|
||||
import exopandora.worldhandler.gui.element.impl.ElementPageList;
|
||||
import exopandora.worldhandler.gui.logic.ILogicMapped;
|
||||
import exopandora.worldhandler.gui.logic.ILogicPageList;
|
||||
import exopandora.worldhandler.helper.ActionHelper;
|
||||
|
||||
@@ -8,7 +8,6 @@ import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.container.impl.GuiWorldHandler;
|
||||
import exopandora.worldhandler.gui.content.Contents;
|
||||
import exopandora.worldhandler.gui.content.impl.abstr.ContentChild;
|
||||
import exopandora.worldhandler.helper.ActionHelper;
|
||||
import exopandora.worldhandler.helper.CommandHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
@@ -7,8 +7,7 @@ import exopandora.worldhandler.config.Config;
|
||||
import exopandora.worldhandler.gui.button.GuiButtonBase;
|
||||
import exopandora.worldhandler.gui.button.GuiButtonTooltip;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.content.element.impl.ElementPageList;
|
||||
import exopandora.worldhandler.gui.content.impl.abstr.ContentChild;
|
||||
import exopandora.worldhandler.gui.element.impl.ElementPageList;
|
||||
import exopandora.worldhandler.gui.logic.ILogicPageList;
|
||||
import exopandora.worldhandler.helper.ActionHelper;
|
||||
import exopandora.worldhandler.util.ActionHandler;
|
||||
|
||||
@@ -2,7 +2,6 @@ package exopandora.worldhandler.gui.content.impl;
|
||||
|
||||
import exopandora.worldhandler.gui.button.GuiButtonBase;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.content.impl.abstr.ContentChild;
|
||||
import exopandora.worldhandler.helper.ActionHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screen.ConnectingScreen;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package exopandora.worldhandler.gui.content.impl.abstr;
|
||||
package exopandora.worldhandler.gui.content.impl;
|
||||
|
||||
import exopandora.worldhandler.gui.category.Category;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
@@ -6,7 +6,6 @@ import exopandora.worldhandler.gui.button.GuiButtonBase;
|
||||
import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.container.impl.GuiWorldHandler;
|
||||
import exopandora.worldhandler.gui.content.impl.abstr.ContentChild;
|
||||
import exopandora.worldhandler.helper.ActionHelper;
|
||||
import exopandora.worldhandler.helper.CommandHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
@@ -9,8 +9,8 @@ import com.google.common.base.Predicates;
|
||||
|
||||
import exopandora.worldhandler.builder.ICommandBuilder;
|
||||
import exopandora.worldhandler.builder.impl.BuilderCustomItem;
|
||||
import exopandora.worldhandler.builder.impl.abstr.EnumAttributes;
|
||||
import exopandora.worldhandler.builder.impl.abstr.EnumAttributes.Applyable;
|
||||
import exopandora.worldhandler.builder.impl.EnumAttributes;
|
||||
import exopandora.worldhandler.builder.impl.EnumAttributes.Applyable;
|
||||
import exopandora.worldhandler.config.Config;
|
||||
import exopandora.worldhandler.gui.button.GuiButtonBase;
|
||||
import exopandora.worldhandler.gui.button.GuiSlider;
|
||||
@@ -20,8 +20,8 @@ import exopandora.worldhandler.gui.category.Category;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.gui.content.Contents;
|
||||
import exopandora.worldhandler.gui.content.element.impl.ElementColorMenu;
|
||||
import exopandora.worldhandler.gui.content.element.impl.ElementPageList;
|
||||
import exopandora.worldhandler.gui.element.impl.ElementColorMenu;
|
||||
import exopandora.worldhandler.gui.element.impl.ElementPageList;
|
||||
import exopandora.worldhandler.gui.logic.ILogicPageList;
|
||||
import exopandora.worldhandler.gui.logic.LogicSliderAttribute;
|
||||
import exopandora.worldhandler.gui.logic.LogicSliderSimple;
|
||||
|
||||
@@ -12,7 +12,7 @@ import exopandora.worldhandler.gui.category.Category;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.gui.content.Contents;
|
||||
import exopandora.worldhandler.gui.content.element.impl.ElementPageList;
|
||||
import exopandora.worldhandler.gui.element.impl.ElementPageList;
|
||||
import exopandora.worldhandler.gui.logic.ILogicPageList;
|
||||
import exopandora.worldhandler.gui.logic.LogicSliderSimple;
|
||||
import exopandora.worldhandler.helper.ActionHelper;
|
||||
|
||||
@@ -18,7 +18,7 @@ import exopandora.worldhandler.gui.category.Category;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.gui.content.Contents;
|
||||
import exopandora.worldhandler.gui.content.element.impl.ElementPageList;
|
||||
import exopandora.worldhandler.gui.element.impl.ElementPageList;
|
||||
import exopandora.worldhandler.gui.logic.ILogicPageList;
|
||||
import exopandora.worldhandler.helper.ActionHelper;
|
||||
import exopandora.worldhandler.helper.CommandHelper;
|
||||
|
||||
@@ -11,8 +11,7 @@ import exopandora.worldhandler.gui.button.GuiButtonBase;
|
||||
import exopandora.worldhandler.gui.button.GuiButtonTooltip;
|
||||
import exopandora.worldhandler.gui.button.GuiSlider;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.content.element.impl.ElementPageList;
|
||||
import exopandora.worldhandler.gui.content.impl.abstr.ContentChild;
|
||||
import exopandora.worldhandler.gui.element.impl.ElementPageList;
|
||||
import exopandora.worldhandler.gui.logic.ILogicPageList;
|
||||
import exopandora.worldhandler.gui.logic.LogicSliderSimple;
|
||||
import exopandora.worldhandler.helper.ActionHelper;
|
||||
|
||||
@@ -13,7 +13,7 @@ import exopandora.worldhandler.gui.category.Category;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.gui.content.Contents;
|
||||
import exopandora.worldhandler.gui.content.element.impl.ElementPageList;
|
||||
import exopandora.worldhandler.gui.element.impl.ElementPageList;
|
||||
import exopandora.worldhandler.gui.logic.ILogicPageList;
|
||||
import exopandora.worldhandler.helper.ActionHelper;
|
||||
import exopandora.worldhandler.helper.CommandHelper;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package exopandora.worldhandler.gui.content.impl.abstr;
|
||||
package exopandora.worldhandler.gui.content.impl;
|
||||
|
||||
import exopandora.worldhandler.gui.category.Categories;
|
||||
import exopandora.worldhandler.gui.category.Category;
|
||||
@@ -15,8 +15,7 @@ import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.gui.content.Contents;
|
||||
import exopandora.worldhandler.gui.content.element.impl.ElementMultiButtonList;
|
||||
import exopandora.worldhandler.gui.content.impl.abstr.ContentScoreboard;
|
||||
import exopandora.worldhandler.gui.element.impl.ElementMultiButtonList;
|
||||
import exopandora.worldhandler.gui.logic.ILogicClickList;
|
||||
import exopandora.worldhandler.helper.ActionHelper;
|
||||
import exopandora.worldhandler.helper.CommandHelper;
|
||||
|
||||
@@ -16,7 +16,6 @@ import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.gui.content.Contents;
|
||||
import exopandora.worldhandler.gui.content.impl.abstr.ContentScoreboard;
|
||||
import exopandora.worldhandler.gui.logic.LogicSliderSimple;
|
||||
import exopandora.worldhandler.helper.ActionHelper;
|
||||
import exopandora.worldhandler.helper.CommandHelper;
|
||||
|
||||
@@ -13,8 +13,7 @@ import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.gui.content.Contents;
|
||||
import exopandora.worldhandler.gui.content.element.impl.ElementMultiButtonList;
|
||||
import exopandora.worldhandler.gui.content.impl.abstr.ContentScoreboard;
|
||||
import exopandora.worldhandler.gui.element.impl.ElementMultiButtonList;
|
||||
import exopandora.worldhandler.gui.logic.ILogicClickList;
|
||||
import exopandora.worldhandler.helper.ActionHelper;
|
||||
import exopandora.worldhandler.helper.CommandHelper;
|
||||
|
||||
@@ -10,10 +10,9 @@ import exopandora.worldhandler.gui.button.GuiButtonBase;
|
||||
import exopandora.worldhandler.gui.button.GuiButtonTooltip;
|
||||
import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.content.element.impl.ElementPageList;
|
||||
import exopandora.worldhandler.gui.content.impl.ContentSettings.Setting.BooleanSetting;
|
||||
import exopandora.worldhandler.gui.content.impl.ContentSettings.Setting.IntegerSetting;
|
||||
import exopandora.worldhandler.gui.content.impl.abstr.ContentChild;
|
||||
import exopandora.worldhandler.gui.element.impl.ElementPageList;
|
||||
import exopandora.worldhandler.gui.logic.ILogicPageList;
|
||||
import exopandora.worldhandler.helper.ActionHelper;
|
||||
import exopandora.worldhandler.util.ActionHandler;
|
||||
|
||||
@@ -15,7 +15,7 @@ import exopandora.worldhandler.gui.category.Category;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.gui.content.Contents;
|
||||
import exopandora.worldhandler.gui.content.element.impl.ElementColorMenu;
|
||||
import exopandora.worldhandler.gui.element.impl.ElementColorMenu;
|
||||
import exopandora.worldhandler.gui.logic.ILogicColorMenu;
|
||||
import exopandora.worldhandler.helper.ActionHelper;
|
||||
import exopandora.worldhandler.helper.BlockHelper;
|
||||
|
||||
@@ -11,8 +11,8 @@ import com.google.common.base.Predicates;
|
||||
|
||||
import exopandora.worldhandler.builder.ICommandBuilder;
|
||||
import exopandora.worldhandler.builder.impl.BuilderSummon;
|
||||
import exopandora.worldhandler.builder.impl.abstr.EnumAttributes;
|
||||
import exopandora.worldhandler.builder.impl.abstr.EnumAttributes.Applyable;
|
||||
import exopandora.worldhandler.builder.impl.EnumAttributes;
|
||||
import exopandora.worldhandler.builder.impl.EnumAttributes.Applyable;
|
||||
import exopandora.worldhandler.config.Config;
|
||||
import exopandora.worldhandler.gui.button.GuiButtonBase;
|
||||
import exopandora.worldhandler.gui.button.GuiButtonItem;
|
||||
@@ -23,7 +23,7 @@ import exopandora.worldhandler.gui.category.Category;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.gui.content.Contents;
|
||||
import exopandora.worldhandler.gui.content.element.impl.ElementPageList;
|
||||
import exopandora.worldhandler.gui.element.impl.ElementPageList;
|
||||
import exopandora.worldhandler.gui.logic.ILogicPageList;
|
||||
import exopandora.worldhandler.gui.logic.LogicSliderAttribute;
|
||||
import exopandora.worldhandler.gui.logic.LogicSliderSimple;
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
package exopandora.worldhandler.gui.content.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import exopandora.worldhandler.Main;
|
||||
import exopandora.worldhandler.builder.CommandSyntax;
|
||||
import exopandora.worldhandler.builder.ICommandBuilder;
|
||||
import exopandora.worldhandler.builder.impl.BuilderMultiCommand;
|
||||
import exopandora.worldhandler.builder.impl.BuilderUsercontent;
|
||||
import exopandora.worldhandler.gui.category.Categories;
|
||||
import exopandora.worldhandler.gui.category.Category;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.gui.content.Contents;
|
||||
import exopandora.worldhandler.usercontent.ScriptEngineAdapter;
|
||||
import exopandora.worldhandler.usercontent.UsercontentAPI;
|
||||
import exopandora.worldhandler.usercontent.UsercontentConfig;
|
||||
import exopandora.worldhandler.usercontent.VisibleActiveObject;
|
||||
import exopandora.worldhandler.usercontent.VisibleObject;
|
||||
import exopandora.worldhandler.usercontent.factory.ActionHandlerFactory;
|
||||
import exopandora.worldhandler.usercontent.factory.ButtonFactory;
|
||||
import exopandora.worldhandler.usercontent.factory.ElementFactory;
|
||||
import exopandora.worldhandler.usercontent.model.JsonButton;
|
||||
import exopandora.worldhandler.usercontent.model.JsonCommand;
|
||||
import exopandora.worldhandler.usercontent.model.JsonElement;
|
||||
import exopandora.worldhandler.usercontent.model.JsonModel;
|
||||
import exopandora.worldhandler.usercontent.model.JsonText;
|
||||
import exopandora.worldhandler.usercontent.model.JsonUsercontent;
|
||||
import exopandora.worldhandler.usercontent.model.JsonWidget;
|
||||
import exopandora.worldhandler.util.TextFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.util.text.ChatType;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class ContentUsercontent extends Content
|
||||
{
|
||||
private final String id;
|
||||
private final JsonUsercontent content;
|
||||
private final ScriptEngineAdapter engineAdapter;
|
||||
private final List<VisibleObject<BuilderUsercontent>> builders;
|
||||
private final Map<String, VisibleActiveObject<TextFieldWidget>> textfields = new HashMap<String, VisibleActiveObject<TextFieldWidget>>();
|
||||
private final List<VisibleActiveObject<Widget>> buttons = new ArrayList<VisibleActiveObject<Widget>>();
|
||||
private UsercontentAPI api;
|
||||
private ButtonFactory buttonFactory;
|
||||
private ElementFactory elementFactory;
|
||||
|
||||
public ContentUsercontent(UsercontentConfig config) throws Exception
|
||||
{
|
||||
this.id = config.getId();
|
||||
this.content = config.getContent();
|
||||
this.engineAdapter = new ScriptEngineAdapter(config.getScriptEngine());
|
||||
this.builders = this.createBuilders(this.content.getModel());
|
||||
this.api = new UsercontentAPI(this.builders.stream().map(VisibleObject::getObject).collect(Collectors.toList()));
|
||||
ActionHandlerFactory actionHandlerFactory = new ActionHandlerFactory(this.api,this. builders, this.engineAdapter);
|
||||
this.buttonFactory = new ButtonFactory(this.api, actionHandlerFactory);
|
||||
this.elementFactory = new ElementFactory(this.api, actionHandlerFactory);
|
||||
this.engineAdapter.addObject("api", this.api);
|
||||
this.engineAdapter.eval(config.getJs());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICommandBuilder getCommandBuilder()
|
||||
{
|
||||
ICommandBuilder[] builders = this.builders.stream()
|
||||
.filter(builder -> builder.isVisible(this.engineAdapter))
|
||||
.map(VisibleObject::getObject)
|
||||
.toArray(ICommandBuilder[]::new);
|
||||
|
||||
return builders.length > 0 ? new BuilderMultiCommand(builders) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui(Container container, int x, int y)
|
||||
{
|
||||
this.textfields.clear();
|
||||
this.buttons.clear();
|
||||
|
||||
for(JsonButton button : this.getWidgets(this.content.getGui().getButtons(), JsonWidget.Type.BUTTON))
|
||||
{
|
||||
Widget widget = this.buttonFactory.createButton(button, this, container, x, y);
|
||||
|
||||
if(JsonButton.Type.TEXTFIELD.equals(button.getType()))
|
||||
{
|
||||
VisibleActiveObject<TextFieldWidget> visObj = new VisibleActiveObject<TextFieldWidget>(button, (TextFieldWidget) widget);
|
||||
this.textfields.put(button.getAttributes().getId(), visObj);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.buttons.add(new VisibleActiveObject<Widget>(button, widget));
|
||||
}
|
||||
}
|
||||
|
||||
for(JsonElement element : this.getWidgets(this.content.getGui().getElements(), JsonWidget.Type.ELEMENT))
|
||||
{
|
||||
container.add(this.elementFactory.createElement(element, this, container, x, y));
|
||||
}
|
||||
|
||||
this.updateTextfields();
|
||||
this.updateButtons();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initButtons(Container container, int x, int y)
|
||||
{
|
||||
this.textfields.values().stream().map(VisibleObject::getObject).forEach(container::add);
|
||||
this.buttons.stream().map(VisibleObject::getObject).forEach(container::add);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(Container container)
|
||||
{
|
||||
for(VisibleObject<TextFieldWidget> textfield : this.textfields.values())
|
||||
{
|
||||
if(textfield.isVisible(this.engineAdapter))
|
||||
{
|
||||
textfield.getObject().tick();
|
||||
}
|
||||
}
|
||||
|
||||
this.updateButtons();
|
||||
this.updateTextfields();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(Container container, int x, int y, int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
for(VisibleObject<TextFieldWidget> textfield : this.textfields.values())
|
||||
{
|
||||
if(textfield.getObject().visible)
|
||||
{
|
||||
textfield.getObject().renderButton(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
}
|
||||
|
||||
if(this.content.getGui() != null && this.content.getGui().getTexts() != null)
|
||||
{
|
||||
for(JsonText text : this.content.getGui().getTexts())
|
||||
{
|
||||
container.getMinecraft().fontRenderer.drawString(TextFormatting.formatNullable(text.getText()), text.getX() + x, text.getY() + y, text.getColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Category getCategory()
|
||||
{
|
||||
return Categories.getRegisteredCategory(this.content.getGui().getTab().getCategory());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle()
|
||||
{
|
||||
return TextFormatting.formatNullable(this.content.getGui().getTitle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTabTitle()
|
||||
{
|
||||
return TextFormatting.formatNullable(this.content.getGui().getTab().getTitle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Content getActiveContent()
|
||||
{
|
||||
if(this.content.getGui().getTab().getActiveContent() == null)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
return Contents.getRegisteredContent(this.content.getGui().getTab().getActiveContent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerNameChanged(String username)
|
||||
{
|
||||
for(VisibleObject<BuilderUsercontent> visObj : this.builders)
|
||||
{
|
||||
visObj.getObject().setPlayerName(username);
|
||||
}
|
||||
}
|
||||
|
||||
private List<VisibleObject<BuilderUsercontent>> createBuilders(JsonModel model)
|
||||
{
|
||||
List<VisibleObject<BuilderUsercontent>> builders = new ArrayList<VisibleObject<BuilderUsercontent>>();
|
||||
|
||||
if(model != null && model.getCommands() != null)
|
||||
{
|
||||
for(JsonCommand command : model.getCommands())
|
||||
{
|
||||
if(command.getName() != null && command.getSyntax() != null)
|
||||
{
|
||||
BuilderUsercontent builder = new BuilderUsercontent(command.getName(), new CommandSyntax(command.getSyntax()));
|
||||
builders.add(new VisibleObject<BuilderUsercontent>(command.getVisible(), builder));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return builders;
|
||||
}
|
||||
|
||||
private <T extends JsonWidget<?>> List<T> getWidgets(List<T> list, JsonWidget.Type type)
|
||||
{
|
||||
List<T> result = new ArrayList<T>();
|
||||
|
||||
if(list == null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
for(int x = 0; x < list.size(); x++)
|
||||
{
|
||||
T widget = list.get(x);
|
||||
|
||||
try
|
||||
{
|
||||
widget.validate();
|
||||
result.add(widget);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
this.printError(type.toString().toLowerCase(), x, e);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void printError(String type, int index, Throwable e)
|
||||
{
|
||||
ITextComponent message = new StringTextComponent(net.minecraft.util.text.TextFormatting.RED + "<" + Main.NAME + ":" + this.id + ":" + type + ":" + index + "> " + e.getMessage());
|
||||
Minecraft.getInstance().ingameGUI.addChatMessage(ChatType.CHAT, message);
|
||||
}
|
||||
|
||||
private void updateTextfields()
|
||||
{
|
||||
for(VisibleActiveObject<TextFieldWidget> visObj : this.textfields.values())
|
||||
{
|
||||
visObj.getObject().setEnabled(visObj.isEnabled(this.engineAdapter));
|
||||
visObj.getObject().visible = visObj.isVisible(this.engineAdapter);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateButtons()
|
||||
{
|
||||
for(VisibleActiveObject<Widget> visObj : this.buttons)
|
||||
{
|
||||
visObj.getObject().active = visObj.isEnabled(this.engineAdapter);
|
||||
visObj.getObject().visible = visObj.isVisible(this.engineAdapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.gui.content.Contents;
|
||||
import exopandora.worldhandler.helper.ActionHelper;
|
||||
import exopandora.worldhandler.text.TextFormatting;
|
||||
import exopandora.worldhandler.util.TextFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package exopandora.worldhandler.gui.content.element;
|
||||
package exopandora.worldhandler.gui.element;
|
||||
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
@@ -1,4 +1,4 @@
|
||||
package exopandora.worldhandler.gui.content.element;
|
||||
package exopandora.worldhandler.gui.element;
|
||||
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
@@ -1,4 +1,4 @@
|
||||
package exopandora.worldhandler.gui.content.element.impl;
|
||||
package exopandora.worldhandler.gui.element.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -7,10 +7,10 @@ import exopandora.worldhandler.gui.button.GuiButtonBase;
|
||||
import exopandora.worldhandler.gui.button.GuiButtonList;
|
||||
import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.content.element.Element;
|
||||
import exopandora.worldhandler.gui.element.Element;
|
||||
import exopandora.worldhandler.gui.logic.ILogicColorMenu;
|
||||
import exopandora.worldhandler.gui.logic.ILogicMapped;
|
||||
import exopandora.worldhandler.text.MutableStringTextComponent;
|
||||
import exopandora.worldhandler.util.MutableStringTextComponent;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
@@ -1,4 +1,4 @@
|
||||
package exopandora.worldhandler.gui.content.element.impl;
|
||||
package exopandora.worldhandler.gui.element.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -11,7 +11,7 @@ import exopandora.worldhandler.gui.button.GuiButtonBase;
|
||||
import exopandora.worldhandler.gui.button.GuiButtonList;
|
||||
import exopandora.worldhandler.gui.button.GuiButtonList.Persistence;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.content.element.Element;
|
||||
import exopandora.worldhandler.gui.element.Element;
|
||||
import exopandora.worldhandler.gui.logic.ILogicClickList;
|
||||
import exopandora.worldhandler.gui.logic.ILogicMapped;
|
||||
import exopandora.worldhandler.helper.Node;
|
||||
@@ -75,7 +75,7 @@ public class ElementMultiButtonList extends Element
|
||||
public void onClick(Node item)
|
||||
{
|
||||
ElementMultiButtonList.this.getPersistence(container, 1).setIndex(0);
|
||||
container.initButtons();
|
||||
container.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1,4 +1,4 @@
|
||||
package exopandora.worldhandler.gui.content.element.impl;
|
||||
package exopandora.worldhandler.gui.element.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -6,9 +6,9 @@ import java.util.Objects;
|
||||
import exopandora.worldhandler.config.Config;
|
||||
import exopandora.worldhandler.gui.button.GuiButtonBase;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
import exopandora.worldhandler.gui.content.element.Element;
|
||||
import exopandora.worldhandler.gui.element.Element;
|
||||
import exopandora.worldhandler.gui.logic.ILogicPageList;
|
||||
import exopandora.worldhandler.text.TextFormatting;
|
||||
import exopandora.worldhandler.util.TextFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
@@ -143,7 +143,7 @@ public class ElementPageList<T> extends Element
|
||||
|
||||
private int getTotalPages()
|
||||
{
|
||||
return (int) Math.ceil((float) this.items.size() / this.length);
|
||||
return Math.max((int) Math.ceil((float) this.items.size() / this.length), 1);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@@ -22,4 +22,9 @@ public interface ILogicMapped<T> extends ILogic
|
||||
}
|
||||
|
||||
void onClick(T item);
|
||||
|
||||
default void onInit(T item)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package exopandora.worldhandler.gui.logic;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import exopandora.worldhandler.builder.impl.abstr.EnumAttributes;
|
||||
import exopandora.worldhandler.builder.impl.EnumAttributes;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
|
||||
@@ -13,18 +13,19 @@ import exopandora.worldhandler.config.Config;
|
||||
import exopandora.worldhandler.gui.container.impl.GuiWorldHandler;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.gui.content.Contents;
|
||||
import exopandora.worldhandler.gui.content.impl.ContentChild;
|
||||
import exopandora.worldhandler.gui.content.impl.ContentContinue;
|
||||
import exopandora.worldhandler.util.ActionHandler;
|
||||
import net.minecraft.block.AbstractSignBlock;
|
||||
import net.minecraft.block.NoteBlock;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.text.ChatType;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.Style;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.util.text.event.ClickEvent;
|
||||
import net.minecraft.util.text.event.ClickEvent.Action;
|
||||
import net.minecraft.world.Difficulty;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
@@ -38,17 +39,45 @@ public class ActionHelper
|
||||
Minecraft.getInstance().mouseHelper.grabMouse();
|
||||
}
|
||||
|
||||
public static void back(String id) throws Exception
|
||||
{
|
||||
ActionHelper.back(Contents.getRegisteredContent(id));
|
||||
}
|
||||
|
||||
public static void back(Content content) throws Exception
|
||||
{
|
||||
if(content.getBackContent() != null)
|
||||
{
|
||||
Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(content.getBackContent()));
|
||||
ActionHelper.open(content.getBackContent());
|
||||
}
|
||||
}
|
||||
|
||||
public static void changeTab(Content content, int index)
|
||||
{
|
||||
ActionHelper.tryRun(() -> Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(content.getCategory().getContent(index))));
|
||||
ActionHelper.tryRun(() -> ActionHelper.open(content.getCategory().getContent(index)));
|
||||
}
|
||||
|
||||
public static void open(String id) throws Exception
|
||||
{
|
||||
if(id != null)
|
||||
{
|
||||
ActionHelper.open(Contents.getRegisteredContent(id));
|
||||
}
|
||||
}
|
||||
|
||||
public static void open(Content content) throws Exception
|
||||
{
|
||||
if(content != null && !(content instanceof ContentContinue))
|
||||
{
|
||||
if(content instanceof ContentChild && Minecraft.getInstance().currentScreen != null && Minecraft.getInstance().currentScreen instanceof GuiWorldHandler)
|
||||
{
|
||||
Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(((ContentChild) content).withParent(((GuiWorldHandler) Minecraft.getInstance().currentScreen).getContent())));
|
||||
}
|
||||
else
|
||||
{
|
||||
Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(content));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void timeDawn()
|
||||
@@ -140,13 +169,14 @@ public class ActionHelper
|
||||
Minecraft.getInstance().displayGuiScreen(null);
|
||||
Minecraft.getInstance().mouseHelper.grabMouse();
|
||||
|
||||
StringTextComponent name = new StringTextComponent(Main.NAME);
|
||||
name.setStyle(new Style().setUnderlined(true).setClickEvent(new ClickEvent(Action.OPEN_URL, Main.URL)));
|
||||
Style redColor = new Style().setColor(TextFormatting.RED);
|
||||
|
||||
TranslationTextComponent message = new TranslationTextComponent("worldhandler.error.gui", name);
|
||||
message.setStyle(new Style().setColor(net.minecraft.util.text.TextFormatting.RED));
|
||||
ITextComponent message = new TranslationTextComponent("<" + Main.NAME + "> %s", new TranslationTextComponent("worldhandler.error.gui")).setStyle(redColor);
|
||||
ITextComponent cause = new StringTextComponent(" " + e.getClass().getCanonicalName() + ": " + e.getMessage()).setStyle(redColor);
|
||||
|
||||
Minecraft.getInstance().ingameGUI.addChatMessage(ChatType.SYSTEM, message);
|
||||
Minecraft.getInstance().ingameGUI.addChatMessage(ChatType.SYSTEM, cause);
|
||||
|
||||
WorldHandler.LOGGER.throwing(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package exopandora.worldhandler.usercontent;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.script.Invocable;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import exopandora.worldhandler.WorldHandler;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class ScriptEngineAdapter
|
||||
{
|
||||
private final ScriptEngine engine;
|
||||
|
||||
public ScriptEngineAdapter(ScriptEngine engine)
|
||||
{
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Object invokeFunction(String function)
|
||||
{
|
||||
return this.invokeFunction(function, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Object invokeFunction(String function, Object value)
|
||||
{
|
||||
if(function != null && !function.isEmpty())
|
||||
{
|
||||
try
|
||||
{
|
||||
if(value != null)
|
||||
{
|
||||
return ((Invocable) this.engine).invokeFunction(function, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((Invocable) this.engine).invokeFunction(function);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WorldHandler.LOGGER.warn("No function specified");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addObject(String key, Object instance)
|
||||
{
|
||||
this.engine.put(key, instance);
|
||||
}
|
||||
|
||||
public void eval(String js) throws ScriptException
|
||||
{
|
||||
if(js != null)
|
||||
{
|
||||
this.engine.eval(js);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package exopandora.worldhandler.usercontent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.impl.BuilderUsercontent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.text.ChatType;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class UsercontentAPI
|
||||
{
|
||||
private final Map<String, String> values = new HashMap<String, String>();
|
||||
private final List<BuilderUsercontent> builders;
|
||||
|
||||
public UsercontentAPI(List<BuilderUsercontent> builders)
|
||||
{
|
||||
this.builders = builders;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getValue(String id)
|
||||
{
|
||||
return this.values.get(id);
|
||||
}
|
||||
|
||||
public void updateValue(String id, String value)
|
||||
{
|
||||
this.values.put(id, value);
|
||||
}
|
||||
|
||||
public void addChatMessage(Object object)
|
||||
{
|
||||
if(object != null)
|
||||
{
|
||||
Minecraft.getInstance().ingameGUI.addChatMessage(ChatType.CHAT, new StringTextComponent(object.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
public void setCommandArgument(int command, int index, String object)
|
||||
{
|
||||
if(command < this.builders.size() && command >= 0)
|
||||
{
|
||||
this.builders.get(command).set(index, object);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getCommandArgument(int command, int index)
|
||||
{
|
||||
if(command < this.builders.size() && command >= 0)
|
||||
{
|
||||
return this.builders.get(command).get(index);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package exopandora.worldhandler.usercontent;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
|
||||
import exopandora.worldhandler.usercontent.model.JsonUsercontent;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class UsercontentConfig
|
||||
{
|
||||
private final String id;
|
||||
private final JsonUsercontent content;
|
||||
private final String js;
|
||||
private final ScriptEngine engine;
|
||||
|
||||
private UsercontentConfig(Builder builder)
|
||||
{
|
||||
this.id = builder.id;
|
||||
this.content = builder.content;
|
||||
this.js = builder.js;
|
||||
this.engine = builder.engine;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public JsonUsercontent getContent()
|
||||
{
|
||||
return this.content;
|
||||
}
|
||||
|
||||
public String getJs()
|
||||
{
|
||||
return this.js;
|
||||
}
|
||||
|
||||
public ScriptEngine getScriptEngine()
|
||||
{
|
||||
return this.engine;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static class Builder
|
||||
{
|
||||
private final String id;
|
||||
private JsonUsercontent content;
|
||||
private String js;
|
||||
private ScriptEngine engine;
|
||||
|
||||
public Builder(Path path)
|
||||
{
|
||||
String fileName = path.getFileName().toString();
|
||||
this.id = fileName.substring(0, fileName.length() - 3);
|
||||
}
|
||||
|
||||
public Builder setContent(JsonUsercontent content)
|
||||
{
|
||||
this.content = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setJs(String js)
|
||||
{
|
||||
this.js = js;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setScriptEngine(ScriptEngine engine)
|
||||
{
|
||||
this.engine = engine;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UsercontentConfig build()
|
||||
{
|
||||
return new UsercontentConfig(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
package exopandora.worldhandler.usercontent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.script.ScriptContext;
|
||||
import javax.script.ScriptEngine;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import exopandora.worldhandler.WorldHandler;
|
||||
import exopandora.worldhandler.builder.types.ArgumentType;
|
||||
import exopandora.worldhandler.gui.button.EnumIcon;
|
||||
import exopandora.worldhandler.usercontent.model.Action;
|
||||
import exopandora.worldhandler.usercontent.model.BooleanExpression;
|
||||
import exopandora.worldhandler.usercontent.model.JsonButton;
|
||||
import exopandora.worldhandler.usercontent.model.JsonElement;
|
||||
import exopandora.worldhandler.usercontent.model.JsonUsercontent;
|
||||
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class UsercontentLoader
|
||||
{
|
||||
public static final List<UsercontentConfig> CONFIGS = new ArrayList<UsercontentConfig>();
|
||||
|
||||
public static void load(Path path)
|
||||
{
|
||||
try
|
||||
{
|
||||
UsercontentLoader.load0(path);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void load0(Path path) throws IOException
|
||||
{
|
||||
if(Files.notExists(path) || !Files.isReadable(path))
|
||||
{
|
||||
throw new IOException("Path is not accessible");
|
||||
}
|
||||
|
||||
final Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapter(ArgumentType.class, new EnumTypeAdapter<ArgumentType>(ArgumentType.class))
|
||||
.registerTypeAdapter(EnumIcon.class, new EnumTypeAdapter<EnumIcon>(EnumIcon.class))
|
||||
.registerTypeAdapter(BooleanExpression.Type.class, new EnumTypeAdapter<BooleanExpression.Type>(BooleanExpression.Type.class))
|
||||
.registerTypeAdapter(JsonButton.Type.class, new EnumTypeAdapter<JsonButton.Type>(JsonButton.Type.class))
|
||||
.registerTypeAdapter(Action.Type.class, new EnumTypeAdapter<Action.Type>(Action.Type.class))
|
||||
.registerTypeAdapter(JsonElement.Type.class, new EnumTypeAdapter<JsonElement.Type>(JsonElement.Type.class))
|
||||
.create();
|
||||
final List<Path> folders = Files.list(path)
|
||||
.filter(Files::isDirectory)
|
||||
.filter(Files::isReadable)
|
||||
.filter(UsercontentLoader::isValidPathName)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for(Path folder : folders)
|
||||
{
|
||||
Optional<Path> json = UsercontentLoader.locateFile(folder, "json");
|
||||
Optional<Path> js = UsercontentLoader.locateFile(folder, "js");
|
||||
|
||||
if(json.isPresent())
|
||||
{
|
||||
UsercontentConfig.Builder builder = new UsercontentConfig.Builder(js.get());
|
||||
String usercontent = UsercontentLoader.readFile(json.get());
|
||||
|
||||
try
|
||||
{
|
||||
JsonUsercontent content = gson.fromJson(usercontent, JsonUsercontent.class);
|
||||
content.validate();
|
||||
builder.setContent(content);
|
||||
|
||||
if(js.isPresent())
|
||||
{
|
||||
builder.setScriptEngine(UsercontentLoader.buildScriptEngine());
|
||||
builder.setJs(UsercontentLoader.readFile(js.get()));
|
||||
}
|
||||
|
||||
UsercontentLoader.CONFIGS.add(builder.build());
|
||||
}
|
||||
catch(JsonSyntaxException | IllegalStateException e)
|
||||
{
|
||||
WorldHandler.LOGGER.error("Error loading usercontent " + json.get().toAbsolutePath());
|
||||
WorldHandler.LOGGER.throwing(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final List<String> ALLOWED_CLASSES = Arrays.asList
|
||||
(
|
||||
"exopandora.worldhandler.helper.ActionHelper"
|
||||
);
|
||||
|
||||
private static ScriptEngine buildScriptEngine()
|
||||
{
|
||||
final NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
|
||||
final ScriptEngine engine = factory.getScriptEngine(s -> ALLOWED_CLASSES.stream().anyMatch(s::equals));
|
||||
final ScriptContext context = engine.getContext();
|
||||
|
||||
context.removeAttribute("load", context.getAttributesScope("load"));
|
||||
context.removeAttribute("quit", context.getAttributesScope("quit"));
|
||||
context.removeAttribute("loadWithNewGlobal", context.getAttributesScope("loadWithNewGlobal"));
|
||||
context.removeAttribute("exit", context.getAttributesScope("exit"));
|
||||
|
||||
return engine;
|
||||
}
|
||||
|
||||
private static Optional<Path> locateFile(Path path, String fileExtension)
|
||||
{
|
||||
Path json = path.resolve(path.getFileName().toString() + "." + fileExtension);
|
||||
|
||||
if(Files.exists(json) && Files.isRegularFile(json) && Files.isReadable(json))
|
||||
{
|
||||
return Optional.of(json);
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private static String readFile(Path path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return IOUtils.toString(path.toUri(), Charset.defaultCharset());
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isValidPathName(Path path)
|
||||
{
|
||||
String name = path.getFileName().toString();
|
||||
boolean valid = ResourceLocation.isResouceNameValid(name);
|
||||
|
||||
if(!valid)
|
||||
{
|
||||
WorldHandler.LOGGER.error("Invalid usercontent folder name: " + name);
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static class EnumTypeAdapter<T extends Enum<T>> extends TypeAdapter<T>
|
||||
{
|
||||
private final Class<T> klass;
|
||||
|
||||
public EnumTypeAdapter(Class<T> klass)
|
||||
{
|
||||
this.klass = klass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter writer, T value) throws IOException
|
||||
{
|
||||
writer.value(value.name().toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public T read(JsonReader reader) throws IOException
|
||||
{
|
||||
return Enum.valueOf(this.klass, reader.nextString().toUpperCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package exopandora.worldhandler.usercontent;
|
||||
|
||||
import exopandora.worldhandler.usercontent.model.BooleanExpression;
|
||||
import exopandora.worldhandler.usercontent.model.JsonButton;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class VisibleActiveObject<T> extends VisibleObject<T>
|
||||
{
|
||||
private final BooleanExpression active;
|
||||
|
||||
public VisibleActiveObject(BooleanExpression visible, BooleanExpression active, T object)
|
||||
{
|
||||
super(visible, object);
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public VisibleActiveObject(JsonButton button, T object)
|
||||
{
|
||||
this(button.getAttributes() != null ? button.getAttributes().getVisible() : null, button.getAttributes() != null ? button.getAttributes().getEnabled() : null, object);
|
||||
}
|
||||
|
||||
public boolean isEnabled(ScriptEngineAdapter engine)
|
||||
{
|
||||
if(this.active != null)
|
||||
{
|
||||
return this.active.eval(engine);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package exopandora.worldhandler.usercontent;
|
||||
|
||||
import exopandora.worldhandler.usercontent.model.BooleanExpression;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class VisibleObject<T>
|
||||
{
|
||||
private final BooleanExpression visible;
|
||||
private final T object;
|
||||
|
||||
public VisibleObject(BooleanExpression visible, T object)
|
||||
{
|
||||
this.visible = visible;
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
public boolean isVisible(ScriptEngineAdapter engine)
|
||||
{
|
||||
if(this.visible != null)
|
||||
{
|
||||
return this.visible.eval(engine);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public T getObject()
|
||||
{
|
||||
return this.object;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package exopandora.worldhandler.usercontent.factory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.impl.BuilderUsercontent;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.helper.ActionHelper;
|
||||
import exopandora.worldhandler.helper.CommandHelper;
|
||||
import exopandora.worldhandler.usercontent.ScriptEngineAdapter;
|
||||
import exopandora.worldhandler.usercontent.UsercontentAPI;
|
||||
import exopandora.worldhandler.usercontent.VisibleObject;
|
||||
import exopandora.worldhandler.usercontent.model.Action;
|
||||
import exopandora.worldhandler.util.ActionHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class ActionHandlerFactory
|
||||
{
|
||||
private final UsercontentAPI api;
|
||||
private final List<VisibleObject<BuilderUsercontent>> builders;
|
||||
private final ScriptEngineAdapter engine;
|
||||
|
||||
public ActionHandlerFactory(UsercontentAPI api, List<VisibleObject<BuilderUsercontent>> builders, ScriptEngineAdapter engine)
|
||||
{
|
||||
this.api = api;
|
||||
this.builders = builders;
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ActionHandler createActionHandler(Content content, Action action)
|
||||
{
|
||||
return this.createActionHandler(content, action, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ActionHandler createActionHandler(Content content, Action action, String value)
|
||||
{
|
||||
if(action == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if(Action.Type.OPEN.equals(action.getType()))
|
||||
{
|
||||
if(action.getAttributes() != null && action.getAttributes().getValue() != null)
|
||||
{
|
||||
return () -> ActionHelper.open(action.getAttributes().getValue());
|
||||
}
|
||||
}
|
||||
else if(Action.Type.SET.equals(action.getType()))
|
||||
{
|
||||
if(action.getAttributes() != null && (action.getAttributes().getValue() != null || value != null))
|
||||
{
|
||||
return () ->
|
||||
{
|
||||
VisibleObject<BuilderUsercontent> visObj = this.builders.get(action.getAttributes().getCommand());
|
||||
|
||||
if(visObj != null && visObj.getObject() != null)
|
||||
{
|
||||
visObj.getObject().set(action.getAttributes().getIndex(), value != null ? value : action.getAttributes().getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
else if(Action.Type.RUN.equals(action.getType()))
|
||||
{
|
||||
if(action.getAttributes() != null)
|
||||
{
|
||||
return () ->
|
||||
{
|
||||
if(action.getAttributes().getValue() == null)
|
||||
{
|
||||
CommandHelper.sendCommand(this.builders.get(action.getAttributes().getCommand()).getObject());
|
||||
}
|
||||
else if(!action.getAttributes().getValue().isEmpty())
|
||||
{
|
||||
Minecraft.getInstance().player.sendChatMessage(action.getAttributes().getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
else if(Action.Type.BACK.equals(action.getType()))
|
||||
{
|
||||
return () -> ActionHelper.back(content);
|
||||
}
|
||||
else if(Action.Type.BACK_TO_GAME.equals(action.getType()))
|
||||
{
|
||||
return ActionHelper::backToGame;
|
||||
}
|
||||
else if(Action.Type.JS.equals(action.getType()))
|
||||
{
|
||||
if(action.getAttributes() != null && action.getAttributes().getFunction() != null && !action.getAttributes().getFunction().isEmpty())
|
||||
{
|
||||
return () -> this.engine.invokeFunction(action.getAttributes().getFunction(), value != null ? value : action.getAttributes().getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T> Consumer<T> createResponder(Function<T, String> toStringMapper, String id, Action action)
|
||||
{
|
||||
if(Action.Type.SET.equals(action.getType()))
|
||||
{
|
||||
if(action.getAttributes() != null)
|
||||
{
|
||||
return string ->
|
||||
{
|
||||
String value = toStringMapper.apply(string);
|
||||
this.api.updateValue(id, value);
|
||||
this.builders.get(action.getAttributes().getCommand()).getObject().set(action.getAttributes().getIndex(), value);
|
||||
};
|
||||
}
|
||||
}
|
||||
else if(Action.Type.JS.equals(action.getType()))
|
||||
{
|
||||
if(action.getAttributes() != null && action.getAttributes().getFunction() != null)
|
||||
{
|
||||
return string ->
|
||||
{
|
||||
String value = toStringMapper.apply(string);
|
||||
this.api.updateValue(id, value);
|
||||
this.engine.invokeFunction(action.getAttributes().getFunction(), value);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return string -> this.api.updateValue(id, toStringMapper.apply(string));
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user