diff --git a/.gitignore b/.gitignore index 5bae765..4c34b44 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ # Except -!/src/ +!/src/main/ !/gradle/ !/run/config/worldhandler/usercontent/ !build.gradle diff --git a/build.gradle b/build.gradle index 8e48b64..67e6f81 100644 --- a/build.gradle +++ b/build.gradle @@ -15,11 +15,11 @@ buildscript { apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' -version = '1.17.1-2.12.8' +version = '1.18-3.0' group = 'exopandora.worldhandler' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'WorldHandler' -java.toolchain.languageVersion = JavaLanguageVersion.of(16) +java.toolchain.languageVersion = JavaLanguageVersion.of(17) println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch')) minecraft { @@ -34,7 +34,7 @@ minecraft { // // Use non-default mappings at your own risk. they may not always work. // Simply re-run your setup task after changing the mappings to update your workspace. - mappings channel: 'official', version: '1.17.1' + mappings channel: 'official', version: '1.18' // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') @@ -106,7 +106,7 @@ dependencies { // Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed // that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied. // The userdev artifact is a special name and will get all sorts of transformations applied to it. - minecraft 'net.minecraftforge:forge:1.17.1-37.0.71' + minecraft 'net.minecraftforge:forge:1.18-38.0.0' // You may put jars on which you depend on in ./libs or you may define them like so.. // compile "some.group:artifact:version:classifier" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ffed3a2..e750102 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/run/config/worldhandler/usercontent/example/example.js b/run/config/worldhandler/usercontent/example/example.js index e1a9fcb..c15030c 100644 --- a/run/config/worldhandler/usercontent/example/example.js +++ b/run/config/worldhandler/usercontent/example/example.js @@ -24,7 +24,7 @@ function selected(arg) { } function updateText(arg) { - api.setCommandArgument(0, 4, arg); + api.setArgument("example1", "textfield", arg); } function openContent(arg) { diff --git a/run/config/worldhandler/usercontent/example/example.json b/run/config/worldhandler/usercontent/example/example.json index 615aabe..50ad648 100644 --- a/run/config/worldhandler/usercontent/example/example.json +++ b/run/config/worldhandler/usercontent/example/example.json @@ -1,73 +1,80 @@ { - "model": { - "commands": [ - { + "commands": { + "example1": { + "label": "textfield", + "syntax": { "name": "example", - "syntax": [ + "children": [ { "name": "list_button", "type": "resource_location", - "required": true - }, - { - "name": "page_list", - "type": "resource_location", - "default": "minecraft:air", - "required": false - }, - { - "name": "slider", - "type": "int", - "default": 0, - "required": false - }, - { - "name": "player", - "type": "player", - "required": false - }, - { - "name": "textfield", - "type": "string", - "required": false + "children": [ + { + "name": "page_list", + "type": "resource_location", + "children": [ + { + "name": "slider", + "type": "int", + "children": [ + { + "name": "player", + "type": "player", + "children": [ + { + "name": "textfield", + "label": "textfield", + "type": "string" + } + ] + } + ] + } + ] + } + ] } - ], - "visible": { - "type": "bool", - "bool": true - } + ] }, - { - "name": "example2", - "syntax": [ - { - "name": "arg1", - "type": "float", - "default": 0, - "required": true - } - ], - "visible": { - "type": "bool", - "bool": true - } - }, - { - "name": "example3", - "syntax": [ - { - "name": "arg1", - "type": "int", - "default": "0", - "required": false - } - ], - "visible": { - "type": "bool", - "bool": false - } + "visible": { + "type": "bool", + "bool": true } - ] + }, + "example2": { + "label": "arg1", + "syntax": { + "name": "example2", + "children": [ + { + "name": "arg1", + "label": "arg1", + "type": "float" + } + ] + }, + "visible": { + "type": "bool", + "bool": true + } + }, + "example3": { + "label": "arg1", + "syntax": { + "name": "example3", + "children": [ + { + "name": "arg1", + "label": "arg1", + "type": "int" + } + ] + }, + "visible": { + "type": "bool", + "bool": false + } + } }, "gui": { "title": "Example Title", @@ -84,7 +91,7 @@ "layout": { "x": 0, "y": 0, - "width": 114, + "width": 56, "height": 20 }, "action": { @@ -105,6 +112,33 @@ } } }, + { + "text": "Send", + "type": "button", + "layout": { + "x": 58, + "y": 0, + "width": 56, + "height": 20 + }, + "action": { + "type": "run", + "attributes": { + "command": "example1", + "value": "textfield" + } + }, + "attributes": { + "visible": { + "type": "bool", + "bool": true + }, + "enabled": { + "type": "bool", + "bool": true + } + } + }, { "text": "Textfield", "type": "textfield", @@ -135,7 +169,7 @@ { "type": "item_button", "action": { - "type": "run", + "type": "run_string", "attributes": { "value": "/give @p minecraft:diamond_sword 1" } @@ -193,8 +227,8 @@ "action": { "type": "set", "attributes": { - "command": 0, - "index": 0 + "command": "example1", + "argument": "list_button" } }, "layout": { @@ -230,8 +264,8 @@ "action": { "type": "set", "attributes": { - "command": 0, - "index": 2 + "command": "example1", + "argument": "slider" } }, "layout": { @@ -311,8 +345,8 @@ "action": { "type": "set", "attributes": { - "command": 0, - "index": 1 + "command": "example1", + "argument": "page_list" } }, "attributes": { @@ -352,4 +386,4 @@ } ] } -} \ No newline at end of file +} diff --git a/src/main/java/exopandora/worldhandler/Main.java b/src/main/java/exopandora/worldhandler/Main.java index ae188be..d13253a 100644 --- a/src/main/java/exopandora/worldhandler/Main.java +++ b/src/main/java/exopandora/worldhandler/Main.java @@ -11,8 +11,8 @@ public class Main { public static final String NAME = "World Handler"; public static final String MODID = "worldhandler"; - public static final String MC_VERSION = "1.17.1"; - public static final String MOD_VERSION = "2.12.8"; + public static final String MC_VERSION = "1.18"; + public static final String MOD_VERSION = "3.0"; public static final String URL = "https://minecraft.curseforge.com/projects/world-handler-command-gui"; public static void main(String[] args) diff --git a/src/main/java/exopandora/worldhandler/WorldHandler.java b/src/main/java/exopandora/worldhandler/WorldHandler.java index 654afea..becd444 100644 --- a/src/main/java/exopandora/worldhandler/WorldHandler.java +++ b/src/main/java/exopandora/worldhandler/WorldHandler.java @@ -14,6 +14,7 @@ import exopandora.worldhandler.usercontent.UsercontentLoader; import exopandora.worldhandler.util.AdvancementHelper; import exopandora.worldhandler.util.CommandHelper; import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.ClientRegistry; import net.minecraftforge.client.event.RegisterClientReloadListenersEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.RegisterCommandsEvent; @@ -28,8 +29,6 @@ import net.minecraftforge.fml.config.ModConfig.Type; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.loading.FMLPaths; -import net.minecraftforge.fmlclient.registry.ClientRegistry; -import net.minecraftforge.fmllegacy.network.FMLNetworkConstants; @Mod(Main.MODID) public class WorldHandler @@ -37,6 +36,7 @@ public class WorldHandler public static final Logger LOGGER = LogManager.getLogger(); public static final Path USERCONTENT_PATH = FMLPaths.CONFIGDIR.get().resolve(Main.MODID).resolve("usercontent"); + @SuppressWarnings("serial") public WorldHandler() { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); @@ -59,14 +59,14 @@ public class WorldHandler modEventBus.addGenericListener(Category.class, Category::register); } }); - modLoadingContext.registerExtensionPoint(DisplayTest.class, () -> new DisplayTest(() -> FMLNetworkConstants.IGNORESERVERONLY, (remote, isServer) -> true)); + modLoadingContext.registerExtensionPoint(DisplayTest.class, () -> new DisplayTest(() -> "ANY", (remote, isServer) -> true)); } @SubscribeEvent public void clientSetup(FMLClientSetupEvent event) { MinecraftForge.EVENT_BUS.addListener(KeyHandler::keyInputEvent); - MinecraftForge.EVENT_BUS.addListener(ClientEventHandler::renderWorldLastEvent); + MinecraftForge.EVENT_BUS.addListener(ClientEventHandler::renderLevelLastEvent); MinecraftForge.EVENT_BUS.addListener(ClientEventHandler::clientChatEvent); ClientRegistry.registerKeyBinding(KeyHandler.KEY_WORLD_HANDLER); diff --git a/src/main/java/exopandora/worldhandler/builder/CommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/CommandBuilder.java index e024551..6af0118 100644 --- a/src/main/java/exopandora/worldhandler/builder/CommandBuilder.java +++ b/src/main/java/exopandora/worldhandler/builder/CommandBuilder.java @@ -1,323 +1,77 @@ package exopandora.worldhandler.builder; -import java.util.AbstractMap.SimpleEntry; import java.util.List; -import java.util.Map.Entry; +import java.util.function.BiFunction; import java.util.stream.Collectors; -import javax.annotation.Nonnull; import javax.annotation.Nullable; -import exopandora.worldhandler.WorldHandler; -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.CompoundTag; -import net.minecraft.resources.ResourceLocation; - -public abstract class CommandBuilder implements ICommandBuilderSyntax +public abstract class CommandBuilder implements ICommandBuilder { - private List> command; + protected abstract CommandNodeLiteral root(); - public CommandBuilder() + public String toCommand(Object label, boolean preview) { - this.updateSyntax(this.getSyntax()); - } - - protected void setNode(int index, String node) - { - this.set(index, node != null && !node.isEmpty() ? node : null, ArgumentType.STRING); - } - - protected void setNode(int index, GreedyString node) - { - this.set(index, node != null && !node.isEmpty() ? node : null, ArgumentType.GREEDY_STRING); - } - - protected void setNode(int index, boolean node) - { - this.set(index, node, ArgumentType.BOOLEAN); - } - - protected void setNode(int index, short node) - { - this.set(index, node, ArgumentType.SHORT); - } - - protected void setNode(int index, byte node) - { - this.set(index, node, ArgumentType.BYTE); - } - - protected void setNode(int index, int node) - { - this.set(index, node, ArgumentType.INT); - } - - protected void setNode(int index, float node) - { - this.set(index, node, ArgumentType.FLOAT); - } - - protected void setNode(int index, double node) - { - this.set(index, node, ArgumentType.DOUBLE); - } - - protected void setNode(int index, long node) - { - this.set(index, node, ArgumentType.LONG); - } - - protected void setNode(int index, ResourceLocation node) - { - this.set(index, node, ArgumentType.RESOURCE_LOCATION); - } - - protected void setNode(int index, CoordinateInt coordinate) - { - this.set(index, coordinate, ArgumentType.COORDINATE_INT); - } - - protected void setNode(int index, CoordinateDouble coordinate) - { - this.set(index, coordinate, ArgumentType.COORDINATE_DOUBLE); - } - - protected void setNode(int index, TargetSelector target) - { - this.set(index, target, ArgumentType.TARGET_SELECTOR); - } - - protected void setNode(int index, ItemResourceLocation resource) - { - this.set(index, resource, ArgumentType.ITEM_RESOURCE_LOCATION); - } - - protected void setNode(int index, BlockResourceLocation resource) - { - this.set(index, resource, ArgumentType.BLOCK_RESOURCE_LOCATION); - } - - protected void setNode(int index, CompoundTag nbt) - { - this.set(index, nbt, ArgumentType.NBT); - } - - protected void setPlayerName(int index, String username) - { - this.set(index, username != null && !username.isEmpty() ? username : null, ArgumentType.PLAYER); - } - - private void set(int index, Object value, ArgumentType type) - { - if(index < this.command.size()) + CommandNode node = this.root().find(label).orElse(this.root()); + + if(preview) { - Argument entry = this.command.get(index).getKey(); - ArgumentType expectedType = entry.getType(); - boolean typeMatch = expectedType.equals(type); - - if(value != null && typeMatch) - { - this.command.get(index).setValue(value.toString()); - } - else - { - this.command.get(index).setValue(entry.toString()); - - if(!typeMatch) - { - this.warn("set", expectedType, type, index); - } - } - } - else - { - WorldHandler.LOGGER.warn("Tried to set invalid index \"" + index + "\" for command \"" + this.getCommandName() + "\""); - } - } - - @Nullable - protected String getNodeAsString(int index) - { - return this.get(index, ArgumentType.STRING); - } - - @Nullable - protected String getNodeAsGreedyString(int index) - { - return this.get(index, ArgumentType.GREEDY_STRING); - } - - protected boolean getNodeAsBoolean(int index) - { - return this.get(index, ArgumentType.BOOLEAN); - } - - protected short getNodeAsShort(int index) - { - return this.get(index, ArgumentType.SHORT); - } - - protected byte getNodeAsByte(int index) - { - return this.get(index, ArgumentType.BYTE); - } - - protected int getNodeAsInt(int index) - { - return this.get(index, ArgumentType.INT); - } - - protected float getNodeAsFloat(int index) - { - return this.get(index, ArgumentType.FLOAT); - } - - protected double getNodeAsDouble(int index) - { - return this.get(index, ArgumentType.DOUBLE); - } - - protected long getNodeAsLong(int index) - { - return this.get(index, ArgumentType.LONG); - } - - @Nonnull - protected CoordinateInt getNodeAsCoordinateInt(int index) - { - return this.get(index, ArgumentType.COORDINATE_INT); - } - - @Nonnull - protected CoordinateDouble getNodeAsCoordinateDouble(int index) - { - return this.get(index, ArgumentType.COORDINATE_DOUBLE); - } - - @Nullable - protected ResourceLocation getNodeAsResourceLocation(int index) - { - return this.get(index, ArgumentType.RESOURCE_LOCATION); - } - - @Nonnull - protected TargetSelector getNodeAsTargetSelector(int index) - { - return this.get(index, ArgumentType.TARGET_SELECTOR); - } - - @Nullable - protected ItemResourceLocation getNodeAsItemResourceLocation(int index) - { - return this.get(index, ArgumentType.ITEM_RESOURCE_LOCATION); - } - - @Nullable - protected BlockResourceLocation getNodeAsBlockResourceLocation(int index) - { - return this.get(index, ArgumentType.BLOCK_RESOURCE_LOCATION); - } - - @Nullable - protected CompoundTag getNodeAsNBT(int index) - { - return this.get(index, ArgumentType.NBT); - } - - @Nullable - private T get(int index, ArgumentType type) - { - if(index < this.command.size()) - { - Entry entry = this.command.get(index); - ArgumentType expected = entry.getKey().getType(); - String value = entry.getValue(); - - if(expected.equals(type)) - { - if(value.equals(entry.getKey().toString())) - { - return null; - } - - return expected.parse(value); - } - - this.warn("get", expected, type, index); - - return type.parse(value); + return this.buildForward(node, label, CommandNode::toValue).toString(); } - return null; + return this.buildReverse(node, label, CommandNode::toValue, false).toString(); } - private void warn(String function, ArgumentType expected, ArgumentType type, int index) + protected StringBuilder buildForward(CommandNode node, Object label, BiFunction, Object, String> valueMapper) { - WorldHandler.LOGGER.warn("[" + function.toUpperCase() + "] Expected \"" + expected + "\" instead of \"" + type + "\" at index \"" + index + "\" for command \"" + this.getCommandName() + "\""); - } - - private boolean isDefaultArgument(Argument argument, String value) - { - return argument.getDefault() != null ? value.equals(argument.getDefault().toString()) : value == null; - } - - protected void updateSyntax(CommandSyntax syntax) - { - if(syntax != null) - { - this.command = syntax.getArguments().stream().map(entry -> new SimpleEntry(entry, entry.toString())).collect(Collectors.toList()); - } - } - - @Override - public String toCommand() - { - CommandString command = new CommandString(this.getCommandName()); + StringBuilder builder = this.buildReverse(node, label, valueMapper, true); - for(Entry entry : this.command) + if(builder.isEmpty()) { - if(this.isDefaultArgument(entry.getKey(), entry.getValue())) + return builder; + } + + if(node != null) + { + List> children = node.getChildren(); + + while(children != null && children.size() == 1) { - command.append(entry.getKey().toString()); + node = children.get(0); + builder.append(" "); + builder.append(valueMapper.apply(children.get(0), label)); + children = node.getChildren(); } - else + + if(children != null && children.size() > 0) { - command.append(entry.getValue()); + builder.append(children.stream().map(child -> valueMapper.apply(child, label)).collect(Collectors.joining("|", " [", "]"))); } } - return command.toString(); + return builder; } - @Override - public String toActualCommand() + protected StringBuilder buildReverse(@Nullable CommandNode node, Object label, BiFunction, Object, String> valueMapper, boolean includeOptionals) { - CommandString command = new CommandString(this.getCommandName()); + StringBuilder builder = new StringBuilder(); - for(Entry entry : this.command) + while(node != null) { - if(!entry.getKey().isRequired() && (entry.getKey().toString().equals(entry.getValue()) || this.isDefaultArgument(entry.getKey(), entry.getValue()))) + CommandNode parent = node.getParent(); + + if(parent == null) { - break; + builder.insert(0, "/" + valueMapper.apply(node, label)); + } + else if(includeOptionals || !builder.isEmpty() || !node.isOptional(label) || !node.isDefault(label)) + { + builder.insert(0, " " + valueMapper.apply(node, label)); } - 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()); - } + node = parent; } - return command.toString(); + return builder; } } diff --git a/src/main/java/exopandora/worldhandler/builder/CommandBuilderNBT.java b/src/main/java/exopandora/worldhandler/builder/CommandBuilderNBT.java deleted file mode 100644 index a5d6186..0000000 --- a/src/main/java/exopandora/worldhandler/builder/CommandBuilderNBT.java +++ /dev/null @@ -1,71 +0,0 @@ -package exopandora.worldhandler.builder; - -import java.util.ArrayList; -import java.util.List; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.component.IBuilderComponent; -import exopandora.worldhandler.util.NBTHelper; -import net.minecraft.nbt.CompoundTag; - -public abstract class CommandBuilderNBT extends CommandBuilder implements ICommandBuilderNBT -{ - private final List TAG_TO_COMPONENT = new ArrayList(); - - @Override - public String toCommand() - { - return this.toCommand(true); - } - - public String toCommand(boolean rebuildNBT) - { - if(rebuildNBT) - { - this.setNBT(this.buildNBT()); - } - - return super.toCommand(); - } - - @Override - public String toActualCommand() - { - return this.toActualCommand(true); - } - - public String toActualCommand(boolean rebuildNBT) - { - if(rebuildNBT) - { - this.setNBT(this.buildNBT()); - } - - return super.toActualCommand(); - } - - @Nullable - protected CompoundTag buildNBT() - { - CompoundTag nbt = new CompoundTag(); - - for(IBuilderComponent component : this.TAG_TO_COMPONENT) - { - NBTHelper.append(nbt, component); - } - - if(nbt.isEmpty()) - { - return null; - } - - return nbt; - } - - public T registerNBTComponent(T component) - { - this.TAG_TO_COMPONENT.add(component); - return component; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/CommandString.java b/src/main/java/exopandora/worldhandler/builder/CommandString.java deleted file mode 100644 index a91cd9b..0000000 --- a/src/main/java/exopandora/worldhandler/builder/CommandString.java +++ /dev/null @@ -1,48 +0,0 @@ -package exopandora.worldhandler.builder; - -import net.minecraft.ChatFormatting; - -public class CommandString -{ - private final StringBuilder command = new StringBuilder("/"); - - public CommandString(String name) - { - this.command.append(name); - } - - public CommandString(String name, String... arguments) - { - this(name); - this.append(arguments); - } - - public void append(String argument) - { - if(argument != null && !argument.isEmpty()) - { - this.command.append(" " + argument); - } - else - { - this.command.append(" " + ChatFormatting.RED + "[error]" + ChatFormatting.RESET); - } - } - - public void append(String... arguments) - { - if(arguments != null) - { - for(String argument : arguments) - { - this.append(argument); - } - } - } - - @Override - public String toString() - { - return this.command.toString(); - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/CommandSyntax.java b/src/main/java/exopandora/worldhandler/builder/CommandSyntax.java deleted file mode 100644 index 02bfb16..0000000 --- a/src/main/java/exopandora/worldhandler/builder/CommandSyntax.java +++ /dev/null @@ -1,108 +0,0 @@ -package exopandora.worldhandler.builder; - -import java.util.ArrayList; -import java.util.List; - -import com.google.gson.annotations.SerializedName; - -import exopandora.worldhandler.builder.types.ArgumentType; - -public class CommandSyntax -{ - private List syntax = new ArrayList(); - - public CommandSyntax() - { - super(); - } - - public CommandSyntax(List 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 getArguments() - { - return this.syntax; - } - - 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 + "]"; - } - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/ICommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/ICommandBuilder.java index 64438f3..2803117 100644 --- a/src/main/java/exopandora/worldhandler/builder/ICommandBuilder.java +++ b/src/main/java/exopandora/worldhandler/builder/ICommandBuilder.java @@ -4,10 +4,10 @@ public interface ICommandBuilder { static final int MAX_COMMAND_LENGTH = 256; - String toCommand(); + String toCommand(Object label, boolean preview); - default boolean needsCommandBlock() + default boolean needsCommandBlock(Object label, boolean preview) { - return this.toCommand().length() > MAX_COMMAND_LENGTH; + return this.toCommand(label, preview).length() > MAX_COMMAND_LENGTH; } } diff --git a/src/main/java/exopandora/worldhandler/builder/ICommandBuilderNBT.java b/src/main/java/exopandora/worldhandler/builder/ICommandBuilderNBT.java deleted file mode 100644 index ebdcda9..0000000 --- a/src/main/java/exopandora/worldhandler/builder/ICommandBuilderNBT.java +++ /dev/null @@ -1,8 +0,0 @@ -package exopandora.worldhandler.builder; - -import net.minecraft.nbt.CompoundTag; - -public interface ICommandBuilderNBT extends ICommandBuilder -{ - void setNBT(CompoundTag nbt); -} diff --git a/src/main/java/exopandora/worldhandler/builder/ICommandBuilderSyntax.java b/src/main/java/exopandora/worldhandler/builder/ICommandBuilderSyntax.java deleted file mode 100644 index b9fb81b..0000000 --- a/src/main/java/exopandora/worldhandler/builder/ICommandBuilderSyntax.java +++ /dev/null @@ -1,14 +0,0 @@ -package exopandora.worldhandler.builder; - -public interface ICommandBuilderSyntax extends ICommandBuilder -{ - String getCommandName(); - String toActualCommand(); - CommandSyntax getSyntax(); - - @Override - default boolean needsCommandBlock() - { - return this.toActualCommand().length() > MAX_COMMAND_LENGTH; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/INBTWritable.java b/src/main/java/exopandora/worldhandler/builder/INBTWritable.java deleted file mode 100644 index 3e01455..0000000 --- a/src/main/java/exopandora/worldhandler/builder/INBTWritable.java +++ /dev/null @@ -1,11 +0,0 @@ -package exopandora.worldhandler.builder; - -import javax.annotation.Nullable; - -import net.minecraft.nbt.Tag; - -public interface INBTWritable -{ - @Nullable - Tag serialize(); -} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/tag/EffectInstance.java b/src/main/java/exopandora/worldhandler/builder/argument/tag/EffectInstance.java new file mode 100644 index 0000000..1ecfc3e --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/tag/EffectInstance.java @@ -0,0 +1,106 @@ +package exopandora.worldhandler.builder.argument.tag; + +public class EffectInstance +{ + private byte amplifier; + private int seconds; + private int minutes; + private int hours; + private boolean showParticles; + private boolean ambient; + + public EffectInstance() + { + this((byte) 0, 0, 0, 0, true, false); + } + + public EffectInstance(byte amplifier, int seconds, int minutes, int hours, boolean showParticles, boolean ambient) + { + this.amplifier = amplifier; + this.seconds = seconds; + this.minutes = minutes; + this.hours = hours; + this.showParticles = showParticles; + this.ambient = ambient; + } + + public byte getAmplifier() + { + return this.amplifier; + } + + public void setAmplifier(byte amplifier) + { + this.amplifier = amplifier; + } + + public int getSeconds() + { + return this.seconds; + } + + public void setSeconds(int seconds) + { + this.seconds = seconds; + } + + public int getMinutes() + { + return this.minutes; + } + + public void setMinutes(int minutes) + { + this.minutes = minutes; + } + + public int getHours() + { + return this.hours; + } + + public void setHours(int hours) + { + this.hours = hours; + } + + public boolean doShowParticles() + { + return this.showParticles; + } + + public void setShowParticles(boolean showParticles) + { + this.showParticles = showParticles; + } + + public boolean isAmbient() + { + return this.ambient; + } + + public void setAmbient(boolean ambient) + { + this.ambient = ambient; + } + + public int toTicks() + { + return EffectInstance.toTicks(this.seconds, this.minutes, this.hours); + } + + public int toSeconds() + { + return EffectInstance.toSeconds(this.seconds, this.minutes, this.hours); + } + + public static int toTicks(int seconds, int minutes, int hours) + { + return seconds * 20 + minutes * 1200 + hours * 72000; + } + + public static int toSeconds(int seconds, int minutes, int hours) + { + return seconds + minutes * 60 + hours * 3600; + } +} \ No newline at end of file diff --git a/src/main/java/exopandora/worldhandler/builder/component/IBuilderComponent.java b/src/main/java/exopandora/worldhandler/builder/component/IBuilderComponent.java deleted file mode 100644 index fa710e8..0000000 --- a/src/main/java/exopandora/worldhandler/builder/component/IBuilderComponent.java +++ /dev/null @@ -1,8 +0,0 @@ -package exopandora.worldhandler.builder.component; - -import exopandora.worldhandler.builder.INBTWritable; - -public interface IBuilderComponent extends INBTWritable -{ - String getTag(); -} diff --git a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttribute.java b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttribute.java deleted file mode 100644 index e733e43..0000000 --- a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttribute.java +++ /dev/null @@ -1,44 +0,0 @@ -package exopandora.worldhandler.builder.component.impl; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -import exopandora.worldhandler.builder.component.IBuilderComponent; -import net.minecraft.client.resources.language.I18n; -import net.minecraft.world.entity.ai.attributes.Attribute; -import net.minecraftforge.registries.ForgeRegistries; - -public abstract class ComponentAttribute implements IBuilderComponent -{ - public static final List ATTRIBUTES = ForgeRegistries.ATTRIBUTES.getValues().stream().filter(attribute -> !attribute.getDescriptionId().equals(I18n.get(attribute.getDescriptionId()))).collect(Collectors.toList()); - - protected Map attributes = new HashMap(); - - public void set(Attribute attribute, double ammount) - { - this.attributes.put(attribute, ammount); - } - - public double getAmmount(Attribute attribute) - { - if(this.attributes.containsKey(attribute)) - { - return this.attributes.get(attribute); - } - - return 0; - } - - public void remove(Attribute attribute) - { - this.attributes.remove(attribute); - } - - public Set getAttributes() - { - return this.attributes.keySet(); - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttributeItem.java b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttributeItem.java deleted file mode 100644 index a8d85c6..0000000 --- a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttributeItem.java +++ /dev/null @@ -1,50 +0,0 @@ -package exopandora.worldhandler.builder.component.impl; - -import java.util.Map.Entry; -import java.util.UUID; - -import javax.annotation.Nullable; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.Tag; -import net.minecraft.world.entity.ai.attributes.Attribute; - -public class ComponentAttributeItem extends ComponentAttribute -{ - @Override - @Nullable - public Tag serialize() - { - ListTag attributes = new ListTag(); - - for(Entry entry : this.attributes.entrySet()) - { - if(entry.getValue() != 0) - { - CompoundTag attribute = new CompoundTag(); - String id = entry.getKey().getRegistryName().toString(); - - attribute.putString("AttributeName", id); - attribute.putDouble("Amount", entry.getValue() / 100); - attribute.putInt("Operation", 1); // 0 = additive, 1 = percentage - attribute.putUUID("UUID", UUID.nameUUIDFromBytes(id.getBytes())); - - attributes.add(attribute); - } - } - - if(attributes.isEmpty()) - { - return null; - } - - return attributes; - } - - @Override - public String getTag() - { - return "AttributeModifiers"; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttributeMob.java b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttributeMob.java deleted file mode 100644 index de290c0..0000000 --- a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttributeMob.java +++ /dev/null @@ -1,47 +0,0 @@ -package exopandora.worldhandler.builder.component.impl; - -import java.util.Map.Entry; - -import javax.annotation.Nullable; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.Tag; -import net.minecraft.world.entity.ai.attributes.Attribute; - -public class ComponentAttributeMob extends ComponentAttribute -{ - @Override - @Nullable - public Tag serialize() - { - ListTag attributes = new ListTag(); - - for(Entry entry : this.attributes.entrySet()) - { - if(entry.getValue() != 0) - { - CompoundTag attribute = new CompoundTag(); - String id = entry.getKey().getRegistryName().toString(); - - attribute.putString("Name", id); - attribute.putDouble("Base", entry.getValue() / 100); - - attributes.add(attribute); - } - } - - if(attributes.isEmpty()) - { - return null; - } - - return attributes; - } - - @Override - public String getTag() - { - return "Attributes"; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentCustom.java b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentCustom.java deleted file mode 100644 index 2e77784..0000000 --- a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentCustom.java +++ /dev/null @@ -1,43 +0,0 @@ -package exopandora.worldhandler.builder.component.impl; - -import exopandora.worldhandler.builder.component.IBuilderComponent; -import net.minecraft.nbt.Tag; - -public class ComponentCustom implements IBuilderComponent -{ - private Tag nbt; - private String tag; - - public void setNBT(Tag nbt) - { - this.nbt = nbt; - } - - public void setTag(String tag) - { - this.tag = tag; - } - - public void set(String tag, Tag nbt) - { - this.setTag(tag); - this.setNBT(nbt); - } - - public void reset() - { - this.set(null, null); - } - - @Override - public Tag serialize() - { - return this.nbt; - } - - @Override - public String getTag() - { - return this.tag; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentDisplay.java b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentDisplay.java deleted file mode 100644 index 5befcf1..0000000 --- a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentDisplay.java +++ /dev/null @@ -1,94 +0,0 @@ -package exopandora.worldhandler.builder.component.impl; - -import exopandora.worldhandler.builder.component.IBuilderComponent; -import exopandora.worldhandler.util.MutableTextComponent; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.StringTag; -import net.minecraft.nbt.Tag; -import net.minecraft.network.chat.Component; - -public class ComponentDisplay implements IBuilderComponent -{ - private MutableTextComponent name = new MutableTextComponent(); - private Component[] lore = new Component[2]; - - @Override - public Tag serialize() - { - CompoundTag display = new CompoundTag(); - - if(this.name.getText() != null && !this.name.getText().isEmpty()) - { - display.putString("Name", Component.Serializer.toJson(this.name)); - } - - ListTag lore = new ListTag(); - - for(int x = 0; x < this.lore.length; x++) - { - if(this.lore[x] != null && !this.lore[x].getString().isEmpty()) - { - lore.add(StringTag.valueOf(Component.Serializer.toJson(this.lore[x]))); - } - } - - if(!lore.isEmpty()) - { - display.put("Lore", lore); - } - - if(!display.isEmpty()) - { - return display; - } - - return null; - } - - public void setName(MutableTextComponent name) - { - this.name = name; - } - - public MutableTextComponent getName() - { - return this.name; - } - - public void setLore(Component[] lore) - { - this.lore = lore; - } - - public Component[] getLore() - { - return this.lore; - } - - public void setLore1(Component lore) - { - this.lore[0] = lore; - } - - public Component getLore1() - { - return this.lore[0]; - } - - public void setLore2(Component lore) - { - this.lore[1] = lore; - } - - public Component getLore2() - { - return this.lore[1]; - } - - @Override - public String getTag() - { - return "display"; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentEnchantment.java b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentEnchantment.java deleted file mode 100644 index cac7360..0000000 --- a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentEnchantment.java +++ /dev/null @@ -1,75 +0,0 @@ -package exopandora.worldhandler.builder.component.impl; - -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.component.IBuilderComponent; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.Tag; -import net.minecraft.world.item.enchantment.Enchantment; -import net.minecraftforge.registries.ForgeRegistries; - -public class ComponentEnchantment implements IBuilderComponent -{ - private Map enchantments = new HashMap(); - - @Override - @Nullable - public Tag serialize() - { - ListTag enchantments = new ListTag(); - - for(Entry entry : this.enchantments.entrySet()) - { - if(entry.getValue() > 0) - { - CompoundTag enchantment = new CompoundTag(); - - enchantment.putString("id", ForgeRegistries.ENCHANTMENTS.getKey(entry.getKey()).toString()); - enchantment.putShort("lvl", entry.getValue()); - - enchantments.add(enchantment); - } - } - - if(enchantments.isEmpty()) - { - return null; - } - - return enchantments; - } - - public void setLevel(Enchantment enchantment, short level) - { - if(level == 0) - { - this.enchantments.remove(enchantment); - } - else - { - this.enchantments.put(enchantment, level); - } - } - - public short getLevel(Enchantment enchantment) - { - return this.enchantments.get(enchantment); - } - - public Set getEnchantments() - { - return this.enchantments.keySet(); - } - - @Override - public String getTag() - { - return "Enchantments"; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotion.java b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotion.java deleted file mode 100644 index da91dee..0000000 --- a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotion.java +++ /dev/null @@ -1,120 +0,0 @@ -package exopandora.worldhandler.builder.component.impl; - -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.component.IBuilderComponent; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.Tag; -import net.minecraft.world.effect.MobEffect; - -public abstract class ComponentPotion implements IBuilderComponent -{ - protected final Map potions = new HashMap(); - - @Override - @Nullable - public Tag serialize() - { - ListTag list = new ListTag(); - - for(Entry entry : this.potions.entrySet()) - { - EffectNBT effect = entry.getValue(); - - if(effect.getAmplifier() > 0) - { - CompoundTag compound = effect.serialize(); - compound.putByte("Id", (byte) MobEffect.getId(entry.getKey())); - list.add(compound); - } - } - - if(list.isEmpty()) - { - return null; - } - - return list; - } - - public void setAmplifier(MobEffect potion, byte amplifier) - { - this.get(potion).setAmplifier(amplifier); - } - - public byte getAmplifier(MobEffect potion) - { - return this.get(potion).getAmplifier(); - } - - public void setSeconds(MobEffect potion, int seconds) - { - this.get(potion).setSeconds(seconds); - } - - public int getSeconds(MobEffect potion) - { - return this.get(potion).getSeconds(); - } - - public void setMinutes(MobEffect potion, int minutes) - { - this.get(potion).setMinutes(minutes); - } - - public int getMinutes(MobEffect potion) - { - return this.get(potion).getMinutes(); - } - - public void setHours(MobEffect potion, int hours) - { - this.get(potion).setHours(hours); - } - - public int getHours(MobEffect potion) - { - return this.get(potion).getHours(); - } - - public void setShowParticles(MobEffect potion, boolean showParticles) - { - this.get(potion).setShowParticles(showParticles); - } - - public boolean getShowParticles(MobEffect potion) - { - return this.get(potion).getShowParticles(); - } - - public void setAmbient(MobEffect potion, boolean ambient) - { - this.get(potion).setAmbient(ambient); - } - - public boolean getAmbient(MobEffect potion) - { - return this.get(potion).getAmbient(); - } - - private EffectNBT get(MobEffect potion) - { - return this.potions.computeIfAbsent(potion, key -> new EffectNBT()); - } - - public Set getMobEffects() - { - return this.potions.keySet(); - } - - public void remove(MobEffect potion) - { - this.potions.remove(potion); - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotionItem.java b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotionItem.java deleted file mode 100644 index 18adb8d..0000000 --- a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotionItem.java +++ /dev/null @@ -1,10 +0,0 @@ -package exopandora.worldhandler.builder.component.impl; - -public class ComponentPotionItem extends ComponentPotion -{ - @Override - public String getTag() - { - return "CustomPotionEffects"; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotionMob.java b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotionMob.java deleted file mode 100644 index 90e66e0..0000000 --- a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotionMob.java +++ /dev/null @@ -1,10 +0,0 @@ -package exopandora.worldhandler.builder.component.impl; - -public class ComponentPotionMob extends ComponentPotion -{ - @Override - public String getTag() - { - return "ActiveEffects"; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentTag.java b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentTag.java deleted file mode 100644 index 86ad7e7..0000000 --- a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentTag.java +++ /dev/null @@ -1,146 +0,0 @@ -package exopandora.worldhandler.builder.component.impl; - -import java.util.Collection; -import java.util.function.Function; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.WorldHandler; -import exopandora.worldhandler.builder.component.IBuilderComponent; -import net.minecraft.nbt.ByteArrayTag; -import net.minecraft.nbt.ByteTag; -import net.minecraft.nbt.DoubleTag; -import net.minecraft.nbt.FloatTag; -import net.minecraft.nbt.IntArrayTag; -import net.minecraft.nbt.IntTag; -import net.minecraft.nbt.LongArrayTag; -import net.minecraft.nbt.LongTag; -import net.minecraft.nbt.ShortTag; -import net.minecraft.nbt.StringTag; -import net.minecraft.nbt.Tag; - -public class ComponentTag implements IBuilderComponent -{ - private final Function serializer; - private final String tag; - private T value; - - public ComponentTag(String tag, T value, Function serializer) - { - this.tag = tag; - this.value = value; - this.serializer = serializer; - } - - public ComponentTag(String tag, Function serializer) - { - this(tag, null, serializer); - } - - public ComponentTag(String tag, T value) - { - this(tag, value, null); - } - - public ComponentTag(String tag) - { - this(tag, null, null); - } - - public void setValue(T value) - { - this.value = value; - } - - @Nullable - public T getValue() - { - return this.value; - } - - @Override - @Nullable - public Tag serialize() - { - if(this.value != null) - { - if(this.serializer != null) - { - return this.serializer.apply(this.value); - } - else if(this.value instanceof String) - { - String string = (String) this.value; - - if(string.isEmpty()) - { - return null; - } - - return StringTag.valueOf(string); - } - else if(this.value instanceof Tag) - { - if(this.value instanceof Collection) - { - Collection collection = (Collection) this.value; - - if(collection.isEmpty()) - { - return null; - } - } - - return (Tag) this.value; - } - else if(this.value instanceof Integer) - { - return IntTag.valueOf((Integer) this.value); - } - else if(this.value instanceof Byte) - { - return ByteTag.valueOf((Byte) this.value); - } - else if(this.value instanceof Float) - { - return FloatTag.valueOf((Float) this.value); - } - else if(this.value instanceof Double) - { - return DoubleTag.valueOf((Double) this.value); - } - else if(this.value instanceof Long) - { - return LongTag.valueOf((Long) this.value); - } - else if(this.value instanceof Short) - { - return ShortTag.valueOf((Short) this.value); - } - else if(this.value instanceof Byte[]) - { - return new ByteArrayTag((byte[]) this.value); - } - else if(this.value instanceof Integer[]) - { - return new IntArrayTag((int[]) this.value); - } - else if(this.value instanceof Long[]) - { - return new LongArrayTag((long[]) this.value); - } - else - { - WorldHandler.LOGGER.warn("Tag \"" + this.tag + "\" has no serializer"); - } - } - - return null; - } - - @Override - public String getTag() - { - return this.tag; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/component/impl/EffectNBT.java b/src/main/java/exopandora/worldhandler/builder/component/impl/EffectNBT.java deleted file mode 100644 index b37bca9..0000000 --- a/src/main/java/exopandora/worldhandler/builder/component/impl/EffectNBT.java +++ /dev/null @@ -1,166 +0,0 @@ -package exopandora.worldhandler.builder.component.impl; - -import exopandora.worldhandler.builder.INBTWritable; -import net.minecraft.nbt.CompoundTag; - -public class EffectNBT implements INBTWritable -{ - private byte amplifier; - private int seconds; - private int minutes; - private int hours; - private boolean showParticles; - private boolean ambient; - - public EffectNBT() - { - this((byte) 0, 0, 0, 0, true, false); - } - - public EffectNBT(byte amplifier, int seconds, int minutes, int hours, boolean showParticles, boolean ambient) - { - this.amplifier = amplifier; - this.seconds = seconds; - this.minutes = minutes; - this.hours = hours; - this.showParticles = showParticles; - this.ambient = ambient; - } - - public byte getAmplifier() - { - return this.amplifier; - } - - public void setAmplifier(byte amplifier) - { - this.amplifier = amplifier; - } - - public int getSeconds() - { - return this.seconds; - } - - public void setSeconds(int seconds) - { - this.seconds = seconds; - } - - public int getMinutes() - { - return this.minutes; - } - - public void setMinutes(int minutes) - { - this.minutes = minutes; - } - - public int getHours() - { - return this.hours; - } - - public void setHours(int hours) - { - this.hours = hours; - } - - public boolean getShowParticles() - { - return this.showParticles; - } - - public void setShowParticles(boolean showParticles) - { - this.showParticles = showParticles; - } - - public boolean getAmbient() - { - return this.ambient; - } - - public void setAmbient(boolean ambient) - { - this.ambient = ambient; - } - - public int toTicks() - { - return EffectNBT.toTicks(this.seconds, this.minutes, this.hours); - } - - public int toSeconds() - { - return EffectNBT.toSeconds(this.seconds, this.minutes, this.hours); - } - - @Override - public CompoundTag serialize() - { - CompoundTag compound = new CompoundTag(); - int ticks = this.toTicks(); - - compound.putByte("Amplifier", (byte) (this.amplifier - 1)); - compound.putInt("Duration", ticks > 0 ? ticks : 1000000); - compound.putBoolean("Ambient", this.ambient); - compound.putBoolean("ShowParticles", this.showParticles); - - return compound; - } - - public static int toTicks(int seconds, int minutes, int hours) - { - return seconds * 20 + minutes * 1200 + hours * 72000; - } - - public static int toSeconds(int seconds, int minutes, int hours) - { - return seconds + minutes * 60 + hours * 3600; - } - - public EffectNBT withAmplifier(byte amplifier) - { - this.amplifier = amplifier; - return this; - } - - public EffectNBT withShowParticles(boolean showParticles) - { - this.showParticles = showParticles; - return this; - } - - public EffectNBT withSeconds(int seconds) - { - this.seconds = seconds; - return this; - } - - public EffectNBT withMinutes(int minutes) - { - this.minutes = minutes; - return this; - } - - public EffectNBT withHours(int hours) - { - this.hours = hours; - return this; - } - - public EffectNBT withAmbient(boolean ambient) - { - this.ambient = ambient; - return this; - } - - @Override - public String toString() - { - return "EffectNBT [amplifier=" + amplifier + ", seconds=" + seconds + ", minutes=" + minutes + ", hours=" + hours + ", showParticles=" + showParticles + ", ambient=" + ambient + "]"; - } -} - diff --git a/src/main/java/exopandora/worldhandler/builder/component/impl/EntityNBT.java b/src/main/java/exopandora/worldhandler/builder/component/impl/EntityNBT.java deleted file mode 100644 index 089d3db..0000000 --- a/src/main/java/exopandora/worldhandler/builder/component/impl/EntityNBT.java +++ /dev/null @@ -1,468 +0,0 @@ -package exopandora.worldhandler.builder.component.impl; - -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import com.mojang.brigadier.exceptions.CommandSyntaxException; - -import exopandora.worldhandler.builder.component.IBuilderComponent; -import exopandora.worldhandler.util.MutableTextComponent; -import exopandora.worldhandler.util.NBTHelper; -import net.minecraft.nbt.ByteTag; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.IntTag; -import net.minecraft.nbt.StringTag; -import net.minecraft.nbt.Tag; -import net.minecraft.nbt.TagParser; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.effect.MobEffect; -import net.minecraft.world.entity.ai.attributes.Attribute; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.Items; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.state.BlockState; - -public class EntityNBT implements IBuilderComponent -{ - private ResourceLocation id; - private String command; - private Integer time; - private double[] motion = {0.0, 0.0, 0.0}; - private boolean isBaby; - private BlockState blockState; - private ComponentCustom entity = new ComponentCustom(); - private ComponentAttributeMob attribute = new ComponentAttributeMob(); - private MutableTextComponent customName = new MutableTextComponent(); - private List passengers = new ArrayList(); - private ResourceLocation[] armorItems = {Items.AIR.getRegistryName(), Items.AIR.getRegistryName(), Items.AIR.getRegistryName(), Items.AIR.getRegistryName()}; - private ResourceLocation[] handItems = {Items.AIR.getRegistryName(), Items.AIR.getRegistryName()}; - private ComponentPotionMob potion = new ComponentPotionMob(); - private CompoundTag nbt; - - public EntityNBT() - { - super(); - } - - public EntityNBT(ResourceLocation id) - { - this.id = id; - } - - public void setId(ResourceLocation id) - { - this.id = id; - } - - public ResourceLocation getId() - { - return this.id; - } - - public void setAttribute(Attribute attribute, double ammount) - { - this.attribute.set(attribute, ammount); - } - - public void removeAttribute(Attribute attribute) - { - this.attribute.remove(attribute); - } - - public double getAttributeAmmount(Attribute attribute) - { - return this.attribute.getAmmount(attribute); - } - - public Set getAttributes() - { - return this.attribute.getAttributes(); - } - - public void setCustomName(String name) - { - this.customName.setText(name); - } - - @Nullable - public MutableTextComponent getCustomName() - { - return this.customName; - } - - public void setPassenger(int index, EntityNBT entity) - { - if(index < 0 || index >= this.passengers.size()) - { - this.passengers.add(entity); - } - else - { - this.passengers.set(index, entity); - } - } - - public void setPassenger(int index, ResourceLocation id) - { - this.setPassenger(index, new EntityNBT(id)); - } - - public void addPassenger(EntityNBT entity) - { - this.passengers.add(entity); - } - - public void addPassenger(int index, EntityNBT entity) - { - this.passengers.add(index, entity); - } - - public void removePassenger(int index) - { - this.passengers.remove(index); - } - - public int getPassengerCount() - { - return this.passengers.size(); - } - - public List getPassengers() - { - return this.passengers; - } - - @Nullable - public EntityNBT getPassenger(int index) - { - if(index >= 0 && index <= this.passengers.size()) - { - return this.passengers.get(index); - } - - return null; - } - - public boolean hasPassengers() - { - for(EntityNBT entity : this.passengers) - { - if(entity.serialize() != null) - { - return true; - } - } - - return false; - } - - public void setArmorItem(int index, Block block) - { - this.setArmorItem(index, block.getRegistryName()); - } - - public void setArmorItem(int index, Item item) - { - this.setArmorItem(index, item.getRegistryName()); - } - - public void setArmorItem(int index, ResourceLocation location) - { - if(EntityNBT.isArrayIndexValid(this.armorItems, index) && location != null) - { - this.armorItems[index] = location; - } - } - - public void setArmorItems(ResourceLocation[] armor) - { - this.armorItems = armor; - } - - @Nonnull - public ResourceLocation getArmorItem(int slot) - { - if(EntityNBT.isArrayIndexValid(this.armorItems, slot)) - { - return this.armorItems[slot]; - } - - return Blocks.AIR.getRegistryName(); - } - - public void setHandItem(int index, Block block) - { - this.setHandItem(index, block.getRegistryName()); - } - - public void setHandItem(int index, Item item) - { - this.setHandItem(index, item.getRegistryName()); - } - - public void setHandItem(int index, ResourceLocation location) - { - if(EntityNBT.isArrayIndexValid(this.handItems, index) && location != null) - { - this.handItems[index] = location; - } - } - - @Nonnull - public ResourceLocation getHandItem(int slot) - { - if(EntityNBT.isArrayIndexValid(this.handItems, slot)) - { - return this.handItems[slot]; - } - - return Blocks.AIR.getRegistryName(); - } - - public double[] getMotion() - { - return this.motion; - } - - public void setMotion(double x, double y, double z) - { - this.setMotionX(x); - this.setMotionY(y); - this.setMotionZ(z); - } - - public double getMotionX() - { - return this.motion[0]; - } - - public double getMotionY() - { - return this.motion[1]; - } - - public double getMotionZ() - { - return this.motion[2]; - } - - public void setMotionX(double x) - { - this.motion[0] = x; - } - - public void setMotionY(double y) - { - this.motion[1] = y; - } - - public void setMotionZ(double z) - { - this.motion[2] = z; - } - - public void setAmplifier(MobEffect potion, byte amplifier) - { - this.potion.setAmplifier(potion, amplifier); - } - - public void setSeconds(MobEffect potion, int seconds) - { - this.potion.setSeconds(potion, seconds); - } - - public void setMinutes(MobEffect potion, int minutes) - { - this.potion.setMinutes(potion, minutes); - } - - public void setHours(MobEffect potion, int hours) - { - this.potion.setHours(potion, hours); - } - - public void setShowParticles(MobEffect potion, boolean showParticles) - { - this.potion.setShowParticles(potion, showParticles); - } - - public void setAmbient(MobEffect potion, boolean ambient) - { - this.potion.setAmbient(potion, ambient); - } - - public byte getAmplifier(MobEffect potion) - { - return this.potion.getAmplifier(potion); - } - - public int getSeconds(MobEffect potion) - { - return this.potion.getSeconds(potion); - } - - public int getMinutes(MobEffect potion) - { - return this.potion.getMinutes(potion); - } - - public int getHours(MobEffect potion) - { - return this.potion.getHours(potion); - } - - public boolean getShowParticles(MobEffect potion) - { - return this.potion.getShowParticles(potion); - } - - public boolean getAmbient(MobEffect potion) - { - return this.potion.getAmbient(potion); - } - - public Set getEffects() - { - return this.potion.getMobEffects(); - } - - public void setBlockState(BlockState blockState) - { - this.blockState = blockState; - } - - public BlockState getBlockState() - { - return this.blockState; - } - - public void setTime(int time) - { - this.time = time; - } - - public int getTime() - { - return this.time; - } - - public void setCustomComponent(String tag, Tag nbt) - { - this.entity.set(tag, nbt); - } - - public void resetCustomComponent() - { - this.entity.set(null, null); - } - - public void setIsBaby(boolean baby) - { - this.isBaby = baby; - } - - public boolean isBaby() - { - return this.isBaby; - } - - public void setCommand(String command) - { - this.command = command; - } - - public String getCommand() - { - return this.command; - } - - public void setNBT(CompoundTag nbt) - { - this.nbt = nbt; - } - - public CompoundTag getNBT() - { - return this.nbt; - } - - public void setNBT(String nbt) - { - try - { - this.nbt = TagParser.parseTag("{" + nbt + "}"); - } - catch(CommandSyntaxException e) - { - this.nbt = null; - } - } - - @Override - public CompoundTag serialize() - { - CompoundTag nbt = new CompoundTag(); - - if(this.time != null) - { - NBTHelper.append(nbt, "Time", IntTag.valueOf(this.time)); - } - - if(this.command != null) - { - NBTHelper.append(nbt, "Command", StringTag.valueOf(this.command)); - } - - if(this.isBaby) - { - NBTHelper.append(nbt, "IsBaby", ByteTag.valueOf(true)); - } - - NBTHelper.append(nbt, "id", NBTHelper.serialize(this.id)); - NBTHelper.append(nbt, "Motion", NBTHelper.serialize(this.motion)); - NBTHelper.append(nbt, "Passengers", NBTHelper.serialize(this.passengers)); - NBTHelper.append(nbt, "ArmorItems", NBTHelper.serialize(this.armorItems)); - NBTHelper.append(nbt, "HandItems", NBTHelper.serialize(this.handItems)); - NBTHelper.append(nbt, "BlockState", NBTHelper.serialize(this.blockState)); - - NBTHelper.append(nbt, "CustomName", this.customName); - - NBTHelper.append(nbt, this.entity); - NBTHelper.append(nbt, this.potion); - NBTHelper.append(nbt, this.attribute); - - if(this.nbt != null) - { - nbt.merge(this.nbt); - } - - if(nbt.isEmpty()) - { - return null; - } - - return nbt; - } - - @Override - public String getTag() - { - return null; - } - - private static boolean isArrayIndexValid(Object[] array, int index) - { - if(array != null && (Array.getLength(array) == 0 || array.length <= index)) - { - return false; - } - - return index >= 0; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderAdvancement.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderAdvancement.java deleted file mode 100644 index 5c637a7..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderAdvancement.java +++ /dev/null @@ -1,125 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; -import exopandora.worldhandler.util.EnumHelper; -import net.minecraft.resources.ResourceLocation; - -public class BuilderAdvancement extends CommandBuilder -{ - public BuilderAdvancement(EnumMode mode) - { - this.setMode(mode); - } - - public BuilderAdvancement(EnumActionType action, String player, EnumMode mode, ResourceLocation advancement) - { - this(mode); - this.setActionType(action); - this.setPlayer(player); - this.setAdvancement(advancement); - } - - public void setActionType(EnumActionType action) - { - this.setNode(0, action != null ? action.toString() : null); - } - - @Nullable - public EnumActionType getActionType() - { - return EnumHelper.valueOf(this.getNodeAsString(1), EnumActionType.class); - } - - public void setPlayer(String player) - { - this.setNode(1, player); - } - - @Nullable - public String getPlayer() - { - return this.getNodeAsString(1); - } - - public void setMode(EnumMode mode) - { - this.setNode(2, mode != null ? mode.toString() : null); - } - - @Nullable - public EnumMode getMode() - { - return EnumHelper.valueOf(this.getNodeAsString(2), EnumMode.class); - } - - public void setAdvancement(ResourceLocation advancement) - { - this.setNode(3, advancement); - } - - @Nullable - public ResourceLocation getAdvancement() - { - return this.getNodeAsResourceLocation(3); - } - - public BuilderAdvancement build(EnumActionType action) - { - return this.build(action, this.getMode()); - } - - public BuilderAdvancement build(EnumActionType action, EnumMode mode) - { - return new BuilderAdvancement(action, this.getPlayer(), mode, !EnumMode.EVERYTHING.equals(mode) ? this.getAdvancement() : null); - } - - @Override - public String getCommandName() - { - return "advancement"; - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - 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; - } - - public static enum EnumActionType - { - GRANT, - REVOKE; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } - - public static enum EnumMode - { - ONLY, - UNTIL, - FROM, - THROUGH, - EVERYTHING; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderBlockPos.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderBlockPos.java deleted file mode 100644 index 7069abf..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderBlockPos.java +++ /dev/null @@ -1,87 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import exopandora.worldhandler.builder.CommandBuilderNBT; -import exopandora.worldhandler.builder.types.CoordinateInt; -import net.minecraft.core.BlockPos; - -public abstract class BuilderBlockPos extends CommandBuilderNBT -{ - private final int offset; - - public BuilderBlockPos(int offset) - { - this.offset = offset; - } - - public void setPosition(BlockPos pos) - { - this.setX(pos.getX()); - this.setY(pos.getY()); - this.setZ(pos.getZ()); - } - - public void setX(int x) - { - this.setX(new CoordinateInt(x)); - } - - public void setY(int y) - { - this.setY(new CoordinateInt(y)); - } - - public void setZ(int z) - { - this.setZ(new CoordinateInt(z)); - } - - public void setX(CoordinateInt x) - { - this.setNode(this.offset, x); - } - - public void setY(CoordinateInt y) - { - this.setNode(this.offset + 1, y); - } - - public void setZ(CoordinateInt z) - { - this.setNode(this.offset + 2, z); - } - - public CoordinateInt getXCoordinate() - { - return this.getNodeAsCoordinateInt(this.offset); - } - - public CoordinateInt getYCoordinate() - { - return this.getNodeAsCoordinateInt(this.offset + 1); - } - - public CoordinateInt getZCoordinate() - { - return this.getNodeAsCoordinateInt(this.offset + 2); - } - - public int getX() - { - return this.getXCoordinate().getValue(); - } - - public int getY() - { - return this.getYCoordinate().getValue(); - } - - public int getZ() - { - return this.getZCoordinate().getValue(); - } - - public BlockPos getBlockPos() - { - return new BlockPos(this.getX(), this.getY(), this.getZ()); - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderButcher.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderButcher.java deleted file mode 100644 index 3f641cc..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderButcher.java +++ /dev/null @@ -1,78 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nonnull; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; -import exopandora.worldhandler.builder.types.TargetSelector; -import net.minecraft.resources.ResourceLocation; - -public class BuilderButcher extends CommandBuilder -{ - private final TargetSelector targetSelector = new TargetSelector(); - - public BuilderButcher() - { - this("", 0); - } - - public BuilderButcher(ResourceLocation entity, int distance) - { - this(entity.toString(), distance); - } - - private BuilderButcher(String entity, int distance) - { - this.setEntity(entity); - this.setDistance(distance); - } - - public void setDistance(int distance) - { - this.targetSelector.set("distance", "0.." + distance); - this.setNode(0, this.targetSelector); - } - - public int getDistance() - { - return Integer.parseInt(this.targetSelector.get("distance").substring(3)); - } - - private void setEntity(String entity) - { - if(entity != null) - { - this.targetSelector.set("type", entity); - } - - this.setNode(0, this.targetSelector); - } - - public void setEntity(ResourceLocation entity) - { - this.setEntity(entity.toString()); - } - - @Nonnull - public ResourceLocation getEntity() - { - return this.targetSelector.get("type"); - } - - @Override - public String getCommandName() - { - return "kill"; - } - - @Override - public CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("entity_name", ArgumentType.TARGET_SELECTOR); - - return syntax; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderClone.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderClone.java deleted file mode 100644 index 12150b5..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderClone.java +++ /dev/null @@ -1,168 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; -import exopandora.worldhandler.builder.types.Coordinate.EnumType; -import exopandora.worldhandler.builder.types.CoordinateInt; -import exopandora.worldhandler.util.EnumHelper; -import net.minecraft.core.BlockPos; - -public class BuilderClone extends BuilderDoubleBlockPos -{ - public BuilderClone() - { - this.setX(new CoordinateInt(EnumType.GLOBAL)); - this.setY(new CoordinateInt(EnumType.GLOBAL)); - this.setZ(new CoordinateInt(EnumType.GLOBAL)); - this.setMask(EnumMask.values()[0]); - } - - public void setPosition(BlockPos pos) - { - this.setX(pos.getX()); - this.setY(pos.getY()); - this.setZ(pos.getZ()); - } - - public void setX(int x) - { - this.setX(new CoordinateInt(x)); - } - - public void setY(int y) - { - this.setY(new CoordinateInt(y)); - } - - public void setZ(int z) - { - this.setZ(new CoordinateInt(z)); - } - - public void setX(CoordinateInt x) - { - this.setNode(6, x); - } - - public void setY(CoordinateInt y) - { - this.setNode(7, y); - } - - public void setZ(CoordinateInt z) - { - this.setNode(8, z); - } - - @Nonnull - public CoordinateInt getXCoordiante() - { - return this.getNodeAsCoordinateInt(6); - } - - @Nonnull - public CoordinateInt getYCoordiante() - { - return this.getNodeAsCoordinateInt(7); - } - - @Nonnull - public CoordinateInt getZCoordiante() - { - return this.getNodeAsCoordinateInt(8); - } - - public double getX() - { - return this.getXCoordiante().getValue(); - } - - public double getY() - { - return this.getYCoordiante().getValue(); - } - - public double getZ() - { - return this.getZCoordiante().getValue(); - } - - public BlockPos getBlockPos() - { - return new BlockPos(this.getX(), this.getY(), this.getZ()); - } - - public void setMask(EnumMask mask) - { - this.setNode(9, mask != null ? mask.toString() : null); - } - - @Nullable - public EnumMask getMask() - { - return EnumHelper.valueOf(this.getNodeAsString(9), EnumMask.class); - } - - public void setFilter(String filter) - { - if(filter != null) - { - this.setMask(EnumMask.FILTERED); - } - - this.setNode(10, filter); - } - - @Nullable - public String getFilter() - { - if(EnumMask.FILTERED.equals(this.getMask())) - { - return this.getNodeAsString(10); - } - - return null; - } - - @Override - public String getCommandName() - { - return "clone"; - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - 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; - } - - public static enum EnumMask - { - FILTERED, - MASKED, - REPLACE; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderCustomItem.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderCustomItem.java deleted file mode 100644 index afa439a..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderCustomItem.java +++ /dev/null @@ -1,97 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -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.util.MutableTextComponent; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.ai.attributes.Attribute; -import net.minecraft.world.item.enchantment.Enchantment; - -public class BuilderCustomItem extends BuilderGive -{ - private final ComponentAttributeItem attribute; - private final ComponentDisplay display; - private final ComponentEnchantment enchantment; - - public BuilderCustomItem() - { - this(null, null); - } - - public BuilderCustomItem(String player, ResourceLocation item) - { - super(player, item); - this.attribute = this.registerNBTComponent(new ComponentAttributeItem()); - this.display = this.registerNBTComponent(new ComponentDisplay()); - this.enchantment = this.registerNBTComponent(new ComponentEnchantment()); - } - - public void setEnchantment(Enchantment enchantment, short level) - { - this.enchantment.setLevel(enchantment, level); - } - - public short getEnchantmentLevel(Enchantment enchantment) - { - return this.enchantment.getLevel(enchantment); - } - - public Set getEnchantments() - { - return this.enchantment.getEnchantments(); - } - - public void setAttribute(Attribute attribute, double ammount) - { - this.attribute.set(attribute, ammount); - } - - public void removeAttribute(Attribute attribute) - { - this.attribute.remove(attribute); - } - - public double getAttributeAmmount(Attribute attribute) - { - return this.attribute.getAmmount(attribute); - } - - public Set getAttributes() - { - return this.attribute.getAttributes(); - } - - public void setName(MutableTextComponent name) - { - this.display.setName(name); - } - - public MutableTextComponent getName() - { - return this.display.getName(); - } - - public void setLore1(Component lore) - { - this.display.setLore1(lore); - } - - public Component getLore1() - { - return this.display.getLore1(); - } - - public void setLore2(Component lore) - { - this.display.setLore2(lore); - } - - public Component getLore2() - { - return this.display.getLore2(); - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderData.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderData.java deleted file mode 100644 index 82db06d..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderData.java +++ /dev/null @@ -1,323 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; -import exopandora.worldhandler.builder.types.CoordinateInt; -import exopandora.worldhandler.builder.types.TargetSelector; -import exopandora.worldhandler.util.EnumHelper; -import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.resources.ResourceLocation; - -public class BuilderData extends BuilderBlockPos -{ - private final TargetSelector targetSelector = new TargetSelector(); - - public BuilderData() - { - super(2); - } - - public BuilderData(EnumMode mode, ResourceLocation entity, CompoundTag nbt) - { - this(); - this.setMode(mode); - this.setEntity(entity); - this.setNBT(nbt); - } - - public BuilderData(EnumMode mode, BlockPos pos, CompoundTag nbt) - { - this(); - this.setMode(mode); - this.setPosition(pos); - this.setNBT(nbt); - } - - public void setMode(EnumMode mode) - { - EnumTarget target = this.getTarget(); - - this.updateSyntax(this.getSyntax(mode, target)); - this.setMode0(mode); - this.setTarget0(target); - } - - private void setMode0(EnumMode mode) - { - if(mode != null) - { - this.setNode(0, mode.toString()); - } - } - - @Nullable - public EnumMode getMode() - { - return EnumHelper.valueOf(this.getNodeAsString(0), EnumMode.class); - } - - public void setTarget(EnumTarget target) - { - EnumMode mode = this.getMode(); - - this.updateSyntax(this.getSyntax(mode, target)); - this.setMode0(mode); - this.setTarget0(target); - } - - private void setTarget0(EnumTarget target) - { - if(target != null) - { - this.setNode(1, target.toString()); - } - } - - @Nullable - public EnumTarget getTarget() - { - return EnumHelper.valueOf(this.getNodeAsString(1), EnumTarget.class); - } - - private void setEntity(String entity) - { - this.ensureTarget(EnumTarget.ENTITY); - - if(entity != null) - { - this.targetSelector.set("type", entity); - } - - this.setNode(2, this.targetSelector); - } - - public void setEntity(ResourceLocation entity) - { - this.setEntity(entity.toString()); - } - - @Nonnull - public ResourceLocation getEntity() - { - return this.targetSelector.get("type"); - } - - public void setPath(String path) - { - if(this.getMode() == null || !this.getMode().equals(EnumMode.REMOVE)) - { - this.setMode(EnumMode.REMOVE); - } - - switch(this.getTarget()) - { - case BLOCK: - this.setNode(5, path); - break; - case ENTITY: - this.setNode(3, path); - break; - default: - break; - } - } - - @Override - public void setNBT(CompoundTag nbt) - { - if(this.getMode() == null || !this.getMode().equals(EnumMode.MERGE)) - { - this.setMode(EnumMode.MERGE); - } - - EnumTarget target = this.getTarget(); - - if(target != null) - { - switch(target) - { - case BLOCK: - this.setNode(5, nbt); - break; - case ENTITY: - this.setNode(3, nbt); - break; - default: - break; - } - } - } - - @Nullable - public CompoundTag getNBT() - { - if(this.getMode() != null && this.getMode().equals(EnumMode.MERGE)) - { - switch(this.getTarget()) - { - case BLOCK: - return this.getNodeAsNBT(5); - case ENTITY: - return this.getNodeAsNBT(3); - default: - break; - } - } - - return null; - } - - @Override - public String getCommandName() - { - return "data"; - } - - @Nullable - private final CommandSyntax getSyntax(EnumMode mode, EnumTarget target) - { - CommandSyntax syntax = new CommandSyntax(); - - 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", ArgumentType.COORDINATE_INT); - syntax.addRequired("y", ArgumentType.COORDINATE_INT); - syntax.addRequired("z", ArgumentType.COORDINATE_INT); - break; - case ENTITY: - syntax.addRequired("entity", ArgumentType.TARGET_SELECTOR); - break; - default: - break; - } - - switch(mode) - { - case GET: - break; - case MERGE: - syntax.addRequired("nbt", ArgumentType.NBT); - break; - case REMOVE: - syntax.addRequired("path", ArgumentType.STRING); - break; - default: - break; - } - } - else - { - syntax.addOptional("...", ArgumentType.STRING); - } - - return syntax; - } - - private void ensureTarget(EnumTarget target) - { - if(this.getTarget() == null || !target.equals(this.getTarget())) - { - this.setTarget(target); - } - } - - @Override - public void setX(CoordinateInt x) - { - this.ensureTarget(EnumTarget.BLOCK); - super.setX(x); - } - - @Override - public void setY(CoordinateInt y) - { - this.ensureTarget(EnumTarget.BLOCK); - super.setY(y); - } - - @Override - public void setZ(CoordinateInt z) - { - this.ensureTarget(EnumTarget.BLOCK); - super.setZ(z); - } - - @Override - @Nonnull - public CoordinateInt getXCoordinate() - { - this.ensureTarget(EnumTarget.BLOCK); - return super.getXCoordinate(); - } - - @Override - @Nonnull - public CoordinateInt getYCoordinate() - { - this.ensureTarget(EnumTarget.BLOCK); - return super.getYCoordinate(); - } - - @Override - @Nonnull - public CoordinateInt getZCoordinate() - { - this.ensureTarget(EnumTarget.BLOCK); - return super.getZCoordinate(); - } - - @Override - @Nonnull - public BlockPos getBlockPos() - { - this.ensureTarget(EnumTarget.BLOCK); - return super.getBlockPos(); - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("get|merge|remove", ArgumentType.STRING); - syntax.addRequired("block|entity", ArgumentType.STRING); - syntax.addOptional("...", ArgumentType.STRING); - - return syntax; - } - - public static enum EnumMode - { - GET, - MERGE, - REMOVE; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } - - public static enum EnumTarget - { - BLOCK, - ENTITY; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderDifficulty.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderDifficulty.java deleted file mode 100644 index ca57b49..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderDifficulty.java +++ /dev/null @@ -1,43 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; -import net.minecraft.world.Difficulty; - -public class BuilderDifficulty extends CommandBuilder -{ - public BuilderDifficulty() - { - super(); - } - - public BuilderDifficulty(Difficulty difficulty) - { - this.setDifficulty(difficulty); - } - - public void setDifficulty(Difficulty difficulty) - { - if(difficulty != null) - { - this.setNode(0, difficulty.getKey()); - } - } - - @Override - public String getCommandName() - { - return "difficulty"; - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("peaceful|easy|normal|hard", ArgumentType.STRING); - - return syntax; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderDoubleBlockPos.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderDoubleBlockPos.java deleted file mode 100644 index 47b05e5..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderDoubleBlockPos.java +++ /dev/null @@ -1,167 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nonnull; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.types.CoordinateInt; -import exopandora.worldhandler.util.BlockHelper; -import net.minecraft.core.BlockPos; - -public abstract class BuilderDoubleBlockPos extends CommandBuilder -{ - public BuilderDoubleBlockPos() - { - this.setPosition1(BlockHelper.getPos1()); - this.setPosition2(BlockHelper.getPos2()); - } - - public void setPosition1(BlockPos pos) - { - this.setX1(pos.getX()); - this.setY1(pos.getY()); - this.setZ1(pos.getZ()); - } - - public void setX1(int x) - { - this.setX1(new CoordinateInt(x)); - } - - public void setY1(int y) - { - this.setY1(new CoordinateInt(y)); - } - - public void setZ1(int z) - { - this.setZ1(new CoordinateInt(z)); - } - - public void setX1(CoordinateInt x) - { - this.setNode(0, x); - } - - public void setY1(CoordinateInt y) - { - this.setNode(1, y); - } - - public void setZ1(CoordinateInt z) - { - this.setNode(2, z); - } - - @Nonnull - public CoordinateInt getX1Coordiante() - { - return this.getNodeAsCoordinateInt(0); - } - - @Nonnull - public CoordinateInt getY1Coordiante() - { - return this.getNodeAsCoordinateInt(1); - } - - @Nonnull - public CoordinateInt getZ1Coordiante() - { - return this.getNodeAsCoordinateInt(2); - } - - public double getX1() - { - return this.getX1Coordiante().getValue(); - } - - public double getY1() - { - return this.getY1Coordiante().getValue(); - } - - public double getZ1() - { - return this.getZ1Coordiante().getValue(); - } - - public BlockPos getBlockPos1() - { - return new BlockPos(this.getX1(), this.getY1(), this.getZ1()); - } - - public void setPosition2(BlockPos pos) - { - this.setX2(pos.getX()); - this.setY2(pos.getY()); - this.setZ2(pos.getZ()); - } - - public void setX2(int x) - { - this.setX2(new CoordinateInt(x)); - } - - public void setY2(int y) - { - this.setY2(new CoordinateInt(y)); - } - - public void setZ2(int z) - { - this.setZ2(new CoordinateInt(z)); - } - - public void setX2(CoordinateInt x) - { - this.setNode(3, x); - } - - public void setY2(CoordinateInt y) - { - this.setNode(4, y); - } - - public void setZ2(CoordinateInt z) - { - this.setNode(5, z); - } - - @Nonnull - public CoordinateInt getX2Coordiante() - { - return this.getNodeAsCoordinateInt(3); - } - - @Nonnull - public CoordinateInt getY2Coordiante() - { - return this.getNodeAsCoordinateInt(4); - } - - @Nonnull - public CoordinateInt getZ2Coordiante() - { - return this.getNodeAsCoordinateInt(5); - } - - public double getX2() - { - return this.getX2Coordiante().getValue(); - } - - public double getY2() - { - return this.getY2Coordiante().getValue(); - } - - public double getZ2() - { - return this.getZ2Coordiante().getValue(); - } - - public BlockPos getBlockPos2() - { - return new BlockPos(this.getX2(), this.getY2(), this.getZ2()); - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderEnchantment.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderEnchantment.java deleted file mode 100644 index c87f425..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderEnchantment.java +++ /dev/null @@ -1,67 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.enchantment.Enchantment; - -public class BuilderEnchantment extends CommandBuilder -{ - @Nullable - public String getPlayer() - { - return this.getNodeAsString(0); - } - - public void setPlayer(String player) - { - this.setNode(0, player); - } - - @Nullable - public ResourceLocation getEnchantment() - { - return this.getNodeAsResourceLocation(1); - } - - public void setEnchantment(Enchantment enchantment) - { - this.setEnchantment(enchantment.getRegistryName()); - } - - public void setEnchantment(ResourceLocation enchantment) - { - this.setNode(1, enchantment); - } - - public void setLevel(int level) - { - this.setNode(2, level); - } - - public int getLevel() - { - return this.getNodeAsInt(2); - } - - @Override - public String getCommandName() - { - return "enchant"; - } - - @Override - public CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("player", ArgumentType.STRING); - syntax.addRequired("enchantment", ArgumentType.RESOURCE_LOCATION); - syntax.addOptional("level", ArgumentType.INT, 1); - - return syntax; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderEntity.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderEntity.java deleted file mode 100644 index 78215fa..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderEntity.java +++ /dev/null @@ -1,506 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import java.util.List; -import java.util.Random; -import java.util.Set; - -import javax.annotation.Nullable; - -import org.apache.commons.lang3.StringUtils; - -import exopandora.worldhandler.builder.CommandBuilderNBT; -import exopandora.worldhandler.builder.component.impl.EntityNBT; -import exopandora.worldhandler.util.MutableTextComponent; -import exopandora.worldhandler.util.ResourceHelper; -import net.minecraft.client.resources.language.I18n; -import net.minecraft.nbt.ByteTag; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.IntTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.effect.MobEffect; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.ai.attributes.Attribute; -import net.minecraft.world.entity.npc.VillagerProfession; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.Items; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.registries.ForgeRegistries; - -public abstract class BuilderEntity extends CommandBuilderNBT -{ - private final EntityNBT nbt = new EntityNBT(); - - public abstract void setEntity(ResourceLocation entity); - - public abstract ResourceLocation getEntity(); - - public void setName(String name) - { - this.setEntity(BuilderEntity.parseEntityName(name)); - this.updateCustomComponent(name); - } - - public void setNameAndId(String name) - { - this.setName(name); - this.nbt.setId(this.getEntity()); - } - - public void setId(ResourceLocation resource) - { - this.nbt.setId(resource); - } - - public ResourceLocation getId() - { - return this.nbt.getId(); - } - - public void setAttribute(Attribute attribute, double ammount) - { - this.nbt.setAttribute(attribute, ammount); - } - - public void removeAttribute(Attribute attribute) - { - this.nbt.removeAttribute(attribute); - } - - public double getAttributeAmmount(Attribute attribute) - { - return this.nbt.getAttributeAmmount(attribute); - } - - public Set getAttributes() - { - return this.nbt.getAttributes(); - } - - public void setCustomName(String name) - { - this.nbt.setCustomName(name); - } - - @Nullable - public MutableTextComponent getCustomName() - { - return this.nbt.getCustomName(); - } - - public void setPassenger(int index, String name) - { - this.nbt.setPassenger(index, BuilderEntity.parseEntityName(name)); - } - - public void setPassenger(int index, EntityNBT entity) - { - this.nbt.setPassenger(index, entity); - } - - public void setPassenger(int index, ResourceLocation id) - { - this.setPassenger(index, new EntityNBT(id)); - } - - public void addPassenger(EntityNBT entity) - { - this.nbt.addPassenger(entity); - } - - public void addPassenger(int index, EntityNBT entity) - { - this.nbt.addPassenger(index, entity); - } - - public void removePassenger(int index) - { - this.nbt.removePassenger(index); - } - - public int getPassengerCount() - { - return this.nbt.getPassengerCount(); - } - - public List getPassengers() - { - return this.nbt.getPassengers(); - } - - @Nullable - public EntityNBT getPassenger(int index) - { - return this.nbt.getPassenger(index); - } - - public boolean hasPassengers() - { - return this.nbt.hasPassengers(); - } - - public void setArmorItem(int index, Block block) - { - this.nbt.setArmorItem(index, block); - } - - public void setArmorItem(int index, Item item) - { - this.nbt.setArmorItem(index, item); - } - - public void setArmorItem(int index, ResourceLocation location) - { - this.nbt.setArmorItem(index, location); - } - - public void setArmorItems(ResourceLocation[] armor) - { - this.nbt.setArmorItems(armor); - } - - public ResourceLocation getArmorItem(int slot) - { - return this.nbt.getArmorItem(slot); - } - - public void setHandItem(int index, Block block) - { - this.nbt.setHandItem(index, block); - } - - public void setHandItem(int index, Item item) - { - this.nbt.setHandItem(index, item); - } - - public void setHandItem(int index, ResourceLocation location) - { - this.nbt.setHandItem(index, location); - } - - public ResourceLocation getHandItem(int slot) - { - return this.nbt.getHandItem(slot); - } - - public double[] getMotion() - { - return this.nbt.getMotion(); - } - - public void setMotion(double x, double y, double z) - { - this.nbt.setMotion(x, y, z); - } - - public double getMotionX() - { - return this.nbt.getMotionX(); - } - - public double getMotionY() - { - return this.nbt.getMotionY(); - } - - public double getMotionZ() - { - return this.nbt.getMotionZ(); - } - - public void setMotionX(double x) - { - this.nbt.setMotionX(x); - } - - public void setMotionY(double y) - { - this.nbt.setMotionY(y); - } - - public void setMotionZ(double z) - { - this.nbt.setMotionZ(z); - } - - public void setAmplifier(MobEffect potion, byte amplifier) - { - this.nbt.setAmplifier(potion, amplifier); - } - - public void setSeconds(MobEffect potion, int seconds) - { - this.nbt.setSeconds(potion, seconds); - } - - public void setMinutes(MobEffect potion, int minutes) - { - this.nbt.setMinutes(potion, minutes); - } - - public void setHours(MobEffect potion, int hours) - { - this.nbt.setHours(potion, hours); - } - - public void setShowParticles(MobEffect potion, boolean showParticles) - { - this.nbt.setShowParticles(potion, showParticles); - } - - public void setAmbient(MobEffect potion, boolean ambient) - { - this.nbt.setAmbient(potion, ambient); - } - - public byte getAmplifier(MobEffect potion) - { - return this.nbt.getAmplifier(potion); - } - - public int getSeconds(MobEffect potion) - { - return this.nbt.getSeconds(potion); - } - - public int getMinutes(MobEffect potion) - { - return this.nbt.getMinutes(potion); - } - - public int getHours(MobEffect potion) - { - return this.nbt.getHours(potion); - } - - public boolean getShowParticles(MobEffect potion) - { - return this.nbt.getShowParticles(potion); - } - - public boolean getAmbient(MobEffect potion) - { - return this.nbt.getAmbient(potion); - } - - public Set getMobEffects() - { - return this.nbt.getEffects(); - } - - public void setBlockState(BlockState blockState) - { - this.nbt.setBlockState(blockState); - } - - public BlockState getBlockState() - { - return this.nbt.getBlockState(); - } - - public void setTime(int time) - { - this.nbt.setTime(time); - } - - public int getTime() - { - return this.nbt.getTime(); - } - - public void setCommand(String command) - { - this.nbt.setCommand(command); - } - - public String getCommand() - { - return this.nbt.getCommand(); - } - - public void setEntityNBT(String nbt) - { - this.nbt.setNBT(nbt); - } - - public void setEntityNBT(CompoundTag nbt) - { - this.nbt.setNBT(nbt); - } - - public CompoundTag getEntityNBT() - { - return this.nbt.getNBT(); - } - - @Override - protected CompoundTag buildNBT() - { - return this.nbt.serialize(); - } - - private void updateCustomComponent(String name) - { - ResourceLocation entity = this.getEntity(); - - if(name != null && entity != null) - { - if(entity.equals(EntityType.CAT.getRegistryName())) - { - this.nbt.setCustomComponent("CatType", IntTag.valueOf(new Random().nextInt(11))); - } - else if(entity.equals(EntityType.VILLAGER.getRegistryName())) - { - for(VillagerProfession profession : ForgeRegistries.PROFESSIONS) - { - if(StringUtils.equalsIgnoreCase(name, profession.toString())) - { - CompoundTag villagerData = new CompoundTag(); - villagerData.putString("profession", profession.getRegistryName().toString()); - - this.nbt.setCustomComponent("VillagerData", villagerData); - break; - } - } - } - else if(entity.equals(EntityType.ZOMBIE.getRegistryName())) - { - if(StringUtils.containsIgnoreCase(name, "Baby")) - { - this.nbt.setCustomComponent("IsBaby", ByteTag.valueOf((byte) 1)); - } - } - else if(entity.equals(EntityType.CHICKEN.getRegistryName())) - { - if(StringUtils.containsIgnoreCase(name, "Jockey") && !this.nbt.hasPassengers()) - { - ListTag list = new ListTag(); - EntityNBT zombie = new EntityNBT(EntityType.ZOMBIE.getRegistryName()); - - zombie.setIsBaby(true); - list.add(zombie.serialize()); - this.nbt.setCustomComponent("Passengers", list); - } - } - else if(entity.equals(EntityType.SPIDER.getRegistryName())) - { - if(StringUtils.containsIgnoreCase(name, "Jockey") && !this.nbt.hasPassengers()) - { - ListTag list = new ListTag(); - EntityNBT skeleton = new EntityNBT(EntityType.SKELETON.getRegistryName()); - - skeleton.setHandItem(0, Items.BOW); - list.add(skeleton.serialize()); - - this.nbt.setCustomComponent("Passengers", list); - } - } - else - { - this.nbt.resetCustomComponent(); - } - } - else - { - this.nbt.resetCustomComponent(); - } - } - - @Nullable - public static ResourceLocation parseEntityName(String entityName) - { - String name = ResourceHelper.stripToResourceLocation(entityName); - - if(name == null || name.isEmpty()) - { - return null; - } - - for(EntityType type : ForgeRegistries.ENTITIES.getValues()) - { - if(type.canSummon() && entityName.equalsIgnoreCase(I18n.get(type.getDescriptionId()))) - { - return type.getRegistryName(); - } - } - - String entity = name.replaceAll("_", ""); - - if("RedCow".equalsIgnoreCase(entity)) - { - return EntityType.MOOSHROOM.getRegistryName(); - } - else if("ChickenJockey".equalsIgnoreCase(entity)) - { - return EntityType.CHICKEN.getRegistryName(); - } - else if("Pigman".equalsIgnoreCase(entity) || "ZombiePig".equalsIgnoreCase(entity) || "ZombiePigman".equalsIgnoreCase(entity)) - { - return EntityType.PIGLIN.getRegistryName(); - } - else if("Dog".equalsIgnoreCase(entity)) - { - return EntityType.WOLF.getRegistryName(); - } - else if("Dragon".equalsIgnoreCase(entity)) - { - return EntityType.ENDER_DRAGON.getRegistryName(); - } - else if("SnowMan".equalsIgnoreCase(entity)) - { - return EntityType.SNOW_GOLEM.getRegistryName(); - } - else if("LavaCube".equalsIgnoreCase(entity)|| "MagmaSlime".equalsIgnoreCase(entity) || "LavaSlime".equalsIgnoreCase(entity)) - { - return EntityType.MAGMA_CUBE.getRegistryName(); - } - else if("SpiderJockey".equalsIgnoreCase(entity)) - { - return EntityType.SPIDER.getRegistryName(); - } - else if("VillagerGolem".equalsIgnoreCase(entity)) - { - return EntityType.IRON_GOLEM.getRegistryName(); - } - else if("Ozelot".equalsIgnoreCase(entity)) - { - return EntityType.OCELOT.getRegistryName(); - } - else if("Kitty".equalsIgnoreCase(entity) || "Kitten".equalsIgnoreCase(entity)) - { - return EntityType.CAT.getRegistryName(); - } - else if("TESTIFICATE".equalsIgnoreCase(entity) || ForgeRegistries.PROFESSIONS.getKeys().stream().anyMatch(profession -> profession.getPath().equalsIgnoreCase(entity))) - { - return EntityType.VILLAGER.getRegistryName(); - } - else if("Octopus".equalsIgnoreCase(entity) || "Kraken".equalsIgnoreCase(entity)) - { - return EntityType.SQUID.getRegistryName(); - } - else if("Exwife".equalsIgnoreCase(entity)) - { - return EntityType.GHAST.getRegistryName(); - } - else if("CommandMinecart".equalsIgnoreCase(entity)) - { - return EntityType.COMMAND_BLOCK_MINECART.getRegistryName(); - } - else if("Wizard".equalsIgnoreCase(entity)) - { - return EntityType.EVOKER.getRegistryName(); - } - else if("Johnny".equalsIgnoreCase(entity)) - { - return EntityType.VINDICATOR.getRegistryName(); - } - else if("BabyZombie".equalsIgnoreCase(entity)) - { - return EntityType.ZOMBIE.getRegistryName(); - } - - return ResourceHelper.stringToResourceLocation(name); - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderExecute.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderExecute.java deleted file mode 100644 index c98db46..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderExecute.java +++ /dev/null @@ -1,97 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; -import exopandora.worldhandler.util.EnumHelper; - -public class BuilderExecute extends CommandBuilder -{ - public void setMode1(EnumMode mode) - { - this.setNode(0, mode.toString()); - } - - @Nullable - public EnumMode getMode1() - { - return EnumHelper.valueOf(this.getNodeAsString(0), EnumMode.class); - } - - public void setTarget(String target) - { - this.setNode(1, target); - } - - @Nullable - public String getTarget() - { - return this.getNodeAsString(1); - } - - public void setMode2(EnumMode mode) - { - this.setNode(2, mode.toString()); - } - - @Nullable - public EnumMode getMode2() - { - return EnumHelper.valueOf(this.getNodeAsString(2), EnumMode.class); - } - - public void setCommand(String command) - { - if(command != null && command.startsWith("/")) - { - this.setNode(3, command.substring(1)); - } - else - { - this.setNode(3, command); - } - } - - @Nullable - public String getCommand() - { - return this.getNodeAsString(3); - } - - @Override - public String getCommandName() - { - return "execute"; - } - - @Override - public CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("modifier", ArgumentType.STRING); - syntax.addRequired("targets", ArgumentType.STRING); - syntax.addRequired("action", ArgumentType.STRING); - syntax.addRequired("command", ArgumentType.STRING); - - return syntax; - } - - public static enum EnumMode - { - ALIGN, - ANCHORED, - AS, - AT, - IN, - RUN; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderExperience.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderExperience.java deleted file mode 100644 index 07452af..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderExperience.java +++ /dev/null @@ -1,127 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; -import exopandora.worldhandler.util.EnumHelper; - -public class BuilderExperience extends CommandBuilder -{ - public BuilderExperience() - { - this.setLevel(0); - } - - public BuilderExperience(EnumMode mode, int level, String player, EnumUnit unit) - { - this.setMode(mode); - this.setLevel(level); - this.setPlayer(player); - this.setUnit(unit); - } - - public void setMode(EnumMode mode) - { - this.setNode(0, mode.toString()); - } - - @Nullable - public EnumMode getMode() - { - return EnumHelper.valueOf(this.getNodeAsString(0), EnumMode.class); - } - - public void setPlayer(String player) - { - this.setNode(1, player); - } - - @Nullable - public String getPlayer() - { - return this.getNodeAsString(1); - } - - public void setLevel(int level) - { - this.setNode(2, level); - } - - @Nullable - public int getLevel() - { - return this.getNodeAsInt(2); - } - - public void setUnit(EnumUnit unit) - { - this.setNode(3, unit.toString()); - } - - @Nullable - public EnumUnit getUnit() - { - return EnumHelper.valueOf(this.getNodeAsString(3), EnumUnit.class); - } - - @Override - public String getCommandName() - { - return "experience"; - } - - @Override - public CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - 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; - } - - public BuilderExperience buildAdd() - { - return new BuilderExperience(EnumMode.ADD, this.getLevel(), this.getPlayer(), EnumUnit.LEVELS); - } - - public BuilderExperience buildRemove() - { - return new BuilderExperience(EnumMode.ADD, -this.getLevel(), this.getPlayer(), EnumUnit.LEVELS); - } - - public BuilderExperience buildReset() - { - return new BuilderExperience(EnumMode.SET, 0, this.getPlayer(), EnumUnit.LEVELS); - } - - public static enum EnumMode - { - ADD, - SET, - QUERY; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } - - public static enum EnumUnit - { - LEVELS, - POINTS; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderFill.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderFill.java deleted file mode 100644 index dbd8560..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderFill.java +++ /dev/null @@ -1,136 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; -import exopandora.worldhandler.builder.types.BlockResourceLocation; -import exopandora.worldhandler.builder.types.CoordinateInt; -import exopandora.worldhandler.util.BlockHelper; -import exopandora.worldhandler.util.EnumHelper; -import net.minecraft.core.BlockPos; - -public class BuilderFill extends BuilderDoubleBlockPos -{ - public BuilderFill() - { - super(); - } - - public BuilderFill(BlockResourceLocation block1, EnumBlockFilter filter, BlockResourceLocation block2) - { - this(BlockHelper.getPos1(), BlockHelper.getPos2(), block1, filter, block2); - } - - public BuilderFill(BlockPos pos1, BlockPos pos2, BlockResourceLocation block1, EnumBlockFilter handling, BlockResourceLocation block2) - { - this.setPosition1(pos1); - this.setPosition2(pos2); - this.setBlock1(block1); - this.setBlockHandling(handling); - this.setBlock2(block2); - } - - public BuilderFill(CoordinateInt x1, CoordinateInt y1, CoordinateInt z1, CoordinateInt x2, CoordinateInt y2, CoordinateInt z2, BlockResourceLocation block1) - { - this.setX1(x1); - this.setY1(y1); - this.setZ1(z1); - this.setX2(x2); - this.setY2(y2); - this.setZ2(z2); - this.setBlock1(block1); - } - - public void setBlock1(String block) - { - this.setBlock1(BlockResourceLocation.valueOf(block)); - } - - public void setBlock1(BlockResourceLocation resource) - { - this.setNode(6, resource); - } - - @Nullable - public BlockResourceLocation getBlock1() - { - return this.getNodeAsBlockResourceLocation(6); - } - - public void setBlockHandling(EnumBlockFilter filter) - { - this.setNode(7, filter != null ? filter.toString() : null); - } - - public void setBlock2(String block) - { - this.setBlock2(BlockResourceLocation.valueOf(block)); - } - - public void setBlock2(BlockResourceLocation resource) - { - this.setNode(8, resource); - } - - @Nullable - public BlockResourceLocation getBlock2() - { - return this.getNodeAsBlockResourceLocation(8); - } - - @Nullable - public EnumBlockFilter getBlockFilter() - { - return EnumHelper.valueOf(this.getNodeAsString(7), EnumBlockFilter.class); - } - - public BuilderFill build() - { - return new BuilderFill(this.getBlock1(), null, null); - } - - public BuilderFill buildReplace() - { - return new BuilderFill(this.getBlock2(), EnumBlockFilter.REPLACE, this.getBlock1()); - } - - @Override - public String getCommandName() - { - return "fill"; - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - 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; - } - - public static enum EnumBlockFilter - { - REPLACE, - DESTROY, - KEEP, - HOLLOW, - OUTLINE; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGamemode.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderGamemode.java deleted file mode 100644 index fc6f1de..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGamemode.java +++ /dev/null @@ -1,65 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; - -public class BuilderGamemode extends CommandBuilder -{ - public BuilderGamemode() - { - super(); - } - - public BuilderGamemode(EnumGamemode mode) - { - this.setMode(mode); - } - - public BuilderGamemode(EnumGamemode mode, String player) - { - this(mode); - this.setPlayer(player); - } - - public void setMode(EnumGamemode mode) - { - this.setNode(0, mode.toString()); - } - - public void setPlayer(String player) - { - this.setNode(1, player); - } - - @Override - public String getCommandName() - { - return "gamemode"; - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("mode", ArgumentType.STRING); - syntax.addOptional("player", ArgumentType.STRING); - - return syntax; - } - - public static enum EnumGamemode - { - SURVIVAL, - CREATIVE, - ADVENTURE, - SPECTATOR; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGamerule.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderGamerule.java deleted file mode 100644 index a124419..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGamerule.java +++ /dev/null @@ -1,61 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; - -public class BuilderGamerule extends CommandBuilder -{ - public BuilderGamerule() - { - super(); - } - - public BuilderGamerule(String rule, String value) - { - this.setRule(rule); - this.setValue(value); - } - - public void setRule(String rule) - { - this.setNode(0, rule); - } - - public String getRule() - { - return this.getNodeAsString(0); - } - - public void setValue(String value) - { - this.setNode(1, value); - } - - public String getValue() - { - return this.getNodeAsString(1); - } - - public BuilderGamerule build(String value) - { - return new BuilderGamerule(this.getRule(), value); - } - - @Override - public String getCommandName() - { - return "gamerule"; - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addOptional("rule", ArgumentType.STRING); - syntax.addOptional("true|false|value", ArgumentType.STRING); - - return syntax; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGeneric.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderGeneric.java deleted file mode 100644 index e92f897..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGeneric.java +++ /dev/null @@ -1,27 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import exopandora.worldhandler.builder.CommandString; -import exopandora.worldhandler.builder.ICommandBuilder; - -public class BuilderGeneric implements ICommandBuilder -{ - private final String command; - private final String[] arguments; - - public BuilderGeneric(String command, String... arguments) - { - this.command = command; - this.arguments = arguments; - } - - @Override - public String toCommand() - { - return new CommandString(this.command, this.arguments).toString(); - } - - public String toActualCommand() - { - return this.toCommand(); - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGive.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderGive.java deleted file mode 100644 index 5faed92..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGive.java +++ /dev/null @@ -1,105 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.CommandBuilderNBT; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; -import exopandora.worldhandler.builder.types.ItemResourceLocation; -import exopandora.worldhandler.util.ResourceHelper; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.resources.ResourceLocation; -import net.minecraftforge.registries.ForgeRegistries; - -public class BuilderGive extends CommandBuilderNBT -{ - private final ItemResourceLocation itemResourceLocation = new ItemResourceLocation(); - - public BuilderGive() - { - this(null, null); - } - - public BuilderGive(String player, ResourceLocation item) - { - this.setPlayer(player); - this.setItem(item); - this.setCount(1); - } - - public void setPlayer(String username) - { - this.setNode(0, username); - } - - @Nullable - public String getPlayer() - { - return this.getNodeAsString(0); - } - - public void setItem(String item) - { - this.setItem(ResourceHelper.assertRegistered(ResourceHelper.stringToResourceLocation(item), ForgeRegistries.ITEMS)); - } - - public void setItem(ResourceLocation item) - { - this.itemResourceLocation.setResourceLocation(item); - this.setNode(1, this.itemResourceLocation); - } - - @Nullable - public ItemResourceLocation getItem() - { - return this.getNodeAsItemResourceLocation(1); - } - - public void setCount(int count) - { - this.setNode(2, count); - } - - public int getCount() - { - return this.getNodeAsInt(2); - } - - @Override - public void setNBT(CompoundTag nbt) - { - this.itemResourceLocation.setNBT(nbt); - this.setNode(1, this.itemResourceLocation); - } - - @Nullable - public CompoundTag getNBT() - { - ItemResourceLocation item = this.getItem(); - - if(item != null) - { - return item.getNBT(); - } - - return null; - } - - @Override - public String getCommandName() - { - return "give"; - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("player", ArgumentType.STRING); - syntax.addRequired("item", ArgumentType.ITEM_RESOURCE_LOCATION); - syntax.addRequired("count", ArgumentType.INT); - - return syntax; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderMultiCommand.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderMultiCommand.java deleted file mode 100644 index a6f4bba..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderMultiCommand.java +++ /dev/null @@ -1,21 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import java.util.Arrays; - -import exopandora.worldhandler.builder.ICommandBuilder; - -public class BuilderMultiCommand implements ICommandBuilder -{ - private final ICommandBuilder[] builders; - - public BuilderMultiCommand(ICommandBuilder... builders) - { - this.builders = builders; - } - - @Override - public String toCommand() - { - return String.join(" | ", Arrays.stream(this.builders).map(ICommandBuilder::toCommand).toArray(String[]::new)); - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderNoteEditor.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderNoteEditor.java deleted file mode 100644 index 861135d..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderNoteEditor.java +++ /dev/null @@ -1,39 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import net.minecraft.client.Minecraft; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import net.minecraft.world.level.block.state.properties.NoteBlockInstrument; - -public class BuilderNoteEditor extends BuilderSetBlock -{ - public BuilderNoteEditor() - { - this.setBlock(Blocks.NOTE_BLOCK.getRegistryName()); - this.setMode(EnumMode.REPLACE); - } - - public BuilderNoteEditor(int note) - { - this(); - this.setNote(note); - } - - public BuilderNoteEditor(int note, BlockPos pos) - { - this(note); - this.setPosition(pos); - this.setState(BlockStateProperties.NOTEBLOCK_INSTRUMENT, NoteBlockInstrument.byState(Minecraft.getInstance().level.getBlockState(pos.below()))); - } - - public void setNote(int note) - { - this.setState(BlockStateProperties.NOTE, note); - } - - public BuilderNoteEditor build(int note) - { - return new BuilderNoteEditor(note, this.getBlockPos()); - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderPlayer.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderPlayer.java deleted file mode 100644 index 770f409..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderPlayer.java +++ /dev/null @@ -1,44 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; - -public class BuilderPlayer extends CommandBuilder -{ - private final String command; - - public BuilderPlayer(String command) - { - this.command = command; - } - - public void setPlayer(String player) - { - this.setNode(0, player); - } - - @Nullable - public String getPlayer() - { - return this.getNodeAsString(0); - } - - @Override - public String getCommandName() - { - return this.command; - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("player", ArgumentType.STRING); - - return syntax; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderPlayerReason.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderPlayerReason.java deleted file mode 100644 index 55e9e8a..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderPlayerReason.java +++ /dev/null @@ -1,56 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; - -public class BuilderPlayerReason extends CommandBuilder -{ - private final String command; - - public BuilderPlayerReason(String command) - { - this.command = command; - } - - public void setPlayer(String player) - { - this.setNode(0, player); - } - - @Nullable - public String getPlayer() - { - return this.getNodeAsString(0); - } - - public void setReason(String reason) - { - this.setNode(1, reason); - } - - @Nullable - public String getReason() - { - return this.getNodeAsString(1); - } - - @Override - public String getCommandName() - { - return this.command; - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("player", ArgumentType.STRING); - syntax.addOptional("reason", ArgumentType.STRING); - - return syntax; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderPotionEffect.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderPotionEffect.java deleted file mode 100644 index c436f13..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderPotionEffect.java +++ /dev/null @@ -1,197 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.component.impl.EffectNBT; -import exopandora.worldhandler.builder.types.ArgumentType; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.effect.MobEffect; -import net.minecraftforge.registries.ForgeRegistries; - -public class BuilderPotionEffect extends CommandBuilder -{ - private int seconds; - private int minutes; - private int hours; - - public BuilderPotionEffect() - { - this(null, null, null); - } - - public BuilderPotionEffect(EnumMode mode, String player, ResourceLocation effect) - { - this(mode, player, effect, 0, (byte) 0, false); - } - - public BuilderPotionEffect(EnumMode mode, String player, ResourceLocation effect, int duration, byte amplifier, boolean hideParticles) - { - this.setMode(mode); - this.setPlayer(player); - this.setMobEffect(effect); - this.setDuration(duration); - this.setAmplifier(amplifier); - this.setHideParticles(hideParticles); - } - - public void setMode(EnumMode mode) - { - if(mode != null) - { - this.setNode(0, mode.toString()); - } - } - - public void setPlayer(String player) - { - this.setNode(1, player); - } - - @Nullable - public String getPlayer() - { - return this.getNodeAsString(1); - } - - public void setMobEffect(MobEffect effect) - { - this.setMobEffect(effect.getRegistryName()); - } - - public void setMobEffect(ResourceLocation effect) - { - this.setNode(2, effect); - } - - @Nullable - public MobEffect getMobEffectAsPotion() - { - ResourceLocation location = this.getNodeAsResourceLocation(2); - - if(location != null) - { - return ForgeRegistries.MOB_EFFECTS.getValue(location); - } - - return null; - } - - @Nullable - public ResourceLocation getMobEffect() - { - return this.getNodeAsResourceLocation(2); - } - - public void setDuration(int duration) - { - this.setNode(3, Math.min(duration, 1000000)); - } - - public int getDuration() - { - return this.getNodeAsInt(3); - } - - public void setAmplifier(byte amplifier) - { - this.setNode(4, (byte) (amplifier - 1)); - } - - public int getAmplifier() - { - return this.getNodeAsByte(4); - } - - public void setHideParticles(boolean hideParticles) - { - this.setNode(5, hideParticles); - } - - public boolean getHideParticles() - { - return this.getNodeAsBoolean(5); - } - - public int getSeconds() - { - return this.seconds; - } - - public void setSeconds(int seconds) - { - this.seconds = seconds; - this.setDuration(EffectNBT.toSeconds(this.seconds, this.minutes, this.hours)); - } - - public int getMinutes() - { - return this.minutes; - } - - public void setMinutes(int minutes) - { - this.minutes = minutes; - this.setDuration(EffectNBT.toSeconds(this.seconds, this.minutes, this.hours)); - } - - public int getHours() - { - return this.hours; - } - - public void setHours(int hours) - { - this.hours = hours; - this.setDuration(EffectNBT.toSeconds(this.seconds, this.minutes, this.hours)); - } - - public BuilderGeneric buildGive() - { - return new BuilderGeneric(this.getCommandName(), EnumMode.GIVE.toString(), this.getPlayer(), this.getMobEffect().toString(), String.valueOf(this.getDuration()), String.valueOf(this.getAmplifier()), String.valueOf(this.getHideParticles())); - } - - public BuilderGeneric buildRemove() - { - return new BuilderGeneric(this.getCommandName(), EnumMode.CLEAR.toString(), this.getPlayer(), this.getMobEffect().toString()); - } - - public BuilderGeneric buildClear() - { - return new BuilderGeneric(this.getCommandName(), EnumMode.CLEAR.toString(), this.getPlayer()); - } - - @Override - public String getCommandName() - { - return "effect"; - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - 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; - } - - public static enum EnumMode - { - GIVE, - CLEAR; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderPotionItem.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderPotionItem.java deleted file mode 100644 index fcf347d..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderPotionItem.java +++ /dev/null @@ -1,94 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import java.util.Set; - -import exopandora.worldhandler.builder.component.impl.ComponentPotionItem; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.effect.MobEffect; -import net.minecraft.world.item.Item; - -public class BuilderPotionItem extends BuilderGive -{ - private final ComponentPotionItem potion; - - public BuilderPotionItem() - { - this(null, null, new ComponentPotionItem()); - } - - public BuilderPotionItem(ResourceLocation item, String player, ComponentPotionItem potion) - { - super(player, item); - this.potion = this.registerNBTComponent(potion); - } - - public void setAmplifier(MobEffect potion, byte amplifier) - { - this.potion.setAmplifier(potion, amplifier); - } - - public void setSeconds(MobEffect potion, int seconds) - { - this.potion.setSeconds(potion, seconds); - } - - public void setMinutes(MobEffect potion, int minutes) - { - this.potion.setMinutes(potion, minutes); - } - - public void setHours(MobEffect potion, int hours) - { - this.potion.setHours(potion, hours); - } - - public void setShowParticles(MobEffect potion, boolean showParticles) - { - this.potion.setShowParticles(potion, showParticles); - } - - public void setAmbient(MobEffect potion, boolean ambient) - { - this.potion.setAmbient(potion, ambient); - } - - public byte getAmplifier(MobEffect potion) - { - return this.potion.getAmplifier(potion); - } - - public int getSeconds(MobEffect potion) - { - return this.potion.getSeconds(potion); - } - - public int getMinutes(MobEffect potion) - { - return this.potion.getMinutes(potion); - } - - public int getHours(MobEffect potion) - { - return this.potion.getHours(potion); - } - - public boolean getShowParticles(MobEffect potion) - { - return this.potion.getShowParticles(potion); - } - - public boolean getAmbient(MobEffect potion) - { - return this.potion.getAmbient(potion); - } - - public Set getMobEffects() - { - return this.potion.getMobEffects(); - } - - public BuilderPotionItem build(Item item) - { - return new BuilderPotionItem(item.getRegistryName(), this.getPlayer(), this.potion); - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderRecipe.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderRecipe.java deleted file mode 100644 index cb77994..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderRecipe.java +++ /dev/null @@ -1,98 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; -import exopandora.worldhandler.util.EnumHelper; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.crafting.Recipe; - -public class BuilderRecipe extends CommandBuilder -{ - public BuilderRecipe() - { - this(null, null, null); - } - - public BuilderRecipe(EnumMode mode, String player, ResourceLocation recipe) - { - this.setMode(mode); - this.setPlayer(player); - this.setRecipe(recipe); - } - - public void setMode(EnumMode mode) - { - this.setNode(0, mode != null ? mode.toString() : null); - } - - @Nullable - public EnumMode getMode() - { - return EnumHelper.valueOf(this.getNodeAsString(0), EnumMode.class); - } - - public void setPlayer(String player) - { - this.setNode(1, player); - } - - @Nullable - public String getPlayer() - { - return this.getNodeAsString(1); - } - - public void setRecipe(Recipe recipe) - { - this.setRecipe(recipe.getId()); - } - - public void setRecipe(ResourceLocation recipe) - { - this.setNode(2, recipe); - } - - @Nullable - public ResourceLocation getRecipe() - { - return this.getNodeAsResourceLocation(2); - } - - public BuilderRecipe build(EnumMode mode) - { - return new BuilderRecipe(mode, this.getPlayer(), this.getRecipe()); - } - - @Override - public String getCommandName() - { - return "recipe"; - } - - @Override - public CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("give|take", ArgumentType.STRING); - syntax.addOptional("player", ArgumentType.STRING); - syntax.addOptional("recipe", ArgumentType.RESOURCE_LOCATION); - - return syntax; - } - - public static enum EnumMode - { - GIVE, - TAKE; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboard.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboard.java deleted file mode 100644 index 1f1e7f6..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboard.java +++ /dev/null @@ -1,12 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import exopandora.worldhandler.builder.CommandBuilder; - -public abstract class BuilderScoreboard extends CommandBuilder -{ - @Override - public String getCommandName() - { - return "scoreboard"; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardObjectives.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardObjectives.java deleted file mode 100644 index 190252e..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardObjectives.java +++ /dev/null @@ -1,173 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; -import exopandora.worldhandler.builder.types.GreedyString; -import exopandora.worldhandler.util.EnumHelper; - -public class BuilderScoreboardObjectives extends BuilderScoreboard -{ - public BuilderScoreboardObjectives() - { - this.init(); - } - - private void init() - { - this.setNode(0, "objectives"); - } - - public void setMode(EnumMode mode) - { - String objective = this.getObjective(); - - this.updateSyntax(this.getSyntax(mode)); - this.setNode(1, mode.toString()); - - if(objective != null) - { - this.setObjective(objective); - } - - this.init(); - } - - @Nullable - public EnumMode getMode() - { - return EnumHelper.valueOf(this.getNodeAsString(1), EnumMode.class); - } - - public void setObjective(String name) - { - String objective = name != null ? name.replaceAll(" ", "_") : null; - - EnumMode mode = this.getMode(); - - if(mode != null) - { - switch(mode) - { - case ADD: - this.setNode(4, new GreedyString(name)); - case REMOVE: - this.setNode(2, objective); - break; - case SETDISPLAY: - this.setNode(3, objective); - break; - default: - break; - } - } - } - - public void setCriteria(String criteria) - { - if(this.getMode() == null || !this.getMode().equals(EnumMode.ADD)) - { - this.setMode(EnumMode.ADD); - } - - this.setNode(3, criteria); - } - - public void setSlot(String slot) - { - if(this.getMode() == null || !this.getMode().equals(EnumMode.SETDISPLAY)) - { - this.setMode(EnumMode.SETDISPLAY); - } - - this.setNode(2, slot); - } - - @Nullable - public String getSlot() - { - if(this.getMode() != null && this.getMode().equals(EnumMode.SETDISPLAY)) - { - return this.getNodeAsString(2); - } - - return null; - } - - @Nullable - public String getObjective() - { - EnumMode mode = this.getMode(); - - if(mode != null) - { - switch(mode) - { - case ADD: case REMOVE: - return this.getNodeAsString(2); - case SETDISPLAY: - return this.getNodeAsString(3); - default: - break; - } - } - - return null; - } - - @Nullable - private CommandSyntax getSyntax(EnumMode mode) - { - CommandSyntax syntax = new CommandSyntax(); - - switch(mode) - { - case ADD: - 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", ArgumentType.STRING); - syntax.addRequired("remove", ArgumentType.STRING); - syntax.addRequired("name", ArgumentType.STRING); - return syntax; - case SETDISPLAY: - 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; - } - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("objectives", ArgumentType.STRING); - syntax.addRequired("list|add|remove|setdisplay", ArgumentType.STRING); - syntax.addOptional("...", ArgumentType.STRING); - - return syntax; - } - - public static enum EnumMode - { - ADD, - REMOVE, - SETDISPLAY; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardPlayers.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardPlayers.java deleted file mode 100644 index 277375f..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardPlayers.java +++ /dev/null @@ -1,169 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; -import exopandora.worldhandler.util.EnumHelper; - -public class BuilderScoreboardPlayers extends BuilderScoreboard -{ - public BuilderScoreboardPlayers() - { - this.init(); - } - - private void init() - { - this.setNode(0, "players"); - } - - @Nullable - public EnumMode getMode() - { - return EnumHelper.valueOf(this.getNodeAsString(1), EnumMode.class); - } - - public void setMode(String mode) - { - String objective = this.getObjective(); - String player = this.getPlayer(); - int points = this.getPoints(); - - this.updateSyntax(this.getSyntax(mode)); - this.setNode(1, mode); - this.setNode(2, player); - this.setObjective(objective); - - if(!mode.equals("enable")) - { - this.setPoints(points); - } - - this.init(); - } - - public void setPlayer(String player) - { - this.setNode(2, player); - } - - @Nullable - public String getPlayer() - { - return this.getNodeAsString(2); - } - - public void setObjective(String name) - { - if(this.getMode() != null) - { - this.setNode(3, name != null ? name.replaceAll(" ", "_") : null); - } - } - - @Nullable - public String getObjective() - { - if(this.getMode() != null) - { - return this.getNodeAsString(3); - } - - return null; - } - - public void setPoints(int points) - { - this.setNode(4, points); - } - - public int getPoints() - { - EnumMode mode = this.getMode(); - - if(mode != null && !EnumMode.ENABLE.equals(mode)) - { - return this.getNodeAsInt(4); - } - - return 0; - } - - private CommandSyntax getSyntax(String mode) - { - CommandSyntax syntax = new CommandSyntax(); - - if(mode.equals("enable")) - { - 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", 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; - } - - public BuilderScoreboardPlayers buildPoints(EnumMode mode) - { - return this.buildPoints(mode, this.getPoints()); - } - - public BuilderScoreboardPlayers buildPoints(EnumMode mode, int points) - { - BuilderScoreboardPlayers builder = new BuilderScoreboardPlayers(); - - builder.setMode(mode.toString()); - builder.setPlayer(this.getPlayer()); - builder.setObjective(this.getObjective()); - builder.setPoints(points); - - return builder; - } - - public BuilderScoreboardPlayers buildEnable() - { - BuilderScoreboardPlayers builder = new BuilderScoreboardPlayers(); - - builder.setMode(EnumMode.ENABLE.toString()); - builder.setPlayer(this.getPlayer()); - builder.setObjective(this.getObjective()); - - return builder; - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("players", ArgumentType.STRING); - syntax.addRequired("add|enable|get|list|operation|remove|reset|set", ArgumentType.STRING); - syntax.addOptional("...", ArgumentType.STRING); - - return syntax; - } - - public static enum EnumMode - { - ADD, - REMOVE, - ENABLE, - SET; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderSetBlock.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderSetBlock.java deleted file mode 100644 index 2826229..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderSetBlock.java +++ /dev/null @@ -1,105 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; -import exopandora.worldhandler.builder.types.BlockResourceLocation; -import exopandora.worldhandler.builder.types.CoordinateInt; -import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.block.state.properties.Property; - -public class BuilderSetBlock extends BuilderBlockPos -{ - private final BlockResourceLocation blockResourceLocation = new BlockResourceLocation(); - - public BuilderSetBlock() - { - super(0); - } - - public BuilderSetBlock(BlockPos pos, ResourceLocation block, EnumMode mode) - { - this(); - this.setPosition(pos); - this.setBlock(block); - this.setMode(mode); - } - - public > BuilderSetBlock(CoordinateInt x, CoordinateInt y, CoordinateInt z, ResourceLocation block, EnumMode mode) - { - this(); - this.setX(x); - this.setY(y); - this.setZ(z); - this.setBlock(block); - this.setMode(mode); - } - - public > void setState(Property property, T value) - { - this.blockResourceLocation.setProperty(property, value); - this.setBlock(this.blockResourceLocation); - } - - public void setBlock(ResourceLocation block) - { - this.blockResourceLocation.setResourceLocation(block); - this.setBlock(this.blockResourceLocation); - } - - public void setMode(EnumMode mode) - { - this.setNode(4, mode.toString()); - } - - public void setBlockNBT(CompoundTag nbt) - { - this.blockResourceLocation.setNBT(nbt); - this.setBlock(this.blockResourceLocation); - } - - protected void setBlock(BlockResourceLocation block) - { - this.setNode(3, this.blockResourceLocation); - } - - @Override - public void setNBT(CompoundTag nbt) - { - - } - - @Override - public String getCommandName() - { - return "setblock"; - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - 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; - } - - public static enum EnumMode - { - KEEP, - REPLACE, - DESTROY; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderSignEditor.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderSignEditor.java deleted file mode 100644 index 899dbf2..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderSignEditor.java +++ /dev/null @@ -1,73 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.component.impl.ComponentTag; -import exopandora.worldhandler.util.MutableTextComponent; -import exopandora.worldhandler.util.SignText; - -public class BuilderSignEditor extends BuilderData -{ - @SuppressWarnings("unchecked") - private final ComponentTag[] sign = new ComponentTag[4]; - - public BuilderSignEditor() - { - this.setMode(EnumMode.MERGE); - this.setTarget(EnumTarget.BLOCK); - - for(int x = 0; x < 4; x++) - { - this.sign[x] = this.registerNBTComponent(new ComponentTag("Text" + (x + 1), new SignText(), SignText::serialize)); - } - } - - public boolean isSpecial() - { - for(int x = 0; x < this.sign.length; x++) - { - if(this.getColoredString(x).isSpecial()) - { - return true; - } - } - - return false; - } - - @Nullable - public MutableTextComponent getColoredString(int line) - { - if(this.checkBounds(line)) - { - return this.sign[line].getValue(); - } - - return null; - } - - @Nullable - public String getCommand(int line) - { - if(this.checkBounds(line)) - { - return this.sign[line].getValue().getCommand(); - } - - return null; - } - - @Nullable - public void setCommand(int line, String command) - { - if(this.checkBounds(line)) - { - this.sign[line].getValue().setCommand(command); - } - } - - private boolean checkBounds(int line) - { - return line >= 0 && line < this.sign.length; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderSpawnpoint.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderSpawnpoint.java deleted file mode 100644 index 9fffcbc..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderSpawnpoint.java +++ /dev/null @@ -1,56 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; -import exopandora.worldhandler.builder.types.Coordinate.EnumType; -import exopandora.worldhandler.builder.types.CoordinateInt; - -public class BuilderSpawnpoint extends CommandBuilder -{ - public BuilderSpawnpoint() - { - this.setX(new CoordinateInt(EnumType.GLOBAL)); - this.setY(new CoordinateInt(EnumType.GLOBAL)); - this.setZ(new CoordinateInt(EnumType.GLOBAL)); - } - - @Override - public String getCommandName() - { - return "spawnpoint"; - } - - public void setPlayer(String player) - { - this.setNode(0, player); - } - - public void setX(CoordinateInt x) - { - this.setNode(1, x); - } - - public void setY(CoordinateInt y) - { - this.setNode(2, y); - } - - public void setZ(CoordinateInt z) - { - this.setNode(3, z); - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - 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; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderSummon.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderSummon.java deleted file mode 100644 index ea70077..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderSummon.java +++ /dev/null @@ -1,84 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; -import exopandora.worldhandler.builder.types.Coordinate.EnumType; -import exopandora.worldhandler.builder.types.CoordinateDouble; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.resources.ResourceLocation; - -public class BuilderSummon extends BuilderEntity -{ - public BuilderSummon() - { - this.setX(new CoordinateDouble(0.0, EnumType.LOCAL)); - this.setY(new CoordinateDouble(0.0, EnumType.LOCAL)); - this.setZ(new CoordinateDouble(2.0, EnumType.LOCAL)); - } - - public void setEntity(ResourceLocation entity) - { - this.setNode(0, entity); - } - - public ResourceLocation getEntity() - { - return this.getNodeAsResourceLocation(0); - } - - public void setX(CoordinateDouble x) - { - this.setNode(1, x); - } - - public CoordinateDouble getX() - { - return this.getNodeAsCoordinateDouble(1); - } - - public void setY(CoordinateDouble y) - { - this.setNode(2, y); - } - - public CoordinateDouble getY() - { - return this.getNodeAsCoordinateDouble(2); - } - - public void setZ(CoordinateDouble z) - { - this.setNode(3, z); - } - - public CoordinateDouble getZ() - { - return this.getNodeAsCoordinateDouble(3); - } - - @Override - public void setNBT(CompoundTag nbt) - { - this.setNode(4, nbt); - } - - @Override - public String getCommandName() - { - return "summon"; - } - - @Override - public CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - 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; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderTag.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderTag.java deleted file mode 100644 index 9a430cc..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderTag.java +++ /dev/null @@ -1,88 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; - -public class BuilderTag extends CommandBuilder -{ - public BuilderTag() - { - super(); - } - - public BuilderTag(String player, EnumMode mode, String name) - { - this.setPlayer(player); - this.setMode(mode); - this.setName(name); - } - - public void setPlayer(String player) - { - this.setNode(0, player); - } - - @Nullable - public String getPlayer() - { - return this.getNodeAsString(0); - } - - public void setMode(EnumMode mode) - { - if(mode != null) - { - this.setNode(1, mode.toString()); - } - } - - public void setName(String name) - { - this.setNode(2, name); - } - - @Nullable - public String getName() - { - return this.getNodeAsString(2); - } - - @Override - public String getCommandName() - { - return "tag"; - } - - @Override - public CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("player", ArgumentType.STRING); - syntax.addRequired("add|list|remove", ArgumentType.STRING); - syntax.addRequired("name", ArgumentType.STRING); - - return syntax; - } - - public BuilderTag build(EnumMode mode) - { - return new BuilderTag(this.getPlayer(), mode, this.getName()); - } - - public static enum EnumMode - { - ADD, - LIST, - REMOVE; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderTeams.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderTeams.java deleted file mode 100644 index ce71f58..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderTeams.java +++ /dev/null @@ -1,254 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; -import exopandora.worldhandler.builder.types.GreedyString; -import exopandora.worldhandler.util.EnumHelper; - -public class BuilderTeams extends CommandBuilder -{ - public void setTeam(String name) - { - String team = name != null ? name.replaceAll(" ", "_") : null; - - if(EnumMode.ADD.equals(this.getMode())) - { - this.setNode(2, new GreedyString(name)); - } - - this.setNode(1, team); - } - - @Nullable - public EnumMode getMode() - { - return EnumHelper.valueOf(this.getNodeAsString(0), EnumMode.class); - } - - @Nullable - public String getTeam() - { - return this.getNodeAsString(1); - } - - public void setMode(EnumMode mode) - { - String team = this.getTeam(); - String player = this.getPlayer(); - - this.updateSyntax(this.getSyntax(mode)); - this.setNode(0, mode.toString()); - - if(team != null) - { - this.setTeam(team); - } - - if(player != null && (EnumMode.JOIN.equals(mode) || EnumMode.LEAVE.equals(mode) || EnumMode.JOIN_OR_LEAVE.equals(mode))) - { - this.setPlayer(player); - } - } - - public void setPlayer(String player) - { - EnumMode mode = this.getMode(); - - if(EnumMode.JOIN.equals(mode) || EnumMode.LEAVE.equals(mode) || EnumMode.JOIN_OR_LEAVE.equals(mode)) - { - this.setNode(2, player); - } - } - - @Nullable - public String getPlayer() - { - EnumMode mode = this.getMode(); - - if(EnumMode.JOIN.equals(mode) || EnumMode.LEAVE.equals(mode) || EnumMode.JOIN_OR_LEAVE.equals(mode)) - { - return this.getNodeAsString(2); - } - - return null; - } - - public void setRule(String rule) - { - if(!EnumMode.MODIFY.equals(this.getMode())) - { - this.setMode(EnumMode.MODIFY); - } - - this.setNode(2, rule); - } - - @Nullable - public String getRule() - { - EnumMode mode = this.getMode(); - - if(mode == null || EnumMode.MODIFY.equals(mode)) - { - return this.getNodeAsString(2); - } - - return null; - } - - public void setValue(String value) - { - if(!EnumMode.MODIFY.equals(this.getMode())) - { - this.setMode(EnumMode.MODIFY); - } - - this.setNode(3, value); - } - - @Nullable - public String getValue() - { - EnumMode mode = this.getMode(); - - if(mode == null || EnumMode.MODIFY.equals(mode)) - { - return this.getNodeAsString(3); - } - - return null; - } - - @Nullable - private CommandSyntax getSyntax(EnumMode mode) - { - if(EnumMode.ADD.equals(mode)) - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("add", ArgumentType.STRING); - syntax.addRequired("name", ArgumentType.STRING); - syntax.addOptional("display_name...", ArgumentType.GREEDY_STRING); - - return syntax; - } - else if(EnumMode.REMOVE.equals(mode) || EnumMode.EMPTY.equals(mode) || EnumMode.REMOVE_OR_EMPTY.equals(mode)) - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("remove|empty", ArgumentType.STRING, "remove|empty"); - syntax.addRequired("name", ArgumentType.STRING); - - return syntax; - } - else if(EnumMode.JOIN.equals(mode) || EnumMode.LEAVE.equals(mode) || EnumMode.JOIN_OR_LEAVE.equals(mode)) - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("join|leave", ArgumentType.STRING, "join|leave"); - syntax.addRequired("player|team", ArgumentType.STRING); - syntax.addOptional("player", ArgumentType.STRING); - - return syntax; - } - else if(EnumMode.MODIFY.equals(mode)) - { - CommandSyntax syntax = new CommandSyntax(); - - 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; - } - - return null; - } - - public BuilderTeams build(EnumMode mode) - { - BuilderTeams builder = new BuilderTeams(); - - switch(mode) - { - case JOIN_OR_LEAVE: - case JOIN: - builder.setNode(0, mode.toString()); - builder.setTeam(this.getTeam()); - builder.setNode(2, this.getPlayer()); - break; - case LEAVE: - builder.setNode(0, mode.toString()); - builder.setNode(1, this.getPlayer()); - break; - case REMOVE_OR_EMPTY: - case REMOVE: - case EMPTY: - builder.setNode(0, mode.toString()); - builder.setTeam(this.getTeam()); - break; - case ADD: - builder.setMode(mode); - builder.setTeam(this.getTeam()); - break; - case MODIFY: - builder.setMode(mode); - builder.setTeam(this.getTeam()); - builder.setRule(this.getRule()); - builder.setValue(this.getValue()); - break; - default: - break; - } - - return builder; - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("list|add|remove|empty|join|leave|modify", ArgumentType.STRING); - syntax.addOptional("...", ArgumentType.STRING); - - return syntax; - } - - @Override - public String getCommandName() - { - return "team"; - } - - public static enum EnumMode - { - JOIN, - LEAVE, - REMOVE, - EMPTY, - ADD, - MODIFY, - JOIN_OR_LEAVE, - REMOVE_OR_EMPTY; - - @Override - public String toString() - { - if(EnumMode.JOIN_OR_LEAVE.equals(this)) - { - return "join|leave"; - } - else if(EnumMode.REMOVE_OR_EMPTY.equals(this)) - { - return "remove|empty"; - } - - return this.name().toLowerCase(); - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderTime.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderTime.java deleted file mode 100644 index 480998e..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderTime.java +++ /dev/null @@ -1,64 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; - -public class BuilderTime extends CommandBuilder -{ - public BuilderTime() - { - super(); - } - - public BuilderTime(EnumMode mode) - { - this.setMode(mode); - } - - public BuilderTime(EnumMode mode, int value) - { - this(mode); - this.setValue(value); - } - - public void setMode(EnumMode mode) - { - this.setNode(0, mode.toString()); - } - - public void setValue(int value) - { - this.setNode(1, value); - } - - @Override - public String getCommandName() - { - return "time"; - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("set|add|query", ArgumentType.STRING); - syntax.addOptional("value", ArgumentType.INT); - - return syntax; - } - - public static enum EnumMode - { - ADD, - SET, - QUERY; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderTrigger.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderTrigger.java deleted file mode 100644 index 94e429b..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderTrigger.java +++ /dev/null @@ -1,93 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; -import exopandora.worldhandler.util.EnumHelper; - -public class BuilderTrigger extends CommandBuilder -{ - public BuilderTrigger() - { - this.setValue(0); - } - - public BuilderTrigger(String objective, EnumMode mode, int value) - { - this.setObjective(objective); - this.setMode(mode); - this.setValue(value); - } - - public void setObjective(String name) - { - this.setNode(0, name != null ? name.replaceAll(" ", "_") : null); - } - - @Nullable - public String getObjective() - { - return this.getNodeAsString(0); - } - - public void setMode(EnumMode mode) - { - if(mode != null) - { - this.setNode(1, mode.toString()); - } - } - - @Nullable - public EnumMode getMode() - { - return EnumHelper.valueOf(this.getNodeAsString(1), EnumMode.class); - } - - public void setValue(int value) - { - this.setNode(2, value); - } - - public int getValue() - { - return this.getNodeAsInt(2); - } - - @Override - public String getCommandName() - { - return "trigger"; - } - - @Override - public CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("objective", ArgumentType.STRING); - syntax.addRequired("add|set", ArgumentType.STRING); - syntax.addRequired("value", ArgumentType.INT); - - return syntax; - } - - public BuilderTrigger build(EnumMode mode) - { - return new BuilderTrigger(this.getObjective(), mode, this.getValue()); - } - - public static enum EnumMode - { - ADD, - SET; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderUsercontent.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderUsercontent.java deleted file mode 100644 index 5ece890..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderUsercontent.java +++ /dev/null @@ -1,164 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nullable; - -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.CompoundTag; -import net.minecraft.resources.ResourceLocation; - -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.parseOfDefault(object, (String) argument.getDefault())); - break; - case BLOCK_RESOURCE_LOCATION: - this.setNode(index, type.parseOfDefault(object, type.parse((String) argument.getDefault()))); - break; - case BOOLEAN: - this.setNode(index, type.parseOfDefault(object, (Boolean) argument.getDefault())); - break; - case BYTE: - this.setNode(index, type.parseOfDefault(object, ((Double) argument.getDefault()).byteValue())); - break; - case COORDINATE_DOUBLE: - this.setNode(index, type.parseOfDefault(object, type.parse((String) argument.getDefault()))); - break; - case COORDINATE_INT: - this.setNode(index, type.parseOfDefault(object, type.parse((String) argument.getDefault()))); - break; - case DOUBLE: - this.setNode(index, type.parseOfDefault(object, (Double) argument.getDefault())); - break; - case FLOAT: - this.setNode(index, type.parseOfDefault(object, ((Double) argument.getDefault()).floatValue())); - break; - case GREEDY_STRING: - this.setNode(index, type.parseOfDefault(object, type.parse((String) argument.getDefault()))); - break; - case INT: - this.setNode(index, type.parseOfDefault(object, ((Double) argument.getDefault()).intValue())); - break; - case ITEM_RESOURCE_LOCATION: - this.setNode(index, type.parseOfDefault(object, type.parse((String) argument.getDefault()))); - break; - case LONG: - this.setNode(index, type.parseOfDefault(object, ((Double) argument.getDefault()).longValue())); - break; - case NBT: - this.setNode(index, type.parseOfDefault(object, type.parse((String) argument.getDefault()))); - break; - case RESOURCE_LOCATION: - this.setNode(index, type.parseOfDefault(object, type.parse((String) argument.getDefault()))); - break; - case SHORT: - this.setNode(index, type.parseOfDefault(object, ((Double) argument.getDefault()).shortValue())); - break; - case TARGET_SELECTOR: - this.setNode(index, type.parseOfDefault(object, type.parse((String) argument.getDefault()))); - break; - default: - break; - } - } - } - - @Nullable - 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; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWH.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderWH.java deleted file mode 100644 index f428726..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWH.java +++ /dev/null @@ -1,24 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; - -public class BuilderWH extends CommandBuilder -{ - @Override - public String getCommandName() - { - return "wh"; - } - - @Override - public CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("pos1|pos2|fill|replace", ArgumentType.STRING); - - return syntax; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWeather.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderWeather.java deleted file mode 100644 index 6b23ebb..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWeather.java +++ /dev/null @@ -1,64 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; - -public class BuilderWeather extends CommandBuilder -{ - public BuilderWeather() - { - super(); - } - - public BuilderWeather(EnumWeather weather) - { - this.setWeather(weather); - } - - public BuilderWeather(EnumWeather weather, int value) - { - this(weather); - this.setValue(value); - } - - public void setWeather(EnumWeather weather) - { - this.setNode(0, weather.toString()); - } - - public void setValue(int value) - { - this.setNode(1, value); - } - - @Override - public String getCommandName() - { - return "weather"; - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("clear|rain|thunde", ArgumentType.STRING); - syntax.addOptional("duration", ArgumentType.INT); - - return syntax; - } - - public static enum EnumWeather - { - CLEAR, - RAIN, - THUNDER; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWhitelist.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderWhitelist.java deleted file mode 100644 index 10bc18f..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWhitelist.java +++ /dev/null @@ -1,91 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import javax.annotation.Nullable; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; - -public class BuilderWhitelist extends CommandBuilder -{ - public BuilderWhitelist() - { - super(); - } - - public BuilderWhitelist(EnumMode mode) - { - this.setMode(mode); - } - - public BuilderWhitelist(EnumMode mode, String player) - { - this(mode); - this.setPlayer(player); - } - - public void setMode(EnumMode mode) - { - this.setNode(0, mode.toString()); - } - - public void setPlayer(String player) - { - this.setNode(1, player); - } - - @Nullable - public String getPlayer() - { - return this.getNodeAsString(1); - } - - @Override - public String getCommandName() - { - return "whitelist"; - } - - @Nullable - public BuilderWhitelist build(EnumMode mode) - { - switch(mode) - { - case ADD: - case REMOVE: - return new BuilderWhitelist(mode, this.getPlayer()); - case RELOAD: - case ON: - case OFF: - return new BuilderWhitelist(mode); - default: - return null; - } - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("add|remove|reload|on|off", ArgumentType.STRING); - syntax.addOptional("player", ArgumentType.STRING); - - return syntax; - } - - public static enum EnumMode - { - ADD, - REMOVE, - RELOAD, - ON, - OFF; - - @Override - public String toString() - { - return this.name().toLowerCase(); - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWorldHandler.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderWorldHandler.java deleted file mode 100644 index 6d2a3fa..0000000 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWorldHandler.java +++ /dev/null @@ -1,24 +0,0 @@ -package exopandora.worldhandler.builder.impl; - -import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.CommandSyntax; -import exopandora.worldhandler.builder.types.ArgumentType; - -public class BuilderWorldHandler extends CommandBuilder -{ - @Override - public String getCommandName() - { - return "worldhandler"; - } - - @Override - public final CommandSyntax getSyntax() - { - CommandSyntax syntax = new CommandSyntax(); - - syntax.addRequired("help|display|version", ArgumentType.STRING); - - return syntax; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/types/ArgumentType.java b/src/main/java/exopandora/worldhandler/builder/types/ArgumentType.java deleted file mode 100644 index 3978ee8..0000000 --- a/src/main/java/exopandora/worldhandler/builder/types/ArgumentType.java +++ /dev/null @@ -1,82 +0,0 @@ -package exopandora.worldhandler.builder.types; - -import java.util.function.Function; - -import javax.annotation.Nullable; - -import com.mojang.brigadier.exceptions.CommandSyntaxException; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.TagParser; -import net.minecraft.resources.ResourceLocation; - -public enum ArgumentType -{ - SHORT(Short::valueOf), - BYTE(Byte::valueOf), - INT(Integer::valueOf), - FLOAT(Float::valueOf), - DOUBLE(Double::valueOf), - LONG(Long::valueOf), - BOOLEAN(Boolean::valueOf), - STRING(String::valueOf), - GREEDY_STRING(GreedyString::valueOf), - RESOURCE_LOCATION(ArgumentType::parseResourceLocation), - ITEM_RESOURCE_LOCATION(ItemResourceLocation::valueOf), - BLOCK_RESOURCE_LOCATION(BlockResourceLocation::valueOf), - NBT(ArgumentType::parseCompoundNBT), - COORDINATE_INT(CoordinateInt::valueOf), - COORDINATE_DOUBLE(CoordinateDouble::valueOf), - TARGET_SELECTOR(TargetSelector::valueOf), - PLAYER(String::valueOf); - - private final Function parser; - - private ArgumentType(Function parser) - { - this.parser = parser; - } - - @Nullable - @SuppressWarnings("unchecked") - public T parse(String object) - { - return (T) this.parser.apply(object); - } - - public T parseOfDefault(String object, T def) - { - try - { - return this.parse(object); - } - catch(Exception e) - { - return def; - } - } - - @Nullable - public static ResourceLocation parseResourceLocation(String value) - { - return value != null && !value.isEmpty() ? new ResourceLocation(value) : null; - } - - @Nullable - public static CompoundTag parseCompoundNBT(String value) - { - if(value != null) - { - try - { - return TagParser.parseTag(value); - } - catch(CommandSyntaxException e) - { - return null; - } - } - - return null; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/types/BlockResourceLocation.java b/src/main/java/exopandora/worldhandler/builder/types/BlockResourceLocation.java deleted file mode 100644 index 7f80dad..0000000 --- a/src/main/java/exopandora/worldhandler/builder/types/BlockResourceLocation.java +++ /dev/null @@ -1,125 +0,0 @@ -package exopandora.worldhandler.builder.types; - -import javax.annotation.Nullable; - -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.exceptions.CommandSyntaxException; - -import net.minecraft.commands.arguments.blocks.BlockStateParser; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.properties.Property; -import net.minecraftforge.registries.ForgeRegistries; - -public class BlockResourceLocation extends ItemResourceLocation -{ - private BlockState state; - - public BlockResourceLocation() - { - this(null); - } - - public BlockResourceLocation(ResourceLocation resource) - { - this(resource, null, null); - } - - public BlockResourceLocation(ResourceLocation resource, BlockState state, CompoundTag nbt) - { - super(resource, nbt); - this.state = this.findState(state, resource); - } - - private BlockState findState(BlockState state, ResourceLocation resource) - { - boolean matchOld = this.state != null && this.state.getBlock().getRegistryName().equals(resource); - boolean matchNew = state != null && state.getBlock().getRegistryName().equals(resource); - - if(matchNew) - { - return state; - } - - if(matchOld) - { - return this.state; - } - - if(resource != null && ForgeRegistries.BLOCKS.containsKey(resource)) - { - return ForgeRegistries.BLOCKS.getValue(resource).defaultBlockState(); - } - - return null; - } - - @Override - public void setResourceLocation(ResourceLocation resource) - { - super.setResourceLocation(resource); - this.state = this.findState(null, resource); - } - - @Nullable - public BlockState getState() - { - return this.state; - } - - public > void setProperty(Property property, T value) - { - if(this.state != null && this.state.hasProperty(property)) - { - this.state = this.state.setValue(property, value); - } - } - - @Nullable - public static BlockResourceLocation valueOf(String input) - { - if(input != null) - { - BlockStateParser parser = new BlockStateParser(new StringReader(input), false); - - try - { - parser.parse(true); - } - catch(CommandSyntaxException e) - { - return null; - } - - BlockState state = parser.getState(); - - if(state != null) - { - return new BlockResourceLocation(state.getBlock().getRegistryName(), state, parser.getNbt()); - } - } - - return null; - } - - @Override - public String toString() - { - if(this.resource != null && this.state != null) - { - StringBuilder builder = new StringBuilder(this.state.toString()); - String block = this.state.getBlock().toString(); - builder.replace(0, block.length(), this.resource.toString()); - - if(this.nbt != null) - { - builder.append(this.nbt.toString()); - } - - return builder.toString(); - } - - return null; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/types/Coordinate.java b/src/main/java/exopandora/worldhandler/builder/types/Coordinate.java deleted file mode 100644 index 98e486c..0000000 --- a/src/main/java/exopandora/worldhandler/builder/types/Coordinate.java +++ /dev/null @@ -1,105 +0,0 @@ -package exopandora.worldhandler.builder.types; - -import java.util.function.Function; - -public abstract class Coordinate implements ICoordinate -{ - protected T value; - protected EnumType type; - - public Coordinate(T value) - { - this(value, EnumType.ABSOLUTE); - } - - public Coordinate(T value, EnumType type) - { - this.value = value; - this.type = type; - } - - public void setValue(T value) - { - this.value = value; - } - - public T getValue() - { - return this.value; - } - - public void setType(EnumType type) - { - this.type = type; - } - - public EnumType getType() - { - return this.type; - } - - @Override - public String toString() - { - return this.type.format(this.value, this.zero()); - } - - public static > U parse(U coordiante, String input, Function parser) - { - for(EnumType type : EnumType.values()) - { - if(!type.prefix.isEmpty() && input.startsWith(type.prefix)) - { - String numbers = input.substring(type.prefix.length()); - - coordiante.setType(type); - coordiante.setValue(numbers.isEmpty() ? coordiante.zero() : parser.apply(numbers)); - - return coordiante; - } - } - - coordiante.setType(EnumType.ABSOLUTE); - coordiante.setValue(parser.apply(input)); - - return coordiante; - } - - public static enum EnumType - { - /** - * Prefix: None - */ - ABSOLUTE(""), - /** - * Prefix: "~" - */ - GLOBAL("~"), - /** - * Prefix: "^" - */ - LOCAL("^"); - - private final String prefix; - - private EnumType(String prefix) - { - this.prefix = prefix; - } - - public String format(T value, T zero) - { - if(value == null || value.equals(zero)) - { - if(this.prefix.isEmpty()) - { - return zero.toString(); - } - - return this.prefix; - } - - return this.prefix + value; - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/types/CoordinateDouble.java b/src/main/java/exopandora/worldhandler/builder/types/CoordinateDouble.java deleted file mode 100644 index 762fcb8..0000000 --- a/src/main/java/exopandora/worldhandler/builder/types/CoordinateDouble.java +++ /dev/null @@ -1,35 +0,0 @@ -package exopandora.worldhandler.builder.types; - -public class CoordinateDouble extends Coordinate -{ - public CoordinateDouble() - { - super(0.0); - } - - public CoordinateDouble(Double value) - { - super(value); - } - - public CoordinateDouble(EnumType type) - { - super(0.0, type); - } - - public CoordinateDouble(Double value, EnumType type) - { - super(value, type); - } - - public static CoordinateDouble valueOf(String value) - { - return Coordinate.parse(new CoordinateDouble(), value, Double::parseDouble); - } - - @Override - public Double zero() - { - return 0.0; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/types/CoordinateInt.java b/src/main/java/exopandora/worldhandler/builder/types/CoordinateInt.java deleted file mode 100644 index 2ef86de..0000000 --- a/src/main/java/exopandora/worldhandler/builder/types/CoordinateInt.java +++ /dev/null @@ -1,35 +0,0 @@ -package exopandora.worldhandler.builder.types; - -public class CoordinateInt extends Coordinate -{ - public CoordinateInt() - { - super(0); - } - - public CoordinateInt(Integer value) - { - super(value); - } - - public CoordinateInt(EnumType type) - { - super(0, type); - } - - public CoordinateInt(Integer value, EnumType type) - { - super(value, type); - } - - public static CoordinateInt valueOf(String value) - { - return Coordinate.parse(new CoordinateInt(), value, Integer::parseInt); - } - - @Override - public Integer zero() - { - return 0; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/types/GreedyString.java b/src/main/java/exopandora/worldhandler/builder/types/GreedyString.java deleted file mode 100644 index 99a4e1d..0000000 --- a/src/main/java/exopandora/worldhandler/builder/types/GreedyString.java +++ /dev/null @@ -1,50 +0,0 @@ -package exopandora.worldhandler.builder.types; - -import javax.annotation.Nullable; - -public class GreedyString -{ - private String string; - - public GreedyString(String string) - { - this.string = string; - } - - public String getString() - { - return this.string; - } - - public void setString(String string) - { - this.string = string; - } - - public boolean isEmpty() - { - if(this.string == null) - { - return true; - } - - return this.string.isEmpty(); - } - - @Nullable - public static GreedyString valueOf(String string) - { - if(string != null && string.matches("\"(.*)\"")) - { - return new GreedyString(string.substring(1, string.length() - 1)); - } - - return null; - } - - @Override - public String toString() - { - return "\"" + this.string + "\""; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/types/ICoordinate.java b/src/main/java/exopandora/worldhandler/builder/types/ICoordinate.java deleted file mode 100644 index 85fe1aa..0000000 --- a/src/main/java/exopandora/worldhandler/builder/types/ICoordinate.java +++ /dev/null @@ -1,6 +0,0 @@ -package exopandora.worldhandler.builder.types; - -public interface ICoordinate -{ - T zero(); -} diff --git a/src/main/java/exopandora/worldhandler/builder/types/ItemResourceLocation.java b/src/main/java/exopandora/worldhandler/builder/types/ItemResourceLocation.java deleted file mode 100644 index 4c87acb..0000000 --- a/src/main/java/exopandora/worldhandler/builder/types/ItemResourceLocation.java +++ /dev/null @@ -1,91 +0,0 @@ -package exopandora.worldhandler.builder.types; - -import javax.annotation.Nullable; - -import com.mojang.brigadier.exceptions.CommandSyntaxException; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.TagParser; -import net.minecraft.resources.ResourceLocation; - -public class ItemResourceLocation -{ - protected ResourceLocation resource; - protected CompoundTag nbt; - - public ItemResourceLocation() - { - this(null, null); - } - - public ItemResourceLocation(ResourceLocation resource) - { - this(resource, null); - } - - public ItemResourceLocation(ResourceLocation resource, CompoundTag nbt) - { - this.resource = resource; - this.nbt = nbt; - } - - public ResourceLocation getResourceLocation() - { - return this.resource; - } - - public void setResourceLocation(ResourceLocation resource) - { - this.resource = resource; - } - - public CompoundTag getNBT() - { - return this.nbt; - } - - public void setNBT(CompoundTag nbt) - { - this.nbt = nbt; - } - - @Nullable - public static ItemResourceLocation valueOf(String input) - { - int start = input.indexOf("{"); - ResourceLocation resource = new ResourceLocation(input.substring(0, start)); - CompoundTag nbt = null; - - if(start > 0) - { - try - { - nbt = TagParser.parseTag(input.substring(start, input.lastIndexOf("}") + 1)); - } - catch(CommandSyntaxException e) - { - return null; - } - } - - return new ItemResourceLocation(resource, nbt); - } - - @Override - public String toString() - { - if(this.resource != null) - { - StringBuilder builder = new StringBuilder(this.resource.toString()); - - if(this.nbt != null) - { - builder.append(this.nbt.toString()); - } - - return builder.toString(); - } - - return null; - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/types/TargetSelector.java b/src/main/java/exopandora/worldhandler/builder/types/TargetSelector.java deleted file mode 100644 index ce7b7d8..0000000 --- a/src/main/java/exopandora/worldhandler/builder/types/TargetSelector.java +++ /dev/null @@ -1,58 +0,0 @@ -package exopandora.worldhandler.builder.types; - -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Collectors; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -public class TargetSelector -{ - private final Map values = new HashMap(); - private static final String REGEX = "@e\\[(.*)\\]"; - - public void set(String id, Object value) - { - this.values.put(id.toLowerCase(), value); - } - - @Nullable - @SuppressWarnings("unchecked") - public T get(String id) - { - return (T) this.values.get(id); - } - - public Object remove(String id) - { - return this.values.remove(id.toLowerCase()); - } - - @Nonnull - public static TargetSelector valueOf(String input) - { - if(input.matches(REGEX)); - { - TargetSelector result = new TargetSelector(); - - for(String keys : input.replaceFirst(REGEX, "$1").split(",")) - { - String[] pair = keys.split("="); - - if(pair.length > 1) - { - result.set(pair[0], pair[1]); - } - } - } - - return new TargetSelector(); - } - - @Override - public String toString() - { - return "@e[" + String.join(",", this.values.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue().toString()).collect(Collectors.toList())) + "]"; - } -} diff --git a/src/main/java/exopandora/worldhandler/command/CommandWH.java b/src/main/java/exopandora/worldhandler/command/CommandWH.java index 6f6364a..2c80d88 100644 --- a/src/main/java/exopandora/worldhandler/command/CommandWH.java +++ b/src/main/java/exopandora/worldhandler/command/CommandWH.java @@ -1,34 +1,28 @@ package exopandora.worldhandler.command; -import java.util.concurrent.CompletableFuture; +import java.util.List; + +import javax.annotation.Nullable; import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.context.ParsedCommandNode; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.suggestion.Suggestions; -import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import exopandora.worldhandler.builder.impl.BuilderClone; -import exopandora.worldhandler.builder.impl.BuilderClone.EnumMask; -import exopandora.worldhandler.builder.impl.BuilderFill; -import exopandora.worldhandler.builder.impl.BuilderFill.EnumBlockFilter; -import exopandora.worldhandler.builder.types.BlockResourceLocation; +import exopandora.worldhandler.builder.argument.Coordinate; +import exopandora.worldhandler.builder.argument.Coordinate.Type; +import exopandora.worldhandler.builder.impl.CloneCommandBuilder; +import exopandora.worldhandler.builder.impl.FillCommandBuilder; import exopandora.worldhandler.util.BlockHelper; import exopandora.worldhandler.util.CommandHelper; -import exopandora.worldhandler.util.EnumHelper; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.blocks.BlockInput; import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; import net.minecraft.commands.arguments.blocks.BlockStateArgument; -import net.minecraft.commands.arguments.blocks.BlockStateParser; import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; -import net.minecraftforge.fml.DistExecutor.SafeRunnable; import net.minecraftforge.registries.ForgeRegistries; public class CommandWH @@ -47,34 +41,28 @@ public class CommandWH .then(Commands.literal("replace") .requires(source -> source.hasPermission(2)) .then(Commands.argument("block", BlockStateArgument.block()) - .then(Commands.argument("replace", BlockStateArgument.block()) - .executes(context -> replace(context.getSource(), BlockStateArgument.getBlock(context, "block"), BlockStateArgument.getBlock(context, "replace")))))) + .then(Commands.argument("filter", BlockPredicateArgument.blockPredicate()) + .executes(context -> replace(context.getSource(), BlockStateArgument.getBlock(context, "block"), getCommandNode("filter", context.getNodes()).getRange().get(context.getInput())))))) .then(Commands.literal("clone") .requires(source -> source.hasPermission(2)) - .executes(context -> clone(context.getSource(), "masked")) + .executes(context -> clone(context.getSource(), "masked", null)) .then(Commands.literal("filtered") - .then(Commands.argument("filter", StringBlockPredicateArgument.blockPredicate()) - .executes(context -> clone(context.getSource(), "filter", StringBlockPredicateArgument.getBlockPredicate(context, "filter"))))) + .then(Commands.argument("filter", BlockPredicateArgument.blockPredicate()) + .executes(context -> clone(context.getSource(), "filter", getCommandNode("filter", context.getNodes()).getRange().get(context.getInput()))))) .then(Commands.literal("masked") - .executes(context -> clone(context.getSource(), "masked"))) + .executes(context -> clone(context.getSource(), "masked", null))) .then(Commands.literal("replace") - .executes(context -> clone(context.getSource(), "replace"))))); + .executes(context -> clone(context.getSource(), "replace", null))))); } private static int pos1(CommandSourceStack source) throws CommandSyntaxException { - DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> new SafeRunnable() + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { - private static final long serialVersionUID = 818420798194963795L; - - @Override - public void run() - { - BlockHelper.setPos1(BlockHelper.getFocusedBlockPos()); - BlockPos pos = BlockHelper.getPos1(); - ResourceLocation block = ForgeRegistries.BLOCKS.getKey(BlockHelper.getBlock(pos)); - CommandHelper.sendFeedback(source, "Set first position to " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ() + " (" + block + ")"); - } + BlockHelper.pos1().set(BlockHelper.getFocusedBlockPos()); + BlockPos pos = BlockHelper.pos1(); + ResourceLocation block = ForgeRegistries.BLOCKS.getKey(BlockHelper.getBlock(pos)); + CommandHelper.sendFeedback(source, "Set first position to " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ() + " (" + block + ")"); }); return 1; @@ -82,18 +70,12 @@ public class CommandWH private static int pos2(CommandSourceStack source) throws CommandSyntaxException { - DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> new SafeRunnable() + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { - private static final long serialVersionUID = 5436684018502529063L; - - @Override - public void run() - { - BlockHelper.setPos2(BlockHelper.getFocusedBlockPos()); - BlockPos pos = BlockHelper.getPos2(); - ResourceLocation block = ForgeRegistries.BLOCKS.getKey(BlockHelper.getBlock(pos)); - CommandHelper.sendFeedback(source, "Set second position to " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ() + " (" + block + ")"); - } + BlockHelper.pos2().set(BlockHelper.getFocusedBlockPos()); + BlockPos pos = BlockHelper.pos2(); + ResourceLocation block = ForgeRegistries.BLOCKS.getKey(BlockHelper.getBlock(pos)); + CommandHelper.sendFeedback(source, "Set second position to " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ() + " (" + block + ")"); }); return 1; @@ -101,39 +83,28 @@ public class CommandWH private static int fill(CommandSourceStack source, BlockInput block) { - DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> new SafeRunnable() + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { - private static final long serialVersionUID = 7622739284160142817L; - - @Override - public void run() - { - BuilderFill builder = new BuilderFill(); - builder.setBlock1(new BlockResourceLocation(block.getState().getBlock().getRegistryName(), block.getState(), block.tag)); - CommandHelper.sendCommand(source.getTextName(), builder); - } + FillCommandBuilder builder = new FillCommandBuilder(); + builder.from().set(BlockHelper.pos1()); + builder.to().set(BlockHelper.pos2()); + builder.block().set(block.getState(), block.tag); + CommandHelper.sendCommand(source.getTextName(), builder, FillCommandBuilder.Label.FILL); }); return 1; } - private static int replace(CommandSourceStack source, BlockInput block, BlockInput replace) + private static int replace(CommandSourceStack source, BlockInput block, String filter) { - DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> new SafeRunnable() + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { - private static final long serialVersionUID = -5007303344454187200L; - - @Override - public void run() - { - BuilderFill builder = new BuilderFill(); - builder.setPosition1(BlockHelper.getPos1()); - builder.setPosition2(BlockHelper.getPos2()); - builder.setBlockHandling(EnumBlockFilter.REPLACE); - builder.setBlock1(new BlockResourceLocation(replace.getState().getBlock().getRegistryName(), replace.getState(), replace.tag)); - builder.setBlock2(new BlockResourceLocation(block.getState().getBlock().getRegistryName(), block.getState(), block.tag)); - CommandHelper.sendCommand(source.getTextName(), builder); - } + FillCommandBuilder builder = new FillCommandBuilder(); + builder.from().set(BlockHelper.pos1()); + builder.to().set(BlockHelper.pos2()); + builder.block().set(block.getState(), block.tag); + builder.filter().deserialize(filter); + CommandHelper.sendCommand(source.getTextName(), builder, FillCommandBuilder.Label.REPLACE); }); return 1; @@ -141,74 +112,44 @@ public class CommandWH private static int clone(CommandSourceStack source, String mask, String filter) { - DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> new SafeRunnable() + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { - private static final long serialVersionUID = -2849956095821394079L; + CloneCommandBuilder builder = new CloneCommandBuilder(); + builder.begin().set(BlockHelper.pos1()); + builder.end().set(BlockHelper.pos2()); + builder.destination().setX(new Coordinate.Ints(Type.RELATIVE)); + builder.destination().setY(new Coordinate.Ints(Type.RELATIVE)); + builder.destination().setZ(new Coordinate.Ints(Type.RELATIVE)); - @Override - public void run() + switch(mask) { - BuilderClone builder = new BuilderClone(); - builder.setPosition1(BlockHelper.getPos1()); - builder.setPosition2(BlockHelper.getPos2()); - builder.setMask(EnumHelper.valueOf(mask, EnumMask.class)); - builder.setFilter(filter); - CommandHelper.sendCommand(source.getTextName(), builder); + case "filtered": + builder.filter().deserialize(filter); + CommandHelper.sendCommand(source.getTextName(), builder, CloneCommandBuilder.Label.FILTERED); + break; + case "masked": + CommandHelper.sendCommand(source.getTextName(), builder, CloneCommandBuilder.Label.MASKED); + break; + case "replace": + CommandHelper.sendCommand(source.getTextName(), builder, CloneCommandBuilder.Label.REPLACE); + break; } }); return 1; } - private static int clone(CommandSourceStack source, String mask) + @Nullable + private static ParsedCommandNode getCommandNode(String name, List> nodes) { - DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> new SafeRunnable() + for(ParsedCommandNode node : nodes) { - private static final long serialVersionUID = -7349335271543407747L; - - @Override - public void run() + if(name.equals(node.getNode().getName())) { - BuilderClone builder = new BuilderClone(); - builder.setPosition1(BlockHelper.getPos1()); - builder.setPosition2(BlockHelper.getPos2()); - builder.setMask(EnumHelper.valueOf(mask, EnumMask.class)); - CommandHelper.sendCommand(source.getTextName(), builder); + return node; } - }); - - return 1; - } - - public static class StringBlockPredicateArgument implements ArgumentType - { - public static StringBlockPredicateArgument blockPredicate() - { - return new StringBlockPredicateArgument(); } - @Override - public String parse(StringReader reader) throws CommandSyntaxException - { - BlockStateParser blockstateparser = new BlockStateParser(reader, true).parse(true); - - if(blockstateparser.getState() != null) - { - return new BlockResourceLocation(blockstateparser.getState().getBlock().getRegistryName(), blockstateparser.getState(), blockstateparser.getNbt()).toString(); - } - - return "#" + blockstateparser.getTag(); - } - - public static String getBlockPredicate(CommandContext context, String name) throws CommandSyntaxException - { - return context.getArgument(name, String.class); - } - - @Override - public CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder) - { - return BlockPredicateArgument.blockPredicate().listSuggestions(context, builder); - } + return null; } } diff --git a/src/main/java/exopandora/worldhandler/command/CommandWorldHandler.java b/src/main/java/exopandora/worldhandler/command/CommandWorldHandler.java index f2586fb..8c5a5f5 100644 --- a/src/main/java/exopandora/worldhandler/command/CommandWorldHandler.java +++ b/src/main/java/exopandora/worldhandler/command/CommandWorldHandler.java @@ -13,7 +13,6 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; -import net.minecraftforge.fml.DistExecutor.SafeRunnable; import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.VersionChecker; @@ -40,17 +39,7 @@ public class CommandWorldHandler private static int display(CommandSourceStack source) throws CommandSyntaxException { - DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> new SafeRunnable() - { - private static final long serialVersionUID = 210782927512442500L; - - @Override - public void run() - { - Minecraft.getInstance().execute(ActionHelper::displayGui); - } - }); - + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> Minecraft.getInstance().execute(ActionHelper::displayGui)); return 1; } diff --git a/src/main/java/exopandora/worldhandler/config/ConfigCategorySettings.java b/src/main/java/exopandora/worldhandler/config/ConfigCategorySettings.java index 9277d79..c941e52 100644 --- a/src/main/java/exopandora/worldhandler/config/ConfigCategorySettings.java +++ b/src/main/java/exopandora/worldhandler/config/ConfigCategorySettings.java @@ -1,7 +1,7 @@ package exopandora.worldhandler.config; -import exopandora.worldhandler.builder.impl.BuilderSetBlock.EnumMode; import exopandora.worldhandler.event.KeyHandler; +import exopandora.worldhandler.util.BlockPlacingMode; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.ForgeConfigSpec.BooleanValue; import net.minecraftforge.common.ForgeConfigSpec.ConfigValue; @@ -23,7 +23,7 @@ public class ConfigCategorySettings private final IntValue noon; private final IntValue sunset; private final IntValue midnight; - private final ConfigValue blockPlacingMode; + private final ConfigValue blockPlacingMode; public ConfigCategorySettings(ForgeConfigSpec.Builder builder) { @@ -90,7 +90,7 @@ public class ConfigCategorySettings this.blockPlacingMode = builder .translation("gui.worldhandler.config.settings.block_placing_mode") .comment("Block placing mode (keep, replace, destroy)") - .defineEnum("block_placing_mode", EnumMode.KEEP, EnumMode.values()); + .defineEnum("block_placing_mode", BlockPlacingMode.KEEP, BlockPlacingMode.values()); builder.pop(); } @@ -242,12 +242,12 @@ public class ConfigCategorySettings Config.set(this.midnight, ticks); } - public EnumMode getBlockPlacingMode() + public BlockPlacingMode getBlockPlacingMode() { return this.blockPlacingMode.get(); } - public void setBlockPlacingMode(EnumMode mode) + public void setBlockPlacingMode(BlockPlacingMode mode) { Config.set(this.blockPlacingMode, mode); } diff --git a/src/main/java/exopandora/worldhandler/event/ClientEventHandler.java b/src/main/java/exopandora/worldhandler/event/ClientEventHandler.java index bad9808..a5bf845 100644 --- a/src/main/java/exopandora/worldhandler/event/ClientEventHandler.java +++ b/src/main/java/exopandora/worldhandler/event/ClientEventHandler.java @@ -10,6 +10,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import exopandora.worldhandler.config.Config; import exopandora.worldhandler.util.BlockHelper; import exopandora.worldhandler.util.CommandHelper; +import exopandora.worldhandler.util.RenderUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.MultiBufferSource.BufferSource; @@ -18,31 +19,31 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import net.minecraftforge.client.event.ClientChatEvent; -import net.minecraftforge.client.event.RenderWorldLastEvent; +import net.minecraftforge.client.event.RenderLevelLastEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; public class ClientEventHandler { @SubscribeEvent - public static void renderWorldLastEvent(RenderWorldLastEvent event) + public static void renderLevelLastEvent(RenderLevelLastEvent event) { if(Config.getSettings().highlightBlocks() && Minecraft.getInstance().level != null && Minecraft.getInstance().getEntityRenderDispatcher().camera != null) { Vec3 projected = Minecraft.getInstance().getEntityRenderDispatcher().camera.getPosition(); - double minX = Math.min(BlockHelper.getPos1().getX(), BlockHelper.getPos2().getX()); - double minY = Math.min(BlockHelper.getPos1().getY(), BlockHelper.getPos2().getY()); - double minZ = Math.min(BlockHelper.getPos1().getZ(), BlockHelper.getPos2().getZ()); + double minX = Math.min(BlockHelper.pos1().getX(), BlockHelper.pos2().getX()) - RenderUtils.EPS; + double minY = Math.min(BlockHelper.pos1().getY(), BlockHelper.pos2().getY()) - RenderUtils.EPS; + double minZ = Math.min(BlockHelper.pos1().getZ(), BlockHelper.pos2().getZ()) - RenderUtils.EPS; - double maxX = Math.max(BlockHelper.getPos1().getX(), BlockHelper.getPos2().getX()) + 1; - double maxY = Math.max(BlockHelper.getPos1().getY(), BlockHelper.getPos2().getY()) + 1; - double maxZ = Math.max(BlockHelper.getPos1().getZ(), BlockHelper.getPos2().getZ()) + 1; + double maxX = Math.max(BlockHelper.pos1().getX(), BlockHelper.pos2().getX()) + 1 + RenderUtils.EPS; + double maxY = Math.max(BlockHelper.pos1().getY(), BlockHelper.pos2().getY()) + 1 + RenderUtils.EPS; + double maxZ = Math.max(BlockHelper.pos1().getZ(), BlockHelper.pos2().getZ()) + 1 + RenderUtils.EPS; AABB aabb = new AABB(minX, minY, minZ, maxX, maxY, maxZ); if(aabb.getCenter().distanceTo(projected) < 96) { - PoseStack matrix = event.getMatrixStack(); + PoseStack matrix = event.getPoseStack(); matrix.pushPose(); matrix.translate(-projected.x(), -projected.y(), -projected.z()); @@ -54,29 +55,6 @@ public class ClientEventHandler buffer.endBatch(RenderType.lines()); buffer.endBatch(); -// try -// { -// Field transparencyChain = WorldRenderer.class.getDeclaredField("transparencyChain"); -// transparencyChain.setAccessible(true); -// ShaderGroup shader = (ShaderGroup) transparencyChain.get(event.getContext()); -// -// if(shader != null) -// { -// Field ITEM_ENTITY_TARGET = RenderState.class.getDeclaredField("ITEM_ENTITY_TARGET"); -// ITEM_ENTITY_TARGET.setAccessible(true); -// RenderState.TargetState target = (RenderState.TargetState) ITEM_ENTITY_TARGET.get(null); -// target.setupRenderState(); -// event.getContext().getItemEntityTarget().framebufferClear(Minecraft.IS_RUNNING_ON_MAC); -// event.getContext().getItemEntityTarget().copyDepthFrom(Minecraft.getInstance().getFramebuffer()); -// Minecraft.getInstance().getFramebuffer().bindFramebuffer(false); -// target.clearRenderState(); -// } -// } -// catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) -// { -// e.printStackTrace(); -// } - matrix.popPose(); } } diff --git a/src/main/java/exopandora/worldhandler/event/KeyHandler.java b/src/main/java/exopandora/worldhandler/event/KeyHandler.java index 24411df..fadc99b 100644 --- a/src/main/java/exopandora/worldhandler/event/KeyHandler.java +++ b/src/main/java/exopandora/worldhandler/event/KeyHandler.java @@ -8,9 +8,9 @@ import exopandora.worldhandler.util.ActionHelper; import exopandora.worldhandler.util.BlockHelper; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; +import net.minecraftforge.client.ClientRegistry; import net.minecraftforge.client.event.InputEvent.KeyInputEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fmlclient.registry.ClientRegistry; public class KeyHandler { @@ -29,11 +29,11 @@ public class KeyHandler } else if(Config.getSettings().shortcutKeys() && KEY_WORLD_HANDLER_POS1.isDown()) { - BlockHelper.setPos1(BlockHelper.getFocusedBlockPos()); + BlockHelper.pos1().set(BlockHelper.getFocusedBlockPos()); } else if(Config.getSettings().shortcutKeys() && KEY_WORLD_HANDLER_POS2.isDown()) { - BlockHelper.setPos2(BlockHelper.getFocusedBlockPos()); + BlockHelper.pos2().set(BlockHelper.getFocusedBlockPos()); } } } diff --git a/src/main/java/exopandora/worldhandler/gui/container/Container.java b/src/main/java/exopandora/worldhandler/gui/container/Container.java index 83b6369..a6f8d05 100644 --- a/src/main/java/exopandora/worldhandler/gui/container/Container.java +++ b/src/main/java/exopandora/worldhandler/gui/container/Container.java @@ -3,8 +3,8 @@ package exopandora.worldhandler.gui.container; import java.util.ArrayList; import java.util.List; -import exopandora.worldhandler.gui.menu.IMenu; -import exopandora.worldhandler.gui.menu.Menu; +import exopandora.worldhandler.gui.widget.menu.IMenu; +import exopandora.worldhandler.gui.widget.menu.Menu; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.components.Widget; diff --git a/src/main/java/exopandora/worldhandler/gui/container/IContainer.java b/src/main/java/exopandora/worldhandler/gui/container/IContainer.java index e90d458..0e2524a 100644 --- a/src/main/java/exopandora/worldhandler/gui/container/IContainer.java +++ b/src/main/java/exopandora/worldhandler/gui/container/IContainer.java @@ -1,7 +1,7 @@ package exopandora.worldhandler.gui.container; import exopandora.worldhandler.gui.content.Content; -import exopandora.worldhandler.gui.menu.Menu; +import exopandora.worldhandler.gui.widget.menu.Menu; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.Widget; import net.minecraft.client.gui.components.events.GuiEventListener; diff --git a/src/main/java/exopandora/worldhandler/gui/container/impl/GuiWorldHandler.java b/src/main/java/exopandora/worldhandler/gui/container/impl/GuiWorldHandler.java index 5946fda..adc88c7 100644 --- a/src/main/java/exopandora/worldhandler/gui/container/impl/GuiWorldHandler.java +++ b/src/main/java/exopandora/worldhandler/gui/container/impl/GuiWorldHandler.java @@ -11,7 +11,6 @@ import exopandora.worldhandler.config.Config; import exopandora.worldhandler.event.KeyHandler; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.content.Content; -import exopandora.worldhandler.gui.menu.IMenu; import exopandora.worldhandler.gui.widget.IContainerWidget; import exopandora.worldhandler.gui.widget.IContainerWidget.EnumLayer; import exopandora.worldhandler.gui.widget.WidgetCommandSyntax; @@ -20,6 +19,7 @@ import exopandora.worldhandler.gui.widget.WidgetShortcuts; import exopandora.worldhandler.gui.widget.WidgetTabRenderer; import exopandora.worldhandler.gui.widget.WidgetWatch; import exopandora.worldhandler.gui.widget.button.GuiButtonTooltip; +import exopandora.worldhandler.gui.widget.menu.IMenu; import exopandora.worldhandler.util.ActionHelper; import exopandora.worldhandler.util.RenderUtils; import exopandora.worldhandler.util.ResourceHelper; diff --git a/src/main/java/exopandora/worldhandler/gui/content/IContent.java b/src/main/java/exopandora/worldhandler/gui/content/IContent.java index b0088c6..ef315a6 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/IContent.java +++ b/src/main/java/exopandora/worldhandler/gui/content/IContent.java @@ -1,5 +1,10 @@ package exopandora.worldhandler.gui.content; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -24,7 +29,7 @@ public interface IContent extends IWidget } @Nullable - default ICommandBuilder getCommandBuilder() + default CommandPreview getCommandPreview() { return null; } @@ -33,4 +38,44 @@ public interface IContent extends IWidget { } + + public static class CommandPreview + { + private final List builders = new ArrayList(); + + public CommandPreview() + { + super(); + } + + public CommandPreview(ICommandBuilder builder, Object label) + { + this.add(builder, label); + } + + public CommandPreview add(ICommandBuilder builder, Object label) + { + this.builders.add(new Entry(builder, label)); + return this; + } + + @Override + public String toString() + { + if(this.builders.isEmpty()) + { + return null; + } + + return this.builders.stream().map(entry -> entry.builder().toCommand(entry.label(), true)).collect(Collectors.joining(" | ")); + } + + private record Entry(ICommandBuilder builder, Object label) + { + public Entry + { + Objects.requireNonNull(builder); + } + } + } } diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentAdvancements.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentAdvancements.java index 273d7d8..f6bc6d1 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentAdvancements.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentAdvancements.java @@ -4,21 +4,19 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.impl.BuilderAdvancement; -import exopandora.worldhandler.builder.impl.BuilderAdvancement.EnumActionType; -import exopandora.worldhandler.builder.impl.BuilderAdvancement.EnumMode; +import exopandora.worldhandler.builder.impl.AdvancementCommandBuilder; +import exopandora.worldhandler.builder.impl.AdvancementCommandBuilder.Label; 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.gui.menu.impl.ILogicMapped; -import exopandora.worldhandler.gui.menu.impl.ILogicPageList; -import exopandora.worldhandler.gui.menu.impl.MenuPageList; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; import exopandora.worldhandler.gui.widget.button.GuiButtonList; import exopandora.worldhandler.gui.widget.button.GuiButtonTooltip; +import exopandora.worldhandler.gui.widget.menu.impl.ILogicMapped; +import exopandora.worldhandler.gui.widget.menu.impl.ILogicPageList; +import exopandora.worldhandler.gui.widget.menu.impl.MenuPageList; import exopandora.worldhandler.util.ActionHandler; import exopandora.worldhandler.util.ActionHelper; import exopandora.worldhandler.util.AdvancementHelper; @@ -31,13 +29,16 @@ import net.minecraft.network.chat.TranslatableComponent; public class ContentAdvancements extends Content { - private final BuilderAdvancement builderAdvancement = new BuilderAdvancement(EnumMode.values()[0]); - private final List modes = Arrays.stream(EnumMode.values()).filter(mode -> !mode.equals(EnumMode.EVERYTHING)).collect(Collectors.toList()); + private final AdvancementCommandBuilder builderAdvancement = new AdvancementCommandBuilder(); + private Mode mode = Mode.ONLY; @Override - public ICommandBuilder getCommandBuilder() + public CommandPreview getCommandPreview() { - return this.builderAdvancement; + CommandPreview preview = new CommandPreview() + .add(this.builderAdvancement, this.mode.getGrant()) + .add(this.builderAdvancement, this.mode.getRevoke()); + return preview; } @Override @@ -64,7 +65,7 @@ public class ContentAdvancements extends Content @Override public void onClick(Advancement item) { - ContentAdvancements.this.builderAdvancement.setAdvancement(item.getId()); + ContentAdvancements.this.builderAdvancement.advancement().set(item.getId()); container.initButtons(); } @@ -90,24 +91,24 @@ public class ContentAdvancements extends Content container.add(new GuiButtonBase(x, y + 96, 114, 20, new TranslatableComponent("gui.worldhandler.generic.back"), () -> ActionHelper.back(this))); container.add(new GuiButtonBase(x + 118, y + 96, 114, 20, new TranslatableComponent("gui.worldhandler.generic.backToGame"), ActionHelper::backToGame)); - container.add(new GuiButtonList(x + 118, y, this.modes, 114, 20, container, new ILogicMapped() + container.add(new GuiButtonList(x + 118, y, Arrays.asList(Mode.values()), 114, 20, container, new ILogicMapped() { @Override - public MutableComponent translate(EnumMode item) + public MutableComponent translate(Mode mode) { - return new TranslatableComponent("gui.worldhandler.advancements." + item.toString()); + return new TranslatableComponent("gui.worldhandler.advancements." + mode.toString()); } @Override - public MutableComponent toTooltip(EnumMode item) + public MutableComponent toTooltip(Mode mode) { - return new TextComponent(item.toString()); + return new TextComponent(mode.toString()); } @Override - public void onClick(EnumMode item) + public void onClick(Mode mode) { - ContentAdvancements.this.builderAdvancement.setMode(item); + ContentAdvancements.this.mode = mode; } @Override @@ -119,15 +120,15 @@ public class ContentAdvancements extends Content container.add(new GuiButtonBase(x + 118, y + 24, 114, 20, new TranslatableComponent("gui.worldhandler.advancements.grant"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderAdvancement.build(EnumActionType.GRANT)); + CommandHelper.sendCommand(container.getPlayer(), this.builderAdvancement, this.mode.getGrant()); })); container.add(new GuiButtonBase(x + 118, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.advancements.revoke"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderAdvancement.build(EnumActionType.REVOKE)); + CommandHelper.sendCommand(container.getPlayer(), this.builderAdvancement, this.mode.getRevoke()); })); container.add(new GuiButtonBase(x + 118, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.actions.reset").withStyle(ChatFormatting.RED), () -> { - ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderAdvancement.build(EnumActionType.REVOKE, EnumMode.EVERYTHING))); + ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderAdvancement, AdvancementCommandBuilder.Label.REVOKE_EVERYTHING)); })); } @@ -158,6 +159,39 @@ public class ContentAdvancements extends Content @Override public void onPlayerNameChanged(String username) { - this.builderAdvancement.setPlayer(username); + this.builderAdvancement.targets().setTarget(username); + } + + private static enum Mode + { + ONLY(AdvancementCommandBuilder.Label.GRANT_ONLY, AdvancementCommandBuilder.Label.REVOKE_ONLY), + UNTIL(AdvancementCommandBuilder.Label.GRANT_UNTIL, AdvancementCommandBuilder.Label.REVOKE_UNTIL), + FROM(AdvancementCommandBuilder.Label.GRANT_FROM, AdvancementCommandBuilder.Label.REVOKE_FROM), + THROUGH(AdvancementCommandBuilder.Label.GRANT_THROUGH, AdvancementCommandBuilder.Label.REVOKE_THROUGH); + + private final AdvancementCommandBuilder.Label grant; + private final AdvancementCommandBuilder.Label revoke; + + private Mode(Label grant, Label revoke) + { + this.grant = grant; + this.revoke = revoke; + } + + public AdvancementCommandBuilder.Label getGrant() + { + return this.grant; + } + + public AdvancementCommandBuilder.Label getRevoke() + { + return this.revoke; + } + + @Override + public String toString() + { + return this.name().toLowerCase(); + } } } diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcher.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcher.java index abc7242..e975439 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcher.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcher.java @@ -7,8 +7,8 @@ import java.util.stream.Collectors; import com.google.common.base.Predicates; import com.mojang.blaze3d.vertex.PoseStack; -import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.impl.BuilderButcher; +import exopandora.worldhandler.builder.argument.TargetArgument.SelectorTypes; +import exopandora.worldhandler.builder.impl.KillCommandBuilder; import exopandora.worldhandler.config.Config; import exopandora.worldhandler.gui.category.Categories; import exopandora.worldhandler.gui.category.Category; @@ -33,12 +33,13 @@ public class ContentButcher extends Content { private GuiTextFieldTooltip radiusField; private String radius; - private final BuilderButcher builderButcher = new BuilderButcher(); + private final KillCommandBuilder builderKill = new KillCommandBuilder(); + private final CommandPreview preview = new CommandPreview(this.builderKill, KillCommandBuilder.Label.KILL_TARGETS); @Override - public ICommandBuilder getCommandBuilder() + public CommandPreview getCommandPreview() { - return this.builderButcher; + return this.preview; } @Override @@ -73,11 +74,11 @@ public class ContentButcher extends Content if(!this.radius.isEmpty()) { - this.builderButcher.setDistance(Integer.valueOf(this.radius)); + this.builderKill.targets().setDistance(Double.valueOf(this.radius)); } else { - this.builderButcher.setDistance(0); + this.builderKill.targets().setDistance(0D); } container.initButtons(); @@ -102,18 +103,19 @@ public class ContentButcher extends Content container.add(slaughter = new GuiButtonBase(x + 58, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.butcher.slaughter"), () -> { - ContentButcher.slaughter(container.getPlayer(), Config.getButcher().getEntities().stream().map(ForgeRegistries.ENTITIES::getValue).filter(Predicates.notNull()).collect(Collectors.toList()), Integer.parseInt(this.radius)); + Collection> entities = Config.getButcher().getEntities().stream().map(ForgeRegistries.ENTITIES::getValue).filter(Predicates.notNull()).collect(Collectors.toList()); + ContentButcher.slaughter(container.getPlayer(), entities, Integer.parseInt(this.radius)); })); slaughter.active = enabled && !Config.getButcher().getEntities().isEmpty(); container.add(slaughter = new GuiButtonBase(x + 58, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.butcher.presets"), () -> { - ActionHelper.open(Contents.BUTCHER_PRESETS.withBuilder(this.builderButcher).withRadius(Integer.parseInt(this.radius))); + ActionHelper.open(Contents.BUTCHER_PRESETS.withBuilder(this.builderKill, KillCommandBuilder.Label.KILL_TARGETS).withRadius(Double.parseDouble(this.radius))); })); slaughter.active = enabled; } - public static void slaughter(String username, Collection> entities, int radius) + public static void slaughter(String username, Collection> entities, double radius) { Player player = Minecraft.getInstance().player; Level level = Minecraft.getInstance().level; @@ -129,7 +131,11 @@ public class ContentButcher extends Content if(!targets.isEmpty()) { - CommandHelper.sendCommand(username, new BuilderButcher(entity.getRegistryName(), radius)); + KillCommandBuilder kill = new KillCommandBuilder(); + kill.targets().setSelectorType(SelectorTypes.ALL_ENTITIES); + kill.targets().setType(entity.getRegistryName()); + kill.targets().setDistanceMax(radius); + CommandHelper.sendCommand(username, kill, KillCommandBuilder.Label.KILL_TARGETS); } } } diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcherPresets.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcherPresets.java index 614cf8a..71f59b0 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcherPresets.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcherPresets.java @@ -13,25 +13,25 @@ import net.minecraftforge.registries.ForgeRegistries; public class ContentButcherPresets extends ContentChild { - private ICommandBuilder builder; - private int radius; + private CommandPreview preview; + private double radius; - public ContentButcherPresets withBuilder(ICommandBuilder builder) + public ContentButcherPresets withBuilder(ICommandBuilder builder, Object label) { - this.builder = builder; + this.preview = new CommandPreview(builder, label); return this; } - public ContentButcherPresets withRadius(int radius) + public ContentButcherPresets withRadius(double radius) { this.radius = radius; return this; } @Override - public ICommandBuilder getCommandBuilder() + public CommandPreview getCommandPreview() { - return this.builder; + return this.preview; } @Override diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcherSettings.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcherSettings.java index e052284..049fc73 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcherSettings.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcherSettings.java @@ -5,10 +5,10 @@ import java.util.stream.Collectors; import exopandora.worldhandler.config.Config; import exopandora.worldhandler.gui.container.Container; -import exopandora.worldhandler.gui.menu.impl.ILogicPageList; -import exopandora.worldhandler.gui.menu.impl.MenuPageList; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; import exopandora.worldhandler.gui.widget.button.GuiButtonTooltip; +import exopandora.worldhandler.gui.widget.menu.impl.ILogicPageList; +import exopandora.worldhandler.gui.widget.menu.impl.MenuPageList; import exopandora.worldhandler.util.ActionHandler; import exopandora.worldhandler.util.ActionHelper; import net.minecraft.network.chat.MutableComponent; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentCommandStack.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentCommandStack.java index 0422d82..15cc1b0 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentCommandStack.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentCommandStack.java @@ -10,17 +10,13 @@ import javax.annotation.Nullable; import com.google.common.base.Predicates; import com.mojang.blaze3d.vertex.PoseStack; -import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.component.impl.EntityNBT; -import exopandora.worldhandler.builder.impl.BuilderButcher; -import exopandora.worldhandler.builder.impl.BuilderFill; -import exopandora.worldhandler.builder.impl.BuilderSetBlock; -import exopandora.worldhandler.builder.impl.BuilderSetBlock.EnumMode; -import exopandora.worldhandler.builder.impl.BuilderSummon; -import exopandora.worldhandler.builder.types.BlockResourceLocation; -import exopandora.worldhandler.builder.types.Coordinate.EnumType; -import exopandora.worldhandler.builder.types.CoordinateDouble; -import exopandora.worldhandler.builder.types.CoordinateInt; +import exopandora.worldhandler.builder.argument.Coordinate; +import exopandora.worldhandler.builder.argument.TargetArgument.SelectorTypes; +import exopandora.worldhandler.builder.argument.tag.EntityTag; +import exopandora.worldhandler.builder.impl.FillCommandBuilder; +import exopandora.worldhandler.builder.impl.KillCommandBuilder; +import exopandora.worldhandler.builder.impl.SetBlockCommandBuilder; +import exopandora.worldhandler.builder.impl.SummonCommandBuilder; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.widget.button.EnumIcon; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; @@ -48,43 +44,63 @@ public class ContentCommandStack extends ContentChild private int scroll; private GuiButtonBase buttonCopy; - private final BuilderSummon builderCommandStack = new BuilderSummon(); - + private final SummonCommandBuilder builderCommandStack = new SummonCommandBuilder(); + private final CommandPreview preview = new CommandPreview(this.builderCommandStack, SummonCommandBuilder.Label.SUMMON_POS_NBT); + private final EntityTag activatorRail = new EntityTag(); + public ContentCommandStack() { - this.builderCommandStack.setEntity(EntityType.FALLING_BLOCK.getRegistryName()); - this.builderCommandStack.setX(new CoordinateDouble(0.0D, EnumType.GLOBAL)); - this.builderCommandStack.setY(new CoordinateDouble(0.5D, EnumType.GLOBAL)); - this.builderCommandStack.setZ(new CoordinateDouble(0.0D, EnumType.GLOBAL)); - this.builderCommandStack.setMotion(0.0D, 0.315D, 0.0D); - this.builderCommandStack.setTime(1); - this.builderCommandStack.setBlockState(Blocks.ACTIVATOR_RAIL.defaultBlockState()); + this.builderCommandStack.entity().set(EntityType.FALLING_BLOCK); + this.builderCommandStack.pos().setX(new Coordinate.Doubles(Coordinate.Type.RELATIVE)); + this.builderCommandStack.pos().setY(new Coordinate.Doubles(0.5, Coordinate.Type.RELATIVE)); + this.builderCommandStack.pos().setZ(new Coordinate.Doubles(Coordinate.Type.RELATIVE)); - EntityNBT redstoneBlock = new EntityNBT(EntityType.FALLING_BLOCK.getRegistryName()); + this.activatorRail.setMotion(0.0D, 0.315D, 0.0D); + this.activatorRail.setTime(1); + this.activatorRail.setBlockState(Blocks.ACTIVATOR_RAIL.defaultBlockState()); + this.builderCommandStack.nbt().addTagProvider(this.activatorRail); + + EntityTag redstoneBlock = new EntityTag(EntityType.FALLING_BLOCK.getRegistryName()); redstoneBlock.setTime(1); redstoneBlock.setBlockState(Blocks.REDSTONE_BLOCK.defaultBlockState()); - this.builderCommandStack.addPassenger(redstoneBlock); + this.activatorRail.addPassenger(redstoneBlock); this.addCommand(0); - EntityNBT blockRemover = new EntityNBT(EntityType.COMMAND_BLOCK_MINECART.getRegistryName()); - BuilderSetBlock builder = new BuilderSetBlock(new CoordinateInt(EnumType.GLOBAL), new CoordinateInt(-2, EnumType.GLOBAL), new CoordinateInt(EnumType.GLOBAL), Blocks.REPEATING_COMMAND_BLOCK.getRegistryName(), EnumMode.DESTROY); + EntityTag blockRemover = new EntityTag(EntityType.COMMAND_BLOCK_MINECART.getRegistryName()); + SetBlockCommandBuilder builder = new SetBlockCommandBuilder(); + builder.pos().setX(new Coordinate.Ints(Coordinate.Type.RELATIVE)); + builder.pos().setY(new Coordinate.Ints(-2, Coordinate.Type.RELATIVE)); + builder.pos().setZ(new Coordinate.Ints(Coordinate.Type.RELATIVE)); + builder.block().set(Blocks.REPEATING_COMMAND_BLOCK); CompoundTag commandBlock = new CompoundTag(); commandBlock.putByte("auto", (byte) 1); - commandBlock.putString("Command", new BuilderFill(new CoordinateInt(EnumType.GLOBAL), new CoordinateInt(EnumType.GLOBAL), new CoordinateInt(EnumType.GLOBAL), new CoordinateInt(EnumType.GLOBAL), new CoordinateInt(2, EnumType.GLOBAL), new CoordinateInt(EnumType.GLOBAL), new BlockResourceLocation(Blocks.AIR.getRegistryName())).toActualCommand()); - builder.setBlockNBT(commandBlock); - blockRemover.setCommand(builder.toActualCommand()); - this.builderCommandStack.addPassenger(blockRemover); + FillCommandBuilder fill = new FillCommandBuilder(); + fill.from().setX(new Coordinate.Ints(Coordinate.Type.RELATIVE)); + fill.from().setY(new Coordinate.Ints(Coordinate.Type.RELATIVE)); + fill.from().setZ(new Coordinate.Ints(Coordinate.Type.RELATIVE)); + fill.to().setX(new Coordinate.Ints(Coordinate.Type.RELATIVE)); + fill.to().setY(new Coordinate.Ints(2, Coordinate.Type.RELATIVE)); + fill.to().setZ(new Coordinate.Ints(Coordinate.Type.RELATIVE)); + fill.block().set(Blocks.AIR); + commandBlock.putString("Command", fill.toCommand(FillCommandBuilder.Label.FILL, false)); + builder.block().setTag(commandBlock); + blockRemover.setCommand(builder.toCommand(SetBlockCommandBuilder.Label.DESTROY, false)); + this.activatorRail.addPassenger(blockRemover); - EntityNBT entityRemover = new EntityNBT(EntityType.COMMAND_BLOCK_MINECART.getRegistryName()); - entityRemover.setCommand(new BuilderButcher(EntityType.COMMAND_BLOCK_MINECART.getRegistryName(), 1).toActualCommand()); - this.builderCommandStack.addPassenger(entityRemover); + EntityTag entityRemover = new EntityTag(EntityType.COMMAND_BLOCK_MINECART.getRegistryName()); + KillCommandBuilder kill = new KillCommandBuilder(); + kill.targets().setSelectorType(SelectorTypes.ALL_ENTITIES); + kill.targets().setType(EntityType.COMMAND_BLOCK_MINECART.getRegistryName()); + kill.targets().setDistanceMax(1.0D); + entityRemover.setCommand(kill.toCommand(KillCommandBuilder.Label.KILL_TARGETS, false)); + this.activatorRail.addPassenger(entityRemover); } @Override - public ICommandBuilder getCommandBuilder() + public CommandPreview getCommandPreview() { - return this.builderCommandStack; + return this.preview; } @Override @@ -166,7 +182,7 @@ public class ContentCommandStack extends ContentChild container.add(this.buttonCopy = new GuiButtonBase(x, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.command_stack.copy_command"), () -> { - Minecraft.getInstance().keyboardHandler.setClipboard(this.builderCommandStack.toActualCommand()); + Minecraft.getInstance().keyboardHandler.setClipboard(this.builderCommandStack.toCommand(SummonCommandBuilder.Label.SUMMON_POS_NBT, false)); })); container.add(buttonScrollUp = new GuiButtonIcon(x + 118, y + 72, 56, 20, EnumIcon.ARROW_UP, new TranslatableComponent("gui.worldhandler.actions.move_up"), () -> { @@ -239,7 +255,7 @@ public class ContentCommandStack extends ContentChild private void setCommand(int index, String command) { - EntityNBT entity = this.builderCommandStack.getPassenger(index + HEAD_LENGTH); + EntityTag entity = this.activatorRail.getPassenger(index + HEAD_LENGTH); if(entity != null) { @@ -249,18 +265,18 @@ public class ContentCommandStack extends ContentChild private void addCommand(int index) { - this.builderCommandStack.addPassenger(index + HEAD_LENGTH, new EntityNBT(EntityType.COMMAND_BLOCK_MINECART.getRegistryName())); + this.activatorRail.addPassenger(index + HEAD_LENGTH, new EntityTag(EntityType.COMMAND_BLOCK_MINECART.getRegistryName())); } private void removeCommand(int index) { - this.builderCommandStack.removePassenger(index + HEAD_LENGTH); + this.activatorRail.removePassenger(index + HEAD_LENGTH); } @Nullable private String getCommand(int index) { - EntityNBT entity = this.builderCommandStack.getPassenger(index + HEAD_LENGTH); + EntityTag entity = this.activatorRail.getPassenger(index + HEAD_LENGTH); if(entity != null) { @@ -272,12 +288,12 @@ public class ContentCommandStack extends ContentChild private int getCommandCount() { - return this.builderCommandStack.getPassengerCount() - HEAD_LENGTH - TAIL_LENGTH; + return this.activatorRail.getPassengerCount() - HEAD_LENGTH - TAIL_LENGTH; } private void swapCommands(int i, int j) { - Collections.swap(this.builderCommandStack.getPassengers(), i + HEAD_LENGTH, j + HEAD_LENGTH); + Collections.swap(this.activatorRail.getPassengers(), i + HEAD_LENGTH, j + HEAD_LENGTH); } @Override diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentContainers.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentContainers.java index cadcc6d..6984685 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentContainers.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentContainers.java @@ -1,9 +1,8 @@ package exopandora.worldhandler.gui.content.impl; -import exopandora.worldhandler.builder.impl.BuilderGive; -import exopandora.worldhandler.builder.impl.BuilderSetBlock; -import exopandora.worldhandler.builder.types.Coordinate.EnumType; -import exopandora.worldhandler.builder.types.CoordinateInt; +import exopandora.worldhandler.builder.argument.Coordinate; +import exopandora.worldhandler.builder.impl.GiveCommandBuilder; +import exopandora.worldhandler.builder.impl.SetBlockCommandBuilder; import exopandora.worldhandler.config.Config; import exopandora.worldhandler.gui.category.Categories; import exopandora.worldhandler.gui.category.Category; @@ -18,7 +17,9 @@ import exopandora.worldhandler.util.CommandHelper; import net.minecraft.client.Minecraft; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; @@ -29,21 +30,9 @@ public class ContentContainers extends Content { container.add(new GuiButtonBase(x, y + 96, 232, 20, new TranslatableComponent("gui.worldhandler.generic.backToGame"), ActionHelper::backToGame)); - container.add(new GuiButtonBase(x + 24, y, 208, 20, Blocks.CRAFTING_TABLE.getName(), () -> - { - BlockHelper.setBlockNearPlayer(container.getPlayer(), Blocks.CRAFTING_TABLE); - ActionHelper.backToGame(); - })); - container.add(new GuiButtonBase(x + 24, y + 24, 208, 20, Blocks.ENDER_CHEST.getName(), () -> - { - BlockHelper.setBlockNearPlayer(container.getPlayer(), Blocks.ENDER_CHEST); - ActionHelper.backToGame(); - })); - container.add(new GuiButtonBase(x + 24, y + 48, 208, 20, Blocks.ANVIL.getName(), () -> - { - BlockHelper.setBlockNearPlayer(container.getPlayer(), Blocks.ANVIL); - ActionHelper.backToGame(); - })); + container.add(new GuiButtonBase(x + 24, y, 208, 20, Blocks.CRAFTING_TABLE.getName(), () -> this.placeBlock(container.getPlayer(), Blocks.CRAFTING_TABLE))); + container.add(new GuiButtonBase(x + 24, y + 24, 208, 20, Blocks.ENDER_CHEST.getName(), () -> this.placeBlock(container.getPlayer(), Blocks.ENDER_CHEST))); + container.add(new GuiButtonBase(x + 24, y + 48, 208, 20, Blocks.ANVIL.getName(), () -> this.placeBlock(container.getPlayer(), Blocks.ANVIL))); container.add(new GuiButtonBase(x + 24, y + 72, 208, 20, Blocks.ENCHANTING_TABLE.getName(), () -> { double angle = Minecraft.getInstance().player.getDirection().get2DDataValue() * Math.PI / 2; @@ -68,10 +57,28 @@ public class ContentContainers extends Content { block = Blocks.ENCHANTING_TABLE; } - - if(block != null) + else { - CommandHelper.sendCommand(container.getPlayer(), new BuilderSetBlock(new CoordinateInt(cx, EnumType.GLOBAL), new CoordinateInt(yOffset, EnumType.GLOBAL), new CoordinateInt(cz, EnumType.GLOBAL), block.getRegistryName(), Config.getSettings().getBlockPlacingMode())); + continue; + } + + SetBlockCommandBuilder builder = new SetBlockCommandBuilder(); + builder.pos().setX(new Coordinate.Ints(cx, Coordinate.Type.RELATIVE)); + builder.pos().setY(new Coordinate.Ints(yOffset, Coordinate.Type.RELATIVE)); + builder.pos().setZ(new Coordinate.Ints(cz, Coordinate.Type.RELATIVE)); + builder.block().set(block); + + switch(Config.getSettings().getBlockPlacingMode()) + { + case KEEP: + CommandHelper.sendCommand(container.getPlayer(), builder, SetBlockCommandBuilder.Label.KEEP); + break; + case REPLACE: + CommandHelper.sendCommand(container.getPlayer(), builder, SetBlockCommandBuilder.Label.REPLACE); + break; + case DESTROY: + CommandHelper.sendCommand(container.getPlayer(), builder, SetBlockCommandBuilder.Label.DESTROY); + break; } } } @@ -80,22 +87,24 @@ public class ContentContainers extends Content ActionHelper.backToGame(); })); - container.add(new GuiButtonItem(x, y, 20, 20, new ItemStack(Blocks.CRAFTING_TABLE), () -> - { - CommandHelper.sendCommand(container.getPlayer(), new BuilderGive(container.getPlayer(), Blocks.CRAFTING_TABLE.getRegistryName())); - })); - container.add(new GuiButtonItem(x, y + 24, 20, 20, new ItemStack(Blocks.ENDER_CHEST), () -> - { - CommandHelper.sendCommand(container.getPlayer(), new BuilderGive(container.getPlayer(), Blocks.ENDER_CHEST.getRegistryName())); - })); - container.add(new GuiButtonItem(x, y + 48, 20, 20, new ItemStack(Blocks.ANVIL), () -> - { - CommandHelper.sendCommand(container.getPlayer(), new BuilderGive(container.getPlayer(), Blocks.ANVIL.getRegistryName())); - })); - container.add(new GuiButtonItem(x, y + 72, 20, 20, new ItemStack(Blocks.ENCHANTING_TABLE), () -> - { - CommandHelper.sendCommand(container.getPlayer(), new BuilderGive(container.getPlayer(), Blocks.ENCHANTING_TABLE.getRegistryName())); - })); + container.add(new GuiButtonItem(x, y, 20, 20, new ItemStack(Blocks.CRAFTING_TABLE), () -> this.giveItem(container.getPlayer(), Items.CRAFTING_TABLE))); + container.add(new GuiButtonItem(x, y + 24, 20, 20, new ItemStack(Blocks.ENDER_CHEST), () -> this.giveItem(container.getPlayer(), Items.ENDER_CHEST))); + container.add(new GuiButtonItem(x, y + 48, 20, 20, new ItemStack(Blocks.ANVIL), () -> this.giveItem(container.getPlayer(), Items.ANVIL))); + container.add(new GuiButtonItem(x, y + 72, 20, 20, new ItemStack(Blocks.ENCHANTING_TABLE), () -> this.giveItem(container.getPlayer(), Items.ENCHANTING_TABLE))); + } + + private void giveItem(String player, Item item) + { + GiveCommandBuilder builder = new GiveCommandBuilder(); + builder.targets().setTarget(player); + builder.item().set(item); + CommandHelper.sendCommand(player, builder, GiveCommandBuilder.Label.GIVE); + } + + private void placeBlock(String player, Block block) + { + BlockHelper.setBlockNearPlayer(player, block); + ActionHelper.backToGame(); } @Override diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentContinue.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentContinue.java index 3dd88ba..311fdf9 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentContinue.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentContinue.java @@ -3,7 +3,6 @@ package exopandora.worldhandler.gui.content.impl; import com.mojang.blaze3d.vertex.PoseStack; import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.ICommandBuilderSyntax; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; import exopandora.worldhandler.gui.widget.button.GuiTextFieldTooltip; @@ -16,24 +15,26 @@ public class ContentContinue extends ContentChild { private ICommandBuilder builder; private GuiTextFieldTooltip commandField; + private Object label; private boolean special; - public ContentContinue withBuilder(ICommandBuilder builder) + public ContentContinue withBuilder(ICommandBuilder builder, Object label) { - return this.withBuilder(builder, false); + return this.withBuilder(builder, label, false); } - public ContentContinue withBuilder(ICommandBuilder builder, boolean special) + public ContentContinue withBuilder(ICommandBuilder builder, Object label, boolean special) { this.builder = builder; + this.label = label; this.special = special; return this; } @Override - public ICommandBuilder getCommandBuilder() + public CommandPreview getCommandPreview() { - return this.builder; + return new CommandPreview(this.builder, this.label); } @Override @@ -41,16 +42,7 @@ public class ContentContinue extends ContentChild { this.commandField = new GuiTextFieldTooltip(x + 116 / 2, y + 12, 116, 20); this.commandField.setFocus(false); - - if(this.builder instanceof ICommandBuilderSyntax) - { - this.commandField.setValue(((ICommandBuilderSyntax) this.builder).toActualCommand()); - } - else - { - this.commandField.setValue(this.builder.toCommand()); - } - + this.commandField.setValue(this.builder.toCommand(this.label, false)); this.commandField.moveCursorToStart(); this.commandField.setFilter(text -> text.equals(this.commandField.getValue())); } @@ -64,7 +56,7 @@ public class ContentContinue extends ContentChild container.add(this.commandField); container.add(new GuiButtonBase(x + 116 / 2, y + 36, 116, 20, new TranslatableComponent("gui.worldhandler.generic.yes").withStyle(ChatFormatting.RED), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builder, this.special); + CommandHelper.sendCommand(container.getPlayer(), this.builder, this.label, this.special); ActionHelper.open(this.getParentContent()); })); container.add(new GuiButtonBase(x + 116 / 2, y + 60, 116, 20, new TranslatableComponent("gui.worldhandler.generic.no"), () -> ActionHelper.back(this))); diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentCustomItem.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentCustomItem.java index fa125ab..9700706 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentCustomItem.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentCustomItem.java @@ -5,27 +5,28 @@ import java.util.ArrayList; import com.google.common.base.Predicates; import com.mojang.blaze3d.vertex.PoseStack; -import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.component.impl.ComponentAttribute; -import exopandora.worldhandler.builder.impl.BuilderCustomItem; +import exopandora.worldhandler.builder.argument.tag.AbstractAttributeTag; +import exopandora.worldhandler.builder.argument.tag.AttributeModifiersTag; +import exopandora.worldhandler.builder.argument.tag.DisplayTag; +import exopandora.worldhandler.builder.argument.tag.EnchantmentsTag; +import exopandora.worldhandler.builder.impl.GiveCommandBuilder; import exopandora.worldhandler.config.Config; 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.gui.menu.impl.ILogicPageList; -import exopandora.worldhandler.gui.menu.impl.MenuColorField; -import exopandora.worldhandler.gui.menu.impl.MenuPageList; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; import exopandora.worldhandler.gui.widget.button.GuiSlider; import exopandora.worldhandler.gui.widget.button.GuiTextFieldTooltip; import exopandora.worldhandler.gui.widget.button.LogicSliderAttribute; import exopandora.worldhandler.gui.widget.button.LogicSliderSimple; +import exopandora.worldhandler.gui.widget.menu.impl.ILogicPageList; +import exopandora.worldhandler.gui.widget.menu.impl.MenuColorField; +import exopandora.worldhandler.gui.widget.menu.impl.MenuPageList; import exopandora.worldhandler.util.ActionHandler; import exopandora.worldhandler.util.ActionHelper; import exopandora.worldhandler.util.CommandHelper; -import exopandora.worldhandler.util.ResourceHelper; import exopandora.worldhandler.util.TextUtils; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.TextComponent; @@ -40,39 +41,49 @@ public class ContentCustomItem extends Content private GuiTextFieldTooltip itemLore1Field; private GuiTextFieldTooltip itemLore2Field; - private final BuilderCustomItem builderCutomItem = new BuilderCustomItem(); + private final GiveCommandBuilder builderCutomItem = new GiveCommandBuilder(); + private final AttributeModifiersTag attributes = new AttributeModifiersTag(); + private final DisplayTag display = new DisplayTag(); + private final EnchantmentsTag enchantments = new EnchantmentsTag(); + private final CommandPreview preview = new CommandPreview(this.builderCutomItem, GiveCommandBuilder.Label.GIVE); private int startPage; - private Page page = Page.START; private String item; - @Override - public ICommandBuilder getCommandBuilder() + public ContentCustomItem() { - return this.builderCutomItem; + this.builderCutomItem.item().addTagProvider(this.attributes); + this.builderCutomItem.item().addTagProvider(this.display); + this.builderCutomItem.item().addTagProvider(this.enchantments); + } + + @Override + public CommandPreview getCommandPreview() + { + return this.preview; } @Override public void init(Container container) { - for(Attribute attribute : this.builderCutomItem.getAttributes()) + for(Attribute attribute : this.attributes.getAttributes()) { - double ammount = this.builderCutomItem.getAttributeAmmount(attribute); + double value = this.attributes.get(attribute); - if(ammount > Config.getSliders().getMaxItemAttributes()) + if(value > Config.getSliders().getMaxItemAttributes()) { - this.builderCutomItem.setAttribute(attribute, Config.getSliders().getMaxItemAttributes()); + this.attributes.set(attribute, Config.getSliders().getMaxItemAttributes()); } } - for(Enchantment enchantment : this.builderCutomItem.getEnchantments()) + for(Enchantment enchantment : this.enchantments.getEnchantments()) { - short level = this.builderCutomItem.getEnchantmentLevel(enchantment); + short level = this.enchantments.get(enchantment); if(level > Config.getSliders().getMaxItemEnchantment()) { - this.builderCutomItem.setEnchantment(enchantment, (short) Config.getSliders().getMaxItemEnchantment()); + this.enchantments.set(enchantment, (short) Config.getSliders().getMaxItemEnchantment()); } } } @@ -86,25 +97,25 @@ public class ContentCustomItem extends Content this.itemField.setResponder(text -> { this.item = text; - this.builderCutomItem.setItem(this.item); + this.builderCutomItem.item().deserialize(this.item); container.initButtons(); }); this.itemLore1Field = new GuiTextFieldTooltip(x + 118, y + 24, 114, 20, new TranslatableComponent("gui.worldhandler.items.custom_item.start.lore_1")); this.itemLore1Field.setFilter(Predicates.notNull()); - this.itemLore1Field.setText(this.builderCutomItem.getLore1()); + this.itemLore1Field.setText(this.display.getLore1()); this.itemLore1Field.setResponder(text -> { - this.builderCutomItem.setLore1(new TextComponent(text)); + this.display.setLore1(new TextComponent(text)); container.initButtons(); }); this.itemLore2Field = new GuiTextFieldTooltip(x + 118, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.items.custom_item.start.lore_2")); this.itemLore2Field.setFilter(Predicates.notNull()); - this.itemLore2Field.setText(this.builderCutomItem.getLore2()); + this.itemLore2Field.setText(this.display.getLore2()); this.itemLore2Field.setResponder(text -> { - this.builderCutomItem.setLore2(new TextComponent(text)); + this.display.setLore2(new TextComponent(text)); container.initButtons(); }); @@ -112,7 +123,7 @@ public class ContentCustomItem extends Content { if(this.startPage == 1) { - container.add(new MenuColorField(x, y, "gui.worldhandler.items.custom_item.start.custom_name", this.builderCutomItem.getName())); + container.add(new MenuColorField(x, y, "gui.worldhandler.items.custom_item.start.custom_name", this.display.getName())); } } else if(Page.ENCHANT.equals(this.page)) @@ -142,7 +153,7 @@ public class ContentCustomItem extends Content { return new GuiSlider(x, y, width, height, 0, Config.getSliders().getMaxItemEnchantment(), 0, container, new LogicSliderSimple(item.getRegistryName().toString(), text, value -> { - ContentCustomItem.this.builderCutomItem.setEnchantment(item, value.shortValue()); + ContentCustomItem.this.enchantments.set(item, value.shortValue()); })); } @@ -162,32 +173,32 @@ public class ContentCustomItem extends Content } else if(Page.ATTRIBUTES.equals(this.page)) { - MenuPageList attributes = new MenuPageList(x + 118, y, ComponentAttribute.ATTRIBUTES, 114, 20, 3, container, new ILogicPageList() + MenuPageList attributes = new MenuPageList(x + 118, y, AbstractAttributeTag.ATTRIBUTES, 114, 20, 3, container, new ILogicPageList() { @Override - public MutableComponent translate(Attribute item) + public MutableComponent translate(Attribute attribute) { - return new TranslatableComponent(item.getDescriptionId()); + return new TranslatableComponent(attribute.getDescriptionId()); } @Override - public MutableComponent toTooltip(Attribute item) + public MutableComponent toTooltip(Attribute attribute) { - return new TextComponent(item.getRegistryName().toString()); + return new TextComponent(attribute.getRegistryName().toString()); } @Override - public void onClick(Attribute item) + public void onClick(Attribute attribute) { } @Override - public GuiButtonBase onRegister(int x, int y, int width, int height, MutableComponent text, Attribute item, ActionHandler actionHandler) + public GuiButtonBase onRegister(int x, int y, int width, int height, MutableComponent text, Attribute attribute, ActionHandler actionHandler) { - return new GuiSlider(x, y, width, height, -Config.getSliders().getMaxItemAttributes(), Config.getSliders().getMaxItemEnchantment(), 0, container, new LogicSliderAttribute(item, text, value -> + return new GuiSlider(x, y, width, height, -Config.getSliders().getMaxItemAttributes(), Config.getSliders().getMaxItemEnchantment(), 0, container, new LogicSliderAttribute(attribute, text, value -> { - ContentCustomItem.this.builderCutomItem.setAttribute(item, value); + ContentCustomItem.this.attributes.set(attribute, value); })); } @@ -273,21 +284,21 @@ public class ContentCustomItem extends Content button3.active = false; } - if(!this.builderCutomItem.needsCommandBlock() && !this.builderCutomItem.getName().isSpecial()) + if(!this.builderCutomItem.needsCommandBlock(GiveCommandBuilder.Label.GIVE, false) && !this.display.getName().isSpecial()) { - container.add(button4 = new GuiButtonBase(x, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.items.custom_item.custom_item"), () -> this.send(container.getPlayer()))); + container.add(button4 = new GuiButtonBase(x, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.items.custom_item.custom_item"), () -> this.giveItem(container.getPlayer()))); } else { - container.add(button4 = new GuiButtonBase(x, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.actions.place_command_block"), () -> this.send(container.getPlayer()))); + container.add(button4 = new GuiButtonBase(x, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.actions.place_command_block"), () -> this.giveItem(container.getPlayer()))); } - button4.active = ResourceHelper.isRegistered(ResourceHelper.stringToResourceLocation(this.item), ForgeRegistries.ITEMS); + button4.active = this.builderCutomItem.item().hasValue(); } - private void send(String player) + private void giveItem(String player) { - CommandHelper.sendCommand(player, this.builderCutomItem, this.builderCutomItem.getName().isSpecial()); + CommandHelper.sendCommand(player, this.builderCutomItem, GiveCommandBuilder.Label.GIVE, this.display.getName().isSpecial()); } @Override @@ -339,7 +350,7 @@ public class ContentCustomItem extends Content @Override public void onPlayerNameChanged(String username) { - this.builderCutomItem.setPlayer(username); + this.builderCutomItem.targets().setTarget(username); } public static enum Page diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentEditBlocks.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentEditBlocks.java index 9e1fc59..104af83 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentEditBlocks.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentEditBlocks.java @@ -5,71 +5,64 @@ import java.util.Arrays; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.brigadier.StringReader; -import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.impl.BuilderClone; -import exopandora.worldhandler.builder.impl.BuilderClone.EnumMask; -import exopandora.worldhandler.builder.impl.BuilderFill; -import exopandora.worldhandler.builder.impl.BuilderWH; -import exopandora.worldhandler.command.CommandWH.StringBlockPredicateArgument; +import exopandora.worldhandler.builder.impl.CloneCommandBuilder; +import exopandora.worldhandler.builder.impl.FillCommandBuilder; +import exopandora.worldhandler.builder.impl.WHCommandBuilder; +import exopandora.worldhandler.builder.impl.CloneCommandBuilder.Label; 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.gui.menu.impl.ILogicMapped; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; import exopandora.worldhandler.gui.widget.button.GuiButtonList; import exopandora.worldhandler.gui.widget.button.GuiTextFieldTooltip; +import exopandora.worldhandler.gui.widget.menu.impl.ILogicMapped; import exopandora.worldhandler.util.ActionHelper; import exopandora.worldhandler.util.BlockHelper; import exopandora.worldhandler.util.CommandHelper; -import exopandora.worldhandler.util.ResourceHelper; +import net.minecraft.client.Minecraft; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; -import net.minecraftforge.registries.ForgeRegistries; public class ContentEditBlocks extends Content { private GuiTextFieldTooltip x1Field; private GuiTextFieldTooltip y1Field; private GuiTextFieldTooltip z1Field; - private GuiTextFieldTooltip x2Field; private GuiTextFieldTooltip y2Field; private GuiTextFieldTooltip z2Field; - private GuiTextFieldTooltip block1Field; private GuiTextFieldTooltip block2Field; - private GuiTextFieldTooltip filterField; - private final BuilderFill builderFill = BlockHelper.addPositionObservers(new BuilderFill(), builder -> builder::setPosition1, builder -> builder::setPosition2); - private final BuilderClone builderClone = BlockHelper.addPositionObservers(new BuilderClone(), builder -> builder::setPosition1, builder -> builder::setPosition2); - private final BuilderWH builderWH = new BuilderWH(); + private final FillCommandBuilder builderFill = new FillCommandBuilder(); + private final CloneCommandBuilder builderClone = new CloneCommandBuilder(); + private final WHCommandBuilder builderWH = new WHCommandBuilder(); private String block1; private String block2; private String filter; - private Page page = Page.COORDINATES; + private Mask mask = Mask.FILTERED; @Override - public ICommandBuilder getCommandBuilder() + public CommandPreview getCommandPreview() { if(Page.COORDINATES.equals(this.page)) { - return this.builderWH; + return new CommandPreview(this.builderWH, null); } else if(Page.FILL.equals(this.page) || Page.REPLACE.equals(this.page)) { - return this.builderFill; + return new CommandPreview(this.builderFill, FillCommandBuilder.Label.FILL); } else if(Page.CLONE.equals(this.page)) { - return this.builderClone; + return new CommandPreview(this.builderClone, this.mask.getLabel()); } return null; @@ -78,53 +71,37 @@ public class ContentEditBlocks extends Content @Override public void initGui(Container container, int x, int y) { + this.updatePositions(); + this.x1Field = new GuiTextFieldTooltip(x + 118, y, 55, 20); - this.x1Field.setFilter(this.getCoordinatePredicate("X1")); - this.x1Field.setValue("X1: " + BlockHelper.getPos1().getX()); - this.x1Field.setResponder(text -> - { - BlockHelper.setPos1(BlockHelper.setX(BlockHelper.getPos1(), this.parseCoordinate(text))); - }); + this.x1Field.setFilter(this.coordinatePredicate("X1")); + this.x1Field.setValue("X1: " + BlockHelper.pos1().getX()); + this.x1Field.setResponder(text -> BlockHelper.pos1().setX(this.parseCoordinate(text))); this.y1Field = new GuiTextFieldTooltip(x + 118, y + 24, 55, 20); - this.y1Field.setFilter(this.getCoordinatePredicate("Y1")); - this.y1Field.setValue("Y1: " + BlockHelper.getPos1().getY()); - this.y1Field.setResponder(text -> - { - BlockHelper.setPos1(BlockHelper.setY(BlockHelper.getPos1(), this.parseCoordinate(text))); - }); + this.y1Field.setFilter(this.coordinatePredicate("Y1")); + this.y1Field.setValue("Y1: " + BlockHelper.pos1().getY()); + this.y1Field.setResponder(text -> BlockHelper.pos1().setY(this.parseCoordinate(text))); this.z1Field = new GuiTextFieldTooltip(x + 118, y + 48, 55, 20); - this.z1Field.setFilter(this.getCoordinatePredicate("Z1")); - this.z1Field.setValue("Z1: " + BlockHelper.getPos1().getZ()); - this.z1Field.setResponder(text -> - { - BlockHelper.setPos1(BlockHelper.setZ(BlockHelper.getPos1(), this.parseCoordinate(text))); - }); + this.z1Field.setFilter(this.coordinatePredicate("Z1")); + this.z1Field.setValue("Z1: " + BlockHelper.pos1().getZ()); + this.z1Field.setResponder(text -> BlockHelper.pos1().setZ(this.parseCoordinate(text))); this.x2Field = new GuiTextFieldTooltip(x + 118 + 59, y, 55, 20); - this.x2Field.setFilter(this.getCoordinatePredicate("X2")); - this.x2Field.setValue("X2: " + BlockHelper.getPos2().getX()); - this.x2Field.setResponder(text -> - { - BlockHelper.setPos2(BlockHelper.setX(BlockHelper.getPos2(), this.parseCoordinate(text))); - }); + this.x2Field.setFilter(this.coordinatePredicate("X2")); + this.x2Field.setValue("X2: " + BlockHelper.pos2().getX()); + this.x2Field.setResponder(text -> BlockHelper.pos2().setX(this.parseCoordinate(text))); this.y2Field = new GuiTextFieldTooltip(x + 118 + 59, y + 24, 55, 20); - this.y2Field.setFilter(this.getCoordinatePredicate("Y2")); - this.y2Field.setValue("Y2: " + BlockHelper.getPos2().getY()); - this.y2Field.setResponder(text -> - { - BlockHelper.setPos2(BlockHelper.setY(BlockHelper.getPos2(), this.parseCoordinate(text))); - }); + this.y2Field.setFilter(this.coordinatePredicate("Y2")); + this.y2Field.setValue("Y2: " + BlockHelper.pos2().getY()); + this.y2Field.setResponder(text -> BlockHelper.pos2().setY(this.parseCoordinate(text))); this.z2Field = new GuiTextFieldTooltip(x + 118 + 59, y + 48, 55, 20); - this.z2Field.setFilter(this.getCoordinatePredicate("Z2")); - this.z2Field.setValue("Z2: " + BlockHelper.getPos2().getZ()); - this.z2Field.setResponder(text -> - { - BlockHelper.setPos2(BlockHelper.setZ(BlockHelper.getPos2(), this.parseCoordinate(text))); - }); + this.z2Field.setFilter(this.coordinatePredicate("Z2")); + this.z2Field.setValue("Z2: " + BlockHelper.pos2().getZ()); + this.z2Field.setResponder(text -> BlockHelper.pos2().setZ(this.parseCoordinate(text))); this.block1Field = new GuiTextFieldTooltip(x + 118, y, 114, 20, Page.FILL.equals(this.page) ? new TranslatableComponent("gui.worldhandler.edit_blocks.fill.block_id_to_fill") : new TranslatableComponent("gui.worldhandler.edit_blocks.replace.block_id_replace")); this.block1Field.setFilter(Predicates.notNull()); @@ -132,7 +109,7 @@ public class ContentEditBlocks extends Content this.block1Field.setResponder(text -> { this.block1 = text; - this.builderFill.setBlock1(this.block1); + this.builderFill.block().deserialize(this.block1); container.initButtons(); }); @@ -142,7 +119,7 @@ public class ContentEditBlocks extends Content this.block2Field.setResponder(text -> { this.block2 = text; - this.builderFill.setBlock2(this.block2); + this.builderFill.filter().deserialize(this.block2); //TODO block2 = filter ??? container.initButtons(); }); @@ -152,7 +129,7 @@ public class ContentEditBlocks extends Content this.filterField.setResponder(text -> { this.filter = text; - this.builderClone.setFilter(this.filter); + this.builderClone.filter().deserialize(this.filter); container.initButtons(); }); } @@ -225,9 +202,9 @@ public class ContentEditBlocks extends Content container.add(this.block1Field); container.add(button1 = new GuiButtonBase(x + 118, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.edit_blocks.fill"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderFill.build()); + CommandHelper.sendCommand(container.getPlayer(), this.builderFill, FillCommandBuilder.Label.FILL); })); - button1.active = ResourceHelper.isRegistered(this.builderFill.getBlock1(), ForgeRegistries.BLOCKS); + button1.active = this.builderFill.block().hasValue(); } else if(Page.REPLACE.equals(this.page)) { @@ -243,9 +220,9 @@ public class ContentEditBlocks extends Content container.add(this.block2Field); container.add(button1 = new GuiButtonBase(x + 118, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.edit_blocks.replace"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderFill.buildReplace()); + CommandHelper.sendCommand(container.getPlayer(), this.builderFill, FillCommandBuilder.Label.REPLACE); })); - button1.active = ResourceHelper.isRegistered(this.builderFill.getBlock1(), ForgeRegistries.BLOCKS) && ResourceHelper.isRegistered(this.builderFill.getBlock2(), ForgeRegistries.BLOCKS); + button1.active = this.builderFill.block().hasValue() && this.builderFill.filter().hasValue(); } else if(Page.CLONE.equals(this.page)) { @@ -257,36 +234,34 @@ public class ContentEditBlocks extends Content width2 = 56; xOffset2 = 58; - if(EnumMask.FILTERED.equals(this.builderClone.getMask())) + if(Mask.FILTERED.equals(this.mask)) { - this.builderClone.setFilter(this.filter); container.add(this.filterField); } else { - this.builderClone.setFilter(null); container.add(button1 = new GuiButtonBase(x + 118, y + 24, 114, 20, TextComponent.EMPTY, null)); button1.active = false; } - container.add(new GuiButtonList(x + 118, y, Arrays.asList(EnumMask.values()), 114, 20, container, new ILogicMapped() + container.add(new GuiButtonList(x + 118, y, Arrays.asList(Mask.values()), 114, 20, container, new ILogicMapped() { @Override - public MutableComponent translate(EnumMask item) + public MutableComponent translate(Mask mask) { - return new TranslatableComponent("gui.worldhandler.edit_blocks.clone.mode." + item.toString()); + return new TranslatableComponent("gui.worldhandler.edit_blocks.clone.mode." + mask.toString()); } @Override - public MutableComponent toTooltip(EnumMask item) + public MutableComponent toTooltip(Mask mask) { - return new TextComponent(item.toString()); + return new TextComponent(mask.toString()); } @Override - public void onClick(EnumMask item) + public void onClick(Mask mask) { - ContentEditBlocks.this.builderClone.setMask(item); + ContentEditBlocks.this.mask = mask; container.init(); } @@ -299,34 +274,38 @@ public class ContentEditBlocks extends Content container.add(button2 = new GuiButtonBase(x + 118, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.edit_blocks.clone"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderClone); + System.out.println(this.builderClone.toCommand(this.mask.getLabel(), false)); + CommandHelper.sendCommand(container.getPlayer(), this.builderClone, this.mask.getLabel()); })); - try + if(Mask.FILTERED.equals(this.mask)) { - if(EnumMask.FILTERED.equals(this.builderClone.getMask())) - { - StringBlockPredicateArgument.blockPredicate().parse(new StringReader(this.builderClone.getFilter())); - } - } - catch(Exception e) - { - button2.active = false; + button2.active = this.builderClone.filter().hasValue(); } } container.add(new GuiButtonBase(x + 118, y + yOffset1, width1, 20, new TranslatableComponent("gui.worldhandler.edit_blocks.pos.set_pos_1"), () -> { - BlockHelper.setPos1(BlockHelper.getFocusedBlockPos()); + BlockHelper.pos1().set(BlockHelper.getFocusedBlockPos()); + this.updatePositions(); container.init(); })); container.add(new GuiButtonBase(x + 118 + xOffset2, y + yOffset2, width2, 20, new TranslatableComponent("gui.worldhandler.edit_blocks.pos.set_pos_2"), () -> { - BlockHelper.setPos2(BlockHelper.getFocusedBlockPos()); + BlockHelper.pos2().set(BlockHelper.getFocusedBlockPos()); + this.updatePositions(); container.init(); })); } + private void updatePositions() + { + this.builderFill.from().set(BlockHelper.pos1()); + this.builderFill.to().set(BlockHelper.pos2()); + this.builderClone.begin().set(BlockHelper.pos1()); + this.builderClone.end().set(BlockHelper.pos2()); + } + @Override public void tick(Container container) { @@ -351,7 +330,9 @@ public class ContentEditBlocks extends Content } else if(Page.CLONE.equals(this.page)) { - if(EnumMask.FILTERED.equals(this.builderClone.getMask())) + this.builderClone.destination().set(Minecraft.getInstance().player.blockPosition()); + + if(Mask.FILTERED.equals(this.mask)) { this.filterField.tick(); } @@ -382,14 +363,14 @@ public class ContentEditBlocks extends Content } else if(Page.CLONE.equals(this.page)) { - if(EnumMask.FILTERED.equals(this.builderClone.getMask())) + if(Mask.FILTERED.equals(this.mask)) { this.filterField.renderButton(matrix, mouseX, mouseY, partialTicks); } } } - private Predicate getCoordinatePredicate(String coordinate) + private Predicate coordinatePredicate(String coordinate) { return string -> string.matches(coordinate + ": [-]?[0-9]*"); } @@ -433,11 +414,36 @@ public class ContentEditBlocks extends Content return Contents.EDIT_BLOCKS; } - public static enum Page + private static enum Page { COORDINATES, FILL, REPLACE, CLONE; } + + private static enum Mask + { + FILTERED(CloneCommandBuilder.Label.FILTERED), + MASKED(CloneCommandBuilder.Label.MASKED), + REPLACE(CloneCommandBuilder.Label.REPLACE); + + private final CloneCommandBuilder.Label label; + + private Mask(Label label) + { + this.label = label; + } + + public CloneCommandBuilder.Label getLabel() + { + return this.label; + } + + @Override + public String toString() + { + return this.name().toLowerCase(); + } + } } diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentEnchantment.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentEnchantment.java index 6ce24af..e4be548 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentEnchantment.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentEnchantment.java @@ -2,19 +2,18 @@ package exopandora.worldhandler.gui.content.impl; import java.util.ArrayList; -import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.impl.BuilderEnchantment; +import exopandora.worldhandler.builder.impl.EnchantCommandBuilder; 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.gui.menu.impl.ILogicPageList; -import exopandora.worldhandler.gui.menu.impl.MenuPageList; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; import exopandora.worldhandler.gui.widget.button.GuiButtonTooltip; import exopandora.worldhandler.gui.widget.button.GuiSlider; import exopandora.worldhandler.gui.widget.button.LogicSliderSimple; +import exopandora.worldhandler.gui.widget.menu.impl.ILogicPageList; +import exopandora.worldhandler.gui.widget.menu.impl.MenuPageList; import exopandora.worldhandler.util.ActionHandler; import exopandora.worldhandler.util.ActionHelper; import exopandora.worldhandler.util.CommandHelper; @@ -26,12 +25,13 @@ import net.minecraftforge.registries.ForgeRegistries; public class ContentEnchantment extends Content { - private final BuilderEnchantment builderEnchantment = new BuilderEnchantment(); + private final EnchantCommandBuilder builderEnchantment = new EnchantCommandBuilder(); + private final CommandPreview preview = new CommandPreview(this.builderEnchantment, EnchantCommandBuilder.Label.ENCHANT_LEVEL); @Override - public ICommandBuilder getCommandBuilder() + public CommandPreview getCommandPreview() { - return this.builderEnchantment; + return this.preview; } @Override @@ -40,22 +40,22 @@ public class ContentEnchantment extends Content MenuPageList enchantments = new MenuPageList(x, y, new ArrayList(ForgeRegistries.ENCHANTMENTS.getValues()), 114, 20, 3, container, new ILogicPageList() { @Override - public MutableComponent translate(Enchantment item) + public MutableComponent translate(Enchantment enchantment) { - return new TranslatableComponent(item.getDescriptionId()); + return new TranslatableComponent(enchantment.getDescriptionId()); } @Override - public MutableComponent toTooltip(Enchantment item) + public MutableComponent toTooltip(Enchantment enchantment) { - return new TextComponent(item.getRegistryName().toString()); + return new TextComponent(enchantment.getRegistryName().toString()); } @Override - public void onClick(Enchantment item) + public void onClick(Enchantment enchantment) { - ContentEnchantment.this.builderEnchantment.setEnchantment(item); - ContentEnchantment.this.builderEnchantment.setLevel(1); + ContentEnchantment.this.builderEnchantment.enchantment().set(enchantment); + ContentEnchantment.this.builderEnchantment.level().set(1); container.initButtons(); } @@ -81,14 +81,14 @@ public class ContentEnchantment extends Content container.add(new GuiButtonBase(x, y + 96, 114, 20, new TranslatableComponent("gui.worldhandler.generic.back"), () -> ActionHelper.back(this))); container.add(new GuiButtonBase(x + 118, y + 96, 114, 20, new TranslatableComponent("gui.worldhandler.generic.backToGame"), ActionHelper::backToGame)); - container.add(new GuiSlider(x + 118, y + 24, 114, 20, 1, ForgeRegistries.ENCHANTMENTS.getValue(this.builderEnchantment.getEnchantment()).getMaxLevel(), 1, container, new LogicSliderSimple("enchantment", new TranslatableComponent("gui.worldhandler.items.enchantment.level"), value -> + container.add(new GuiSlider(x + 118, y + 24, 114, 20, 1, this.builderEnchantment.enchantment().getEnchantment().getMaxLevel(), 1, container, new LogicSliderSimple("enchantment", new TranslatableComponent("gui.worldhandler.items.enchantment.level"), value -> { - this.builderEnchantment.setLevel(value.intValue()); + this.builderEnchantment.level().set(value.intValue()); }))); container.add(new GuiButtonBase(x + 118, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.items.enchantment.enchant"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderEnchantment); + CommandHelper.sendCommand(container.getPlayer(), this.builderEnchantment, EnchantCommandBuilder.Label.ENCHANT_LEVEL); })); } @@ -119,6 +119,6 @@ public class ContentEnchantment extends Content @Override public void onPlayerNameChanged(String username) { - this.builderEnchantment.setPlayer(username); + this.builderEnchantment.target().setTarget(username); } } diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentExperience.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentExperience.java index 20894c7..5d86ac6 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentExperience.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentExperience.java @@ -1,7 +1,6 @@ package exopandora.worldhandler.gui.content.impl; -import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.impl.BuilderExperience; +import exopandora.worldhandler.builder.impl.ExperienceCommandBuilder; import exopandora.worldhandler.config.Config; import exopandora.worldhandler.gui.category.Categories; import exopandora.worldhandler.gui.category.Category; @@ -19,23 +18,29 @@ import net.minecraft.network.chat.TranslatableComponent; public class ContentExperience extends Content { - private final BuilderExperience builderExperience = new BuilderExperience(); + private final ExperienceCommandBuilder builderExperience = new ExperienceCommandBuilder(); + private final CommandPreview preview = new CommandPreview(this.builderExperience, null); private GuiButtonBase buttonAdd; private GuiButtonBase buttonRemove; - @Override - public ICommandBuilder getCommandBuilder() + public ContentExperience() { - return this.builderExperience; + this.builderExperience.amount().set(0); + } + + @Override + public CommandPreview getCommandPreview() + { + return this.preview; } @Override public void init(Container container) { - if(this.builderExperience.getLevel() > Config.getSliders().getMaxExperience()) + if(this.builderExperience.amount().get() > Config.getSliders().getMaxExperience()) { - this.builderExperience.setLevel((int) Config.getSliders().getMaxExperience()); + this.builderExperience.amount().set((int) Config.getSliders().getMaxExperience()); } } @@ -47,25 +52,30 @@ public class ContentExperience extends Content container.add(new GuiSlider(x + 116 / 2, y, 114, 20, 0, Config.getSliders().getMaxExperience(), 0, container, new LogicSliderSimple("experience", new TranslatableComponent("gui.worldhandler.title.player.experience"), value -> { - this.builderExperience.setLevel(value); + this.builderExperience.amount().set(value); }))); container.add(this.buttonAdd = new GuiButtonBase(x + 116 / 2, y + 24, 114, 20, new TranslatableComponent("gui.worldhandler.actions.add"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderExperience.buildAdd()); + CommandHelper.sendCommand(container.getPlayer(), this.builderExperience, ExperienceCommandBuilder.Label.ADD_LEVELS); container.init(); })); container.add(this.buttonRemove = new GuiButtonBase(x + 116 / 2, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.actions.remove"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderExperience.buildRemove()); + ExperienceCommandBuilder builder = new ExperienceCommandBuilder(); + builder.targets().setTarget(this.builderExperience.targets().getTarget()); + builder.amount().set(-this.builderExperience.amount().get()); + CommandHelper.sendCommand(container.getPlayer(), builder, ExperienceCommandBuilder.Label.ADD_LEVELS); })); container.add(new GuiButtonTooltip(x + 116 / 2, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.actions.reset"), new TranslatableComponent("gui.worldhandler.actions.set_to_0"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderExperience.buildReset()); - container.init(); + ExperienceCommandBuilder builder = new ExperienceCommandBuilder(); + builder.amount().set(0); + builder.targets().setTarget(this.builderExperience.targets().getTarget()); + CommandHelper.sendCommand(container.getPlayer(), builder, ExperienceCommandBuilder.Label.SET_POINTS); })); - boolean enabled = this.builderExperience.getLevel() > 0; + boolean enabled = this.builderExperience.amount().get() > 0; this.buttonAdd.active = enabled; this.buttonRemove.active = enabled; @@ -74,7 +84,7 @@ public class ContentExperience extends Content @Override public void tick(Container container) { - boolean enabled = this.builderExperience.getLevel() > 0; + boolean enabled = this.builderExperience.amount().get() > 0; this.buttonAdd.active = enabled; this.buttonRemove.active = enabled; @@ -107,6 +117,6 @@ public class ContentExperience extends Content @Override public void onPlayerNameChanged(String username) { - this.builderExperience.setPlayer(username); + this.builderExperience.targets().setTarget(username); } } diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentGamerules.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentGamerules.java index 3ff4b09..0e2c9ec 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentGamerules.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentGamerules.java @@ -9,18 +9,17 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.BoolArgumentType; -import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.impl.BuilderGamerule; +import exopandora.worldhandler.builder.impl.GameRuleCommandBuilder; 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.gui.menu.impl.ILogicPageList; -import exopandora.worldhandler.gui.menu.impl.MenuPageList; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; import exopandora.worldhandler.gui.widget.button.GuiButtonTooltip; import exopandora.worldhandler.gui.widget.button.GuiTextFieldTooltip; +import exopandora.worldhandler.gui.widget.menu.impl.ILogicPageList; +import exopandora.worldhandler.gui.widget.menu.impl.MenuPageList; import exopandora.worldhandler.util.ActionHandler; import exopandora.worldhandler.util.ActionHelper; import exopandora.worldhandler.util.CommandHelper; @@ -37,12 +36,13 @@ public class ContentGamerules extends Content private boolean booleanValue; private String value; - private final BuilderGamerule builderGamerule = new BuilderGamerule(); + private final GameRuleCommandBuilder builderGamerule = new GameRuleCommandBuilder(); + private final CommandPreview preview = new CommandPreview(this.builderGamerule, GameRuleCommandBuilder.Label.GAMERULE_VALUE); @Override - public ICommandBuilder getCommandBuilder() + public CommandPreview getCommandPreview() { - return this.builderGamerule; + return this.preview; } @Override @@ -55,7 +55,7 @@ public class ContentGamerules extends Content this.valueField.setResponder(text -> { this.value = text; - this.builderGamerule.setValue(this.value); + this.builderGamerule.value().set(text); }); Map> map = new HashMap>(); @@ -72,30 +72,30 @@ public class ContentGamerules extends Content MenuPageList rules = new MenuPageList(x, y, new ArrayList(map.keySet()), 114, 20, 3, container, new ILogicPageList() { @Override - public MutableComponent translate(String item) + public MutableComponent translate(String rule) { - return new TranslatableComponent("gamerule." + item); + return new TranslatableComponent("gamerule." + rule); } @Override - public MutableComponent toTooltip(String item) + public MutableComponent toTooltip(String rule) { - return new TextComponent(item); + return new TextComponent(rule); } @Override - public void onClick(String item) + public void onClick(String rule) { - ContentGamerules.this.builderGamerule.setRule(item); - ContentGamerules.this.booleanValue = map.get(item) instanceof BoolArgumentType; + ContentGamerules.this.builderGamerule.rule().set(rule); + ContentGamerules.this.booleanValue = map.get(rule) instanceof BoolArgumentType; if(ContentGamerules.this.booleanValue) { - ContentGamerules.this.builderGamerule.setValue(null); + ContentGamerules.this.builderGamerule.value().set(null); } else { - ContentGamerules.this.builderGamerule.setValue(ContentGamerules.this.value); + ContentGamerules.this.builderGamerule.value().set(ContentGamerules.this.value); } container.initButtons(); @@ -127,11 +127,11 @@ public class ContentGamerules extends Content { container.add(new GuiButtonBase(x + 118, y + 24, 114, 20, new TranslatableComponent("gui.worldhandler.generic.enable"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderGamerule.build(String.valueOf(true))); + this.setGameRule(container.getPlayer(), String.valueOf(true)); })); container.add(new GuiButtonBase(x + 118, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.generic.disable"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderGamerule.build(String.valueOf(false))); + this.setGameRule(container.getPlayer(), String.valueOf(false)); })); } else @@ -139,11 +139,19 @@ public class ContentGamerules extends Content container.add(this.valueField); container.add(new GuiButtonBase(x + 118, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.actions.perform"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderGamerule); + this.setGameRule(container.getPlayer(), this.value); })); } } + private void setGameRule(String player, String value) + { + GameRuleCommandBuilder builder = new GameRuleCommandBuilder(); + builder.rule().set(this.builderGamerule.rule().get()); + builder.value().set(value); + CommandHelper.sendCommand(player, builder, GameRuleCommandBuilder.Label.GAMERULE_VALUE); + } + @Override public void tick(Container container) { diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentMain.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentMain.java index 4eaec0e..a1ca8d3 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentMain.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentMain.java @@ -88,7 +88,7 @@ public class ContentMain extends Content { return Contents.MAIN; } - + @Override public Content getBackContent() { diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentMultiplayer.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentMultiplayer.java index 4738c3a..33aab4e 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentMultiplayer.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentMultiplayer.java @@ -3,13 +3,16 @@ package exopandora.worldhandler.gui.content.impl; import com.google.common.base.Predicates; import com.mojang.blaze3d.vertex.PoseStack; -import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.impl.BuilderGeneric; -import exopandora.worldhandler.builder.impl.BuilderMultiCommand; -import exopandora.worldhandler.builder.impl.BuilderPlayer; -import exopandora.worldhandler.builder.impl.BuilderPlayerReason; -import exopandora.worldhandler.builder.impl.BuilderWhitelist; -import exopandora.worldhandler.builder.impl.BuilderWhitelist.EnumMode; +import exopandora.worldhandler.builder.impl.BanCommandBuilder; +import exopandora.worldhandler.builder.impl.DeOpCommandBuilder; +import exopandora.worldhandler.builder.impl.KickCommandBuilder; +import exopandora.worldhandler.builder.impl.OpCommandBuilder; +import exopandora.worldhandler.builder.impl.PardonCommandBuilder; +import exopandora.worldhandler.builder.impl.SaveAllCommandBuilder; +import exopandora.worldhandler.builder.impl.SaveOffCommandBuilder; +import exopandora.worldhandler.builder.impl.SaveOnCommandBuilder; +import exopandora.worldhandler.builder.impl.StopCommandBuilder; +import exopandora.worldhandler.builder.impl.WhitelistCommandBuilder; import exopandora.worldhandler.gui.category.Categories; import exopandora.worldhandler.gui.category.Category; import exopandora.worldhandler.gui.container.Container; @@ -35,43 +38,53 @@ public class ContentMultiplayer extends Content private Page page = Page.KICK_AND_BAN; - private final BuilderPlayerReason builderKick = new BuilderPlayerReason("kick"); - private final BuilderPlayerReason builderBan = new BuilderPlayerReason("ban"); - private final BuilderPlayer builderPardon = new BuilderPlayer("pardon"); - private final BuilderPlayer builderOp = new BuilderPlayer("op"); - private final BuilderPlayer builderDeop = new BuilderPlayer("deop"); - private final BuilderGeneric builderSaveAll = new BuilderGeneric("save-all"); - private final BuilderGeneric builderSaveOn = new BuilderGeneric("save-on"); - private final BuilderGeneric builderSaveOff = new BuilderGeneric("save-off"); - private final BuilderGeneric builderStop = new BuilderGeneric("stop"); - private final BuilderWhitelist builderWhitelist = new BuilderWhitelist(); + private final KickCommandBuilder builderKick = new KickCommandBuilder(); + private final BanCommandBuilder builderBan = new BanCommandBuilder(); + private final PardonCommandBuilder builderPardon = new PardonCommandBuilder(); + private final OpCommandBuilder builderOp = new OpCommandBuilder(); + private final DeOpCommandBuilder builderDeop = new DeOpCommandBuilder(); + private final SaveAllCommandBuilder builderSaveAll = new SaveAllCommandBuilder(); + private final SaveOnCommandBuilder builderSaveOn = new SaveOnCommandBuilder(); + private final SaveOffCommandBuilder builderSaveOff = new SaveOffCommandBuilder(); + private final StopCommandBuilder builderStop = new StopCommandBuilder(); + private final WhitelistCommandBuilder builderWhitelist = new WhitelistCommandBuilder(); - private final BuilderMultiCommand builderKickBan = new BuilderMultiCommand(this.builderKick, this.builderBan); - private final BuilderMultiCommand builderPermissions = new BuilderMultiCommand(this.builderOp, this.builderDeop); - private final BuilderMultiCommand builderRuntime = new BuilderMultiCommand(this.builderSaveAll, this.builderSaveOn, this.builderSaveOff, this.builderStop); + private final CommandPreview previewKickBan = new CommandPreview() + .add(this.builderKick, KickCommandBuilder.Label.KICK) + .add(this.builderBan, BanCommandBuilder.Label.BAN); + private final CommandPreview previewPardon = new CommandPreview(this.builderPardon, PardonCommandBuilder.Label.PARDON); + private final CommandPreview previewPermissions = new CommandPreview() + .add(this.builderOp, OpCommandBuilder.Label.OP) + .add(this.builderDeop, DeOpCommandBuilder.Label.DEOP); + private final CommandPreview previewRuntime = new CommandPreview() + .add(this.builderSaveAll, SaveAllCommandBuilder.Label.SAVE_ALL) + .add(this.builderSaveOn, SaveOnCommandBuilder.Label.SAVE_ON) + .add(this.builderSaveOff, SaveOffCommandBuilder.Label.SAVE_OFF) + .add(this.builderStop, StopCommandBuilder.Label.STOP); + private final CommandPreview previewWhitelist = new CommandPreview(this.builderWhitelist, null); @Override - public ICommandBuilder getCommandBuilder() + public CommandPreview getCommandPreview() { if(Page.KICK_AND_BAN.equals(this.page)) { - return this.builderKickBan; + return this.previewKickBan; } else if(Page.PARDON.equals(this.page)) { - return this.builderPardon; + return this.previewPardon; } else if(Page.PERMISSIONS.equals(this.page)) { - return this.builderPermissions; + return this.previewPermissions; } else if(Page.RUNTIME.equals(this.page)) { - return this.builderRuntime; + return this.previewRuntime; } else if(Page.WHITELIST.equals(this.page)) { - return this.builderWhitelist; + return this.previewWhitelist; } return null; @@ -83,7 +96,7 @@ public class ContentMultiplayer extends Content this.playerField = new GuiTextFieldTooltip(x + 118, y + this.page.getShift(), 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.username")); this.playerField.setFilter(Predicates.notNull()); this.playerField.setFocus(false); - this.playerField.setValue(this.builderKick.getPlayer()); + this.playerField.setValue(this.builderKick.targets().getTarget()); this.playerField.setMaxLength(16); this.playerField.setResponder(text -> { @@ -94,7 +107,7 @@ public class ContentMultiplayer extends Content this.reasonField = new GuiTextFieldTooltip(x + 118, y + 24 + this.page.getShift(), 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.kick_ban.reason")); this.reasonField.setFilter(Predicates.notNull()); this.reasonField.setFocus(false); - this.reasonField.setValue(this.builderKick.getReason()); + this.reasonField.setValue(this.builderKick.reason().get()); this.reasonField.setResponder(text -> { this.setReason(this.reasonField.getValue()); @@ -145,13 +158,13 @@ public class ContentMultiplayer extends Content { container.add(this.playerField); container.add(this.reasonField); - container.add(button6 = new GuiButtonTooltip(x + 118, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.kick"), new TextComponent(this.builderKick.toActualCommand()), () -> + container.add(button6 = new GuiButtonTooltip(x + 118, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.kick"), new TextComponent(this.builderKick.toCommand(KickCommandBuilder.Label.KICK_REASON, false)), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderKick); + CommandHelper.sendCommand(container.getPlayer(), this.builderKick, KickCommandBuilder.Label.KICK_REASON); })); - container.add(button7 = new GuiButtonTooltip(x + 118, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.ban"), new TextComponent(this.builderBan.toActualCommand()), () -> + container.add(button7 = new GuiButtonTooltip(x + 118, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.ban"), new TextComponent(this.builderBan.toCommand(BanCommandBuilder.Label.BAN_REASON, false)), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderBan); + CommandHelper.sendCommand(container.getPlayer(), this.builderBan, BanCommandBuilder.Label.BAN_REASON); })); if(this.playerField.getValue().isEmpty()) @@ -165,9 +178,9 @@ public class ContentMultiplayer extends Content else if(Page.PARDON.equals(this.page)) { container.add(this.playerField); - container.add(button6 = new GuiButtonTooltip(x + 118, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.pardon"), new TextComponent(this.builderPardon.toActualCommand()), () -> + container.add(button6 = new GuiButtonTooltip(x + 118, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.pardon"), new TextComponent(this.builderPardon.toCommand(PardonCommandBuilder.Label.PARDON, false)), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderPardon); + CommandHelper.sendCommand(container.getPlayer(), this.builderPardon, PardonCommandBuilder.Label.PARDON); })); if(this.playerField.getValue().isEmpty()) @@ -180,13 +193,13 @@ public class ContentMultiplayer extends Content else if(Page.PERMISSIONS.equals(this.page)) { container.add(this.playerField); - container.add(button6 = new GuiButtonTooltip(x + 118, y + 24 + 12, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.permissions.give"), new TextComponent(this.builderOp.toActualCommand()), () -> + container.add(button6 = new GuiButtonTooltip(x + 118, y + 24 + 12, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.permissions.give"), new TextComponent(this.builderOp.toCommand(OpCommandBuilder.Label.OP, false)), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderOp); + CommandHelper.sendCommand(container.getPlayer(), this.builderOp, OpCommandBuilder.Label.OP); })); - container.add(button7 = new GuiButtonTooltip(x + 118, y + 48 + 12, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.permissions.take"), new TextComponent(this.builderDeop.toActualCommand()), () -> + container.add(button7 = new GuiButtonTooltip(x + 118, y + 48 + 12, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.permissions.take"), new TextComponent(this.builderDeop.toCommand(DeOpCommandBuilder.Label.DEOP, false)), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderDeop); + CommandHelper.sendCommand(container.getPlayer(), this.builderDeop, DeOpCommandBuilder.Label.DEOP); })); if(this.playerField.getValue().isEmpty()) @@ -199,21 +212,21 @@ public class ContentMultiplayer extends Content } else if(Page.RUNTIME.equals(this.page)) { - container.add(new GuiButtonTooltip(x + 118, y, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.runtime.save_world"), new TextComponent(this.builderSaveAll.toActualCommand()), () -> + container.add(new GuiButtonTooltip(x + 118, y, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.runtime.save_world"), new TextComponent(this.builderSaveAll.toCommand(SaveAllCommandBuilder.Label.SAVE_ALL, false)), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderSaveAll); + CommandHelper.sendCommand(container.getPlayer(), this.builderSaveAll, SaveAllCommandBuilder.Label.SAVE_ALL); })); - container.add(new GuiButtonTooltip(x + 118, y + 24, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.runtime.autosave", new TranslatableComponent("gui.worldhandler.generic.on")), new TextComponent(this.builderSaveOn.toActualCommand()), () -> + container.add(new GuiButtonTooltip(x + 118, y + 24, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.runtime.autosave", new TranslatableComponent("gui.worldhandler.generic.on")), new TextComponent(this.builderSaveOn.toCommand(SaveOnCommandBuilder.Label.SAVE_ON, false)), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderSaveOn); + CommandHelper.sendCommand(container.getPlayer(), this.builderSaveOn, SaveOnCommandBuilder.Label.SAVE_ON); })); - container.add(new GuiButtonTooltip(x + 118, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.runtime.autosave", new TranslatableComponent("gui.worldhandler.generic.off")).withStyle(ChatFormatting.RED), new TextComponent(this.builderSaveOff.toActualCommand()), () -> + container.add(new GuiButtonTooltip(x + 118, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.runtime.autosave", new TranslatableComponent("gui.worldhandler.generic.off")).withStyle(ChatFormatting.RED), new TextComponent(this.builderSaveOff.toCommand(SaveOffCommandBuilder.Label.SAVE_OFF, false)), () -> { - ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderSaveOff)); + ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderSaveOff, SaveOffCommandBuilder.Label.SAVE_OFF)); })); - container.add(new GuiButtonTooltip(x + 118, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.runtime.stop_server").withStyle(ChatFormatting.RED), new TextComponent(this.builderStop.toActualCommand()), () -> + container.add(new GuiButtonTooltip(x + 118, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.runtime.stop_server").withStyle(ChatFormatting.RED), new TextComponent(this.builderStop.toCommand(StopCommandBuilder.Label.STOP, false)), () -> { - ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderStop)); + ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderStop, StopCommandBuilder.Label.STOP)); })); button4.active = false; @@ -223,25 +236,25 @@ public class ContentMultiplayer extends Content container.add(this.playerField); container.add(button6 = new GuiButtonBase(x + 118, y + 24, 44, 20, new TranslatableComponent("gui.worldhandler.multiplayer.whitelist.add"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderWhitelist.build(EnumMode.ADD)); + CommandHelper.sendCommand(container.getPlayer(), this.builderWhitelist, WhitelistCommandBuilder.Label.ADD); })); container.add(button7 = new GuiButtonBase(x + 118 + 47, y + 24, 44, 20, new TranslatableComponent("gui.worldhandler.multiplayer.whitelist.remove"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderWhitelist.build(EnumMode.REMOVE)); + CommandHelper.sendCommand(container.getPlayer(), this.builderWhitelist, WhitelistCommandBuilder.Label.REMOVE); })); container.add(new GuiButtonBase(x + 118, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.whitelist.whitelist", new TranslatableComponent("gui.worldhandler.generic.on")), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderWhitelist.build(EnumMode.ON)); + CommandHelper.sendCommand(container.getPlayer(), this.builderWhitelist, WhitelistCommandBuilder.Label.ON); })); container.add(new GuiButtonBase(x + 118, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.multiplayer.whitelist.whitelist", new TranslatableComponent("gui.worldhandler.generic.off")), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderWhitelist.build(EnumMode.OFF)); + CommandHelper.sendCommand(container.getPlayer(), this.builderWhitelist, WhitelistCommandBuilder.Label.OFF); })); container.add(new GuiButtonIcon(x + 232 - 20, y + 24, 20, 20, EnumIcon.RELOAD, new TranslatableComponent("gui.worldhandler.multiplayer.whitelist.reload"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderWhitelist.build(EnumMode.RELOAD)); + CommandHelper.sendCommand(container.getPlayer(), this.builderWhitelist, WhitelistCommandBuilder.Label.RELOAD); })); if(this.playerField.getValue().isEmpty()) @@ -284,20 +297,18 @@ public class ContentMultiplayer extends Content private void setPlayer(String player) { - this.builderBan.setPlayer(player); - this.builderKick.setPlayer(player); - - this.builderPardon.setPlayer(player); - this.builderOp.setPlayer(player); - this.builderDeop.setPlayer(player); - - this.builderWhitelist.setPlayer(player); + this.builderBan.targets().setTarget(player); + this.builderKick.targets().setTarget(player); + this.builderPardon.targets().setTarget(player); + this.builderOp.targets().setTarget(player); + this.builderDeop.targets().setTarget(player); + this.builderWhitelist.targets().setTarget(player); } private void setReason(String reason) { - this.builderBan.setReason(reason); - this.builderKick.setReason(reason); + this.builderBan.reason().set(reason); + this.builderKick.reason().set(reason); } @Override diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentNoteEditor.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentNoteEditor.java index 4ef7b16..ccac8e3 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentNoteEditor.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentNoteEditor.java @@ -4,8 +4,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import exopandora.worldhandler.Main; -import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.impl.BuilderNoteEditor; +import exopandora.worldhandler.builder.impl.SetBlockCommandBuilder; import exopandora.worldhandler.config.Config; import exopandora.worldhandler.event.KeyHandler; import exopandora.worldhandler.gui.category.Categories; @@ -30,27 +29,32 @@ import net.minecraft.sounds.SoundEvent; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.NoteBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.NoteBlockInstrument; public class ContentNoteEditor extends Content { private static final ResourceLocation NOTE = new ResourceLocation(Main.MODID, "textures/misc/note.png"); - private final BuilderNoteEditor builderNoteEditor = new BuilderNoteEditor(); + + private final SetBlockCommandBuilder builderNoteEditor = new SetBlockCommandBuilder(); + private final CommandPreview preview = new CommandPreview(this.builderNoteEditor, SetBlockCommandBuilder.Label.REPLACE); private boolean isActive; @Override - public ICommandBuilder getCommandBuilder() + public CommandPreview getCommandPreview() { - return this.isActive ? this.builderNoteEditor : null; + return this.isActive ? this.preview : null; } @Override public void init(Container container) { this.isActive = BlockHelper.getFocusedBlock() instanceof NoteBlock; - this.builderNoteEditor.setPosition(BlockHelper.getFocusedBlockPos()); + this.builderNoteEditor.pos().set(BlockHelper.getFocusedBlockPos()); } @Override @@ -61,118 +65,55 @@ public class ContentNoteEditor extends Content if(this.isActive) { - BlockPos pos = this.builderNoteEditor.getBlockPos(); + BlockPos pos = this.builderNoteEditor.pos().getBlockPos(); SoundEvent sound = this.getSoundEvent(pos.below()); - container.add(new GuiButtonPiano(x - 3 + 15, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.g"), sound, 0.53F, Type.NORMAL, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(1)); - })); - container.add(new GuiButtonPiano(x - 3 + 15 * 2, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.a"), sound, 0.6F, Type.NORMAL, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(3)); - })); - container.add(new GuiButtonPiano(x - 3 + 15 * 3, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.b"), sound, 0.67F, Type.RIGHT, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(5)); - })); + container.add(new GuiButtonPiano(x - 3 + 15, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.g"), sound, 0.53F, Type.NORMAL, () -> this.setNote(container.getPlayer(), 1))); + container.add(new GuiButtonPiano(x - 3 + 15 * 2, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.a"), sound, 0.6F, Type.NORMAL, () -> this.setNote(container.getPlayer(), 3))); + container.add(new GuiButtonPiano(x - 3 + 15 * 3, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.b"), sound, 0.67F, Type.RIGHT, () -> this.setNote(container.getPlayer(), 5))); - container.add(new GuiButtonPiano(x - 3 + 15 * 4, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.c"), sound, 0.7F, Type.LEFT, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(6)); - })); - container.add(new GuiButtonPiano(x - 3 + 15 * 5, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.d"), sound, 0.8F, Type.NORMAL, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(8)); - })); - container.add(new GuiButtonPiano(x - 3 + 15 * 6, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.e"), sound, 0.9F, Type.RIGHT, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(10)); - })); - container.add(new GuiButtonPiano(x - 3 + 15 * 7, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.f"), sound, 0.95F, Type.LEFT, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(11)); - })); - container.add(new GuiButtonPiano(x - 3 + 15 * 8, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.g"), sound, 1.05F, Type.NORMAL, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(13)); - })); - container.add(new GuiButtonPiano(x - 3 + 15 * 9, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.a"), sound, 1.2F, Type.NORMAL, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(15)); - })); - container.add(new GuiButtonPiano(x - 3 + 15 * 10, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.b"), sound, 1.32F, Type.RIGHT, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(17)); - })); + container.add(new GuiButtonPiano(x - 3 + 15 * 4, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.c"), sound, 0.7F, Type.LEFT, () -> this.setNote(container.getPlayer(), 6))); + container.add(new GuiButtonPiano(x - 3 + 15 * 5, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.d"), sound, 0.8F, Type.NORMAL, () -> this.setNote(container.getPlayer(), 8))); + container.add(new GuiButtonPiano(x - 3 + 15 * 6, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.e"), sound, 0.9F, Type.RIGHT, () -> this.setNote(container.getPlayer(), 10))); + container.add(new GuiButtonPiano(x - 3 + 15 * 7, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.f"), sound, 0.95F, Type.LEFT, () -> this.setNote(container.getPlayer(), 11))); + container.add(new GuiButtonPiano(x - 3 + 15 * 8, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.g"), sound, 1.05F, Type.NORMAL, () -> this.setNote(container.getPlayer(), 13))); + container.add(new GuiButtonPiano(x - 3 + 15 * 9, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.a"), sound, 1.2F, Type.NORMAL, () -> this.setNote(container.getPlayer(), 15))); + container.add(new GuiButtonPiano(x - 3 + 15 * 10, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.b"), sound, 1.32F, Type.RIGHT, () -> this.setNote(container.getPlayer(), 17))); - container.add(new GuiButtonPiano(x - 3 + 15 * 11, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.c"), sound, 1.4F, Type.LEFT, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(18)); - })); - container.add(new GuiButtonPiano(x - 3 + 15 * 12, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.d"), sound, 1.6F, Type.NORMAL, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(20)); - })); - container.add(new GuiButtonPiano(x - 3 + 15 * 13, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.e"), sound, 1.8F, Type.RIGHT, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(22)); - })); - container.add(new GuiButtonPiano(x - 3 + 15 * 14, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.f"), sound, 1.9F, Type.LEFT, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(23)); - })); + container.add(new GuiButtonPiano(x - 3 + 15 * 11, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.c"), sound, 1.4F, Type.LEFT, () -> this.setNote(container.getPlayer(), 18))); + container.add(new GuiButtonPiano(x - 3 + 15 * 12, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.d"), sound, 1.6F, Type.NORMAL, () -> this.setNote(container.getPlayer(), 20))); + container.add(new GuiButtonPiano(x - 3 + 15 * 13, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.e"), sound, 1.8F, Type.RIGHT, () -> this.setNote(container.getPlayer(), 22))); + container.add(new GuiButtonPiano(x - 3 + 15 * 14, y, 14, 92, new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.f"), sound, 1.9F, Type.LEFT, () -> this.setNote(container.getPlayer(), 23))); - container.add(new GuiButtonPiano(x - 3 - 5 + 15, y, 9, 58, new TextComponent("F#"), sound, 0.5F, Type.BLACK, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(0)); - })); - container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 2, y, 9, 58, new TextComponent("G#"), sound, 0.56F, Type.BLACK, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(2)); - })); - container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 3, y, 9, 58, new TextComponent("A#"), sound, 0.63F, Type.BLACK, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(4)); - })); + container.add(new GuiButtonPiano(x - 3 - 5 + 15, y, 9, 58, new TextComponent("F#"), sound, 0.5F, Type.BLACK, () -> this.setNote(container.getPlayer(), 0))); + container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 2, y, 9, 58, new TextComponent("G#"), sound, 0.56F, Type.BLACK, () -> this.setNote(container.getPlayer(), 2))); + container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 3, y, 9, 58, new TextComponent("A#"), sound, 0.63F, Type.BLACK, () -> this.setNote(container.getPlayer(), 4))); - container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 5, y, 9, 58, new TextComponent("C#"), sound, 0.75F, Type.BLACK, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(7)); - })); - container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 6, y, 9, 58, new TextComponent("D#"), sound, 0.85F, Type.BLACK, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(9)); - })); + container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 5, y, 9, 58, new TextComponent("C#"), sound, 0.75F, Type.BLACK, () -> this.setNote(container.getPlayer(), 7))); + container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 6, y, 9, 58, new TextComponent("D#"), sound, 0.85F, Type.BLACK, () -> this.setNote(container.getPlayer(), 9))); - container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 8, y, 9, 58, new TextComponent("F#"), sound, 1.0F, Type.BLACK, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(12)); - })); - container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 9, y, 9, 58, new TextComponent("G#"), sound, 1.1F, Type.BLACK, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(14)); - })); - container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 10, y, 9, 58, new TextComponent("A#"), sound, 1.25F, Type.BLACK, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(16)); - })); + container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 8, y, 9, 58, new TextComponent("F#"), sound, 1.0F, Type.BLACK, () -> this.setNote(container.getPlayer(), 12))); + container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 9, y, 9, 58, new TextComponent("G#"), sound, 1.1F, Type.BLACK, () -> this.setNote(container.getPlayer(), 14))); + container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 10, y, 9, 58, new TextComponent("A#"), sound, 1.25F, Type.BLACK, () -> this.setNote(container.getPlayer(), 16))); - container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 12, y, 9, 58, new TextComponent("C#"), sound, 1.5F, Type.BLACK, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(19)); - })); - container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 13, y, 9, 58, new TextComponent("D#"), sound, 1.7F, Type.BLACK, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(21)); - })); - container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 15, y, 9, 58, new TextComponent("F#"), sound, 2.0F, Type.BLACK, () -> - { - CommandHelper.sendCommand(container.getPlayer(), this.builderNoteEditor.build(24)); - })); + container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 12, y, 9, 58, new TextComponent("C#"), sound, 1.5F, Type.BLACK, () -> this.setNote(container.getPlayer(), 19))); + container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 13, y, 9, 58, new TextComponent("D#"), sound, 1.7F, Type.BLACK, () -> this.setNote(container.getPlayer(), 21))); + container.add(new GuiButtonPiano(x - 3 - 5 + 15 * 15, y, 9, 58, new TextComponent("F#"), sound, 2.0F, Type.BLACK, () -> this.setNote(container.getPlayer(), 24))); } } + private void setNote(String player, int note) + { + SetBlockCommandBuilder builder = new SetBlockCommandBuilder(); + builder.pos().set(this.builderNoteEditor.pos().getBlockPos()); + NoteBlockInstrument instrument = NoteBlockInstrument.byState(Minecraft.getInstance().level.getBlockState(this.builderNoteEditor.pos().getBlockPos().below())); + BlockState state = Blocks.NOTE_BLOCK.defaultBlockState() + .setValue(BlockStateProperties.NOTEBLOCK_INSTRUMENT, instrument) + .setValue(BlockStateProperties.NOTE, note); + builder.block().set(state); + CommandHelper.sendCommand(player, builder, SetBlockCommandBuilder.Label.REPLACE); + } + @Override public void drawScreen(PoseStack matrix, Container container, int x, int y, int mouseX, int mouseY, float partialTicks) { @@ -192,7 +133,7 @@ public class ContentNoteEditor extends Content } else { - float scale = 4; + float scale = 4; PoseStack posestack = RenderSystem.getModelViewStack(); posestack.pushPose(); @@ -204,7 +145,7 @@ public class ContentNoteEditor extends Content posestack.popPose(); RenderSystem.applyModelViewMatrix(); - TranslatableComponent text = new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.look_at_note_block", KeyHandler.KEY_WORLD_HANDLER.getTranslatedKeyMessage()); + TranslatableComponent text = new TranslatableComponent("gui.worldhandler.blocks.note_block_editor.look_at_note_block", KeyHandler.KEY_WORLD_HANDLER.getTranslatedKeyMessage()); Font font = Minecraft.getInstance().font; font.draw(matrix, text, x + 116 - font.width(text) / 2, y + 70, Config.getSkin().getLabelColor()); } @@ -215,9 +156,9 @@ public class ContentNoteEditor extends Content Level level = Minecraft.getInstance().level; if(level != null) - { + { return NoteBlockInstrument.byState(level.getBlockState(blockPos)).getSoundEvent(); - } + } return null; } diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentPlayer.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentPlayer.java index 169686d..46cfdb8 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentPlayer.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentPlayer.java @@ -3,11 +3,10 @@ package exopandora.worldhandler.gui.content.impl; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.impl.BuilderGeneric; -import exopandora.worldhandler.builder.impl.BuilderMultiCommand; -import exopandora.worldhandler.builder.impl.BuilderPlayer; -import exopandora.worldhandler.builder.impl.BuilderSpawnpoint; +import exopandora.worldhandler.builder.impl.ClearInventoryCommandBuilder; +import exopandora.worldhandler.builder.impl.KillCommandBuilder; +import exopandora.worldhandler.builder.impl.SetSpawnCommandBuilder; +import exopandora.worldhandler.builder.impl.SetWorldSpawnCommandBuilder; import exopandora.worldhandler.gui.category.Categories; import exopandora.worldhandler.gui.category.Category; import exopandora.worldhandler.gui.container.Container; @@ -38,19 +37,22 @@ public class ContentPlayer extends Content private GuiTextFieldTooltip coinsField; private GuiTextFieldTooltip xpField; - private final BuilderGeneric builderSetworldspawn = new BuilderGeneric("setworldspawn"); - private final BuilderSpawnpoint builderSpawnpoint = new BuilderSpawnpoint(); - private final BuilderPlayer builderKill = new BuilderPlayer("kill"); - private final BuilderGeneric builderClear = new BuilderGeneric("clear"); - - private final BuilderMultiCommand builderMiscellaneous = new BuilderMultiCommand(this.builderSetworldspawn, this.builderSpawnpoint, this.builderKill, this.builderClear); + private final SetWorldSpawnCommandBuilder builderSetWorldSpawn = new SetWorldSpawnCommandBuilder(); + private final SetSpawnCommandBuilder builderSpawnpoint = new SetSpawnCommandBuilder(); + private final KillCommandBuilder builderKill = new KillCommandBuilder(); + private final ClearInventoryCommandBuilder builderClear = new ClearInventoryCommandBuilder(); + private final CommandPreview preview = new CommandPreview() + .add(this.builderSetWorldSpawn, SetWorldSpawnCommandBuilder.Label.SET_WORLD_SPAWN) + .add(this.builderSpawnpoint, SetSpawnCommandBuilder.Label.SPAWNPOINT) + .add(this.builderKill, KillCommandBuilder.Label.KILL) + .add(this.builderClear, ClearInventoryCommandBuilder.Label.CLEAR); @Override - public ICommandBuilder getCommandBuilder() + public CommandPreview getCommandPreview() { if(Page.MISC.equals(this.page)) { - return this.builderMiscellaneous; + return this.preview; } return null; @@ -130,19 +132,19 @@ public class ContentPlayer extends Content container.add(new GuiButtonBase(x + 118, y, 114, 20, new TranslatableComponent("gui.worldhandler.entities.player.miscellaneous.set_spawn").withStyle(ChatFormatting.RED), () -> { - ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderSpawnpoint)); + ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderSpawnpoint, SetSpawnCommandBuilder.Label.SPAWNPOINT)); })); container.add(new GuiButtonBase(x + 118, y + 24, 114, 20, new TranslatableComponent("gui.worldhandler.entities.player.miscellaneous.set_global_spawn").withStyle(ChatFormatting.RED), () -> { - ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderSetworldspawn)); + ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderSetWorldSpawn, SetWorldSpawnCommandBuilder.Label.SET_WORLD_SPAWN)); })); container.add(new GuiButtonBase(x + 118, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.entities.player.miscellaneous.kill").withStyle(ChatFormatting.RED), () -> { - ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderKill)); + ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderKill, KillCommandBuilder.Label.KILL)); })); container.add(new GuiButtonBase(x + 118, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.entities.player.miscellaneous.clear_inventory").withStyle(ChatFormatting.RED), () -> { - ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderClear)); + ActionHelper.open(Contents.CONTINUE.withBuilder(this.builderClear, ClearInventoryCommandBuilder.Label.CLEAR)); })); } } @@ -198,8 +200,8 @@ public class ContentPlayer extends Content @Override public void onPlayerNameChanged(String username) { - this.builderSpawnpoint.setPlayer(username); - this.builderKill.setPlayer(username); + this.builderSpawnpoint.targets().setTarget(username); + this.builderKill.targets().setTarget(username); } @Override diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentPotions.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentPotions.java index 42616a4..9855553 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentPotions.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentPotions.java @@ -2,18 +2,18 @@ package exopandora.worldhandler.gui.content.impl; import java.util.ArrayList; -import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.impl.BuilderMultiCommand; -import exopandora.worldhandler.builder.impl.BuilderPotionEffect; -import exopandora.worldhandler.builder.impl.BuilderPotionItem; +import exopandora.worldhandler.builder.argument.tag.CustomPotionEffectsTag; +import exopandora.worldhandler.builder.argument.tag.EffectInstance; +import exopandora.worldhandler.builder.impl.EffectCommandBuilder; +import exopandora.worldhandler.builder.impl.GiveCommandBuilder; import exopandora.worldhandler.config.Config; import exopandora.worldhandler.gui.container.Container; -import exopandora.worldhandler.gui.menu.impl.ILogicPageList; -import exopandora.worldhandler.gui.menu.impl.MenuPageList; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; import exopandora.worldhandler.gui.widget.button.GuiButtonTooltip; import exopandora.worldhandler.gui.widget.button.GuiSlider; import exopandora.worldhandler.gui.widget.button.LogicSliderSimple; +import exopandora.worldhandler.gui.widget.menu.impl.ILogicPageList; +import exopandora.worldhandler.gui.widget.menu.impl.MenuPageList; import exopandora.worldhandler.util.ActionHandler; import exopandora.worldhandler.util.ActionHelper; import exopandora.worldhandler.util.CommandHelper; @@ -22,37 +22,49 @@ import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; import net.minecraftforge.registries.ForgeRegistries; public class ContentPotions extends ContentChild { + private final EffectCommandBuilder builderPotion = new EffectCommandBuilder(); + private final CustomPotionEffectsTag effects = new CustomPotionEffectsTag(); + private final GiveCommandBuilder builderPotionItem = new GiveCommandBuilder(); + private final CommandPreview preview = new CommandPreview() + .add(this.builderPotion, EffectCommandBuilder.Label.GIVE_SECONDS_AMPLIFIER_HIDEPARTICLES) + .add(this.builderPotionItem, GiveCommandBuilder.Label.GIVE_COUNT); + private int potionPage; - private final BuilderPotionEffect builderPotion = new BuilderPotionEffect(); - private final BuilderPotionItem builderPotionItem = new BuilderPotionItem(); + public ContentPotions() + { + this.builderPotionItem.item().addTagProvider(this.effects); + this.builderPotion.amplifier().set((byte) 0); + this.builderPotion.hideParticles().set(false); + } @Override - public ICommandBuilder getCommandBuilder() + public CommandPreview getCommandPreview() { - return new BuilderMultiCommand(this.builderPotion, this.builderPotionItem); + return this.preview; } @Override public void init(Container container) { - if(this.builderPotion.getAmplifier() > Config.getSliders().getMaxPotionAmplifier()) + if(this.builderPotion.amplifier().get() > Config.getSliders().getMaxPotionAmplifier()) { - this.builderPotion.setAmplifier((byte) Config.getSliders().getMaxPotionAmplifier()); + this.builderPotion.amplifier().set((byte) Config.getSliders().getMaxPotionAmplifier()); } - for(MobEffect potion : this.builderPotionItem.getMobEffects()) + for(MobEffect effect : this.effects.getMobEffects()) { - byte amplifier = this.builderPotionItem.getAmplifier(potion); + EffectInstance tag = this.effects.getOrCreate(effect); - if(amplifier > Config.getSliders().getMaxPotionAmplifier()) + if(tag.getAmplifier() > Config.getSliders().getMaxPotionAmplifier()) { - this.builderPotionItem.setAmplifier(potion, (byte) Config.getSliders().getMaxPotionAmplifier()); + tag.setAmplifier((byte) Config.getSliders().getMaxPotionAmplifier()); } } } @@ -63,28 +75,37 @@ public class ContentPotions extends ContentChild MenuPageList potions = new MenuPageList(x, y, new ArrayList(ForgeRegistries.MOB_EFFECTS.getValues()), 114, 20, 3, container, new ILogicPageList() { @Override - public MutableComponent translate(MobEffect item) + public MutableComponent translate(MobEffect effect) { - return new TranslatableComponent(item.getDescriptionId()); + return new TranslatableComponent(effect.getDescriptionId()); } @Override - public MutableComponent toTooltip(MobEffect item) + public MutableComponent toTooltip(MobEffect effect) { - return new TextComponent(item.getRegistryName().toString()); + return new TextComponent(effect.getRegistryName().toString()); } @Override - public void onClick(MobEffect item) + public void onClick(MobEffect effect) { - ContentPotions.this.builderPotion.setMobEffect(item); + ContentPotions.this.builderPotion.effect().set(effect); + + for(MobEffect entry : ContentPotions.this.effects.getMobEffects()) + { + if(!entry.equals(effect)) + { + ContentPotions.this.effects.remove(entry); + } + } + container.initButtons(); } @Override - public GuiButtonBase onRegister(int x, int y, int width, int height, MutableComponent text, MobEffect item, ActionHandler actionHandler) + public GuiButtonBase onRegister(int x, int y, int width, int height, MutableComponent text, MobEffect effect, ActionHandler actionHandler) { - return new GuiButtonTooltip(x, y, width, height, text, this.toTooltip(item), actionHandler); + return new GuiButtonTooltip(x, y, width, height, text, this.toTooltip(effect), actionHandler); } @Override @@ -117,90 +138,92 @@ public class ContentPotions extends ContentChild })); container.add(new GuiButtonBase(x + 118, y + 36, 114, 20, new TranslatableComponent("gui.worldhandler.potions.effect.remove"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderPotion.buildRemove()); + CommandHelper.sendCommand(container.getPlayer(), this.builderPotion, EffectCommandBuilder.Label.CLEAR_TARGETS_EFFECT); container.init(); })); container.add(new GuiButtonBase(x + 118, y + 60, 114, 20, new TranslatableComponent("gui.worldhandler.potions.effect.remove_all"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderPotion.buildClear()); + CommandHelper.sendCommand(container.getPlayer(), this.builderPotion, EffectCommandBuilder.Label.CLEAR); container.init(); })); } else if(this.potionPage == 1) { - MobEffect potion = this.builderPotion.getMobEffectAsPotion(); + MobEffect effect = this.builderPotion.effect().getEffect(); + EffectInstance tag = this.effects.getOrCreate(effect); - container.add(new GuiButtonBase(x + 118, y + 24, 114, 20, new TranslatableComponent("gui.worldhandler.potions.effect.ambient", this.builderPotionItem.getAmbient(potion) ? new TranslatableComponent("gui.worldhandler.generic.on") : new TranslatableComponent("gui.worldhandler.generic.off")), () -> + container.add(new GuiButtonBase(x + 118, y + 24, 114, 20, new TranslatableComponent("gui.worldhandler.potions.effect.ambient", tag.isAmbient() ? new TranslatableComponent("gui.worldhandler.generic.on") : new TranslatableComponent("gui.worldhandler.generic.off")), () -> { - this.builderPotionItem.setAmbient(potion, !this.builderPotionItem.getAmbient(potion)); + tag.setAmbient(!tag.isAmbient()); container.init(); })); - container.add(new GuiButtonBase(x + 118, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.potions.effect.particles", this.builderPotion.getHideParticles() ? new TranslatableComponent("gui.worldhandler.generic.off") : new TranslatableComponent("gui.worldhandler.generic.on")), () -> + container.add(new GuiButtonBase(x + 118, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.potions.effect.particles", this.builderPotion.hideParticles().get() ? new TranslatableComponent("gui.worldhandler.generic.off") : new TranslatableComponent("gui.worldhandler.generic.on")), () -> { - this.builderPotion.setHideParticles(!this.builderPotion.getHideParticles()); - this.builderPotionItem.setShowParticles(potion, !this.builderPotionItem.getShowParticles(potion)); + this.builderPotion.hideParticles().set(!this.builderPotion.hideParticles().get()); + tag.setShowParticles(!tag.doShowParticles()); container.init(); })); - container.add(new GuiSlider(x + 118, y, 114, 20, 0, Config.getSliders().getMaxPotionAmplifier(), 0, container, new LogicSliderSimple("amplifier" + potion.getRegistryName(), new TranslatableComponent("gui.worldhandler.potions.effect.amplifier"), value -> + container.add(new GuiSlider(x + 118, y, 114, 20, 1, Config.getSliders().getMaxPotionAmplifier(), 1, container, new LogicSliderSimple("amplifier" + effect.getRegistryName(), new TranslatableComponent("gui.worldhandler.potions.effect.amplifier"), value -> { - this.builderPotion.setAmplifier(value.byteValue()); - this.builderPotionItem.setAmplifier(potion, value.byteValue()); + this.builderPotion.amplifier().set((byte) (value.byteValue() - 1)); + tag.setAmplifier(value.byteValue()); }))); } else if(this.potionPage == 2) { - MobEffect potion = this.builderPotion.getMobEffectAsPotion(); + MobEffect effect = this.builderPotion.effect().getEffect(); + EffectInstance tag = this.effects.getOrCreate(effect); - container.add(new GuiSlider(x + 118, y, 114, 20, 0, 59, 0, container, new LogicSliderSimple("s" + potion.getRegistryName(), new TranslatableComponent("gui.worldhandler.potion.time.seconds"), value -> + container.add(new GuiSlider(x + 118, y, 114, 20, 0, 59, 0, container, new LogicSliderSimple("s" + effect.getRegistryName(), new TranslatableComponent("gui.worldhandler.potion.time.seconds"), value -> { - this.builderPotion.setSeconds(value.intValue()); - this.builderPotionItem.setSeconds(potion, value.intValue()); + tag.setSeconds(value.intValue()); + this.builderPotion.seconds().set(tag.toSeconds()); }))); - container.add(new GuiSlider(x + 118, y + 24, 114, 20, 0, 59, 0, container, new LogicSliderSimple("m" + potion.getRegistryName(), new TranslatableComponent("gui.worldhandler.potion.time.minutes"), value -> + container.add(new GuiSlider(x + 118, y + 24, 114, 20, 0, 59, 0, container, new LogicSliderSimple("m" + effect.getRegistryName(), new TranslatableComponent("gui.worldhandler.potion.time.minutes"), value -> { - this.builderPotion.setMinutes(value.intValue()); - this.builderPotionItem.setMinutes(potion, value.intValue()); + tag.setMinutes(value.intValue()); + this.builderPotion.seconds().set(tag.toSeconds()); }))); - container.add(new GuiSlider(x + 118, y + 48, 114, 20, 0, 99, 0, container, new LogicSliderSimple("h" + potion.getRegistryName(), new TranslatableComponent("gui.worldhandler.potion.time.hours"), value -> + container.add(new GuiSlider(x + 118, y + 48, 114, 20, 0, 99, 0, container, new LogicSliderSimple("h" + effect.getRegistryName(), new TranslatableComponent("gui.worldhandler.potion.time.hours"), value -> { - this.builderPotion.setHours(value.intValue()); - this.builderPotionItem.setHours(potion, value.intValue()); + tag.setHours(value.intValue()); + this.builderPotion.seconds().set(tag.toSeconds()); }))); } else if(this.potionPage == 3) { container.add(button1 = new GuiButtonBase(x + 118, y, 114, 20, new TranslatableComponent("gui.worldhandler.potions.effect"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderPotion.buildGive()); + CommandHelper.sendCommand(container.getPlayer(), this.builderPotion, EffectCommandBuilder.Label.GIVE_SECONDS_AMPLIFIER_HIDEPARTICLES); this.potionPage = 0; container.init(); })); container.add(button2 = new GuiButtonBase(x + 118, y + 24, 56, 20, new TranslatableComponent("gui.worldhandler.potions.effect.tipped_arrow"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderPotionItem.build(Items.TIPPED_ARROW)); + this.giveItem(container.getPlayer(), Items.TIPPED_ARROW, 0.125F); this.potionPage = 0; container.init(); })); container.add(button3 = new GuiButtonTooltip(x + 178, y + 24, 55, 20, new TranslatableComponent("gui.worldhandler.potions.effect.bottle"), new TranslatableComponent("gui.worldhandler.actions.place_command_block"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderPotionItem.build(Items.POTION)); + this.giveItem(container.getPlayer(), Items.POTION, 1.0F); this.potionPage = 0; container.init(); })); container.add(button4 = new GuiButtonTooltip(x + 118, y + 48, 56, 20, new TranslatableComponent("gui.worldhandler.potions.effect.splash"), new TranslatableComponent("gui.worldhandler.actions.place_command_block"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderPotionItem.build(Items.SPLASH_POTION)); + this.giveItem(container.getPlayer(), Items.SPLASH_POTION, 1.0F); this.potionPage = 0; container.init(); })); container.add(button5 = new GuiButtonTooltip(x + 178, y + 48, 55, 20, new TranslatableComponent("gui.worldhandler.potions.effect.lingering"), new TranslatableComponent("gui.worldhandler.actions.place_command_block"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderPotionItem.build(Items.LINGERING_POTION)); + this.giveItem(container.getPlayer(), Items.LINGERING_POTION, 0.25F); this.potionPage = 0; container.init(); })); - boolean enabled = this.builderPotion.getAmplifier() >= 0 && this.builderPotion.getDuration() > 0; + boolean enabled = this.builderPotion.amplifier().get() >= 0 && this.builderPotion.seconds().get() > 0; button1.active = enabled; button2.active = enabled; @@ -231,6 +254,28 @@ public class ContentPotions extends ContentChild container.init(); } + private void giveItem(String player, Item item, float modifier) + { + CustomPotionEffectsTag effects = new CustomPotionEffectsTag(); + MobEffect effect = this.builderPotion.effect().getEffect(); + EffectInstance tag = effects.getOrCreate(effect); + EffectInstance original = this.effects.getOrCreate(effect); + + tag.setAmbient(original.isAmbient()); + tag.setAmplifier(original.getAmplifier()); + tag.setHours((int) (original.getHours() / modifier)); + tag.setMinutes((int) (original.getMinutes() / modifier)); + tag.setSeconds((int) (original.getSeconds() / modifier)); + tag.setShowParticles(original.doShowParticles()); + + GiveCommandBuilder builder = new GiveCommandBuilder(); + builder.targets().setTarget(this.builderPotionItem.targets().getTarget()); + builder.item().set(item); + builder.item().addTagProvider(effects); + + CommandHelper.sendCommand(player, builder, GiveCommandBuilder.Label.GIVE); + } + @Override public MutableComponent getTitle() { @@ -240,7 +285,7 @@ public class ContentPotions extends ContentChild @Override public void onPlayerNameChanged(String username) { - this.builderPotion.setPlayer(username); - this.builderPotionItem.setPlayer(username); + this.builderPotion.targets().setTarget(username); + this.builderPotionItem.targets().setTarget(username); } } diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentRecipes.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentRecipes.java index aeeeaf1..391ac29 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentRecipes.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentRecipes.java @@ -3,18 +3,16 @@ package exopandora.worldhandler.gui.content.impl; import java.util.List; import java.util.stream.Collectors; -import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.impl.BuilderRecipe; -import exopandora.worldhandler.builder.impl.BuilderRecipe.EnumMode; +import exopandora.worldhandler.builder.impl.RecipeCommandBuilder; 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.gui.menu.impl.ILogicPageList; -import exopandora.worldhandler.gui.menu.impl.MenuPageList; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; import exopandora.worldhandler.gui.widget.button.GuiButtonTooltip; +import exopandora.worldhandler.gui.widget.menu.impl.ILogicPageList; +import exopandora.worldhandler.gui.widget.menu.impl.MenuPageList; import exopandora.worldhandler.util.ActionHandler; import exopandora.worldhandler.util.ActionHelper; import exopandora.worldhandler.util.CommandHelper; @@ -27,12 +25,13 @@ import net.minecraft.world.item.crafting.Recipe; public class ContentRecipes extends Content { - private final BuilderRecipe builderRecipe = new BuilderRecipe(); + private final RecipeCommandBuilder builderRecipe = new RecipeCommandBuilder(); + private final CommandPreview preview = new CommandPreview(this.builderRecipe, null); @Override - public ICommandBuilder getCommandBuilder() + public CommandPreview getCommandPreview() { - return this.builderRecipe; + return this.preview; } @Override @@ -46,33 +45,33 @@ public class ContentRecipes extends Content MenuPageList> list = new MenuPageList>(x, y, recipes, 114, 20, 3, container, new ILogicPageList>() { @Override - public MutableComponent translate(Recipe item) + public MutableComponent translate(Recipe recipe) { - if(!item.getResultItem().equals(ItemStack.EMPTY)) + if(!ItemStack.EMPTY.equals(recipe.getResultItem())) { - return (MutableComponent) item.getResultItem().getHoverName(); + return (MutableComponent) recipe.getResultItem().getHoverName(); } - return new TextComponent(item.getId().toString()); + return new TextComponent(recipe.getId().toString()); } @Override - public MutableComponent toTooltip(Recipe item) + public MutableComponent toTooltip(Recipe recipe) { - return new TextComponent(item.getId().toString()); + return new TextComponent(recipe.getId().toString()); } @Override - public void onClick(Recipe item) + public void onClick(Recipe recipe) { - ContentRecipes.this.builderRecipe.setRecipe(item); + ContentRecipes.this.builderRecipe.recipe().set(recipe.getId()); container.initButtons(); } @Override - public GuiButtonBase onRegister(int x, int y, int width, int height, MutableComponent text, Recipe item, ActionHandler actionHandler) + public GuiButtonBase onRegister(int x, int y, int width, int height, MutableComponent text, Recipe recipe, ActionHandler actionHandler) { - return new GuiButtonTooltip(x, y, width, height, text, this.toTooltip(item), actionHandler); + return new GuiButtonTooltip(x, y, width, height, text, this.toTooltip(recipe), actionHandler); } @Override @@ -93,12 +92,12 @@ public class ContentRecipes extends Content container.add(new GuiButtonBase(x + 118, y + 24, 114, 20, new TranslatableComponent("gui.worldhandler.recipes.give"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderRecipe.build(EnumMode.GIVE)); + CommandHelper.sendCommand(container.getPlayer(), this.builderRecipe, RecipeCommandBuilder.Label.GIVE); container.initButtons(); })); container.add(new GuiButtonBase(x + 118, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.recipes.take"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderRecipe.build(EnumMode.TAKE)); + CommandHelper.sendCommand(container.getPlayer(), this.builderRecipe, RecipeCommandBuilder.Label.TAKE); container.initButtons(); })); } @@ -130,6 +129,6 @@ public class ContentRecipes extends Content @Override public void onPlayerNameChanged(String username) { - this.builderRecipe.setPlayer(username); + this.builderRecipe.targets().setTarget(username); } } diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboard.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboard.java index 90108c9..c8bf505 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboard.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboard.java @@ -1,5 +1,6 @@ package exopandora.worldhandler.gui.content.impl; +import exopandora.worldhandler.builder.impl.ScoreboardCommandBuilder; import exopandora.worldhandler.gui.category.Categories; import exopandora.worldhandler.gui.category.Category; import exopandora.worldhandler.gui.content.Content; @@ -10,21 +11,11 @@ import net.minecraft.network.chat.TranslatableComponent; public abstract class ContentScoreboard extends Content { protected static final ScoreboardHelper HELPER = new ScoreboardHelper(); - private static String objective; + protected static final ScoreboardCommandBuilder BUILDER = new ScoreboardCommandBuilder(); - protected boolean isObjectiveValid() + static { - return ContentScoreboard.objective != null && ContentScoreboard.objective.length() > 0; - } - - protected void setObjective(String objective) - { - ContentScoreboard.objective = objective; - } - - protected String getObjective() - { - return ContentScoreboard.objective; + BUILDER.score().set(0); } @Override diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardObjectives.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardObjectives.java index 69583a0..5f9cab6 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardObjectives.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardObjectives.java @@ -8,16 +8,14 @@ import javax.annotation.Nullable; import com.google.common.base.Predicates; import com.mojang.blaze3d.vertex.PoseStack; -import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.impl.BuilderScoreboardObjectives; -import exopandora.worldhandler.builder.impl.BuilderScoreboardObjectives.EnumMode; +import exopandora.worldhandler.builder.impl.ScoreboardCommandBuilder; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.gui.content.Contents; -import exopandora.worldhandler.gui.menu.impl.ILogicButtonList; -import exopandora.worldhandler.gui.menu.impl.MenuButtonList; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; import exopandora.worldhandler.gui.widget.button.GuiTextFieldTooltip; +import exopandora.worldhandler.gui.widget.menu.impl.ILogicButtonList; +import exopandora.worldhandler.gui.widget.menu.impl.MenuButtonList; import exopandora.worldhandler.util.ActionHelper; import exopandora.worldhandler.util.CommandHelper; import exopandora.worldhandler.util.RegistryHelper; @@ -37,12 +35,10 @@ public class ContentScoreboardObjectives extends ContentScoreboard private GuiTextFieldTooltip objectField; private Page page = Page.CREATE; - private final BuilderScoreboardObjectives builderObjectives = new BuilderScoreboardObjectives(); - @Override - public ICommandBuilder getCommandBuilder() + public CommandPreview getCommandPreview() { - return this.builderObjectives; + return new CommandPreview(BUILDER, this.page.getLabel()); } @Override @@ -50,13 +46,13 @@ public class ContentScoreboardObjectives extends ContentScoreboard { this.objectField = new GuiTextFieldTooltip(x + 118, y + this.page.getShift(), 114, 20, new TranslatableComponent("gui.worldhandler.scoreboard.objectives.objective")); this.objectField.setFilter(Predicates.notNull()); - this.objectField.setValue(this.getObjective()); this.objectField.setResponder(text -> { - this.setObjective(text); - this.builderObjectives.setObjective(this.getObjective()); + BUILDER.objective().set(text); + BUILDER.displayName().deserialize(text); container.initButtons(); }); + this.objectField.setValue(BUILDER.objective().get()); if(Page.CREATE.equals(this.page)) { @@ -115,7 +111,7 @@ public class ContentScoreboardObjectives extends ContentScoreboard @Override public void onClick(String key, int depth) { - ContentScoreboardObjectives.this.builderObjectives.setCriteria(key); + BUILDER.criteria().set(key); } @Override @@ -188,7 +184,7 @@ public class ContentScoreboardObjectives extends ContentScoreboard @Override public void onClick(String key, int depth) { - ContentScoreboardObjectives.this.builderObjectives.setSlot(key); + BUILDER.slot().set(key); } @Override @@ -239,27 +235,17 @@ public class ContentScoreboardObjectives extends ContentScoreboard button3.active = !Page.UNDISPLAY.equals(this.page); button4.active = !Page.REMOVE.equals(this.page); - if(Page.UNDISPLAY.equals(this.page)) - { - this.builderObjectives.setObjective(null); - } - else if(Page.REMOVE.equals(this.page)) - { - this.builderObjectives.setMode(EnumMode.REMOVE); - } - if(!Page.UNDISPLAY.equals(this.page)) { container.add(this.objectField); - this.builderObjectives.setObjective(this.getObjective()); } container.add(button1 = new GuiButtonBase(x + 118, y + 72 - this.page.getShift(), 114, 20, new TranslatableComponent("gui.worldhandler.actions.perform"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderObjectives); + CommandHelper.sendCommand(container.getPlayer(), BUILDER, this.page.getLabel()); container.init(); })); - button1.active = Page.UNDISPLAY.equals(this.page) || this.isObjectiveValid(); + button1.active = Page.UNDISPLAY.equals(this.page) || BUILDER.objective().get() != null && !BUILDER.objective().get().isEmpty(); } @Override @@ -294,21 +280,28 @@ public class ContentScoreboardObjectives extends ContentScoreboard public static enum Page { - CREATE(0), - DISPLAY(0), - UNDISPLAY(12), - REMOVE(24); + CREATE(0, ScoreboardCommandBuilder.Label.OBJECTIVES_ADD_DISPLAYNAME), + DISPLAY(0, ScoreboardCommandBuilder.Label.OBJECTIVES_SETDISPLAY_SLOT_OBJECTIVE), + UNDISPLAY(12, ScoreboardCommandBuilder.Label.OBJECTIVES_SETDISPLAY_SLOT), + REMOVE(24, ScoreboardCommandBuilder.Label.OBJECTIVES_REMOVE); private final int shift; + private final ScoreboardCommandBuilder.Label label; - private Page(int shift) + private Page(int shift, ScoreboardCommandBuilder.Label label) { this.shift = shift; + this.label = label; } public int getShift() { return this.shift; } + + public ScoreboardCommandBuilder.Label getLabel() + { + return this.label; + } } } \ No newline at end of file diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardPlayers.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardPlayers.java index e823c72..c945464 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardPlayers.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardPlayers.java @@ -3,12 +3,9 @@ package exopandora.worldhandler.gui.content.impl; import com.google.common.base.Predicates; import com.mojang.blaze3d.vertex.PoseStack; -import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.impl.BuilderMultiCommand; -import exopandora.worldhandler.builder.impl.BuilderScoreboardPlayers; -import exopandora.worldhandler.builder.impl.BuilderScoreboardPlayers.EnumMode; -import exopandora.worldhandler.builder.impl.BuilderTag; -import exopandora.worldhandler.builder.impl.BuilderTrigger; +import exopandora.worldhandler.builder.impl.ScoreboardCommandBuilder; +import exopandora.worldhandler.builder.impl.TagCommandBuilder; +import exopandora.worldhandler.builder.impl.TriggerCommandBuilder; import exopandora.worldhandler.config.Config; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.content.Content; @@ -25,51 +22,53 @@ import net.minecraft.network.chat.TranslatableComponent; public class ContentScoreboardPlayers extends ContentScoreboard { - private GuiTextFieldTooltip objectField; - private GuiTextFieldTooltip tagField; - - private final BuilderScoreboardPlayers builderPlayers = new BuilderScoreboardPlayers(); - private final BuilderTag builderTag = new BuilderTag(); - private final BuilderTrigger builderTrigger = new BuilderTrigger(); - private final BuilderMultiCommand builderTriggerMulti = new BuilderMultiCommand(this.builderTrigger, this.builderPlayers); + private final TagCommandBuilder builderTag = new TagCommandBuilder(); + private final TriggerCommandBuilder builderTrigger = new TriggerCommandBuilder(); + private final CommandPreview previewPlayers = new CommandPreview(BUILDER, ScoreboardCommandBuilder.Label.PLAYERS); + private final CommandPreview previewTag = new CommandPreview(this.builderTag, null); + private final CommandPreview previewTrigger = new CommandPreview() + .add(this.builderTrigger, null) + .add(BUILDER, ScoreboardCommandBuilder.Label.PLAYERS_ENABLE_OBJECTIVE); private Page page = Page.ADD_SET_REMOVE; - private String tag; - private GuiButtonBase addButton; private GuiButtonBase removeButton; + private GuiTextFieldTooltip objectField; + private GuiTextFieldTooltip tagField; + + public ContentScoreboardPlayers() + { + this.builderTrigger.value().set(0); + } @Override - public ICommandBuilder getCommandBuilder() + public CommandPreview getCommandPreview() { - if(Page.ADD_SET_REMOVE.equals(this.page)) + switch(this.page) { - return this.builderPlayers; + case ADD_SET_REMOVE: + return this.previewPlayers; + case ENABLE: + return this.previewTrigger; + case TAG: + return this.previewTag; + default: + return null; } - else if(Page.TAG.equals(this.page)) - { - return this.builderTag; - } - else if(Page.ENABLE.equals(this.page)) - { - return this.builderTriggerMulti; - } - - return null; } @Override public void init(Container container) { - if(this.builderPlayers.getPoints() > Config.getSliders().getMaxPlayerPoints()) + if(BUILDER.score().get() > Config.getSliders().getMaxPlayerPoints()) { - this.builderPlayers.setPoints((int) Config.getSliders().getMaxPlayerPoints()); + BUILDER.score().set((int) Config.getSliders().getMaxPlayerPoints()); } - if(this.builderTrigger.getValue() > Config.getSliders().getMaxTriggerValue()) + if(this.builderTrigger.value().get() > Config.getSliders().getMaxTriggerValue()) { - this.builderTrigger.setValue((int) Config.getSliders().getMaxTriggerValue()); + this.builderTrigger.value().set((int) Config.getSliders().getMaxTriggerValue()); } } @@ -78,22 +77,21 @@ public class ContentScoreboardPlayers extends ContentScoreboard { this.objectField = new GuiTextFieldTooltip(x + 118, y, 114, 20, new TranslatableComponent("gui.worldhandler.scoreboard.objectives.objective")); this.objectField.setFilter(Predicates.notNull()); - this.objectField.setValue(this.getObjective()); this.objectField.setResponder(text -> { - this.setObjective(text); - this.builderPlayers.setObjective(this.getObjective()); - this.builderTrigger.setObjective(this.getObjective()); + BUILDER.objective().set(text); + BUILDER.displayName().deserialize(text); + this.builderTrigger.objective().set(text); container.initButtons(); }); + this.objectField.setValue(BUILDER.objective().get()); this.tagField = new GuiTextFieldTooltip(x + 118, y + 12, 114, 20, new TranslatableComponent("gui.worldhandler.scoreboard.players.tag")); this.tagField.setFilter(string -> string != null && !string.contains(" ")); - this.tagField.setValue(this.tag); + this.tagField.setValue(this.builderTag.name().get()); this.tagField.setResponder(text -> { - this.tag = text; - this.builderTag.setName(this.tag); + this.builderTag.name().set(text); container.initButtons(); }); } @@ -128,51 +126,50 @@ public class ContentScoreboardPlayers extends ContentScoreboard button2.active = !Page.TAG.equals(this.page); button3.active = !Page.ENABLE.equals(this.page); - boolean enabled = this.isObjectiveValid(); - this.builderPlayers.setMode(this.page.getMode()); + boolean enabled = BUILDER.objective().get() != null && !BUILDER.objective().get().isEmpty(); if(Page.ADD_SET_REMOVE.equals(this.page)) { container.add(new GuiSlider(x + 118, y + 24, 114, 20, 0, Config.getSliders().getMaxPlayerPoints(), 0, container, new LogicSliderSimple("points", new TranslatableComponent("gui.worldhandler.scoreboard.players.points"), value -> { - this.builderPlayers.setPoints(value); + BUILDER.score().set(value); }))); container.add(this.addButton = new GuiButtonBase(x + 118, y + 48, 56, 20, new TranslatableComponent("gui.worldhandler.actions.add"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderPlayers.buildPoints(EnumMode.ADD)); + CommandHelper.sendCommand(container.getPlayer(), BUILDER, ScoreboardCommandBuilder.Label.PLAYERS_ADD_SCORE); container.init(); })); container.add(this.removeButton = new GuiButtonBase(x + 118 + 114 / 2 + 1, y + 48, 56, 20, new TranslatableComponent("gui.worldhandler.actions.remove"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderPlayers.buildPoints(EnumMode.REMOVE)); + CommandHelper.sendCommand(container.getPlayer(), BUILDER, ScoreboardCommandBuilder.Label.PLAYERS_REMOVE_SCORE); container.init(); })); container.add(button1 = new GuiButtonTooltip(x + 118, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.actions.reset"), new TranslatableComponent("gui.worldhandler.actions.set_to_0"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderPlayers.buildPoints(EnumMode.SET, 0)); + CommandHelper.sendCommand(container.getPlayer(), BUILDER, ScoreboardCommandBuilder.Label.PLAYERS_RESET_SCORE); container.init(); })); - boolean points = enabled && this.builderPlayers.getPoints() > 0; + boolean score = enabled && BUILDER.score().get() > 0; - this.addButton.active = points; - this.removeButton.active = points; + this.addButton.active = score; + this.removeButton.active = score; button1.active = enabled; } else if(Page.TAG.equals(this.page)) { container.add(button1 = new GuiButtonBase(x + 118, y + 36, 114, 20, new TranslatableComponent("gui.worldhandler.actions.add"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderTag.build(BuilderTag.EnumMode.ADD)); + CommandHelper.sendCommand(container.getPlayer(), this.builderTag, TagCommandBuilder.Label.ADD); container.init(); })); container.add(button2 = new GuiButtonBase(x + 118, y + 60, 114, 20, new TranslatableComponent("gui.worldhandler.actions.remove"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderTag.build(BuilderTag.EnumMode.REMOVE)); + CommandHelper.sendCommand(container.getPlayer(), this.builderTag, TagCommandBuilder.Label.REMOVE); container.init(); })); - boolean tag = this.tag != null && !this.tag.isEmpty(); + boolean tag = this.builderTag.name().get() != null && !this.builderTag.name().get().isEmpty(); button1.active = tag; button2.active = tag; @@ -181,25 +178,25 @@ public class ContentScoreboardPlayers extends ContentScoreboard { container.add(new GuiSlider(x + 118, y + 24, 114, 20, 0, Config.getSliders().getMaxTriggerValue(), 0, container, new LogicSliderSimple("enable", new TranslatableComponent("gui.worldhandler.generic.value"), value -> { - this.builderTrigger.setValue(value.intValue()); + this.builderTrigger.value().set(value); }))); container.add(this.addButton = new GuiButtonBase(x + 118, y + 48, 56, 20, new TranslatableComponent("gui.worldhandler.actions.add"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderTrigger.build(BuilderTrigger.EnumMode.ADD)); + CommandHelper.sendCommand(container.getPlayer(), this.builderTrigger, TriggerCommandBuilder.Label.ADD); container.init(); })); container.add(this.removeButton = new GuiButtonBase(x + 118 + 114 / 2 + 1, y + 48, 56, 20, new TranslatableComponent("gui.worldhandler.actions.set"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderTrigger.build(BuilderTrigger.EnumMode.SET)); + CommandHelper.sendCommand(container.getPlayer(), this.builderTrigger, TriggerCommandBuilder.Label.SET); container.init(); })); container.add(button1 = new GuiButtonBase(x + 118, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.generic.enable"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderPlayers.buildEnable()); + CommandHelper.sendCommand(container.getPlayer(), BUILDER, ScoreboardCommandBuilder.Label.PLAYERS_ENABLE_OBJECTIVE); container.init(); })); - this.addButton.active = enabled && this.builderTrigger.getValue() > 0; + this.addButton.active = enabled && this.builderTrigger.value().get() > 0; this.removeButton.active = enabled; button1.active = enabled; } @@ -211,8 +208,6 @@ public class ContentScoreboardPlayers extends ContentScoreboard else { container.add(this.objectField); - this.builderPlayers.setObjective(this.getObjective()); - this.builderTrigger.setObjective(this.getObjective()); } } @@ -225,18 +220,18 @@ public class ContentScoreboardPlayers extends ContentScoreboard } else { - boolean enabled = this.isObjectiveValid(); + boolean enabled = BUILDER.objective().get() != null && !BUILDER.objective().get().isEmpty(); if(Page.ADD_SET_REMOVE.equals(this.page)) { - boolean points = enabled && this.builderPlayers.getPoints() > 0; + boolean points = enabled && BUILDER.score().get() > 0; this.addButton.active = points; this.removeButton.active = points; } else if(Page.ENABLE.equals(this.page)) { - this.addButton.active = enabled && this.builderTrigger.getValue() > 0; + this.addButton.active = enabled && this.builderTrigger.value().get() > 0; this.removeButton.active = enabled; } @@ -272,26 +267,14 @@ public class ContentScoreboardPlayers extends ContentScoreboard @Override public void onPlayerNameChanged(String username) { - this.builderPlayers.setPlayer(username); - this.builderTag.setPlayer(username); + BUILDER.targets().setTarget(username); + this.builderTag.targets().setTarget(username); } public static enum Page { - ADD_SET_REMOVE("add|set|remove"), - TAG("tag"), - ENABLE("enable"); - - private final String mode; - - private Page(String mode) - { - this.mode = mode; - } - - public String getMode() - { - return this.mode; - } + ADD_SET_REMOVE, + TAG, + ENABLE; } } diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardTeams.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardTeams.java index 1f305da..e3d24c2 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardTeams.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardTeams.java @@ -6,16 +6,14 @@ import java.util.List; import com.google.common.base.Predicates; import com.mojang.blaze3d.vertex.PoseStack; -import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.impl.BuilderTeams; -import exopandora.worldhandler.builder.impl.BuilderTeams.EnumMode; +import exopandora.worldhandler.builder.impl.TeamCommandBuilder; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.gui.content.Contents; -import exopandora.worldhandler.gui.menu.impl.ILogicButtonList; -import exopandora.worldhandler.gui.menu.impl.MenuButtonList; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; import exopandora.worldhandler.gui.widget.button.GuiTextFieldTooltip; +import exopandora.worldhandler.gui.widget.menu.impl.ILogicButtonList; +import exopandora.worldhandler.gui.widget.menu.impl.MenuButtonList; import exopandora.worldhandler.util.ActionHelper; import exopandora.worldhandler.util.CommandHelper; import net.minecraft.ChatFormatting; @@ -26,17 +24,35 @@ import net.minecraft.network.chat.TranslatableComponent; public class ContentScoreboardTeams extends ContentScoreboard { - private GuiTextFieldTooltip teamField; + private final TeamCommandBuilder builderTeams = new TeamCommandBuilder(); + private final CommandPreview previewAdd = new CommandPreview(this.builderTeams, TeamCommandBuilder.Label.ADD_DISPLAYNAME); + private final CommandPreview previewJoinOrLeave = new CommandPreview() + .add(this.builderTeams, TeamCommandBuilder.Label.JOIN) + .add(this.builderTeams, TeamCommandBuilder.Label.LEAVE); + private final CommandPreview previewRemoveOrEmpty = new CommandPreview() + .add(this.builderTeams, TeamCommandBuilder.Label.REMOVE) + .add(this.builderTeams, TeamCommandBuilder.Label.EMPTY); + private final CommandPreview previewModify = new CommandPreview(this.builderTeams, TeamCommandBuilder.Label.MODIFY); - private String team; + private GuiTextFieldTooltip teamField; private Page page = Page.ADD; - private final BuilderTeams builderTeams = new BuilderTeams(); - @Override - public ICommandBuilder getCommandBuilder() + public CommandPreview getCommandPreview() { - return this.builderTeams; + switch(this.page) + { + case ADD: + return this.previewAdd; + case JOIN_OR_LEAVE: + return this.previewJoinOrLeave; + case REMOVE_OR_EMPTY: + return this.previewRemoveOrEmpty; + case OPTION: + return this.previewModify; + default: + return null; + } } @Override @@ -44,11 +60,11 @@ public class ContentScoreboardTeams extends ContentScoreboard { this.teamField = new GuiTextFieldTooltip(x + 118, y + this.page.getShift(), 114, 20, new TranslatableComponent("gui.worldhandler.scoreboard.team.team")); this.teamField.setFilter(Predicates.notNull()); - this.teamField.setValue(this.team); + this.teamField.setValue(this.builderTeams.team().get()); this.teamField.setResponder(text -> { - this.team = text; - this.builderTeams.setTeam(this.team); + this.builderTeams.team().set(text); + this.builderTeams.displayName().deserialize(text); container.initButtons(); }); @@ -87,11 +103,11 @@ public class ContentScoreboardTeams extends ContentScoreboard { if(depth == 0) { - ContentScoreboardTeams.this.builderTeams.setRule(key); + ContentScoreboardTeams.this.builderTeams.option().set(key); } else if(depth == 1) { - ContentScoreboardTeams.this.builderTeams.setValue(key); + ContentScoreboardTeams.this.builderTeams.value().set(key); } } @@ -143,26 +159,18 @@ public class ContentScoreboardTeams extends ContentScoreboard button3.active = !Page.REMOVE_OR_EMPTY.equals(this.page); button4.active = !Page.OPTION.equals(this.page); - this.builderTeams.setMode(this.page.getMode()); + boolean enabled = this.builderTeams.team().get() != null && !this.builderTeams.team().get().isEmpty(); - boolean enabled = this.team != null && this.team.length() > 0; - - if(Page.ADD.equals(this.page)) + if(Page.JOIN_OR_LEAVE.equals(this.page)) { - this.builderTeams.setTeam(this.team); - } - else if(Page.JOIN_OR_LEAVE.equals(this.page)) - { - this.builderTeams.setPlayer(container.getPlayer()); - container.add(button1 = new GuiButtonBase(x + 118, y + 36, 114, 20, new TranslatableComponent("gui.worldhandler.scoreboard.team.join"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderTeams.build(EnumMode.JOIN)); + CommandHelper.sendCommand(container.getPlayer(), this.builderTeams, TeamCommandBuilder.Label.JOIN); container.initButtons(); })); container.add(new GuiButtonBase(x + 118, y + 60, 114, 20, new TranslatableComponent("gui.worldhandler.scoreboard.team.leave"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderTeams.build(EnumMode.LEAVE)); + CommandHelper.sendCommand(container.getPlayer(), this.builderTeams, TeamCommandBuilder.Label.LEAVE); container.initButtons(); })); @@ -172,12 +180,12 @@ public class ContentScoreboardTeams extends ContentScoreboard { container.add(button1 = new GuiButtonBase(x + 118, y + 36, 114, 20, new TranslatableComponent("gui.worldhandler.scoreboard.team.remove"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderTeams.build(EnumMode.REMOVE)); + CommandHelper.sendCommand(container.getPlayer(), this.builderTeams, TeamCommandBuilder.Label.REMOVE); container.initButtons(); })); container.add(button2 = new GuiButtonBase(x + 118, y + 60, 114, 20, new TranslatableComponent("gui.worldhandler.scoreboard.team.empty"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderTeams.build(EnumMode.EMPTY)); + CommandHelper.sendCommand(container.getPlayer(), this.builderTeams, TeamCommandBuilder.Label.EMPTY); container.initButtons(); })); @@ -189,7 +197,14 @@ public class ContentScoreboardTeams extends ContentScoreboard { container.add(button1 = new GuiButtonBase(x + 118, y + 72 - this.page.getShift(), 114, 20, new TranslatableComponent("gui.worldhandler.actions.perform"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderTeams); + if(Page.ADD.equals(this.page)) + { + CommandHelper.sendCommand(container.getPlayer(), this.builderTeams, TeamCommandBuilder.Label.ADD_DISPLAYNAME); + } + else if(Page.OPTION.equals(this.page)) + { + CommandHelper.sendCommand(container.getPlayer(), this.builderTeams, TeamCommandBuilder.Label.MODIFY); + } container.initButtons(); })); button1.active = enabled; @@ -227,29 +242,22 @@ public class ContentScoreboardTeams extends ContentScoreboard { if(Page.JOIN_OR_LEAVE.equals(this.page)) { - this.builderTeams.setPlayer(username); + this.builderTeams.members().setTarget(username); } } public static enum Page { - ADD(EnumMode.ADD, 24), - JOIN_OR_LEAVE(EnumMode.JOIN_OR_LEAVE, 12), - REMOVE_OR_EMPTY(EnumMode.REMOVE_OR_EMPTY, 12), - OPTION(EnumMode.MODIFY, 0); + ADD(24), + JOIN_OR_LEAVE(12), + REMOVE_OR_EMPTY(12), + OPTION(0); - private final EnumMode mode; private final int shift; - private Page(EnumMode mode, int shift) + private Page(int shift) { this.shift = shift; - this.mode = mode; - } - - public EnumMode getMode() - { - return this.mode; } public int getShift() diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSettings.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSettings.java index aae98c7..3b7e2a3 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSettings.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSettings.java @@ -11,11 +11,11 @@ import exopandora.worldhandler.config.Config; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.content.impl.ContentSettings.Setting.BooleanSetting; import exopandora.worldhandler.gui.content.impl.ContentSettings.Setting.IntegerSetting; -import exopandora.worldhandler.gui.menu.impl.ILogicPageList; -import exopandora.worldhandler.gui.menu.impl.MenuPageList; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; import exopandora.worldhandler.gui.widget.button.GuiButtonTooltip; import exopandora.worldhandler.gui.widget.button.GuiTextFieldTooltip; +import exopandora.worldhandler.gui.widget.menu.impl.ILogicPageList; +import exopandora.worldhandler.gui.widget.menu.impl.MenuPageList; import exopandora.worldhandler.util.ActionHandler; import exopandora.worldhandler.util.ActionHelper; import net.minecraft.network.chat.MutableComponent; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSignEditor.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSignEditor.java index ebe974c..940b8df 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSignEditor.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSignEditor.java @@ -1,12 +1,15 @@ package exopandora.worldhandler.gui.content.impl; +import java.util.Arrays; + import com.google.common.base.Predicates; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.impl.BuilderSignEditor; +import exopandora.worldhandler.builder.argument.PrimitiveArgument.Linkage; +import exopandora.worldhandler.builder.argument.tag.TextTag; +import exopandora.worldhandler.builder.impl.DataCommandBuilder; import exopandora.worldhandler.config.Config; import exopandora.worldhandler.event.KeyHandler; import exopandora.worldhandler.gui.category.Categories; @@ -14,10 +17,10 @@ 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.menu.impl.ILogicColorMenu; -import exopandora.worldhandler.gui.menu.impl.MenuColorField; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; import exopandora.worldhandler.gui.widget.button.GuiTextFieldTooltip; +import exopandora.worldhandler.gui.widget.menu.impl.ILogicColorMenu; +import exopandora.worldhandler.gui.widget.menu.impl.MenuColorField; import exopandora.worldhandler.util.ActionHelper; import exopandora.worldhandler.util.BlockHelper; import exopandora.worldhandler.util.CommandHelper; @@ -31,26 +34,39 @@ import net.minecraft.world.level.block.SignBlock; public class ContentSignEditor extends Content { - private int selectedLine = 0; - private boolean editColor; + private final DataCommandBuilder builderSignEditor = new DataCommandBuilder(); + private final TextTag[] texts = new TextTag[4]; + private final CommandPreview preview = new CommandPreview(this.builderSignEditor, DataCommandBuilder.Label.MERGE_BLOCK); private GuiTextFieldTooltip commandField; - private final BuilderSignEditor builderSignEditor = new BuilderSignEditor(); - + private int selectedLine; + private boolean editColor; private boolean isActive; - @Override - public ICommandBuilder getCommandBuilder() + public ContentSignEditor() { - return this.isActive ? this.builderSignEditor : null; + this.builderSignEditor.linkage().set(Linkage.MERGE); + + for(int x = 0; x < this.texts.length; x++) + { + TextTag text = new TextTag(x + 1); + this.texts[x] = text; + this.builderSignEditor.nbt().addTagProvider(text); + } + } + + @Override + public CommandPreview getCommandPreview() + { + return this.isActive ? this.preview : null; } @Override public void init(Container container) { this.isActive = BlockHelper.getFocusedBlock() instanceof SignBlock; - this.builderSignEditor.setPosition(BlockHelper.getFocusedBlockPos()); + this.builderSignEditor.targetPos().set(BlockHelper.getFocusedBlockPos()); } @Override @@ -60,15 +76,15 @@ public class ContentSignEditor extends Content { this.commandField = new GuiTextFieldTooltip(x + 118, y + 24, 114, 20, new TranslatableComponent("gui.worldhandler.blocks.sign_editor.commmand")); this.commandField.setFilter(Predicates.notNull()); - this.commandField.setValue(this.builderSignEditor.getCommand(this.selectedLine)); + this.commandField.setValue(this.texts[this.selectedLine].getText().getCommand()); this.commandField.moveCursorToEnd(); this.commandField.setResponder(text -> { - this.builderSignEditor.setCommand(this.selectedLine, text); + this.texts[this.selectedLine].getText().setCommand(text); container.initButtons(); }); - MenuColorField colors = new MenuColorField(x, y, "gui.worldhandler.blocks.sign_editor.text_line_" + (this.selectedLine + 1), this.builderSignEditor.getColoredString(this.selectedLine), new ILogicColorMenu() + MenuColorField colors = new MenuColorField(x, y, "gui.worldhandler.blocks.sign_editor.text_line_" + (this.selectedLine + 1), this.texts[this.selectedLine].getText(), new ILogicColorMenu() { @Override public boolean validate(String text) @@ -137,7 +153,7 @@ public class ContentSignEditor extends Content container.add(new GuiButtonBase(x + 118, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.blocks.sign_editor.format_text_line"), () -> this.toggleEditColor(container))); container.add(new GuiButtonBase(x + 118, y + 72, 114, 20, new TranslatableComponent("gui.worldhandler.actions.place_command_block"), () -> { - CommandHelper.sendCommand(container.getPlayer(), this.builderSignEditor, this.builderSignEditor.isSpecial()); + CommandHelper.sendCommand(container.getPlayer(), this.builderSignEditor, DataCommandBuilder.Label.MERGE_BLOCK, Arrays.stream(this.texts).anyMatch(text -> text.getText().isSpecial())); })); } diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSummon.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSummon.java index 628fa16..fce4179 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSummon.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSummon.java @@ -1,27 +1,30 @@ package exopandora.worldhandler.gui.content.impl; import java.util.List; +import java.util.Random; import java.util.stream.Collectors; import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; import com.google.common.base.Predicates; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.component.impl.ComponentAttribute; -import exopandora.worldhandler.builder.impl.BuilderSummon; +import exopandora.worldhandler.builder.argument.Coordinate; +import exopandora.worldhandler.builder.argument.tag.AbstractAttributeTag; +import exopandora.worldhandler.builder.argument.tag.ActiveEffectsTag; +import exopandora.worldhandler.builder.argument.tag.AttributesTag; +import exopandora.worldhandler.builder.argument.tag.EffectInstance; +import exopandora.worldhandler.builder.argument.tag.EntityTag; +import exopandora.worldhandler.builder.argument.tag.MutableTag; +import exopandora.worldhandler.builder.impl.SummonCommandBuilder; import exopandora.worldhandler.config.Config; 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.gui.menu.impl.ILogicColorMenu; -import exopandora.worldhandler.gui.menu.impl.ILogicPageList; -import exopandora.worldhandler.gui.menu.impl.MenuColorField; -import exopandora.worldhandler.gui.menu.impl.MenuPageList; import exopandora.worldhandler.gui.widget.button.EnumIcon; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; import exopandora.worldhandler.gui.widget.button.GuiButtonIcon; @@ -30,26 +33,89 @@ import exopandora.worldhandler.gui.widget.button.GuiSlider; import exopandora.worldhandler.gui.widget.button.GuiTextFieldTooltip; import exopandora.worldhandler.gui.widget.button.LogicSliderAttribute; import exopandora.worldhandler.gui.widget.button.LogicSliderSimple; +import exopandora.worldhandler.gui.widget.menu.impl.ILogicColorMenu; +import exopandora.worldhandler.gui.widget.menu.impl.ILogicPageList; +import exopandora.worldhandler.gui.widget.menu.impl.MenuColorField; +import exopandora.worldhandler.gui.widget.menu.impl.MenuPageList; import exopandora.worldhandler.util.ActionHandler; import exopandora.worldhandler.util.ActionHelper; import exopandora.worldhandler.util.CommandHelper; import exopandora.worldhandler.util.TextUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.language.I18n; +import net.minecraft.nbt.ByteTag; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.IntTag; +import net.minecraft.nbt.ListTag; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.ai.attributes.Attribute; +import net.minecraft.world.entity.npc.VillagerProfession; +import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; -import net.minecraft.world.level.block.Blocks; import net.minecraftforge.registries.ForgeRegistries; public class ContentSummon extends Content { private static final ResourceLocation BEACON_LOCATION = new ResourceLocation("textures/gui/container/beacon.png"); + private static final Item[] HELMETS = + { + Items.AIR, + Items.LEATHER_HELMET, + Items.IRON_HELMET, + Items.CHAINMAIL_HELMET, + Items.GOLDEN_HELMET, + Items.DIAMOND_HELMET, + Items.NETHERITE_HELMET + }; + private static final Item[] CHESTPLATES = + { + Items.AIR, + Items.LEATHER_CHESTPLATE, + Items.IRON_CHESTPLATE, + Items.CHAINMAIL_CHESTPLATE, + Items.GOLDEN_CHESTPLATE, + Items.DIAMOND_CHESTPLATE, + Items.NETHERITE_CHESTPLATE + }; + private static final Item[] LEGGINGS = + { + Items.AIR, + Items.LEATHER_LEGGINGS, + Items.IRON_LEGGINGS, + Items.CHAINMAIL_LEGGINGS, + Items.GOLDEN_LEGGINGS, + Items.DIAMOND_LEGGINGS, + Items.NETHERITE_LEGGINGS + }; + private static final Item[] BOOTS = + { + Items.AIR, + Items.LEATHER_BOOTS, + Items.IRON_BOOTS, + Items.CHAINMAIL_BOOTS, + Items.GOLDEN_BOOTS, + Items.DIAMOND_BOOTS, + Items.NETHERITE_BOOTS + }; + private static final Item[] SWORDS = + { + Items.AIR, + Items.WOODEN_SWORD, + Items.STONE_SWORD, + Items.IRON_SWORD, + Items.GOLDEN_SWORD, + Items.DIAMOND_SWORD, + Items.NETHERITE_SWORD + }; + private static final Item[][] ARMOR = {HELMETS, CHESTPLATES, LEGGINGS, BOOTS}; + private static final Item[][] HANDS = {SWORDS, SWORDS}; + private static final Random RANDOM = new Random(); private GuiTextFieldTooltip mobField; private GuiTextFieldTooltip nbtField; @@ -61,94 +127,55 @@ public class ContentSummon extends Content private String mob; private String nbt; - private final BuilderSummon builderSummon = new BuilderSummon(); + private final SummonCommandBuilder builderSummon = new SummonCommandBuilder(); + private final EntityTag entity = new EntityTag(); + private final AttributesTag attributes = new AttributesTag(); + private final ActiveEffectsTag effects = new ActiveEffectsTag(); + private final MutableTag mutable = new MutableTag(); + private final CommandPreview preview = new CommandPreview(this.builderSummon, SummonCommandBuilder.Label.SUMMON_POS_NBT); - private final ResourceLocation[] helmets = + public ContentSummon() { - Blocks.AIR.getRegistryName(), - Items.LEATHER_HELMET.getRegistryName(), - Items.IRON_HELMET.getRegistryName(), - Items.CHAINMAIL_HELMET.getRegistryName(), - Items.GOLDEN_HELMET.getRegistryName(), - Items.DIAMOND_HELMET.getRegistryName(), - Items.NETHERITE_HELMET.getRegistryName() - }; - private final ResourceLocation[] chestplates = - { - Blocks.AIR.getRegistryName(), - Items.LEATHER_CHESTPLATE.getRegistryName(), - Items.IRON_CHESTPLATE.getRegistryName(), - Items.CHAINMAIL_CHESTPLATE.getRegistryName(), - Items.GOLDEN_CHESTPLATE.getRegistryName(), - Items.DIAMOND_CHESTPLATE.getRegistryName(), - Items.NETHERITE_CHESTPLATE.getRegistryName() - }; - private final ResourceLocation[] leggings = - { - Blocks.AIR.getRegistryName(), - Items.LEATHER_LEGGINGS.getRegistryName(), - Items.IRON_LEGGINGS.getRegistryName(), - Items.CHAINMAIL_LEGGINGS.getRegistryName(), - Items.GOLDEN_LEGGINGS.getRegistryName(), - Items.DIAMOND_LEGGINGS.getRegistryName(), - Items.NETHERITE_LEGGINGS.getRegistryName() - }; - private final ResourceLocation[] boots = - { - Blocks.AIR.getRegistryName(), - Items.LEATHER_BOOTS.getRegistryName(), - Items.IRON_BOOTS.getRegistryName(), - Items.CHAINMAIL_BOOTS.getRegistryName(), - Items.GOLDEN_BOOTS.getRegistryName(), - Items.DIAMOND_BOOTS.getRegistryName(), - Items.NETHERITE_BOOTS.getRegistryName() - }; - private final ResourceLocation[] swords = - { - Blocks.AIR.getRegistryName(), - Items.WOODEN_SWORD.getRegistryName(), - Items.STONE_SWORD.getRegistryName(), - Items.IRON_SWORD.getRegistryName(), - Items.GOLDEN_SWORD.getRegistryName(), - Items.DIAMOND_SWORD.getRegistryName(), - Items.NETHERITE_SWORD.getRegistryName() - }; - private final ResourceLocation[][] armor = {this.helmets, this.chestplates, this.leggings, this.boots}; - private final ResourceLocation[][] hands = {this.swords, this.swords}; + this.builderSummon.pos().setX(new Coordinate.Ints(Coordinate.Type.LOCAL)); + this.builderSummon.pos().setY(new Coordinate.Ints(Coordinate.Type.LOCAL)); + this.builderSummon.pos().setZ(new Coordinate.Ints(2, Coordinate.Type.LOCAL)); + this.builderSummon.nbt().addTagProvider(this.entity); + this.builderSummon.nbt().addTagProvider(this.attributes); + this.builderSummon.nbt().addTagProvider(this.effects); + this.builderSummon.nbt().addTagProvider(this.mutable); + } @Override - public ICommandBuilder getCommandBuilder() + public CommandPreview getCommandPreview() { - return this.builderSummon; + return this.preview; } @Override public void init(Container container) { - for(Attribute attribute : this.builderSummon.getAttributes()) + for(Attribute attribute : this.attributes.getAttributes()) { - double ammount = this.builderSummon.getAttributeAmmount(attribute); + double value = this.attributes.get(attribute); - if(ammount > Config.getSliders().getMaxSummonAttributes()) + if(value > Config.getSliders().getMaxSummonAttributes()) { - this.builderSummon.setAttribute(attribute, Config.getSliders().getMaxSummonAttributes()); + this.attributes.set(attribute, Config.getSliders().getMaxSummonAttributes()); } } - for(MobEffect potion : this.builderSummon.getMobEffects()) + for(MobEffect effect : this.effects.getMobEffects()) { - byte amplifier = this.builderSummon.getAmplifier(potion); + EffectInstance tag = this.effects.getOrCreate(effect); - if(amplifier > Config.getSliders().getMaxSummonPotionAmplifier()) + if(tag.getAmplifier() > Config.getSliders().getMaxSummonPotionAmplifier()) { - this.builderSummon.setAmplifier(potion, (byte) Config.getSliders().getMaxSummonPotionAmplifier()); + tag.setAmplifier((byte) Config.getSliders().getMaxSummonPotionAmplifier()); } - int minutes = this.builderSummon.getMinutes(potion); - - if(minutes > Config.getSliders().getMaxSummonPotionMinutes()) + if(tag.getMinutes() > Config.getSliders().getMaxSummonPotionMinutes()) { - this.builderSummon.setMinutes(potion, (int) Config.getSliders().getMaxSummonPotionMinutes()); + tag.setMinutes((int) Config.getSliders().getMaxSummonPotionMinutes()); } } } @@ -162,7 +189,8 @@ public class ContentSummon extends Content this.mobField.setResponder(text -> { this.mob = text; - this.builderSummon.setName(this.mob); + this.builderSummon.entity().deserialize(this.mob); + this.updateMutableTag(); container.initButtons(); }); @@ -172,13 +200,13 @@ public class ContentSummon extends Content this.nbtField.setResponder(text -> { this.nbt = text; - this.builderSummon.setEntityNBT(this.nbt); + this.entity.setNBT(this.nbt); container.initButtons(); }); if(Page.START.equals(this.page)) { - MenuColorField customName = new MenuColorField(x, y, "gui.worldhandler.entities.summon.start.custom_name", this.builderSummon.getCustomName(), new ILogicColorMenu() + MenuColorField customName = new MenuColorField(x, y, "gui.worldhandler.entities.summon.start.custom_name", this.entity.getCustomName(), new ILogicColorMenu() { @Override public boolean doDrawButtons() @@ -203,18 +231,18 @@ public class ContentSummon extends Content } else if(Page.ATTRIBUTES.equals(this.page)) { - MenuPageList attributes = new MenuPageList(x + 118, y, ComponentAttribute.ATTRIBUTES, 114, 20, 3, container, new ILogicPageList() + MenuPageList attributes = new MenuPageList(x + 118, y, AbstractAttributeTag.ATTRIBUTES, 114, 20, 3, container, new ILogicPageList() { @Override - public MutableComponent translate(Attribute item) + public MutableComponent translate(Attribute attribute) { - return new TranslatableComponent(item.getDescriptionId()); + return new TranslatableComponent(attribute.getDescriptionId()); } @Override - public MutableComponent toTooltip(Attribute item) + public MutableComponent toTooltip(Attribute attribute) { - return new TextComponent(item.getRegistryName().toString()); + return new TextComponent(attribute.getRegistryName().toString()); } @Override @@ -224,11 +252,11 @@ public class ContentSummon extends Content } @Override - public GuiButtonBase onRegister(int x, int y, int width, int height, MutableComponent text, Attribute item, ActionHandler actionHandler) + public GuiButtonBase onRegister(int x, int y, int width, int height, MutableComponent text, Attribute attribute, ActionHandler actionHandler) { - return new GuiSlider(x, y, width, height, -Config.getSliders().getMaxSummonAttributes(), Config.getSliders().getMaxSummonAttributes(), 0, container, new LogicSliderAttribute(item, text, value -> + return new GuiSlider(x, y, width, height, -Config.getSliders().getMaxSummonAttributes(), Config.getSliders().getMaxSummonAttributes(), 0, container, new LogicSliderAttribute(attribute, text, value -> { - ContentSummon.this.builderSummon.setAttribute(item, value); + ContentSummon.this.attributes.set(attribute, value); })); } @@ -282,7 +310,7 @@ public class ContentSummon extends Content container.add(new GuiButtonBase(x + 118, y + 24, 114, 20, "gui.worldhandler.entities.summon.start.custom_name", () -> this.toggleEditColor(container))); container.add(this.nbtField); - if(!this.builderSummon.needsCommandBlock() && !this.builderSummon.getCustomName().isSpecial()) + if(!this.builderSummon.needsCommandBlock(SummonCommandBuilder.Label.SUMMON_POS_NBT, false) && !this.entity.getCustomName().isSpecial()) { container.add(button3 = new GuiButtonBase(x + 118, y + 72, 114, 20, "gui.worldhandler.title.entities.summon", () -> this.send(container.getPlayer()))); } @@ -291,7 +319,7 @@ public class ContentSummon extends Content container.add(button3 = new GuiButtonBase(x + 118, y + 72, 114, 20, "gui.worldhandler.actions.place_command_block", () -> this.send(container.getPlayer()))); } - button3.active = ForgeRegistries.ENTITIES.containsKey(this.builderSummon.getEntity()); + button3.active = this.builderSummon.entity().hasValue(); } } else if(Page.POTIONS.equals(this.page)) @@ -311,42 +339,46 @@ public class ContentSummon extends Content int count = 0; - for(ResourceLocation location : this.sortedPotions()) + for(ResourceLocation location : this.sortedEffects()) { - MobEffect potion = ForgeRegistries.MOB_EFFECTS.getValue(location); + MobEffect effect = ForgeRegistries.MOB_EFFECTS.getValue(location); - if(!potion.equals(MobEffects.HARM) && !potion.equals(MobEffects.HEAL)) + if(effect.equals(MobEffects.HARM) || effect.equals(MobEffects.HEAL)) { - if(this.potionPage == 0) - { - button1.active = false; - } - - if(this.potionPage == ForgeRegistries.MOB_EFFECTS.getKeys().size() - 3) - { - button2.active = false; - } - - if(count == this.potionPage) - { - container.add(new GuiSlider(x + 118, y, 114, 20, 0, Config.getSliders().getMaxSummonPotionAmplifier(), 0, container, new LogicSliderSimple("amplifier" + potion.getRegistryName(), new TranslatableComponent(potion.getDescriptionId()), value -> - { - this.builderSummon.setAmplifier(potion, value.byteValue()); - }))); - container.add(new GuiSlider(x + 118, y + 24, 114, 20, 0, Config.getSliders().getMaxSummonPotionMinutes(), 0, container, new LogicSliderSimple("duration" + potion.getRegistryName(), new TranslatableComponent("gui.worldhandler.potion.time.minutes"), value -> - { - this.builderSummon.setMinutes(potion, value); - }))); - container.add(new GuiButtonBase(x + 118, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.potions.effect.particles", this.builderSummon.getShowParticles(potion) ? new TranslatableComponent("gui.worldhandler.generic.on") : new TranslatableComponent("gui.worldhandler.generic.off")), () -> - { - this.builderSummon.setShowParticles(potion, !this.builderSummon.getShowParticles(potion)); - container.init(); - })); - break; - } - - count++; + continue; } + + if(this.potionPage == 0) + { + button1.active = false; + } + + if(this.potionPage == ForgeRegistries.MOB_EFFECTS.getKeys().size() - 3) + { + button2.active = false; + } + + if(count == this.potionPage) + { + EffectInstance tag = this.effects.getOrCreate(effect); + + container.add(new GuiSlider(x + 118, y, 114, 20, 0, Config.getSliders().getMaxSummonPotionAmplifier(), 0, container, new LogicSliderSimple("amplifier" + effect.getRegistryName(), new TranslatableComponent(effect.getDescriptionId()), value -> + { + tag.setAmplifier(value.byteValue()); + }))); + container.add(new GuiSlider(x + 118, y + 24, 114, 20, 0, Config.getSliders().getMaxSummonPotionMinutes(), 0, container, new LogicSliderSimple("duration" + effect.getRegistryName(), new TranslatableComponent("gui.worldhandler.potion.time.minutes"), value -> + { + tag.setMinutes(value.intValue()); + }))); + container.add(new GuiButtonBase(x + 118, y + 48, 114, 20, new TranslatableComponent("gui.worldhandler.potions.effect.particles", tag.doShowParticles() ? new TranslatableComponent("gui.worldhandler.generic.on") : new TranslatableComponent("gui.worldhandler.generic.off")), () -> + { + tag.setShowParticles(!tag.doShowParticles()); + container.init(); + })); + break; + } + + count++; } } else if(Page.ATTRIBUTES.equals(this.page)) @@ -361,13 +393,13 @@ public class ContentSummon extends Content container.add(new GuiButtonBase(x + 118, y + 24 * i, 20, 20, TextUtils.ARROW_LEFT, () -> { - this.builderSummon.setArmorItem(3 - index, this.armor[index][Math.floorMod(ArrayUtils.indexOf(this.armor[index], this.builderSummon.getArmorItem(3 - index)) - 1, this.armor[index].length)]); + this.entity.setArmorItem(3 - index, ARMOR[index][Math.floorMod(ArrayUtils.indexOf(ARMOR[index], this.entity.getArmorItem(3 - index)) - 1, ARMOR[index].length)]); container.init(); })); - container.add(button1 = new GuiButtonItem(x + 118 + 24, y + 24 * i, 20, 20, ForgeRegistries.ITEMS.getValue(this.builderSummon.getArmorItem(3 - i)), null)); + container.add(button1 = new GuiButtonItem(x + 118 + 24, y + 24 * i, 20, 20, this.entity.getArmorItem(3 - i), null)); container.add(new GuiButtonBase(x + 118 + 47, y + 24 * i, 20, 20, TextUtils.ARROW_RIGHT, () -> { - this.builderSummon.setArmorItem(3 - index, this.armor[index][Math.floorMod(ArrayUtils.indexOf(this.armor[index], this.builderSummon.getArmorItem(3 - index)) + 1, this.armor[index].length)]); + this.entity.setArmorItem(3 - index, ARMOR[index][Math.floorMod(ArrayUtils.indexOf(ARMOR[index], this.entity.getArmorItem(3 - index)) + 1, ARMOR[index].length)]); container.init(); })); @@ -380,13 +412,13 @@ public class ContentSummon extends Content container.add(new GuiButtonIcon(x + 118 + 70 + 24 * i, y + 12, 20, 20, EnumIcon.ARROW_UP, null, () -> { - this.builderSummon.setHandItem(index, this.hands[index][Math.floorMod(ArrayUtils.indexOf(this.hands[index], this.builderSummon.getHandItem(index)) - 1, this.hands[index].length)]); + this.entity.setHandItem(index, HANDS[index][Math.floorMod(ArrayUtils.indexOf(HANDS[index], this.entity.getHandItem(index)) - 1, HANDS[index].length)]); container.init(); })); - container.add(button1 = new GuiButtonItem(x + 118 + 70 + 24 * i, y + 36, 20, 20, ForgeRegistries.ITEMS.getValue(this.builderSummon.getHandItem(i)), null)); + container.add(button1 = new GuiButtonItem(x + 118 + 70 + 24 * i, y + 36, 20, 20, this.entity.getHandItem(i), null)); container.add(new GuiButtonIcon(x + 118 + 70 + 24 * i, y + 60, 20, 20, EnumIcon.ARROW_DOWN, null, () -> { - this.builderSummon.setHandItem(index, this.hands[index][Math.floorMod(ArrayUtils.indexOf(this.hands[index], this.builderSummon.getHandItem(index)) + 1, this.hands[index].length)]); + this.entity.setHandItem(index, HANDS[index][Math.floorMod(ArrayUtils.indexOf(HANDS[index], this.entity.getHandItem(index)) + 1, HANDS[index].length)]); container.init(); })); @@ -399,7 +431,67 @@ public class ContentSummon extends Content private void send(String player) { - CommandHelper.sendCommand(player, this.builderSummon, this.builderSummon.getCustomName().isSpecial()); + CommandHelper.sendCommand(player, this.builderSummon, SummonCommandBuilder.Label.SUMMON_POS_NBT, this.entity.getCustomName().isSpecial()); + } + + private void updateMutableTag() + { + EntityType entity = this.builderSummon.entity().getEntity(); + + if(EntityType.CAT.equals(entity)) + { + this.mutable.setKey("CatType"); + this.mutable.setTag(IntTag.valueOf(RANDOM.nextInt(11))); + } + else if(EntityType.VILLAGER.equals(entity)) + { + for(VillagerProfession profession : ForgeRegistries.PROFESSIONS) + { + if(StringUtils.equalsIgnoreCase(this.mob, profession.toString())) + { + CompoundTag villagerData = new CompoundTag(); + villagerData.putString("profession", profession.getRegistryName().toString()); + + this.mutable.setKey("VillagerData"); + this.mutable.setTag(villagerData); + + return; + } + } + + this.mutable.reset(); + } + else if(EntityType.ZOMBIE.equals(entity) && StringUtils.containsIgnoreCase(this.mob, "Baby")) + { + this.mutable.setKey("IsBaby"); + this.mutable.setTag(ByteTag.valueOf((byte) 1)); + } + else if(EntityType.CHICKEN.equals(entity) && StringUtils.containsIgnoreCase(this.mob, "Jockey") && !this.entity.hasPassengers()) + { + ListTag list = new ListTag(); + EntityTag zombie = new EntityTag(EntityType.ZOMBIE.getRegistryName()); + + zombie.setIsBaby(true); + list.add(zombie.value()); + + this.mutable.setKey("Passengers"); + this.mutable.setTag(list); + } + else if(EntityType.SPIDER.equals(entity) && StringUtils.containsIgnoreCase(this.mob, "Jockey") && !this.entity.hasPassengers()) + { + ListTag list = new ListTag(); + EntityTag skeleton = new EntityTag(EntityType.SKELETON.getRegistryName()); + + skeleton.setHandItem(0, Items.BOW); + list.add(skeleton.value()); + + this.mutable.setKey("Passengers"); + this.mutable.setTag(list); + } + else + { + this.mutable.reset(); + } } @Override @@ -438,7 +530,7 @@ public class ContentSummon extends Content for(int i = 0; i < 4; i++) { - if(this.builderSummon.getArmorItem(3 - i).equals(Items.AIR.getRegistryName())) + if(Items.AIR.equals(this.entity.getArmorItem(3 - i))) { container.blit(matrix, x + 118 + 24 + 2, y + 2 + 24 * i, 112, 221, 16, 16); } @@ -446,7 +538,7 @@ public class ContentSummon extends Content for(int i = 0; i < 2; i++) { - if(this.builderSummon.getHandItem(i).equals(Items.AIR.getRegistryName())) + if(Items.AIR.equals(this.entity.getHandItem(i))) { container.blit(matrix, x + 118 + 70 + 2 + 24 * i, y + 2 + 36, 112, 221, 16, 16); } @@ -454,7 +546,7 @@ public class ContentSummon extends Content } } - private List sortedPotions() + private List sortedEffects() { return ForgeRegistries.MOB_EFFECTS.getKeys().stream() .sorted((a, b) -> I18n.get(ForgeRegistries.MOB_EFFECTS.getValue(a).getDescriptionId()).compareTo(I18n.get(ForgeRegistries.MOB_EFFECTS.getValue(b).getDescriptionId()))) diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentUsercontent.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentUsercontent.java index 92cfd3c..0d2a476 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentUsercontent.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentUsercontent.java @@ -4,16 +4,15 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; import java.util.stream.Collectors; import java.util.stream.Stream; import com.mojang.blaze3d.vertex.PoseStack; 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.builder.impl.UsercontentCommandBuilder; import exopandora.worldhandler.gui.category.Categories; import exopandora.worldhandler.gui.category.Category; import exopandora.worldhandler.gui.container.Container; @@ -31,7 +30,6 @@ import exopandora.worldhandler.usercontent.model.AbstractJsonWidget; import exopandora.worldhandler.usercontent.model.JsonCommand; import exopandora.worldhandler.usercontent.model.JsonLabel; import exopandora.worldhandler.usercontent.model.JsonMenu; -import exopandora.worldhandler.usercontent.model.JsonModel; import exopandora.worldhandler.usercontent.model.JsonUsercontent; import exopandora.worldhandler.usercontent.model.JsonWidget; import exopandora.worldhandler.util.TextUtils; @@ -43,6 +41,7 @@ import net.minecraft.client.gui.components.EditBox; import net.minecraft.network.chat.ChatType; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; import net.minecraft.network.chat.TextComponent; public class ContentUsercontent extends Content @@ -50,11 +49,11 @@ public class ContentUsercontent extends Content private final String id; private final JsonUsercontent content; private final ScriptEngineAdapter engineAdapter; - private final List> builders; + private final Map> builders; private final Map> textfields = new HashMap>(); - private final List> buttons = new ArrayList>(); + private final List> widgets = new ArrayList>(); private final UsercontentAPI api; - private final WidgetFactory buttonFactory; + private final WidgetFactory widgetFactory; private final MenuFactory menuFactory; public ContentUsercontent(UsercontentConfig config) throws Exception @@ -62,35 +61,42 @@ public class ContentUsercontent extends Content 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())); + this.builders = this.createBuilders(this.content.getCommands()); + this.api = new UsercontentAPI(this.builders.entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().get()))); ActionHandlerFactory actionHandlerFactory = new ActionHandlerFactory(this.api, this.builders, this.engineAdapter); - this.buttonFactory = new WidgetFactory(this.api, actionHandlerFactory); + this.widgetFactory = new WidgetFactory(this.api, actionHandlerFactory); this.menuFactory = new MenuFactory(this.api, actionHandlerFactory); this.engineAdapter.addObject("api", this.api); this.engineAdapter.eval(config.getJs()); } @Override - public ICommandBuilder getCommandBuilder() + public CommandPreview getCommandPreview() { - ICommandBuilder[] builders = this.builders.stream() + List builders = this.builders.values().stream() .filter(builder -> builder.isVisible(this.engineAdapter)) - .map(VisibleObject::getObject) - .toArray(ICommandBuilder[]::new); + .map(VisibleObject::get) + .collect(Collectors.toList()); - return builders.length > 0 ? new BuilderMultiCommand(builders) : null; + if(builders.isEmpty()) + { + return null; + } + + CommandPreview preview = new CommandPreview(); + builders.forEach(builder -> preview.add(builder, builder.getLabel())); + return preview; } @Override public void initGui(Container container, int x, int y) { this.textfields.clear(); - this.buttons.clear(); + this.widgets.clear(); for(JsonWidget json : this.getWidgets(this.content.getGui().getWidgets(), AbstractJsonWidget.Type.BUTTON)) { - AbstractWidget widget = this.buttonFactory.createWidget(json, this, container, x, y); + AbstractWidget widget = this.widgetFactory.createWidget(json, this, container, x, y); if(JsonWidget.Type.TEXTFIELD.equals(json.getType())) { @@ -99,7 +105,7 @@ public class ContentUsercontent extends Content } else { - this.buttons.add(new VisibleActiveObject(json, widget)); + this.widgets.add(new VisibleActiveObject(json, widget)); } } @@ -115,7 +121,7 @@ public class ContentUsercontent extends Content @Override public void initButtons(Container container, int x, int y) { - Stream.concat(this.textfields.values().stream(), this.buttons.stream()).map(VisibleObject::getObject).forEach(container::add); + Stream.concat(this.textfields.values().stream(), this.widgets.stream()).map(VisibleObject::get).forEach(container::add); } @Override @@ -125,7 +131,7 @@ public class ContentUsercontent extends Content { if(textfield.isVisible(this.engineAdapter)) { - textfield.getObject().tick(); + textfield.get().tick(); } } @@ -138,9 +144,9 @@ public class ContentUsercontent extends Content { for(VisibleObject textfield : this.textfields.values()) { - if(textfield.getObject().visible) + if(textfield.get().visible) { - textfield.getObject().renderButton(matrix, mouseX, mouseY, partialTicks); + textfield.get().renderButton(matrix, mouseX, mouseY, partialTicks); } } @@ -199,24 +205,27 @@ public class ContentUsercontent extends Content @Override public void onPlayerNameChanged(String username) { - for(VisibleObject visObj : this.builders) + for(VisibleObject visObj : this.builders.values()) { - visObj.getObject().setPlayerName(username); + visObj.get().setPlayerName(username); } } - private List> createBuilders(JsonModel model) + private Map> createBuilders(Map commands) { - List> builders = new ArrayList>(); + Map> builders = new TreeMap>(); - if(model != null && model.getCommands() != null) + if(commands != null) { - for(JsonCommand command : model.getCommands()) + for(Entry command : commands.entrySet()) { - if(command.getName() != null && command.getSyntax() != null) + JsonCommand root = command.getValue(); + + if(root.getSyntax() != null) { - BuilderUsercontent builder = new BuilderUsercontent(command.getName(), new CommandSyntax(command.getSyntax())); - builders.add(new VisibleObject(command.getVisible(), builder)); + root.getSyntax().validate(); + UsercontentCommandBuilder builder = new UsercontentCommandBuilder(root.getSyntax(), root.getLabel()); + builders.put(command.getKey(), new VisibleObject(root.getVisible(), builder)); } } } @@ -253,7 +262,7 @@ public class ContentUsercontent extends Content private void printError(String type, int index, Throwable e) { - Component message = new TextComponent(ChatFormatting.RED + "<" + Main.NAME + ":" + this.id + ":" + type + ":" + index + "> " + e.getMessage()); + Component message = new TextComponent("<" + Main.NAME + ":" + this.id + ":" + type + ":" + index + "> " + e.getMessage()).setStyle(Style.EMPTY.withColor(ChatFormatting.RED)); Minecraft.getInstance().gui.handleChat(ChatType.CHAT, message, Util.NIL_UUID); } @@ -261,17 +270,17 @@ public class ContentUsercontent extends Content { for(VisibleActiveObject visObj : this.textfields.values()) { - visObj.getObject().setEditable(visObj.isEnabled(this.engineAdapter)); - visObj.getObject().setVisible(visObj.isVisible(this.engineAdapter)); + visObj.get().setEditable(visObj.isEnabled(this.engineAdapter)); + visObj.get().setVisible(visObj.isVisible(this.engineAdapter)); } } private void updateButtons() { - for(VisibleActiveObject visObj : this.buttons) + for(VisibleActiveObject visObj : this.widgets) { - visObj.getObject().active = visObj.isEnabled(this.engineAdapter); - visObj.getObject().visible = visObj.isVisible(this.engineAdapter); + visObj.get().active = visObj.isEnabled(this.engineAdapter); + visObj.get().visible = visObj.isVisible(this.engineAdapter); } } } diff --git a/src/main/java/exopandora/worldhandler/gui/widget/WidgetCommandSyntax.java b/src/main/java/exopandora/worldhandler/gui/widget/WidgetCommandSyntax.java index 72d52a6..5cc90c5 100644 --- a/src/main/java/exopandora/worldhandler/gui/widget/WidgetCommandSyntax.java +++ b/src/main/java/exopandora/worldhandler/gui/widget/WidgetCommandSyntax.java @@ -3,14 +3,14 @@ package exopandora.worldhandler.gui.widget; import com.google.common.base.Predicates; import com.mojang.blaze3d.vertex.PoseStack; -import exopandora.worldhandler.builder.impl.BuilderWorldHandler; +import exopandora.worldhandler.builder.impl.WorldHandlerCommandBuilder; import exopandora.worldhandler.config.Config; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.widget.button.GuiTextFieldTooltip; public class WidgetCommandSyntax implements IContainerWidget { - private static final BuilderWorldHandler BUILDER_WORLD_HANDLER = new BuilderWorldHandler(); + private static final WorldHandlerCommandBuilder BUILDER_WORLD_HANDLER = new WorldHandlerCommandBuilder(); private GuiTextFieldTooltip syntaxField; @@ -53,13 +53,13 @@ public class WidgetCommandSyntax implements IContainerWidget { this.syntaxField.setFilter(Predicates.alwaysTrue()); - if(container.getContent().getCommandBuilder() != null) + if(container.getContent().getCommandPreview() != null) { - this.syntaxField.setValue(container.getContent().getCommandBuilder().toCommand()); + this.syntaxField.setValue(container.getContent().getCommandPreview().toString()); } else { - this.syntaxField.setValue(BUILDER_WORLD_HANDLER.toCommand()); + this.syntaxField.setValue(BUILDER_WORLD_HANDLER.toCommand(null, true)); } this.syntaxField.setFilter(string -> string.equals(this.syntaxField.getValue())); diff --git a/src/main/java/exopandora/worldhandler/gui/widget/button/GuiButtonBase.java b/src/main/java/exopandora/worldhandler/gui/widget/button/GuiButtonBase.java index 30a7019..63b025e 100644 --- a/src/main/java/exopandora/worldhandler/gui/widget/button/GuiButtonBase.java +++ b/src/main/java/exopandora/worldhandler/gui/widget/button/GuiButtonBase.java @@ -39,7 +39,7 @@ public class GuiButtonBase extends Button RenderSystem.enableBlend(); RenderUtils.colorDefaultButton(); - int hovered = this.getYImage(this.isHovered()); + int hovered = this.getYImage(this.isHoveredOrFocused()); RenderSystem.setShaderTexture(0, ResourceHelper.buttonTexture()); int hWidth = this.width / 2; diff --git a/src/main/java/exopandora/worldhandler/gui/widget/button/GuiButtonList.java b/src/main/java/exopandora/worldhandler/gui/widget/button/GuiButtonList.java index b4e6332..8ba9d6d 100644 --- a/src/main/java/exopandora/worldhandler/gui/widget/button/GuiButtonList.java +++ b/src/main/java/exopandora/worldhandler/gui/widget/button/GuiButtonList.java @@ -5,7 +5,7 @@ import java.util.List; import com.mojang.blaze3d.vertex.PoseStack; import exopandora.worldhandler.gui.container.Container; -import exopandora.worldhandler.gui.menu.impl.ILogicMapped; +import exopandora.worldhandler.gui.widget.menu.impl.ILogicMapped; import exopandora.worldhandler.util.TextUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; diff --git a/src/main/java/exopandora/worldhandler/gui/widget/button/GuiButtonPiano.java b/src/main/java/exopandora/worldhandler/gui/widget/button/GuiButtonPiano.java index ecf5fe4..cd62f98 100644 --- a/src/main/java/exopandora/worldhandler/gui/widget/button/GuiButtonPiano.java +++ b/src/main/java/exopandora/worldhandler/gui/widget/button/GuiButtonPiano.java @@ -50,7 +50,7 @@ public class GuiButtonPiano extends GuiButtonBase break; } - int hovered = this.getYImage(this.isHovered()); + int hovered = this.getYImage(this.isHoveredOrFocused()); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, Config.getSkin().getButtonAlpha()); RenderSystem.setShaderTexture(0, NOTE); @@ -76,7 +76,7 @@ public class GuiButtonPiano extends GuiButtonBase Font font = Minecraft.getInstance().font; this.blit(matrix, this.x, this.y, 25 + hoverstate * 15 - 15, 0, 15, 92); - font.draw(matrix, this.getMessage(), (float) (this.x + this.width / 2 - font.width(this.getMessage()) / 2), (float) (this.y + (this.height - 8) / 2 + 36), textColor); //drawString + font.draw(matrix, this.getMessage(), (float) (this.x + this.width / 2 - font.width(this.getMessage()) / 2), (float) (this.y + (this.height - 8) / 2 + 36), textColor); } protected void drawBlackKey(PoseStack matrix, int hoverstate) @@ -93,7 +93,7 @@ public class GuiButtonPiano extends GuiButtonBase { textColor = 0xA0A0A0; } - else if(this.isHovered()) + else if(this.isHoveredOrFocused()) { textColor = 0x8B8B8B; } diff --git a/src/main/java/exopandora/worldhandler/gui/widget/button/GuiButtonTooltip.java b/src/main/java/exopandora/worldhandler/gui/widget/button/GuiButtonTooltip.java index dcafc61..5d2bdfd 100644 --- a/src/main/java/exopandora/worldhandler/gui/widget/button/GuiButtonTooltip.java +++ b/src/main/java/exopandora/worldhandler/gui/widget/button/GuiButtonTooltip.java @@ -18,7 +18,7 @@ public class GuiButtonTooltip extends GuiButtonBase public void renderTooltip(Screen screen, PoseStack matrix, int mouseX, int mouseY) { - if(this.isHovered() && this.tooltip != null && !this.tooltip.getString().isEmpty()) + if(this.isHoveredOrFocused() && this.tooltip != null && !this.tooltip.getString().isEmpty()) { screen.renderTooltip(matrix, this.tooltip, mouseX, mouseY); } diff --git a/src/main/java/exopandora/worldhandler/gui/widget/button/GuiSlider.java b/src/main/java/exopandora/worldhandler/gui/widget/button/GuiSlider.java index 067e69c..f5c07ee 100644 --- a/src/main/java/exopandora/worldhandler/gui/widget/button/GuiSlider.java +++ b/src/main/java/exopandora/worldhandler/gui/widget/button/GuiSlider.java @@ -37,7 +37,7 @@ public class GuiSlider extends GuiButtonBase { super.renderBg(matrix, minecraft, mouseX, mouseY); - int hovered = super.getYImage(this.isHovered()); + int hovered = super.getYImage(this.isHoveredOrFocused()); int textureOffset = (Config.getSkin().getTextureType().equals("resourcepack") ? 46 : 0) + hovered * 20; RenderSystem.enableBlend(); diff --git a/src/main/java/exopandora/worldhandler/gui/menu/IMenu.java b/src/main/java/exopandora/worldhandler/gui/widget/menu/IMenu.java similarity index 85% rename from src/main/java/exopandora/worldhandler/gui/menu/IMenu.java rename to src/main/java/exopandora/worldhandler/gui/widget/menu/IMenu.java index 92f914b..3d9eab5 100644 --- a/src/main/java/exopandora/worldhandler/gui/menu/IMenu.java +++ b/src/main/java/exopandora/worldhandler/gui/widget/menu/IMenu.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.gui.menu; +package exopandora.worldhandler.gui.widget.menu; import com.mojang.blaze3d.vertex.PoseStack; diff --git a/src/main/java/exopandora/worldhandler/gui/menu/Menu.java b/src/main/java/exopandora/worldhandler/gui/widget/menu/Menu.java similarity index 75% rename from src/main/java/exopandora/worldhandler/gui/menu/Menu.java rename to src/main/java/exopandora/worldhandler/gui/widget/menu/Menu.java index 3bdae0e..5d13710 100644 --- a/src/main/java/exopandora/worldhandler/gui/menu/Menu.java +++ b/src/main/java/exopandora/worldhandler/gui/widget/menu/Menu.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.gui.menu; +package exopandora.worldhandler.gui.widget.menu; public abstract class Menu implements IMenu { diff --git a/src/main/java/exopandora/worldhandler/gui/menu/impl/ILogicButtonList.java b/src/main/java/exopandora/worldhandler/gui/widget/menu/impl/ILogicButtonList.java similarity index 89% rename from src/main/java/exopandora/worldhandler/gui/menu/impl/ILogicButtonList.java rename to src/main/java/exopandora/worldhandler/gui/widget/menu/impl/ILogicButtonList.java index 0377712..d085bd5 100644 --- a/src/main/java/exopandora/worldhandler/gui/menu/impl/ILogicButtonList.java +++ b/src/main/java/exopandora/worldhandler/gui/widget/menu/impl/ILogicButtonList.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.gui.menu.impl; +package exopandora.worldhandler.gui.widget.menu.impl; import java.util.List; diff --git a/src/main/java/exopandora/worldhandler/gui/menu/impl/ILogicColorMenu.java b/src/main/java/exopandora/worldhandler/gui/widget/menu/impl/ILogicColorMenu.java similarity index 86% rename from src/main/java/exopandora/worldhandler/gui/menu/impl/ILogicColorMenu.java rename to src/main/java/exopandora/worldhandler/gui/widget/menu/impl/ILogicColorMenu.java index 1002385..dfc793c 100644 --- a/src/main/java/exopandora/worldhandler/gui/menu/impl/ILogicColorMenu.java +++ b/src/main/java/exopandora/worldhandler/gui/widget/menu/impl/ILogicColorMenu.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.gui.menu.impl; +package exopandora.worldhandler.gui.widget.menu.impl; import exopandora.worldhandler.util.ILogic; diff --git a/src/main/java/exopandora/worldhandler/gui/menu/impl/ILogicMapped.java b/src/main/java/exopandora/worldhandler/gui/widget/menu/impl/ILogicMapped.java similarity index 91% rename from src/main/java/exopandora/worldhandler/gui/menu/impl/ILogicMapped.java rename to src/main/java/exopandora/worldhandler/gui/widget/menu/impl/ILogicMapped.java index 0f95b90..7ddba99 100644 --- a/src/main/java/exopandora/worldhandler/gui/menu/impl/ILogicMapped.java +++ b/src/main/java/exopandora/worldhandler/gui/widget/menu/impl/ILogicMapped.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.gui.menu.impl; +package exopandora.worldhandler.gui.widget.menu.impl; import exopandora.worldhandler.util.ILogic; import net.minecraft.network.chat.MutableComponent; diff --git a/src/main/java/exopandora/worldhandler/gui/menu/impl/ILogicPageList.java b/src/main/java/exopandora/worldhandler/gui/widget/menu/impl/ILogicPageList.java similarity index 88% rename from src/main/java/exopandora/worldhandler/gui/menu/impl/ILogicPageList.java rename to src/main/java/exopandora/worldhandler/gui/widget/menu/impl/ILogicPageList.java index 99efed0..1323b1e 100644 --- a/src/main/java/exopandora/worldhandler/gui/menu/impl/ILogicPageList.java +++ b/src/main/java/exopandora/worldhandler/gui/widget/menu/impl/ILogicPageList.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.gui.menu.impl; +package exopandora.worldhandler.gui.widget.menu.impl; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; import exopandora.worldhandler.util.ActionHandler; diff --git a/src/main/java/exopandora/worldhandler/gui/menu/impl/MenuButtonList.java b/src/main/java/exopandora/worldhandler/gui/widget/menu/impl/MenuButtonList.java similarity index 97% rename from src/main/java/exopandora/worldhandler/gui/menu/impl/MenuButtonList.java rename to src/main/java/exopandora/worldhandler/gui/widget/menu/impl/MenuButtonList.java index f25c7a3..c575939 100644 --- a/src/main/java/exopandora/worldhandler/gui/menu/impl/MenuButtonList.java +++ b/src/main/java/exopandora/worldhandler/gui/widget/menu/impl/MenuButtonList.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.gui.menu.impl; +package exopandora.worldhandler.gui.widget.menu.impl; import java.util.ArrayList; import java.util.Collections; @@ -10,10 +10,10 @@ import javax.annotation.Nullable; import com.mojang.blaze3d.vertex.PoseStack; import exopandora.worldhandler.gui.container.Container; -import exopandora.worldhandler.gui.menu.Menu; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; import exopandora.worldhandler.gui.widget.button.GuiButtonList; import exopandora.worldhandler.gui.widget.button.GuiButtonList.Persistence; +import exopandora.worldhandler.gui.widget.menu.Menu; import exopandora.worldhandler.util.Node; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.TextComponent; diff --git a/src/main/java/exopandora/worldhandler/gui/menu/impl/MenuColorField.java b/src/main/java/exopandora/worldhandler/gui/widget/menu/impl/MenuColorField.java similarity index 98% rename from src/main/java/exopandora/worldhandler/gui/menu/impl/MenuColorField.java rename to src/main/java/exopandora/worldhandler/gui/widget/menu/impl/MenuColorField.java index 6a2b8b4..a050284 100644 --- a/src/main/java/exopandora/worldhandler/gui/menu/impl/MenuColorField.java +++ b/src/main/java/exopandora/worldhandler/gui/widget/menu/impl/MenuColorField.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.gui.menu.impl; +package exopandora.worldhandler.gui.widget.menu.impl; import java.util.ArrayList; import java.util.List; @@ -6,10 +6,10 @@ import java.util.List; import com.mojang.blaze3d.vertex.PoseStack; import exopandora.worldhandler.gui.container.Container; -import exopandora.worldhandler.gui.menu.Menu; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; import exopandora.worldhandler.gui.widget.button.GuiButtonList; import exopandora.worldhandler.gui.widget.button.GuiTextFieldTooltip; +import exopandora.worldhandler.gui.widget.menu.Menu; import exopandora.worldhandler.util.MutableTextComponent; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.MutableComponent; diff --git a/src/main/java/exopandora/worldhandler/gui/menu/impl/MenuPageList.java b/src/main/java/exopandora/worldhandler/gui/widget/menu/impl/MenuPageList.java similarity index 94% rename from src/main/java/exopandora/worldhandler/gui/menu/impl/MenuPageList.java rename to src/main/java/exopandora/worldhandler/gui/widget/menu/impl/MenuPageList.java index 05107e8..2756e89 100644 --- a/src/main/java/exopandora/worldhandler/gui/menu/impl/MenuPageList.java +++ b/src/main/java/exopandora/worldhandler/gui/widget/menu/impl/MenuPageList.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.gui.menu.impl; +package exopandora.worldhandler.gui.widget.menu.impl; import java.util.List; import java.util.Objects; @@ -7,8 +7,8 @@ import com.mojang.blaze3d.vertex.PoseStack; import exopandora.worldhandler.config.Config; import exopandora.worldhandler.gui.container.Container; -import exopandora.worldhandler.gui.menu.Menu; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; +import exopandora.worldhandler.gui.widget.menu.Menu; import exopandora.worldhandler.util.TextUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; diff --git a/src/main/java/exopandora/worldhandler/usercontent/UsercontentAPI.java b/src/main/java/exopandora/worldhandler/usercontent/UsercontentAPI.java index 3299fe1..e36717e 100644 --- a/src/main/java/exopandora/worldhandler/usercontent/UsercontentAPI.java +++ b/src/main/java/exopandora/worldhandler/usercontent/UsercontentAPI.java @@ -1,12 +1,12 @@ 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 exopandora.worldhandler.builder.argument.IDeserializableArgument; +import exopandora.worldhandler.builder.impl.UsercontentCommandBuilder; import net.minecraft.Util; import net.minecraft.client.Minecraft; import net.minecraft.network.chat.ChatType; @@ -15,9 +15,9 @@ import net.minecraft.network.chat.TextComponent; public class UsercontentAPI { private final Map values = new HashMap(); - private final List builders; + private final Map builders; - public UsercontentAPI(List builders) + public UsercontentAPI(Map builders) { this.builders = builders; } @@ -28,33 +28,47 @@ public class UsercontentAPI return this.values.get(id); } - public void updateValue(String id, String value) + public void setValue(String id, String value) { this.values.put(id, value); } public void addChatMessage(Object object) { - if(object != null) - { - Minecraft.getInstance().gui.handleChat(ChatType.CHAT, new TextComponent(object.toString()), Util.NIL_UUID); - } + Minecraft.getInstance().gui.handleChat(ChatType.CHAT, new TextComponent(object != null ? object.toString() : "null"), Util.NIL_UUID); } - public void setCommandArgument(int command, int index, String object) + public void setArgument(String command, String argument, String value) { - if(command < this.builders.size() && command >= 0) + UsercontentCommandBuilder builder = this.builders.get(command); + + if(builder != null) { - this.builders.get(command).set(index, object); + builder.setArgument(argument, value); } } @Nullable - public String getCommandArgument(int command, int index) + private IDeserializableArgument getArgumentInternal(String command, String argument) { - if(command < this.builders.size() && command >= 0) + UsercontentCommandBuilder builder = this.builders.get(command); + + if(builder != null) { - return this.builders.get(command).get(index); + return builder.getArgument(argument); + } + + return null; + } + + @Nullable + public String getArgument(String command, String argument) + { + IDeserializableArgument result = this.getArgumentInternal(command, argument); + + if(result != null) + { + return result.serialize(); } return null; diff --git a/src/main/java/exopandora/worldhandler/usercontent/UsercontentLoader.java b/src/main/java/exopandora/worldhandler/usercontent/UsercontentLoader.java index 3c5d1af..fd4d7d4 100644 --- a/src/main/java/exopandora/worldhandler/usercontent/UsercontentLoader.java +++ b/src/main/java/exopandora/worldhandler/usercontent/UsercontentLoader.java @@ -24,9 +24,9 @@ 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.widget.button.EnumIcon; import exopandora.worldhandler.usercontent.model.Action; +import exopandora.worldhandler.usercontent.model.ArgumentType; import exopandora.worldhandler.usercontent.model.BooleanExpression; import exopandora.worldhandler.usercontent.model.JsonMenu; import exopandora.worldhandler.usercontent.model.JsonUsercontent; @@ -173,7 +173,7 @@ public class UsercontentLoader @Override public void write(JsonWriter writer, T value) throws IOException { - writer.value(value.name().toLowerCase()); + writer.value(value.toString()); } @Override diff --git a/src/main/java/exopandora/worldhandler/usercontent/VisibleObject.java b/src/main/java/exopandora/worldhandler/usercontent/VisibleObject.java index 5e39f90..146ae3b 100644 --- a/src/main/java/exopandora/worldhandler/usercontent/VisibleObject.java +++ b/src/main/java/exopandora/worldhandler/usercontent/VisibleObject.java @@ -23,7 +23,7 @@ public class VisibleObject return true; } - public T getObject() + public T get() { return this.object; } diff --git a/src/main/java/exopandora/worldhandler/usercontent/factory/AbstractWidgetFactory.java b/src/main/java/exopandora/worldhandler/usercontent/factory/AbstractWidgetFactory.java index 08aa530..c71194c 100644 --- a/src/main/java/exopandora/worldhandler/usercontent/factory/AbstractWidgetFactory.java +++ b/src/main/java/exopandora/worldhandler/usercontent/factory/AbstractWidgetFactory.java @@ -4,7 +4,7 @@ import java.util.function.Supplier; import exopandora.worldhandler.WorldHandler; import exopandora.worldhandler.gui.content.Content; -import exopandora.worldhandler.gui.menu.impl.ILogicMapped; +import exopandora.worldhandler.gui.widget.menu.impl.ILogicMapped; import exopandora.worldhandler.usercontent.UsercontentAPI; import exopandora.worldhandler.usercontent.model.AbstractJsonWidget; import exopandora.worldhandler.usercontent.model.JsonItem; @@ -73,7 +73,7 @@ public abstract class AbstractWidgetFactory { try { - this.api.updateValue(this.widget.getAttributes().getId(), item.getId()); + this.api.setValue(this.widget.getAttributes().getId(), item.getId()); ActionHandler action = this.actionHandlerFactory.createActionHandler(this.content, this.widget.getAction(), this.player, item.getId()); if(action != null) diff --git a/src/main/java/exopandora/worldhandler/usercontent/factory/ActionHandlerFactory.java b/src/main/java/exopandora/worldhandler/usercontent/factory/ActionHandlerFactory.java index 1b3c630..857f971 100644 --- a/src/main/java/exopandora/worldhandler/usercontent/factory/ActionHandlerFactory.java +++ b/src/main/java/exopandora/worldhandler/usercontent/factory/ActionHandlerFactory.java @@ -1,14 +1,14 @@ package exopandora.worldhandler.usercontent.factory; -import java.util.List; +import java.util.Map; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; import javax.annotation.Nullable; -import exopandora.worldhandler.builder.impl.BuilderGeneric; -import exopandora.worldhandler.builder.impl.BuilderUsercontent; +import exopandora.worldhandler.builder.impl.LiteralCommandBuilder; +import exopandora.worldhandler.builder.impl.UsercontentCommandBuilder; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.usercontent.ScriptEngineAdapter; import exopandora.worldhandler.usercontent.UsercontentAPI; @@ -21,10 +21,10 @@ import exopandora.worldhandler.util.CommandHelper; public class ActionHandlerFactory { private final UsercontentAPI api; - private final List> builders; + private final Map> builders; private final ScriptEngineAdapter engine; - public ActionHandlerFactory(UsercontentAPI api, List> builders, ScriptEngineAdapter engine) + public ActionHandlerFactory(UsercontentAPI api, Map> builders, ScriptEngineAdapter engine) { this.api = api; this.builders = builders; @@ -57,11 +57,11 @@ public class ActionHandlerFactory { return () -> { - VisibleObject visObj = this.builders.get(action.getAttributes().getCommand()); + VisibleObject visObj = this.builders.get(action.getAttributes().getCommand()); - if(visObj != null && visObj.getObject() != null) + if(visObj != null && visObj.get() != null) { - visObj.getObject().set(action.getAttributes().getIndex(), value != null ? value : action.getAttributes().getValue()); + visObj.get().setArgument(action.getAttributes().getArgument(), value != null ? value : action.getAttributes().getValue()); } }; } @@ -72,11 +72,20 @@ public class ActionHandlerFactory { return () -> { - if(action.getAttributes().getValue() == null) + if(action.getAttributes().getValue() != null && !action.getAttributes().getValue().isEmpty() && action.getAttributes().getCommand() != null) { - CommandHelper.sendCommand(player.get(), this.builders.get(action.getAttributes().getCommand()).getObject()); + CommandHelper.sendCommand(player.get(), this.builders.get(action.getAttributes().getCommand()).get(), action.getAttributes().getValue()); } - else if(!action.getAttributes().getValue().isEmpty()) + }; + } + } + else if(Action.Type.RUN_STRING.equals(action.getType())) + { + if(action.getAttributes() != null) + { + return () -> + { + if(action.getAttributes().getValue() != null && !action.getAttributes().getValue().isEmpty()) { String command = action.getAttributes().getValue(); @@ -85,7 +94,7 @@ public class ActionHandlerFactory command = command.substring(1); } - CommandHelper.sendCommand(player.get(), new BuilderGeneric(command)); + CommandHelper.sendCommand(player.get(), new LiteralCommandBuilder(command), LiteralCommandBuilder.Label.ROOT); } }; } @@ -118,8 +127,8 @@ public class ActionHandlerFactory return string -> { String value = toStringMapper.apply(string); - this.api.updateValue(id, value); - this.builders.get(action.getAttributes().getCommand()).getObject().set(action.getAttributes().getIndex(), value); + this.api.setValue(id, value); + this.builders.get(action.getAttributes().getCommand()).get().setArgument(action.getAttributes().getArgument(), value); }; } } @@ -130,12 +139,12 @@ public class ActionHandlerFactory return string -> { String value = toStringMapper.apply(string); - this.api.updateValue(id, value); + this.api.setValue(id, value); this.engine.invokeFunction(action.getAttributes().getFunction(), value); }; } } - return string -> this.api.updateValue(id, toStringMapper.apply(string)); + return string -> this.api.setValue(id, toStringMapper.apply(string)); } } diff --git a/src/main/java/exopandora/worldhandler/usercontent/factory/MenuFactory.java b/src/main/java/exopandora/worldhandler/usercontent/factory/MenuFactory.java index 6ae62c3..0953852 100644 --- a/src/main/java/exopandora/worldhandler/usercontent/factory/MenuFactory.java +++ b/src/main/java/exopandora/worldhandler/usercontent/factory/MenuFactory.java @@ -6,11 +6,11 @@ import javax.annotation.Nullable; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.content.Content; -import exopandora.worldhandler.gui.menu.Menu; -import exopandora.worldhandler.gui.menu.impl.ILogicPageList; -import exopandora.worldhandler.gui.menu.impl.MenuPageList; import exopandora.worldhandler.gui.widget.button.GuiButtonBase; import exopandora.worldhandler.gui.widget.button.GuiButtonTooltip; +import exopandora.worldhandler.gui.widget.menu.Menu; +import exopandora.worldhandler.gui.widget.menu.impl.ILogicPageList; +import exopandora.worldhandler.gui.widget.menu.impl.MenuPageList; import exopandora.worldhandler.usercontent.UsercontentAPI; import exopandora.worldhandler.usercontent.model.AbstractJsonWidget; import exopandora.worldhandler.usercontent.model.JsonItem; diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/Action.java b/src/main/java/exopandora/worldhandler/usercontent/model/Action.java index 94efadb..4099b1b 100644 --- a/src/main/java/exopandora/worldhandler/usercontent/model/Action.java +++ b/src/main/java/exopandora/worldhandler/usercontent/model/Action.java @@ -68,6 +68,13 @@ public class Action throw new IllegalStateException("action.attributes is null"); } } + else if(this.type == Type.RUN_STRING) + { + if(this.getAttributes() == null) + { + throw new IllegalStateException("action.attributes is null"); + } + } else if(this.type == Type.JS) { if(this.getAttributes() == null) @@ -86,6 +93,7 @@ public class Action OPEN, SET, RUN, + RUN_STRING, BACK, BACK_TO_GAME, JS; diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/ActionAttributes.java b/src/main/java/exopandora/worldhandler/usercontent/model/ActionAttributes.java index 6b2c38f..f9e0452 100644 --- a/src/main/java/exopandora/worldhandler/usercontent/model/ActionAttributes.java +++ b/src/main/java/exopandora/worldhandler/usercontent/model/ActionAttributes.java @@ -8,19 +8,19 @@ public class ActionAttributes private String function; @SerializedName("command") - private int command; + private String command; - @SerializedName("index") - private int index; + @SerializedName("argument") + private String argument; @SerializedName("value") private String value; - public ActionAttributes(String function, int command, int index, String value) + public ActionAttributes(String function, String command, String argument, String value) { this.function = function; this.command = command; - this.index = index; + this.argument = argument; this.value = value; } @@ -34,24 +34,24 @@ public class ActionAttributes this.function = function; } - public int getCommand() + public String getCommand() { return this.command; } - public void setCommand(int command) + public void setCommand(String command) { this.command = command; } - public int getIndex() + public String getArgument() { - return this.index; + return this.argument; } - public void setIndex(int index) + public void setArgument(String argument) { - this.index = index; + this.argument = argument; } public String getValue() diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/JsonCommand.java b/src/main/java/exopandora/worldhandler/usercontent/model/JsonCommand.java index 0e5b67a..9aa48e9 100644 --- a/src/main/java/exopandora/worldhandler/usercontent/model/JsonCommand.java +++ b/src/main/java/exopandora/worldhandler/usercontent/model/JsonCommand.java @@ -1,45 +1,41 @@ package exopandora.worldhandler.usercontent.model; -import java.util.List; - import com.google.gson.annotations.SerializedName; -import exopandora.worldhandler.builder.CommandSyntax.Argument; - public class JsonCommand { - @SerializedName("name") - private String name; + @SerializedName("label") + private String label; @SerializedName("syntax") - private List syntax = null; + private JsonArgument syntax = null; @SerializedName("visible") private BooleanExpression visible; - public JsonCommand(String name, List syntax, BooleanExpression visible) + public JsonCommand(String label, JsonArgument syntax, BooleanExpression visible) { - this.name = name; + this.label = label; this.syntax = syntax; this.visible = visible; } - public String getName() + public String getLabel() { - return this.name; + return this.label; } - public void setName(String name) + public void setLabel(String label) { - this.name = name; + this.label = label; } - public List getSyntax() + public JsonArgument getSyntax() { return this.syntax; } - public void setSyntax(List syntax) + public void setSyntax(JsonArgument syntax) { this.syntax = syntax; } diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/JsonModel.java b/src/main/java/exopandora/worldhandler/usercontent/model/JsonModel.java deleted file mode 100644 index 3a8ada5..0000000 --- a/src/main/java/exopandora/worldhandler/usercontent/model/JsonModel.java +++ /dev/null @@ -1,26 +0,0 @@ -package exopandora.worldhandler.usercontent.model; - -import java.util.List; - -import com.google.gson.annotations.SerializedName; - -public class JsonModel -{ - @SerializedName("commands") - private List commands = null; - - public JsonModel(List commands) - { - this.commands = commands; - } - - public List getCommands() - { - return this.commands; - } - - public void setCommands(List commands) - { - this.commands = commands; - } -} diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/JsonUsercontent.java b/src/main/java/exopandora/worldhandler/usercontent/model/JsonUsercontent.java index e50b304..5acb2b8 100644 --- a/src/main/java/exopandora/worldhandler/usercontent/model/JsonUsercontent.java +++ b/src/main/java/exopandora/worldhandler/usercontent/model/JsonUsercontent.java @@ -1,29 +1,31 @@ package exopandora.worldhandler.usercontent.model; +import java.util.Map; + import com.google.gson.annotations.SerializedName; public class JsonUsercontent { - @SerializedName("model") - private JsonModel model; + @SerializedName("commands") + private Map commands = null; @SerializedName("gui") private JsonGui gui; - public JsonUsercontent(JsonModel model, JsonGui gui) + public JsonUsercontent(Map commands, JsonGui gui) { - this.model = model; + this.commands = commands; this.gui = gui; } - public JsonModel getModel() + public Map getCommands() { - return this.model; + return this.commands; } - public void setModel(JsonModel model) + public void setCommands(Map commands) { - this.model = model; + this.commands = commands; } public JsonGui getGui() diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/JsonWidget.java b/src/main/java/exopandora/worldhandler/usercontent/model/JsonWidget.java index 6be2ef0..7749a36 100644 --- a/src/main/java/exopandora/worldhandler/usercontent/model/JsonWidget.java +++ b/src/main/java/exopandora/worldhandler/usercontent/model/JsonWidget.java @@ -75,7 +75,7 @@ public class JsonWidget extends AbstractJsonWidget throw new IllegalStateException("widget.attributes.item is null"); } - this.validateAction(Action.Type.OPEN, Action.Type.SET, Action.Type.RUN, Action.Type.BACK, Action.Type.BACK_TO_GAME, Action.Type.JS); + this.validateAction(Action.Type.OPEN, Action.Type.SET, Action.Type.RUN, Action.Type.RUN_STRING, Action.Type.BACK, Action.Type.BACK_TO_GAME, Action.Type.JS); } else if(this.type == Type.ICON_BUTTON) { @@ -88,7 +88,7 @@ public class JsonWidget extends AbstractJsonWidget throw new IllegalStateException("widget.attributes.icon is null"); } - this.validateAction(Action.Type.OPEN, Action.Type.SET, Action.Type.RUN, Action.Type.BACK, Action.Type.BACK_TO_GAME, Action.Type.JS); + this.validateAction(Action.Type.OPEN, Action.Type.SET, Action.Type.RUN, Action.Type.RUN_STRING, Action.Type.BACK, Action.Type.BACK_TO_GAME, Action.Type.JS); } else if(this.type == Type.LIST_BUTTON) { diff --git a/src/main/java/exopandora/worldhandler/util/ActionHelper.java b/src/main/java/exopandora/worldhandler/util/ActionHelper.java index 6af2972..f106ccf 100644 --- a/src/main/java/exopandora/worldhandler/util/ActionHelper.java +++ b/src/main/java/exopandora/worldhandler/util/ActionHelper.java @@ -2,13 +2,11 @@ package exopandora.worldhandler.util; import exopandora.worldhandler.Main; import exopandora.worldhandler.WorldHandler; -import exopandora.worldhandler.builder.impl.BuilderDifficulty; -import exopandora.worldhandler.builder.impl.BuilderGamemode; -import exopandora.worldhandler.builder.impl.BuilderGamemode.EnumGamemode; -import exopandora.worldhandler.builder.impl.BuilderTime; -import exopandora.worldhandler.builder.impl.BuilderTime.EnumMode; -import exopandora.worldhandler.builder.impl.BuilderWeather; -import exopandora.worldhandler.builder.impl.BuilderWeather.EnumWeather; +import exopandora.worldhandler.builder.argument.Gamemode; +import exopandora.worldhandler.builder.impl.DifficultyCommandBuilder; +import exopandora.worldhandler.builder.impl.GamemodeCommandBuilder; +import exopandora.worldhandler.builder.impl.TimeCommandBuilder; +import exopandora.worldhandler.builder.impl.WeatherCommandBuilder; import exopandora.worldhandler.config.Config; import exopandora.worldhandler.gui.container.impl.GuiWorldHandler; import exopandora.worldhandler.gui.content.Content; @@ -67,77 +65,98 @@ public class ActionHelper public static void timeDawn() { - CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderTime(EnumMode.SET, Config.getSettings().getDawn())); + ActionHelper.setDayTime(Config.getSettings().getDawn()); } public static void timeNoon() { - CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderTime(EnumMode.SET, Config.getSettings().getNoon())); + ActionHelper.setDayTime(Config.getSettings().getNoon()); } public static void timeSunset() { - CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderTime(EnumMode.SET, Config.getSettings().getSunset())); + ActionHelper.setDayTime(Config.getSettings().getSunset()); } public static void timeMidnight() { - CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderTime(EnumMode.SET, Config.getSettings().getMidnight())); + ActionHelper.setDayTime(Config.getSettings().getMidnight()); + } + + public static void setDayTime(int time) + { + TimeCommandBuilder builder = new TimeCommandBuilder(); + builder.time().set((float) time); + CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), builder, TimeCommandBuilder.Label.SET); } public static void weatherClear() { - CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderWeather(EnumWeather.CLEAR)); + CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new WeatherCommandBuilder(), WeatherCommandBuilder.Label.CLEAR); } public static void weatherRain() { - CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderWeather(EnumWeather.RAIN)); + CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new WeatherCommandBuilder(), WeatherCommandBuilder.Label.RAIN); } public static void weatherThunder() { - CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderWeather(EnumWeather.THUNDER)); + CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new WeatherCommandBuilder(), WeatherCommandBuilder.Label.THUNDER); } public static void difficultyPeaceful() { - CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderDifficulty(Difficulty.PEACEFUL)); + ActionHelper.setDifficulty(Difficulty.PEACEFUL); } public static void difficultyEasy() { - CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderDifficulty(Difficulty.EASY)); + ActionHelper.setDifficulty(Difficulty.EASY); } public static void difficultyNormal() { - CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderDifficulty(Difficulty.NORMAL)); + ActionHelper.setDifficulty(Difficulty.NORMAL); } public static void difficultyHard() { - CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderDifficulty(Difficulty.HARD)); + ActionHelper.setDifficulty(Difficulty.HARD); + } + + private static void setDifficulty(Difficulty difficulty) + { + DifficultyCommandBuilder builder = new DifficultyCommandBuilder(); + builder.difficulty().set(difficulty); + CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), builder, DifficultyCommandBuilder.Label.DIFFICULTY); } public static void gamemodeSurvival() { - CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderGamemode(EnumGamemode.SURVIVAL)); + ActionHelper.setGamemode(Gamemode.SURVIVAL); } public static void gamemodeCreative() { - CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderGamemode(EnumGamemode.CREATIVE)); + ActionHelper.setGamemode(Gamemode.CREATIVE); } public static void gamemodeAdventure() { - CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderGamemode(EnumGamemode.ADVENTURE)); + ActionHelper.setGamemode(Gamemode.ADVENTURE); } public static void gamemodeSpectator() { - CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), new BuilderGamemode(EnumGamemode.SPECTATOR)); + ActionHelper.setGamemode(Gamemode.SPECTATOR); + } + + private static void setGamemode(Gamemode gamemode) + { + GamemodeCommandBuilder builder = new GamemodeCommandBuilder(); + builder.gamemode().set(gamemode); + CommandHelper.sendCommand(Minecraft.getInstance().getUser().getName(), builder, GamemodeCommandBuilder.Label.GAMEMODE); } public static void tryRun(ActionHandler action) diff --git a/src/main/java/exopandora/worldhandler/util/BlockHelper.java b/src/main/java/exopandora/worldhandler/util/BlockHelper.java index e6f8b28..627667a 100644 --- a/src/main/java/exopandora/worldhandler/util/BlockHelper.java +++ b/src/main/java/exopandora/worldhandler/util/BlockHelper.java @@ -1,30 +1,26 @@ package exopandora.worldhandler.util; -import java.util.ArrayList; -import java.util.List; -import java.util.function.Consumer; -import java.util.function.Function; - import javax.annotation.Nonnull; import org.apache.commons.lang3.ArrayUtils; -import exopandora.worldhandler.builder.impl.BuilderExecute; -import exopandora.worldhandler.builder.impl.BuilderExecute.EnumMode; -import exopandora.worldhandler.builder.impl.BuilderFill; -import exopandora.worldhandler.builder.impl.BuilderSetBlock; -import exopandora.worldhandler.builder.types.BlockResourceLocation; -import exopandora.worldhandler.builder.types.Coordinate.EnumType; -import exopandora.worldhandler.builder.types.CoordinateInt; +import exopandora.worldhandler.builder.ICommandBuilder; +import exopandora.worldhandler.builder.argument.Coordinate; +import exopandora.worldhandler.builder.impl.ExecuteCommandBuilder; +import exopandora.worldhandler.builder.impl.FillCommandBuilder; +import exopandora.worldhandler.builder.impl.SetBlockCommandBuilder; +import exopandora.worldhandler.builder.impl.ExecuteCommandBuilder.AtOptionalArgument; import exopandora.worldhandler.config.Config; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.BlockPos; +import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.network.protocol.game.ServerboundSetCommandBlockPacket; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.CommandBlockEntity; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; @@ -32,10 +28,8 @@ import net.minecraft.world.phys.HitResult.Type; public class BlockHelper { - private static BlockPos pos1 = BlockPos.ZERO; - private static BlockPos pos2 = BlockPos.ZERO; - private static final List> POS_1_OBSERVERS = new ArrayList>(); - private static final List> POS_2_OBSERVERS = new ArrayList>(); + private static MutableBlockPos pos1 = new MutableBlockPos(0, -64, 0); + private static MutableBlockPos pos2 = new MutableBlockPos(0, -64, 0); private static final Block[] BLACKLIST = new Block[] {Blocks.AIR, Blocks.WATER, Blocks.LAVA}; @Nonnull @@ -83,116 +77,36 @@ public class BlockHelper return Blocks.AIR; } - public static BlockPos setX(BlockPos pos, double x) - { - return new BlockPos(x, pos.getY(), pos.getZ()); - } - - public static BlockPos setY(BlockPos pos, double y) - { - return new BlockPos(pos.getX(), y, pos.getZ()); - } - - public static BlockPos setZ(BlockPos pos, double z) - { - return new BlockPos(pos.getX(), pos.getY(), z); - } - - @Nonnull - public static BlockPos getPos1() - { - return BlockHelper.pos1; - } - - public static void setPos1(BlockPos pos) - { - if(pos != null && !BlockHelper.pos1.equals(pos)) - { - BlockHelper.pos1 = pos; - - for(Consumer observer : POS_1_OBSERVERS) - { - observer.accept(BlockHelper.pos1); - } - } - } - - @Nonnull - public static BlockPos getPos2() - { - return BlockHelper.pos2; - } - - public static void setPos2(BlockPos pos) - { - if(pos != null && !BlockHelper.pos2.equals(pos)) - { - BlockHelper.pos2 = pos; - - for(Consumer observer : POS_2_OBSERVERS) - { - observer.accept(BlockHelper.pos2); - } - } - } - - public static T addPositionObservers(T observer, Function> pos1generator, Function> pos2generator) - { - BlockHelper.addPos1Observer(pos1generator.apply(observer)); - BlockHelper.addPos2Observer(pos2generator.apply(observer)); - return observer; - } - - public static void addPos1Observer(Consumer observer) - { - POS_1_OBSERVERS.add(observer); - } - - public static void removePos1Observer(Consumer observer) - { - POS_1_OBSERVERS.remove(observer); - } - - public static void addPos2Observer(Consumer observer) - { - POS_2_OBSERVERS.add(observer); - } - - public static void removePos2Observer(Consumer observer) - { - POS_2_OBSERVERS.add(observer); - } - - public static boolean setCommandBlockNearPlayer(String player, String command) + public static boolean setCommandBlockNearPlayer(String player, ICommandBuilder command, Object label) { if(CommandHelper.canPlayerIssueCommand() && Minecraft.getInstance().getConnection() != null) { BlockPos pos = Minecraft.getInstance().player.blockPosition().offset(0, 3, 0); - BuilderFill placeFill = new BuilderFill(); - placeFill.setPosition1(pos); - placeFill.setPosition2(pos.above()); - placeFill.setBlock1(new BlockResourceLocation(Blocks.COMMAND_BLOCK.getRegistryName())); + FillCommandBuilder place = new FillCommandBuilder(); + place.from().set(pos); + place.to().set(pos.above()); + place.block().set(Blocks.COMMAND_BLOCK); - BuilderFill removeFill = new BuilderFill(); - removeFill.setX1(new CoordinateInt(0, EnumType.GLOBAL)); - removeFill.setY1(new CoordinateInt(-1, EnumType.GLOBAL)); - removeFill.setZ1(new CoordinateInt(0, EnumType.GLOBAL)); - removeFill.setX2(new CoordinateInt(0, EnumType.GLOBAL)); - removeFill.setY2(new CoordinateInt(0, EnumType.GLOBAL)); - removeFill.setZ2(new CoordinateInt(0, EnumType.GLOBAL)); - removeFill.setBlock1(new BlockResourceLocation(Blocks.AIR.getRegistryName())); + FillCommandBuilder remove = new FillCommandBuilder(); + remove.from().setX(new Coordinate.Ints(0, Coordinate.Type.RELATIVE)); + remove.from().setY(new Coordinate.Ints(-1, Coordinate.Type.RELATIVE)); + remove.from().setZ(new Coordinate.Ints(0, Coordinate.Type.RELATIVE)); + remove.to().setX(new Coordinate.Ints(0, Coordinate.Type.RELATIVE)); + remove.to().setY(new Coordinate.Ints(0, Coordinate.Type.RELATIVE)); + remove.to().setZ(new Coordinate.Ints(0, Coordinate.Type.RELATIVE)); + remove.block().set(Blocks.AIR); - Minecraft.getInstance().player.chat(placeFill.toActualCommand()); + Minecraft.getInstance().player.chat(place.toCommand(FillCommandBuilder.Label.FILL, false)); - BuilderExecute wrapped = new BuilderExecute(); - wrapped.setMode1(EnumMode.AT); - wrapped.setTarget(player); - wrapped.setMode2(EnumMode.RUN); - wrapped.setCommand(command); + ExecuteCommandBuilder execute = new ExecuteCommandBuilder(); + AtOptionalArgument at = new AtOptionalArgument(AtOptionalArgument.Label.AT); + at.targets().setTarget(player); + execute.modifiers().add(at); + execute.command().set(command, label); - Minecraft.getInstance().getConnection().send(new ServerboundSetCommandBlockPacket(pos, wrapped.toActualCommand(), CommandBlockEntity.Mode.REDSTONE, true, false, true)); - Minecraft.getInstance().getConnection().send(new ServerboundSetCommandBlockPacket(pos.above(), removeFill.toActualCommand(), CommandBlockEntity.Mode.REDSTONE, true, false, true)); + Minecraft.getInstance().getConnection().send(new ServerboundSetCommandBlockPacket(pos, execute.toCommand(ExecuteCommandBuilder.Label.RUN, false), CommandBlockEntity.Mode.REDSTONE, true, false, true)); + Minecraft.getInstance().getConnection().send(new ServerboundSetCommandBlockPacket(pos.above(), remove.toCommand(FillCommandBuilder.Label.FILL, false), CommandBlockEntity.Mode.REDSTONE, true, false, true)); return true; } @@ -202,13 +116,41 @@ public class BlockHelper public static void setBlockNearPlayer(String player, Block block) { - BuilderSetBlock builder = new BuilderSetBlock(new CoordinateInt(EnumType.LOCAL), new CoordinateInt(EnumType.LOCAL), new CoordinateInt(2, EnumType.LOCAL), block.getRegistryName(), Config.getSettings().getBlockPlacingMode()); + SetBlockCommandBuilder builder = new SetBlockCommandBuilder(); + builder.pos().setX(new Coordinate.Ints(Coordinate.Type.LOCAL)); + builder.pos().setY(new Coordinate.Ints(Coordinate.Type.LOCAL)); + builder.pos().setZ(new Coordinate.Ints(2, Coordinate.Type.LOCAL)); - if(Minecraft.getInstance().player != null) + BlockState state = block.defaultBlockState(); + + if(Minecraft.getInstance().player != null && state.hasProperty(BlockStateProperties.HORIZONTAL_FACING)) { - builder.setState(BlockStateProperties.HORIZONTAL_FACING, Minecraft.getInstance().player.getDirection().getOpposite()); + state = state.setValue(BlockStateProperties.HORIZONTAL_FACING, Minecraft.getInstance().player.getDirection().getOpposite()); } - CommandHelper.sendCommand(player, builder); + builder.block().set(state); + + switch(Config.getSettings().getBlockPlacingMode()) + { + case KEEP: + CommandHelper.sendCommand(player, builder, SetBlockCommandBuilder.Label.KEEP); + break; + case REPLACE: + CommandHelper.sendCommand(player, builder, SetBlockCommandBuilder.Label.REPLACE); + break; + case DESTROY: + CommandHelper.sendCommand(player, builder, SetBlockCommandBuilder.Label.DESTROY); + break; + } + } + + public static MutableBlockPos pos1() + { + return pos1; + } + + public static MutableBlockPos pos2() + { + return pos2; } } diff --git a/src/main/java/exopandora/worldhandler/util/CommandHelper.java b/src/main/java/exopandora/worldhandler/util/CommandHelper.java index 171d617..e499f6d 100644 --- a/src/main/java/exopandora/worldhandler/util/CommandHelper.java +++ b/src/main/java/exopandora/worldhandler/util/CommandHelper.java @@ -4,7 +4,6 @@ import com.mojang.brigadier.CommandDispatcher; import exopandora.worldhandler.WorldHandler; import exopandora.worldhandler.builder.ICommandBuilder; -import exopandora.worldhandler.builder.ICommandBuilderSyntax; import exopandora.worldhandler.command.CommandWH; import exopandora.worldhandler.command.CommandWorldHandler; import net.minecraft.client.Minecraft; @@ -13,6 +12,8 @@ import net.minecraft.network.chat.TextComponent; public class CommandHelper { + public static final int MAX_COMMAND_LENGTH = 256; + public static void sendFeedback(CommandSourceStack source, String message) { source.sendSuccess(new TextComponent(message), false); @@ -34,36 +35,24 @@ public class CommandHelper CommandWH.register(dispatcher); } - public static void sendCommand(String player, ICommandBuilder builder) + public static void sendCommand(String player, ICommandBuilder builder, Object label) { - CommandHelper.sendCommand(player, builder, false); + CommandHelper.sendCommand(player, builder, label, false); } - public static void sendCommand(String player, ICommandBuilder builder, boolean special) + public static void sendCommand(String player, ICommandBuilder builder, Object label, boolean special) { - if(builder != null) + String command = builder.toCommand(label, false); + + if(builder.needsCommandBlock(label, false) || special) { - String command; - - if(builder instanceof ICommandBuilderSyntax) - { - command = ((ICommandBuilderSyntax) builder).toActualCommand(); - } - else - { - command = builder.toCommand(); - } - - WorldHandler.LOGGER.info("Command: " + command); - - if(builder.needsCommandBlock() || special) - { - BlockHelper.setCommandBlockNearPlayer(player, command); - } - else if(Minecraft.getInstance().player != null) - { - Minecraft.getInstance().player.chat(command); - } + BlockHelper.setCommandBlockNearPlayer(player, builder, label); } + else if(Minecraft.getInstance().player != null) + { + Minecraft.getInstance().player.chat(command); + } + + WorldHandler.LOGGER.info("Command: " + command); } } diff --git a/src/main/java/exopandora/worldhandler/util/EnumHelper.java b/src/main/java/exopandora/worldhandler/util/EnumHelper.java index 0b07e0a..1499bdc 100644 --- a/src/main/java/exopandora/worldhandler/util/EnumHelper.java +++ b/src/main/java/exopandora/worldhandler/util/EnumHelper.java @@ -1,5 +1,7 @@ package exopandora.worldhandler.util; +import java.util.function.Function; + import javax.annotation.Nullable; public class EnumHelper @@ -16,4 +18,18 @@ public class EnumHelper return null; } } + + @Nullable + public static > T find(String key, T[] values, Function mapper) + { + for(T value : values) + { + if(mapper.apply(value).equals(key)) + { + return value; + } + } + + return null; + } } diff --git a/src/main/java/exopandora/worldhandler/util/MutableTextComponent.java b/src/main/java/exopandora/worldhandler/util/MutableTextComponent.java index 4eceb5f..37bf565 100644 --- a/src/main/java/exopandora/worldhandler/util/MutableTextComponent.java +++ b/src/main/java/exopandora/worldhandler/util/MutableTextComponent.java @@ -1,6 +1,5 @@ package exopandora.worldhandler.util; -import exopandora.worldhandler.builder.INBTWritable; import net.minecraft.ChatFormatting; import net.minecraft.nbt.StringTag; import net.minecraft.nbt.Tag; @@ -8,7 +7,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; import net.minecraft.util.FormattedCharSequence; -public class MutableTextComponent extends TextComponent implements INBTWritable +public class MutableTextComponent extends TextComponent { public MutableTextComponent() { @@ -70,7 +69,6 @@ public class MutableTextComponent extends TextComponent implements INBTWritable return FormattedCharSequence.forward(string, this.getStyle()); } - @Override public Tag serialize() { if(this.getContents() != null && !this.getContents().isEmpty()) diff --git a/src/main/java/exopandora/worldhandler/util/NBTHelper.java b/src/main/java/exopandora/worldhandler/util/NBTHelper.java index 418c127..999f53f 100644 --- a/src/main/java/exopandora/worldhandler/util/NBTHelper.java +++ b/src/main/java/exopandora/worldhandler/util/NBTHelper.java @@ -3,9 +3,8 @@ package exopandora.worldhandler.util; import java.util.Arrays; import java.util.List; -import exopandora.worldhandler.builder.INBTWritable; -import exopandora.worldhandler.builder.component.IBuilderComponent; -import exopandora.worldhandler.builder.component.impl.EntityNBT; +import exopandora.worldhandler.builder.argument.tag.EntityTag; +import exopandora.worldhandler.builder.argument.tag.ITagProvider; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.DoubleTag; import net.minecraft.nbt.ListTag; @@ -13,6 +12,7 @@ import net.minecraft.nbt.NbtUtils; import net.minecraft.nbt.StringTag; import net.minecraft.nbt.Tag; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; import net.minecraft.world.level.block.state.BlockState; @@ -49,19 +49,19 @@ public class NBTHelper return null; } - public static Tag serialize(ResourceLocation[] itemArray) + public static Tag serialize(Item[] itemArray) { - if(Arrays.stream(itemArray).allMatch(resource -> resource != null && resource.equals(Items.AIR.getRegistryName()))) + if(Arrays.stream(itemArray).allMatch(Items.AIR::equals)) { return null; } ListTag list = new ListTag(); - for(ResourceLocation item : itemArray) + for(Item item : itemArray) { CompoundTag compound = new CompoundTag(); - compound.putString("id", item.toString()); + compound.putString("id", item.getRegistryName().toString()); compound.putInt("Count", 1); list.add(compound); } @@ -69,13 +69,13 @@ public class NBTHelper return list; } - public static Tag serialize(List entities) + public static Tag serialize(List entities) { ListTag list = new ListTag(); - for(EntityNBT entity : entities) + for(EntityTag entity : entities) { - Tag nbt = entity.serialize(); + Tag nbt = entity.value(); if(nbt != null) { @@ -91,24 +91,16 @@ public class NBTHelper return list; } - public static void append(CompoundTag compound, String tag, INBTWritable writable) + public static void append(CompoundTag compound, ITagProvider component) { - NBTHelper.append(compound, tag, writable.serialize()); - } - - public static void append(CompoundTag compound, IBuilderComponent component) - { - NBTHelper.append(compound, component.getTag(), component.serialize()); + NBTHelper.append(compound, component.key(), component.value()); } public static void append(CompoundTag compound, String tag, Tag nbt) { - if(nbt != null) + if(nbt != null && !compound.contains(tag)) { - if(!compound.contains(tag)) - { - compound.put(tag, nbt); - } + compound.put(tag, nbt); } } } diff --git a/src/main/java/exopandora/worldhandler/util/Node.java b/src/main/java/exopandora/worldhandler/util/Node.java index 3ef5804..679592a 100644 --- a/src/main/java/exopandora/worldhandler/util/Node.java +++ b/src/main/java/exopandora/worldhandler/util/Node.java @@ -52,7 +52,6 @@ public class Node { this.validateEntries(); this.entries.add(node); - return node; } @@ -145,8 +144,7 @@ public class Node } } - root.addNode(node); - return this.insertNode(index + 1, path, node); + return this.insertNode(index + 1, path, root.addNode(node)); } public void mergeItems() diff --git a/src/main/java/exopandora/worldhandler/util/RegistryHelper.java b/src/main/java/exopandora/worldhandler/util/RegistryHelper.java index b2aaba3..21926af 100644 --- a/src/main/java/exopandora/worldhandler/util/RegistryHelper.java +++ b/src/main/java/exopandora/worldhandler/util/RegistryHelper.java @@ -36,7 +36,6 @@ public class RegistryHelper Registry registry = RegistryAccess.builtin().registryOrThrow(Registry.BIOME_REGISTRY); ResourceLocation resource = registry.getKey(biome); String key = "biome." + biome.getRegistryName().getNamespace() + "." + resource.getPath(); - return Language.getInstance().has(key) ? key : resource.toString(); }); registerRegistry(ForgeRegistries.ENCHANTMENTS, Enchantment::getDescriptionId); diff --git a/src/main/java/exopandora/worldhandler/util/RenderUtils.java b/src/main/java/exopandora/worldhandler/util/RenderUtils.java index fc1b267..f14f43b 100644 --- a/src/main/java/exopandora/worldhandler/util/RenderUtils.java +++ b/src/main/java/exopandora/worldhandler/util/RenderUtils.java @@ -9,6 +9,8 @@ import net.minecraft.client.gui.GuiComponent; public class RenderUtils { + public static final double EPS = 0.0020000000949949026D; + public static void drawWatchIntoGui(PoseStack matrix, GuiComponent gui, int width, int height, long worldTicks, boolean smooth) { float hour = TextUtils.toHour(worldTicks); diff --git a/src/main/java/exopandora/worldhandler/util/ResourceHelper.java b/src/main/java/exopandora/worldhandler/util/ResourceHelper.java index 0c3022d..ea80240 100644 --- a/src/main/java/exopandora/worldhandler/util/ResourceHelper.java +++ b/src/main/java/exopandora/worldhandler/util/ResourceHelper.java @@ -3,8 +3,6 @@ package exopandora.worldhandler.util; import javax.annotation.Nullable; import exopandora.worldhandler.Main; -import exopandora.worldhandler.builder.types.BlockResourceLocation; -import exopandora.worldhandler.builder.types.ItemResourceLocation; import exopandora.worldhandler.config.Config; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.registries.IForgeRegistry; @@ -15,59 +13,26 @@ public class ResourceHelper private static final ResourceLocation BACKGROUND_VANILLA = new ResourceLocation(Main.MODID, "textures/skins/vanilla/vanilla.png"); private static final ResourceLocation BUTTON = new ResourceLocation("textures/gui/widgets.png"); - public static ResourceLocation stringToResourceLocation(String resource) + @Nullable + public static ResourceLocation stringToResourceLocation(@Nullable String resource) { - if(resource != null) + if(resource != null && !resource.isEmpty()) { - return new ResourceLocation(stripToResourceLocation(resource)); + return ResourceLocation.tryParse(resource.toLowerCase().replaceAll("[^a-z0-9/._\\-:]", "_")); } return null; } - @Nullable - public static String stripToResourceLocation(String resource) - { - if(resource != null) - { - return resource.toLowerCase().replaceAll("[^a-z0-9/._\\-:]", "_"); - } - - return null; - } - - @Nullable public static boolean isRegistered(ResourceLocation resource, IForgeRegistry registry) { return resource != null && registry != null && registry.containsKey(resource); } - @Nullable - public static boolean isRegistered(BlockResourceLocation resource, IForgeRegistry registry) - { - if(resource != null) - { - return isRegistered(resource.getResourceLocation(), registry); - } - - return false; - } - - @Nullable - public static boolean isRegistered(ItemResourceLocation resource, IForgeRegistry registry) - { - if(resource != null) - { - return isRegistered(resource.getResourceLocation(), registry); - } - - return false; - } - @Nullable public static ResourceLocation assertRegistered(ResourceLocation resource, IForgeRegistry registry) { - if(ResourceHelper.isRegistered(resource, registry)) + if(resource != null && ResourceHelper.isRegistered(resource, registry)) { return resource; } diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index febb540..111c437 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -1,3 +1,7 @@ -public net.minecraft.commands.arguments.blocks.BlockInput f_114664_ # tag -public net.minecraft.server.MinecraftServer f_129744_ # storageSource -public net.minecraft.client.gui.screens.OptionsScreen m_96244_(Lnet/minecraft/server/packs/repository/PackRepository;)V # updatePackList protected-f net.minecraft.network.chat.TextComponent f_131283_ # text +public net.minecraft.commands.arguments.blocks.BlockInput f_114664_ # tag +public net.minecraft.server.MinecraftServer f_129744_ # storageSource +public net.minecraft.client.gui.screens.OptionsScreen m_96244_(Lnet/minecraft/server/packs/repository/PackRepository;)V # updatePackList +public net.minecraft.commands.arguments.EntityAnchorArgument$Anchor f_90367_ # name +public net.minecraft.commands.arguments.coordinates.LocalCoordinates m_119908_(Lcom/mojang/brigadier/StringReader;I)D # readDouble +public net.minecraft.advancements.critereon.MinMaxBounds$Doubles (Ljava/lang/Double;Ljava/lang/Double;)V # constructor +protected-f net.minecraft.network.chat.TextComponent f_131283_ # text diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 23a501f..8957c05 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader="javafml" -loaderVersion="[37,)" +loaderVersion="[38,)" updateJSONURL="https://raw.githubusercontent.com/Exopandora/worldhandler/master/version.json" issueTrackerURL="https://github.com/Exopandora/WorldHandler/issues" displayURL="https://minecraft.curseforge.com/projects/world-handler-command-gui" @@ -11,13 +11,13 @@ license="GPL v3.0" [[mods]] modId="worldhandler" - version="1.17.1-2.12.8" + version="1.18-3.0" displayName="World Handler" description="The World Handler provides a simple and easy to use graphical user interface for commands. It lets you create powerful and complex sub-commands alongside NBT-structures within seconds." [[dependencies.worldhandler]] modId="minecraft" mandatory=true - versionRange="[1.17,)" + versionRange="[1.18,)" ordering="NONE" side="BOTH" \ No newline at end of file diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta index bc0572a..72dc25d 100644 --- a/src/main/resources/pack.mcmeta +++ b/src/main/resources/pack.mcmeta @@ -1,7 +1,6 @@ { - "pack": - { + "pack": { "description": "World Handler", - "pack_format": 6 + "pack_format": 8 } }