From ead1385464310f4fddda2c5566d541c187d659fc Mon Sep 17 00:00:00 2001 From: Jakub <53441451+kuba6000@users.noreply.github.com> Date: Wed, 4 Sep 2024 02:43:47 +0200 Subject: [PATCH] fix (#3038) --- .../events/EnderDragonDeathHandler.java | 59 ++++++++++++++++++- .../handler/events/EntityDeathHandler.java | 45 +++++++++++++- 2 files changed, 101 insertions(+), 3 deletions(-) diff --git a/src/main/java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java b/src/main/java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java index 008f0db0d4c..13dc18c4b15 100644 --- a/src/main/java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java +++ b/src/main/java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java @@ -1,15 +1,25 @@ package gtPlusPlus.core.handler.events; +import java.util.ArrayList; + import net.minecraft.entity.boss.EntityDragon; import net.minecraftforge.event.entity.living.LivingDropsEvent; +import org.jetbrains.annotations.NotNull; + +import com.kuba6000.mobsinfo.api.IMobExtraInfoProvider; +import com.kuba6000.mobsinfo.api.MobDrop; +import com.kuba6000.mobsinfo.api.MobRecipe; + +import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import gtPlusPlus.core.material.MaterialsElements; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.core.util.reflect.ReflectionUtils; -public class EnderDragonDeathHandler { +@Optional.Interface(iface = "com.kuba6000.mobsinfo.api.IMobExtraInfoProvider", modid = "mobsinfo") +public class EnderDragonDeathHandler implements IMobExtraInfoProvider { private static final String mDragonClassName = "chylex.hee.entity.boss.EntityBossDragon"; private static final boolean mHEE; @@ -28,6 +38,7 @@ public class EnderDragonDeathHandler { @SubscribeEvent public void onEntityDrop(LivingDropsEvent event) { + // int aCountTotal = 0; @@ -61,4 +72,50 @@ public void onEntityDrop(LivingDropsEvent event) { .messageAllPlayers(aCountTotal + " Shards of Dragons Blood have crystalized into a metallic form."); } } + + @Optional.Method(modid = "mobsinfo") + @Override + public void provideExtraDropsInformation(@NotNull String entityString, @NotNull ArrayList drops, + @NotNull MobRecipe recipe) { + if (mHEE && mHardcoreDragonClass != null && mHardcoreDragonClass.isInstance(recipe.entity)) { + MobDrop drop = new MobDrop( + MaterialsElements.STANDALONE.DRAGON_METAL.getNugget(1), + MobDrop.DropType.Normal, + (int) (MobDrop.getChanceBasedOnFromTo(100, 250) * MobDrop.getChanceBasedOnFromTo(5, 25) * 10000d), + null, + null, + false, + false); + + drop.clampChance(); + + drops.add(drop); + } else if (mDE && mChaoseDragonClass != null && mChaoseDragonClass.isInstance(recipe.entity)) { + MobDrop drop = new MobDrop( + MaterialsElements.STANDALONE.DRAGON_METAL.getIngot(1), + MobDrop.DropType.Normal, + (int) (MobDrop.getChanceBasedOnFromTo(100, 200) * MobDrop.getChanceBasedOnFromTo(1, 5) * 10000d), + null, + null, + false, + false); + + drop.clampChance(); + + drops.add(drop); + } else if (recipe.entity instanceof EntityDragon) { + MobDrop drop = new MobDrop( + MaterialsElements.STANDALONE.DRAGON_METAL.getNugget(1), + MobDrop.DropType.Normal, + (int) (MobDrop.getChanceBasedOnFromTo(25, 50) * MobDrop.getChanceBasedOnFromTo(1, 10) * 10000d), + null, + null, + false, + false); + + drop.clampChance(); + + drops.add(drop); + } + } } diff --git a/src/main/java/gtPlusPlus/core/handler/events/EntityDeathHandler.java b/src/main/java/gtPlusPlus/core/handler/events/EntityDeathHandler.java index 20d64f2b365..4baa7a80dd6 100644 --- a/src/main/java/gtPlusPlus/core/handler/events/EntityDeathHandler.java +++ b/src/main/java/gtPlusPlus/core/handler/events/EntityDeathHandler.java @@ -1,5 +1,6 @@ package gtPlusPlus.core.handler.events; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -8,6 +9,13 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.event.entity.living.LivingDropsEvent; +import org.jetbrains.annotations.NotNull; + +import com.kuba6000.mobsinfo.api.IMobExtraInfoProvider; +import com.kuba6000.mobsinfo.api.MobDrop; +import com.kuba6000.mobsinfo.api.MobRecipe; + +import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; @@ -17,14 +25,15 @@ import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; -public class EntityDeathHandler { +@Optional.Interface(iface = "com.kuba6000.mobsinfo.api.IMobExtraInfoProvider", modid = "mobsinfo") +public class EntityDeathHandler implements IMobExtraInfoProvider { private static final HashMap>> mMobDropMap = new HashMap<>(); private static final HashSet mInternalClassKeyCache = new HashSet<>(); /** * Provides the ability to provide custom drops upon the death of EntityLivingBase objects. - * + * * @param aMobClass - The Base Class you want to drop this item. * @param aStack - The ItemStack, stack size is not respected. * @param aMaxAmount - The maximum size of the ItemStack which drops. @@ -123,4 +132,36 @@ public void onEntityDrop(LivingDropsEvent event) { } } } + + @Optional.Method(modid = "mobsinfo") + @Override + public void provideExtraDropsInformation(@NotNull String entityString, @NotNull ArrayList drops, + @NotNull MobRecipe recipe) { + AutoMap> dropEntry = mMobDropMap.get(recipe.entity.getClass()); + + if (dropEntry != null && !dropEntry.isEmpty()) { + for (Triplet data : dropEntry) { + ItemStack loot = data.getValue_1(); + int maxDrop = data.getValue_2(); + int chance = data.getValue_3(); + if (loot == null) continue; + + loot = loot.copy(); + loot.stackSize = 1; + + MobDrop drop = new MobDrop( + loot, + MobDrop.DropType.Normal, + (int) (MobDrop.getChanceBasedOnFromTo(1, maxDrop) * 10000d * ((double) chance / 10000d)), + null, + null, + false, + false); + + drop.clampChance(); + + drops.add(drop); + } + } + } }