-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uses a workaround that returns a dummy `ProtoChunk` in `ChunkRegion#getChunk` to prevent issues due to missing `null` checks. This means there are issues at chunk borders, where features will get cut off. A potential solution for this is to store features' block modifications in the save data, and apply these block modifications on top of world generation chunk data.
- Loading branch information
1 parent
1fad880
commit a537247
Showing
7 changed files
with
256 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
common/src/main/java/io/github/steveplays28/noisium/mixin/world/ChunkRegionMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.github.steveplays28.noisium.mixin.world; | ||
|
||
import net.minecraft.registry.RegistryKeys; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.math.ChunkPos; | ||
import net.minecraft.world.ChunkRegion; | ||
import net.minecraft.world.StructureWorldAccess; | ||
import net.minecraft.world.chunk.Chunk; | ||
import net.minecraft.world.chunk.ChunkStatus; | ||
import net.minecraft.world.chunk.ProtoChunk; | ||
import net.minecraft.world.chunk.UpgradeData; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import java.util.List; | ||
|
||
@Mixin(ChunkRegion.class) | ||
public abstract class ChunkRegionMixin implements StructureWorldAccess { | ||
|
||
@Shadow | ||
@Final | ||
private ServerWorld world; | ||
|
||
@Shadow | ||
@Final | ||
private ChunkPos lowerCorner; | ||
|
||
@Shadow | ||
@Final | ||
private List<Chunk> chunks; | ||
|
||
@Shadow | ||
@Final | ||
private int width; | ||
|
||
/** | ||
* @return The loaded {@link Chunk} at the specified chunk position, or a dummy {@link ProtoChunk} if the specified chunk position isn't loaded. | ||
* @author Steveplays28 | ||
* @reason Workaround for there not being {@code null} checks when the specified chunk position isn't in this {@link ChunkRegion}'s bounds. | ||
*/ | ||
@Overwrite | ||
public @Nullable Chunk getChunk(int chunkPosX, int chunkPosZ, ChunkStatus leastChunkStatus, boolean create) { | ||
if (!this.isChunkLoaded(chunkPosX, chunkPosZ)) { | ||
// TODO: Replace the ProtoChunk instances with null and add null checks where needed using ASM | ||
var protoChunk = new ProtoChunk( | ||
new ChunkPos(chunkPosX, chunkPosZ), UpgradeData.NO_UPGRADE_DATA, this.world, this.world.getRegistryManager().get( | ||
RegistryKeys.BIOME), null); | ||
protoChunk.setLightingProvider(world.getLightingProvider()); | ||
protoChunk.setStatus(ChunkStatus.FULL); | ||
return protoChunk; | ||
} | ||
|
||
int i = chunkPosX - this.lowerCorner.x; | ||
int j = chunkPosZ - this.lowerCorner.z; | ||
var chunk = (Chunk) this.chunks.get(i + j * this.width); | ||
if (chunk.getStatus().isAtLeast(leastChunkStatus)) { | ||
return chunk; | ||
} | ||
|
||
// TODO: Replace the ProtoChunk instances with null and add null checks where needed using ASM | ||
var protoChunk = new ProtoChunk( | ||
new ChunkPos(chunkPosX, chunkPosZ), UpgradeData.NO_UPGRADE_DATA, this.world, this.world.getRegistryManager().get( | ||
RegistryKeys.BIOME), null); | ||
protoChunk.setLightingProvider(world.getLightingProvider()); | ||
protoChunk.setStatus(ChunkStatus.FULL); | ||
return protoChunk; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters