I'm working on a terraforming mod. I'm using the following code to remove a frozen planet and replace it with a water planet:
String newPlanetType = "water";
CampaignPlanet oldPlanet = (CampaignPlanet)this.market.getPrimaryEntity();
CampaignPlanet newPlanet = null;
newPlanet = new CampaignPlanet(oldPlanet.getId(), oldPlanet.getName(), newPlanetType, oldPlanet.getRadius(), oldPlanet.getLocation().x, oldPlanet.getLocation().y, (CampaignEntity)oldPlanet.getLightSource());
newPlanet.setContainingLocation(oldPlanet.getContainingLocation());
newPlanet.setOrbit(oldPlanet.getOrbit());
newPlanet.setMarket(this.market);
newPlanet.setMemory(oldPlanet.getMemory());
newPlanet.setFaction(oldPlanet.getFaction());
this.market.getStarSystem().removeEntity(oldPlanet);
this.market.getStarSystem().addEntity(newPlanet);
this.market.setPrimaryEntity(newPlanet);
But if I try to get the planet type ID with the following code, it still returns "frozen" despite the oldPlanet SectorEntityToken having been removed and the newPlanet set as the primary entity.
this.market.getPlanetEntity().getTypeId()
This prevents farming/aquaculture from working properly on the market as it gets the planet type ID to determine which variant to use. I think this may happen because objects cannot be removed from the connectedEntities LinkedHashSet in the Market class. When getPlanetEntity() iterates through connectedEntities, it will always return the first item placed on the list (the old frozen planet PlanetAPI) even though newPlanet is now the primary entity.
Whether or not I'm correct about why this occurs, is there any change I can make to my code so farming/aquaculture will correctly identify the new planet type? Thank you!