aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/Java/gtPlusPlus/core')
-rw-r--r--src/Java/gtPlusPlus/core/common/CommonProxy.java42
-rw-r--r--src/Java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java6
-rw-r--r--src/Java/gtPlusPlus/core/handler/events/EntityDeathHandler.java95
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java75
-rw-r--r--src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java11
5 files changed, 198 insertions, 31 deletions
diff --git a/src/Java/gtPlusPlus/core/common/CommonProxy.java b/src/Java/gtPlusPlus/core/common/CommonProxy.java
index 23bdb2c5f1..6058d03b80 100644
--- a/src/Java/gtPlusPlus/core/common/CommonProxy.java
+++ b/src/Java/gtPlusPlus/core/common/CommonProxy.java
@@ -28,6 +28,7 @@ import gtPlusPlus.core.handler.GuiHandler;
import gtPlusPlus.core.handler.StopAnnoyingFuckingAchievements;
import gtPlusPlus.core.handler.events.BlockEventHandler;
import gtPlusPlus.core.handler.events.EnderDragonDeathHandler;
+import gtPlusPlus.core.handler.events.EntityDeathHandler;
import gtPlusPlus.core.handler.events.GeneralTooltipEventHandler;
import gtPlusPlus.core.handler.events.PickaxeBlockBreakEventHandler;
import gtPlusPlus.core.handler.events.ZombieBackupSpawnEventHandler;
@@ -36,17 +37,26 @@ import gtPlusPlus.core.item.chemistry.GenericChem;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.lib.CORE.ConfigSwitches;
import gtPlusPlus.core.lib.LoadedMods;
+import gtPlusPlus.core.material.ALLOY;
import gtPlusPlus.core.material.Material;
import gtPlusPlus.core.recipe.common.CI;
import gtPlusPlus.core.tileentities.ModTileEntities;
import gtPlusPlus.core.util.Utils;
import gtPlusPlus.core.util.debug.DEBUG_INIT;
+import gtPlusPlus.core.util.minecraft.EntityUtils;
+import gtPlusPlus.core.util.minecraft.ItemUtils;
import gtPlusPlus.core.util.player.PlayerCache;
+import gtPlusPlus.core.util.reflect.ReflectionUtils;
import gtPlusPlus.plugin.villagers.block.BlockGenericSpawner;
import gtPlusPlus.xmod.eio.handler.HandlerTooltip_EIO;
import gtPlusPlus.xmod.galacticraft.handler.HandlerTooltip_GC;
import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList;
+import gtPlusPlus.xmod.thermalfoundation.item.TF_Items;
+import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.Entity;
+import net.minecraft.entity.monster.EntityBlaze;
+import net.minecraft.entity.monster.EntityZombie;
+import net.minecraft.item.ItemStack;
import net.minecraftforge.common.ForgeChunkManager;
public class CommonProxy {
@@ -147,6 +157,7 @@ public class CommonProxy {
ForgeChunkManager.setForcedChunkLoadingCallback(GTplusplus.instance, ChunkManager.getInstance());
Utils.registerEvent(ChunkManager.getInstance());
Utils.registerEvent(new EnderDragonDeathHandler());
+ Utils.registerEvent(new EntityDeathHandler());
if (ConfigSwitches.disableZombieReinforcement) {
// Make Zombie reinforcements fuck off.
@@ -181,6 +192,7 @@ public class CommonProxy {
COMPAT_HANDLER.startLoadingGregAPIBasedRecipes();
COMPAT_IntermodStaging.postInit(e);
COMPAT_HANDLER.runQueuedRecipes();
+ registerCustomMobDrops();
}
public void serverStarting(final FMLServerStartingEvent e) {
@@ -226,5 +238,35 @@ public class CommonProxy {
public void registerCustomItemsForMaterials() {
Material.registerComponentForMaterial(GenericChem.CARBYNE, OrePrefixes.plate, GregtechItemList.Carbyne_Sheet_Finished.get(1));
}
+
+ public void registerCustomMobDrops() {
+
+ //Zombie
+ EntityUtils.registerDropsForMob(EntityZombie.class, ItemUtils.getSimpleStack(ModItems.itemRope), 3, 100);
+ EntityUtils.registerDropsForMob(EntityZombie.class, ItemUtils.getSimpleStack(ModItems.itemFiber), 5, 250);
+ EntityUtils.registerDropsForMob(EntityZombie.class, ItemUtils.getSimpleStack(ModItems.itemSandstoneHammer), 1, 10);
+ EntityUtils.registerDropsForMob(EntityZombie.class, ItemUtils.getSimpleStack(ModItems.itemBomb), 2, 10);
+ EntityUtils.registerDropsForMob(EntityZombie.class, ALLOY.TUMBAGA.getTinyDust(1), 1, 10);
+ EntityUtils.registerDropsForMob(EntityZombie.class, ALLOY.POTIN.getTinyDust(1), 1, 10);
+
+ //Blazes
+ EntityUtils.registerDropsForMob(EntityBlaze.class, ItemUtils.getSimpleStack(TF_Items.dustPyrotheum, 1), 1, 10);
+ EntityUtils.registerDropsForMob(EntityBlaze.class, ItemUtils.getSimpleStack(TF_Items.dustPyrotheum, 1), 1, 10);
+
+ //Special mobs Support
+ if (ReflectionUtils.doesClassExist("toast.specialMobs.entity.zombie.EntityBrutishZombie")) {
+ Class aBrutishZombie = ReflectionUtils.getClass("toast.specialMobs.entity.zombie.EntityBrutishZombie");
+ ItemStack aFortune1 = ItemUtils.getEnchantedBook(Enchantment.fortune, 1);
+ ItemStack aFortune2 = ItemUtils.getEnchantedBook(Enchantment.fortune, 1);
+ ItemStack aFortune3 = ItemUtils.getEnchantedBook(Enchantment.fortune, 1);
+ EntityUtils.registerDropsForMob(aBrutishZombie, aFortune1, 1, 100);
+ EntityUtils.registerDropsForMob(aBrutishZombie, aFortune2, 1, 50);
+ EntityUtils.registerDropsForMob(aBrutishZombie, aFortune3, 1, 1);
+ EntityUtils.registerDropsForMob(aBrutishZombie, ItemUtils.getItemStackOfAmountFromOreDict("ingotRedAlloy", 1), 3, 200);
+ }
+
+
+
+ }
}
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);
+ }
+ }
+ }
+
+}
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java
index 8c5a9f6581..49aa3a1306 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java
@@ -11,6 +11,7 @@ import gregtech.api.util.GT_Utility;
import gtPlusPlus.api.objects.data.AutoMap;
import gtPlusPlus.api.objects.minecraft.AABB;
import gtPlusPlus.api.objects.minecraft.BlockPos;
+import gtPlusPlus.core.handler.events.EntityDeathHandler;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
import ic2.core.IC2Potion;
import ic2.core.item.armor.ItemArmorHazmat;
@@ -20,6 +21,7 @@ import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
@@ -87,7 +89,7 @@ public class EntityUtils {
}
return false;
}
-
+
public static boolean applyHeatDamageToEntity(final int heatLevel, final World world, final Entity entityHolding){
if (!world.isRemote){
if ((heatLevel > 0) && (entityHolding instanceof EntityLivingBase)) {
@@ -113,11 +115,7 @@ public class EntityUtils {
*/
public synchronized static boolean doFireDamage(Entity entity, int amount){
if (dealFireDamage == null){
- try {
- dealFireDamage = Entity.class.getDeclaredMethod("dealFireDamage", int.class);
- dealFireDamage.setAccessible(true);
- }
- catch (NoSuchMethodException | SecurityException e) {}
+ dealFireDamage = ReflectionUtils.getMethod(Entity.class, "dealFireDamage", int.class);
}
else {
try {
@@ -131,42 +129,41 @@ public class EntityUtils {
public static void doDamage(Entity entity, DamageSource dmg, int i) {
entity.attackEntityFrom(dmg, i);
}
-
+
public static boolean isTileEntityRegistered(Class aTileClass, String aTileName) {
Field aRegistry = ReflectionUtils.getField(ReflectionUtils.getClass("net.minecraft.tileentity.TileEntity"), "nameToClassMap");
Field aRegistry2 = ReflectionUtils.getField(ReflectionUtils.getClass("net.minecraft.tileentity.TileEntity"), "classToNameMap");
try {
Object o = aRegistry.get(null);
if (o != null) {
- Map nameToClassMap = (Map) o;
- if (!nameToClassMap.containsKey(aTileName)) {
- o = aRegistry2.get(null);
- if (o != null) {
- Map classToNameMap = (Map) o;
- if (!classToNameMap.containsKey(aTileClass)) {
- return false;
- }
- else {
- return true;
- }
- }
- }
- else {
- return true;
- }
+ Map nameToClassMap = (Map) o;
+ if (!nameToClassMap.containsKey(aTileName)) {
+ o = aRegistry2.get(null);
+ if (o != null) {
+ Map classToNameMap = (Map) o;
+ if (!classToNameMap.containsKey(aTileClass)) {
+ return false;
+ }
+ else {
+ return true;
+ }
+ }
+ }
+ else {
+ return true;
+ }
}
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
return false;
}
-
+
public static double getDistance(Entity p1, Entity p2) {
- return Math.sqrt( Math.pow(p1.posX - p2.posX, 2) + Math.pow(p1.posY - p2.posY, 2) + Math.pow(p1.posZ - p2.posZ, 2));
+ return Math.sqrt( Math.pow(p1.posX - p2.posX, 2) + Math.pow(p1.posY - p2.posY, 2) + Math.pow(p1.posZ - p2.posZ, 2));
}
-
+
public static AutoMap<Entity> getEntitiesWithinBoundingBoxExcluding(Entity aExclusion, AABB aBoundingBox){
-
if (aExclusion == null) {
return new AutoMap<Entity>();
}
@@ -175,9 +172,8 @@ public class EntityUtils {
return new AutoMap<Entity>(aEntities);
}
}
-
+
public static AutoMap<Entity> getEntitiesWithinBoundingBox(Class aEntityType, AABB aBoundingBox){
-
if (aEntityType == null) {
return new AutoMap<Entity>();
}
@@ -186,5 +182,26 @@ public class EntityUtils {
return new AutoMap<Entity>(aEntities);
}
}
+
+ /**
+ * Provides the ability to provide custom drops upon the death of EntityLivingBase objects. Simplified function with static Max drop size of 1.
+ * @param aMobClass - The Base Class you want to drop this item.
+ * @param aStack - The ItemStack, stack size is not respected.
+ * @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 aChance) {
+ registerDropsForMob(aMobClass, aStack, 1, aChance);
+ }
+
+ /**
+ * 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) {
+ EntityDeathHandler.registerDropsForMob(aMobClass, aStack, aMaxAmount, aChance);
+ }
}
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java
index 8b2e04d738..433f26aa11 100644
--- a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java
+++ b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java
@@ -35,6 +35,8 @@ import gtPlusPlus.xmod.gregtech.api.items.Gregtech_MetaTool;
import gtPlusPlus.xmod.gregtech.common.items.MetaGeneratedGregtechTools;
import gtPlusPlus.xmod.gregtech.loaders.RecipeGen_DustGeneration;
import net.minecraft.block.Block;
+import net.minecraft.enchantment.Enchantment;
+import net.minecraft.enchantment.EnchantmentData;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
@@ -1205,4 +1207,13 @@ public class ItemUtils {
return aOutput;
}
+ public static ItemStack getEnchantedBook(Enchantment aEnch, int aLevel) {
+ return enchantItem(new ItemStack(Items.enchanted_book), aEnch, aLevel);
+ }
+
+ public static ItemStack enchantItem(ItemStack aStack, Enchantment aEnch, int aLevel) {
+ Items.enchanted_book.addEnchantment(aStack, new EnchantmentData(aEnch, aLevel));
+ return aStack;
+ }
+
}