diff options
author | Raven Szewczyk <git@eigenraven.me> | 2024-07-27 07:12:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-27 13:12:04 +0700 |
commit | c7b38c23c5b34a324256966f0a9335694fe8d63b (patch) | |
tree | 92aab6471745549a79c9f84f38c3076d9275ac4f /src/main/java/gtPlusPlus/core/common | |
parent | c55db9d91fa0a065d7565107a1eca679698eab04 (diff) | |
download | GT5-Unofficial-c7b38c23c5b34a324256966f0a9335694fe8d63b.tar.gz GT5-Unofficial-c7b38c23c5b34a324256966f0a9335694fe8d63b.tar.bz2 GT5-Unofficial-c7b38c23c5b34a324256966f0a9335694fe8d63b.zip |
Optimize load time (#2774)
* Load time optimization: replace recipe reflection with mixin accessor
* Save an inner loop allocation in StaticRecipeChangeLoaders
* Move Bauble event handler from individual items to GT++ proxy
* Update mobs info with more optimizations
Diffstat (limited to 'src/main/java/gtPlusPlus/core/common')
-rw-r--r-- | src/main/java/gtPlusPlus/core/common/CommonProxy.java | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/main/java/gtPlusPlus/core/common/CommonProxy.java b/src/main/java/gtPlusPlus/core/common/CommonProxy.java index 5d93141c56..12f0971e73 100644 --- a/src/main/java/gtPlusPlus/core/common/CommonProxy.java +++ b/src/main/java/gtPlusPlus/core/common/CommonProxy.java @@ -6,14 +6,19 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.client.IItemRenderer; +import net.minecraftforge.event.entity.living.LivingAttackEvent; +import baubles.common.container.InventoryBaubles; +import baubles.common.lib.PlayerHandler; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLLoadCompleteEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.enums.Mods; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.api.objects.data.Pair; @@ -30,6 +35,7 @@ import gtPlusPlus.core.handler.events.EntityDeathHandler; import gtPlusPlus.core.handler.events.GeneralTooltipEventHandler; import gtPlusPlus.core.handler.events.PlayerSleepEventHandler; import gtPlusPlus.core.item.ModItems; +import gtPlusPlus.core.item.bauble.BaseBauble; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.recipe.common.CI; import gtPlusPlus.core.tileentities.ModTileEntities; @@ -204,4 +210,34 @@ public class CommonProxy { public EntityPlayer getPlayerEntity(MessageContext ctx) { return ctx.getServerHandler().playerEntity; } + + @SuppressWarnings("unused") // used by the event bus + @SubscribeEvent + public void onPlayerAttacked(LivingAttackEvent event) { + if (Mods.Baubles.isModLoaded()) { + BaubleAttackHandler.run(event); + } + } + + // 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); + final ItemStack bauble1 = baubles.getStackInSlot(1); + if (bauble1.getItem() instanceof BaseBauble gtBauble && gtBauble.getDamageNegations() + .contains(event.source.damageType)) { + event.setCanceled(true); + return; + } + final ItemStack bauble2 = baubles.getStackInSlot(2); + if (bauble2.getItem() instanceof BaseBauble gtBauble && gtBauble.getDamageNegations() + .contains(event.source.damageType)) { + event.setCanceled(true); + } + } + } } |