-
Bonjour, j’ai créer une dynamite en m’aidant du tuto qui est sur le forum, elle fonctionne mais elle ne fais pas qu’une seule explosion, elle en fais énormément ( donc fais des trous énormes). Comment je peux modifier ça ?
La class EntityDynamite:
package com.hybride.mod.init; import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData; import io.netty.buffer.ByteBuf; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.projectile.EntityThrowable; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; public class EntityDynamite extends EntityThrowable implements IEntityAdditionalSpawnData { private int fuseTime = 20; public EntityDynamite(World world) { super(world); } public EntityDynamite(World world, EntityLivingBase thrower) { super(world,thrower); } protected void onImpact(MovingObjectPosition mop) { this.motionX = 0; this.motionY = 0; this.motionZ = 0; } public void onUpdate() { super.onUpdate(); if(fuseTime > 0) { this.fuseTime --; } else if (!this.worldObj.isRemote) { this.worldObj.newExplosion(this, this.posX, this.posY, this.posZ, 2.0F, false, true); } } @Override public void writeSpawnData(ByteBuf buffer) { buffer.writeInt(this.fuseTime); buffer.writeDouble(this.motionX); buffer.writeDouble(this.motionY); buffer.writeDouble(this.motionZ); } @Override public void readSpawnData(ByteBuf additionalData) { this.fuseTime = additionalData.readInt(); this.motionX = additionalData.readDouble(); this.motionY = additionalData.readDouble(); this.motionZ = additionalData.readDouble(); } }La class DynamiteRender:
package com.hybride.mod.items; import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.entity.Entity; import net.minecraft.item.Item; import net.minecraft.util.IIcon; import net.minecraft.util.ResourceLocation; public class DynamiteRender extends Render{ private Item Dynamite; private int renderDynamite; public DynamiteRender(Item Dynamite, int RenderDynamite) { this.Dynamite = Dynamite; this.renderDynamite = RenderDynamite; } public DynamiteRender(Item Dynamite){ this(Dynamite,0); } @Override public void doRender(Entity entity, double x, double y, double z, float p_76986_8_, float p_76986_9_) { IIcon icon = this.Dynamite.getIconFromDamage(this.renderDynamite); } @Override protected ResourceLocation getEntityTexture(Entity entity) { return TextureMap.locationItemsTexture; } }Et la class Dynamite:
package com.hybride.mod.init; import com.hybride.mod.HybrideMod; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class Dynamite extends Item{ public Dynamite() { this.setMaxStackSize(64); this.setCreativeTab(HybrideMod.HybrideMod); } public ItemStack onItemRightClick(ItemStack stack ,World world, EntityPlayer player){ world.playSoundAtEntity(player, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); if(!world.isRemote){ world.spawnEntityInWorld(new EntityDynamite(world, player)); stack.stackSize--; } return stack; } }merci.
-
Mets ta ligne d’explosion à l’impact.
C’est plus cohérent non ?Car là c’est normal que ça explose plein de fois c’est dans une fonction d’
update…Et puis baisse la valeur de puissance de ton explosion aussi.
-
en fait, utilise ce code pour la classe de ton entité:
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_70227_1_) { this.worldObj.spawnParticle("smoke", this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D); this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 2.0F, true); if (!this.worldObj.isRemote) { this.setDead(); } } }le 2.0F est la valeur a modif pour la taille
-
Bonsoir, s’il veut une tnt qui explose au bout d’un certains temps et non à l’impacte c’est normal d’avoir l’explosion dans update. Ce qui manque, c’est la fonction setDeath pour supprimer l’entité de dynamite lors de l’explosion …
-
Oui c’est bon. Je l’ai rajouté. Merci