From 42d8f14b778650f24176fd3abfd8c6f2877ef9aa Mon Sep 17 00:00:00 2001 From: noeppi_noeppi Date: Sun, 4 Feb 2024 14:33:34 +0100 Subject: [PATCH] Add a leve.keep key to the settings. --- build.gradle | 4 +- custom-bingos.md | 18 +++++++ .../bongo/data/settings/KeptLevelData.java | 28 +++++++++++ .../bongo/data/settings/LevelSettings.java | 4 ++ .../mods/bongo/effect/DefaultEffects.java | 50 +++++++++++++------ src/main/resources/META-INF/mods.toml | 2 +- 6 files changed, 88 insertions(+), 18 deletions(-) create mode 100644 src/main/java/io/github/noeppi_noeppi/mods/bongo/data/settings/KeptLevelData.java diff --git a/build.gradle b/build.gradle index e2e6c98..96e6cca 100644 --- a/build.gradle +++ b/build.gradle @@ -13,9 +13,9 @@ repositories { } dependencies { - annotationProcessor fg.deobf('org.moddingx:LibX:1.20.1-5.0.12') + annotationProcessor fg.deobf('org.moddingx:LibX:1.20.1-5.0.13') - implementation fg.deobf('org.moddingx:LibX:1.20.1-5.0.12') + implementation fg.deobf('org.moddingx:LibX:1.20.1-5.0.13') compileOnly fg.deobf('top.theillusivec4.curios:curios-forge:5.2.0-beta.3+1.20.1:api') runtimeOnly fg.deobf('de.melanx:JustEnoughAdvancements:1.20.1-5.0.2') compileOnly fg.deobf('de.melanx:SkyblockBuilder:1.20.1-5.0.12') diff --git a/custom-bingos.md b/custom-bingos.md index c6608f8..b839b1a 100644 --- a/custom-bingos.md +++ b/custom-bingos.md @@ -23,6 +23,7 @@ Your settings should be defined in a file in `data//bingo_settings/ "lockout": false }, "level": { + "keep": [], "teleporter": "bongo.default", "teleport_radius": 10000 }, @@ -127,6 +128,23 @@ The `equipment` settings control the equipment in the game. `inventory`, `head`, All items are in [recipe format](https://minecraft.fandom.com/wiki/Recipe#JSON_format). +### Keep + +The `level.keep` setting is a list of strings that determines, what Bongo should not reset, when thegame starts. Supported keys: + +``` +game_mode If set, the game mode of player is not changed to survival. +equipment If set, armor and inventory are not cleared. Also prevents filling in starting inventory and armor items. +advancements If set, advancements are not revoked. +experience If set, experience is not removed. +statistics If set, statistics are kept. Otherwise they are set to 0. +time If set, the level time is not set to 0. +weather If set, the weather is not cleared. +wandering_trader_time If set, the wandering trader spawn delay is not reset. +``` + +`level.keep` can also be set to the special value `"all"` which causes Bongo to keep everything. The default is the empty list `[]`, which means Bongo will clear everything. + ### Teleporter The `level.teleporter` setting specifies how bongo should teleport players when the game starts. Other mods may register their teleporters as well. Bongo has the following builtin teleporters: diff --git a/src/main/java/io/github/noeppi_noeppi/mods/bongo/data/settings/KeptLevelData.java b/src/main/java/io/github/noeppi_noeppi/mods/bongo/data/settings/KeptLevelData.java new file mode 100644 index 0000000..7cfc1ee --- /dev/null +++ b/src/main/java/io/github/noeppi_noeppi/mods/bongo/data/settings/KeptLevelData.java @@ -0,0 +1,28 @@ +package io.github.noeppi_noeppi.mods.bongo.data.settings; + +import com.mojang.datafixers.util.Either; +import com.mojang.serialization.Codec; +import net.minecraft.util.Unit; +import org.moddingx.libx.codec.MoreCodecs; + +import java.util.List; +import java.util.Set; +import java.util.function.Function; + +public enum KeptLevelData { + game_mode, + equipment, + advancements, + experience, + statistics, + time, + weather, + wandering_trader_time; + + public static final Set ALL = Set.of(values()); + + public static final Codec> CODEC = Codec.either( + MoreCodecs.fixed("all"), + MoreCodecs.enumCodec(KeptLevelData.class).listOf().xmap(Set::copyOf, List::copyOf) + ).xmap(either -> either.map(unit -> ALL, Function.identity()), set -> ALL.equals(set) ? Either.left(Unit.INSTANCE) : Either.right(set)); +} diff --git a/src/main/java/io/github/noeppi_noeppi/mods/bongo/data/settings/LevelSettings.java b/src/main/java/io/github/noeppi_noeppi/mods/bongo/data/settings/LevelSettings.java index 4f7edd4..19703e9 100644 --- a/src/main/java/io/github/noeppi_noeppi/mods/bongo/data/settings/LevelSettings.java +++ b/src/main/java/io/github/noeppi_noeppi/mods/bongo/data/settings/LevelSettings.java @@ -9,8 +9,11 @@ import org.moddingx.libx.annotation.codec.Param; import org.moddingx.libx.annotation.codec.PrimaryConstructor; +import java.util.Set; + @PrimaryConstructor public record LevelSettings( + @Param(KeptLevelData.class) Set keep, @Param(PlayerTeleporters.class) PlayerTeleporter teleporter, int teleportRadius ) { @@ -18,6 +21,7 @@ public record LevelSettings( public static final Codec CODEC = Codecs.get(BongoMod.class, LevelSettings.class); public static final LevelSettings DEFAULT = new LevelSettings( + Set.of(), PlayerTeleporterDefault.INSTANCE, 10000 ); diff --git a/src/main/java/io/github/noeppi_noeppi/mods/bongo/effect/DefaultEffects.java b/src/main/java/io/github/noeppi_noeppi/mods/bongo/effect/DefaultEffects.java index 8260ba9..c200e29 100644 --- a/src/main/java/io/github/noeppi_noeppi/mods/bongo/effect/DefaultEffects.java +++ b/src/main/java/io/github/noeppi_noeppi/mods/bongo/effect/DefaultEffects.java @@ -1,6 +1,7 @@ package io.github.noeppi_noeppi.mods.bongo.effect; import io.github.noeppi_noeppi.mods.bongo.data.Team; +import io.github.noeppi_noeppi.mods.bongo.data.settings.KeptLevelData; import io.github.noeppi_noeppi.mods.bongo.event.BongoStartEvent; import io.github.noeppi_noeppi.mods.bongo.event.BongoTaskEvent; import io.github.noeppi_noeppi.mods.bongo.event.BongoWinEvent; @@ -22,30 +23,49 @@ import java.util.Comparator; import java.util.List; +import java.util.Set; public class DefaultEffects { @SubscribeEvent public void gameStart(BongoStartEvent.Level event) { - event.getLevel().setDayTime(600); - event.getLevel().serverLevelData.setRaining(false); - event.getLevel().serverLevelData.setThundering(false); - event.getLevel().serverLevelData.setWanderingTraderSpawnDelay(24000); - event.getLevel().serverLevelData.setWanderingTraderSpawnDelay(25); + Set keep = event.getBongo().getSettings().level().keep(); + if (!keep.contains(KeptLevelData.time)) { + event.getLevel().setDayTime(600); + } + if (!keep.contains(KeptLevelData.weather)) { + event.getLevel().serverLevelData.setRaining(false); + event.getLevel().serverLevelData.setThundering(false); + } + if (!keep.contains(KeptLevelData.wandering_trader_time)) { + event.getLevel().serverLevelData.setWanderingTraderSpawnDelay(24000); + event.getLevel().serverLevelData.setWanderingTraderSpawnChance(25); + } } @SubscribeEvent public void playerInit(BongoStartEvent.Player event) { - event.getPlayer().getInventory().clearContent(); - event.getPlayer().setExperienceLevels(0); - event.getPlayer().setExperiencePoints(0); - event.getPlayer().setGameMode(GameType.SURVIVAL); - event.getBongo().getSettings().equipment().equip(event.getPlayer()); - AdvancementCommands.Action.REVOKE.perform(event.getPlayer(), event.getLevel().getServer().getAdvancements().getAllAdvancements()); - ServerStatsCounter mgr = event.getLevel().getServer().getPlayerList().getPlayerStats(event.getPlayer()); - mgr.stats.keySet().forEach(stat -> mgr.stats.put(stat, 0)); - mgr.markAllDirty(); - mgr.sendStats(event.getPlayer()); + Set keep = event.getBongo().getSettings().level().keep(); + if (!keep.contains(KeptLevelData.equipment)) { + event.getPlayer().getInventory().clearContent(); + event.getBongo().getSettings().equipment().equip(event.getPlayer()); + } + if (!keep.contains(KeptLevelData.experience)) { + event.getPlayer().setExperienceLevels(0); + event.getPlayer().setExperiencePoints(0); + } + if (!keep.contains(KeptLevelData.game_mode)) { + event.getPlayer().setGameMode(GameType.SURVIVAL); + } + if (!keep.contains(KeptLevelData.advancements)) { + AdvancementCommands.Action.REVOKE.perform(event.getPlayer(), event.getLevel().getServer().getAdvancements().getAllAdvancements()); + } + if (!keep.contains(KeptLevelData.statistics)) { + ServerStatsCounter mgr = event.getLevel().getServer().getPlayerList().getPlayerStats(event.getPlayer()); + mgr.stats.keySet().forEach(stat -> mgr.stats.put(stat, 0)); + mgr.markAllDirty(); + mgr.sendStats(event.getPlayer()); + } } @SubscribeEvent diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 02012a6..aeef26c 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -31,7 +31,7 @@ It's a bingo mod. [[dependencies.bongo]] modId="libx" mandatory=true - versionRange="[1.20.1-5.0.12,)" + versionRange="[1.20.1-5.0.13,)" ordering="NONE" side="BOTH"