Commit a585c5b1 authored by Theray070696's avatar Theray070696

Remove more unneeded instances of square root calls

Update some ItemStack comparisons to ItemStack.EMPTY instead of null
parent a347d647
......@@ -13,12 +13,12 @@ import com.lycanitesmobs.core.pets.DonationFamiliars;
import com.lycanitesmobs.core.pets.PetEntry;
import com.lycanitesmobs.core.pets.PetManager;
import com.lycanitesmobs.core.pets.SummonSet;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumHand;
......@@ -167,14 +167,13 @@ public class ExtendedPlayer implements IExtendedPlayer {
double heightCompensation = 0;
if(heightOffset > 0)
heightCompensation = Math.min(heightOffset, targetHeight);
double distance = Math.sqrt(this.player.getDistance(targetEntity));
double range = 6 + heightCompensation + (targetWidth / 2);
return distance <= range;
return this.player.getDistanceSq(targetEntity) <= range * range;
}
/** Makes this player attempt to melee attack. This is typically used for when the vanilla attack range fails on big entities. **/
public void meleeAttack(Entity targetEntity) {
if(!this.hasAttacked && this.player.getHeldItemMainhand() != null && this.canMeleeBigEntity(targetEntity)) {
if(!this.hasAttacked && this.player.getHeldItemMainhand() != ItemStack.EMPTY && this.canMeleeBigEntity(targetEntity)) {
this.player.attackTargetEntityWithCurrentItem(targetEntity);
this.player.resetCooldown();
this.player.swingArm(EnumHand.MAIN_HAND);
......@@ -214,8 +213,8 @@ public class ExtendedPlayer implements IExtendedPlayer {
this.summonFocus++;
if(!this.player.getEntityWorld().isRemote && !creative && this.currentTick % 20 == 0
|| this.summonFocus < this.summonFocusMax
|| (this.player.getHeldItemMainhand() != null && this.player.getHeldItemMainhand().getItem() instanceof ItemStaffSummoning)
|| (this.player.getHeldItemOffhand() != null && this.player.getHeldItemOffhand().getItem() instanceof ItemStaffSummoning)) {
|| (this.player.getHeldItemMainhand() != ItemStack.EMPTY && this.player.getHeldItemMainhand().getItem() instanceof ItemStaffSummoning)
|| (this.player.getHeldItemOffhand() != ItemStack.EMPTY && this.player.getHeldItemOffhand().getItem() instanceof ItemStaffSummoning)) {
sync = true;
}
}
......
......@@ -1673,7 +1673,7 @@ public abstract class EntityCreatureBase extends EntityLiving {
if(!this.getEntityWorld().isRemote && this.pickupEntity != null) {
if(!this.pickupEntity.isEntityAlive())
this.dropPickupEntity();
else if(Math.sqrt(this.getDistance(this.pickupEntity)) > 32D) {
else if(this.getDistanceSq(this.pickupEntity) > 32D * 32D) {
this.dropPickupEntity();
}
}
......
......@@ -52,9 +52,8 @@ public class StructureSpawnLocation extends RandomSpawnLocation {
}
// Too Far:
double structureDistance = Math.sqrt(structurePos.distanceSq(triggerPos));
if(structureDistance > this.structureRange) {
LycanitesMobs.printDebug("JSONSpawner", "No Structures within range, nearest was: " + structureDistance + " at: " + structurePos);
if(structurePos.distanceSq(triggerPos) > this.structureRange * this.structureRange) {
LycanitesMobs.printDebug("JSONSpawner", "No Structures within range, nearest was: " + Math.sqrt(structurePos.distanceSq(triggerPos)) + " at: " + structurePos);
return new ArrayList<>();
}
......
......@@ -38,9 +38,8 @@ public class VillageSpawnLocation extends RandomSpawnLocation {
}
// Too Far:
double villageDistance = Math.sqrt(village.getCenter().distanceSq(triggerPos));
if(villageDistance > this.villageRange) {
LycanitesMobs.printDebug("JSONSpawner", "No Village within range, nearest was: " + villageDistance + " at: " + village.getCenter());
if(village.getCenter().distanceSq(triggerPos) > this.villageRange * this.villageRange) {
LycanitesMobs.printDebug("JSONSpawner", "No Village within range, nearest was: " + Math.sqrt(village.getCenter().distanceSq(triggerPos)) + " at: " + village.getCenter());
return new ArrayList<>();
}
......
......@@ -6,15 +6,16 @@ import com.lycanitesmobs.api.IGroupRock;
import com.lycanitesmobs.core.config.ConfigBase;
import com.lycanitesmobs.core.entity.EntityCreatureTameable;
import com.lycanitesmobs.core.entity.ai.*;
import net.minecraft.block.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockChest;
import net.minecraft.block.BlockDoor;
import net.minecraft.block.BlockGlowstone;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.monster.EntityIronGolem;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ContainerChest;
import net.minecraft.inventory.ContainerFurnace;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.BlockPos;
import net.minecraft.village.Village;
......@@ -114,7 +115,7 @@ public class EntityAegis extends EntityCreatureTameable implements IGroupRock, I
if(this.village != null) {
reputation = this.village.getPlayerReputation(player.getUniqueID());
}
if (this.chestProtection && reputation <= 0 && Math.sqrt(player.getDistanceSq(protectLocation)) <= 60)
if (this.chestProtection && reputation <= 0 && player.getDistanceSq(protectLocation) <= 60 * 60)
if (player.openContainer != null && (player.openContainer instanceof ContainerChest)) {
this.setAttackTarget(player);
this.setFixateTarget(player);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment