Fix butterflies spawning in the middle of nowhere

This commit is contained in:
Sollace 2024-03-25 18:09:16 +00:00
parent fd03dabdd6
commit f0c5cdb156
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 6 additions and 1 deletions

View file

@ -72,6 +72,10 @@ public class ButterflyEntity extends AmbientEntity {
return createMobAttributes().add(EntityAttributes.GENERIC_MAX_HEALTH, 2);
}
public static boolean canSpawn(EntityType<? extends ButterflyEntity> type, WorldAccess world, SpawnReason spawnReason, BlockPos pos, Random random) {
return world.getBlockState(pos.down()).isIn(BlockTags.ANIMALS_SPAWNABLE_ON);
}
@Override
public float getSoundPitch() {
return super.getSoundPitch() * 0.95F;

View file

@ -25,7 +25,8 @@ import net.minecraft.registry.tag.BiomeTags;
import net.minecraft.world.Heightmap.Type;
public interface UEntities {
EntityType<ButterflyEntity> BUTTERFLY = register("butterfly", FabricEntityTypeBuilder.create(SpawnGroup.AMBIENT, ButterflyEntity::new)
EntityType<ButterflyEntity> BUTTERFLY = register("butterfly", FabricEntityTypeBuilder.createMob().spawnGroup(SpawnGroup.AMBIENT).entityFactory(ButterflyEntity::new)
.spawnRestriction(Location.NO_RESTRICTIONS, Type.WORLD_SURFACE_WG, ButterflyEntity::canSpawn)
.dimensions(EntityDimensions.fixed(0.25F, 0.25F)));
EntityType<MagicProjectileEntity> THROWN_ITEM = register("thrown_item", FabricEntityTypeBuilder.<MagicProjectileEntity>create(SpawnGroup.MISC, MagicProjectileEntity::new)
.trackRangeBlocks(100)