BlockTagOrItemIdField class

Пакет: com.hypixel.hytale.builtin.adventure.objectives.config.task

Файл: com/hypixel/hytale/builtin/adventure/objectives/config/task/BlockTagOrItemIdField.java

Поля (2)

МодификаторыТипИмя
int var1
BlockTagOrItemIdField var2

Методы (9)

МодификаторыВозвратСигнатура
public void consumeItemStacksvoid consumeItemStacks(@Nonnull ItemContainer var1, int var2)
public int getBlockTagIndexint getBlockTagIndex()
public String getItemIdString getItemId()
if if(var0.blockTag == null && var0.itemId == null)
if if(var0.blockTag != null)
if if(this.blockTagIndex != Integer.MIN_VALUE)
if if(this.itemId != null)
if if(this == var1)
public boolean isBlockTypeIncludedboolean isBlockTypeIncluded(String var1)

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.builtin.adventure.objectives.config.task;

class="kw">import com.hypixel.hytale.assetstore.AssetRegistry;
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.server.core.asset.type.item.config.Item;
class="kw">import com.hypixel.hytale.server.core.inventory.ItemStack;
class="kw">import com.hypixel.hytale.server.core.inventory.container.ItemContainer;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;

class="kw">public class BlockTagOrItemIdField {
   @Nonnull
   class="kw">public class="kw">static class="kw">final BuilderCodec<BlockTagOrItemIdField> CODEC = BuilderCodec.builder(BlockTagOrItemIdField.class, BlockTagOrItemIdField::new)
      .append(new KeyedCodec<>("BlockTag", Codec.STRING), (var0, var1) -> var0.blockTag = var1, var0 -> var0.blockTag)
      .add()
      .<String>append(new KeyedCodec<>("ItemId", Codec.STRING), (var0, var1) -> var0.itemId = var1, var0 -> var0.itemId)
      .addValidator(Item.VALIDATOR_CACHE.getValidator())
      .add()
      .validator((var0, var1) -> {
         if (var0.blockTag == null && var0.itemId == null) {
            var1.fail("One and only one of BlockTag or ItemId must be set!");
         }
      })
      .afterDecode(var0 -> {
         if (var0.blockTag != null) {
            var0.blockTagIndex = AssetRegistry.getOrCreateTagIndex(var0.blockTag);
         }
      })
      .build();
   class="kw">protected String blockTag;
   class="kw">protected int blockTagIndex = Integer.MIN_VALUE;
   class="kw">protected String itemId;

   class="kw">public BlockTagOrItemIdField(String var1, String var2) {
      this.blockTag = var1;
      this.itemId = var2;
   }

   class="kw">protected BlockTagOrItemIdField() {
   }

   class="kw">public int getBlockTagIndex() {
      class="kw">return this.blockTagIndex;
   }

   class="kw">public String getItemId() {
      class="kw">return this.itemId;
   }

   class="kw">public boolean isBlockTypeIncluded(String var1) {
      if (this.blockTagIndex != Integer.MIN_VALUE) {
         class="kw">return Item.getAssetMap().getKeysForTag(this.blockTagIndex).contains(var1);
      } else {
         class="kw">return this.itemId != null ? this.itemId.equals(var1) : false;
      }
   }

   class="kw">public void consumeItemStacks(@Nonnull ItemContainer var1, int var2) {
      if (this.itemId != null) {
         var1.removeItemStack(new ItemStack(this.itemId, var2));
      } else if (this.blockTagIndex != Integer.MIN_VALUE) {
         var1.removeTag(this.blockTagIndex, var2);
      }
   }

   @Override
   class="kw">public boolean equals(@Nullable Object var1) {
      if (this == var1) {
         class="kw">return true;
      }

      if (var1 != null && this.getClass() == var1.getClass()) {
         BlockTagOrItemIdField var2 = (BlockTagOrItemIdField)var1;
         if (this.blockTag != null ? this.blockTag.equals(var2.blockTag) : var2.blockTag == null) {
            class="kw">return this.itemId != null ? this.itemId.equals(var2.itemId) : var2.itemId == null;
         } else {
            class="kw">return false;
         }
      } else {
         class="kw">return false;
      }
   }

   @Override
   class="kw">public int hashCode() {
      int var1 = this.blockTag != null ? this.blockTag.hashCode() : 0;
      class="kw">return 31 * var1 + (this.itemId != null ? this.itemId.hashCode() : 0);
   }

   @Nonnull
   @Override
   class="kw">public String toString() {
      class="kw">return "BlockTagOrItemIdField{blockTag='" + this.blockTag + "', itemId=" + this.itemId + "}";
   }
}