From b1589b66f1a0ab436fd920478404b379e59bd9ee Mon Sep 17 00:00:00 2001 From: Globox1997 Date: Tue, 23 Mar 2021 11:40:23 +0100 Subject: [PATCH] fixed orc --- .../java/net/adventurez/entity/OrcEntity.java | 19 +++++++++++-------- .../adventurez/entity/goal/OrcAttackGoal.java | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 src/main/java/net/adventurez/entity/goal/OrcAttackGoal.java diff --git a/src/main/java/net/adventurez/entity/OrcEntity.java b/src/main/java/net/adventurez/entity/OrcEntity.java index 965e7ff0..5fe7bf55 100644 --- a/src/main/java/net/adventurez/entity/OrcEntity.java +++ b/src/main/java/net/adventurez/entity/OrcEntity.java @@ -4,6 +4,7 @@ import org.jetbrains.annotations.Nullable; +import net.adventurez.entity.goal.OrcAttackGoal; import net.adventurez.entity.goal.OrcGroupGoal; import net.adventurez.entity.goal.WanderAroundVeryFarGoal; import net.adventurez.init.SoundInit; @@ -16,7 +17,6 @@ import net.minecraft.entity.ai.goal.FollowTargetGoal; import net.minecraft.entity.ai.goal.LookAroundGoal; import net.minecraft.entity.ai.goal.LookAtEntityGoal; -import net.minecraft.entity.ai.goal.MeleeAttackGoal; import net.minecraft.entity.ai.goal.RevengeGoal; import net.minecraft.entity.ai.goal.SwimGoal; import net.minecraft.entity.ai.goal.WanderAroundGoal; @@ -60,7 +60,7 @@ public static DefaultAttributeContainer.Builder createOrkAttributes() { public void initGoals() { super.initGoals(); this.goalSelector.add(0, new SwimGoal(this)); - this.goalSelector.add(1, new MeleeAttackGoal(this, 1.0D, true)); + this.goalSelector.add(1, new OrcAttackGoal(this, 1.0D, true)); this.goalSelector.add(3, new OrcGroupGoal(this)); this.goalSelector.add(4, new WanderAroundVeryFarGoal(this, 1.0D, 0.3F)); this.goalSelector.add(5, new WanderAroundGoal(this, 0.9D)); @@ -89,7 +89,7 @@ protected void initDataTracker() { @Override public void readCustomDataFromTag(CompoundTag tag) { - this.setSize(tag.getInt("OrkSize")); + this.setSize(tag.getInt("OrkSize"), false); super.readCustomDataFromTag(tag); } @@ -105,10 +105,13 @@ public int getSize() { return (Integer) this.dataTracker.get(ORK_SIZE); } - public void setSize(int size) { + public void setSize(int size, boolean healOrc) { this.dataTracker.set(ORK_SIZE, size); this.refreshPosition(); this.calculateDimensions(); + if (healOrc) { + this.setHealth(this.getMaxHealth()); + } } @Override @@ -162,11 +165,11 @@ protected float getActiveEyeHeight(EntityPose pose, EntityDimensions dimensions) public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData, @Nullable CompoundTag entityTag) { int random = this.random.nextInt(3) + 1; - this.setSize(random); - this.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH).setBaseValue((double) (16D + this.getSize() * 6D)); + this.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH).setBaseValue((double) (16D + random * 6D)); this.getAttributeInstance(EntityAttributes.GENERIC_MOVEMENT_SPEED) - .setBaseValue((double) (0.26F - 0.012F * (float) this.getSize())); - this.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE).setBaseValue((double) this.getSize() * 3D + 2D); + .setBaseValue((double) (0.26F - 0.012F * (float) random)); + this.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE).setBaseValue((double) random * 3D + 2D); + this.setSize(random, true); return super.initialize(world, difficulty, spawnReason, entityData, entityTag); } diff --git a/src/main/java/net/adventurez/entity/goal/OrcAttackGoal.java b/src/main/java/net/adventurez/entity/goal/OrcAttackGoal.java new file mode 100644 index 00000000..8cdb7973 --- /dev/null +++ b/src/main/java/net/adventurez/entity/goal/OrcAttackGoal.java @@ -0,0 +1,19 @@ +package net.adventurez.entity.goal; + +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.ai.goal.MeleeAttackGoal; +import net.minecraft.entity.mob.PathAwareEntity; + +public class OrcAttackGoal extends MeleeAttackGoal { + protected final PathAwareEntity mob; + + public OrcAttackGoal(PathAwareEntity mob, double speed, boolean pauseWhenMobIdle) { + super(mob, speed, pauseWhenMobIdle); + this.mob = mob; + } + + @Override + protected double getSquaredMaxAttackDistance(LivingEntity entity) { + return (double) (this.mob.getWidth() * 2.0F * this.mob.getWidth() + entity.getWidth()); + } +}