Added a ghast behaviour

This commit is contained in:
Sollace 2020-10-01 20:23:40 +02:00
parent a6d083584a
commit fbb5abbba5
3 changed files with 67 additions and 11 deletions

View file

@ -241,6 +241,7 @@ public class EntityBehaviour<T extends Entity> {
register(TraderBehaviour::new, EntityType.VILLAGER, EntityType.WANDERING_TRADER); register(TraderBehaviour::new, EntityType.VILLAGER, EntityType.WANDERING_TRADER);
register(SheepBehaviour::new, EntityType.SHEEP); register(SheepBehaviour::new, EntityType.SHEEP);
register(BeeBehaviour::new, EntityType.BEE); register(BeeBehaviour::new, EntityType.BEE);
register(GhastBehaviour::new, EntityType.GHAST);
register(EndermanBehaviour::new, EntityType.ENDERMAN); register(EndermanBehaviour::new, EntityType.ENDERMAN);
EntityBehaviour.<LlamaEntity>register(() -> new RangedAttackBehaviour<>(SoundEvents.ENTITY_LLAMA_SPIT, LlamaSpitEntity::new), EntityType.LLAMA, EntityType.TRADER_LLAMA); EntityBehaviour.<LlamaEntity>register(() -> new RangedAttackBehaviour<>(SoundEvents.ENTITY_LLAMA_SPIT, LlamaSpitEntity::new), EntityType.LLAMA, EntityType.TRADER_LLAMA);
EntityBehaviour.<SnowGolemEntity>register(() -> new RangedAttackBehaviour<>(SoundEvents.ENTITY_SNOW_GOLEM_SHOOT, SnowballEntity::new), EntityType.SNOW_GOLEM); EntityBehaviour.<SnowGolemEntity>register(() -> new RangedAttackBehaviour<>(SoundEvents.ENTITY_SNOW_GOLEM_SHOOT, SnowballEntity::new), EntityType.SNOW_GOLEM);

View file

@ -0,0 +1,51 @@
package com.minelittlepony.unicopia.entity.behaviour;
import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell;
import com.minelittlepony.unicopia.entity.player.Pony;
import net.minecraft.entity.mob.GhastEntity;
import net.minecraft.entity.projectile.FireballEntity;
import net.minecraft.util.math.Vec3d;
public class GhastBehaviour extends MobBehaviour<GhastEntity> {
@Override
public void update(Pony player, GhastEntity entity, DisguiseSpell spell) {
if (player.sneakingChanged()) {
boolean sneaking = player.getOwner().isSneaking();
entity.setShooting(sneaking);
entity.setTarget(sneaking ? findTarget(player, entity) : null);
if (sneaking) {
if (!entity.isSilent()) {
entity.world.syncWorldEvent(null, 1015, entity.getBlockPos(), 0);
}
} else {
Vec3d vec3d = entity.getRotationVec(1);
if (!entity.isSilent()) {
entity.world.syncWorldEvent(null, 1016, entity.getBlockPos(), 0);
}
Vec3d rot = player.getEntity().getRotationVec(1);
FireballEntity fireballEntity = new FireballEntity(entity.world, entity, rot.getX(), rot.getY(), rot.getZ());
fireballEntity.explosionPower = entity.getFireballStrength();
fireballEntity.setOwner(player.getOwner());
fireballEntity.updatePosition(entity.getX() + vec3d.x * 4, entity.getBodyY(0.5D) + 0.5D, fireballEntity.getZ() + vec3d.z * 4);
entity.world.spawnEntity(fireballEntity);
}
}
}
@Override
protected GhastEntity getDummy(GhastEntity entity) {
GhastEntity dummy = super.getDummy(entity);
Vec3d pos = entity.getCameraPosVec(1).add(entity.getRotationVec(1));
dummy.setPos(pos.x, pos.y, pos.z);
return dummy;
}
}

View file

@ -7,33 +7,37 @@ import com.minelittlepony.unicopia.util.RayTraceHelper;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.mob.MobEntity;
public class MobBehaviour extends EntityBehaviour<MobEntity> { public class MobBehaviour<T extends MobEntity> extends EntityBehaviour<T> {
private MobEntity dummy; private T dummy;
@Override @Override
public void onDestroy(MobEntity entity) { public void onDestroy(T entity) {
entity.setAiDisabled(false); entity.setAiDisabled(false);
super.onDestroy(entity); super.onDestroy(entity);
} }
@Override @Override
public void update(Pony player, MobEntity entity, DisguiseSpell spell) { public void update(Pony player, T entity, DisguiseSpell spell) {
if (player.sneakingChanged() && isSneakingOnGround(player)) { if (player.sneakingChanged() && isSneakingOnGround(player)) {
LivingEntity target = findTarget(player, entity);
LivingEntity target = RayTraceHelper.<LivingEntity>findEntity(player.getEntity(), 6, 1,
e -> e instanceof LivingEntity && e != entity && e != player.getOwner())
.orElseGet(() -> getDummy(entity));
entity.tryAttack(target); entity.tryAttack(target);
target.setAttacker(player.getOwner()); target.setAttacker(player.getOwner());
} }
} }
private MobEntity getDummy(MobEntity entity) { protected LivingEntity findTarget(Pony player, T entity) {
if (dummy == null) { return RayTraceHelper.<LivingEntity>findEntity(player.getEntity(), 6, 1,
dummy = (MobEntity)entity.getType().create(entity.world); e -> e instanceof LivingEntity && e != entity && e != player.getOwner())
.orElseGet(() -> getDummy(entity));
} }
@SuppressWarnings("unchecked")
protected T getDummy(T entity) {
if (dummy == null) {
dummy = (T)entity.getType().create(entity.world);
}
return dummy; return dummy;
} }
} }