Finished update of data classes
This commit is contained in:
parent
c8b21e9b5c
commit
0df194b33a
3 changed files with 214 additions and 237 deletions
|
@ -3,40 +3,20 @@ package cr0s.warpdrive.data;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
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.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.entity.projectile.EntityArrow;
|
import net.minecraft.network.Packet;
|
||||||
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.util.AxisAlignedBB;
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
import net.minecraft.util.MathHelper;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import com.sun.media.jfxmedia.logging.Logger;
|
||||||
|
|
||||||
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
|
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
|
||||||
import cr0s.warpdrive.PacketHandler;
|
import cr0s.warpdrive.PacketHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cloak manager stores cloaking devices covered areas
|
* Cloak manager stores cloaking devices covered areas
|
||||||
|
*
|
||||||
* @author Cr0s
|
* @author Cr0s
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -44,7 +24,7 @@ import cr0s.warpdrive.PacketHandler;
|
||||||
public class CloakManager {
|
public class CloakManager {
|
||||||
|
|
||||||
private LinkedList<CloakedArea> cloaks;
|
private LinkedList<CloakedArea> cloaks;
|
||||||
|
|
||||||
public CloakManager() {
|
public CloakManager() {
|
||||||
this.cloaks = new LinkedList<CloakedArea>();
|
this.cloaks = new LinkedList<CloakedArea>();
|
||||||
}
|
}
|
||||||
|
@ -54,161 +34,157 @@ public class CloakManager {
|
||||||
if (area.dimensionId != dimensionID) {
|
if (area.dimensionId != dimensionID) {
|
||||||
continue;
|
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) {
|
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 true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkChunkLoaded(EntityPlayerMP player, int chunkPosX, int chunkPosZ) {
|
public boolean checkChunkLoaded(EntityPlayerMP player, int chunkPosX, int chunkPosZ) {
|
||||||
for (CloakedArea area : this.cloaks) {
|
for (CloakedArea area : this.cloaks) {
|
||||||
if (area.dimensionId != player.worldObj.provider.dimensionId) {
|
if (area.dimensionId != player.worldObj.provider.dimensionId) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( area.aabb.minX <= (chunkPosX << 4 + 15) && area.aabb.maxX >= (chunkPosX << 4)
|
if (area.aabb.minX <= (chunkPosX << 4 + 15) && area.aabb.maxX >= (chunkPosX << 4) && area.aabb.minZ <= (chunkPosZ << 4 + 15)
|
||||||
&& area.aabb.minZ <= (chunkPosZ << 4 + 15) && area.aabb.maxZ >= (chunkPosZ << 4) ) {
|
&& area.aabb.maxZ >= (chunkPosZ << 4)) {
|
||||||
PacketHandler.sendCloakPacket(player, area.aabb, area.tier, false);
|
PacketHandler.sendCloakPacket(player, area.aabb, area.tier, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAreaExists(World worldObj, int x, int y, int z) {
|
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));
|
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) {
|
public void removeCloakedArea(World worldObj, int x, int y, int z) {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (int i = 0; i < this.cloaks.size(); i++) {
|
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) {
|
if (this.cloaks.get(i).coreX == x && this.cloaks.get(i).coreY == y && this.cloaks.get(i).coreZ == z
|
||||||
this.cloaks.get(i).sendCloakPacketToPlayersEx(true); // send info about collapsing cloaking field
|
&& this.cloaks.get(i).dimensionId == worldObj.provider.dimensionId) {
|
||||||
|
this.cloaks.get(i).sendCloakPacketToPlayersEx(true); // send
|
||||||
|
// info
|
||||||
|
// about
|
||||||
|
// collapsing
|
||||||
|
// cloaking
|
||||||
|
// field
|
||||||
index = i;
|
index = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cloaks.remove(index);
|
cloaks.remove(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CloakedArea getCloakedArea(World worldObj, int x, int y, int z) {
|
public CloakedArea getCloakedArea(World worldObj, int x, int y, int z) {
|
||||||
for (CloakedArea area : this.cloaks) {
|
for (CloakedArea area : this.cloaks) {
|
||||||
if (area.coreX == x && area.coreY == y && area.coreZ == z && area.dimensionId == worldObj.provider.dimensionId)
|
if (area.coreX == x && area.coreY == y && area.coreZ == z && area.dimensionId == worldObj.provider.dimensionId)
|
||||||
return area;
|
return area;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePlayer(EntityPlayer player) {
|
public void updatePlayer(EntityPlayer player) {
|
||||||
for (CloakedArea area : this.cloaks) {
|
for (CloakedArea area : this.cloaks) {
|
||||||
area.updatePlayer(player);
|
area.updatePlayer(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Packet getPacketForThisEntity(Entity e) {
|
public static Packet getPacketForThisEntity(Entity e) {
|
||||||
if (e.isDead) {
|
if (e.isDead) {
|
||||||
e.worldObj.getWorldLogAgent().logWarning("Fetching addPacket for removed entity");
|
Logger.logMsg(Logger.WARNING, "Fetching addPacket for removed entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
Packet pkt = FMLNetworkHandler.getEntitySpawningPacket(e);
|
Packet pkt = FMLNetworkHandler.getEntitySpawningPacket(e);
|
||||||
if (pkt != null) {
|
if (pkt != null) {
|
||||||
return pkt;
|
return pkt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e instanceof EntityItem) {
|
return null;
|
||||||
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) {
|
// TODO: Major, redo networking
|
||||||
EntityFireball entityfireball = (EntityFireball)e;
|
/*
|
||||||
packet23vehiclespawn = null;
|
* if (e instanceof EntityItem) { return new Packet23VehicleSpawn(e, 2,
|
||||||
byte b0 = 63;
|
* 1); } else if (e instanceof EntityPlayerMP) { return new
|
||||||
|
* Packet20NamedEntitySpawn((EntityPlayer) e); } else if (e instanceof
|
||||||
if (e instanceof EntitySmallFireball) {
|
* EntityMinecart) { EntityMinecart entityminecart = (EntityMinecart) e;
|
||||||
b0 = 64;
|
* return new Packet23VehicleSpawn(e, 10,
|
||||||
} else if (e instanceof EntityWitherSkull) {
|
* entityminecart.getMinecartType()); } else if (e instanceof
|
||||||
b0 = 66;
|
* EntityBoat) { return new Packet23VehicleSpawn(e, 1); } else if (!(e
|
||||||
}
|
* instanceof IAnimals) && !(e instanceof EntityDragon)) { if (e
|
||||||
|
* instanceof EntityFishHook) { EntityPlayer entityplayer =
|
||||||
if (entityfireball.shootingEntity != null) {
|
* ((EntityFishHook) e).angler; return new Packet23VehicleSpawn(e, 90,
|
||||||
packet23vehiclespawn = new Packet23VehicleSpawn(e, b0, ((EntityFireball)e).shootingEntity.entityId);
|
* entityplayer != null ? entityplayer.entityId : e.entityId); } else if
|
||||||
} else {
|
* (e instanceof EntityArrow) { Entity entity = ((EntityArrow)
|
||||||
packet23vehiclespawn = new Packet23VehicleSpawn(e, b0, 0);
|
* 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
|
||||||
packet23vehiclespawn.speedX = (int)(entityfireball.accelerationX * 8000.0D);
|
* (e instanceof EntityPotion) { return new Packet23VehicleSpawn(e, 73,
|
||||||
packet23vehiclespawn.speedY = (int)(entityfireball.accelerationY * 8000.0D);
|
* ((EntityPotion) e).getPotionDamage()); } else if (e instanceof
|
||||||
packet23vehiclespawn.speedZ = (int)(entityfireball.accelerationZ * 8000.0D);
|
* EntityExpBottle) { return new Packet23VehicleSpawn(e, 75); } else if
|
||||||
return packet23vehiclespawn;
|
* (e instanceof EntityEnderPearl) { return new Packet23VehicleSpawn(e,
|
||||||
} else if (e instanceof EntityEgg) {
|
* 65); } else if (e instanceof EntityEnderEye) { return new
|
||||||
return new Packet23VehicleSpawn(e, 62);
|
* Packet23VehicleSpawn(e, 72); } else if (e instanceof
|
||||||
} else if (e instanceof EntityTNTPrimed) {
|
* EntityFireworkRocket) { return new Packet23VehicleSpawn(e, 76); }
|
||||||
return new Packet23VehicleSpawn(e, 50);
|
* else { Packet23VehicleSpawn packet23vehiclespawn;
|
||||||
} else if (e instanceof EntityEnderCrystal) {
|
*
|
||||||
return new Packet23VehicleSpawn(e, 51);
|
* if (e instanceof EntityFireball) { EntityFireball entityfireball =
|
||||||
} else if (e instanceof EntityFallingSand) {
|
* (EntityFireball) e; packet23vehiclespawn = null; byte b0 = 63;
|
||||||
EntityFallingSand entityfallingsand = (EntityFallingSand)e;
|
*
|
||||||
return new Packet23VehicleSpawn(e, 70, entityfallingsand.blockID | entityfallingsand.metadata << 16);
|
* if (e instanceof EntitySmallFireball) { b0 = 64; } else if (e
|
||||||
} else if (e instanceof EntityPainting) {
|
* instanceof EntityWitherSkull) { b0 = 66; }
|
||||||
return new Packet25EntityPainting((EntityPainting)e);
|
*
|
||||||
} else if (e instanceof EntityItemFrame) {
|
* if (entityfireball.shootingEntity != null) { packet23vehiclespawn =
|
||||||
EntityItemFrame entityitemframe = (EntityItemFrame)e;
|
* new Packet23VehicleSpawn(e, b0, ((EntityFireball)
|
||||||
packet23vehiclespawn = new Packet23VehicleSpawn(e, 71, entityitemframe.hangingDirection);
|
* e).shootingEntity.entityId); } else { packet23vehiclespawn = new
|
||||||
packet23vehiclespawn.xPosition = MathHelper.floor_float(entityitemframe.xPosition * 32);
|
* Packet23VehicleSpawn(e, b0, 0); }
|
||||||
packet23vehiclespawn.yPosition = MathHelper.floor_float(entityitemframe.yPosition * 32);
|
*
|
||||||
packet23vehiclespawn.zPosition = MathHelper.floor_float(entityitemframe.zPosition * 32);
|
* packet23vehiclespawn.speedX = (int) (entityfireball.accelerationX *
|
||||||
return packet23vehiclespawn;
|
* 8000.0D); packet23vehiclespawn.speedY = (int)
|
||||||
} else if (e instanceof EntityLeashKnot) {
|
* (entityfireball.accelerationY * 8000.0D); packet23vehiclespawn.speedZ
|
||||||
EntityLeashKnot entityleashknot = (EntityLeashKnot)e;
|
* = (int) (entityfireball.accelerationZ * 8000.0D); return
|
||||||
packet23vehiclespawn = new Packet23VehicleSpawn(e, 77);
|
* packet23vehiclespawn; } else if (e instanceof EntityEgg) { return new
|
||||||
packet23vehiclespawn.xPosition = MathHelper.floor_float(entityleashknot.xPosition * 32);
|
* Packet23VehicleSpawn(e, 62); } else if (e instanceof EntityTNTPrimed)
|
||||||
packet23vehiclespawn.yPosition = MathHelper.floor_float(entityleashknot.yPosition * 32);
|
* { return new Packet23VehicleSpawn(e, 50); } else if (e instanceof
|
||||||
packet23vehiclespawn.zPosition = MathHelper.floor_float(entityleashknot.zPosition * 32);
|
* EntityEnderCrystal) { return new Packet23VehicleSpawn(e, 51); } else
|
||||||
return packet23vehiclespawn;
|
* if (e instanceof EntityFallingSand) { EntityFallingSand
|
||||||
} else if (e instanceof EntityXPOrb) {
|
* entityfallingsand = (EntityFallingSand) e; return new
|
||||||
return new Packet26EntityExpOrb((EntityXPOrb)e);
|
* Packet23VehicleSpawn(e, 70, entityfallingsand.blockID |
|
||||||
} else {
|
* entityfallingsand.metadata << 16); } else if (e instanceof
|
||||||
throw new IllegalArgumentException("Don\'t know how to add " + e.getClass() + "!");
|
* EntityPainting) { return new Packet25EntityPainting((EntityPainting)
|
||||||
}
|
* e); } else if (e instanceof EntityItemFrame) { EntityItemFrame
|
||||||
}
|
* entityitemframe = (EntityItemFrame) e; packet23vehiclespawn = new
|
||||||
} else {
|
* Packet23VehicleSpawn(e, 71, entityitemframe.hangingDirection);
|
||||||
return new Packet24MobSpawn((EntityLivingBase)e);
|
* 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);
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.util.AxisAlignedBB;
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
@ -18,18 +19,20 @@ public class CloakedArea {
|
||||||
public AxisAlignedBB aabb;
|
public AxisAlignedBB aabb;
|
||||||
private LinkedList<String> playersInArea;
|
private LinkedList<String> playersInArea;
|
||||||
public byte tier = 0;
|
public byte tier = 0;
|
||||||
|
|
||||||
public boolean isPlayerListedInArea(String username) {
|
public boolean isPlayerListedInArea(String username) {
|
||||||
for (String playerInArea : playersInArea) {
|
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)) {
|
if (playerInArea.equals(username)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removePlayer(String username) {
|
private void removePlayer(String username) {
|
||||||
for (int i = 0; i < playersInArea.size(); i++) {
|
for (int i = 0; i < playersInArea.size(); i++) {
|
||||||
if (playersInArea.get(i).equals(username)) {
|
if (playersInArea.get(i).equals(username)) {
|
||||||
|
@ -38,19 +41,18 @@ public class CloakedArea {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPlayer(String username) {
|
private void addPlayer(String username) {
|
||||||
if (!isPlayerListedInArea(username)) {
|
if (!isPlayerListedInArea(username)) {
|
||||||
playersInArea.add(username);
|
playersInArea.add(username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEntityWithinArea(EntityLivingBase entity) {
|
public boolean isEntityWithinArea(EntityLivingBase entity) {
|
||||||
return (aabb.minX <= entity.posX && (aabb.maxX + 1) > entity.posX
|
return (aabb.minX <= entity.posX && (aabb.maxX + 1) > entity.posX && aabb.minY <= (entity.posY + entity.height) && (aabb.maxY + 1) > entity.posY
|
||||||
&& aabb.minY <= (entity.posY + entity.height) && (aabb.maxY + 1) > entity.posY
|
&& aabb.minZ <= entity.posZ && (aabb.maxZ + 1) > entity.posZ);
|
||||||
&& aabb.minZ <= entity.posZ && (aabb.maxZ + 1) > entity.posZ);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CloakedArea(World worldObj, int x, int y, int z, AxisAlignedBB aabb, byte tier) {
|
public CloakedArea(World worldObj, int x, int y, int z, AxisAlignedBB aabb, byte tier) {
|
||||||
this.coreX = x;
|
this.coreX = x;
|
||||||
this.coreY = y;
|
this.coreY = y;
|
||||||
|
@ -58,36 +60,36 @@ public class CloakedArea {
|
||||||
this.aabb = aabb;
|
this.aabb = aabb;
|
||||||
this.tier = tier;
|
this.tier = tier;
|
||||||
this.playersInArea = new LinkedList<String>();
|
this.playersInArea = new LinkedList<String>();
|
||||||
|
|
||||||
if (worldObj == null || aabb == null) {
|
if (worldObj == null || aabb == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dimensionId = worldObj.provider.dimensionId;
|
this.dimensionId = worldObj.provider.dimensionId;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Add all players currently inside the field
|
// Add all players currently inside the field
|
||||||
List<Entity> list = worldObj.getEntitiesWithinAABB(EntityPlayerMP.class, this.aabb);
|
List<Entity> list = worldObj.getEntitiesWithinAABB(EntityPlayerMP.class, this.aabb);
|
||||||
for (Entity e : list) {
|
for (Entity e : list) {
|
||||||
if (e instanceof EntityPlayer) {
|
if (e instanceof EntityPlayer) {
|
||||||
addPlayer(((EntityPlayer)e).username);
|
addPlayer(((EntityPlayer) e).getDisplayName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sending only if field changes: sets up or collapsing
|
// Sending only if field changes: sets up or collapsing
|
||||||
public void sendCloakPacketToPlayersEx(boolean decloak) {
|
public void sendCloakPacketToPlayersEx(boolean decloak) {
|
||||||
final int RADIUS = 250;
|
final int RADIUS = 250;
|
||||||
|
|
||||||
double midX = this.aabb.minX + (Math.abs(this.aabb.maxX - this.aabb.minX) / 2);
|
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 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);
|
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++) {
|
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) {
|
if (entityPlayerMP.dimension == dimensionId) {
|
||||||
double d4 = midX - entityPlayerMP.posX;
|
double d4 = midX - entityPlayerMP.posX;
|
||||||
|
@ -99,7 +101,7 @@ public class CloakedArea {
|
||||||
revealChunksToPlayer(entityPlayerMP);
|
revealChunksToPlayer(entityPlayerMP);
|
||||||
revealEntityToPlayer(entityPlayerMP);
|
revealEntityToPlayer(entityPlayerMP);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isEntityWithinArea(entityPlayerMP) && !decloak) {
|
if (!isEntityWithinArea(entityPlayerMP) && !decloak) {
|
||||||
PacketHandler.sendCloakPacket(entityPlayerMP, aabb, tier, false);
|
PacketHandler.sendCloakPacket(entityPlayerMP, aabb, tier, false);
|
||||||
} else if (decloak) {
|
} else if (decloak) {
|
||||||
|
@ -109,68 +111,74 @@ public class CloakedArea {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePlayer(EntityPlayer player) {
|
public void updatePlayer(EntityPlayer player) {
|
||||||
if (isEntityWithinArea(player)) {
|
if (isEntityWithinArea(player)) {
|
||||||
if (!isPlayerListedInArea(player.username)) {
|
if (!isPlayerListedInArea(player.getDisplayName())) {
|
||||||
// WarpDrive.debugPrint("" + this + " Player " + player.username + " has entered");
|
// WarpDrive.debugPrint("" + this + " Player " + player.username
|
||||||
addPlayer(player.username);
|
// + " has entered");
|
||||||
|
addPlayer(player.getDisplayName());
|
||||||
revealChunksToPlayer(player);
|
revealChunksToPlayer(player);
|
||||||
revealEntityToPlayer(player);
|
revealEntityToPlayer(player);
|
||||||
PacketHandler.sendCloakPacket(player, aabb, tier, false);
|
PacketHandler.sendCloakPacket(player, aabb, tier, false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isPlayerListedInArea(player.username)) {
|
if (isPlayerListedInArea(player.getDisplayName())) {
|
||||||
// WarpDrive.debugPrint("" + this + " Player " + player.username + " has left");
|
// WarpDrive.debugPrint("" + this + " Player " + player.username
|
||||||
removePlayer(player.username);
|
// + " has left");
|
||||||
MinecraftServer.getServer().getConfigurationManager().sendToAllNearExcept(player, player.posX, player.posY, player.posZ, 100, player.worldObj.provider.dimensionId, CloakManager.getPacketForThisEntity(player));
|
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);
|
PacketHandler.sendCloakPacket(player, aabb, tier, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void revealChunksToPlayer(EntityPlayer p) {
|
public void revealChunksToPlayer(EntityPlayer p) {
|
||||||
// WarpDrive.debugPrint("" + this + " Revealing cloaked blocks to player " + p.username);
|
// WarpDrive.debugPrint("" + this +
|
||||||
int minY = (int) Math.max( 0, aabb.minY);
|
// " Revealing cloaked blocks to player " + p.username);
|
||||||
|
int minY = (int) Math.max(0, aabb.minY);
|
||||||
int maxY = (int) Math.min(255, aabb.maxY);
|
int maxY = (int) Math.min(255, aabb.maxY);
|
||||||
for (int x = (int)aabb.minX; x <= (int)aabb.maxX; x++) {
|
for (int x = (int) aabb.minX; x <= (int) aabb.maxX; x++) {
|
||||||
for (int z = (int)aabb.minZ; z <= (int)aabb.maxZ; z++) {
|
for (int z = (int) aabb.minZ; z <= (int) aabb.maxZ; z++) {
|
||||||
for (int y = minY; y <= maxY; y++) {
|
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);
|
p.worldObj.markBlockForUpdate(x, y, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*ArrayList<Chunk> chunksToSend = new ArrayList<Chunk>();
|
/*
|
||||||
|
* 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++) {
|
* for (int x = (int)aabb.minX >> 4; x <= (int)aabb.maxX >> 4; x++) for
|
||||||
chunksToSend.add(p.worldObj.getChunkFromChunkCoords(x, z));
|
* (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);
|
* //System.outprintln("[Cloak] Sending " + chunksToSend.size() +
|
||||||
((EntityPlayerMP)p).playerNetServerHandler.sendPacketToPlayer(new Packet56MapChunks(chunksToSend));
|
* " chunks to player " + p.username);
|
||||||
|
* ((EntityPlayerMP)p).playerNetServerHandler.sendPacketToPlayer(new
|
||||||
//System.outprintln("[Cloak] Sending decloak packet to player " + p.username);
|
* Packet56MapChunks(chunksToSend));
|
||||||
area.sendCloakPacketToPlayer(p, true); // decloak = true
|
*
|
||||||
*/
|
* //System.outprintln("[Cloak] Sending decloak packet to player " +
|
||||||
|
* p.username); area.sendCloakPacketToPlayer(p, true); // decloak = true
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public void revealEntityToPlayer(EntityPlayer p) {
|
public void revealEntityToPlayer(EntityPlayer p) {
|
||||||
List<Entity> list = p.worldObj.getEntitiesWithinAABBExcludingEntity(p, aabb);
|
List<Entity> list = p.worldObj.getEntitiesWithinAABBExcludingEntity(p, aabb);
|
||||||
|
|
||||||
for (Entity e : list) {
|
for (Entity e : list) {
|
||||||
((EntityPlayerMP)p).playerNetServerHandler.sendPacketToPlayer(CloakManager.getPacketForThisEntity(e));
|
((EntityPlayerMP) p).playerNetServerHandler.sendPacket(CloakManager.getPacketForThisEntity(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%s @ DIM%d %d, %d, %d %s", new Object[] {
|
return String.format("%s @ DIM%d %d, %d, %d %s", new Object[] { getClass().getSimpleName(), Integer.valueOf(dimensionId), Integer.valueOf(coreX),
|
||||||
getClass().getSimpleName(),
|
Integer.valueOf(coreY), Integer.valueOf(coreZ), aabb.toString() });
|
||||||
Integer.valueOf(dimensionId),
|
|
||||||
Integer.valueOf(coreX), Integer.valueOf(coreY), Integer.valueOf(coreZ),
|
|
||||||
aabb.toString()});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,9 @@ import cr0s.warpdrive.WarpDriveConfig;
|
||||||
import cr0s.warpdrive.machines.TileEntityReactor;
|
import cr0s.warpdrive.machines.TileEntityReactor;
|
||||||
import cr0s.warpdrive.machines.TileEntityReactor.ReactorMode;
|
import cr0s.warpdrive.machines.TileEntityReactor.ReactorMode;
|
||||||
|
|
||||||
/** Registry of active Warp Cores in world
|
/**
|
||||||
|
* Registry of active Warp Cores in world
|
||||||
|
*
|
||||||
* @author Cr0s
|
* @author Cr0s
|
||||||
*/
|
*/
|
||||||
public class WarpCoresRegistry {
|
public class WarpCoresRegistry {
|
||||||
|
@ -69,7 +71,7 @@ public class WarpCoresRegistry {
|
||||||
double dZ = core.zCoord - z;
|
double dZ = core.zCoord - z;
|
||||||
double distance2 = dX * dX + dY * dY + dZ * dZ;
|
double distance2 = dX * dX + dY * dY + dZ * dZ;
|
||||||
|
|
||||||
if (distance2 <= radius2 && ! core.isHidden()) {
|
if (distance2 <= radius2 && !core.isHidden()) {
|
||||||
res.add(core);
|
res.add(core);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,8 +84,8 @@ public class WarpCoresRegistry {
|
||||||
removeDeadCores();
|
removeDeadCores();
|
||||||
|
|
||||||
for (TileEntityReactor core : registry) {
|
for (TileEntityReactor core : registry) {
|
||||||
WarpDrive.print("- Frequency '" + core.coreFrequency + "' @ '" + core.worldObj.provider.getDimensionName() + "' " + core.xCoord + ", " + core.yCoord + ", " + core.zCoord
|
WarpDrive.print("- Frequency '" + core.coreFrequency + "' @ '" + core.getWorldObj().provider.getDimensionName() + "' " + core.xCoord + ", "
|
||||||
+ " with " + core.isolationBlocksCount + " isolation blocks");
|
+ core.yCoord + ", " + core.zCoord + " with " + core.isolationBlocksCount + " isolation blocks");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,13 +93,13 @@ public class WarpCoresRegistry {
|
||||||
StringBuilder reason = new StringBuilder();
|
StringBuilder reason = new StringBuilder();
|
||||||
AxisAlignedBB aabb1, aabb2;
|
AxisAlignedBB aabb1, aabb2;
|
||||||
removeDeadCores();
|
removeDeadCores();
|
||||||
|
|
||||||
core.validateShipSpatialParameters(reason);
|
core.validateShipSpatialParameters(reason);
|
||||||
aabb1 = AxisAlignedBB.getBoundingBox(core.minX, core.minY, core.minZ, core.maxX, core.maxY, core.maxZ);
|
aabb1 = AxisAlignedBB.getBoundingBox(core.minX, core.minY, core.minZ, core.maxX, core.maxY, core.maxZ);
|
||||||
|
|
||||||
for (TileEntityReactor c : registry) {
|
for (TileEntityReactor c : registry) {
|
||||||
// Skip cores in other worlds
|
// Skip cores in other worlds
|
||||||
if (c.worldObj != core.worldObj) {
|
if (c.getWorldObj() != core.getWorldObj()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,8 +137,11 @@ public class WarpCoresRegistry {
|
||||||
TileEntityReactor c;
|
TileEntityReactor c;
|
||||||
for (int i = registry.size() - 1; i >= 0; i--) {
|
for (int i = registry.size() - 1; i >= 0; i--) {
|
||||||
c = registry.get(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()) {
|
if (c == null || c.getWorldObj() == null || c.getWorldObj().getBlock(c.xCoord, c.yCoord, c.zCoord) != WarpDrive.warpCore
|
||||||
WarpDrive.debugPrint("Removing 'dead' core at " + ((c != null)? c.xCoord : "?") + ", " + ((c != null)? c.yCoord : "?") + ", " + ((c != null)? c.zCoord : "?"));
|
|| 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);
|
registry.remove(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,39 +150,27 @@ public class WarpCoresRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: fix it to normal work in client
|
// TODO: fix it to normal work in client
|
||||||
/*public boolean isEntityInsideAnyWarpField(Entity e) {
|
/*
|
||||||
AxisAlignedBB aabb1, aabb2;
|
* public boolean isEntityInsideAnyWarpField(Entity e) { AxisAlignedBB
|
||||||
|
* aabb1, aabb2;
|
||||||
double x = e.posX;
|
*
|
||||||
double y = e.posY;
|
* double x = e.posX; double y = e.posY; double z = e.posZ;
|
||||||
double z = e.posZ;
|
*
|
||||||
|
* for (TileEntityReactor c : registry) { // Skip offline or disassembled
|
||||||
for (TileEntityReactor c : registry) {
|
* warp cores if (c.controller == null || !c.prepareToJump()) {
|
||||||
// Skip offline or disassembled warp cores
|
* System.out.println("Skipping " + c); if (c.controller == null) {
|
||||||
if (c.controller == null || !c.prepareToJump()) {
|
* System.out.println("Controller is null!"); continue; }
|
||||||
System.out.println("Skipping " + c);
|
*
|
||||||
if (c.controller == null) {
|
* if (c.controller.getMode() == 0) { System.out.println("Mode is zero!");
|
||||||
System.out.println("Controller is null!");
|
* continue; }
|
||||||
continue;
|
*
|
||||||
}
|
* if (!c.prepareToJump()) {
|
||||||
|
* System.out.println("prepareToJump() returns false!"); continue; }
|
||||||
if (c.controller.getMode() == 0) {
|
* continue; }
|
||||||
System.out.println("Mode is zero!");
|
*
|
||||||
continue;
|
* if (c.minX <= x && c.maxX >= x && c.minY <= y && c.maxY >= y && c.minZ <=
|
||||||
}
|
* z && c.maxZ >= z) { return true; } }
|
||||||
|
*
|
||||||
if (!c.prepareToJump()) {
|
* return false; }
|
||||||
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;
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue