LoadBlockChunkPacketSystem class

Пакет: com.hypixel.hytale.server.core.universe.world.chunk

Файл: com/hypixel/hytale/server/core/universe/world/chunk/BlockChunk.java

extends: ChunkStore.LoadFuturePacketDataQuerySystem

Поля (2)

МодификаторыТипИмя
private final ComponentType<ChunkStore, BlockChunk> componentType
BlockChunk var7

Методы (3)

МодификаторыВозвратСигнатура
public void fetchpublic void fetch(int var1, @Nonnull ArchetypeChunk<ChunkStore> var2, Store<ChunkStore> var3, CommandBuffer<ChunkStore> var4, PlayerRef var5, @Nonnull List<CompletableFuture<ToClientPacket>> var6)
public Query<ChunkStore> getQuerypublic Query<ChunkStore> getQuery()
if if(var0 != null)

Исходный код

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

class="kw">import com.hypixel.hytale.codec.Codec;
class="kw">import com.hypixel.hytale.codec.ExtraInfo;
class="kw">import com.hypixel.hytale.codec.KeyedCodec;
class="kw">import com.hypixel.hytale.codec.builder.BuilderCodec;
class="kw">import com.hypixel.hytale.component.ArchetypeChunk;
class="kw">import com.hypixel.hytale.component.CommandBuffer;
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.component.query.Query;
class="kw">import com.hypixel.hytale.function.predicate.ObjectPositionBlockFunction;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.math.util.ChunkUtil;
class="kw">import com.hypixel.hytale.math.util.MathUtil;
class="kw">import com.hypixel.hytale.protocol.CachedPacket;
class="kw">import com.hypixel.hytale.protocol.Opacity;
class="kw">import com.hypixel.hytale.protocol.ToClientPacket;
class="kw">import com.hypixel.hytale.protocol.packets.world.SetChunkEnvironments;
class="kw">import com.hypixel.hytale.protocol.packets.world.SetChunkTintmap;
class="kw">import com.hypixel.hytale.protocol.packets.world.SetColumn;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktick.BlockTickStrategy;
class="kw">import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
class="kw">import com.hypixel.hytale.server.core.modules.LegacyModule;
class="kw">import com.hypixel.hytale.server.core.universe.PlayerRef;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.environment.EnvironmentChunk;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.environment.EnvironmentColumn;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.palette.IntBytePalette;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.palette.ShortBytePalette;
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.ChunkSection;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
class="kw">import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
class="kw">import it.unimi.dsi.fastutil.ints.IntSet;
class="kw">import java.lang.foreign.MemorySegment;
class="kw">import java.lang.foreign.ValueLayout;
class="kw">import java.lang.ref.SoftReference;
class="kw">import java.util.List;
class="kw">import java.util.concurrent.CompletableFuture;
class="kw">import java.util.function.Function;
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">import org.joml.Vector3i;

class="kw">public class BlockChunk class="kw">implements Component<ChunkStore> {
   class="kw">public class="kw">static class="kw">final int VERSION = 3;
   class="kw">public class="kw">static class="kw">final BuilderCodec<BlockChunk> CODEC = BuilderCodec.<BlockChunk>builder(BlockChunk.class, BlockChunk::new)
      .versioned()
      .codecVersion(3)
      .append(new KeyedCodec<>("Data", Codec.BYTE_ARRAY), BlockChunk::deserialize, BlockChunk::serialize)
      .add()
      .build();
   class="kw">private class="kw">static class="kw">final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
   class="kw">public class="kw">static boolean SEND_LOCAL_LIGHTING_DATA = true;
   class="kw">public class="kw">static boolean SEND_GLOBAL_LIGHTING_DATA = false;
   class="kw">private long index;
   class="kw">private int x;
   class="kw">private int z;
   class="kw">private class="kw">final ShortBytePalette height;
   class="kw">private class="kw">final IntBytePalette tint;
   @Deprecated(forRemoval = true)
   class="kw">private BlockSection[] chunkSections;
   @Deprecated(forRemoval = true)
   class="kw">private ChunkSection[] chunkSectionsRefs;
   class="kw">private EnvironmentChunk environments;
   class="kw">private boolean needsPhysics = true;
   class="kw">private boolean needsSaving = false;
   @Nullable
   class="kw">private class="kw">transient SoftReference<CompletableFuture<CachedPacket<SetColumn>>> cachedColumnPacket;
   @Nullable
   class="kw">private class="kw">transient SoftReference<CompletableFuture<CachedPacket<SetChunkTintmap>>> cachedTintmapPacket;
   @Nullable
   class="kw">private class="kw">transient SoftReference<CompletableFuture<CachedPacket<SetChunkEnvironments>>> cachedEnvironmentsPacket;

   class="kw">public class="kw">static ComponentType<ChunkStore, BlockChunk> getComponentType() {
      class="kw">return LegacyModule.get().getBlockChunkComponentType();
   }

   class="kw">private BlockChunk() {
      this(new ShortBytePalette(), new IntBytePalette(), new EnvironmentChunk(), new BlockSection[10]);
   }

   class="kw">public void load(int var1, int var2) {
      this.x = var1;
      this.z = var2;
      this.index = ChunkUtil.indexChunk(var1, var2);
   }

   class="kw">public BlockChunk(int var1, int var2) {
      this(var1, var2, new ShortBytePalette(), new IntBytePalette(), new EnvironmentChunk());
   }

   class="kw">public BlockChunk(int var1, int var2, ShortBytePalette var3, IntBytePalette var4, EnvironmentChunk var5) {
      this(var3, var4, var5, new BlockSection[10]);
      this.x = var1;
      this.z = var2;
      this.index = ChunkUtil.indexChunk(var1, var2);
   }

   class="kw">public BlockChunk(ShortBytePalette var1, IntBytePalette var2, EnvironmentChunk var3, BlockSection[] var4) {
      this.height = var1;
      this.tint = var2;
      this.environments = var3;
      this.chunkSections = var4;
      this.chunkSectionsRefs = new ChunkSection[10];
   }

   @Override
   class="kw">public Component<ChunkStore> clone() {
      throw new UnsupportedOperationException("Not implemented!");
   }

   @Nonnull
   @Override
   class="kw">public Component<ChunkStore> cloneSerializable() {
      class="kw">return this;
   }

   class="kw">public long getIndex() {
      class="kw">return this.index;
   }

   class="kw">public int getX() {
      class="kw">return this.x;
   }

   class="kw">public int getZ() {
      class="kw">return this.z;
   }

   @Deprecated
   class="kw">public EnvironmentChunk getEnvironmentChunk() {
      class="kw">return this.environments;
   }

   class="kw">public void setEnvironmentChunk(EnvironmentChunk var1) {
      this.environments = var1;
   }

   class="kw">public short getHeight(int var1, int var2) {
      class="kw">return this.height.get(var1, var2);
   }

   class="kw">public short getHeight(int var1) {
      class="kw">return this.height.get(var1);
   }

   class="kw">public void setHeight(int var1, int var2, short var3) {
      this.height.set(var1, var2, var3);
      this.cachedColumnPacket = null;
      this.markNeedsSaving();
   }

   class="kw">public void updateHeightmap() {
      for (int var1 = 0; var1 < 32; var1++) {
         for (int var2 = 0; var2 < 32; var2++) {
            this.updateHeight(var1, var2);
         }
      }
   }

   class="kw">public short updateHeight(int var1, int var2) {
      class="kw">return this.updateHeight(var1, var2, (short)320);
   }

   class="kw">public short updateHeight(int var1, int var2, short var3) {
      short var6 = var3;

      while (--var6 > 0) {
         BlockSection var4 = this.getSectionAtBlockY(var6);
         if (var4.isSolidAir()) {
            var6 = (short)(ChunkUtil.indexSection(var6) * 32);
            if (var6 == 0) {
               break;
            }
         } else {
            int var5 = var4.get(var1, var6, var2);
            BlockType var7 = BlockType.getAssetMap().getAsset(var5);
            if (var5 != 0 && var7 != null && var7.getOpacity() != Opacity.Transparent) {
               break;
            }
         }
      }

