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

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

この編集を取り消せます。 下記の差分を確認して、本当に取り消していいか検証してください。よろしければ変更を保存して取り消しを完了してください。
最新版 編集中の文章
41行目: 41行目:
 
         if (event.getSide().isClient()) {
 
         if (event.getSide().isClient()) {
 
             //モデルJSONファイルのファイル名を登録。1IDで1つだけなら、登録名はGameRegistryでの登録名と同じものにする。
 
             //モデルJSONファイルのファイル名を登録。1IDで1つだけなら、登録名はGameRegistryでの登録名と同じものにする。
             ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(sampleBlock), 0, new ModelResourceLocation(MOD_ID + ":" + "sampleblock", "inventory"));
+
            //ItemStackのmetadataで種類を分けて描画させたい場合。登録名を予め登録する。
 +
            ModelBakery.addVariantName(Item.getItemFromBlock(sampleBlock), MOD_ID + ":" + "sampleblock0", MOD_ID + ":" + "sampleblock1");
 +
            //1IDで複数モデルを登録するなら、上のメソッドで登録した登録名を指定する。
 +
             ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(sampleBlock), 0, new ModelResourceLocation(MOD_ID + ":" + "sampleblock0", "inventory"));
 +
            ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(sampleBlock), 1, new ModelResourceLocation(MOD_ID + ":" + "sampleblock1", "inventory"));
 
         }
 
         }
 
     }
 
     }
53行目: 57行目:
  
 
public class SampleBlock extends Block {
 
public class SampleBlock extends Block {
 +
    //BlockState用Property変数。今回はmetadataと同じようなPropertyIntegerを用いる。
 +
    public static final PropertyInteger METADATA = PropertyInteger.create("meta", 0, 1);
 +
 
     public SampleBlock() {
 
     public SampleBlock() {
 
         super(Material.rock);
 
         super(Material.rock);
 
         setCreativeTab(CreativeTabs.tabBlock);/*クリエイティブタブの選択*/
 
         setCreativeTab(CreativeTabs.tabBlock);/*クリエイティブタブの選択*/
 
         setUnlocalizedName("blockSample");/*システム名の設定*/
 
         setUnlocalizedName("blockSample");/*システム名の設定*/
 +
        /*以下のものは消しても結構です*/
 +
        setHardness(1.5F);/*硬さ*/
 +
        setResistance(1.0F);/*爆破耐性*/
 +
        setStepSound(Block.soundTypeStone);/*ブロックの上を歩いた時の音*/
 +
/*setBlockUnbreakable();*//*ブロックを破壊不可に設定*/
 +
/*setTickRandomly(true);*//*ブロックのtick処理をランダムに。デフォルトfalse*/
 +
/*disableStats();*//*ブロックの統計情報を保存しない*/
 +
        setLightOpacity(1);/*ブロックの透過係数。デフォルト0(不透過)*/
 +
        setLightLevel(1.0F);/*明るさ 1.0F = 15*/
 +
        //初期BlockStateの設定
 +
        this.setDefaultState(this.blockState.getBaseState().withProperty(METADATA, 0));
 +
    }
 +
 +
    //ItemStackのmetadataからIBlockStateを生成。設置時に呼ばれる。
 +
    @Override
 +
    public IBlockState getStateFromMeta(int meta) {
 +
        return this.getDefaultState().withProperty(METADATA, meta);
 +
    }
 +
 +
    //IBlockStateからItemStackのmetadataを生成。ドロップ時とテクスチャ・モデル参照時に呼ばれる。
 +
    @Override
 +
    public int getMetaFromState(IBlockState state) {
 +
        return (Integer)state.getValue(METADATA);
 +
    }
 +
 +
    //初期BlockStateの生成。
 +
    @Override
 +
    protected BlockState createBlockState() {
 +
        return new BlockState(this, METADATA);
 +
    }
 +
 +
    //複数種類のブロックをクリエイティブタブに登録するためのメソッド
 +
    @Override
 +
    public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) {
 +
        super.getSubBlocks(itemIn, tab, list);
 +
        list.add(new ItemStack(itemIn, 1, 1));
 
     }
 
     }
  
67行目: 110行目:
  
 
     /**
 
     /**
 +
    特に変えない
 +
    */
 +
    @SideOnly(Side.CLIENT)
 +
    public int getBlockColor(){
 +
        return 0xffffff;
 +
    }
 +
 +
    /**
 +
    BlockStateで色を変えている。 パーティクルは変えないようにする。
 +
    */
 +
    @SideOnly(Side.CLIENT)
 +
    public int getRenderColor(IBlockState state){
 +
        if(checkStackRoot()) return 0xffffff;
 +
        return ItemDye.dyeColors[(Integer) state.getValue(METADATA)];
 +
    }
 +
 +
    /**
 +
    RenderPassを利用しないのでgetRenderColorと同じで良い
 
     RenderPassに渡される数値はJsonで指定したtintindexで、tintindexを指定しないとこのメソッドは呼ばれない。
 
     RenderPassに渡される数値はJsonで指定したtintindexで、tintindexを指定しないとこのメソッドは呼ばれない。
 
     @see #getRenderColor
 
     @see #getRenderColor
72行目: 133行目:
 
     @SideOnly(Side.CLIENT)
 
     @SideOnly(Side.CLIENT)
 
     public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass){
 
     public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass){
         return ItemDye.dyeColors[renderPass];
+
         return getRenderColor(worldIn.getBlockState(pos));
 +
    }
 +
 
 +
    /**
 +
    StackTraceElementを使ってパーティクル生成時にメソッドが呼ばれているかチェック
 +
    */
 +
    public static boolean checkStackRoot(){
 +
        StackTraceElement[] es = new Exception().getStackTrace();
 +
        String particle = EntityDiggingFX.class.getCanonicalName()/*"net.minecraft.client.particle.EntityDiggingFX"*/;
 +
        return es[2].getClassName().equals(particle) || es[4].getClassName().equals(particle);
 
     }
 
     }
 
}
 
}
80行目: 150行目:
 
