BenchWindow class

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

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

extends: BlockWindow

implements: MaterialContainerWindow

Поля (22)

МодификаторыТипИмя
final float CRAFTING_UPDATE_MIN_PERCENT
PlayerRef var1
int var10
String var2
long var2
Ref var2
CraftingManager var3
World var3
WorldChunk var3
WorldChunk var3
World var3
World var4
CraftingManager var4
BlockType var4
BlockType var4
int var5
int var6
CraftingConfig var7
Item var8
int var8
JsonArray var9
int var9

Методы (17)

МодификаторыВозвратСигнатура
private void checkProgressInvalidatevoid checkProgressInvalidate(float var1)
protected int getBenchTierLevelint getBenchTierLevel()
if if(var8 == null)
if if(var3 == null)
if if(var4 != null)
if if(var3 != null)
if if(var4 != null)
if if(var3 == null)
if if(this.lastUpdatePercent != var1)
if if(var1 >= 1.0F || var1 < this.lastUpdatePercent || var1 - this.lastUpdatePercent > 0.05F || var2 - this.lastUpdateTimeMs > 500L || this.lastUpdateTimeMs == 0L)
if if(var1 != null)
public void setBlockInteractionStatevoid setBlockInteractionState(@Nonnull String var1, @Nonnull World var2)
abstract super super(var1, var2, var3, var4, var5, var6)
public void updateBenchTierLevelvoid updateBenchTierLevel(int var1)
public void updateBenchUpgradeJobvoid updateBenchUpgradeJob(float var1)
public void updateCraftingJobvoid updateCraftingJob(float var1)
public void updateQueueSizevoid updateQueueSize(int var1)

Исходный код

Показать/скрыть
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.adventure.memories.MemoriesPlugin;
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.math.util.ChunkUtil;
class="kw">import com.hypixel.hytale.protocol.SoundCategory;
class="kw">import com.hypixel.hytale.protocol.packets.window.WindowType;
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.Bench;
class="kw">import com.hypixel.hytale.server.core.asset.type.gameplay.CraftingConfig;
class="kw">import com.hypixel.hytale.server.core.asset.type.item.config.Item;
class="kw">import com.hypixel.hytale.server.core.entity.entities.player.windows.BlockWindow;
class="kw">import com.hypixel.hytale.server.core.entity.entities.player.windows.MaterialContainerWindow;
class="kw">import com.hypixel.hytale.server.core.entity.entities.player.windows.MaterialExtraResourcesSection;
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.chunk.WorldChunk;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import javax.annotation.Nonnull;

class="kw">public class="kw">abstract class BenchWindow class="kw">extends BlockWindow class="kw">implements MaterialContainerWindow {
   class="kw">private class="kw">static class="kw">final float CRAFTING_UPDATE_MIN_PERCENT = 0.05F;
   class="kw">private class="kw">static class="kw">final long CRAFTING_UPDATE_INTERVAL_MS = 500L;
   @Nonnull
   class="kw">protected class="kw">static class="kw">final String BENCH_UPGRADING = "BenchUpgrading";
   class="kw">private float lastUpdatePercent;
   class="kw">private long lastUpdateTimeMs;
   class="kw">protected class="kw">final Bench bench;
   @Nonnull
   class="kw">protected class="kw">final BenchBlock benchBlock;
   @Nonnull
   class="kw">protected class="kw">final JsonObject windowData = new JsonObject();
   @Nonnull
   class="kw">private class="kw">final MaterialExtraResourcesSection extraResourcesSection = new MaterialExtraResourcesSection();

   class="kw">public BenchWindow(@Nonnull WindowType var1, int var2, int var3, int var4, int var5, @Nonnull BlockType var6, @Nonnull BenchBlock var7) {
      super(var1, var2, var3, var4, var5, var6);
      this.bench = var6.getBench();
      this.benchBlock = var7;
      Item var8 = var6.getItem();
      if (var8 == null) {
         throw new IllegalStateException("Bench block type " + var6.getId() + " does not have an associated item!");
      }

      this.windowData.addProperty("type", this.bench.getType().ordinal());
      this.windowData.addProperty("id", this.bench.getId());
      this.windowData.addProperty("name", var8.getTranslationKey());
      this.windowData.addProperty("blockItemId", var8.getId());
      this.windowData.addProperty("tierLevel", this.getBenchTierLevel());
      JsonArray var9 = new JsonArray();

      for (String var11 : var7.getGrantedAugmentTags()) {
         var9.add(var11);
      }

      this.windowData.add("grantedAugmentTags", var9);
   }

   @Nonnull
   @Override
   class="kw">public JsonObject getData() {
      class="kw">return this.windowData;
   }

   @Override
   class="kw">protected boolean onOpen0(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2) {
      CraftingManager var3 = var2.getComponent(var1, CraftingManager.getComponentType());
      if (var3 == null) {
         class="kw">return false;
      }

      var3.setBench(this.x, this.y, this.z, this.blockType);
      World var4 = var2.getExternalData().getWorld();
      int var5 = MemoriesPlugin.get().getMemoriesLevel(var4.getGameplayConfig());
      this.windowData.addProperty("worldMemoriesLevel", var5);
      int var6 = CraftingManager.feedExtraResourcesSection(
         var4, this.x, this.y, this.z, this.blockType, this.rotationIndex, this.bench, this.getBenchTierLevel(), this.extraResourcesSection
      );
      CraftingConfig var7 = var4.getGameplayConfig().getCraftingConfig();
      int var8 = var7.getBenchMaterialChestLimit();
      int var9 = var7.getBenchMaterialHorizontalChestSearchRadius();
      int var10 = var7.getBenchMaterialVerticalChestSearchRadius();
      this.windowData.addProperty("nearbyChestCount", var6);
      this.windowData.addProperty("maxChestCount", var8);
      this.windowData.addProperty("chestHorizontalRadius", var9);
      this.windowData.addProperty("chestVerticalRadius", var10);
      class="kw">return true;
   }

   class="kw">protected int getBenchTierLevel() {
      class="kw">return this.benchBlock != null ? this.benchBlock.getTierLevel() : 1;
   }

   @Override
   class="kw">public void onClose0(@Nonnull Ref<EntityStore> var1, @Nonnull ComponentAccessor<EntityStore> var2) {
      World var3 = var2.getExternalData().getWorld();
      this.setBlockInteractionState(this.getResetInteractionState(var3), var3);
      CraftingManager var4 = var2.getComponent(var1, CraftingManager.getComponentType());
      if (var4 != null) {
         if (var4.clearBench(var1, var2) && this.bench.getFailedSoundEventIndex() != 0) {
            SoundUtil.playSoundEvent2d(var1, this.bench.getFailedSoundEventIndex(), SoundCategory.UI, var2);
         }
      }
   }

   class="kw">public void setBlockInteractionState(@Nonnull String var1, @Nonnull World var2) {
      WorldChunk var3 = var2.getChunk(ChunkUtil.indexChunkFromBlock(this.x, this.z));
      if (var3 != null) {
         BlockType var4 = var3.getBlockType(this.x, this.y, this.z);
         if (var4 != null) {
            var3.setBlockInteractionState(this.x, this.y, this.z, var4, var1, true);
         }
      }
   }

   @Nonnull
   class="kw">private String getResetInteractionState(@Nonnull World var1) {
      String var2 = this.benchBlock.getTierStateName();
      if ("class="kw">default".equals(var2)) {
         class="kw">return var2;
      }

      WorldChunk var3 = var1.getChunk(ChunkUtil.indexChunkFromBlock(this.x, this.z));
      if (var3 == null) {
         class="kw">return var2;
      }

      BlockType var4 = var3.getBlockType(this.x, this.y, this.z);
      class="kw">return var4 != null && var4.getBlockForState(var2) != null ? var2 : "class="kw">default";
   }

   class="kw">public void updateQueueSize(int var1) {
      this.windowData.addProperty("queueSize", var1);
   }

   class="kw">public void updateCraftingJob(float var1) {
      this.windowData.addProperty("progress", var1);
      this.checkProgressInvalidate(var1);
   }

   class="kw">public void updateBenchUpgradeJob(float var1) {
      this.windowData.addProperty("tierUpgradeProgress", var1);
      this.checkProgressInvalidate(var1);
   }

   class="kw">private void checkProgressInvalidate(float var1) {
      if (this.lastUpdatePercent != var1) {
         long var2 = System.currentTimeMillis();
         if (var1 >= 1.0F
            || var1 < this.lastUpdatePercent
            || var1 - this.lastUpdatePercent > 0.05F
            || var2 - this.lastUpdateTimeMs > 500L
            || this.lastUpdateTimeMs == 0L) {
            this.lastUpdatePercent = var1;
            this.lastUpdateTimeMs = var2;
            this.invalidate();
         }
      }
   }

   class="kw">public void updateBenchTierLevel(int var1) {
      this.windowData.addProperty("tierLevel", var1);
      this.updateBenchUpgradeJob(0.0F);
      this.invalidateExtraResources();
      this.setNeedRebuild();
   }

   @Nonnull
   @Override
   class="kw">public MaterialExtraResourcesSection getExtraResourcesSection() {
      if (!this.extraResourcesSection.isValid()) {
         PlayerRef var1 = this.getPlayerRef();
         if (var1 != null) {
            Ref var2 = var1.getReference();
            if (var2 != null && var2.isValid()) {
               World var3 = var2.getStore().getExternalData().getWorld();
               CraftingManager.feedExtraResourcesSection(
                  var3, this.x, this.y, this.z, this.blockType, this.rotationIndex, this.bench, this.getBenchTierLevel(), this.extraResourcesSection
               );
            }
         }
      }

      class="kw">return this.extraResourcesSection;
   }

   @Override
   class="kw">public void invalidateExtraResources() {
      this.extraResourcesSection.setValid(false);
      this.invalidate();
   }

   @Override
   class="kw">public boolean isValid() {
      class="kw">return this.extraResourcesSection.isValid();
   }
}