Search in sources :

Example 6 with TameableEntity

use of net.minecraft.entity.passive.TameableEntity in project meteor-client by MeteorDevelopment.

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(meteordevelopment.meteorclient.mixin.ProjectileEntityAccessor) EventHandler(meteordevelopment.orbit.EventHandler)

Example 7 with TameableEntity

use of net.minecraft.entity.passive.TameableEntity in project Arclight by IzzelAliz.

the class LivingEntityMixin method attackEntityFrom.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public boolean attackEntityFrom(DamageSource source, float amount) {
    if (!ForgeHooks.onLivingAttack((LivingEntity) (Object) this, source, amount))
        return false;
    if (this.isInvulnerableTo(source)) {
        return false;
    } else if (this.world.isRemote) {
        return false;
    } else if (this.dead || this.removed || this.getHealth() <= 0.0F) {
        return false;
    } else if (source.isFireDamage() && this.isPotionActive(Effects.FIRE_RESISTANCE)) {
        return false;
    } else {
        if (this.isSleeping() && !this.world.isRemote) {
            this.wakeUp();
        }
        this.idleTime = 0;
        float f = amount;
        if (false && (source == DamageSource.ANVIL || source == DamageSource.FALLING_BLOCK) && !this.getItemStackFromSlot(EquipmentSlotType.HEAD).isEmpty()) {
            this.getItemStackFromSlot(EquipmentSlotType.HEAD).damageItem((int) (amount * 4.0F + this.rand.nextFloat() * amount * 2.0F), (LivingEntity) (Object) this, (p_213341_0_) -> {
                p_213341_0_.sendBreakAnimation(EquipmentSlotType.HEAD);
            });
            amount *= 0.75F;
        }
        boolean flag = false;
        float f1 = 0.0F;
        if (false && amount > 0.0F && this.canBlockDamageSource(source)) {
            this.damageShield(amount);
            f1 = amount;
            amount = 0.0F;
            if (!source.isProjectile()) {
                Entity entity = source.getImmediateSource();
                if (entity instanceof LivingEntity) {
                    this.blockUsingShield((LivingEntity) entity);
                }
            }
            flag = true;
        }
        this.limbSwingAmount = 1.5F;
        boolean flag1 = true;
        if ((float) this.hurtResistantTime > 10.0F) {
            if (amount <= this.lastDamage) {
                this.forceExplosionKnockback = true;
                return false;
            }
            if (!this.damageEntity0(source, amount - this.lastDamage)) {
                return false;
            }
            this.lastDamage = amount;
            flag1 = false;
        } else {
            if (!this.damageEntity0(source, amount)) {
                return false;
            }
            this.lastDamage = amount;
            this.hurtResistantTime = 20;
            this.maxHurtTime = 10;
            this.hurtTime = this.maxHurtTime;
        }
        if ((Object) this instanceof AnimalEntity) {
            ((AnimalEntity) (Object) this).resetInLove();
            if ((Object) this instanceof TameableEntity) {
                ((TameableEntity) (Object) this).getAISit().setSitting(false);
            }
        }
        this.attackedAtYaw = 0.0F;
        Entity entity1 = source.getTrueSource();
        if (entity1 != null) {
            if (entity1 instanceof LivingEntity) {
                this.setRevengeTarget((LivingEntity) entity1);
            }
            if (entity1 instanceof PlayerEntity) {
                this.recentlyHit = 100;
                this.attackingPlayer = (PlayerEntity) entity1;
            } else if (entity1 instanceof TameableEntity) {
                TameableEntity wolfentity = (TameableEntity) entity1;
                if (wolfentity.isTamed()) {
                    this.recentlyHit = 100;
                    LivingEntity livingentity = wolfentity.getOwner();
                    if (livingentity != null && livingentity.getType() == EntityType.PLAYER) {
                        this.attackingPlayer = (PlayerEntity) livingentity;
                    } else {
                        this.attackingPlayer = null;
                    }
                }
            }
        }
        if (flag1) {
            if (flag) {
                this.world.setEntityState((LivingEntity) (Object) this, (byte) 29);
            } else if (source instanceof EntityDamageSource && ((EntityDamageSource) source).getIsThornsDamage()) {
                this.world.setEntityState((LivingEntity) (Object) this, (byte) 33);
            } else {
                byte b0;
                if (source == DamageSource.DROWN) {
                    b0 = 36;
                } else if (source.isFireDamage()) {
                    b0 = 37;
                } else if (source == DamageSource.SWEET_BERRY_BUSH) {
                    b0 = 44;
                } else {
                    b0 = 2;
                }
                this.world.setEntityState((LivingEntity) (Object) this, b0);
            }
            if (source != DamageSource.DROWN && (!flag || amount > 0.0F)) {
                this.markVelocityChanged();
            }
            if (entity1 != null) {
                double d1 = entity1.posX - this.posX;
                double d0;
                for (d0 = entity1.posZ - this.posZ; d1 * d1 + d0 * d0 < 1.0E-4D; d0 = (Math.random() - Math.random()) * 0.01D) {
                    d1 = (Math.random() - Math.random()) * 0.01D;
                }
                this.attackedAtYaw = (float) (MathHelper.atan2(d0, d1) * (double) (180F / (float) Math.PI) - (double) this.rotationYaw);
                this.knockBack(entity1, 0.4F, d1, d0);
            } else {
                this.attackedAtYaw = (float) ((int) (Math.random() * 2.0D) * 180);
            }
        }
        if (this.getHealth() <= 0.0F) {
            if (!this.checkTotemDeathProtection(source)) {
                SoundEvent soundevent = this.getDeathSound();
                if (flag1 && soundevent != null) {
                    this.playSound(soundevent, this.getSoundVolume(), this.getSoundPitch());
                }
                this.onDeath(source);
            }
        } else if (flag1) {
            this.playHurtSound(source);
        }
        boolean flag2 = !flag || amount > 0.0F;
        if (flag2) {
            this.lastDamageSource = source;
            this.lastDamageStamp = this.world.getGameTime();
        }
        if ((Object) this instanceof ServerPlayerEntity) {
            CriteriaTriggers.ENTITY_HURT_PLAYER.trigger((ServerPlayerEntity) (Object) this, source, f, amount, flag);
            if (f1 > 0.0F && f1 < 3.4028235E37F) {
                ((ServerPlayerEntity) (Object) this).addStat(Stats.DAMAGE_BLOCKED_BY_SHIELD, Math.round(f1 * 10.0F));
            }
        }
        if (entity1 instanceof ServerPlayerEntity) {
            CriteriaTriggers.PLAYER_HURT_ENTITY.trigger((ServerPlayerEntity) entity1, (LivingEntity) (Object) this, source, f, amount, flag);
        }
        return flag2;
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v.entity.CraftLivingEntity) EntityType(net.minecraft.entity.EntityType) GameRules(net.minecraft.world.GameRules) CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) Inject(org.spongepowered.asm.mixin.injection.Inject) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) CompoundNBT(net.minecraft.nbt.CompoundNBT) Random(java.util.Random) Player(org.bukkit.entity.Player) FloatNBT(net.minecraft.nbt.FloatNBT) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) Location(org.bukkit.Location) CriteriaTriggers(net.minecraft.advancements.CriteriaTriggers) Mixin(org.spongepowered.asm.mixin.Mixin) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) CraftEventFactory(org.bukkit.craftbukkit.v.event.CraftEventFactory) Bukkit(org.bukkit.Bukkit) At(org.spongepowered.asm.mixin.injection.At) Function(com.google.common.base.Function) AbstractAttributeMap(net.minecraft.entity.ai.attributes.AbstractAttributeMap) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) Collection(java.util.Collection) CraftPlayer(org.bukkit.craftbukkit.v.entity.CraftPlayer) DataParameter(net.minecraft.network.datasync.DataParameter) Final(org.spongepowered.asm.mixin.Final) EntityResurrectEvent(org.bukkit.event.entity.EntityResurrectEvent) IntNBT(net.minecraft.nbt.IntNBT) CraftLivingEntity(org.bukkit.craftbukkit.v.entity.CraftLivingEntity) Shadow(org.spongepowered.asm.mixin.Shadow) Optional(java.util.Optional) TameableEntity(net.minecraft.entity.passive.TameableEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ForgeHooks(net.minecraftforge.common.ForgeHooks) ForgeEventFactory(net.minecraftforge.event.ForgeEventFactory) PlayerItemConsumeEvent(org.bukkit.event.player.PlayerItemConsumeEvent) LivingEntityBridge(io.izzel.arclight.common.bridge.entity.LivingEntityBridge) Overwrite(org.spongepowered.asm.mixin.Overwrite) Effect(net.minecraft.potion.Effect) ItemStack(net.minecraft.item.ItemStack) EffectInstance(net.minecraft.potion.EffectInstance) Stats(net.minecraft.stats.Stats) Hand(net.minecraft.util.Hand) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) IAttribute(net.minecraft.entity.ai.attributes.IAttribute) LocalCapture(org.spongepowered.asm.mixin.injection.callback.LocalCapture) INBT(net.minecraft.nbt.INBT) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Nullable(javax.annotation.Nullable) Entity(net.minecraft.entity.Entity) Effects(net.minecraft.potion.Effects) World(net.minecraft.world.World) Redirect(org.spongepowered.asm.mixin.injection.Redirect) EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent) EntityRegainHealthEvent(org.bukkit.event.entity.EntityRegainHealthEvent) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) CraftAttributeMap(org.bukkit.craftbukkit.v.attribute.CraftAttributeMap) EntityPotionEffectEvent(org.bukkit.event.entity.EntityPotionEffectEvent) DamageSource(net.minecraft.util.DamageSource) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) SharedMonsterAttributes(net.minecraft.entity.SharedMonsterAttributes) CombatTracker(net.minecraft.util.CombatTracker) EquipmentSlotType(net.minecraft.inventory.EquipmentSlotType) MathHelper(net.minecraft.util.math.MathHelper) EntityDamageSource(net.minecraft.util.EntityDamageSource) ItemEntity(net.minecraft.entity.item.ItemEntity) SoundEvent(net.minecraft.util.SoundEvent) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v.entity.CraftLivingEntity) TameableEntity(net.minecraft.entity.passive.TameableEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) Entity(net.minecraft.entity.Entity) ItemEntity(net.minecraft.entity.item.ItemEntity) SoundEvent(net.minecraft.util.SoundEvent) TameableEntity(net.minecraft.entity.passive.TameableEntity) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) EntityDamageSource(net.minecraft.util.EntityDamageSource) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 8 with TameableEntity

