2021-02-14 16:52:56 +01:00
|
|
|
package com.minelittlepony.unicopia.entity;
|
|
|
|
|
2022-12-25 23:21:34 +01:00
|
|
|
import java.util.*;
|
2021-02-14 17:46:41 +01:00
|
|
|
import java.util.stream.Stream;
|
2022-12-09 21:45:49 +01:00
|
|
|
import java.util.stream.StreamSupport;
|
2021-02-14 17:46:41 +01:00
|
|
|
|
2021-08-04 15:38:03 +02:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2021-02-14 16:52:56 +01:00
|
|
|
|
2022-10-12 10:40:36 +02:00
|
|
|
import com.minelittlepony.unicopia.USounds;
|
2023-06-02 21:20:30 +02:00
|
|
|
import com.minelittlepony.unicopia.UTags;
|
2021-12-29 16:18:26 +01:00
|
|
|
import com.minelittlepony.unicopia.Unicopia;
|
2022-12-25 23:21:34 +01:00
|
|
|
import com.minelittlepony.unicopia.ability.Abilities;
|
2024-02-21 23:46:10 +01:00
|
|
|
import com.minelittlepony.unicopia.ability.Ability;
|
2021-02-14 16:52:56 +01:00
|
|
|
import com.minelittlepony.unicopia.ability.magic.Caster;
|
2021-03-05 18:22:27 +01:00
|
|
|
import com.minelittlepony.unicopia.ability.magic.SpellContainer;
|
2021-12-22 15:43:06 +01:00
|
|
|
import com.minelittlepony.unicopia.ability.magic.SpellPredicate;
|
2023-08-06 19:56:31 +02:00
|
|
|
import com.minelittlepony.unicopia.ability.magic.spell.AbstractDisguiseSpell;
|
2021-11-05 14:18:32 +01:00
|
|
|
import com.minelittlepony.unicopia.ability.magic.spell.Situation;
|
2022-09-28 22:43:45 +02:00
|
|
|
import com.minelittlepony.unicopia.advancement.UCriteria;
|
2023-09-10 23:14:27 +02:00
|
|
|
import com.minelittlepony.unicopia.compat.trinkets.TrinketsDelegate;
|
2023-08-06 19:56:31 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.behaviour.EntityAppearance;
|
2024-02-13 19:47:01 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.behaviour.Guest;
|
2024-02-06 16:44:12 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.damage.MagicalDamageSource;
|
2023-04-29 23:32:00 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.duck.LivingEntityDuck;
|
2024-03-12 15:49:41 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.effect.CorruptInfluenceStatusEffect;
|
2023-09-03 16:51:05 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.effect.EffectUtils;
|
2022-12-04 16:25:03 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.effect.UEffects;
|
2022-12-25 23:21:34 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
2023-04-29 23:32:00 +02:00
|
|
|
import com.minelittlepony.unicopia.input.Heuristic;
|
|
|
|
import com.minelittlepony.unicopia.input.Interactable;
|
2022-09-25 22:32:38 +02:00
|
|
|
import com.minelittlepony.unicopia.item.GlassesItem;
|
2021-02-14 17:46:41 +01:00
|
|
|
import com.minelittlepony.unicopia.item.UItems;
|
2024-03-28 16:32:21 +01:00
|
|
|
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
|
2021-12-21 16:28:47 +01:00
|
|
|
import com.minelittlepony.unicopia.network.datasync.EffectSync;
|
2022-12-10 01:16:23 +01:00
|
|
|
import com.minelittlepony.unicopia.network.datasync.Transmittable;
|
2022-09-18 01:23:29 +02:00
|
|
|
import com.minelittlepony.unicopia.particle.ParticleUtils;
|
2021-03-06 10:58:44 +01:00
|
|
|
import com.minelittlepony.unicopia.projectile.ProjectileImpactListener;
|
2023-04-30 11:46:33 +02:00
|
|
|
import com.minelittlepony.unicopia.server.world.DragonBreathStore;
|
2022-12-25 23:21:34 +01:00
|
|
|
import com.minelittlepony.unicopia.util.*;
|
2021-02-14 16:52:56 +01:00
|
|
|
|
2023-07-06 18:27:03 +02:00
|
|
|
import it.unimi.dsi.fastutil.floats.Float2ObjectFunction;
|
2024-02-13 19:47:01 +01:00
|
|
|
import net.fabricmc.fabric.api.util.TriState;
|
2023-09-02 22:55:20 +02:00
|
|
|
import net.minecraft.block.BlockState;
|
2023-10-18 19:52:59 +02:00
|
|
|
import net.minecraft.enchantment.Enchantment;
|
|
|
|
import net.minecraft.enchantment.EnchantmentHelper;
|
2022-09-18 01:23:29 +02:00
|
|
|
import net.minecraft.entity.*;
|
2023-07-06 18:27:03 +02:00
|
|
|
import net.minecraft.entity.attribute.EntityAttribute;
|
|
|
|
import net.minecraft.entity.attribute.EntityAttributeInstance;
|
|
|
|
import net.minecraft.entity.attribute.EntityAttributeModifier;
|
2021-02-14 16:52:56 +01:00
|
|
|
import net.minecraft.entity.damage.DamageSource;
|
2024-02-13 19:47:01 +01:00
|
|
|
import net.minecraft.entity.damage.DamageTypes;
|
2022-12-25 19:36:43 +01:00
|
|
|
import net.minecraft.entity.data.*;
|
2024-03-12 15:49:41 +01:00
|
|
|
import net.minecraft.entity.mob.HostileEntity;
|
2022-09-18 01:23:29 +02:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2021-02-14 16:52:56 +01:00
|
|
|
import net.minecraft.entity.projectile.ProjectileEntity;
|
2023-09-02 22:55:20 +02:00
|
|
|
import net.minecraft.item.BlockItem;
|
2023-09-03 20:12:54 +02:00
|
|
|
import net.minecraft.item.Item;
|
2023-09-02 22:55:20 +02:00
|
|
|
import net.minecraft.item.ItemPlacementContext;
|
2021-02-14 17:46:41 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2021-08-04 15:38:03 +02:00
|
|
|
import net.minecraft.nbt.NbtCompound;
|
2022-10-03 23:44:30 +02:00
|
|
|
import net.minecraft.network.packet.s2c.play.EntityPassengersSetS2CPacket;
|
2022-09-18 01:23:29 +02:00
|
|
|
import net.minecraft.particle.ParticleTypes;
|
2023-06-02 21:20:30 +02:00
|
|
|
import net.minecraft.registry.tag.DamageTypeTags;
|
2022-10-03 23:44:30 +02:00
|
|
|
import net.minecraft.server.world.ServerWorld;
|
2023-09-02 22:55:20 +02:00
|
|
|
import net.minecraft.sound.BlockSoundGroup;
|
|
|
|
import net.minecraft.sound.SoundCategory;
|
2021-02-14 17:46:41 +01:00
|
|
|
import net.minecraft.util.Hand;
|
2023-09-02 22:55:20 +02:00
|
|
|
import net.minecraft.util.hit.BlockHitResult;
|
2022-09-18 01:23:29 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2023-09-02 22:55:20 +02:00
|
|
|
import net.minecraft.util.math.Direction;
|
2023-07-06 18:27:03 +02:00
|
|
|
import net.minecraft.util.math.MathHelper;
|
2022-09-18 01:23:29 +02:00
|
|
|
import net.minecraft.util.math.Vec3d;
|
2021-02-14 16:52:56 +01:00
|
|
|
|
2022-12-10 01:16:23 +01:00
|
|
|
public abstract class Living<T extends LivingEntity> implements Equine<T>, Caster<T>, Transmittable {
|
2022-12-25 19:36:43 +01:00
|
|
|
private static final TrackedData<Optional<UUID>> CARRIER_ID = DataTracker.registerData(LivingEntity.class, TrackedDataHandlerRegistry.OPTIONAL_UUID);
|
2021-02-14 16:52:56 +01:00
|
|
|
|
|
|
|
protected final T entity;
|
|
|
|
|
|
|
|
private final EffectSync effectDelegate;
|
|
|
|
|
2023-04-29 23:32:00 +02:00
|
|
|
private final Interactable sneakingHeuristic;
|
|
|
|
private final Interactable landedHeuristic;
|
|
|
|
private final Interactable jumpingHeuristic;
|
2021-02-14 16:52:56 +01:00
|
|
|
|
2022-12-25 16:01:12 +01:00
|
|
|
private boolean invisible = false;
|
|
|
|
|
2021-03-06 13:27:52 +01:00
|
|
|
@Nullable
|
2022-12-19 23:23:08 +01:00
|
|
|
private Caster<?> attacker;
|
2024-02-13 19:47:01 +01:00
|
|
|
@Nullable
|
|
|
|
private transient Caster<?> host;
|
2021-03-06 13:27:52 +01:00
|
|
|
|
2023-03-05 02:28:43 +01:00
|
|
|
private Optional<Living<?>> target = Optional.empty();
|
|
|
|
|
2021-02-14 17:46:41 +01:00
|
|
|
private int invinsibilityTicks;
|
|
|
|
|
2022-12-25 23:21:34 +01:00
|
|
|
private final List<Tickable> tickers = new ArrayList<>();
|
2021-02-16 12:39:39 +01:00
|
|
|
|
2024-05-17 20:28:08 +02:00
|
|
|
private final LandingEventHandler landEvent = addTicker(new LandingEventHandler(this));
|
2022-12-25 23:21:34 +01:00
|
|
|
private final Enchantments enchants = addTicker(new Enchantments(this));
|
|
|
|
private final ItemTracker armour = addTicker(new ItemTracker(this));
|
2024-03-28 13:08:06 +01:00
|
|
|
private final Transportation<T> transportation = new Transportation<>(this);
|
2022-12-09 21:45:49 +01:00
|
|
|
|
2021-08-04 15:38:03 +02:00
|
|
|
protected Living(T entity, TrackedData<NbtCompound> effect) {
|
2021-02-14 16:52:56 +01:00
|
|
|
this.entity = entity;
|
|
|
|
this.effectDelegate = new EffectSync(this, effect);
|
2023-04-29 23:32:00 +02:00
|
|
|
this.sneakingHeuristic = addTicker(new Interactable(entity::isSneaking));
|
|
|
|
this.landedHeuristic = addTicker(new Interactable(entity::isOnGround));
|
|
|
|
this.jumpingHeuristic = addTicker(new Interactable(((LivingEntityDuck)entity)::isJumping));
|
2024-02-27 01:01:22 +01:00
|
|
|
}
|
2023-04-29 23:32:00 +02:00
|
|
|
|
2024-02-27 01:01:22 +01:00
|
|
|
@Override
|
|
|
|
public void initDataTracker() {
|
|
|
|
effectDelegate.initDataTracker();
|
|
|
|
entity.getDataTracker().startTracking(Creature.GRAVITY, 1F);
|
2022-12-25 19:36:43 +01:00
|
|
|
entity.getDataTracker().startTracking(CARRIER_ID, Optional.empty());
|
2021-02-14 16:52:56 +01:00
|
|
|
}
|
|
|
|
|
2022-12-25 23:21:34 +01:00
|
|
|
public <Q extends Tickable> Q addTicker(Q tickable) {
|
2023-09-13 14:55:06 +02:00
|
|
|
tickers.add(Objects.requireNonNull(tickable, "tickable cannot be null"));
|
2022-12-25 23:21:34 +01:00
|
|
|
return tickable;
|
|
|
|
}
|
|
|
|
|
2022-12-25 16:01:12 +01:00
|
|
|
public boolean isInvisible() {
|
|
|
|
return invisible && SpellPredicate.IS_DISGUISE.isOn(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setInvisible(boolean invisible) {
|
|
|
|
this.invisible = invisible;
|
|
|
|
}
|
|
|
|
|
2024-05-17 20:28:08 +02:00
|
|
|
public void waitForFall(LandingEventHandler.Callback callback) {
|
|
|
|
landEvent.setCallback(callback);
|
2021-02-14 16:52:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean sneakingChanged() {
|
2023-04-29 23:32:00 +02:00
|
|
|
return sneakingHeuristic.hasChanged(Heuristic.ONCE);
|
2021-02-14 16:52:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean landedChanged() {
|
2023-04-29 23:32:00 +02:00
|
|
|
return landedHeuristic.hasChanged(Heuristic.ONCE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Interactable getJumpingHeuristic() {
|
|
|
|
return jumpingHeuristic;
|
2021-02-14 16:52:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-03-05 18:22:27 +01:00
|
|
|
public SpellContainer getSpellSlot() {
|
2021-02-14 16:52:56 +01:00
|
|
|
return effectDelegate;
|
|
|
|
}
|
|
|
|
|
2021-02-16 12:39:39 +01:00
|
|
|
public Enchantments getEnchants() {
|
|
|
|
return enchants;
|
|
|
|
}
|
|
|
|
|
2022-12-09 21:45:49 +01:00
|
|
|
public ItemTracker getArmour() {
|
|
|
|
return armour;
|
|
|
|
}
|
|
|
|
|
2024-03-28 13:08:06 +01:00
|
|
|
public Transportation<T> getTransportation() {
|
|
|
|
return transportation;
|
|
|
|
}
|
|
|
|
|
2022-12-19 16:03:35 +01:00
|
|
|
@Override
|
|
|
|
public final T asEntity() {
|
2021-02-14 16:52:56 +01:00
|
|
|
return entity;
|
|
|
|
}
|
|
|
|
|
2022-12-25 19:36:43 +01:00
|
|
|
public Optional<UUID> getCarrierId() {
|
|
|
|
return entity.getDataTracker().get(CARRIER_ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCarrier(UUID carrier) {
|
|
|
|
entity.getDataTracker().set(CARRIER_ID, Optional.ofNullable(carrier));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCarrier(Entity carrier) {
|
|
|
|
entity.getDataTracker().set(CARRIER_ID, Optional.ofNullable(carrier).map(Entity::getUuid));
|
|
|
|
}
|
|
|
|
|
2023-03-05 02:28:43 +01:00
|
|
|
@Nullable
|
|
|
|
public Optional<Living<?>> getTarget() {
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTarget(Living<?> target) {
|
|
|
|
this.target = Optional.ofNullable(target);
|
|
|
|
}
|
|
|
|
|
2022-12-25 19:36:43 +01:00
|
|
|
public boolean isBeingCarried() {
|
|
|
|
Entity vehicle = entity.getVehicle();
|
|
|
|
return vehicle != null && getCarrierId().filter(vehicle.getUuid()::equals).isPresent();
|
|
|
|
}
|
|
|
|
|
2024-03-28 16:32:21 +01:00
|
|
|
@Override
|
|
|
|
public boolean hasFeatherTouch() {
|
|
|
|
return EnchantmentHelper.getEquipmentLevel(UEnchantments.FEATHER_TOUCH, entity) > 0;
|
|
|
|
}
|
|
|
|
|
2023-08-11 19:51:35 +02:00
|
|
|
@Override
|
|
|
|
public boolean beforeUpdate() {
|
2024-05-17 20:28:08 +02:00
|
|
|
landEvent.beforeTick();
|
2023-09-03 16:51:05 +02:00
|
|
|
if (EffectUtils.getAmplifier(entity, UEffects.PARALYSIS) > 1 && entity.getVelocity().horizontalLengthSquared() > 0) {
|
|
|
|
entity.setVelocity(entity.getVelocity().multiply(0, 1, 0));
|
|
|
|
updateVelocity();
|
|
|
|
}
|
|
|
|
|
2023-08-12 16:59:13 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-02-14 16:52:56 +01:00
|
|
|
@Override
|
|
|
|
public void tick() {
|
2022-12-25 23:21:34 +01:00
|
|
|
tickers.forEach(Tickable::tick);
|
2023-09-02 20:59:42 +02:00
|
|
|
effectDelegate.tick(Situation.BODY);
|
2021-02-14 16:52:56 +01:00
|
|
|
|
2023-01-09 01:27:22 +01:00
|
|
|
if (!(entity instanceof PlayerEntity)) {
|
|
|
|
if (!entity.hasVehicle() && getCarrierId().isPresent() && !asWorld().isClient && entity.age % 10 == 0) {
|
|
|
|
UUID carrierId = getCarrierId().get();
|
|
|
|
Entity carrier = ((ServerWorld)asWorld()).getEntity(carrierId);
|
2023-02-26 01:37:56 +01:00
|
|
|
if (carrier != null) {
|
|
|
|
asEntity().startRiding(carrier, true);
|
|
|
|
Living.transmitPassengers(carrier);
|
|
|
|
} else {
|
|
|
|
Unicopia.LOGGER.warn("No passenger with id {]", carrierId);
|
|
|
|
}
|
2023-01-09 01:27:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-14 17:46:41 +01:00
|
|
|
if (invinsibilityTicks > 0) {
|
|
|
|
invinsibilityTicks--;
|
|
|
|
}
|
|
|
|
|
2022-12-04 16:25:03 +01:00
|
|
|
if (entity.hasStatusEffect(UEffects.PARALYSIS) && entity.getVelocity().horizontalLengthSquared() > 0) {
|
|
|
|
entity.setVelocity(entity.getVelocity().multiply(0, 1, 0));
|
|
|
|
updateVelocity();
|
|
|
|
}
|
|
|
|
|
2022-12-25 23:23:11 +01:00
|
|
|
if (isBeingCarried()) {
|
|
|
|
Pony carrier = Pony.of(entity.getVehicle()).orElse(null);
|
2023-10-16 16:18:36 +02:00
|
|
|
if (!Abilities.CARRY.canUse(carrier.getCompositeRace()) && !Abilities.HUG.canUse(carrier.getCompositeRace())) {
|
2022-12-25 23:23:11 +01:00
|
|
|
entity.stopRiding();
|
|
|
|
entity.refreshPositionAfterTeleport(carrier.getOriginVector());
|
|
|
|
Living.transmitPassengers(carrier.asEntity());
|
|
|
|
}
|
2023-08-09 17:47:03 +02:00
|
|
|
entity.setYaw(carrier.asEntity().getYaw());
|
2022-12-25 23:23:11 +01:00
|
|
|
}
|
2022-12-25 23:21:34 +01:00
|
|
|
|
|
|
|
updateDragonBreath();
|
2023-08-12 21:43:37 +02:00
|
|
|
|
2024-03-28 13:08:06 +01:00
|
|
|
transportation.tick();
|
2022-12-25 23:21:34 +01:00
|
|
|
}
|
2022-09-18 01:23:29 +02:00
|
|
|
|
2023-07-06 18:27:03 +02:00
|
|
|
public void updateAttributeModifier(UUID id, EntityAttribute attribute, float desiredValue, Float2ObjectFunction<EntityAttributeModifier> modifierSupplier, boolean permanent) {
|
|
|
|
@Nullable
|
|
|
|
EntityAttributeInstance instance = asEntity().getAttributeInstance(attribute);
|
|
|
|
if (instance == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
EntityAttributeModifier modifier = instance.getModifier(id);
|
|
|
|
|
|
|
|
if (!MathHelper.approximatelyEquals(desiredValue, modifier == null ? 0 : modifier.getValue())) {
|
|
|
|
if (modifier != null) {
|
|
|
|
instance.removeModifier(modifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desiredValue != 0) {
|
|
|
|
if (permanent) {
|
|
|
|
instance.addPersistentModifier(modifierSupplier.get(desiredValue));
|
|
|
|
} else {
|
|
|
|
instance.addTemporaryModifier(modifierSupplier.get(desiredValue));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-12 15:49:00 +02:00
|
|
|
public boolean canBeSeenBy(Entity entity) {
|
|
|
|
return !isInvisible()
|
|
|
|
&& getSpellSlot()
|
|
|
|
.get(SpellPredicate.IS_DISGUISE, true)
|
|
|
|
.filter(spell -> spell.getDisguise().getAppearance() == entity)
|
|
|
|
.isEmpty();
|
|
|
|
}
|
|
|
|
|
2023-10-09 23:54:57 +02:00
|
|
|
public Optional<Vec3d> adjustMovementSpeedInWater(Vec3d speed) {
|
|
|
|
return Optional.empty();
|
|
|
|
}
|
|
|
|
|
2022-12-25 23:21:34 +01:00
|
|
|
private void updateDragonBreath() {
|
2023-06-03 13:40:54 +02:00
|
|
|
if (!entity.getWorld().isClient && (entity instanceof PlayerEntity || entity.hasCustomName())) {
|
2022-09-18 01:23:29 +02:00
|
|
|
|
|
|
|
Vec3d targetPos = entity.getRotationVector().multiply(2).add(entity.getEyePos());
|
|
|
|
|
2023-06-02 21:20:30 +02:00
|
|
|
if (entity.getWorld().isAir(BlockPos.ofFloored(targetPos))) {
|
2023-06-03 13:40:54 +02:00
|
|
|
DragonBreathStore store = DragonBreathStore.get(entity.getWorld());
|
2022-09-18 01:23:29 +02:00
|
|
|
String name = entity.getDisplayName().getString();
|
|
|
|
store.popEntries(name).forEach(stack -> {
|
2023-09-03 20:12:54 +02:00
|
|
|
ItemStack payload = stack.payload();
|
|
|
|
Item item = payload.getItem();
|
2023-09-02 22:55:20 +02:00
|
|
|
|
2024-03-31 15:35:04 +02:00
|
|
|
boolean deliverAggressively = payload.isIn(UTags.Items.IS_DELIVERED_AGGRESSIVELY);
|
2023-09-02 22:55:20 +02:00
|
|
|
|
2023-09-03 20:12:54 +02:00
|
|
|
Vec3d randomPos = deliverAggressively ? targetPos.add(0, 2, 0) : targetPos.add(VecHelper.supply(() -> entity.getRandom().nextTriangular(0.1, 0.5)));
|
2023-09-02 22:55:20 +02:00
|
|
|
|
2023-09-03 20:12:54 +02:00
|
|
|
if (deliverAggressively && item instanceof BlockItem blockItem) {
|
|
|
|
do {
|
|
|
|
ItemStack instance = payload.split(1);
|
|
|
|
BlockPos pos = BlockPos.ofFloored(randomPos);
|
|
|
|
if (!entity.getWorld().isAir(pos)) {
|
|
|
|
store.put(name, instance);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
ParticleUtils.spawnParticle(entity.getWorld(), ParticleTypes.FLAME, randomPos.add(
|
|
|
|
VecHelper.supply(() -> entity.getRandom().nextTriangular(0.1, 0.5))
|
|
|
|
), Vec3d.ZERO);
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemPlacementContext context = new ItemPlacementContext(entity.getWorld(), (PlayerEntity)null, Hand.MAIN_HAND, instance,
|
|
|
|
BlockHitResult.createMissed(Vec3d.ZERO, Direction.UP, pos)
|
|
|
|
);
|
|
|
|
|
|
|
|
BlockState state = blockItem.getBlock().getPlacementState(context);
|
|
|
|
if (state == null) {
|
|
|
|
state = blockItem.getBlock().getDefaultState();
|
|
|
|
}
|
|
|
|
|
|
|
|
entity.getWorld().setBlockState(pos, state);
|
|
|
|
BlockSoundGroup sound = state.getSoundGroup();
|
|
|
|
entity.getWorld().playSound(null, pos, sound.getPlaceSound(), SoundCategory.BLOCKS, (sound.getVolume() + 1) * 0.5F, sound.getPitch() * 0.8F);
|
|
|
|
}
|
|
|
|
randomPos = targetPos.add(VecHelper.supply(() -> entity.getRandom().nextTriangular(0.1, 0.5)));
|
|
|
|
} while (!payload.isEmpty());
|
2023-09-02 22:55:20 +02:00
|
|
|
} else {
|
2023-09-03 20:12:54 +02:00
|
|
|
if (!entity.getWorld().isAir(BlockPos.ofFloored(randomPos))) {
|
|
|
|
store.put(name, stack.payload());
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
ParticleUtils.spawnParticle(entity.getWorld(), ParticleTypes.FLAME, randomPos.add(
|
|
|
|
VecHelper.supply(() -> entity.getRandom().nextTriangular(0.1, 0.5))
|
|
|
|
), Vec3d.ZERO);
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemEntity itemEntity = EntityType.ITEM.create(entity.getWorld());
|
|
|
|
itemEntity.setStack(payload);
|
|
|
|
itemEntity.setPosition(randomPos);
|
|
|
|
itemEntity.getWorld().spawnEntity(itemEntity);
|
|
|
|
entity.getWorld().playSoundFromEntity(null, entity, USounds.ITEM_DRAGON_BREATH_ARRIVE, entity.getSoundCategory(), 1, 1);
|
2023-09-09 19:46:41 +02:00
|
|
|
UCriteria.SEND_DRAGON_BREATH.triggerReceived(entity, payload.copy());
|
2023-09-03 20:12:54 +02:00
|
|
|
}
|
2022-09-28 22:43:45 +02:00
|
|
|
}
|
2022-09-18 01:23:29 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-02-14 16:52:56 +01:00
|
|
|
}
|
|
|
|
|
2022-12-25 19:36:43 +01:00
|
|
|
public boolean onUpdatePassengerPosition(Entity passender, Entity.PositionUpdater positionUpdater) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-03-06 13:27:52 +01:00
|
|
|
@Nullable
|
2022-12-19 23:23:08 +01:00
|
|
|
public final Caster<?> getAttacker() {
|
2021-03-06 13:27:52 +01:00
|
|
|
return attacker;
|
|
|
|
}
|
|
|
|
|
2021-02-14 17:46:41 +01:00
|
|
|
public Optional<Boolean> onDamage(DamageSource source, float amount) {
|
|
|
|
|
2024-02-15 15:17:02 +01:00
|
|
|
if (Guest.of(source.getAttacker()).hostIs(this)
|
|
|
|
|| Guest.of(source.getSource()).hostIs(this)) {
|
2024-02-13 19:47:01 +01:00
|
|
|
var type = source.getTypeRegistryEntry();
|
|
|
|
return Optional.of(entity.damage(
|
|
|
|
type.matchesKey(DamageTypes.FIREBALL) ? entity.getDamageSources().create(DamageTypes.UNATTRIBUTED_FIREBALL) :
|
|
|
|
type.matchesKey(DamageTypes.PLAYER_EXPLOSION) ? entity.getDamageSources().create(DamageTypes.EXPLOSION) :
|
|
|
|
new DamageSource(type, entity, entity), amount));
|
|
|
|
}
|
|
|
|
|
2024-02-15 15:17:02 +01:00
|
|
|
if (Guest.of(entity).getHost() instanceof Living l) {
|
2024-02-13 19:47:01 +01:00
|
|
|
l.asEntity().damage(source, amount);
|
|
|
|
}
|
|
|
|
|
2023-06-02 21:20:30 +02:00
|
|
|
if (source.isIn(DamageTypeTags.IS_LIGHTNING) && (invinsibilityTicks > 0 || tryCaptureLightning())) {
|
2022-12-19 23:23:08 +01:00
|
|
|
return Optional.of(false);
|
2021-02-14 17:46:41 +01:00
|
|
|
}
|
|
|
|
|
2022-09-25 22:32:38 +02:00
|
|
|
if (source instanceof MagicalDamageSource magical) {
|
2022-12-19 23:23:08 +01:00
|
|
|
Caster<?> attacker = ((MagicalDamageSource)source).getSpell();
|
2021-03-06 13:27:52 +01:00
|
|
|
if (attacker != null) {
|
|
|
|
this.attacker = attacker;
|
|
|
|
}
|
2022-09-25 22:32:38 +02:00
|
|
|
|
2024-03-31 15:35:04 +02:00
|
|
|
if (magical.isIn(UTags.DamageTypes.BREAKS_SUNGLASSES)) {
|
2022-09-25 22:32:38 +02:00
|
|
|
ItemStack glasses = GlassesItem.getForEntity(entity);
|
|
|
|
if (glasses.getItem() == UItems.SUNGLASSES) {
|
|
|
|
ItemStack broken = UItems.BROKEN_SUNGLASSES.getDefaultStack();
|
|
|
|
broken.setNbt(glasses.getNbt());
|
2024-02-24 14:06:32 +01:00
|
|
|
TrinketsDelegate.getInstance(entity).setEquippedStack(entity, TrinketsDelegate.FACE, broken);
|
2023-08-22 17:25:36 +02:00
|
|
|
playSound(USounds.ITEM_SUNGLASSES_SHATTER, 1, 1);
|
2022-09-25 22:32:38 +02:00
|
|
|
}
|
|
|
|
}
|
2021-03-06 13:27:52 +01:00
|
|
|
}
|
|
|
|
|
2024-03-12 15:49:41 +01:00
|
|
|
if (entity instanceof HostileEntity mob && mob.hasStatusEffect(UEffects.CORRUPT_INFLUENCE) && mob.getRandom().nextInt(4) == 0) {
|
|
|
|
CorruptInfluenceStatusEffect.reproduce(mob);
|
|
|
|
}
|
|
|
|
|
2021-02-14 17:46:41 +01:00
|
|
|
return Optional.empty();
|
|
|
|
}
|
|
|
|
|
2024-02-13 19:47:01 +01:00
|
|
|
public TriState canBeHurtByWater() {
|
|
|
|
return TriState.DEFAULT;
|
|
|
|
}
|
|
|
|
|
2023-08-06 19:56:31 +02:00
|
|
|
public Optional<BlockPos> chooseClimbingPos() {
|
|
|
|
return getSpellSlot().get(SpellPredicate.IS_DISGUISE, false)
|
|
|
|
.map(AbstractDisguiseSpell::getDisguise)
|
|
|
|
.filter(EntityAppearance::canClimbWalls)
|
|
|
|
.map(v -> entity.getBlockPos());
|
|
|
|
}
|
|
|
|
|
2021-02-14 17:46:41 +01:00
|
|
|
private boolean tryCaptureLightning() {
|
|
|
|
return getInventoryStacks().filter(stack -> !stack.isEmpty() && stack.getItem() == UItems.EMPTY_JAR).findFirst().map(stack -> {
|
|
|
|
invinsibilityTicks = 20;
|
|
|
|
stack.split(1);
|
|
|
|
giveBackItem(UItems.LIGHTNING_JAR.getDefaultStack());
|
|
|
|
return stack;
|
|
|
|
}).isPresent();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected Stream<ItemStack> getInventoryStacks() {
|
|
|
|
return Stream.of(entity.getStackInHand(Hand.MAIN_HAND), entity.getStackInHand(Hand.OFF_HAND));
|
|
|
|
}
|
|
|
|
|
2022-12-09 21:45:49 +01:00
|
|
|
protected Stream<ItemStack> getArmourStacks() {
|
|
|
|
if (!TrinketsDelegate.hasTrinkets()) {
|
|
|
|
return StreamSupport.stream(entity.getArmorItems().spliterator(), false);
|
|
|
|
}
|
|
|
|
return Stream.concat(
|
2024-02-24 14:06:32 +01:00
|
|
|
TrinketsDelegate.getInstance(entity).getEquipped(entity, TrinketsDelegate.NECKLACE),
|
2022-12-09 21:45:49 +01:00
|
|
|
StreamSupport.stream(entity.getArmorItems().spliterator(), false)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-14 17:46:41 +01:00
|
|
|
protected void giveBackItem(ItemStack stack) {
|
|
|
|
entity.dropStack(stack);
|
|
|
|
}
|
|
|
|
|
2021-02-14 16:52:56 +01:00
|
|
|
@Override
|
|
|
|
public boolean onProjectileImpact(ProjectileEntity projectile) {
|
2021-03-03 10:33:23 +01:00
|
|
|
return getSpellSlot().get(true)
|
2021-03-06 10:58:44 +01:00
|
|
|
.filter(effect -> !effect.isDead()
|
|
|
|
&& effect instanceof ProjectileImpactListener
|
|
|
|
&& ((ProjectileImpactListener)effect).onProjectileImpact(projectile))
|
2021-03-03 10:33:23 +01:00
|
|
|
.isPresent();
|
2021-02-14 16:52:56 +01:00
|
|
|
}
|
|
|
|
|
2024-05-17 19:23:38 +02:00
|
|
|
public float onImpact(float distance, float damageMultiplier, DamageSource cause) {
|
2024-05-17 20:28:08 +02:00
|
|
|
float fallDistance = landEvent.fire(getEffectiveFallDistance(distance));
|
2024-05-17 19:23:38 +02:00
|
|
|
|
2021-12-22 15:43:06 +01:00
|
|
|
getSpellSlot().get(SpellPredicate.IS_DISGUISE, false).ifPresent(spell -> {
|
2024-05-17 19:23:38 +02:00
|
|
|
spell.getDisguise().onImpact(this, fallDistance, damageMultiplier, cause);
|
2021-02-14 16:52:56 +01:00
|
|
|
});
|
2024-05-17 19:23:38 +02:00
|
|
|
return fallDistance;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected float getEffectiveFallDistance(float distance) {
|
|
|
|
return distance;
|
2021-02-14 16:52:56 +01:00
|
|
|
}
|
2021-02-16 12:39:39 +01:00
|
|
|
|
2023-10-18 19:52:59 +02:00
|
|
|
@Override
|
|
|
|
public float getCloudWalkingStrength() {
|
|
|
|
Enchantment featherFalling = net.minecraft.enchantment.Enchantments.FEATHER_FALLING;
|
|
|
|
int maxLevel = featherFalling.getMaxLevel();
|
|
|
|
int level = EnchantmentHelper.getEquipmentLevel(featherFalling, entity);
|
|
|
|
return MathHelper.clamp(level / (float)maxLevel, 0, 1);
|
|
|
|
}
|
|
|
|
|
2022-12-10 01:16:23 +01:00
|
|
|
@Override
|
|
|
|
public void setDirty() {}
|
|
|
|
|
2021-02-16 12:39:39 +01:00
|
|
|
@Override
|
2021-08-04 15:38:03 +02:00
|
|
|
public void toNBT(NbtCompound compound) {
|
2021-02-16 12:39:39 +01:00
|
|
|
enchants.toNBT(compound);
|
2022-10-13 18:15:21 +02:00
|
|
|
effectDelegate.toNBT(compound);
|
2022-12-10 01:16:23 +01:00
|
|
|
toSyncronisedNbt(compound);
|
2021-02-16 12:39:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-08-04 15:38:03 +02:00
|
|
|
public void fromNBT(NbtCompound compound) {
|
2021-02-16 12:39:39 +01:00
|
|
|
enchants.fromNBT(compound);
|
2022-10-13 18:15:21 +02:00
|
|
|
effectDelegate.fromNBT(compound);
|
2022-12-10 01:16:23 +01:00
|
|
|
fromSynchronizedNbt(compound);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void toSyncronisedNbt(NbtCompound compound) {
|
|
|
|
compound.put("armour", armour.toNBT());
|
2022-12-25 19:36:43 +01:00
|
|
|
getCarrierId().ifPresent(id -> compound.putUuid("carrier", id));
|
2022-12-10 01:16:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fromSynchronizedNbt(NbtCompound compound) {
|
2022-12-09 21:45:49 +01:00
|
|
|
armour.fromNBT(compound.getCompound("armour"));
|
2022-12-25 19:36:43 +01:00
|
|
|
setCarrier(compound.containsUuid("carrier") ? compound.getUuid("carrier") : null);
|
2021-02-16 12:39:39 +01:00
|
|
|
}
|
2022-09-26 21:13:03 +02:00
|
|
|
|
|
|
|
public void updateVelocity() {
|
|
|
|
updateVelocity(entity);
|
|
|
|
}
|
|
|
|
|
2024-02-21 23:46:10 +01:00
|
|
|
@Override
|
|
|
|
public boolean canUse(Ability<?> ability) {
|
|
|
|
return ability.canUse(getCompositeRace());
|
|
|
|
}
|
|
|
|
|
2022-12-09 23:16:54 +01:00
|
|
|
public static Optional<Living<?>> getOrEmpty(Entity entity) {
|
2022-12-25 16:01:12 +01:00
|
|
|
return Equine.of(entity, a -> a instanceof Living);
|
2022-12-09 22:19:45 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 21:45:49 +01:00
|
|
|
public static Living<?> living(Entity entity) {
|
2022-12-09 23:16:54 +01:00
|
|
|
return getOrEmpty(entity).orElse(null);
|
2022-12-09 21:45:49 +01:00
|
|
|
}
|
|
|
|
|
2022-12-25 19:36:43 +01:00
|
|
|
public static <E extends LivingEntity> Living<E> living(E entity) {
|
|
|
|
return Equine.<E, Living<E>>of(entity, e -> e instanceof Living<?>).orElse(null);
|
|
|
|
}
|
|
|
|
|
2023-05-29 11:41:02 +02:00
|
|
|
public static void updateVelocity(@Nullable Entity entity) {
|
|
|
|
if (entity != null) {
|
|
|
|
entity.velocityModified = true;
|
|
|
|
//if (entity instanceof ServerPlayerEntity ply) {
|
|
|
|
// ply.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(ply));
|
|
|
|
//}
|
|
|
|
}
|
2022-09-26 21:13:03 +02:00
|
|
|
}
|
2022-10-03 23:44:30 +02:00
|
|
|
|
2023-05-29 11:41:02 +02:00
|
|
|
public static void transmitPassengers(@Nullable Entity entity) {
|
2023-06-03 13:40:54 +02:00
|
|
|
if (entity != null && entity.getWorld() instanceof ServerWorld sw) {
|
2022-10-03 23:44:30 +02:00
|
|
|
sw.getChunkManager().sendToNearbyPlayers(entity, new EntityPassengersSetS2CPacket(entity));
|
|
|
|
}
|
|
|
|
}
|
2021-02-14 16:52:56 +01:00
|
|
|
}
|