java
1public void init(FMLInitializationEvent event){ 2 3 GameRegistry.addRecipe(new ItemStack(Items.diamond), 4 "#", 5 "#", 6 "#", 7 '#', Blocks.dirt 8 );
マインクラフトのレシピ追加するときのソースなんですが、
java
1GameRegistry.addRecipe(new ItemStack(Items.diamond)
この部分、addRecipeメソッドの引数にnewがありますよね。
これは何をしてるんでしょうか。。
引数の中でインスタンスの生成...??
ItemStackクラスを見ると、
下記のようなソースがたくさん載ってました。
public ItemStack(Item p_i1879_1_)
{
this(p_i1879_1_, 1);
}
次はどこをみればいいのかさえわからずです。。
ダイヤモンドを作るレシピを作るために、
どのクラスをそれぞれ使っているのかがわからないです。。
追記
回答いただきありがとうございます(T-T)
追加でお聞きしたい点があります。
...javaってクラスやメソッドだけでは動かなくて、
クラス(設計図)を元に、動いてくれる実態(オブジェクト)が必要と本で読んだのですが、
この場合、「レシピを作る」(設計図)クラスが、GameRegistryクラスで、
その中のaddRecipeメソッドがその機能ですよね。
そして、ItemStackという設計図を元に、
ダイヤモンドのレシピという要素を持ったオブジェクトであるitemが生成され、
そのオブジェクト自体をメソッドに渡しているということでしょうか...?
※単に、レシピっていう要素自体を渡しているということでしょか・・
addRecipeメソッドに渡しているのは、
(①ダイヤモンドのレシピ自体と、②なんか#の連続と、③ブロックである砂)
の3つの引数を渡しているということで、
そのaddRecipeメソッドは、受け取った引数を、今度は、
addShapedRecipeメソッドに渡していて、
java
1public static void addRecipe(ItemStack output, Object... params) 2 { 3 addShapedRecipe(output, params); 4 } 5 6 public static IRecipe addShapedRecipe(ItemStack output, Object... params) 7 { 8 return CraftingManager.getInstance().addRecipe(output, params); 9 }
addShapeRecipeは受け取った引数をさらに
CraftingManagerのgetInstanceメソッドのaddRecipeに渡していますよね。
java
1public class CraftingManager 2{ 3 /** The static instance of this class */ 4 private static final CraftingManager instance = new CraftingManager(); 5 /** A list of all the recipes added */ 6 private List recipes = new ArrayList(); 7 private static final String __OBFID = "CL_00000090"; 8 9 /** 10 * Returns the static instance of this class 11 */ 12 public static final CraftingManager getInstance() 13 { 14 /** The static instance of this class */ 15 return instance; 16 } 17 18 private CraftingManager() 19 { 20 (new RecipesTools()).addRecipes(this); 21 (new RecipesWeapons()).addRecipes(this); 22 (new RecipesIngots()).addRecipes(this); 23 (new RecipesFood()).addRecipes(this); 24 (new RecipesCrafting()).addRecipes(this); 25 (new RecipesArmor()).addRecipes(this); 26 (new RecipesDyes()).addRecipes(this); 27 this.recipes.add(new RecipesArmorDyes()); 28 this.recipes.add(new RecipeBookCloning()); 29 this.recipes.add(new RecipesMapCloning()); 30 this.recipes.add(new RecipesMapExtending()); 31 this.recipes.add(new RecipeFireworks()); 32 this.addRecipe(new ItemStack(Items.paper, 3), new Object[] {"###", '#', Items.reeds}); 33 this.addShapelessRecipe(new ItemStack(Items.book, 1), new Object[] {Items.paper, Items.paper, Items.paper, Items.leather}); 34 ・ 35 ・ 36 ・ 37 省略
つまりaddShapeRecipeがCraftingManagerクラスのメソッドに引数を渡すことで、
レシピの追加ができているということでしょうか。
で、わからないのが、この最後にCraftingManagerクラスのメソッドに渡しているところなんですが、
引数をどこに渡しているのかがわからないんです。
java
1public static IRecipe addShapedRecipe(ItemStack output, Object... params) 2 { 3 return CraftingManager.getInstance().addRecipe(output, params); 4 }
さっきのこのreturnの箇所なんですが、
これがCraftingManagerクラスのどこと関連しているのか知りたいです。
そして、これらの「レシピを生成する」という機能は、
クラス(設計図)だけじゃう動かないよ!って本に書いてあるんですが、
これらを機能させるためのオブジェクトとはどのことなんでしょうか。
長文ですみません。・゚゚・(>_<;)・゚゚・。
そしてなんか悪い質問の仕方だったようで、
本当にごめんなさい。。
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/07 09:37
2018/08/07 09:38
2018/08/07 09:43
2018/08/07 11:21
2018/08/07 11:42 編集
2018/08/07 11:59