Skip to content

Commit 41e5685

Browse files
committed
Decreased spell circle scan time
Decreased spell circle scan time Removed comment
1 parent 813a489 commit 41e5685

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

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

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@
1818
import net.minecraft.server.level.*;
1919
import net.minecraft.world.item.ItemStack;
2020
import net.minecraft.world.item.Items;
21+
import net.minecraft.world.level.ChunkPos;
2122
import net.minecraft.world.level.block.state.BlockState;
23+
import net.minecraft.world.level.chunk.ChunkAccess;
24+
import net.minecraft.world.level.chunk.ChunkStatus;
2225
import net.minecraft.world.phys.AABB;
2326
import org.jetbrains.annotations.Nullable;
2427

2528
import java.util.*;
29+
import java.util.concurrent.ExecutionException;
2630

2731
/**
2832
* See {@link BlockEntityAbstractImpetus}, this is what's stored in it
@@ -109,29 +113,31 @@ protected CircleExecutionState(BlockPos impetusPos, Direction impetusDir,
109113
var negativeBlock = new BlockPos.MutableBlockPos();
110114
var lastBlockPos = new BlockPos.MutableBlockPos();
111115
BlockPos firstBlock = null;
112-
116+
HashMap<ChunkPos, ChunkAccess> chunkSet = new HashMap<>();
113117
while (!todo.isEmpty()) {
114-
/*
115-
Sophia/Stickia here!
116-
This block of code works well enough, it gets all the ICircleComponent that it can. However,
117-
this tries to do all the calculating in a single tick, so it can get *really* laggy for larger circles.
118-
So, this `while` would likely need to be moved into the #tick method, so it can be spread out over time during start up.
119-
Why are these comments here? Likely so Sophia can remember this for after she gets sleep, or if anyone
120-
else wants to take up the challenge. As for her system will work, but not be clean lmao
121-
122-
As brought up by Chloe, the slates *could* change during start up.
123-
Meaning someone could just place/remove slate at the same rate of discovery, and have World Ambit for almost no slate
124-
cost and generally cheating the system. What would be best would be (somehow) getting the block slate
125-
without loading the chunk its self, meaning servers wont have to handle 1000s of chunks being loaded at once
126-
and players not cheating the system.
127-
But this is easier said than done.
128-
*/
129118

130119
var pair = todo.pop();
131120
var enterDir = pair.getFirst();
132121
var herePos = pair.getSecond();
133122

134-
BlockState hereBs = level.getLevel().getBlockState(herePos); //FUCK THIS LINE. THIS FUC-
123+
BlockState hereBs;
124+
var chunkPos = new ChunkPos(herePos);
125+
126+
if (!chunkSet.containsKey(chunkPos)) {
127+
var z = level.getChunkSource().getChunkFuture(chunkPos.x,chunkPos.z, ChunkStatus.EMPTY,true);
128+
try {
129+
if (z.get().left().isPresent()){
130+
chunkSet.put(chunkPos,z.get().left().get());
131+
hereBs = z.get().left().get().getBlockState(herePos);
132+
} else {
133+
hereBs = level.getLevel().getBlockState(herePos);
134+
}
135+
} catch (InterruptedException | ExecutionException e) {
136+
hereBs = level.getLevel().getBlockState(herePos);
137+
}
138+
} else {
139+
hereBs = chunkSet.get(chunkPos).getBlockState(herePos);
140+
}
135141
if (!(hereBs.getBlock() instanceof ICircleComponent cmp)) {
136142
continue;
137143
}

0 commit comments

Comments
 (0)