mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Added llama behaviours
This commit is contained in:
parent
ea34a93bbc
commit
e177f74c8f
3 changed files with 45 additions and 7 deletions
|
@ -3,9 +3,7 @@ package com.minelittlepony.unicopia.entity.behaviour;
|
|||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||
import com.minelittlepony.unicopia.ability.magic.Spell;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.mob.CreeperEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
||||
public class CreeperBehaviour extends EntityBehaviour<CreeperEntity> {
|
||||
@Override
|
||||
|
@ -18,9 +16,4 @@ public class CreeperBehaviour extends EntityBehaviour<CreeperEntity> {
|
|||
entity.getVisibilityCache().clear();
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isSneakingOnGround(Caster<?> source) {
|
||||
Entity e = source.getEntity();
|
||||
return e.isSneaking() && (e.isOnGround() || !(e instanceof PlayerEntity && ((PlayerEntity)e).abilities.flying));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -172,6 +172,11 @@ public class EntityBehaviour<T extends Entity> {
|
|||
return false;
|
||||
}
|
||||
|
||||
protected boolean isSneakingOnGround(Caster<?> source) {
|
||||
Entity e = source.getEntity();
|
||||
return e.isSneaking() && (e.isOnGround() || !(e instanceof PlayerEntity && ((PlayerEntity)e).abilities.flying));
|
||||
}
|
||||
|
||||
public static <T extends Entity> void register(Supplier<EntityBehaviour<T>> behaviour, EntityType<?>... types) {
|
||||
for (EntityType<?> type : types) {
|
||||
Registry.register(REGISTRY, EntityType.getId(type), behaviour.get());
|
||||
|
@ -192,6 +197,7 @@ public class EntityBehaviour<T extends Entity> {
|
|||
register(SheepBehaviour::new, EntityType.SHEEP);
|
||||
register(BeeBehaviour::new, EntityType.BEE);
|
||||
register(EndermanBehaviour::new, EntityType.ENDERMAN);
|
||||
register(LlamaBehaviour::new, EntityType.LLAMA, EntityType.TRADER_LLAMA);
|
||||
register(SpellcastingIllagerBehaviour::new, EntityType.ILLUSIONER, EntityType.EVOKER);
|
||||
register(ShulkerBehaviour::new, EntityType.SHULKER);
|
||||
register(CreeperBehaviour::new, EntityType.CREEPER);
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package com.minelittlepony.unicopia.entity.behaviour;
|
||||
|
||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||
import com.minelittlepony.unicopia.ability.magic.Spell;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import net.minecraft.entity.passive.LlamaEntity;
|
||||
import net.minecraft.entity.projectile.LlamaSpitEntity;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public class LlamaBehaviour extends EntityBehaviour<LlamaEntity> {
|
||||
|
||||
@Override
|
||||
public void update(Caster<?> source, LlamaEntity entity, Spell spell) {
|
||||
|
||||
if (source instanceof Pony) {
|
||||
Pony player = (Pony)source;
|
||||
|
||||
if (player.sneakingChanged() && isSneakingOnGround(player)) {
|
||||
|
||||
LlamaSpitEntity spit = new LlamaSpitEntity(entity.world, entity);
|
||||
|
||||
Vec3d rot = source.getEntity().getRotationVec(1);
|
||||
|
||||
spit.setVelocity(rot.getX(), rot.getY(), rot.getZ(), 1.5F, 3);
|
||||
spit.setOwner(source.getOwner());
|
||||
|
||||
if (!entity.isSilent()) {
|
||||
entity.world.playSound(null, entity.getX(), entity.getY(), entity.getZ(),
|
||||
SoundEvents.ENTITY_LLAMA_SPIT, entity.getSoundCategory(), 1,
|
||||
1 + (entity.world.random.nextFloat() - entity.world.random.nextFloat()) * 0.2F);
|
||||
}
|
||||
|
||||
entity.world.spawnEntity(spit);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue