From 6312636fd9a4d0f56dc7c9ff474a99d879bcb4e9 Mon Sep 17 00:00:00 2001 From: OnyxDarkKnight Date: Mon, 23 Mar 2015 14:51:06 +0000 Subject: Reworked the whole repo. --- .../jewelrycraft/effects/EffectBlazePowder.java | 95 ++++++++++++++++++++++ .../jewelrycraft/effects/EffectEnderEye.java | 79 ++++++++++++++++++ .../jewelrycraft/effects/EffectFeather.java | 88 ++++++++++++++++++++ .../jewelrycraft/effects/EffectsList.java | 22 +++++ .../jewelrycraft/effects/ModifierEffects.java | 85 +++++++++++++++++++ 5 files changed, 369 insertions(+) create mode 100644 src/main/java/darkknight/jewelrycraft/effects/EffectBlazePowder.java create mode 100644 src/main/java/darkknight/jewelrycraft/effects/EffectEnderEye.java create mode 100644 src/main/java/darkknight/jewelrycraft/effects/EffectFeather.java create mode 100644 src/main/java/darkknight/jewelrycraft/effects/EffectsList.java create mode 100644 src/main/java/darkknight/jewelrycraft/effects/ModifierEffects.java (limited to 'src/main/java/darkknight/jewelrycraft/effects') diff --git a/src/main/java/darkknight/jewelrycraft/effects/EffectBlazePowder.java b/src/main/java/darkknight/jewelrycraft/effects/EffectBlazePowder.java new file mode 100644 index 0000000..949d0d8 --- /dev/null +++ b/src/main/java/darkknight/jewelrycraft/effects/EffectBlazePowder.java @@ -0,0 +1,95 @@ +package darkknight.jewelrycraft.effects; + +import net.minecraft.block.material.Material; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.DamageSource; +import darkknight.jewelrycraft.item.ItemBracelet; +import darkknight.jewelrycraft.item.ItemEarrings; +import darkknight.jewelrycraft.item.ItemNecklace; +import darkknight.jewelrycraft.item.ItemRing; +import darkknight.jewelrycraft.util.JewelryNBT; +import darkknight.jewelrycraft.util.PlayerUtils; + +public class EffectBlazePowder extends ModifierEffects +{ + public EffectBlazePowder() + { + super(new ItemStack(Items.blaze_powder)); + } + + @Override + public void action(ItemStack item, EntityPlayer player, Item jewelry) + { + int pos = JewelryNBT.doesModifierExist(item, modifier); + if (jewelry instanceof ItemNecklace && pos != -1){ + //Positive for necklace + player.extinguish(); + + //Negative for necklace + if (player.isInWater()) player.attackEntityFrom(DamageSource.drown, 1f); + } + //Negative for bracelet + if (jewelry instanceof ItemBracelet && pos != -1 && player.isInWater()){ + player.motionX *= 0.6D; + player.motionY *= 0.6D; + player.motionZ *= 0.6D; + player.motionY -= 0.02D; + if (player.isCollidedHorizontally) player.motionY = 0.30000001192092896D; + } + + //Negative for earrings + if (jewelry instanceof ItemEarrings && pos != -1){ + if (player.getAir() >= 300) player.setAir(player.getAir() / 2); + else player.setAir(player.getAir() - 1); + } + } + + @Override + public boolean onEntityAttackedCacellable(ItemStack item, EntityPlayer player, Entity target, Item jewelry, float amount) + { + int pos = JewelryNBT.doesModifierExist(item, modifier); + //Balanced for ring + if (jewelry instanceof ItemRing && pos != -1 && !player.isInWater()) target.setFire(2); + return false; + } + + @Override + public boolean onPlayerAttackedCacellable(ItemStack item, EntityPlayer player, DamageSource source, Item jewelry, float amount) + { +// int pos = JewelryNBT.doesModifierExist(item, modifier); +// if (jewelry instanceof ItemEarrings && pos != -1 && rand.nextInt(4) == 0) if (source == DamageSource.lava || source == DamageSource.inFire || source == DamageSource.onFire){ +// //Positive for earrings +// int stackSize = JewelryNBT.modifier(item).get(pos).stackSize; +// player.heal((float)(0.05 * stackSize)); +// return true; +// } +// //Positive for bracelet +// if (jewelry instanceof ItemBracelet && pos != -1) if (source == DamageSource.inFire || source == DamageSource.onFire || source == DamageSource.lava && player.worldObj.isMaterialInBB(AxisAlignedBB.getBoundingBox(player.boundingBox.minX, player.boundingBox.minY, player.boundingBox.minZ, player.boundingBox.maxX, player.boundingBox.maxY - 0.7, player.boundingBox.maxZ), Material.lava) && !player.worldObj.isMaterialInBB(AxisAlignedBB.getBoundingBox(player.boundingBox.minX, player.boundingBox.minY + 0.9, player.boundingBox.minZ, player.boundingBox.maxX, player.boundingBox.maxY, player.boundingBox.maxZ), Material.lava)) return true; + return false; + } + + public void onEntityAttacked(ItemStack item, EntityPlayer player, Entity target, Item jewelry, float amount) + { + + } + + public void onPlayerAttacked(ItemStack item, EntityPlayer player, DamageSource source, Item jewelry, float amount) + { + int pos = JewelryNBT.doesModifierExist(item, modifier); + NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, "Jewelrycraft"); + if (jewelry instanceof ItemEarrings && pos != -1 && rand.nextInt(4) == 0) if (source == DamageSource.lava || source == DamageSource.inFire || source == DamageSource.onFire){ + //Positive for earrings + int stackSize = JewelryNBT.modifier(item).get(pos).stackSize; + player.heal((float)(0.05 * stackSize)); + playerInfo.setBoolean("negateDamage", true); + } + //Positive for bracelet + if (jewelry instanceof ItemBracelet && pos != -1) if (source == DamageSource.inFire || source == DamageSource.onFire || source == DamageSource.lava && player.worldObj.isMaterialInBB(AxisAlignedBB.getBoundingBox(player.boundingBox.minX, player.boundingBox.minY, player.boundingBox.minZ, player.boundingBox.maxX, player.boundingBox.maxY - 0.7, player.boundingBox.maxZ), Material.lava) && !player.worldObj.isMaterialInBB(AxisAlignedBB.getBoundingBox(player.boundingBox.minX, player.boundingBox.minY + 0.9, player.boundingBox.minZ, player.boundingBox.maxX, player.boundingBox.maxY, player.boundingBox.maxZ), Material.lava)) playerInfo.setBoolean("negateDamage", true); + } +} diff --git a/src/main/java/darkknight/jewelrycraft/effects/EffectEnderEye.java b/src/main/java/darkknight/jewelrycraft/effects/EffectEnderEye.java new file mode 100644 index 0000000..eb7bef7 --- /dev/null +++ b/src/main/java/darkknight/jewelrycraft/effects/EffectEnderEye.java @@ -0,0 +1,79 @@ +package darkknight.jewelrycraft.effects; + +import net.minecraft.block.BlockOre; +import net.minecraft.client.Minecraft; +import net.minecraft.client.settings.GameSettings.Options; +import net.minecraft.entity.monster.EntityEnderman; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.Vec3; +import net.minecraft.world.ChunkPosition; +import net.minecraft.world.biome.BiomeGenBase; +import cpw.mods.fml.relauncher.ReflectionHelper; +import darkknight.jewelrycraft.item.ItemBracelet; +import darkknight.jewelrycraft.item.ItemEarrings; +import darkknight.jewelrycraft.item.ItemNecklace; +import darkknight.jewelrycraft.item.ItemRing; +import darkknight.jewelrycraft.util.JewelryNBT; + +public class EffectEnderEye extends ModifierEffects +{ + private boolean originalVD = false; + private float originalViewDistance; + public EffectEnderEye() + { + super(new ItemStack(Items.ender_eye)); + } + + @Override + public void action(ItemStack item, EntityPlayer player, Item jewelry) + { + int pos = JewelryNBT.doesModifierExist(item, modifier); + if (jewelry instanceof ItemEarrings && pos != -1 && !player.worldObj.isRemote){ + for(Object e: player.worldObj.getEntitiesWithinAABB(EntityEnderman.class, player.boundingBox.expand(100D, 0D, 100D))){ + EntityEnderman enderman = (EntityEnderman)e; + ReflectionHelper.setPrivateValue(EntityEnderman.class, enderman, -1, "stareTimer", "field_70826_g"); + Vec3 vec3 = player.getLook(1.0F).normalize(); + Vec3 vec31 = Vec3.createVectorHelper(enderman.posX - player.posX, enderman.boundingBox.minY + (double)(enderman.height / 2.0F) - (player.posY + (double)player.getEyeHeight()), enderman.posZ - player.posZ); + double d0 = vec31.lengthVector(); + vec31 = vec31.normalize(); + double d1 = vec3.dotProduct(vec31); + if (d1 > 1.0D - 0.025D / d0 && player.canEntityBeSeen(enderman)){ + enderman.setTarget(null); + if (!player.isPotionActive(Potion.confusion) || player.getActivePotionEffect(Potion.confusion).getDuration() <= 80) player.addPotionEffect(new PotionEffect(Potion.confusion.id, 300, 2)); + } + } + } + if (jewelry instanceof ItemNecklace && pos != -1 && !player.worldObj.isRemote){ + ChunkPosition chunkposition = player.worldObj.findClosestStructure("Stronghold", (int)player.posX, (int)player.posY, (int)player.posZ); + if (chunkposition != null){ + Minecraft.getMinecraft().thePlayer.motionX += 0.01D * Math.signum((double)chunkposition.chunkPosX - player.posX); + Minecraft.getMinecraft().thePlayer.motionZ += 0.01D * Math.signum((double)chunkposition.chunkPosZ - player.posZ); + } + } + if (jewelry instanceof ItemBracelet && pos != -1 && !player.worldObj.isRemote && player.worldObj.getBiomeGenForCoords((int)player.posX, (int)player.posZ) == BiomeGenBase.sky && (!player.isPotionActive(Potion.moveSpeed) || player.getActivePotionEffect(Potion.moveSpeed).getDuration() < 30)) player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 140, 1)); + if (jewelry instanceof ItemBracelet && pos != -1 && !player.worldObj.isRemote && rand.nextInt(500) == 15) player.setPositionAndUpdate(player.posX + rand.nextInt(30)*(rand.nextBoolean()?-1:1), player.posY, player.posZ + rand.nextInt(30)*(rand.nextBoolean()?-1:1)); + if (jewelry instanceof ItemRing && pos != -1 && rand.nextInt(200) == 12){ + Minecraft.getMinecraft().gameSettings.setOptionFloatValue(Options.RENDER_DISTANCE, 1.0F); + for(int i = (int)player.posX - 2; i <= (int)player.posX + 2; i++) + for(int j = (int)player.posY - 2; j <= (int)player.posY + 2; j++) + for(int k = (int)player.posZ - 2; k <= (int)player.posZ + 2; k++) + if(player.worldObj.getBlock(i, j, k) instanceof BlockOre) + player.addChatComponentMessage(new ChatComponentText(EnumChatFormatting.GRAY + "You sense some " + player.worldObj.getBlock(i, j, k).getLocalizedName() + " around you.")); + } + } + + @Override + public void onPlayerAttacked(ItemStack item, EntityPlayer player, DamageSource source, Item jewelry, float amount) + { + int pos = JewelryNBT.doesModifierExist(item, modifier); + if (jewelry instanceof ItemNecklace && pos != -1 && !player.worldObj.isRemote) player.addPotionEffect(new PotionEffect(Potion.blindness.id, 100, 1)); + } +} diff --git a/src/main/java/darkknight/jewelrycraft/effects/EffectFeather.java b/src/main/java/darkknight/jewelrycraft/effects/EffectFeather.java new file mode 100644 index 0000000..2acaf76 --- /dev/null +++ b/src/main/java/darkknight/jewelrycraft/effects/EffectFeather.java @@ -0,0 +1,88 @@ +package darkknight.jewelrycraft.effects; + +import java.util.Iterator; +import java.util.List; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumChatFormatting; +import darkknight.jewelrycraft.damage.DamageSourceList; +import darkknight.jewelrycraft.item.ItemBracelet; +import darkknight.jewelrycraft.item.ItemEarrings; +import darkknight.jewelrycraft.item.ItemNecklace; +import darkknight.jewelrycraft.item.ItemRing; +import darkknight.jewelrycraft.util.JewelryNBT; +import darkknight.jewelrycraft.util.PlayerUtils; + +public class EffectFeather extends ModifierEffects +{ + public EffectFeather() + { + super(new ItemStack(Items.feather)); + } + + @Override + public void action(ItemStack item, EntityPlayer player, Item jewelry) + { + int pos = JewelryNBT.doesModifierExist(item, modifier); + NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, "Jewelrycraft"); + // Positive earrings + if (jewelry instanceof ItemEarrings && pos != -1){ + AxisAlignedBB axisalignedbb = player.boundingBox.expand(1.0D, 1.0D, 1.0D); + List list = player.worldObj.getEntitiesWithinAABB(EntityArrow.class, axisalignedbb); + if (!player.worldObj.isRemote && list != null && !list.isEmpty()){ + Iterator iterator = list.iterator(); + while (iterator.hasNext()){ + EntityArrow arrow = (EntityArrow)iterator.next(); + if (rand.nextInt(3) == 0 && (arrow.shootingEntity == null || !(arrow.shootingEntity.equals(player)) || arrow.canBePickedUp == 0)) arrow.setDead(); + } + } + } + // Positive bracelet + if (jewelry instanceof ItemBracelet && pos != -1){ + if (player.motionY < 0) player.motionY *= 0.6D; + player.setAIMoveSpeed(player.getAIMoveSpeed() / 2); + player.fallDistance = 0F; + } + } + + @Override + public void onEntityAttacked(ItemStack item, EntityPlayer player, Entity target, Item jewelry, float amount) + { + int pos = JewelryNBT.doesModifierExist(item, modifier); + NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, "Jewelrycraft"); + NBTTagCompound enemyData = target.getEntityData(); + if (jewelry instanceof ItemRing && pos != -1 && enemyData.getInteger("reAttacked") == 0){ + enemyData.setInteger("reAttacked", enemyData.getInteger("reAttacked") + 1); + target.attackEntityFrom(DamageSource.causePlayerDamage(player), amount / 2F); + if (rand.nextInt(2) == 0){ + enemyData.setInteger("stunTime", 50); + enemyData.setBoolean("stunned", true); + } + playerInfo.setBoolean("weakDamage", true); + } + if (enemyData.getInteger("reAttacked") == 1) enemyData.setInteger("reAttacked", 0); + } + + @Override + public void onPlayerAttacked(ItemStack item, EntityPlayer player, DamageSource source, Item jewelry, float amount) + { + int pos = JewelryNBT.doesModifierExist(item, modifier); + NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, "Jewelrycraft"); + if (jewelry instanceof ItemNecklace && pos != -1 && rand.nextInt(4) == 0 && source != DamageSourceList.weak && source != DamageSource.inFire && source != DamageSource.onFire && source != DamageSource.lava){ + player.addChatComponentMessage(new ChatComponentText(EnumChatFormatting.GRAY + "The necklace protected you from taking damage!")); + playerInfo.setBoolean("negateDamage", true); + } + // Negative necklace + if (jewelry instanceof ItemNecklace && pos != -1 && (source == DamageSource.inFire || source == DamageSource.onFire || source == DamageSource.lava) && source != DamageSourceList.weak) player.attackEntityFrom(DamageSourceList.weak, amount * 3F); + // Negative earrings + if (jewelry instanceof ItemEarrings && pos != -1 && source.damageType.equals("arrow") && source != DamageSourceList.weak) player.attackEntityFrom(DamageSourceList.weak, amount * 2F); + } +} diff --git a/src/main/java/darkknight/jewelrycraft/effects/EffectsList.java b/src/main/java/darkknight/jewelrycraft/effects/EffectsList.java new file mode 100644 index 0000000..13abc48 --- /dev/null +++ b/src/main/java/darkknight/jewelrycraft/effects/EffectsList.java @@ -0,0 +1,22 @@ +package darkknight.jewelrycraft.effects; + +import cpw.mods.fml.common.event.FMLPostInitializationEvent; + +public class EffectsList +{ + private static ModifierEffects blazePowder, enderEye, feather; + private static boolean isInitialized = false; + + /** + * @param e + */ + public static void postInit(FMLPostInitializationEvent e) + { + if (!isInitialized){ + blazePowder = new EffectBlazePowder(); + enderEye = new EffectEnderEye(); + feather = new EffectFeather(); + isInitialized = true; + } + } +} diff --git a/src/main/java/darkknight/jewelrycraft/effects/ModifierEffects.java b/src/main/java/darkknight/jewelrycraft/effects/ModifierEffects.java new file mode 100644 index 0000000..d3c8e38 --- /dev/null +++ b/src/main/java/darkknight/jewelrycraft/effects/ModifierEffects.java @@ -0,0 +1,85 @@ +package darkknight.jewelrycraft.effects; + +import java.util.ArrayList; +import java.util.Random; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; + +public class ModifierEffects +{ + protected ItemStack modifier; + protected Random rand = new Random(); + protected static ArrayList effects = new ArrayList(); + + /** + * @param modifier + */ + public ModifierEffects(ItemStack modifier) + { + this.modifier = modifier; + effects.add(this); + } + + /** + * @return + */ + public static ArrayList getEffects() + { + return effects; + } + + /** + * @param item + * @param player + * @param jewelry + */ + public void action(ItemStack item, EntityPlayer player, Item jewelry) + {}; + + /** + * @param item + * @param player + * @param target + * @param jewelry + * @return + */ + public boolean onEntityAttackedCacellable(ItemStack item, EntityPlayer player, Entity target, Item jewelry, float amount) + { + return false; + } + + /** + * @param item + * @param player + * @param source + * @param jewelry + * @return + */ + public boolean onPlayerAttackedCacellable(ItemStack item, EntityPlayer player, DamageSource source, Item jewelry, float amount) + { + return false; + } + + /** + * @param item + * @param player + * @param target + * @param jewelry + * @return + */ + public void onEntityAttacked(ItemStack item, EntityPlayer player, Entity target, Item jewelry, float amount) + {} + + /** + * @param item + * @param player + * @param source + * @param jewelry + * @return + */ + public void onPlayerAttacked(ItemStack item, EntityPlayer player, DamageSource source, Item jewelry, float amount) + {} +} -- cgit v1.2.3