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

[MC1.7.10][CC1.7x] DixPeripherals

Started by MindenCucc, 07 September 2015 - 02:10 AM
MindenCucc #1
Posted 07 September 2015 - 04:10 AM



Hi! I just made a "simple" mod that adds only 3 blocks:
  1. NBT Reader
  2. NBT Writer
  3. "Generic peripheral block" aka. "Colorable block"
Documentation (these below are all functions)
SpoilerColorable block
Spoiler
  • get - gets the color of the block
  • set(int color) - sets the color of the block
  • getR/getG/getB - gets the red/green/blue color intensity (0-255)
  • setR/setG/setB(byte intensity) - sets the red/green/blue color intensity (0-255)
  • getHex - gets the color in 6digit Hexadecimal format
  • setHex(string hexstring) - sets the color from a hexadecimal string (for example, you have #00FEED, you write "00FEED", or just simply "FEED")

NBT Reader/Writer
(writer-specific functions are marked with italics+bold)
Spoiler
  • proxy - returns a proxy object used to query/manipulate the item in the block
    • stack - returns nil if no item is in the block, or a table with the item's details
    • compound - returns nil if the item doesn't have any special data, or a proxy table if it has
      • keys - returns a key list
      • typeof(String key):String - returns the type of the item under *key*
      • types - returns an ipairs-able table with name + type pairs
      • valueof(String key) - returns the key's value, or if a special type, a proxy to it (listwrapper below)
        • count - number of elements
        • type - list type, 0 or "end" if untyped
        • nth(int key) - returns the N-th element of the list
        • dump(int key) - returns a Minecraft-compilant JSON string of the given object
        • dumpme - dumps this object into a Minecraft-compilant JSON string
        • clear - clears the array, and resets its type
        • del(int key) - removes the N-th item from the list
        • put(mixed stuff, [string/int NBTtype]) - puts *stuff* into the list. if it was untyped, NBTtype is required
        • set(int key, mixed stuff, [string/int NBTtype]) - sets *stuff* in the list. if the list was untyped, NBTtype is required
        • putCompound - if the list is untyped / compound typed, puts an empty Compound on top of the list
        • newCompound(int key) - if the list is untyped / compound typed, sets an empty Compound at the given key
        • load(int key, string MC-NBT) - loads the contents of a Minecraft-compilant JSON into the list's given key
      • nbt_types - returns a both value-to-key, and a key-to-value table with all the NBT types associated with a number and a string value
      • dump(int key) - returns a Minecraft-compilant JSON string of the given object
      • dumpme - dumps this object into a Minecraft-compilant JSON string
      • del(String index) - removes the index from the compound
      • set(String index, mixed stuff, [string/int NBTtype]) - sets *stuff* in the compound. if the index didn't exist before, NBTtype is required
      • newCompound(String index) - sets an empty Compound at the given index
      • newList(String index) - sets an empty List at the given index
      • load(String index, String MC-NBT) - loads the contents of a Minecraft-compilant JSON into the compound's given index
    • recipe(boolean ignoreMeta(default=false), boolean ignreNBT(default=true)) - returns a bit complicated table containing the item's recipe(s)
      • I'll explain it later
    • dumpme - dumps the item's NBT data into a string. if it didn't have one, it returns nil
    • dumps - dumps the whole item into a string for later storage
    • size(int size) - sets the number of items, -1 means infinite
    • damage(short damage) - sets the item's damage value (0-32767*)
    • display(string displaystring) - sets the item's display name (use \174\167 in replacement of § or & or \u00a7)
    • cpurge - deletes the item's NBT data if it had one
    • creset - (re)creates a new NBT data for the item
    • loadme(string nbtjson) - loads the contents of a Minecraft-compilant JSON as the item's NBT data
  • dump - same functionality as proxy.dumps()
  • eject - ejects the contents of the block on top of it in item form
  • destroy - sends the contents of the block into the void ;)/>
  • forge(string mcid, [int amount, [short metadata]]) - makes an item from the void's dust :P/> similar syntax to /give (for example /minecraft:give MarcusD ComputerCraft:CC-Computer 64 16385, you do writer.forge("ComputerCraft:CC-Computer", 64, 16385) here)
  • load(string nbtjson) - creates a stored item from the contents of a Minecraft-compilant JSON

Bugs
Spoiler
  • Sometimes NBT Writers turn into NBT Readers. Breaking'n'replacing the block fixes it. Fortunately this doesn't happen vice-versa :P/>
  • nbtwriter.forge method can throw a Java exception about it can't cast the third argument from String to Double (number)

Downloads
SpoilerDownload it from CurseForge:
http://minecraft.cur...-dixperipherals

Screenshot
Spoiler
http://puu.sh/jo9v6/07fa0f37f4.png
Edited on 07 September 2015 - 02:13 AM
Bomb Bloke #2
Posted 07 September 2015 - 03:11 PM
So a block with about 16mill different colour possibilities… huh.

On one hand I'm sitting here thinking surely someone would've written such a thing before, on the other I've never heard of any examples. In any case this adds a whole new dimension to my current project. Is it possible to place a version without the shading effect you've pictured?

Any chance of an NBT reader that can target blocks placed within the world? Preferably at any range, even if means the peripheral is accessible via creative-mode only? WorldPorter is sorely missing such a thing.
MindenCucc #3
Posted 08 September 2015 - 12:10 AM
So a block with about 16mill different colour possibilities… huh.

On one hand I'm sitting here thinking surely someone would've written such a thing before, on the other I've never heard of any examples. In any case this adds a whole new dimension to my current project. Is it possible to place a version without the shading effect you've pictured?

Any chance of an NBT reader that can target blocks placed within the world? Preferably at any range, even if means the peripheral is accessible via creative-mode only? WorldPorter is sorely missing such a thing.

Yeah, thanks for the tips! I was thinking of an Entity editor, but the original plan was to make a dynamic shop using this (and I'm currently working on it ^_^/>).

I planned a function to hide the texture of the block, but I just never got around it, becaue 1) I don't have that much time, and 2) I'm lazy :P/>

I think it'll be hard to edit a blocks' NBT that's placed in-world, because it may cause issues with some type of blocks, like multiblocks, and especially Thaumcraft stuff. I'll try to finish the Block editor this week, so I could push a documentation this week, and after that I'll try to push the mod update itself too.
Bomb Bloke #4
Posted 08 September 2015 - 12:44 AM
Command Computers are already functional NBT editors for in-world blocks; they simply lack NBT reading functionality.
MindenCucc #5
Posted 08 September 2015 - 11:01 AM
Okay, you'll be able to continue the development, because I have a function list for you :D/> (I'm not at my computer, so I can't edit the first post without messing it up)

Single-state functions:

