Search in sources :

Example 1 with HorseLike

use of org.spongepowered.api.entity.living.animal.horse.HorseLike in project SpongeCommon by SpongePowered.

the class RunAroundLikeCrazyGoalMixin method tick.

// @formatter:on
/**
 * @author rexbut - December 16th, 2016
 * @author i509VCB - February 18th, 2020 - 1.14.4
 *
 * @reason - adjusted to support {@link DismountTypes}
 */
@Overwrite
public void tick() {
    if (!this.horse.isTamed() && this.horse.getRandom().nextInt(50) == 0) {
        Entity entity = this.horse.getPassengers().get(0);
        if (entity == null) {
            return;
        }
        if (entity instanceof Player) {
            int i = this.horse.getTemper();
            int j = this.horse.getMaxTemper();
            if (j > 0 && this.horse.getRandom().nextInt(j) < i) {
                // Sponge start - Fire Tame Entity event
                try (CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
                    frame.pushCause(entity);
                    if (SpongeCommon.post(SpongeEventFactory.createTameEntityEvent(frame.currentCause(), (HorseLike) this.horse))) {
                        return;
                    }
                }
                // Sponge end
                this.horse.tameWithName((Player) entity);
                return;
            }
            this.horse.modifyTemper(5);
        }
        // this.horseHost.ejectPassengers(); // Vanilla
        if (((EntityBridge) this.horse).bridge$removePassengers(DismountTypes.DERAIL.get())) {
            // Sponge end
            this.horse.makeMad();
            this.horse.level.broadcastEntityEvent(this.horse, (byte) 6);
        }
    }
}
Also used : Entity(net.minecraft.world.entity.Entity) Player(net.minecraft.world.entity.player.Player) CauseStackManager(org.spongepowered.api.event.CauseStackManager) HorseLike(org.spongepowered.api.entity.living.animal.horse.HorseLike) EntityBridge(org.spongepowered.common.bridge.world.entity.EntityBridge) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

Entity (net.minecraft.world.entity.Entity)1 Player (net.minecraft.world.entity.player.Player)1 HorseLike (org.spongepowered.api.entity.living.animal.horse.HorseLike)1 CauseStackManager (org.spongepowered.api.event.CauseStackManager)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 EntityBridge (org.spongepowered.common.bridge.world.entity.EntityBridge)1