mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-11-02 08:59:31 +01:00
Fixed build error
This commit is contained in:
parent
7494a220ab
commit
3fb0b2a22b
@ -19,40 +19,51 @@
|
|||||||
|
|
||||||
package de.florianmichael.viafabricplus.fixes;
|
package de.florianmichael.viafabricplus.fixes;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ArmorType;
|
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ArmorType;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
|
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||||
import de.florianmichael.viafabricplus.ViaFabricPlus;
|
import de.florianmichael.viafabricplus.ViaFabricPlus;
|
||||||
|
import de.florianmichael.viafabricplus.injection.access.IClientConnection;
|
||||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.registry.Registries;
|
import net.minecraft.registry.Registries;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ArmorUpdateListener {
|
public class ArmorUpdateListener {
|
||||||
|
|
||||||
|
private static final UUID ARMOR_POINTS_UUID = UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150");
|
||||||
|
|
||||||
|
private static double oldArmor = 0;
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
ClientTickEvents.START_WORLD_TICK.register(world -> {
|
ClientTickEvents.START_WORLD_TICK.register(world -> {
|
||||||
if (MinecraftClient.getInstance().player != null) {
|
if (MinecraftClient.getInstance().player != null) {
|
||||||
try {
|
final UserConnection userConnection = ((IClientConnection) MinecraftClient.getInstance().getNetworkHandler().getConnection()).viaFabricPlus$getUserConnection();
|
||||||
sendArmorUpdate();
|
if (userConnection != null) {
|
||||||
} catch (Throwable t) {
|
try {
|
||||||
ViaFabricPlus.global().getLogger().error("Error sending armor update", t);
|
sendArmorUpdate(userConnection);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
ViaFabricPlus.global().getLogger().error("Error sending armor update", t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendArmorUpdate() throws Exception {
|
public static void sendArmorUpdate(final UserConnection userConnection) throws Exception {
|
||||||
int armor = 0;
|
int armor = 0;
|
||||||
for (final ItemStack stack : MinecraftClient.getInstance().player.getInventory().armor) {
|
for (final ItemStack stack : MinecraftClient.getInstance().player.getInventory().armor) {
|
||||||
armor += ArmorType.findByType(Registries.ITEM.getId(stack.getItem()).toString()).getArmorPoints();
|
armor += ArmorType.findByType(Registries.ITEM.getId(stack.getItem()).toString()).getArmorPoints();
|
||||||
}
|
}
|
||||||
if (armor == this.oldArmor) return;
|
if (armor == oldArmor) return;
|
||||||
|
|
||||||
this.oldArmor = armor;
|
oldArmor = armor;
|
||||||
final PacketWrapper properties = PacketWrapper.create(ClientboundPackets1_9.ENTITY_PROPERTIES, MinecraftClient.getInstance().getNetworkHandler().getConnection().getUserConnection());
|
final PacketWrapper properties = PacketWrapper.create(ClientboundPackets1_9.ENTITY_PROPERTIES, userConnection);
|
||||||
properties.write(Type.VAR_INT, MinecraftClient.getInstance().player.getId());
|
properties.write(Type.VAR_INT, MinecraftClient.getInstance().player.getId());
|
||||||
properties.write(Type.INT, 1);
|
properties.write(Type.INT, 1);
|
||||||
properties.write(Type.STRING, "generic.armor");
|
properties.write(Type.STRING, "generic.armor");
|
||||||
|
Loading…
Reference in New Issue
Block a user