Skip to content

Commit

Permalink
Add a leve.keep key to the settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
noeppi-noeppi committed Feb 4, 2024
1 parent eb94eeb commit 42d8f14
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 18 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
18 changes: 18 additions & 0 deletions custom-bingos.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Your settings should be defined in a file in `data/<datapack-id>/bingo_settings/
"lockout": false
},
"level": {
"keep": [],
"teleporter": "bongo.default",
"teleport_radius": 10000
},
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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<KeptLevelData> ALL = Set.of(values());

public static final Codec<Set<KeptLevelData>> 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));
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
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<KeptLevelData> keep,
@Param(PlayerTeleporters.class) PlayerTeleporter teleporter,
int teleportRadius
) {

public static final Codec<LevelSettings> CODEC = Codecs.get(BongoMod.class, LevelSettings.class);

public static final LevelSettings DEFAULT = new LevelSettings(
Set.of(),
PlayerTeleporterDefault.INSTANCE,
10000
);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<KeptLevelData> 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<KeptLevelData> 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
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 42d8f14

Please sign in to comment.