Get cached RTPs to work properly
This commit is contained in:
parent
3a8ce9b989
commit
19fff5778d
5 changed files with 38 additions and 71 deletions
|
@ -35,7 +35,6 @@ public class RTP
|
|||
{
|
||||
public RTP(ServerLevel level)
|
||||
{
|
||||
Age = Instant.now().getEpochSecond();
|
||||
position = new WorldPosition(new Vector3(0,500,0), WorldPosition.getDim(level));
|
||||
|
||||
if(position.getActualDimension().dimensionType().hasCeiling())
|
||||
|
@ -53,10 +52,6 @@ public class RTP
|
|||
public WorldPosition position;
|
||||
private List<Block> BLACKLIST = Lists.of(Blocks.LAVA, Blocks.WATER);
|
||||
protected int tries;
|
||||
/**
|
||||
* This is a unix timestamp, that is checked for being Stale
|
||||
*/
|
||||
public long Age;
|
||||
|
||||
public boolean isDimension(ServerLevel level)
|
||||
{
|
||||
|
@ -67,23 +62,6 @@ public class RTP
|
|||
}else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the RTP Cached position is stale. This means over 2 hours old
|
||||
* @return True if stale
|
||||
*/
|
||||
public boolean isStale()
|
||||
{
|
||||
if((Age+(2*60*60)) < Instant.now().getEpochSecond())
|
||||
{
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
public boolean readyForNewer()
|
||||
{
|
||||
return ((Age + (10*60)) < Instant.now().getEpochSecond());
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for, and finds, a valid RTP location
|
||||
* @param level The level to scan
|
||||
|
@ -116,7 +94,10 @@ public class RTP
|
|||
List<RTP> slice = slicedByDimension(level);
|
||||
if(slice.size()>0)
|
||||
{
|
||||
return slice.get(AriasEssentials.random.nextInt(0, slice.size()));
|
||||
RTP ret = slice.get(AriasEssentials.random.nextInt(0, slice.size()));
|
||||
RTPCaches.Locations.remove(ret);
|
||||
RandomPositionFactory.beginRTPSearch(ret.position.getActualDimension());
|
||||
return ret;
|
||||
} else return null;
|
||||
}
|
||||
|
||||
|
@ -222,49 +203,4 @@ public class RTP
|
|||
|
||||
return s;
|
||||
}
|
||||
|
||||
public void putAge()
|
||||
{
|
||||
Age = Instant.now().getEpochSecond();
|
||||
}
|
||||
|
||||
public static void checkStale()
|
||||
{
|
||||
Iterator<RTP> it = RTPCaches.Locations.iterator();
|
||||
List<ServerLevel> uniqueDims = new ArrayList<>();
|
||||
while(it.hasNext())
|
||||
{
|
||||
RTP loc = it.next();
|
||||
if(loc.isStale()){
|
||||
it.remove();
|
||||
}
|
||||
|
||||
if(!uniqueDims.contains(loc.position.getActualDimension()))
|
||||
{
|
||||
uniqueDims.add(loc.position.getActualDimension());
|
||||
}
|
||||
}
|
||||
|
||||
checkNeedsNewer(uniqueDims);
|
||||
}
|
||||
|
||||
public static void checkNeedsNewer(List<ServerLevel> dims)
|
||||
{
|
||||
Iterator<ServerLevel> it = dims.iterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
ServerLevel lvl = it.next();
|
||||
List<RTP> slice = slicedByDimension(lvl);
|
||||
boolean needsNewer = true;
|
||||
for(var X : slice)
|
||||
{
|
||||
if(!X.readyForNewer()) needsNewer=false;
|
||||
}
|
||||
|
||||
if(needsNewer)
|
||||
{
|
||||
RandomPositionFactory.beginRTPSearch(lvl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue