CarriedBlock class

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

Файл: com/hypixel/hytale/server/core/modules/interaction/components/CarriedBlock.java

implements: Component<EntityStore>

Поля (20)

МодификаторыТипИмя
final Map<InteractionType, String> DROPPED_BLOCK_INTERACTIONS
return
return
return
BlockType var1
ItemStack var1
BlockType var1
Rotation3f var10
Item var2
Item var2
CarriedBlock var2
ItemStack var3
var3
ItemStack var3
Holder var4
TransformComponent var5
String var6
BlockTypeAssetMap var7
BlockType var8
Vector3d var9

Методы (17)

МодификаторыВозвратСигнатура
public void clearItemBlockKeyvoid clearItemBlockKey()
public void clearItemContainervoid clearItemContainer()
static void dropAndClearvoid dropAndClear(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1)
public String getEntityEffectIdString getEntityEffectId()
public SimpleItemContainer getItemContainerSimpleItemContainer getItemContainer()
if if(this.blockTypeKey == null)
if if(var1 == null)
if if(this.itemContainer == null)
if if(this.blockTypeKey == null)
if if(var1 == null)
if if(var2 == null)
if if(this.holder != null)
if if(var2 != null)
if if(var3 != null)
if if(var5 == null)
if if(var7 == null)
if if(var8 == null)

Исходный код

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

class="kw">import com.hypixel.hytale.assetstore.map.BlockTypeAssetMap;
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.store.StoredCodec;
class="kw">import com.hypixel.hytale.component.AddReason;
class="kw">import com.hypixel.hytale.component.Component;
class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.ComponentType;
class="kw">import com.hypixel.hytale.component.Holder;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.math.vector.Rotation3f;
class="kw">import com.hypixel.hytale.protocol.InteractionType;
class="kw">import com.hypixel.hytale.server.core.asset.type.blockhitbox.BlockBoundingBoxes;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
class="kw">import com.hypixel.hytale.server.core.asset.type.item.config.Item;
class="kw">import com.hypixel.hytale.server.core.entity.UUIDComponent;
class="kw">import com.hypixel.hytale.server.core.entity.effect.EffectControllerComponent;
class="kw">import com.hypixel.hytale.server.core.entity.entities.BlockEntity;
class="kw">import com.hypixel.hytale.server.core.inventory.ItemStack;
class="kw">import com.hypixel.hytale.server.core.inventory.container.SimpleItemContainer;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.Interactable;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.tracker.NetworkId;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.InteractionModule;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.Interactions;
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.Map;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;

class="kw">public class CarriedBlock class="kw">implements Component<EntityStore> {
   class="kw">static class="kw">final Map<InteractionType, String> DROPPED_BLOCK_INTERACTIONS = Map.of(InteractionType.Use, "Root_Carry_Dropped_Block");
   class="kw">public class="kw">static class="kw">final BuilderCodec<CarriedBlock> CODEC = BuilderCodec.builder(CarriedBlock.class, CarriedBlock::new)
      .append(new KeyedCodec<>("BlockTypeKey", Codec.STRING), (var0, var1) -> var0.blockTypeKey = var1, var0 -> var0.blockTypeKey)
      .add()
      .append(new KeyedCodec<>("Holder", new StoredCodec<>(ChunkStore.HOLDER_CODEC_KEY)), (var0, var1) -> var0.holder = var1, var0 -> var0.holder)
      .add()
      .append(new KeyedCodec<>("EntityEffectId", Codec.STRING), (var0, var1) -> var0.entityEffectId = var1, var0 -> var0.entityEffectId)
      .add()
      .build();
   @Nullable
   class="kw">private String blockTypeKey;
   @Nullable
   class="kw">private Holder<ChunkStore> holder;
   class="kw">private String entityEffectId;
   @Nullable
   class="kw">private class="kw">transient SimpleItemContainer itemContainer;

   @Nonnull
   class="kw">public class="kw">static ComponentType<EntityStore, CarriedBlock> getComponentType() {
      class="kw">return InteractionModule.get().getCarriedBlockComponentType();
   }

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

   class="kw">public CarriedBlock(@Nullable String var1, @Nullable Holder<ChunkStore> var2, String var3) {
      this.blockTypeKey = var1;
      this.holder = var2;
      this.entityEffectId = var3;
   }

   @Nullable
   class="kw">public String getBlockTypeKey() {
      class="kw">return this.blockTypeKey;
   }

   @Nullable
   class="kw">public Holder<ChunkStore> getHolder() {
      class="kw">return this.holder;
   }

   class="kw">public String getEntityEffectId() {
      class="kw">return this.entityEffectId;
   }

   @Nullable
   class="kw">public String getCarriedItemId() {
      if (this.blockTypeKey == null) {
         class="kw">return null;
      }

      BlockType var1 = BlockType.getAssetMap().getAsset(this.blockTypeKey);
      if (var1 == null) {
         class="kw">return null;
      }

      Item var2 = var1.getItem();
      class="kw">return var2 == null ? null : var2.getId();
   }

   class="kw">public SimpleItemContainer getItemContainer() {
      if (this.itemContainer == null) {
         ItemStack var1 = new ItemStack(this.getCarriedItemId());
         this.itemContainer = new SimpleItemContainer((short)1);
         this.itemContainer.addItemStack(var1);
      }

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

   class="kw">public void clearItemBlockKey() {
      this.blockTypeKey = null;
   }

   class="kw">public void clearItemContainer() {
      this.itemContainer = null;
   }

   @Nullable
   class="kw">public ItemStack toItemStack() {
      if (this.blockTypeKey == null) {
         class="kw">return null;
      }

      BlockType var1 = BlockType.getAssetMap().getAsset(this.blockTypeKey);
      if (var1 == null) {
         class="kw">return null;
      }

      Item var2 = var1.getItem();
      if (var2 == null) {
         class="kw">return null;
      }

      ItemStack var3 = new ItemStack(var2.getId(), 1);
      if (this.holder != null) {
         var3 = var3.withMetadata("BlockHolder", ChunkStore.REGISTRY.serialize(this.holder));
      }

      class="kw">return var3;
   }

   class="kw">public class="kw">static void dropAndClear(@Nonnull Ref<EntityStore> var0, @Nonnull ComponentAccessor<EntityStore> var1) {
      CarriedBlock var2 = var1.getComponent(var0, getComponentType());
      if (var2 != null) {
         var1.removeComponent(var0, getComponentType());
         ItemStack var3 = var2.toItemStack();
         if (var3 != null) {
            Holder var4 = EntityStore.REGISTRY.newHolder();
            TransformComponent var5 = var1.getComponent(var0, TransformComponent.getComponentType());
            if (var5 == null) {
               class="kw">return;
            }

            var4.putComponent(getComponentType(), var2);
            String var6 = var2.getBlockTypeKey();
            BlockTypeAssetMap var7 = BlockType.getAssetMap();
            if (var7 == null) {
               class="kw">return;
            }

            BlockType var8 = var7.getAsset(var6);
            if (var8 == null) {
               class="kw">return;
            }

            Vector3d var9 = new Vector3d(var5.getPosition());
            var9.y = var9.y + BlockBoundingBoxes.getAssetMap().getAsset(var8.getHitboxTypeIndex()).get(0).getBoundingBox().height() / 2.0;
            Rotation3f var10 = new Rotation3f(0.0F, var5.getRotation().y + (float) Math.PI, 0.0F);
            var4.putComponent(TransformComponent.getComponentType(), new TransformComponent(var9, var10));
            var4.putComponent(BlockEntity.getComponentType(), new BlockEntity(var6));
            var4.putComponent(NetworkId.getComponentType(), new NetworkId(var1.getExternalData().takeNextNetworkId()));
            var4.ensureComponent(UUIDComponent.getComponentType());
            var4.ensureComponent(Interactable.getComponentType());
            var4.ensureComponent(EffectControllerComponent.getComponentType());
            var4.addComponent(Interactions.getComponentType(), new Interactions(DROPPED_BLOCK_INTERACTIONS));
            var1.addEntity(var4, AddReason.SPAWN);
         }
      }
   }

   @Nonnull
   @Override
   class="kw">public Component<EntityStore> clone() {
      class="kw">return new CarriedBlock(this.blockTypeKey, this.holder == null ? null : this.holder.clone(), this.entityEffectId);
   }
}