-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathStargateDimensionGenerator.java
More file actions
122 lines (110 loc) · 5.17 KB
/
StargateDimensionGenerator.java
File metadata and controls
122 lines (110 loc) · 5.17 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package tauri.dev.jsg.worldgen;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.DimensionType;
import net.minecraft.world.World;
import tauri.dev.jsg.JSG;
import tauri.dev.jsg.config.JSGConfig;
import tauri.dev.jsg.config.JSGConfigUtil;
//new sparcky
import tauri.dev.jsg.config.stargate.StargateDimensionConfig;
import tauri.dev.jsg.config.stargate.StargateDimensionConfigEntry;
//end
import tauri.dev.jsg.stargate.network.StargateAddress;
import tauri.dev.jsg.stargate.network.StargateNetwork;
import tauri.dev.jsg.stargate.network.StargatePos;
import tauri.dev.jsg.stargate.network.SymbolTypeEnum;
import tauri.dev.jsg.stargate.teleportation.TeleportHelper;
import tauri.dev.jsg.util.DimensionsHelper;
import tauri.dev.jsg.worldgen.util.GeneratedStargate;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Map;
import java.util.Random;
public class StargateDimensionGenerator {
@SuppressWarnings("all")
public static void tryGenerate(@Nonnull World worldServer) {
if (!JSGConfig.WorldGen.otherDimGenerator.generatorEnabled) {
JSG.debug("Skipping dimensions to generate addresses... Disabled in CONFIG");
return;
}
JSG.info("Checking dimensions to generate addresses of possible gates there...");
StargateNetwork sgn = StargateNetwork.get(worldServer);
ArrayList<Integer> dimensionsWithGate = new ArrayList<>();
Map<StargatePos, Map<SymbolTypeEnum, StargateAddress>> virtualGates = sgn.getMapNotGenerated();
Map<StargateAddress, StargatePos> sgNetwork = sgn.getMap().get(SymbolTypeEnum.MILKYWAY);
for (StargatePos p : virtualGates.keySet()) {
dimensionsWithGate.add(p.dimensionID);
}
for (StargatePos p : sgNetwork.values()) {
dimensionsWithGate.add(p.dimensionID);
}
int i = 0;
int y = 0;
for (Map.Entry<Integer, DimensionType> entry : DimensionsHelper.getRegisteredDimensions().entrySet()) {
int id = entry.getKey();
DimensionType dt = entry.getValue();
SymbolTypeEnum symbolType = SymbolTypeEnum.MILKYWAY;
if (JSGConfigUtil.isDimBlacklistedForSGSpawn(id)) {
JSG.debug("Dim " + id + " is blacklisted. Skipping...");
continue;
}
if(id == 1) symbolType = SymbolTypeEnum.UNIVERSE;
//new code sparcky
StargateDimensionConfigEntry data = StargateDimensionConfig.getDimensionMap().get(id);
if (data.groups.contains("milkyway")) {
symbolType = SymbolTypeEnum.MILKYWAY;
} else if (data.groups.contains("pegasus")) {
symbolType = SymbolTypeEnum.PEGASUS;
} else if (data.groups.contains("universe")){
symbolType = SymbolTypeEnum.UNIVERSE;
}
//end
if (id == 0 || id == -1) {
JSG.debug("Dim " + id + " is internally blacklisted. Skipping...");
continue;
}
i++;
if (dimensionsWithGate.contains(id)) {
JSG.debug("Dim " + id + " has already gate. Skipping...");
continue;
}
World world = TeleportHelper.getWorld(id);
if (world == null || world.provider == null) {
JSG.debug("Dim " + id + " has corrupted provider. (Is world null? " + (world == null ? "true" : "false") + ") Skipping...");
continue;
}
if (!world.provider.isSurfaceWorld() && id != 1) {
boolean shouldSkip = true;
if (dt.getName().startsWith("planet")) shouldSkip = false;
if (dt.getName().startsWith("moon")) shouldSkip = false;
if (dt.getName().contains("asteroids")) shouldSkip = true;
if (shouldSkip) {
JSG.debug("Dim " + id + " is not surface world. Skipping...");
continue;
}
}
GeneratedStargate gs = generateAndPutAddresses(sgn, id, symbolType);
JSG.debug("Found unknown dimension " + id + "! This is it's address:");
JSG.debug(gs.address.toString());
y++;
}
JSG.info("Found " + i + " unknown dimensions. Total " + y + " addresses were added as possible gates!");
}
public static GeneratedStargate generateAndPutAddresses(StargateNetwork sgn, int dim, SymbolTypeEnum symbolTypeEnum) {
Random random = new Random(new BlockPos(0, 0, 0).hashCode() * 31L + dim);
GeneratedStargate gs = null;
StargatePos gatePos = null;
for (SymbolTypeEnum symbolType : SymbolTypeEnum.values()) {
StargateAddress address = new StargateAddress(symbolType);
do {
address.generate(random);
} while (sgn.isStargateInNetwork(address));
if (gatePos == null)
gatePos = new StargatePos(dim, new BlockPos(0, 0, 0), address, symbolTypeEnum);
sgn.addNotGeneratedStargate(address, gatePos);
if (gs == null)
gs = new GeneratedStargate(address, null, true, 0);
}
return gs;
}
}