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));
}
}
}
}
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;
}
}
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
}
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();
}
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()));
}
}
}
}
Aggregations