aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java
blob: e6133e22db7704e6b446391d18b3db565d7ff90b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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 gregtech.api.util.ReflectionUtil;
import gtPlusPlus.core.material.MaterialsElements;
import gtPlusPlus.core.util.math.MathUtils;
import gtPlusPlus.core.util.minecraft.PlayerUtils;

@Optional.Interface(iface = "com.kuba6000.mobsinfo.api.IMobExtraInfoProvider", modid = "mobsinfo")
public class EnderDragonDeathHandler implements IMobExtraInfoProvider {

    private static final Class<?> mHardcoreDragonClass = ReflectionUtil
        .getClass("chylex.hee.entity.boss.EntityBossDragon");
    private static final Class<?> mChaoseDragonClass = ReflectionUtil
        .getClass("com.brandon3055.draconicevolution.common.entity.EntityCustomDragon");

    @SubscribeEvent
    public void onEntityDrop(LivingDropsEvent event) {
        int aCountTotal = 0;
        if (mHardcoreDragonClass != null && mHardcoreDragonClass.isInstance(event.entityLiving)) {
            for (int y = 0; y < MathUtils.randInt(100, 250); y++) {
                int aAmount = MathUtils.randInt(5, 25);
                event.entityLiving.entityDropItem(
                    MaterialsElements.STANDALONE.DRAGON_METAL.getNugget(aAmount),
                    MathUtils.randFloat(0, 1));
                aCountTotal = aAmount;
            }
        } else if (mChaoseDragonClass != null && mChaoseDragonClass.isInstance(event.entityLiving)) {
            for (int y = 0; y < MathUtils.randInt(100, 200); y++) {
                int aAmount = MathUtils.randInt(1, 5);
                event.entityLiving.entityDropItem(
                    MaterialsElements.STANDALONE.DRAGON_METAL.getIngot(aAmount),
                    MathUtils.randFloat(0, 1));
                aCountTotal = aAmount;
            }
        } else if (event.entityLiving instanceof EntityDragon) {
            for (int y = 0; y < MathUtils.randInt(25, 50); y++) {
                int aAmount = MathUtils.randInt(1, 10);
                event.entityLiving.entityDropItem(
                    MaterialsElements.STANDALONE.DRAGON_METAL.getNugget(aAmount),
                    MathUtils.randFloat(0, 1));
                aCountTotal = aAmount;
            }
        }
        if (aCountTotal > 0) {
            PlayerUtils
                .messageAllPlayers(aCountTotal + " Shards of Dragons Blood have crystallized into a metallic form.");
        }
    }

    @Optional.Method(modid = "mobsinfo")
    @Override
    public void provideExtraDropsInformation(@NotNull String entityString, @NotNull ArrayList<MobDrop> drops,
        @NotNull MobRecipe recipe) {
        if (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 (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);
        }
    }
}