From 43be31d2ac5c8d390579edd4faa5817e91fc4b1a Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Sun, 23 Jan 2022 17:41:06 +0000 Subject: Added framework for custom bees. Boosted drops of Dragon Metal from Chaos Dragons. Fixed https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/9556. --- .../handler/events/EnderDragonDeathHandler.java | 57 +++++++++++----------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'src/main/java/gtPlusPlus/core/handler') diff --git a/src/main/java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java b/src/main/java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java index 884f14386d..967a51fad6 100644 --- a/src/main/java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java +++ b/src/main/java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java @@ -13,47 +13,48 @@ public class EnderDragonDeathHandler { private static final String mDragonClassName = "chylex.hee.entity.boss.EntityBossDragon"; private static final boolean mHEE; private static final Class mHardcoreDragonClass; - + + private static final String mChaosDragonClassName = "com.brandon3055.draconicevolution.common.entity.EntityCustomDragon"; + private static final boolean mDE; + private static final Class mChaoseDragonClass; + static { mHEE = ReflectionUtils.doesClassExist(mDragonClassName); mHardcoreDragonClass = (mHEE ? ReflectionUtils.getClass(mDragonClassName) : null); + mDE = ReflectionUtils.doesClassExist(mChaosDragonClassName); + mChaoseDragonClass = (mDE ? ReflectionUtils.getClass(mChaosDragonClassName) : 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; - } - } + + if (mHEE && mHardcoreDragonClass != null && 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)); + 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; - } + else if (mDE && mChaoseDragonClass != null && mChaoseDragonClass.isInstance(event.entityLiving)) { + for (int y = 0; y < MathUtils.randInt(100, 200); y++) { + int aAmount = MathUtils.randInt(1, 5); + event.entityLiving.entityDropItem(ELEMENT.STANDALONE.DRAGON_METAL.getIngot(aAmount), MathUtils.randFloat(0, 1)); + aCountTotal = +aAmount; } } - - if (aDidDrop) { - PlayerUtils.messageAllPlayers(aCountTotal+" Shards of Dragons Blood have crystalized into a metallic form."); + 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)); + aCountTotal = +aAmount; + } + } + if (aCountTotal > 0) { + PlayerUtils.messageAllPlayers(aCountTotal + " Shards of Dragons Blood have crystalized into a metallic form."); } - + } } -- cgit From 143a76dd8b380f85dad4fee6359b5a17022feccb Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Sat, 29 Jan 2022 13:07:43 +0000 Subject: Added Mob Mentality. Added perks to sleeping. Added Magic Feather. --- .../java/gtPlusPlus/core/handler/MobMentality.java | 58 ++++++++++ .../handler/events/PlayerSleepEventHandler.java | 124 +++++++++++++++++++++ 2 files changed, 182 insertions(+) create mode 100644 src/main/java/gtPlusPlus/core/handler/MobMentality.java create mode 100644 src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java (limited to 'src/main/java/gtPlusPlus/core/handler') diff --git a/src/main/java/gtPlusPlus/core/handler/MobMentality.java b/src/main/java/gtPlusPlus/core/handler/MobMentality.java new file mode 100644 index 0000000000..acc289fecd --- /dev/null +++ b/src/main/java/gtPlusPlus/core/handler/MobMentality.java @@ -0,0 +1,58 @@ +package gtPlusPlus.core.handler; + +import java.util.*; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import gtPlusPlus.core.util.minecraft.EntityUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.monster.IMob; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.event.entity.living.LivingHurtEvent; + +public class MobMentality { + + public static HashSet> sIgnoredTypes = new HashSet>(); + + @SubscribeEvent + public void onEntityDamaged(LivingHurtEvent event) { + final EntityLivingBase target = event.entityLiving; + for (Class aEntityClass : sIgnoredTypes) { + if (aEntityClass.isInstance(target)) { + return; + } + } + if (target instanceof EntityLivingBase) { + final EntityLivingBase entity = target; + final Entity attacker = event.source.getSourceOfDamage(); + if (/*this.configuration.shouldIgnoreNeutralMobs() && */!(entity instanceof IMob)) { + return; + } + if (attacker == null) { + return; + } + if (attacker instanceof EntityLivingBase && !PlayerUtils.isRealPlayer((EntityLivingBase) attacker)) { + return; + } + if (attacker instanceof EntityPlayer && PlayerUtils.isCreative((EntityPlayer) attacker)) { + return; + } + if (attacker instanceof EntityLivingBase) { + List aEntityList = target.worldObj.loadedEntityList; + List aRangedEntity = new ArrayList(); + for (Entity aEntity : aEntityList) { + if (target.getClass().isInstance(aEntity)) { + if (EntityUtils.getDistance(target, aEntity) <= 32) { + aRangedEntity.add((EntityLivingBase) aEntity); + } + } + } + for (EntityLivingBase aEntity : aRangedEntity) { + aEntity.setRevengeTarget((EntityLivingBase) attacker); + } + } + } + } + +} diff --git a/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java b/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java new file mode 100644 index 0000000000..d3700e1373 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java @@ -0,0 +1,124 @@ +package gtPlusPlus.core.handler.events; + +import cpw.mods.fml.common.eventhandler.Event.Result; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.*; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.potion.GtPotionEffect; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent; +import net.minecraftforge.event.entity.player.PlayerWakeUpEvent; + +public class PlayerSleepEventHandler { + + private static ArrayList sPositiveEffects = new ArrayList(); + private static ArrayList sNegativeEffects = new ArrayList(); + + public static void init() { + Utils.registerEvent(new PlayerSleepEventHandler()); + sPositiveEffects.add(Potion.moveSpeed); + sPositiveEffects.add(Potion.waterBreathing); + sPositiveEffects.add(Potion.resistance); + sPositiveEffects.add(Potion.regeneration); + sPositiveEffects.add(Potion.damageBoost); + sPositiveEffects.add(Potion.digSpeed); + sPositiveEffects.add(Potion.fireResistance); + sPositiveEffects.add(Potion.field_76434_w); // Health Boost + sPositiveEffects.add(Potion.field_76444_x); // Absorption + sNegativeEffects.add(Potion.blindness); + sNegativeEffects.add(Potion.confusion); + sNegativeEffects.add(Potion.digSlowdown); + sNegativeEffects.add(Potion.harm); + sNegativeEffects.add(Potion.hunger); + sNegativeEffects.add(Potion.moveSlowdown); + sNegativeEffects.add(Potion.poison); + sNegativeEffects.add(Potion.weakness); + sNegativeEffects.add(Potion.wither); + } + + @SubscribeEvent + public void sleep(PlayerSleepInBedEvent event) { + event.setResult(Result.ALLOW); + } + + @SubscribeEvent + public void wake(PlayerWakeUpEvent event) { + EntityPlayer aPlayer = event.entityPlayer; + if (aPlayer != null && !aPlayer.worldObj.isRemote) { + // Try Heal + float aCurrentHP = aPlayer.getHealth(); + float aMaxHP = aPlayer.getMaxHealth(); + if (aCurrentHP < aMaxHP) { + float aDamage = aMaxHP - aCurrentHP; + float aToHeal = MathUtils.randFloat(1, aDamage); + if (aToHeal > 0) { + aPlayer.heal(aToHeal); + PlayerUtils.messagePlayer(aPlayer, "You slept well and now feel " + (aToHeal >= aDamage / 2 ? "much" : "a little") + " better."); + } + } + // Already healed, try give a buff + else { + int aRandomBuff = MathUtils.randInt(0, sPositiveEffects.size() - 1); + Potion aPotionToApply = sPositiveEffects.get(aRandomBuff); + if (aPotionToApply != null) { + aPlayer.addPotionEffect(new GtPotionEffect(aPotionToApply.id, MathUtils.randInt(60, 180), MathUtils.randInt(0, 2))); + PlayerUtils.messagePlayer(aPlayer, "You feel really well rested."); + } + } + boolean aRemovedBad = false; + /*for (Potion aBadPotion : sNegativeEffects) { + if (curePotionEffect(aPlayer, aBadPotion)) { + aRemovedBad = true; + } + }*/ + if (aRemovedBad) { + PlayerUtils.messagePlayer(aPlayer, "The downsides of life no longer effect you."); + } + } + } + + private static Field sActivePotionEffects = ReflectionUtils.getField(EntityPlayer.class, "activePotionsMap"); + private static Method sOnFinishedPotionEffect = ReflectionUtils.getMethod(EntityPlayer.class, "onFinishedPotionEffect", PotionEffect.class); + + public boolean curePotionEffect(EntityPlayer aPlayer, Potion aPotion) { + HashMap activePotionsMap = new HashMap(); + try { + activePotionsMap = ReflectionUtils.getFieldValue(sActivePotionEffects, aPlayer); + } + catch (Throwable t) { + t.printStackTrace(); + } + if (aPlayer != null && aPotion != null && activePotionsMap != null && activePotionsMap.size() > 0) { + Iterator potionKey = activePotionsMap.keySet().iterator(); + if (!aPlayer.worldObj.isRemote) { + while (potionKey.hasNext()) { + try { + Integer key = potionKey.next(); + PotionEffect effect = (PotionEffect) activePotionsMap.get(key); + if (effect.getPotionID() == aPotion.getId()) { + potionKey.remove(); + ReflectionUtils.invokeVoid(aPlayer, sOnFinishedPotionEffect, new Object[]{effect}); + return true; + } + } + catch (ConcurrentModificationException e) { + e.printStackTrace(); + } + } + } + } + return false; + } + +} -- cgit From e7fb530caf15236026808ffaecaf1b2cae140776 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Sat, 29 Jan 2022 13:33:21 +0000 Subject: Re-allow removal of debuffs when sleeping. Localized chat strings. --- .../handler/events/PlayerSleepEventHandler.java | 70 ++++++++++++++-------- 1 file changed, 44 insertions(+), 26 deletions(-) (limited to 'src/main/java/gtPlusPlus/core/handler') diff --git a/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java b/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java index d3700e1373..b9419a5ba6 100644 --- a/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java +++ b/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java @@ -17,6 +17,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; +import net.minecraft.util.ChatComponentTranslation; import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent; import net.minecraftforge.event.entity.player.PlayerWakeUpEvent; @@ -49,45 +50,62 @@ public class PlayerSleepEventHandler { @SubscribeEvent public void sleep(PlayerSleepInBedEvent event) { - event.setResult(Result.ALLOW); + } @SubscribeEvent public void wake(PlayerWakeUpEvent event) { EntityPlayer aPlayer = event.entityPlayer; - if (aPlayer != null && !aPlayer.worldObj.isRemote) { - // Try Heal - float aCurrentHP = aPlayer.getHealth(); - float aMaxHP = aPlayer.getMaxHealth(); - if (aCurrentHP < aMaxHP) { - float aDamage = aMaxHP - aCurrentHP; - float aToHeal = MathUtils.randFloat(1, aDamage); - if (aToHeal > 0) { - aPlayer.heal(aToHeal); - PlayerUtils.messagePlayer(aPlayer, "You slept well and now feel " + (aToHeal >= aDamage / 2 ? "much" : "a little") + " better."); + if (aPlayer != null && !aPlayer.worldObj.isRemote) { + boolean aRemovedBad = false; + try { + Collection aActive = aPlayer.getActivePotionEffects(); + for (PotionEffect aEffect : aActive) { + for (Potion aBadPotion : sNegativeEffects) { + if (aEffect.getPotionID() == aBadPotion.getId()) { + ReflectionUtils.setField(aEffect, sEffectDuration, 1); + aRemovedBad = true; + Logger.INFO("Set duration of " + aEffect.getEffectName() + " to 1 tick"); + } + } } } - // Already healed, try give a buff - else { - int aRandomBuff = MathUtils.randInt(0, sPositiveEffects.size() - 1); - Potion aPotionToApply = sPositiveEffects.get(aRandomBuff); - if (aPotionToApply != null) { - aPlayer.addPotionEffect(new GtPotionEffect(aPotionToApply.id, MathUtils.randInt(60, 180), MathUtils.randInt(0, 2))); - PlayerUtils.messagePlayer(aPlayer, "You feel really well rested."); - } + catch (Throwable t) { + t.printStackTrace(); } - boolean aRemovedBad = false; - /*for (Potion aBadPotion : sNegativeEffects) { - if (curePotionEffect(aPlayer, aBadPotion)) { - aRemovedBad = true; - } - }*/ if (aRemovedBad) { - PlayerUtils.messagePlayer(aPlayer, "The downsides of life no longer effect you."); + messagePlayer(aPlayer, "sleep.event.downsides"); } + else { + // Try Heal + float aCurrentHP = aPlayer.getHealth(); + float aMaxHP = aPlayer.getMaxHealth(); + if (aCurrentHP < aMaxHP) { + float aDamage = aMaxHP - aCurrentHP; + float aToHeal = MathUtils.randFloat(1, aDamage); + if (aToHeal > 0) { + aPlayer.heal(aToHeal); + messagePlayer(aPlayer, (aToHeal >= aDamage / 2 ? "sleep.event.good" : "sleep.event.okay")); + } + } + // Already healed, try give a buff + else { + int aRandomBuff = MathUtils.randInt(0, sPositiveEffects.size() - 1); + Potion aPotionToApply = sPositiveEffects.get(aRandomBuff); + if (aPotionToApply != null) { + aPlayer.addPotionEffect(new GtPotionEffect(aPotionToApply.id, MathUtils.randInt(60, 180), MathUtils.randInt(0, 2))); + messagePlayer(aPlayer, "sleep.event.wellrested"); + } + } + } } } + + private static void messagePlayer(EntityPlayer aPlayer, String aChatKey) { + PlayerUtils.messagePlayer(aPlayer, new ChatComponentTranslation(aChatKey, new Object[0])); + } + private static Field sEffectDuration = ReflectionUtils.getField(PotionEffect.class, "duration"); private static Field sActivePotionEffects = ReflectionUtils.getField(EntityPlayer.class, "activePotionsMap"); private static Method sOnFinishedPotionEffect = ReflectionUtils.getMethod(EntityPlayer.class, "onFinishedPotionEffect", PotionEffect.class); -- cgit From 228ddd39273b2ac38350764d29982519e27761c1 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Sat, 29 Jan 2022 14:54:57 +0000 Subject: Fixed Magic Feather death handling. Improved Magic Feather beacon handling. --- .../java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/main/java/gtPlusPlus/core/handler') diff --git a/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java b/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java index b9419a5ba6..c36344d805 100644 --- a/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java +++ b/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java @@ -1,7 +1,5 @@ package gtPlusPlus.core.handler.events; -import cpw.mods.fml.common.eventhandler.Event.Result; - import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.*; @@ -14,7 +12,6 @@ import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; import gtPlusPlus.core.util.reflect.ReflectionUtils; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.ChatComponentTranslation; -- cgit From 1d983706ef427b1d008787843ac23529e43cc659 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Sat, 29 Jan 2022 19:55:05 +0000 Subject: Minor Clean-up/Regression. --- .../handler/events/PlayerSleepEventHandler.java | 39 ++-------------------- 1 file changed, 3 insertions(+), 36 deletions(-) (limited to 'src/main/java/gtPlusPlus/core/handler') diff --git a/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java b/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java index c36344d805..10677c12db 100644 --- a/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java +++ b/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java @@ -1,8 +1,8 @@ package gtPlusPlus.core.handler.events; import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import gtPlusPlus.api.objects.Logger; @@ -20,6 +20,7 @@ import net.minecraftforge.event.entity.player.PlayerWakeUpEvent; public class PlayerSleepEventHandler { + private static Field sEffectDuration = ReflectionUtils.getField(PotionEffect.class, "duration"); private static ArrayList sPositiveEffects = new ArrayList(); private static ArrayList sNegativeEffects = new ArrayList(); @@ -102,38 +103,4 @@ public class PlayerSleepEventHandler { PlayerUtils.messagePlayer(aPlayer, new ChatComponentTranslation(aChatKey, new Object[0])); } - private static Field sEffectDuration = ReflectionUtils.getField(PotionEffect.class, "duration"); - private static Field sActivePotionEffects = ReflectionUtils.getField(EntityPlayer.class, "activePotionsMap"); - private static Method sOnFinishedPotionEffect = ReflectionUtils.getMethod(EntityPlayer.class, "onFinishedPotionEffect", PotionEffect.class); - - public boolean curePotionEffect(EntityPlayer aPlayer, Potion aPotion) { - HashMap activePotionsMap = new HashMap(); - try { - activePotionsMap = ReflectionUtils.getFieldValue(sActivePotionEffects, aPlayer); - } - catch (Throwable t) { - t.printStackTrace(); - } - if (aPlayer != null && aPotion != null && activePotionsMap != null && activePotionsMap.size() > 0) { - Iterator potionKey = activePotionsMap.keySet().iterator(); - if (!aPlayer.worldObj.isRemote) { - while (potionKey.hasNext()) { - try { - Integer key = potionKey.next(); - PotionEffect effect = (PotionEffect) activePotionsMap.get(key); - if (effect.getPotionID() == aPotion.getId()) { - potionKey.remove(); - ReflectionUtils.invokeVoid(aPlayer, sOnFinishedPotionEffect, new Object[]{effect}); - return true; - } - } - catch (ConcurrentModificationException e) { - e.printStackTrace(); - } - } - } - } - return false; - } - } -- cgit