3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-26 08:10:06 +01:00
Paper/src/main/java/net/minecraft/server/EntitySquid.java
Travis Watkins a2d9f33ca3 Various minor performance improvements
Add a check to avoid doing movement work if an entity doesn't move. This
usually will not ever happen in the current server but is useful when it
does and will be more useful in the future.

Only process mob on mob (non-player) collisions every other tick. Players
tend to pack a lot of mobs into a small space (sheep farm, mob grinder, etc)
so they do a lot of work processing collisions. To help alleviate some of
this we only run these calculations every other tick. This has no visible
effect on the client but can be a huge win on the server depending on
circumstances.

Use generic entity inWater checking for squids. Squids have their own logic
currently for determining if they are in water. This check is almost
identical to the generic entity checking which is run anyway. To avoid
doing duplicate work we just remove the squid version. This does not
have any noticeable effect on gameplay since the checks are so similar.

Use HashSet for tile entities instead of ArrayList. Using an ArrayList for
storing tile entities in a world means we have very expensive inserts and
removes that aren't at the end of the array due to the array copy this
causes. This is most noticeable during chunk unload when a large number of
tile entities are removed from the world at once. Using a HashSet here uses
a little more memory but is O(1) for all operations so removes this
bottleneck.
2013-04-13 00:30:43 -05:00

153 Zeilen
4.5 KiB
Java

package net.minecraft.server;
import org.bukkit.craftbukkit.TrigMath; // CraftBukkit
public class EntitySquid extends EntityWaterAnimal {
public float d = 0.0F;
public float e = 0.0F;
public float f = 0.0F;
public float g = 0.0F;
public float h = 0.0F;
public float i = 0.0F;
public float j = 0.0F;
public float bK = 0.0F;
private float bL = 0.0F;
private float bM = 0.0F;
private float bN = 0.0F;
private float bO = 0.0F;
private float bP = 0.0F;
private float bQ = 0.0F;
public EntitySquid(World world) {
super(world);
this.texture = "/mob/squid.png";
this.a(0.95F, 0.95F);
this.bM = 1.0F / (this.random.nextFloat() + 1.0F) * 0.2F;
}
public int getMaxHealth() {
return 10;
}
protected String bb() {
return null;
}
protected String bc() {
return null;
}
protected String bd() {
return null;
}
protected float ba() {
return 0.4F;
}
protected int getLootId() {
return 0;
}
protected void dropDeathLoot(boolean flag, int i) {
// CraftBukkit start - Whole method
java.util.List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<org.bukkit.inventory.ItemStack>();
int count = this.random.nextInt(3 + i) + 1;
if (count > 0) {
loot.add(new org.bukkit.inventory.ItemStack(org.bukkit.Material.INK_SACK, count));
}
org.bukkit.craftbukkit.event.CraftEventFactory.callEntityDeathEvent(this, loot);
// CraftBukkit end
}
/* CraftBukkit start - Delegate to Entity to use existing inWater value
public boolean G() {
return this.world.a(this.boundingBox.grow(0.0D, -0.6000000238418579D, 0.0D), Material.WATER, (Entity) this);
}
// CraftBukkit end */
public void c() {
super.c();
this.e = this.d;
this.g = this.f;
this.i = this.h;
this.bK = this.j;
this.h += this.bM;
if (this.h > 6.2831855F) {
this.h -= 6.2831855F;
if (this.random.nextInt(10) == 0) {
this.bM = 1.0F / (this.random.nextFloat() + 1.0F) * 0.2F;
}
}
if (this.G()) {
float f;
if (this.h < 3.1415927F) {
f = this.h / 3.1415927F;
this.j = MathHelper.sin(f * f * 3.1415927F) * 3.1415927F * 0.25F;
if ((double) f > 0.75D) {
this.bL = 1.0F;
this.bN = 1.0F;
} else {
this.bN *= 0.8F;
}
} else {
this.j = 0.0F;
this.bL *= 0.9F;
this.bN *= 0.99F;
}
if (!this.world.isStatic) {
this.motX = (double) (this.bO * this.bL);
this.motY = (double) (this.bP * this.bL);
this.motZ = (double) (this.bQ * this.bL);
}
f = MathHelper.sqrt(this.motX * this.motX + this.motZ * this.motZ);
// CraftBukkit - Math -> TrigMath
this.ay += (-((float) TrigMath.atan2(this.motX, this.motZ)) * 180.0F / 3.1415927F - this.ay) * 0.1F;
this.yaw = this.ay;
this.f += 3.1415927F * this.bN * 1.5F;
// CraftBukkit - Math -> TrigMath
this.d += (-((float) TrigMath.atan2((double) f, this.motY)) * 180.0F / 3.1415927F - this.d) * 0.1F;
} else {
this.j = MathHelper.abs(MathHelper.sin(this.h)) * 3.1415927F * 0.25F;
if (!this.world.isStatic) {
this.motX = 0.0D;
this.motY -= 0.08D;
this.motY *= 0.9800000190734863D;
this.motZ = 0.0D;
}
this.d = (float) ((double) this.d + (double) (-90.0F - this.d) * 0.02D);
}
}
public void e(float f, float f1) {
this.move(this.motX, this.motY, this.motZ);
}
protected void bq() {
++this.bC;
if (this.bC > 100) {
this.bO = this.bP = this.bQ = 0.0F;
} else if (this.random.nextInt(50) == 0 || !this.inWater || this.bO == 0.0F && this.bP == 0.0F && this.bQ == 0.0F) {
float f = this.random.nextFloat() * 3.1415927F * 2.0F;
this.bO = MathHelper.cos(f) * 0.2F;
this.bP = -0.1F + this.random.nextFloat() * 0.2F;
this.bQ = MathHelper.sin(f) * 0.2F;
}
this.bn();
}
public boolean canSpawn() {
return this.locY > 45.0D && this.locY < 63.0D && super.canSpawn();
}
}