提供: Minecraft Modding Wiki
この編集を取り消せます。
下記の差分を確認して、本当に取り消していいか検証してください。よろしければ変更を保存して取り消しを完了してください。
最新版 | 編集中の文章 | ||
6行目: | 6行目: | ||
ブロックやアイテムにGUIを追加する | ブロックやアイテムにGUIを追加する | ||
===ソースコード=== | ===ソースコード=== | ||
− | + | SmpleMod.java | |
<source lang = "java"> | <source lang = "java"> | ||
package mods.sampleMod; | package mods.sampleMod; | ||
32行目: | 32行目: | ||
@EventHandler | @EventHandler | ||
− | public void preInit( | + | public void preInit(FMLPostInitializationEvent event) { |
sampleGuiBlock = new SampleGuiBlock().setBlockTextureName("stone").setBlockName("sampleGuiBlock").setCreativeTab(CreativeTabs.tabBlock); | sampleGuiBlock = new SampleGuiBlock().setBlockTextureName("stone").setBlockName("sampleGuiBlock").setCreativeTab(CreativeTabs.tabBlock); | ||
GameRegistry.registerBlock(sampleGuiBlock, "sample_guiGlock"); | GameRegistry.registerBlock(sampleGuiBlock, "sample_guiGlock"); | ||
121行目: | 121行目: | ||
public class SampleContainer extends Container { | public class SampleContainer extends Container { | ||
//座標でGUIを開くか判定するためのもの。 | //座標でGUIを開くか判定するためのもの。 | ||
− | int xCoord, yCoord, | + | int xCoord, yCoord, zCorrd; |
public SampleContainer(int x, int y, int z) { | public SampleContainer(int x, int y, int z) { | ||
this.xCoord = x; | this.xCoord = x; | ||
this.yCoord = y; | this.yCoord = y; | ||
− | this. | + | this.zCorrd = z; |
} | } | ||
131行目: | 131行目: | ||
public boolean canInteractWith(EntityPlayer player) { | public boolean canInteractWith(EntityPlayer player) { | ||
//もし、ブロックとの位置関係でGUI制御したいなら、こちらを使う | //もし、ブロックとの位置関係でGUI制御したいなら、こちらを使う | ||
− | // return player.getDistanceSq(this.xCoord + 0.5D, this.yCoord + 0.5D, this. | + | // return player.getDistanceSq(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCorrd + 0.5D) <= 64D; |
return true; | return true; | ||
} | } | ||
214行目: | 214行目: | ||
</source> | </source> | ||
アイテムを右クリックした際にGUIを開く。プレイヤーの位置情報を渡しているが、アイテムの場合は無くてもよい。 | アイテムを右クリックした際にGUIを開く。プレイヤーの位置情報を渡しているが、アイテムの場合は無くてもよい。 | ||
− | ==SampleContainerクラス== | + | ===SampleContainerクラス== |
<source lang = "java"> | <source lang = "java"> | ||
public boolean canInteractWith(EntityPlayer player) { | public boolean canInteractWith(EntityPlayer player) { | ||
223行目: | 223行目: | ||
</source> | </source> | ||
GUIを開くかどうかを判定するメソッド。trueで開く。プレイヤーの位置情報や、TileEntityで判定してもよい。 | GUIを開くかどうかを判定するメソッド。trueで開く。プレイヤーの位置情報や、TileEntityで判定してもよい。 | ||
− | ==SampleGuiContainerクラス== | + | ===SampleGuiContainerクラス=== |
<source lang = "java"> | <source lang = "java"> | ||
private static final ResourceLocation TEXTURE = new ResourceLocation("<DomainName>", "textures/gui/gui_texture.png"); | private static final ResourceLocation TEXTURE = new ResourceLocation("<DomainName>", "textures/gui/gui_texture.png"); | ||
245行目: | 245行目: | ||
return false; | return false; | ||
} | } | ||
− | </source> | + | </source>= |
GUIを開いている時にTick処理を続けるかどうか。trueで止める。 | GUIを開いている時にTick処理を続けるかどうか。trueで止める。 |