This is my very first mod which I made for MineCraft. Specifically this is made for ComputerCraft, obviously.
This is more of a framework than a mod, because it only does things 'behind the scenes' of ComputerCraft. This framework solves the problem which CC has with its API: only one peripheral can be mount per block (which can be caused by multiple mods). Well, I solved that, which should be obvious by the name of the mod.
This mod does not only allow more peripherals on one block, it also gives OpenPeripheral inspired annotations for the implementation of IPeripheral's (actual peripherals), or ILuaObject's (tables with methods). In short, a great way to hook into CC's API via my framework. It makes you type less
More information on the API can be found on the github's wiki, which has yet to be written. For now you can use the JavaDoc, which I tried to make obvious. You can PM me for questions about the API until the wiki has been written, which is going to contain examples and excessive explanation.
This mod is open source and licensed under the GNUv3 license. A short overview what the license allows/disallows you can be found here: choose a license. The source can be found on GitHub.
If you find any bug or issue with the mod, preferably open an issue on the Hub. You can post them here as well, but that is going to be discouraged..
Let's get on to the Lua part, which is probably the most interesting for you guys. You can find a brief description in the spoiler, but this is going to move to the GitHub wiki in the end.
The Lua Side
So, how would you interact with my mod? Some requirements are that you briefly know how CC and peripherals work together and a bit of Lua programming knowledge.
First of all, you dont directly interact with my mod. You only can interact with it when there are multiple peripherals mount on one block, and you can check for that. Just like this:
print(peripheral.getType(side))
If that prints MultiPeripheral (which get returned as a string by peripheral.getType(side)), then you know my mod did something. If you want to discover what peripherals are mount on that block you can use the method getTypes() to get a table with all peripheral types:
local side = "right"
local wrap = peripheral.wrap(side)
if peripheral.getType(side) == "MultiPeripheral" then
for k, v in pairs(wrap.getTypes()) do
print(string.format("%s: %s", k, tostring(v)))
end
else
print(peripheral.getType(side))
end
The key contains a key which is the literal type of the peripheral, and the value is the table just like you have wrapped it normally.
Then, you can programatically check if the MultiPeripheral is some type of peripheral, with the method isPeripheral(strPeripheral). After that you can obtain a table (which is the same table like you normally would have wrapped to) with the method getPeripheral(strPeripheral).
So, lets say the peripheral on the right is a MultiPeripheral which contains a 'inventory' and 'dispenser' peripheral. Here is an example:
local side = "right"
local wrap = peripheral.wrap(side)
local inventoryWrap = nil
local dispenserWrap = nil
if peripheral.getType(side) == "MultiPeripheral" then
if wrap.isPeripheral("inventory") then
inventoryWrap = wrap.getPeripheral("inventory")
-- Call it via the wrap:
inventoryWrap.someMethod()
-- or on the original wrap:
wrap.someMethod_inventory()
-- The normal wrap contains a list of methods like: method_type
-- I would encourage you to use the getPeripheral method!
end
if wrap.isPeripheral("dispenser") then
dispenserWrap = wrap.getPeripheral("dispenser")
end
elseif peripheral.getType(side) == "inventory" then
inventoryWrap = wrap
elseif peripheral.getType(side) == "dispenser" then
dispenerWrap = wrap
end
I hope it is clear how it works, but this is just a brief description. If you have questions, please post them below and I will include those here:
Spoiler
none yet
This mod has been made for CC1.6pr0 and should stay stable for some quite some time, though that depends on the Dan200.
Downloads can be found here. Always use the latest stable version and use the beta's at your own risk. This is a warning too, I dont take responsibility for damage to worlds etc. etc. But that shouldnt happen, if it happens throw me a bug report and log!
I'm unable to test it currently because I'm on my bad laptop.
Are you able to access the peripheral's GUI when it's in the MultiPeripheral?
Err.. I would have to ask you how you define 'accessing the GUI.' Because it is a bit vague to me what you are asking. If you are talking about lua-side that's a definite no.
After thinking a while I figered you probably meant that two peripherals (both a block), which has both gui's, can be melted to one peripheral.
For that my answer is no, and I'm going to explain why:
If you want to make a peripheral on a block, you have to implement an interface to your TileEntity which says 'I'm a peripheral.'
You can also add peripherals on blocks which you haven't made yourself (thus, you don't have access to them). Then you can register that to computercraft and it gets handled.
When a computer gets next to this 'external TileEntity' it calls a loop, and if the peripheral is valid it gets returned. The problem with this is that there can be more than that 1 peripheral, but those never get used. That is where MultiPeripheral kicks in, it adds those together.
An example mod which uses this cc api is OpenPeripheral, and I originally wanted to make a similair mod but with my twist. Then I stumped on the annoying error above, and decided to make it work for everybody so to speak.
My side project is my original goal what I wanted to achieve, and compitble with OpenPeripheral. Thanks to MultiPeripheral, it is compatible with OpenPeripheral and this 'java-side' mod is my core which I finally finished after two weeks.
I learnt a lot in the process, and this is just the beginning of something that can make CC even more awesome than it already is.
If this was not your question, please expand your question to a more specific question.
I am thinking about making a block which can combine two or more peripherals at once. The block will open a gui with slots where you then can put that block. And I'm talking about the real deal, it will allow to open all those GUI's of those blocks! Probably with another GUI with all blocks. I'll see how this is going to be
Should I implement this yes or no? One yes is more than enough for me!
Yes, but add a config that can change how many peripherals you can add in with a non-editable maximum too make sure it's not too OP. c:<
I don't think the OP argument really pans out here, seeing as you can just setup cables and connect as many peripherals as you want already anyways. It would however be a nice addition for those of us who like to keep things tidy!
I don't think the OP argument really pans out here, seeing as you can just setup cables and connect as many peripherals as you want already anyways. It would however be a nice addition for those of us who like to keep things tidy!
But with each peripheral added to the network you need A: cables and B: modems. We were talking about it and we're probably doing something around a six to eight maximum
If you used this mod in pr0 (which I frankly dont expect), and want to use it in pr1 it is necessary to replace your computers. I dont know why, but it fixed my problem
By the way, Im starting development on the peripheral block this weekend, because tuesday my wishdom tooth got pulled and it hurts like crazy. Not really in the mood for coding...
I am thinking about making a block which can combine two or more peripherals at once. The block will open a gui with slots where you then can put that block. And I'm talking about the real deal, it will allow to open all those GUI's of those blocks! Probably with another GUI with all blocks. I'll see how this is going to be
Im scrapping this. Mostly due to my interest that is somewhere else and it is really a pain to simulate a block while it hasnt been placed down.
I am thinking about making a block which can combine two or more peripherals at once. The block will open a gui with slots where you then can put that block. And I'm talking about the real deal, it will allow to open all those GUI's of those blocks! Probably with another GUI with all blocks. I'll see how this is going to be
Im scrapping this. Mostly due to my interest that is somewhere else and it is really a pain to simulate a block while it hasnt been placed down.
Dang, that sounded very promising! Oh well, can't wait to see what else you cook up
I am thinking about making a block which can combine two or more peripherals at once. The block will open a gui with slots where you then can put that block. And I'm talking about the real deal, it will allow to open all those GUI's of those blocks! Probably with another GUI with all blocks. I'll see how this is going to be
Im scrapping this. Mostly due to my interest that is somewhere else and it is really a pain to simulate a block while it hasnt been placed down.
...I was so hopeful for this. Time to watch someone else do it
Such a great idea, shame you're giving up on it.