Faire un double extends



  • Bonjour, pour faire ma "Dynamite", j'ai besoin d'extends la classe EntityThrowable pour la lancer mais aussi la classe Entity pour la faire exploser. comment faire ?



  • ok j ai trouver un bout de code qui devrais te servir

    package flaxbeard.dynamite.entity;
    
    import cpw.mods.fml.common.network.PacketDispatcher;
    import cpw.mods.fml.relauncher.Side;
    import cpw.mods.fml.relauncher.SideOnly;
    
    import java.io.ByteArrayOutputStream;
    import java.io.DataOutputStream;
    import java.util.List;
    
    import flaxbeard.dynamite.DynamiteMod;
    import net.minecraft.block.Block;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.EntityLiving;
    import net.minecraft.entity.IProjectile;
    import net.minecraft.entity.item.EntityItem;
    import net.minecraft.entity.monster.EntityBlaze;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.projectile.EntityThrowable;
    import net.minecraft.item.ItemStack;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.network.packet.Packet250CustomPayload;
    import net.minecraft.util.AxisAlignedBB;
    import net.minecraft.util.DamageSource;
    import net.minecraft.util.EnumMovingObjectType;
    import net.minecraft.util.MathHelper;
    import net.minecraft.util.MovingObjectPosition;
    import net.minecraft.util.Vec3;
    import net.minecraft.world.World;
    
    public class EntityDynamite extends EntityThrowable
    {
    	boolean stopped = false;
    	boolean bounce = false;
    	public int type = 0;
    	int fuse;
    	
    	public EntityDynamite(World par1World) {
    		super(par1World);
    		
    	}
    	public EntityDynamite(World par1World, double x, double y, double z, float yaw, float pitch, double force, int fuseLength, int ty) {
    		super(par1World);
    		this.setRotation(yaw, 0);
    		System.out.println(yaw);
    		System.out.println(pitch);
            double xHeading = -MathHelper.sin((yaw * 3.141593F) / 180F);
            double zHeading = MathHelper.cos((yaw * 3.141593F) / 180F);
            motionX = force*xHeading*MathHelper.cos((pitch / 180F) * 3.141593F);
            motionY = -force*MathHelper.sin((pitch / 180F) * 3.141593F);
            motionZ = force*zHeading*MathHelper.cos((pitch / 180F) * 3.141593F);
    
            setPosition(x+xHeading*0.8, y+1.5, z+zHeading*0.8);
            prevPosX = posX;
            prevPosY = posY;
            prevPosZ = posZ;
     
            fuse = fuseLength;
            type = ty;
            System.out.println(type);
    	}
    	
    	public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
    	{
    		return false;
    	}
    	
        public EntityDynamite(World world, Entity entity, double force, int ty)
        {
            this(world, entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch, force, 50, ty);
        }
        
        public void onUpdate()
        {
            if(fuse-- <= 0)
            {
            	if (!worldObj.isRemote) {
            	
            	worldObj.createExplosion(null, posX, posY, posZ, 2.0F, true);
                this.setDead();
            	}
                
            }
            if(stopped && !worldObj.isRemote) {
                ByteArrayOutputStream bos = new ByteArrayOutputStream(7);
                DataOutputStream outputStream = new DataOutputStream(bos);
                try
                {
                    outputStream.writeByte(1);
                    outputStream.writeInt(this.entityId);
                    outputStream.writeInt((int) posX);
                    outputStream.writeInt((int) posY);
                    outputStream.writeInt((int) posZ);
                }
                catch (Exception ex)
                {
                    ex.printStackTrace();
                }
                Packet250CustomPayload packet = new Packet250CustomPayload();
                packet.channel = "DynamiteMod";
                packet.data = bos.toByteArray();
                packet.length = bos.size();
                PacketDispatcher.sendPacketToAllAround(posX, posY, posZ, 50, worldObj.provider.dimensionId, packet);
            }
            if(!(stopped))
            {
                    double prevVelX = motionX;
                    double prevVelY = motionY;
                    double prevVelZ = motionZ;
                    prevPosX = posX;
                    prevPosY = posY;
                    prevPosZ = posZ;
                    moveEntity(motionX, motionY, motionZ);
             
                    boolean collided = false;
                            
                    if(motionX!=prevVelX)
                    {
                    		if (type == 1) {
                    			stopped = true;
                                motionX = 0;
                                motionY = 0;
                                motionZ = 0;
                    		}
                    		else
                    		{
                            motionX = -0.5*prevVelX;
                            collided = true;
                    		}
                    }
                    if(motionZ!=prevVelZ)
                    {
    	            		if (type == 1) {
    	            			stopped = true;
    	                        motionX = 0;
    	                        motionY = 0;
    	                        motionZ = 0;
    	            		}
    	            		else
    	            		{
                            motionZ = -0.5*prevVelZ;
    	            		}
                    }
             
                    if(motionY!=prevVelY)
                    {
    	            		if (type == 1) {
    	            			stopped = true;
    	                        motionX = 0;
    	                        motionY = 0;
    	                        motionZ = 0;
    	            		}
    	            		else
    	            		{
                            motionY = -prevVelY;
                            collided = true;   
    	            		}
                    }
                    else
                    {
                            motionY -= 0.04;
                    }
             
                    if(collided)
                    {
    						motionX *= 0.5;
                            motionY *= 0.1;
                            motionZ *= 0.5;
                    }
             
                    motionX *= 0.99;
                    motionY *= 0.99;
                    motionZ *= 0.99;
                    System.out.println(Boolean.toString(worldObj.isRemote) + Integer.toString(entityId));
                    if(onGround && (motionX*motionX+motionY*motionY+motionZ*motionZ)<0.02)
                    {
                            stopped = true;
                            motionX = 0;
                            motionY = 0;
                            motionZ = 0;
                    }
            }
        }
    
    	@Override
    	protected void onImpact(MovingObjectPosition movingobjectposition) {
    		// TODO Auto-generated method stub
    		
    	}
    	public void stop(int x, int y, int z) {
    		stopped = true;
    		this.posX = x;
    		this.posY = y;
    		this.posZ = z;
    		System.out.println("i trai to stop but i fal.");
    	}
    
    	
      
    }
    


  • Par hasard, est-ce-que EntityThrowable extends Entity ?
    Si c'est le cas, tu as juste à faire un extends EntityThrowable !



  • oui mais si je met

    private void explode()
                {
                    float f = 4.0F;
                    this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, f, true);
                }
    

    ca me met une erreur : the method explode is undefined for the type "maclasse"

    package com.extremium.mod.entity;
    
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.EntityLivingBase;
    import net.minecraft.entity.monster.EntityBlaze;
    import net.minecraft.entity.projectile.EntityThrowable;
    import net.minecraft.util.DamageSource;
    import net.minecraft.util.MovingObjectPosition;
    import net.minecraft.world.World;
    
    public class DynamiteEntity extends EntityThrowable
    {
        private static final String __OBFID = "CL_00001722";
    
        public DynamiteEntity(World p_i1773_1_)
        {
            super(p_i1773_1_);
        }
    
        public DynamiteEntity(World p_i1774_1_, EntityLivingBase p_i1774_2_)
        {
            super(p_i1774_1_, p_i1774_2_);
        }
    
        public DynamiteEntity(World p_i1775_1_, double p_i1775_2_, double p_i1775_4_, double p_i1775_6_)
        {
            super(p_i1775_1_, p_i1775_2_, p_i1775_4_, p_i1775_6_);
        }
    
        /**
         * Called when this EntityThrowable hits a block or entity.
         */
        protected void onImpact(MovingObjectPosition p_70184_1_)
        {
            if (p_70184_1_.entityHit != null)
            {
                byte b0 = 0;
                
    
                if (p_70184_1_.entityHit instanceof EntityBlaze)
                {
                    b0 = 3;
                }
    
                p_70184_1_.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)b0);
                
                private void explode()
                {
                    float f = 4.0F;
                    this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, f, true);
                }
            }
    
            for (int i = 0; i < 8; ++i)
            {
               
            }
    
            if (!this.worldObj.isRemote)
            {
                this.setDead();
            }
            
            
        }
    }
    
    
    


  • Ton

    private void explode()
    {
        float f = 4.0F;
        this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, f, true);
    }
    

    est mal placé (déjà dans une méthode de ta classe).
    Il n'y a pas une méthode qui fait la même chose et que tu pourrais appeler à la place ?



  • tu pourrais peut être regarder dans la classe de la Tnt ?



  • alors en fait g mis le explode alors que pas besoin. par contre, comment régler la taille de l'explosion ?



  • et bien il faut voir dans la classe de la Tnt
    je ne suis pas sur mais cette méthode peut etre utile

     public void onBlockDestroyedByExplosion(World p_149723_1_, int p_149723_2_, int p_149723_3_, int p_149723_4_, Explosion p_149723_5_)
        {
            if (!p_149723_1_.isRemote)
            {
                EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(p_149723_1_, (double)((float)p_149723_2_ + 0.5F), (double)((float)p_149723_3_ + 0.5F), (double)((float)p_149723_4_ + 0.5F), p_149723_5_.getExplosivePlacedBy());
                entitytntprimed.fuse = p_149723_1_.rand.nextInt(entitytntprimed.fuse / 4) + entitytntprimed.fuse / 8;
                p_149723_1_.spawnEntityInWorld(entitytntprimed);
            }
        }
    


  • oui mais je netrouve pas 😞



  • je viens de te donner la soluce (peut etre)



  • @Heaven malheureusement la soluce n'y est pas



  • ok j ai trouver un bout de code qui devrais te servir

    package flaxbeard.dynamite.entity;
    
    import cpw.mods.fml.common.network.PacketDispatcher;
    import cpw.mods.fml.relauncher.Side;
    import cpw.mods.fml.relauncher.SideOnly;
    
    import java.io.ByteArrayOutputStream;
    import java.io.DataOutputStream;
    import java.util.List;
    
    import flaxbeard.dynamite.DynamiteMod;
    import net.minecraft.block.Block;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.EntityLiving;
    import net.minecraft.entity.IProjectile;
    import net.minecraft.entity.item.EntityItem;
    import net.minecraft.entity.monster.EntityBlaze;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.projectile.EntityThrowable;
    import net.minecraft.item.ItemStack;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.network.packet.Packet250CustomPayload;
    import net.minecraft.util.AxisAlignedBB;
    import net.minecraft.util.DamageSource;
    import net.minecraft.util.EnumMovingObjectType;
    import net.minecraft.util.MathHelper;
    import net.minecraft.util.MovingObjectPosition;
    import net.minecraft.util.Vec3;
    import net.minecraft.world.World;
    
    public class EntityDynamite extends EntityThrowable
    {
    	boolean stopped = false;
    	boolean bounce = false;
    	public int type = 0;
    	int fuse;
    	
    	public EntityDynamite(World par1World) {
    		super(par1World);
    		
    	}
    	public EntityDynamite(World par1World, double x, double y, double z, float yaw, float pitch, double force, int fuseLength, int ty) {
    		super(par1World);
    		this.setRotation(yaw, 0);
    		System.out.println(yaw);
    		System.out.println(pitch);
            double xHeading = -MathHelper.sin((yaw * 3.141593F) / 180F);
            double zHeading = MathHelper.cos((yaw * 3.141593F) / 180F);
            motionX = force*xHeading*MathHelper.cos((pitch / 180F) * 3.141593F);
            motionY = -force*MathHelper.sin((pitch / 180F) * 3.141593F);
            motionZ = force*zHeading*MathHelper.cos((pitch / 180F) * 3.141593F);
    
            setPosition(x+xHeading*0.8, y+1.5, z+zHeading*0.8);
            prevPosX = posX;
            prevPosY = posY;
            prevPosZ = posZ;
     
            fuse = fuseLength;
            type = ty;
            System.out.println(type);
    	}
    	
    	public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
    	{
    		return false;
    	}
    	
        public EntityDynamite(World world, Entity entity, double force, int ty)
        {
            this(world, entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch, force, 50, ty);
        }
        
        public void onUpdate()
        {
            if(fuse-- <= 0)
            {
            	if (!worldObj.isRemote) {
            	
            	worldObj.createExplosion(null, posX, posY, posZ, 2.0F, true);
                this.setDead();
            	}
                
            }
            if(stopped && !worldObj.isRemote) {
                ByteArrayOutputStream bos = new ByteArrayOutputStream(7);
                DataOutputStream outputStream = new DataOutputStream(bos);
                try
                {
                    outputStream.writeByte(1);
                    outputStream.writeInt(this.entityId);
                    outputStream.writeInt((int) posX);
                    outputStream.writeInt((int) posY);
                    outputStream.writeInt((int) posZ);
                }
                catch (Exception ex)
                {
                    ex.printStackTrace();
                }
                Packet250CustomPayload packet = new Packet250CustomPayload();
                packet.channel = "DynamiteMod";
                packet.data = bos.toByteArray();
                packet.length = bos.size();
                PacketDispatcher.sendPacketToAllAround(posX, posY, posZ, 50, worldObj.provider.dimensionId, packet);
            }
            if(!(stopped))
            {
                    double prevVelX = motionX;
                    double prevVelY = motionY;
                    double prevVelZ = motionZ;
                    prevPosX = posX;
                    prevPosY = posY;
                    prevPosZ = posZ;
                    moveEntity(motionX, motionY, motionZ);
             
                    boolean collided = false;
                            
                    if(motionX!=prevVelX)
                    {
                    		if (type == 1) {
                    			stopped = true;
                                motionX = 0;
                                motionY = 0;
                                motionZ = 0;
                    		}
                    		else
                    		{
                            motionX = -0.5*prevVelX;
                            collided = true;
                    		}
                    }
                    if(motionZ!=prevVelZ)
                    {
    	            		if (type == 1) {
    	            			stopped = true;
    	                        motionX = 0;
    	                        motionY = 0;
    	                        motionZ = 0;
    	            		}
    	            		else
    	            		{
                            motionZ = -0.5*prevVelZ;
    	            		}
                    }
             
                    if(motionY!=prevVelY)
                    {
    	            		if (type == 1) {
    	            			stopped = true;
    	                        motionX = 0;
    	                        motionY = 0;
    	                        motionZ = 0;
    	            		}
    	            		else
    	            		{
                            motionY = -prevVelY;
                            collided = true;   
    	            		}
                    }
                    else
                    {
                            motionY -= 0.04;
                    }
             
                    if(collided)
                    {
    						motionX *= 0.5;
                            motionY *= 0.1;
                            motionZ *= 0.5;
                    }
             
                    motionX *= 0.99;
                    motionY *= 0.99;
                    motionZ *= 0.99;
                    System.out.println(Boolean.toString(worldObj.isRemote) + Integer.toString(entityId));
                    if(onGround && (motionX*motionX+motionY*motionY+motionZ*motionZ)<0.02)
                    {
                            stopped = true;
                            motionX = 0;
                            motionY = 0;
                            motionZ = 0;
                    }
            }
        }
    
    	@Override
    	protected void onImpact(MovingObjectPosition movingobjectposition) {
    		// TODO Auto-generated method stub
    		
    	}
    	public void stop(int x, int y, int z) {
    		stopped = true;
    		this.posX = x;
    		this.posY = y;
    		this.posZ = z;
    		System.out.println("i trai to stop but i fal.");
    	}
    
    	
      
    }
    


  • merci, mais je ne sais toujours pas comment faire pour mettre un model + texture



  • la je ne pourrais pas t aider demande sur le discorde ou regarde dans la classe de le boule de neige jsp



  • @Heaven merci


Log in to reply