Search in sources :

Example 1 with TameableEntity

use of net.minecraft.entity.passive.TameableEntity in project ChocolateQuestRepoured by TeamChocoQuest.

the class EntityAITameAndLeashPet method canUse.

@Override
public boolean canUse() {
    if (!this.entity.canTameEntity()) {
        return false;
    }
    if ((!(this.entity.getHeldItemMainhand().getItem() instanceof LeadItem) && !(this.entity.getMainHandItem().getItem() instanceof LeadItem))) {
        return false;
    }
    if (this.random.nextInt(10) == 0) {
        Vector3d vec1 = this.entity.position().add(PET_SEARCH_RADIUS, PET_SEARCH_RADIUS * 0.5D, PET_SEARCH_RADIUS);
        Vector3d vec2 = this.entity.position().subtract(PET_SEARCH_RADIUS, PET_SEARCH_RADIUS * 0.5D, PET_SEARCH_RADIUS);
        AxisAlignedBB aabb = new AxisAlignedBB(vec1.x, vec1.y, vec1.z, vec2.x, vec2.y, vec2.z);
        List<TameableEntity> possiblePets = this.entity.world.getEntitiesWithinAABB(TameableEntity.class, aabb, input -> TargetUtil.PREDICATE_PETS.apply(input) && this.entity.getSensing().canSee(input));
        if (!possiblePets.isEmpty()) {
            this.entityToTame = TargetUtil.getNearestEntity(this.entity, possiblePets);
            return true;
        }
    }
    return false;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Vector3d(net.minecraft.util.math.vector.Vector3d) TameableEntity(net.minecraft.entity.passive.TameableEntity) LeadItem(net.minecraft.item.LeadItem)

Example 2 with TameableEntity

use of net.minecraft.entity.passive.TameableEntity in project ChocolateQuestRepoured by TeamChocoQuest.

the class AbstractEntityCQR method spawnShoulderEntity.

private void spawnShoulderEntity(@Nullable CompoundNBT compound) {
    if (!this.level.isClientSide && compound != null && !compound.isEmpty()) {
        Entity entity = EntityList.createEntityFromNBT(compound, this.level);
        if (entity instanceof TameableEntity) {
            ((TameableEntity) entity).setOwnerUUID(this.getUUID());
        }
        final Vector3d pos = this.position().add(0, 0.699999988079071D, 0);
        entity.setPos(pos.x, pos.y, pos.z);
        this.level.addFreshEntity(entity);
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) TameableEntity(net.minecraft.entity.passive.TameableEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CreatureEntity(net.minecraft.entity.CreatureEntity) Entity(net.minecraft.entity.Entity) TameableEntity(net.minecraft.entity.passive.TameableEntity) Vector3d(net.minecraft.util.math.vector.Vector3d)

Example 3 with TameableEntity

use of net.minecraft.entity.passive.TameableEntity in project ChaosAwakens by ChaosAwakens.

the class UltimateArrowEntity method onHitEntity.

@Override
protected void onHitEntity(EntityRayTraceResult result) {
    Entity entity = result.getEntity();
    if (entity instanceof PlayerEntity || (entity instanceof TameableEntity && ((TameableEntity) entity).isTame() && ((TameableEntity) entity).getOwner() == this.getOwner())) {
        ((LivingEntity) entity).heal(5.0F);
        remove();
        return;
    }
    super.onHitEntity(result);
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) Entity(net.minecraft.entity.Entity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) TameableEntity(net.minecraft.entity.passive.TameableEntity) TameableEntity(net.minecraft.entity.passive.TameableEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 4 with TameableEntity

use of net.minecraft.entity.passive.TameableEntity in project Client by MatHax.

the class EntityOwner method onRender2D.

@EventHandler
private void onRender2D(Render2DEvent event) {
    for (Entity entity : mc.world.getEntities()) {
        UUID ownerUuid;
        if (entity instanceof TameableEntity)
            ownerUuid = ((TameableEntity) entity).getOwnerUuid();
        else if (entity instanceof HorseBaseEntity)
            ownerUuid = ((HorseBaseEntity) entity).getOwnerUuid();
        else if (entity instanceof ProjectileEntity && projectiles.get())
            ownerUuid = ((ProjectileEntityAccessor) entity).getOwnerUuid();
        else
            continue;
        if (ownerUuid != null) {
            pos.set(entity, event.tickDelta);
            pos.add(0, entity.getEyeHeight(entity.getPose()) + 0.75, 0);
            if (NametagUtils.to2D(pos, scale.get())) {
                renderNametag(getOwnerName(ownerUuid));
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) HorseBaseEntity(net.minecraft.entity.passive.HorseBaseEntity) TameableEntity(net.minecraft.entity.passive.TameableEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) TameableEntity(net.minecraft.entity.passive.TameableEntity) UUID(java.util.UUID) HorseBaseEntity(net.minecraft.entity.passive.HorseBaseEntity) ProjectileEntityAccessor(mathax.client.mixin.ProjectileEntityAccessor) EventHandler(mathax.client.eventbus.EventHandler)

Example 5 with TameableEntity

use of net.minecraft.entity.passive.TameableEntity in project LittleMaidReBirth-Fabric by SistrScarlet.

the class SyncIFFPacket method applyIFFServer.

private static void applyIFFServer(int id, CompoundTag tag, PlayerEntity player) {
    Entity entity = player.world.getEntityById(id);
    if (!(entity instanceof HasIFF)) {
        return;
    }
    if (entity instanceof TameableEntity && !player.getUuid().equals(((TameableEntity) entity).getOwnerUuid())) {
        return;
    }
    ListTag list = tag.getList("IFFs", 10);
    List<IFF> iffs = list.stream().map(t -> (CompoundTag) t).map(t -> IFFTypeManager.getINSTANCE().loadIFF(t)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
    ((HasIFF) entity).setIFFs(iffs);
}
Also used : Entity(net.minecraft.entity.Entity) PacketSender(net.fabricmc.fabric.api.networking.v1.PacketSender) ClientPlayNetworking(net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking) IFF(net.sistr.littlemaidrebirth.entity.iff.IFF) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Environment(net.fabricmc.api.Environment) PacketByteBuf(net.minecraft.network.PacketByteBuf) Collectors(java.util.stream.Collectors) Unpooled(io.netty.buffer.Unpooled) HasIFF(net.sistr.littlemaidrebirth.entity.iff.HasIFF) IFFTypeManager(net.sistr.littlemaidrebirth.entity.iff.IFFTypeManager) MinecraftServer(net.minecraft.server.MinecraftServer) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) LittleMaidReBirthMod(net.sistr.littlemaidrebirth.LittleMaidReBirthMod) EnvType(net.fabricmc.api.EnvType) Identifier(net.minecraft.util.Identifier) Optional(java.util.Optional) TameableEntity(net.minecraft.entity.passive.TameableEntity) ListTag(net.minecraft.nbt.ListTag) ServerPlayNetworkHandler(net.minecraft.server.network.ServerPlayNetworkHandler) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) TameableEntity(net.minecraft.entity.passive.TameableEntity) Optional(java.util.Optional) TameableEntity(net.minecraft.entity.passive.TameableEntity) HasIFF(net.sistr.littlemaidrebirth.entity.iff.HasIFF) IFF(net.sistr.littlemaidrebirth.entity.iff.IFF) HasIFF(net.sistr.littlemaidrebirth.entity.iff.HasIFF) ListTag(net.minecraft.nbt.ListTag)

Aggregations

TameableEntity (net.minecraft.entity.passive.TameableEntity)12 Entity (net.minecraft.entity.Entity)8 PlayerEntity (net.minecraft.entity.player.PlayerEntity)7 UUID (java.util.UUID)4 LivingEntity (net.minecraft.entity.LivingEntity)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)4 HorseBaseEntity (net.minecraft.entity.passive.HorseBaseEntity)3 Inject (org.spongepowered.asm.mixin.injection.Inject)3 LivingEntityBridge (io.izzel.arclight.common.bridge.entity.LivingEntityBridge)2 Optional (java.util.Optional)2 EventHandler (meteordevelopment.orbit.EventHandler)2 ProjectileEntity (net.minecraft.entity.projectile.ProjectileEntity)2 Vector3d (net.minecraft.util.math.vector.Vector3d)2 Function (com.google.common.base.Function)1 MobEntityBridge (io.izzel.arclight.common.bridge.entity.MobEntityBridge)1 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)1 WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)1 Unpooled (io.netty.buffer.Unpooled)1 Collection (java.util.Collection)1 List (java.util.List)1