Le modding en vidéo

Toadico

Architecte en herbe
23 Avril 2011
84
5
105
@Zehirmahn : Oui c'est normal je m'étais trompé dans le tuto :

Toadico a dit:
C'est bon j'ai trouvé la solution :)
En fait c'est de ma faute, je m'étais trompé dans le code source : lorsqu'on ajoute une armure, le 3ème chiffre entre parenthèses représente le skin de l'armure :

Code :
(new ItemArmor(420, 0, 5, 0))

0 = cuir
1 = maille
2 = fer
3 = diamant
4 = or
5 = 1ère armure que vous ajoutez
6 = 2ème armure que vous ajoutez
...

Donc il suffit de remplacer 0 par 5 (ou un autre chiffre si vous avez fait plusieurs armures) à chaque new ItemArmor et normalement c'est bon.

Désolé pour l'erreur :s

@kasyos : en fait c'est un peu compliqué à faire ; tu veux modifier la particule de feu ou la texture du bloc (ou les deux) ?
 

kasyos

Slime des glaces
30 Mars 2011
56
0
1
30
mineboxradio.fr
Enfaite j'aimerais faire un distributeur de bière, donc je vais reprendre le principe du four avec une texture de bloc nouvelle et une shop a la place de la flamme.
 

Toadico

Architecte en herbe
23 Avril 2011
84
5
105
Pour la texture du bloc tu pourras la modifier assez simplement, mais pour la chope de bière ce sera bien plus dur parce que les particules comme les flammes ne se basent pas sur des images png, tu les définis directement depuis le code source, ce que je ne sais absolument pas faire. Si tu veux quand même faire ton four, je te donnerai la méthode pour le créer et modifier sa texture.
 

kasyos

Slime des glaces
30 Mars 2011
56
0
1
30
mineboxradio.fr
Je souhaite toujours faire mon four, si tu pouvais m'expliquer comment le crée et changer sa texture tu me serait d'une très grande aide !

Pour la flamme c'est pas grave :)
 

Toadico

Architecte en herbe
23 Avril 2011
84
5
105
Alors déjà pour faire un four il faut créer 2 nouveaux blocs : le four éteint et le four allumé. Tu vas donc rajouter dans ton fichier mod_TonMod.java les 2 blocs :

Code:
public static final Block fourEteint = (new BlockTonBloc(230, false))
.setHardness(3.5F)
.setStepSound(Block.soundStoneFootstep)
.setBlockName("Four éteint")
.disableNeighborNotifyOnMetadataChange();

public static final Block fourAllume = (new BlockTonBloc(231, true))
.setHardness(3.5F)
.setStepSound(Block.soundStoneFootstep)
.setLightValue(0.875F)
.setBlockName("Four allumé")
.disableNeighborNotifyOnMetadataChange();

Comme tu l'as peut-être remarqué, si à new BlockTonBloc, entre parenthèses, tu mets false, ton four sera éteint ; à l'inverse, si tu mets true, il sera allumé. J'ai aussi rajouté la ligne ".disableNeighborNotifyOnMetadataChange();", mais ce n'est pas important :)

Ensuite tu vas copier ceci dans ton fichier BlockTonBloc.java :

Code:
package net.minecraft.src;
import java.util.Random;

public class BlockTonBloc extends BlockContainer
{
    protected BlockTonBloc(int i, boolean flag)
    {
        super(i, Material.rock);
        furnaceRand = new Random();
        isActive = flag;
    }

    public int idDropped(int i, Random random)
    {
        return Block.stoneOvenIdle.blockID;
    }

    public void onBlockAdded(World world, int i, int j, int k)
    {
        super.onBlockAdded(world, i, j, k);
        setDefaultDirection(world, i, j, k);
    }

    private void setDefaultDirection(World world, int i, int j, int k)
    {
        if(world.multiplayerWorld)
        {
            return;
        }
        int l = world.getBlockId(i, j, k - 1);
        int i1 = world.getBlockId(i, j, k + 1);
        int j1 = world.getBlockId(i - 1, j, k);
        int k1 = world.getBlockId(i + 1, j, k);
        byte byte0 = 3;
        if(Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[i1])
        {
            byte0 = 3;
        }
        if(Block.opaqueCubeLookup[i1] && !Block.opaqueCubeLookup[l])
        {
            byte0 = 2;
        }
        if(Block.opaqueCubeLookup[j1] && !Block.opaqueCubeLookup[k1])
        {
            byte0 = 5;
        }
        if(Block.opaqueCubeLookup[k1] && !Block.opaqueCubeLookup[j1])
        {
            byte0 = 4;
        }
        world.setBlockMetadataWithNotify(i, j, k, byte0);
    }

    public void randomDisplayTick(World world, int i, int j, int k, Random random)
    {
        if(!isActive)
        {
            return;
        }
        int l = world.getBlockMetadata(i, j, k);
        float f = (float)i + 0.5F;
        float f1 = (float)j + 0.0F + (random.nextFloat() * 6F) / 16F;
        float f2 = (float)k + 0.5F;
        float f3 = 0.52F;
        float f4 = random.nextFloat() * 0.6F - 0.3F;
        if(l == 4)
        {
            world.spawnParticle("smoke", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
            world.spawnParticle("flame", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
        } else
        if(l == 5)
        {
            world.spawnParticle("smoke", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
            world.spawnParticle("flame", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
        } else
        if(l == 2)
        {
            world.spawnParticle("smoke", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D);
            world.spawnParticle("flame", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D);
        } else
        if(l == 3)
        {
            world.spawnParticle("smoke", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D);
            world.spawnParticle("flame", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D);
        }
    }
	
	public int getBlockTexture(IBlockAccess iblockaccess, int i, int j, int k, int l)
    {
		if(l == 1)
        {
            return mod_TonMod.textureHaut;
        }
        if(l == 0)
        {
            return mod_TonMod.textureBas;
        }
		int i1 = iblockaccess.getBlockMetadata(i, j, k);
        if(l != i1)
        {
            return mod_TonMod.textureDerriereEtCote;
        }
        if(isActive)
        {
            return mod_TonMod.textureDevantActif;
        } else
        {
            return mod_TonMod.textureDevantInactif;
        }
    }

    public int getBlockTextureFromSide(int i)
    {
        if(i == 1)
        {
            return mod_TonMod.textureHaut;
        }
        if(i == 0)
        {
            return mod_TonMod.textureBas;
        }
        if(i == 3)
        {
            return mod_TonMod.textureDevantInactif;
        } else
        {
            return mod_TonMod.textureDerriereEtCote;
        }
    }

    public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer)
    {
        if(world.multiplayerWorld)
        {
            return true;
        } else
        {
            TileEntityFurnace tileentityfurnace = (TileEntityFurnace)world.getBlockTileEntity(i, j, k);
            entityplayer.displayGUIFurnace(tileentityfurnace);
            return true;
        }
    }

    public static void updateFurnaceBlockState(boolean flag, World world, int i, int j, int k)
    {
        int l = world.getBlockMetadata(i, j, k);
        TileEntity tileentity = world.getBlockTileEntity(i, j, k);
        keepFurnaceInventory = true;
        if(flag)
        {
            world.setBlockWithNotify(i, j, k, Block.stoneOvenActive.blockID);
        } else
        {
            world.setBlockWithNotify(i, j, k, Block.stoneOvenIdle.blockID);
        }
        keepFurnaceInventory = false;
        world.setBlockMetadataWithNotify(i, j, k, l);
        tileentity.func_31004_j();
        world.setBlockTileEntity(i, j, k, tileentity);
    }

    protected TileEntity getBlockEntity()
    {
        return new TileEntityFurnace();
    }

    public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving)
    {
        int l = MathHelper.floor_double((double)((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
        if(l == 0)
        {
            world.setBlockMetadataWithNotify(i, j, k, 2);
        }
        if(l == 1)
        {
            world.setBlockMetadataWithNotify(i, j, k, 5);
        }
        if(l == 2)
        {
            world.setBlockMetadataWithNotify(i, j, k, 3);
        }
        if(l == 3)
        {
            world.setBlockMetadataWithNotify(i, j, k, 4);
        }
    }

    public void onBlockRemoval(World world, int i, int j, int k)
    {
        if(!keepFurnaceInventory)
        {
            TileEntityFurnace tileentityfurnace = (TileEntityFurnace)world.getBlockTileEntity(i, j, k);
label0:
            for(int l = 0; l < tileentityfurnace.getSizeInventory(); l++)
            {
                ItemStack itemstack = tileentityfurnace.getStackInSlot(l);
                if(itemstack == null)
                {
                    continue;
                }
                float f = furnaceRand.nextFloat() * 0.8F + 0.1F;
                float f1 = furnaceRand.nextFloat() * 0.8F + 0.1F;
                float f2 = furnaceRand.nextFloat() * 0.8F + 0.1F;
                do
                {
                    if(itemstack.stackSize <= 0)
                    {
                        continue label0;
                    }
                    int i1 = furnaceRand.nextInt(21) + 10;
                    if(i1 > itemstack.stackSize)
                    {
                        i1 = itemstack.stackSize;
                    }
                    itemstack.stackSize -= i1;
                    EntityItem entityitem = new EntityItem(world, (float)i + f, (float)j + f1, (float)k + f2, new ItemStack(itemstack.itemID, i1, itemstack.getItemDamage()));
                    float f3 = 0.05F;
                    entityitem.motionX = (float)furnaceRand.nextGaussian() * f3;
                    entityitem.motionY = (float)furnaceRand.nextGaussian() * f3 + 0.2F;
                    entityitem.motionZ = (float)furnaceRand.nextGaussian() * f3;
                    world.entityJoinedWorld(entityitem);
                } while(true);
            }

        }
        super.onBlockRemoval(world, i, j, k);
    }

    private Random furnaceRand;
    private final boolean isActive;
    private static boolean keepFurnaceInventory = false;

}

Il ne te reste plus qu'à déclarer tes textures dans mod_TonMod.java comme expliqué dans l'épisode 5 et à suivre la procédure normal avec ModLoader.RegisterBlock, etc. Je te montre mon fichier mod_MonMod.java :

Code:
package net.minecraft.src;

public class mod_MonMod extends BaseMod
{
	public static final Block fourEteint = (new BlockFour(230, false))
	.setHardness(3.5F)
	.setStepSound(Block.soundStoneFootstep)
	.setBlockName("Four éteint")
	.disableNeighborNotifyOnMetadataChange();
	
	public static final Block fourAllume = (new BlockFour(231, true))
	.setHardness(3.5F)
	.setStepSound(Block.soundStoneFootstep)
	.setLightValue(0.875F)
	.setBlockName("Four allumé")
	.disableNeighborNotifyOnMetadataChange();
	
	public static int textureHaut, textureBas, textureDevantActif, textureDevantInactif, textureDerriereEtCote;

	public mod_MonMod()
	{
		textureHaut = ModLoader.addOverride("/terrain.png", "/blue.png");
		textureBas = ModLoader.addOverride("/terrain.png", "/green.png");
		textureDevantActif = ModLoader.addOverride("/terrain.png", "/red.png");
		textureDevantInactif = ModLoader.addOverride("/terrain.png", "/pink.png");
		textureDerriereEtCote = ModLoader.addOverride("/terrain.png", "/yellow.png");
		
		ModLoader.RegisterBlock(fourEteint);
		ModLoader.AddRecipe(
		new ItemStack(fourEteint, 4), 
		new Object[] {"#", Character.valueOf('#'), Block.dirt}
		);
		ModLoader.AddName(fourEteint, "Four éteint");
		
		ModLoader.RegisterBlock(fourAllume);
		ModLoader.AddRecipe(
		new ItemStack(fourAllume, 4), 
		new Object[] {"##", Character.valueOf('#'), Block.dirt}
		);
		ModLoader.AddName(fourAllume, "Four allumé");
	}
	
	public String Version()
	{
		return "1.7.3";
	}
}

Voilà ! N'hésites pas à poser de questions si tu ne comprends pas quelque chose :)
 

kasyos

Slime des glaces
30 Mars 2011
56
0
1
30
mineboxradio.fr
Impeccable sa marche :) Un grand merci.

Juste dernière question : Je voudrais que les items que j'ai crée ne puisse être être mis que dans ce nouveau four est pas dans le normal. Comment faire ?

Et une autre question : Comment retirer les flamme que fait le four quand il est on ?

Merci d'avance

Edit : Je viens de trouver un bug, quand je met a fondre un objet dans mon four le temps de la fonte il prend la texture d'un bloc normal.
 

Rackprod

Aventurier
31 Août 2011
5
0
0
Bonjour
j'ai une question concernant les recettes, lorsque je créer deux objets sur le même mod, les deux recettes sont attribuées a un seul des deux objets.
Ceci est bien embattent, pourtant mes deux objets sont bien séparer.
Voila mon Code :
Celui du mod :
package net.minecraft.src;
public class mod_Beer extends BaseMod
{
public mod_Beer()
{
Beer = (new ItemBeer(1000, 12))
.setIconIndex(ModLoader.addOverride("/gui/items.png", "/Mod/Beer.png"))
.setItemName("Beer");
ModLoader.AddName(Beer, "Beer");
ModLoader.AddRecipe(
new ItemStack(Beer, 1),
new Object[] {"#", Character.valueOf('#'), mod_Beer.Houblon}
);
}
{
Houblon = (new ItemHoublon(1000, 4))
.setIconIndex(ModLoader.addOverride("/gui/items.png", "/Mod/Houbon.png"))
.setItemName("Houblon");
ModLoader.AddName(Houblon, "Houblon");
ModLoader.AddRecipe(
new ItemStack(Houblon, 1),
new Object[] {"XX", Character.valueOf('X'), Item.stick}
);
}
public static Item Beer;
public static Item Houblon;

public String Version()
{
return "1.7_03";
}

}


Et celui des deux objet
Beer:
package net.minecraft.src;

public class ItemBeer extends Item
{
public ItemBeer(int i, int j)
{
super(i);
healAmount = j;;
maxStackSize = 1;
}
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
{
itemstack.stackSize--;
entityplayer.heal(healAmount);
return itemstack;
}
public int getHealAmount()
{
return healAmount;
}

private int healAmount;
}

Et Houblon :
package net.minecraft.src;

public class ItemHoublon extends Item
{
public ItemHoublon(int i, int j)
{
super(i);
healAmount = j;;
maxStackSize = 64;
}
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
{
itemstack.stackSize--;
entityplayer.heal(healAmount);
return itemstack;
}
public int getHealAmount()
{
return healAmount;
}

private int healAmount;
}

Je vous remercie d'avance pour votre aide[/font]