Skip to content
This repository was archived by the owner on Feb 19, 2019. It is now read-only.

Commit 57ca7b1

Browse files
committed
Check if Neutral mobs are angry
EntityFilter should check if neutral mobs are angry when deciding if they are hostile or passive. - Check if Zombie Pigmen are angry - Check if Polar Bears are angry - If the polar bear is a child it can't be hostile - Check if the bear is targeting the player - Check if Iron Golems are angry - If player spawned, they will not turn hostile - If the player has angered the village, they will turn hostile - If they are targeting the player, they are hostile Also, return as soon as a condition is true instead of continuing to check all conditions.
1 parent 559fbc7 commit 57ca7b1

1 file changed

Lines changed: 76 additions & 14 deletions

File tree

src/main/java/me/zero/client/api/util/EntityFilter.java

Lines changed: 76 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@
2020
import me.zero.client.api.util.interfaces.Helper;
2121
import me.zero.client.api.value.type.BooleanType;
2222
import net.minecraft.entity.Entity;
23+
import net.minecraft.entity.EntityLiving;
24+
import net.minecraft.entity.EntityLivingBase;
2325
import net.minecraft.entity.boss.EntityDragon;
2426
import net.minecraft.entity.monster.*;
2527
import net.minecraft.entity.passive.EntityAnimal;
2628
import net.minecraft.entity.passive.EntityBat;
2729
import net.minecraft.entity.passive.EntitySquid;
2830
import net.minecraft.entity.passive.EntityVillager;
2931
import net.minecraft.entity.player.EntityPlayer;
32+
import net.minecraft.village.Village;
3033

31-
import java.util.Arrays;
3234
import java.util.List;
3335
import java.util.function.Predicate;
3436
import java.util.stream.Collectors;
@@ -142,12 +144,22 @@ public static boolean isPlayer(Entity e) {
142144
* @return Whether or not the entity is a hostile
143145
*/
144146
public static boolean isHostile(Entity e) {
145-
boolean c1 = e instanceof EntityMob;
146-
boolean c2 = e instanceof EntitySlime;
147-
boolean c3 = e instanceof EntityShulker;
148-
boolean c4 = e instanceof EntityGhast;
149-
boolean c5 = e instanceof EntityDragon;
150-
return c1 || c2 || c3 || c4 || c5;
147+
if (e instanceof EntityPigZombie)
148+
return isAngry((EntityPigZombie) e);
149+
150+
if (e instanceof EntityIronGolem)
151+
return isAngry((EntityIronGolem) e);
152+
153+
if (e instanceof EntityPolarBear)
154+
return isAngry((EntityPolarBear) e);
155+
156+
if (e instanceof EntityMob) return true;
157+
if (e instanceof EntitySlime) return true;
158+
if (e instanceof EntityShulker) return true;
159+
if (e instanceof EntityGhast) return true;
160+
if (e instanceof EntityDragon) return true;
161+
162+
return false;
151163
}
152164

153165
/**
@@ -157,13 +169,22 @@ public static boolean isHostile(Entity e) {
157169
* @return Whether or not the entity is a passive
158170
*/
159171
public static boolean isPassive(Entity e) {
160-
boolean c1 = e instanceof EntityAnimal;
161-
boolean c2 = e instanceof EntitySquid;
162-
boolean c3 = e instanceof EntityBat;
163-
boolean c4 = e instanceof EntityVillager;
164-
boolean c5 = e instanceof EntitySnowman;
165-
boolean c6 = e instanceof EntityIronGolem;
166-
return c1 || c2 || c3 || c4 || c5 || c6;
172+
if (e instanceof EntityPigZombie)
173+
return !isAngry((EntityPigZombie) e);
174+
175+
if (e instanceof EntityIronGolem)
176+
return !isAngry((EntityIronGolem) e);
177+
178+
if (e instanceof EntityPolarBear)
179+
return !isAngry((EntityPolarBear) e);
180+
181+
if (e instanceof EntityAnimal) return true;
182+
if (e instanceof EntitySquid) return true;
183+
if (e instanceof EntityBat) return true;
184+
if (e instanceof EntityVillager) return true;
185+
if (e instanceof EntitySnowman) return true;
186+
187+
return false;
167188
}
168189

169190
/**
@@ -179,4 +200,45 @@ public static boolean onSameTeam(Entity e1, Entity e2) {
179200

180201
return e1.isOnSameTeam(e2);
181202
}
203+
204+
private static boolean isAngry(EntityPigZombie e) {
205+
// Zombie Pigmen are nice and easy to check
206+
return e.isAngry();
207+
}
208+
209+
private static boolean isAngry(EntityIronGolem e) {
210+
// Manually spawned golems will not turn hostile
211+
if (e.isPlayerCreated()) return false;
212+
213+
// Check if the village dislike the player
214+
{
215+
Village village = e.getVillage();
216+
if (village != null && village.isPlayerReputationTooLow(mc.player.getName())) return true;
217+
}
218+
219+
// Check if the player is being targeted
220+
if (isTargeting(e, mc.player)) return true;
221+
222+
return false;
223+
}
224+
225+
private static boolean isAngry(EntityPolarBear e) {
226+
// Polar Bear Cubs can't be angry
227+
if (e.isChild()) return false;
228+
229+
// Check if the bear is targeting the player
230+
if (isTargeting(e, mc.player)) return true;
231+
232+
return false;
233+
}
234+
235+
private static boolean isTargeting(EntityLiving entity, EntityLivingBase target) {
236+
EntityLivingBase attackTarget = entity.getAttackTarget();
237+
EntityLivingBase revengeTarget = entity.getRevengeTarget();
238+
239+
if (attackTarget != null && attackTarget.equals(target)) return true;
240+
if (revengeTarget != null && revengeTarget.equals(target)) return true;
241+
242+
return false;
243+
}
182244
}

0 commit comments

Comments
 (0)