aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/handler/events
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2019-05-13 18:20:11 +1000
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2019-05-13 18:20:11 +1000
commitff47ff098d524402639b3593a0eb58dbbcbeb538 (patch)
tree5dbf22a9a978e6b1c6fc690c5d3a54c6b70bc5c7 /src/Java/gtPlusPlus/core/handler/events
parentf7390af19986b4e4370379bb46dee71f12b717e8 (diff)
downloadGT5-Unofficial-ff47ff098d524402639b3593a0eb58dbbcbeb538.tar.gz
GT5-Unofficial-ff47ff098d524402639b3593a0eb58dbbcbeb538.tar.bz2
GT5-Unofficial-ff47ff098d524402639b3593a0eb58dbbcbeb538.zip
+ Added EntityDeathHandler.java, along with some custom drops for Zombies, Blazes and SpecialMob's Brutish Zombie.
$ Temporarily disabled bonus outputs again on Multiblocks, fixing the ghost item issue along with processing.
Diffstat (limited to 'src/Java/gtPlusPlus/core/handler/events')
-rw-r--r--src/Java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java6
-rw-r--r--src/Java/gtPlusPlus/core/handler/events/EntityDeathHandler.java95
2 files changed, 99 insertions, 2 deletions
diff --git a/src/Java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java b/src/Java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java
index c1c2341dd6..884f14386d 100644
--- a/src/Java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java
+++ b/src/Java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java
@@ -2,7 +2,6 @@ package gtPlusPlus.core.handler.events;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import gtPlusPlus.core.material.ELEMENT;
-import gtPlusPlus.core.util.Utils;
import gtPlusPlus.core.util.math.MathUtils;
import gtPlusPlus.core.util.minecraft.PlayerUtils;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
@@ -24,6 +23,7 @@ public class EnderDragonDeathHandler {
public void onEntityDrop(LivingDropsEvent event) {
boolean aDidDrop = false;
+ int aCountTotal = 0;
//HEE Dragon
if (mHEE) {
@@ -33,6 +33,7 @@ public class EnderDragonDeathHandler {
int aAmount = MathUtils.randInt(5, 25);
event.entityLiving.entityDropItem(ELEMENT.STANDALONE.DRAGON_METAL.getNugget(aAmount), MathUtils.randFloat(0, 1));
aDidDrop = true;
+ aCountTotal =+ aAmount;
}
}
}
@@ -44,12 +45,13 @@ public class EnderDragonDeathHandler {
int aAmount = MathUtils.randInt(1, 10);
event.entityLiving.entityDropItem(ELEMENT.STANDALONE.DRAGON_METAL.getNugget(aAmount), MathUtils.randFloat(0, 1));
aDidDrop = true;
+ aCountTotal =+ aAmount;
}
}
}
if (aDidDrop) {
- PlayerUtils.messageAllPlayers("Small quantities of Dragonsblood has crystalized after the death of the Ender Dragon!");
+ PlayerUtils.messageAllPlayers(aCountTotal+" Shards of Dragons Blood have crystalized into a metallic form.");
}
}
diff --git a/src/Java/gtPlusPlus/core/handler/events/EntityDeathHandler.java b/src/Java/gtPlusPlus/core/handler/events/EntityDeathHandler.java
new file mode 100644
index 0000000000..c4ab6edaa6
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/handler/events/EntityDeathHandler.java
@@ -0,0 +1,95 @@
+package gtPlusPlus.core.handler.events;
+
+import java.util.HashMap;
+import java.util.HashSet;
+
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.api.objects.data.AutoMap;
+import gtPlusPlus.api.objects.data.Triplet;
+import gtPlusPlus.core.util.math.MathUtils;
+import gtPlusPlus.core.util.minecraft.ItemUtils;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.item.ItemStack;
+import net.minecraftforge.event.entity.living.LivingDropsEvent;
+
+public class EntityDeathHandler {
+
+
+ private static final HashMap<Class, AutoMap<Triplet<ItemStack, Integer, Integer>>> mMobDropMap = new HashMap<Class, AutoMap<Triplet<ItemStack, Integer, Integer>>>();
+ private static final HashSet<Class> mInternalClassKeyCache = new HashSet<Class>();
+
+ /**
+ * 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.
+ * @param aChance - Chance out of 10000, where 100 is 1%. (1 = 0.01% - this is ok)
+ */
+ public static void registerDropsForMob(Class aMobClass, ItemStack aStack, int aMaxAmount, int aChance) {
+ Triplet<ItemStack, Integer, Integer> aData = new Triplet<ItemStack, Integer, Integer>(aStack, aMaxAmount, aChance);
+ AutoMap<Triplet<ItemStack, Integer, Integer>> aDataMap = mMobDropMap.get(aMobClass);
+ if (aDataMap == null) {
+ aDataMap = new AutoMap<Triplet<ItemStack, Integer, Integer>>();
+ }
+ aDataMap.put(aData);
+ mMobDropMap.put(aMobClass, aDataMap);
+
+ Logger.INFO("[Loot] Registered "+aStack.getDisplayName()+" (1-"+aMaxAmount+") as a valid drop for "+aMobClass.getCanonicalName());
+
+ if (!mInternalClassKeyCache.contains(aMobClass)) {
+ mInternalClassKeyCache.add(aMobClass);
+ }
+
+ }
+
+ private static ItemStack processItemDropTriplet(Triplet<ItemStack, Integer, Integer> aData) {
+ ItemStack aLoot = aData.getValue_1();
+ int aMaxDrop = aData.getValue_2();
+ int aChanceOutOf10000 = aData.getValue_3();
+ if (MathUtils.randInt(0, 10000) <= aChanceOutOf10000) {
+ aLoot = ItemUtils.getSimpleStack(aLoot, MathUtils.randInt(1, aMaxDrop));
+ if (ItemUtils.checkForInvalidItems(aLoot)) {
+ return aLoot;
+ }
+ }
+ return null;
+ }
+
+ private static boolean processDropsForMob(EntityLivingBase entityLiving) {
+ AutoMap<Triplet<ItemStack, Integer, Integer>> aMobData = mMobDropMap.get(entityLiving.getClass());
+ boolean aDidDrop = false;
+ if (aMobData != null) {
+ if (!aMobData.isEmpty()) {
+ ItemStack aPossibleDrop;
+ for (Triplet<ItemStack, Integer, Integer> g : aMobData) {
+ aPossibleDrop = processItemDropTriplet(g);
+ if (aPossibleDrop != null) {
+ if (entityLiving.entityDropItem(aPossibleDrop, MathUtils.randFloat(0, 1)) != null) {
+ aDidDrop = true;
+ }
+ }
+ }
+ }
+ }
+ return aDidDrop;
+ }
+
+
+
+
+
+ @SubscribeEvent
+ public void onEntityDrop(LivingDropsEvent event) {
+ boolean aDidDrop = false;
+ if (event == null || event.entityLiving == null) {
+ return;
+ }
+ for (Class c : mInternalClassKeyCache) {
+ if (c.isInstance(event.entityLiving)) {
+ aDidDrop = processDropsForMob(event.entityLiving);
+ }
+ }
+ }
+
+}