|
2 | 2 |
|
3 | 3 | import net.minecraft.core.BlockPos; |
4 | 4 | import net.minecraft.core.Direction; |
5 | | -import net.minecraft.world.level.Level; |
6 | 5 | import net.minecraft.world.level.LevelAccessor; |
7 | 6 | import net.minecraft.world.level.block.Blocks; |
8 | 7 | import net.minecraft.world.level.block.state.BlockState; |
9 | 8 | import net.minecraft.world.level.material.FluidState; |
10 | 9 | import net.minecraft.world.level.material.Fluids; |
11 | 10 |
|
12 | 11 | import java.util.ArrayList; |
| 12 | +import java.util.Collections; |
13 | 13 | import java.util.List; |
| 14 | +import java.util.Map; |
| 15 | +import net.minecraft.server.level.ServerLevel; |
| 16 | +import java.util.WeakHashMap; |
14 | 17 |
|
15 | 18 | public class FloodingManager { |
16 | 19 |
|
17 | 20 | public static final int FLOOD_TIME = 10; |
18 | 21 | private static final int MAX_DEPTH = 6; |
19 | 22 |
|
20 | | - private static final List<ScheduledFloodingEntry> scheduledFloods = new ArrayList<>(); |
| 23 | + private static final Map<ServerLevel, List<ScheduledFloodingEntry>> scheduledFloods = Collections.synchronizedMap(new WeakHashMap<>()); |
21 | 24 |
|
22 | 25 | public static void scheduleForFlooding(LevelAccessor level, BlockPos pos, int depth) { |
23 | 26 | if (PrettyBeachesConfig.getActive().animatedFlooding) { |
24 | | - scheduledFloods.add(new ScheduledFloodingEntry(level, pos, depth)); |
| 27 | + if (level instanceof ServerLevel serverLevel) { |
| 28 | + List<ScheduledFloodingEntry> floods = scheduledFloods.computeIfAbsent(serverLevel, k -> new ArrayList<>()); |
| 29 | + floods.add(new ScheduledFloodingEntry(pos, depth)); |
| 30 | + } |
25 | 31 | } else { |
26 | 32 | populateWater(level, pos, depth); |
27 | 33 | } |
28 | 34 | } |
29 | 35 |
|
30 | | - public static void onWorldTick(Level level) { |
31 | | - for (int i = scheduledFloods.size() - 1; i >= 0; i--) { |
32 | | - ScheduledFloodingEntry entry = scheduledFloods.get(i); |
| 36 | + public static void onWorldTick(ServerLevel level) { |
| 37 | + List<ScheduledFloodingEntry> floods = scheduledFloods.get(level); |
| 38 | + if (floods == null || floods.isEmpty()) { |
| 39 | + return; |
| 40 | + } |
| 41 | + for (int i = floods.size() - 1; i >= 0; i--) { |
| 42 | + ScheduledFloodingEntry entry = floods.get(i); |
33 | 43 | entry.ticksExisted++; |
34 | 44 | if (entry.ticksExisted >= FLOOD_TIME) { |
35 | | - populateWater(entry.level, entry.pos, entry.depth); |
36 | | - scheduledFloods.remove(i); |
| 45 | + populateWater(level, entry.pos, entry.depth); |
| 46 | + floods.remove(i); |
37 | 47 | } |
38 | 48 | } |
39 | 49 | } |
|
0 commit comments