Skip to content

Commit

Permalink
Grace Period Bug Fix
Browse files Browse the repository at this point in the history
Fixed a crashing bug when setting the thief's grace period.
Added a config option to set the grace period.
  • Loading branch information
Bletch1971 committed Jan 7, 2022
1 parent 0680322 commit 7dd1896
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public static class Thief {
@Config.LangKey("config.thief.thiefdetectsplayer")
public Boolean thiefdetectsplayer = false;

@Config.Comment("The number of days before the thief visits the village again after they were successful. Set the 0 to disable to grace period. Default: 2")
@Config.LangKey("config.thief.thiefgraceperiod")
@Config.RangeInt(min = 0, max = 365)
public int thiefgraceperiod = 2;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ protected void setupAITasks() {
ItemStack aquiredItem = this.getAquiredItem();

if (aquiredItem != null && !aquiredItem.isEmpty()) {
ThiefScheduler.setGracePeriod(this.village, 2);
ThiefScheduler.resetGracePeriod(this.village);

String aquiredItemDescription = aquiredItem.getDisplayName();
if (aquiredItem.getCount() > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.tangotek.tektopia.structures.VillageStructure;
import net.tangotek.tektopia.structures.VillageStructureType;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -120,7 +121,18 @@ public static int getGracePeriod(Village village) {
}

public static void reduceGracePeriods() {
gracePeriods.forEach((v, p) -> setGracePeriod(v, p - 1));
List<Village> villages = new ArrayList<Village>(gracePeriods.keySet());

for (int index = villages.size() - 1; index >= 0; index--) {
setGracePeriod(villages.get(index), gracePeriods.getOrDefault(villages.get(index), 0) - 1);
}
}

public static void resetGracePeriod(Village village) {
if (village == null)
return;

setGracePeriod(village, ModConfig.thief.thiefgraceperiod);
}

public static void setGracePeriod(Village village, int gracePeriod) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ config.thief.thiefspawnswhenpeaceful=Thief Spawns on Peaceful Difficulty
config.thief.thiefspawnswhenpeaceful.tooltop=If enabled, the Thief will spawn even if the difficulty is set to Peaceful.
config.thief.thiefdetectsplayer=Thief Detects Players
config.thief.thiefdetectsplayer.tooltop=If enabled, the Thief will detect players and flee from them.

config.thief.thiefgraceperiod=Thief Grace Period
config.thief.thiefgraceperiod.tooltip=The number of days before the thief visits the village again after they were successful. Set the 0 to disable to grace period.

#============
#= Commands =
Expand Down
7 changes: 4 additions & 3 deletions src/main/updateforge.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"homepage": "https://minecraft.curseforge.com/projects/tektopia-thief",
"promos": {
"1.12.2-latest": "1.2.0",
"1.12.2-recommended": "1.2.0"
"1.12.2-latest": "1.2.1",
"1.12.2-recommended": "1.2.1"
},
"1.12.2":{
"1.0.0": "Initial alpha release.",
"1.1.0": "Updated entity models.\nAdded config option for Thief to detect players.\nFixed escape notification.\nWhen killed will notify player of any dropped items.\nSpawn and Kill command clean-up.",
"1.2.0": "Added glowing effect to the thief when seen or injured.\nMinor adjustments to the desire counts.\nChanged start time of thief to 10:00pm.\nAdded a grace period of 2 days after the thief successfully steals an item from the village."
"1.2.0": "Added glowing effect to the thief when seen or injured.\nMinor adjustments to the desire counts.\nChanged start time of thief to 10:00pm.\nAdded a grace period of 2 days after the thief successfully steals an item from the village.",
"1.2.1": "Fixed a crashing bug when setting the thief's grace period.\nAdded a config option to set the grace period."
}
}

0 comments on commit 7dd1896

Please sign in to comment.