質問編集履歴

1

追加しました

2018/08/07 09:35

投稿

feeling_jumper
feeling_jumper

スコア19

test CHANGED
File without changes
test CHANGED
@@ -65,3 +65,209 @@
65
65
  ダイヤモンドを作るレシピを作るために、
66
66
 
67
67
  どのクラスをそれぞれ使っているのかがわからないです。。
68
+
69
+
70
+
71
+ ---
72
+
73
+
74
+
75
+ 追記
76
+
77
+
78
+
79
+ 回答いただきありがとうございます(T-T)
80
+
81
+ 追加でお聞きしたい点があります。
82
+
83
+
84
+
85
+ ...javaってクラスやメソッドだけでは動かなくて、
86
+
87
+ クラス(設計図)を元に、動いてくれる実態(オブジェクト)が必要と本で読んだのですが、
88
+
89
+
90
+
91
+ この場合、「レシピを作る」(設計図)クラスが、GameRegistryクラスで、
92
+
93
+ その中のaddRecipeメソッドがその機能ですよね。
94
+
95
+
96
+
97
+ そして、ItemStackという設計図を元に、
98
+
99
+ ダイヤモンドのレシピという要素を持ったオブジェクトであるitemが生成され、
100
+
101
+ そのオブジェクト自体をメソッドに渡しているということでしょうか...?
102
+
103
+ ※単に、レシピっていう要素自体を渡しているということでしょか・・
104
+
105
+
106
+
107
+ addRecipeメソッドに渡しているのは、
108
+
109
+ (①ダイヤモンドのレシピ自体と、②なんか#の連続と、③ブロックである砂)
110
+
111
+ の3つの引数を渡しているということで、
112
+
113
+
114
+
115
+ そのaddRecipeメソッドは、受け取った引数を、今度は、
116
+
117
+ addShapedRecipeメソッドに渡していて、
118
+
119
+
120
+
121
+ ```java
122
+
123
+ public static void addRecipe(ItemStack output, Object... params)
124
+
125
+ {
126
+
127
+ addShapedRecipe(output, params);
128
+
129
+ }
130
+
131
+
132
+
133
+ public static IRecipe addShapedRecipe(ItemStack output, Object... params)
134
+
135
+ {
136
+
137
+ return CraftingManager.getInstance().addRecipe(output, params);
138
+
139
+ }
140
+
141
+ ```
142
+
143
+
144
+
145
+ addShapeRecipeは受け取った引数をさらに
146
+
147
+ CraftingManagerのgetInstanceメソッドのaddRecipeに渡していますよね。
148
+
149
+
150
+
151
+ ```java
152
+
153
+ public class CraftingManager
154
+
155
+ {
156
+
157
+ /** The static instance of this class */
158
+
159
+ private static final CraftingManager instance = new CraftingManager();
160
+
161
+ /** A list of all the recipes added */
162
+
163
+ private List recipes = new ArrayList();
164
+
165
+ private static final String __OBFID = "CL_00000090";
166
+
167
+
168
+
169
+ /**
170
+
171
+ * Returns the static instance of this class
172
+
173
+ */
174
+
175
+ public static final CraftingManager getInstance()
176
+
177
+ {
178
+
179
+ /** The static instance of this class */
180
+
181
+ return instance;
182
+
183
+ }
184
+
185
+
186
+
187
+ private CraftingManager()
188
+
189
+ {
190
+
191
+ (new RecipesTools()).addRecipes(this);
192
+
193
+ (new RecipesWeapons()).addRecipes(this);
194
+
195
+ (new RecipesIngots()).addRecipes(this);
196
+
197
+ (new RecipesFood()).addRecipes(this);
198
+
199
+ (new RecipesCrafting()).addRecipes(this);
200
+
201
+ (new RecipesArmor()).addRecipes(this);
202
+
203
+ (new RecipesDyes()).addRecipes(this);
204
+
205
+ this.recipes.add(new RecipesArmorDyes());
206
+
207
+ this.recipes.add(new RecipeBookCloning());
208
+
209
+ this.recipes.add(new RecipesMapCloning());
210
+
211
+ this.recipes.add(new RecipesMapExtending());
212
+
213
+ this.recipes.add(new RecipeFireworks());
214
+
215
+ this.addRecipe(new ItemStack(Items.paper, 3), new Object[] {"###", '#', Items.reeds});
216
+
217
+ this.addShapelessRecipe(new ItemStack(Items.book, 1), new Object[] {Items.paper, Items.paper, Items.paper, Items.leather});
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+ 省略
226
+
227
+ ```
228
+
229
+
230
+
231
+ つまりaddShapeRecipeがCraftingManagerクラスのメソッドに引数を渡すことで、
232
+
233
+ レシピの追加ができているということでしょうか。
234
+
235
+
236
+
237
+ で、わからないのが、この最後にCraftingManagerクラスのメソッドに渡しているところなんですが、
238
+
239
+ 引数をどこに渡しているのかがわからないんです。
240
+
241
+
242
+
243
+ ```java
244
+
245
+ public static IRecipe addShapedRecipe(ItemStack output, Object... params)
246
+
247
+ {
248
+
249
+ return CraftingManager.getInstance().addRecipe(output, params);
250
+
251
+ }
252
+
253
+ ```
254
+
255
+ さっきのこのreturnの箇所なんですが、
256
+
257
+ これがCraftingManagerクラスのどこと関連しているのか知りたいです。
258
+
259
+
260
+
261
+ そして、これらの「レシピを生成する」という機能は、
262
+
263
+ クラス(設計図)だけじゃう動かないよ!って本に書いてあるんですが、
264
+
265
+ これらを機能させるためのオブジェクトとはどのことなんでしょうか。
266
+
267
+
268
+
269
+ 長文ですみません。・゚゚・(>_<;)・゚゚・。
270
+
271
+ そしてなんか悪い質問の仕方だったようで、
272
+
273
+ 本当にごめんなさい。。