* load(x, y, z), returns true if success, or false if 1) there's already a block loaded, or 2) if that block doesn't have a TileEntity
* loads - loads a setblock-compatible JSON string, true if success, false if no block is loaded, error if malformed JSON
* wrap - returns a compound wrapper (see the reader's proxy.compound function), nil if no block loaded/the block's TileEntity is gone
* haz - returns true if a block is loaded
* flush - writes the changes to the block, returns false if unsuccessful
* clear - resets the block editor

Stateless functions:

* mycoords - returns this block's x,y,z coordinates (x,y,z = p.mycoords())
* air(x, y, z) - vanilla World method, sets the block to air
* destroy(x, y, z, [silent]) - destroys the block without dropping items. see below for more info
* break(x, y, z, [capture]) - breaks a block with item drops (if the item doesn't drop, put true as the 4th argument) also, this function may dupe items/crash the server on some poorly-implemented blocks
* get(x, y, z) - gets info about the block
* set(x, y, z, block, [[[meta,] silent,] updateflags]) - sets a block in world
* getmeta(x, y, z) - gets the block's meta
* setmeta(x, y, z, meta, [[updateNeighbors,] updateflags]) - sets a block's metadata
* forcetick(x, y, z, [multiplier]) - forces (multiple) block ticks, accelerates crops'n'machines
* tilereset(x, y, z) - recreates the block's TileEntity, true if successful, false if the block has no TileEntity
Edited on 08 September 2015 - 09:09 AM
Bomb Bloke #6
Posted 09 September 2015 - 03:27 PM
Alright, got it installed, gave it a go. Although I assume they're simply things you haven't gotten around to yet, a few things could be tweaked/fixed maybe:

A creative inventory tab would be nice.

The colourable block doesn't seem to change colour until a block update occurs next to it.

cb.set() doesn't appear to be rigged to work with the values in the colours API, but rather seems to expect a 24bit unsigned int. Not exactly a "problem", but worth documenting, at least.

Inventory icons for readers/writers are grey, though the blocks themselves never are.

Can't seem to find these extra functions you've posted, get/forcetick/etc…?

Regarding the texture of the colourable block, it'd be nice to be able to toggle it via a peripheral call. But even better, how about being able to switch between a few templates? Eg, wool, clay, stone, planks…
MindenCucc #7
Posted 10 September 2015 - 06:32 AM
I planned a function to hide the texture of the block, but I just never got around it, becaue 1) I don't have that much time, and 2) I'm lazy :P/>

I think it'll be hard to edit a blocks' NBT that's placed in-world, because it may cause issues with some type of blocks, like multiblocks, and especially Thaumcraft stuff. I'll try to finish the Block editor this week, so I could push a documentation this week, and after that I'll try to push the mod update itself too.

Okay, you'll be able to continue the development, because I have a function list for you :D/> (I'm not at my computer, so I can't edit the first post without messing it up)

–snip'o'functions–

That means that that version of the mod I'm talking is still not out, I just posted the functions, so you could start working on your project, so you could finish faster.

Alright, got it installed, gave it a go. Although I assume they're simply things you haven't gotten around to yet, a few things could be tweaked/fixed maybe:

A creative inventory tab would be nice.

The colourable block doesn't seem to change colour until a block update occurs next to it.

cb.set() doesn't appear to be rigged to work with the values in the colours API, but rather seems to expect a 24bit unsigned int. Not exactly a "problem", but worth documenting, at least.

Inventory icons for readers/writers are grey, though the blocks themselves never are.

Can't seem to find these extra functions you've posted, get/forcetick/etc…?

Regarding the texture of the colourable block, it'd be nice to be able to toggle it via a peripheral call. But even better, how about being able to switch between a few templates? Eg, wool, clay, stone, planks…

I'll go through in order:

As I said, this is a mod devwloped for the shop only, but I posted it anyways, so others could use this for their shops too. Because the original modpack I use this mod with has NEI, I never got into making a CreativeTab for it :P/> I'll add it as a config option defaulting to false in the next update.

I know, sadly it takes a few seconds / a chunk update to update the color of the block, because of MC's rendering cache. I'll try to make it more instant.

Sorry, I assumed that getHex returning a 24bit value would be logical that set also uses a 24bit number. I'll edit the documentation as soon as i get near a computer.

That's because I can't find a way to apply a color to the ItemBlock in your inventory :(/>

See the explaination the top of this post. I still haven't finished that block :P/>

That would be a though job to make that block use another block's IIcon, because
1) it would be slow looking up for the block EVERY TIME
2) IIcon is not containing a texture, if I understand correctly, it's a rectangule pointing to a location on the stitchermap.
Also, you said templates, so write down the list of blocks you would like to see, and I should make a function then to change its texture (sadly it would have the same update problem as it had with the color change)
TestUser #8
Posted 11 June 2016 - 10:24 PM
There is so much potential in this mod. Sad to see this didn't get enough attention. :/