diamond-lang 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 146ad378461d50b88c212bf338df996e7eeea8e5
4
- data.tar.gz: 2f1ae43f3e504de2db3d3106cd41f2b293fe7025
3
+ metadata.gz: 3075c30a0c08b540e5bfacab36b24805454376ff
4
+ data.tar.gz: df3af1c137c9ecb555391eeb2633caa64d588d05
5
5
  SHA512:
6
- metadata.gz: c2e772bf13e68a58a50c8f51f2caf5baa09204da999e1bd8c114c01f714d394b7a379de160708242634258d56e1d30a07585447b1681ac5396fbdc78b782fb3d
7
- data.tar.gz: 2b12b8f1c1c7b581b3054bce42a63a8f1d6f0acce21da0adcefc9c4879b598b96db3ebce94baee8ad0e967bd43ecc1723a330bb3c44f128ca18084830ad359c5
6
+ metadata.gz: d08ee782327aff9f96a183d80a04f4edb4ddcaa2400b3beddec5f43f11814d146936e6d849a7d8ae4064d35a230eeef3a73a9ddd59217ffc5ef1893137f2e21f
7
+ data.tar.gz: 7bb9541370b490cebfc9a6fba68ea2bb9310e2587db284d120f5c870c07ab0f4587f16ffee309130f309ef524f747501faecfb251047a6efd0fca1737c93e8e6
data/README.md CHANGED
@@ -153,11 +153,10 @@ DiamondLang::Helpers::Coordinate(:x, 6) + 5 #=> 11
153
153
  ~~~
154
154
 
155
155
  ##Conditions:
156
- *Coming soon!*
157
156
  To make commands run on success, attach a block:
158
157
 
159
158
  ~~~rb
160
- c.test_for s(a: {r: 10}) do |c| # conditionals coming soon!
159
+ c.test_for s(a: {r: 10}) do |c|
161
160
  c.tell s(a: {r: 10}), 'hello'
162
161
  end
163
162
  #=> Command Block: test_for @a[r=10]
@@ -169,7 +168,7 @@ Diamond Lang is just a Ruby framework, so you can have awesome things, like vari
169
168
 
170
169
  ~~~rb
171
170
  close_players = s(a: {r: 10})
172
- c.test_for close_players do |c| # conditionals coming soon!
171
+ c.test_for close_players do |c|
173
172
  c.tell close_players, 'hello'
174
173
  end #=> @a[r=10]
175
174
  ~~~
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.2.0
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: diamond-lang 1.1.1 ruby lib
5
+ # stub: diamond-lang 1.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "diamond-lang"
9
- s.version = "1.1.1"
9
+ s.version = "1.2.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Ben (@penne12_)"]
14
- s.date = "2015-12-29"
14
+ s.date = "2016-01-01"
15
15
  s.description = "Making Minecraft 1 Command Creations with ruby. It's as easy as `c.say 123`"
16
16
  s.email = "ben@bensites.com"
17
17
  s.extra_rdoc_files = [
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  "VERSION",
29
29
  "diamond-lang.gemspec",
30
30
  "examples/conveyor.rb",
31
+ "examples/custom_crafting.rb",
31
32
  "examples/hello_world.rb",
32
33
  "lib/diamond-lang.rb",
33
34
  "lib/diamond-lang/command_chain.rb",
@@ -38,6 +39,7 @@ Gem::Specification.new do |s|
38
39
  "lib/diamond-lang/helpers/constants.rb",
39
40
  "lib/diamond-lang/helpers/coordinate.rb",
40
41
  "lib/diamond-lang/helpers/coordinates.rb",
42
+ "lib/diamond-lang/helpers/custom_crafting.rb",
41
43
  "lib/diamond-lang/helpers/entity.rb",
42
44
  "lib/diamond-lang/helpers/errors/invalid_axis.rb",
43
45
  "lib/diamond-lang/helpers/errors/invalid_coordinate_value.rb",
@@ -0,0 +1,37 @@
1
+ require 'diamond-lang'
2
+
3
+ class CustomCrafting < DiamondLang::OneCommand
4
+ def setup(c)
5
+ c.title s(:a), :subtitle, {"text " => "command by Ben from bensites.com"}.to_json
6
+ c.title s(:a), :title, {"text " => "Custom"}.to_json
7
+ add_crafting([
8
+ {
9
+ pattern: " s"+
10
+ " p "+
11
+ "p ",
12
+ result: " "+
13
+ " n "+
14
+ " ",
15
+ n: "id:\"minecraft:name_tag\",Count:1b",
16
+ s: "id:\"minecraft:string\",Count:1b",
17
+ p: "id:\"minecraft:paper\",Count:1b"
18
+ },
19
+ {
20
+ pattern: "bbb"+
21
+ "bpb"+
22
+ "bbb",
23
+ result: " "+
24
+ " s ",
25
+ b: "id:\"minecraft:iron_bars\",Count:1b",
26
+ p: "id:\"minecraft:porkchop\",Count:64b",
27
+ s: "id:\"minecraft:mob_spawner\",Count:1b"
28
+ }
29
+ ])
30
+ end
31
+
32
+ def tick(c)
33
+
34
+ end
35
+ end
36
+
37
+ CustomCrafting.create
@@ -1,4 +1,3 @@
1
- require 'byebug'
2
1
  require 'json'
3
2
  require 'require_all'
4
3
  require_rel 'diamond-lang'
@@ -29,7 +29,7 @@ module DiamondLang
29
29
  if conditional? && !val
30
30
  @data_value -= 8
31
31
  elsif !@conditional && val
32
- @date_value += 8
32
+ @data_value += 8
33
33
  end
34
34
  end
35
35
  def conditional?(data_value=@data_value)
@@ -0,0 +1,176 @@
1
+ module DiamondLang
2
+ module Helpers
3
+ # Please Note:
4
+ #
5
+ # This class uses the scoreboard objectives:
6
+ # - ask_table
7
+ # - craft_table
8
+ # - on_table
9
+ # - ct_has_block
10
+ # - craft_success
11
+ # And ArmorStands named
12
+ # - CraftingTable
13
+ # - CraftingCreator
14
+ #
15
+ # Including those in your command will break this, and other creations that use this.
16
+ #
17
+ # Do not change the scoreboard objectives ask_table, or on_table.
18
+ # Also, do not change the ArmorStand name "CraftingTable".
19
+ # If you do, you'll risk breaking other creations in the same world.
20
+ #
21
+ #
22
+ # It also creates about 21 commands + 5 for every recipe.
23
+ # On default settings, that's
24
+ # - 1 level
25
+ # - 1 row per recipe
26
+ # - 1 block
27
+ #
28
+ # 2 should be able to be in the same world without any conflict.
29
+ class CustomCrafting
30
+ def initialize(c, recipes)
31
+ @crafting_recipes = recipes
32
+ c.scoreboard :objectives, :add, :ask_table, :dummy, "Asked to Create A Table"
33
+ c.scoreboard :objectives, :add, :craft_table, :trigger, "Creating a Crafting Table"
34
+ c.scoreboard :objectives, :add, :on_table, :trigger, "Players on a crafting table"
35
+ c.scoreboard :objectives, :add, :ct_has_block, :dummy, "Crafting Table with block?"
36
+ c.scoreboard :objectives, :add, :craft_success, :dummy, "Crafting Success:"
37
+ end
38
+ def tick(c)
39
+ #Blocks
40
+ crafting_table = b('crafting_table')
41
+ stone = b('stone')
42
+
43
+ #Enable the on_table trigger
44
+ c.scoreboard :players, :enable, s(:a), :on_table
45
+
46
+ #Mark all players on a crafting table pattern
47
+ c.execute s(:a), relative, :detect, coords('~', '~-1', '~'), crafting_table,
48
+ :execute, sp, relative, :detect, coords('~-1', '~-1', '~'), crafting_table,
49
+ :execute, sp, relative, :detect, coords('~1', '~-1', '~'), crafting_table,
50
+ :execute, sp, relative, :detect, coords('~1', '~-1', '~1'), stone,
51
+ :execute, sp, relative, :detect, coords('~1', '~-1', '~-1'), stone,
52
+ :execute, sp, relative, :detect, coords('~-1', '~-1', '~-1'), stone,
53
+ :execute, sp, relative, :detect, coords('~-1', '~-1', '~-1'), stone,
54
+ :execute, sp, relative, :detect, coords('~', '~-1', '~1'), crafting_table,
55
+ :execute, sp, relative, :detect, coords('~', '~-1', '~-1'), crafting_table,
56
+ :trigger, :on_table, :set, 1
57
+
58
+ #Set all players who are not on a crafting table pattern to ask again once they are
59
+ c.scoreboard :players, :set, s(:a, {score_on_table: 0}), :ask_table, 0
60
+
61
+ #Get all players who have not been asked yet and are on a crafting table pattern if they want to build a crafting table
62
+ ask_players = s(:a, {score_on_table_min: 1, score_ask_table: 0})
63
+ c.scoreboard :players, :enable, ask_players, :craft_table
64
+ c.tellraw ask_players, {text: "Build a ", extra: [
65
+ {
66
+ text: "Crafting Table",
67
+ color: "yellow",
68
+ underlined: true,
69
+ clickEvent: {
70
+ action: "run_command",
71
+ value: "/trigger craft_table set 1"
72
+ }
73
+ },
74
+ {
75
+ text: "?"
76
+ }
77
+ ]}.to_json
78
+
79
+ #Mark all players who have been asked
80
+ c.scoreboard :players, :set, ask_players, :ask_table, 1
81
+
82
+ #Get a player that is crafting a table
83
+ player = s(:a, {score_craft_table_min: 1})
84
+
85
+ #Tell the player that it is now building the crafting table
86
+ c.tellraw player, {text: "Now building a ", extra: [
87
+ {text: "Crafting Table", color: "yellow"},
88
+ {text: ". Please hold still for a moment..."}
89
+ ]}.to_json
90
+
91
+ player << {c: 1}
92
+
93
+ #Create the armorstand
94
+ c.testfor player do |c|
95
+ c.summon 'ArmorStand', relative, "{CustomName:CraftingCreator,Invisible:true}"
96
+ end
97
+
98
+ #Teleport the armorstand one block below the player
99
+ armorstand = s(:e, {name: "CraftingCreator", type: 'ArmorStand'})
100
+ c.tp armorstand, player
101
+ c.tp armorstand, "~ ~-1 ~"
102
+
103
+ #Remove pattern
104
+ c.execute armorstand, relative, :fill, "~-1 ~ ~-1 ~1 ~ ~1", b('air'), 'replace'
105
+
106
+ #Create blocks for crafting table
107
+ c.execute armorstand, relative, :setblock, relative, b('dropper'), :replace, "{CustomName:Crafting Table}"
108
+ c.execute armorstand, relative, :summon, 'ItemFrame', '~ ~ ~-1', "{Facing:2,Item:{id:\"crafting_table\"}}"
109
+ c.execute armorstand, relative, :summon, 'ItemFrame', '~ ~ ~1', "{Facing:4,Item:{id:\"crafting_table\"}}"
110
+
111
+ #Reset scores for creating crafting table
112
+ c.scoreboard :players, :reset, player, :craft_table
113
+ c.scoreboard :players, :set, s(:a), :on_table, 0
114
+
115
+ #Find Stale Crafting Tables
116
+ crafting_tables = s(:e, {name: "CraftingTable", type: "ArmorStand"})
117
+ c.scoreboard :players, :set, crafting_tables, :ct_has_block, 0
118
+ c.execute crafting_tables, relative, :detect, relative, b("dropper"),
119
+ :scoreboard, :players, :set, s_self, :ct_has_block, 1
120
+
121
+ #Kill Stale Crafting Tables
122
+ c.kill s(:e, {score_ct_has_block: 0})
123
+ @crafting_recipes.map do |recipe|
124
+ blockItems, resultItems = [recipe[:pattern], recipe[:result]].map do |str|
125
+ str.split('').each_with_index.map do |letter, i|
126
+ (item = recipe[letter.to_sym]) ? "{" + item + ",Slot:#{i}b}" : nil
127
+ end.compact.join(",")
128
+ end
129
+ {
130
+ block: "{" +
131
+ "Items:[#{blockItems}]," +
132
+ "CustomName:\"Crafting Table\"" +
133
+ "}",
134
+ result: "{" +
135
+ "Items:[#{resultItems}],"+
136
+ "CustomName:\"Crafting Table\""+
137
+ "}"
138
+ }
139
+ end.each do |recipe|
140
+ c.scoreboard :players, :set, crafting_tables, :craft_success, 0
141
+ c.stats :entity, crafting_tables, :set, :SuccessCount, s_self, :craft_success
142
+
143
+ c.execute crafting_tables, relative, :testforblock, relative, 'dropper', 0, recipe[:block]
144
+
145
+ success_tables = s(:e, {name: "CraftingTable", type: "ArmorStand", score_craft_success_min: 1})
146
+
147
+ c.execute success_tables, relative, :blockdata, relative, recipe[:result]
148
+
149
+ c.stats :entity, crafting_tables, :clear, :SuccessCount
150
+ end
151
+ c.entitydata armorstand, "{CustomName:CraftingTable}"
152
+ end
153
+ def b(*args)
154
+ Helpers::Block.new(*args)
155
+ end
156
+ def e(*args)
157
+ Helpers::Entity.new(*args)
158
+ end
159
+ def s(*args)
160
+ Helpers::TargetSelector.new(*args)
161
+ end
162
+ def sp
163
+ s :p
164
+ end
165
+ def s_self
166
+ s :e, {r: 0, c: 1}
167
+ end
168
+ def coords(*args)
169
+ Helpers::Coordinates.new(*args)
170
+ end
171
+ def relative
172
+ coords('~', '~', '~')
173
+ end
174
+ end
175
+ end
176
+ end
@@ -9,10 +9,10 @@ module DiamondLang
9
9
  @arguments = @arguments.merge arguments
10
10
  end
11
11
  def to_s
12
- if @arguments
13
- @variable + "[" + mc_args + "]"
14
- else
12
+ if @arguments.empty?
15
13
  @variable
14
+ else
15
+ @variable + "[" + mc_args + "]"
16
16
  end
17
17
  end
18
18
  alias inspect to_s
@@ -17,6 +17,10 @@ module DiamondLang
17
17
  @corner1 = coords("~#{@offset.x}", "~#{@offset.y}", "~#{@offset.z}").freeze
18
18
  @corner2 = coords("~#{@offset.x._value + @length}", "~#{@offset.y._value + @height}", "~#{@offset.z._value + @width}").freeze
19
19
  @surrond = surrond
20
+
21
+ @setup_commands = []
22
+ @tick_commands = []
23
+ @custom_crafting = nil
20
24
  end
21
25
  def startup(c)
22
26
  c.gamerule(:commandBlockOutput, @output)
@@ -29,9 +33,22 @@ module DiamondLang
29
33
  end
30
34
  def create_commands(c)
31
35
  chain = CommandChain.new self
36
+ chain.commands.push *@tick_commands
37
+ if @custom_crafting
38
+ @custom_crafting.tick chain
39
+ end
32
40
  tick chain
33
- commands = chain.commands.map do |command|
34
- command.to_block
41
+ commands = []
42
+ chain.commands.each do |command|
43
+ if command.chain
44
+ command.chain.each do |con_command|
45
+ con_command = con_command.to_block
46
+ con_command.conditional = true
47
+ commands.push command.to_block, con_command
48
+ end
49
+ else
50
+ commands.push command.to_block
51
+ end
35
52
  end
36
53
  command_lines = commands.each_slice(@length - 1).each_with_index.map do |line, z|
37
54
  direction = z.even? ? 5 : 4
@@ -71,6 +88,7 @@ module DiamondLang
71
88
  chain = CommandChain.new self
72
89
  startup chain
73
90
  setup chain
91
+ chain.commands.push *@setup_commands
74
92
  create_commands chain
75
93
  cleanup chain
76
94
  chain
@@ -130,5 +148,10 @@ module DiamondLang
130
148
  black: 15
131
149
  }.freeze[color]
132
150
  end
151
+ def add_crafting(recipes)
152
+ chain = CommandChain.new self
153
+ @custom_crafting = Helpers::CustomCrafting.new(chain, recipes)
154
+ @setup_commands.push *chain.commands
155
+ end
133
156
  end
134
157
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diamond-lang
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben (@penne12_)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-29 00:00:00.000000000 Z
11
+ date: 2016-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: require_all
@@ -154,6 +154,7 @@ files:
154
154
  - VERSION
155
155
  - diamond-lang.gemspec
156
156
  - examples/conveyor.rb
157
+ - examples/custom_crafting.rb
157
158
  - examples/hello_world.rb
158
159
  - lib/diamond-lang.rb
159
160
  - lib/diamond-lang/command_chain.rb
@@ -164,6 +165,7 @@ files:
164
165
  - lib/diamond-lang/helpers/constants.rb
165
166
  - lib/diamond-lang/helpers/coordinate.rb
166
167
  - lib/diamond-lang/helpers/coordinates.rb
168
+ - lib/diamond-lang/helpers/custom_crafting.rb
167
169
  - lib/diamond-lang/helpers/entity.rb
168
170
  - lib/diamond-lang/helpers/errors/invalid_axis.rb
169
171
  - lib/diamond-lang/helpers/errors/invalid_coordinate_value.rb