Résolu Grenade collante
-
Bonjour les gens,
Je me suis lancé dans le projet de pouvoir proposer de sympathiques grenades collantes.
Actuellement, je lance, ça colle et 2.5s après ça explose mais ce tant qu’une entité n’a pas été touché. Si c’est une entité qui est touchée alors la grenade **rebondit **lamentablement dessus et génère un magnifique lag de 2.5s xD.
Voici où en est rendu mon entité pour le moment::::
package fr.powergame.modpg.common; import java.util.List; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.command.IEntitySelector; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IProjectile; import net.minecraft.entity.monster.EntityEnderman; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.play.server.S2BPacketChangeGameState; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class EntitySticky extends Entity implements IProjectile { private int field_145791_d = -1; private int field_145792_e = -1; private int field_145789_f = -1; private Block field_145790_g; private int inData; private boolean inGround; public int canBePickedUp; public int arrowShake; public Entity shootingEntity; private int ticksInGround; private int ticksInAir; private double damage = 2.0D; private int knockbackStrength; private int timer = 0; public EntitySticky(World world) { super(world); this.renderDistanceWeight = 10.0D; this.setSize(0.5F, 0.5F); } public EntitySticky(World world, double x, double y, double z) { super(world); this.renderDistanceWeight = 10.0D; this.setSize(0.5F, 0.5F); this.setPosition(x, y, z); this.yOffset = 0.0F; } public EntitySticky(World world, EntityLivingBase player, EntityLivingBase target, float fl1, float fl2) { super(world); this.renderDistanceWeight = 10.0D; this.shootingEntity = player; if (player instanceof EntityPlayer) { this.canBePickedUp = 1; } this.posY = player.posY + (double)player.getEyeHeight() - 0.10000000149011612D; double d0 = target.posX - player.posX; double d1 = target.boundingBox.minY + (double)(target.height / 3.0F) - this.posY; double d2 = target.posZ - player.posZ; double d3 = (double)MathHelper.sqrt_double(d0 * d0 + d2 * d2); if (d3 >= 1.0E-7D) { float f2 = (float)(Math.atan2(d2, d0) * 180.0D / Math.PI) - 90.0F; float f3 = (float)(-(Math.atan2(d1, d3) * 180.0D / Math.PI)); double d4 = d0 / d3; double d5 = d2 / d3; this.setLocationAndAngles(player.posX + d4, this.posY, player.posZ + d5, f2, f3); this.yOffset = 0.0F; float f4 = (float)d3 * 0.2F; this.setThrowableHeading(d0, d1 + (double)f4, d2, fl1, fl2); } } public EntitySticky(World world, EntityLivingBase player, float fl) { super(world); this.renderDistanceWeight = 10.0D; this.shootingEntity = player; if (player instanceof EntityPlayer) { this.canBePickedUp = 1; } this.setSize(0.5F, 0.5F); this.setLocationAndAngles(player.posX, player.posY + (double)player.getEyeHeight(), player.posZ, player.rotationYaw, player.rotationPitch); this.posX -= (double)(MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F); this.posY -= 0.10000000149011612D; this.posZ -= (double)(MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F); this.setPosition(this.posX, this.posY, this.posZ); this.yOffset = 0.0F; this.motionX = (double)(-MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI)); this.motionZ = (double)(MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(this.rotationPitch / 180.0F * (float)Math.PI)); this.motionY = (double)(-MathHelper.sin(this.rotationPitch / 180.0F * (float)Math.PI)); this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, fl * 1.5F, 1.0F); } public void shouldRender3DInInventory(int modelId) { return; } protected void entityInit() { this.dataWatcher.addObject(16, Byte.valueOf((byte)0)); } public void setThrowableHeading(double x, double y, double z, float p_70186_7_, float p_70186_8_) { float f2 = MathHelper.sqrt_double(x * x + y * y + z * z); x /= (double)f2; y /= (double)f2; z /= (double)f2; x += this.rand.nextGaussian() * (double)(this.rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * (double)p_70186_8_; y += this.rand.nextGaussian() * (double)(this.rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * (double)p_70186_8_; z += this.rand.nextGaussian() * (double)(this.rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * (double)p_70186_8_; x *= (double)p_70186_7_; y *= (double)p_70186_7_; z *= (double)p_70186_7_; this.motionX = x; this.motionY = y; this.motionZ = z; float f3 = MathHelper.sqrt_double(x * x + z * z); this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(x, z) * 180.0D / Math.PI); this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(y, (double)f3) * 180.0D / Math.PI); this.ticksInGround = 0; } @SideOnly(Side.CLIENT) public void setPositionAndRotation2(double p_70056_1_, double p_70056_3_, double p_70056_5_, float p_70056_7_, float p_70056_8_, int p_70056_9_) { this.setPosition(p_70056_1_, p_70056_3_, p_70056_5_); this.setRotation(p_70056_7_, p_70056_8_); } @SideOnly(Side.CLIENT) public void setVelocity(double x, double y, double z) { this.motionX = x; this.motionY = y; this.motionZ = z; if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) { float f = MathHelper.sqrt_double(x * x + z * z); this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(x, z) * 180.0D / Math.PI); this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(y, (double)f) * 180.0D / Math.PI); this.prevRotationPitch = this.rotationPitch; this.prevRotationYaw = this.rotationYaw; this.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch); this.ticksInGround = 0; } } public void onUpdate() { super.onUpdate(); if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) { float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI); this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(this.motionY, (double)f) * 180.0D / Math.PI); } Block block = this.worldObj.getBlock(this.field_145791_d, this.field_145792_e, this.field_145789_f); if (block.getMaterial() != Material.air) { block.setBlockBoundsBasedOnState(this.worldObj, this.field_145791_d, this.field_145792_e, this.field_145789_f); AxisAlignedBB axisalignedbb = block.getCollisionBoundingBoxFromPool(this.worldObj, this.field_145791_d, this.field_145792_e, this.field_145789_f); if (axisalignedbb != null && axisalignedbb.isVecInside(Vec3.createVectorHelper(this.posX, this.posY, this.posZ))) { this.inGround = true; } } if (this.arrowShake > 0) { –this.arrowShake; } if (this.inGround) { int j = this.worldObj.getBlockMetadata(this.field_145791_d, this.field_145792_e, this.field_145789_f); if (block == this.field_145790_g && j == this.inData) { ++this.ticksInGround; if (!this.worldObj.isRemote && this.ticksInGround == 50) { this.worldObj.newExplosion((Entity) null, this.posX, this.posY, this.posZ, 4.5F, false, true); this.setDead(); IEntitySelector filter; filter = new IEntitySelector() { @Override public boolean isEntityApplicable(Entity entity) { if(entity instanceof EntityPlayer) { return true; } return false; } }; @SuppressWarnings("rawtypes") List entityTargetList = this.shootingEntity.worldObj.selectEntitiesWithinAABB(EntityLivingBase.class, this.shootingEntity.boundingBox.expand(3.0D, 2.0D, 3.0D), filter); for(Object entity1 : entityTargetList) { EntityLivingBase living = (EntityLivingBase)entity1; living.attackEntityFrom(DamageSource.generic, 10.0F); System.out.println("Il va faire tout noir!"); } } } else { this.inGround = false; this.motionX *= (double)(this.rand.nextFloat() * 0.2F); this.motionY *= (double)(this.rand.nextFloat() * 0.2F); this.motionZ *= (double)(this.rand.nextFloat() * 0.2F); this.ticksInGround = 0; this.ticksInAir = 0; } } else { ++this.ticksInAir; Vec3 vec31 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ); Vec3 vec3 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); MovingObjectPosition movingobjectposition = this.worldObj.func_147447_a(vec31, vec3, false, true, false); vec31 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ); vec3 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); if (movingobjectposition != null) { vec3 = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord); } Entity entity = null; @SuppressWarnings("rawtypes") List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D)); double d0 = 0.0D; int i; float f1; for (i = 0; i < list.size(); ++i) { Entity entity1 = (Entity)list.get(i); if (entity1.canBeCollidedWith() && (entity1 != this.shootingEntity || this.ticksInAir >= 5)) { f1 = 0.3F; AxisAlignedBB axisalignedbb1 = entity1.boundingBox.expand((double)f1, (double)f1, (double)f1); MovingObjectPosition movingobjectposition1 = axisalignedbb1.calculateIntercept(vec31, vec3); if (movingobjectposition1 != null) { double d1 = vec31.distanceTo(movingobjectposition1.hitVec); if (d1 < d0 || d0 == 0.0D) { entity = entity1; d0 = d1; } } } } if (entity != null) { movingobjectposition = new MovingObjectPosition(entity); } if (movingobjectposition != null && movingobjectposition.entityHit != null && movingobjectposition.entityHit instanceof EntityPlayer) { EntityPlayer entityplayer = (EntityPlayer)movingobjectposition.entityHit; if (entityplayer.capabilities.disableDamage || this.shootingEntity instanceof EntityPlayer && !((EntityPlayer)this.shootingEntity).canAttackPlayer(entityplayer)) { movingobjectposition = null; } } float f2; float f4; if (movingobjectposition != null) { if (movingobjectposition.entityHit != null) { f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ); int k = MathHelper.ceiling_double_int((double)f2 * this.damage); if (this.getIsCritical()) { k += this.rand.nextInt(k / 2 + 2); } DamageSource damagesource = null; if (this.shootingEntity == null) { damagesource = DamageSource.causeThrownDamage(this, this); } else { damagesource = DamageSource.causeThrownDamage(this, this.shootingEntity); } if (this.isBurning() && !(movingobjectposition.entityHit instanceof EntityEnderman)) { movingobjectposition.entityHit.setFire(5); } if (movingobjectposition.entityHit.attackEntityFrom(damagesource, (float)k)) { if (movingobjectposition.entityHit instanceof EntityLivingBase) { EntityLivingBase entitylivingbase = (EntityLivingBase)movingobjectposition.entityHit; if (!this.worldObj.isRemote) { for (int i1 = 0; i1 < 50; i1--) { this.timer --; } if (timer == 0) { // entitylivingbase.setArrowCountInEntity(entitylivingbase.getArrowCountInEntity() + 1); this.worldObj.newExplosion((Entity) null, this.posX, this.posY, this.posZ, 4.5F, false, true); this.setDead(); IEntitySelector filter; filter = new IEntitySelector() { @Override public boolean isEntityApplicable(Entity entity) { if(entity instanceof EntityPlayer) { return true; } return false; } }; @SuppressWarnings("rawtypes") List entityTargetList = this.shootingEntity.worldObj.selectEntitiesWithinAABB(EntityLivingBase.class, this.shootingEntity.boundingBox.expand(3.0D, 2.0D, 3.0D), filter); for(Object entity1 : entityTargetList) { EntityLivingBase living = (EntityLivingBase)entity1; living.attackEntityFrom(DamageSource.generic, 10.0F); System.out.println("Oups, toujours pas"); } } } if (this.knockbackStrength > 0) { f4 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); if (f4 > 0.0F) { movingobjectposition.entityHit.addVelocity(this.motionX * (double)this.knockbackStrength * 0.6000000238418579D / (double)f4, 0.1D, this.motionZ * (double)this.knockbackStrength * 0.6000000238418579D / (double)f4); } } if (this.shootingEntity != null && this.shootingEntity instanceof EntityLivingBase) { EnchantmentHelper.func_151384_a(entitylivingbase, this.shootingEntity); EnchantmentHelper.func_151385_b((EntityLivingBase)this.shootingEntity, entitylivingbase); } if (this.shootingEntity != null && movingobjectposition.entityHit != this.shootingEntity && movingobjectposition.entityHit instanceof EntityPlayer && this.shootingEntity instanceof EntityPlayerMP) { ((EntityPlayerMP)this.shootingEntity).playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(6, 0.0F)); } } this.playSound("random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F)); //Penser à mettre un son fun if (!(movingobjectposition.entityHit instanceof EntityEnderman)) { this.setDead(); } } else { this.motionX *= -0.10000000149011612D; this.motionY *= -0.10000000149011612D; this.motionZ *= -0.10000000149011612D; this.rotationYaw += 180.0F; this.prevRotationYaw += 180.0F; this.ticksInAir = 0; } } else { this.field_145791_d = movingobjectposition.blockX; this.field_145792_e = movingobjectposition.blockY; this.field_145789_f = movingobjectposition.blockZ; this.field_145790_g = this.worldObj.getBlock(this.field_145791_d, this.field_145792_e, this.field_145789_f); this.inData = this.worldObj.getBlockMetadata(this.field_145791_d, this.field_145792_e, this.field_145789_f); this.motionX = (double)((float)(movingobjectposition.hitVec.xCoord - this.posX)); this.motionY = (double)((float)(movingobjectposition.hitVec.yCoord - this.posY)); this.motionZ = (double)((float)(movingobjectposition.hitVec.zCoord - this.posZ)); f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ); this.posX -= this.motionX / (double)f2 * 0.05000000074505806D; this.posY -= this.motionY / (double)f2 * 0.05000000074505806D; this.posZ -= this.motionZ / (double)f2 * 0.05000000074505806D; this.playSound("random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F)); this.inGround = true; this.arrowShake = 7; this.setIsCritical(false); if (this.field_145790_g.getMaterial() != Material.air) { this.field_145790_g.onEntityCollidedWithBlock(this.worldObj, this.field_145791_d, this.field_145792_e, this.field_145789_f, this); } } } if (this.getIsCritical()) { for (i = 0; i < 4; ++i) { this.worldObj.spawnParticle("crit", this.posX + this.motionX * (double)i / 4.0D, this.posY + this.motionY * (double)i / 4.0D, this.posZ + this.motionZ * (double)i / 4.0D, -this.motionX, -this.motionY + 0.2D, -this.motionZ); } } this.posX += this.motionX; this.posY += this.motionY; this.posZ += this.motionZ; f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI); for (this.rotationPitch = (float)(Math.atan2(this.motionY, (double)f2) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) { ; } while (this.rotationPitch - this.prevRotationPitch >= 180.0F) { this.prevRotationPitch += 360.0F; } while (this.rotationYaw - this.prevRotationYaw < -180.0F) { this.prevRotationYaw -= 360.0F; } while (this.rotationYaw - this.prevRotationYaw >= 180.0F) { this.prevRotationYaw += 360.0F; } this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F; this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F; float f3 = 0.99F; f1 = 0.05F; if (this.isInWater()) { for (int l = 0; l < 4; ++l) { f4 = 0.25F; this.worldObj.spawnParticle("bubble", this.posX - this.motionX * (double)f4, this.posY - this.motionY * (double)f4, this.posZ - this.motionZ * (double)f4, this.motionX, this.motionY, this.motionZ); } f3 = 0.8F; } if (this.isWet()) { this.extinguish(); } this.motionX *= (double)f3; this.motionY *= (double)f3; this.motionZ *= (double)f3; this.motionY -= (double)f1; this.setPosition(this.posX, this.posY, this.posZ); this.func_145775_I(); } } public void writeEntityToNBT(NBTTagCompound p_70014_1_) { p_70014_1_.setShort("xTile", (short)this.field_145791_d); p_70014_1_.setShort("yTile", (short)this.field_145792_e); p_70014_1_.setShort("zTile", (short)this.field_145789_f); p_70014_1_.setShort("life", (short)this.ticksInGround); p_70014_1_.setByte("inTile", (byte)Block.getIdFromBlock(this.field_145790_g)); p_70014_1_.setByte("inData", (byte)this.inData); p_70014_1_.setByte("shake", (byte)this.arrowShake); p_70014_1_.setByte("inGround", (byte)(this.inGround ? 1 : 0)); p_70014_1_.setByte("pickup", (byte)this.canBePickedUp); p_70014_1_.setDouble("damage", this.damage); } public void readEntityFromNBT(NBTTagCompound p_70037_1_) { this.field_145791_d = p_70037_1_.getShort("xTile"); this.field_145792_e = p_70037_1_.getShort("yTile"); this.field_145789_f = p_70037_1_.getShort("zTile"); this.ticksInGround = p_70037_1_.getShort("life"); this.field_145790_g = Block.getBlockById(p_70037_1_.getByte("inTile") & 255); this.inData = p_70037_1_.getByte("inData") & 255; this.arrowShake = p_70037_1_.getByte("shake") & 255; this.inGround = p_70037_1_.getByte("inGround") == 1; if (p_70037_1_.hasKey("damage", 99)) { this.damage = p_70037_1_.getDouble("damage"); } if (p_70037_1_.hasKey("pickup", 99)) { this.canBePickedUp = p_70037_1_.getByte("pickup"); } else if (p_70037_1_.hasKey("player", 99)) { this.canBePickedUp = p_70037_1_.getBoolean("player") ? 1 : 0; } } // public void onCollideWithPlayer(EntityPlayer player) // { // if (!this.worldObj.isRemote && this.inGround && this.arrowShake <= 0) // { // boolean flag = this.canBePickedUp == 1 || this.canBePickedUp == 2 && player.capabilities.isCreativeMode; // // if (this.canBePickedUp == 1 && !player.inventory.addItemStackToInventory(new ItemStack(Modpg.itemSticky, 1))) // { // flag = false; // } // // if (flag) // { // this.playSound("random.pop", 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F); // player.onItemPickup(this, 1); // this.setDead(); // } // } // } protected boolean canTriggerWalking() { return false; } @SideOnly(Side.CLIENT) public float getShadowSize() { return 0.0F; } public void setDamage(double p_70239_1_) { this.damage = p_70239_1_; } public double getDamage() { return this.damage; } public void setKnockbackStrength(int p_70240_1_) { this.knockbackStrength = p_70240_1_; } public boolean canAttackWithItem() { return false; } public void setIsCritical(boolean p_70243_1_) { byte b0 = this.dataWatcher.getWatchableObjectByte(16); if (p_70243_1_) { this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 1))); } else { this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -2))); } } public boolean getIsCritical() { byte b0 = this.dataWatcher.getWatchableObjectByte(16); return (b0 & 1) != 0; } }
:::
:::
if (this.inGround) { int j = this.worldObj.getBlockMetadata(this.field_145791_d, this.field_145792_e, this.field_145789_f); if (block == this.field_145790_g && j == this.inData) { ++this.ticksInGround; if (!this.worldObj.isRemote && this.ticksInGround == 50) { this.worldObj.newExplosion((Entity) null, this.posX, this.posY, this.posZ, 4.5F, false, true); this.setDead(); IEntitySelector filter; filter = new IEntitySelector() { @Override public boolean isEntityApplicable(Entity entity) { if(entity instanceof EntityPlayer) { return true; } return false; } }; @SuppressWarnings("rawtypes") List entityTargetList = this.shootingEntity.worldObj.selectEntitiesWithinAABB(EntityLivingBase.class, this.shootingEntity.boundingBox.expand(3.0D, 2.0D, 3.0D), filter); for(Object entity1 : entityTargetList) { EntityLivingBase living = (EntityLivingBase)entity1; living.attackEntityFrom(DamageSource.generic, 10.0F); System.out.println("Il va faire tout noir!"); } } }
:::
:::
if (movingobjectposition.entityHit.attackEntityFrom(damagesource, (float)k)) { if (movingobjectposition.entityHit instanceof EntityLivingBase) { EntityLivingBase entitylivingbase = (EntityLivingBase)movingobjectposition.entityHit; if (!this.worldObj.isRemote) { for (int i1 = 0; i1 < 50; i1--) { this.timer --; } if (timer == 0) { // entitylivingbase.setArrowCountInEntity(entitylivingbase.getArrowCountInEntity() + 1); this.worldObj.newExplosion((Entity) null, this.posX, this.posY, this.posZ, 4.5F, false, true); this.setDead(); IEntitySelector filter; filter = new IEntitySelector() { @Override public boolean isEntityApplicable(Entity entity) { if(entity instanceof EntityPlayer) { return true; } return false; } }; @SuppressWarnings("rawtypes") List entityTargetList = this.shootingEntity.worldObj.selectEntitiesWithinAABB(EntityLivingBase.class, this.shootingEntity.boundingBox.expand(3.0D, 2.0D, 3.0D), filter); for(Object entity1 : entityTargetList) { EntityLivingBase living = (EntityLivingBase)entity1; living.attackEntityFrom(DamageSource.generic, 10.0F); System.out.println("Oups, toujours pas"); } } } if (this.knockbackStrength > 0) { f4 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); if (f4 > 0.0F) { movingobjectposition.entityHit.addVelocity(this.motionX * (double)this.knockbackStrength * 0.6000000238418579D / (double)f4, 0.1D, this.motionZ * (double)this.knockbackStrength * 0.6000000238418579D / (double)f4); } } if (this.shootingEntity != null && this.shootingEntity instanceof EntityLivingBase) { EnchantmentHelper.func_151384_a(entitylivingbase, this.shootingEntity); EnchantmentHelper.func_151385_b((EntityLivingBase)this.shootingEntity, entitylivingbase); } if (this.shootingEntity != null && movingobjectposition.entityHit != this.shootingEntity && movingobjectposition.entityHit instanceof EntityPlayer && this.shootingEntity instanceof EntityPlayerMP) { ((EntityPlayerMP)this.shootingEntity).playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(6, 0.0F)); } } this.playSound("random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F)); //Penser à mettre un son fun if (!(movingobjectposition.entityHit instanceof EntityEnderman)) { this.setDead(); } } else { this.motionX *= -0.10000000149011612D; this.motionY *= -0.10000000149011612D; this.motionZ *= -0.10000000149011612D; this.rotationYaw += 180.0F; this.prevRotationYaw += 180.0F; this.ticksInAir = 0; }
:::
Alors du coup, il faut que j’explique le fonctionnement de mes explosions. Comme sur le serveur pour lequel est dédié ce mod les dégâts d’explosions sont cancelled, je dois ré-appliquer des damages en zone.
Pour en revenir au cas où une entité est touchée, peut-être que ma façon de faire un cooldown est mauvais.
Toujours est-il que j’aimerais que l’entité touchée par la grenade soit mémorisée et qu’une explose se produise à sa position après un certain délai.
Il n’est pas forcément nécessaire que la grenade apparaisse sur le joueur (si trop compliqué), je pense me contenter de produire un son spécifique si ce cas de figure se produit (un son qui rappelle bien au joueur qu’il va bientôt exploser comme une bouse fourrée…).
L’usage du code de la flèche le permet-il? Est-ce que je suis encore loin du compte au final?Merci à vous les gens,
Edit: Si je retire mon timer un peu bizarre, la grenade explose au contact d’une entité.
-
je pense qu’il faudrait que tu fasse une entité qui follow (pour quelle se colle sur une autre entité) et tu garde ton code actuel (si il fonctionne ?) pour qu’elle reste collée sur un mur/bloc
-
Oui actuellement, tant que ça ne concerne pas une entité, ça fonctionne.
J’imagine que je vais devoir faire une nouvelle classe pour l’entité qui devra suivre celle touchée.
Mais je vois mal le genre de méthodes qu’il faut pour “tracer” l’entité touchée.edit: J’entends par là que je vois mal comment récupérer les coordonnées du joueur touché par la grenade dans une autre classe d’une entité appelée à ce moment-là.
-
Moi, j’ai réussi à faire en sorte que ma grenade collante s’attache à l’entité, mais d’une manière un peu
:::de schlag…
:::
Du coup, si tu veux mon code, je te l’envoies en MP ou même ici (si tu acceptes).
-
Euh étant donné que cet aprem je ne suis encore arrivé à rien de ce côté là, je veux bien x]
ps: autant le mettre ici, ça en aidera d’autres
Edit:
J’ai finalement obtenu le résultat voulu grâce à SuperLoup qui m’a orienté vers Des chapeaux et aidé à peaufiner la logique des positions.
Reste plus que le test sur serveur et je passerai en Résolu si tout est ok. -
EntityStickyGrenade : http://pastebin.com/Lx1UaQNR
EntityGrenade : http://pastebin.com/KhedAAcr
IGrenade : http://pastebin.com/EcWDY7iMVoilà voilà !