Skip to content

Commit

Permalink
new: util.chunk_access
Browse files Browse the repository at this point in the history
  • Loading branch information
2No2Name committed Mar 14, 2023
1 parent eaaa756 commit 5039f0e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package me.jellysquid.mods.lithium.common.world;

import net.minecraft.world.chunk.Chunk;
import org.jetbrains.annotations.Nullable;

public interface ChunkView {

@Nullable
Chunk getLoadedChunk(int chunkX, int chunkZ);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package me.jellysquid.mods.lithium.mixin.util.chunk_access;

import me.jellysquid.mods.lithium.common.world.ChunkView;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkCache;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(ChunkCache.class)
public abstract class ChunkCacheMixin implements ChunkView {

@Shadow
protected abstract Chunk getChunk(int chunkX, int chunkZ);

@Override
public @Nullable Chunk getLoadedChunk(int chunkX, int chunkZ) {
return this.getChunk(chunkX, chunkZ);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package me.jellysquid.mods.lithium.mixin.util.chunk_access;

import me.jellysquid.mods.lithium.common.world.ChunkView;
import net.minecraft.world.WorldView;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkStatus;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(WorldView.class)
public interface WorldViewMixin extends ChunkView {

@Shadow
@Nullable Chunk getChunk(int var1, int var2, ChunkStatus var3, boolean var4);

@Override
default @Nullable Chunk getLoadedChunk(int chunkX, int chunkZ) {
return this.getChunk(chunkX, chunkZ, ChunkStatus.FULL, false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@MixinConfigOption(
description = "Access chunks of worlds, chunk caches and chunk regions directly."
)
package me.jellysquid.mods.lithium.mixin.util.chunk_access;

import net.caffeinemc.gradle.MixinConfigOption;
2 changes: 2 additions & 0 deletions src/main/resources/lithium.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
"util.block_entity_retrieval.WorldMixin",
"util.block_tracking.AbstractBlockStateMixin",
"util.block_tracking.ChunkSectionMixin",
"util.chunk_access.ChunkCacheMixin",
"util.chunk_access.WorldViewMixin",
"util.entity_movement_tracking.EntityTrackingSectionMixin",
"util.entity_movement_tracking.SectionedEntityCacheMixin",
"util.entity_movement_tracking.ServerEntityManagerAccessor",
Expand Down

0 comments on commit 5039f0e

Please sign in to comment.