diff --git a/common/src/main/java/dev/ryanhcode/sable/mixin/stop_lightning/ServerLevelMixin.java b/common/src/main/java/dev/ryanhcode/sable/mixin/stop_lightning/ServerLevelMixin.java new file mode 100644 index 00000000..8d685df4 --- /dev/null +++ b/common/src/main/java/dev/ryanhcode/sable/mixin/stop_lightning/ServerLevelMixin.java @@ -0,0 +1,47 @@ +package dev.ryanhcode.sable.mixin.stop_lightning; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import dev.ryanhcode.sable.api.sublevel.SubLevelContainer; +import net.minecraft.core.Holder; +import net.minecraft.core.RegistryAccess; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.world.level.Level; +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.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import java.util.function.Supplier; + +/** + * Prevents lightning or skeleton traps from spawning inside plots to avoid inflating spawn rates + */ +@Mixin(ServerLevel.class) +public abstract class ServerLevelMixin extends Level { + + protected ServerLevelMixin( + final WritableLevelData levelData, + final ResourceKey dimension, + final RegistryAccess registryAccess, + final Holder dimensionTypeRegistration, + final Supplier profiler, + final boolean isClientSide, + final boolean isDebug, + final long biomeZoomSeed, + final int maxChainedNeighborUpdates) { + super(levelData, dimension, registryAccess, dimensionTypeRegistration, profiler, isClientSide, isDebug, biomeZoomSeed, maxChainedNeighborUpdates); + } + + @WrapOperation(method = "tickChunk", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;isThundering()Z")) + private boolean sable$preventLightningInPlot(final ServerLevel instance, final Operation original, @Local(argsOnly = true) final LevelChunk chunk) { + final SubLevelContainer plotContainer = SubLevelContainer.getContainer(this); + if (plotContainer != null && plotContainer.inBounds(chunk.getPos())) { + return false; + } + return original.call(instance); + } +} \ No newline at end of file diff --git a/common/src/main/resources/sable.mixins.json b/common/src/main/resources/sable.mixins.json index faf5ee1b..33dcb788 100644 --- a/common/src/main/resources/sable.mixins.json +++ b/common/src/main/resources/sable.mixins.json @@ -208,6 +208,7 @@ "sculk_vibrations.VibrationSystemListenerMixin", "sculk_vibrations.VibrationSystemTickerMixin", "sign_interaction.SignBlockEntityMixin", + "stop_lightning.ServerLevelMixin", "tracking_points.EntityMixin", "tracking_points.ServerPlayerMixin", "udp.ConnectionMixin",