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

Minecraft version?

Started by Kameko, 30 May 2015 - 07:31 PM
Kameko #1
Posted 30 May 2015 - 09:31 PM
I couldn't find an existing API for it nor a suggestion for it. Can we get an API call to get the current version of Minecraft? It would be pretty useful for running commands like "summon" which break between 1.7 and 1.8. I don't think relying on the OS version is very reliable, since critical bug fix updates could be released at any time.
Edited on 30 May 2015 - 07:32 PM
Creator #2
Posted 30 May 2015 - 09:54 PM
That is actually a good idea. However, rather use __MCN or something similar. <== a constant
Lupus590 #3
Posted 30 May 2015 - 10:25 PM
A simple way to do this is to check if the index in the API table is not nil before you try to call it.
Although, having the MC version could be useful in some other way.
Edited on 30 May 2015 - 08:25 PM
Bomb Bloke #4
Posted 30 May 2015 - 11:54 PM
As it happens, the 1.74's beta introduces a _CCVERSION constant. Determining the MineCraft version from that should be fairly easy to do.

For older builds, it's indeed a case of looking to see which functions are available.
Kameko #5
Posted 31 May 2015 - 01:25 AM
As it happens, the 1.74's beta introduces a _CCVERSION constant. Determining the MineCraft version from that should be fairly easy to do.

For older builds, it's indeed a case of looking to see which functions are available.
Neat! So then I can just put in a "ver = _CCVERSION or 1.7" in my code then until the beta's out?
Bomb Bloke #6
Posted 31 May 2015 - 03:39 AM
That depends on what, exactly, you're trying to determine. The initial example you gave is impossible to check for, as thus far there aren't any builds of CC - including the beta - which work under MC 1.8.
Kameko #7
Posted 31 May 2015 - 04:52 AM
That depends on what, exactly, you're trying to determine. The initial example you gave is impossible to check for, as thus far there aren't any builds of CC - including the beta - which work under MC 1.8.
I know, it's future proofing. I don't want people loading up my map in 1.8 if/when CC is updated for 1.8, and find a bunch of mobs totally naked because 1.8 doesn't accept number IDs in the summon command.
Bomb Bloke #8
Posted 31 May 2015 - 05:12 AM
The thing is we don't know yet which version of CC is going to make the jump to 1.8.

But a command computer can still determine your MineCraft version. Command functions are automatically added to the API based on what's available to command blocks.

For example, you should be able to do:

if commands.blockdata then
  -- User is on at least MineCraft 1.8, snapshot 14w02a.
else
  -- User is on something earlier.
end
Kameko #9
Posted 31 May 2015 - 05:24 AM
Ah, I didn't know that, I thought it was just commands.exec, which runs regardless of the validity of the JSON passed to it. Thanks for the help with that.
I guess checking what commands are available is good too, but I'm still throwing a suggestion out there if it sounds like a good idea. It's just one hard-coded variable and all.
TsarN #10
Posted 01 June 2015 - 04:57 PM
You can use following code:
local ccver = "1.0" --Precise ComputerCraft version
if not fs.exists("/rom/help/changelog") then
	printError("Failed to find ComputerCraft version")
	return
end
local fChangelog = fs.open("/rom/help/changelog", "r")
local sChangelog = fChangelog.readLine()
fChangelog.close()
ccver = sChangelog:match("New Features in ComputerCraft ([%d%.]+):")
local mcversion = "unknown"
if ccver >= "1.64" then mcversion = "1.7.10" elseif
ccver > "1.57" then mcversion = "1.6.4" elseif
ccver > "1.53" then mcversion = "1.6.2" elseif
ccver == "1.53" then mcversion = "1.5.2" elseif
ccver == "1.52" then mcversion = "1.5.1" elseif
ccver >= "1.48" then mcversion = "1.4.5" end

This should work on non-command computers, in case somebody wants that
Edited on 01 June 2015 - 02:59 PM
KingofGamesYami #11
Posted 01 June 2015 - 05:00 PM
@TsarN - Except for the part where you attempt to compare strings using less-than. Might want to consider using tonumber.
Creator #12
Posted 01 June 2015 - 05:14 PM
This is smart actually.
MKlegoman357 #13
Posted 01 June 2015 - 08:23 PM
@TsarN - Except for the part where you attempt to compare strings using less-than. Might want to consider using tonumber.

Actually, comparing strings like that is valid in Lua.
Edited on 01 June 2015 - 06:24 PM
biggest yikes #14
Posted 11 June 2015 - 02:46 PM
ComputerCraft 1.74pr30 adds _MC_VERSION. Looks like the suggestion got implemented!
Edited on 11 June 2015 - 12:47 PM