Skip to content

Commit

Permalink
Fix desync in health values, fixes part to of #36
Browse files Browse the repository at this point in the history
  • Loading branch information
ichttt committed Sep 11, 2018
1 parent bcd3920 commit 594726e
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 22 deletions.
5 changes: 3 additions & 2 deletions src/main/java/ichttt/mods/firstaid/FirstAid.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@
acceptedMinecraftVersions = "[1.12.2,1.13)",
dependencies = "required-after:forge@[14.23.4.2724,);",
guiFactory = "ichttt.mods.firstaid.client.config.GuiFactory",
certificateFingerprint = "7904c4e13947c8a616c5f39b26bdeba796500722")
certificateFingerprint = FirstAid.FINGERPRINT)
public class FirstAid {
public static final String MODID = "firstaid";
public static final String NAME = "First Aid";
public static final String VERSION = "1.5.6";
public static final String FINGERPRINT = "7904c4e13947c8a616c5f39b26bdeba796500722";
public static final Logger LOGGER = LogManager.getLogger(MODID);

public static boolean isSynced = false;
Expand Down Expand Up @@ -130,7 +131,6 @@ public void readNBT(Capability<AbstractPlayerDamageModel> capability, AbstractPl
proxy.init();

if (Loader.isModLoaded("morpheus")) {
LOGGER.info("Morpheus present - enabling compatibility module");
MorpheusHelper.register();
}

Expand All @@ -146,6 +146,7 @@ public void loadComplete(FMLLoadCompleteEvent event) {

@Mod.EventHandler
public void wrongFingerprint(FMLFingerprintViolationEvent event) {
if (!event.getExpectedFingerprint().equals(FINGERPRINT)) return;
if (event.getFingerprints().isEmpty()) {
LOGGER.error("NO VALID FINGERPRINT FOR FIRST AID! EXPECTED " + event.getExpectedFingerprint() + " BUT FOUND NONE!");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface IDebuffBuilder {
* If OnHit damage: value = absolute damage taken for this multiplier to apply;
* If Constant: value = percentage of health left for this multiplier
*
* @param value absolute damage (onHit) or percentage of the health left
* @param value absolute damage (onHit) or percentage of the health left (constant)
* @param multiplier the potion effect multiplier
* @return this
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

Expand Down Expand Up @@ -85,6 +86,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
GlStateManager.pushMatrix();
this.action.draw();
GlStateManager.popMatrix();
drawCenteredString(mc.fontRenderer, I18n.format("firstaid.tutorial.notice"), parent.guiLeft + (GuiHealthScreen.xSize / 2), parent.guiTop + 140, 0xFFFFFF);
super.drawScreen(mouseX, mouseY, partialTicks);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public <T> void set(@Nonnull DataParameter<T> key, @Nonnull T value) {
}
Objects.requireNonNull(player.getCapability(CapabilityExtendedHealthSystem.INSTANCE, null)).setAbsorption(floatValue);
} else if (key == EntityLivingBase.HEALTH) {
if (!player.world.isRemote && (Float) value > player.getMaxHealth())
if (!player.world.isRemote && (Float) value > player.getMaxHealth()) //I don't know why only if !world.isRemote... maybe double check this
Objects.requireNonNull(player.getCapability(CapabilityExtendedHealthSystem.INSTANCE, null)).forEach(damageablePart -> damageablePart.currentHealth = damageablePart.getMaxHealth());
}
set_impl(key, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public class EventHandler {
@SubscribeEvent(priority = EventPriority.LOWEST) //so all other can modify their damage first, and we apply after that
public static void onLivingHurt(LivingHurtEvent event) {
EntityLivingBase entity = event.getEntityLiving();
float amountToDamage = event.getAmount();
if (entity.world.isRemote || !(entity instanceof EntityPlayer) || entity instanceof FakePlayer)
return;
float amountToDamage = event.getAmount();
EntityPlayer player = (EntityPlayer) entity;
AbstractPlayerDamageModel damageModel = Objects.requireNonNull(player.getCapability(CapabilityExtendedHealthSystem.INSTANCE, null));
DamageSource source = event.getSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,14 @@ public void tick(World world, EntityPlayer player) {
return;
}

if (FirstAid.isSynced) {
float newCurrentHealth = (currentHealth / getCurrentMaxHealth()) * player.getMaxHealth();
float newCurrentHealth = (currentHealth / getCurrentMaxHealth()) * player.getMaxHealth();

if (Float.isInfinite(newCurrentHealth)) {
FirstAid.LOGGER.error("Error calculating current health: Value was infinite"); //Shouldn't happen anymore, but let's be safe
} else {
if (newCurrentHealth != prevHealthCurrent)
((DataManagerWrapper) player.dataManager).set_impl(EntityPlayer.HEALTH, newCurrentHealth);
prevHealthCurrent = newCurrentHealth;
}
if (Float.isInfinite(newCurrentHealth)) {
FirstAid.LOGGER.error("Error calculating current health: Value was infinite"); //Shouldn't happen anymore, but let's be safe
} else {
if (newCurrentHealth != prevHealthCurrent)
((DataManagerWrapper) player.dataManager).set_impl(EntityPlayer.HEALTH, newCurrentHealth);
prevHealthCurrent = newCurrentHealth;
}

if (!this.hasTutorial)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public void update(EntityPlayer player, float healthPerMax) {
if (healthPerMax != -1)
syncMultiplier(healthPerMax); //There are apparently some cases where the multiplier does not sync up right... fix this
if (activeMultiplier != 0)
player.addPotionEffect(new PotionEffect(effect, 240, activeMultiplier - 1, false, false));
player.addPotionEffect(new PotionEffect(effect, 169, activeMultiplier - 1, false, false));
}
ticks++;
if (ticks >= 200) ticks = 0;
if (ticks >= 79) ticks = 0;
}
}
}
11 changes: 5 additions & 6 deletions src/main/java/ichttt/mods/firstaid/common/util/CommonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.creativemd.playerrevive.api.IRevival;
import com.creativemd.playerrevive.api.capability.CapaRevive;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.primitives.Ints;
import ichttt.mods.firstaid.api.damagesystem.AbstractPlayerDamageModel;
Expand All @@ -18,8 +19,6 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

Expand All @@ -36,10 +35,10 @@ public class CommonUtils {
ARMOR_SLOTS[1] = EntityEquipmentSlot.LEGS;
ARMOR_SLOTS[0] = EntityEquipmentSlot.FEET;
slotToParts = ImmutableMap.<EntityEquipmentSlot, List<EnumPlayerPart>>builder().
put(EntityEquipmentSlot.HEAD, Collections.singletonList(EnumPlayerPart.HEAD)).
put(EntityEquipmentSlot.CHEST, Arrays.asList(EnumPlayerPart.LEFT_ARM, EnumPlayerPart.RIGHT_ARM, EnumPlayerPart.BODY)).
put(EntityEquipmentSlot.LEGS, Arrays.asList(EnumPlayerPart.LEFT_LEG, EnumPlayerPart.RIGHT_LEG)).
put(EntityEquipmentSlot.FEET, Arrays.asList(EnumPlayerPart.LEFT_FOOT, EnumPlayerPart.RIGHT_FOOT)).build();
put(EntityEquipmentSlot.HEAD, ImmutableList.of(EnumPlayerPart.HEAD)).
put(EntityEquipmentSlot.CHEST, ImmutableList.of(EnumPlayerPart.LEFT_ARM, EnumPlayerPart.RIGHT_ARM, EnumPlayerPart.BODY)).
put(EntityEquipmentSlot.LEGS, ImmutableList.of(EnumPlayerPart.LEFT_LEG, EnumPlayerPart.RIGHT_LEG)).
put(EntityEquipmentSlot.FEET, ImmutableList.of(EnumPlayerPart.LEFT_FOOT, EnumPlayerPart.RIGHT_FOOT)).build();
}

public static void killPlayer(@Nonnull EntityPlayer player, @Nullable DamageSource source) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ichttt.mods.firstaid.common.util;

import ichttt.mods.firstaid.FirstAid;
import ichttt.mods.firstaid.api.CapabilityExtendedHealthSystem;
import ichttt.mods.firstaid.api.damagesystem.AbstractPlayerDamageModel;
import ichttt.mods.firstaid.common.FirstAidConfig;
Expand All @@ -18,6 +19,7 @@ public class MorpheusHelper implements INewDayHandler {
public static void register() {
if (INSTANCE.oldHandler != null) throw new IllegalStateException("MorpheusHelper did already init!");
INSTANCE.oldHandler = MorpheusRegistry.registry.get(0);
FirstAid.LOGGER.info("Morpheus present - enabling compatibility module. Parent: " + INSTANCE.oldHandler.getClass());
Morpheus.register.registerHandler(INSTANCE, 0);
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/firstaid/lang/de_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ gui.sleep_heal_amount=Schlafen stellt %s%% des maximalen Lebens wieder her
firstaid.tooltip.morphine=Undrückt negative Effekte von fehlendem Leben für %s
firstaid.tooltip.healer=Stellt %s Herzen wieder her, braucht %s pro halbes Herz

firstaid.tutorial.notice=TUTORIAL - NICHT TATSÄCHLICHE WERTE
firstaid.tutorial.hint=Drücke %s für das Tutorial
firstaid.tutorial.welcome=Willkommen zum FirstAid Mod! Dieses Tutorial wird dich durch den Mod und seine Mechaniken führen.
firstaid.tutorial.line1=Wie du vielleicht schon gemerkt hast, ist die normale Lebensleiste weg. Sie wurde duch dieses System ersetzt.
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/firstaid/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ gui.sleep_heal_amount=Sleeping restores %s%% of max health
firstaid.tooltip.morphine=Suppresses health debuffs for %s
firstaid.tooltip.healer=Restores %s hearts total, requires %s per half heart

firstaid.tutorial.notice=TUTORIAL - NO REAL VALUES
firstaid.tutorial.hint=Press %s for the tutorial
firstaid.tutorial.welcome=Welcome to the FirstAid mod! This tutorial will guide you through this mod and explain the different mechanics.
firstaid.tutorial.line1=As you may already have noticed, the vanilla health bar is gone. It has been replaced by this system.
Expand Down

0 comments on commit 594726e

Please sign in to comment.