|
| 1 | +package com.mangojellypudding.mangojs.kubejs.event; |
| 2 | + |
| 3 | +import com.mangojellypudding.mangojs.MangoJS; |
| 4 | +import com.mangojellypudding.mangojs.kubejs.event.living.*; |
| 5 | +import com.mangojellypudding.mangojs.kubejs.plugin.event.LivingEvents; |
| 6 | +import net.minecraft.resources.ResourceKey; |
| 7 | +import net.minecraft.world.entity.EntityType; |
| 8 | +import net.neoforged.bus.api.SubscribeEvent; |
| 9 | +import net.neoforged.fml.common.EventBusSubscriber; |
| 10 | +import net.neoforged.neoforge.event.entity.living.*; |
| 11 | +import net.neoforged.neoforge.event.entity.living.LivingEvent.*; |
| 12 | + |
| 13 | +@EventBusSubscriber(modid = MangoJS.MODID) |
| 14 | +public class KubeLivingEventHandler { |
| 15 | + public static ResourceKey<EntityType<?>> getKey(LivingEvent event) { |
| 16 | + return event.getEntity().getType().kjs$getKey(); |
| 17 | + } |
| 18 | + |
| 19 | + @SubscribeEvent |
| 20 | + public static void breath(LivingBreatheEvent event) throws Throwable { |
| 21 | + var key = getKey(event); |
| 22 | + |
| 23 | + if (LivingEvents.BREATH.hasListeners(key)) { |
| 24 | + LivingEvents.BREATH.post(event.getEntity(), key, new LivingBreathKubeEvent(event)); |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + @SubscribeEvent |
| 29 | + public static void changeTarget(LivingChangeTargetEvent event) { |
| 30 | + var key = getKey(event); |
| 31 | + |
| 32 | + if (LivingEvents.CHANGE_TARGET.hasListeners(key)) { |
| 33 | + LivingEvents.CHANGE_TARGET.post(event.getEntity(), key, new LivingChangeTargetKubeEvent(event)); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + @SubscribeEvent |
| 38 | + public static void beforeConversion(LivingConversionEvent.Pre event) { |
| 39 | + var key = getKey(event); |
| 40 | + |
| 41 | + if (LivingEvents.BEFORE_CONVERSION.hasListeners(key)) { |
| 42 | + LivingEvents.BEFORE_CONVERSION.post(event.getEntity(), key, new LivingConversionKubeEvent.Pre(event)); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + @SubscribeEvent |
| 47 | + public static void afterConversion(LivingConversionEvent.Post event) { |
| 48 | + var key = getKey(event); |
| 49 | + |
| 50 | + if (LivingEvents.AFTER_CONVERSION.hasListeners(key)) { |
| 51 | + LivingEvents.AFTER_CONVERSION.post(event.getEntity(), key, new LivingConversionKubeEvent.Post(event)); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + @SubscribeEvent |
| 56 | + public static void destroyBlock(LivingDestroyBlockEvent event) { |
| 57 | + var key = getKey(event); |
| 58 | + |
| 59 | + if (LivingEvents.DESTROY_BLOCK.hasListeners(key)) { |
| 60 | + LivingEvents.DESTROY_BLOCK.post(event.getEntity(), key, new LivingDestroyBlockKubeEvent(event)); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + @SubscribeEvent |
| 65 | + public static void drown(LivingDrownEvent event) { |
| 66 | + var key = getKey(event); |
| 67 | + |
| 68 | + if (LivingEvents.DROWN.hasListeners(key)) { |
| 69 | + LivingEvents.DROWN.post(event.getEntity(), key, new LivingDrownKubeEvent(event)); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + @SubscribeEvent |
| 74 | + public static void experienceDrops(LivingExperienceDropEvent event) { |
| 75 | + var key = getKey(event); |
| 76 | + |
| 77 | + if (LivingEvents.EXPERIENCE_DROPS.hasListeners(key)) { |
| 78 | + LivingEvents.EXPERIENCE_DROPS.post(event.getEntity(), key, new LivingExperienceDropKubeEvent(event)); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + @SubscribeEvent |
| 83 | + public static void fall(LivingFallEvent event) { |
| 84 | + var key = getKey(event); |
| 85 | + |
| 86 | + if (LivingEvents.FALL.hasListeners(key)) { |
| 87 | + LivingEvents.FALL.post(event.getEntity(), key, new LivingFallKubeEvent(event)); |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + @SubscribeEvent |
| 92 | + public static void getProjectile(LivingGetProjectileEvent event) { |
| 93 | + var key = getKey(event); |
| 94 | + |
| 95 | + if (LivingEvents.GET_PROJECTILE.hasListeners(key)) { |
| 96 | + LivingEvents.GET_PROJECTILE.post(event.getEntity(), key, new LivingGetProjectileKubeEvent(event)); |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + @SubscribeEvent |
| 101 | + public static void heal(LivingHealEvent event) { |
| 102 | + var key = getKey(event); |
| 103 | + |
| 104 | + if (LivingEvents.HEAL.hasListeners(key)) { |
| 105 | + LivingEvents.HEAL.post(event.getEntity(), key, new LivingHealKubeEvent(event)); |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + @SubscribeEvent |
| 110 | + public static void incomingDamage(LivingIncomingDamageEvent event) { |
| 111 | + var key = getKey(event); |
| 112 | + |
| 113 | + if (LivingEvents.INCOMING_DAMAGE.hasListeners(key)) { |
| 114 | + LivingEvents.INCOMING_DAMAGE.post(event.getEntity(), key, new LivingIncomingDamageKubeEvent(event)); |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + @SubscribeEvent |
| 119 | + public static void jump(LivingJumpEvent event) { |
| 120 | + var key = getKey(event); |
| 121 | + |
| 122 | + if (LivingEvents.JUMP.hasListeners(key)) { |
| 123 | + LivingEvents.JUMP.post(event.getEntity(), key, new LivingJumpKubeEvent(event)); |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + @SubscribeEvent |
| 128 | + public static void knockBack(LivingKnockBackEvent event) { |
| 129 | + var key = getKey(event); |
| 130 | + |
| 131 | + if (LivingEvents.KNOCK_BACK.hasListeners(key)) { |
| 132 | + LivingEvents.KNOCK_BACK.post(event.getEntity(), key, new LivingKnockBackKubeEvent(event)); |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + @SubscribeEvent |
| 137 | + public static void shieldBlock(LivingShieldBlockEvent event) { |
| 138 | + var key = getKey(event); |
| 139 | + |
| 140 | + if (LivingEvents.SHIELD_BLOCK.hasListeners(key)) { |
| 141 | + LivingEvents.SHIELD_BLOCK.post(event.getEntity(), key, new LivingShieldBlockKubeEvent(event)); |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + @SubscribeEvent |
| 146 | + public static void swapItem(LivingSwapItemsEvent.Hands event) { |
| 147 | + var key = getKey(event); |
| 148 | + |
| 149 | + if (LivingEvents.SWAP_ITEM.hasListeners(key)) { |
| 150 | + LivingEvents.SWAP_ITEM.post(event.getEntity(), key, new LivingSwapItemKubeEvent.Hands(event)); |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + @SubscribeEvent |
| 155 | + public static void totem(LivingUseTotemEvent event) { |
| 156 | + var key = getKey(event); |
| 157 | + |
| 158 | + if (LivingEvents.TOTEM.hasListeners(key)) { |
| 159 | + LivingEvents.TOTEM.post(event.getEntity(), key, new LivingUseTotemKubeEvent(event)); |
| 160 | + } |
| 161 | + } |
| 162 | + |
| 163 | + @SubscribeEvent |
| 164 | + public static void useItemFinish(LivingEntityUseItemEvent.Finish event) { |
| 165 | + var key = getKey(event); |
| 166 | + |
| 167 | + if (LivingEvents.USE_ITEM_FINISH.hasListeners(key)) { |
| 168 | + LivingEvents.USE_ITEM_FINISH.post(event.getEntity(), key, new LivingEntityUseItemKubeEvent.Finish(event)); |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + @SubscribeEvent |
| 173 | + public static void useItemStart(LivingEntityUseItemEvent.Start event) { |
| 174 | + var key = getKey(event); |
| 175 | + |
| 176 | + if (LivingEvents.USE_ITEM_START.hasListeners(key)) { |
| 177 | + LivingEvents.USE_ITEM_START.post(event.getEntity(), key, new LivingEntityUseItemKubeEvent.Start(event)); |
| 178 | + } |
| 179 | + } |
| 180 | + |
| 181 | + @SubscribeEvent |
| 182 | + public static void useItemStop(LivingEntityUseItemEvent.Stop event) { |
| 183 | + var key = getKey(event); |
| 184 | + |
| 185 | + if (LivingEvents.USE_ITEM_STOP.hasListeners(key)) { |
| 186 | + LivingEvents.USE_ITEM_STOP.post(event.getEntity(), key, new LivingEntityUseItemKubeEvent.Stop(event)); |
| 187 | + } |
| 188 | + } |
| 189 | + |
| 190 | + @SubscribeEvent |
| 191 | + public static void useItemTick(LivingEntityUseItemEvent.Tick event) { |
| 192 | + var key = getKey(event); |
| 193 | + |
| 194 | + if (LivingEvents.USE_ITEM_TICK.hasListeners(key)) { |
| 195 | + LivingEvents.USE_ITEM_TICK.post(event.getEntity(), key, new LivingEntityUseItemKubeEvent.Tick(event)); |
| 196 | + } |
| 197 | + } |
| 198 | + |
| 199 | + @SubscribeEvent |
| 200 | + public static void visibility(LivingVisibilityEvent event) { |
| 201 | + var key = getKey(event); |
| 202 | + |
| 203 | + if (LivingEvents.VISIBILITY.hasListeners(key)) { |
| 204 | + LivingEvents.VISIBILITY.post(event.getEntity(), key, new LivingVisibilityKubeEvent(event)); |
| 205 | + } |
| 206 | + } |
| 207 | +} |
0 commit comments