HotbarManager class

Пакет: com.hypixel.hytale.server.core.entity.entities.player

Файл: com/hypixel/hytale/server/core/entity/entities/player/HotbarManager.java

Поля (9)

МодификаторыТипИмя
final int HOTBARS_MAX
PlayerRef var4
PlayerRef var4
Player var5
Player var5
InventoryComponent.Hotbar var6
InventoryComponent.Hotbar var6
ItemContainer var7
ItemContainer var8

Методы (9)

МодификаторыВозвратСигнатура
public int getCurrentHotbarIndexint getCurrentHotbarIndex()
public boolean getIsCurrentlyLoadingHotbarboolean getIsCurrentlyLoadingHotbar()
if if(var2 >= 0 && var2 <= 9)
if if(var6 != null)
if if(var2 >= 0 && var2 <= 9)
if if(var6 != null)
if if(this.savedHotbars[var2] != null)
public void loadHotbarvoid loadHotbar(@Nonnull Ref<EntityStore> var1, short var2, @Nonnull ComponentAccessor<EntityStore> var3)
public void saveHotbarvoid saveHotbar(@Nonnull Ref<EntityStore> var1, short var2, @Nonnull ComponentAccessor<EntityStore> var3)

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.entity.entities.player;

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.array.ArrayCodec;
class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.protocol.GameMode;
class="kw">import com.hypixel.hytale.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.entity.entities.Player;
class="kw">import com.hypixel.hytale.server.core.inventory.InventoryComponent;
class="kw">import com.hypixel.hytale.server.core.inventory.container.ItemContainer;
class="kw">import com.hypixel.hytale.server.core.universe.PlayerRef;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import javax.annotation.Nonnull;

class="kw">public class HotbarManager {
   class="kw">public class="kw">static class="kw">final int HOTBARS_MAX = 10;
   @Nonnull
   class="kw">public class="kw">static class="kw">final BuilderCodec<HotbarManager> CODEC = BuilderCodec.builder(HotbarManager.class, HotbarManager::new)
      .append(
         new KeyedCodec<>("SavedHotbars", new ArrayCodec<>(ItemContainer.CODEC, ItemContainer[]::new)),
         (var0, var1) -> var0.savedHotbars = var1,
         var0 -> var0.savedHotbars
      )
      .documentation("An array of item containers that represent the saved hotbars.")
      .add()
      .<Integer>append(new KeyedCodec<>("CurrentHotbar", Codec.INTEGER), (var0, var1) -> var0.currentHotbar = var1, var0 -> var0.currentHotbar)
      .documentation("The current hotbar that the player has active.")
      .add()
      .build();
   class="kw">private class="kw">static class="kw">final Message MESSAGE_GENERAL_HOTBAR_INVALID_SLOT = Message.translation("server.general.hotbar.invalidSlot");
   class="kw">private class="kw">static class="kw">final Message MESSAGE_GENERAL_HOTBAR_INVALID_GAME_MODE = Message.translation("server.general.hotbar.invalidGameMode");
   @Nonnull
   class="kw">private ItemContainer[] savedHotbars = new ItemContainer[10];
   class="kw">private int currentHotbar = 0;
   class="kw">private boolean currentlyLoadingHotbar;

   class="kw">public HotbarManager() {
   }

   class="kw">public void saveHotbar(@Nonnull Ref<EntityStore> var1, short var2, @Nonnull ComponentAccessor<EntityStore> var3) {
      PlayerRef var4 = var3.getComponent(var1, PlayerRef.getComponentType());
      assert var4 != null;
      if (var2 >= 0 && var2 <= 9) {
         Player var5 = var3.getComponent(var1, Player.getComponentType());
         assert var5 != null;
         if (!var5.getGameMode().equals(GameMode.Creative)) {
            var4.sendMessage(MESSAGE_GENERAL_HOTBAR_INVALID_GAME_MODE);
         } else {
            this.currentlyLoadingHotbar = true;
            InventoryComponent.Hotbar var6 = var3.getComponent(var1, InventoryComponent.Hotbar.getComponentType());
            if (var6 != null) {
               this.savedHotbars[var2] = var6.getInventory().clone();
               this.currentHotbar = var2;
               this.currentlyLoadingHotbar = false;
            }
         }
      } else {
         var4.sendMessage(MESSAGE_GENERAL_HOTBAR_INVALID_SLOT);
      }
   }

   class="kw">public void loadHotbar(@Nonnull Ref<EntityStore> var1, short var2, @Nonnull ComponentAccessor<EntityStore> var3) {
      PlayerRef var4 = var3.getComponent(var1, PlayerRef.getComponentType());
      assert var4 != null;
      if (var2 >= 0 && var2 <= 9) {
         Player var5 = var3.getComponent(var1, Player.getComponentType());
         assert var5 != null;
         if (!var5.getGameMode().equals(GameMode.Creative)) {
            var4.sendMessage(MESSAGE_GENERAL_HOTBAR_INVALID_GAME_MODE);
         } else {
            this.currentlyLoadingHotbar = true;
            InventoryComponent.Hotbar var6 = var3.getComponent(var1, InventoryComponent.Hotbar.getComponentType());
            if (var6 != null) {
               ItemContainer var7 = var6.getInventory();
               var7.removeAllItemStacks();
               if (this.savedHotbars[var2] != null) {
                  ItemContainer var8 = this.savedHotbars[var2].clone();
                  var8.forEach(var7::setItemStackForSlot);
               }

               this.currentHotbar = var2;
               this.currentlyLoadingHotbar = false;
               var4.sendMessage(Message.translation("server.general.hotbar.loaded").param("id", var2 + 1));
            }
         }
      } else {
         var4.sendMessage(MESSAGE_GENERAL_HOTBAR_INVALID_SLOT);
      }
   }

   class="kw">public int getCurrentHotbarIndex() {
      class="kw">return this.currentHotbar;
   }

   class="kw">public boolean getIsCurrentlyLoadingHotbar() {
      class="kw">return this.currentlyLoadingHotbar;
   }
}