Created
December 21, 2023 03:26
-
-
Save keksgauner/3c2c072a188b272a5dc11ed91d9b4cd2 to your computer and use it in GitHub Desktop.
Display totem effects with custom model data in Minecraft with ProtocolLib
This file contains hidden or 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
import com.comphenix.protocol.PacketType; | |
import com.comphenix.protocol.ProtocolLibrary; | |
import com.comphenix.protocol.ProtocolManager; | |
import com.comphenix.protocol.events.PacketContainer; | |
import org.bukkit.EntityEffect; | |
import org.bukkit.Material; | |
import org.bukkit.entity.Player; | |
import org.bukkit.inventory.ItemStack; | |
import org.bukkit.inventory.meta.ItemMeta; | |
public class CustomTotemRessurectEffect { | |
/** | |
* Sends a custom Totem of Undying animation to the player | |
* @param player The player to send the animation to | |
* @param customModelDataId The custom model data id of the Totem of Undying | |
*/ | |
public static void sendCustomTotemAnimation(Player player, int customModelDataId) { | |
ItemStack itemStack = new ItemStack(Material.TOTEM_OF_UNDYING); | |
ItemMeta itemMeta = itemStack.getItemMeta(); | |
itemMeta.setCustomModelData(customModelDataId); | |
itemStack.setItemMeta(itemMeta); | |
sendCustomTotemAnimation(player, itemStack); | |
} | |
/** | |
* Sends a custom Totem of Undying animation to the player | |
* @param player The player to send the animation to | |
* @param itemStack The ItemStack of the Totem of Undying | |
*/ | |
public static void sendCustomTotemAnimation(Player player, ItemStack itemStack) { | |
if (itemStack.getType() != Material.TOTEM_OF_UNDYING) | |
throw new IllegalArgumentException("ItemStack $itemStack isn't a Totem of Undying!"); | |
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); | |
// https://wiki.vg/index.php?title=Protocol&oldid=14204#Set_Slot | |
PacketContainer packetContainer = protocolManager.createPacket(PacketType.Play.Server.SET_SLOT); | |
packetContainer.getIntegers().write(0, 0); | |
packetContainer.getIntegers().write(0, 45); | |
packetContainer.getItemModifier().write(0, itemStack); | |
protocolManager.sendServerPacket(player, packetContainer); | |
player.playEffect(EntityEffect.TOTEM_RESURRECT); | |
player.updateInventory(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment