3raser Posted August 20, 2011 Share Posted August 20, 2011 May I ask, why is it when I compile I get a compiling error stating that variable name is already defined? Here are two variables causing the errors: public EntityLiving owner; private EntityPlayer owner; Wouldn't those be two completely different variables? My compiling error: 2011-08-19 23:35 - commands.recompile - ERROR - src\minecraft\net\minecraft\src\EntityAAShell.java:310: owner is already defined in net.minecraft.src.EntityAAShell 2011-08-19 23:35 - commands.recompile - ERROR - private EntityPlayer owner; 2011-08-19 23:35 - commands.recompile - ERROR - ^ ------------------- Thanks! All helped appreciated. Full file: // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov. // Jad home page: http://www.kpdus.com/jad.html // Decompiler options: packimports(3) braces deadcode package net.minecraft.src; import java.util.List; import java.util.Random; import net.minecraft.client.Minecraft; // Referenced classes of package net.minecraft.src: // Entity, MathHelper, Vec3D, World, // MovingObjectPosition, AxisAlignedBB, Block, BlockLeaves, // ModLoader, StepSound, SoundManager, EntityPlane, // EntitySmokeFX, EntityFX, EffectRenderer, EntityLiving, // NBTTagCompound, EntityPlayer, ItemStack, Item, // InventoryPlayer public class EntityAAShell extends Entity { public EntityAAShell(World world) { super(world); xTile = -1; yTile = -1; zTile = -1; inTile = 0; flyTime = 0; setSize(0.5F, 0.5F); } public EntityAAShell(World world, double d, double d1, double d2, double d3, double d4, double d5, EntityPlayer entityplayer) { super(world); xTile = -1; yTile = -1; zTile = -1; inTile = 0; flyTime = 0; setSize(0.5F, 0.5F); setPosition(d, d1, d2); yOffset = 0.0F; setVelocity(d3, d4, d5); owner = entityplayer; } public EntityAAShell(World world, double d, double d1, double d2) { super(world); xTile = -1; yTile = -1; zTile = -1; inTile = 0; inGround = false; arrowShake = 0; flyTime = 0; setSize(0.5F, 0.5F); setPosition(d, d1, d2); yOffset = 0.0F; } protected void entityInit() { } public void setArrowHeading(double d, double d1, double d2, float f, float f1) { float f2 = MathHelper.sqrt_double(d * d + d1 * d1 + d2 * d2); d /= f2; d1 /= f2; d2 /= f2; d += rand.nextGaussian() * 0.0074999998323619366D * (double)f1; d1 += rand.nextGaussian() * 0.0074999998323619366D * (double)f1; d2 += rand.nextGaussian() * 0.0074999998323619366D * (double)f1; d *= f; d1 *= f; d2 *= f; motionX = d; motionY = d1; motionZ = d2; float f3 = MathHelper.sqrt_double(d * d + d2 * d2); prevRotationYaw = rotationYaw = (float)((Math.atan2(d, d2) * 180D) / 3.1415927410125732D); prevRotationPitch = rotationPitch = (float)((Math.atan2(d1, f3) * 180D) / 3.1415927410125732D); timeTillDeath = 0; } public void setVelocity(double d, double d1, double d2) { motionX = d; motionY = d1; motionZ = d2; if(prevRotationPitch == 0.0F && prevRotationYaw == 0.0F) { float f = MathHelper.sqrt_double(d * d + d2 * d2); prevRotationYaw = rotationYaw = (float)((Math.atan2(d, d2) * 180D) / 3.1415927410125732D); prevRotationPitch = rotationPitch = (float)((Math.atan2(d1, f) * 180D) / 3.1415927410125732D); } } public void onUpdate() { super.onUpdate(); if(flyTime > 1000) { setEntityDead(); } if(prevRotationPitch == 0.0F && prevRotationYaw == 0.0F) { float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ); prevRotationYaw = rotationYaw = (float)((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D); prevRotationPitch = rotationPitch = (float)((Math.atan2(motionY, f) * 180D) / 3.1415927410125732D); } flyTime++; Vec3D vec3d = Vec3D.createVector(posX, posY, posZ); Vec3D vec3d1 = Vec3D.createVector(posX + motionX, posY + motionY, posZ + motionZ); MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks(vec3d, vec3d1); vec3d = Vec3D.createVector(posX, posY, posZ); vec3d1 = Vec3D.createVector(posX + motionX, posY + motionY, posZ + motionZ); if(movingobjectposition != null) { vec3d1 = Vec3D.createVector(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord); } Entity entity = null; List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D)); double d = 0.0D; for(int i = 0; i < list.size(); i++) { Entity entity1 = (Entity)list.get(i); if(!entity1.canBeCollidedWith() || entity1 == owner && flyTime < 5) { continue; } float f2 = 0.3F; AxisAlignedBB axisalignedbb = entity1.boundingBox.expand(f2, f2, f2); MovingObjectPosition movingobjectposition1 = axisalignedbb.func_1169_a(vec3d, vec3d1); if(movingobjectposition1 == null) { continue; } double d1 = vec3d.distanceTo(movingobjectposition1.hitVec); if(d1 < d || d == 0.0D) { entity = entity1; d = d1; } } if(entity != null) { movingobjectposition = new MovingObjectPosition(entity); } if(movingobjectposition != null) { if(movingobjectposition.entityHit != null) { if(movingobjectposition.entityHit.attackEntityFrom(owner, 5)) { worldObj.playSoundAtEntity(this, "Flak", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F)); setEntityDead(); } } else { xTile = movingobjectposition.blockX; yTile = movingobjectposition.blockY; zTile = movingobjectposition.blockZ; inTile = worldObj.getBlockId(xTile, yTile, zTile); if(inTile == Block.glass.blockID || inTile == Block.glowStone.blockID || inTile == Block.leaves.blockID) { Block block = Block.blocksList[inTile]; ModLoader.getMinecraftInstance().sndManager.playSound(block.stepSound.stepSoundDir(), (float)xTile + 0.5F, (float)yTile + 0.5F, (float)zTile + 0.5F, (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F); worldObj.setBlockWithNotify(xTile, yTile, zTile, 0); } else { motionX = (float)(movingobjectposition.hitVec.xCoord - posX); motionY = (float)(movingobjectposition.hitVec.yCoord - posY); motionZ = (float)(movingobjectposition.hitVec.zCoord - posZ); float f1 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ); posX -= (motionX / (double)f1) * 0.05000000074505806D; posY -= (motionY / (double)f1) * 0.05000000074505806D; posZ -= (motionZ / (double)f1) * 0.05000000074505806D; worldObj.playSoundAtEntity(this, "bulletHit", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F)); setEntityDead(); } } } List list1 = worldObj.getEntitiesWithinAABB(net.minecraft.src.EntityPlane.class, AxisAlignedBB.getBoundingBoxFromPool(posX - 4D, posY - 4D, posZ - 4D, posX + 4D, posY + 4D, posZ + 4D)); if(!list1.isEmpty() || flyTime >= 20) { for(int j = 0; j < 1000; j++) { EntitySmokeFX entitysmokefx = new EntitySmokeFX(worldObj, posX + rand.nextGaussian(), posY + rand.nextGaussian(), posZ + rand.nextGaussian(), 0.01D, 0.01D, 0.01D); entitysmokefx.motionX = rand.nextGaussian() / 20D; entitysmokefx.motionY = rand.nextGaussian() / 20D; entitysmokefx.motionZ = rand.nextGaussian() / 20D; entitysmokefx.renderDistanceWeight = 200D; ModLoader.getMinecraftInstance().effectRenderer.addEffect(entitysmokefx); } worldObj.playSoundAtEntity(this, "Flak", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F)); for(int k = 0; k < list1.size(); k++) { EntityPlane entityplane = (EntityPlane)list1.get(k); entityplane.attackEntityFrom(this, 40); } setEntityDead(); } List list2 = worldObj.getEntitiesWithinAABB(net.minecraft.src.EntityLiving.class, AxisAlignedBB.getBoundingBoxFromPool(posX, posY, posZ, posX + 1.0D, posY + 1.0D, posZ + 1.0D)); if(!list2.isEmpty() || flyTime >= 20) { for(int l = 0; l < 1000; l++) { EntitySmokeFX entitysmokefx1 = new EntitySmokeFX(worldObj, posX + rand.nextGaussian(), posY + rand.nextGaussian(), posZ + rand.nextGaussian(), 0.01D, 0.01D, 0.01D); entitysmokefx1.motionX = rand.nextGaussian() / 20D; entitysmokefx1.motionY = rand.nextGaussian() / 20D; entitysmokefx1.motionZ = rand.nextGaussian() / 20D; entitysmokefx1.renderDistanceWeight = 200D; ModLoader.getMinecraftInstance().effectRenderer.addEffect(entitysmokefx1); } worldObj.playSoundAtEntity(this, "Flak", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F)); for(int i1 = 0; i1 < list2.size(); i1++) { EntityLiving entityliving = (EntityLiving)list2.get(i1); entityliving.attackEntityFrom(this, 40); } setEntityDead(); } posX += motionX; posY += motionY; posZ += motionZ; float f3 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ); rotationYaw = (float)((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D); for(rotationPitch = (float)((Math.atan2(motionY, f3) * 180D) / 3.1415927410125732D); rotationPitch - prevRotationPitch < -180F; prevRotationPitch -= 360F) { } for(; rotationPitch - prevRotationPitch >= 180F; prevRotationPitch += 360F) { } for(; rotationYaw - prevRotationYaw < -180F; prevRotationYaw -= 360F) { } for(; rotationYaw - prevRotationYaw >= 180F; prevRotationYaw += 360F) { } rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F; rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F; float f4 = 0.99F; float f5 = 0.03F; if(handleWaterMovement()) { for(int j1 = 0; j1 < 4; j1++) { float f6 = 0.25F; worldObj.spawnParticle("bubble", posX - motionX * (double)f6, posY - motionY * (double)f6, posZ - motionZ * (double)f6, motionX, motionY, motionZ); } f4 = 0.8F; } motionX *= f4; motionY *= f4; motionZ *= f4; setPosition(posX, posY, posZ); } public void writeEntityToNBT(NBTTagCompound nbttagcompound) { nbttagcompound.setShort("xTile", (short)xTile); nbttagcompound.setShort("yTile", (short)yTile); nbttagcompound.setShort("zTile", (short)zTile); nbttagcompound.setByte("inTile", (byte)inTile); nbttagcompound.setByte("shake", (byte)arrowShake); nbttagcompound.setByte("inGround", (byte)(inGround ? 1 : 0)); } public void readEntityFromNBT(NBTTagCompound nbttagcompound) { xTile = nbttagcompound.getShort("xTile"); yTile = nbttagcompound.getShort("yTile"); zTile = nbttagcompound.getShort("zTile"); inTile = nbttagcompound.getByte("inTile") & 0xff; arrowShake = nbttagcompound.getByte("shake") & 0xff; inGround = nbttagcompound.getByte("inGround") == 1; } public void onCollideWithPlayer(EntityPlayer entityplayer) { if(worldObj.multiplayerWorld) { return; } if(inGround && owner == entityplayer && arrowShake <= 0 && entityplayer.inventory.addItemStackToInventory(new ItemStack(Item.arrow, 1))) { worldObj.playSoundAtEntity(this, "random.pop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F); entityplayer.onItemPickup(this, 1); setEntityDead(); } } public float getShadowSize() { return 0.0F; } private int xTile; private int yTile; private int zTile; private int inTile; private boolean inGround; public int arrowShake; public EntityLiving owner; private int timeTillDeath; private int flyTime; private EntityPlayer owner; } Quote Link to comment https://forums.phpfreaks.com/topic/245260-java-already-defined-variable/ Share on other sites More sharing options...
KevinM1 Posted August 20, 2011 Share Posted August 20, 2011 Unless the variables are in separate namespaces, you can't have two with the same name. The compiler cannot guess at your intent when you try to use one of them, regardless if you think the context of their use is explicit. Since it's ambiguous to the compiler, it's an error. Why would you want two variables with the same name in the same namespace anyway? From a useability standpoint, that's just asking for trouble. Quote Link to comment https://forums.phpfreaks.com/topic/245260-java-already-defined-variable/#findComment-1259921 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.