diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2019-05-13 18:20:11 +1000 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2019-05-13 18:20:11 +1000 |
commit | ff47ff098d524402639b3593a0eb58dbbcbeb538 (patch) | |
tree | 5dbf22a9a978e6b1c6fc690c5d3a54c6b70bc5c7 /src/Java/gtPlusPlus/core/util | |
parent | f7390af19986b4e4370379bb46dee71f12b717e8 (diff) | |
download | GT5-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/util')
-rw-r--r-- | src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java | 75 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java | 11 |
2 files changed, 57 insertions, 29 deletions
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; + } + } |