Added functions get/set_block_command() and get/set_command_block_name() #209

Merged
merged 15 commits into from Mar 11, 2014

Projects

None yet

3 participants

@PseudoKnight
Contributor

No description provided.

@EntityReborn
Contributor

For the set commands, verify that the input is really a string.

@PseudoKnight
Contributor

Sorry for splitting that into two commits. I'm relatively new with this tool set.

@LadyCailin LadyCailin and 1 other commented on an outdated diff Jan 30, 2014
.../java/com/laytonsmith/core/functions/Environment.java
+ return new ExceptionType[]{ExceptionType.CastException, ExceptionType.FormatException};
+ }
+
+ @Override
+ public boolean isRestricted() {
+ return true;
+ }
+
+ @Override
+ public Boolean runAsync() {
+ return false;
+ }
+
+ @Override
+ public String docs() {
+ return "boolean {locationArray} Returns the command in the Command Block at the given location.";
@LadyCailin
LadyCailin Jan 30, 2014 Contributor

Looks like this returns a string, not a boolean.

@PseudoKnight
PseudoKnight Jan 31, 2014 Contributor

Whoops.. missed that part of the docs completely.

@LadyCailin LadyCailin commented on an outdated diff Jan 30, 2014
.../java/com/laytonsmith/core/functions/Environment.java
+ return new ExceptionType[]{ExceptionType.CastException, ExceptionType.FormatException};
+ }
+
+ @Override
+ public boolean isRestricted() {
+ return true;
+ }
+
+ @Override
+ public Boolean runAsync() {
+ return false;
+ }
+
+ @Override
+ public String docs() {
+ return "boolean {locationArray, [cmd]} Sets a command to a Command Block at the given location."
@LadyCailin
LadyCailin Jan 30, 2014 Contributor

void, not boolean

@LadyCailin LadyCailin commented on an outdated diff Jan 30, 2014
.../java/com/laytonsmith/core/functions/Environment.java
+ return new ExceptionType[]{ExceptionType.CastException, ExceptionType.FormatException};
+ }
+
+ @Override
+ public boolean isRestricted() {
+ return true;
+ }
+
+ @Override
+ public Boolean runAsync() {
+ return false;
+ }
+
+ @Override
+ public String docs() {
+ return "boolean {locationArray} Returns the name of the Command Block at the given location.";
@LadyCailin
LadyCailin Jan 30, 2014 Contributor

I'm beginning to recognize a pattern ;)

@LadyCailin LadyCailin commented on an outdated diff Jan 30, 2014
.../java/com/laytonsmith/core/functions/Environment.java
+ return new ExceptionType[]{ExceptionType.CastException, ExceptionType.FormatException};
+ }
+
+ @Override
+ public boolean isRestricted() {
+ return true;
+ }
+
+ @Override
+ public Boolean runAsync() {
+ return false;
+ }
+
+ @Override
+ public String docs() {
+ return "boolean {locationArray, [name]} Sets the name to the Command Block at the given location."
@LadyCailin
LadyCailin Jan 30, 2014 Contributor

Last one!

@EntityReborn EntityReborn commented on an outdated diff Jan 30, 2014
.../java/com/laytonsmith/core/functions/Environment.java
+ }
+
+ @Override
+ public Version since() {
+ return CHVersion.V3_3_1;
+ }
+
+ @Override
+ public Construct exec(Target t, com.laytonsmith.core.environments.Environment environment, Construct... args)
+ throws ConfigRuntimeException {
+ MCLocation loc = ObjectGenerator.GetGenerator().location(args[0], null, t);
+ if(loc.getBlock().isCommandBlock()) {
+ MCCommandBlock cb = loc.getBlock().getCommandBlock();
+ String cmd = "";
+ if(args.length == 2) {
+ if(!(args[1] instanceof CString)) {
@EntityReborn
EntityReborn Jan 30, 2014 Contributor

It might be interesting to allow CNull here, actually, to allow for more flexible code. Setting a CNull would clear the command.

@EntityReborn EntityReborn commented on an outdated diff Jan 30, 2014
.../java/com/laytonsmith/core/functions/Environment.java
+ }
+
+ @Override
+ public Version since() {
+ return CHVersion.V3_3_1;
+ }
+
+ @Override
+ public Construct exec(Target t, com.laytonsmith.core.environments.Environment environment, Construct... args
+ ) throws ConfigRuntimeException {
+ MCLocation loc = ObjectGenerator.GetGenerator().location(args[0], null, t);
+ if(loc.getBlock().isCommandBlock()) {
+ MCCommandBlock cb = loc.getBlock().getCommandBlock();
+ String name = "";
+ if(args.length == 2) {
+ if(!(args[1] instanceof CString)) {
@EntityReborn
EntityReborn Jan 30, 2014 Contributor

It might be interesting to allow CNull here, actually, to allow for more flexible code. Setting a CNull would clear the command.

@PseudoKnight
Contributor

I wonder if I should add support for command minecarts -- check if args[0] is an array, otherwise entity. (like inventory functions) Do you think the function names would still be appropriate?

@EntityReborn
Contributor

No, commandcarts are entities, that would have to be another function. Also, your code is still unmergable, you need to merge in from the origin master.

@LadyCailin
Contributor

I'm not opposed to combining the two. There is precedence for that already, but I'm also not opposed to two different functions.

@PseudoKnight
Contributor

I looked for a standard, but like inventories, Command Blocks do seem to be an exception. From a functional point of view (as opposed to an object oriented one), having them both handled by the same functions makes sense. However, if [set_]entity_spec() is the new recommended approach, I could do it that way. Or both?

I'm not sure I like the idea of creating two sets of similar but differently named functions for the block and entity. eg. set_minecart_command and set_command_minecart_name

@LadyCailin
Contributor

Using [set_]entity_spec would be an acceptable compromise for minecarts, and the function for blocks.

@PseudoKnight
Contributor

Note: The command in the command minecart will not visually update in the interface until the next time it is activated.

@LadyCailin LadyCailin merged commit 4148ac3 into EngineHub:master Mar 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment