Hello community!
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.. :P/>
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 yetThis 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!
Enjoy!