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

[CC 1.47] [MC 1.45] AdventureMap Peripheral - Updated to Version 1.5

Started by Bubba, 23 November 2012 - 09:02 AM
Bubba #1
Posted 23 November 2012 - 10:02 AM
Although this project is rather dead, I've kept the old content here for posterity's sake. Feel free to do what you wish with the source code (fair warning - it's poorly written). A good alternative can be found here.
Spoiler

The Adventure Map Peripheral, for all your adventure map needs!


I have been working on an adventure peripheral for the past several days pretty much nonstop, and I am fairly happy with the result. It has many functions which could be useful to map makers, although so far SMP is not fully supported (I will attempt to work on that, but it's not a priority right now).

Changelog
V1.5 Changelog
- Modified the method of retrieving computer/turtle coordinates (No longer hit and miss)
- Added the peripheral.getDirection() function

V1.4 Changelog (Skipped a version because of bugs)
- Can now retrieve block metadata
- Can now create explosions (awww yeah)
- Fixed a bug with finding the computer location.
- Other minor bug fixes

V1.2 Changelog
Spoiler- Added the option to set block metadata
- Added three new functions: peripheral.say(), peripheral.createFireball(), and peripheral.playerLooking(). See the functions list for more info

Disclaimer
This peripheral was not created to be a legit tool (although you can use it that way if you want). It is aimed towards map makers and perhaps structure building and is absurdly easy to get and use. No longer absurdly easy to get, but still absurdly easy to use.

Functions List

peripheral.getBlock(int x, int y, int z) --Returns the id and metadata at the specified x,y,z location
peripheral.setBlock(int x, int y, int z, int id, [int metadata]) --Sets the block at the specified x,y,z location to the given id and (optionally) metadata
peripheral.findPeripheral() --Returns the x,y,z position of the peripheral block
peripheral.findComputer() --Returns the x,y,z position of the computer attached to the peripheral
peripheral.playerCoords(str username) -- Returns the x,y,z position of the specified player
peripheral.playerHealth(str username) --Returns the current amount of health the player has
peripheral.attackPlayer(str username, int damageValue) -- Damages the player by the specified amount
peripheral.setPlayerPos(str username, int x, int y, int z) --Sets the player's x,y,z position the given coordinates
peripheral.givePlayer(str username, int itemID, int amount) --Gives the player the specified amount of the itemID
peripheral.getPlayers(integer) --Returns a player from a table. Inputting peripheral.getPlayers(1) will get you the first connected player.
peripheral.say(str text) --Adds the given text value in the chat
peripheral.createFireball(int startX, int startY, int startZ, double velocityX, double velocityY, double velocityZ) --Adds a fireball to the world with the given values
peripheral.playerLooking(str username) --Returns the specified vecX, vecY, and vecZ as doubles
peripheral.createExplosion(int x,int y, int z, int damagevalue) --Creates explosion of specified magnitude at given coordinates
peripheral.getDirection() --Returns the direction the attached computer (or turtle) is facing

Crafting
DDD
DSD
DDD
Where D is a diamond block and S is smooth stone.

Screenshots
Here are some screenshots of the peripheral in action. Hopefully I will be able to record a video sometime in the near future.
http://www.4shared.c...ral_Images.html

Sample Programs
Spoiler

--Give the player specified items
local args = {...}
if args[2] == nil then
  print("Requires 2 arguments")
else
  local p = peripheral.wrap('left')
  local username = p.getPlayers(1)
  p.givePlayer(username, tonumber(args[1]), tonumber(args[2]))
end


--Move the player to the specified coordinates
local args = {...}
if args[3] == nil then
  print('Requires 3 args.')
else
  local p = peripheral.wrap('left')
  local username = p.getPlayers(1)
  local cX,cY,cZ = p.playerCoords(username)
  cX = math.floor(cX)
  cY = math.floor(cY)
  cZ = math.floor(cZ)
  local x = tonumber(args[1])
  local y = tonumber(args[2])
  local z = tonumber(args[3])
  local nX = cX + x
  local nY = cY + y
  local nZ = cZ + z
  print("Current player position: "..cX..", "..cY..", "..cZ)
  print("New player position: "..nX..", "..nY..", "..nZ)
  p.setPlayerPos(username, nX,nY,nZ)
end


--Print same basic info about the player
local p = peripheral.wrap('left')
local username = p.getPlayers(1)
pX, pY, pZ = p.playerCoords(username)
print("Player X: "..pX)
print("Player Y: "..pY)
print("Player Z: "..pZ)
print("Player health: "..p.playerHealth())
print("------------------------------------")
print("Getting the id of the block underneath the player")
pX = math.floor(pX)
pY = math.floor(pY)
pZ = math.floor(pZ)
print("ID is: "..p.getBlock(pX,pY-1,pZ))


--Set the block at the given coords relative to the Computer to the specified ID
local args = {...}
if args[4] == nil then
  print("Requires 4 args")
else
  local p = peripheral.wrap('left')
  local cX, cY, cZ = p.findComputer()
  p.setBlock(cX + tonumber(args[1]),cY + tonumber(args[2]),cZ + tonumber(args[3]),tonumber(args[4]))
end

Install
Just drop the zip file into your mods folder. No extra steps are necessary!

Notes
- I give anybody and everybody full rights to this peripheral, up to and including making small modifications to the code and releasing it as your own.
- This peripheral is still in development, meaning that it may still have bugs or could use improvements in some areas.


Download
Version 1.5 (Current - CC 1.47 MC 1.45)
Client
Source

Old versions
SpoilerV1.4 (Outdated - CC 1.47 MC 1.45)
Client
Source
V1.2 (Outdated - CC 1.47 MC 1.45)
Client: http://www.4shared.c...ipheralv12.html
Source: http://www.4shared.c...eralv12SRC.html

V1.1 (Outdated - CC 1.47 MC 1.45)
Client: http://www.4shared.c...pheral_v11.html
Source: http://www.4shared.c...al_v11_src.html

V1.0 (Outdated - CC 1.47 MC 1.45)
Client with diamond recipe: http://www.4shared.c...ralDRecipe.html
Client with cobble recipe http://www.4shared.c...peripheral.html
Source http://www.4shared.c...5oPrl/Code.html
Tiin57 #2
Posted 23 November 2012 - 10:07 AM
:/
I suppose I won't ever get around to balancing CCMPU. I retract all rights to the ideas behind CCMPU (if I ever owned them ;)/>/>).
Bubba #3
Posted 23 November 2012 - 10:24 AM
:/
I suppose I won't ever get around to balancing CCMPU. I retract all rights to the ideas behind CCMPU (if I ever owned them ;)/>/>).

You don't think you'll get to it because you don't have time or because you don't want to? I think a balanced alternative to this would be fantastic and I'm not an experienced enough coder yet to do it -_-/>/>
gknova61 #4
Posted 23 November 2012 - 10:31 AM
Could you change the recipe to have like a smoothstone in the middle or something so it doesn't interfere with this mod that adds condensed blocks, including cobblestone ;)/>/>
Bubba #5
Posted 23 November 2012 - 10:34 AM
Could you change the recipe to have like a smoothstone in the middle or something so it doesn't interfere with this mod that adds condensed blocks, including cobblestone ;)/>/>

Sure. I think I'll change the recipe to be like this:
DDD
DSD
DDD
Where D is diamond blocks and S is smooth stone. This makes it more difficult for players to get the item in adventure maps and also I can't imagine too many mods that would conflict with this recipe.

Edit: Okay added it
sirdabalot #6
Posted 23 November 2012 - 10:41 AM
Hell, nice job on making this! And seriously, thanks for making it open source, not enough people do that and it's how I learn so things get tough for me as a newbie minecraft modder.
Bubba #7
Posted 23 November 2012 - 10:56 AM
Hell, nice job on making this! And seriously, thanks for making it open source, not enough people do that and it's how I learn so things get tough for me as a newbie minecraft modder.

Thank you ;)/>/> I am a noob myself when it comes to Java so this project was no small task. If you have difficulty figuring stuff out I would suggest using the JD-Gui to look at decompiled code and get the general idea of how people are going about things (I would never have been able to do this project without it). Of course, open source is in my opinion far easier to use than looking at the code with a decompiler which is why I released it with this peripheral.
sirdabalot #8
Posted 23 November 2012 - 11:04 AM
-Snip-

Thanks for the tip, I'll look into it. -_-/>/>

EDIT: Well, would have been nice if I knew about that before I made my first peripheral. ;)/>/>
billysback #9
Posted 23 November 2012 - 11:27 AM
Could you add data values?
currently you cannot set things like wool color or log type, that's all modified by a block's data value ;)/>/>
Bubba #10
Posted 23 November 2012 - 11:35 AM
Could you add data values?
currently you cannot set things like wool color or log type, that's all modified by a block's data value ;)/>/>/>/>

