提供: Minecraft Modding Wiki
移動先: 案内検索

警告: ログインしていません。編集を行うと、あなたの IP アドレスが公開されます。ログインまたはアカウントを作成すれば、あなたの編集はその利用者名とともに表示されるほか、その他の利点もあります。

この編集を取り消せます。 下記の差分を確認して、本当に取り消していいか検証してください。よろしければ変更を保存して取り消しを完了してください。
最新版 編集中の文章
1行目: 1行目:
 
このページは[http://www.minecraftforge.net/wiki/ Minecraft Forge Wiki]の[http://www.minecraftforge.net/wiki/How_to_use_NBT_Tag_Compound How to use NBT Tag Compound]の訳です。
 
このページは[http://www.minecraftforge.net/wiki/ Minecraft Forge Wiki]の[http://www.minecraftforge.net/wiki/How_to_use_NBT_Tag_Compound How to use NBT Tag Compound]の訳です。
 +
翻訳はプログラミングやModdingに疎い人間がしています。訳語に不自然な点があれば訂正してください。
  
 
=NBT Tag Compoundの使い方=
 
=NBT Tag Compoundの使い方=
  
 
==最終的な目標==
 
==最終的な目標==
 
+
最後にブロックに右クリックをしたプレイヤーを記録する "last 5 visitors" Blockを作成します
最後にブロックを右クリックした5人のプレイヤーを記録する "last 5 visitors"ブロックを作成します
+
*前提となる知識
 
+
Basic blocks
==前提となる知識==
 
 
 
[[Basic blocks]]
 
  
 
==NBTとは?==
 
==NBTとは?==
  
NBTとは、Minecraftのマップ保存の為にNotchが作成したフォーマットです。ノードを基にしたファイルで、regionファイル、player.datファイル、level.datファイルに使われています。
+
NBTとは、Minecraftのマップ保存の為にNotchが作成したフォーマットです。ノードをベースにしたファイル{node-based file}で、region files、player.dat files、level.dat filesに使われています。
 
 
バイナリだということを除けば、NBTの構造はとてもXMLに似ていると考えることができます。
 
  
 +
NBTの構造は、バイナリを除いて、XMLのようなビットと考えることができます。<br>
 
どのNBTファイルも必ず"Tag_Compound"という種類のルートタグから始まっていて、それがこのチュートリアルの名前になっています。1つのTag_Compoundは他のノードをその中に保持することができます。そのルートタグは通常名前を持ちません。
 
どのNBTファイルも必ず"Tag_Compound"という種類のルートタグから始まっていて、それがこのチュートリアルの名前になっています。1つのTag_Compoundは他のノードをその中に保持することができます。そのルートタグは通常名前を持ちません。
  
 
==NBTを使う理由==
 
==NBTを使う理由==
  
NBTはブロックやアイテムのデータ/メタデータに保存出来ないものを保存するのにとても優れています。例えば、チェストの全アイテムの情報は4ビットのメタデータには保存出来ません。でも、NBTなら実質無限なのです。ただ、HDDの容量が実に増えているとは言え、大量に自然に現れるブロックにNBTを使用してはいけません。
+
NBT is very good if you want to store data that cannot be stored in data/metadata of the block/item. For example, you cant save all the item information from a chest in a 4 bit metadata, so you use NBT, which is practically infinite big. Size of block on the hard drive does increase a lot, though, so dont use NBT in blocks appearing naturally in big quantities.
 
+
NBT may also be useful in items. For example, the book uses NBT to save the author and contents of itself.
また、NBTはアイテムにも便利です。例えば、本は作者と内容を保存するためにNBTを使用しています。
+
What is NBT used for in Minecraft?
 
 
===MinecraftのどこにNBTが使われているでしょう?===
 
 
 
*看板
 
*本
 
*インベントリを持つ全てのブロック(かまど、チェスト、などなど)
 
 
 
===タグの種類===
 
 
 
NBTには12種類ものタグがあり、様々なデータが格納可能です:
 
{|
 
|'''ID'''
 
|'''名前'''
 
|'''解説'''
 
|-
 
|0
 
|TAG_End
 
|Compound Tagの終わり。通常見ることはない。
 
|-
 
|1
 
|TAG_Byte
 
|1バイトのデータを含むタグ
 
|-
 
|2
 
|TAG_Short
 
|1つのshort(数値)を含むタグ
 
|-
 
|3
 
|TAG_Int
 
|1つのintegerを含むタグ
 
|-
 
|4
 
|TAG_Long
 
|1つのlongを含むタグ
 
|-
 
|5
 
|TAG_Float
 
|1つのfloatを含むタグ
 
|-
 
|6
 
|TAG_Double
 
|1つのdoubleを含むタグ
 
|-
 
|7
 
|TAG_Byte_Array
 
|byteの配列を含むタグ
 
|-
 
|8
 
|TAG_String
 
|文字列を含むタグ
 
|-
 
|9
 
|TAG_List
 
|同じ種類の無名タグのリスト
 
|-
 
|10
 
|TAG_Compound
 
|名前付きタグのリスト。それぞれのNBTファイルの起点。他のCompoundを含むことが出来る。
 
|-
 
|11
 
|TAG_Int_Array
 
|integerの配列
 
|-
 
|}
 
 
 
''MinecraftCoalitionのNBTに関する情報はこのページの「参照」以下より参照してください。''
 
  
===ブロックのクラスを書く===
+
Signs
 +
Books
 +
All blocks with an inventory(Furnace, Chest, etc...)
 +
Types of tags
  
もし作っているのがアイテムなら、ItemStackからCompound Tagを取得出来ます。それについてのチュートリアルを作成する必要があるでしょう。でも今はブロックで忙しいのです。
+
There are 12 different types of tags, capable of storing different data:
 +
ID Name Description
 +
0 TAG_End End of a compound tag. Normally never seen.
 +
1 TAG_Byte A tag containing 1 byte of data.
 +
2 TAG_Short A tag containing 1 short(Number value)
 +
3 TAG_Int A tag containing 1 integer
 +
4 TAG_Long A tag containing 1 long
 +
5 TAG_Float A tag containing 1 float
 +
6 TAG_Double A tag containing 1 double
 +
7 TAG_Byte_Array A tag containing an array of bytes
 +
8 TAG_String A tag containing a string
 +
9 TAG_List A list of nameless tags of the same type.
 +
10 TAG_Compound A list of named tag. The start of each NBT file. Can contain other compounds.
 +
11 TAG_Int_Array An array of integers
 +
Information taken from the MinecraftCoalition page on NBT. Please see the bottom of the page under "read more".
  
NBTの値を保存するためにはTileEntityというものが必要です。TileEntityは基本的にブロックと繋がったエンティティで、ブロックの情報を保存するために使われます。
+
Writing the block class
  
最初に、コンストラクタを作ります。このクラスはBlockContainerを継承することに注意してください。
+
If it was an item we was making, you can get the tag compound from the ItemStack the item resolves in. I might make another tutorial about that. But because we are working with a block, we need to use something called a TileEntity to save NBT values. A TileEntity is basically a entity connected to a block, used to store stuff for the block.
 +
First, we make the constructor. Please note that the class extends BlockContainer.
  
<source lang="java">
 
 
public BlockVisitor(int id) {
 
public BlockVisitor(int id) {
 
         super(id, 35, Material.circuits);
 
         super(id, 35, Material.circuits);
 
         // TODO Auto-generated constructor stub
 
         // TODO Auto-generated constructor stub
 
}
 
}
</source>
+
I won't go through this in detail, because you should allready know this stuff.
これについては説明する必要は無いでしょう。
+
Next, the method used for detecting right clicks.
 
 
次は、右クリックを検知するメソッドです。
 
<source lang="java">
 
 
public boolean onBlockActivated(World world, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
 
public boolean onBlockActivated(World world, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
 
{
 
{
118行目: 63行目:
 
         return true;
 
         return true;
 
}
 
}
</source>
+
Lets go through the content line for line...
 
 
行ごとに見て行きましょう。
 
<source lang="java">
 
 
if(!world.isRemote)
 
if(!world.isRemote)
</source>
+
This line checks if it is the server or client calling this. isRemote is true if it is the client, because after Minecraft 1.2.5, single player is run on a local server. Therefore, this is a easy way of detecting server/client.
この行は、メソッドを呼び出しているのがサーバーかクライアントかを確認します。isRemoteはクライアントではtrueを返します。これは、1.2.5以降ではシングルでもローカルサーバー上で実行されているためです。つまり、これはサーバー/クライアントを検知する簡単な方法なのです。
 
 
 
<source lang="java">
 
 
TileEntityVisitor t = (TileEntityVisitor) world.getBlockTileEntity(par2, par3, par4);
 
TileEntityVisitor t = (TileEntityVisitor) world.getBlockTileEntity(par2, par3, par4);
</source>
+
This line gives us the variable t, by getting a tile entity from the world with the getBlockTileEntity method. par2, 3, and 4 are x, y, and z coordinates. Notice how we cast to a TileEntityVisitor.
この行では変数tにgetBlockTileEntityメソッドを用いてワールドからTileEntityを取得します。par2、3、4はx、y、z座標を表します。
 
TileEntityVisitorにキャストしていることに注意してください。
 
 
 
<source lang="java">
 
 
t.processActivate(par5EntityPlayer, world);
 
t.processActivate(par5EntityPlayer, world);
</source>
+
There is a method i made in our tileEntity called processActivate, that we use to do all the stuff in registering, and printing. The arguments are the player, and the world.
これは、登録と表示のためにTileEntityに設けた、processActivateというメソッドを呼び出しています。引数はプレイヤーとワールドです。
+
Now we need to add a method to the file that tells Minecraft that we are using a tile entity:
 
 
また、MinecraftにTileEntityを使うことを知らせるためにメソッドを追加する必要があります:
 
<source lang="java">
 
 
public boolean hasTileEntity(int metadata)
 
public boolean hasTileEntity(int metadata)
 
{
 
{
 
     return true;
 
     return true;
 
}
 
}
</source>
+
The last method in the block file is the createNewTileEntity() method. It is quite simple, it just returns a new instance of a TileEntityVisitor:
ブロックのファイルの最後のメソッドはcreateNewTileEntity()です。これは非常に単純で、TileEntityVisitorの新しいインスタンスを返すのみとなっています:
 
<source lang="java">
 
 
public TileEntity createNewTileEntity(World par1World)
 
public TileEntity createNewTileEntity(World par1World)
 
{
 
{
157行目: 87行目:
 
     }
 
     }
 
}
 
}
</source>
+
We are now done with the block file. Lets move on to the tile entity file.
これでブロックのファイルについては終わりました。TileEntityに移りましょう。
 
  
===TileEntityを作る===
+
Making the TileEntity
  
TileEntityはコンストラクタを必要としません。実際、最初にするのは訪問者を保持する変数の定義です:
+
The TileEntity does not need a constructor. In fact, the first thing we do is to declare the variables containing the visitors:
<source lang="java">
 
 
String visitor1="none";
 
String visitor1="none";
 
String visitor2="none";
 
String visitor2="none";
169行目: 97行目:
 
String visitor4="none";
 
String visitor4="none";
 
String visitor5="none";
 
String visitor5="none";
</source>
+
I'm not using an array. Sue me.
配列は使いません。何か問題でも?
+
The next thing we are going to do is to write the method that loads the information from the NBT tag compound:
 
 
次はNBT Tag Compoundから情報を読み込むメソッドを書きます:
 
<source lang="java">
 
 
@Override
 
@Override
 
public void readFromNBT(NBTTagCompound nbt)
 
public void readFromNBT(NBTTagCompound nbt)
184行目: 109行目:
 
     this.visitor5 = nbt.getString("visitor5");
 
     this.visitor5 = nbt.getString("visitor5");
 
}
 
}
</source>
+
As you can se, we get a NBTTagComponund to use for reading. The rest of the code is quite self-explaining. On a note, remember to run super.readFromNBT(TagCompound); Because a lot of information is actually saved and loaded my the tileentity itself.
お分かりの通り、読み込みのためにNBTTagComponundを使います。コードについては自明です。注意として、super.readFromNBT(TagCompound);の実行を忘れないでください。幾つもの情報をTileEntity自身が保存し、読み込んでいるからです。
+
The next method saves to NBT:
 
 
次のメソッドはNBTへの保存です:
 
