Finished update of data classes

This commit is contained in:
Francesco Macagno 2015-07-20 22:36:29 -07:00
parent c8b21e9b5c
commit 0df194b33a
3 changed files with 214 additions and 237 deletions

View file

@ -3,40 +3,20 @@ package cr0s.warpdrive.data;
import java.util.LinkedList;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLeashKnot;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.boss.EntityDragon;
import net.minecraft.entity.item.EntityBoat;
import net.minecraft.entity.item.EntityEnderCrystal;
import net.minecraft.entity.item.EntityEnderEye;
import net.minecraft.entity.item.EntityEnderPearl;
import net.minecraft.entity.item.EntityExpBottle;
import net.minecraft.entity.item.EntityFireworkRocket;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.entity.item.EntityPainting;
import net.minecraft.entity.item.EntityTNTPrimed;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.passive.IAnimals;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.entity.projectile.EntityEgg;
import net.minecraft.entity.projectile.EntityFireball;
import net.minecraft.entity.projectile.EntityFishHook;
import net.minecraft.entity.projectile.EntityPotion;
import net.minecraft.entity.projectile.EntitySmallFireball;
import net.minecraft.entity.projectile.EntitySnowball;
import net.minecraft.entity.projectile.EntityWitherSkull;
import net.minecraft.network.Packet;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import com.sun.media.jfxmedia.logging.Logger;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import cr0s.warpdrive.PacketHandler;
/**
* Cloak manager stores cloaking devices covered areas
*
* @author Cr0s
*
*/
@ -44,7 +24,7 @@ import cr0s.warpdrive.PacketHandler;
public class CloakManager {
private LinkedList<CloakedArea> cloaks;
public CloakManager() {
this.cloaks = new LinkedList<CloakedArea>();
}
@ -54,161 +34,157 @@ public class CloakManager {
if (area.dimensionId != dimensionID) {
continue;
}
if (area.aabb.minX <= x && area.aabb.maxX >= x && area.aabb.minY <= y && area.aabb.maxY >= y && area.aabb.minZ <= z && area.aabb.maxZ >= z) {
return true;
}
}
return false;
}
public boolean checkChunkLoaded(EntityPlayerMP player, int chunkPosX, int chunkPosZ) {
for (CloakedArea area : this.cloaks) {
if (area.dimensionId != player.worldObj.provider.dimensionId) {
continue;
}
if ( area.aabb.minX <= (chunkPosX << 4 + 15) && area.aabb.maxX >= (chunkPosX << 4)
&& area.aabb.minZ <= (chunkPosZ << 4 + 15) && area.aabb.maxZ >= (chunkPosZ << 4) ) {
if (area.aabb.minX <= (chunkPosX << 4 + 15) && area.aabb.maxX >= (chunkPosX << 4) && area.aabb.minZ <= (chunkPosZ << 4 + 15)
&& area.aabb.maxZ >= (chunkPosZ << 4)) {
PacketHandler.sendCloakPacket(player, area.aabb, area.tier, false);
}
}
return false;
}
public boolean isAreaExists(World worldObj, int x, int y, int z) {
return (getCloakedArea(worldObj, x, y, z) != null);
return (getCloakedArea(worldObj, x, y, z) != null);
}
public void addCloakedAreaWorld(World worldObj, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int x, int y, int z, byte tier) {
public void addCloakedAreaWorld(World worldObj, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int x, int y, int z, byte tier) {
cloaks.add(new CloakedArea(worldObj, x, y, z, AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ), tier));
}
}
public void removeCloakedArea(World worldObj, int x, int y, int z) {
int index = 0;
for (int i = 0; i < this.cloaks.size(); i++) {
if (this.cloaks.get(i).coreX == x && this.cloaks.get(i).coreY == y && this.cloaks.get(i).coreZ == z && this.cloaks.get(i).dimensionId == worldObj.provider.dimensionId) {
this.cloaks.get(i).sendCloakPacketToPlayersEx(true); // send info about collapsing cloaking field
if (this.cloaks.get(i).coreX == x && this.cloaks.get(i).coreY == y && this.cloaks.get(i).coreZ == z
&& this.cloaks.get(i).dimensionId == worldObj.provider.dimensionId) {
this.cloaks.get(i).sendCloakPacketToPlayersEx(true); // send
// info
// about
// collapsing
// cloaking
// field
index = i;
break;
}
}
cloaks.remove(index);
}
public CloakedArea getCloakedArea(World worldObj, int x, int y, int z) {
for (CloakedArea area : this.cloaks) {
if (area.coreX == x && area.coreY == y && area.coreZ == z && area.dimensionId == worldObj.provider.dimensionId)
return area;
}
return null;
}
public void updatePlayer(EntityPlayer player) {
for (CloakedArea area : this.cloaks) {
area.updatePlayer(player);
}
}
public static Packet getPacketForThisEntity(Entity e) {
if (e.isDead) {
e.worldObj.getWorldLogAgent().logWarning("Fetching addPacket for removed entity");
}
if (e.isDead) {
Logger.logMsg(Logger.WARNING, "Fetching addPacket for removed entity");
}
Packet pkt = FMLNetworkHandler.getEntitySpawningPacket(e);
if (pkt != null) {
return pkt;
}
Packet pkt = FMLNetworkHandler.getEntitySpawningPacket(e);
if (pkt != null) {
return pkt;
}
if (e instanceof EntityItem) {
return new Packet23VehicleSpawn(e, 2, 1);
} else if (e instanceof EntityPlayerMP) {
return new Packet20NamedEntitySpawn((EntityPlayer)e);
} else if (e instanceof EntityMinecart) {
EntityMinecart entityminecart = (EntityMinecart)e;
return new Packet23VehicleSpawn(e, 10, entityminecart.getMinecartType());
} else if (e instanceof EntityBoat) {
return new Packet23VehicleSpawn(e, 1);
} else if (!(e instanceof IAnimals) && !(e instanceof EntityDragon)) {
if (e instanceof EntityFishHook) {
EntityPlayer entityplayer = ((EntityFishHook)e).angler;
return new Packet23VehicleSpawn(e, 90, entityplayer != null ? entityplayer.entityId : e.entityId);
} else if (e instanceof EntityArrow) {
Entity entity = ((EntityArrow)e).shootingEntity;
return new Packet23VehicleSpawn(e, 60, entity != null ? entity.entityId : e.entityId);
} else if (e instanceof EntitySnowball) {
return new Packet23VehicleSpawn(e, 61);
} else if (e instanceof EntityPotion) {
return new Packet23VehicleSpawn(e, 73, ((EntityPotion)e).getPotionDamage());
} else if (e instanceof EntityExpBottle) {
return new Packet23VehicleSpawn(e, 75);
} else if (e instanceof EntityEnderPearl) {
return new Packet23VehicleSpawn(e, 65);
} else if (e instanceof EntityEnderEye) {
return new Packet23VehicleSpawn(e, 72);
} else if (e instanceof EntityFireworkRocket) {
return new Packet23VehicleSpawn(e, 76);
} else {
Packet23VehicleSpawn packet23vehiclespawn;
return null;
if (e instanceof EntityFireball) {
EntityFireball entityfireball = (EntityFireball)e;
packet23vehiclespawn = null;
byte b0 = 63;
if (e instanceof EntitySmallFireball) {
b0 = 64;
} else if (e instanceof EntityWitherSkull) {
b0 = 66;
}
if (entityfireball.shootingEntity != null) {
packet23vehiclespawn = new Packet23VehicleSpawn(e, b0, ((EntityFireball)e).shootingEntity.entityId);
} else {
packet23vehiclespawn = new Packet23VehicleSpawn(e, b0, 0);
}
packet23vehiclespawn.speedX = (int)(entityfireball.accelerationX * 8000.0D);
packet23vehiclespawn.speedY = (int)(entityfireball.accelerationY * 8000.0D);
packet23vehiclespawn.speedZ = (int)(entityfireball.accelerationZ * 8000.0D);
return packet23vehiclespawn;
} else if (e instanceof EntityEgg) {
return new Packet23VehicleSpawn(e, 62);
} else if (e instanceof EntityTNTPrimed) {
return new Packet23VehicleSpawn(e, 50);
} else if (e instanceof EntityEnderCrystal) {
return new Packet23VehicleSpawn(e, 51);
} else if (e instanceof EntityFallingSand) {
EntityFallingSand entityfallingsand = (EntityFallingSand)e;
return new Packet23VehicleSpawn(e, 70, entityfallingsand.blockID | entityfallingsand.metadata << 16);
} else if (e instanceof EntityPainting) {
return new Packet25EntityPainting((EntityPainting)e);
} else if (e instanceof EntityItemFrame) {
EntityItemFrame entityitemframe = (EntityItemFrame)e;
packet23vehiclespawn = new Packet23VehicleSpawn(e, 71, entityitemframe.hangingDirection);
packet23vehiclespawn.xPosition = MathHelper.floor_float(entityitemframe.xPosition * 32);
packet23vehiclespawn.yPosition = MathHelper.floor_float(entityitemframe.yPosition * 32);
packet23vehiclespawn.zPosition = MathHelper.floor_float(entityitemframe.zPosition * 32);
return packet23vehiclespawn;
} else if (e instanceof EntityLeashKnot) {
EntityLeashKnot entityleashknot = (EntityLeashKnot)e;
packet23vehiclespawn = new Packet23VehicleSpawn(e, 77);
packet23vehiclespawn.xPosition = MathHelper.floor_float(entityleashknot.xPosition * 32);
packet23vehiclespawn.yPosition = MathHelper.floor_float(entityleashknot.yPosition * 32);
packet23vehiclespawn.zPosition = MathHelper.floor_float(entityleashknot.zPosition * 32);
return packet23vehiclespawn;
} else if (e instanceof EntityXPOrb) {
return new Packet26EntityExpOrb((EntityXPOrb)e);
} else {
throw new IllegalArgumentException("Don\'t know how to add " + e.getClass() + "!");
}
}
} else {
return new Packet24MobSpawn((EntityLivingBase)e);
}
}
// TODO: Major, redo networking
/*
* if (e instanceof EntityItem) { return new Packet23VehicleSpawn(e, 2,
* 1); } else if (e instanceof EntityPlayerMP) { return new
* Packet20NamedEntitySpawn((EntityPlayer) e); } else if (e instanceof
* EntityMinecart) { EntityMinecart entityminecart = (EntityMinecart) e;
* return new Packet23VehicleSpawn(e, 10,
* entityminecart.getMinecartType()); } else if (e instanceof
* EntityBoat) { return new Packet23VehicleSpawn(e, 1); } else if (!(e
* instanceof IAnimals) && !(e instanceof EntityDragon)) { if (e
* instanceof EntityFishHook) { EntityPlayer entityplayer =
* ((EntityFishHook) e).angler; return new Packet23VehicleSpawn(e, 90,
* entityplayer != null ? entityplayer.entityId : e.entityId); } else if
* (e instanceof EntityArrow) { Entity entity = ((EntityArrow)
* e).shootingEntity; return new Packet23VehicleSpawn(e, 60, entity !=
* null ? entity.entityId : e.entityId); } else if (e instanceof
* EntitySnowball) { return new Packet23VehicleSpawn(e, 61); } else if
* (e instanceof EntityPotion) { return new Packet23VehicleSpawn(e, 73,
* ((EntityPotion) e).getPotionDamage()); } else if (e instanceof
* EntityExpBottle) { return new Packet23VehicleSpawn(e, 75); } else if
* (e instanceof EntityEnderPearl) { return new Packet23VehicleSpawn(e,
* 65); } else if (e instanceof EntityEnderEye) { return new
* Packet23VehicleSpawn(e, 72); } else if (e instanceof
* EntityFireworkRocket) { return new Packet23VehicleSpawn(e, 76); }
* else { Packet23VehicleSpawn packet23vehiclespawn;
*
* if (e instanceof EntityFireball) { EntityFireball entityfireball =
* (EntityFireball) e; packet23vehiclespawn = null; byte b0 = 63;
*
* if (e instanceof EntitySmallFireball) { b0 = 64; } else if (e
* instanceof EntityWitherSkull) { b0 = 66; }
*
* if (entityfireball.shootingEntity != null) { packet23vehiclespawn =
* new Packet23VehicleSpawn(e, b0, ((EntityFireball)
* e).shootingEntity.entityId); } else { packet23vehiclespawn = new
* Packet23VehicleSpawn(e, b0, 0); }
*
* packet23vehiclespawn.speedX = (int) (entityfireball.accelerationX *
* 8000.0D); packet23vehiclespawn.speedY = (int)
* (entityfireball.accelerationY * 8000.0D); packet23vehiclespawn.speedZ
* = (int) (entityfireball.accelerationZ * 8000.0D); return
* packet23vehiclespawn; } else if (e instanceof EntityEgg) { return new
* Packet23VehicleSpawn(e, 62); } else if (e instanceof EntityTNTPrimed)
* { return new Packet23VehicleSpawn(e, 50); } else if (e instanceof
* EntityEnderCrystal) { return new Packet23VehicleSpawn(e, 51); } else
* if (e instanceof EntityFallingSand) { EntityFallingSand
* entityfallingsand = (EntityFallingSand) e; return new
* Packet23VehicleSpawn(e, 70, entityfallingsand.blockID |
* entityfallingsand.metadata << 16); } else if (e instanceof
* EntityPainting) { return new Packet25EntityPainting((EntityPainting)
* e); } else if (e instanceof EntityItemFrame) { EntityItemFrame
* entityitemframe = (EntityItemFrame) e; packet23vehiclespawn = new
* Packet23VehicleSpawn(e, 71, entityitemframe.hangingDirection);
* packet23vehiclespawn.xPosition =
* MathHelper.floor_float(entityitemframe.xPosition * 32);
* packet23vehiclespawn.yPosition =
* MathHelper.floor_float(entityitemframe.yPosition * 32);
* packet23vehiclespawn.zPosition =
* MathHelper.floor_float(entityitemframe.zPosition * 32); return
* packet23vehiclespawn; } else if (e instanceof EntityLeashKnot) {
* EntityLeashKnot entityleashknot = (EntityLeashKnot) e;
* packet23vehiclespawn = new Packet23VehicleSpawn(e, 77);
* packet23vehiclespawn.xPosition =
* MathHelper.floor_float(entityleashknot.xPosition * 32);
* packet23vehiclespawn.yPosition =
* MathHelper.floor_float(entityleashknot.yPosition * 32);
* packet23vehiclespawn.zPosition =
* MathHelper.floor_float(entityleashknot.zPosition * 32); return
* packet23vehiclespawn; } else if (e instanceof EntityXPOrb) { return
* new Packet26EntityExpOrb((EntityXPOrb) e); } else { throw new
* IllegalArgumentException("Don\'t know how to add " + e.getClass() +
* "!"); } } } else { return new Packet24MobSpawn((EntityLivingBase) e);
* }
*/
}
}

