mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 01:49:40 +00:00
Full Imports and Code Format Optimization
This commit is contained in:
1 parent
250edf099c
commit
6815f579a7
1192 files changed
+60344
-62167
No files matched your search
@@ -12,77 +12,77 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class JobChunkLoader extends JobInterface{
|
||||
|
||||
private List<ChunkCoordIntPair> chunks = new ArrayList<ChunkCoordIntPair>();
|
||||
private int ticks = 20;
|
||||
private long playerLastSeen = 0;
|
||||
public class JobChunkLoader extends JobInterface {
|
||||
|
||||
public JobChunkLoader(EntityNPCInterface npc) {
|
||||
super(npc);
|
||||
}
|
||||
private List<ChunkCoordIntPair> chunks = new ArrayList<ChunkCoordIntPair>();
|
||||
private int ticks = 20;
|
||||
private long playerLastSeen = 0;
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setLong("ChunkPlayerLastSeen", playerLastSeen);
|
||||
return compound;
|
||||
}
|
||||
public JobChunkLoader(EntityNPCInterface npc) {
|
||||
super(npc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
playerLastSeen = compound.getLong("ChunkPlayerLastSeen");
|
||||
}
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setLong("ChunkPlayerLastSeen", playerLastSeen);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean aiShouldExecute() {
|
||||
ticks--;
|
||||
if(ticks > 0)
|
||||
return false;
|
||||
ticks = 20;
|
||||
|
||||
List players = npc.worldObj.getEntitiesWithinAABB(EntityPlayer.class, npc.boundingBox.expand(48, 48, 48));
|
||||
if(!players.isEmpty())
|
||||
playerLastSeen = System.currentTimeMillis();
|
||||
|
||||
//unload after 10 min
|
||||
if(System.currentTimeMillis() > playerLastSeen + 600000){
|
||||
ChunkController.Instance.deleteNPC(npc);
|
||||
chunks.clear();
|
||||
return false;
|
||||
}
|
||||
Ticket ticket = ChunkController.Instance.getTicket(npc);
|
||||
if(ticket == null) //Only null when too many active chunkloaders already
|
||||
return false;
|
||||
double x = npc.posX / 16;
|
||||
double z = npc.posZ / 16;
|
||||
|
||||
List<ChunkCoordIntPair> list = new ArrayList<ChunkCoordIntPair>();
|
||||
list.add(new ChunkCoordIntPair(MathHelper.floor_double(x), MathHelper.floor_double(z)));
|
||||
list.add(new ChunkCoordIntPair(MathHelper.ceiling_double_int(x), MathHelper.ceiling_double_int(z)));
|
||||
list.add(new ChunkCoordIntPair(MathHelper.floor_double(x), MathHelper.ceiling_double_int(z)));
|
||||
list.add(new ChunkCoordIntPair(MathHelper.ceiling_double_int(x), MathHelper.floor_double(z)));
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
playerLastSeen = compound.getLong("ChunkPlayerLastSeen");
|
||||
}
|
||||
|
||||
for(ChunkCoordIntPair chunk : list){
|
||||
if(!chunks.contains(chunk)){
|
||||
ForgeChunkManager.forceChunk(ticket, chunk);
|
||||
}
|
||||
else
|
||||
chunks.remove(chunk);
|
||||
}
|
||||
|
||||
for(ChunkCoordIntPair chunk : chunks)
|
||||
ForgeChunkManager.unforceChunk(ticket, chunk);
|
||||
|
||||
this.chunks = list;
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean aiShouldExecute() {
|
||||
ticks--;
|
||||
if (ticks > 0)
|
||||
return false;
|
||||
ticks = 20;
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
ChunkController.Instance.deleteNPC(npc);
|
||||
chunks.clear();
|
||||
playerLastSeen = 0;
|
||||
}
|
||||
public void delete() {
|
||||
}
|
||||
List players = npc.worldObj.getEntitiesWithinAABB(EntityPlayer.class, npc.boundingBox.expand(48, 48, 48));
|
||||
if (!players.isEmpty())
|
||||
playerLastSeen = System.currentTimeMillis();
|
||||
|
||||
//unload after 10 min
|
||||
if (System.currentTimeMillis() > playerLastSeen + 600000) {
|
||||
ChunkController.Instance.deleteNPC(npc);
|
||||
chunks.clear();
|
||||
return false;
|
||||
}
|
||||
Ticket ticket = ChunkController.Instance.getTicket(npc);
|
||||
if (ticket == null) //Only null when too many active chunkloaders already
|
||||
return false;
|
||||
double x = npc.posX / 16;
|
||||
double z = npc.posZ / 16;
|
||||
|
||||
List<ChunkCoordIntPair> list = new ArrayList<ChunkCoordIntPair>();
|
||||
list.add(new ChunkCoordIntPair(MathHelper.floor_double(x), MathHelper.floor_double(z)));
|
||||
list.add(new ChunkCoordIntPair(MathHelper.ceiling_double_int(x), MathHelper.ceiling_double_int(z)));
|
||||
list.add(new ChunkCoordIntPair(MathHelper.floor_double(x), MathHelper.ceiling_double_int(z)));
|
||||
list.add(new ChunkCoordIntPair(MathHelper.ceiling_double_int(x), MathHelper.floor_double(z)));
|
||||
|
||||
for (ChunkCoordIntPair chunk : list) {
|
||||
if (!chunks.contains(chunk)) {
|
||||
ForgeChunkManager.forceChunk(ticket, chunk);
|
||||
} else
|
||||
chunks.remove(chunk);
|
||||
}
|
||||
|
||||
for (ChunkCoordIntPair chunk : chunks)
|
||||
ForgeChunkManager.unforceChunk(ticket, chunk);
|
||||
|
||||
this.chunks = list;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
ChunkController.Instance.deleteNPC(npc);
|
||||
chunks.clear();
|
||||
playerLastSeen = 0;
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user