package等省略
 
package等省略
  
public class SampleItemBlock extends ItemBlock{
+
public class SampleItemBlock extends ItemColored {
     public SampleItemBlock(Block block){
+
    /**booleanとBooleanの違いか、GameRegistoryでItemColoredそのままを利用できないので第二引数を潰す*/
         super(block);
+
     public SampleItemBlock(Block block) {
 +
         super(block,false);
 
     }
 
     }
 +
}
  
    /**
 
    Layerが機能しているかの確認。
 
    */
 
    @SideOnly(Side.CLIENT)
 
    public int getColorFromItemStack(ItemStack stack, int renderPass){
 
        return block.colorMultiplier(null, null, renderPass);
 
    }
 
}
 
 
</source>
 
</source>
 
*sampleblock.json(BlockState用)
 
*sampleblock.json(BlockState用)
98行目: 162行目:
 
{
 
{
 
     "variants": {
 
     "variants": {
         "normal":  { "model": "samplemod:sampleblock" }
+
         "meta=0":  { "model": "samplemod:sampleblock0" },
 +
        "meta=1":  { "model": "samplemod:sampleblock1" }
 
     }
 
     }
 
}
 
}
239行目: 304行目:
 
     "textures": {
 
     "textures": {
 
         "all": "blocks/dirt",
 
         "all": "blocks/dirt",
         "overlayall": "items/snowball"
+
         "overlayall": "items/potion_overlay"
 
     }
 
     }
 
}
 
}
271行目: 336行目:
  
 
     /**
 
     /**
 +
    特に変えない
 +
    */
 +
    @SideOnly(Side.CLIENT)
 +
    public int getBlockColor(){
 +
        return 0xffffff;
 +
    }
 +
 +
    /**
 +
    BlockStateで色を変えている。 パーティクルは変えないようにする。
 +
    */
 +
    @SideOnly(Side.CLIENT)
 +
    public int getRenderColor(IBlockState state){
 +
        if(checkStackRoot()) return 0xffffff;
 +
        return ItemDye.dyeColors[(Integer) state.getValue(METADATA)];
 +
    }
 +
 +
    /**
 +
    RenderPassを利用しないのでgetRenderColorと同じで良い
 
     RenderPassに渡される数値はJsonで指定したtintindexで、tintindexを指定しないとこのメソッドは呼ばれない。
 
     RenderPassに渡される数値はJsonで指定したtintindexで、tintindexを指定しないとこのメソッドは呼ばれない。
 
     @see #getRenderColor
 
     @see #getRenderColor
276行目: 359行目:
 
     @SideOnly(Side.CLIENT)
 
     @SideOnly(Side.CLIENT)
 
     public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass){
 
     public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass){
         return ItemDye.dyeColors[renderPass];
+
         return getRenderColor(worldIn.getBlockState(pos));
 +
    }
 +
 
 +
    /**
 +
    StackTraceElementを使ってパーティクル生成時にメソッドが呼ばれているかチェック
 +
    */
 +
    public static boolean checkStackRoot(){
 +
        StackTraceElement[] es = new Exception().getStackTrace();
 +
        String particle = EntityDiggingFX.class.getCanonicalName()/*"net.minecraft.client.particle.EntityDiggingFX"*/;
 +
        return es[2].getClassName().equals(particle) || es[4].getClassName().equals(particle);
 
     }
 
     }
 
</source>
 
</source>
 
基本的にコメントのとおりである。
 
基本的にコメントのとおりである。
 +
 +
===SampleItemBlock.java===
 +
ItemColorを継承しているため、特に気にすべき点はない。
  
 
===sampleblock0.json(BlockState用)===
 
===sampleblock0.json(BlockState用)===

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

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

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