Skip to content

Commit

Permalink
Fix two regressions from 1.16 - only set the weather once for each wo…
Browse files Browse the repository at this point in the history
…rld, and additionally set weather cycle to false to prevent beds from clearing the storm. Closes #60
  • Loading branch information
alcatrazEscapee committed Jun 26, 2022
1 parent a6298ed commit ddc67c8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.biome.Biome;
Expand Down Expand Up @@ -79,8 +80,11 @@ public static void setLevelToThunder(LevelAccessor maybeLevel)
{
if (maybeLevel instanceof ServerLevel level && Config.INSTANCE.isWinterDimension(level.dimension().location()))
{
// Copied from WeatherCommand
level.setWeatherParameters(0, Integer.MAX_VALUE, true, true);
NewWorldSavedData.onlyForNewWorlds(level, () -> {
LOGGER.info("Modifying weather for world {}", level.dimension().location());
level.setWeatherParameters(0, Integer.MAX_VALUE, true, true); // Copied from WeatherCommand
level.getGameRules().getRule(GameRules.RULE_WEATHER_CYCLE).set(false, level.getServer());
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.alcatrazescapee.primalwinter.util;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.saveddata.SavedData;

import com.alcatrazescapee.primalwinter.PrimalWinter;

public final class NewWorldSavedData extends SavedData
{
private static final String ID = PrimalWinter.MOD_ID;

public static void onlyForNewWorlds(ServerLevel level, Runnable action)
{
level.getDataStorage().computeIfAbsent(tag -> new NewWorldSavedData(), () -> {
final NewWorldSavedData data = new NewWorldSavedData();
data.setDirty();
action.run();
return data;
}, ID);
}

@Override
public CompoundTag save(CompoundTag tag)
{
tag.putBoolean("new_world", false);
return tag;
}
}

0 comments on commit ddc67c8

Please sign in to comment.