Search in sources :

Example 1 with EntityBreedEvent

use of org.bukkit.event.entity.EntityBreedEvent in project LaBoulangerieMmo by LaBoulangerie.

the class AnimalTwins method trigger.

@Override
public void trigger(Event baseEvent, int level) {
    EntityBreedEvent event = (EntityBreedEvent) baseEvent;
    Entity animal = event.getEntity();
    int max_number = 100;
    int min_number = 1;
    Random random_chance = new Random();
    int find_nearest_int = min_number + random_chance.nextInt(max_number);
    if (level >= 60) {
        animal.getWorld().spawnEntity(animal.getLocation(), animal.getType());
    } else if (level >= 40 && find_nearest_int <= 40) {
        animal.getWorld().spawnEntity(animal.getLocation(), animal.getType());
    } else if (find_nearest_int <= 10) {
        animal.getWorld().spawnEntity(animal.getLocation(), animal.getType());
    }
}
Also used : EntityBreedEvent(org.bukkit.event.entity.EntityBreedEvent) Entity(org.bukkit.entity.Entity) Random(java.util.Random)

Example 2 with EntityBreedEvent

use of org.bukkit.event.entity.EntityBreedEvent in project Arclight by IzzelAliz.

the class FoxEntity_MateGoalMixin method spawnBaby.

/**
 * @author IzzekAkuz
 * @reason
 */
@Overwrite
protected void spawnBaby() {
    FoxEntity foxentity = (FoxEntity) this.animal.createChild(this.targetMate);
    if (foxentity != null) {
        ServerPlayerEntity serverplayerentity = this.animal.getLoveCause();
        ServerPlayerEntity serverplayerentity1 = this.targetMate.getLoveCause();
        ServerPlayerEntity serverplayerentity2 = serverplayerentity;
        if (serverplayerentity != null) {
            ((FoxEntityBridge) foxentity).bridge$addTrustedUUID(serverplayerentity.getUniqueID());
        } else {
            serverplayerentity2 = serverplayerentity1;
        }
        if (serverplayerentity1 != null && serverplayerentity != serverplayerentity1) {
            ((FoxEntityBridge) foxentity).bridge$addTrustedUUID(serverplayerentity1.getUniqueID());
        }
        int experience = this.animal.getRNG().nextInt(7) + 1;
        final EntityBreedEvent entityBreedEvent = CraftEventFactory.callEntityBreedEvent(foxentity, this.animal, this.targetMate, serverplayerentity, ((AnimalEntityBridge) this.animal).bridge$getBreedItem(), experience);
        if (entityBreedEvent.isCancelled()) {
            return;
        }
        experience = entityBreedEvent.getExperience();
        if (serverplayerentity2 != null) {
            serverplayerentity2.addStat(Stats.ANIMALS_BRED);
            CriteriaTriggers.BRED_ANIMALS.trigger(serverplayerentity2, this.animal, this.targetMate, foxentity);
        }
        int i = 6000;
        this.animal.setGrowingAge(6000);
        this.targetMate.setGrowingAge(6000);
        this.animal.resetInLove();
        this.targetMate.resetInLove();
        foxentity.setGrowingAge(-24000);
        foxentity.setLocationAndAngles(this.animal.posX, this.animal.posY, this.animal.posZ, 0.0F, 0.0F);
        ((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.BREEDING);
        this.world.addEntity(foxentity);
        this.world.setEntityState(this.animal, (byte) 18);
        if (this.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) {
            if (experience > 0) {
                this.world.addEntity(new ExperienceOrbEntity(this.world, this.animal.posX, this.animal.posY, this.animal.posZ, experience));
            }
        }
    }
}
Also used : EntityBreedEvent(org.bukkit.event.entity.EntityBreedEvent) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) FoxEntity(net.minecraft.entity.passive.FoxEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) FoxEntityBridge(io.izzel.arclight.common.bridge.entity.passive.FoxEntityBridge) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 3 with EntityBreedEvent

use of org.bukkit.event.entity.EntityBreedEvent in project Arclight by IzzelAliz.

the class BreedGoalMixin method arclight$persist.

@Inject(method = "spawnBaby", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/entity/passive/AnimalEntity;getLoveCause()Lnet/minecraft/entity/player/ServerPlayerEntity;"))
public void arclight$persist(CallbackInfo ci, AgeableEntity ageableEntity) {
    if (ageableEntity instanceof TameableEntity && ((TameableEntity) ageableEntity).isTamed()) {
        ((LivingEntityBridge) ageableEntity).bridge$setPersist(true);
    }
    ServerPlayerEntity playerEntity = this.animal.getLoveCause();
    if (playerEntity == null && this.targetMate.getLoveCause() != null) {
        playerEntity = this.targetMate.getLoveCause();
    }
    arclight$exp = this.animal.getRNG().nextInt(7) + 1;
    EntityBreedEvent event = CraftEventFactory.callEntityBreedEvent(ageableEntity, this.animal, this.targetMate, playerEntity, ((AnimalEntityBridge) this.animal).bridge$getBreedItem(), arclight$exp);
    if (event.isCancelled()) {
        ci.cancel();
        return;
    }
    arclight$exp = event.getExperience();
}
Also used : EntityBreedEvent(org.bukkit.event.entity.EntityBreedEvent) TameableEntity(net.minecraft.entity.passive.TameableEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) LivingEntityBridge(io.izzel.arclight.common.bridge.entity.LivingEntityBridge) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

EntityBreedEvent (org.bukkit.event.entity.EntityBreedEvent)3 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 LivingEntityBridge (io.izzel.arclight.common.bridge.entity.LivingEntityBridge)1 FoxEntityBridge (io.izzel.arclight.common.bridge.entity.passive.FoxEntityBridge)1 WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)1 Random (java.util.Random)1 ExperienceOrbEntity (net.minecraft.entity.item.ExperienceOrbEntity)1 FoxEntity (net.minecraft.entity.passive.FoxEntity)1 TameableEntity (net.minecraft.entity.passive.TameableEntity)1 Entity (org.bukkit.entity.Entity)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1