Skip to content

Commit

Permalink
Fix entity selectors not updating when entity's data was updated (i.e…
Browse files Browse the repository at this point in the history
…. when name tag changed, etc.)
  • Loading branch information
mchorse committed Jul 30, 2021
1 parent 79f9e0e commit 5105a08
Showing 1 changed file with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public class ModelRenderer implements IModelRenderer
public AbstractMorph morph;
public long lastUpdate = -1;

private int timer;
private float lastW = -1;
private float lastH = -1;

public static IModelRenderer get(Entity entity)
{
return entity.getCapability(ModelProvider.MODEL, null);
Expand All @@ -25,7 +29,7 @@ public static IModelRenderer get(Entity entity)
@Override
public void update(EntityLivingBase target)
{
if (this.lastUpdate < selectorsUpdate)
if (this.lastUpdate < selectorsUpdate || this.IsNotMatchedAnymore(target))
{
this.lastUpdate = selectorsUpdate;

Expand All @@ -38,6 +42,25 @@ public void update(EntityLivingBase target)
}
}

private boolean IsNotMatchedAnymore(EntityLivingBase target)
{
this.timer += 1;

if (this.timer > 10)
{
this.timer = 0;

if (this.selector == null)
{
return true;
}

return !this.selector.matches(target);
}

return false;
}

@Override
@SideOnly(Side.CLIENT)
public void updateSelector(EntityLivingBase target)
Expand All @@ -52,9 +75,24 @@ public void updateSelector(EntityLivingBase target)
this.selector = selector;
this.morph = MorphManager.INSTANCE.morphFromNBT(this.selector.morph);

if (this.lastW < 0)
{
this.lastW = target.width;
this.lastH = target.height;
}

return;
}
}

if (this.selector == null && this.lastW > 0 && this.lastH > 0)
{
target.width = this.lastW;
target.height = this.lastH;

this.lastW = -1;
this.lastH = -1;
}
}

@Override
Expand Down

0 comments on commit 5105a08

Please sign in to comment.