Skip to content

Commit

Permalink
Resolve 1.11.2 conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mchorse committed Jan 5, 2020
2 parents 52486e8 + 0fd5f9d commit cb1af2e
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 121 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ out
*.iws
*.iml
.idea
classes/

# gradle
build
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Metamorph gradle properties
mclib=1.0.4
version=1.1.10
version=1.2

mc_version=1.11.2
forge_version=13.20.0.2228
Expand Down
101 changes: 14 additions & 87 deletions src/main/java/mchorse/metamorph/api/morphs/AbstractMorph.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@
*/
public abstract class AbstractMorph
{
/* Abilities */

/**
* Morph settings
*/
public MorphSettings settings = MorphSettings.DEFAULT;

/* Meta information */

/**
Expand All @@ -49,10 +42,12 @@ public abstract class AbstractMorph
*/
public boolean favorite = false;

/* Abilities */

/**
* Health when the player morphed into this morph
* Morph settings
*/
protected float lastHealth;
public MorphSettings settings = MorphSettings.DEFAULT;

/* Rendering */

Expand All @@ -63,6 +58,15 @@ public abstract class AbstractMorph
@SideOnly(Side.CLIENT)
public Render<? extends Entity> renderer;

/* Clone code */

public static void copyBase(AbstractMorph from, AbstractMorph to)
{
to.name = from.name;
to.favorite = from.favorite;
to.settings = from.settings;
}

/* Render methods */

/**
Expand Down Expand Up @@ -94,11 +98,6 @@ public boolean renderHand(EntityPlayer player, EnumHand hand)
*/
public void update(EntityLivingBase target, IMorphing cap)
{
if (!Metamorph.proxy.config.disable_health)
{
this.setMaxHealth(target, this.settings.health);
}

if (this.settings.speed != 0.1F)
{
target.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(this.settings.speed);
Expand All @@ -120,9 +119,6 @@ public void update(EntityLivingBase target, IMorphing cap)
*/
public void morph(EntityLivingBase target)
{
this.lastHealth = (float)target.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).getBaseValue();
this.setHealth(target, this.settings.health);

for (IAbility ability : this.settings.abilities)
{
ability.onMorph(target);
Expand All @@ -137,9 +133,6 @@ public void morph(EntityLivingBase target)
*/
public void demorph(EntityLivingBase target)
{
/* 20 is default player's health */
this.setHealth(target, this.lastHealth <= 0.0F ? 20.0F : this.lastHealth);

for (IAbility ability : this.settings.abilities)
{
ability.onDemorph(target);
Expand Down Expand Up @@ -190,68 +183,6 @@ public static void updateSizeDefault(EntityLivingBase target, float width, float
}
}

/* Adjusting health */

/**
* Set player's health proportional to the current health with given max
* health.
*
* @author asanetargoss
*/
protected void setHealth(EntityLivingBase target, float health)
{
if (Metamorph.proxy.config.disable_health)
{
return;
}

float maxHealth = target.getMaxHealth();
float currentHealth = target.getHealth();
float ratio = currentHealth / maxHealth;

// A sanity check to prevent "healing" health when morphing to and from
// a mob
// with essentially zero health
if (target instanceof EntityPlayer)
{
IMorphing capability = Morphing.get((EntityPlayer) target);
if (capability != null)
{
// Check if a health ratio makes sense for the old health value
if (maxHealth > IMorphing.REASONABLE_HEALTH_VALUE)
{
// If it makes sense, store that ratio in the capability
capability.setLastHealthRatio(ratio);
}
else if (health > IMorphing.REASONABLE_HEALTH_VALUE)
{
// If it doesn't make sense, BUT the new max health makes
// sense, retrieve the
// ratio from the capability and use that instead
ratio = capability.getLastHealthRatio();
}
}
}

this.setMaxHealth(target, health);
// We need to retrieve the max health of the target after modifiers are
// applied
// to get a sensible value
float proportionalHealth = target.getMaxHealth() * ratio;
target.setHealth(proportionalHealth <= 0.0F ? Float.MIN_VALUE : proportionalHealth);
}

/**
* Set player's max health
*/
protected void setMaxHealth(EntityLivingBase target, float health)
{
if (target.getMaxHealth() != health)
{
target.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(health);
}
}

/* Safe shortcuts for activating action and attack */

/**
Expand Down Expand Up @@ -281,9 +212,7 @@ public void attack(Entity target, EntityLivingBase source)
*
* <p>
* <b>IMPORTANT</b>: when you subclass other morphs, don't forget to override
* their method with your own, because otherwise its going to create
* another {@link CustomMorph} instance, for example, instead of
* MyCustomMorph instance.
* their method with your own.
* </p>
*/
public abstract AbstractMorph clone(boolean isRemote);
Expand Down Expand Up @@ -404,7 +333,6 @@ public void reset()
public void toNBT(NBTTagCompound tag)
{
tag.setString("Name", this.name);
tag.setFloat("LastHealth", this.lastHealth);

if (this.favorite) tag.setBoolean("Favorite", this.favorite);
}
Expand All @@ -417,7 +345,6 @@ public void fromNBT(NBTTagCompound tag)
this.reset();

this.name = tag.getString("Name");
this.lastHealth = tag.getFloat("LastHealth");

if (tag.hasKey("Favorite")) this.favorite = tag.getBoolean("Favorite");
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/mchorse/metamorph/api/morphs/EntityMorph.java
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,7 @@ public AbstractMorph clone(boolean isRemote)
{
EntityMorph morph = new EntityMorph();

morph.name = this.name;
morph.settings = this.settings;
AbstractMorph.copyBase(this, morph);
morph.entityData = this.entityData.copy();

return morph;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public void render(EntityLivingBase entity, float partialTicks)
}

@Override
@SideOnly(Side.CLIENT)
public void update(EntityLivingBase entity, IMorphing cap)
{
entity = this.useTarget ? entity : this.entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ public interface IMorphing
*/
public void setSquidAir(int squidAir);

/**
* Get last health
*/
public float getLastHealth();

/**
* Set last health
*/
public void setLastHealth(float lastHealth);

/**
* Update the player
*/
Expand Down
100 changes: 99 additions & 1 deletion src/main/java/mchorse/metamorph/capabilities/morphing/Morphing.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import mchorse.metamorph.api.morphs.AbstractMorph;
import mchorse.metamorph.client.gui.elements.GuiSurvivalMorphs;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.nbt.NBTTagCompound;
Expand Down Expand Up @@ -68,6 +70,11 @@ public class Morphing implements IMorphing
*/
private int squidAir = 300;

/**
* Last health that player had before morphing, should fix issue that people complain about
*/
private float lastHealth;

/**
* GUI menu which is responsible for choosing morphs
*/
Expand Down Expand Up @@ -271,6 +278,11 @@ public boolean setCurrentMorph(AbstractMorph morph, EntityPlayer player, boolean

if (force || creative || this.acquiredMorph(morph))
{
if (this.morph == null)
{
this.lastHealth = (float) player.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).getBaseValue();
}

if (player != null && this.morph != null)
{
this.morph.demorph(player);
Expand All @@ -280,6 +292,8 @@ public boolean setCurrentMorph(AbstractMorph morph, EntityPlayer player, boolean

if (player != null)
{
this.setHealth(player, this.morph.settings.health);

this.morph.morph(player);
}

Expand All @@ -297,6 +311,12 @@ public void demorph(EntityPlayer player)
this.morph.demorph(player);
}

if (player != null)
{
/* 20 is default player's health */
this.setHealth(player, this.lastHealth <= 0.0F ? 20.0F : this.lastHealth);
}

this.setMorph(null, player == null ? false : player.world.isRemote);
}

Expand Down Expand Up @@ -411,6 +431,18 @@ public void setSquidAir(int squidAir)
this.squidAir = squidAir;
}

@Override
public float getLastHealth()
{
return this.lastHealth;
}

@Override
public void setLastHealth(float lastHealth)
{
this.lastHealth = lastHealth;
}

@Override
public void update(EntityPlayer player)
{
Expand All @@ -429,19 +461,85 @@ public void update(EntityPlayer player)

if (this.morph != null)
{
if (!Metamorph.proxy.config.disable_health)
{
this.setMaxHealth(player, this.morph.settings.health);
}

this.morph.update(player, this);
}
}

/* Adjusting health */

/**
* Set player's health proportional to the current health with given max
* health.
*
* @author asanetargoss
*/
protected void setHealth(EntityLivingBase target, float health)
{
if (Metamorph.proxy.config.disable_health)
{
return;
}

float maxHealth = target.getMaxHealth();
float currentHealth = target.getHealth();
float ratio = currentHealth / maxHealth;

// A sanity check to prevent "healing" health when morphing to and from
// a mob with essentially zero health
if (target instanceof EntityPlayer)
{
IMorphing capability = Morphing.get((EntityPlayer) target);
if (capability != null)
{
// Check if a health ratio makes sense for the old health value
if (maxHealth > IMorphing.REASONABLE_HEALTH_VALUE)
{
// If it makes sense, store that ratio in the capability
capability.setLastHealthRatio(ratio);
}
else if (health > IMorphing.REASONABLE_HEALTH_VALUE)
{
// If it doesn't make sense, BUT the new max health makes
// sense, retrieve the ratio from the capability and use that instead
ratio = capability.getLastHealthRatio();
}
}
}

this.setMaxHealth(target, health);
// We need to retrieve the max health of the target after modifiers are
// applied to get a sensible value
float proportionalHealth = target.getMaxHealth() * ratio;
target.setHealth(proportionalHealth <= 0.0F ? Float.MIN_VALUE : proportionalHealth);
}

/**
* Set player's max health
*/
protected void setMaxHealth(EntityLivingBase target, float health)
{
if (target.getMaxHealth() != health)
{
target.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(health);
}
}

@Override
@SideOnly(Side.CLIENT)
public GuiSurvivalMorphs getOverlay() {
public GuiSurvivalMorphs getOverlay()
{
if (this.overlay == null)
{
this.overlay = new GuiSurvivalMorphs();
this.overlay.setupMorphs(this);
this.hasOverlay = true;
}

return this.overlay;
}
}
Loading

0 comments on commit cb1af2e

Please sign in to comment.