(fix) emotes on servers

This commit is contained in:
kirillsaint 2024-02-05 14:01:02 +06:00
parent 2d8723756d
commit 30b2f27796
4 changed files with 37 additions and 16 deletions

View File

@ -1,9 +1,7 @@
package net.silentclient.client.emotes; package net.silentclient.client.emotes;
import net.minecraft.entity.Entity;
import java.util.HashMap; import java.util.HashMap;
public class EmoteControllerManager { public class EmoteControllerManager {
public static final HashMap<Entity, AnimatorController> controllers = new HashMap<Entity, AnimatorController>(); public static final HashMap<String, AnimatorController> controllers = new HashMap<String, AnimatorController>();
} }

View File

@ -2,6 +2,8 @@ package net.silentclient.client.emotes;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.silentclient.client.Client;
import net.silentclient.client.emotes.emoticons.Emote; import net.silentclient.client.emotes.emoticons.Emote;
public class EmoteManager { public class EmoteManager {
@ -12,24 +14,45 @@ public class EmoteManager {
public static void play(String name, int i) { public static void play(String name, int i) {
if (Minecraft.getMinecraft().theWorld != null) { if (Minecraft.getMinecraft().theWorld != null) {
String s = PlayerModelManager.get().map.get(i); String s = PlayerModelManager.get().map.get(i);
EntityPlayer entityPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(name); EntityPlayer entityPlayer = EmoteManager.getPlayerEntityByName(Minecraft.getMinecraft().theWorld, name);
if (entityPlayer != null && s != null) { if (entityPlayer != null && s != null) {
Emote emote = PlayerModelManager.get().registry.get(s); Emote emote = PlayerModelManager.get().registry.get(s);
if (EmoteControllerManager.controllers.get(entityPlayer) != null) { if (EmoteControllerManager.controllers.get(entityPlayer.getName()) != null) {
EmoteControllerManager.controllers.get(entityPlayer).setEmote(entityPlayer, emote); EmoteControllerManager.controllers.get(entityPlayer.getName()).setEmote(entityPlayer, emote);
} else {
Client.logger.info("emote player controller is null");
} }
} else {
Client.logger.info("entity player or emote is null");
} }
} }
} }
public static void stop(String name) { public static void stop(String name) {
if (Minecraft.getMinecraft().theWorld != null) { if (Minecraft.getMinecraft().theWorld != null) {
EntityPlayer entityPlayer = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(name); EntityPlayer entityPlayer = EmoteManager.getPlayerEntityByName(Minecraft.getMinecraft().theWorld, name);
if (entityPlayer != null) { if (entityPlayer != null) {
if (EmoteControllerManager.controllers.get(entityPlayer) != null) { if (EmoteControllerManager.controllers.get(entityPlayer.getName()) != null) {
EmoteControllerManager.controllers.get(entityPlayer).resetEmote(); EmoteControllerManager.controllers.get(entityPlayer.getName()).resetEmote();
} }
} }
} }
} }
public static EntityPlayer getPlayerEntityByName(World world, String name)
{
for (int i = 0; i < world.playerEntities.size(); ++i)
{
EntityPlayer entityplayer = (EntityPlayer)world.playerEntities.get(i);
Client.logger.info(entityplayer.getName());
if (name.equalsIgnoreCase(entityplayer.getName()))
{
return entityplayer;
}
}
return null;
}
} }

View File

@ -7,6 +7,7 @@ import net.silentclient.client.emotes.EmotesMod;
import net.silentclient.client.emotes.PlayerModelManager; import net.silentclient.client.emotes.PlayerModelManager;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
@ -16,17 +17,16 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
* @author refactoring * @author refactoring
*/ */
@Mixin(EntityPlayer.class) @Mixin(EntityPlayer.class)
public class EntityPlayerMixin { public abstract class EntityPlayerMixin {
@Shadow public abstract String getName();
@Unique @Unique
public AnimatorController controller; public AnimatorController controller;
@Inject(method = "<init>", at = @At("RETURN")) @Inject(method = "<init>", at = @At("RETURN"))
public void ae$init(CallbackInfo ci) { public void ae$init(CallbackInfo ci) {
if(!Client.getInstance().getSettingsManager().getSettingByClass(EmotesMod.class, "Emotes").getValBoolean()) {
return;
}
controller = new AnimatorController(PlayerModelManager.get().steve, PlayerModelManager.get().steveConfig); controller = new AnimatorController(PlayerModelManager.get().steve, PlayerModelManager.get().steveConfig);
EmoteControllerManager.controllers.put((EntityPlayer) (Object) this, controller); EmoteControllerManager.controllers.put(this.getName(), controller);
} }
@Inject(method = "onUpdate", at = @At("RETURN")) @Inject(method = "onUpdate", at = @At("RETURN"))

View File

@ -31,8 +31,8 @@ public abstract class RenderPlayerMixin extends RendererLivingEntity<AbstractCli
if(!Client.getInstance().getSettingsManager().getSettingByClass(EmotesMod.class, "Emotes").getValBoolean()) { if(!Client.getInstance().getSettingsManager().getSettingByClass(EmotesMod.class, "Emotes").getValBoolean()) {
return; return;
} }
if (EmoteControllerManager.controllers.get(entity) != null) { if (EmoteControllerManager.controllers.get(entity.getName()) != null) {
if (EmoteControllerManager.controllers.get(entity).renderHook((RenderPlayer) (Object) (this), entity, x, y, z, partialTicks, this.canRenderName(entity))) { if (EmoteControllerManager.controllers.get(entity.getName()).renderHook((RenderPlayer) (Object) (this), entity, x, y, z, partialTicks, this.canRenderName(entity))) {
ci.cancel(); ci.cancel();
} }
} }