From 7f6ddfa6dd6ad88eeb25328511399ff44ef19166 Mon Sep 17 00:00:00 2001 From: TheBv Date: Mon, 23 Oct 2023 18:43:49 +0200 Subject: [PATCH] fix: fixed crashes related to custom entity attributes. Closes #4987, Closes #4983 --- .../iceandfire/entity/EntityAmphithere.java | 32 +++++----- .../iceandfire/entity/EntityCockatrice.java | 2 +- .../iceandfire/entity/EntityCyclops.java | 6 +- .../iceandfire/entity/EntityDeathWorm.java | 41 ++++++------ .../iceandfire/entity/EntityDragonBase.java | 62 +++++++++++-------- .../iceandfire/entity/EntityGhost.java | 12 ++-- .../iceandfire/entity/EntityGorgon.java | 7 ++- .../iceandfire/entity/EntityHippocampus.java | 17 ++--- .../iceandfire/entity/EntityHydra.java | 2 +- .../iceandfire/entity/EntityMyrmexBase.java | 5 +- .../iceandfire/entity/EntitySeaSerpent.java | 2 +- .../iceandfire/entity/EntitySiren.java | 29 +++++---- .../iceandfire/entity/EntityTroll.java | 2 +- .../util/IHasCustomizableAttributes.java | 4 +- 14 files changed, 125 insertions(+), 98 deletions(-) diff --git a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityAmphithere.java b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityAmphithere.java index 2747398f3..8ea332f05 100644 --- a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityAmphithere.java +++ b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityAmphithere.java @@ -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; @@ -99,8 +100,6 @@ public class EntityAmphithere extends TamableAnimal implements ISyncMount, IAnim public EntityAmphithere(EntityType type, Level worldIn) { super(type, worldIn); - IHasCustomizableAttributes.applyAttributesForEntity(type, this); - this.setMaxUpStep(1); if (worldIn.isClientSide) { roll_buffer = new IFChainBuffer(); pitch_buffer = new IFChainBuffer(); @@ -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; } @@ -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)); @@ -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() { @@ -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; } @@ -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 @@ -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) this.getType(), this); } //TODO: Create entity placements @@ -929,7 +930,6 @@ public SpawnGroupData finalizeSpawn(@NotNull ServerLevelAccessor worldIn, @NotNu } - public void fall(float distance, float damageMultiplier) { } @@ -1071,6 +1071,7 @@ public void tick() { } } } + @Override public boolean requiresUpdateEveryTick() { return true; @@ -1119,6 +1120,7 @@ public void tick() { } } } + @Override public boolean requiresUpdateEveryTick() { return true; diff --git a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityCockatrice.java b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityCockatrice.java index c977756e4..a6aa75528 100644 --- a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityCockatrice.java +++ b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityCockatrice.java @@ -88,7 +88,6 @@ public EntityCockatrice(EntityType 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() { @@ -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) this.getType(), this); } @Override diff --git a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityCyclops.java b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityCyclops.java index 7c4595bfb..9e54f0957 100644 --- a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityCyclops.java +++ b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityCyclops.java @@ -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; @@ -68,7 +69,6 @@ public class EntityCyclops extends Monster implements IAnimatedEntity, IBlacklis public EntityCyclops(EntityType 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); @@ -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 @@ -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) this.getType(), this); } public int getVariant() { diff --git a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityDeathWorm.java b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityDeathWorm.java index 4ee8b9dde..0d6c7dab1 100644 --- a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityDeathWorm.java +++ b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityDeathWorm.java @@ -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; @@ -96,14 +97,16 @@ public class EntityDeathWorm extends TamableAnimal implements ISyncMount, ICusto public EntityDeathWorm(EntityType 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)); @@ -122,11 +125,11 @@ 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(); } } })); @@ -134,16 +137,17 @@ public boolean apply(@Nullable LivingEntity input) { 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 @@ -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) this.getType(), this); } private void setStateField(int i, boolean newState) { @@ -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) { diff --git a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityDragonBase.java b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityDragonBase.java index c04afc3b2..a3f35ac4f 100644 --- a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityDragonBase.java +++ b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityDragonBase.java @@ -64,6 +64,8 @@ import net.minecraft.world.entity.ai.goal.target.OwnerHurtTargetGoal; import net.minecraft.world.entity.ai.navigation.PathNavigation; import net.minecraft.world.entity.animal.Animal; +import net.minecraft.world.entity.animal.horse.AbstractChestedHorse; +import net.minecraft.world.entity.animal.horse.AbstractHorse; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -224,8 +226,6 @@ public abstract class EntityDragonBase extends TamableAnimal implements IPassabi public EntityDragonBase(EntityType t, Level world, DragonType type, double minimumDamage, double maximumDamage, double minimumHealth, double maximumHealth, double minimumSpeed, double maximumSpeed) { super(t, world); - IHasCustomizableAttributes.applyAttributesForEntity(t, this); - this.dragonType = type; this.minimumDamage = minimumDamage; this.maximumDamage = maximumDamage; @@ -255,16 +255,16 @@ public EntityDragonBase(EntityType t, Level world, DragonType type, double minim public static AttributeSupplier.Builder bakeAttributes() { return Mob.createMobAttributes() - //HEALTH - .add(Attributes.MAX_HEALTH, 20.0D) - //SPEED - .add(Attributes.MOVEMENT_SPEED, 0.3D) - //ATTACK - .add(Attributes.ATTACK_DAMAGE, 1) - //FOLLOW RANGE - .add(Attributes.FOLLOW_RANGE, Math.min(2048, IafConfig.dragonTargetSearchLength)) - //ARMOR - .add(Attributes.ARMOR, 4); + //HEALTH + .add(Attributes.MAX_HEALTH, 20.0D) + //SPEED + .add(Attributes.MOVEMENT_SPEED, 0.3D) + //ATTACK + .add(Attributes.ATTACK_DAMAGE, 1) + //FOLLOW RANGE + .add(Attributes.FOLLOW_RANGE, Math.min(2048, IafConfig.dragonTargetSearchLength)) + //ARMOR + .add(Attributes.ARMOR, 4); } @Override @@ -289,8 +289,8 @@ public String getHomeDimensionName() { @Override public boolean hasRestriction() { return this.hasHomePosition && - getHomeDimensionName().equals(DragonUtils.getDimensionName(this.level())) - || super.hasRestriction(); + getHomeDimensionName().equals(DragonUtils.getDimensionName(this.level())) + || super.hasRestriction(); } @Override @@ -464,7 +464,7 @@ protected void updateBurnTarget() { if (burningTarget != null && !this.isSleeping() && !this.isModelDead() && !this.isBaby()) { float maxDist = 115 * this.getDragonStage(); if (level().getBlockEntity(burningTarget) instanceof TileEntityDragonforgeInput && ((TileEntityDragonforgeInput) level().getBlockEntity(burningTarget)).isAssembled() - && this.distanceToSqr(burningTarget.getX() + 0.5D, burningTarget.getY() + 0.5D, burningTarget.getZ() + 0.5D) < maxDist && canPositionBeSeen(burningTarget.getX() + 0.5D, burningTarget.getY() + 0.5D, burningTarget.getZ() + 0.5D)) { + && this.distanceToSqr(burningTarget.getX() + 0.5D, burningTarget.getY() + 0.5D, burningTarget.getZ() + 0.5D) < maxDist && canPositionBeSeen(burningTarget.getX() + 0.5D, burningTarget.getY() + 0.5D, burningTarget.getZ() + 0.5D)) { this.getLookControl().setLookAt(burningTarget.getX() + 0.5D, burningTarget.getY() + 0.5D, burningTarget.getZ() + 0.5D, 180F, 180F); this.breathFireAtPos(burningTarget); this.setBreathingFire(true); @@ -820,6 +820,10 @@ public void readAdditionalSaveData(@NotNull CompoundTag compound) { if (compound.contains("CustomName", 8) && !compound.getString("CustomName").startsWith("TextComponent")) { this.setCustomName(Component.Serializer.fromJson(compound.getString("CustomName"))); } + + this.applyAttributesForEntity((EntityType) this.getType(), this); + + this.updateAttributes(); } public int getContainerSize() { @@ -1333,7 +1337,7 @@ public boolean canPositionBeSeen(final double x, final double y, final double z) public ItemStack getItemFromLootTable() { LootTable loottable = this.level().getServer().getServerResources().managers().getLootData().getLootTable(getDeadLootTable()); - LootParams.Builder lootparams$builder = (new LootParams.Builder((ServerLevel)this.level())).withParameter(LootContextParams.THIS_ENTITY, this).withParameter(LootContextParams.ORIGIN, this.position()).withParameter(LootContextParams.DAMAGE_SOURCE, this.level().damageSources().generic()); + LootParams.Builder lootparams$builder = (new LootParams.Builder((ServerLevel) this.level())).withParameter(LootContextParams.THIS_ENTITY, this).withParameter(LootContextParams.ORIGIN, this.position()).withParameter(LootContextParams.DAMAGE_SOURCE, this.level().damageSources().generic()); for (ItemStack itemstack : loottable.getRandomItems(lootparams$builder.create(LootContextParamSets.ENTITY))) { return itemstack; } @@ -1443,12 +1447,12 @@ public void breakBlock() { final int flightModifier = isFlying() && this.getTarget() != null ? -1 : 1; final int yMinus = calculateDownY(); BlockPos.betweenClosedStream( - (int) Math.floor(this.getBoundingBox().minX) - bounds, - (int) Math.floor(this.getBoundingBox().minY) + yMinus, - (int) Math.floor(this.getBoundingBox().minZ) - bounds, - (int) Math.floor(this.getBoundingBox().maxX) + bounds, - (int) Math.floor(this.getBoundingBox().maxY) + bounds + flightModifier, - (int) Math.floor(this.getBoundingBox().maxZ) + bounds + (int) Math.floor(this.getBoundingBox().minX) - bounds, + (int) Math.floor(this.getBoundingBox().minY) + yMinus, + (int) Math.floor(this.getBoundingBox().minZ) - bounds, + (int) Math.floor(this.getBoundingBox().maxX) + bounds, + (int) Math.floor(this.getBoundingBox().maxY) + bounds + flightModifier, + (int) Math.floor(this.getBoundingBox().maxZ) + bounds ).forEach(pos -> { if (MinecraftForge.EVENT_BUS.post(new GenericGriefEvent(this, pos.getX(), pos.getY(), pos.getZ()))) return; @@ -1635,7 +1639,6 @@ public SpawnGroupData finalizeSpawn(@NotNull ServerLevelAccessor worldIn, @NotNu this.growDragon(age); this.setVariant(new Random().nextInt(4)); this.setInSittingPose(false); - this.updateAttributes(); final double healthStep = (maximumHealth - minimumHealth) / 125; this.heal((Math.round(minimumHealth + (healthStep * age)))); this.usingGroundAttack = true; @@ -1975,6 +1978,7 @@ public float getDistanceSquared(Vec3 Vector3d) { public abstract Item getVariantEgg(int variant); public abstract Item getSummoningCrystal(); + @Override public boolean isImmobile() { return this.getHealth() <= 0.0F || isOrderedToSit() && !this.isVehicle() || this.isModelDead() || this.isPassenger(); @@ -2176,6 +2180,7 @@ else if (isInWater() || isInLava()) { * Update dragon pitch for the server on {@link IafDragonLogic#updateDragonServer()}
* For some reason the {@link LivingEntity#yo} failed to update the pitch properly when the movement is handled by client. * Use {@link LivingEntity#yOld} instead will properly update the pitch on server. + * * @param verticalDelta vertical distance from last update */ protected void updatePitch(final double verticalDelta) { @@ -2553,6 +2558,7 @@ public HitResult rayTraceRider(Entity rider, double blockReachDistance, float pa * Stage 4 / 75 Days / 1800000 Ticks / Render size 12.5 / Scale 4.375 | XZ 2.9 Y 1.6
* Stage 5 / 100 Days / 2400000 Ticks / Render size 20.0 / Scale 7.0 | XZ 5.2 Y 3.8
* Stage 5 / 125 Days / 3000000 Ticks / Render size 30.0 / Scale 7.0 | XZ 8.8 Y 7.4
+ * * @return rider's vertical position delta, in blocks * @see EntityDragonBase#getRideHorizontalBase() */ @@ -2562,6 +2568,7 @@ protected float getRideHeightBase() { /** * Provide a rough horizontal distance of rider's hitbox + * * @return rider's horizontal position delta, in blocks * @see EntityDragonBase#getRideHeightBase() */ @@ -2571,6 +2578,7 @@ protected float getRideHorizontalBase() { // For slowly raise rider position protected float riderWalkingExtraY = 0; + public Vec3 getRiderPosition() { // The old position is seems to be given by a series compute of magic numbers // So I replace the number with an even more magical yet better one I tuned @@ -2760,10 +2768,10 @@ public boolean canAttack(@NotNull LivingEntity target) { public boolean isPart(Entity entityHit) { return headPart != null && headPart.is(entityHit) || neckPart != null && neckPart.is(entityHit) || - leftWingLowerPart != null && leftWingLowerPart.is(entityHit) || rightWingLowerPart != null && rightWingLowerPart.is(entityHit) || - leftWingUpperPart != null && leftWingUpperPart.is(entityHit) || rightWingUpperPart != null && rightWingUpperPart.is(entityHit) || - tail1Part != null && tail1Part.is(entityHit) || tail2Part != null && tail2Part.is(entityHit) || - tail3Part != null && tail3Part.is(entityHit) || tail4Part != null && tail4Part.is(entityHit); + leftWingLowerPart != null && leftWingLowerPart.is(entityHit) || rightWingLowerPart != null && rightWingLowerPart.is(entityHit) || + leftWingUpperPart != null && leftWingUpperPart.is(entityHit) || rightWingUpperPart != null && rightWingUpperPart.is(entityHit) || + tail1Part != null && tail1Part.is(entityHit) || tail2Part != null && tail2Part.is(entityHit) || + tail3Part != null && tail3Part.is(entityHit) || tail4Part != null && tail4Part.is(entityHit); } @Override diff --git a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityGhost.java b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityGhost.java index b7b2c8627..4c0e650ab 100644 --- a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityGhost.java +++ b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityGhost.java @@ -64,7 +64,6 @@ public class EntityGhost extends Monster implements IAnimatedEntity, IVillagerFe public EntityGhost(EntityType type, Level worldIn) { super(type, worldIn); - IHasCustomizableAttributes.applyAttributesForEntity(type, this); ANIMATION_SCARE = Animation.create(30); ANIMATION_HIT = Animation.create(10); this.moveControl = new MoveHelper(this); @@ -343,21 +342,24 @@ public void setDaytimeCounter(int counter) { } @Override - public void readAdditionalSaveData(CompoundTag compound) { + public void readAdditionalSaveData(@NotNull CompoundTag compound) { + super.readAdditionalSaveData(compound); this.setColor(compound.getInt("Color")); this.setDaytimeMode(compound.getBoolean("DaytimeMode")); this.setDaytimeCounter(compound.getInt("DaytimeCounter")); this.setFromChest(compound.getBoolean("FromChest")); - super.readAdditionalSaveData(compound); + + this.applyAttributesForEntity((EntityType) this.getType(), this); } @Override - public void addAdditionalSaveData(CompoundTag compound) { + public void addAdditionalSaveData(@NotNull CompoundTag compound) { + super.addAdditionalSaveData(compound); compound.putInt("Color", this.getColor()); compound.putBoolean("DaytimeMode", this.isDaytimeMode()); compound.putInt("DaytimeCounter", this.getDaytimeCounter()); compound.putBoolean("FromChest", this.wasFromChest()); - super.addAdditionalSaveData(compound); + } public boolean isHauntedShoppingList() { diff --git a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityGorgon.java b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityGorgon.java index 415f47a40..bdc1f8953 100644 --- a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityGorgon.java +++ b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityGorgon.java @@ -14,6 +14,7 @@ import com.github.alexthe666.iceandfire.misc.IafSoundRegistry; import com.google.common.base.Predicate; import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.nbt.CompoundTag; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.effect.MobEffectInstance; @@ -47,7 +48,6 @@ public class EntityGorgon extends Monster implements IAnimatedEntity, IVillagerF public EntityGorgon(EntityType type, Level worldIn) { super(type, worldIn); - IHasCustomizableAttributes.applyAttributesForEntity(type, this); ANIMATION_SCARE = Animation.create(30); ANIMATION_HIT = Animation.create(10); } @@ -288,6 +288,11 @@ public void forcePreyToLook(LivingEntity mob) { } } + @Override + public void readAdditionalSaveData(CompoundTag pCompound) { + super.readAdditionalSaveData(pCompound); + this.applyAttributesForEntity((EntityType) this.getType(), this); + } @Override public int getAnimationTick() { diff --git a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityHippocampus.java b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityHippocampus.java index fe0b6985c..3b33ae756 100644 --- a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityHippocampus.java +++ b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityHippocampus.java @@ -47,6 +47,7 @@ import net.minecraft.world.level.ServerLevelAccessor; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.phys.Vec3; +import net.minecraftforge.common.ForgeMod; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; @@ -88,8 +89,6 @@ public class EntityHippocampus extends TamableAnimal implements ISyncMount, IAni public EntityHippocampus(EntityType t, Level worldIn) { super(t, worldIn); - IHasCustomizableAttributes.applyAttributesForEntity(t, this); - this.setMaxUpStep(1); ANIMATION_SPEAK = Animation.create(15); this.switchNavigator(true); if (worldIn.isClientSide) { @@ -113,12 +112,13 @@ public static int getIntFromArmor(ItemStack stack) { public static AttributeSupplier.Builder bakeAttributes() { return Mob.createMobAttributes() - //HEALTH - .add(Attributes.MAX_HEALTH, 40.0D) - //SPEED - .add(Attributes.MOVEMENT_SPEED, 0.3D) - //ATTACK - .add(Attributes.ATTACK_DAMAGE, 1.0D); + //HEALTH + .add(Attributes.MAX_HEALTH, 40.0D) + //SPEED + .add(Attributes.MOVEMENT_SPEED, 0.3D) + //ATTACK + .add(Attributes.ATTACK_DAMAGE, 1.0D) + .add(ForgeMod.STEP_HEIGHT.get(), 1.0F); } @Override @@ -384,6 +384,7 @@ public void readAdditionalSaveData(@NotNull CompoundTag compound) { this.inventory.setItem(j, ItemStack.of(CompoundNBT)); } } + this.applyAttributesForEntity((EntityType) this.getType(), this); } protected int getInventorySize() { diff --git a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityHydra.java b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityHydra.java index 9a1de261a..8c44e32af 100644 --- a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityHydra.java +++ b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityHydra.java @@ -75,7 +75,6 @@ public class EntityHydra extends Monster implements IAnimatedEntity, IMultipartE public EntityHydra(EntityType type, Level worldIn) { super(type, worldIn); - IHasCustomizableAttributes.applyAttributesForEntity(type, this); resetParts(); headDamageThreshold = Math.max(5, (float) IafConfig.hydraMaxHealth * 0.08F); } @@ -341,6 +340,7 @@ public void readAdditionalSaveData(@NotNull CompoundTag compound) { for (int i = 0; i < HEADS; i++) { headDamageTracker[i] = compound.getFloat("HeadDamage" + i); } + this.applyAttributesForEntity((EntityType) this.getType(), this); } @Override diff --git a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityMyrmexBase.java b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityMyrmexBase.java index 8914cf0b0..1711ef606 100644 --- a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityMyrmexBase.java +++ b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityMyrmexBase.java @@ -84,15 +84,11 @@ public abstract class EntityMyrmexBase extends Animal implements IAnimatedEntity private boolean leveledUp; @Nullable private Player customer; - private float flyingSpeed = 0.2F; public EntityMyrmexBase(EntityType t, Level worldIn) { super(t, worldIn); - IHasCustomizableAttributes.applyAttributesForEntity(t, this); - this.setMaxUpStep(1); this.navigation = createNavigator(worldIn, AdvancedPathNavigate.MovementType.CLIMBING); - //this.moveController = new GroundMoveHelper(this); } private static boolean isJungleBiome(Level world, BlockPos position) { @@ -317,6 +313,7 @@ public void readAdditionalSaveData(@NotNull CompoundTag tag) { this.villagerInventory.addItem(itemstack); } } + this.applyAttributesForEntity((EntityType) this.getType(), this); } diff --git a/src/main/java/com/github/alexthe666/iceandfire/entity/EntitySeaSerpent.java b/src/main/java/com/github/alexthe666/iceandfire/entity/EntitySeaSerpent.java index 5b3f31273..afc14da8a 100644 --- a/src/main/java/com/github/alexthe666/iceandfire/entity/EntitySeaSerpent.java +++ b/src/main/java/com/github/alexthe666/iceandfire/entity/EntitySeaSerpent.java @@ -105,7 +105,6 @@ public boolean apply(@Nullable Entity entity) { public EntitySeaSerpent(EntityType t, Level worldIn) { super(t, worldIn); - IHasCustomizableAttributes.applyAttributesForEntity(t, this); switchNavigator(false); this.noCulling = true; resetParts(1.0F); @@ -389,6 +388,7 @@ public void readAdditionalSaveData(@NotNull CompoundTag compound) { attackDecision = compound.getBoolean("AttackDecision"); this.setBreathing(compound.getBoolean("Breathing")); this.setAncient(compound.getBoolean("Ancient")); + this.applyAttributesForEntity((EntityType) this.getType(), this); } private void updateAttributes() { diff --git a/src/main/java/com/github/alexthe666/iceandfire/entity/EntitySiren.java b/src/main/java/com/github/alexthe666/iceandfire/entity/EntitySiren.java index eca75b1f6..feca42f69 100644 --- a/src/main/java/com/github/alexthe666/iceandfire/entity/EntitySiren.java +++ b/src/main/java/com/github/alexthe666/iceandfire/entity/EntitySiren.java @@ -50,6 +50,7 @@ import net.minecraft.world.level.pathfinder.BlockPathTypes; 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; @@ -86,9 +87,15 @@ public boolean apply(@Nullable Entity p_apply_1_) { public EntitySiren(EntityType t, Level worldIn) { super(t, worldIn); - IHasCustomizableAttributes.applyAttributesForEntity(t, this); this.switchNavigator(true); - this.setMaxUpStep(2); + if (worldIn.isClientSide) { + tail_buffer = new ChainBuffer(); + } + } + + @Override + protected void registerGoals() { + super.registerGoals(); this.goalSelector.addGoal(0, new SirenAIFindWaterTarget(this)); this.goalSelector.addGoal(1, new AquaticAIGetInWater(this, 1.0D)); this.goalSelector.addGoal(1, new AquaticAIGetOutOfWater(this, 1.0D)); @@ -109,9 +116,6 @@ public boolean apply(@Nullable AbstractVillager entity) { return EntitySiren.this.isAgressive(); } })); - if (worldIn.isClientSide) { - tail_buffer = new ChainBuffer(); - } } public static boolean isWearingEarplugs(LivingEntity entity) { @@ -351,7 +355,7 @@ public void readAdditionalSaveData(@NotNull CompoundTag tag) { this.setSinging(tag.getBoolean("Singing")); this.setSwimming(tag.getBoolean("Swimming")); this.setCharmed(tag.getBoolean("Passive")); - + this.applyAttributesForEntity((EntityType) this.getType(), this); } public boolean isSinging() { @@ -432,12 +436,13 @@ public void setSingingPose(int pose) { public static AttributeSupplier.Builder bakeAttributes() { return Mob.createMobAttributes() - //HEALTH - .add(Attributes.MAX_HEALTH, IafConfig.sirenMaxHealth) - //SPEED - .add(Attributes.MOVEMENT_SPEED, 0.25D) - //ATTACK - .add(Attributes.ATTACK_DAMAGE, 6.0D); + //HEALTH + .add(Attributes.MAX_HEALTH, IafConfig.sirenMaxHealth) + //SPEED + .add(Attributes.MOVEMENT_SPEED, 0.25D) + //ATTACK + .add(Attributes.ATTACK_DAMAGE, 6.0D) + .add(ForgeMod.STEP_HEIGHT.get(), 2.0F); } @Override diff --git a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityTroll.java b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityTroll.java index 7b882be0a..b22961560 100644 --- a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityTroll.java +++ b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityTroll.java @@ -70,7 +70,6 @@ public class EntityTroll extends Monster implements IAnimatedEntity, IVillagerFe public EntityTroll(EntityType t, Level worldIn) { super(t, worldIn); - IHasCustomizableAttributes.applyAttributesForEntity(t, this); } public static boolean canTrollSpawnOn(EntityType typeIn, ServerLevelAccessor worldIn, MobSpawnType reason, BlockPos pos, RandomSource randomIn) { @@ -199,6 +198,7 @@ public void readAdditionalSaveData(@NotNull CompoundTag compound) { this.setVariant(compound.getInt("Variant")); this.setWeapon(compound.getInt("Weapon")); this.stoneProgress = compound.getFloat("StoneProgress"); + this.applyAttributesForEntity((EntityType) this.getType(), this); } @Override diff --git a/src/main/java/com/github/alexthe666/iceandfire/entity/util/IHasCustomizableAttributes.java b/src/main/java/com/github/alexthe666/iceandfire/entity/util/IHasCustomizableAttributes.java index 7cc4b2d64..10678535d 100644 --- a/src/main/java/com/github/alexthe666/iceandfire/entity/util/IHasCustomizableAttributes.java +++ b/src/main/java/com/github/alexthe666/iceandfire/entity/util/IHasCustomizableAttributes.java @@ -14,12 +14,12 @@ public interface IHasCustomizableAttributes { Map, AttributeSupplier> ATTRIBUTE_MODIFIER_MAP = new HashMap<>(); - static void applyAttributesForEntity(EntityType type, M entity) { + default void applyAttributesForEntity(EntityType type, T entity) { entity.attributes = new AttributeMap(getAttributesForEntity(type, entity)); entity.setHealth(entity.getMaxHealth()); } - static AttributeSupplier getAttributesForEntity(EntityType type, M entity) { + default AttributeSupplier getAttributesForEntity(EntityType type, T entity) { if (!IafConfig.allowAttributeOverriding) return DefaultAttributes.getSupplier(type); if (ATTRIBUTE_MODIFIER_MAP.containsKey(type)) {