|
6 | 6 | import at.petrak.hexcasting.api.misc.Result; |
7 | 7 | import at.petrak.hexcasting.api.mod.HexConfig; |
8 | 8 | import at.petrak.hexcasting.api.pigment.FrozenPigment; |
| 9 | +import at.petrak.hexcasting.api.utils.ChunkScanning; |
9 | 10 | import at.petrak.hexcasting.api.utils.HexUtils; |
10 | 11 | import com.mojang.datafixers.util.Pair; |
11 | 12 | import net.minecraft.ChatFormatting; |
|
19 | 20 | import net.minecraft.server.level.*; |
20 | 21 | import net.minecraft.world.item.ItemStack; |
21 | 22 | import net.minecraft.world.item.Items; |
22 | | -import net.minecraft.world.level.ChunkPos; |
23 | | -import net.minecraft.world.level.block.state.BlockState; |
24 | | -import net.minecraft.world.level.chunk.ChunkAccess; |
25 | | -import net.minecraft.world.level.chunk.ChunkStatus; |
26 | 23 | import net.minecraft.world.phys.AABB; |
27 | 24 | import org.jetbrains.annotations.Nullable; |
28 | 25 |
|
29 | 26 | import java.util.*; |
30 | | -import java.util.concurrent.ExecutionException; |
31 | 27 |
|
32 | 28 | /** |
33 | 29 | * See {@link BlockEntityAbstractImpetus}, this is what's stored in it |
@@ -113,30 +109,17 @@ protected CircleExecutionState(BlockPos impetusPos, Direction impetusDir, |
113 | 109 | var positiveBlock = new BlockPos.MutableBlockPos(); |
114 | 110 | var negativeBlock = new BlockPos.MutableBlockPos(); |
115 | 111 | var lastBlockPos = new BlockPos.MutableBlockPos(); |
| 112 | + var scanning = new ChunkScanning(level); |
116 | 113 | BlockPos firstBlock = null; |
117 | | - HashMap<ChunkPos, ChunkAccess> chunkMap = new HashMap<>(); |
| 114 | + |
118 | 115 | while (!todo.isEmpty()) { |
119 | 116 | var pair = todo.pop(); |
120 | 117 | var enterDir = pair.getFirst(); |
121 | 118 | var herePos = pair.getSecond(); |
| 119 | + var hereBs = scanning.getBlock(herePos); |
122 | 120 |
|
123 | | - BlockState hereBs; |
124 | | - var chunkPos = new ChunkPos(herePos); |
125 | | - |
126 | | - if (!chunkMap.containsKey(chunkPos)) { // Have we found/loaded this chunk yet? |
127 | | - var z = level.getChunkSource().getChunkFuture(chunkPos.x,chunkPos.z, ChunkStatus.EMPTY,true); // For some reason, loads almost no chunks |
128 | | - try { |
129 | | - if (z.get().left().isPresent()){ // Has the Future computed yet? |
130 | | - chunkMap.put(chunkPos,z.get().left().get()); |
131 | | - hereBs = z.get().left().get().getBlockState(herePos); |
132 | | - } else { // If the future has not been somehow, run normal getBlockState |
133 | | - hereBs = level.getLevel().getBlockState(herePos); |
134 | | - } |
135 | | - } catch (InterruptedException | ExecutionException e) { // If something goes *wrong*, run normal getBlockState |
136 | | - hereBs = level.getLevel().getBlockState(herePos); |
137 | | - } |
138 | | - } else { // Oh good! We found this chunk already, get it from the HashMap |
139 | | - hereBs = chunkMap.get(chunkPos).getBlockState(herePos); |
| 121 | + if (hereBs == null){ |
| 122 | + continue; |
140 | 123 | } |
141 | 124 |
|
142 | 125 | if (!(hereBs.getBlock() instanceof ICircleComponent cmp)) { |
@@ -175,6 +158,8 @@ protected CircleExecutionState(BlockPos impetusPos, Direction impetusDir, |
175 | 158 | return new Result.Err<>(null); |
176 | 159 | } |
177 | 160 | } |
| 161 | + // Maybe not required, but still seems like a good idea |
| 162 | + scanning.clearCache(); |
178 | 163 |
|
179 | 164 | if (firstBlock == null) { |
180 | 165 | return new Result.Err<>(null); |
|
0 commit comments