- Баллы
- 76
- Ник в Minecraft
- _Nanit_
Решил поделиться своей утилитой для создания ItemStack'а головы игрока с любым скином.
Класс Skull:
Использовать его просто:
При желании можно модернизировать класс, добавив в конструктор такие параметры как количество айтемов в стаке и т.д.
Источник - https://spongeapi.com/d/223-sozdanie-golovy-igroka-s-kastomnym-skinom
Класс Skull:
PHP:
import java.util.List;
import java.util.UUID;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.type.SkullTypes;
import org.spongepowered.api.item.ItemTypes;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.ItemStack.Builder;
import org.spongepowered.api.profile.GameProfile;
import org.spongepowered.api.profile.property.ProfileProperty;
import org.spongepowered.api.text.Text;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
public class Skull {
private Text displayName; // Отображаемое имя предмета
private String skinUrl; // Прямая ссылка на изображение скина
private List<Text> lore; // Lore предмета
public Skull(Text name, List<Text> lore, String skinUrl) {
this.displayName = name;
this.lore = lore;
this.skinUrl = skinUrl;
}
public ItemStack build() {
Builder item = ItemStack.builder().itemType(ItemTypes.SKULL); //Создаем Builder предмета
GameProfile profile = GameProfile.of(UUID.randomUUID(), "Head"); // Создаем новый игровой профиль
String encodedData = Base64Coder.encodeString(String.format("{textures:{SKIN:{url:\"%s\"}}}", this.skinUrl)); //Создаем закодированный json с информацией о скине
profile.getPropertyMap().put("textures", ProfileProperty.of("textures", encodedData)); //Присваиваем скин нашему профилю
item.add(Keys.DISPLAY_NAME, this.displayName); //Присваиваем ему имя
item.add(Keys.SKULL_TYPE, SkullTypes.PLAYER); //Меняем тип головы на голову игрока
item.add(Keys.REPRESENTED_PLAYER, profile); //Присваиваем данные профиля нашему ItemStack'у
if(this.lore != null) {
item.add(Keys.ITEM_LORE, this.lore); //Присваиваем lore
}
return item.build(); //Создаем ItemStack
}
}
Использовать его просто:
PHP:
ItemStack skull = new Skull(Text.of("Голова"), null, "http://textures.minecraft.net/texture/5f8d6e8682c592a1f940321ed8119d96758fc67b9470fb3dadc5ddc8dec101c1").build();
При желании можно модернизировать класс, добавив в конструктор такие параметры как количество айтемов в стаке и т.д.
Источник - https://spongeapi.com/d/223-sozdanie-golovy-igroka-s-kastomnym-skinom
Последнее редактирование: