Demande de l'aide d'un codeur expérimenté sur les mobs

  • Auteur de la discussion Auteur de la discussion iKlem
  • Date de début Date de début

iKlem

Aventurier
4 Juin 2011
94
0
1
32
iklem.livehost.fr
Bonjour.
Vous me connaissez sans doute comme étant le créateur de ce mod qui est en développement.
Je ne vient pas ici pour faire de la pub mais je vais avoir besoin de personnes pour m'aider à "faire avancer le minecart" (tiens pas mal l'expression x) ).
En gros voila mon problème :

Sur mon mod Rabbids, j'ai des lapins apprivoisés, et je souhaiterai qu'ils se comportent comme les loups, ceci ne sera qu'un stade de test, pour qu'ensuite je modifie en conséquence le code. J'ai donc "copier" le code du fichier EntityWolf.java, vers mon EntityRabbids.java.
Donc, si on réfléchit bien, le lapin doit se comporter comme un loups. Mais lors des test, le lapin est apprivoisable, mais il ne me défend pas, lorsque je me fait attaquer, et il n'attaque lorsque je lui demande.

Donc je poste ici, le code du fichier "EntityRabbids.java", qui bien sur ne sert qu'à aider ceux qui peuvent m'aider.

Code:
package net.minecraft.src;

/*import java.util.List;
import java.util.Random;*/
import java.util.*;

public class EntityRabbids extends EntityCreature
{

   public EntityRabbids(World world)
   {
      super(world);
      looksWithInterest = false;
      texture = "/mob/Rabbids/rabbids.png";
      moveSpeed = 1.3F;
      health = 10;
   }
//--   
   protected void entityInit()
   {
       super.entityInit();
       dataWatcher.addObject(16, Byte.valueOf((byte)0));
       dataWatcher.addObject(17, "");
       dataWatcher.addObject(18, new Integer(health));
   }
//--
   public String getEntityTexture()
   {
	   if(isRabbidsTamed())
       {
    	   return "/mob/Rabbids/rabbidstamed.png";
       }
       if(isRabbidsAngry())
       {
            return "/mob/Rabbids/rabbidsangry.png";
       }else
       {
    	   return super.getEntityTexture();
       }
   }
//--   
   public void writeEntityToNBT(NBTTagCompound nbttagcompound)
   {
       super.writeEntityToNBT(nbttagcompound);
       nbttagcompound.setBoolean("Angry", isRabbidsAngry());
       nbttagcompound.setBoolean("Sitting", isRabbidsSitting());
       if(getRabbidsOwner() == null)
       {
           nbttagcompound.setString("Owner", "");
       } else
       {
           nbttagcompound.setString("Owner", getRabbidsOwner());
       }
   }
//--
   public void readEntityFromNBT(NBTTagCompound nbttagcompound)
   {
       super.readEntityFromNBT(nbttagcompound);
       setRabbidsAngry(nbttagcompound.getBoolean("Angry"));
       setRabbidsSitting(nbttagcompound.getBoolean("Sitting"));
       String s = nbttagcompound.getString("Owner");
       if(s.length() > 0)
       {
           setRabbidsOwner(s);
           setRabbidsTamed(true);
       }
   }
//--   
   protected boolean canDespawn()
   {
       return !isRabbidsTamed();
   }
//--   
   protected String getLivingSound()
   {
       if(isRabbidsAngry())
       {
           return "Rabbids.bwah";
       }
       if(rand.nextInt(3) == 0)
       {
           if(isRabbidsTamed() && dataWatcher.getWatchableObjectInt(18) < 10)
           {
               return "Rabbids.normal";
           }
       } else
       {
           return "Rabbids.normal";
       }
   }
 //--
	protected String getHurtSound()
	{
		return "Rabbids.bwah";
	}
	//--
	protected String getDeathSound()
	{
		return "Rabbids.dead";
	}
//--	
	protected float getSoundVolume()
	{
	   return 0.5F;
	}
//--
	protected int getDropItemId()
	{
		return -1;
	}
//--	
	protected void updatePlayerActionState()
    {
        super.updatePlayerActionState();
        if(!hasAttacked && !hasPath() && isRabbidsTamed() && ridingEntity == null)
        {
            EntityPlayer entityplayer = worldObj.getPlayerEntityByName(getRabbidsOwner());
            if(entityplayer != null)
            {
                float f = entityplayer.getDistanceToEntity(this);
                if(f > 5F)
                {
                    getPathOrWalkableBlock(entityplayer, f);
                }
            } else
            if(!isInWater())
            {
                setRabbidsSitting(true);
            } 
        } else
        if(playerToAttack == null && !hasPath() && !isRabbidsTamed() && worldObj.rand.nextInt(100) == 0)
        {
            List list = worldObj.getEntitiesWithinAABB(net.minecraft.src.EntityCow.class, AxisAlignedBB.getBoundingBoxFromPool(posX, posY, posZ, posX + 1.0D, posY + 1.0D, posZ + 1.0D).expand(16D, 4D, 16D));
            if(!list.isEmpty())
            {
                setTarget((Entity)list.get(worldObj.rand.nextInt(list.size())));
                worldObj.playSoundAtEntity(this, "Rabbids.bwah", getSoundVolume() * 1.0F, ((rand.nextFloat() - rand.nextFloat()) * 0.2F + 1.0F) * 1.0F);
            }
        }
        if(playerToAttack == null && !hasPath() && !isRabbidsTamed() && worldObj.rand.nextInt(200) == 0)
        {
            List list = worldObj.getEntitiesWithinAABB(net.minecraft.src.EntityPig.class, AxisAlignedBB.getBoundingBoxFromPool(posX, posY, posZ, posX + 1.0D, posY + 1.0D, posZ + 1.0D).expand(16D, 4D, 16D));
            if(!list.isEmpty())
            {
                setTarget((Entity)list.get(worldObj.rand.nextInt(list.size())));
                worldObj.playSoundAtEntity(this, "Rabbids.bwah", getSoundVolume() * 1.0F, ((rand.nextFloat() - rand.nextFloat()) * 0.2F + 1.0F) * 1.0F);
            }
        } 
        if(playerToAttack == null && !hasPath() && !isRabbidsTamed() && worldObj.rand.nextInt(300) == 0)
        {
            List list = worldObj.getEntitiesWithinAABB(net.minecraft.src.EntityChicken.class, AxisAlignedBB.getBoundingBoxFromPool(posX, posY, posZ, posX + 1.0D, posY + 1.0D, posZ + 1.0D).expand(16D, 4D, 16D));
            if(!list.isEmpty())
            {
                setTarget((Entity)list.get(worldObj.rand.nextInt(list.size())));
                worldObj.playSoundAtEntity(this, "Rabbids.bwah", getSoundVolume() * 1.0F, ((rand.nextFloat() - rand.nextFloat()) * 0.2F + 1.0F) * 1.0F);
            }
        }
        if(playerToAttack == null && !hasPath() && !isRabbidsTamed() && worldObj.rand.nextInt(400) == 0)
        {
            List list = worldObj.getEntitiesWithinAABB(net.minecraft.src.EntitySheep.class, AxisAlignedBB.getBoundingBoxFromPool(posX, posY, posZ, posX + 1.0D, posY + 1.0D, posZ + 1.0D).expand(16D, 4D, 16D));
            if(!list.isEmpty())
            {
                setTarget((Entity)list.get(worldObj.rand.nextInt(list.size())));
                worldObj.playSoundAtEntity(this, "Rabbids.bwah", getSoundVolume() * 1.0F, ((rand.nextFloat() - rand.nextFloat()) * 0.2F + 1.0F) * 1.0F);
            }
        }
        if(playerToAttack == null && !hasPath() && !isRabbidsTamed() && worldObj.rand.nextInt(500) == 0)
        {
            List list = worldObj.getEntitiesWithinAABB(net.minecraft.src.EntityWolf.class, AxisAlignedBB.getBoundingBoxFromPool(posX, posY, posZ, posX + 1.0D, posY + 1.0D, posZ + 1.0D).expand(16D, 4D, 16D));
            if(!list.isEmpty())
            {
                setTarget((Entity)list.get(worldObj.rand.nextInt(list.size())));
                worldObj.playSoundAtEntity(this, "Rabbids.bwah", getSoundVolume() * 1.0F, ((rand.nextFloat() - rand.nextFloat()) * 0.2F + 1.0F) * 1.0F);
            }
        }
        if(isInWater())
        {
            setRabbidsSitting(false);
        }
        if(!worldObj.multiplayerWorld)
        {
            dataWatcher.updateObject(18, Integer.valueOf(health));
        }
    }
//--
	public void onLivingUpdate()
	{
		super.onLivingUpdate();
		looksWithInterest = false;
		if(hasCurrentTarget() && !hasPath() && !isRabbidsAngry())
		{
			Entity entity = getCurrentTarget();
			if(entity instanceof EntityPlayer)
			{
				EntityPlayer entityplayer = (EntityPlayer)entity;
				ItemStack itemstack = entityplayer.inventory.getCurrentItem();
				if(itemstack != null)
				{
					if(!isRabbidsTamed() && itemstack.itemID == Item.stick.shiftedIndex)
					{
						looksWithInterest = true;
					} else
						if(isRabbidsTamed() && (Item.itemsList[itemstack.itemID] instanceof ItemFood))
						{
							looksWithInterest = ((ItemFood)Item.itemsList[itemstack.itemID]).getIsWolfsFavoriteMeat();
						}
					}
				}
			}
		}
//--
    public void onUpdate()
    {
        super.onUpdate();
        field_25054_c = field_25048_b;
        if(looksWithInterest)
        {
            field_25048_b = field_25048_b + (1.0F - field_25048_b) * 0.4F;
        } else
        {
            field_25048_b = field_25048_b + (0.0F - field_25048_b) * 0.4F;
        }
        if(looksWithInterest)
        {
            numTicksToChaseTarget = 10;
        }
    }
//--
    public float getInterestedAngle(float f)
    {
        return (field_25054_c + (field_25048_b - field_25054_c) * f) * 0.15F * 3.141593F;
    }
//--    
    protected int func_25026_x()
    {
        if(isRabbidsSitting())
        {
            return 20;
        } else
        {
            return super.func_25026_x();
        }
    }
//--
    private void getPathOrWalkableBlock(Entity entity, float f)
    {
        PathEntity pathentity = worldObj.getPathToEntity(this, entity, 16F);
        if(pathentity == null && f > 12F)
        {
            int i = MathHelper.floor_double(entity.posX) - 2;
            int j = MathHelper.floor_double(entity.posZ) - 2;
            int k = MathHelper.floor_double(entity.boundingBox.minY);
            for(int l = 0; l <= 4; l++)
            {
                for(int i1 = 0; i1 <= 4; i1++)
                {
                    if((l < 1 || i1 < 1 || l > 3 || i1 > 3) && worldObj.func_28100_h(i + l, k - 1, j + i1) && !worldObj.func_28100_h(i + l, k, j + i1) && !worldObj.func_28100_h(i + l, k + 1, j + i1))
                    {
                        setLocationAndAngles((float)(i + l) + 0.5F, k, (float)(j + i1) + 0.5F, rotationYaw, rotationPitch);
                        return;
                    }
                }

            }

        } else
        {
            setPathToEntity(pathentity);
        }
    }
//--	
    protected boolean isMovementCeased()
    {
        return isRabbidsSitting() || field_25052_g;
    }
//--    
    public boolean attackEntityFrom(Entity entity, int i)
    {
        setRabbidsSitting(false);
        if(entity != null && !(entity instanceof EntityPlayer) && !(entity instanceof EntityArrow))
        {
            i = (i + 1) / 2;
        }
        if(super.attackEntityFrom(entity, i))
        {
            if(!isRabbidsTamed() && !isRabbidsAngry())
            {
                if(entity instanceof EntityPlayer)
                {
                    setRabbidsAngry(true);
                    playerToAttack = entity;
                }
                if((entity instanceof EntityArrow) && ((EntityArrow)entity).owner != null)
                {
                    entity = ((EntityArrow)entity).owner;
                }
                if(entity instanceof EntityLiving)
                {
                    List list = worldObj.getEntitiesWithinAABB(net.minecraft.src.EntityRabbids.class, AxisAlignedBB.getBoundingBoxFromPool(posX, posY, posZ, posX + 1.0D, posY + 1.0D, posZ + 1.0D).expand(16D, 4D, 16D));
                    Iterator iterator = list.iterator();
                    do
                    {
                        if(!iterator.hasNext())
                        {
                            break;
                        }
                        Entity entity1 = (Entity)iterator.next();
                        EntityRabbids entityrabbids = (EntityRabbids)entity1;
                        if(!entityrabbids.isRabbidsTamed() && entityrabbids.playerToAttack == null)
                        {
                            entityrabbids.playerToAttack = entity;
                            if(entity instanceof EntityPlayer)
                            {
                                entityrabbids.setRabbidsAngry(true);
                            }
                        }
                    } while(true);
                }
            } else
            if(entity != this && entity != null)
            {
                if(isRabbidsTamed() && (entity instanceof EntityPlayer) && ((EntityPlayer)entity).username.equalsIgnoreCase(getRabbidsOwner()))
                {
                    return true;
                }
                playerToAttack = entity;
            }
            return true;
        } else
        {
            return false;
        }
    }
//--
    protected Entity findPlayerToAttack()
    {
        if(isRabbidsAngry())
        {
            return worldObj.getClosestPlayerToEntity(this, 16D);
        } else
        {
            return null;
        }
    }
//--
   protected void attackEntity(Entity entity, float f)
   {
       if(f > 2.0F && f < 6F && rand.nextInt(10) == 0)
       {
           if(onGround)
           {
               double d = entity.posX - posX;
               double d1 = entity.posZ - posZ;
               float f1 = MathHelper.sqrt_double(d * d + d1 * d1);
               motionX = (d / (double)f1) * 0.5D * 0.80000001192092896D + motionX * 0.20000000298023224D;
               motionZ = (d1 / (double)f1) * 0.5D * 0.80000001192092896D + motionZ * 0.20000000298023224D;
               motionY = 0.40000000596046448D;
           }
       } else
       if((double)f < 1.5D && entity.boundingBox.maxY > boundingBox.minY && entity.boundingBox.minY < boundingBox.maxY)
       {
           attackTime = 20;
           byte byte0 = 2;
           if(isRabbidsTamed())
           {
               byte0 = 4;
           }
           entity.attackEntityFrom(this, byte0);
       }
   }
//--
   public boolean interact(EntityPlayer entityplayer)
   {
       ItemStack itemstack = entityplayer.inventory.getCurrentItem();
       if(!isRabbidsTamed())
       {
           if(itemstack != null && itemstack.itemID == Item.stick.shiftedIndex && !isRabbidsAngry())
           {
               itemstack.stackSize--;
               if(itemstack.stackSize <= 0)
               {
                   entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, null);
               }
               if(!worldObj.multiplayerWorld)
               {
                   if(rand.nextInt(3) == 0)
                   {
                       setRabbidsTamed(true);
                       setPathToEntity(null);
                       setRabbidsSitting(true);
                       health = 10;
                       setRabbidsOwner(entityplayer.username);
                       showHeartsOrSmokeFX(true);
                       worldObj.func_9425_a(this, (byte)7);
                   } else
                   {
                       showHeartsOrSmokeFX(false);
                       worldObj.func_9425_a(this, (byte)6);
                   }
               }
               return true;
           }
       } else
       {
           if(itemstack != null && (Item.itemsList[itemstack.itemID] instanceof ItemFood))
           {
               ItemFood itemfood = (ItemFood)Item.itemsList[itemstack.itemID];
               if(itemfood.getIsWolfsFavoriteMeat() && dataWatcher.getWatchableObjectInt(18) < 20)
               {
                   itemstack.stackSize--;
                   if(itemstack.stackSize <= 0)
                   {
                       entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, null);
                   }
                   heal(((ItemFood)Item.porkRaw).getHealAmount());
                   return true;
               }
           }
           if(entityplayer.username.equalsIgnoreCase(getRabbidsOwner()))
           {
        	   if(!worldObj.multiplayerWorld)
               {
                   setRabbidsSitting(!isRabbidsSitting());
                   isJumping = false;
                   setPathToEntity(null);
               }
               return true;
           }
       }
       return false;
   }
