DiagramCraftingWindow class

Пакет: com.hypixel.hytale.builtin.crafting.window

Файл: com/hypixel/hytale/builtin/crafting/window/DiagramCraftingWindow.java

extends: CraftingWindow

implements: ItemContainerWindow

Поля (54)

МодификаторыТипИмя
break
break
return
return
return
CraftingBench.BenchCategory var10
ItemStack var10
JsonObject var10
Set var11
ItemStack var12
boolean var12
var12
ItemStack var12
ObjectList var13
List var13
boolean var14
boolean var14
CraftingRecipe var15
CraftingRecipe var15
String var16
PlayerRef var2
boolean var3
ObjectList var3
List var3
DiagramCraftingBench var3
Ref var3
JsonArray var3
CombinedItemContainer var4
CombinedItemContainer var4
World var4
List var4
Store var4
Player var4
ItemStack var4
List var4
CraftingManager var5
PlayerRef var5
CombinedItemContainer var5
CombinedItemContainer var5
Player var5
JsonObject var5
CraftingManager var6
ItemStack var6
Set var6
ItemStack var6
List var7
short var7
int var7
var7
boolean var8
var8
CraftingRecipe var8
DiagramCraftingBench var9
ItemStack var9

Методы (15)

МодификаторыВозвратСигнатура
abstract throw new IllegalArgumentExceptionthrow new IllegalArgumentException("Failed to get category!")
private boolean collectRecipesboolean collectRecipes(@Nonnull Ref<EntityStore> var1, @Nonnull List<CraftingRecipe> var2, @Nonnull Store<EntityStore> var3)
for for(short var11 = 0; var11 < var7; var11++)
abstract for for(short var8 = 0; var8 < this.inputSecondaryContainer.getCapacity()
abstract for for(short var9 = 0; var9 < this.combinedInputItemContainer.getCapacity()
if if(this.benchItemCategory == null)
if if(this.benchItemCategory != null)
if if(var1 != null && var2 != null)
if if(this.combinedInputItemContainer != null)
if if(var2 != null)
abstract super super(WindowType.DiagramCrafting, var3, var4, var5, var6, var7, var8)
switch switch(var3)
private void updateInputvoid updateInput(@Nonnull ItemContainer.ItemContainerChangeEvent var1)
private void updateInputvoid updateInput(@Nullable ItemContainer var1, @Nonnull Ref<EntityStore> var2, @Nonnull Store<EntityStore> var3)
private void updateInventoryvoid updateInventory(@Nonnull Ref<EntityStore> var1, @Nonnull ComponentAccessor<EntityStore> var2, @Nonnull CraftingBench.BenchItemCategory var3)

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.builtin.crafting.window;

class="kw">import com.google.gson.JsonArray;
class="kw">import com.google.gson.JsonObject;
class="kw">import com.hypixel.hytale.builtin.crafting.CraftingPlugin;
class="kw">import com.hypixel.hytale.builtin.crafting.component.BenchBlock;
class="kw">import com.hypixel.hytale.builtin.crafting.component.CraftingManager;
class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.event.EventPriority;
class="kw">import com.hypixel.hytale.event.EventRegistration;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.protocol.SoundCategory;
class="kw">import com.hypixel.hytale.protocol.packets.window.CancelCraftingAction;
class="kw">import com.hypixel.hytale.protocol.packets.window.CraftItemAction;
class="kw">import com.hypixel.hytale.protocol.packets.window.UpdateCategoryAction;
class="kw">import com.hypixel.hytale.protocol.packets.window.WindowAction;
class="kw">import com.hypixel.hytale.protocol.packets.window.WindowType;
class="kw">import com.hypixel.hytale.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.bench.CraftingBench;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.bench.DiagramCraftingBench;
class="kw">import com.hypixel.hytale.server.core.asset.type.item.config.CraftingRecipe;
class="kw">import com.hypixel.hytale.server.core.entity.entities.Player;
class="kw">import com.hypixel.hytale.server.core.entity.entities.player.windows.ItemContainerWindow;
class="kw">import com.hypixel.hytale.server.core.inventory.InventoryComponent;
class="kw">import com.hypixel.hytale.server.core.inventory.ItemStack;
class="kw">import com.hypixel.hytale.server.core.inventory.container.CombinedItemContainer;
class="kw">import com.hypixel.hytale.server.core.inventory.container.ItemContainer;
class="kw">import com.hypixel.hytale.server.core.inventory.container.SimpleItemContainer;
class="kw">import com.hypixel.hytale.server.core.inventory.container.filter.FilterActionType;
class="kw">import com.hypixel.hytale.server.core.inventory.container.filter.FilterType;
class="kw">import com.hypixel.hytale.server.core.inventory.container.filter.SlotFilter;
class="kw">import com.hypixel.hytale.server.core.universe.PlayerRef;
class="kw">import com.hypixel.hytale.server.core.universe.world.SoundUtil;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import it.unimi.dsi.fastutil.objects.ObjectArrayList;
class="kw">import it.unimi.dsi.fastutil.objects.ObjectList;
class="kw">import java.util.List;
class="kw">import java.util.Set;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;

class="kw">public class DiagramCraftingWindow class="kw">extends CraftingWindow class="kw">implements ItemContainerWindow {
   @Nonnull
   class="kw">private class="kw">static class="kw">final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
   class="kw">private String category;
   class="kw">private String itemCategory;
   @Nullable
   class="kw">private CraftingBench.BenchItemCategory benchItemCategory;
   class="kw">private SimpleItemContainer inputPrimaryContainer;
   class="kw">private SimpleItemContainer inputSecondaryContainer;
   class="kw">private CombinedItemContainer combinedInputItemContainer;
   class="kw">private SimpleItemContainer outputContainer;
   class="kw">private CombinedItemContainer combinedItemContainer;
   class="kw">private EventRegistration<?, ?> inventoryRegistration;

   class="kw">public DiagramCraftingWindow(
      @Nonnull Ref<EntityStore> var1,
      @Nonnull ComponentAccessor<EntityStore> var2,
      int var3,
      int var4,
      int var5,
      int var6,
      @Nonnull BlockType var7,
      @Nonnull BenchBlock var8
   ) {
      super(WindowType.DiagramCrafting, var3, var4, var5, var6, var7, var8);
      DiagramCraftingBench var9 = (DiagramCraftingBench)this.bench;
      if (var9.getCategories() != null && var9.getCategories().length > 0) {
         CraftingBench.BenchCategory var10 = var9.getCategories()[0];
         this.category = var10.getId();
         if (var10.getItemCategories() != null && var10.getItemCategories().length > 0) {
            this.itemCategory = var10.getItemCategories()[0].getId();
         }
      }

      this.benchItemCategory = this.getBenchItemCategory(this.category, this.itemCategory);
      if (this.benchItemCategory == null) {
         throw new IllegalArgumentException("Failed to get category!");
      }

      this.updateInventory(var1, var2, this.benchItemCategory);
   }

   @Override
   class="kw">public boolean onOpen0(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2) {
      boolean var3 = super.onOpen0(var1, var2);
      CombinedItemContainer var4 = InventoryComponent.getCombined(var2, var1, InventoryComponent.HOTBAR_FIRST);
      this.updateInput(null, var1, var2);
      this.inventoryRegistration = var4.registerChangeEvent(var2x -> {
         ObjectList var3 = new ObjectArrayList();
         this.windowData.add("slots", this.generateSlots(var4, var3));
         this.invalidate();
      });
      class="kw">return var3;
   }

   @Override
   class="kw">public void onClose0(@Nonnull Ref<EntityStore> var1, @Nonnull ComponentAccessor<EntityStore> var2) {
      List var3 = this.combinedInputItemContainer.dropAllItemStacks();
      CombinedItemContainer var4 = InventoryComponent.getCombined(var2, var1, InventoryComponent.HOTBAR_FIRST);
      SimpleItemContainer.addOrDropItemStacks(var2, var1, var4, var3);
      CraftingManager var5 = var2.getComponent(var1, CraftingManager.getComponentType());
      assert var5 != null;
      var5.cancelAllCrafting(var1, var2);
      this.inventoryRegistration.unregister();
      super.onClose0(var1, var2);
   }

   @Override
   class="kw">public void handleAction(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull WindowAction var3) {
      World var4 = var2.getExternalData().getWorld();
      PlayerRef var5 = var2.getComponent(var1, PlayerRef.getComponentType());
      assert var5 != null;
      CraftingManager var6 = var2.getComponent(var1, CraftingManager.getComponentType());
      assert var6 != null;
      class="kw">switch (var3) {
         case CancelCraftingAction var9:
            var6.cancelAllCrafting(var1, var2);
            break;
         case UpdateCategoryAction var10:
            this.category = var10.category;
            this.itemCategory = var10.itemCategory;
            this.benchItemCategory = this.getBenchItemCategory(this.category, this.itemCategory);
            if (this.benchItemCategory != null) {
               this.updateInventory(var1, var2, this.benchItemCategory);
            } else {
               var5.sendMessage(Message.translation("server.ui.diagramcraftingwindow.invalidCategory"));
               this.close(var1, var2);
            }
            break;
         case CraftItemAction var11:
            label63: {
               ItemStack var12 = this.outputContainer.getItemStack((short)0);
               if (var12 == null || var12.isEmpty()) {
                  var5.sendMessage(Message.translation("server.ui.diagramcraftingwindow.noOutputItem"));
                  class="kw">return;
               }

               ObjectList var13 = new ObjectArrayList();
               boolean var14 = this.collectRecipes(var1, var13, var2);
               if (var13.size() != 1 || !var14) {
                  var5.sendMessage(Message.translation("server.ui.diagramcraftingwindow.failedVerifyRecipy"));
                  class="kw">return;
               }

               CraftingRecipe var15 = (CraftingRecipe)var13.getFirst();
               if (!var6.queueCraft(var1, var2, this, 0, var15, 1, this.combinedInputItemContainer, CraftingManager.InputRemovalType.ORDERED)) {
                  class="kw">return;
               }

               this.updateQueueSize(var6.getRemainingQueueSize());
               String var16 = var15.getTimeSeconds() > 0.0F ? "CraftCompleted" : "CraftCompletedInstant";
               this.setBlockInteractionState(var16, var4);
               if (this.bench.getCompletedSoundEventIndex() != 0) {
                  SoundUtil.playSoundEvent3d(this.bench.getCompletedSoundEventIndex(), SoundCategory.SFX, this.x + 0.5, this.y + 0.5, this.z + 0.5, var2);
               }

               if (CraftingPlugin.learnRecipe(var1, var15.getId(), var2)) {
                  this.updateInput(this.outputContainer, var1, var2);
               }
               break label63;
            }
         class="kw">default:
      }
   }

   @Nonnull
   @Override
   class="kw">public ItemContainer getItemContainer() {
      class="kw">return this.combinedItemContainer;
   }

   @Nullable
   class="kw">private CraftingBench.BenchItemCategory getBenchItemCategory(@Nullable String var1, @Nullable String var2) {
      if (var1 != null && var2 != null) {
         DiagramCraftingBench var3 = (DiagramCraftingBench)this.bench;

         for (CraftingBench.BenchCategory var7 : var3.getCategories()) {
            if (var1.equals(var7.getId())) {
               for (CraftingBench.BenchItemCategory var11 : var7.getItemCategories()) {
                  if (var2.equals(var11.getId())) {
                     class="kw">return var11;
                  }
               }
            }
         }

         class="kw">return null;
      } else {
         class="kw">return null;
      }
   }

   class="kw">private void updateInventory(@Nonnull Ref<EntityStore> var1, @Nonnull ComponentAccessor<EntityStore> var2, @Nonnull CraftingBench.BenchItemCategory var3) {
      if (this.combinedInputItemContainer != null) {
         List var4 = this.combinedInputItemContainer.dropAllItemStacks();
         CombinedItemContainer var5 = InventoryComponent.getCombined(var2, var1, InventoryComponent.HOTBAR_FIRST);
         SimpleItemContainer.addOrDropItemStacks(var2, var1, var5, var4);
      }

      this.inputPrimaryContainer = new SimpleItemContainer((short)1);
      this.inputSecondaryContainer = new SimpleItemContainer((short)(var3.getSlots() + (var3.isSpecialSlot() ? 1 : 0)));
      this.inputSecondaryContainer.setGlobalFilter(FilterType.ALLOW_OUTPUT_ONLY);
      this.combinedInputItemContainer = new CombinedItemContainer(this.inputPrimaryContainer, this.inputSecondaryContainer);
      this.combinedInputItemContainer.registerChangeEvent(EventPriority.LAST, this::updateInput);
      this.outputContainer = new SimpleItemContainer((short)1);
      this.outputContainer.setGlobalFilter(FilterType.DENY_ALL);
      this.combinedItemContainer = new CombinedItemContainer(this.combinedInputItemContainer, this.outputContainer);
   }

   class="kw">private void updateInput(@Nonnull ItemContainer.ItemContainerChangeEvent var1) {
      PlayerRef var2 = this.getPlayerRef();
      if (var2 != null) {
         Ref var3 = var2.getReference();
         if (var3 != null && var3.isValid()) {
            Store var4 = var3.getStore();
            this.updateInput(var1.container(), var3, var4);
         }
      }
   }

   class="kw">private void updateInput(@Nullable ItemContainer var1, @Nonnull Ref<EntityStore> var2, @Nonnull Store<EntityStore> var3) {
      Player var4 = var3.getComponent(var2, Player.getComponentType());
      assert var4 != null;
      CombinedItemContainer var5 = InventoryComponent.getCombined(var3, var2, InventoryComponent.HOTBAR_FIRST);
      ItemStack var6 = this.inputPrimaryContainer.getItemStack((short)0);
      if (var6 != null && !var6.isEmpty()) {
         this.inputSecondaryContainer.setGlobalFilter(FilterType.ALLOW_ALL);
         boolean var12 = true;

         for (short var8 = 0; var8 < this.inputSecondaryContainer.getCapacity(); var8++) {
            ItemStack var9 = this.inputSecondaryContainer.getItemStack(var8);
            if (var9 != null && !var9.isEmpty()) {
               this.inputSecondaryContainer.setSlotFilter(FilterActionType.ADD, var8, null);
            } else if (var12) {
               this.inputSecondaryContainer.setSlotFilter(FilterActionType.ADD, var8, null);
               var12 = false;
            } else {
               this.inputSecondaryContainer.setSlotFilter(FilterActionType.ADD, var8, SlotFilter.DENY);
            }
         }
      } else {
         this.inputSecondaryContainer.setGlobalFilter(FilterType.ALLOW_OUTPUT_ONLY);
         if (var1 != this.inputSecondaryContainer && !this.inputSecondaryContainer.isEmpty()) {
            List var7 = this.inputSecondaryContainer.dropAllItemStacks();
            SimpleItemContainer.addOrDropItemStacks(var3, var2, var5, var7);
         }
      }

      List var13 = new ObjectArrayList();
      boolean var14 = this.collectRecipes(var2, var13, var3);
      this.windowData.add("slots", this.generateSlots(var5, var13));
      if (var13.size() == 1 && var14) {
         CraftingRecipe var15 = var13.getFirst();
         ItemStack var10 = CraftingManager.getOutputItemStacks(var15).getFirst();
         Set var11 = var4.getPlayerConfigData().getKnownRecipes();
         if (var15.isKnowledgeRequired() && !var11.contains(var15.getId())) {
            this.outputContainer.setItemStackForSlot((short)0, new ItemStack("Unknown", 1), false);
         } else {
            this.outputContainer.setItemStackForSlot((short)0, var10, false);
         }
      } else {
         if (!var13.isEmpty() && var14) {
            LOGGER.at(Level.WARNING).log("Multiple recipes defined for the same materials! %s", var13);
         }

         this.outputContainer.setItemStackForSlot((short)0, ItemStack.EMPTY, false);
      }

      this.invalidate();
   }

   class="kw">private boolean collectRecipes(@Nonnull Ref<EntityStore> var1, @Nonnull List<CraftingRecipe> var2, @Nonnull Store<EntityStore> var3) {
      assert this.benchItemCategory != null;
      ItemStack var4 = this.inputPrimaryContainer.getItemStack((short)0);
      if (var4 != null && !var4.isEmpty()) {
         Player var5 = var3.getComponent(var1, Player.getComponentType());
         assert var5 != null;
         Set var6 = var5.getPlayerConfigData().getKnownRecipes();
         short var7 = this.combinedInputItemContainer.getCapacity();
         boolean var8 = true;

         label65:
         for (CraftingRecipe var10 : this.getBenchRecipes()) {
            if (var10.getInput().length != var7 && (!this.benchItemCategory.isSpecialSlot() || var10.getInput().length != var7 - 1)) {
               LOGGER.at(Level.WARNING)
                  .log(
                     "Recipe for %s has different input length than the diagram! %s - %s, %s, %s",
                     var10.getId(),
                     var10,
                     this.bench,
                     this.category,
                     this.itemCategory
                  );
            } else if (!var10.isKnowledgeRequired() || var6.contains(var10.getId())) {
               for (short var11 = 0; var11 < var7; var11++) {
                  ItemStack var12 = this.combinedInputItemContainer.getItemStack(var11);
                  if (var12 != null && !var12.isEmpty()) {
                     if (!CraftingManager.matches(var10.getInput()[var11], var12)) {
                        class="kw">continue label65;
                     }
                  } else if (!this.benchItemCategory.isSpecialSlot() && var11 == var7 - 1) {
                     var8 = false;
                  }
               }

               var2.add(var10);
            }
         }

         class="kw">return var8;
      } else {
         class="kw">return false;
      }
   }

   @Nonnull
   class="kw">private JsonArray generateSlots(@Nonnull CombinedItemContainer var1, @Nonnull List<CraftingRecipe> var2) {
      JsonArray var3 = new JsonArray();
      if (var2.isEmpty()) {
         List var4 = this.getBenchRecipes();
         JsonObject var5 = new JsonObject();
         var5.add("inventoryHints", CraftingManager.generateInventoryHints(var4, 0, var1));
         var3.add(var5);
      } else {
         for (short var9 = 0; var9 < this.combinedInputItemContainer.getCapacity(); var9++) {
            JsonObject var10 = new JsonObject();
            ItemStack var6 = this.combinedInputItemContainer.getItemStack(var9);
            if (var6 == null || var6.isEmpty()) {
               var10.add("inventoryHints", CraftingManager.generateInventoryHints(var2, var9, var1));
            }

            int var7 = -1;
            if (var2.size() == 1) {
               CraftingRecipe var8 = var2.getFirst();
               if (var9 < var8.getInput().length) {
                  var7 = var8.getInput()[var9].getQuantity();
               }
            }

            var10.addProperty("requiredAmount", var7);
            var3.add(var10);
         }
      }

      class="kw">return var3;
   }

   @Nonnull
   class="kw">public List<CraftingRecipe> getBenchRecipes() {
      class="kw">return CraftingPlugin.getBenchRecipes(this.bench.getType(), this.bench.getId(), this.category + "." + this.itemCategory);
   }
}