Постепенно я буду рассказывать Вам о создании полублоков. Сегодня мы рассмотрим пример с , только вместо земленокаменных ступенек у нас будут доски с узорами.
Открываем нашу среду разработки (я работаю с Eclipse) и создаем 4 файла: BlockStairx1.java, BlockStairx2.java, BlockStairx3.java, BlockStairx4.java.
Начинаем работу со ступеньками ()
Непосредственно мы работаем с Metadata.
Вставляем данный код в BlockStairx1.java
package net.minecraft.src;
import java.util.List;
public class BlockStairx1 extends Block
{
/** The type of tree this block came from. */
public static final String[] slabsType = new String[] {"oak", "spruce", "birch", "jungle"};
public static final String[] slabsTextureTypes = new String[] {"oak", "spruce", "birch", "jungle"};
private Icon[] iconArray;
public BlockStairx1(int par1)
{
super(par1, Material.wood);
this.setCreativeTab(CreativeTabs.tabBlock);
}
public void setBlockBoundsForItemRender()
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.25F, 1.0F);
}
public boolean renderAsNormalBlock()
{
return false;
}
public boolean isOpaqueCube()
{
return false;
}
public Icon getIcon(int par1, int par2)
{
if (par2 ‹ 0 || par2 ›= this.iconArray.length)
{
par2 = 0;
}
return this.iconArray[par2];
}
/**
* Determines the damage on the item the block drops. Used in cloth and wood.
*/
public int damageDropped(int par1)
{
return par1;
}
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
par3List.add(new ItemStack(par1, 1, 2));
par3List.add(new ItemStack(par1, 1, 3));
}
/**
* When this method is called, your block should register all the icons it needs with the given IconRegister. This
* is the only chance you get to register icons.
*/
public void registerIcons(IconRegister par1IconRegister)
{
this.iconArray = new Icon[slabsTextureTypes.length];
for (int var2 = 0; var2 ‹ this.iconArray.length; ++var2)
{
this.iconArray[var2] = par1IconRegister.registerIcon(slabsTextureTypes[var2]);
}
}
}
Вставляем данный код в BlockStairx2.java
package net.minecraft.src;
import java.util.List;
public class BlockStairx2 extends Block
{
/** The type of tree this block came from. */
public static final String[] slabsType = new String[] {"oak", "spruce", "birch", "jungle"};
public static final String[] slabsTextureTypes = new String[] {"oak", "spruce", "birch", "jungle"};
private Icon[] iconArray;
public BlockStairx2(int par1)
{
super(par1, Material.wood);
this.setCreativeTab(CreativeTabs.tabBlock);
}
public void setBlockBoundsForItemRender()
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
}
public boolean renderAsNormalBlock()
{
return false;
}
public boolean isOpaqueCube()
{
return false;
}
public Icon getIcon(int par1, int par2)
{
if (par2 ‹ 0 || par2 ›= this.iconArray.length)
{
par2 = 0;
}
return this.iconArray[par2];
}
/**
* Determines the damage on the item the block drops. Used in cloth and wood.
*/
public int damageDropped(int par1)
{
return par1;
}
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
par3List.add(new ItemStack(par1, 1, 2));
par3List.add(new ItemStack(par1, 1, 3));
}
/**
* When this method is called, your block should register all the icons it needs with the given IconRegister. This
* is the only chance you get to register icons.
*/
public void registerIcons(IconRegister par1IconRegister)
{
this.iconArray = new Icon[slabsTextureTypes.length];
for (int var2 = 0; var2 ‹ this.iconArray.length; ++var2)
{
this.iconArray[var2] = par1IconRegister.registerIcon(slabsTextureTypes[var2]);
}
}
}
Вставляем данный код в BlockStairx3.java
package net.minecraft.src;
import java.util.List;
public class BlockStairx3 extends Block
{
/** The type of tree this block came from. */
public static final String[] slabsType = new String[] {"oak", "spruce", "birch", "jungle"};
public static final String[] slabsTextureTypes = new String[] {"oak", "spruce", "birch", "jungle"};
private Icon[] iconArray;
public BlockStairx3(int par1)
{
super(par1, Material.wood);
this.setCreativeTab(CreativeTabs.tabBlock);
}
public void setBlockBoundsForItemRender()
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
}
public boolean renderAsNormalBlock()
{
return false;
}
public boolean isOpaqueCube()
{
return false;
}
public Icon getIcon(int par1, int par2)
{
if (par2 ‹ 0 || par2 ›= this.iconArray.length)
{
par2 = 0;
}
return this.iconArray[par2];
}
/**
* Determines the damage on the item the block drops. Used in cloth and wood.
*/
public int damageDropped(int par1)
{
return par1;
}
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
par3List.add(new ItemStack(par1, 1, 2));
par3List.add(new ItemStack(par1, 1, 3));
}
/**
* When this method is called, your block should register all the icons it needs with the given IconRegister. This
* is the only chance you get to register icons.
*/
public void registerIcons(IconRegister par1IconRegister)
{
this.iconArray = new Icon[slabsTextureTypes.length];
for (int var2 = 0; var2 ‹ this.iconArray.length; ++var2)
{
this.iconArray[var2] = par1IconRegister.registerIcon(slabsTextureTypes[var2]);
}
}
}
Код
package net.minecraft.src;
import java.util.List;
public class BlockStairx4 extends Block
{
/** The type of tree this block came from. */
public static final String[] woodType = new String[] {"oak", "spruce", "birch", "jungle"};
public static final String[] woodTextureTypes = new String[] {"oak", "spruce", "birch", "jungle"};
private Icon[] iconArray;
public BlockStairx4(int par1)
{
super(par1, Material.wood);
this.setCreativeTab(CreativeTabs.tabBlock);
}
/**
* From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
*/
public Icon getIcon(int par1, int par2)
{
if (par2 ‹ 0 || par2 ›= this.iconArray.length)
{
par2 = 0;
}
return this.iconArray[par2];
}
/**
* Determines the damage on the item the block drops. Used in cloth and wood.
*/
public int damageDropped(int par1)
{
return par1;
}
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
par3List.add(new ItemStack(par1, 1, 2));
par3List.add(new ItemStack(par1, 1, 3));
}
/**
* When this method is called, your block should register all the icons it needs with the given IconRegister. This
* is the only chance you get to register icons.
*/
public void registerIcons(IconRegister par1IconRegister)
{
this.iconArray = new Icon[woodTextureTypes.length];
for (int var2 = 0; var2 ‹ this.iconArray.length; ++var2)
{
this.iconArray[var2] = par1IconRegister.registerIcon(woodTextureTypes[var2]);
}
}
}
Разберём что да как.
Типы блоков и текстуры
public static final String[] woodType = new String[] {"oak", "spruce", "birch", "jungle"};
//Типы наших блоков. В данном случае: дуб, ель, берёза, тропическое дерево.
public static final String[] woodTextureTypes = new String[] {"oak", "spruce", "birch", "jungle"};
//Текстуры наших блоков. В данном случае: oak.png, spruce.png, birch.png, jungle.png.
public void setBlockBoundsForItemRender()
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
}
Не забываем, что блок у нас принял другой рендер. Данный код позволит спокойно взаимодействовать с блоком (если не вписать этот код, то Вас будет отталкивать от него)
public boolean renderAsNormalBlock()
{
return false;
}
И конечно убираем X-Ray
public boolean isOpaqueCube()
{
return false;
}
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
par3List.add(new ItemStack(par1, 1, 2));
par3List.add(new ItemStack(par1, 1, 3));
}
Начинаем работу с файлом Block.java
После данной записи (217 стока)
public static final Block dropper = (new BlockDropper(158)).setHardness(3.5F).setStepSound(soundStoneFootstep).setUnlocalizedName("dropper");
public static final Block stairx4 = (new BlockStairx4(164)).setHardness(1.5F).setResistance(10.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("stairx4");
public static final Block stairx3 = (new BlockStairx3(165)).setHardness(1.5F).setResistance(10.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("stairx3");
public static final Block stairx2 = (new BlockStairx2(166)).setHardness(1.5F).setResistance(10.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("stairx2");
public static final Block stairx1 = (new BlockStairx1(167)).setHardness(1.5F).setResistance(10.0F).setStepSound(soundWoodFootstep).setUnlocalizedName("stairx1");
Item.itemsList[stairx4.blockID] = (new ItemMultiTextureTile(stairx4.blockID - 256, stairx4, BlockStairx4.slabsType)).setUnlocalizedName("stairx4");
Item.itemsList[stairx3.blockID] = (new ItemMultiTextureTile(stairx3.blockID - 256, stairx3, BlockStairx3.slabsType)).setUnlocalizedName("stairx3");
Item.itemsList[stairx2.blockID] = (new ItemMultiTextureTile(stairx2.blockID - 256, stairx2, BlockStairx2.slabsType)).setUnlocalizedName("stairx2");
Item.itemsList[stairx1.blockID] = (new ItemMultiTextureTile(stairx1.blockID - 256, stairx1, BlockStairx1.slabsType)).setUnlocalizedName("stairx1");
Готово! Наши блоки появились в игре. Вот пример моих:
*Ну же, чел, жмякай на меня!*
также можно сделать и вертикальные ступени:
public void setBlockBoundsForItemRender()
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.75F, 1.0F, 1.0F);
}
Открой