CC: Tweaked

CC: Tweaked

57M Downloads

Tweak the "commands" library to return correct data back

ArsiTheFox opened this issue ยท 10 comments

commented

Hello, I was wondering if there was a way you can code and or change the way how the commands library returns some of its commands like vanilla does to help us mapmakers and commands specialists.

Example:
Typing out print(commands.data("get player @p Health"))
would return: The Player's Health and not a boolean value or string
would be very helpful to use with data to sift through tags of entities and blocks

commented

We already return the output of existing vanilla commands, so I'm a little confused about what you're asking here?

Am I right in saying you want a new system (not really tied to any existing existing command) which allows querying data about entities and blocks in the world? We've got the ability to query block states already, but it might be nice to expand this - though not 100% convinced it's in scope for CC.

Technically entity/block info can be fetched with /entitydata et. all, but it's not ideal.

commented

The current library would return it as a string and not just the data that was selected:
commands.data("get entity @p SelectedItem.id") would return "ModID:ItemName"
NOT: "PlayerName has the following entity data:\"ModID:ItemName\""

If this is possible that would be awesome, especially with intergers that commands send as returns

commented

Ahhh, /data is a 1.13+ command. Woops, clearly entirely missed that one.

Yeah, I'm afraid this isn't really possible - commands are pretty opaque - all we can really do is run them and capture what they print. Can definitely expose the number that they return though.

commented

I mess with command blocks and commands all the time and they allow me to get a single part of data if specified but and computer uses the chat command format and not the command block cmd format

commented

I don't know how to mod through Java "yet" so I don't know how hard it would be to change that but thank you for checking this out

commented

I mess with command blocks and commands all the time and they allow me to get a single part of data

Hrmr, can you give an example of how to do that? I haven't really messed with the usage of 1.13's command system.

Internally, /data get is pretty much doing:

ITextComponent feedback = new TranslationTextComponent("commands.data.entity.query", entity.getDisplayName(), nbt.toFormattedComponent());
source.sendFeedback(feedback, false);
return sizeOf(nbt);
commented

I may be looking at this wrong, I'm seeing it may not be the return of the command but the command that is being used

data get entity @p SelectedItem.id
Would return "Player has the following entity data: "ModID:ItemName""

tellraw @A {"entity":"@p","nbt":"SelectedItem.id"}
Would put in chat "ModID:ItemName" if an item was held

execute if entity @e
Would return the number of entities found in the world

commented

I'm seeing now that I may be wrong about this slightly

commented

Just wanted to see if the added string that is auto generated can be removed in the command computer so that you could do: success,data=commands.data("get entity @p SelectedItem.id")
so that success would equal True of False depending on if their was an item in my hand and data would equal: "ModID:ItemName", but if I do print(data) it prints on the screen: "Player has the following entity data: "ModID:ItemName""

commented

Example.lua:

success,data=commands.data("get entity @p "SelectedItem.id"")
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.gray)
print("Example")
term.setCursorPos(1,3)
term.setTextColor(colors.lightGray)
textutils.slowPrint("commands.data("get entity @p SelectedItem.id") = ")
term.setTextColor(colors.yellow)
print("minecraft:apple")
term.setTextColor(colors.white)

sleep(1)

term.setCursorPos(1,6)
term.setTextColor(colors.lightGray)
print("{NOT}")
textutils.slowPrint("commands.data("get entity @p SelectedItem.id") = ")
term.setTextColor(colors.yellow)
print(data[1])

In Action: Example.lua