Modification de la vitesse d'une fireball buggé côté serveur :/
-
Essaies, tu verra bien x)
-
Je viens d’essaye en soit ça mache avec l’entitylargefireball.
Le problème c’est que j’utilise pas vraiment L’entitylargefireball j’utilise ma propre entité qui est un copier coller de l’entitylargefireball avec juste quelques truc enlever j’ai regarder et re regarder mais je vois pas d’ou ça peut venir…
package com.CSC.net.Entity; import com.CSC.net.Main; import com.CSC.net.packet.PacketSounds; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.projectile.EntityFireball; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; import net.minecraft.util.datafix.DataFixer; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class EntityTesting2 extends EntityTesting { public int explosionPower = 1; public int damage; public EntityTesting2(World worldIn) { super(worldIn); } @SideOnly(Side.CLIENT) public EntityTesting2(World worldIn, double x, double y, double z, double accelX, double accelY, double accelZ) { super(worldIn, x, y, z, accelX, accelY, accelZ); } public EntityTesting2(World worldIn, EntityLivingBase shooter, double accelX, double accelY, double accelZ, int damage) { super(worldIn, shooter, accelX, accelY, accelZ, damage); this.damage = damage; } /** * Called when this EntityFireball hits a block or entity. */ protected void onImpact(RayTraceResult result) { if (!this.worldObj.isRemote) { if (result.entityHit != null && this.shootingEntity != null) { result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.shootingEntity), damage); this.applyEnchantments(this.shootingEntity, result.entityHit); } if (result.typeOfHit == RayTraceResult.Type.BLOCK && this.shootingEntity != null) { System.out.println(""); if(this.shootingEntity.worldObj.rand.nextInt(2) == 0) { Main.network.sendToAllAround(new PacketSounds(84), new NetworkRegistry.TargetPoint(shootingEntity.dimension, shootingEntity.posX, shootingEntity.posY, shootingEntity.posZ, 10)); } } //boolean flag = this.worldObj.getGameRules().getBoolean("mobGriefing"); //this.worldObj.newExplosion((Entity)null, this.posX, this.posY, this.posZ, (float)this.explosionPower, flag, flag); this.setDead(); } } public static void func_189744_a(DataFixer p_189744_0_) { EntityFireball.func_189743_a(p_189744_0_, "Fireball"); } /** * (abstract) Protected helper method to write subclass entity data to NBT. */ public void writeEntityToNBT(NBTTagCompound compound) { super.writeEntityToNBT(compound); compound.setInteger("ExplosionPower", this.explosionPower); } /** * (abstract) Protected helper method to read subclass entity data from NBT. */ public void readEntityFromNBT(NBTTagCompound compound) { super.readEntityFromNBT(compound); if (compound.hasKey("ExplosionPower", 99)) { this.explosionPower = compound.getInteger("ExplosionPower"); } } }package com.CSC.net.Entity; import com.CSC.net.Main; import com.CSC.net.packet.PacketSounds; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.projectile.ProjectileHelper; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.DamageSource; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.ResourceLocation; import net.minecraft.util.datafix.DataFixer; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class EntityTesting extends Entity { public static EntityTesting instance; public int damage; private int xTile = -1; private int yTile = -1; private int zTile = -1; private Block inTile; private boolean inGround; public EntityLivingBase shootingEntity; private int ticksAlive; private int ticksInAir; public double accelerationX; public double accelerationY; public double accelerationZ; public EntityTesting(World worldIn) { super(worldIn); this.setSize(1.0F, 1.0F); this.instance = this; } protected void entityInit() { } /** * Checks if the entity is in range to render. */ @SideOnly(Side.CLIENT) public boolean isInRangeToRenderDist(double distance) { double d0 = this.getEntityBoundingBox().getAverageEdgeLength() * 4.0D; if (Double.isNaN(d0)) { d0 = 4.0D; } d0 = d0 * 64.0D; return distance < d0 * d0; } public EntityTesting(World worldIn, double x, double y, double z, double accelX, double accelY, double accelZ) { super(worldIn); this.setSize(0.15F, 0.15F); this.setLocationAndAngles(x, y, z, this.rotationYaw, this.rotationPitch); this.setPosition(x, y, z); double d0 = (double)MathHelper.sqrt_double(accelX * accelX + accelY * accelY + accelZ * accelZ); this.accelerationX = accelX / d0 * 0.1D; this.accelerationY = accelY / d0 * 0.1D; this.accelerationZ = accelZ / d0 * 0.1D; this.instance = this; } public EntityTesting(World worldIn, EntityLivingBase shooter, double accelX, double accelY, double accelZ, int damage) { super(worldIn); this.shootingEntity = shooter; this.setSize(0.15F, 0.15F); this.setLocationAndAngles(shooter.posX, shooter.posY, shooter.posZ, shooter.rotationYaw, shooter.rotationPitch); this.setPosition(this.posX, this.posY, this.posZ); this.motionX = 0.0D; this.motionY = 0.0D; this.motionZ = 0.0D; accelX = accelX + this.rand.nextGaussian() * 0.4D; accelY = accelY + this.rand.nextGaussian() * 0.4D; accelZ = accelZ + this.rand.nextGaussian() * 0.4D; double d0 = (double)MathHelper.sqrt_double(accelX * accelX + accelY * accelY + accelZ * accelZ); this.accelerationX = accelX / d0 * 0.1D; this.accelerationY = accelY / d0 * 0.1D; this.accelerationZ = accelZ / d0 * 0.1D; this.instance = this; this.damage = damage; } /** * Called to update the entity's position/logic. */ public void onUpdate() { if (this.worldObj.isRemote || (this.shootingEntity == null || !this.shootingEntity.isDead) && this.worldObj.isBlockLoaded(new BlockPos(this))) { super.onUpdate(); if (this.isFireballFiery()) { this.setFire(1); } if (this.inGround) { if (this.worldObj.getBlockState(new BlockPos(this.xTile, this.yTile, this.zTile)).getBlock() == this.inTile) { ++this.ticksAlive; if (this.ticksAlive == 600) { this.setDead(); } return; } 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.ticksAlive = 0; this.ticksInAir = 0; } else { ++this.ticksInAir; } RayTraceResult raytraceresult = ProjectileHelper.forwardsRaycast(this, true, this.ticksInAir >= 25, this.shootingEntity); if (raytraceresult != null) { this.onImpact(raytraceresult); } this.posX += this.motionX; this.posY += this.motionY; this.posZ += this.motionZ; ProjectileHelper.rotateTowardsMovement(this, 0.2F); float f = this.getMotionFactor(); if (this.isInWater()) { for (int i = 0; i < 4; ++i) { float f1 = 0.25F; this.worldObj.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * 0.25D, this.posY - this.motionY * 0.25D, this.posZ - this.motionZ * 0.25D, this.motionX, this.motionY, this.motionZ, new int[0]); } f = 0.8F; } this.motionX += this.accelerationX; this.motionY += this.accelerationY; this.motionZ += this.accelerationZ; this.motionX *= (double)f; this.motionY *= (double)f; this.motionZ *= (double)f; this.worldObj.spawnParticle(this.getParticleType(), this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]); this.setPosition(this.posX, this.posY, this.posZ); } else { this.setDead(); } } protected boolean isFireballFiery() { return true; } protected EnumParticleTypes getParticleType() { return EnumParticleTypes.SMOKE_NORMAL; } /** * Return the motion factor for this projectile. The factor is multiplied by the original motion. */ protected float getMotionFactor() { return 0.95F; } /** * Called when this EntityFireball hits a block or entity. */ protected void onImpact(RayTraceResult result) { } public static void func_189743_a(DataFixer p_189743_0_, String p_189743_1_) { } /** * (abstract) Protected helper method to write subclass entity data to NBT. */ public void writeEntityToNBT(NBTTagCompound compound) { compound.setInteger("xTile", this.xTile); compound.setInteger("yTile", this.yTile); compound.setInteger("zTile", this.zTile); ResourceLocation resourcelocation = (ResourceLocation)Block.REGISTRY.getNameForObject(this.inTile); compound.setString("inTile", resourcelocation == null ? "" : resourcelocation.toString()); compound.setByte("inGround", (byte)(this.inGround ? 1 : 0)); compound.setTag("direction", this.newDoubleNBTList(new double[] {this.motionX, this.motionY, this.motionZ})); compound.setTag("power", this.newDoubleNBTList(new double[] {this.accelerationX, this.accelerationY, this.accelerationZ})); compound.setInteger("life", this.ticksAlive); } /** * (abstract) Protected helper method to read subclass entity data from NBT. */ public void readEntityFromNBT(NBTTagCompound compound) { this.xTile = compound.getInteger("xTile"); this.yTile = compound.getInteger("yTile"); this.zTile = compound.getInteger("zTile"); if (compound.hasKey("inTile", 8)) { this.inTile = Block.getBlockFromName(compound.getString("inTile")); } else { this.inTile = Block.getBlockById(compound.getByte("inTile") & 255); } this.inGround = compound.getByte("inGround") == 1; if (compound.hasKey("power", 9)) { NBTTagList nbttaglist = compound.getTagList("power", 6); if (nbttaglist.tagCount() == 3) { this.accelerationX = nbttaglist.getDoubleAt(0); this.accelerationY = nbttaglist.getDoubleAt(1); this.accelerationZ = nbttaglist.getDoubleAt(2); } } this.ticksAlive = compound.getInteger("life"); if (compound.hasKey("direction", 9) && compound.getTagList("direction", 6).tagCount() == 3) { NBTTagList nbttaglist1 = compound.getTagList("direction", 6); this.motionX = nbttaglist1.getDoubleAt(0); this.motionY = nbttaglist1.getDoubleAt(1); this.motionZ = nbttaglist1.getDoubleAt(2); } else { this.setDead(); } } /** * Returns true if other Entities should be prevented from moving through this Entity. */ public boolean canBeCollidedWith() { return true; } public float getCollisionBorderSize() { return 1.0F; } /** * Called when the entity is attacked. */ public boolean attackEntityFrom(DamageSource source, float amount) { if (this.isEntityInvulnerable(source)) { return false; } else { this.setBeenAttacked(); if (source.getEntity() != null) { Vec3d vec3d = source.getEntity().getLookVec(); if (vec3d != null) { this.motionX = vec3d.xCoord; this.motionY = vec3d.yCoord; this.motionZ = vec3d.zCoord; this.accelerationX = this.motionX * 0.1D; this.accelerationY = this.motionY * 0.1D; this.accelerationZ = this.motionZ * 0.1D; } if (source.getEntity() instanceof EntityLivingBase) { this.shootingEntity = (EntityLivingBase)source.getEntity(); } return true; } else { return false; } } } /** * Gets how bright this entity is. */ public float getBrightness(float partialTicks) { return 1.0F; } @SideOnly(Side.CLIENT) public int getBrightnessForRender(float partialTicks) { return 15728880; } } -
public static EntityTesting instance;
C’est quoi ça ?
-
Euhh je sais pas du tout …
Pourquoi cette question ? x)
-
Parce que tu devrais pas avoir besoin d’une telle chose sur une entité, où est-ce que tu l’utilises ? (Clic droit dessus, References -> Workspace)
-
Je ne l’utilise plus, je viens de l’enlever.
C’est ça qui causé problème ? -
Je ne pense pas, mais en tout cas ça n’a rien à faire là.
Je ne sais pas trop d’où peut venir le problème. Faudrait que je débug de mon côté quand j’aurai le temps (si tu peux m’envoyer les sources ça serait bien). -
Tien:
Je t’envoies le mdp du zip en privé
-
Source:
ps: j’ai oublié de enlever le menu principal du coup dans le clientproxy tout en bas vire l’event onGui.
-
En fait la raison est surment du au fait que les valeurs de look.xCoord, look.yCoord et look.zCoord ne sont pas les mêmes côtés serveur.
Je ne vois que ça qui pourrait causer ce soucis.Pour avoir une balle qui va plus vite fait simplement une classe extends EntityFireball (pas besoin de recréer un équivalent de EntityFireball comme actuellement) et reprend simplement cette partie du code dans le constructeur :
accelX = accelX + this.rand.nextGaussian() * 0.4D; accelY = accelY + this.rand.nextGaussian() * 0.4D; accelZ = accelZ + this.rand.nextGaussian() * 0.4D; double d0 = (double)MathHelper.sqrt_double(accelX * accelX + accelY * accelY + accelZ * accelZ); this.accelerationX = accelX / d0 * 0.1D; this.accelerationY = accelY / d0 * 0.1D; this.accelerationZ = accelZ / d0 * 0.1D;En augmentant l’accélération. Exemple :
accelX = accelX + this.rand.nextGaussian() * 0.4D; accelY = accelY + this.rand.nextGaussian() * 0.4D; accelZ = accelZ + this.rand.nextGaussian() * 0.4D; double d0 = (double)MathHelper.sqrt_double(accelX * accelX + accelY * accelY + accelZ * accelZ); this.accelerationX = accelX * 2 / d0 * 0.1D; this.accelerationY = accelY * 2 / d0 * 0.1D; this.accelerationZ = accelZ * 2 / d0 * 0.1D; -
J’ai fais se que tu m’as dis mais y’a un soucis^^
La vitesse la fireball est bien modifié et tout mais le truc c’est elle part pas droite et de façon aléatoire.
Pour que elle ne parte pas de travers je fais ça:if(stack != null && stack.getItem() == /*Item.getByNameOrId("flansmod:9mm")*/Items.APPLE) { if(cap.getammo9mm() >= 1 | entityplayer.capabilities.isCreativeMode && timer <= 0) { timer = 20*2; Main.network.sendToAllAround(new PacketSounds(58), new NetworkRegistry.TargetPoint(entityplayer.dimension, entityplayer.posX, entityplayer.posY, entityplayer.posZ, 25)); TEST fireball2 = new TEST(worldIn, entityplayer, look.xCoord, look.yCoord, look.zCoord); fireball2.setPosition( entityplayer.posX + look.xCoord, entityplayer.posY + 1 + look.yCoord, entityplayer.posZ + look.zCoord); fireball2.accelerationX = look.xCoord;//ça fireball2.accelerationY = look.yCoord;//ça fireball2.accelerationZ = look.zCoord;//ça System.out.println(fireball2.accelerationX + " " + fireball2.accelerationY + " " + fireball2.accelerationZ); worldIn.spawnEntityInWorld(fireball2); cap.removeammo9mm(); cap.sync(); System.out.println(cap.getammo9mm()); }Mais le soucis c’est que quand je fais ça, la vitesse de la fireball n’est plus modifier forcément …
J’ai essayer de regarder comment la fireball du ghast faisait mais j’ai pas trop compris x) !
Voilà donc je sais pas trop comment faire la…
-
J’ai fais se que tu m’as dis
-
J’ai fais se que tu m’as dis mais y’a un soucis^^
La vitesse la fireball est bien modifié et tout mais le truc c’est elle part pas droite et de façon aléatoire (en solo pas testé en multi).
Pour que elle ne parte pas de travers je fais ça:if(stack != null && stack.getItem() == /*Item.getByNameOrId("flansmod:9mm")*/Items.APPLE) { if(cap.getammo9mm() >= 1 | entityplayer.capabilities.isCreativeMode && timer <= 0) { timer = 20*2; Main.network.sendToAllAround(new PacketSounds(58), new NetworkRegistry.TargetPoint(entityplayer.dimension, entityplayer.posX, entityplayer.posY, entityplayer.posZ, 25)); TEST fireball2 = new TEST(worldIn, entityplayer, look.xCoord, look.yCoord, look.zCoord); fireball2.setPosition( entityplayer.posX + look.xCoord, entityplayer.posY + 1 + look.yCoord, entityplayer.posZ + look.zCoord); fireball2.accelerationX = look.xCoord;//ça fireball2.accelerationY = look.yCoord;//ça fireball2.accelerationZ = look.zCoord;//ça System.out.println(fireball2.accelerationX + " " + fireball2.accelerationY + " " + fireball2.accelerationZ); worldIn.spawnEntityInWorld(fireball2); cap.removeammo9mm(); cap.sync(); System.out.println(cap.getammo9mm()); }Mais le soucis c’est que quand je fais ça, la vitesse de la fireball n’est plus modifier forcément …
J’ai essayer de regarder comment la fireball du ghast faisait mais j’ai pas trop compris x) !
Voilà donc je sais pas trop comment faire la…
J’ai essayer de faire le Vec3d dans le constructeur de l’entity la vitesse est modif en solo mais pas multi c’est comme avant…
-
Vires les 3 lignes avec du random et voila. (celle-ci :
accelX = accelX + this.rand.nextGaussian() * 0.4D;
accelY = accelY + this.rand.nextGaussian() * 0.4D;
accelZ = accelZ + this.rand.nextGaussian() * 0.4D; ) -
Exact^^ ça ma l’air pas mal je testes en multi ce week-end je te dirais merci

EDIT:
Ouais c’est bon, par contre on voit la fireball partir y’a pas moyen de pas la voir? appart re créer l’entité
-
Ouais c’est bon, par contre on voit la fireball partir y’a pas moyen de pas la voir? appart re créer l’entité
-
Il faut lui ajouter un rendu et enregistrer l’entité.
-
@‘robin4002’:
Il faut lui ajouter un rendu et enregistrer l’entité.
Ok donc j’ai ajouter mon rendu puis enregistrer comme tu m’as dis:
Dans le clientproxy:
RenderingRegistry.registerEntityRenderingHandler(Bullet.class, RenderBullet::new);render:
package com.CSC.net.Render; import org.lwjgl.opengl.GL11; import com.CSC.net.Entity.EntityBullet; import com.CSC.net.Entity.Bullet; import com.CSC.net.Model.ModelBullet; import net.minecraft.client.Minecraft; import net.minecraft.client.model.ModelBase; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.VertexBuffer; import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.entity.Entity; import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.MathHelper; import net.minecraftforge.fml.client.registry.IRenderFactory; public class RenderBullet extends Render { public RenderBullet(RenderManager renderMan) { super(renderMan); } private static final ResourceLocation bulletTexture = new ResourceLocation("csc:textures/items/bullet.png"); protected ResourceLocation getEntityTexture(Bullet bullet) { return bulletTexture; } protected ResourceLocation getEntityTexture(Entity entity) { return this.getEntityTexture((Bullet)entity); } public void doRender(Entity entity, double transX, double transY, double transZ, float param5, float dir) { this.doRender((Bullet)entity, transX, transY, transZ, param5, dir); } public void doRender(Bullet star, double transX, double transY, double transZ, float param5, float dir) { this.bindEntityTexture(star); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); GlStateManager.pushMatrix(); GlStateManager.translate((float)transX, (float)transY, (float)transZ); //GlStateManager.rotate(star.prevRotationYaw + (star.rotationYaw - star.prevRotationYaw) * dir - 90.0F, 0.0F, 1.0F, 0.0F); //GlStateManager.rotate(star.getRandomTilt(), 1.0F, 0.0F, 0.0F); Tessellator tessellator = Tessellator.getInstance(); VertexBuffer vertexbuffer = tessellator.getBuffer(); GlStateManager.enableRescaleNormal(); float scale = 0.05F; GlStateManager.scale(scale, scale, scale); GL11.glNormal3f(0.0F, 0.0F,scale); vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX); vertexbuffer.pos(-2.0D, -2.0D, 0.0D).tex(0, 0); vertexbuffer.pos(2.0D, -2.0D, 0.0D).tex(1, 0); vertexbuffer.pos(2.0D, 2.0D, 0.0D).tex(1, 1); vertexbuffer.pos(-2.0D, 2.0D, 0.0D).tex(0, 1); tessellator.draw(); GlStateManager.rotate(180.0F, 1.0F, 0.0F, 0.0F); vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX); vertexbuffer.pos(-2.0D, -2.0D, 0.0D).tex(0, 0); vertexbuffer.pos(2.0D, -2.0D, 0.0D).tex(1, 0); vertexbuffer.pos(2.0D, 2.0D, 0.0D).tex(1, 1); vertexbuffer.pos(-2.0D, 2.0D, 0.0D).tex(0, 1); tessellator.draw(); GlStateManager.disableRescaleNormal(); GlStateManager.popMatrix(); super.doRender(star, transX, transY, transZ, param5, dir); } }bullet:
public class Bullet extends EntityFireball{ public int damage = 0; public Bullet(World worldIn, EntityLivingBase shooter, double accelX, double accelY, double accelZ, int damage) { super(worldIn, shooter, accelX, accelY, accelZ); this.damage = damage; double d0 = (double)MathHelper.sqrt_double(accelX * accelX + accelY * accelY + accelZ * accelZ); this.accelerationX = accelX * 40 / d0 * 0.1D; this.accelerationY = accelY * 40 / d0 * 0.1D; this.accelerationZ = accelZ * 40 / d0 * 0.1D; this.setSize(0.15F, 0.15F); } @Override protected void onImpact(RayTraceResult result) { if (!this.worldObj.isRemote) { if (result.entityHit != null && this.shootingEntity != null) { result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.shootingEntity), damage); this.applyEnchantments(this.shootingEntity, result.entityHit); } if (result.typeOfHit == RayTraceResult.Type.BLOCK && this.shootingEntity != null) { System.out.println(""); if(this.shootingEntity.worldObj.rand.nextInt(2) == 0) { Main.network.sendToAllAround(new PacketSounds(84), new NetworkRegistry.TargetPoint(shootingEntity.dimension, shootingEntity.posX, shootingEntity.posY, shootingEntity.posZ, 10)); } } //boolean flag = this.worldObj.getGameRules().getBoolean("mobGriefing"); //this.worldObj.newExplosion((Entity)null, this.posX, this.posY, this.posZ, (float)this.explosionPower, flag, flag); this.setDead(); } } }La fireball est toujours présente normal?
EDIT:
Aussi petit question quand je tire ma balle part droite par contre la fireball du moin la texture par de travers normal? je peux réglé ça ou pas?
-
Tu as enregistré l’entité ?
Et j’ai pas très bien compris ta question.
-
Ah oui c’est vrai il faut l’enregistrer l’entité.
Euhh j’ai regarder j’ai pas trouvé appart des veille façon de register qui existe plus pour une simple entité apparemment (EntityRegistry).
Pour ma question en gros quand je tire avec mon arme mon entity par droite par contre la texture de la fireball par a droite ou a gauche fin elle part dans une direction random au lieux de partir droite je sais si tu vois se que je veux dire sinon je te montrerais .