mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 08:14:23 +01:00
Only send events for players that are supposed to send events. Should also fix clients sending unneccessary events and maybe triggering some anti-spam filtering on servers.
This commit is contained in:
parent
53625f6b44
commit
70f4ab7a0a
3 changed files with 33 additions and 13 deletions
|
@ -5,13 +5,14 @@ import com.minelittlepony.api.pony.IPonyManager;
|
|||
import com.minelittlepony.client.IPreviewModel;
|
||||
import com.minelittlepony.client.MineLittlePony;
|
||||
import com.minelittlepony.client.model.entity.race.PlayerModels;
|
||||
import com.minelittlepony.client.pony.Pony;
|
||||
import com.minelittlepony.hdskins.client.dummy.DummyPlayer;
|
||||
import com.minelittlepony.hdskins.client.dummy.TextureProxy;
|
||||
|
||||
/**
|
||||
* Dummy model used for the skin uploading screen.
|
||||
*/
|
||||
class DummyPony extends DummyPlayer implements IPreviewModel, ModelAttributes.Swimmer, IPonyManager.ForcedPony {
|
||||
class DummyPony extends DummyPlayer implements IPreviewModel, ModelAttributes.Swimmer, IPonyManager.ForcedPony, Pony.RegistrationHandler {
|
||||
|
||||
public DummyPony(TextureProxy textures) {
|
||||
super(textures);
|
||||
|
@ -20,6 +21,11 @@ class DummyPony extends DummyPlayer implements IPreviewModel, ModelAttributes.Sw
|
|||
public void setWet(boolean wet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldUpdateRegistration(Pony pony) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSubmergedInWater() {
|
||||
return getTextures().getSkinType() == MineLPHDSkins.seaponySkinType || super.isSubmergedInWater();
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.minelittlepony.client.mixin;
|
|||
|
||||
import com.minelittlepony.api.pony.IPony;
|
||||
import com.minelittlepony.client.MineLittlePony;
|
||||
import com.minelittlepony.client.pony.Pony;
|
||||
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
|
@ -14,9 +15,11 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ClientPlayerEntity.class)
|
||||
abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity {
|
||||
abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity implements Pony.RegistrationHandler {
|
||||
public MixinClientPlayerEntity() { super(null, null); }
|
||||
|
||||
private Pony pony;
|
||||
|
||||
@Inject(method = "startRiding(Lnet/minecraft/entity/Entity;Z)Z", at = @At("RETURN"))
|
||||
public void onStartRiding(Entity entity, boolean bl, CallbackInfoReturnable<Boolean> info) {
|
||||
calculateDimensions();
|
||||
|
@ -28,6 +31,15 @@ abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity {
|
|||
calculateDimensions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldUpdateRegistration(Pony pony) {
|
||||
if (this.pony != pony) {
|
||||
this.pony = pony;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getActiveEyeHeight(EntityPose pose, EntityDimensions dimensions) {
|
||||
float value = super.getActiveEyeHeight(pose, dimensions);
|
||||
|
|
|
@ -15,6 +15,8 @@ import com.minelittlepony.client.render.PonyRenderDispatcher;
|
|||
import com.minelittlepony.client.transform.PonyTransformation;
|
||||
import com.minelittlepony.settings.PonyLevel;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
|
@ -37,11 +39,8 @@ public class Pony implements IPony {
|
|||
private final Identifier texture;
|
||||
private final IPonyData metadata;
|
||||
|
||||
private boolean initialized = false;
|
||||
private boolean defaulted = false;
|
||||
|
||||
private int entityId = -1;
|
||||
|
||||
Pony(Identifier resource, IPonyData data) {
|
||||
texture = resource;
|
||||
metadata = data;
|
||||
|
@ -58,17 +57,16 @@ public class Pony implements IPony {
|
|||
|
||||
@Override
|
||||
public void updateForEntity(Entity entity) {
|
||||
if (!initialized || entityId != entity.getId()) {
|
||||
entityId = entity.getId();
|
||||
initialized = true;
|
||||
if (entity instanceof RegistrationHandler && ((RegistrationHandler)entity).shouldUpdateRegistration(this)) {
|
||||
entity.calculateDimensions();
|
||||
|
||||
if (entity == MinecraftClient.getInstance().player) {
|
||||
PlayerEntity clientPlayer = MinecraftClient.getInstance().player;
|
||||
if (clientPlayer != null) {
|
||||
if (Objects.equals(entity, clientPlayer) || Objects.equals(((PlayerEntity)entity).getGameProfile(), clientPlayer.getGameProfile())) {
|
||||
Channel.CLIENT_PONY_DATA.accept(new MsgPonyData(metadata, defaulted));
|
||||
}
|
||||
if (entity instanceof PlayerEntity) {
|
||||
PonyDataCallback.EVENT.invoker().onPonyDataAvailable((PlayerEntity)entity, metadata, defaulted, EnvType.CLIENT);
|
||||
}
|
||||
PonyDataCallback.EVENT.invoker().onPonyDataAvailable((PlayerEntity)entity, metadata, defaulted, EnvType.CLIENT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,4 +253,8 @@ public class Pony implements IPony {
|
|||
|
||||
return race;
|
||||
}
|
||||
|
||||
public interface RegistrationHandler {
|
||||
boolean shouldUpdateRegistration(Pony pony);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue