FallingBlock class

Пакет: com.hypixel.hytale.builtin.fallingblocks

Файл: com/hypixel/hytale/builtin/fallingblocks/FallingBlock.java

implements: Component<EntityStore>

Поля (18)

МодификаторыТипИмя
RotationTuple var10
int var10
boolean var11
BlockBoundingBoxes var12
FallingBlockSettings var13
Vector3d var14
Holder var15
String var4
WorldChunk var5
Holder var5
int var6
BlockEntity var6
BlockType var7
PhysicsValues var7
BlockSection var8
Box var8
int var9
Box var9

Методы (7)

МодификаторыВозвратСигнатура
static boolean fallBlockboolean fallBlock(@Nonnull World var0, @Nonnull Store<EntityStore> var1, int var2, int var3, int var4)
if if(var5 == null)
if if(!var11)
if if(var12 != null)
if if(var15 == null)
if if(var4 != null)
if if(var10 != Integer.MIN_VALUE)

Исходный код

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

class="kw">import com.hypixel.hytale.codec.builder.BuilderCodec;
class="kw">import com.hypixel.hytale.component.AddReason;
class="kw">import com.hypixel.hytale.component.Component;
class="kw">import com.hypixel.hytale.component.ComponentType;
class="kw">import com.hypixel.hytale.component.Holder;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.math.shape.Box;
class="kw">import com.hypixel.hytale.math.util.ChunkUtil;
class="kw">import com.hypixel.hytale.math.vector.Rotation3f;
class="kw">import com.hypixel.hytale.protocol.BlockMaterial;
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.blocktype.config.RotationTuple;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.fallingblocks.FallingBlockSettings;
class="kw">import com.hypixel.hytale.server.core.entity.UUIDComponent;
class="kw">import com.hypixel.hytale.server.core.entity.entities.BlockEntity;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.BoundingBox;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.hitboxcollision.HitboxCollision;
class="kw">import com.hypixel.hytale.server.core.modules.entity.hitboxcollision.HitboxCollisionConfig;
class="kw">import com.hypixel.hytale.server.core.modules.physics.component.PhysicsValues;
class="kw">import com.hypixel.hytale.server.core.modules.physics.component.Velocity;
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.chunk.section.BlockSection;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.core.util.FillerBlockUtil;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;

class="kw">public class FallingBlock class="kw">implements Component<EntityStore> {
   @Nonnull
   class="kw">private class="kw">static class="kw">final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
   @Nonnull
   class="kw">public class="kw">static class="kw">final BuilderCodec<FallingBlock> CODEC = BuilderCodec.builder(FallingBlock.class, FallingBlock::new).build();

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

   @Nonnull
   class="kw">public class="kw">static ComponentType<EntityStore, FallingBlock> getComponentType() {
      class="kw">return FallingBlocksPlugin.get().getFallingBlockComponentType();
   }

   class="kw">public class="kw">static boolean fallBlock(@Nonnull World var0, @Nonnull Store<EntityStore> var1, int var2, int var3, int var4) {
      WorldChunk var5 = var0.getChunk(ChunkUtil.indexChunkFromBlock(var2, var4));
      if (var5 == null) {
         class="kw">return false;
      }

      int var6 = var5.getBlock(var2, var3, var4);
      BlockType var7 = BlockType.getAssetMap().getAsset(var6);
      if (var7 != null && var7.getMaterial() != BlockMaterial.Empty) {
         BlockSection var8 = var5.getBlockChunk().getSectionAtBlockY(var3);
         int var9 = var8 != null ? var8.getRotationIndex(var2, var3, var4) : 0;
         RotationTuple var10 = RotationTuple.get(var9);
         boolean var11 = var0.breakBlock(var2, var3, var4, 0);
         if (!var11) {
            class="kw">return false;
         }

         BlockBoundingBoxes var12 = BlockBoundingBoxes.getAssetMap().getAsset(var7.getHitboxTypeIndex());
         if (var12 != null) {
            FillerBlockUtil.forEachFillerBlock(
               var12.get(var9), (var4x, var5x, var6x) -> var0.performBlockUpdate(var2 + var4x, var3 + var5x, var4 + var6x, false)
            );
         }

         FallingBlockSettings var13 = var7.getFallingBlockSettings();
         Vector3d var14 = new Vector3d(var2 + 0.5, var3 + 0.5, var4 + 0.5);
         Holder var15 = generateFallingBlock(var7, var14, var10, var13);
         if (var15 == null) {
            class="kw">return false;
         }

         var1.addEntity(var15, AddReason.SPAWN);
         class="kw">return true;
      } else {
         class="kw">return false;
      }
   }

   @Nullable
   class="kw">public class="kw">static Holder<EntityStore> generateFallingBlock(
      @Nullable BlockType var0, @Nonnull Vector3d var1, @Nonnull RotationTuple var2, @Nullable FallingBlockSettings var3
   ) {
      if (var0 != null && var0.getMaterial() != BlockMaterial.Empty) {
         String var4 = var3 != null ? var3.getHitboxCollisionConfigId() : null;
         Holder var5 = EntityStore.REGISTRY.newHolder();
         var5.addComponent(getComponentType(), new FallingBlock());
         BlockEntity var6 = new BlockEntity(var0.getId());
         var5.addComponent(BlockEntity.getComponentType(), var6);
         var5.addComponent(
            TransformComponent.getComponentType(),
            new TransformComponent(
               var1, new Rotation3f((float)var2.pitch().getRadians(), (float)var2.yaw().getRadians() + (float) Math.PI, (float)var2.roll().getRadians())
            )
         );
         var5.ensureAndGetComponent(Velocity.getComponentType());
         PhysicsValues var7 = var5.ensureAndGetComponent(PhysicsValues.getComponentType());
         var7.replaceValues(new PhysicsValues(0.5, 0.05, false));
         var5.ensureComponent(UUIDComponent.getComponentType());
         Box var8 = BlockBoundingBoxes.getAssetMap().getAsset(var0.getHitboxTypeIndex()).get(var2.index()).getBoundingBox();
         Box var9 = new Box(var8);
         var9.offset(-0.5, -0.5, -0.5);
         var5.addComponent(BoundingBox.getComponentType(), new BoundingBox(var9));
         if (var4 != null) {
            int var10 = HitboxCollisionConfig.getAssetMap().getIndex(var4);
            if (var10 != Integer.MIN_VALUE) {
               var5.addComponent(HitboxCollision.getComponentType(), new HitboxCollision(HitboxCollisionConfig.getAssetMap().getAsset(var10)));
            } else {
               LOGGER.at(Level.WARNING).log("Attempted to spawn falling block %s at %s with invalid hitbox collision config id %s", var0.getId(), var1, var4);
            }
         }

         class="kw">return var5;
      } else {
         LOGGER.at(Level.WARNING).log("Attempted to spawn invalid falling block %s at %s", var0, var1);
         class="kw">return null;
      }
   }

   @Override
   class="kw">public Component<EntityStore> clone() {
      class="kw">return new FallingBlock();
   }
}