minecraft-pi 0.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +54 -0
- data/LICENSE.txt +21 -0
- data/README.org +56 -0
- data/lib/minecraft-pi.rb +12 -0
- data/lib/minecraft-pi/camera.rb +26 -0
- data/lib/minecraft-pi/camera_mode.rb +30 -0
- data/lib/minecraft-pi/chat.rb +20 -0
- data/lib/minecraft-pi/client.rb +60 -0
- data/lib/minecraft-pi/entity.rb +43 -0
- data/lib/minecraft-pi/error.rb +10 -0
- data/lib/minecraft-pi/events.rb +26 -0
- data/lib/minecraft-pi/events_block.rb +23 -0
- data/lib/minecraft-pi/player.rb +41 -0
- data/lib/minecraft-pi/socket.rb +44 -0
- data/lib/minecraft-pi/world.rb +78 -0
- data/lib/minecraft-pi/world_checkpoint.rb +25 -0
- data/minecraft-pi.gemspec +16 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d5b5ed60a8685816376d1654eacbaf8f0ac0ba03
|
4
|
+
data.tar.gz: d18b7763ab930175507706c5551cd96ef3357f14
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1c5eedd31aa445c81a61361735a3108c6bf1944836b86a3a2535a239ace1ad244f03aeff91998ae0beafbb60e65a57784474bef1018ac7a28f17b5ab3159cd23
|
7
|
+
data.tar.gz: b31bef5c294e7f7e71cfc7de25f13b79040138714d9006c88b89d7b1643290107725866a33cb8547ac570de9f24faf33feb06bce210adbc4b55dd830ec0d549f
|
data/.gitignore
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
|
2
|
+
# Created by https://www.gitignore.io/api/ruby
|
3
|
+
|
4
|
+
### Ruby ###
|
5
|
+
*.gem
|
6
|
+
*.rbc
|
7
|
+
/.config
|
8
|
+
/coverage/
|
9
|
+
/InstalledFiles
|
10
|
+
/pkg/
|
11
|
+
/spec/reports/
|
12
|
+
/spec/examples.txt
|
13
|
+
/test/tmp/
|
14
|
+
/test/version_tmp/
|
15
|
+
/tmp/
|
16
|
+
|
17
|
+
# Used by dotenv library to load environment variables.
|
18
|
+
# .env
|
19
|
+
|
20
|
+
## Specific to RubyMotion:
|
21
|
+
.dat*
|
22
|
+
.repl_history
|
23
|
+
build/
|
24
|
+
*.bridgesupport
|
25
|
+
build-iPhoneOS/
|
26
|
+
build-iPhoneSimulator/
|
27
|
+
|
28
|
+
## Specific to RubyMotion (use of CocoaPods):
|
29
|
+
#
|
30
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
31
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
32
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
33
|
+
#
|
34
|
+
# vendor/Pods/
|
35
|
+
|
36
|
+
## Documentation cache and generated files:
|
37
|
+
/.yardoc/
|
38
|
+
/_yardoc/
|
39
|
+
/doc/
|
40
|
+
/rdoc/
|
41
|
+
|
42
|
+
## Environment normalization:
|
43
|
+
/.bundle/
|
44
|
+
/vendor/bundle
|
45
|
+
/lib/bundler/man/
|
46
|
+
|
47
|
+
# for a library or gem, you might want to ignore these files since the code is
|
48
|
+
# intended to run in multiple environments; otherwise, check them in:
|
49
|
+
# Gemfile.lock
|
50
|
+
# .ruby-version
|
51
|
+
# .ruby-gemset
|
52
|
+
|
53
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
54
|
+
.rvmrc
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
The MIT License (MIT)
|
3
|
+
Copyright © 2016 Chris Olstrom <chris@olstrom.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the “Software”), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.org
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#+TITLE: minecraft-pi
|
2
|
+
#+LATEX: \pagebreak
|
3
|
+
|
4
|
+
* Overview
|
5
|
+
|
6
|
+
~minecraft-pi~ is a low-level interface to the Minecraft Pi Edition API for
|
7
|
+
Ruby. It covers the known API, and should map directly to the documentation
|
8
|
+
included with MCPI (minus the bits that are python-specific).
|
9
|
+
|
10
|
+
* Notable Features
|
11
|
+
|
12
|
+
- All methods have =Contracts= defined, and conform to them.
|
13
|
+
- Where appropriate, most methods have automatic retry behaviour.
|
14
|
+
- The undocumented =Entity= API is supported, making it easier to work with multiplayer sessions.
|
15
|
+
|
16
|
+
* Supported Versions
|
17
|
+
|
18
|
+
~minecraft-pi~ is tested with the official =0.1.1= release, and the unofficial =0.6.1= patches.
|
19
|
+
|
20
|
+
* Installation
|
21
|
+
|
22
|
+
#+BEGIN_SRC shell
|
23
|
+
gem install minecraft-pi
|
24
|
+
#+END_SRC
|
25
|
+
|
26
|
+
* Usage
|
27
|
+
|
28
|
+
The following code will set the block at the host player's feet to pink wool:
|
29
|
+
|
30
|
+
#+BEGIN_SRC ruby
|
31
|
+
require 'minecraft-pi'
|
32
|
+
|
33
|
+
mc = MinecraftPi::Client.new
|
34
|
+
|
35
|
+
x, y, z = mc.player.getPos
|
36
|
+
|
37
|
+
mc.world.setBlockWithData x, y-1, z, 35, 6
|
38
|
+
#+END_SRC
|
39
|
+
|
40
|
+
See the [[https://colstrom.github.io/minecraft-pi/doc/][documentation]] for more information.
|
41
|
+
|
42
|
+
* Known Issues
|
43
|
+
|
44
|
+
- =EventsBlock#hits= has been observed to cause crashes with some patched
|
45
|
+
versions of MCPI. This has been observed on a client with community-provided
|
46
|
+
patches applied, enabling surivival mode and fullscreen support. This does
|
47
|
+
not occur with the official =0.1.1= release.
|
48
|
+
|
49
|
+
* License
|
50
|
+
|
51
|
+
The ~minecraft-pi~ gem is available under the [[https://tldrlegal.com/license/mit-license][MIT License]]. See ~LICENSE.txt~
|
52
|
+
for the full text.
|
53
|
+
|
54
|
+
* Contributors
|
55
|
+
|
56
|
+
- [[https://colstrom.github.io/][Chris Olstrom]] | [[mailto:chris@olstrom.com][e-mail]] | [[https://twitter.com/ChrisOlstrom][Twitter]]
|
data/lib/minecraft-pi.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require_relative 'minecraft-pi/camera'
|
2
|
+
require_relative 'minecraft-pi/camera_mode'
|
3
|
+
require_relative 'minecraft-pi/chat'
|
4
|
+
require_relative 'minecraft-pi/client'
|
5
|
+
require_relative 'minecraft-pi/entity'
|
6
|
+
require_relative 'minecraft-pi/error'
|
7
|
+
require_relative 'minecraft-pi/events'
|
8
|
+
require_relative 'minecraft-pi/events_block'
|
9
|
+
require_relative 'minecraft-pi/player'
|
10
|
+
require_relative 'minecraft-pi/socket'
|
11
|
+
require_relative 'minecraft-pi/world'
|
12
|
+
require_relative 'minecraft-pi/world_checkpoint'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'contracts'
|
2
|
+
require_relative 'socket'
|
3
|
+
require_relative 'camera_mode'
|
4
|
+
|
5
|
+
module MinecraftPi
|
6
|
+
class Camera
|
7
|
+
include ::Contracts::Core
|
8
|
+
include ::Contracts::Builtin
|
9
|
+
|
10
|
+
Contract Socket => Camera
|
11
|
+
def initialize(socket)
|
12
|
+
@socket = socket
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
Contract None => CameraMode
|
17
|
+
def mode
|
18
|
+
@mode ||= CameraMode.new @socket
|
19
|
+
end
|
20
|
+
|
21
|
+
Contract RespondTo[:to_f], RespondTo[:to_f], RespondTo[:to_f] => nil
|
22
|
+
def setPos(x, y, z)
|
23
|
+
@socket.write "camera.setPos(#{x.to_f},#{y.to_f},#{z.to_f})"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'contracts'
|
2
|
+
require_relative 'socket'
|
3
|
+
|
4
|
+
module MinecraftPi
|
5
|
+
class CameraMode
|
6
|
+
include ::Contracts::Core
|
7
|
+
include ::Contracts::Builtin
|
8
|
+
|
9
|
+
Contract Socket => CameraMode
|
10
|
+
def initialize(socket)
|
11
|
+
@socket = socket
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
Contract RespondTo[:to_i] => nil
|
16
|
+
def setNormal(entity)
|
17
|
+
@socket.write "camera.mode.setNormal(#{entity.to_i})"
|
18
|
+
end
|
19
|
+
|
20
|
+
Contract RespondTo[:to_i] => nil
|
21
|
+
def setFollow(entity)
|
22
|
+
@socket.write "camera.mode.setFollow(#{entity.to_i})"
|
23
|
+
end
|
24
|
+
|
25
|
+
Contract None => nil
|
26
|
+
def setFixed
|
27
|
+
@socket.write 'camera.mode.setFixed()'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'contracts'
|
2
|
+
require_relative 'socket'
|
3
|
+
|
4
|
+
module MinecraftPi
|
5
|
+
class Chat
|
6
|
+
include ::Contracts::Core
|
7
|
+
include ::Contracts::Builtin
|
8
|
+
|
9
|
+
Contract Socket => Chat
|
10
|
+
def initialize(socket)
|
11
|
+
@socket = socket
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
Contract RespondTo[:to_s] => nil
|
16
|
+
def post(message)
|
17
|
+
@socket.write "chat.post(#{message})"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'contracts'
|
2
|
+
require_relative 'camera'
|
3
|
+
require_relative 'chat'
|
4
|
+
require_relative 'entity'
|
5
|
+
require_relative 'events'
|
6
|
+
require_relative 'player'
|
7
|
+
require_relative 'socket'
|
8
|
+
require_relative 'world'
|
9
|
+
|
10
|
+
module MinecraftPi
|
11
|
+
class Client
|
12
|
+
include ::Contracts::Core
|
13
|
+
include ::Contracts::Builtin
|
14
|
+
|
15
|
+
Contract KeywordArgs[
|
16
|
+
address: Optional[RespondTo[:to_s]],
|
17
|
+
port: Optional[RespondTo[:to_i]]
|
18
|
+
] => Client
|
19
|
+
def initialize(address: 'localhost', port: 4711)
|
20
|
+
@address = address.to_s
|
21
|
+
@port = port.to_i
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
Contract None => Socket
|
26
|
+
def socket
|
27
|
+
@socket ||= Socket.new(address: @address, port: @port)
|
28
|
+
end
|
29
|
+
|
30
|
+
Contract None => Camera
|
31
|
+
def camera
|
32
|
+
@camera ||= Camera.new socket
|
33
|
+
end
|
34
|
+
|
35
|
+
Contract None => Chat
|
36
|
+
def chat
|
37
|
+
@chat ||= Chat.new socket
|
38
|
+
end
|
39
|
+
|
40
|
+
Contract None => Entity
|
41
|
+
def entity
|
42
|
+
@entity ||= Entity.new socket
|
43
|
+
end
|
44
|
+
|
45
|
+
Contract None => Events
|
46
|
+
def events
|
47
|
+
@events ||= Events.new socket
|
48
|
+
end
|
49
|
+
|
50
|
+
Contract None => Player
|
51
|
+
def player
|
52
|
+
@player ||= Player.new socket
|
53
|
+
end
|
54
|
+
|
55
|
+
Contract None => World
|
56
|
+
def world
|
57
|
+
@world ||= World.new socket
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'contracts'
|
2
|
+
require_relative 'socket'
|
3
|
+
|
4
|
+
module MinecraftPi
|
5
|
+
class Entity
|
6
|
+
include ::Contracts::Core
|
7
|
+
include ::Contracts::Builtin
|
8
|
+
|
9
|
+
Contract Socket => Entity
|
10
|
+
def initialize(socket)
|
11
|
+
@socket = socket
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
Contract RespondTo[:to_i] => ArrayOf[Float]
|
16
|
+
def getPos(entity)
|
17
|
+
@socket
|
18
|
+
.request("entity.getPos(#{entity.to_i})")
|
19
|
+
.split(',')
|
20
|
+
.map(&:to_f)
|
21
|
+
end
|
22
|
+
|
23
|
+
Contract RespondTo[:to_i], RespondTo[:to_f], RespondTo[:to_f], RespondTo[:to_f] => nil
|
24
|
+
def setPos(entity, x, y, z)
|
25
|
+
@socket
|
26
|
+
.write("entity.setPos(#{entity.to_i},#{x.to_f},#{y.to_f},#{z.to_f})")
|
27
|
+
end
|
28
|
+
|
29
|
+
Contract RespondTo[:to_i] => ArrayOf[Fixnum]
|
30
|
+
def getTile(entity)
|
31
|
+
@socket
|
32
|
+
.request("entity.getTile(#{entity.to_i})")
|
33
|
+
.split(',')
|
34
|
+
.map(&:to_i)
|
35
|
+
end
|
36
|
+
|
37
|
+
Contract RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i] => nil
|
38
|
+
def setTile(entity, x, y, z)
|
39
|
+
@socket
|
40
|
+
.write("entity.setTile(#{entity.to_i},#{x.to_i},#{y.to_i},#{z.to_i})")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'contracts'
|
2
|
+
require_relative 'events_block'
|
3
|
+
require_relative 'socket'
|
4
|
+
|
5
|
+
module MinecraftPi
|
6
|
+
class Events
|
7
|
+
include ::Contracts::Core
|
8
|
+
include ::Contracts::Builtin
|
9
|
+
|
10
|
+
Contract Socket => Events
|
11
|
+
def initialize(socket)
|
12
|
+
@socket = socket
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
Contract None => EventsBlock
|
17
|
+
def block
|
18
|
+
@block ||= EventsBlock.new @socket
|
19
|
+
end
|
20
|
+
|
21
|
+
Contract None => nil
|
22
|
+
def clear
|
23
|
+
@socket.write 'events.clear()'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'contracts'
|
2
|
+
require_relative 'socket'
|
3
|
+
|
4
|
+
module MinecraftPi
|
5
|
+
class EventsBlock
|
6
|
+
include ::Contracts::Core
|
7
|
+
include ::Contracts::Builtin
|
8
|
+
|
9
|
+
Contract Socket => EventsBlock
|
10
|
+
def initialize(socket)
|
11
|
+
@socket = socket
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
Contract None => ArrayOf[ArrayOf[Fixnum]]
|
16
|
+
def hits
|
17
|
+
@socket
|
18
|
+
.request('events.block.hits()')
|
19
|
+
.split('|')
|
20
|
+
.map { |event| event.split(',').map(&:to_i) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'contracts'
|
2
|
+
require_relative 'socket'
|
3
|
+
|
4
|
+
module MinecraftPi
|
5
|
+
class Player
|
6
|
+
include ::Contracts::Core
|
7
|
+
include ::Contracts::Builtin
|
8
|
+
|
9
|
+
Contract Socket => Player
|
10
|
+
def initialize(socket)
|
11
|
+
@socket = socket
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
Contract None => ArrayOf[Float]
|
16
|
+
def getPos
|
17
|
+
@socket
|
18
|
+
.request('player.getPos()')
|
19
|
+
.split(',')
|
20
|
+
.map(&:to_f)
|
21
|
+
end
|
22
|
+
|
23
|
+
Contract RespondTo[:to_f], RespondTo[:to_f], RespondTo[:to_f] => nil
|
24
|
+
def setPos(x, y, z)
|
25
|
+
@socket.write "player.setPos(#{x.to_f},#{y.to_f},#{z.to_f})"
|
26
|
+
end
|
27
|
+
|
28
|
+
Contract None => ArrayOf[Fixnum]
|
29
|
+
def getTile
|
30
|
+
@socket
|
31
|
+
.request('player.getTile()')
|
32
|
+
.split(',')
|
33
|
+
.map(&:to_i)
|
34
|
+
end
|
35
|
+
|
36
|
+
Contract RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i] => nil
|
37
|
+
def setTile(x, y, z)
|
38
|
+
@socket.write "player.setTile(#{x.to_i},#{y.to_i},#{z.to_i})"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'contracts'
|
2
|
+
require 'socket'
|
3
|
+
require_relative 'error'
|
4
|
+
|
5
|
+
module MinecraftPi
|
6
|
+
class Socket
|
7
|
+
include ::Contracts::Core
|
8
|
+
include ::Contracts::Builtin
|
9
|
+
|
10
|
+
Contract KeywordArgs[
|
11
|
+
address: Optional[RespondTo[:to_s]],
|
12
|
+
port: Optional[RespondTo[:to_i]]
|
13
|
+
] => Socket
|
14
|
+
def initialize(address: 'localhost', port: 4711)
|
15
|
+
@socket = ::TCPSocket.new address.to_s, port.to_i
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
Contract RespondTo[:to_s] => nil
|
20
|
+
def write(message)
|
21
|
+
message.to_s.tap do |m|
|
22
|
+
STDERR.puts m
|
23
|
+
@socket.puts m
|
24
|
+
end
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
Contract None => String
|
29
|
+
def read
|
30
|
+
@socket.gets.chomp.tap { |reply| STDERR.puts "=> #{reply}" }
|
31
|
+
end
|
32
|
+
|
33
|
+
Contract RespondTo[:to_s], Maybe[RespondTo[:to_i]] => String
|
34
|
+
def request(message, attempt = 1)
|
35
|
+
write message.to_s
|
36
|
+
read.tap { |reply| raise FailError if reply == 'Fail' }
|
37
|
+
|
38
|
+
rescue FailError
|
39
|
+
STDERR.puts "retry #{attempt}"
|
40
|
+
sleep 0.1
|
41
|
+
request(message, attempt.to_i + 1)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'contracts'
|
2
|
+
require_relative 'error'
|
3
|
+
require_relative 'socket'
|
4
|
+
require_relative 'world_checkpoint'
|
5
|
+
|
6
|
+
module MinecraftPi
|
7
|
+
class World
|
8
|
+
include ::Contracts::Core
|
9
|
+
include ::Contracts::Builtin
|
10
|
+
|
11
|
+
Contract Socket => World
|
12
|
+
def initialize(socket)
|
13
|
+
@socket = socket
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
Contract None => WorldCheckpoint
|
18
|
+
def checkpoint
|
19
|
+
@checkpoint ||= WorldCheckpoint.new @socket
|
20
|
+
end
|
21
|
+
|
22
|
+
# TODO: Should return a collection
|
23
|
+
def getPlayerIds
|
24
|
+
@socket.request 'world.getPlayerIds()'
|
25
|
+
end
|
26
|
+
|
27
|
+
Contract RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i] => Fixnum
|
28
|
+
def getBlock(x, y, z)
|
29
|
+
@socket.request("world.getBlock(#{x.to_i},#{y.to_i},#{z.to_i})").to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
Contract RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i] => ArrayOf[Fixnum]
|
33
|
+
def getBlockWithData(x, y, z)
|
34
|
+
@socket
|
35
|
+
.request("world.getBlockWithData(#{x.to_i},#{y.to_i},#{z.to_i})")
|
36
|
+
.split(',')
|
37
|
+
.map(&:to_i)
|
38
|
+
end
|
39
|
+
|
40
|
+
Contract RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i] => nil
|
41
|
+
def setBlock(x, y, z, id, attempt = 1)
|
42
|
+
@socket.write "world.setBlock(#{x.to_i},#{y.to_i},#{z.to_i},#{id.to_i})"
|
43
|
+
raise SetBlockError if getBlock(x, y, z) != id
|
44
|
+
rescue SetBlockError
|
45
|
+
STDERR.puts "retry #{attempt}"
|
46
|
+
setBlock(x, y, z, id, attempt.to_i + 1)
|
47
|
+
end
|
48
|
+
|
49
|
+
Contract RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i] => nil
|
50
|
+
def setBlockWithData(x, y, z, id, data, attempt = 1)
|
51
|
+
@socket.write "world.setBlock(#{x.to_i},#{y.to_i},#{z.to_i},#{id.to_i},#{data.to_i})"
|
52
|
+
raise SetBlockError if getBlockWithData(x, y, z) != [id.to_i, data.to_i]
|
53
|
+
rescue SetBlockError
|
54
|
+
STDERR.puts "retry #{attempt}"
|
55
|
+
setBlockWithData(x, y, z, id, data, attempt.to_i + 1)
|
56
|
+
end
|
57
|
+
|
58
|
+
Contract RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i] => nil
|
59
|
+
def setBlocks(x1, y1, z1, x2, y2, z2, id)
|
60
|
+
@socket.write "world.setBlocks(#{x1},#{y1},#{z1},#{x2},#{y2},#{z2},#{id})"
|
61
|
+
end
|
62
|
+
|
63
|
+
Contract RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i], RespondTo[:to_i] => nil
|
64
|
+
def setBlocksWithData(x1, y1, z1, x2, y2, z2, id, data)
|
65
|
+
@socket.write "world.setBlocks(#{x1.to_i},#{y1.to_i},#{z1.to_i},#{x2.to_i},#{y2.to_i},#{z2.to_i},#{id.to_i},#{data.to_i})"
|
66
|
+
end
|
67
|
+
|
68
|
+
Contract RespondTo[:to_i], RespondTo[:to_i] => Fixnum
|
69
|
+
def getHeight(x, z)
|
70
|
+
@socket.request("world.getHeight(#{x.to_i},#{z.to_i})").to_i
|
71
|
+
end
|
72
|
+
|
73
|
+
Contract Enum[:world_immutable, :nametags_visible], Bool => nil
|
74
|
+
def setting(setting, status)
|
75
|
+
@socket.write "world.setting(#{setting},#{status ? 1 : 0})"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'contracts'
|
2
|
+
require_relative 'socket'
|
3
|
+
|
4
|
+
module MinecraftPi
|
5
|
+
class WorldCheckpoint
|
6
|
+
include ::Contracts::Core
|
7
|
+
include ::Contracts::Builtin
|
8
|
+
|
9
|
+
Contract Socket => WorldCheckpoint
|
10
|
+
def initialize(socket)
|
11
|
+
@socket = socket
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
Contract None => nil
|
16
|
+
def save
|
17
|
+
@socket.write 'world.checkpoint.save()'
|
18
|
+
end
|
19
|
+
|
20
|
+
Contract None => nil
|
21
|
+
def restore
|
22
|
+
@socket.write 'world.checkpoint.restore()'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.name = 'minecraft-pi'
|
3
|
+
gem.version = `git describe --tags --abbrev=0`.chomp
|
4
|
+
gem.licenses = 'MIT'
|
5
|
+
gem.authors = ['Chris Olstrom']
|
6
|
+
gem.email = 'chris@olstrom.com'
|
7
|
+
gem.homepage = 'https://github.com/colstrom/minecraft-pi'
|
8
|
+
gem.summary = 'Control Minecraft Pi Edition from Ruby'
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split("\n")
|
11
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
12
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
13
|
+
gem.require_paths = ['lib']
|
14
|
+
|
15
|
+
gem.add_runtime_dependency 'contracts', '~> 0.14', '>= 0.14.0'
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: minecraft-pi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.12.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Olstrom
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: contracts
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.14'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.14.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.14'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.14.0
|
33
|
+
description:
|
34
|
+
email: chris@olstrom.com
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- ".gitignore"
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.org
|
42
|
+
- lib/minecraft-pi.rb
|
43
|
+
- lib/minecraft-pi/camera.rb
|
44
|
+
- lib/minecraft-pi/camera_mode.rb
|
45
|
+
- lib/minecraft-pi/chat.rb
|
46
|
+
- lib/minecraft-pi/client.rb
|
47
|
+
- lib/minecraft-pi/entity.rb
|
48
|
+
- lib/minecraft-pi/error.rb
|
49
|
+
- lib/minecraft-pi/events.rb
|
50
|
+
- lib/minecraft-pi/events_block.rb
|
51
|
+
- lib/minecraft-pi/player.rb
|
52
|
+
- lib/minecraft-pi/socket.rb
|
53
|
+
- lib/minecraft-pi/world.rb
|
54
|
+
- lib/minecraft-pi/world_checkpoint.rb
|
55
|
+
- minecraft-pi.gemspec
|
56
|
+
homepage: https://github.com/colstrom/minecraft-pi
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.5.1
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Control Minecraft Pi Edition from Ruby
|
80
|
+
test_files: []
|
81
|
+
has_rdoc:
|