Création de Bloc : Direction + RedStonne

Mack

Architecte en herbe
3 Juin 2011
123
5
124
Mack a dit:
Bon, j'ai finalement réussis mes problème de la page précédente.
Mais maintenant, j'en ai une autre :
Comment faire pour utiliser une planche de sprite ?
Parce que pour l'instant, j'ai une image par objets ...
J'ai pas beaucoup d'objet, mais bon, j'aimerai bien tout mettre sur une seule image.

De plus, j'ai une seconde question :
Comment faire pour que le bloc s'oriente comme un piston ?
En gros, suivant comment le joueur place le bloc, je voudrais que ce dernier s'oriente de certaine façon. ( En gros, c'est vraiment comme le piston que je voudrais ... )
J'ai beau chercher, je trouve pas ...
Dans le même genre, comment faire pour donner une texture "custom" à un bloc à l'interrieur de celui ci ?
En gros, comment faire pour qu'une seule de ses faces et un côté custom ?
Si on le veux pas custom il suffit de faire un truc comme ça :
Code:
 public int getBlockTextureFromSideAndMetadata(int i, int j)
    {
        if(i == 1)
        {
            return 1;
        }
        else
        {
            return blockIndexInTexture;
        }
    }
Et le bloc du dessus est pas le même, mais il doit resté dans Terrain.png. Comment faire pour prendre l'image à autre part ?
Et comment savoir quelle est la direction du bloc ?

Et autre question :
Comment faire pour activer des trucs seulement si le bloc et parcourut par du courant ?
Enfin, plus exactement, je voudrais faire que si le bloc reçoit du courant redstone, un truc se passe une seule fois. Et dès que le courant passe plus, un au truc se passe ( Une seule fois aussi. )
J'ai bien essayer un truc du genre :
Code:
public void updateTick(World world, int i, int j, int k, Random random)
	{
		super.updateTick(world, i, j, k, random);
		int id_bloc = world.getBlockId(i, j-1, k);
		if (world.isBlockIndirectlyGettingPowered(i, j, k))
		{
			if ( id_bloc == 0 )
			{
				int block = 203;//Block.wood.blockID;
				world.setBlockWithNotify(i,j-1,k,block);
				if ( world.isAirBlock(i,j-2,k) )
				{
					world.setBlockWithNotify(i,j-2,k,block);
					
					if ( world.isAirBlock(i,j-3,k) )
					{
						world.setBlockWithNotify(i,j-3,k,block);
					}
				}
			}
		}
		else
		{
			if ( id_bloc == 203 )
			{
				int block = 0;

				world.setBlockWithNotify(i,j-1,k,block);
				
				id_bloc = world.getBlockId(i, j-2, k);
				if ( id_bloc == 203 )
				{
					world.setBlockWithNotify(i,j-2,k,block);
					
					id_bloc = world.getBlockId(i, j-3, k);
					if ( id_bloc == 203 )
					{
						world.setBlockWithNotify(i,j-3,k,block);
					}
				}
			}
		}
	}
Mais y a rien qui se passe ...

Merci d'avance.
 

Mack

Architecte en herbe
3 Juin 2011
123
5
124
J'ai une autre question :

Comment ajouté une Entity ?

En gros, j'ai créer une EntitySkeletonSword.java :
Code:
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode 

package net.minecraft.src;

import java.util.Random;

// Referenced classes of package net.minecraft.src:
//            EntityMob, World, MathHelper, Entity, 
//            EntityArrow, Item, ItemStack, NBTTagCompound

public class EntitySkeletonSword extends EntityMob
{

    public EntitySkeletonSword(World world)
    {
        super(world);
        texture = "/mob/skeleton.png";
    }

    protected String getLivingSound()
    {
        return "mob.skeleton";
    }

    protected String getHurtSound()
    {
        return "mob.skeletonhurt";
    }

    protected String getDeathSound()
    {
        return "mob.skeletonhurt";
    }
    public void onLivingUpdate()
    {
        if(worldObj.isDaytime())
        {
            float f = getEntityBrightness(1.0F);
            if(f > 0.5F && worldObj.canBlockSeeTheSky(MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ)) && rand.nextFloat() * 30F < (f - 0.4F) * 2.0F)
            {
                fire = 300;
            }
        }
        super.onLivingUpdate();
    }


    protected int getDropItemId()
    {
        return Item.arrow.shiftedIndex;
    }

    protected void dropFewItems()
    {
        int i = rand.nextInt(3);
        for(int j = 0; j < i; j++)
        {
            dropItem(Item.arrow.shiftedIndex, 1);
        }

        i = rand.nextInt(3);
        for(int k = 0; k < i; k++)
        {
            dropItem(Item.bone.shiftedIndex, 1);
        }

    }

