Rework clipping logic again, now works as well as the original implementation

Dieser Commit ist enthalten in:
EvilSeph 2012-04-20 00:28:30 -05:00
Ursprung 3e15a6911f
Commit 8f6fe0a643
3 geänderte Dateien mit 84 neuen und 30 gelöschten Zeilen

Datei anzeigen

@ -22,9 +22,65 @@ import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.plugin.PluginManager;
import org.bukkit.util.NumberConversions;
// CraftBukkit end
public abstract class Entity {
// CraftBukkit start - size of entity for clipping calculations
public enum EntitySize {
SIZE_1,
SIZE_2,
SIZE_3,
SIZE_4,
SIZE_5,
SIZE_6;
public int getXZCoord(double loc) {
double diff = loc - (NumberConversions.floor(loc) + 0.5D);
switch (this) {
case SIZE_1:
if (diff < 0.0D ? diff < -0.3125D : diff < 0.3125D) {
return NumberConversions.ceil(loc * 32.0D);
}
return NumberConversions.floor(loc * 32.0D);
case SIZE_2:
if (diff < 0.0D ? diff < -0.3125D : diff < 0.3125D) {
return NumberConversions.floor(loc * 32.0D);
}
return NumberConversions.ceil(loc * 32.0D);
case SIZE_3:
if (diff > 0.0D) {
return NumberConversions.floor(loc * 32.0D);
}
return NumberConversions.ceil(loc * 32.0D);
case SIZE_4:
if (diff < 0.0D ? diff < -0.1875D : diff < 0.1875D) {
return NumberConversions.ceil(loc * 32.0D);
}
return NumberConversions.floor(loc * 32.0D);
case SIZE_5:
if (diff < 0.0D ? diff < -0.1875D : diff < 0.1875D) {
return NumberConversions.floor(loc * 32.0D);
}
return NumberConversions.ceil(loc * 32.0D);
case SIZE_6:
default:
if (diff > 0.0D) {
return NumberConversions.ceil(loc * 32.0D);
}
return NumberConversions.floor(loc * 32.0D);
}
}
}
public EntitySize size;
// CraftBukkit end
private static int entityCount = 0;
public int id;
@ -100,6 +156,7 @@ public abstract class Entity {
this.dead = false;
this.height = 0.0F;
this.width = 0.6F;
this.size = EntitySize.SIZE_2; // CraftBukkit
this.length = 1.8F;
this.bI = 0.0F;
this.bJ = 0.0F;
@ -147,6 +204,22 @@ public abstract class Entity {
protected void b(float f, float f1) {
this.width = f;
this.length = f1;
// CraftBukkit start - figure out entity size for clipping calculations
float mod = f % 2f;
if (mod < 0.375) {
this.size = EntitySize.SIZE_1;
} else if (mod < 0.75) {
this.size = EntitySize.SIZE_2;
} else if (mod < 1.0) {
this.size = EntitySize.SIZE_3;
} else if (mod < 1.375) {
this.size = EntitySize.SIZE_4;
} else if (mod < 1.75) {
this.size = EntitySize.SIZE_5;
} else {
this.size = EntitySize.SIZE_6;
}
// CraftBukkit end
}
protected void c(float f, float f1) {

Datei anzeigen

@ -6,8 +6,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.bukkit.util.NumberConversions; // Craftbukkit
public class EntityTrackerEntry {
public Entity tracker;
@ -66,29 +64,10 @@ public class EntityTrackerEntry {
++this.u;
if (this.m++ % this.c == 0 || this.tracker.ce) {
// CraftBukkit start - Add logic for clipping;
boolean xFlag = NumberConversions.floor(this.tracker.locX) - this.tracker.locX > -.5d;
boolean zFlag = NumberConversions.floor(this.tracker.locZ) - this.tracker.locZ > -.5d;
if ((this.tracker.width % 2f) >= 1f) {
xFlag = !xFlag;
zFlag = !zFlag;
}
int i;
int j = NumberConversions.ceil(this.tracker.locY * 32.0D);;
int k;
if (xFlag) {
i = NumberConversions.ceil(this.tracker.locX * 32.0D);
} else {
i = NumberConversions.floor(this.tracker.locX * 32.0D);
}
if (zFlag) {
k = NumberConversions.ceil(this.tracker.locZ * 32.0D);
} else {
k = NumberConversions.floor(this.tracker.locZ * 32.0D);
}
// CraftBukkit start - add logic for clipping
int i = this.tracker.size.getXZCoord(this.tracker.locX);
int j = org.bukkit.util.NumberConversions.floor(this.tracker.locY * 32.0D);
int k = this.tracker.size.getXZCoord(this.tracker.locZ);
// CraftBukkit end - logic for clipping
int l = MathHelper.d(this.tracker.yaw * 256.0F / 360.0F);
@ -124,7 +103,7 @@ public class EntityTrackerEntry {
} else {
this.u = 0;
// CraftBukkit start
// remove (redundant?) setting of entity location to avoid clipping through blocks
// remove setting of entity location to avoid clipping through blocks
//this.tracker.locX = (double) i / 32.0D;
//this.tracker.locY = (double) j / 32.0D;
//this.tracker.locZ = (double) k / 32.0D;
@ -133,7 +112,7 @@ public class EntityTrackerEntry {
if (this.tracker instanceof EntityPlayer) {
this.scanPlayers(new ArrayList(this.trackedPlayers));
}
object = new Packet34EntityTeleport(this.tracker.id, i, j, k, (byte) l, (byte) i1); // move entities down 1 client side so they don't clip up out of boxes
object = new Packet34EntityTeleport(this.tracker.id, i, j, k, (byte) l, (byte) i1);
// CraftBukkit end
}

Datei anzeigen

@ -24,9 +24,11 @@ public class Packet24MobSpawn extends Packet {
public Packet24MobSpawn(EntityLiving entityliving) {
this.a = entityliving.id;
this.b = (byte) EntityTypes.a((Entity) entityliving);
this.c = MathHelper.floor(entityliving.locX * 32.0D);
this.d = MathHelper.floor(entityliving.locY * 32.0D);
this.e = MathHelper.floor(entityliving.locZ * 32.0D);
// CraftBukkit start - floors to new intelligence
this.c = entityliving.size.getXZCoord(entityliving.locX);
this.d = org.bukkit.util.NumberConversions.floor(entityliving.locY * 32.0D);
this.e = entityliving.size.getXZCoord(entityliving.locZ);
// CraftBukkit end
this.f = (byte) ((int) (entityliving.yaw * 256.0F / 360.0F));
this.g = (byte) ((int) (entityliving.pitch * 256.0F / 360.0F));
this.h = (byte) ((int) (entityliving.X * 256.0F / 360.0F));