diamond-lang 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9a816bc76009b376879f5701b08383fdf4ff4fa2
4
+ data.tar.gz: 7ba525b2610ded9f516d6383cea1fd0ff8016084
5
+ SHA512:
6
+ metadata.gz: 259b7b425a2fa1db817a49bca407b6807ed63b4060a33b0021cfd6daf64a88f174e62e92820f89a7b91874096c0449e0e114f855b3c2d90b9acf985908470e4f
7
+ data.tar.gz: f2c1d554438a5d17ee170900f442e3901808a18b4f6a4927d155dfdf23ad4ef464197c5891f0bdfa2de646864ea15ccee7e00673b6d3cd23aaa70311d272504a
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", "~> 3.5"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0"
12
+ gem "jeweler", "~> 2.0"
13
+ gem "simplecov", "~> 0.11"
14
+ end
15
+
16
+ gem 'require_all', "~> 1.3"
data/Gemfile.lock ADDED
@@ -0,0 +1,84 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.2.5)
5
+ i18n (~> 0.7)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.3, >= 0.3.4)
9
+ tzinfo (~> 1.1)
10
+ addressable (2.4.0)
11
+ builder (3.2.2)
12
+ descendants_tracker (0.0.4)
13
+ thread_safe (~> 0.3, >= 0.3.1)
14
+ docile (1.1.5)
15
+ faraday (0.9.2)
16
+ multipart-post (>= 1.2, < 3)
17
+ git (1.2.9.1)
18
+ github_api (0.13.1)
19
+ addressable (~> 2.4.0)
20
+ descendants_tracker (~> 0.0.4)
21
+ faraday (~> 0.8, < 0.10)
22
+ hashie (>= 3.4)
23
+ multi_json (>= 1.7.5, < 2.0)
24
+ oauth2
25
+ hashie (3.4.3)
26
+ highline (1.7.8)
27
+ i18n (0.7.0)
28
+ jeweler (2.0.1)
29
+ builder
30
+ bundler (>= 1.0)
31
+ git (>= 1.2.5)
32
+ github_api
33
+ highline (>= 1.6.15)
34
+ nokogiri (>= 1.5.10)
35
+ rake
36
+ rdoc
37
+ json (1.8.3)
38
+ jwt (1.5.2)
39
+ mini_portile2 (2.0.0)
40
+ minitest (5.8.3)
41
+ multi_json (1.11.2)
42
+ multi_xml (0.5.5)
43
+ multipart-post (2.0.0)
44
+ nokogiri (1.6.7.1)
45
+ mini_portile2 (~> 2.0.0.rc2)
46
+ oauth2 (1.0.0)
47
+ faraday (>= 0.8, < 0.10)
48
+ jwt (~> 1.0)
49
+ multi_json (~> 1.3)
50
+ multi_xml (~> 0.5)
51
+ rack (~> 1.2)
52
+ rack (1.6.4)
53
+ rake (10.4.2)
54
+ rdoc (3.12.2)
55
+ json (~> 1.4)
56
+ require_all (1.3.3)
57
+ shoulda (3.5.0)
58
+ shoulda-context (~> 1.0, >= 1.0.1)
59
+ shoulda-matchers (>= 1.4.1, < 3.0)
60
+ shoulda-context (1.2.1)
61
+ shoulda-matchers (2.8.0)
62
+ activesupport (>= 3.0.0)
63
+ simplecov (0.11.1)
64
+ docile (~> 1.1.0)
65
+ json (~> 1.8)
66
+ simplecov-html (~> 0.10.0)
67
+ simplecov-html (0.10.0)
68
+ thread_safe (0.3.5)
69
+ tzinfo (1.2.2)
70
+ thread_safe (~> 0.1)
71
+
72
+ PLATFORMS
73
+ ruby
74
+
75
+ DEPENDENCIES
76
+ bundler (~> 1.0)
77
+ jeweler (~> 2.0)
78
+ rdoc (~> 3.12)
79
+ require_all (~> 1.3)
80
+ shoulda (~> 3.5)
81
+ simplecov (~> 0.11)
82
+
83
+ BUNDLED WITH
84
+ 1.10.6
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 Tech Edge Advisors LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,198 @@
1
+ #Diamond Lang
2
+ Diamond Lang is a minimal framework for Ruby that compiles into Minecraft One Command Creations.
3
+
4
+ #Installation:
5
+
6
+ DiamondLang is a Ruby Gem.
7
+
8
+ ##Ruby
9
+ DiamondLang is tested to work on Ruby 2.2.X. If you don't have Ruby 2.2.X, but know how to install it, do so in your preferred way. Otherwise, read on:
10
+
11
+ ###Mac Or Linux
12
+
13
+ Open Terminal (or your equivalent, on Linux) and type:
14
+
15
+ ~~~sh
16
+ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
17
+ \curl -sSL https://get.rvm.io | bash -s stable --ruby
18
+ ~~~
19
+
20
+ ###Windows
21
+ Go to <http://rubyinstaller.org> and download the correct version of Ruby.
22
+
23
+ ##Gem
24
+
25
+ You should have [ruby gems][gems], which allows you to download gems. To install diamond lang, type the following in your terminal:
26
+
27
+ ~~~sh
28
+ gem DiamondLang
29
+ ~~~
30
+
31
+ Now, you're good to go.
32
+
33
+
34
+ ---
35
+
36
+ #Getting Started
37
+ Using diamond lang is simpler then command blocks, although we'd recommend learning [a bit of ruby first][try-ruby] - that guide will only take 15 minutes, and is completely optional.
38
+
39
+ Once you've read that, we'll create a Hello World program that will say "Hello World" when the command is pasted into the world.
40
+
41
+ First, we'll include diamond lang, so that we can create a command.
42
+
43
+ ~~~rb
44
+ require 'diamond-lang' # Requires DiamondLang
45
+ ~~~
46
+
47
+ Next, we'll create our command. The name of your command should have no spaces, and the start of each word should be capitalized. So, we'll name our "Hello World" command "HelloWorld". It should also extend (`<`) `DiamondLang::OneCommand`.
48
+
49
+ ~~~rb
50
+ require 'diamond-lang'
51
+ class HelloWorld < DiamondLang::OneCommand
52
+ end
53
+ ~~~
54
+
55
+ To run a command at setup, create a `#setup` method:
56
+
57
+ ~~~rb
58
+ require 'diamond-lang'
59
+ class HelloWorld < DiamondLang::OneCommand
60
+ def setup(c)
61
+
62
+ end
63
+ end
64
+ ~~~
65
+
66
+ We're asking for the variable `c`, which is our command block chain. To attach a command, we call it as if it was a method on `c`:
67
+
68
+ ~~~rb
69
+ ...
70
+ def setup(c):
71
+ c.tell 'penne12', 'it worked!' #=> 'tell penne12 it worked!'
72
+ end
73
+ ...
74
+ ~~~
75
+
76
+ At the end of the code you wrote, run `{YourCommandName}.create`
77
+
78
+ ~~~rb
79
+ require 'diamond-lang'
80
+ class HelloWorld < DiamondLang::OneCommand
81
+ def setup(c)
82
+ c.tell 'penne12', 'it worked!' #=> 'tell penne12 it worked!'
83
+ end
84
+ end
85
+ HelloWorld.create
86
+ ~~~
87
+
88
+ to run your code
89
+
90
+ ---
91
+
92
+
93
+ #Helpers
94
+ To make your life easier, we implemented these features to mimic parts of Minecraft, and commonly used idioms:
95
+
96
+ ##Commands
97
+ Commands are attached to a chain (`c`), and arguments are separated with commas (`,`):
98
+
99
+ ###Examples:
100
+
101
+ ~~~rb
102
+ c.say "hi" #=> say hi
103
+ c.tell "penne12", "it works!" #=> tell penne12 it works
104
+ ~~~
105
+
106
+ ##Selectors
107
+ Entity/Player selectors are created with `#s`, and can be used as arguments in commands:
108
+
109
+ ###Examples:
110
+
111
+ ~~~rb
112
+ s(:p) #=> @p
113
+ s(:a) #=> @a (etc)
114
+ s(a: {r: 1}) #=> @a[r=1]
115
+ s(p: {c: 2}) #=> @p[c=2]
116
+ s(p: {x: 5, y: 64, z: 5}) #=> @p[x=5,y=64,z=5]
117
+ ~~~
118
+
119
+ ##Coordinates:
120
+ Coordinates can be created with `#coords`:
121
+
122
+ ###Examples:
123
+
124
+ ~~~rb
125
+ coords(4, 5, 6) #=> x: 4, y: 5, z: 6
126
+ coords('~', '~5', '~') #=> x: ~0, y: 5, z: ~0
127
+ ~~~
128
+
129
+ You can also get a coordinate:
130
+
131
+ ~~~rb
132
+ coords(4, 5, 6).z #=> DiamondLang::Helpers::Coordinate(z: 6)
133
+ coords(4, 5, 6).y #=> DiamondLang::Helpers::Coordinate(y: 5)
134
+ coords(4, 5, 6).x #=> DiamondLang::Helpers::Coordinate(x: 4)
135
+
136
+ test = coords(4, 5, 6) #=> coords(4, 5, 6)
137
+ text.x + 5 #=> 9
138
+ test #=> coords(9, 5, 6)
139
+ ~~~
140
+
141
+ ##Coordinate:
142
+ A single coordinate on the x, y, or z axis.
143
+
144
+ You can run `+` or `-`, which adds/substracts to the coordinate respectivly.
145
+
146
+ ###Examples:
147
+
148
+ ~~~rb
149
+ DiamondLang::Helpers::Coordinate(:x, 6) #=> x: 3
150
+ DiamondLang::Helpers::Coordinate(:x, 6) + 5 #=> 11
151
+ #=> Command Block: test_for @a[r=10]
152
+ #=> Chained conditional command block: tell @a[r=10] hello
153
+ ~~~
154
+
155
+ ##Conditions:
156
+ To make commands run on success, attach a block:
157
+
158
+ ~~~rb
159
+ c.test_for s(a: {r: 10}) do |c|
160
+ c.tell s(a: {r: 10}), 'hello'
161
+ end
162
+ #=> Command Block: test_for @a[r=10]
163
+ #=> Chained conditional command block: tell @a[r=10] hello
164
+ ~~~
165
+
166
+ ##Plain Ruby:
167
+ Diamond Lang is just a Ruby framework, so you can have awesome things, like variables:
168
+
169
+ ~~~rb
170
+ close_players = s(a: {r: 10})
171
+ c.test_for close_players do |c|
172
+ c.tell close_players, 'hello'
173
+ end #=> @a[r=10]
174
+ ~~~
175
+
176
+ hashes instead of arrays (we flatten the command arguments)
177
+
178
+ ~~~rb
179
+ c.tell penne12: 'something' #=> tell penne12 something
180
+ ~~~
181
+
182
+ string interpolation:
183
+
184
+ ~~~rb
185
+ c.tell penne12: "2 + 2 is #{2 + 2}" #=> tell penne12 2 + 2 is 4
186
+ ~~~
187
+
188
+ loops to ease the creation of commands:
189
+
190
+ ~~~rb
191
+ (5..10).each do |number|
192
+ c.tell 'penne12', number
193
+ end #=> tell penne12 5, tell penne12 6, tell penne12 7, tell penne12 8, tell penne12 9, tell penne12 10
194
+ ~~~
195
+
196
+ and more.
197
+
198
+ [gems]: https://rubygems.org
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "diamond-lang"
18
+ gem.homepage = "http://bensites.com/diamond-lang/"
19
+ gem.license = "MIT"
20
+ gem.summary = "A Ruby Framework for creating Minecraft 1 Command Creations."
21
+ gem.description = "Making Minecraft 1 Command Creations with ruby. It's as easy as `c.say 123`"
22
+ gem.email = "ben@bensites.com"
23
+ gem.authors = ["Ben (@penne12_)"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['test'].execute
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "diamond-lang #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,72 @@
1
+ =begin
2
+ /summon FallingSand ~ ~1 ~
3
+ {
4
+ Block:stone,
5
+ Time:1, Passengers:[
6
+ {
7
+ id:FallingSand,
8
+ Block:redstone_block,
9
+ Time:1,
10
+ Passengers:[
11
+ {
12
+ id:FallingSand,
13
+ Block:activator_rail,
14
+ Time:1,
15
+ Passengers:[
16
+ {
17
+ id:MinecartCommandBlock,
18
+ Command: gamerule commandBlockOutput false
19
+ },
20
+ {
21
+ id:MinecartCommandBlock,
22
+ Command: "fill ~2 ~-3 ~-1 ~4 ~-1 ~1 stained_hardened_clay 13 hollow"
23
+ },
24
+ {
25
+ id:MinecartCommandBlock,
26
+ Command:"fill ~2 ~-2 ~-1 ~4 ~-2 ~1 stained_glass 12 replace stained_hardened_clay"
27
+ },
28
+ {
29
+ id:MinecartCommandBlock,
30
+ Command:"scoreboard objectives add IqWApo_I dummy"
31
+ },
32
+ {
33
+ id:MinecartCommandBlock,
34
+ Command:setblock ~3 ~-2 ~ repeating_command_block 5 replace {
35
+ auto:1,Command:"say Hello World"
36
+ }
37
+ },
38
+ {
39
+ id:MinecartCommandBlock,
40
+ Command:setblock ~ ~ ~1 command_block 0 replace {
41
+ Command:fill ~ ~-3 ~-1 ~ ~ ~ air
42
+ }
43
+ },
44
+ {
45
+ id:MinecartCommandBlock,
46
+ Command:setblock ~ ~-1 ~1 redstone_block
47
+ },
48
+ {
49
+ id:MinecartCommandBlock,
50
+ Command:kill @e[type=MinecartCommandBlock,r=1]
51
+ }
52
+ ]
53
+ }
54
+ ]
55
+ }
56
+ ]
57
+ }
58
+ =end
59
+ require 'diamond-lang'
60
+
61
+ class HelloWorld < DiamondLang::OneCommand
62
+ def setup(c)
63
+ c.say "hello world"
64
+ end
65
+ def tick(c)
66
+ c.testfor s(e: {name: "woof"}) do |c|
67
+ c.say "<woof> woof"
68
+ end
69
+ end
70
+ end
71
+
72
+ HelloWorld.create_not_strict
@@ -0,0 +1,6 @@
1
+ require 'json'
2
+ require 'require_all'
3
+ require_rel 'diamond-lang'
4
+
5
+ module DiamondLang
6
+ end
@@ -0,0 +1,14 @@
1
+ require 'json'
2
+
3
+ module DiamondLang
4
+ class CommandChain
5
+ attr_reader :commands
6
+ def initialize(parent)
7
+ @parent = parent
8
+ @commands = []
9
+ end
10
+ def method_missing(name, *args, &block)
11
+ @commands << Helpers::Command.new(name.to_s.downcase, args, &block)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ module DiamondLang
2
+ module Helpers
3
+ class Block
4
+ attr_accessor :id, :data_value, :nbt
5
+ def initialize(id, data_value=0, nbt=nil)
6
+ @id = id
7
+ @data_value = data_value
8
+ @nbt = nbt
9
+ end
10
+ def to_s(replace_method=nil)
11
+ [id, data_value, replace_method, nbt.to_json].select{|e| e && e != 'null'}.join(' ')
12
+ end
13
+ def to_falling_sand
14
+ FallingSand.new self
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,36 @@
1
+ # say ...
2
+ # summon <entity> <coordinates> {entityData}
3
+ # gamemode <gamemode> @
4
+ # tellraw @ {text}
5
+ # blockdata <coordinates> {blockData}
6
+ # setblock <coordinates> <block dataValue> [old] {blockData}
7
+
8
+ module DiamondLang
9
+ module Helpers
10
+ class Command
11
+ attr_accessor :command
12
+ attr_reader :chain
13
+ def initialize(name, *args, &block)
14
+ @command = name.freeze
15
+ @arguments = args.flatten
16
+ if block
17
+ chain = CommandChain.new self
18
+ block.call(chain)
19
+ @chain = chain.commands.freeze
20
+ end
21
+ end
22
+ def to_s
23
+ [@command, *@arguments].join " "
24
+ end
25
+ def inspect
26
+ [@command, *@arguments].join(" ") + ", success: " + @chain.inspect
27
+ end
28
+ def to_minecart
29
+ CommandBlockMinecart.new self
30
+ end
31
+ def to_block(type=:chain)
32
+ CommandBlock.new self, type
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,45 @@
1
+ module DiamondLang
2
+ module Helpers
3
+ class CommandBlock < Block
4
+ Types = {
5
+ chain: 'chain_command_block',
6
+ impulse: 'command_block',
7
+ repeat: 'repeating_command_block'
8
+ }.freeze
9
+ def direction
10
+ conditional? ? @data_value - 8 : @data_value
11
+ end
12
+ def direction=(val)
13
+ @data_value = val + (conditional? ? 8 : 0)
14
+ end
15
+ def initialize(command,type=:chain,data_value=0,auto=true,conditional=false)
16
+ super Types[type], data_value, {
17
+ Command: command.to_s,
18
+ auto: auto
19
+ }
20
+ conditional = conditional
21
+ end
22
+ def type=(type)
23
+ @id = Types[type]
24
+ end
25
+ def type
26
+ Types.reverse[@id]
27
+ end
28
+ def conditional=(val)
29
+ if conditional? && !val
30
+ @data_value -= 8
31
+ elsif !@conditional && val
32
+ @date_value += 8
33
+ end
34
+ end
35
+ def conditional?(data_value=@data_value)
36
+ data_value >= 8
37
+ end
38
+ end
39
+ end
40
+ end
41
+ class Hash
42
+ def reverse
43
+ self.to_a.map{|i| i.reverse}.to_h
44
+ end
45
+ end
@@ -0,0 +1,9 @@
1
+ module DiamondLang
2
+ module Helpers
3
+ class CommandBlockMinecart < Entity
4
+ def initialize(command)
5
+ super 'MinecartCommandBlock', {Command: command.to_s}
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module DiamondLang
2
+ module Helpers
3
+ module Constants
4
+ Variables = {
5
+ closest_player: '@p'.freeze, # Closest player
6
+ random_player: '@r'.freeze, # Random player
7
+ all_player: '@a'.freeze, # All players
8
+ all: '@e'.freeze # All entities
9
+ }.freeze
10
+ Axes = %w[x y z].freeze
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,46 @@
1
+ module DiamondLang
2
+ module Helpers
3
+ class Coordinate
4
+ attr_reader :axis
5
+ def initialize(axis, v, relative=v.is_a?(String)&&v.include?('~'))
6
+ raise Errors::InvalidAxis.new(axis) unless Constants::Axes.include? (axis = axis.to_s.downcase)
7
+ @axis = axis
8
+ self.value=(v)
9
+ @relative = relative
10
+ end
11
+ def value=(value)
12
+ @value = if value.is_a? Integer
13
+ value
14
+ elsif value.is_a?(String) && /^(?<rel>~)?(?<number>\d+)?$/ =~ value
15
+ @relative = rel
16
+ number.to_i
17
+ else
18
+ raise Errors::InvalidCoordinateValue.new value
19
+ end
20
+ end
21
+ def +(amount)
22
+ @value += amount
23
+ end
24
+ def -(amount)
25
+ @value -= amount
26
+ end
27
+ def _value=(value)
28
+ @value = value
29
+ end
30
+ def _value
31
+ @value
32
+ end
33
+ def value
34
+ (@relative ? '~' : '') + @value.to_s
35
+ end
36
+ alias to_s value
37
+ def to_arg
38
+ raise Errors::RelativeCordinateConvertedToArgument if @relative
39
+ "#{@axis}=#{@value}".freeze
40
+ end
41
+ def inspect
42
+ "#{self.class.to_s}(" + @axis + ": " + value + ")"
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,40 @@
1
+ module DiamondLang
2
+ module Helpers
3
+ class Coordinates
4
+ def initialize(*args)
5
+ @coordinates, args = if args.first.is_a? Coordinate
6
+ args.slice_before{|a| a.is_a? Coordinate }
7
+ else
8
+ axes_args = args.take Constants::Axes.length
9
+ [
10
+ axes_args.zip(Constants::Axes).flat_map do |value, axis|
11
+ Coordinate.new axis, value
12
+ end,
13
+ args.drop(axes_args.length+1)
14
+ ]
15
+ end
16
+ end
17
+ def [](axis)
18
+ @coordinates.select{|coord| coord.axis == axis}[0]
19
+ end
20
+ def x
21
+ self['x'.freeze]
22
+ end
23
+ def y
24
+ self['y'.freeze]
25
+ end
26
+ def z
27
+ self['z'.freeze]
28
+ end
29
+ def to_s
30
+ self.to_fs "{x} {y} {z}".freeze
31
+ end
32
+ def to_fs(format)
33
+ format.gsub(/{(\w)}/) {|match| self[match[1]].value}
34
+ end
35
+ def to_arg
36
+ @coordinates.map {|coord| coord.to_arg}.join ','
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,45 @@
1
+ # /summon FallingSand ~ ~1 ~
2
+ # {
3
+ # Block:stone,
4
+ # Time:1, Passengers:[
5
+ # {
6
+ # id:FallingSand,
7
+ # Block:redstone_block,
8
+ # Time:1,
9
+ # Passengers:[
10
+
11
+ module DiamondLang
12
+ module Helpers
13
+ class Entity
14
+ attr_reader :id
15
+ attr_accessor :data
16
+ def initialize(id, data={})
17
+ @id = id
18
+ data[:Passengers] ||= []
19
+ @data = data
20
+ end
21
+ def passengers
22
+ data[:Passengers]
23
+ end
24
+ def passengers=(v)
25
+ data[:Passengers]=(v)
26
+ end
27
+ def to_h
28
+ data = @data.dup
29
+ data[:id] = @id
30
+ data[:Passengers] = data[:Passengers].map{ |passenger| passenger.to_h }
31
+ data.delete :Passengers if data[:Passengers].empty?
32
+ data
33
+ end
34
+ def summon(coords)
35
+ data = @data.dup
36
+ data[:Passengers] = data[:Passengers].map{ |passenger| passenger.to_h }
37
+ Command.new 'summon'.freeze, @id, coords.to_s, data.to_json
38
+ end
39
+ def selector(args={})
40
+ args[:type] = @id
41
+ TargetSelector.new({e: args})
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,9 @@
1
+ module DiamondLang
2
+ module Errors
3
+ class InvalidAxis < StandardError
4
+ def initialize(axis)
5
+ super "A cordinate was created with an axis of #{axis}, which isn't in: [#{Helpers::Constants::Axes.join(', ')}]"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module DiamondLang
2
+ module Errors
3
+ class InvalidCoordinateValue < StandardError
4
+ def initialize(value)
5
+ super "#{value} isn't a valid coordinate."
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module DiamondLang
2
+ module Errors
3
+ class RelativeCordinateConvertedToArgument < StandardError
4
+ def initialize
5
+ super "A relative cordinate was converted to an argument."
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module DiamondLang
2
+ module Errors
3
+ class TooSmall < StandardError
4
+ def initialize
5
+ super "Could not fit all commands in the area you selected."
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module DiamondLang
2
+ module Helpers
3
+ class FallingSand < Entity
4
+ def initialize(block=Block.new('sand'), time=1)
5
+ super 'FallingSand', {
6
+ Block: block.id,
7
+ Time: time,
8
+ Data: block.data_value
9
+ }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,31 @@
1
+ module DiamondLang
2
+ module Helpers
3
+ class TargetSelector
4
+ attr_accessor :arguments
5
+ def initialize(args)
6
+ variable, @arguments = args.flatten
7
+ @variable = "@#{variable}"
8
+ end
9
+ def <<(arguments)
10
+ @arguments = @arguments.merge arguments
11
+ end
12
+ def to_s
13
+ if @arguments
14
+ @variable + "[" + mc_args + "]"
15
+ else
16
+ @variable
17
+ end
18
+ end
19
+ alias inspect to_s
20
+ def mc_args
21
+ @arguments.map { |arg, val| val.to_arg arg }.join ','
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ class Object
28
+ def to_arg(arg)
29
+ arg.to_s + "=" + self.to_s
30
+ end
31
+ end
@@ -0,0 +1,14 @@
1
+ module DiamondLang
2
+ module Minecraft
3
+ module Commands
4
+ class Say < Helpers::Command
5
+ def initialize
6
+ super 'say', Helpers::CommandParts::Text
7
+ end
8
+ def call(*args)
9
+
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,93 @@
1
+ module DiamondLang
2
+ class OneCommand
3
+ def self.instance
4
+ @@instance
5
+ end
6
+ def self.create(*args)
7
+ @@instance = self.new(*args)
8
+ puts @@instance.to_command
9
+ end
10
+ def self.create_not_strict(*args)
11
+ @@instance = self.new(*args)
12
+ puts @@instance.to_command.to_s.gsub(/\\?"(\w+?)\\?":/, '\1:')
13
+ end
14
+ def initialize(hieght=5, length=6, width=5, offset=coords(2, 2, 0), surrond=Helpers::Block.new('stained_hardened_clay', 13))
15
+ @height = hieght # y
16
+ @width = width # z
17
+ @length = (length / 2).floor * 2 # x
18
+ puts "WARNING: The length of your command block needs to be even. Rounding down to #{@length}." unless length % 2 == 0
19
+ @offset = offset
20
+ @corner1 = coords("~#{@offset.x}", "~#{@offset.y}", "~#{@offset.z}").freeze
21
+ @corner2 = coords("~#{@offset.x + @length}", "~#{@offset.y + @height}", "~#{@offset.z + @width}").freeze
22
+ @surrond = surrond
23
+ end
24
+ def startup(c)
25
+ c.gamerule(:commandBlockOutput, @output)
26
+ c.fill @corner1.to_s, @corner2.to_s, @surrond.to_s, 'hollow' if @surrond
27
+ end
28
+ def cleanup(c)
29
+ c.setblock "~ ~ ~1 command_block 0 replace {Command:fill ~ ~-1 ~-1 ~ ~ ~ air}"
30
+ c.setblock "~ ~-1 ~1 redstone_block"
31
+ c.kill e('MinecartCommandBlock').selector({r: 1})
32
+ end
33
+ def create_commands(c)
34
+ chain = CommandChain.new self
35
+ tick chain
36
+ commands = chain.commands.map do |command|
37
+ command.to_block
38
+ end.reverse
39
+ command_lines = commands.each_slice(@length - 2).each_with_index.map do |line, z|
40
+ direction = 4 + (z % 2)
41
+ end_block = line[-1]
42
+ end_block.direction = direction - 2
43
+ line[0..-2].map{|command|command.direction = direction}.push end_block
44
+ end.reverse
45
+ command_levels = command_lines.each_slice(@width - 2).map do |level|
46
+ level.last.last.direction = 1 unless level == command_levels.to_a[-1]
47
+ level
48
+ end.reverse
49
+ raise Errors::TooSmall if command_levels.to_a.length > (@height - 2)
50
+ command_levels.each_with_index do |level, y|
51
+ level.each_with_index do |row, z|
52
+ row.each_with_index do |command, x|
53
+ c.setblock coords("~#{@offset.x + x - 1}", "~#{@offset.y + y - 1}", "~#{@offset.z + z - 1}"), command.to_s(:replace)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ def chain
59
+ chain = CommandChain.new self
60
+ startup chain
61
+ setup chain
62
+ create_commands chain
63
+ cleanup chain
64
+ chain
65
+ end
66
+ def to_command
67
+ activator_rail = b('activator_rail').to_falling_sand
68
+ redstone_block = b('redstone_block').to_falling_sand
69
+ activator_rail.passengers.push(*chain.commands.map{|command| command.to_minecart})
70
+ redstone_block.passengers << activator_rail
71
+ redstone_block.summon coords('~', '~1', '~')
72
+ end
73
+ def setup(c)
74
+ puts "Warning: You haven't implimented a setup function."
75
+ end
76
+ def tick(c)
77
+ puts "Warning: You haven't implimented a tick function."
78
+ end
79
+ private
80
+ def b(*args)
81
+ Helpers::Block.new(*args)
82
+ end
83
+ def e(*args)
84
+ Helpers::Entity.new(*args)
85
+ end
86
+ def s(*args)
87
+ Helpers::TargetSelector.new(*args)
88
+ end
89
+ def coords(*args)
90
+ Helpers::Coordinates.new(*args)
91
+ end
92
+ end
93
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_adapter 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ require 'rubygems'
18
+ require 'bundler'
19
+ begin
20
+ Bundler.setup(:default, :development)
21
+ rescue Bundler::BundlerError => e
22
+ $stderr.puts e.message
23
+ $stderr.puts "Run `bundle install` to install missing gems"
24
+ exit e.status_code
25
+ end
26
+ require 'test/unit'
27
+ require 'shoulda'
28
+
29
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
30
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
31
+ require 'diamond-lang'
32
+
33
+ class Test::Unit::TestCase
34
+ end
@@ -0,0 +1,5 @@
1
+ require 'helper'
2
+
3
+ class TestDiamondLang < Test::Unit::TestCase
4
+
5
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: diamond-lang
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben (@penne12_)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: require_all
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: shoulda
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rdoc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.11'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.11'
97
+ description: Making Minecraft 1 Command Creations with ruby. It's as easy as `c.say
98
+ 123`
99
+ email: ben@bensites.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files:
103
+ - LICENSE.txt
104
+ - README.md
105
+ files:
106
+ - ".document"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - VERSION
113
+ - examples/hello_world.rb
114
+ - lib/diamond-lang.rb
115
+ - lib/diamond-lang/command_chain.rb
116
+ - lib/diamond-lang/helpers/block.rb
117
+ - lib/diamond-lang/helpers/command.rb
118
+ - lib/diamond-lang/helpers/command_block.rb
119
+ - lib/diamond-lang/helpers/command_block_minecart.rb
120
+ - lib/diamond-lang/helpers/constants.rb
121
+ - lib/diamond-lang/helpers/coordinate.rb
122
+ - lib/diamond-lang/helpers/coordinates.rb
123
+ - lib/diamond-lang/helpers/entity.rb
124
+ - lib/diamond-lang/helpers/errors/invalid_axis.rb
125
+ - lib/diamond-lang/helpers/errors/invalid_coordinate_value.rb
126
+ - lib/diamond-lang/helpers/errors/relative_cordinate_converted_to_argument.rb
127
+ - lib/diamond-lang/helpers/errors/too_small.rb
128
+ - lib/diamond-lang/helpers/falling_sand.rb
129
+ - lib/diamond-lang/helpers/target_selector.rb
130
+ - lib/diamond-lang/minecraft/commands/say.rb
131
+ - lib/diamond-lang/one_command.rb
132
+ - test/helper.rb
133
+ - test/test_diamond-lang.rb
134
+ homepage: http://bensites.com/diamond-lang/
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.4.5.1
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: A Ruby Framework for creating Minecraft 1 Command Creations.
158
+ test_files: []