public ItemStack getHeldItem()
{
return defaultHeldItem;
}

private static final ItemStack defaultHeldItem;

static
{
defaultHeldItem = new ItemStack(Item.swordDiamond, 1);
}
}

Dans mon mod j'ai mis ça :
Code:
    public void AddEntityId()
    {
        ModLoader.RegisterEntityID(net.minecraft.src.EntitySkeletonSword.class, "SkeletonSwordman", ModLoader.getUniqueEntityId());
        ModLoader.AddSpawn(net.minecraft.src.EntitySkeletonSword.class, 10, EnumCreatureType.creature);
    }

Et pour "invoquer" le monstre j'ai créer ce bloc :
Code:
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode 

package net.minecraft.src;


// Referenced classes of package net.minecraft.src:
//            Block, Material

public class BlockTest extends Block
{

    protected BlockTest(int i, int j)
    {
        super(i, j, Material.ground);
    }
    public void onBlockClicked(World world, int i, int j, int k, EntityPlayer entityplayer)
    {
        int i1 = 0;
        int j1 = 0;
	double d = (double)i + (double)i1 * 0.59999999999999998D + 0.5D;
        double d1 = (double)j + 0.5D;
        double d2 = (double)k + (double)j1 * 0.59999999999999998D + 0.5D;
        EntitySkeletonSword entityskeletonsword = new EntitySkeletonSword(world, d, d1, d2);
	//EntityArrow entityarrow = new EntityArrow(world, d, d1, d2);
	world.entityJoinedWorld(entityskeletonsword);
    }
}

Et voici le message d'erreur :

A savoir que quand je créer une flèche au lieu de mon monstre, ça marche ...
 

kifkif43

Bucheron
29 Avril 2011
173
2
13
Il faut que tu rajoute ceci dans EntitymonMonstre

public EntityMonMonstre(double d, double d1, double d2)
{
setPosition(d, d1, d2);
}
 

Mack

Architecte en herbe
3 Juin 2011
123
5
124
Ah effectivement j'ai plus de message d'erreur =P.
Par contre, y a rien que la flèche qui apparaît ...
Mais le son du squelette se joue ...
 

kifkif43

Bucheron
29 Avril 2011
173
2
13
Tu peut aussi rajouter apres setposition
motionX = 0.0F;
motionY = 0.0F;
motionZ = 0.0F;
posX = prevPosX;
posY = prevPosY;
posZ = prevPosZ;
 

Mack

Architecte en herbe
3 Juin 2011
123
5
124
Ça marche toujours pas =/.

Est ce que ça peut venir du fait qu'il fasse jour ? Parce que j'ai essayer même avec un Zombie normal, et ça marche pas non plus ...


EDIT : Ah, non, en faite c'est bon, j'avais juste oublier de passer en autre chose que peacefull ^^".

Par contre, même avec le code qui est censée lui mettre un objet dans la main y a quedal qui apparait ....
Voila mon code au complet :
Code:
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode 

package net.minecraft.src;
import java.util.List;
import java.util.Random;

// Referenced classes of package net.minecraft.src:
//            EntityMob, World, MathHelper, Entity, 
//            EntityArrow, Item, ItemStack, NBTTagCompound

public class EntitySkeletonSword extends EntityMob
{

 public EntitySkeletonSword(World world)
    {
        super(world);
        angerLevel = 0;
        randomSoundDelay = 0;
	texture = "/mob/skeleton.png";
        moveSpeed = 0.5F;
        attackStrength = 5;
    }


    public void writeEntityToNBT(NBTTagCompound nbttagcompound)
    {
        super.writeEntityToNBT(nbttagcompound);
        nbttagcompound.setShort("Anger", (short)angerLevel);
    }

    public void readEntityFromNBT(NBTTagCompound nbttagcompound)
    {
        super.readEntityFromNBT(nbttagcompound);
        angerLevel = nbttagcompound.getShort("Anger");
    }

    protected Entity findPlayerToAttack()
    {
        if(angerLevel == 0)
        {
            return null;
        } else
        {
            return super.findPlayerToAttack();
        }
    }

    public void onLivingUpdate()
    {
        super.onLivingUpdate();
    }

    public boolean attackEntityFrom(Entity entity, int i)
    {
        if(entity instanceof EntityPlayer)
        {
            List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(32D, 32D, 32D));
            for(int j = 0; j < list.size(); j++)
            {
                Entity entity1 = (Entity)list.get(j);
                if(entity1 instanceof EntitySkeletonSword)
                {
                    EntitySkeletonSword entityskeletonsword= (EntitySkeletonSword)entity1;
                    entityskeletonsword.becomeAngryAt(entity);
                }
            }

            becomeAngryAt(entity);
        }
        return super.attackEntityFrom(entity, i);
    }

    private void becomeAngryAt(Entity entity)
    {
        playerToAttack = entity;
        angerLevel = 400 + rand.nextInt(400);
        randomSoundDelay = rand.nextInt(40);
    }


    protected String getLivingSound()
    {
        return "mob.skeleton";
    }

    protected String getHurtSound()
    {
        return "mob.skeletonhurt";
    }

    protected String getDeathSound()
    {
        return "mob.skeletonhurt";
    }

    protected int getDropItemId()
    {
        return Item.porkCooked.shiftedIndex;
    }

    public ItemStack getHeldItem()
    {
        return defaultHeldItem;
    }

    private int angerLevel;
    private int randomSoundDelay;
    private static final ItemStack defaultHeldItem;

    static 
    {
        defaultHeldItem = new ItemStack(Item.swordGold, 1);
    }
}
 

Mack

Architecte en herbe
3 Juin 2011
123
5
124
C'est bon, suffisait de mettre extend EntityZombie au lieu de EntityMob ^^.


Et pour les autres questions ?
 

Mack

Architecte en herbe
3 Juin 2011
123
5
124
Mack a dit:
Mack a dit:
Bon, j'ai finalement réussis mes problème de la page précédente.
Mais maintenant, j'en ai une autre :
Comment faire pour utiliser une planche de sprite ?
Parce que pour l'instant, j'ai une image par objets ...
J'ai pas beaucoup d'objet, mais bon, j'aimerai bien tout mettre sur une seule image.

De plus, j'ai une seconde question :
Comment faire pour que le bloc s'oriente comme un piston ?
En gros, suivant comment le joueur place le bloc, je voudrais que ce dernier s'oriente de certaine façon. ( En gros, c'est vraiment comme le piston que je voudrais ... )
J'ai beau chercher, je trouve pas ...
Dans le même genre, comment faire pour donner une texture "custom" à un bloc à l'interrieur de celui ci ?
En gros, comment faire pour qu'une seule de ses faces et un côté custom ?
Si on le veux pas custom il suffit de faire un truc comme ça :
Code:
 public int getBlockTextureFromSideAndMetadata(int i, int j)
    {
        if(i == 1)
        {
            return 1;
        }
        else
        {
            return blockIndexInTexture;
        }
    }
Et le bloc du dessus est pas le même, mais il doit resté dans Terrain.png. Comment faire pour prendre l'image à autre part ?
Et comment savoir quelle est la direction du bloc ?

Et autre question :
Comment faire pour activer des trucs seulement si le bloc et parcourut par du courant ?
Enfin, plus exactement, je voudrais faire que si le bloc reçoit du courant redstone, un truc se passe une seule fois. Et dès que le courant passe plus, un au truc se passe ( Une seule fois aussi. )
J'ai bien essayer un truc du genre :
Code:
public void updateTick(World world, int i, int j, int k, Random random)
	{
		super.updateTick(world, i, j, k, random);
		int id_bloc = world.getBlockId(i, j-1, k);
		if (world.isBlockIndirectlyGettingPowered(i, j, k))
		{
			if ( id_bloc == 0 )
			{
				int block = 203;//Block.wood.blockID;
				world.setBlockWithNotify(i,j-1,k,block);
				if ( world.isAirBlock(i,j-2,k) )
				{
					world.setBlockWithNotify(i,j-2,k,block);
					
					if ( world.isAirBlock(i,j-3,k) )
					{
						world.setBlockWithNotify(i,j-3,k,block);
					}
				}
			}
		}
		else
		{
			if ( id_bloc == 203 )
			{
				int block = 0;

				world.setBlockWithNotify(i,j-1,k,block);
				
				id_bloc = world.getBlockId(i, j-2, k);
				if ( id_bloc == 203 )
				{
					world.setBlockWithNotify(i,j-2,k,block);
					
					id_bloc = world.getBlockId(i, j-3, k);
					if ( id_bloc == 203 )
					{
						world.setBlockWithNotify(i,j-3,k,block);
					}
				}
			}
		}
	}
Mais y a rien qui se passe ...

Merci d'avance.


EDIT : C'est bon pour la redstone j'ai réussis