Skip to content

Commit

Permalink
Merge branch 'downstream-master' into changeling-master
Browse files Browse the repository at this point in the history
  • Loading branch information
asanetargoss committed Jan 14, 2021
2 parents ba3f563 + 301bb43 commit 1f3367a
Show file tree
Hide file tree
Showing 32 changed files with 726 additions and 197 deletions.
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
# Metamorph Change Log
## Metamorph 1.2.4

This patch fix features some bug fixes that are required for the release of my new Chameleon mod.

**Compatible** with McLib `2.1`. It doesn't mean that future versions of McLib would be incompatible, but older versions are most likely incompatible.

* Changed the scrolling speed of morph panels from `35` to `45` pixels per mouse wheel scroll
* Fixed morph settings parsing to be more lenient to the provided data types

## Metamorph 1.2.3

This small update mostly needed for Blockbuster update.

**Compatible** with McLib `2.1`. It doesn't mean that future versions of McLib would be incompatible, but older versions are most likely incompatible.

* Added an option to allow morphing in recent and user categories morphs (and opening creative morph menu)
* Added an option to allow disable population of entity morphs (suggested by Chunk7)
* Added remove category confirmation modal (suggested by JC2020)
* Fixed `/morph` command not working with MC functions (reported by Joziah2)
* Fixed animated morphs jittering when enabling animates or changing the duration

## Metamorph 1.2.2

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changeling gradle properties
version=1.2.3
dominionlib=2.1
version=1.2.5
dominionlib=2.1.3

mc_version=1.10.2
forge_version=12.18.3.2511
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mchorse/metamorph/Metamorph.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void postLoad(FMLPostInitializationEvent event)
public void serverStarting(FMLServerStartingEvent event)
{
/* Setting up the blacklist */
MorphManager.INSTANCE.setActiveBlacklist(MorphUtils.reloadBlacklist());
MorphManager.INSTANCE.setActiveBlacklist(null, MorphUtils.reloadBlacklist());
MorphManager.INSTANCE.setActiveSettings(MorphUtils.reloadMorphSettings());
MorphManager.INSTANCE.setActiveMap(MorphUtils.reloadRemapper());

Expand Down
12 changes: 11 additions & 1 deletion src/main/java/mchorse/metamorph/api/MorphManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import mchorse.metamorph.api.creative.sections.UserSection;
import mchorse.metamorph.api.morphs.AbstractMorph;
import mchorse.metamorph.client.gui.editor.GuiAbstractMorph;
import mchorse.vanilla_pack.MetamorphSection;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

Expand Down Expand Up @@ -85,10 +87,18 @@ public static boolean isBlacklisted(String name)
/**
* Set currently used morph ID blacklist
*/
public void setActiveBlacklist(Set<String> blacklist)
public void setActiveBlacklist(World world, Set<String> blacklist)
{
this.activeBlacklist.clear();
this.activeBlacklist.addAll(blacklist);

MetamorphSection section = this.list.getSection(MetamorphSection.class);

if (section != null && world != null)
{
section.reset();
section.update(world);
}
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/mchorse/metamorph/api/creative/MorphList.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,17 @@ public boolean keyTyped(EntityPlayer player, int keycode)

return false;
}

public <T> T getSection(Class<T> clazz)
{
for (MorphSection section : this.sections)
{
if (section.getClass() == clazz)
{
return clazz.cast(section);
}
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import mchorse.metamorph.api.morphs.AbstractMorph;
import mchorse.metamorph.network.Dispatcher;
import mchorse.metamorph.network.common.creative.PacketAcquireMorph;
import mchorse.metamorph.network.common.creative.PacketClearAcquired;
import mchorse.metamorph.network.common.creative.PacketSyncMorph;
import mchorse.metamorph.network.common.survival.PacketRemoveMorph;
import mchorse.metamorph.network.common.survival.PacketSelectMorph;
Expand All @@ -24,6 +25,14 @@ public void setMorph(List<AbstractMorph> morphs)
this.morphs = morphs;
}

@Override
public void clear()
{
super.clear();

Dispatcher.sendToServer(new PacketClearAcquired());
}

@Override
protected void addMorph(AbstractMorph morph)
{
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/mchorse/metamorph/api/json/MorphSettingsAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,42 @@ public MorphSettings deserialize(JsonElement json, Type typeOfT, JsonDeserializa
MorphSettings morph = new MorphSettings();
MorphManager manager = MorphManager.INSTANCE;

morph.hasHealth = object.has("health");
morph.hasHealth = object.has("health") && object.get("health").isJsonPrimitive();
if (morph.hasHealth)
{
morph.health = object.get("health").getAsInt();
}

morph.hasSpeed = object.has("speed");
morph.hasSpeed = object.has("speed") && object.get("speed").isJsonPrimitive();
if (morph.hasSpeed)
{
morph.speed = object.get("speed").getAsFloat();
}

morph.hasHostile = object.has("hostile");
morph.hasHostile = object.has("hostile") && object.get("hostile").isJsonPrimitive();
if (morph.hasHostile)
{
morph.hostile = object.get("hostile").getAsBoolean();
}

morph.hasHands = object.has("hands");
morph.hasHands = object.has("hands") && object.get("hands").isJsonPrimitive();
if (morph.hasHands)
{
morph.hands = object.get("hands").getAsBoolean();
}

morph.hasAbilities = object.has("abilities");
morph.hasAbilities = object.has("abilities") && object.get("abilities").isJsonArray();
if (morph.hasAbilities)
{
morph.abilities.clear();

for (JsonElement ability : object.get("abilities").getAsJsonArray())
{
if (!ability.isJsonPrimitive())
{
continue;
}

IAbility iability = manager.abilities.get(ability.getAsString());

if (iability != null)
Expand All @@ -69,19 +74,19 @@ public MorphSettings deserialize(JsonElement json, Type typeOfT, JsonDeserializa
}
}

morph.hasAction = object.has("action");
morph.hasAction = object.has("action") && object.get("action").isJsonPrimitive();
if (morph.hasAction)
{
morph.action = manager.actions.get(object.get("action").getAsString());
}

morph.hasAttack = object.has("attack");
morph.hasAttack = object.has("attack") && object.get("attack").isJsonPrimitive();
if (morph.hasAttack)
{
morph.attack = manager.attacks.get(object.get("attack").getAsString());
}

morph.hasUpdates = object.has("updates");
morph.hasUpdates = object.has("updates") && object.get("updates").isJsonPrimitive();
if (morph.hasUpdates)
{
morph.updates = object.get("updates").getAsBoolean();
Expand Down
79 changes: 68 additions & 11 deletions src/main/java/mchorse/metamorph/api/morphs/AbstractMorph.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import mchorse.metamorph.api.MorphManager;
import mchorse.metamorph.api.MorphSettings;
import mchorse.metamorph.api.abilities.IAbility;
import mchorse.metamorph.api.morphs.utils.Hitbox;
import mchorse.metamorph.entity.SoundHandler;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -150,6 +151,11 @@ public MorphSettings getSettings()
return this.settings;
}

/**
* Custom hitbox setting
*/
public Hitbox hitbox = new Hitbox();

/**
* Whether this morph is erroring when rendering
*/
Expand Down Expand Up @@ -227,8 +233,10 @@ public boolean renderHand(EntityPlayer player, EnumHand hand)
*/
public void update(EntityLivingBase target)
{
this.updateHitbox(target);

MorphSettings settings = this.getSettings();
if (getSettings().speed != 0.1F)
if (settings.speed != 0.1F)
{
target.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(settings.speed);
}
Expand Down Expand Up @@ -271,18 +279,42 @@ public void demorph(EntityLivingBase target)

/* Adjusting size */

/**
* Update player's size based on given width and height.
*
* This method is responsible for doing trickshots, 360 noscopes while being
* morped in a morph. Probably...
*/
protected void updateHitbox(EntityLivingBase target)
{
if (this.hitbox.enabled)
{
float height = target.isSneaking() ? this.hitbox.sneakingHeight : this.hitbox.height;

this.updateSize(target, this.hitbox.width, height, this.hitbox.eye);
}
else
{
this.updateUserHitbox(target);
}
}

protected void updateUserHitbox(EntityLivingBase target)
{}

public void updateSize(EntityLivingBase target, float width, float height)
{
updateSizeDefault(target, width, height);
}

/**
* Update player's size based on given width and height
*/
public void updateSize(EntityLivingBase target, float width, float height, float eyeFactor)
{
updateSizeDefault(target, width, height, eyeFactor);
}

public static void updateSizeDefault(EntityLivingBase target, float width, float height)
{
updateSizeDefault(target, width, height, 0.9F);
}

public static void updateSizeDefault(EntityLivingBase target, float width, float height, float eyeFactor)
{
/* Any lower than this, and the morph will take damage when hitting the ceiling.
* Likewise, an eye height less than this will cause suffocation damage when standing
Expand All @@ -291,17 +323,17 @@ public static void updateSizeDefault(EntityLivingBase target, float width, float
*/
float minEyeToHeadDifference = 0.1F;
height = Math.max(height, minEyeToHeadDifference * 2);

if (target instanceof EntityPlayer && !Metamorph.disablePov.get())
{
float eyeHeight = height * 0.9F;
float eyeHeight = height * eyeFactor;
if (eyeHeight + minEyeToHeadDifference > height)
{
eyeHeight = height - minEyeToHeadDifference;
}
((EntityPlayer) target).eyeHeight = eyeHeight;
}

/* This is a total rip-off of EntityPlayer#setSize method */
if (width != target.width || height != target.height)
{
Expand Down Expand Up @@ -378,6 +410,8 @@ public void copy(AbstractMorph from)
this.activeSettings = from.activeSettings != null ? from.activeSettings.copy() : null;
this.forcedSettings = from.forcedSettings;
this.needSettingsUpdate = from.needSettingsUpdate;
this.keybind = from.keybind;
this.hitbox.copy(from.hitbox);
}

/* Getting size */
Expand Down Expand Up @@ -468,7 +502,8 @@ public boolean equals(Object obj)
AbstractMorph morph = (AbstractMorph) obj;

return Objects.equals(this.name, morph.name) &&
Objects.equals(this.displayName, morph.displayName);
Objects.equals(this.displayName, morph.displayName) &&
Objects.equals(this.hitbox, morph.hitbox);
}

return super.equals(obj);
Expand All @@ -489,13 +524,25 @@ public boolean canMerge(AbstractMorph morph)
public void afterMerge(AbstractMorph morph)
{}

/**
* This method should be used by any morphs that support merging to copy essential
* whenever they merge
*/
protected void mergeBasic(AbstractMorph morph)
{
this.displayName = morph.displayName;
this.settings = morph.settings;
this.hitbox.copy(morph.hitbox);
}

/**
* Reset data for editing
*/
public void reset()
{
setActiveSettings(null);
clearForcedSettings();
this.hitbox.reset();
}

/* Reading / writing to NBT */
Expand Down Expand Up @@ -542,6 +589,11 @@ public void toNBT(NBTTagCompound tag)
{
tag.setInteger("Keybind", this.keybind);
}

if (!this.hitbox.isDefault())
{
tag.setTag("Hitbox", this.hitbox.toNBT());
}
}

/**
Expand Down Expand Up @@ -573,5 +625,10 @@ public void fromNBT(NBTTagCompound tag)
{
this.keybind = tag.getInteger("Keybind");
}

if (tag.hasKey("Hitbox"))
{
this.hitbox.fromNBT(tag.getCompoundTag("Hitbox"));
}
}
}
Loading

0 comments on commit 1f3367a

Please sign in to comment.