Вверх ↑
Этот топик читают: Гость
Ответов: 4557
#1: 2014-11-18 18:58:12 ЛС | профиль | цитата
Работа происходит на чистом клиенте Minecraft vanila на версии 1.5.2.
  Постепенно я буду рассказывать Вам о создании полублоков. Сегодня мы рассмотрим пример с
, только вместо земленокаменных ступенек у нас будут доски с узорами.

Открываем нашу среду разработки (я работаю с 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]);
}
}
}
И в файл BlockStairx4 вставляем
Код

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.

Рендер блока. 1.0F, 0.75F , 1.0F -
, 1.0F, 0.50F , 1.0F -
, 1.0F, 0.25F , 1.0F -

    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;

}

Метадата. Счет начинает идти с 0.
    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");
начинаем вписывать наши 4 блока:

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");

И внизу файла вставляем (под строкой 1337):

        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);
}


Открой

карма: 6
6
Голосовали:Shmel, OTBETCTBEHHblN, STL1te, Armata, SuperSs, Sedgewick
Ответов: 13
#2: 2014-11-18 19:02:18 ЛС | профиль | цитата
Сферу можешь сделать?
карма: 0
0
Ответов: 4557
#3: 2014-11-18 19:05:20 ЛС | профиль | цитата
Embr0n,
Тут твое счастье

package net.minecraft.src;

public class Modelsphere extends ModelBase
{
//fields
ModelRenderer Shape2;
ModelRenderer Shape1;

public Modelsphere()
{
textureWidth = 16;
textureHeight = 16;

Shape2 = new ModelRenderer(this, 0, 0);
Shape2.addBox(0F, 0F, 0F, 0, 0, 0);
Shape2.setRotationPoint(0F, 0F, 0F);
Shape2.setTextureSize(16, 16);
Shape2.mirror = true;
setRotation(Shape2, 0F, 0F, 0F);
Shape1 = new ModelRenderer(this, 0, 0);
Shape1.addBox(0F, 0F, 0F, 8, 8, 8);
Shape1.setRotationPoint(-4F, 11F, 0F);
Shape1.setTextureSize(16, 16);
Shape1.mirror = true;
setRotation(Shape1, -0.8922867F, 0F, 0F);
}

public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
{
super.render(entity, f, f1, f2, f3, f4, f5);
setRotationAngles(f, f1, f2, f3, f4, f5);
Shape2.render(f5);
Shape1.render(f5);
}

private void setRotation(ModelRenderer model, float x, float y, float z)
{
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}

public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5)
{
super.setRotationAngles(f, f1, f2, f3, f4, f5);
}

}


карма: 6
0
Ответов: 13
#4: 2014-11-18 19:21:50 ЛС | профиль | цитата
Flanagun, попробуй сделать кварцевую сферу (для примера).
[container=1]
карма: 0
0
Ответов: 13
#5: 2014-11-18 20:13:59 ЛС | профиль | цитата
Хорошая штучка, пригодится, спасибки=З
карма: 0
0
-_Revers_- (сообщение скрыто ввиду неодобрения читателями) показать
-4
Голосовали:Flanagun, OTBETCTBEHHblN, Bro_DyaGa, define
Ответов: 4557
#7: 2014-11-18 21:07:44 ЛС | профиль | цитата
-_Revers_- писал(а):
Хорошая,идея.

Ты с головой дружишь?
карма: 6
0
Ответов: 312
Storm
Inactive
#8: 2014-11-18 21:59:34 ЛС | профиль | цитата
Спасибо помог
карма: -2
0
Ответов: 588
Identity
Комедиант
#9: 2014-11-19 22:51:12 ЛС | профиль | цитата
Где да нибудь пригодится, спасибо, Флано.
карма: 9
VK. ; Identity clan. ; [2014-11-25] "Сука, волосня из жопы уже на спину лезет".
0
Ответов: 26
Destiny
Ilyha
#10: 2014-12-07 00:12:50 ЛС | профиль | цитата
Спасибо)
карма: 2
0
Ответов: 48
Clear Sky
лидер
#11: 2014-12-07 00:16:39 ЛС | профиль | цитата
хороша идея различность блоков в MCG не помешает ~за~
карма: 2
Не суди игрока по нику и аватарке
-1
Голосовали:OTBETCTBEHHblN
HipTjx (сообщение скрыто ввиду неодобрения читателями) показать
-5
Голосовали:MrShock, Flanagun, IE33, define, En9T
Ведущий разработчик
Ответов: 445
#13: 2015-02-23 10:18:02 ЛС | профиль | цитата
Все делается одним файлом и используется 1 id под блок, а не 4. Здесь избыточность кода.
Я скажу больше, метаданных одного блока хватит чтобы разместить все ступеньки в кастомном порядке.

К примеру через одну.
Или, например в таком порядке:

=======
=======

=======
карма: 66
Спокойно, парни, всё будет.
0
Ответов: 178
#14: 2015-03-25 15:00:42 ЛС | профиль | цитата
За
карма: -8
:(
-2
Голосовали:Flanagun, Crazy_Fox
Ответов: 461
#15: 2015-03-30 14:06:37 ЛС | профиль | цитата
Благодарю.
До самого не доходило.
карма: -53
0
Ответов: 380
MC academy
Твинки
#16: 2015-03-30 14:13:33 ЛС | профиль | цитата
PLOMBIR писал(а):
За

В чем за??

Попробуем посмотрим что получиться :Р
карма: 4
...
0
16
Сообщение
...