Skip to content

Commit

Permalink
Fixed Slimes and Magma Cubes not spawning.
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Jan 13, 2025
1 parent 23c16ae commit c2e27ce
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/net/frozenblock/wilderwild/block/AlgaeBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<BlockPos> 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<BlockPos> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
),
Expand All @@ -47,7 +48,7 @@ public class SlimeMixin {
EntityType<Slime> type, @NotNull LevelAccessor level, MobSpawnType spawnReason, BlockPos pos, @NotNull RandomSource random, CallbackInfoReturnable<Boolean> 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);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/wilderwild.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c2e27ce

Please sign in to comment.