This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
xuma202's profile picture

Turtle NBT editor Peripheral [Suggestion][WIP]

Started by xuma202, 05 February 2013 - 02:18 AM
xuma202 #1
Posted 05 February 2013 - 03:18 AM
Hi,

beacuse of a bug in the current version of RedPower2 I had to manually set many RedBusIds this weekend using an InGame NBT editor which became annoying quickly. Today I came with an epic idea solving this and maybe lots of other problems. A peripheral, that can be crafted onto a turtle, that adds the following functions:

getNBTData() - would return a multidimensional Array containing the values of the NBTData of the block in front of the Turtle. (Maybe a getNBTDataUp() and getNBTDataDown())
getNBTDataTypes() - would return a multidimensional Array containing the types ("double", "byte", …) of the NBTData of the block in front of the Turtle. (Maybe a getNBTDataTypesUp() and
getNBTDataTypesDown())
setNBTData() - would allow setting values to the NBT fields

of course the name of the functions could be different but I hope you get my point.

This peripheral would allow not only setting many RP2 BusIds but also setting much Metadata of Blocks like setting the rotation or the inventory or ….

What do you think about this idea guys?
Is someone interested/willing to create this peripheral?

Thanks in advance Chris
Cranium #2
Posted 05 February 2013 - 03:58 AM
Split to new topic in Suggestions. You do not have to post on the new members thread, since you have been here for some time. Please keep that in mind.
PixelToast #3
Posted 05 February 2013 - 03:59 AM
i suggested NBT editing awhile ago
its not gona happen, you can easily crash and burn a server
get someone to make a peripheral for it
Cloudy #4
Posted 05 February 2013 - 04:18 AM
Split to new topic in Suggestions. You do not have to post on the new members thread, since you have been here for some time. Please keep that in mind.

Yes, he did. It wouldn't let him for some reason, something I'm going to look into.
Cranium #5
Posted 05 February 2013 - 04:20 AM
Split to new topic in Suggestions. You do not have to post on the new members thread, since you have been here for some time. Please keep that in mind.

Yes, he did. It wouldn't let him for some reason, something I'm going to look into.
Then I retract my previous statement. I thought he was able to, seeing as he has been here since March.
xuma202 #6
Posted 05 February 2013 - 04:42 AM
Split to new topic in Suggestions. You do not have to post on the new members thread, since you have been here for some time. Please keep that in mind.

Yes, he did. It wouldn't let him for some reason, something I'm going to look into.
Then I retract my previous statement. I thought he was able to, seeing as he has been here since March.

The Problem has been fixed. I can now create threads on my own again. Thanks
xuma202 #7
Posted 06 February 2013 - 07:29 AM
Update:

I worked on a peripheral for this. It works great. But I'm currently too lazy to write a documentation and because it can harm your minecraft world I won't release it just now. However, if you're interested in using it or develop this further here https://drive.google...WURjWjlvdDFLT0U you can find the binaries and the source code. You can use it in anyway you want but please mention my name or put a link. You can retrieve NBT data and edit values. You can't delete or create new NBT Tags or array elements.

Note it is using the Turtle Upgrade id 254 though I don't reserve it currently.

Chris
PixelToast #8
Posted 06 February 2013 - 08:28 AM
:D/>
thanks, im testing it now :3

EDIT: cant place it 3:
i tried 65024
and 254 damage values but it still reverts to a normal turtle when i place it >_>
EDIT2:
derp Dx forgot to restart server when installing
EDIT3:
this is awesome :D/>, toataly gona make a UI for it when i have the time
one problem: you have to do this to get the table:

loadstring(editor.getNBTData())()()
Orwell #9
Posted 06 February 2013 - 08:32 AM
I would definitely restrict the use of this. Changing the NBT data of a chest could give me total spawn power.
xuma202 #10
Posted 06 February 2013 - 08:41 AM
:D/>
thanks, im testing it now :3

EDIT: cant place it 3:
i tried 65024
and 254 damage values but it still reverts to a normal turtle when i place it >_>

Try crafting it using a turtle and a Bottle o' Enchanting this should work

I would definitely restrict the use of this. Changing the NBT data of a chest could give me total spawn power.

This is intended to be used in creative only or for special purposes. I think ppl should decided on their own for what they use it. For example I used it o set many RedPower BusIds.
Of course this should not be used on a public server. But when you're building stuff alone or with friends it could be useful. However if ppl wanna use it for getting items illegally I see no reason to stop them.
Orwell #11
Posted 06 February 2013 - 08:47 AM
:D/>
thanks, im testing it now :3

EDIT: cant place it 3:
i tried 65024
and 254 damage values but it still reverts to a normal turtle when i place it >_>

Try crafting it using a turtle and a Bottle o' Enchanting this should work

I would definitely restrict the use of this. Changing the NBT data of a chest could give me total spawn power.

This is intended to be used in creative only or for special purposes. I think ppl should decided on their own for what they use it. For example I used it o set many RedPower BusIds.
Of course this should not be used on a public server. But when you're building stuff alone or with friends it could be useful. However if ppl wanna use it for getting items illegally I see no reason to stop them.
I agree. I use the mod NBTEdit to change the RedPower Bus ID's in game though. :)/>
PixelToast #12
Posted 06 February 2013 - 09:13 AM
this could still corrupt maps :P/>
xuma202 #13
Posted 06 February 2013 - 09:28 AM
EDIT3:
this is awesome :D/>, toataly gona make a UI for it when i have the time
one problem: you have to do this to get the table:

loadstring(editor.getNBTData())()()

Yes I know but I don't know of a better way since I can't give a table as a function return. Though I'll make an API for this. At this point I wanna thank Espen. His mod "ccDB" is using a similar technique which inspired me.