I definitely plan to add this in the next version. Hopefully I'll have that done by tomorrow.
Tiin57 #11
Posted 23 November 2012 - 03:21 PM
:/
I suppose I won't ever get around to balancing CCMPU. I retract all rights to the ideas behind CCMPU (if I ever owned them ;)/>/>/>).

You don't think you'll get to it because you don't have time or because you don't want to? I think a balanced alternative to this would be fantastic and I'm not an experienced enough coder yet to do it -_-/>/>/>
Both; JavaCraft and LuaForge take up most of my time. Oh, and ofc Chivalry.
Orwell #12
Posted 23 November 2012 - 03:54 PM
Hell, nice job on making this! And seriously, thanks for making it open source, not enough people do that and it's how I learn so things get tough for me as a newbie minecraft modder.

Well, I was thinking about posting this somewhere sometime, but I'll do it here for now. The OpenCCSensors project is open source and I think it's a good example of a peripheral. Almost everything up to know has been coded by Cloudy so you can be quite sure that all the stuff in there is done in the correct way. -_-/>/> Although I must admit that there aren't much comments in there. ;)/>/>
Cloudy #13
Posted 24 November 2012 - 12:01 AM
Although I must admit that there aren't much comments in there. ;)/>/>/>

I do plan to comment it once I clean it up a bit -_-/>/>
sirdabalot #14
Posted 24 November 2012 - 12:44 AM
-Snip-