View file

@ -7,6 +7,7 @@ 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.init.Blocks;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
@ -18,18 +19,20 @@ public class CloakedArea {
public AxisAlignedBB aabb;
private LinkedList<String> playersInArea;
public byte tier = 0;
public boolean isPlayerListedInArea(String username) {
for (String playerInArea : playersInArea) {
// WarpDrive.debugPrint("" + this + " Checking player: " + p.username + "(" + p.entityId + ")" + " =? " + player.username + " (" + p.entityId + ")");
// WarpDrive.debugPrint("" + this + " Checking player: " +
// p.username + "(" + p.entityId + ")" + " =? " + player.username +
// " (" + p.entityId + ")");
if (playerInArea.equals(username)) {
return true;
}
}
return false;
}
private void removePlayer(String username) {
for (int i = 0; i < playersInArea.size(); i++) {
if (playersInArea.get(i).equals(username)) {
@ -38,19 +41,18 @@ public class CloakedArea {
}
}
}
private void addPlayer(String username) {
if (!isPlayerListedInArea(username)) {
playersInArea.add(username);
}
}
public boolean isEntityWithinArea(EntityLivingBase entity) {
return (aabb.minX <= entity.posX && (aabb.maxX + 1) > entity.posX
&& aabb.minY <= (entity.posY + entity.height) && (aabb.maxY + 1) > entity.posY
&& aabb.minZ <= entity.posZ && (aabb.maxZ + 1) > entity.posZ);
return (aabb.minX <= entity.posX && (aabb.maxX + 1) > entity.posX && aabb.minY <= (entity.posY + entity.height) && (aabb.maxY + 1) > entity.posY
&& aabb.minZ <= entity.posZ && (aabb.maxZ + 1) > entity.posZ);
}
public CloakedArea(World worldObj, int x, int y, int z, AxisAlignedBB aabb, byte tier) {
this.coreX = x;
this.coreY = y;
@ -58,36 +60,36 @@ public class CloakedArea {
this.aabb = aabb;
this.tier = tier;
this.playersInArea = new LinkedList<String>();
if (worldObj == null || aabb == null) {
return;
}
this.dimensionId = worldObj.provider.dimensionId;
try {
// Add all players currently inside the field
List<Entity> list = worldObj.getEntitiesWithinAABB(EntityPlayerMP.class, this.aabb);
for (Entity e : list) {
if (e instanceof EntityPlayer) {
addPlayer(((EntityPlayer)e).username);
addPlayer(((EntityPlayer) e).getDisplayName());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
// Sending only if field changes: sets up or collapsing
public void sendCloakPacketToPlayersEx(boolean decloak) {
final int RADIUS = 250;
double midX = this.aabb.minX + (Math.abs(this.aabb.maxX - this.aabb.minX) / 2);
double midY = this.aabb.minY + (Math.abs(this.aabb.maxY - this.aabb.minY) / 2);
double midZ = this.aabb.minZ + (Math.abs(this.aabb.maxZ - this.aabb.minZ) / 2);
for (int j = 0; j < MinecraftServer.getServer().getConfigurationManager().playerEntityList.size(); j++) {
EntityPlayerMP entityPlayerMP = (EntityPlayerMP)MinecraftServer.getServer().getConfigurationManager().playerEntityList.get(j);
EntityPlayerMP entityPlayerMP = (EntityPlayerMP) MinecraftServer.getServer().getConfigurationManager().playerEntityList.get(j);
if (entityPlayerMP.dimension == dimensionId) {
double d4 = midX - entityPlayerMP.posX;
@ -99,7 +101,7 @@ public class CloakedArea {
revealChunksToPlayer(entityPlayerMP);
revealEntityToPlayer(entityPlayerMP);
}
if (!isEntityWithinArea(entityPlayerMP) && !decloak) {
PacketHandler.sendCloakPacket(entityPlayerMP, aabb, tier, false);
} else if (decloak) {
@ -109,68 +111,74 @@ public class CloakedArea {
}
}
}
public void updatePlayer(EntityPlayer player) {
if (isEntityWithinArea(player)) {
if (!isPlayerListedInArea(player.username)) {
// WarpDrive.debugPrint("" + this + " Player " + player.username + " has entered");
addPlayer(player.username);
if (!isPlayerListedInArea(player.getDisplayName())) {
// WarpDrive.debugPrint("" + this + " Player " + player.username
// + " has entered");
addPlayer(player.getDisplayName());
revealChunksToPlayer(player);
revealEntityToPlayer(player);
PacketHandler.sendCloakPacket(player, aabb, tier, false);
}
} else {
if (isPlayerListedInArea(player.username)) {
// WarpDrive.debugPrint("" + this + " Player " + player.username + " has left");
removePlayer(player.username);
MinecraftServer.getServer().getConfigurationManager().sendToAllNearExcept(player, player.posX, player.posY, player.posZ, 100, player.worldObj.provider.dimensionId, CloakManager.getPacketForThisEntity(player));
if (isPlayerListedInArea(player.getDisplayName())) {
// WarpDrive.debugPrint("" + this + " Player " + player.username
// + " has left");
removePlayer(player.getDisplayName());
MinecraftServer
.getServer()
.getConfigurationManager()
.sendToAllNearExcept(player, player.posX, player.posY, player.posZ, 100, player.worldObj.provider.dimensionId,
CloakManager.getPacketForThisEntity(player));
PacketHandler.sendCloakPacket(player, aabb, tier, false);
}
}
}
public void revealChunksToPlayer(EntityPlayer p) {
// WarpDrive.debugPrint("" + this + " Revealing cloaked blocks to player " + p.username);
int minY = (int) Math.max( 0, aabb.minY);
// WarpDrive.debugPrint("" + this +
// " Revealing cloaked blocks to player " + p.username);
int minY = (int) Math.max(0, aabb.minY);
int maxY = (int) Math.min(255, aabb.maxY);
for (int x = (int)aabb.minX; x <= (int)aabb.maxX; x++) {
for (int z = (int)aabb.minZ; z <= (int)aabb.maxZ; z++) {
for (int x = (int) aabb.minX; x <= (int) aabb.maxX; x++) {
for (int z = (int) aabb.minZ; z <= (int) aabb.maxZ; z++) {
for (int y = minY; y <= maxY; y++) {
if (p.worldObj.getBlockId(x, y, z) != 0) {
if (!p.worldObj.getBlock(x, y, z).isAssociatedBlock(Blocks.air)) {
p.worldObj.markBlockForUpdate(x, y, z);
}
}
}
}
/*ArrayList<Chunk> chunksToSend = new ArrayList<Chunk>();
for (int x = (int)aabb.minX >> 4; x <= (int)aabb.maxX >> 4; x++)
for (int z = (int)aabb.minZ >> 4; z <= (int)aabb.maxZ >> 4; z++) {
chunksToSend.add(p.worldObj.getChunkFromChunkCoords(x, z));
}
//System.outprintln("[Cloak] Sending " + chunksToSend.size() + " chunks to player " + p.username);
((EntityPlayerMP)p).playerNetServerHandler.sendPacketToPlayer(new Packet56MapChunks(chunksToSend));
//System.outprintln("[Cloak] Sending decloak packet to player " + p.username);
area.sendCloakPacketToPlayer(p, true); // decloak = true
*/
/*
* ArrayList<Chunk> chunksToSend = new ArrayList<Chunk>();
*
* for (int x = (int)aabb.minX >> 4; x <= (int)aabb.maxX >> 4; x++) for
* (int z = (int)aabb.minZ >> 4; z <= (int)aabb.maxZ >> 4; z++) {
* chunksToSend.add(p.worldObj.getChunkFromChunkCoords(x, z)); }
*
* //System.outprintln("[Cloak] Sending " + chunksToSend.size() +
* " chunks to player " + p.username);
* ((EntityPlayerMP)p).playerNetServerHandler.sendPacketToPlayer(new
* Packet56MapChunks(chunksToSend));
*
* //System.outprintln("[Cloak] Sending decloak packet to player " +
* p.username); area.sendCloakPacketToPlayer(p, true); // decloak = true
*/
}
public void revealEntityToPlayer(EntityPlayer p) {
List<Entity> list = p.worldObj.getEntitiesWithinAABBExcludingEntity(p, aabb);
for (Entity e : list) {
((EntityPlayerMP)p).playerNetServerHandler.sendPacketToPlayer(CloakManager.getPacketForThisEntity(e));
((EntityPlayerMP) p).playerNetServerHandler.sendPacket(CloakManager.getPacketForThisEntity(e));
}
}
@Override
public String toString() {
return String.format("%s @ DIM%d %d, %d, %d %s", new Object[] {
getClass().getSimpleName(),
Integer.valueOf(dimensionId),
Integer.valueOf(coreX), Integer.valueOf(coreY), Integer.valueOf(coreZ),
aabb.toString()});
return String.format("%s @ DIM%d %d, %d, %d %s", new Object[] { getClass().getSimpleName(), Integer.valueOf(dimensionId), Integer.valueOf(coreX),
Integer.valueOf(coreY), Integer.valueOf(coreZ), aabb.toString() });
}
}

View file

@ -10,7 +10,9 @@ import cr0s.warpdrive.WarpDriveConfig;
import cr0s.warpdrive.machines.TileEntityReactor;
import cr0s.warpdrive.machines.TileEntityReactor.ReactorMode;
/** Registry of active Warp Cores in world
/**
* Registry of active Warp Cores in world
*
* @author Cr0s
*/
public class WarpCoresRegistry {
@ -69,7 +71,7 @@ public class WarpCoresRegistry {
double dZ = core.zCoord - z;
double distance2 = dX * dX + dY * dY + dZ * dZ;
if (distance2 <= radius2 && ! core.isHidden()) {
if (distance2 <= radius2 && !core.isHidden()) {
res.add(core);
}
}
@ -82,8 +84,8 @@ public class WarpCoresRegistry {
removeDeadCores();
for (TileEntityReactor core : registry) {
WarpDrive.print("- Frequency '" + core.coreFrequency + "' @ '" + core.worldObj.provider.getDimensionName() + "' " + core.xCoord + ", " + core.yCoord + ", " + core.zCoord
+ " with " + core.isolationBlocksCount + " isolation blocks");
WarpDrive.print("- Frequency '" + core.coreFrequency + "' @ '" + core.getWorldObj().provider.getDimensionName() + "' " + core.xCoord + ", "
+ core.yCoord + ", " + core.zCoord + " with " + core.isolationBlocksCount + " isolation blocks");
}
}
@ -91,13 +93,13 @@ public class WarpCoresRegistry {
StringBuilder reason = new StringBuilder();
AxisAlignedBB aabb1, aabb2;
removeDeadCores();
core.validateShipSpatialParameters(reason);
aabb1 = AxisAlignedBB.getBoundingBox(core.minX, core.minY, core.minZ, core.maxX, core.maxY, core.maxZ);
for (TileEntityReactor c : registry) {
// Skip cores in other worlds
if (c.worldObj != core.worldObj) {
if (c.getWorldObj() != core.getWorldObj()) {
continue;
}
@ -135,8 +137,11 @@ public class WarpCoresRegistry {
TileEntityReactor c;
for (int i = registry.size() - 1; i >= 0; i--) {
c = registry.get(i);
if (c == null || c.worldObj == null || c.worldObj.getBlockId(c.xCoord, c.yCoord, c.zCoord) != WarpDriveConfig.coreID || c.worldObj.getBlockTileEntity(c.xCoord, c.yCoord, c.zCoord) != c || c.worldObj.getBlockTileEntity(c.xCoord, c.yCoord, c.zCoord).isInvalid()) {
WarpDrive.debugPrint("Removing 'dead' core at " + ((c != null)? c.xCoord : "?") + ", " + ((c != null)? c.yCoord : "?") + ", " + ((c != null)? c.zCoord : "?"));
if (c == null || c.getWorldObj() == null || c.getWorldObj().getBlock(c.xCoord, c.yCoord, c.zCoord) != WarpDrive.warpCore
|| c.getWorldObj().getTileEntity(c.xCoord, c.yCoord, c.zCoord) != c
|| c.getWorldObj().getTileEntity(c.xCoord, c.yCoord, c.zCoord).isInvalid()) {
WarpDrive.debugPrint("Removing 'dead' core at " + ((c != null) ? c.xCoord : "?") + ", " + ((c != null) ? c.yCoord : "?") + ", "
+ ((c != null) ? c.zCoord : "?"));
registry.remove(i);
}
}
@ -145,39 +150,27 @@ public class WarpCoresRegistry {
}
// TODO: fix it to normal work in client
/*public boolean isEntityInsideAnyWarpField(Entity e) {
AxisAlignedBB aabb1, aabb2;
double x = e.posX;
double y = e.posY;
double z = e.posZ;
for (TileEntityReactor c : registry) {
// Skip offline or disassembled warp cores
if (c.controller == null || !c.prepareToJump()) {
System.out.println("Skipping " + c);
if (c.controller == null) {
System.out.println("Controller is null!");
continue;
}
if (c.controller.getMode() == 0) {
System.out.println("Mode is zero!");
continue;
}
if (!c.prepareToJump()) {
System.out.println("prepareToJump() returns false!");
continue;
}
continue;
}
if (c.minX <= x && c.maxX >= x && c.minY <= y && c.maxY >= y && c.minZ <= z && c.maxZ >= z) {
return true;
}
}
return false;
}*/
/*
* public boolean isEntityInsideAnyWarpField(Entity e) { AxisAlignedBB
* aabb1, aabb2;
*
* double x = e.posX; double y = e.posY; double z = e.posZ;
*
* for (TileEntityReactor c : registry) { // Skip offline or disassembled
* warp cores if (c.controller == null || !c.prepareToJump()) {
* System.out.println("Skipping " + c); if (c.controller == null) {
* System.out.println("Controller is null!"); continue; }
*
* if (c.controller.getMode() == 0) { System.out.println("Mode is zero!");
* continue; }
*
* if (!c.prepareToJump()) {
* System.out.println("prepareToJump() returns false!"); continue; }
* continue; }
*
* if (c.minX <= x && c.maxX >= x && c.minY <= y && c.maxY >= y && c.minZ <=
* z && c.maxZ >= z) { return true; } }
*
* return false; }
*/
}