diff options
author | â€huajijam <strhuaji@gmail.com> | 2019-05-17 23:26:41 +0800 |
---|---|---|
committer | â€huajijam <strhuaji@gmail.com> | 2019-05-17 23:26:41 +0800 |
commit | 5920c6db3ff62d89ba41db4eda59cc6d70ddce3b (patch) | |
tree | d4d6d5036e8cb95d2232066f0ee257f59b5aa967 /src/Java/gtPlusPlus/core/handler | |
parent | 787c31758d2ea3259f8da9c5c7ffd4b28429eb9a (diff) | |
parent | cacc2915ef0039e3460817e4f116d44cf8e44e5f (diff) | |
download | GT5-Unofficial-5920c6db3ff62d89ba41db4eda59cc6d70ddce3b.tar.gz GT5-Unofficial-5920c6db3ff62d89ba41db4eda59cc6d70ddce3b.tar.bz2 GT5-Unofficial-5920c6db3ff62d89ba41db4eda59cc6d70ddce3b.zip |
Automatic synchronization
Diffstat (limited to 'src/Java/gtPlusPlus/core/handler')
3 files changed, 166 insertions, 1 deletions
diff --git a/src/Java/gtPlusPlus/core/handler/COMPAT_HANDLER.java b/src/Java/gtPlusPlus/core/handler/COMPAT_HANDLER.java index 1e3cb0ffbb..fd30457b46 100644 --- a/src/Java/gtPlusPlus/core/handler/COMPAT_HANDLER.java +++ b/src/Java/gtPlusPlus/core/handler/COMPAT_HANDLER.java @@ -22,6 +22,9 @@ import gtPlusPlus.core.recipe.*; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.RecipeUtils; import gtPlusPlus.xmod.gregtech.HANDLER_GT; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic.GregtechMetaGarbageCollector; +import gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic.GregtechMetaPollutionCreator; import gtPlusPlus.xmod.gregtech.loaders.RecipeGen_Recycling; import gtPlusPlus.xmod.gregtech.registration.gregtech.*; import net.minecraft.item.ItemStack; @@ -49,6 +52,14 @@ public class COMPAT_HANDLER { public static void registerGregtechMachines() { if (Gregtech) { + //Debug + GregtechItemList.Garbage_Collector_Debug_Machine.set( + new GregtechMetaGarbageCollector( + "garbagecollector.01.tier.single", + "JVM Garbage Collector", + "Useful for debugging or smoother performance on local servers").getStackForm(1L)); + + //Free IDs /* --- @@ -114,7 +125,7 @@ public class COMPAT_HANDLER { GregtechBedrockPlatforms.run(); GregtechBufferDynamos.run(); GregtechAmazonWarehouse.run(); - GregtechIndustrialCryogenicFreezer.run(); + GregtechFactoryGradeReplacementMultis.run(); GregtechThaumcraftDevices.run(); GregtechThreadedBuffers.run(); GregtechIndustrialMixer.run(); diff --git a/src/Java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java b/src/Java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java new file mode 100644 index 0000000000..884f14386d --- /dev/null +++ b/src/Java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java @@ -0,0 +1,59 @@ +package gtPlusPlus.core.handler.events; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import gtPlusPlus.core.material.ELEMENT; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import net.minecraft.entity.boss.EntityDragon; +import net.minecraftforge.event.entity.living.LivingDropsEvent; + +public class EnderDragonDeathHandler { + + private static final String mDragonClassName = "chylex.hee.entity.boss.EntityBossDragon"; + private static final boolean mHEE; + private static final Class mHardcoreDragonClass; + + static { + mHEE = ReflectionUtils.doesClassExist(mDragonClassName); + mHardcoreDragonClass = (mHEE ? ReflectionUtils.getClass(mDragonClassName) : null); + } + + @SubscribeEvent + public void onEntityDrop(LivingDropsEvent event) { + + boolean aDidDrop = false; + int aCountTotal = 0; + + //HEE Dragon + if (mHEE) { + if (mHardcoreDragonClass != null) { + if (mHardcoreDragonClass.isInstance(event.entityLiving)) { + for (int y = 0; y < MathUtils.randInt(100, 250); y++) { + int aAmount = MathUtils.randInt(5, 25); + event.entityLiving.entityDropItem(ELEMENT.STANDALONE.DRAGON_METAL.getNugget(aAmount), MathUtils.randFloat(0, 1)); + aDidDrop = true; + aCountTotal =+ aAmount; + } + } + } + } + //Vanilla Dragon or any other dragon that extends it + 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(ELEMENT.STANDALONE.DRAGON_METAL.getNugget(aAmount), MathUtils.randFloat(0, 1)); + aDidDrop = true; + aCountTotal =+ aAmount; + } + } + } + + if (aDidDrop) { + 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); + } + } + } + +} |