Don't worry, I wan't neglecting that, I just thought that it would be a bit too much of a complex peripheral for me to start looking at. ;)/>/>
Bubba #15
Posted 24 November 2012 - 07:27 AM
Could you add data values?
currently you cannot set things like wool color or log type, that's all modified by a block's data value ;)/>/>

This has now been added, in case anybody was missing metadata values.
billysback #16
Posted 25 November 2012 - 03:28 AM
Could you also add getBlockData(x, y, z) or add a second return for the getBlock(), This could then be used to save and draw 3D models :D/>/>
Bubba #17
Posted 25 November 2012 - 06:35 AM
Could you also add getBlockData(x, y, z) or add a second return for the getBlock(), This could then be used to save and draw 3D models :D/>/>/>

Done. It will now return the metadata as a second return of the getBlock() function.
Bubba #18
Posted 25 November 2012 - 04:29 PM
Updated to Version 1.5 with peripheral.getDirection() and several bug fixes
Sukasa #19
Posted 27 November 2012 - 03:48 PM
When you say SMP is not "fully" supported, is there a subset of features that are known to work or not work?

On that topic, any chance of a function to send raw text to only a specific player?
Bubba #20
Posted 27 November 2012 - 05:58 PM
When you say SMP is not "fully" supported, is there a subset of features that are known to work or not work?

On that topic, any chance of a function to send raw text to only a specific player?

I just have not been able to test it on an SMP server as of yet and so I am unsure if SMP will work - you are certainly free to try, but keep in mind that I did not design this peripheral to specifically work with SMP and am to new to Java/Peripheral programming to know whether or not it might work. As for a function to send raw text to only a specific player, I'll try look into it later this week. Right now I'm afraid school is taking pretty much all of my spare time.
Sukasa #21
Posted 27 November 2012 - 06:20 PM
Another request: PlayerDimension(str playername) - returns the dimension that the player is in.
Bubba #22
Posted 27 November 2012 - 06:53 PM
Another request: PlayerDimension(str playername) - returns the dimension that the player is in.

