|
19 | 19 |
|
20 | 20 | package net.minecraftforge.common; |
21 | 21 |
|
| 22 | +import java.util.Collection; |
| 23 | +import javax.annotation.Nullable; |
| 24 | + |
| 25 | +import net.minecraftforge.event.ForgeEventFactory; |
| 26 | +import net.minecraftforge.eventbus.api.Event; |
| 27 | + |
| 28 | +import net.minecraft.entity.Entity; |
| 29 | +import net.minecraft.entity.ItemEntity; |
| 30 | +import net.minecraft.entity.LivingEntity; |
| 31 | +import net.minecraft.entity.SpawnType; |
| 32 | +import net.minecraft.entity.damage.DamageSource; |
| 33 | +import net.minecraft.entity.mob.MobEntity; |
| 34 | +import net.minecraft.entity.player.PlayerEntity; |
| 35 | +import net.minecraft.util.ActionResult; |
| 36 | +import net.minecraft.util.Hand; |
| 37 | +import net.minecraft.world.IWorld; |
| 38 | +import net.minecraft.world.MobSpawnerLogic; |
| 39 | + |
| 40 | +import net.patchworkmc.impl.event.entity.EntityEvents; |
| 41 | + |
22 | 42 | /* |
23 | 43 | * Note: this class is intended for mod use only, to dispatch to the implementations kept in their own modules. |
24 | 44 | * Do not keep implementation details here, methods should be thin wrappers around methods in other modules. |
25 | 45 | */ |
26 | 46 | public class ForgeHooks { |
| 47 | + public static int canEntitySpawn(MobEntity entity, IWorld world, double x, double y, double z, MobSpawnerLogic spawner, SpawnType spawnReason) { |
| 48 | + Event.Result res = ForgeEventFactory.canEntitySpawn(entity, world, x, y, z, null, spawnReason); |
| 49 | + return res == Event.Result.DEFAULT ? 0 : res == Event.Result.DENY ? -1 : 1; |
| 50 | + } |
| 51 | + |
| 52 | + // TODO: onInteractEntityAt |
| 53 | + |
| 54 | + public static ActionResult onInteractEntity(PlayerEntity player, Entity entity, Hand hand) { |
| 55 | + return EntityEvents.onInteractEntity(player, entity, hand); |
| 56 | + } |
| 57 | + |
| 58 | + public static boolean onLivingDeath(LivingEntity entity, DamageSource src) { |
| 59 | + return EntityEvents.onLivingDeath(entity, src); |
| 60 | + } |
| 61 | + |
| 62 | + public static boolean onLivingUpdate(LivingEntity entity) { |
| 63 | + return EntityEvents.onLivingUpdateEvent(entity); |
| 64 | + } |
| 65 | + |
| 66 | + // TODO: forge calls the equivilant to this in LivingEntity, but patchwork only calls the equivilant to onPlayerAttack |
| 67 | + public static boolean onLivingAttack(LivingEntity entity, DamageSource src, float amount) { |
| 68 | + return entity instanceof PlayerEntity || onPlayerAttack(entity, src, amount); |
| 69 | + } |
| 70 | + |
| 71 | + public static boolean onPlayerAttack(LivingEntity entity, DamageSource src, float amount) { |
| 72 | + return !EntityEvents.onLivingAttack(entity, src, amount); |
| 73 | + } |
| 74 | + |
| 75 | + // optifine wants this? O.o |
| 76 | + public static void onLivingSetAttackTarget(LivingEntity entity, LivingEntity target) { |
| 77 | + EntityEvents.onLivingSetAttackTarget(entity, target); |
| 78 | + } |
| 79 | + |
| 80 | + public static float onLivingHurt(LivingEntity entity, DamageSource src, float amount) { |
| 81 | + return EntityEvents.onLivingHurt(entity, src, amount); |
| 82 | + } |
| 83 | + |
| 84 | + @Nullable |
| 85 | + public static float[] onLivingFall(LivingEntity entity, float distance, float damageMultiplier) { |
| 86 | + return EntityEvents.onLivingFall(entity, distance, damageMultiplier); |
| 87 | + } |
| 88 | + |
| 89 | + public static float onLivingDamage(LivingEntity entity, DamageSource src, float amount) { |
| 90 | + return EntityEvents.onLivingDamage(entity, src, amount); |
| 91 | + } |
| 92 | + |
| 93 | + public static boolean onLivingDrops(LivingEntity entity, DamageSource source, Collection<ItemEntity> drops, int lootingLevel, boolean recentlyHit) { |
| 94 | + return EntityEvents.onLivingDrops(entity, source, drops, lootingLevel, recentlyHit); |
| 95 | + } |
| 96 | + |
| 97 | + public static boolean onPlayerAttackTarget(PlayerEntity player, Entity target) { |
| 98 | + return EntityEvents.attackEntity(player, target); |
| 99 | + } |
27 | 100 | } |
0 commit comments