Skip to content

Commit

Permalink
Citizen Cap improvements, adjust Research GUI to match configs (ldtte…
Browse files Browse the repository at this point in the history
  • Loading branch information
gattsuru authored Apr 4, 2021
1 parent 5d8cd06 commit 70c1662
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
25.0,
50.0,
75.0,
175.0
475.0
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.minecolonies.coremod.network.messages.server.colony.building.university.TryResearchMessage;
import com.minecolonies.coremod.research.AlternateBuildingResearchRequirement;
import com.minecolonies.coremod.research.BuildingResearchRequirement;
import com.minecolonies.coremod.research.GlobalResearchEffect;
import net.minecraft.client.Minecraft;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -304,6 +305,14 @@ private int drawTree(
{
continue;
}
// WORKING_IN_RAIN does nothing if the server config equivalent is already on, and it blocks other research of the same tier.
// I'd rather remove it at the initial ResearchListener, but JsonReloadListeners only fire long before the config files are read,
// and colonies that already bought the research before changing configs do need the ability to cancel or undo it.
if(IMinecoloniesAPI.getInstance().getConfig().getServer().workersAlwaysWorkInRain.get() && research.getEffects().size() == 1 &&
research.getEffects().get(0).getId().equals(WORKING_IN_RAIN) && building.getColony().getResearchManager().getResearchTree().getResearch(branch, researchList.get(i)) == null)
{
continue;
}

final int offsetX = (depth * (GRADIENT_WIDTH + X_SPACING)) + INITIAL_X_OFFSET + ICON_X_OFFSET;
final int offsetY = nextHeight * (GRADIENT_HEIGHT + Y_SPACING) + Y_SPACING + TIMELABEL_Y_POSITION;
Expand Down Expand Up @@ -618,7 +627,19 @@ private void generateResearchTooltips(final Button tipItem, final IGlobalResearc
}
for (int txt = 0; txt < research.getEffects().size(); txt++)
{
hoverPaneBuilder.paragraphBreak().append(research.getEffects().get(txt).getDesc());
// CITIZEN_CAP's meaningful effect range is controlled by configuration file settings. Very low values will necessarily make their researches a little weird, but we should at least handle 'sane' ranges.
// Only change the effect description, rather than removing the effect, as someone may plausibly use the research as a parent research.
// I'd rather make these modifications during ResearchListener.apply, but that's called before config files can be loaded, and the other workarounds are even uglier.
if(research.getEffects().get(txt).getId().equals(CITIZEN_CAP)
&& (((GlobalResearchEffect)research.getEffects().get(txt)).getEffect() + 25) > IMinecoloniesAPI.getInstance().getConfig().getServer().maxCitizenPerColony.get())
{
hoverPaneBuilder.paragraphBreak().append(new TranslationTextComponent("com.minecolonies.research.effects.citizencapaddition.description", new TranslationTextComponent(
"com.minecolonies.coremod.research.limit.maxeffect")));
}
else
{
hoverPaneBuilder.paragraphBreak().append(research.getEffects().get(txt).getDesc());
}
if (!research.getEffects().get(txt).getSubtitle().getKey().isEmpty())
{
hoverPaneBuilder.paragraphBreak().append(new StringTextComponent("-")).append(research.getEffects().get(txt).getSubtitle());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public String getWorkerName()
*/
public String getProgress()
{
int localProgress = 100 - (int) (progress * 100);
int localProgress = Math.max(100 - (int) (progress * 100), 0);
if (finishedStages == 0)
{
if (totalStages == finishedStages)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private ICitizenData spawnCitizenOnPosition(
{
citizenData = createAndRegisterCivilianData();

if (getMaxCitizens() == getCitizens().size() && !force)
if (getMaxCitizens() >= getCitizens().size() && !force)
{
if (maxCitizensFromResearch() <= getCitizens().size())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import com.minecolonies.api.colony.IColony;
import com.minecolonies.api.colony.buildings.IBuilding;
import com.minecolonies.api.colony.buildings.ModBuildings;
import com.minecolonies.api.research.IGlobalResearch;
import com.minecolonies.api.research.IGlobalResearchTree;
import com.minecolonies.api.research.ILocalResearch;
import com.minecolonies.api.research.IResearchManager;
import com.minecolonies.api.research.*;
import com.minecolonies.api.research.effects.IResearchEffect;
import com.minecolonies.api.research.effects.IResearchEffectManager;
import com.minecolonies.api.research.util.ResearchState;
Expand Down Expand Up @@ -110,22 +107,27 @@ public void checkAutoStartResearch()
{
continue;
}
Map<BlockPos, IBuilding> buildings = colony.getBuildingManager().getBuildings();
int level = 0;
for (Map.Entry<BlockPos, IBuilding> building : buildings.entrySet())
// Unlockable Branch Research should trigger even if the university isn't at the required depth. Otherwise, we do need to consider it. CheckAutoStart will rerun on the university upgrade completion.
if(IGlobalResearchTree.getInstance().getBranchData(research.getBranch()).getType() != ResearchBranchType.UNLOCKABLES)
{
if (building.getValue().getBuildingRegistryEntry() == ModBuildings.university)
int level = 0;
Map<BlockPos, IBuilding> buildings = colony.getBuildingManager().getBuildings();
for (Map.Entry<BlockPos, IBuilding> building : buildings.entrySet())
{
if (building.getValue().getBuildingLevel() > level)
if (building.getValue().getBuildingRegistryEntry() == ModBuildings.university)
{
level = building.getValue().getBuildingLevel();
if (building.getValue().getBuildingLevel() > level)
{
level = building.getValue().getBuildingLevel();
}
}
}
if (level < research.getDepth())
{
continue;
}
}
if (level < research.getDepth())
{
continue;
}

boolean researchAlreadyRun = false;
for (ILocalResearch progressResearch : colony.getResearchManager().getResearchTree().getResearchInProgress())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Collection<ResearchEffect> getResearchEffectCollection()
effects.add(new ResearchEffect(BLOCK_ATTACKS).setTranslatedName("Knight Shield Blocking Chance +%3$s%%").setLevels(new double[] {0.05, 0.1, 0.25, 0.5}));
effects.add(new ResearchEffect(BLOCK_BREAK_SPEED).setTranslatedName("Citizen Block Break Speed +%3$s%%").setLevels(new double[] {0.1, 0.25, 0.5, 1, 2}));
effects.add(new ResearchEffect(BLOCK_PLACE_SPEED).setTranslatedName("Citizen Block Place Speed +%3$s%%").setLevels(new double[] {0.1, 0.25, 0.5, 1, 2}));
effects.add(new ResearchEffect(CITIZEN_CAP).setTranslatedName("Increase Max Citizens +%s").setLevels(new double[] {25, 50, 75, 175}));
effects.add(new ResearchEffect(CITIZEN_CAP).setTranslatedName("Increase Max Citizens +%s").setLevels(new double[] {25, 50, 75, 475}));
effects.add(new ResearchEffect(CITIZEN_INV_SLOTS).setTranslatedName("Citizen Inventory +%s Slots").setLevels(new double[] {9, 18, 27}));
effects.add(new ResearchEffect(DOUBLE_ARROWS).setTranslatedName("Archer Multishot +%3$s%%").setLevels(new double[] {0.05, 0.1, 0.25, 0.5}));
effects.add(new ResearchEffect(MECHANIC_ENHANCED_GATES).setTranslatedName("Gates Gain +100% Raider Swarm Resistance").setLevels(new double[] {5, 15}));
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/minecolonies/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,7 @@
"com.minecolonies.coremod.research.requirement.university.level": "Requires University Level %d",
"com.minecolonies.coremod.research.limit.onemaxperbranch": "Only one max-level research can be unlocked per branch.",
"com.minecolonies.coremod.research.limit.immutable": "This research cannot be undone.",
"com.minecolonies.coremod.research.limit.maxeffect": "MAX",
"com.minecolonies.coremod.research.effect.modifier.multiplication": "%s by %d percent",
"com.minecolonies.coremod.research.effect.modifier.addition": "%s + %d",
"com.minecolonies.coremod.research.effect.unlock": "Unlocks %s",
Expand Down

0 comments on commit 70c1662

Please sign in to comment.