@SubscribeEvent(priority = EventPriority.LOW) public static void onHeal(LivingHealEvent event) { EntityLivingBase entity = event.getEntityLiving(); if (!entity.hasCapability(CapabilityExtendedHealthSystem.INSTANCE, null)) return; event.setCanceled(true); if (!FirstAid.activeHealingConfig.allowOtherHealingItems) return; float amount = event.getAmount(); //Hacky shit to reduce vanilla regen if (FirstAid.activeHealingConfig.allowNaturalRegeneration && Arrays.stream(Thread.currentThread().getStackTrace()).anyMatch(stackTraceElement -> stackTraceElement.getClassName().equals(FoodStats.class.getName()))) amount = amount * (float) FirstAid.activeHealingConfig.naturalRegenMultiplier; else amount = amount * (float) FirstAid.activeHealingConfig.otherRegenMultiplier; HealthDistribution.distributeHealth(amount, (EntityPlayer) entity, true); }
@Override public void onUpdate(EntityPlayerSP player) { ItemStack curStack = player.inventory.getCurrentItem(); if(isEnabled()) { if(!shouldEat()) { Wrapper.getMinecraft().gameSettings.keyBindUseItem.pressed = false; return; } FoodStats foodStats = player.getFoodStats(); if (foodStats.getFoodLevel() <= hungerFactor.getValue() && shouldEat()) { eatFood(); } } }
public static float getExhaustion(EntityPlayer of) { FoodStats stats = of.getFoodStats(); if (!foodExhaustionLevelFld.isAccessible()) { foodExhaustionLevelFld.setAccessible(true); } try { return foodExhaustionLevelFld.getFloat(stats); } catch (Exception ex) { FMLCommonHandler.instance().raiseException(ex, "ExPetrum was unable to reflect player's FoodStats!", true); return -1; } }
@SuppressWarnings("SameParameterValue") public static void setExhaustion(EntityPlayer of, float f) { FoodStats stats = of.getFoodStats(); if (!foodExhaustionLevelFld.isAccessible()) { foodExhaustionLevelFld.setAccessible(true); } try { foodExhaustionLevelFld.setFloat(stats, f); } catch (Exception ex) { FMLCommonHandler.instance().raiseException(ex, "ExPetrum was unable to reflect player's FoodStats!", true); } }
public static void addNutrition(FoodStats fs, ItemStack is) { IFoodStatsTFC stats = (IFoodStatsTFC)fs; TFCFood food = FoodRegistry.getInstance().getFood(is.getItem(), is.getItemDamage()); if(food != null && is.getItem() instanceof ItemFood) { ItemFood item = (ItemFood)is.getItem(); Iterator iter = food.foodGroup.iterator(); while(iter.hasNext()) { FoodGroupPair pair = (FoodGroupPair) iter.next(); float amount = pair.amount; if(pair.foodGroup != EnumFoodGroup.None) { amount = Math.min(stats.getNutritionMap().get(pair.foodGroup) + (item.getHealAmount(is) * (pair.amount / 100f)*0.25f), 20); stats.getNutritionMap().put(pair.foodGroup, amount); } } } }
/** Handles the hunger setting, returns if hunger is enabled. */ private boolean handleHunger(EntityPlayer player, FoodStats foodStats) { EnumHunger hunger = AdvHealthOptions.config.<EnumHunger>get(AHOWorldConfig.miscHunger); if (hunger == EnumHunger.ENABLE) return true; // Make direct changes to the food meter affect health directly. if ((hunger == EnumHunger.HEALTH) && foodLevelSet) { int change = (foodStats.getFoodLevel() - 8); if (change > 0) player.heal(change); else if (change < 0) player.attackEntityFrom(DamageSource.starve, -change); } // Reset the food level and saturation. setFoodLevel(player, 0); foodStats.addStats(8, 20.0F); foodLevelSet = true; return false; }
@Override public void doOnServer(EntityPlayer player, NBTTagCompound dataFromClient) { FoodStats food = player.getFoodStats(); switch (dataFromClient.getInteger(OPERATION_KEY)) { case ADD: food.addStats((int) dataFromClient.getFloat(AMOUNT_KEY), 0); break; case SUBTRACT: food.addStats((int) -dataFromClient.getFloat(AMOUNT_KEY), 0); break; case SET: food.addStats(-food.getFoodLevel(), 0); food.addStats((int) dataFromClient.getFloat(AMOUNT_KEY), 0); break; } }
@Override public void doOnServer(EntityPlayer player, NBTTagCompound dataFromClient) { FoodStats food = player.getFoodStats(); switch (dataFromClient.getInteger(OPERATION_KEY)) { case ADD: food.addStats(0, dataFromClient.getFloat(AMOUNT_KEY)); break; case SUBTRACT: food.addStats(0, -dataFromClient.getFloat(AMOUNT_KEY)); break; case SET: food.addStats(0, -food.getSaturationLevel()); food.addStats(0, dataFromClient.getFloat(AMOUNT_KEY)); break; } }
public static void setFoodStats(EntityPlayer player, FoodStats stats) { Field[] fields = EntityPlayer.class.getDeclaredFields(); for (Field f : fields) { if (f.getType() == FoodStats.class) { f.setAccessible(true); try { f.set(player, stats); } catch (Exception e) { System.out.println(e); } } } }
@Override public void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player) { if (stack.getTagCompound() == null) { stack.setTagCompound(new NBTTagCompound()); //not really supposed to happen ingame since you only get the stews with NBT values assigned but it prevents crashing } final FoodStats foodStats = player.getFoodStats(); foodStats.setFoodLevel(foodStats.getFoodLevel() + stack.getTagCompound().getInteger("hunger")); foodStats.setFoodSaturationLevel(foodStats.getFoodLevel() + stack.getTagCompound().getFloat("saturation")); player.addItemStackToInventory(new ItemStack(Items.BOWL, 1)); }
@SubscribeEvent public void onUpdate(LocalPlayerUpdateEvent event) { FoodStats foodStats = getLocalPlayer().getFoodStats(); int foodSlot = -1; ItemStack foodStack = null; for (int i = 0; i < 9; i++) { ItemStack stack = getLocalPlayer().inventory.getStackInSlot(i); if (stack != null && stack.getItem() instanceof ItemFood) { foodSlot = i; foodStack = stack; break; } } if (foodStack != null) { ItemFood itemFood = (ItemFood) foodStack.getItem(); if (20 - foodStats.getFoodLevel() >= itemFood.getHealAmount(foodStack) && !getLocalPlayer().isHandActive() && FastReflection.Fields.Minecraft_rightClickDelayTimer.get(MC) == 0) { isEating = true; MC.player.inventory.currentItem = foodSlot; // need to fake use key to stop code that stops the eating Bindings.use.setPressed(true); FastReflection.Methods.Minecraft_rightClickMouse.invoke(MC); return; } } if(isEating && !getLocalPlayer().isHandActive()) { isEating = false; Bindings.use.setPressed(false); } }
@Override public FoodStats getFoodStats() { if (m_realPlayer == null) { return super.getFoodStats(); } else { syncToRealPlayer(); return syncPublicFieldsFromRealAndReturn(m_realPlayer.getFoodStats()); } }
@Override public FoodStats getFoodStats() { if (m_realPlayer == null) { return super.getFoodStats(); } else { return m_realPlayer.getFoodStats(); } }
@SubscribeEvent public void entityUpdate(LivingEvent.LivingUpdateEvent event) { if(!isPlayer(event.entityLiving)) { return; } EntityPlayer player = (EntityPlayer)event.entityLiving; PlayerCapabilities capabilities = player.capabilities; IAttributeInstance movementSpeed = player.getEntityAttribute(SharedMonsterAttributes.movementSpeed); if(!checkEquips(player)) { event.entityLiving.stepHeight = 0.5F; capabilities.allowFlying = player.capabilities.isCreativeMode; if(!ModConfig.useSpeedPotion) { movementSpeed.setBaseValue(0.1); } FoodStats fs = player.getFoodStats(); if(fs != null) { fs.addStats(20, 5); } return; } player.stepHeight = 1; capabilities.allowFlying = true; if(!ModConfig.useSpeedPotion) { movementSpeed.setBaseValue(ModConfig.speedMultiplicator); } }
/** Reset the "food timer" to disable Vanilla natural regeneration. */ private void resetFoodTimer(FoodStats foodStats) { if (foodTimerField == null) foodTimerField = ReflectionHelper.findField(FoodStats.class, "field_75123_d", "foodTimer"); if (foodStats.getFoodLevel() > 0) { try { foodTimerField.set(foodStats, 0); } catch (Exception ex) { throw new RuntimeException(ex); } } }
public void reset() { float exp = 0; boolean keepInventory = this.worldObj.getGameRules().getGameRuleBooleanValue("keepInventory"); if (this.keepLevel || keepInventory) { exp = this.experience; this.newTotalExp = this.experienceTotal; this.newLevel = this.experienceLevel; } this.setHealth(this.getMaxHealth()); this.fire = 0; this.fallDistance = 0; this.foodStats = new FoodStats(this); this.experienceLevel = this.newLevel; this.experienceTotal = this.newTotalExp; this.experience = 0; this.deathTime = 0; this.clearActivePotions(); // Should be remapped: removeAllEffects should be remapped to this. super.potionsNeedUpdate = true; // Cauldron - change to super to temporarily workaround remapping bug with SpecialSource this.openContainer = this.inventoryContainer; this.attackingPlayer = null; this.entityLivingToAttack = null; this._combatTracker = new CombatTracker(this); this.lastExperience = -1; if (this.keepLevel || keepInventory) { this.experience = exp; } else { this.addExperience(this.newExp); } this.keepLevel = false; }
@Override public ItemStack onItemRightClick(ItemStack stack, World w, EntityPlayer player){ int lunchCarried=MAX_FOOD_CARRIED-stack.getItemDamage(); FoodStats stats=player.getFoodStats(); int playerHunger=20-stats.getFoodLevel(); //feed the player until either they are full or the luncher is out of food int toFeedToPlayer=Math.min(lunchCarried, playerHunger); if(toFeedToPlayer>0){ //if player is hungry and luncher isn't empty w.playSoundAtEntity(player, "random.burp", 0.5F, w.rand.nextFloat() * 0.1F + 0.9F); stats.addStats(toFeedToPlayer, 0); stack.setItemDamage(stack.getItemDamage()+toFeedToPlayer); //Debug.dbg("Luncher omnomnomnom! Ate "+toFeedToPlayer); }else{ int foodGathered=0; boolean full=false; for(int i=0; i<player.inventory.mainInventory.length; i++){ ItemStack stk=player.inventory.mainInventory[i]; if(stk!=null && stk.getItem() instanceof ItemFood){ //check if food ItemFood item=(ItemFood) stk.getItem(); int foodPerItem=item.func_150905_g(stk); int numberCanConsume=(int) Math.floor( (double)stack.getItemDamage() /foodPerItem ); int eating=stack.getItemDamage()-foodPerItem*Math.min(numberCanConsume, stk.stackSize); //Debug.dbg("Can eat "+numberCanConsume + " of " + stk.stackSize +". Eating "+eating ); stack.setItemDamage(Math.max(eating,0)); if(numberCanConsume>=stk.stackSize){ player.inventory.mainInventory[i]=null; }else{ stk.stackSize-=numberCanConsume; } } if(full)break; } } return stack; }
@Override public void render(Minecraft mc, ScaledResolution res, float partialTicks, HPHud hud) { super.render(mc, res, partialTicks, hud); hud.bindTexture(ICONS); int left = halfWidth + hudHalfWidth; int top = height - hudBaseline; FoodStats stats = mc.thePlayer.getFoodStats(); int level = stats.getFoodLevel(); for (int i = 0; i < maxFood/2; i++) { int x = left - (i * 8) - iconSize; int y = top; int icon = 16; byte backgound = 0; //determines how the current icon will be displayed (full, partial, empty) int wholeFood = (i * 2) + 1; if (stats.getSaturationLevel() <= 0.0F && hud.getUpdateCounter() % (level * 3 + 1) == 0) { y = top + (hud.getRand().nextInt(3) - 1); } if (mc.thePlayer.isPotionActive(Potion.hunger)) { icon += 36; backgound = 13; } //draws the haunch outline (background) hud.drawTexturedModalRect(x, y, 16 + (backgound * iconSize), 27, iconSize, iconSize); //draws the actual food haunch if (wholeFood < level) hud.drawTexturedModalRect(x, y, icon + (iconSize * 4), 27, iconSize, iconSize); else if (wholeFood == level) hud.drawTexturedModalRect(x, y, icon + (iconSize * 5), 27, iconSize, iconSize); //else; draw nothing. no haunch is drawn but the background is. } }
/** * Returns the player's FoodStats object. */ public FoodStats getFoodStats() { return this.foodStats; }
public void renderFood(int width, int height) { if (pre(FOOD)) return; mc.mcProfiler.startSection("food"); EntityPlayer player = (EntityPlayer)this.mc.getRenderViewEntity(); GlStateManager.enableBlend(); int left = width / 2 + 91; int top = height - right_height; right_height += 10; boolean unused = false;// Unused flag in vanilla, seems to be part of a 'fade out' mechanic FoodStats stats = mc.thePlayer.getFoodStats(); int level = stats.getFoodLevel(); for (int i = 0; i < 10; ++i) { int idx = i * 2 + 1; int x = left - i * 8 - 9; int y = top; int icon = 16; byte background = 0; if (mc.thePlayer.isPotionActive(MobEffects.HUNGER)) { icon += 36; background = 13; } if (unused) background = 1; //Probably should be a += 1 but vanilla never uses this if (player.getFoodStats().getSaturationLevel() <= 0.0F && updateCounter % (level * 3 + 1) == 0) { y = top + (rand.nextInt(3) - 1); } drawTexturedModalRect(x, y, 16 + background * 9, 27, 9, 9); if (idx < level) drawTexturedModalRect(x, y, icon + 36, 27, 9, 9); else if (idx == level) drawTexturedModalRect(x, y, icon + 45, 27, 9, 9); } GlStateManager.disableBlend(); mc.mcProfiler.endSection(); post(FOOD); }
public FoodStats getFoodStats() { return this.foodStats; }
public void renderFood(int width, int height) { if (pre(FOOD)) return; field_73839_d.field_71424_I.func_76320_a("food"); GL11.glEnable(GL11.GL_BLEND); int left = width / 2 + 91; int top = height - right_height; right_height += 10; boolean unused = false;// Unused flag in vanilla, seems to be part of a 'fade out' mechanic FoodStats stats = field_73839_d.field_71439_g.func_71024_bL(); int level = stats.func_75116_a(); int levelLast = stats.func_75120_b(); for (int i = 0; i < 10; ++i) { int idx = i * 2 + 1; int x = left - i * 8 - 9; int y = top; int icon = 16; byte backgound = 0; if (field_73839_d.field_71439_g.func_70644_a(Potion.field_76438_s)) { icon += 36; backgound = 13; } if (unused) backgound = 1; //Probably should be a += 1 but vanilla never uses this if (field_73839_d.field_71439_g.func_71024_bL().func_75115_e() <= 0.0F && field_73837_f % (level * 3 + 1) == 0) { y = top + (field_73842_c.nextInt(3) - 1); } func_73729_b(x, y, 16 + backgound * 9, 27, 9, 9); if (unused) { if (idx < levelLast) func_73729_b(x, y, icon + 54, 27, 9, 9); else if (idx == levelLast) func_73729_b(x, y, icon + 63, 27, 9, 9); } if (idx < level) func_73729_b(x, y, icon + 36, 27, 9, 9); else if (idx == level) func_73729_b(x, y, icon + 45, 27, 9, 9); } GL11.glDisable(GL11.GL_BLEND); field_73839_d.field_71424_I.func_76319_b(); post(FOOD); }
public void renderFood(int width, int height) { if (pre(FOOD)) return; mc.mcProfiler.startSection("food"); GL11.glEnable(GL11.GL_BLEND); int left = width / 2 + 91; int top = height - right_height; right_height += 10; boolean unused = false;// Unused flag in vanilla, seems to be part of a 'fade out' mechanic FoodStats stats = mc.thePlayer.getFoodStats(); int level = stats.getFoodLevel(); int levelLast = stats.getPrevFoodLevel(); for (int i = 0; i < 10; ++i) { int idx = i * 2 + 1; int x = left - i * 8 - 9; int y = top; int icon = 16; byte backgound = 0; if (mc.thePlayer.isPotionActive(Potion.hunger)) { icon += 36; backgound = 13; } if (unused) backgound = 1; //Probably should be a += 1 but vanilla never uses this if (mc.thePlayer.getFoodStats().getSaturationLevel() <= 0.0F && updateCounter % (level * 3 + 1) == 0) { y = top + (rand.nextInt(3) - 1); } drawTexturedModalRect(x, y, 16 + backgound * 9, 27, 9, 9); if (unused) { if (idx < levelLast) drawTexturedModalRect(x, y, icon + 54, 27, 9, 9); else if (idx == levelLast) drawTexturedModalRect(x, y, icon + 63, 27, 9, 9); } if (idx < level) drawTexturedModalRect(x, y, icon + 36, 27, 9, 9); else if (idx == level) drawTexturedModalRect(x, y, icon + 45, 27, 9, 9); } GL11.glDisable(GL11.GL_BLEND); mc.mcProfiler.endSection(); post(FOOD); }
@Override public void update() { super.update(); EntityPlayer player = (EntityPlayer)getEntity(); boolean wasHurt = hurt; hurt = false; FoodStats foodStats = player.getFoodStats(); boolean hungerEnabled = handleHunger(player, foodStats); boolean shieldPreventHeal = handleShield(player, wasHurt); resetFoodTimer(foodStats); // If the heal time is set to 0, disable all regeneration. double regenHealTime = AdvHealthOptions.config.<Double>get(AHOWorldConfig.regenHealTime); if ((regenHealTime <= 0) && !DEBUG) return; if (wasHurt) increasePenaltyTimer(player); // Decrease penalty timer. penaltyTimer.set(Math.max(0, penaltyTimer.get() - 1 / 20.0)); // If player has full or no health, reset regeneration timer and return. if (!player.shouldHeal()) { regenTimer.set(0.0); if (!DEBUG) return; } double foodFactor = (hungerEnabled ? calculateFoodFactor(foodStats.getFoodLevel()) : 1.0); // If player has the hunger potion effect (food poisoning?), apply hunger poison factor. if (player.getActivePotionEffect(Potion.hunger) != null) foodFactor *= AdvHealthOptions.config.<Double>get(AHOWorldConfig.regenHungerPoisonFactor); double penaltyFactor = calculatePenaltyFactor(penaltyTimer.get()); if (!shieldPreventHeal && (regenHealTime > 0) && ((regenTimer.set(regenTimer.get() + (penaltyFactor * foodFactor) / 20.0)) > regenHealTime)) { player.heal(1); double regenExhaustion = AdvHealthOptions.config.<Double>get(AHOWorldConfig.regenExhaustion); foodStats.addExhaustion((float)regenExhaustion); regenTimer.set(regenTimer.get() - regenHealTime); } if (DEBUG) System.out.println(String.format("%s: Regen=%d/%d+%.2f Penalty=%d/%d/%d+%.2f Shield=%d/%d", player.getCommandSenderName(), regenTimer.get().intValue(), (int)regenHealTime, foodFactor, penaltyTimer.get().intValue(), AdvHealthOptions.config.<Double>get(AHOWorldConfig.hurtPenaltyBuffer).intValue(), AdvHealthOptions.config.<Double>get(AHOWorldConfig.hurtPenaltyMaximum).intValue(), penaltyFactor, shieldTimer.get().intValue(), AdvHealthOptions.config.<Double>get(AHOWorldConfig.shieldRechargeTime).intValue())); }
private void setFoodLevel(EntityPlayer player, int level) { if (foodLevelField == null) foodLevelField = ReflectionHelper.findField(FoodStats.class, "field_75127_a", "foodLevel"); try { foodLevelField.set(player.getFoodStats(), level); } catch (Exception ex) { throw new RuntimeException(ex); } }