use of net.minecraft.entity.passive.TameableEntity in project Arclight by IzzelAliz.

the class EntityMixin method arclight$read$ReadBukkitValues.

@Inject(method = "read", at = @At(value = "RETURN"))
public void arclight$read$ReadBukkitValues(CompoundNBT compound, CallbackInfo ci) {
    // CraftBukkit start
    if ((Object) this instanceof LivingEntity) {
        LivingEntity entity = (LivingEntity) (Object) this;
        this.ticksExisted = compound.getInt("Spigot.ticksLived");
        // Reset the persistence for tamed animals
        if (entity instanceof TameableEntity && !isLevelAtLeast(compound, 2) && !compound.getBoolean("PersistenceRequired")) {
            MobEntity entityInsentient = (MobEntity) entity;
            ((MobEntityBridge) entityInsentient).bridge$setPersistenceRequired(!entityInsentient.canDespawn(0));
        }
    }
    // CraftBukkit start - Reset world
    if ((Object) this instanceof ServerPlayerEntity) {
        Server server = Bukkit.getServer();
        org.bukkit.World bworld = null;
        String worldName = compound.getString("world");
        if (compound.contains("WorldUUIDMost") && compound.contains("WorldUUIDLeast")) {
            UUID uid = new UUID(compound.getLong("WorldUUIDMost"), compound.getLong("WorldUUIDLeast"));
            bworld = server.getWorld(uid);
        } else {
            bworld = server.getWorld(worldName);
        }
        if (bworld == null) {
            bworld = ((WorldBridge) ((CraftServer) server).getServer().getWorld(DimensionType.OVERWORLD)).bridge$getWorld();
        }
        setWorld(bworld == null ? null : ((CraftWorld) bworld).getHandle());
    }
    this.getBukkitEntity().readBukkitValues(compound);
// CraftBukkit end
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) MinecraftServer(net.minecraft.server.MinecraftServer) Server(org.bukkit.Server) CraftServer(org.bukkit.craftbukkit.v.CraftServer) TameableEntity(net.minecraft.entity.passive.TameableEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) UUID(java.util.UUID) CraftWorld(org.bukkit.craftbukkit.v.CraftWorld) MobEntity(net.minecraft.entity.MobEntity) MobEntityBridge(io.izzel.arclight.common.bridge.entity.MobEntityBridge) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 9 with TameableEntity

use of net.minecraft.entity.passive.TameableEntity 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)

Example 10 with TameableEntity

use of net.minecraft.entity.passive.TameableEntity in project meteor-rejects by AntiCope.

the class CoordLogger method onPacketReceive.

@EventHandler
private void onPacketReceive(PacketEvent.Receive event) {
    // Teleports
    if (event.packet instanceof EntityPositionS2CPacket) {
        EntityPositionS2CPacket packet = (EntityPositionS2CPacket) event.packet;
        try {
            Entity entity = mc.world.getEntityById(packet.getId());
            // Player teleport
            if (entity.getType().equals(EntityType.PLAYER) && players.get()) {
                Vec3d packetPosition = new Vec3d(packet.getX(), packet.getY(), packet.getZ());
                Vec3d playerPosition = entity.getPos();
                if (playerPosition.distanceTo(packetPosition) >= minDistance.get()) {
                    info(formatMessage("Player '" + entity.getEntityName() + "' has teleported to ", packetPosition));
                }
            } else // World teleport
            if (entity.getType().equals(EntityType.WOLF) && wolves.get()) {
                Vec3d packetPosition = new Vec3d(packet.getX(), packet.getY(), packet.getZ());
                Vec3d wolfPosition = entity.getPos();
                UUID ownerUuid = ((TameableEntity) entity).getOwnerUuid();
                if (ownerUuid != null && wolfPosition.distanceTo(packetPosition) >= minDistance.get()) {
                    info(formatMessage("Wolf has teleported to ", packetPosition));
                }
            }
        } catch (NullPointerException ignored) {
        }
    // World events
    } else if (event.packet instanceof WorldEventS2CPacket) {
        WorldEventS2CPacket worldEventS2CPacket = (WorldEventS2CPacket) event.packet;
        if (worldEventS2CPacket.isGlobal()) {
            // Min distance
            if (PlayerUtils.distanceTo(worldEventS2CPacket.getPos()) <= minDistance.get())
                return;
            switch(worldEventS2CPacket.getEventId()) {
                case 1023:
                    if (withers.get())
                        info(formatMessage("Wither spawned at ", worldEventS2CPacket.getPos()));
                    break;
                case 1038:
                    if (endPortals.get())
                        info(formatMessage("End portal opened at ", worldEventS2CPacket.getPos()));
                    break;
                case 1028:
                    if (enderDragons.get())
                        info(formatMessage("Ender dragon killed at ", worldEventS2CPacket.getPos()));
                    break;
                default:
                    if (otherEvents.get())
                        info(formatMessage("Unknown global event at ", worldEventS2CPacket.getPos()));
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) TameableEntity(net.minecraft.entity.passive.TameableEntity) EntityPositionS2CPacket(net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket) WorldEventS2CPacket(net.minecraft.network.packet.s2c.play.WorldEventS2CPacket) UUID(java.util.UUID) Vec3d(net.minecraft.util.math.Vec3d) EventHandler(meteordevelopment.orbit.EventHandler)

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