fabric-1.18: add CustomServerChunkEvents.CHUNK_GENERATE

This commit is contained in:
Kosma Moczek 2021-12-16 20:18:33 +01:00
parent 69a6bb2a2a
commit 32d618e99b
4 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,5 @@
package org.dynmap.fabric_1_18.access;
public interface ProtoChunkAccessor {
boolean getTouchedByWorldGen();
}

View File

@ -0,0 +1,21 @@
package org.dynmap.fabric_1_18.event;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.chunk.Chunk;
public class CustomServerChunkEvents {
public static Event<ChunkGenerate> CHUNK_GENERATE = EventFactory.createArrayBacked(ChunkGenerate.class,
(listeners) -> (world, chunk) -> {
for (ChunkGenerate callback : listeners) {
callback.onChunkGenerate(world, chunk);
}
}
);
@FunctionalInterface
public interface ChunkGenerate {
void onChunkGenerate(ServerWorld world, Chunk chunk);
}
}

View File

@ -0,0 +1,30 @@
package org.dynmap.fabric_1_18.mixin;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.ProtoChunk;
import org.dynmap.fabric_1_18.access.ProtoChunkAccessor;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ProtoChunk.class)
public class ProtoChunkMixin implements ProtoChunkAccessor {
private boolean touchedByWorldGen = false;
@Inject(
method = "setBlockState",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/chunk/ChunkSection;setBlockState(IIILnet/minecraft/block/BlockState;)Lnet/minecraft/block/BlockState;"
)
)
public void setBlockState(BlockPos pos, BlockState state, boolean moved, CallbackInfoReturnable<BlockState> info) {
touchedByWorldGen = true;
}
public boolean getTouchedByWorldGen() {
return touchedByWorldGen;
}
}

View File

@ -7,6 +7,7 @@
"BiomeEffectsAccessor",
"MinecraftServerMixin",
"PlayerManagerMixin",
"ProtoChunkMixin",
"ServerPlayerEntityMixin",
"ServerPlayNetworkHandlerMixin",
"ThreadedAnvilChunkStorageAccessor",