public static ItemStack chargeHealth( ItemStack stack, World world, EntityPlayer player, String tag) { if (!stack.hasTagCompound()) stack.setTagCompound(new NBTTagCompound()); NBTTagCompound nbtData = stack.getTagCompound(); if (nbtData == null) { stack.getTagCompound().setInteger(tag, 0); } if (player.isSneaking()) { int points = stack.getTagCompound().getInteger(tag); if (points != 0) { int current = (int) player.getHealth(); int max = (int) player.getMaxHealth(); if (current != max & (current < max)) { int used = max - current; if (!(points - used < 0)) { nbtData.setInteger(tag, points - used); player.setHealth(player.getMaxHealth()); } else if ((points - used < 0)) { nbtData.setInteger(tag, 0); player.setHealth(nbtData.getInteger(tag) + current); } } } } else { FontHelper.sendMessage( FontHelper.translate("points.health") + ": " + stack.getTagCompound().getInteger(tag), world, player); } return stack; }
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { if (player.isSneaking()) { ItemStack newStack = new ItemStack(ModObjects.heartWand, 1, stack.getItemDamage() + 1); if (newStack.getItemDamage() >= 3) { newStack.setItemDamage(0); } return newStack; } else { ItemStack container; switch (stack.getItemDamage()) { case 0: container = LifeSystem.findFilledLifeContainer(player.inventory.mainInventory); if (container != null && player.getHealth() < player.getMaxHealth()) { if (((ILifeContainer) container.getItem()).takeLife(container, 1) > 0) { player.heal(1f); player.addStat(ModAchievements.useLP, 1); } } break; case 1: break; case 2: container = LifeSystem.findEmptyLifeContainer(player.inventory.mainInventory); if (container != null && player.attackEntityFrom(ModObjects.sacrifice, 1f)) { if (((ILifeContainer) container.getItem()).addLife(container, 1) > 0) { player.addStat(ModAchievements.useHeartWand, 1); } } break; } } return stack; }
@Override protected void onFoodEaten(ItemStack itemstack, World world, EntityPlayer player) { player.extinguish(); if (!world.isRemote) { Random random = player.getRNG(); int max = random.nextInt(3) + 1; for (int i = 0; i < max; ++i) { Potion potion = null; while (potion == null || potion.getEffectiveness() <= 0.5D || player.isPotionActive(potion)) { potion = Potion.potionTypes[random.nextInt(Potion.potionTypes.length)]; } if (potion != null) { player.addPotionEffect(new PotionEffect(potion.getId(), random.nextInt(500) + 150)); } } } player.getFoodStats().addStats((20 - player.getFoodStats().getFoodLevel()) / 2, 0.5F); player.heal((player.getMaxHealth() - player.getHealth()) * 0.5F); }
@Override public void doAttack(int ticks, EntityFinalBoss boss, World w, Random rand) { if (ticks % 5 == 0) { Vec3 start = Vec3.createVectorHelper(boss.posX, boss.posY + 0.5, boss.posZ); AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox( start.xCoord - 50, start.yCoord - 50, start.zCoord - 50, start.xCoord + 50, start.yCoord + 50, start.zCoord + 50); for (Object o : w.getEntitiesWithinAABB(EntityPlayer.class, bounds)) { EntityPlayer pl = (EntityPlayer) o; // For some reason, the server's position is normal, but // the client's position is 1.62 higher Vec3 end = Vec3.createVectorHelper(pl.posX, pl.posY + (w.isRemote ? 0 : 1.62), pl.posZ); Vec3 vec = start.subtract(end).normalize(); vec.xCoord /= 2; vec.yCoord /= 2; vec.zCoord /= 2; double lastDistSq = -1; Vec3 pos = Vec3.createVectorHelper(start.xCoord, start.yCoord, start.zCoord); boolean hit = true; while (true) { pos = pos.addVector(vec.xCoord, vec.yCoord, vec.zCoord); if (w.getBlock( (int) Math.floor(pos.xCoord), (int) Math.floor(pos.yCoord), (int) Math.floor(pos.zCoord)) .isOpaqueCube()) { hit = false; break; } if (lastDistSq >= 0 && pos.squareDistanceTo(end) > lastDistSq) { break; } w.spawnParticle("witchMagic", pos.xCoord, pos.yCoord, pos.zCoord, 0, 0, 0); lastDistSq = pos.squareDistanceTo(end); } if (hit) { pl.attackEntityFrom( DamageSource.causeMobDamage(boss).setDamageBypassesArmor(), pl.getMaxHealth() / 4); } } } }
@Override public boolean onItemUse( ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { EntityPlayer player = par2EntityPlayer; ExtendedPlayer props = ExtendedPlayer.get(player); if (!player.capabilities.isCreativeMode) { float maxHealth = player.getMaxHealth(); IAttributeInstance attrMaxHealth = player.getEntityAttribute(SharedMonsterAttributes.maxHealth); if (attrMaxHealth.getAttributeValue() < dblMaxHealthLimit && props.getMaxHealth() < dblMaxHealthLimit) { maxHealth += healthIncreaseAmount; player.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(maxHealth); player.setHealth(maxHealth); props.setMaxHealth(maxHealth); par1ItemStack.damageItem(2, par2EntityPlayer); if (!player.worldObj.isRemote) { ZollernHelper.addChatMessage( player, EnumChatFormatting.GOLD + "+" + this.healthIncreaseAmount + " Max Health! Total: " + props.getMaxHealth()); } } else { ZollernHelper.addChatMessage(player, "Max health cannot exceed " + dblMaxHealthLimit + "."); } } return true; }
@Override public void useDoomsday( DoomsdayEffect effect, PropertyDoom doom, EntityPlayer player, boolean crucMoment) { double d0 = 12.0; List<Entity> list = player.worldObj.getEntitiesWithinAABBExcludingEntity( player, player.boundingBox.expand(d0, d0, d0)); float crisis = this.getCrisis(player); crisis /= 1.0F / 20.0F; if (list.size() > 0) { for (int i = 0; i < list.size(); i++) { if (list.get(i) instanceof EntityLivingBase) { EntityLivingBase entity = (EntityLivingBase) list.get(i); if (entity instanceof EntityPlayer && !TragicConfig.allowPvP) continue; int dur = crucMoment ? 600 : 300; if (TragicConfig.allowHarmony) { entity.addPotionEffect(new PotionEffect(TragicPotion.Harmony.id, dur)); } else { entity.addPotionEffect(new PotionEffect(Potion.blindness.id, dur)); } if (player.getHealth() < player.getMaxHealth()) { float potato = crucMoment ? crisis * 2 : crisis; player.heal(potato); } } } } else { addNoEntityMessage(player); } }
@Override public void runForPlayer(EntityPlayer player) { player.setHealth(player.getMaxHealth()); player.addChatMessage(notice); }