I am trying to delete planets. That much is easy. However, I am having trouble finding the nascent gravity well matching the planet so that can be deleted. Alex remarked on twitter that running .getLocationInHyperspace() just returns the location of the system, not the nascent well.
https://pastebin.com/3n1Dp4W9 code I've tried. the printloc returns the hyperspace location of the system itself
Right now I unable to A. find the hyperspace location of the nascent well and B. unable to find it that well corresponds to a particular planet. Any advice would be greatly appreciated.
In brief, you want to check if the entity is an instanceof NascentGravityWellAPI, and then use the .getTarget() method in that interface to check if that well points to the planet you're removing.
Very sorry to bother again, but I'm having a somewhat odd casting error while trying to call the getTarget method on the entity. I can't call the getTarget method on the generic SectorEntityToken, and when I try the cast, I get...this. Which is odd, because I don't know how on earth I'm getting a Location Token.
List<SectorEntityToken>allEntities=Global.getSector().getHyperspace().getAllEntities();
for (SectorEntityToken entity:allEntities)
{
if (entity instanceof NascentGravityWellAPI)
log.info("Looking for nascent gravity wells to purge.");
//note: isInCurrentLocation doesn't work because the well is in hyper, not realspace
NascentGravityWellAPI nascwell= (NascentGravityWellAPI) entity; //note: yeah the cast is not legit
if(nascwell.getTarget() == planet);
{
//note: it's nothing in this code block that's causing the cast problem, I tried commenting it out
log.info("Purging nascent gravity well.");
LocationAPI location = entity.getContainingLocation();
log.info("nascent grav well's location is" + location.getLocation());
location.removeEntity(entity);
break;
}
}