Search in sources :

Example 1 with PatrolEntity

use of net.minecraft.entity.mob.PatrolEntity in project Biome-Makeover by Lemonszz.

the class PillagerSpawnerMixin method spawnMixin.

@Inject(at = @At("HEAD"), method = "spawnPillager", cancellable = true)
private void spawnMixin(ServerWorld world, BlockPos pos, Random random, boolean captain, CallbackInfoReturnable<Boolean> cbi) {
    Biome biome = world.getBiome(pos);
    Biome.Category category = biome.getCategory();
    if (category == Biome.Category.MESA) {
        BlockState blockState = world.getBlockState(pos);
        if (!SpawnHelper.isClearForSpawn(world, pos, blockState, blockState.getFluidState(), BMEntities.COWBOY)) {
            cbi.setReturnValue(false);
            return;
        } else if (!PatrolEntity.canSpawn(BMEntities.COWBOY, world, SpawnReason.PATROL, pos, random)) {
            cbi.setReturnValue(false);
            return;
        } else {
            PatrolEntity patrolEntity = BMEntities.COWBOY.create(world);
            if (patrolEntity != null) {
                HorseEntity horseEntity = EntityType.HORSE.create(world);
                horseEntity.updatePosition(pos.getX(), pos.getY(), pos.getZ());
                horseEntity.initialize(world, world.getLocalDifficulty(pos), SpawnReason.PATROL, null, null);
                patrolEntity.startRiding(horseEntity);
                if (captain) {
                    patrolEntity.setPatrolLeader(true);
                    patrolEntity.setRandomPatrolTarget();
                    ((HorseHat) horseEntity).setHat();
                }
                ((HorseHat) horseEntity).setCowboySpawned();
                patrolEntity.updatePosition(pos.getX(), pos.getY(), pos.getZ());
                patrolEntity.initialize(world, world.getLocalDifficulty(pos), SpawnReason.PATROL, null, null);
                world.spawnEntityAndPassengers(horseEntity);
                cbi.setReturnValue(true);
                return;
            } else {
                cbi.setReturnValue(false);
                return;
            }
        }
    }
}
Also used : Biome(net.minecraft.world.biome.Biome) BlockState(net.minecraft.block.BlockState) HorseEntity(net.minecraft.entity.passive.HorseEntity) PatrolEntity(net.minecraft.entity.mob.PatrolEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

BlockState (net.minecraft.block.BlockState)1 PatrolEntity (net.minecraft.entity.mob.PatrolEntity)1 HorseEntity (net.minecraft.entity.passive.HorseEntity)1 Biome (net.minecraft.world.biome.Biome)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1