From c2e27ce76cedb4fe3ac5b0bed7e2e7468d1e7a9f Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Mon, 13 Jan 2025 17:06:52 -0500 Subject: [PATCH] Fixed Slimes and Magma Cubes not spawning. --- CHANGELOG.md | 2 +- .../wilderwild/block/AlgaeBlock.java | 11 +++-- .../wilderwild/mixin/entity/ai/MobMixin.java | 17 ------- .../mixin/entity/slime/MobMixin.java | 45 +++++++++++++++++++ .../mixin/entity/slime/SlimeMixin.java | 7 +-- src/main/resources/wilderwild.mixins.json | 1 + 6 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 src/main/java/net/frozenblock/wilderwild/mixin/entity/slime/MobMixin.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 398ae12f8..c08021562 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,7 @@ hi - Added Pollen and all Glory of the Snow Petals to the `minecraft:inside_step_sound_blocks` and `minecraft:combination_step_sound_blocks` block tags. - Removed the Bush from the `minecraft:inside_step_sound_blocks` block tag. - Slightly decreased the pitch of Magma block sounds. -- Fixed any potential issues with Slime spawning. +- Fixed Slimes and Magma Cubes not spawning. # Butterfly Branch - Added Butterflies diff --git a/src/main/java/net/frozenblock/wilderwild/block/AlgaeBlock.java b/src/main/java/net/frozenblock/wilderwild/block/AlgaeBlock.java index d319650af..6910fbe72 100644 --- a/src/main/java/net/frozenblock/wilderwild/block/AlgaeBlock.java +++ b/src/main/java/net/frozenblock/wilderwild/block/AlgaeBlock.java @@ -22,6 +22,7 @@ import java.util.Iterator; import java.util.List; import net.frozenblock.lib.math.api.AdvancedMath; +import net.frozenblock.wilderwild.registry.WWBlocks; import net.frozenblock.wilderwild.tag.WWEntityTags; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -138,14 +139,12 @@ public void performBonemeal(@NotNull ServerLevel level, @NotNull RandomSource ra this.bonemealPos = null; } - public boolean hasAmountNearby(@NotNull LevelAccessor level, @NotNull BlockPos blockPos, int x, int threshold) { - Iterator posesToCheck = BlockPos.betweenClosed(blockPos.offset(-x, -x, -x), blockPos.offset(x, x, x)).iterator(); + public static boolean hasNearbyAlgae(@NotNull LevelAccessor level, @NotNull BlockPos blockPos, int distance, int threshold) { + Iterator posesToCheck = BlockPos.betweenClosed(blockPos.offset(-distance, -distance, -distance), blockPos.offset(distance, distance, distance)).iterator(); int count = 0; do { - if (!posesToCheck.hasNext()) { - return false; - } - if (level.getBlockState(posesToCheck.next()).is(this)) { + if (!posesToCheck.hasNext()) return false; + if (level.getBlockState(posesToCheck.next()).is(WWBlocks.ALGAE)) { count = count + 1; } } while (count < threshold); diff --git a/src/main/java/net/frozenblock/wilderwild/mixin/entity/ai/MobMixin.java b/src/main/java/net/frozenblock/wilderwild/mixin/entity/ai/MobMixin.java index 7011f32d3..b8ae8efc2 100644 --- a/src/main/java/net/frozenblock/wilderwild/mixin/entity/ai/MobMixin.java +++ b/src/main/java/net/frozenblock/wilderwild/mixin/entity/ai/MobMixin.java @@ -18,12 +18,9 @@ package net.frozenblock.wilderwild.mixin.entity.ai; -import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import net.frozenblock.wilderwild.config.WWEntityConfig; -import net.frozenblock.wilderwild.registry.WWBlocks; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; -import net.minecraft.world.entity.monster.Slime; import net.minecraft.world.level.Level; import net.minecraft.world.level.pathfinder.PathType; import org.spongepowered.asm.mixin.Mixin; @@ -47,18 +44,4 @@ public void setPathfindingMalus(PathType pathType, float malus) { } } - @ModifyExpressionValue( - method = "checkSpawnObstruction", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/level/LevelReader;containsAnyLiquid(Lnet/minecraft/world/phys/AABB;)Z" - ) - ) - public boolean wilderWild$checkSpawnObstruction(boolean original) { - if (Mob.class.cast(this) instanceof Slime slime) { - return original || !WWBlocks.ALGAE.hasAmountNearby(slime.level(), slime.blockPosition(), 1, 3); - } - return original; - } - } diff --git a/src/main/java/net/frozenblock/wilderwild/mixin/entity/slime/MobMixin.java b/src/main/java/net/frozenblock/wilderwild/mixin/entity/slime/MobMixin.java new file mode 100644 index 000000000..cdb335397 --- /dev/null +++ b/src/main/java/net/frozenblock/wilderwild/mixin/entity/slime/MobMixin.java @@ -0,0 +1,45 @@ +/* + * Copyright 2023-2025 FrozenBlock + * This file is part of Wilder Wild. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, see . + */ + +package net.frozenblock.wilderwild.mixin.entity.slime; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import net.frozenblock.wilderwild.block.AlgaeBlock; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.Mob; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(Mob.class) +public class MobMixin { + + @ModifyExpressionValue( + method = "checkSpawnObstruction", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/level/LevelReader;containsAnyLiquid(Lnet/minecraft/world/phys/AABB;)Z" + ) + ) + public boolean wilderWild$checkSpawnObstruction(boolean original) { + if (Mob.class.cast(this) instanceof Mob mob && mob.getType() == EntityType.SLIME) { + return original && !AlgaeBlock.hasNearbyAlgae(mob.level(), mob.blockPosition(), 1, 3); + } + return original; + } + +} diff --git a/src/main/java/net/frozenblock/wilderwild/mixin/entity/slime/SlimeMixin.java b/src/main/java/net/frozenblock/wilderwild/mixin/entity/slime/SlimeMixin.java index c997bb299..6b852fba3 100644 --- a/src/main/java/net/frozenblock/wilderwild/mixin/entity/slime/SlimeMixin.java +++ b/src/main/java/net/frozenblock/wilderwild/mixin/entity/slime/SlimeMixin.java @@ -18,7 +18,7 @@ package net.frozenblock.wilderwild.mixin.entity.slime; -import net.frozenblock.wilderwild.registry.WWBlocks; +import net.frozenblock.wilderwild.block.AlgaeBlock; import net.minecraft.core.BlockPos; import net.minecraft.util.RandomSource; import net.minecraft.world.entity.EntityType; @@ -37,7 +37,8 @@ public class SlimeMixin { @Inject( method = "checkSlimeSpawnRules", - at = @At(value = "INVOKE", + at = @At( + value = "INVOKE", target = "Lnet/minecraft/world/level/LevelAccessor;getBiome(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/core/Holder;", shift = At.Shift.BEFORE ), @@ -47,7 +48,7 @@ public class SlimeMixin { EntityType type, @NotNull LevelAccessor level, MobSpawnType spawnReason, BlockPos pos, @NotNull RandomSource random, CallbackInfoReturnable info ) { if (level.getBrightness(LightLayer.BLOCK, pos) <= random.nextInt(7)) { - if ((MobSpawnType.ignoresLightRequirements(spawnReason) || random.nextInt(5) == 0) && WWBlocks.ALGAE.hasAmountNearby(level, pos, 1, 3)) { + if ((MobSpawnType.ignoresLightRequirements(spawnReason) || random.nextInt(5) == 0) && AlgaeBlock.hasNearbyAlgae(level, pos, 1, 3)) { info.setReturnValue(true); } } diff --git a/src/main/resources/wilderwild.mixins.json b/src/main/resources/wilderwild.mixins.json index 5b941956e..70789e0c4 100644 --- a/src/main/resources/wilderwild.mixins.json +++ b/src/main/resources/wilderwild.mixins.json @@ -50,6 +50,7 @@ "entity.jellyfish.NaturalSpawnerMixin", "entity.lightning.LightningBoltMixin", "entity.penguin.LivingEntityMixin", + "entity.slime.MobMixin", "entity.slime.SlimeMixin", "entity.slime.SpawnPlacementsMixin", "entity.stray.StrayMixin",