From 6f45c3efaeed07c81089872b2d8f8cb9331b24a2 Mon Sep 17 00:00:00 2001 From: koolkrafter5 Date: Tue, 14 Jul 2026 14:06:43 -0400 Subject: [PATCH] Fix bound blade not dropping blood shards if you kill in one hit (#141) --- .../AlchemicalWizardry.java | 2 -- .../common/AlchemicalWizardryEventHooks.java | 30 ++++++++++++++++++ .../common/ModLivingDropsEvent.java | 31 ------------------- .../common/items/EnergySword.java | 14 --------- 4 files changed, 30 insertions(+), 47 deletions(-) delete mode 100644 src/main/java/WayofTime/alchemicalWizardry/common/ModLivingDropsEvent.java diff --git a/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java b/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java index 6abde414..dd0d925f 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java +++ b/src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java @@ -64,7 +64,6 @@ import WayofTime.alchemicalWizardry.common.ClientToServerPacketHandler; import WayofTime.alchemicalWizardry.common.CommonProxy; import WayofTime.alchemicalWizardry.common.LifeBucketHandler; import WayofTime.alchemicalWizardry.common.LifeEssence; -import WayofTime.alchemicalWizardry.common.ModLivingDropsEvent; import WayofTime.alchemicalWizardry.common.NewPacketHandler; import WayofTime.alchemicalWizardry.common.achievements.ModAchievements; import WayofTime.alchemicalWizardry.common.alchemy.CombinedPotionRegistry; @@ -1554,7 +1553,6 @@ public class AlchemicalWizardry { blacklistAccelerators(); - MinecraftForge.EVENT_BUS.register(new ModLivingDropsEvent()); proxy.InitRendering(); NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandler()); diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/AlchemicalWizardryEventHooks.java b/src/main/java/WayofTime/alchemicalWizardry/common/AlchemicalWizardryEventHooks.java index e6dd8ae8..72a703ca 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/AlchemicalWizardryEventHooks.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/AlchemicalWizardryEventHooks.java @@ -11,6 +11,7 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IProjectile; import net.minecraft.entity.monster.EntityCreeper; import net.minecraft.entity.monster.EntityMob; +import net.minecraft.entity.passive.EntityAnimal; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.projectile.EntityArrow; @@ -27,6 +28,7 @@ import net.minecraftforge.event.AnvilUpdateEvent; import net.minecraftforge.event.entity.living.EnderTeleportEvent; import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.living.LivingDeathEvent; +import net.minecraftforge.event.entity.living.LivingDropsEvent; import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent; import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; @@ -35,14 +37,17 @@ import net.minecraftforge.event.entity.player.EntityInteractEvent; import WayofTime.alchemicalWizardry.AlchemicalWizardry; import WayofTime.alchemicalWizardry.BloodMagicConfiguration; +import WayofTime.alchemicalWizardry.ModItems; import WayofTime.alchemicalWizardry.api.BlockStack; import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent; import WayofTime.alchemicalWizardry.api.event.TeleposeEvent; +import WayofTime.alchemicalWizardry.api.items.interfaces.IBindable; import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler; import WayofTime.alchemicalWizardry.api.spell.APISpellHelper; import WayofTime.alchemicalWizardry.common.achievements.ModAchievements; import WayofTime.alchemicalWizardry.common.demonVillage.demonHoard.demon.IHoardDemon; import WayofTime.alchemicalWizardry.common.entity.projectile.EnergyBlastProjectile; +import WayofTime.alchemicalWizardry.common.items.EnergyItems; import WayofTime.alchemicalWizardry.common.items.EnergySword; import WayofTime.alchemicalWizardry.common.items.armour.BoundArmour; import WayofTime.alchemicalWizardry.common.items.armour.OmegaArmour; @@ -153,6 +158,31 @@ public class AlchemicalWizardryEventHooks { } } + @SubscribeEvent + public void onHurt(LivingHurtEvent event) { + if (!(event.source.getEntity() instanceof EntityPlayer player)) { + return; + } + ItemStack item = player.getCurrentEquippedItem(); + if (item != null && item.getItem() instanceof EnergySword sword + && IBindable.checkAndSetItemOwner(item, player) + && EnergyItems.syphonBatteries(item, player, sword.drainCost())) { + event.entityLiving.addPotionEffect(new PotionEffect(Potion.weakness.id, 60, 2)); + } + } + + @SubscribeEvent + public void onEntityDrop(LivingDropsEvent event) { + if (!event.source.getDamageType().equals("player") || event.entityLiving instanceof EntityAnimal) { + return; + } + PotionEffect effect = event.entityLiving.getActivePotionEffect(Potion.weakness); + + if (effect != null && effect.getAmplifier() >= 2 && Math.random() < 0.50d) { + event.entityLiving.dropItem(ModItems.weakBloodShard, 1); + } + } + @SubscribeEvent public void omegaUpdateReagentAndHpEvent(LivingUpdateEvent event) { if (event.entityLiving instanceof EntityPlayer player && !event.entityLiving.worldObj.isRemote) { diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/ModLivingDropsEvent.java b/src/main/java/WayofTime/alchemicalWizardry/common/ModLivingDropsEvent.java deleted file mode 100644 index 90535d38..00000000 --- a/src/main/java/WayofTime/alchemicalWizardry/common/ModLivingDropsEvent.java +++ /dev/null @@ -1,31 +0,0 @@ -package WayofTime.alchemicalWizardry.common; - -import net.minecraft.entity.passive.EntityAnimal; -import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionEffect; -import net.minecraftforge.event.entity.living.LivingDropsEvent; - -import WayofTime.alchemicalWizardry.ModItems; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; - -public class ModLivingDropsEvent { - - public static double rand; - - @SubscribeEvent - public void onEntityDrop(LivingDropsEvent event) { - if (event.source.getDamageType().equals("player")) { - rand = Math.random(); - - if (!(event.entityLiving instanceof EntityAnimal)) { - PotionEffect effect = event.entityLiving.getActivePotionEffect(Potion.weakness); - - if (effect != null) { - if (effect.getAmplifier() >= 2) if (rand < 0.50d) { - event.entityLiving.dropItem(ModItems.weakBloodShard, 1); - } - } - } - } - } -} diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/items/EnergySword.java b/src/main/java/WayofTime/alchemicalWizardry/common/items/EnergySword.java index ca7cc9ef..babf69c2 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/items/EnergySword.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/items/EnergySword.java @@ -4,12 +4,9 @@ import java.util.List; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; -import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionEffect; import net.minecraft.util.IIcon; import net.minecraft.util.StatCollector; import net.minecraft.world.World; @@ -88,17 +85,6 @@ public class EnergySword extends ItemSword implements IBindable { return !isActive; } - @Override - public boolean hitEntity(ItemStack item, EntityLivingBase target, EntityLivingBase attacker) { - if (attacker instanceof EntityPlayer player && (!IBindable.checkAndSetItemOwner(item, player) - || !EnergyItems.syphonBatteries(item, player, this.drainCost()))) { - return false; - } - - target.addPotionEffect(new PotionEffect(Potion.weakness.id, 60, 2)); - return true; - } - @Override public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) { super.onItemRightClick(item, world, player);