Skip to content

Commit

Permalink
add thunder continuation chance
Browse files Browse the repository at this point in the history
  • Loading branch information
jesus committed Jan 9, 2021
1 parent 74ee6cc commit 0d8fcbd
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 33 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '0.1.3'
version = '0.1.4'
group = 'xyz.yermolim.keeptherain' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'keeptherain'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ public class CommonConfig {

public final BooleanValue preserveRainTime;
public final DoubleValue rainContinuationChance;
public final DoubleValue thunderContinuationChance;

public CommonConfig(ForgeConfigSpec.Builder builder) {
preserveRainTime = builder
.comment("Enable preserving the time left to next rain after players woke up")
.comment("Enable preserving the time left to next rain or thunder after players woke up")
.define("preserveRainTime", true);

rainContinuationChance = builder
.comment("Change the chance of rain continuation after players woke up from 0(never) to 1(always)")
.defineInRange("rainContinuationChance", 0.5, 0.0, 1.0);

thunderContinuationChance = builder
.comment("Change the chance of thunder continuation after players woke up from 0(never) to 1(always when rain continuation is passed)")
.defineInRange("thunderContinuationChance", 0.5, 0.0, 1.0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ public class ConfigManager {

public static boolean preserveRainTime;
public static double rainContinuationChance;
public static double thunderContinuationChance;

private static void bakeCommonConfig() {
preserveRainTime = COMMON.preserveRainTime.get();
rainContinuationChance = COMMON.rainContinuationChance.get();
thunderContinuationChance = COMMON.thunderContinuationChance.get();
}

private static void bakeClientConfig() {
Expand Down
73 changes: 45 additions & 28 deletions src/main/java/xyz/yermolim/keeptherain/core/SleepEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,50 @@ public class SleepEventHandler {

@SubscribeEvent
public static void onWake(SleepFinishedTimeEvent event) {
IWorld world = event.getWorld();
IWorldInfo worldInfo = world.getWorldInfo();
if (!(worldInfo instanceof ServerWorldInfo)) {
return;
}
ServerWorldInfo serverWorldInfo = (ServerWorldInfo)worldInfo;
int untilRain = !worldInfo.isRaining() && !worldInfo.isThundering()
? serverWorldInfo.getRainTime()
: 0;
new Timer().schedule(new TimerTask(){
@Override
public void run() {
if (untilRain == 0) {
double rainContinuationChance = ConfigManager.rainContinuationChance;
double roll = Math.random();
KeepTheRain.LOGGER.info(String.format("Rain continuation dice rolled: %s/%s.", roll, rainContinuationChance));
if (roll < rainContinuationChance) {
serverWorldInfo.setRaining(true);
KeepTheRain.LOGGER.info("Rain continuation passed.");
} else {
serverWorldInfo.setRaining(false);
KeepTheRain.LOGGER.info("Rain continuation not passed.");
}
} else if (ConfigManager.preserveRainTime) {
serverWorldInfo.setRainTime(untilRain);
}
}
}, 10);
IWorld world = event.getWorld();
IWorldInfo worldInfo = world.getWorldInfo();
if (!(worldInfo instanceof ServerWorldInfo)) {
return;
}
ServerWorldInfo serverWorldInfo = (ServerWorldInfo)worldInfo;
int untilRain = !worldInfo.isRaining()
? serverWorldInfo.getRainTime()
: 0;
int untilThunder = !worldInfo.isThundering()
? serverWorldInfo.getThunderTime()
: 0;

new Timer().schedule(new TimerTask(){
@Override
public void run() {
if (untilRain == 0) {
double rainContinuationChance = ConfigManager.rainContinuationChance;
double rainRoll = Math.random();
KeepTheRain.LOGGER.info(String.format("Rain continuation dice rolled: %s/%s.", rainRoll, rainContinuationChance));
if (rainRoll < rainContinuationChance) {
serverWorldInfo.setRaining(true);
KeepTheRain.LOGGER.info("Rain continuation passed.");
if (untilThunder == 0) {
double thunderContinuationChance = ConfigManager.thunderContinuationChance;
double thunderRoll = Math.random();
KeepTheRain.LOGGER.info(String.format("Thunder continuation dice rolled: %s/%s.", thunderRoll, thunderContinuationChance));
if (thunderRoll < thunderContinuationChance) {
serverWorldInfo.setThundering(true);
KeepTheRain.LOGGER.info("Thunder continuation passed.");
} else {
KeepTheRain.LOGGER.info("Thunder continuation not passed.");
}
}
} else {
serverWorldInfo.setRaining(false);
serverWorldInfo.setThundering(false);
KeepTheRain.LOGGER.info("Rain continuation not passed.");
}
} else if (ConfigManager.preserveRainTime) {
serverWorldInfo.setRainTime(untilRain);
serverWorldInfo.setThunderTime(untilThunder);
}
}
}, 10);
}
}
3 changes: 2 additions & 1 deletion src/main/resources/assets/keeptherain/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"config.keeptherain.title": "KTR! Settings",
"config.keeptherain.preserveRainTime": "Enable preserving the time left to next rain after players woke up",
"config.keeptherain.rainContinuationChance": "Change the chance of rain continuation after players woke up from 0(never) to 1(always)"
"config.keeptherain.rainContinuationChance": "Change the chance of rain continuation after players woke up from 0(never) to 1(always)",
"config.keeptherain.thunderContinuationChance": "Change the chance of thunder continuation after players woke up from 0(never) to 1(always when rain continuation is passed)"
}
4 changes: 2 additions & 2 deletions update.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"homepage": "https://github.com/yermolim/keep-the-rain/releases",
"promos": {
"1.16.3-latest": "0.1.3",
"1.16.3-recommended": "0.1.3"
"1.16.3-latest": "0.1.4",
"1.16.3-recommended": "0.1.4"
}
}

0 comments on commit 0d8fcbd

Please sign in to comment.