mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Added a ghast behaviour
This commit is contained in:
parent
a6d083584a
commit
fbb5abbba5
3 changed files with 67 additions and 11 deletions
|
@ -241,6 +241,7 @@ public class EntityBehaviour<T extends Entity> {
|
|||
register(TraderBehaviour::new, EntityType.VILLAGER, EntityType.WANDERING_TRADER);
|
||||
register(SheepBehaviour::new, EntityType.SHEEP);
|
||||
register(BeeBehaviour::new, EntityType.BEE);
|
||||
register(GhastBehaviour::new, EntityType.GHAST);
|
||||
register(EndermanBehaviour::new, EntityType.ENDERMAN);
|
||||
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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -7,33 +7,37 @@ import com.minelittlepony.unicopia.util.RayTraceHelper;
|
|||
import net.minecraft.entity.LivingEntity;
|
||||
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
|
||||
public void onDestroy(MobEntity entity) {
|
||||
public void onDestroy(T entity) {
|
||||
entity.setAiDisabled(false);
|
||||
super.onDestroy(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Pony player, MobEntity entity, DisguiseSpell spell) {
|
||||
public void update(Pony player, T entity, DisguiseSpell spell) {
|
||||
if (player.sneakingChanged() && isSneakingOnGround(player)) {
|
||||
|
||||
LivingEntity target = RayTraceHelper.<LivingEntity>findEntity(player.getEntity(), 6, 1,
|
||||
e -> e instanceof LivingEntity && e != entity && e != player.getOwner())
|
||||
.orElseGet(() -> getDummy(entity));
|
||||
|
||||
LivingEntity target = findTarget(player, entity);
|
||||
entity.tryAttack(target);
|
||||
target.setAttacker(player.getOwner());
|
||||
}
|
||||
}
|
||||
|
||||
private MobEntity getDummy(MobEntity entity) {
|
||||
if (dummy == null) {
|
||||
dummy = (MobEntity)entity.getType().create(entity.world);
|
||||
protected LivingEntity findTarget(Pony player, T entity) {
|
||||
return RayTraceHelper.<LivingEntity>findEntity(player.getEntity(), 6, 1,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue