Skip to content

Commit

Permalink
fixed orc
Browse files Browse the repository at this point in the history
  • Loading branch information
Globox1997 committed Mar 23, 2021
1 parent ac99b6d commit b1589b6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/main/java/net/adventurez/entity/OrcEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);

}
Expand All @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/net/adventurez/entity/goal/OrcAttackGoal.java
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit b1589b6

Please sign in to comment.