diff options
author | Alexdoru <57050655+Alexdoru@users.noreply.github.com> | 2024-09-16 03:46:57 +0200 |
---|---|---|
committer | boubou19 <miisterunknown@gmail.com> | 2024-09-17 22:55:46 +0200 |
commit | 3874c017b82e4ff7577513e99d2bc17b0552c8ad (patch) | |
tree | 09a31df821b7e86dea5ce25a2f6508d5b180db88 /src/main/java/gtPlusPlus/core | |
parent | a62b97852d7d9979e2394293363927c5737d4d14 (diff) | |
download | GT5-Unofficial-3874c017b82e4ff7577513e99d2bc17b0552c8ad.tar.gz GT5-Unofficial-3874c017b82e4ff7577513e99d2bc17b0552c8ad.tar.bz2 GT5-Unofficial-3874c017b82e4ff7577513e99d2bc17b0552c8ad.zip |
handle baubles dependency in gt++ ServerProxy with @optional method annotation
Diffstat (limited to 'src/main/java/gtPlusPlus/core')
-rw-r--r-- | src/main/java/gtPlusPlus/core/common/CommonProxy.java | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/src/main/java/gtPlusPlus/core/common/CommonProxy.java b/src/main/java/gtPlusPlus/core/common/CommonProxy.java index 436f04868c..dc45ae15e5 100644 --- a/src/main/java/gtPlusPlus/core/common/CommonProxy.java +++ b/src/main/java/gtPlusPlus/core/common/CommonProxy.java @@ -9,6 +9,7 @@ import net.minecraftforge.event.entity.living.LivingAttackEvent; import baubles.common.container.InventoryBaubles; import baubles.common.lib.PlayerHandler; +import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLLoadCompleteEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; @@ -47,7 +48,7 @@ public class CommonProxy { public CommonProxy() { // Should Register Gregtech Materials I've Made - Utils.registerEvent(this); + MinecraftForge.EVENT_BUS.register(this); } public void preInit(final FMLPreInitializationEvent e) { @@ -87,7 +88,7 @@ public class CommonProxy { // Handles Magic Feather Utils.registerEvent(ModItems.itemMagicFeather); - Utils.registerEvent(new EnderDragonDeathHandler()); + MinecraftForge.EVENT_BUS.register(new EnderDragonDeathHandler()); Utils.registerEvent(new EntityDeathHandler()); // Compat Handling @@ -204,38 +205,28 @@ public class CommonProxy { return ctx.getServerHandler().playerEntity; } - @SuppressWarnings("unused") // used by the event bus + @Optional.Method(modid = Mods.Names.BAUBLES) @SubscribeEvent public void onPlayerAttacked(LivingAttackEvent event) { - if (Mods.Baubles.isModLoaded()) { - BaubleAttackHandler.run(event); + if (!(event.entityLiving instanceof EntityPlayer player)) { + return; } - } - - // Prevent class loading errors if Baubles are missing - private static final class BaubleAttackHandler { - - public static void run(LivingAttackEvent event) { - if (!(event.entityLiving instanceof EntityPlayer player)) { - return; - } - InventoryBaubles baubles = PlayerHandler.getPlayerBaubles(player); - if (baubles == null) { - return; - } - final ItemStack bauble1 = baubles.getStackInSlot(1); - if (bauble1 != null && bauble1.getItem() instanceof BaseBauble gtBauble - && gtBauble.getDamageNegations() - .contains(event.source.damageType)) { - event.setCanceled(true); - return; - } - final ItemStack bauble2 = baubles.getStackInSlot(2); - if (bauble2 != null && bauble2.getItem() instanceof BaseBauble gtBauble - && gtBauble.getDamageNegations() - .contains(event.source.damageType)) { - event.setCanceled(true); - } + InventoryBaubles baubles = PlayerHandler.getPlayerBaubles(player); + if (baubles == null) { + return; + } + final ItemStack bauble1 = baubles.getStackInSlot(1); + if (bauble1 != null && bauble1.getItem() instanceof BaseBauble gtBauble + && gtBauble.getDamageNegations() + .contains(event.source.damageType)) { + event.setCanceled(true); + return; + } + final ItemStack bauble2 = baubles.getStackInSlot(2); + if (bauble2 != null && bauble2.getItem() instanceof BaseBauble gtBauble + && gtBauble.getDamageNegations() + .contains(event.source.damageType)) { + event.setCanceled(true); } } } |