diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2019-07-25 17:18:06 +0100 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2019-07-25 17:18:06 +0100 |
commit | ccbc6cdf102965d4614c1724518dd88c19f8f9d5 (patch) | |
tree | edd088c448729c47d406ea3a7cd16db7f13aa392 | |
parent | 3107f6306125a2b7a8702d1c675f5c4110baa747 (diff) | |
download | GT5-Unofficial-ccbc6cdf102965d4614c1724518dd88c19f8f9d5.tar.gz GT5-Unofficial-ccbc6cdf102965d4614c1724518dd88c19f8f9d5.tar.bz2 GT5-Unofficial-ccbc6cdf102965d4614c1724518dd88c19f8f9d5.zip |
- Removed Witchery compile dependency.
-rw-r--r-- | src/Java/gtPlusPlus/xmod/witchery/WitchUtils.java | 119 |
1 files changed, 66 insertions, 53 deletions
diff --git a/src/Java/gtPlusPlus/xmod/witchery/WitchUtils.java b/src/Java/gtPlusPlus/xmod/witchery/WitchUtils.java index 9e5efb452c..35f9f4bbe8 100644 --- a/src/Java/gtPlusPlus/xmod/witchery/WitchUtils.java +++ b/src/Java/gtPlusPlus/xmod/witchery/WitchUtils.java @@ -3,11 +3,10 @@ package gtPlusPlus.xmod.witchery; import java.lang.reflect.Field; import java.util.ArrayList; -import com.emoniph.witchery.Witchery; -import com.emoniph.witchery.entity.ai.EntityAIDigBlocks; import com.mojang.authlib.GameProfile; import gtPlusPlus.core.lib.LoadedMods; +import gtPlusPlus.core.material.ALLOY; import gtPlusPlus.core.util.reflect.ReflectionUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -16,57 +15,71 @@ import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.oredict.OreDictionary; public class WitchUtils { - - private static final Field KOBOLDITE_MINER_PROFILE; + private static final GameProfile NORMAL_MINER_PROFILE; + private static final GameProfile KOBOLDITE_MINER_PROFILE; + static { + Field a1 = null, a2 = null; + GameProfile b1 = null, b2 = null; if (LoadedMods.Witchery) { - KOBOLDITE_MINER_PROFILE = getField("com.emoniph.witchery.entity.ai.EntityAIDigBlocks", "KOBOLDITE_MINER_PROFILE"); - } - else { - KOBOLDITE_MINER_PROFILE = null; - } - + try { + a1 = getField("com.emoniph.witchery.entity.ai.EntityAIDigBlocks", "NORMAL_MINER_PROFILE"); + a2 = getField("com.emoniph.witchery.entity.ai.EntityAIDigBlocks", "KOBOLDITE_MINER_PROFILE"); + b1 = (GameProfile) a1.get(null); + b2 = (GameProfile) a2.get(null); + } + catch (Throwable t) { + } + } + NORMAL_MINER_PROFILE = b1; + KOBOLDITE_MINER_PROFILE = b2; } - + //com.emoniph.witchery.entity.ai.EntityAIDigBlocks.onHarvestDrops(EntityPlayer, HarvestDropsEvent) - public static void onHarvestDrops(final EntityPlayer harvester, final BlockEvent.HarvestDropsEvent event) { - if (harvester != null && !harvester.worldObj.isRemote && !event.isCanceled() && (isEqual(harvester.getGameProfile(), EntityAIDigBlocks.KOBOLDITE_MINER_PROFILE) || isEqual(harvester.getGameProfile(), EntityAIDigBlocks.NORMAL_MINER_PROFILE))) { - final boolean hasKobolditePick = isEqual(harvester.getGameProfile(), EntityAIDigBlocks.KOBOLDITE_MINER_PROFILE); - final ArrayList<ItemStack> newDrops = new ArrayList<ItemStack>(); - double kobolditeChance = hasKobolditePick ? 0.02 : 0.01; - for (final ItemStack drop : event.drops) { - final int[] oreIDs = OreDictionary.getOreIDs(drop); - boolean addOriginal = true; - if (oreIDs.length > 0) { - final String oreName = OreDictionary.getOreName(oreIDs[0]); - if (oreName != null && oreName.startsWith("ore")) { - final ItemStack smeltedDrop = FurnaceRecipes.smelting().getSmeltingResult(drop); - if (smeltedDrop != null && hasKobolditePick && harvester.worldObj.rand.nextDouble() < 0.5) { - addOriginal = false; - newDrops.add(smeltedDrop.copy()); - newDrops.add(smeltedDrop.copy()); - if (harvester.worldObj.rand.nextDouble() < 0.25) { - newDrops.add(smeltedDrop.copy()); - } - } - kobolditeChance = (hasKobolditePick ? 0.08 : 0.05); - } - } - if (addOriginal) { - newDrops.add(drop); - } - } - event.drops.clear(); - for (final ItemStack newDrop : newDrops) { - event.drops.add(newDrop); - } - if (kobolditeChance > 0.0 && harvester.worldObj.rand.nextDouble() < kobolditeChance) { - event.drops.add(Witchery.Items.GENERIC.itemKobolditeDust.createStack()); - } - } - } - + public static void onHarvestDrops(final EntityPlayer harvester, final BlockEvent.HarvestDropsEvent event) { + + + if (LoadedMods.Witchery) { + + if (harvester != null && !harvester.worldObj.isRemote && !event.isCanceled() && (isEqual(harvester.getGameProfile(), KOBOLDITE_MINER_PROFILE) || isEqual(harvester.getGameProfile(), NORMAL_MINER_PROFILE))) { + final boolean hasKobolditePick = isEqual(harvester.getGameProfile(), KOBOLDITE_MINER_PROFILE); + final ArrayList<ItemStack> newDrops = new ArrayList<ItemStack>(); + double kobolditeChance = hasKobolditePick ? 0.02 : 0.01; + for (final ItemStack drop : event.drops) { + final int[] oreIDs = OreDictionary.getOreIDs(drop); + boolean addOriginal = true; + if (oreIDs.length > 0) { + final String oreName = OreDictionary.getOreName(oreIDs[0]); + if (oreName != null && oreName.startsWith("ore")) { + final ItemStack smeltedDrop = FurnaceRecipes.smelting().getSmeltingResult(drop); + if (smeltedDrop != null && hasKobolditePick && harvester.worldObj.rand.nextDouble() < 0.5) { + addOriginal = false; + newDrops.add(smeltedDrop.copy()); + newDrops.add(smeltedDrop.copy()); + if (harvester.worldObj.rand.nextDouble() < 0.25) { + newDrops.add(smeltedDrop.copy()); + } + } + kobolditeChance = (hasKobolditePick ? 0.08 : 0.05); + } + } + if (addOriginal) { + newDrops.add(drop); + } + } + event.drops.clear(); + for (final ItemStack newDrop : newDrops) { + event.drops.add(newDrop); + } + if (kobolditeChance > 0.0 && harvester.worldObj.rand.nextDouble() < kobolditeChance) { + event.drops.add(ALLOY.KOBOLDITE.getDust(1)); + } + } + } + + } + public static Field getField(String aClassName, String aFieldName) { Class c; c = ReflectionUtils.getClass(aClassName); @@ -78,9 +91,9 @@ public class WitchUtils { } return null; } - - public static boolean isEqual(final GameProfile a, final GameProfile b) { - return a != null && b != null && a.getId() != null && b.getId() != null && a.getId().equals(b.getId()); - } - + + public static boolean isEqual(final GameProfile a, final GameProfile b) { + return a != null && b != null && a.getId() != null && b.getId() != null && a.getId().equals(b.getId()); + } + } |