this could still corrupt maps :P/>

This is one of the reasons why it's not an officially released peripheral. :P/>
Orwell #14
Posted 06 February 2013 - 09:34 AM
Yes I know but I don't know of a better way since I can't give a table as a function return.
Returning a Map from callMethod in Java will result in returning a table in CC. The idea of key/value is the same for the Map as it is for Lua tables.
PixelToast #15
Posted 06 February 2013 - 09:41 AM
cant figure out the set function >_>
dosent return any useful information
xuma202 #16
Posted 06 February 2013 - 10:04 AM
Yes I know but I don't know of a better way since I can't give a table as a function return.
Returning a Map from callMethod in Java will result in returning a table in CC. The idea of key/value is the same for the Map as it is for Lua tables.

Oh really?! In the javadocs it just says
Returns: An array of objects, representing values you wish to return to the lua program.
Integers, Doubles, Floats, Strings, Booleans and null be converted to their corresponding lua type.
All other types will be converted to nil.
You may return null to indicate no values should be returned.

But I'll try it. Thanks for the hint.


cant figure out the set function >_>
dosent return any useful information

Well, using the set function is a bit tricky. I'll give you an example:

Let's say the data is

{name="", type="TAG_Compound", value={{name="rbaddr", type="TAG_Int", value=4}, {name="x", type="TAG_Int", value=85}, {name="data", type="TAG_IntArray", value={3, 6, 9}}, {name="compound", type="TAG_Compound", value={{name="tag", type="TAG_String", value="I'm a string"}} […]}}



[indent=1]rbaddr = 4[/indent]
[indent=1]x = 85[/indent]
[indent=1]data[/indent]
[indent=2]3[/indent]
[indent=2]6[/indent]
[indent=2]9[/indent]
[indent=1]compound[/indent]
[indent=2]tag = I'm a string[/indent]
[indent=1][…][/indent]



now if you want to change the value of rbaddr you'll call setNBTTagValue(x,"rbaddr")
where x is the new value and all following parameter the name of the element.

If you'd like to change the value of a Tag inside an IntArray or ByteArray, use the name of the Array and as the next parameter the id of the field.
So changing the 6 into a 13 would be done this way:
setNBTTagValue(13,"data",1) because 1 is the index. (STARTING WITH 0 NOT WITH 1)

If you'd like to change the value of a Tag inside a compound do it this way:
setNBTTagValue("I'm another string","compound","tag")
or
setNBTTagValue(<newValue>,<name of the compound>,[<name another compound>][…],<name of the Tag>)

However, how would you'd like to set the values. Have you got a way doing this which is simpler?

Chris
immibis #17
Posted 06 February 2013 - 12:42 PM
Here is a fix for RP screwdrivers not changing bus IDs, in a way that doesn't allow people to spawn items or crash the server: http://pastehtml.com.&#46;&#46;/cr72r0hhu.html
xuma202 #18
Posted 06 February 2013 - 11:47 PM
This is great immibis. I've asked many times for such a fix in the redpower irc but nobody knew about this. However if you have to set hundreds of ids this mod is still useful.
PixelToast #19
Posted 07 February 2013 - 04:35 AM
id like to be able to modify the returned table and have the changes work instantly

local chest=peripheral.call("right","getNBTData")
chest.x.value="something"
and have a function to set the entire table because when you do

chest=table
the actual data of the chest isnt modified, its just setting the variable to a new table
Cloudy #20
Posted 07 February 2013 - 04:40 AM
Not possible with the CC API.
xuma202 #21
Posted 07 February 2013 - 05:03 AM
Not possible with the CC API.

You mean passing an array to a peripheral function?

Well I could create an API that turns the array into a string or splits it up over several parameters and then sends it to the peripheral where it gets turned into a map again.
xuma202 #22
Posted 07 February 2013 - 05:51 AM
Update: I've redone some things. Now getNBTData will return a table directly. Next is redoing the setNBTData so you can just pass in the modified array.

This is how the serialized table looks likes:

open for screenshot
Spoiler
PixelToast #23
Posted 07 February 2013 - 06:45 AM
awesome :D/>
xuma202 #24
Posted 09 February 2013 - 03:05 AM
UPDATE: Ok this was a real lot of work. I've created a concept to send the array to the Peripheral and it worked, until I ran into problems because lua was not able to handle all the parameters.
I've tried different stuff some of which I didn't liked from the beginning on. I tried a JSON String but it didn't work for some reason. What I ended up with is not the prettiest and best solution but it works and is an ok compromise.

How it works (may be interesting for other modders as well:

I use a lua JSON api to convert my table into a JSON string. (http://regex.info/blog/lua/json)
Next I save the table to a file and call my peripheral function with the name of that file.
In Java I load the file and convert it to a HashMap (http://wiki.fasterxm...onInFiveMinutes)


String p = ModLoader.getMinecraftInstance().getMinecraftDir() + "\\saves\\" + myTurtle.getWorld().getWorldInfo().getWorldName() + "\\computer\\" + (String) arguments[0];

  File f = new File(p);
  Map m1 = new ObjectMapper().readValue(f, HashMap.class);

Now I recursively turn this HashMap into an NBTTag which I then write to the TileEntity.
In lua I now delete the temporary file.

For the non-developers:

You can now simply manipulate the table and call a function from the api :D/>

Now I'll quickly write an api and make a separate thread in the peripheral section.
xuma202 #25
Posted 09 February 2013 - 06:27 AM
Ok it's released http://www.computercraft.info/forums2/index.php?/topic/10324-cc-1481mc-147-turtle-nbt-editor-10/page__fromsearch__1