From 3fb311fd03fe57748515d5a01efd9a2691bb4845 Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 29 Sep 2020 23:13:48 +0200 Subject: [PATCH] Generalize and added golem behaviours --- .../entity/behaviour/EntityBehaviour.java | 10 +++++-- ...avagerBehaviour.java => MobBehaviour.java} | 8 ++--- ...aviour.java => RangedAttackBehaviour.java} | 30 +++++++++++++------ 3 files changed, 33 insertions(+), 15 deletions(-) rename src/main/java/com/minelittlepony/unicopia/entity/behaviour/{RavagerBehaviour.java => MobBehaviour.java} (67%) rename src/main/java/com/minelittlepony/unicopia/entity/behaviour/{LlamaBehaviour.java => RangedAttackBehaviour.java} (52%) diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java index 7c72d0c9..a44a6728 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java @@ -17,9 +17,14 @@ import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.FallingBlockEntity; import net.minecraft.entity.LivingEntity; 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.player.PlayerEntity; +import net.minecraft.entity.projectile.LlamaSpitEntity; +import net.minecraft.entity.projectile.thrown.SnowballEntity; import net.minecraft.item.ItemStack; +import net.minecraft.sound.SoundEvents; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -217,13 +222,14 @@ public class EntityBehaviour { static { 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(VillagerBehaviour::new, EntityType.VILLAGER, EntityType.WANDERING_TRADER); register(SheepBehaviour::new, EntityType.SHEEP); register(BeeBehaviour::new, EntityType.BEE); register(EndermanBehaviour::new, EntityType.ENDERMAN); - register(LlamaBehaviour::new, EntityType.LLAMA, EntityType.TRADER_LLAMA); + EntityBehaviour.register(() -> new RangedAttackBehaviour<>(SoundEvents.ENTITY_LLAMA_SPIT, LlamaSpitEntity::new), EntityType.LLAMA, EntityType.TRADER_LLAMA); + EntityBehaviour.register(() -> new RangedAttackBehaviour<>(SoundEvents.ENTITY_SNOW_GOLEM_SHOOT, SnowballEntity::new), EntityType.SNOW_GOLEM); register(SpellcastingIllagerBehaviour::new, EntityType.ILLUSIONER, EntityType.EVOKER); register(ShulkerBehaviour::new, EntityType.SHULKER); register(CreeperBehaviour::new, EntityType.CREEPER); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/RavagerBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MobBehaviour.java similarity index 67% rename from src/main/java/com/minelittlepony/unicopia/entity/behaviour/RavagerBehaviour.java rename to src/main/java/com/minelittlepony/unicopia/entity/behaviour/MobBehaviour.java index 563febaa..e4312f29 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/RavagerBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MobBehaviour.java @@ -6,16 +6,16 @@ import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.util.RayTraceHelper; import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.mob.RavagerEntity; +import net.minecraft.entity.mob.MobEntity; -public class RavagerBehaviour extends EntityBehaviour { +public class MobBehaviour extends EntityBehaviour { @Override - public void update(Caster source, RavagerEntity entity, Spell spell) { + public void update(Caster source, MobEntity entity, Spell spell) { if (source instanceof Pony) { 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)); } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/LlamaBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/RangedAttackBehaviour.java similarity index 52% rename from src/main/java/com/minelittlepony/unicopia/entity/behaviour/LlamaBehaviour.java rename to src/main/java/com/minelittlepony/unicopia/entity/behaviour/RangedAttackBehaviour.java index 7be7e470..da994ae1 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/LlamaBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/RangedAttackBehaviour.java @@ -1,24 +1,37 @@ package com.minelittlepony.unicopia.entity.behaviour; +import java.util.function.BiFunction; 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 { +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 extends EntityBehaviour { + + private final BiFunction projectileSupplier; + + private final SoundEvent sound; + + public RangedAttackBehaviour(SoundEvent sound, BiFunction projectileSupplier) { + this.sound = sound; + this.projectileSupplier = projectileSupplier; + } @Override - public void update(Caster source, LlamaEntity entity, Spell spell) { + public void update(Caster source, T entity, Spell spell) { if (source instanceof Pony) { Pony player = (Pony)source; 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); @@ -27,13 +40,12 @@ public class LlamaBehaviour extends EntityBehaviour { if (!entity.isSilent()) { 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); } entity.world.spawnEntity(spit); } } - } }