<source lang="java">
 
 
@Override
 
@Override
 
public void writeToNBT(NBTTagCompound nbt)
 
public void writeToNBT(NBTTagCompound nbt)
199行目: 121行目:
 
     nbt.setString("visitor5", visitor5);
 
     nbt.setString("visitor5", visitor5);
 
}
 
}
</source>
+
This code is also very self-explanatory.
このコードもまた自明です。
+
The last method to add is the one called in the block.
 
 
最後のコードはブロックの方で呼び出されていたメソッドです。
 
<source lang="java">
 
 
public void processActivate(EntityPlayer par5EntityPlayer, World world) {
 
public void processActivate(EntityPlayer par5EntityPlayer, World world) {
 
         if(!visitor1.equals(par5EntityPlayer.getEntityName()))
 
         if(!visitor1.equals(par5EntityPlayer.getEntityName()))
217行目: 136行目:
 
         world.notifyBlockChange(xCoord, yCoord, zCoord, 2);
 
         world.notifyBlockChange(xCoord, yCoord, zCoord, 2);
 
}
 
}
</source>
+
This might require some explanation:
 
 
これには幾らかの説明が必要でしょう:
 
<source lang="java">
 
 
if(!visitor1.equals(par5EntityPlayer.getEntityName()))
 
if(!visitor1.equals(par5EntityPlayer.getEntityName()))
</source>
+
This makes sure you cant register twice in a row in the guest list.
これは、同じ訪問者を2度登録させないためです。
 
 
 
<source lang="java">
 
 
visitor5=visitor4;
 
visitor5=visitor4;
 
visitor4=visitor3;
 
visitor4=visitor3;
231行目: 144行目:
 
visitor2=visitor1;
 
visitor2=visitor1;
 
visitor1=par5EntityPlayer.getEntityName();
 
visitor1=par5EntityPlayer.getEntityName();
</source>
+
This part shifts the guest list.
これは訪問者一覧を入れ替えます。
 
 
 
<source lang="java">
 
 
world.notifyBlockChange(xCoord, yCoord, zCoord, 2);
 
world.notifyBlockChange(xCoord, yCoord, zCoord, 2);
</source>
+
To be safe. This method tells the world to update neighbour blocks. Please note that i also print the visitors to the chat.
安全のためです。このメソッドはワールドに周囲のブロックを更新することを伝えます。チャットに訪問者を表示していることにも注意してください。
 
  
===全てのコード===
+
All the code
  
VisitorBlock.java(メインのコード)
+
VisitorBlock.java(Main code file)
<source lang="java">
 
 
package com.generic.tutorial.nbt.block;
 
package com.generic.tutorial.nbt.block;
  
258行目: 166行目:
 
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
 
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
 
public class VisitorBlock {
 
public class VisitorBlock {
@Instance("VisitorBlock")
+
        @Instance("VisitorBlock")
VisitorBlock instance;
+
        VisitorBlock instance;
BlockVisitor visitor;
+
        BlockVisitor visitor;
int blockID=200;
+
        int blockID=200;
@PreInit
+
        @PreInit
public void preInit(FMLPreInitializationEvent event)
+
        public void preInit(FMLPreInitializationEvent event)
{
+
        {
+
               
}
+
        }
@Init
+
        @Init
public void load(FMLInitializationEvent event) {
+
        public void load(FMLInitializationEvent event) {
visitor = new BlockVisitor(blockID);
+
                visitor = new BlockVisitor(blockID);
GameRegistry.registerBlock(visitor);
+
                GameRegistry.registerBlock(visitor);
GameRegistry.registerTileEntity(TileEntityVisitor.class, "visitorBlock");
+
                GameRegistry.registerTileEntity(TileEntityVisitor.class, "visitorBlock");
GameRegistry.addRecipe(new ItemStack(visitor, 1), "###", "#%#", "###", '#', Item.redstone, '%', Item.paper);
+
                GameRegistry.addRecipe(new ItemStack(visitor, 1), "###", "#%#", "###", '#', Item.redstone, '%', Item.paper);
}
+
        }
 
}
 
}
 
+
BlockVisitor.java (Block class)
</source>
 
 
 
BlockVisitor.java (ブロックのクラス)
 
 
 
<source lang="java">
 
 
package com.generic.tutorial.nbt.block;
 
package com.generic.tutorial.nbt.block;
  
292行目: 195行目:
 
public class BlockVisitor extends BlockContainer {
 
public class BlockVisitor extends BlockContainer {
  
public BlockVisitor(int id) {
+
        public BlockVisitor(int id) {
super(id, 35, Material.circuits);
+
                super(id, 35, Material.circuits);
// TODO Auto-generated constructor stub
+
                // TODO Auto-generated constructor stub
}
+
        }
public boolean onBlockActivated(World world, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
+
        public boolean onBlockActivated(World world, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
 
     {
 
     {
if(!world.isRemote)
+
                if(!world.isRemote)
{
+
                {
TileEntityVisitor t = (TileEntityVisitor) world.getBlockTileEntity(par2, par3, par4);
+
                        TileEntityVisitor t = (TileEntityVisitor) world.getBlockTileEntity(par2, par3, par4);
t.processActivate(par5EntityPlayer, world);
+
                        t.processActivate(par5EntityPlayer, world);
}
+
                }
return true;
+
                return true;
 
     }
 
     }
public boolean hasTileEntity(int metadata)
+
        public boolean hasTileEntity(int metadata)
 
     {
 
     {
 
         return true;
 
         return true;
 
     }
 
     }
@Override
+
        @Override
public TileEntity createNewTileEntity(World par1World)
+
        public TileEntity createNewTileEntity(World par1World)
 
     {
 
     {
 
         try
 
         try
323行目: 226行目:
  
 
}
 
}
</source>
 
 
 
TileEntityVisitor.java
 
TileEntityVisitor.java
<source lang="java">
 
 
package com.generic.tutorial.nbt.block;
 
package com.generic.tutorial.nbt.block;
  
333行目: 233行目:
 
public class TileEntityVisitor extends TileEntity{
 
public class TileEntityVisitor extends TileEntity{
  
String visitor1="none";
+
        String visitor1="none";
String visitor2="none";
+
        String visitor2="none";
String visitor3="none";
+
        String visitor3="none";
String visitor4="none";
+
        String visitor4="none";
String visitor5="none";
+
        String visitor5="none";
public void processActivate(EntityPlayer par5EntityPlayer, World world) {
+
        public void processActivate(EntityPlayer par5EntityPlayer, World world) {
if(!visitor1.equals(par5EntityPlayer.getEntityName()))
+
                if(!visitor1.equals(par5EntityPlayer.getEntityName()))
{
+
                {
visitor5=visitor4;
+
                        visitor5=visitor4;
visitor4=visitor3;
+
                        visitor4=visitor3;
visitor3=visitor2;
+
                        visitor3=visitor2;
visitor2=visitor1;
+
                        visitor2=visitor1;
visitor1=par5EntityPlayer.getEntityName();
+
                        visitor1=par5EntityPlayer.getEntityName();
}
+
                }
//System.out.println("Visitors: " + visitor1 + ", " + visitor2 + ", " + visitor3 + ", " + visitor4 + ", " + visitor5);
+
                //System.out.println("Visitors: " + visitor1 + ", " + visitor2 + ", " + visitor3 + ", " + visitor4 + ", " + visitor5);
 
                 par5EntityPlayer.addChatMessage("Visitors: " + visitor1 + ", " + visitor2 + ", " + visitor3 + ", " + visitor4 + ", " + visitor5);
 
                 par5EntityPlayer.addChatMessage("Visitors: " + visitor1 + ", " + visitor2 + ", " + visitor3 + ", " + visitor4 + ", " + visitor5);
world.notifyBlockChange(xCoord, yCoord, zCoord, 2);
+
                world.notifyBlockChange(xCoord, yCoord, zCoord, 2);
}
+
        }
+
       
@Override
+
        @Override
public void readFromNBT(NBTTagCompound nbt)
+
        public void readFromNBT(NBTTagCompound nbt)
 
     {
 
     {
 
         super.readFromNBT(nbt);
 
         super.readFromNBT(nbt);
366行目: 266行目:
 
     public void writeToNBT(NBTTagCompound nbt)
 
     public void writeToNBT(NBTTagCompound nbt)
 
     {
 
     {
    super.writeToNBT(nbt);
+
        super.writeToNBT(nbt);
    nbt.setString("visitor1", visitor1);
+
        nbt.setString("visitor1", visitor1);
 
         nbt.setString("visitor2", visitor2);
 
         nbt.setString("visitor2", visitor2);
 
         nbt.setString("visitor3", visitor3);
 
         nbt.setString("visitor3", visitor3);
375行目: 275行目:
  
 
}
 
}
</source>
 
  
===注意事項===
+
Please note
  
Forge(訳注:これ自体はFML)を使ってTileEntityを登録する必要があります:
+
You have to register the tileEntity with Forge, using:
<source lang="java">
 
 
GameRegistry.registerTileEntity(TileEntityVisitor.class, "visitorBlock");
 
GameRegistry.registerTileEntity(TileEntityVisitor.class, "visitorBlock");
</source>
+
Read more
 
 
===参考==
 
  
[http://wiki.vg/NBT Minecraft CoalitionのNBTのページ]
+
NBT page at Minecraft Coalition
 +
Categories: TutorialsTutorials/Intermediate

Minecraft Modding Wikiへの投稿はすべて、他の投稿者によって編集、変更、除去される場合があります。 自分が書いたものが他の人に容赦なく編集されるのを望まない場合は、ここに投稿しないでください。
また、投稿するのは、自分で書いたものか、パブリック ドメインまたはそれに類するフリーな資料からの複製であることを約束してください(詳細はMinecraft Modding Wiki:著作権を参照)。 著作権保護されている作品は、許諾なしに投稿しないでください!

このページを編集するには、下記の確認用の質問に回答してください (詳細):

取り消し 編集の仕方 (新しいウィンドウで開きます)