aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/core/handler
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gtPlusPlus/core/handler')
-rw-r--r--src/main/java/gtPlusPlus/core/handler/MobMentality.java58
-rw-r--r--src/main/java/gtPlusPlus/core/handler/events/EnderDragonDeathHandler.java57
-rw-r--r--src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java106
3 files changed, 193 insertions, 28 deletions
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<Class<EntityLivingBase>> sIgnoredTypes = new HashSet<Class<EntityLivingBase>>();
+
+ @SubscribeEvent
+ public void onEntityDamaged(LivingHurtEvent event) {
+ final EntityLivingBase target = event.entityLiving;
+ for (Class<EntityLivingBase> 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<Entity> aEntityList = target.worldObj.loadedEntityList;
+ List<EntityLivingBase> aRangedEntity = new ArrayList<EntityLivingBase>();
+ 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/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.");
}
-
+
}
}
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..10677c12db
--- /dev/null
+++ b/src/main/java/gtPlusPlus/core/handler/events/PlayerSleepEventHandler.java
@@ -0,0 +1,106 @@
+package gtPlusPlus.core.handler.events;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+
+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.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;
+
+public class PlayerSleepEventHandler {
+
+ private static Field sEffectDuration = ReflectionUtils.getField(PotionEffect.class, "duration");
+ private static ArrayList<Potion> sPositiveEffects = new ArrayList<Potion>();
+ private static ArrayList<Potion> sNegativeEffects = new ArrayList<Potion>();
+
+ 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) {
+
+ }
+
+ @SubscribeEvent
+ public void wake(PlayerWakeUpEvent event) {
+ EntityPlayer aPlayer = event.entityPlayer;
+ if (aPlayer != null && !aPlayer.worldObj.isRemote) {
+ boolean aRemovedBad = false;
+ try {
+ Collection<PotionEffect> 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");
+ }
+ }
+ }
+ }
+ catch (Throwable t) {
+ t.printStackTrace();
+ }
+ if (aRemovedBad) {
+ 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]));
+ }
+
+}