forked from PaperMC/Starlight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServerWorldMixin.java
58 lines (48 loc) · 2.48 KB
/
ServerWorldMixin.java
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
package ca.spottedleaf.starlight.mixin.common.world;
import ca.spottedleaf.starlight.common.util.CoordinateUtils;
import ca.spottedleaf.starlight.common.world.ExtendedWorld;
import com.mojang.datafixers.util.Either;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.storage.WritableLevelData;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.util.function.Supplier;
@Mixin(ServerLevel.class)
public abstract class ServerWorldMixin extends Level implements WorldGenLevel, ExtendedWorld {
@Shadow
@Final
private ServerChunkCache chunkSource;
protected ServerWorldMixin(final WritableLevelData writableLevelData, final ResourceKey<Level> resourceKey,
final DimensionType dimensionType, final Supplier<ProfilerFiller> supplier, final boolean bl,
final boolean bl2, final long l) {
super(writableLevelData, resourceKey, dimensionType, supplier, bl, bl2, l);
}
@Override
public final LevelChunk getChunkAtImmediately(final int chunkX, final int chunkZ) {
final ChunkMap storage = this.chunkSource.chunkMap;
final ChunkHolder holder = storage.getVisibleChunkIfPresent(CoordinateUtils.getChunkKey(chunkX, chunkZ));
if (holder == null) {
return null;
}
final Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure> either = holder.getFutureIfPresentUnchecked(ChunkStatus.FULL).getNow(null);
return either == null ? null : (LevelChunk)either.left().orElse(null);
}
@Override
public final ChunkAccess getAnyChunkImmediately(final int chunkX, final int chunkZ) {
final ChunkMap storage = this.chunkSource.chunkMap;
final ChunkHolder holder = storage.getVisibleChunkIfPresent(CoordinateUtils.getChunkKey(chunkX, chunkZ));
return holder == null ? null : holder.getLastAvailable();
}
}