-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathBRMap.java
More file actions
83 lines (70 loc) · 3.41 KB
/
BRMap.java
File metadata and controls
83 lines (70 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package fr.hugman.build_rush.map;
import fr.hugman.build_rush.BRConfig;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.world.rule.GameRules;
import xyz.nucleoid.fantasy.RuntimeWorldConfig;
import xyz.nucleoid.map_templates.BlockBounds;
import xyz.nucleoid.map_templates.MapTemplateSerializer;
import xyz.nucleoid.plasmid.api.game.GameOpenContext;
import xyz.nucleoid.plasmid.api.game.GameOpenException;
import xyz.nucleoid.plasmid.api.game.world.generator.TemplateChunkGenerator;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public record BRMap(Plot centerPlot, List<Plot> plots, RuntimeWorldConfig worldConfig) {
public static BRMap from(GameOpenContext<BRConfig> context) throws IOException {
var server = context.server();
var config = context.config();
var template = MapTemplateSerializer.loadFromResource(server, config.mapConfig().template());
var metadata = template.getMetadata();
var worldConfig = new RuntimeWorldConfig().setGenerator(new TemplateChunkGenerator(server, template))
.setGameRule(GameRules.FIRE_SPREAD_RADIUS_AROUND_PLAYER, -1)
.setGameRule(GameRules.FIRE_DAMAGE, false)
.setGameRule(GameRules.FREEZE_DAMAGE, false)
.setGameRule(GameRules.DO_MOB_GRIEFING, false)
.setGameRule(GameRules.DO_MOB_SPAWNING, false)
.setGameRule(GameRules.RANDOM_TICK_SPEED, 0)
.setGameRule(GameRules.WATER_SOURCE_CONVERSION, false)
.setGameRule(GameRules.LAVA_SOURCE_CONVERSION, false);
var centerPlotBounds = metadata.getFirstRegionBounds("center_plot");
if (centerPlotBounds == null) {
throw new GameOpenException(Text.translatable("error.build_rush.mapConfig.center_plot.not_found"));
}
var centerPlot = Plot.of(centerPlotBounds);
final int size = centerPlotBounds.size().getX()+1;
validateBounds(centerPlotBounds, size);
var plotBoundsList = metadata.getRegionBounds("plot").toList();
config.playerConfig().playerConfig().maxPlayers().ifPresent(value -> {
if (plotBoundsList.size() > value) {
throw new GameOpenException(Text.translatable("error.build_rush.mapConfig.plots.too_much", plotBoundsList.size(), value));
}
});
List<Plot> plots = new ArrayList<>();
for(var plotBounds : plotBoundsList) {
validateBounds(plotBounds, size);
plots.add(Plot.of(plotBounds));
}
return new BRMap(centerPlot, plots, worldConfig);
}
private static void validateBounds(BlockBounds plot, int size) {
int x = plot.size().getX()+1;
int y = plot.size().getY()+1;
int z = plot.size().getZ()+1;
if(x != z) {
throw new GameOpenException(Text.translatable("error.build_rush.mapConfig.plot.wrong_size", x, z));
}
if(y != 1) {
throw new GameOpenException(Text.translatable("error.build_rush.mapConfig.plot.wrong_height", y));
}
if(x != size) {
throw new GameOpenException(Text.translatable("error.build_rush.mapConfig.plot.wrong_size_as_center", x, size));
}
}
public void cachePlotGrounds(ServerWorld world) {
centerPlot.cacheGround(world);
for(var plot : plots) {
plot.cacheGround(world);
}
}
}