-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic support for persistent game worlds
- Loading branch information
Showing
6 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/testmod/java/xyz/nucleoid/plasmid/test/PersistentGame.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package xyz.nucleoid.plasmid.test; | ||
|
||
import net.minecraft.registry.RegistryKeys; | ||
import net.minecraft.util.*; | ||
import net.minecraft.util.math.Vec3d; | ||
import net.minecraft.world.GameMode; | ||
import net.minecraft.world.GameRules; | ||
import net.minecraft.world.biome.BiomeKeys; | ||
import net.minecraft.world.gen.chunk.FlatChunkGenerator; | ||
import net.minecraft.world.gen.chunk.FlatChunkGeneratorConfig; | ||
import xyz.nucleoid.fantasy.RuntimeWorldConfig; | ||
import xyz.nucleoid.plasmid.api.game.*; | ||
import xyz.nucleoid.plasmid.api.game.event.GamePlayerEvents; | ||
import xyz.nucleoid.plasmid.api.game.player.JoinOffer; | ||
import xyz.nucleoid.plasmid.api.game.rule.GameRuleType; | ||
import xyz.nucleoid.stimuli.event.EventResult; | ||
import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public final class PersistentGame { | ||
public static GameOpenProcedure open(GameOpenContext<Unit> context) { | ||
var biome = context.server().getRegistryManager().getOrThrow(RegistryKeys.BIOME).getOrThrow(BiomeKeys.CHERRY_GROVE); | ||
|
||
var worldConfig = new RuntimeWorldConfig() | ||
.setGenerator(new FlatChunkGenerator(new FlatChunkGeneratorConfig(Optional.empty(), biome, List.of()))) | ||
.setTimeOfDay(6000) | ||
.setGameRule(GameRules.KEEP_INVENTORY, true); | ||
|
||
return context.open((activity) -> { | ||
var gameSpace = activity.getGameSpace(); | ||
var world = gameSpace.getWorlds().addPersistent(Identifier.of("testmod", "persistent_world"), worldConfig); | ||
|
||
|
||
activity.listen(GamePlayerEvents.OFFER, JoinOffer::accept); | ||
activity.listen(GamePlayerEvents.ACCEPT, acceptor -> | ||
acceptor.teleport(world, new Vec3d(0.0, 65.0, 0.0)) | ||
.thenRunForEach(joiningPlayer -> { | ||
joiningPlayer.changeGameMode(GameMode.CREATIVE); | ||
}) | ||
); | ||
|
||
|
||
activity.allow(GameRuleType.PVP).allow(GameRuleType.MODIFY_ARMOR); | ||
activity.deny(GameRuleType.FALL_DAMAGE).deny(GameRuleType.HUNGER); | ||
activity.deny(GameRuleType.THROW_ITEMS); | ||
|
||
activity.listen(PlayerDeathEvent.EVENT, (player, source) -> { | ||
player.setPos(0.0, 65.0, 0.0); | ||
return EventResult.DENY; | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/testmod/resources/data/testmod/plasmid/game/persistent.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type": "testmod:persistent", | ||
"icon": "dirt", | ||
"description": [] | ||
} |