code cleanup

Updated star bypass for creative players and invulnerables
This commit is contained in:
LemADEC 2016-02-07 13:10:02 +01:00
parent b0039e5229
commit bce770c28f

View file

@ -11,151 +11,144 @@ import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import cr0s.warpdrive.WarpDrive;
public final class EntityStarCore extends Entity
{
public int xCoord;
public int yCoord;
public int zCoord;
public final class EntityStarCore extends Entity {
public int xCoord;
public int yCoord;
public int zCoord;
private int radius;
private final int KILL_RADIUS = 60;
private final int BURN_RADIUS = 200;
//private final int ROCKET_INTERCEPT_RADIUS = 100; //disabled
private boolean isLogged = false;
private final int ENTITY_ACTION_INTERVAL = 10; // ticks
private int ticks = 0;
public EntityStarCore(World world) {
super(world);
}
public EntityStarCore(World world, int x, int y, int z, int radius) {
super(world);
this.xCoord = x;
this.posX = x;
this.yCoord = y;
this.posY = y;
this.zCoord = z;
this.posZ = z;
this.radius = radius;
}
private void actionToEntitiesNearStar() {
int xmax, ymax, zmax;
int xmin, ymin, zmin;
final int MAX_RANGE = this.radius + KILL_RADIUS + BURN_RADIUS;// + ROCKET_INTERCEPT_RADIUS;
final int KILL_RANGESQ = (this.radius + KILL_RADIUS) * (this.radius + KILL_RADIUS);
final int BURN_RANGESQ = (this.radius + KILL_RADIUS + BURN_RADIUS) * (this.radius + KILL_RADIUS + BURN_RADIUS);
xmin = xCoord - MAX_RANGE;
xmax = xCoord + MAX_RANGE;
zmin = zCoord - MAX_RANGE;
zmax = zCoord + MAX_RANGE;
ymin = yCoord - MAX_RANGE;
ymax = yCoord + MAX_RANGE;
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(xmin, ymin, zmin, xmax, ymax, zmax);
List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, aabb);
if (!isLogged) {
isLogged = true;
WarpDrive.logger.info(this + " Capture range " + MAX_RANGE + " X " + xmin + " to " + xmax + " Y " + ymin + " to " + ymax + " Z " + zmin + " to " + zmax);
}
for (Object object : list) {
if (!(object instanceof Entity)) {
continue;
}
if (object instanceof EntityLivingBase) {
EntityLivingBase entity = (EntityLivingBase) object;
//System.out.println("Found: " + entity.getEntityName() + " distance: " + entity.getDistanceToEntity(this));
// creative bypass
if (entity.invulnerable) {
continue;
}
if (entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
if (player.capabilities.isCreativeMode) {
continue;
}
}
double distanceSq = entity.getDistanceSqToEntity(this);
if (distanceSq <= KILL_RANGESQ) {
// 100% kill, ignores any protection
entity.attackEntityFrom(DamageSource.onFire, 9000);
entity.attackEntityFrom(DamageSource.generic, 9000);
if (!entity.isDead) {
WarpDrive.logger.warn("Forcing entity death due to star proximity: " + entity);
entity.setDead();
}
} else if (distanceSq <= BURN_RANGESQ) {
// burn entity
if (!entity.isImmuneToFire()) {
entity.setFire(3);
}
entity.attackEntityFrom(DamageSource.onFire, 1);
}
}/* else { // Intercept ICBM rocket and kill
private int radius;
private final int KILL_RADIUS = 60;
private final int BURN_RADIUS = 200;
//private final int ROCKET_INTERCEPT_RADIUS = 100; //disabled
private boolean isLogged = false;
private final int ENTITY_ACTION_INTERVAL = 10; // ticks
private int ticks = 0;
public EntityStarCore(World world)
{
super(world);
}
public EntityStarCore(World world, int x, int y, int z, int radius)
{
super(world);
this.xCoord = x;
this.posX = x;
this.yCoord = y;
this.posY = y;
this.zCoord = z;
this.posZ = z;
this.radius = radius;
}
private void actionToEntitiesNearStar()
{
int xmax, ymax, zmax;
int xmin, ymin, zmin;
final int MAX_RANGE = this.radius + KILL_RADIUS + BURN_RADIUS;// + ROCKET_INTERCEPT_RADIUS;
final int KILL_RANGESQ = (this.radius + KILL_RADIUS) * (this.radius + KILL_RADIUS);
final int BURN_RANGESQ = (this.radius + KILL_RADIUS + BURN_RADIUS) * (this.radius + KILL_RADIUS + BURN_RADIUS);
xmin = xCoord - MAX_RANGE;
xmax = xCoord + MAX_RANGE;
zmin = zCoord - MAX_RANGE;
zmax = zCoord + MAX_RANGE;
ymin = yCoord - MAX_RANGE;
ymax = yCoord + MAX_RANGE;
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(xmin, ymin, zmin, xmax, ymax, zmax);
List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, aabb);
if (!isLogged)
{
isLogged = true;
WarpDrive.logger.info(this + " Capture range " + MAX_RANGE
+ " X " + xmin + " to " + xmax + " Y " + ymin + " to " + ymax + " Z " + zmin + " to " + zmax);
}
for (Object o : list)
{
if (o == null || !(o instanceof Entity))
{
continue;
}
if (o instanceof EntityLivingBase)
{
EntityLivingBase entity = (EntityLivingBase)o;
//System.out.println("Found: " + entity.getEntityName() + " distance: " + entity.getDistanceToEntity(this));
if (entity.getDistanceSqToEntity(this) <= KILL_RANGESQ)
{
// 100% kill, ignores any protection
entity.attackEntityFrom(DamageSource.onFire, 9000);
}
else if (entity.getDistanceSqToEntity(this) <= BURN_RANGESQ)
{
if (entity instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer)entity;
if (player.capabilities.isCreativeMode)
continue;
}
// burn entity to 100 seconds
if (!entity.isImmuneToFire())
entity.setFire(100);
entity.attackEntityFrom(DamageSource.onFire, 1);
}
}/* else { // Intercept ICBM rocket and kill
Entity entity = (Entity) o;
if (entity.getDistanceToEntity(this) <= (this.radius + ROCKET_INTERCEPT_RADIUS)) {
System.out.println("[SC] Intercepted entity: " + entity.getEntityName());
worldObj.removeEntity(entity);
}
}*/
}
}
public void killEntity()
{
worldObj.removeEntity(this);
}
@Override
public void onUpdate()
{
if (worldObj.isRemote)
{
return;
}
if (++ticks > ENTITY_ACTION_INTERVAL)
{
ticks = 0;
actionToEntitiesNearStar();
}
}
@Override
protected void readEntityFromNBT(NBTTagCompound nbttagcompound)
{
this.xCoord = nbttagcompound.getInteger("x");
this.yCoord = nbttagcompound.getInteger("y");
this.zCoord = nbttagcompound.getInteger("z");
this.radius = nbttagcompound.getInteger("radius");
}
@Override
protected void entityInit()
{
}
@Override
protected void writeEntityToNBT(NBTTagCompound nbttagcompound)
{
nbttagcompound.setInteger("x", this.xCoord);
nbttagcompound.setInteger("y", this.yCoord);
nbttagcompound.setInteger("z", this.zCoord);
nbttagcompound.setInteger("radius", this.radius);
}
@Override
public boolean shouldRenderInPass(int pass)
{
return false;
}
Entity entity = (Entity) o;
if (entity.getDistanceToEntity(this) <= (this.radius + ROCKET_INTERCEPT_RADIUS)) {
System.out.println("[SC] Intercepted entity: " + entity.getEntityName());
worldObj.removeEntity(entity);
}
}*/
}
}
public void killEntity() {
worldObj.removeEntity(this);
}
@Override
public void onUpdate() {
if (worldObj.isRemote) {
return;
}
if (++ticks > ENTITY_ACTION_INTERVAL) {
ticks = 0;
actionToEntitiesNearStar();
}
}
@Override
protected void readEntityFromNBT(NBTTagCompound nbttagcompound) {
this.xCoord = nbttagcompound.getInteger("x");
this.yCoord = nbttagcompound.getInteger("y");
this.zCoord = nbttagcompound.getInteger("z");
this.radius = nbttagcompound.getInteger("radius");
}
@Override
protected void entityInit() {
}
@Override
protected void writeEntityToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setInteger("x", this.xCoord);
nbttagcompound.setInteger("y", this.yCoord);
nbttagcompound.setInteger("z", this.zCoord);
nbttagcompound.setInteger("radius", this.radius);
}
@Override
public boolean shouldRenderInPass(int pass) {
return false;
}
}