Skip to content

Commit 54b659b

Browse files
committed
fix #4361 fix #3845
1 parent 8932e64 commit 54b659b

File tree

3 files changed

+28
-33
lines changed

3 files changed

+28
-33
lines changed

src/main/java/com/github/alexthe666/iceandfire/entity/EntityCockatrice.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public boolean apply(@Nullable Entity entity) {
134134
return !((PlayerEntity) entity).isCreative() && !entity.isSpectator();
135135
}else{
136136
return ((entity instanceof IMob) && EntityCockatrice.this.isTamed() && !(entity instanceof CreeperEntity) && !(entity instanceof ZombifiedPiglinEntity) && !(entity instanceof EndermanEntity) ||
137-
ServerEvents.isAnimaniaFerret(entity) && !ServerEvents.isAnimaniaChicken(entity));
137+
ServerEvents.doesScareCockatrice(entity) && !ServerEvents.isChicken(entity));
138138
}
139139
}
140140
}));
@@ -164,12 +164,12 @@ public BlockPos getHomePosition() {
164164
}
165165

166166
public boolean isOnSameTeam(Entity entityIn) {
167-
return ServerEvents.isAnimaniaChicken(entityIn) || super.isOnSameTeam(entityIn);
167+
return ServerEvents.isChicken(entityIn) || super.isOnSameTeam(entityIn);
168168
}
169169

170170
@Override
171171
public boolean attackEntityFrom(DamageSource source, float damage) {
172-
if (source.getTrueSource() != null && ServerEvents.isAnimaniaFerret(source.getTrueSource())) {
172+
if (source.getTrueSource() != null && ServerEvents.doesScareCockatrice(source.getTrueSource())) {
173173
damage *= 5;
174174
}
175175
if (source == DamageSource.IN_WALL) {
@@ -179,7 +179,7 @@ public boolean attackEntityFrom(DamageSource source, float damage) {
179179
}
180180

181181
private boolean canUseStareOn(Entity entity) {
182-
return (!(entity instanceof IBlacklistedFromStatues) || ((IBlacklistedFromStatues) entity).canBeTurnedToStone()) && !ServerEvents.isAnimaniaFerret(entity);
182+
return (!(entity instanceof IBlacklistedFromStatues) || ((IBlacklistedFromStatues) entity).canBeTurnedToStone()) && !ServerEvents.doesScareCockatrice(entity);
183183
}
184184

185185
private void switchAI(boolean melee) {
@@ -656,7 +656,7 @@ public int getAttackDuration() {
656656
private boolean shouldMelee() {
657657
boolean blindness = this.isPotionActive(Effects.BLINDNESS) || this.getAttackTarget() != null && this.getAttackTarget().isPotionActive(Effects.BLINDNESS);
658658
if (this.getAttackTarget() != null) {
659-
return this.getDistance(this.getAttackTarget()) < 4D || ServerEvents.isAnimaniaFerret(this.getAttackTarget()) || blindness || !this.canUseStareOn(this.getAttackTarget());
659+
return this.getDistance(this.getAttackTarget()) < 4D || ServerEvents.doesScareCockatrice(this.getAttackTarget()) || blindness || !this.canUseStareOn(this.getAttackTarget());
660660
}
661661
return false;
662662
}

src/main/java/com/github/alexthe666/iceandfire/entity/EntityCyclops.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ protected void registerGoals() {
114114
this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, LivingEntity.class, 0, true, true, new Predicate<LivingEntity>() {
115115
@Override
116116
public boolean apply(@Nullable LivingEntity entity) {
117-
return !EntityGorgon.isStoneMob(entity) && DragonUtils.isAlive(entity) && !(entity instanceof WaterMobEntity) && (!(entity instanceof PlayerEntity) || ((PlayerEntity)entity).isCreative()) && !(entity instanceof EntityCyclops) && !ServerEvents.isAnimaniaSheep(entity) && !(entity instanceof AnimalEntity && !(entity instanceof WolfEntity || entity instanceof PolarBearEntity || entity instanceof EntityDragonBase)) || entity instanceof EntityGorgon || entity instanceof AbstractVillagerEntity;
117+
return !EntityGorgon.isStoneMob(entity) && DragonUtils.isAlive(entity) && !(entity instanceof WaterMobEntity) && (!(entity instanceof PlayerEntity) || ((PlayerEntity)entity).isCreative()) && !(entity instanceof EntityCyclops) && !ServerEvents.isSheep(entity) && !(entity instanceof AnimalEntity && !(entity instanceof WolfEntity || entity instanceof PolarBearEntity || entity instanceof EntityDragonBase)) || entity instanceof EntityGorgon || entity instanceof AbstractVillagerEntity;
118118
}
119119
}));
120120

@@ -129,7 +129,7 @@ public boolean apply(@Nullable PlayerEntity entity) {
129129
}
130130

131131
protected void collideWithEntity(Entity entityIn) {
132-
if (!ServerEvents.isAnimaniaSheep(entityIn)) {
132+
if (!ServerEvents.isSheep(entityIn)) {
133133
entityIn.applyEntityCollision(this);
134134
}
135135
}

src/main/java/com/github/alexthe666/iceandfire/event/ServerEvents.java

+21-26
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
import com.github.alexthe666.iceandfire.message.MessageSwingArm;
3737
import com.github.alexthe666.iceandfire.misc.IafDamageRegistry;
3838
import com.github.alexthe666.iceandfire.misc.IafTagRegistry;
39-
import com.github.alexthe666.iceandfire.pathfinding.raycoms.AdvancedPathNavigate;
40-
import com.github.alexthe666.iceandfire.pathfinding.raycoms.Pathfinding;
4139
import com.github.alexthe666.iceandfire.recipe.IafRecipeRegistry;
4240
import com.github.alexthe666.iceandfire.world.gen.WorldGenFireDragonCave;
4341
import com.github.alexthe666.iceandfire.world.gen.WorldGenIceDragonCave;
@@ -49,11 +47,7 @@
4947
import net.minecraft.block.WallBlock;
5048
import net.minecraft.enchantment.EnchantmentHelper;
5149
import net.minecraft.enchantment.Enchantments;
52-
import net.minecraft.entity.CreatureEntity;
53-
import net.minecraft.entity.Entity;
54-
import net.minecraft.entity.LivingEntity;
55-
import net.minecraft.entity.MobEntity;
56-
import net.minecraft.entity.SpawnReason;
50+
import net.minecraft.entity.*;
5751
import net.minecraft.entity.ai.attributes.Attribute;
5852
import net.minecraft.entity.ai.attributes.AttributeModifier;
5953
import net.minecraft.entity.ai.attributes.Attributes;
@@ -63,7 +57,6 @@
6357
import net.minecraft.entity.monster.WitherSkeletonEntity;
6458
import net.minecraft.entity.passive.AnimalEntity;
6559
import net.minecraft.entity.passive.TameableEntity;
66-
import net.minecraft.entity.passive.horse.AbstractHorseEntity;
6760
import net.minecraft.entity.player.PlayerEntity;
6861
import net.minecraft.entity.projectile.AbstractArrowEntity;
6962
import net.minecraft.inventory.EquipmentSlotType;
@@ -82,10 +75,8 @@
8275
import net.minecraft.potion.EffectInstance;
8376
import net.minecraft.potion.Effects;
8477
import net.minecraft.tags.EntityTypeTags;
85-
import net.minecraft.util.CombatEntry;
86-
import net.minecraft.util.CombatTracker;
87-
import net.minecraft.util.DamageSource;
88-
import net.minecraft.util.SoundEvents;
78+
import net.minecraft.tags.ITag;
79+
import net.minecraft.util.*;
8980
import net.minecraft.util.math.AxisAlignedBB;
9081
import net.minecraft.util.math.EntityRayTraceResult;
9182
import net.minecraft.util.math.MathHelper;
@@ -217,25 +208,29 @@ public static float updateRotation(float angle, float targetAngle, float maxIncr
217208
return angle + f;
218209
}
219210

220-
public static boolean isLivestock(Entity entity) {
221-
return entity != null && EntityTypeTags.getCollection().get(IafTagRegistry.FEAR_DRAGONS).contains(entity.getType());
211+
private static boolean isInEntityTag(ResourceLocation loc, EntityType type) {
212+
ITag<EntityType<?>> tag = EntityTypeTags.getCollection().get(loc);
213+
return tag != null && tag.contains(type);
214+
}
222215

216+
public static boolean isLivestock(Entity entity) {
217+
return entity != null && isInEntityTag(IafTagRegistry.FEAR_DRAGONS, entity.getType());
223218
}
224219

225220
public static boolean isVillager(Entity entity) {
226-
return entity != null && EntityTypeTags.getCollection().get(IafTagRegistry.VILLAGERS).contains(entity.getType());
221+
return entity != null && isInEntityTag(IafTagRegistry.VILLAGERS, entity.getType());
227222
}
228223

229-
public static boolean isAnimaniaSheep(Entity entity) {
230-
return entity != null && EntityTypeTags.getCollection().get(IafTagRegistry.SHEEP).contains(entity.getType());
224+
public static boolean isSheep(Entity entity) {
225+
return entity != null && isInEntityTag(IafTagRegistry.SHEEP, entity.getType());
231226
}
232227

233-
public static boolean isAnimaniaChicken(Entity entity) {
234-
return entity != null && EntityTypeTags.getCollection().get(IafTagRegistry.CHICKENS).contains(entity.getType());
228+
public static boolean isChicken(Entity entity) {
229+
return entity != null && isInEntityTag(IafTagRegistry.CHICKENS, entity.getType());
235230
}
236231

237-
public static boolean isAnimaniaFerret(Entity entity) {
238-
return entity != null && EntityTypeTags.getCollection().get(IafTagRegistry.SCARES_COCKATRICES).contains(entity.getType());
232+
public static boolean doesScareCockatrice(Entity entity) {
233+
return entity != null && isInEntityTag(IafTagRegistry.SCARES_COCKATRICES, entity.getType());
239234
}
240235

241236
public static boolean isRidingOrBeingRiddenBy(Entity first, Entity entityIn) {
@@ -388,7 +383,7 @@ public void onLivingAttacked(LivingAttackEvent event) {
388383
if (properties != null && properties.inLoveTicks > 0) {
389384
event.setCanceled(true);
390385
}
391-
if (isAnimaniaChicken(event.getEntityLiving()) && attacker instanceof LivingEntity) {
386+
if (isChicken(event.getEntityLiving()) && attacker instanceof LivingEntity) {
392387
signalChickenAlarm(event.getEntityLiving(), (LivingEntity) attacker);
393388
}
394389
if (DragonUtils.isVillager(event.getEntityLiving()) && attacker instanceof LivingEntity) {
@@ -403,7 +398,7 @@ public void onLivingAttacked(LivingAttackEvent event) {
403398
public void onLivingSetTarget(LivingSetAttackTargetEvent event) {
404399
if (event.getTarget() != null) {
405400
LivingEntity attacker = event.getEntityLiving();
406-
if (isAnimaniaChicken(event.getTarget())) {
401+
if (isChicken(event.getTarget())) {
407402
signalChickenAlarm(event.getTarget(), attacker);
408403
}
409404
if (DragonUtils.isVillager(event.getTarget())) {
@@ -414,7 +409,7 @@ public void onLivingSetTarget(LivingSetAttackTargetEvent event) {
414409

415410
@SubscribeEvent
416411
public void onPlayerAttack(AttackEntityEvent event) {
417-
if (event.getTarget() != null && isAnimaniaSheep(event.getTarget())) {
412+
if (event.getTarget() != null && isSheep(event.getTarget())) {
418413
float dist = IafConfig.cyclopesSheepSearchLength;
419414
List<Entity> list = event.getTarget().world.getEntitiesWithinAABBExcludingEntity(event.getPlayer(), event.getPlayer().getBoundingBox().expand(dist, dist, dist));
420415
if (!list.isEmpty()) {
@@ -566,7 +561,7 @@ public void onEntityUpdate(LivingEvent.LivingUpdateEvent event) {
566561
} catch (Exception e) {
567562

568563
}
569-
if (IafConfig.chickensLayRottenEggs && !event.getEntityLiving().world.isRemote && isAnimaniaChicken(event.getEntityLiving()) && !event.getEntityLiving().isChild() && event.getEntityLiving() instanceof AnimalEntity) {
564+
if (IafConfig.chickensLayRottenEggs && !event.getEntityLiving().world.isRemote && isChicken(event.getEntityLiving()) && !event.getEntityLiving().isChild() && event.getEntityLiving() instanceof AnimalEntity) {
570565
ChickenEntityProperties chickenProps = EntityPropertiesHandler.INSTANCE.getProperties(event.getEntityLiving(), ChickenEntityProperties.class);
571566
if (chickenProps != null) {
572567
if (chickenProps.timeUntilNextEgg < 0) {
@@ -882,7 +877,7 @@ public void onEntityJoinWorld(LivingSpawnEvent.SpecialSpawn event) {
882877
IceAndFire.LOGGER.warn("could not instantiate chain properties for " + event.getEntity().getName());
883878
}
884879
}
885-
if (event.getEntity() != null && isAnimaniaSheep(event.getEntity()) && event.getEntity() instanceof AnimalEntity) {
880+
if (event.getEntity() != null && isSheep(event.getEntity()) && event.getEntity() instanceof AnimalEntity) {
886881
AnimalEntity animal = (AnimalEntity) event.getEntity();
887882
animal.goalSelector.addGoal(8, new EntitySheepAIFollowCyclops(animal, 1.2D));
888883
}

0 commit comments

Comments
 (0)