mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 08:14:23 +01:00
Fixed pony data change event being triggered multipled times
This commit is contained in:
parent
960b98eac9
commit
d7d0c71ca5
4 changed files with 42 additions and 6 deletions
|
@ -1,10 +1,14 @@
|
|||
package com.minelittlepony.api.pony;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import com.minelittlepony.api.pony.meta.Race;
|
||||
import com.minelittlepony.client.MineLittlePony;
|
||||
|
||||
public interface IPony {
|
||||
public interface IPony extends Comparable<IPony> {
|
||||
|
||||
/**
|
||||
* Gets the global pony manager instance.
|
||||
|
@ -48,4 +52,13 @@ public interface IPony {
|
|||
* Gets the metadata associated with this pony's model texture.
|
||||
*/
|
||||
IPonyData metadata();
|
||||
|
||||
|
||||
@Override
|
||||
default int compareTo(@Nullable IPony o) {
|
||||
return o == this ? 0 : o == null ? 1 : ComparisonChain.start()
|
||||
.compare(texture(), o.texture())
|
||||
.compare(metadata(), o.metadata())
|
||||
.result();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package com.minelittlepony.api.pony;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import com.minelittlepony.api.pony.meta.Gender;
|
||||
import com.minelittlepony.api.pony.meta.Race;
|
||||
import com.minelittlepony.api.pony.meta.Size;
|
||||
|
@ -7,13 +10,14 @@ import com.minelittlepony.api.pony.meta.TailLength;
|
|||
import com.minelittlepony.api.pony.meta.Wearable;
|
||||
import com.minelittlepony.common.util.animation.Interpolator;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Metadata for a pony.
|
||||
*/
|
||||
public interface IPonyData {
|
||||
public interface IPonyData extends Comparable<IPonyData> {
|
||||
/**
|
||||
* Gets this pony's race.
|
||||
*/
|
||||
|
@ -70,4 +74,16 @@ public interface IPonyData {
|
|||
* Gets the trigger pixel values as they appeared in the underlying image.
|
||||
*/
|
||||
Map<String, TriggerPixelType<?>> getTriggerPixels();
|
||||
|
||||
@Override
|
||||
default int compareTo(@Nullable IPonyData o) {
|
||||
return o == this ? 0 : o == null ? 1 : ComparisonChain.start()
|
||||
.compare(getRace(), o.getRace())
|
||||
.compare(getTail(), o.getTail())
|
||||
.compare(getGender(), o.getGender())
|
||||
.compare(getSize().ordinal(), o.getSize().ordinal())
|
||||
.compare(getGlowColor(), o.getGlowColor())
|
||||
.compare(0, Arrays.compare(getGear(), o.getGear()))
|
||||
.result();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ import net.minecraft.client.network.ClientPlayerEntity;
|
|||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityDimensions;
|
||||
import net.minecraft.entity.EntityPose;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
|
@ -19,7 +21,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|||
abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity implements Pony.RegistrationHandler {
|
||||
public MixinClientPlayerEntity() { super(null, null); }
|
||||
|
||||
private Pony pony;
|
||||
@Nullable
|
||||
private IPony pony;
|
||||
|
||||
@Inject(method = "startRiding(Lnet/minecraft/entity/Entity;Z)Z", at = @At("RETURN"))
|
||||
private void onStartRiding(Entity entity, boolean bl, CallbackInfoReturnable<Boolean> info) {
|
||||
|
@ -32,9 +35,9 @@ abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldUpdateRegistration(Pony pony) {
|
||||
if (this.pony != pony) {
|
||||
this.pony = pony;
|
||||
public boolean shouldUpdateRegistration(IPony pony) {
|
||||
if (this.pony != pony && (this.pony == null || this.pony.metadata().compareTo(pony.metadata()) != 0)) {
|
||||
this.pony = Pony.snapshot(pony);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -69,4 +69,8 @@ public class Pony implements IPony {
|
|||
public interface RegistrationHandler {
|
||||
boolean shouldUpdateRegistration(IPony pony);
|
||||
}
|
||||
|
||||
public static IPony snapshot(IPony pony) {
|
||||
return new Pony(pony.texture(), Memoize.of(new MsgPonyData(pony.metadata(), pony.defaulted())));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue