-
-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathEntityUtils.java
More file actions
68 lines (59 loc) · 2.38 KB
/
EntityUtils.java
File metadata and controls
68 lines (59 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* This file is part of the BleachHack distribution (https://github.com/BleachDev/BleachHack/).
* Copyright (c) 2021 Bleach and contributors.
*
* This source code is subject to the terms of the GNU General Public
* License, version 3. If a copy of the GPL was not distributed with this
* file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt
*/
package org.bleachhack.util.world;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.AmbientEntity;
import net.minecraft.entity.mob.Monster;
import net.minecraft.entity.mob.WaterCreatureEntity;
import net.minecraft.entity.passive.IronGolemEntity;
import net.minecraft.entity.passive.PassiveEntity;
import net.minecraft.entity.passive.SnowGolemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.AbstractFireballEntity;
import net.minecraft.entity.projectile.ShulkerBulletEntity;
import org.bleachhack.BleachHack;
import static org.bleachhack.util.world.WorldUtils.mc;
public class EntityUtils {
public static boolean isAnimal(Entity e) {
return e instanceof PassiveEntity
|| e instanceof AmbientEntity
|| e instanceof WaterCreatureEntity
|| e instanceof IronGolemEntity
|| e instanceof SnowGolemEntity;
}
public static boolean isMob(Entity e) {
return e instanceof Monster;
}
public static boolean isPlayer(Entity e) {
return e instanceof PlayerEntity;
}
public static boolean isOtherServerPlayer(Entity e) {
return e instanceof PlayerEntity
&& e != MinecraftClient.getInstance().player
&& !(e instanceof PlayerCopyEntity);
}
public static boolean isAttackable(Entity e, boolean ignoreFriends) {
return (e instanceof LivingEntity || e instanceof ShulkerBulletEntity || e instanceof AbstractFireballEntity)
&& e.isAlive()
&& e != MinecraftClient.getInstance().player
&& !e.isConnectedThroughVehicle(MinecraftClient.getInstance().player)
&& !(e instanceof PlayerCopyEntity)
&& (!ignoreFriends || !BleachHack.friendMang.has(e));
}
public static <T extends Entity> T findClosest(Class<T> entityClass, float range) {
for (Entity entity : mc.world.getEntities()) {
if (entityClass.isAssignableFrom(entity.getClass()) && !entity.equals(mc.player) && entity.distanceTo(mc.player) <= range) {
return (T) entity;
}
}
return null;
}
}