      this.setHeight(var1, var2, var6);
      class="kw">return var6;
   }

   @Deprecated(forRemoval = true)
   class="kw">public void loadFromHolder(@Nonnull Holder<ChunkStore> var1) {
      ChunkColumn var2 = var1.getComponent(ChunkColumn.getComponentType());
      if (var2 != null) {
         Holder[] var3 = var2.getSectionHolders();

         for (int var4 = 0; var4 < var3.length; var4++) {
            Holder var5 = var3[var4];
            if (var5 != null) {
               this.chunkSections[var4] = var5.ensureAndGetComponent(BlockSection.getComponentType());
               this.chunkSectionsRefs[var4] = var5.getComponent(ChunkSection.getComponentType());
            }
         }
      }
   }

   @Deprecated(forRemoval = true)
   class="kw">public void refreshSectionRefs(@Nonnull Holder<ChunkStore>[] var1) {
      for (int var2 = 0; var2 < var1.length; var2++) {
         this.chunkSections[var2] = var1[var2].ensureAndGetComponent(BlockSection.getComponentType());
         this.chunkSectionsRefs[var2] = var1[var2].getComponent(ChunkSection.getComponentType());
      }
   }

   @Deprecated(forRemoval = false)
   class="kw">public BlockSection getSectionAtIndex(int var1) {
      if (var1 >= 0 && var1 < this.chunkSections.length) {
         class="kw">return this.chunkSections[var1];
      } else {
         throw new IllegalArgumentException("Section index must >=0 and <" + this.chunkSections.length + " but was given " + var1);
      }
   }

   @Deprecated(forRemoval = false)
   class="kw">public ChunkSection getSectionRefAtIndex(int var1) {
      if (var1 >= 0 && var1 < this.chunkSectionsRefs.length) {
         class="kw">return this.chunkSectionsRefs[var1];
      } else {
         throw new IllegalArgumentException("Section index must >=0 and <" + this.chunkSectionsRefs.length + " but was given " + var1);
      }
   }

   @Deprecated(forRemoval = false)
   class="kw">public BlockSection getSectionAtBlockY(int var1) {
      int var2 = ChunkUtil.indexSection(var1);
      if (var2 >= 0 && var2 < this.chunkSections.length) {
         class="kw">return this.chunkSections[var2];
      } else {
         throw new IllegalArgumentException("Section y must >=0 and <320 but was given " + var1);
      }
   }

   class="kw">public int getTint(int var1, int var2) {
      class="kw">return this.tint.get(var1, var2);
   }

   class="kw">public void setTint(int var1, int var2, int var3) {
      this.tint.set(var1, var2, var3);
      this.cachedColumnPacket = null;
      this.cachedTintmapPacket = null;
      this.markNeedsSaving();
   }

   class="kw">public int getEnvironment(@Nonnull Vector3d var1) {
      class="kw">return this.getEnvironment(MathUtil.floor(var1.x), MathUtil.floor(var1.y), MathUtil.floor(var1.z));
   }

   class="kw">public int getEnvironment(@Nonnull Vector3i var1) {
      class="kw">return this.getEnvironment(var1.x, var1.y, var1.z);
   }

   class="kw">public int getEnvironment(int var1, int var2, int var3) {
      class="kw">return var2 >= 0 && var2 < 320 ? this.environments.get(var1, var2, var3) : 0;
   }

   class="kw">public EnvironmentColumn getEnvironmentColumn(int var1, int var2) {
      class="kw">return this.environments.get(var1, var2);
   }

   class="kw">public void setEnvironment(int var1, int var2, int var3, int var4) {
      if (var2 >= 0 && var2 < 320) {
         this.environments.set(var1, var2, var3, var4);
         this.cachedColumnPacket = null;
         this.cachedEnvironmentsPacket = null;
         this.markNeedsSaving();
      }
   }

   class="kw">public int getBlock(int var1, int var2, int var3) {
      class="kw">return var2 >= 0 && var2 < 320 ? this.getSectionAtBlockY(var2).get(var1, var2, var3) : 0;
   }

   class="kw">public boolean setBlock(int var1, int var2, int var3, int var4, int var5, int var6) {
      if (var2 >= 0 && var2 < 320) {
         int var7 = ChunkUtil.indexSection(var2);
         BlockSection var8 = this.chunkSections[var7];
         boolean var9 = var8.set(var1, var2, var3, var4, var5, var6);
         if (var9) {
            this.invalidateChunkSection(var7);
            ChunkSection var10 = this.chunkSectionsRefs[var7];
            if (var10 != null) {
               var10.markNeedsSaving();
            }
         }

         class="kw">return var9;
      } else {
         throw new IllegalArgumentException(
            String.format("Failed to set block at %d, %d, %d to %d because it is outside the world bounds", var1, var2, var3, var4)
         );
      }
   }

   class="kw">public boolean contains(int var1) {
      class="kw">return this.count(var1) != 0;
   }

   class="kw">public int count(int var1) {
      int var2 = 0;

      for (BlockSection var6 : this.chunkSections) {
         var2 += var6.count(var1);
      }

      class="kw">return var2;
   }

   @Nonnull
   class="kw">public IntSet blocks() {
      IntSet var1 = new IntOpenHashSet();

      for (BlockSection var5 : this.chunkSections) {
         var1.addAll(var5.values());
      }

      class="kw">return var1;
   }

   class="kw">public int blockCount() {
      class="kw">return this.blocks().size();
   }

   class="kw">public <T, V> int forEachTicking(T var1, V var2, ObjectPositionBlockFunction<T, V, BlockTickStrategy> var3) {
      int var4 = 0;

      for (int var5 = 0; var5 < this.chunkSections.length; var5++) {
         BlockSection var6 = this.chunkSections[var5];
         int var7 = var6.forEachTicking(var1, var2, var5, var3);
         ChunkSection var8 = this.chunkSectionsRefs[var5];
         if (var7 > 0 && var8 != null) {
            var8.markNeedsSaving();
         }

         var4 += var7;
      }

      class="kw">return var4;
   }

   class="kw">public boolean setTicking(int var1, int var2, int var3, boolean var4) {
      if (var2 >= 0 && var2 < 320) {
         boolean var5 = this.getSectionAtBlockY(var2).setTicking(var1, var2, var3, var4);
         if (var5) {
            ChunkSection var6 = this.chunkSectionsRefs[ChunkUtil.chunkCoordinate(var2)];
            if (var6 != null) {
               var6.markNeedsSaving();
            }
         }

         class="kw">return var5;
      } else {
         class="kw">return false;
      }
   }

   class="kw">public boolean isTicking(int var1, int var2, int var3) {
      class="kw">return var2 >= 0 && var2 < 320 ? this.getSectionAtBlockY(var2).isTicking(var1, var2, var3) : false;
   }

   class="kw">public void markNeedsSaving() {
      this.needsSaving = true;
   }

   class="kw">public boolean getNeedsSaving() {
      class="kw">return this.needsSaving;
   }

   class="kw">public boolean consumeNeedsSaving() {
      boolean var1 = this.needsSaving;
      this.needsSaving = false;
      class="kw">return var1;
   }

   class="kw">public void markNeedsPhysics() {
      this.needsPhysics = true;
   }

   class="kw">public boolean consumeNeedsPhysics() {
      boolean var1 = this.needsPhysics;
      this.needsPhysics = false;
      class="kw">return var1;
   }

   class="kw">public void invalidateChunkSection(int var1) {
      this.chunkSections[var1].invalidate();
   }

   class="kw">private byte[] serialize(ExtraInfo var1) {
      int var2 = this.height.byteSize();
      byte[] var3 = new byte[1 + var2 + this.tint.byteSize()];
      MemorySegment var4 = MemorySegment.ofArray(var3);
      var4.set(ValueLayout.JAVA_BOOLEAN, 0L, this.needsPhysics);
      this.height.serialize(var4, 1);
      this.tint.serialize(var4, 1 + var2);
      class="kw">return var3;
   }

   class="kw">private void deserialize(@Nonnull byte[] var1, @Nonnull ExtraInfo var2) {
      if (var2.getVersion() < 3) {
         throw new IllegalArgumentException("Version not supported");
      }

      MemorySegment var3 = MemorySegment.ofArray(var1);
      this.needsPhysics = var3.get(ValueLayout.JAVA_BOOLEAN, 0L);
      int var4 = this.height.deserialize(var3, 1);
      this.tint.deserialize(var3, 1 + var4);
   }

   @Nonnull
   class="kw">private CompletableFuture<CachedPacket<SetColumn>> getCachedColumnPacket() {
      SoftReference var1 = this.cachedColumnPacket;
      CompletableFuture var2 = var1 != null ? var1.get() : null;
      if (var2 != null) {
         class="kw">return var2;
      }

      var2 = CompletableFuture.supplyAsync(() -> {
         SetColumn var1 = new SetColumn(this.x, this.z, this.height.serialize(), this.tint.serialize(), this.environments.serializeProtocol());
         class="kw">return CachedPacket.cache(var1);
      });
      this.cachedColumnPacket = new SoftReference<>(var2);
      class="kw">return var2;
   }

   @Nonnull
   class="kw">public CompletableFuture<CachedPacket<SetChunkTintmap>> getCachedTintsPacket() {
      SoftReference var1 = this.cachedTintmapPacket;
      CompletableFuture var2 = var1 != null ? var1.get() : null;
      if (var2 != null) {
         class="kw">return var2;
      }

      var2 = CompletableFuture.supplyAsync(() -> {
         SetChunkTintmap var1 = new SetChunkTintmap(this.x, this.z, this.tint.serialize());
         class="kw">return CachedPacket.cache(var1);
      });
      this.cachedTintmapPacket = new SoftReference<>(var2);
      class="kw">return var2;
   }

   @Nonnull
   class="kw">public CompletableFuture<CachedPacket<SetChunkEnvironments>> getCachedEnvironmentsPacket() {
      SoftReference var1 = this.cachedEnvironmentsPacket;
      CompletableFuture var2 = var1 != null ? var1.get() : null;
      if (var2 != null) {
         class="kw">return var2;
      }

      var2 = CompletableFuture.supplyAsync(() -> {
         SetChunkEnvironments var1 = new SetChunkEnvironments(this.x, this.z, this.environments.serializeProtocol());
         class="kw">return CachedPacket.cache(var1);
      });
      this.cachedEnvironmentsPacket = new SoftReference<>(var2);
      class="kw">return var2;
   }

   class="kw">public class="kw">static class LoadBlockChunkPacketSystem class="kw">extends ChunkStore.LoadFuturePacketDataQuerySystem {
      class="kw">private class="kw">final ComponentType<ChunkStore, BlockChunk> componentType;

      class="kw">public LoadBlockChunkPacketSystem(ComponentType<ChunkStore, BlockChunk> var1) {
         this.componentType = var1;
      }

      @Override
      class="kw">public Query<ChunkStore> getQuery() {
         class="kw">return this.componentType;
      }

      class="kw">public void fetch(
         int var1,
         @Nonnull ArchetypeChunk<ChunkStore> var2,
         Store<ChunkStore> var3,
         CommandBuffer<ChunkStore> var4,
         PlayerRef var5,
         @Nonnull List<CompletableFuture<ToClientPacket>> var6
      ) {
         BlockChunk var7 = var2.getComponent(var1, this.componentType);
         assert var7 != null;
         var6.add(var7.getCachedColumnPacket().exceptionally(var0 -> {
            if (var0 != null) {
               ((HytaleLogger.Api)BlockChunk.LOGGER.at(Level.SEVERE).withCause(var0)).log("Exception when compressing chunk column:");
            }

            class="kw">return null;
         }).thenApply(Function.identity()));
      }
   }
}