@Override
  public void onWornTick(ItemStack stack, EntityLivingBase player) {
    if (!player.isInvisible()) {
      player.setInvisible(true);
    }
    NBTTagCompound tag = new NBTTagCompound();
    ((EntityPlayer) player).writeToNBT(tag);
    NBTTagCompound forgeTag = tag.getCompoundTag("ForgeData");

    int corruption = 0;

    if (forgeTag.hasKey("MindCorruption")) corruption = forgeTag.getInteger("MindCorruption");
    else forgeTag.setInteger("MindCorruption", 0);

    ((EntityPlayer) player).capabilities.disableDamage = true;

    if (!player.worldObj.isRemote) {
      if (corruption <= 0) {
        ((EntityPlayer) player)
            .addChatMessage(
                new ChatComponentText(
                    EMTTextHelper.PURPLE
                        + "You have worn the Ring. Your soul has now been forever "
                        + EMTTextHelper.PURPLE
                        + "tainted. "
                        + EMTTextHelper.RED
                        + EMTTextHelper.ITALIC
                        + "Beware of wearing the ring. The tainting will only "
                        + EMTTextHelper.RED
                        + EMTTextHelper.ITALIC
                        + "increase, and strange things will start happening."));
      } else if (corruption > 6000 && corruption < 24000 && random.nextInt(2000) == 0) {
        player.addPotionEffect(new PotionEffect(Potion.blindness.id, 500, 2, false));
      } else if (corruption >= 6000 && corruption < 24000 && random.nextInt(2000) == 0) {
        player.addPotionEffect(new PotionEffect(Potion.confusion.id, 500, 2, false));
      } else if (corruption >= 24000 && corruption < 72000 && random.nextInt(2000) == 0) {
        ((EntityPlayer) player).capabilities.disableDamage = false;

        player.attackEntityFrom(DamageSource.magic, 5);
      } else if (corruption >= 72000 && corruption < 120000 && random.nextInt(4000) == 0) {
        ((EntityPlayer) player).capabilities.disableDamage = false;

        player.motionY += 2d;
      } else if (corruption >= 120000 && random.nextInt(10000) == 0) {
        ((EntityPlayer) player).capabilities.disableDamage = false;

        player.addPotionEffect(new PotionEffect(Potion.wither.id, 5000, 4, false));
      } else if (corruption + 100 >= Integer.MAX_VALUE) { // =3333333
        player.isDead = true;
      }
    }
    forgeTag.setInteger("MindCorruption", ++corruption);
    tag.setTag("ForgeData", forgeTag);
    ((EntityPlayer) player).readFromNBT(tag);
  }
Beispiel #2
0
 public static boolean canSneakAttack(EntityLivingBase source, Entity target) {
   // TODO handle cover, etc.
   return MonsterUtil.isCritable(target)
       && source.getDistanceToEntity(target) <= MathUtil.feetToMeters(30)
       && (source.isInvisible() || isBehind(source, target));
 }