Skip to content

Commit

Permalink
Dimensions and remove config boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
ellieisjelly committed Jan 10, 2024
1 parent 7e17d8f commit 21b8338
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 59 deletions.
19 changes: 10 additions & 9 deletions src/main/java/me/ellieis/Sabotage/game/config/SabotageConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
import net.minecraft.util.Identifier;
import xyz.nucleoid.plasmid.game.common.config.PlayerConfig;

public record SabotageConfig(Identifier map, int countdownTime, int gracePeriod, int timeLimit, int endDelay, int chestCount, InnocentConfig innocentConfig, DetectiveConfig detectiveConfig, SaboteurConfig saboteurConfig, PlayerConfig playerConfig) {
public record SabotageConfig(Identifier map, Identifier dimension, int countdownTime, int gracePeriod, int timeLimit, int endDelay, int chestCount, InnocentConfig innocentConfig, DetectiveConfig detectiveConfig, SaboteurConfig saboteurConfig, PlayerConfig playerConfig) {
public static final Codec<SabotageConfig> CODEC = RecordCodecBuilder.create(instance ->
instance.group(
Identifier.CODEC.fieldOf("map").forGetter(SabotageConfig::map),
Codec.INT.fieldOf("countdown_time").forGetter(SabotageConfig::countdownTime),
Codec.INT.fieldOf("grace_period").forGetter(SabotageConfig::gracePeriod),
Codec.INT.fieldOf("time_limit").forGetter(SabotageConfig::timeLimit),
Codec.INT.fieldOf("end_delay").forGetter(SabotageConfig::endDelay),
Identifier.CODEC.optionalFieldOf("dimension", new Identifier("minecraft:overworld")).forGetter(SabotageConfig::dimension),
Codec.INT.optionalFieldOf("countdown_time", 5).forGetter(SabotageConfig::countdownTime),
Codec.INT.optionalFieldOf("grace_period", 15).forGetter(SabotageConfig::gracePeriod),
Codec.INT.optionalFieldOf("time_limit", 1200).forGetter(SabotageConfig::timeLimit),
Codec.INT.optionalFieldOf("end_delay", 10).forGetter(SabotageConfig::endDelay),
Codec.INT.fieldOf("chest_count").forGetter(SabotageConfig::chestCount),
InnocentConfig.CODEC.fieldOf("innocent").forGetter(SabotageConfig::innocentConfig),
DetectiveConfig.CODEC.fieldOf("detective").forGetter(SabotageConfig::detectiveConfig),
SaboteurConfig.CODEC.fieldOf("saboteur").forGetter(SabotageConfig::saboteurConfig),
PlayerConfig.CODEC.fieldOf("players").forGetter(SabotageConfig::playerConfig)
InnocentConfig.CODEC.optionalFieldOf("innocent", new InnocentConfig(20, 100, 20)).forGetter(SabotageConfig::innocentConfig),
DetectiveConfig.CODEC.optionalFieldOf("detective", new DetectiveConfig(20, 100, 100)).forGetter(SabotageConfig::detectiveConfig),
SaboteurConfig.CODEC.optionalFieldOf("saboteur", new SaboteurConfig(20, 100, 20)).forGetter(SabotageConfig::saboteurConfig),
PlayerConfig.CODEC.optionalFieldOf("players", new PlayerConfig(4, 64, 6, new PlayerConfig.Countdown(30, 5))).forGetter(SabotageConfig::playerConfig)
).apply(instance, SabotageConfig::new)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
import me.ellieis.Sabotage.game.config.SabotageConfig;
import me.ellieis.Sabotage.game.map.SabotageMap;
import me.ellieis.Sabotage.game.map.SabotageMapBuilder;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameMode;
import xyz.nucleoid.fantasy.RuntimeWorldConfig;

import xyz.nucleoid.plasmid.game.GameActivity;
import xyz.nucleoid.plasmid.game.GameOpenContext;
import xyz.nucleoid.plasmid.game.GameOpenProcedure;
import xyz.nucleoid.plasmid.game.GameSpace;
import xyz.nucleoid.plasmid.game.GameResult;
import xyz.nucleoid.plasmid.game.*;
import xyz.nucleoid.plasmid.game.common.GameWaitingLobby;
import xyz.nucleoid.plasmid.game.event.GameActivityEvents;
import xyz.nucleoid.plasmid.game.event.GamePlayerEvents;
Expand Down Expand Up @@ -56,6 +53,7 @@ public static GameOpenProcedure Open(GameOpenContext<SabotageConfig> context) {
SabotageMap map = SabotageMapBuilder.build(server, config.map(), config);
RuntimeWorldConfig worldConfig = new RuntimeWorldConfig()
.setGenerator(map.asChunkGenerator(server))
.setDimensionType(RegistryKey.of(RegistryKeys.DIMENSION_TYPE, config.dimension()))
.setTimeOfDay(6000);

return context.openWithWorld(worldConfig, (activity, world) -> {
Expand Down
20 changes: 1 addition & 19 deletions src/main/resources/data/sabotage/games/hellbound.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
{
"type": "sabotage:sabotage",
"dimension": "minecraft:the_nether",
"map": "sabotage:hellbound",
"countdown_time": 5,
"grace_period": 15,
"time_limit": 1200,
"end_delay": 10,
"chest_count": 200,
"innocent": {
"innocent_karma_penalty": 20,
"detective_karma_penalty": 100,
"saboteur_karma_award": 20
},
"detective": {
"innocent_karma_penalty": 20,
"detective_karma_penalty": 100,
"saboteur_karma_award": 100
},
"saboteur": {
"innocent_karma_award": 20,
"detective_karma_award": 100,
"saboteur_karma_penalty": 20
},
"players": {
"min": 1,
"max": 64,
Expand Down
26 changes: 1 addition & 25 deletions src/main/resources/data/sabotage/games/village.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@
{
"type": "sabotage:sabotage",
"map": "sabotage:village",
"countdown_time": 5,
"grace_period": 15,
"time_limit": 1200,
"end_delay": 10,
"chest_count": 125,
"innocent": {
"innocent_karma_penalty": 20,
"detective_karma_penalty": 100,
"saboteur_karma_award": 20
},
"detective": {
"innocent_karma_penalty": 20,
"detective_karma_penalty": 100,
"saboteur_karma_award": 100
},
"saboteur": {
"innocent_karma_award": 20,
"detective_karma_award": 100,
"saboteur_karma_penalty": 20
},
"players": {
"min": 1,
"max": 64,
"threshold": 6
}
"chest_count": 125
}

0 comments on commit 21b8338

Please sign in to comment.