SubCategoryDefinition class
Пакет: com.hypixel.hytale.server.core.asset.type.item.config
Файл: com/hypixel/hytale/server/core/asset/type/item/config/ItemCategory.java
Поля (5)
| Модификаторы | Тип | Имя |
|---|---|---|
|
public static final Codec<ItemCategory.SubCategoryDefinition> |
CODEC |
|
protected String |
description |
|
protected String |
id |
|
protected String |
name |
|
protected int |
order |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.asset.type.item.config;
class="kw">import com.hypixel.hytale.assetstore.AssetExtraInfo;
class="kw">import com.hypixel.hytale.assetstore.AssetKeyValidator;
class="kw">import com.hypixel.hytale.assetstore.AssetRegistry;
class="kw">import com.hypixel.hytale.assetstore.AssetStore;
class="kw">import com.hypixel.hytale.assetstore.codec.AssetBuilderCodec;
class="kw">import com.hypixel.hytale.assetstore.map.DefaultAssetMap;
class="kw">import com.hypixel.hytale.assetstore.map.JsonAssetWithMap;
class="kw">import com.hypixel.hytale.codec.Codec;
class="kw">import com.hypixel.hytale.codec.KeyedCodec;
class="kw">import com.hypixel.hytale.codec.builder.BuilderCodec;
class="kw">import com.hypixel.hytale.codec.codecs.EnumCodec;
class="kw">import com.hypixel.hytale.codec.codecs.array.ArrayCodec;
class="kw">import com.hypixel.hytale.codec.validation.ValidatorCache;
class="kw">import com.hypixel.hytale.codec.validation.Validators;
class="kw">import com.hypixel.hytale.common.util.ArrayUtil;
class="kw">import com.hypixel.hytale.protocol.ItemGridInfoDisplayMode;
class="kw">import com.hypixel.hytale.server.core.asset.common.CommonAssetValidator;
class="kw">import com.hypixel.hytale.server.core.io.NetworkSerializable;
class="kw">import java.lang.ref.SoftReference;
class="kw">import java.util.Arrays;
class="kw">import java.util.Comparator;
class="kw">import javax.annotation.Nonnull;
class="kw">public class ItemCategory
class="kw">implements JsonAssetWithMap<String, DefaultAssetMap<String, ItemCategory>>,
NetworkSerializable<com.hypixel.hytale.protocol.ItemCategory> {
class="kw">private class="kw">static class="kw">final AssetBuilderCodec.Builder<String, ItemCategory> CODEC_BUILDER = AssetBuilderCodec.builder(
ItemCategory.class,
ItemCategory::new,
Codec.STRING,
(var0, var1) -> var0.id = var1,
var0 -> var0.id,
(var0, var1) -> var0.data = var1,
var0 -> var0.data
)
.append(new KeyedCodec<>("Id", Codec.STRING), (var0, var1) -> var0.id = var1, var0 -> var0.id)
.add()
.append(new KeyedCodec<>("Name", Codec.STRING), (var0, var1) -> var0.name = var1, var0 -> var0.name)
.add()
.<String>append(new KeyedCodec<>("Icon", Codec.STRING), (var0, var1) -> var0.icon = var1, var0 -> var0.icon)
.addValidator(CommonAssetValidator.ICON_ITEM_CATEGORIES)
.add()
.<ItemGridInfoDisplayMode>append(
new KeyedCodec<>("InfoDisplayMode", new EnumCodec<>(ItemGridInfoDisplayMode.class), false, true),
(var0, var1) -> var0.infoDisplayMode = var1,
var0 -> var0.infoDisplayMode
)
.addValidator(Validators.nonNull())
.add()
.append(new KeyedCodec<>("Order", Codec.INTEGER), (var0, var1) -> var0.order = var1, var0 -> var0.order)
.add()
.append(
new KeyedCodec<>("SubCategories", new ArrayCodec<>(ItemCategory.SubCategoryDefinition.CODEC, ItemCategory.SubCategoryDefinition[]::new)),
(var0, var1) -> var0.subCategories = var1,
var0 -> var0.subCategories
)
.add()
.afterDecode(var0 -> {
if (var0.children != null) {
Arrays.sort(var0.children, Comparator.comparingInt(var0x -> var0x.order));
}
});
class="kw">public class="kw">static class="kw">final AssetBuilderCodec<String, ItemCategory> CODEC = CODEC_BUILDER.build();
class="kw">private class="kw">static AssetStore<String, ItemCategory, DefaultAssetMap<String, ItemCategory>> ASSET_STORE;
class="kw">public class="kw">static class="kw">final ValidatorCache<String> VALIDATOR_CACHE = new ValidatorCache<>(new AssetKeyValidator<>(ItemCategory::getAssetStore));
class="kw">protected AssetExtraInfo.Data data;
class="kw">protected String id;
class="kw">protected String name;
class="kw">protected String icon;
class="kw">protected int order;
@Nonnull
class="kw">protected ItemGridInfoDisplayMode infoDisplayMode = ItemGridInfoDisplayMode.Tooltip;
class="kw">protected ItemCategory[] children;
class="kw">protected ItemCategory.SubCategoryDefinition[] subCategories;
class="kw">private SoftReference<com.hypixel.hytale.protocol.ItemCategory> cachedPacket;
class="kw">public class="kw">static AssetStore<String, ItemCategory, DefaultAssetMap<String, ItemCategory>> getAssetStore() {
if (ASSET_STORE == null) {
ASSET_STORE = AssetRegistry.getAssetStore(ItemCategory.class);
}
class="kw">return ASSET_STORE;
}
class="kw">public class="kw">static DefaultAssetMap<String, ItemCategory> getAssetMap() {
class="kw">return (DefaultAssetMap<String, ItemCategory>)getAssetStore().getAssetMap();
}
class="kw">public ItemCategory(
String var1, String var2, String var3, @Nonnull ItemGridInfoDisplayMode var4, ItemCategory[] var5, ItemCategory.SubCategoryDefinition[] var6
) {
this.id = var1;
this.name = var2;
this.icon = var3;
this.infoDisplayMode = var4;
this.children = var5;
this.subCategories = var6;
}
class="kw">protected ItemCategory() {
}
@Nonnull
class="kw">public com.hypixel.hytale.protocol.ItemCategory toPacket() {
com.hypixel.hytale.protocol.ItemCategory var1 = this.cachedPacket == null ? null : this.cachedPacket.get();
if (var1 != null) {
class="kw">return var1;
}
com.hypixel.hytale.protocol.ItemCategory var2 = new com.hypixel.hytale.protocol.ItemCategory();
var2.id = this.id;
var2.name = this.name;
var2.icon = this.icon;
var2.order = this.order;
var2.infoDisplayMode = this.infoDisplayMode;
if (this.children != null && this.children.length > 0) {
var2.children = ArrayUtil.copyAndMutate(this.children, ItemCategory::toPacket, com.hypixel.hytale.protocol.ItemCategory[]::new);
}
if (this.subCategories != null && this.subCategories.length > 0) {
var2.subCategories = new com.hypixel.hytale.protocol.SubCategoryDefinition[this.subCategories.length];
for (int var3 = 0; var3 < this.subCategories.length; var3++) {
com.hypixel.hytale.protocol.SubCategoryDefinition var4 = new com.hypixel.hytale.protocol.SubCategoryDefinition();
var4.id = this.subCategories[var3].id;
var4.name = this.subCategories[var3].name;
var4.description = this.subCategories[var3].description;
var4.order = this.subCategories[var3].order;
var2.subCategories[var3] = var4;
}
}
this.cachedPacket = new SoftReference<>(var2);
class="kw">return var2;
}
class="kw">public String getId() {
class="kw">return this.id;
}
class="kw">public String getName() {
class="kw">return this.name;
}
class="kw">public String getIcon() {
class="kw">return this.icon;
}
class="kw">public int getOrder() {
class="kw">return this.order;
}
@Nonnull
class="kw">public ItemGridInfoDisplayMode getInfoDisplayMode() {
class="kw">return this.infoDisplayMode;
}
class="kw">public ItemCategory[] getChildren() {
class="kw">return this.children;
}
class="kw">public ItemCategory.SubCategoryDefinition[] getSubCategories() {
class="kw">return this.subCategories;
}
@Nonnull
@Override
class="kw">public String toString() {
class="kw">return "ItemCategory{id='"
+ this.id
+ "', name='"
+ this.name
+ "', icon='"
+ this.icon
+ "', order="
+ this.order
+ ", infoDisplayMode="
+ this.infoDisplayMode
+ ", children="
+ Arrays.toString(this.children)
+ ", subCategories"
+ Arrays.toString(this.subCategories)
+ "}";
}
class="kw">static {
CODEC_BUILDER.append(
new KeyedCodec<>("Children", new ArrayCodec<>(CODEC, ItemCategory[]::new)), (var0, var1) -> var0.children = var1, var0 -> var0.children
)
.add();
}
class="kw">public class="kw">static class SubCategoryDefinition {
class="kw">public class="kw">static class="kw">final Codec<ItemCategory.SubCategoryDefinition> CODEC = BuilderCodec.builder(
ItemCategory.SubCategoryDefinition.class, ItemCategory.SubCategoryDefinition::new
)
.append(new KeyedCodec<>("Id", Codec.STRING), (var0, var1) -> var0.id = var1, var0 -> var0.id)
.add()
.append(new KeyedCodec<>("Name", Codec.STRING), (var0, var1) -> var0.name = var1, var0 -> var0.name)
.add()
.append(new KeyedCodec<>("Description", Codec.STRING), (var0, var1) -> var0.description = var1, var0 -> var0.description)
.add()
.append(new KeyedCodec<>("Order", Codec.INTEGER), (var0, var1) -> var0.order = var1, var0 -> var0.order)
.add()
.build();
class="kw">protected String id;
class="kw">protected String name;
class="kw">protected String description;
class="kw">protected int order;
class="kw">public SubCategoryDefinition() {
}
}
}