BlockEntityCustomPageSupplier interface

Пакет: com.hypixel.hytale.server.core.modules.interaction.interaction.config.server

Файл: com/hypixel/hytale/server/core/modules/interaction/interaction/config/server/OpenCustomUIInteraction.java

Методы (1)

МодификаторыВозвратСигнатура
abstract CustomUIPage tryCreateCustomUIPage tryCreate(@Nonnull PlayerRef var1, @Nonnull Ref<ChunkStore> var2)

Исходный код

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

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.lookup.CodecMapCodec;
class="kw">import com.hypixel.hytale.codec.validation.Validators;
class="kw">import com.hypixel.hytale.component.AddReason;
class="kw">import com.hypixel.hytale.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.Holder;
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.BlockPosition;
class="kw">import com.hypixel.hytale.protocol.InteractionType;
class="kw">import com.hypixel.hytale.server.core.entity.InteractionContext;
class="kw">import com.hypixel.hytale.server.core.entity.entities.Player;
class="kw">import com.hypixel.hytale.server.core.entity.entities.player.pages.CustomUIPage;
class="kw">import com.hypixel.hytale.server.core.entity.entities.player.pages.PageManager;
class="kw">import com.hypixel.hytale.server.core.modules.block.BlockModule;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.CooldownHandler;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.config.SimpleInstantInteraction;
class="kw">import com.hypixel.hytale.server.core.plugin.PluginBase;
class="kw">import com.hypixel.hytale.server.core.universe.PlayerRef;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.section.BlockComponentSection;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import java.util.function.Function;
class="kw">import java.util.function.Supplier;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;

class="kw">public class OpenCustomUIInteraction class="kw">extends SimpleInstantInteraction {
   @Nonnull
   class="kw">public class="kw">static class="kw">final CodecMapCodec<OpenCustomUIInteraction.CustomPageSupplier> PAGE_CODEC = new CodecMapCodec<>();
   @Nonnull
   class="kw">public class="kw">static class="kw">final BuilderCodec<OpenCustomUIInteraction> CODEC = BuilderCodec.builder(
         OpenCustomUIInteraction.class, OpenCustomUIInteraction::new, SimpleInstantInteraction.CODEC
      )
      .documentation("Opens a custom ui page.")
      .<OpenCustomUIInteraction.CustomPageSupplier>appendInherited(
         new KeyedCodec<>("Page", PAGE_CODEC),
         (var0, var1) -> var0.customPageSupplier = var1,
         var0 -> var0.customPageSupplier,
         (var0, var1) -> var0.customPageSupplier = var1.customPageSupplier
      )
      .addValidator(Validators.nonNull())
      .add()
      .build();
   class="kw">private OpenCustomUIInteraction.CustomPageSupplier customPageSupplier;

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

   @Override
   class="kw">protected void firstRun(@Nonnull InteractionType var1, @Nonnull InteractionContext var2, @Nonnull CooldownHandler var3) {
      CommandBuffer var4 = var2.getCommandBuffer();
      assert var4 != null;
      Ref var5 = var2.getEntity();
      Player var6 = var4.getComponent(var5, Player.getComponentType());
      if (var6 != null) {
         PageManager var7 = var6.getPageManager();
         if (var7.getCustomPage() == null) {
            PlayerRef var8 = var4.getComponent(var5, PlayerRef.getComponentType());
            if (var8 != null) {
               CustomUIPage var9 = this.customPageSupplier.tryCreate(var5, var4, var8, var2);
               if (var9 != null) {
                  Store var10 = var4.getStore();
                  var7.openCustomPage(var5, var10, var9);
               }
            }
         }
      }
   }

   class="kw">public class="kw">static <S class="kw">extends OpenCustomUIInteraction.CustomPageSupplier> void registerCustomPageSupplier(
      @Nonnull PluginBase var0, Class<?> var1, String var2, @Nonnull S var3
   ) {
      var0.getCodecRegistry(PAGE_CODEC)
         .register(
            var2,
            (Class<? class="kw">extends OpenCustomUIInteraction.CustomPageSupplier>)var3.getClass(),
            (Codec<? class="kw">extends OpenCustomUIInteraction.CustomPageSupplier>)BuilderCodec.builder(var1, () -> var3).build()
         );
   }

   class="kw">public class="kw">static void registerSimple(@Nonnull PluginBase var0, Class<?> var1, String var2, @Nonnull Function<PlayerRef, CustomUIPage> var3) {
      registerCustomPageSupplier(var0, var1, var2, (var1x, var2x, var3x, var4) -> var3.apply(var3x));
   }

   class="kw">public class="kw">static void registerBlockEntityCustomPage(
      @Nonnull PluginBase var0, Class<?> var1, String var2, @Nonnull OpenCustomUIInteraction.BlockEntityCustomPageSupplier var3
   ) {
      OpenCustomUIInteraction.CustomPageSupplier var4 = (var1x, var2x, var3x, var4x) -> {
         BlockPosition var5 = var4x.getTargetBlock();
         if (var5 == null) {
            class="kw">return null;
         }

         Store var6 = var1x.getStore();
         World var7 = var6.getExternalData().getWorld();
         Ref var8 = BlockModule.getBlockEntity(var7, var5.x, var5.y, var5.z);
         class="kw">return var8 == null ? null : var3.tryCreate(var3x, var8);
      };
      registerCustomPageSupplier(var0, var1, var2, var4);
   }

   class="kw">public class="kw">static void registerBlockEntityCustomPage(
      @Nonnull PluginBase var0,
      Class<?> var1,
      String var2,
      @Nonnull OpenCustomUIInteraction.BlockEntityCustomPageSupplier var3,
      Supplier<Holder<ChunkStore>> var4
   ) {
      OpenCustomUIInteraction.CustomPageSupplier var5 = (var2x, var3x, var4x, var5x) -> {
         BlockPosition var6 = var5x.getTargetBlock();
         if (var6 == null) {
            class="kw">return null;
         }

         Store var7 = var2x.getStore();
         World var8 = var7.getExternalData().getWorld();
         ChunkStore var9 = var8.getChunkStore();
         Store var10 = var9.getStore();
         Ref var11 = var9.getChunkSectionReferenceAtBlock(var6.x, var6.y, var6.z);
         if (var11 != null && var11.isValid()) {
            BlockComponentSection var12 = var10.getComponent(var11, BlockComponentSection.getComponentType());
            if (var12 == null) {
               class="kw">return null;
            }

            int var13 = ChunkUtil.indexBlock(var6.x, var6.y, var6.z);
            Ref var14 = var12.getBlockReference(var13);
            if (var14 == null || !var14.isValid()) {
               Holder var15 = var4.get();
               var15.putComponent(BlockModule.BlockStateInfo.getComponentType(), new BlockModule.BlockStateInfo(var13, var11));
               var14 = var10.addEntity(var15, AddReason.SPAWN);
            }

            class="kw">return var3.tryCreate(var4x, var14);
         } else {
            class="kw">return null;
         }
      };
      registerCustomPageSupplier(var0, var1, var2, var5);
   }

   @FunctionalInterface
   class="kw">public class="kw">interface BlockEntityCustomPageSupplier {
      CustomUIPage tryCreate(@Nonnull PlayerRef var1, @Nonnull Ref<ChunkStore> var2);
   }

   @FunctionalInterface
   class="kw">public class="kw">interface CustomPageSupplier {
      @Nullable
      CustomUIPage tryCreate(
         @Nonnull Ref<EntityStore> var1, @Nonnull ComponentAccessor<EntityStore> var2, @Nonnull PlayerRef var3, @Nonnull InteractionContext var4
      );
   }
}