Added preventive fix for cloaking

This commit is contained in:
LemADEC 2015-08-27 03:05:32 +02:00
parent 172d89fcac
commit 73b1dc41d2
2 changed files with 51 additions and 18 deletions

View file

@ -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);
}
}
}
}

View file

@ -39,12 +39,32 @@ public class CloakManager {
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);
}
}