-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add show-armor-hud option to emulate armor hud in 1.8->1.9
Fixes #152
- Loading branch information
1 parent
67d33c6
commit 435ab07
Showing
6 changed files
with
96 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/com/viaversion/fabric/common/util/ArmorHudEmulation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.viaversion.fabric.common.util; | ||
|
||
import com.viaversion.viaversion.api.connection.UserConnection; | ||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; | ||
import com.viaversion.viaversion.api.type.Types; | ||
import com.viaversion.viaversion.protocols.v1_8to1_9.Protocol1_8To1_9; | ||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_9; | ||
|
||
import java.util.UUID; | ||
|
||
// Stolen from https://github.com/ViaVersion/ViaFabricPlus/blob/main/src/main/java/de/florianmichael/viafabricplus/fixes/versioned/visual/ArmorHudEmulation1_8.java | ||
public class ArmorHudEmulation { | ||
|
||
private static final UUID ARMOR_POINTS_UUID = UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150"); | ||
|
||
private static double previousArmorPoints = 0; | ||
|
||
public static void sendArmorUpdate(final UserConnection userConnection, final int playerId, final int armorPoints) { | ||
// We only want to update the armor points if they actually changed. | ||
if (armorPoints == previousArmorPoints) { | ||
return; | ||
} | ||
previousArmorPoints = armorPoints; | ||
|
||
final PacketWrapper updateAttributes = PacketWrapper.create(ClientboundPackets1_9.UPDATE_ATTRIBUTES, userConnection); | ||
updateAttributes.write(Types.VAR_INT, playerId); | ||
updateAttributes.write(Types.INT, 1); | ||
updateAttributes.write(Types.STRING, "generic.armor"); | ||
updateAttributes.write(Types.DOUBLE, 0.0D); | ||
updateAttributes.write(Types.VAR_INT, 1); | ||
updateAttributes.write(Types.UUID, ARMOR_POINTS_UUID); | ||
updateAttributes.write(Types.DOUBLE, (double) armorPoints); | ||
updateAttributes.write(Types.BYTE, (byte) 0); | ||
updateAttributes.scheduleSend(Protocol1_8To1_9.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Leaving this as a note: Should be considered a hard-coded feature as i basically do not see the reasoning why we have to make this a boolean unless issues actually occur from it, Also this currently causes crashes on 1.21 instance. (contains nullified value in specific class section)