Search in sources :

Example 1 with LeashKnotEntity

use of net.minecraft.entity.item.LeashKnotEntity in project Arclight by IzzelAliz.

the class LeadItemMixin_1_14 method attachToFence.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public static boolean attachToFence(PlayerEntity player, World worldIn, BlockPos fence) {
    LeashKnotEntity leashknotentity = null;
    boolean flag = false;
    double d0 = 7.0D;
    int i = fence.getX();
    int j = fence.getY();
    int k = fence.getZ();
    for (MobEntity mobentity : worldIn.getEntitiesWithinAABB(MobEntity.class, new AxisAlignedBB((double) i - 7.0D, (double) j - 7.0D, (double) k - 7.0D, (double) i + 7.0D, (double) j + 7.0D, (double) k + 7.0D))) {
        if (mobentity.getLeashHolder() == player) {
            if (leashknotentity == null) {
                leashknotentity = LeashKnotEntity.create(worldIn, fence);
                HangingPlaceEvent event = new HangingPlaceEvent((Hanging) ((EntityBridge) leashknotentity).bridge$getBukkitEntity(), player != null ? (Player) ((PlayerEntityBridge) player).bridge$getBukkitEntity() : null, CraftBlock.at(worldIn, fence), BlockFace.SELF);
                Bukkit.getPluginManager().callEvent(event);
                if (event.isCancelled()) {
                    leashknotentity.remove();
                    return false;
                }
            }
            if (CraftEventFactory.callPlayerLeashEntityEvent(mobentity, leashknotentity, player).isCancelled()) {
                continue;
            }
            mobentity.setLeashHolder(leashknotentity, true);
            flag = true;
        }
    }
    return flag;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Player(org.bukkit.entity.Player) HangingPlaceEvent(org.bukkit.event.hanging.HangingPlaceEvent) LeashKnotEntity(net.minecraft.entity.item.LeashKnotEntity) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) MobEntity(net.minecraft.entity.MobEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with LeashKnotEntity

use of net.minecraft.entity.item.LeashKnotEntity in project Arclight by IzzelAliz.

the class LeashKnotEntityMixin method processInitialInteract.

/**
 * @author IzzelAliz
 * @reason
 */
@SuppressWarnings("ConstantConditions")
@Overwrite
public boolean processInitialInteract(final PlayerEntity entityhuman, final Hand enumhand) {
    if (this.world.isRemote) {
        return true;
    }
    boolean flag = false;
    final double d0 = 7.0;
    final List<MobEntity> list = this.world.getEntitiesWithinAABB((Class<? extends MobEntity>) MobEntity.class, new AxisAlignedBB(this.posX - 7.0, this.posY - 7.0, this.posZ - 7.0, this.posX + 7.0, this.posY + 7.0, this.posZ + 7.0));
    for (final MobEntity entityinsentient : list) {
        if (entityinsentient.getLeashHolder() == entityhuman) {
            if (CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, (LeashKnotEntity) (Object) this, entityhuman).isCancelled()) {
                ((ServerPlayerEntity) entityhuman).connection.sendPacket(new SMountEntityPacket(entityinsentient, entityinsentient.getLeashHolder()));
            } else {
                entityinsentient.setLeashHolder((LeashKnotEntity) (Object) this, true);
                flag = true;
            }
        }
    }
    if (!flag) {
        boolean die = true;
        for (final MobEntity entityinsentient : list) {
            if (entityinsentient.getLeashed() && entityinsentient.getLeashHolder() == (Object) this) {
                if (CraftEventFactory.callPlayerUnleashEntityEvent(entityinsentient, entityhuman).isCancelled()) {
                    die = false;
                } else {
                    entityinsentient.clearLeashed(true, !entityhuman.abilities.isCreativeMode);
                }
            }
        }
        if (die) {
            this.remove();
        }
    }
    return true;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) SMountEntityPacket(net.minecraft.network.play.server.SMountEntityPacket) LeashKnotEntity(net.minecraft.entity.item.LeashKnotEntity) MobEntity(net.minecraft.entity.MobEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 3 with LeashKnotEntity

use of net.minecraft.entity.item.LeashKnotEntity in project Arclight by IzzelAliz.

the class LeadItemMixin_1_15 method bindPlayerMobs.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public static ActionResultType bindPlayerMobs(PlayerEntity player, World worldIn, BlockPos fence) {
    LeashKnotEntity leashknotentity = null;
    boolean flag = false;
    double d0 = 7.0D;
    int i = fence.getX();
    int j = fence.getY();
    int k = fence.getZ();
    for (MobEntity mobentity : worldIn.getEntitiesWithinAABB(MobEntity.class, new AxisAlignedBB((double) i - 7.0D, (double) j - 7.0D, (double) k - 7.0D, (double) i + 7.0D, (double) j + 7.0D, (double) k + 7.0D))) {
        if (mobentity.getLeashHolder() == player) {
            if (leashknotentity == null) {
                leashknotentity = LeashKnotEntity.create(worldIn, fence);
                HangingPlaceEvent event = new HangingPlaceEvent((Hanging) ((EntityBridge) leashknotentity).bridge$getBukkitEntity(), player != null ? (Player) ((PlayerEntityBridge) player).bridge$getBukkitEntity() : null, CraftBlock.at(worldIn, fence), BlockFace.SELF);
                Bukkit.getPluginManager().callEvent(event);
                if (event.isCancelled()) {
                    leashknotentity.remove();
                    return ActionResultType.PASS;
                }
            }
            if (CraftEventFactory.callPlayerLeashEntityEvent(mobentity, leashknotentity, player).isCancelled()) {
                continue;
            }
            mobentity.setLeashHolder(leashknotentity, true);
            flag = true;
        }
    }
    return flag ? ActionResultType.SUCCESS : ActionResultType.PASS;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Player(org.bukkit.entity.Player) HangingPlaceEvent(org.bukkit.event.hanging.HangingPlaceEvent) LeashKnotEntity(net.minecraft.entity.item.LeashKnotEntity) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) MobEntity(net.minecraft.entity.MobEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

MobEntity (net.minecraft.entity.MobEntity)3 LeashKnotEntity (net.minecraft.entity.item.LeashKnotEntity)3 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)3 Overwrite (org.spongepowered.asm.mixin.Overwrite)3 EntityBridge (io.izzel.arclight.common.bridge.entity.EntityBridge)2 PlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge)2 Player (org.bukkit.entity.Player)2 HangingPlaceEvent (org.bukkit.event.hanging.HangingPlaceEvent)2 SMountEntityPacket (net.minecraft.network.play.server.SMountEntityPacket)1