/** Plays step sound at given x, y, z for the entity */ protected void playStepSound(int par1, int par2, int par3, int par4) { StepSound stepsound = Block.blocksList[par4].stepSound; if (worldObj.getBlockId(par1, par2 + 1, par3) == Block.snow.blockID) { stepsound = Block.snow.stepSound; worldObj.playSoundAtEntity( this, stepsound.getStepSound(), stepsound.getVolume() * 0.15F, stepsound.getPitch()); } else if (!Block.blocksList[par4].blockMaterial.isLiquid()) { worldObj.playSoundAtEntity( this, stepsound.getStepSound(), stepsound.getVolume() * 0.15F, stepsound.getPitch()); } }
/** * called when the player releases the use item button. Args: itemstack, world, entityplayer, * itemInUseCount */ public void onPlayerStoppedUsing( ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) { boolean flag = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0; if (flag || par3EntityPlayer.inventory.hasItem(Item.arrow.shiftedIndex)) { int i = getMaxItemUseDuration(par1ItemStack) - par4; float f = (float) i / 20F; f = (f * f + f * 2.0F) / 3F; if ((double) f < 0.10000000000000001D) { return; } if (f > 1.0F) { f = 1.0F; } EntityArrow entityarrow = new EntityArrow(par2World, par3EntityPlayer, f * 2.0F); if (f == 1.0F) { entityarrow.func_56125_a(true); } int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack); if (j > 0) { entityarrow.setDamage(entityarrow.getDamage() + (double) j * 0.5D + 0.5D); } int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack); if (k > 0) { entityarrow.func_46007_b(k); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0) { entityarrow.setFire(100); } par1ItemStack.damageItem(1, par3EntityPlayer); par2World.playSoundAtEntity( par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F); if (flag) { entityarrow.field_58012_a = 2; } else { par3EntityPlayer.inventory.consumeInventoryItem(Item.arrow.shiftedIndex); } if (!par2World.isRemote) { par2World.spawnEntityInWorld(entityarrow); } } }
/** * called when the player releases the use item button. Args: itemstack, world, entityplayer, * itemInUseCount */ public void onPlayerStoppedUsing( ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) { boolean var5 = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0; if (var5 || par3EntityPlayer.inventory.hasItem(Item.arrow.shiftedIndex)) { int var6 = this.getMaxItemUseDuration(par1ItemStack) - par4; float var7 = (float) var6 / 20.0F; var7 = (var7 * var7 + var7 * 2.0F) / 3.0F; if ((double) var7 < 0.1D) { return; } if (var7 > 1.0F) { var7 = 1.0F; } EntityArrow var8 = new EntityArrow(par2World, par3EntityPlayer, var7 * 2.0F); if (var7 == 1.0F) { var8.setIsCritical(true); } int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack); if (var9 > 0) { var8.setDamage(var8.getDamage() + (double) var9 * 0.5D + 0.5D); } int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack); if (var10 > 0) { var8.setKnockbackStrength(var10); } if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0) { var8.setFire(100); } par1ItemStack.damageItem(1, par3EntityPlayer); par2World.playSoundAtEntity( par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F); if (var5) { var8.canBePickedUp = 2; } else { par3EntityPlayer.inventory.consumeInventoryItem(Item.arrow.shiftedIndex); } if (!par2World.isRemote) { par2World.spawnEntityInWorld(var8); } } }
public ItemStack onFoodEaten( ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { par1ItemStack.stackSize--; par3EntityPlayer.getFoodStats().addStats(this); par2World.playSoundAtEntity( par3EntityPlayer, "random.burp", 0.5F, par2World.rand.nextFloat() * 0.1F + 0.9F); func_77849_c(par1ItemStack, par2World, par3EntityPlayer); return par1ItemStack; }
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) { if (entityplayer.inventory.consumeInventoryItem(Item.arrow.shiftedIndex)) { world.playSoundAtEntity( entityplayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 0.8F)); if (!world.singleplayerWorld) { world.entityJoinedWorld(new EntityArrow(world, entityplayer)); } } return itemstack; }
public void onBlockDestroyedByPlayer(World world, int i, int j, int k, int l) { if (world.multiplayerWorld) { return; } if ((l & 1) == 0) { dropBlockAsItem_do(world, i, j, k, new ItemStack(Block.tnt.blockID, 1, 0)); } else { EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(world, (float) i + 0.5F, (float) j + 0.5F, (float) k + 0.5F); world.spawnEntityInWorld(entitytntprimed); world.playSoundAtEntity(entitytntprimed, "random.fuse", 1.0F, 1.0F); } }
public void explode(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase igniter) { if (!worldIn.isRemote) { if (((Boolean) state.getValue(EXPLODE)).booleanValue()) { // float power = 2F + (((5000) / 10369F) * 18F); // ProcessHandler.addProcess(new NuclearExplosion(worldIn, pos.getX(), pos.getY(), // pos.getZ(), power)); EntityNukePrimed entitytntprimed = new EntityNukePrimed( worldIn, pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, igniter); worldIn.spawnEntityInWorld(entitytntprimed); worldIn.playSoundAtEntity(entitytntprimed, "game.tnt.primed", 1.0F, 1.0F); } } }
public void func_94391_a( World par1World, int par2, int par3, int par4, int par5, EntityLiving par6EntityLiving) { if (!par1World.isRemote) { if ((par5 & 1) == 1) { EntityTNTPrimed var7 = new EntityTNTPrimed( par1World, (double) ((float) par2 + 0.5F), (double) ((float) par3 + 0.5F), (double) ((float) par4 + 0.5F), par6EntityLiving); par1World.spawnEntityInWorld(var7); par1World.playSoundAtEntity(var7, "random.fuse", 1.0F, 1.0F); } } }
/** Tries to moves the entity by the passed in displacement. Args: x, y, z */ public void moveEntity(double par1, double par3, double par5) { if (noClip) { boundingBox.offset(par1, par3, par5); posX = (boundingBox.minX + boundingBox.maxX) / 2D; posY = (boundingBox.minY + (double) yOffset) - (double) ySize; posZ = (boundingBox.minZ + boundingBox.maxZ) / 2D; return; } Profiler.startSection("move"); ySize *= 0.4F; double d = posX; double d1 = posZ; if (isInWeb) { isInWeb = false; par1 *= 0.25D; par3 *= 0.05D; par5 *= 0.25D; motionX = 0.0D; motionY = 0.0D; motionZ = 0.0D; } double d2 = par1; double d3 = par3; double d4 = par5; AxisAlignedBB axisalignedbb = boundingBox.copy(); boolean flag = onGround && isSneaking() && (this instanceof EntityPlayer); if (flag) { double d5 = 0.05D; for (; par1 != 0.0D && worldObj .getCollidingBoundingBoxes( this, boundingBox.getOffsetBoundingBox(par1, -1D, 0.0D)) .size() == 0; d2 = par1) { if (par1 < d5 && par1 >= -d5) { par1 = 0.0D; continue; } if (par1 > 0.0D) { par1 -= d5; } else { par1 += d5; } } for (; par5 != 0.0D && worldObj .getCollidingBoundingBoxes( this, boundingBox.getOffsetBoundingBox(0.0D, -1D, par5)) .size() == 0; d4 = par5) { if (par5 < d5 && par5 >= -d5) { par5 = 0.0D; continue; } if (par5 > 0.0D) { par5 -= d5; } else { par5 += d5; } } } List list = worldObj.getCollidingBoundingBoxes(this, boundingBox.addCoord(par1, par3, par5)); for (int i = 0; i < list.size(); i++) { par3 = ((AxisAlignedBB) list.get(i)).calculateYOffset(boundingBox, par3); } boundingBox.offset(0.0D, par3, 0.0D); if (!field_9293_aM && d3 != par3) { par1 = par3 = par5 = 0.0D; } boolean flag1 = onGround || d3 != par3 && d3 < 0.0D; for (int j = 0; j < list.size(); j++) { par1 = ((AxisAlignedBB) list.get(j)).calculateXOffset(boundingBox, par1); } boundingBox.offset(par1, 0.0D, 0.0D); if (!field_9293_aM && d2 != par1) { par1 = par3 = par5 = 0.0D; } for (int k = 0; k < list.size(); k++) { par5 = ((AxisAlignedBB) list.get(k)).calculateZOffset(boundingBox, par5); } boundingBox.offset(0.0D, 0.0D, par5); if (!field_9293_aM && d4 != par5) { par1 = par3 = par5 = 0.0D; } if (stepHeight > 0.0F && flag1 && (flag || ySize < 0.05F) && (d2 != par1 || d4 != par5)) { double d6 = par1; double d8 = par3; double d10 = par5; par1 = d2; par3 = stepHeight; par5 = d4; AxisAlignedBB axisalignedbb1 = boundingBox.copy(); boundingBox.setBB(axisalignedbb); List list1 = worldObj.getCollidingBoundingBoxes(this, boundingBox.addCoord(par1, par3, par5)); for (int j2 = 0; j2 < list1.size(); j2++) { par3 = ((AxisAlignedBB) list1.get(j2)).calculateYOffset(boundingBox, par3); } boundingBox.offset(0.0D, par3, 0.0D); if (!field_9293_aM && d3 != par3) { par1 = par3 = par5 = 0.0D; } for (int k2 = 0; k2 < list1.size(); k2++) { par1 = ((AxisAlignedBB) list1.get(k2)).calculateXOffset(boundingBox, par1); } boundingBox.offset(par1, 0.0D, 0.0D); if (!field_9293_aM && d2 != par1) { par1 = par3 = par5 = 0.0D; } for (int l2 = 0; l2 < list1.size(); l2++) { par5 = ((AxisAlignedBB) list1.get(l2)).calculateZOffset(boundingBox, par5); } boundingBox.offset(0.0D, 0.0D, par5); if (!field_9293_aM && d4 != par5) { par1 = par3 = par5 = 0.0D; } if (!field_9293_aM && d3 != par3) { par1 = par3 = par5 = 0.0D; } else { par3 = -stepHeight; for (int i3 = 0; i3 < list1.size(); i3++) { par3 = ((AxisAlignedBB) list1.get(i3)).calculateYOffset(boundingBox, par3); } boundingBox.offset(0.0D, par3, 0.0D); } if (d6 * d6 + d10 * d10 >= par1 * par1 + par5 * par5) { par1 = d6; par3 = d8; par5 = d10; boundingBox.setBB(axisalignedbb1); } else { double d11 = boundingBox.minY - (double) (int) boundingBox.minY; if (d11 > 0.0D) { ySize += d11 + 0.01D; } } } Profiler.endSection(); Profiler.startSection("rest"); posX = (boundingBox.minX + boundingBox.maxX) / 2D; posY = (boundingBox.minY + (double) yOffset) - (double) ySize; posZ = (boundingBox.minZ + boundingBox.maxZ) / 2D; isCollidedHorizontally = d2 != par1 || d4 != par5; isCollidedVertically = d3 != par3; onGround = d3 != par3 && d3 < 0.0D; isCollided = isCollidedHorizontally || isCollidedVertically; updateFallState(par3, onGround); if (d2 != par1) { motionX = 0.0D; } if (d3 != par3) { motionY = 0.0D; } if (d4 != par5) { motionZ = 0.0D; } double d7 = posX - d; double d9 = posZ - d1; if (canTriggerWalking() && !flag && ridingEntity == null) { distanceWalkedModified += (double) MathHelper.sqrt_double(d7 * d7 + d9 * d9) * 0.6D; int l = MathHelper.floor_double(posX); int j1 = MathHelper.floor_double(posY - 0.2D - (double) yOffset); int l1 = MathHelper.floor_double(posZ); int j3 = worldObj.getBlockId(l, j1, l1); if (j3 == 0 && worldObj.getBlockId(l, j1 - 1, l1) == Block.fence.blockID) { j3 = worldObj.getBlockId(l, j1 - 1, l1); } if (distanceWalkedModified > (float) nextStepDistance && j3 > 0) { nextStepDistance = (int) distanceWalkedModified + 1; playStepSound(l, j1, l1, j3); Block.blocksList[j3].onEntityWalking(worldObj, l, j1, l1, this); } } int i1 = MathHelper.floor_double(boundingBox.minX + 0.001D); int k1 = MathHelper.floor_double(boundingBox.minY + 0.001D); int i2 = MathHelper.floor_double(boundingBox.minZ + 0.001D); int k3 = MathHelper.floor_double(boundingBox.maxX - 0.001D); int l3 = MathHelper.floor_double(boundingBox.maxY - 0.001D); int i4 = MathHelper.floor_double(boundingBox.maxZ - 0.001D); if (worldObj.checkChunksExist(i1, k1, i2, k3, l3, i4)) { for (int j4 = i1; j4 <= k3; j4++) { for (int k4 = k1; k4 <= l3; k4++) { for (int l4 = i2; l4 <= i4; l4++) { int i5 = worldObj.getBlockId(j4, k4, l4); if (i5 > 0) { Block.blocksList[i5].onEntityCollidedWithBlock(worldObj, j4, k4, l4, this); } } } } } boolean flag2 = isWet(); if (worldObj.isBoundingBoxBurning(boundingBox.contract(0.001D, 0.001D, 0.001D))) { dealFireDamage(1); if (!flag2) { fire++; if (fire == 0) { setFire(8); } } } else if (fire <= 0) { fire = -fireResistance; } if (flag2 && fire > 0) { worldObj.playSoundAtEntity( this, "random.fizz", 0.7F, 1.6F + (rand.nextFloat() - rand.nextFloat()) * 0.4F); fire = -fireResistance; } Profiler.endSection(); }
/** Gets called every tick from main Entity class */ public void onEntityUpdate() { Profiler.startSection("entityBaseTick"); if (ridingEntity != null && ridingEntity.isDead) { ridingEntity = null; } ticksExisted++; prevDistanceWalkedModified = distanceWalkedModified; prevPosX = posX; prevPosY = posY; prevPosZ = posZ; prevRotationPitch = rotationPitch; prevRotationYaw = rotationYaw; if (isSprinting() && !isInWater()) { int i = MathHelper.floor_double(posX); int j = MathHelper.floor_double(posY - 0.2D - (double) yOffset); int k = MathHelper.floor_double(posZ); int j1 = worldObj.getBlockId(i, j, k); if (j1 > 0) { worldObj.spawnParticle( (new StringBuilder()).append("tilecrack_").append(j1).toString(), posX + ((double) rand.nextFloat() - 0.5D) * (double) width, boundingBox.minY + 0.1D, posZ + ((double) rand.nextFloat() - 0.5D) * (double) width, -motionX * 4D, 1.5D, -motionZ * 4D); } } if (handleWaterMovement()) { if (!inWater && !firstUpdate) { float f = MathHelper.sqrt_double( motionX * motionX * 0.2D + motionY * motionY + motionZ * motionZ * 0.2D) * 0.2F; if (f > 1.0F) { f = 1.0F; } worldObj.playSoundAtEntity( this, "random.splash", f, 1.0F + (rand.nextFloat() - rand.nextFloat()) * 0.4F); float f1 = MathHelper.floor_double(boundingBox.minY); for (int l = 0; (float) l < 1.0F + width * 20F; l++) { float f2 = (rand.nextFloat() * 2.0F - 1.0F) * width; float f4 = (rand.nextFloat() * 2.0F - 1.0F) * width; worldObj.spawnParticle( "bubble", posX + (double) f2, f1 + 1.0F, posZ + (double) f4, motionX, motionY - (double) (rand.nextFloat() * 0.2F), motionZ); } for (int i1 = 0; (float) i1 < 1.0F + width * 20F; i1++) { float f3 = (rand.nextFloat() * 2.0F - 1.0F) * width; float f5 = (rand.nextFloat() * 2.0F - 1.0F) * width; worldObj.spawnParticle( "splash", posX + (double) f3, f1 + 1.0F, posZ + (double) f5, motionX, motionY, motionZ); } } fallDistance = 0.0F; inWater = true; fire = 0; } else { inWater = false; } if (worldObj.isRemote) { fire = 0; } else if (fire > 0) { if (isImmuneToFire) { fire -= 4; if (fire < 0) { fire = 0; } } else { if (fire % 20 == 0) { attackEntityFrom(DamageSource.onFire, 1); } fire--; } } if (handleLavaMovement()) { setOnFireFromLava(); fallDistance *= 0.5F; } if (posY < -64D) { kill(); } if (!worldObj.isRemote) { setFlag(0, fire > 0); setFlag(2, ridingEntity != null); } firstUpdate = false; Profiler.endSection(); }