diff --git a/gradle.properties b/gradle.properties index f4a65c1e..28163db3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ minecraft_version=1.17.1 yarn_mappings=6 loader_version=0.12.4 # Mod Properties -mod_version=0.12.4 +mod_version=0.12.5 maven_group=ru.betterend archives_base_name=better-end @@ -15,6 +15,6 @@ archives_base_name=better-end patchouli_version = 55-FABRIC-SNAPSHOT fabric_version = 0.42.1+1.17 -bclib_version = 0.5.3 +bclib_version = 0.5.4 rei_version = 6.0.264-alpha canvas_version = 1.0.+ diff --git a/src/main/java/ru/betterend/entity/CubozoaEntity.java b/src/main/java/ru/betterend/entity/CubozoaEntity.java index b973567a..fc30e836 100644 --- a/src/main/java/ru/betterend/entity/CubozoaEntity.java +++ b/src/main/java/ru/betterend/entity/CubozoaEntity.java @@ -1,6 +1,5 @@ package ru.betterend.entity; -import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.game.ClientboundGameEventPacket; import net.minecraft.network.syncher.EntityDataAccessor; @@ -27,14 +26,10 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.ServerLevelAccessor; -import net.minecraft.world.phys.AABB; import ru.bclib.api.BiomeAPI; import ru.betterend.registry.EndBiomes; import ru.betterend.registry.EndItems; -import java.util.List; -import java.util.Random; - public class CubozoaEntity extends AbstractSchoolingFish { public static final int VARIANTS = 2; private static final EntityDataAccessor VARIANT = SynchedEntityData.defineId( @@ -124,14 +119,6 @@ public class CubozoaEntity extends AbstractSchoolingFish { return getByteScale() / 32F + 0.75F; } - public static boolean canSpawn(EntityType type, ServerLevelAccessor world, MobSpawnType spawnReason, BlockPos pos, Random random) { - AABB box = new AABB(pos).inflate(16); - List list = world.getEntitiesOfClass(CubozoaEntity.class, box, (entity) -> { - return true; - }); - return list.size() < 9; - } - protected float getStandingEyeHeight(Pose pose, EntityDimensions dimensions) { return dimensions.height * 0.5F; } diff --git a/src/main/java/ru/betterend/entity/DragonflyEntity.java b/src/main/java/ru/betterend/entity/DragonflyEntity.java index 5c4fe209..87705b1c 100644 --- a/src/main/java/ru/betterend/entity/DragonflyEntity.java +++ b/src/main/java/ru/betterend/entity/DragonflyEntity.java @@ -9,7 +9,6 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.Mob; -import net.minecraft.world.entity.MobSpawnType; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.control.FlyingMoveControl; @@ -27,9 +26,7 @@ import net.minecraft.world.entity.animal.FlyingAnimal; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelReader; -import net.minecraft.world.level.ServerLevelAccessor; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.levelgen.Heightmap.Types; import net.minecraft.world.level.pathfinder.BlockPathTypes; import net.minecraft.world.level.pathfinder.Path; import net.minecraft.world.phys.Vec3; @@ -39,7 +36,6 @@ import ru.betterend.registry.EndEntities; import ru.betterend.registry.EndSounds; import java.util.EnumSet; -import java.util.Random; public class DragonflyEntity extends Animal implements FlyingAnimal { public DragonflyEntity(EntityType entityType, Level world) { @@ -218,9 +214,4 @@ public class DragonflyEntity extends Animal implements FlyingAnimal { public AgeableMob getBreedOffspring(ServerLevel world, AgeableMob entity) { return EndEntities.DRAGONFLY.create(world); } - - public static boolean canSpawn(EntityType type, ServerLevelAccessor world, MobSpawnType spawnReason, BlockPos pos, Random random) { - int y = world.getChunk(pos).getHeight(Types.WORLD_SURFACE, pos.getX() & 15, pos.getY() & 15); - return y > 0 && pos.getY() >= y; - } } diff --git a/src/main/java/ru/betterend/entity/EndFishEntity.java b/src/main/java/ru/betterend/entity/EndFishEntity.java index 6430dc65..7474f5c3 100644 --- a/src/main/java/ru/betterend/entity/EndFishEntity.java +++ b/src/main/java/ru/betterend/entity/EndFishEntity.java @@ -1,6 +1,5 @@ package ru.betterend.entity; -import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.syncher.EntityDataAccessor; @@ -22,14 +21,10 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.ServerLevelAccessor; import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.phys.AABB; import ru.bclib.api.BiomeAPI; import ru.betterend.registry.EndBiomes; import ru.betterend.registry.EndItems; -import java.util.List; -import java.util.Random; - public class EndFishEntity extends AbstractSchoolingFish { public static final int VARIANTS_NORMAL = 5; public static final int VARIANTS_SULPHUR = 3; @@ -152,14 +147,6 @@ public class EndFishEntity extends AbstractSchoolingFish { return getByteScale() / 32F + 0.75F; } - public static boolean canSpawn(EntityType type, ServerLevelAccessor world, MobSpawnType spawnReason, BlockPos pos, Random random) { - AABB box = new AABB(pos).inflate(16); - List list = world.getEntitiesOfClass(EndFishEntity.class, box, (entity) -> { - return true; - }); - return list.size() < 9; - } - @Override protected void dropFromLootTable(DamageSource source, boolean causedByPlayer) { ItemEntity drop = new ItemEntity(level, getX(), getY(), getZ(), new ItemStack(EndItems.END_FISH_RAW)); diff --git a/src/main/java/ru/betterend/entity/EndSlimeEntity.java b/src/main/java/ru/betterend/entity/EndSlimeEntity.java index f1655073..7effbacb 100644 --- a/src/main/java/ru/betterend/entity/EndSlimeEntity.java +++ b/src/main/java/ru/betterend/entity/EndSlimeEntity.java @@ -30,11 +30,11 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.ServerLevelAccessor; -import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.phys.AABB; import ru.bclib.api.BiomeAPI; +import ru.bclib.api.TagAPI; import ru.bclib.util.BlocksHelper; import ru.bclib.util.MHelper; import ru.bclib.world.biomes.BCLBiome; @@ -42,7 +42,6 @@ import ru.betterend.interfaces.ISlime; import ru.betterend.registry.EndBiomes; import java.util.EnumSet; -import java.util.List; import java.util.Random; public class EndSlimeEntity extends Slime { @@ -212,34 +211,26 @@ public class EndSlimeEntity extends Slime { return this.entityData.get(VARIANT) == 0; } - public static boolean canSpawn(EntityType type, ServerLevelAccessor world, MobSpawnType spawnReason, BlockPos pos, Random random) { - return random.nextInt(16) == 0 || isPermanentBiome(world, pos) || (notManyEntities( - world, - pos, - 32, - 3 - ) && isWaterNear(world, pos, 32, 8)); - } - - private static boolean isPermanentBiome(ServerLevelAccessor world, BlockPos pos) { - Biome biome = world.getBiome(pos); - return BiomeAPI.getFromBiome(biome) == EndBiomes.CHORUS_FOREST; - } - - private static boolean notManyEntities(ServerLevelAccessor world, BlockPos pos, int radius, int maxCount) { - AABB box = new AABB(pos).inflate(radius); - List list = world.getEntitiesOfClass(EndSlimeEntity.class, box, (entity) -> { + public static boolean canSpawn(EntityType entityType, LevelAccessor world, MobSpawnType spawnType, BlockPos pos, Random random) { + if (!world.getBlockState(pos.below()).is(TagAPI.BLOCK_END_GROUND)) { + return false; + } + BCLBiome biome = BiomeAPI.getFromBiome(world.getBiome(pos)); + if (biome == EndBiomes.CHORUS_FOREST || biome == EndBiomes.MEGALAKE) { return true; - }); - return list.size() <= maxCount; + } + if (biome == EndBiomes.MEGALAKE_GROVE && random.nextBoolean()) { + return true; + } + return random.nextInt(4) == 0 && isWaterNear(world, pos); } - private static boolean isWaterNear(ServerLevelAccessor world, BlockPos pos, int radius, int radius2) { - for (int x = pos.getX() - radius; x <= pos.getX() + radius; x++) { + private static boolean isWaterNear(LevelAccessor world, BlockPos pos) { + for (int x = pos.getX() - 32; x <= pos.getX() + 32; x++) { POS.setX(x); - for (int z = pos.getZ() - radius; z <= pos.getZ() + radius; z++) { + for (int z = pos.getZ() - 32; z <= pos.getZ() + 32; z++) { POS.setZ(z); - for (int y = pos.getY() - radius2; y <= pos.getY() + radius2; y++) { + for (int y = pos.getY() - 8; y <= pos.getY() + 8; y++) { POS.setY(y); if (world.getBlockState(POS).getBlock() == Blocks.WATER) { return true; diff --git a/src/main/java/ru/betterend/entity/ShadowWalkerEntity.java b/src/main/java/ru/betterend/entity/ShadowWalkerEntity.java index 3dfc5431..8e0b6338 100644 --- a/src/main/java/ru/betterend/entity/ShadowWalkerEntity.java +++ b/src/main/java/ru/betterend/entity/ShadowWalkerEntity.java @@ -9,7 +9,6 @@ import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.MobSpawnType; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal; @@ -20,15 +19,10 @@ import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal; import net.minecraft.world.entity.monster.Monster; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; -import net.minecraft.world.level.ServerLevelAccessor; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.AABB; import ru.bclib.util.MHelper; import ru.betterend.registry.EndSounds; -import java.util.List; -import java.util.Random; - public class ShadowWalkerEntity extends Monster { public ShadowWalkerEntity(EntityType entityType, Level world) { super(entityType, world); @@ -125,17 +119,6 @@ public class ShadowWalkerEntity extends Monster { return attack; } - public static boolean canSpawn(EntityType type, ServerLevelAccessor world, MobSpawnType spawnReason, BlockPos pos, Random random) { - if (Monster.checkMonsterSpawnRules(type, world, spawnReason, pos, random)) { - AABB box = new AABB(pos).inflate(16); - List entities = world.getEntitiesOfClass(ShadowWalkerEntity.class, box, (entity) -> { - return true; - }); - return entities.size() < 6; - } - return false; - } - private final class AttackGoal extends MeleeAttackGoal { private final ShadowWalkerEntity walker; private int ticks; diff --git a/src/main/java/ru/betterend/entity/SilkMothEntity.java b/src/main/java/ru/betterend/entity/SilkMothEntity.java index e894533d..d5fca8ca 100644 --- a/src/main/java/ru/betterend/entity/SilkMothEntity.java +++ b/src/main/java/ru/betterend/entity/SilkMothEntity.java @@ -15,7 +15,6 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.Mob; -import net.minecraft.world.entity.MobSpawnType; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.control.FlyingMoveControl; @@ -35,12 +34,9 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.level.Level; -import net.minecraft.world.level.ServerLevelAccessor; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import net.minecraft.world.level.levelgen.Heightmap.Types; import net.minecraft.world.level.pathfinder.BlockPathTypes; -import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.Nullable; import ru.bclib.util.BlocksHelper; @@ -52,8 +48,6 @@ import ru.betterend.registry.EndEntities; import ru.betterend.registry.EndItems; import java.util.EnumSet; -import java.util.List; -import java.util.Random; public class SilkMothEntity extends Animal implements FlyingAnimal { private BlockPos hivePos; @@ -184,17 +178,6 @@ public class SilkMothEntity extends Animal implements FlyingAnimal { this.level.addFreshEntity(drop); } - public static boolean canSpawn(EntityType type, ServerLevelAccessor world, MobSpawnType spawnReason, BlockPos pos, Random random) { - int y = world.getChunk(pos).getHeight(Types.WORLD_SURFACE, pos.getX() & 15, pos.getY() & 15); - return y > 0 && pos.getY() >= y && notManyEntities(world, pos, 32, 1); - } - - private static boolean notManyEntities(ServerLevelAccessor world, BlockPos pos, int radius, int maxCount) { - AABB box = new AABB(pos).inflate(radius); - List list = world.getEntitiesOfClass(SilkMothEntity.class, box, (entity) -> true); - return list.size() <= maxCount; - } - class MothLookControl extends LookControl { MothLookControl(Mob entity) { super(entity); diff --git a/src/main/java/ru/betterend/integration/EnderscapeIntegration.java b/src/main/java/ru/betterend/integration/EnderscapeIntegration.java index decc5f1c..c8716469 100644 --- a/src/main/java/ru/betterend/integration/EnderscapeIntegration.java +++ b/src/main/java/ru/betterend/integration/EnderscapeIntegration.java @@ -8,7 +8,6 @@ import ru.bclib.api.BiomeAPI; import ru.bclib.api.TagAPI; import ru.bclib.integration.ModIntegration; import ru.bclib.world.features.BCLFeature; -import ru.betterend.registry.EndTags; public class EnderscapeIntegration extends ModIntegration { public EnderscapeIntegration() { diff --git a/src/main/java/ru/betterend/registry/EndEntities.java b/src/main/java/ru/betterend/registry/EndEntities.java index ecce2911..eef41c45 100644 --- a/src/main/java/ru/betterend/registry/EndEntities.java +++ b/src/main/java/ru/betterend/registry/EndEntities.java @@ -11,6 +11,8 @@ import net.minecraft.world.entity.EntityType.EntityFactory; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.MobCategory; import net.minecraft.world.entity.ai.attributes.AttributeSupplier.Builder; +import net.minecraft.world.level.levelgen.Heightmap.Types; +import ru.bclib.api.spawning.SpawnRuleBulder; import ru.bclib.util.ColorUtil; import ru.betterend.BetterEnd; import ru.betterend.config.Configs; @@ -20,7 +22,6 @@ import ru.betterend.entity.EndFishEntity; import ru.betterend.entity.EndSlimeEntity; import ru.betterend.entity.ShadowWalkerEntity; import ru.betterend.entity.SilkMothEntity; -import ru.betterend.util.SpawnHelper; public class EndEntities { public static final EntityType DRAGONFLY = register( @@ -91,12 +92,24 @@ public class EndEntities { ); public static void register() { - SpawnHelper.restrictionAir(DRAGONFLY, DragonflyEntity::canSpawn); - SpawnHelper.restrictionLand(END_SLIME, EndSlimeEntity::canSpawn); - SpawnHelper.restrictionWater(END_FISH, EndFishEntity::canSpawn); - SpawnHelper.restrictionLand(SHADOW_WALKER, ShadowWalkerEntity::canSpawn); - SpawnHelper.restrictionWater(CUBOZOA, CubozoaEntity::canSpawn); - SpawnHelper.restrictionAir(SILK_MOTH, SilkMothEntity::canSpawn); + // Air // + SpawnRuleBulder.start(DRAGONFLY).aboveGround(2).maxNearby(8).buildNoRestrictions(Types.MOTION_BLOCKING); + SpawnRuleBulder.start(SILK_MOTH).aboveGround(2).maxNearby(4).buildNoRestrictions(Types.MOTION_BLOCKING); + + // Land // + SpawnRuleBulder + .start(END_SLIME) + .notPeaceful() + .maxNearby(4, 64) + .onlyOnValidBlocks() + .customRule(EndSlimeEntity::canSpawn) + .buildNoRestrictions(Types.MOTION_BLOCKING); + + SpawnRuleBulder.start(SHADOW_WALKER).notPeaceful().onlyOnValidBlocks().maxNearby(8, 64).buildNoRestrictions(Types.MOTION_BLOCKING); + + // Water // + SpawnRuleBulder.start(END_FISH).maxNearby(8, 64).buildInWater(Types.MOTION_BLOCKING); + SpawnRuleBulder.start(CUBOZOA).maxNearby(8, 64).buildInWater(Types.MOTION_BLOCKING); } protected static EntityType register(String name, MobCategory group, float width, float height, EntityFactory entity) { diff --git a/src/main/java/ru/betterend/util/SpawnHelper.java b/src/main/java/ru/betterend/util/SpawnHelper.java deleted file mode 100644 index e42a688a..00000000 --- a/src/main/java/ru/betterend/util/SpawnHelper.java +++ /dev/null @@ -1,22 +0,0 @@ -package ru.betterend.util; - -import net.fabricmc.fabric.mixin.object.builder.SpawnRestrictionAccessor; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.Mob; -import net.minecraft.world.entity.SpawnPlacements.SpawnPredicate; -import net.minecraft.world.entity.SpawnPlacements.Type; -import net.minecraft.world.level.levelgen.Heightmap.Types; - -public class SpawnHelper { - public static void restrictionAir(EntityType entity, SpawnPredicate predicate) { - SpawnRestrictionAccessor.callRegister(entity, Type.NO_RESTRICTIONS, Types.MOTION_BLOCKING, predicate); - } - - public static void restrictionLand(EntityType entity, SpawnPredicate predicate) { - SpawnRestrictionAccessor.callRegister(entity, Type.ON_GROUND, Types.MOTION_BLOCKING, predicate); - } - - public static void restrictionWater(EntityType entity, SpawnPredicate predicate) { - SpawnRestrictionAccessor.callRegister(entity, Type.IN_WATER, Types.MOTION_BLOCKING, predicate); - } -} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 43bee6c0..7d1697ab 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -45,7 +45,7 @@ "fabricloader": ">=0.12.4", "fabric": ">=0.42.1", "minecraft": ">=1.17", - "bclib": ">=0.5.3" + "bclib": ">=0.5.4" }, "suggests": { "byg": ">=1.1.3",