Generalize and added golem behaviours

This commit is contained in:
Sollace 2020-09-29 23:13:48 +02:00
parent 2fd97fedcf
commit 3fb311fd03
3 changed files with 33 additions and 15 deletions

View file

@ -17,9 +17,14 @@ import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.FallingBlockEntity; import net.minecraft.entity.FallingBlockEntity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.AbstractSkeletonEntity; import net.minecraft.entity.mob.AbstractSkeletonEntity;
import net.minecraft.entity.passive.LlamaEntity;
import net.minecraft.entity.passive.SnowGolemEntity;
import net.minecraft.entity.passive.TameableEntity; import net.minecraft.entity.passive.TameableEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.LlamaSpitEntity;
import net.minecraft.entity.projectile.thrown.SnowballEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -217,13 +222,14 @@ public class EntityBehaviour<T extends Entity> {
static { static {
register(FallingBlockBehaviour::new, EntityType.FALLING_BLOCK); register(FallingBlockBehaviour::new, EntityType.FALLING_BLOCK);
register(RavagerBehaviour::new, EntityType.RAVAGER); register(MobBehaviour::new, EntityType.RAVAGER, EntityType.IRON_GOLEM);
register(RabbitBehaviour::new, EntityType.RABBIT); register(RabbitBehaviour::new, EntityType.RABBIT);
register(VillagerBehaviour::new, EntityType.VILLAGER, EntityType.WANDERING_TRADER); register(VillagerBehaviour::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(EndermanBehaviour::new, EntityType.ENDERMAN); register(EndermanBehaviour::new, EntityType.ENDERMAN);
register(LlamaBehaviour::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);
register(SpellcastingIllagerBehaviour::new, EntityType.ILLUSIONER, EntityType.EVOKER); register(SpellcastingIllagerBehaviour::new, EntityType.ILLUSIONER, EntityType.EVOKER);
register(ShulkerBehaviour::new, EntityType.SHULKER); register(ShulkerBehaviour::new, EntityType.SHULKER);
register(CreeperBehaviour::new, EntityType.CREEPER); register(CreeperBehaviour::new, EntityType.CREEPER);

View file

@ -6,16 +6,16 @@ import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.RayTraceHelper; import com.minelittlepony.unicopia.util.RayTraceHelper;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.RavagerEntity; import net.minecraft.entity.mob.MobEntity;
public class RavagerBehaviour extends EntityBehaviour<RavagerEntity> { public class MobBehaviour extends EntityBehaviour<MobEntity> {
@Override @Override
public void update(Caster<?> source, RavagerEntity entity, Spell spell) { public void update(Caster<?> source, MobEntity entity, Spell spell) {
if (source instanceof Pony) { if (source instanceof Pony) {
Pony player = (Pony)source; Pony player = (Pony)source;
if (player.sneakingChanged() && this.isSneakingOnGround(source)) { if (player.sneakingChanged() && isSneakingOnGround(source)) {
entity.tryAttack(RayTraceHelper.findEntity(source.getEntity(), 6, 1, e -> e instanceof LivingEntity).orElse(entity)); entity.tryAttack(RayTraceHelper.findEntity(source.getEntity(), 6, 1, e -> e instanceof LivingEntity).orElse(entity));
} }
} }

View file

@ -1,24 +1,37 @@
package com.minelittlepony.unicopia.entity.behaviour; package com.minelittlepony.unicopia.entity.behaviour;
import java.util.function.BiFunction;
import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.Caster;
import com.minelittlepony.unicopia.ability.magic.Spell; import com.minelittlepony.unicopia.ability.magic.Spell;
import com.minelittlepony.unicopia.entity.player.Pony; 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> { import net.minecraft.entity.Entity;
import net.minecraft.entity.ai.RangedAttackMob;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
public class RangedAttackBehaviour<T extends Entity & RangedAttackMob> extends EntityBehaviour<T> {
private final BiFunction<World, T, ProjectileEntity> projectileSupplier;
private final SoundEvent sound;
public RangedAttackBehaviour(SoundEvent sound, BiFunction<World, T, ProjectileEntity> projectileSupplier) {
this.sound = sound;
this.projectileSupplier = projectileSupplier;
}
@Override @Override
public void update(Caster<?> source, LlamaEntity entity, Spell spell) { public void update(Caster<?> source, T entity, Spell spell) {
if (source instanceof Pony) { if (source instanceof Pony) {
Pony player = (Pony)source; Pony player = (Pony)source;
if (player.sneakingChanged() && isSneakingOnGround(player)) { if (player.sneakingChanged() && isSneakingOnGround(player)) {
LlamaSpitEntity spit = new LlamaSpitEntity(entity.world, entity); ProjectileEntity spit = projectileSupplier.apply(entity.world, entity);
Vec3d rot = source.getEntity().getRotationVec(1); Vec3d rot = source.getEntity().getRotationVec(1);
@ -27,13 +40,12 @@ public class LlamaBehaviour extends EntityBehaviour<LlamaEntity> {
if (!entity.isSilent()) { if (!entity.isSilent()) {
entity.world.playSound(null, entity.getX(), entity.getY(), entity.getZ(), entity.world.playSound(null, entity.getX(), entity.getY(), entity.getZ(),
SoundEvents.ENTITY_LLAMA_SPIT, entity.getSoundCategory(), 1, sound, entity.getSoundCategory(), 1,
1 + (entity.world.random.nextFloat() - entity.world.random.nextFloat()) * 0.2F); 1 + (entity.world.random.nextFloat() - entity.world.random.nextFloat()) * 0.2F);
} }
entity.world.spawnEntity(spit); entity.world.spawnEntity(spit);
} }
} }
} }
} }