mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 16:24: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.IPreviewModel;
|
||||||
import com.minelittlepony.client.MineLittlePony;
|
import com.minelittlepony.client.MineLittlePony;
|
||||||
import com.minelittlepony.client.model.entity.race.PlayerModels;
|
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.DummyPlayer;
|
||||||
import com.minelittlepony.hdskins.client.dummy.TextureProxy;
|
import com.minelittlepony.hdskins.client.dummy.TextureProxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dummy model used for the skin uploading screen.
|
* 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) {
|
public DummyPony(TextureProxy textures) {
|
||||||
super(textures);
|
super(textures);
|
||||||
|
@ -20,6 +21,11 @@ class DummyPony extends DummyPlayer implements IPreviewModel, ModelAttributes.Sw
|
||||||
public void setWet(boolean wet) {
|
public void setWet(boolean wet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldUpdateRegistration(Pony pony) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSubmergedInWater() {
|
public boolean isSubmergedInWater() {
|
||||||
return getTextures().getSkinType() == MineLPHDSkins.seaponySkinType || super.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.api.pony.IPony;
|
||||||
import com.minelittlepony.client.MineLittlePony;
|
import com.minelittlepony.client.MineLittlePony;
|
||||||
|
import com.minelittlepony.client.pony.Pony;
|
||||||
|
|
||||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||||
import net.minecraft.client.network.ClientPlayerEntity;
|
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;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
@Mixin(ClientPlayerEntity.class)
|
@Mixin(ClientPlayerEntity.class)
|
||||||
abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity {
|
abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity implements Pony.RegistrationHandler {
|
||||||
public MixinClientPlayerEntity() { super(null, null); }
|
public MixinClientPlayerEntity() { super(null, null); }
|
||||||
|
|
||||||
|
private Pony pony;
|
||||||
|
|
||||||
@Inject(method = "startRiding(Lnet/minecraft/entity/Entity;Z)Z", at = @At("RETURN"))
|
@Inject(method = "startRiding(Lnet/minecraft/entity/Entity;Z)Z", at = @At("RETURN"))
|
||||||
public void onStartRiding(Entity entity, boolean bl, CallbackInfoReturnable<Boolean> info) {
|
public void onStartRiding(Entity entity, boolean bl, CallbackInfoReturnable<Boolean> info) {
|
||||||
calculateDimensions();
|
calculateDimensions();
|
||||||
|
@ -28,6 +31,15 @@ abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity {
|
||||||
calculateDimensions();
|
calculateDimensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldUpdateRegistration(Pony pony) {
|
||||||
|
if (this.pony != pony) {
|
||||||
|
this.pony = pony;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getActiveEyeHeight(EntityPose pose, EntityDimensions dimensions) {
|
public float getActiveEyeHeight(EntityPose pose, EntityDimensions dimensions) {
|
||||||
float value = super.getActiveEyeHeight(pose, 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.client.transform.PonyTransformation;
|
||||||
import com.minelittlepony.settings.PonyLevel;
|
import com.minelittlepony.settings.PonyLevel;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Material;
|
import net.minecraft.block.Material;
|
||||||
|
@ -37,11 +39,8 @@ public class Pony implements IPony {
|
||||||
private final Identifier texture;
|
private final Identifier texture;
|
||||||
private final IPonyData metadata;
|
private final IPonyData metadata;
|
||||||
|
|
||||||
private boolean initialized = false;
|
|
||||||
private boolean defaulted = false;
|
private boolean defaulted = false;
|
||||||
|
|
||||||
private int entityId = -1;
|
|
||||||
|
|
||||||
Pony(Identifier resource, IPonyData data) {
|
Pony(Identifier resource, IPonyData data) {
|
||||||
texture = resource;
|
texture = resource;
|
||||||
metadata = data;
|
metadata = data;
|
||||||
|
@ -58,17 +57,16 @@ public class Pony implements IPony {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateForEntity(Entity entity) {
|
public void updateForEntity(Entity entity) {
|
||||||
if (!initialized || entityId != entity.getId()) {
|
if (entity instanceof RegistrationHandler && ((RegistrationHandler)entity).shouldUpdateRegistration(this)) {
|
||||||
entityId = entity.getId();
|
|
||||||
initialized = true;
|
|
||||||
entity.calculateDimensions();
|
entity.calculateDimensions();
|
||||||
|
|
||||||
if (entity == MinecraftClient.getInstance().player) {
|
PlayerEntity clientPlayer = MinecraftClient.getInstance().player;
|
||||||
Channel.CLIENT_PONY_DATA.accept(new MsgPonyData(metadata, defaulted));
|
if (clientPlayer != null) {
|
||||||
}
|
if (Objects.equals(entity, clientPlayer) || Objects.equals(((PlayerEntity)entity).getGameProfile(), clientPlayer.getGameProfile())) {
|
||||||
if (entity instanceof PlayerEntity) {
|
Channel.CLIENT_PONY_DATA.accept(new MsgPonyData(metadata, defaulted));
|
||||||
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;
|
return race;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface RegistrationHandler {
|
||||||
|
boolean shouldUpdateRegistration(Pony pony);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue