RefillContainerInteraction class

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

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

extends: SimpleInstantInteraction

Поля (41)

МодификаторыТипИмя
final BuilderCodec<RefillContainerInteraction> CODEC
public static final BuilderCodec<RefillContainerInteraction.RefillState> CODEC
protected String[] allowedFluids
protected double durability
protected String transformFluid
TransformComponent var10
HeadRotation var11
ModelComponent var12
ItemStack var13
WorldConfig var14
CombinedItemContainer var15
InteractionConfiguration var16
float var17
Vector3d var18
Vector3d var19
Vector3d var20
AtomicBoolean var21
Ref var23
BlockSection var24
FluidSection var25
int var26
int[] var27
String var28
ItemStack var29
Item var30
RefillContainerInteraction.RefillState var31
double var32
ItemStack var33
var33
ItemStack var34
ItemStackSlotTransaction var35
ItemStackSlotTransaction var36
int var37
boolean var38
ItemStackSlotTransaction var39
CommandBuffer var4
InteractionSyncData var5
World var6
Ref var7
Ref var8
Player var9

Методы (23)

МодификаторыВозвратСигнатура
protected RefillStateprotected RefillState()
protected int[] getAllowedFluidIdsint[] getAllowedFluidIds()
public String[] getAllowedFluidspublic String[] getAllowedFluids()
public double getDurabilitypublic double getDurability()
protected Int2ObjectMap<String> getFluidToStateInt2ObjectMap<String> getFluidToState()
public String getTransformFluidpublic String getTransformFluid()
if if(this.allowedFluidIds != null)
if if(this.fluidToState != null)
if if(var8 != null)
if if(var9 == null)
if if(var10 == null)
if if(var11 == null)
if if(var12 == null)
if if(var13 == null)
if if(var23 == null)
if if(var24 == null)
if if(var25 == null)
if if(var28 == null)
if if(var30 == null)
if if(var31 != null)
if if(var31 != null && var31.durability > 0.0)
if if(!var38)
public String toStringpublic String toString()

Исходный код

Показать/скрыть
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.codecs.array.ArrayCodec;
class="kw">import com.hypixel.hytale.codec.codecs.map.MapCodec;
class="kw">import com.hypixel.hytale.codec.validation.Validators;
class="kw">import com.hypixel.hytale.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.math.iterator.BlockIterator;
class="kw">import com.hypixel.hytale.math.util.MathUtil;
class="kw">import com.hypixel.hytale.protocol.InteractionState;
class="kw">import com.hypixel.hytale.protocol.InteractionSyncData;
class="kw">import com.hypixel.hytale.protocol.InteractionType;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
class="kw">import com.hypixel.hytale.server.core.asset.type.fluid.Fluid;
class="kw">import com.hypixel.hytale.server.core.asset.type.fluid.FluidTicker;
class="kw">import com.hypixel.hytale.server.core.asset.type.gameplay.WorldConfig;
class="kw">import com.hypixel.hytale.server.core.asset.type.item.config.Item;
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.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.SimpleItemContainer;
class="kw">import com.hypixel.hytale.server.core.inventory.transaction.ItemStackSlotTransaction;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.HeadRotation;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.ModelComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.CooldownHandler;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.config.InteractionConfiguration;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.config.SimpleInstantInteraction;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.section.BlockSection;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.section.FluidSection;
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 it.unimi.dsi.fastutil.ints.Int2ObjectMap;
class="kw">import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
class="kw">import java.util.Arrays;
class="kw">import java.util.HashMap;
class="kw">import java.util.Map;
class="kw">import java.util.concurrent.atomic.AtomicBoolean;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
class="kw">import org.joml.Vector3d;

class="kw">public class RefillContainerInteraction class="kw">extends SimpleInstantInteraction {
   class="kw">public class="kw">static class="kw">final BuilderCodec<RefillContainerInteraction> CODEC = BuilderCodec.builder(
         RefillContainerInteraction.class, RefillContainerInteraction::new, SimpleInstantInteraction.CODEC
      )
      .documentation("Refills a container item that is currently held.")
      .<Map>appendInherited(
         new KeyedCodec<>("States", new MapCodec<>(RefillContainerInteraction.RefillState.CODEC, HashMap::new)),
         (var0, var1) -> var0.refillStateMap = var1,
         var0 -> var0.refillStateMap,
         (var0, var1) -> var0.refillStateMap = var1.refillStateMap
      )
      .addValidator(Validators.nonNull())
      .add()
      .afterDecode(var0 -> {
         var0.allowedFluidIds = null;
         var0.fluidToState = null;
      })
      .build();
   class="kw">protected Map<String, RefillContainerInteraction.RefillState> refillStateMap;
   @Nullable
   class="kw">protected int[] allowedFluidIds;
   @Nullable
   class="kw">protected Int2ObjectMap<String> fluidToState;

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

   class="kw">protected int[] getAllowedFluidIds() {
      if (this.allowedFluidIds != null) {
         class="kw">return this.allowedFluidIds;
      }

      this.allowedFluidIds = this.refillStateMap
         .values()
         .stream()
         .map(RefillContainerInteraction.RefillState::getAllowedFluids)
         .flatMap(Arrays::stream)
         .mapToInt(var0 -> Fluid.getAssetMap().getIndex(var0))
         .sorted()
         .toArray();
      class="kw">return this.allowedFluidIds;
   }

   class="kw">protected Int2ObjectMap<String> getFluidToState() {
      if (this.fluidToState != null) {
         class="kw">return this.fluidToState;
      }

      this.fluidToState = new Int2ObjectOpenHashMap();
      this.refillStateMap.forEach((var1, var2) -> {
         for (String var6 : var2.getAllowedFluids()) {
            this.fluidToState.put(Fluid.getAssetMap().getIndex(var6), var1);
         }
      });
      class="kw">return this.fluidToState;
   }

   @Override
   class="kw">protected void firstRun(@NonNullDecl InteractionType var1, @NonNullDecl InteractionContext var2, @NonNullDecl CooldownHandler var3) {
      CommandBuffer var4 = var2.getCommandBuffer();
      assert var4 != null;
      InteractionSyncData var5 = var2.getState();
      World var6 = var4.getExternalData().getWorld();
      Ref var7 = var2.getEntity();
      Ref var8 = var2.getTargetEntity();
      if (var8 != null) {
         var2.getState().state = InteractionState.Failed;
      } else {
         Player var9 = var4.getComponent(var7, Player.getComponentType());
         if (var9 == null) {
            var5.state = InteractionState.Failed;
         } else {
            TransformComponent var10 = var4.getComponent(var7, TransformComponent.getComponentType());
            if (var10 == null) {
               var5.state = InteractionState.Failed;
            } else {
               HeadRotation var11 = var4.getComponent(var7, HeadRotation.getComponentType());
               if (var11 == null) {
                  var5.state = InteractionState.Failed;
               } else {
                  ModelComponent var12 = var4.getComponent(var7, ModelComponent.getComponentType());
                  if (var12 == null) {
                     var5.state = InteractionState.Failed;
                  } else {
                     ItemStack var13 = var2.getHeldItem();
                     if (var13 == null) {
                        var5.state = InteractionState.Failed;
                     } else {
                        WorldConfig var14 = var6.getGameplayConfig().getWorldConfig();
                        if (!var14.isBlockPlacementAllowed()) {
                           var5.state = InteractionState.Failed;
                        } else {
                           CombinedItemContainer var15 = InventoryComponent.getCombined(var4, var7, InventoryComponent.HOTBAR_FIRST);
                           InteractionConfiguration var16 = var13.getItem().getInteractionConfig();
                           float var17 = var16.getUseDistance(var9.getGameMode());
                           Vector3d var18 = new Vector3d(var10.getPosition());
                           var18.y = var18.y + var12.getModel().getEyeHeight(var7, var4);
                           Vector3d var19 = var11.getDirection();
                           Vector3d var20 = new Vector3d(var18).add(var19.mul(var17));
                           AtomicBoolean var21 = new AtomicBoolean(false);
                           BlockIterator.iterateFromTo(var18, var20, (var8x, var9x, var10x, var11x, var13x, var15x, var17x, var19x, var21x) -> {
                              Ref var23 = var6.getChunkStore().getChunkSectionReferenceAtBlock(var8x, var9x, var10x);
                              if (var23 == null) {
                                 class="kw">return true;
                              }

                              BlockSection var24 = var23.getStore().getComponent(var23, BlockSection.getComponentType());
                              if (var24 == null) {
                                 class="kw">return true;
                              }

                              if (FluidTicker.isSolid(BlockType.getAssetMap().getAsset(var24.get(var8x, var9x, var10x)))) {
                                 var5.state = InteractionState.Failed;
                                 class="kw">return false;
                              }

                              FluidSection var25 = var23.getStore().getComponent(var23, FluidSection.getComponentType());
                              if (var25 == null) {
                                 class="kw">return true;
                              }

                              int var26 = var25.getFluidId(var8x, var9x, var10x);
                              int[] var27 = this.getAllowedFluidIds();
                              if (var27 != null && Arrays.binarySearch(var27, var26) < 0) {
                                 var5.state = InteractionState.Failed;
                                 class="kw">return true;
                              }

                              String var28 = (String)this.getFluidToState().get(var26);
                              if (var28 == null) {
                                 var5.state = InteractionState.Failed;
                                 class="kw">return false;
                              }

                              ItemStack var29 = var2.getHeldItem();
                              Item var30 = var29.getItem().getItemForState(var28);
                              if (var30 == null) {
                                 var5.state = InteractionState.Failed;
                                 class="kw">return false;
                              }

                              RefillContainerInteraction.RefillState var31 = this.refillStateMap.get(var28);
                              if (var30.getId().equals(var29.getItemId())) {
                                 if (var31 != null) {
                                    double var32 = MathUtil.maxValue(var31.durability, var29.getMaxDurability());
                                    if (var32 <= var29.getDurability()) {
                                       var5.state = InteractionState.Failed;
                                       class="kw">return false;
                                    }

                                    ItemStack var34 = var29.withIncreasedDurability(var32);
                                    ItemStackSlotTransaction var35 = var2.getHeldItemContainer().setItemStackForSlot(var2.getHeldItemSlot(), var34);
                                    if (!var35.succeeded()) {
                                       var5.state = InteractionState.Failed;
                                       class="kw">return false;
                                    }

                                    var2.setHeldItem(var34);
                                    var21.set(true);
                                 }
                              } else {
                                 ItemStackSlotTransaction var36 = var2.getHeldItemContainer().removeItemStackFromSlot(var2.getHeldItemSlot(), var29, 1);
                                 if (!var36.succeeded()) {
                                    var5.state = InteractionState.Failed;
                                    class="kw">return false;
                                 }

                                 ItemStack var33 = new ItemStack(var30.getId(), 1);
                                 if (var31 != null && var31.durability > 0.0) {
                                    var33 = var33.withDurability(var31.durability);
                                 }

                                 if (var29.getQuantity() == 1) {
                                    ItemStackSlotTransaction var39 = var2.getHeldItemContainer().setItemStackForSlot(var2.getHeldItemSlot(), var33);
                                    if (!var39.succeeded()) {
                                       var5.state = InteractionState.Failed;
                                       class="kw">return false;
                                    }

                                    var2.setHeldItem(var33);
                                 } else {
                                    SimpleItemContainer.addOrDropItemStack(var4, var7, var15, var33);
                                    var2.setHeldItem(var2.getHeldItemContainer().getItemStack(var2.getHeldItemSlot()));
                                 }
                              }

                              if (var31 != null && var31.getTransformFluid() != null) {
                                 int var37 = Fluid.getFluidIdOrUnknown(var31.getTransformFluid(), "Unknown fluid %s", var31.getTransformFluid());
                                 boolean var38 = var25.setFluid(var8x, var9x, var10x, var37, (byte)Fluid.getAssetMap().getAsset(var37).getMaxFluidLevel());
                                 if (!var38) {
                                    var5.state = InteractionState.Failed;
                                 }

                                 var6.performBlockUpdate(var8x, var9x, var10x);
                                 var21.set(true);
                              }

                              class="kw">return false;
                           });
                           if (!var21.get()) {
                              var2.getState().state = InteractionState.Failed;
                           }
                        }
                     }
                  }
               }
            }
         }
      }
   }

   @Nonnull
   @Override
   class="kw">public String toString() {
      class="kw">return "RefillContainerInteraction{refillStateMap="
         + this.refillStateMap
         + ", allowedFluidIds="
         + Arrays.toString(this.allowedFluidIds)
         + ", fluidToState="
         + this.fluidToState
         + "} "
         + super.toString();
   }

   class="kw">protected class="kw">static class RefillState {
      class="kw">public class="kw">static class="kw">final BuilderCodec<RefillContainerInteraction.RefillState> CODEC = BuilderCodec.builder(
            RefillContainerInteraction.RefillState.class, RefillContainerInteraction.RefillState::new
         )
         .append(
            new KeyedCodec<>("AllowedFluids", new ArrayCodec<>(Codec.STRING, String[]::new)),
            (var0, var1) -> var0.allowedFluids = var1,
            var0 -> var0.allowedFluids
         )
         .addValidator(Validators.nonNull())
         .add()
         .addField(new KeyedCodec<>("TransformFluid", Codec.STRING), (var0, var1) -> var0.transformFluid = var1, var0 -> var0.transformFluid)
         .addField(new KeyedCodec<>("Durability", Codec.DOUBLE), (var0, var1) -> var0.durability = var1, var0 -> var0.durability)
         .build();
      class="kw">protected String[] allowedFluids;
      class="kw">protected String transformFluid;
      class="kw">protected double durability = -1.0;

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

      class="kw">public String[] getAllowedFluids() {
         class="kw">return this.allowedFluids;
      }

      class="kw">public String getTransformFluid() {
         class="kw">return this.transformFluid;
      }

      class="kw">public double getDurability() {
         class="kw">return this.durability;
      }

      @Nonnull
      @Override
      class="kw">public String toString() {
         class="kw">return "RefillState{allowedFluids="
            + Arrays.toString(this.allowedFluids)
            + ", transformFluid='"
            + this.transformFluid
            + "', durability="
            + this.durability
            + "}";
      }
   }
}