Skip to content

Commit

Permalink
fix: fixed crashes related to custom entity attributes. Closes #4987, C…
Browse files Browse the repository at this point in the history
…loses #4983
  • Loading branch information
TheBv committed Oct 23, 2023
1 parent 97d6f5b commit 7f6ddfa
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.ForgeMod;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -99,8 +100,6 @@ public class EntityAmphithere extends TamableAnimal implements ISyncMount, IAnim

public EntityAmphithere(EntityType<EntityAmphithere> type, Level worldIn) {
super(type, worldIn);
IHasCustomizableAttributes.applyAttributesForEntity(type, this);
this.setMaxUpStep(1);
if (worldIn.isClientSide) {
roll_buffer = new IFChainBuffer();
pitch_buffer = new IFChainBuffer();
Expand Down Expand Up @@ -158,7 +157,7 @@ public static BlockPos getPositionInOrbit(EntityAmphithere entity, Level world,
float angle = (0.01745329251F * possibleOrbitRadius);
double extraX = radius * Mth.sin((float) (Math.PI + angle));
double extraZ = radius * Mth.cos(angle);
BlockPos radialPos = BlockPos.containing(orbit.getX() + extraX, orbit.getY(),orbit.getZ() + extraZ);
BlockPos radialPos = BlockPos.containing(orbit.getX() + extraX, orbit.getY(), orbit.getZ() + extraZ);
entity.orbitRadius = possibleOrbitRadius;
return radialPos;
}
Expand Down Expand Up @@ -236,7 +235,7 @@ public float getWalkTargetValue(@NotNull BlockPos pos) {

@Override
protected void registerGoals() {
this.goalSelector.addGoal(0, new DragonAIRide(this));
this.goalSelector.addGoal(0, new DragonAIRide<>(this));
this.goalSelector.addGoal(0, new SitWhenOrderedToGoal(this));
this.goalSelector.addGoal(1, new FloatGoal(this));
this.goalSelector.addGoal(1, new AmphithereAIAttackMelee(this, 1.0D, true));
Expand All @@ -250,7 +249,7 @@ protected void registerGoals() {
this.targetSelector.addGoal(1, new OwnerHurtTargetGoal(this));
this.targetSelector.addGoal(2, new OwnerHurtByTargetGoal(this));
this.targetSelector.addGoal(3, new AmphithereAIHurtByTarget(this, false, new Class[0]));
this.targetSelector.addGoal(3, new AmphithereAITargetItems(this, false));
this.targetSelector.addGoal(3, new AmphithereAITargetItems<>(this, false));
}

public boolean isStill() {
Expand All @@ -267,7 +266,7 @@ protected void switchNavigator(int navigatorType) {
this.navigation = new PathNavigateFlyingCreature(this, level());
this.navigatorType = 1;
} else {
this.moveControl = new IafDragonFlightManager.PlayerFlightMoveHelper(this);
this.moveControl = new IafDragonFlightManager.PlayerFlightMoveHelper<>(this);
this.navigation = new PathNavigateFlyingCreature(this, level());
this.navigatorType = 2;
}
Expand Down Expand Up @@ -575,14 +574,15 @@ public boolean isAlliedTo(@NotNull Entity entityIn) {

public static AttributeSupplier.Builder bakeAttributes() {
return Mob.createMobAttributes()
//HEALTH
.add(Attributes.MAX_HEALTH, IafConfig.amphithereMaxHealth)
//SPEED
.add(Attributes.MOVEMENT_SPEED, 0.4D)
//ATTACK
.add(Attributes.ATTACK_DAMAGE, IafConfig.amphithereAttackStrength)
//FOLLOW RANGE
.add(Attributes.FOLLOW_RANGE, 32.0D);
//HEALTH
.add(Attributes.MAX_HEALTH, IafConfig.amphithereMaxHealth)
//SPEED
.add(Attributes.MOVEMENT_SPEED, 0.4D)
//ATTACK
.add(Attributes.ATTACK_DAMAGE, IafConfig.amphithereAttackStrength)
//FOLLOW RANGE
.add(Attributes.FOLLOW_RANGE, 32.0D)
.add(ForgeMod.STEP_HEIGHT.get(), 1);
}

@Override
Expand Down Expand Up @@ -628,6 +628,7 @@ public void readAdditionalSaveData(@NotNull CompoundTag compound) {
homePos = new BlockPos(compound.getInt("HomeAreaX"), compound.getInt("HomeAreaY"), compound.getInt("HomeAreaZ"));
}
this.setCommand(compound.getInt("Command"));
this.applyAttributesForEntity((EntityType<? extends LivingEntity>) this.getType(), this);
}

//TODO: Create entity placements
Expand Down Expand Up @@ -929,7 +930,6 @@ public SpawnGroupData finalizeSpawn(@NotNull ServerLevelAccessor worldIn, @NotNu
}



public void fall(float distance, float damageMultiplier) {
}

Expand Down Expand Up @@ -1071,6 +1071,7 @@ public void tick() {
}
}
}

@Override
public boolean requiresUpdateEveryTick() {
return true;
Expand Down Expand Up @@ -1119,6 +1120,7 @@ public void tick() {
}
}
}

@Override
public boolean requiresUpdateEveryTick() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public EntityCockatrice(EntityType<EntityCockatrice> type, Level worldIn) {
this.lookControl = new IAFLookHelper(this);
aiStare = new CockatriceAIStareAttack(this, 1.0D, 0, 15.0F);
aiMelee = new EntityAIAttackMeleeNoCooldown(this, 1.5D, false);
IHasCustomizableAttributes.applyAttributesForEntity(type, this);
}

public static AttributeSupplier.Builder bakeAttributes() {
Expand Down Expand Up @@ -362,6 +361,7 @@ public void readAdditionalSaveData(@NotNull CompoundTag tag) {
if (hasHomePosition && tag.getInt("HomeAreaX") != 0 && tag.getInt("HomeAreaY") != 0 && tag.getInt("HomeAreaZ") != 0) {
homePos = new HomePosition(tag, this.level());
}
this.applyAttributesForEntity((EntityType<? extends LivingEntity>) this.getType(), this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.pathfinder.BlockPathTypes;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.ForgeMod;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.NotNull;
Expand All @@ -68,7 +69,6 @@ public class EntityCyclops extends Monster implements IAnimatedEntity, IBlacklis

public EntityCyclops(EntityType<EntityCyclops> type, Level worldIn) {
super(type, worldIn);
IHasCustomizableAttributes.applyAttributesForEntity(type, this);
this.setMaxUpStep(2.5F);
this.setPathfindingMalus(BlockPathTypes.WATER, -1.0F);
this.setPathfindingMalus(BlockPathTypes.FENCE, 0.0F);
Expand All @@ -90,7 +90,8 @@ public static AttributeSupplier.Builder bakeAttributes() {
//FOLLOW RANGE
.add(Attributes.FOLLOW_RANGE, 32D)
//ARMOR
.add(Attributes.ARMOR, 20.0D);
.add(Attributes.ARMOR, 20.0D)
.add(ForgeMod.STEP_HEIGHT.get(), 2.5F);
}

@Override
Expand Down Expand Up @@ -202,6 +203,7 @@ public void readAdditionalSaveData(@NotNull CompoundTag compound) {
super.readAdditionalSaveData(compound);
this.setBlinded(compound.getBoolean("Blind"));
this.setVariant(compound.getInt("Variant"));
this.applyAttributesForEntity((EntityType<? extends LivingEntity>) this.getType(), this);
}

public int getVariant() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.common.ForgeMod;
import net.minecraftforge.common.MinecraftForge;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -96,14 +97,16 @@ public class EntityDeathWorm extends TamableAnimal implements ISyncMount, ICusto

public EntityDeathWorm(EntityType<EntityDeathWorm> type, Level worldIn) {
super(type, worldIn);
IHasCustomizableAttributes.applyAttributesForEntity(type, this);
this.lookHelper = new IAFLookHelper(this);
this.noCulling = true;
this.setMaxUpStep(1);
if (worldIn.isClientSide) {
tail_buffer = new ChainBuffer();
}
this.switchNavigator(false);
}

@Override
protected void registerGoals() {
this.goalSelector.addGoal(0, new EntityGroundAIRide<>(this));
this.goalSelector.addGoal(1, new FloatGoal(this));
this.goalSelector.addGoal(2, new DeathWormAIAttack(this));
Expand All @@ -122,28 +125,29 @@ public boolean apply(@Nullable LivingEntity input) {
return input instanceof Monster;
} else {
return (IafConfig.deathWormAttackMonsters ?
input instanceof LivingEntity && DragonUtils.isAlive(input) && !input.isInWater() :
(input instanceof Animal || input instanceof Player)) &&
DragonUtils.isAlive(input) && !(input instanceof EntityDragonBase &&
((EntityDragonBase) input).isModelDead()) && !EntityDeathWorm.this.isOwnedBy(input)
&& !input.isInWater();
input instanceof LivingEntity && DragonUtils.isAlive(input) && !input.isInWater() :
(input instanceof Animal || input instanceof Player)) &&
DragonUtils.isAlive(input) && !(input instanceof EntityDragonBase &&
((EntityDragonBase) input).isModelDead()) && !EntityDeathWorm.this.isOwnedBy(input)
&& !input.isInWater();
}
}
}));
}

public static AttributeSupplier.Builder bakeAttributes() {
return Mob.createMobAttributes()
//HEALTH
.add(Attributes.MAX_HEALTH, IafConfig.deathWormMaxHealth)
//SPEED
.add(Attributes.MOVEMENT_SPEED, 0.15D)
//ATTACK
.add(Attributes.ATTACK_DAMAGE, IafConfig.deathWormAttackStrength)
//FOLLOW RANGE
.add(Attributes.FOLLOW_RANGE, IafConfig.deathWormTargetSearchLength)
//ARMOR
.add(Attributes.ARMOR, 3);
//HEALTH
.add(Attributes.MAX_HEALTH, IafConfig.deathWormMaxHealth)
//SPEED
.add(Attributes.MOVEMENT_SPEED, 0.15D)
//ATTACK
.add(Attributes.ATTACK_DAMAGE, IafConfig.deathWormAttackStrength)
//FOLLOW RANGE
.add(Attributes.FOLLOW_RANGE, IafConfig.deathWormTargetSearchLength)
//ARMOR
.add(Attributes.ARMOR, 3)
.add(ForgeMod.STEP_HEIGHT.get(), 1.0F);
}

@Override
Expand Down Expand Up @@ -303,6 +307,7 @@ public void readAdditionalSaveData(@NotNull CompoundTag compound) {
this.setWormAge(compound.getInt("WormAge"));
this.setWormHome(BlockPos.of(compound.getLong("WormHome")));
this.willExplode = compound.getBoolean("WillExplode");
this.applyAttributesForEntity((EntityType<? extends LivingEntity>) this.getType(), this);
}

private void setStateField(int i, boolean newState) {
Expand Down Expand Up @@ -477,7 +482,7 @@ protected void moveTowardsClosestSpace(double x, double y, double z) {
for (Direction direction1 : new Direction[]{Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST, Direction.UP}) {
blockpos$mutable.setWithOffset(vec3i, direction1);
if (!this.level().getBlockState(blockpos$mutable).isCollisionShapeFullBlock(this.level(), blockpos$mutable)
|| level().getBlockState(blockpos$mutable).is(BlockTags.SAND)) {
|| level().getBlockState(blockpos$mutable).is(BlockTags.SAND)) {
double d1 = vector3d.get(direction1.getAxis());
double d2 = direction1.getAxisDirection() == Direction.AxisDirection.POSITIVE ? 1.0D - d1 : d1;
if (d2 < d0) {
Expand Down
Loading

0 comments on commit 7f6ddfa

Please sign in to comment.