Added preventive fix for cloaking
This commit is contained in:
parent
172d89fcac
commit
73b1dc41d2
2 changed files with 51 additions and 18 deletions
|
@ -1,6 +1,9 @@
|
|||
package cr0s.warpdrive;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||
import net.minecraftforge.event.world.ChunkWatchEvent;
|
||||
|
||||
public class CloakChunkWatcher {
|
||||
|
@ -10,8 +13,8 @@ public class CloakChunkWatcher {
|
|||
ChunkCoordIntPair chunk = event.chunk;
|
||||
|
||||
// Check chunk for locating in cloaked areas
|
||||
WarpDrive.cloaks.onChunkLoaded(event.player, chunk.chunkXPos, chunk.chunkZPos);
|
||||
WarpDrive.logger.info("onChunkLoaded " + chunk.chunkXPos + " " + chunk.chunkZPos);
|
||||
WarpDrive.cloaks.onChunkLoaded(event.player, chunk.chunkXPos, chunk.chunkZPos);
|
||||
|
||||
/*
|
||||
List<Chunk> list = new ArrayList<Chunk>();
|
||||
|
@ -22,4 +25,14 @@ public class CloakChunkWatcher {
|
|||
((EntityPlayerMP)p).playerNetServerHandler.sendPacketToPlayer(new Packet56MapChunks(list));
|
||||
*/
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onEntityJoinWorld(EntityJoinWorldEvent event){
|
||||
if (!event.world.isRemote) {
|
||||
if (event.entity instanceof EntityPlayerMP) {
|
||||
WarpDrive.logger.info("onEntityJoinWorld " + event.entity);
|
||||
WarpDrive.cloaks.onEntityJoinWorld((EntityPlayerMP)event.entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,50 +16,70 @@ import cr0s.warpdrive.network.PacketHandler;
|
|||
*/
|
||||
|
||||
public class CloakManager {
|
||||
|
||||
|
||||
private LinkedList<CloakedArea> cloaks;
|
||||
|
||||
|
||||
public CloakManager() {
|
||||
this.cloaks = new LinkedList<CloakedArea>();
|
||||
}
|
||||
|
||||
|
||||
public boolean isCloaked(int dimensionID, int x, int y, int z) {
|
||||
for (CloakedArea area : this.cloaks) {
|
||||
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 onChunkLoaded(EntityPlayerMP player, int chunkPosX, int chunkPosZ) {
|
||||
for (CloakedArea area : this.cloaks) {
|
||||
// skip other dimensions
|
||||
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)) {
|
||||
|
||||
// force refresh if the chunk overlap the cloak
|
||||
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 onEntityJoinWorld(EntityPlayerMP player) {
|
||||
for (CloakedArea area : this.cloaks) {
|
||||
// skip other dimensions
|
||||
if (area.dimensionId != player.worldObj.provider.dimensionId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// force refresh if player is outside the cloak
|
||||
if ( area.aabb.minX > player.posX || area.aabb.maxX < player.posX
|
||||
|| area.aabb.minY > player.posY || area.aabb.maxY < player.posY
|
||||
|| area.aabb.minZ > player.posZ || area.aabb.maxZ < player.posZ ) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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 < cloaks.size(); i++) {
|
||||
|
@ -72,19 +92,19 @@ public class CloakManager {
|
|||
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);
|
||||
|
|
Loading…
Reference in a new issue