//--
   void showHeartsOrSmokeFX(boolean flag)
   {
       String s = "heart";
       if(!flag)
       {
           s = "smoke";
       }
       for(int i = 0; i < 7; i++)
       {
           double d = rand.nextGaussian() * 0.02D;
           double d1 = rand.nextGaussian() * 0.02D;
           double d2 = rand.nextGaussian() * 0.02D;
           worldObj.spawnParticle(s, (posX + (double)(rand.nextFloat() * width * 2.0F)) - (double)width, posY + 0.5D + (double)(rand.nextFloat() * height), (posZ + (double)(rand.nextFloat() * width * 2.0F)) - (double)width, d, d1, d2);
       }

   }
//--
   public void handleHealthUpdate(byte byte0)
   {
       if(byte0 == 7)
       {
           showHeartsOrSmokeFX(true);
       } else
       if(byte0 == 6)
       {
           showHeartsOrSmokeFX(false);
       } else
       {
           super.handleHealthUpdate(byte0);
       }
   }
//--
	public int getMaxSpawnedInChunk()
	{
		return 10;
	}
//--
	public String getRabbidsOwner()
	   {
	       return dataWatcher.getWatchableObjectString(17);
	   }
	   
	   public void setRabbidsOwner(String s)
	   {
	       dataWatcher.updateObject(17, s);
	   }
//--
	   public boolean isRabbidsSitting()
	   {
	       return (dataWatcher.getWatchableObjectByte(16) & 1) != 0;
	   }

	   public void setRabbidsSitting(boolean flag)
	   {
	       byte byte0 = dataWatcher.getWatchableObjectByte(16);
	       if(flag)
	       {
	           dataWatcher.updateObject(16, Byte.valueOf((byte)(byte0 | 1)));
	       } else
	       {
	           dataWatcher.updateObject(16, Byte.valueOf((byte)(byte0 & -2)));
	       }
	   }
//--
	   public boolean isRabbidsAngry()
	   {
		   return (dataWatcher.getWatchableObjectByte(16) & 2) != 0;	   
	   }

	   public void setRabbidsAngry(boolean flag)
	   {
		   byte byte0 = dataWatcher.getWatchableObjectByte(16);
		   if(flag)
		   {
			   dataWatcher.updateObject(16, Byte.valueOf((byte)(byte0 | 2)));
		   } else
		   {
			   dataWatcher.updateObject(16, Byte.valueOf((byte)(byte0 & -3)));
		   }
	   }
//--
	   public boolean isRabbidsTamed()
	   {
	       return (dataWatcher.getWatchableObjectByte(16) & 4) != 0;
	   }

	   public void setRabbidsTamed(boolean flag)
	   {
	       byte byte0 = dataWatcher.getWatchableObjectByte(16);
	       if(flag)
	       {
	           dataWatcher.updateObject(16, Byte.valueOf((byte)(byte0 | 4)));
	       } else
	       {
	           dataWatcher.updateObject(16, Byte.valueOf((byte)(byte0 & -5)));
	       }
	   }
//--
	   //lookwithinterest code
//--	  
   public boolean getCanSpawnHere()
   {
            if(worldObj.countEntities(this.getClass()) >= 25){
           return false;
       }
       int i = MathHelper.floor_double(posX);
       int j = MathHelper.floor_double(boundingBox.minY);
       int k = MathHelper.floor_double(posZ);
       int l = worldObj.getBlockId(i, j - 1, k);
       return worldObj.difficultySetting > 0 && worldObj.checkIfAABBIsClear(boundingBox) && worldObj.getCollidingBoundingBoxes(this, boundingBox).size() == 0 && !worldObj.getIsAnyLiquid(boundingBox);
   }

//---------------
 private boolean looksWithInterest;
 private float field_25048_b;
 private float field_25054_c;
 private boolean field_25052_g;
 private int randomSoundDelay;
 
}

Je remercie d'avance ceux qui parviendront à m'aider.