Hmm. I like this one. I'll try to implement this in the next update.
00Fant #23
Posted 28 November 2012 - 03:09 AM
and more ideas…

setPlayerSpeed( player, value)
setJumpPower( player, value )

char = getPressedKey( player )


and a other question, can u make a turtle with ur peripheral integrated?

i´ve made a trutle follower but i must spawn ur peripheral on top to get the coords ^^ that is not the best way xD


Thanks for ur peripheral, that is what we need! ;)/>
Larethian #24
Posted 04 December 2012 - 11:14 AM
This sounds interesting and I plan to use it on a server where nobody knows Lua so I can safely use it…
However I cant seem to download this without registering on the downloadpage, which I do not want (There are enough out there who have my (not too reliable) data). Can you upload it maybe at another spot where it can be accessed without having to register?
Bubba #25
Posted 04 December 2012 - 01:45 PM
This sounds interesting and I plan to use it on a server where nobody knows Lua so I can safely use it…
However I cant seem to download this without registering on the downloadpage, which I do not want (There are enough out there who have my (not too reliable) data). Can you upload it maybe at another spot where it can be accessed without having to register?

Here is a link to it on Mediafire - http://www.mediafire.com/?87o869ggdo08e6p

Please keep in mind that I've never tested it on a server so I have no idea whether or not it will work. If it doesn't, let me know what (if any) errors you get and I will attempt to fix the issue. Unfortunately my computer is undergoing repairs right now so it may be a few days before I am able to do anything about it.
Shnupbups #26
Posted 21 January 2013 - 01:35 PM
Sound awesome. Gonna be trying this.
Heh.

-- The Mob Killer 2000 --
args = {...}
if not args[1] or not args[2] or not args[3] or not args[4] then
  print("Usage: mobKiller <x> <y> <z> <loop> [damage]")
  return
end
adv = peripheral.wrap("right")
if loop == "true" then
  while true do
	if args[5] then
	  adv.createExplosion(tonumber(args[1]),tonumber(args[2]),tonumber(args[3]),tonumber(args[5]))
	else
	  adv.createExplosion(tonumber(args[1]),tonumber(args[2]),tonumber(args[3]),1)
	end
  end
else
  if args[5] then
	  adv.createExplosion(tonumber(args[1]),tonumber(args[2]),tonumber(args[3]),tonumber(args[5]))
  else
	  adv.createExplosion(tonumber(args[1]),tonumber(args[2]),tonumber(args[3]),1)
  end
end
Heh.
sirdabalot #27
Posted 24 January 2013 - 10:47 PM
Sound awesome. Gonna be trying this.
Heh.

-- The Mob Killer 2000 --
args = {...}
if not args[1] or not args[2] or not args[3] or not args[4] then
  print("Usage: mobKiller <x> <y> <z> <loop> [damage]")
  return
end
adv = peripheral.wrap("right")
if loop == "true" then
  while true do
	if args[5] then
	  adv.createExplosion(tonumber(args[1]),tonumber(args[2]),tonumber(args[3]),tonumber(args[5]))
	else
	  adv.createExplosion(tonumber(args[1]),tonumber(args[2]),tonumber(args[3]),1)
	end
  end
else
  if args[5] then
	  adv.createExplosion(tonumber(args[1]),tonumber(args[2]),tonumber(args[3]),tonumber(args[5]))
  else
	  adv.createExplosion(tonumber(args[1]),tonumber(args[2]),tonumber(args[3]),1)
  end
end
Heh.

You have just given me an idea to make an explosion circle thingy. O_o Forcefields FTW!
NOTUSEDPLEASEDELETE #28
Posted 06 August 2013 - 05:43 PM
Awesome! I have an idea:
Add a function that executes the command added as the parameter.
Example:

--Clears someone's inventory
peripheral.executeCommand("clear")
Bubba #29
Posted 08 August 2013 - 11:14 PM
Awesome! I have an idea:
Add a function that executes the command added as the parameter.
Example:

--Clears someone's inventory
peripheral.executeCommand("clear")

This project is way dead. Check out immibis' peripherals. I believe he has an AdventureMap peripheral that does more than mine did.
Cranium #30
Posted 09 August 2013 - 10:23 AM
Locked as requested.