Skip to content

Commit 86bdac9

Browse files
committed
Added config limit
1 parent 41e5685 commit 86bdac9

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

Common/src/main/java/at/petrak/hexcasting/api/casting/circles/CircleExecutionState.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import at.petrak.hexcasting.api.casting.eval.env.CircleCastEnv;
55
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage;
66
import at.petrak.hexcasting.api.misc.Result;
7+
import at.petrak.hexcasting.api.mod.HexConfig;
78
import at.petrak.hexcasting.api.pigment.FrozenPigment;
89
import at.petrak.hexcasting.api.utils.HexUtils;
910
import com.mojang.datafixers.util.Pair;
@@ -113,7 +114,7 @@ protected CircleExecutionState(BlockPos impetusPos, Direction impetusDir,
113114
var negativeBlock = new BlockPos.MutableBlockPos();
114115
var lastBlockPos = new BlockPos.MutableBlockPos();
115116
BlockPos firstBlock = null;
116-
HashMap<ChunkPos, ChunkAccess> chunkSet = new HashMap<>();
117+
HashMap<ChunkPos, ChunkAccess> chunkMap = new HashMap<>();
117118
while (!todo.isEmpty()) {
118119

119120
var pair = todo.pop();
@@ -123,21 +124,22 @@ protected CircleExecutionState(BlockPos impetusPos, Direction impetusDir,
123124
BlockState hereBs;
124125
var chunkPos = new ChunkPos(herePos);
125126

126-
if (!chunkSet.containsKey(chunkPos)) {
127-
var z = level.getChunkSource().getChunkFuture(chunkPos.x,chunkPos.z, ChunkStatus.EMPTY,true);
127+
if (!chunkMap.containsKey(chunkPos)) { // Have we found/loaded this chunk yet?
128+
var z = level.getChunkSource().getChunkFuture(chunkPos.x,chunkPos.z, ChunkStatus.EMPTY,true); // For some reason, loads almost no chunks
128129
try {
129-
if (z.get().left().isPresent()){
130-
chunkSet.put(chunkPos,z.get().left().get());
130+
if (z.get().left().isPresent()){ // Has the Future computed yet?
131+
chunkMap.put(chunkPos,z.get().left().get());
131132
hereBs = z.get().left().get().getBlockState(herePos);
132-
} else {
133+
} else { // If the future has not been somehow, run normal getBlockState
133134
hereBs = level.getLevel().getBlockState(herePos);
134135
}
135-
} catch (InterruptedException | ExecutionException e) {
136+
} catch (InterruptedException | ExecutionException e) { // If something goes *wrong*, run normal getBlockState
136137
hereBs = level.getLevel().getBlockState(herePos);
137138
}
138-
} else {
139-
hereBs = chunkSet.get(chunkPos).getBlockState(herePos);
139+
} else { // Oh good! We found this chunk already, get it from the HashMap
140+
hereBs = chunkMap.get(chunkPos).getBlockState(herePos);
140141
}
142+
141143
if (!(hereBs.getBlock() instanceof ICircleComponent cmp)) {
142144
continue;
143145
}
@@ -162,12 +164,17 @@ protected CircleExecutionState(BlockPos impetusPos, Direction impetusDir,
162164
if (herePos.getZ() > positiveBlock.getZ()) positiveBlock.setZ(herePos.getZ());
163165
if (herePos.getZ() < negativeBlock.getZ()) negativeBlock.setZ(herePos.getZ());
164166

165-
// it's new
167+
// It's new
166168
var outs = cmp.possibleExitDirections(herePos, hereBs, level);
167169
for (var out : outs) {
168170
todo.add(Pair.of(out, herePos.relative(out)));
169171
}
170172
}
173+
174+
// Who would leave out the config limit? If this is forgotten, someone could make a Spell Circle the size of a world
175+
if (seenGoodPosSet.size() >= HexConfig.server().maxSpellCircleLength()){
176+
return new Result.Err<>(null);
177+
}
171178
}
172179

173180
if (firstBlock == null) {

0 commit comments

Comments
 (0)