BlockTypeView class

Пакет: com.hypixel.hytale.server.npc.blackboard.view.blocktype

Файл: com/hypixel/hytale/server/npc/blackboard/view/blocktype/BlockTypeView.java

extends: BlockRegionView<BlockTypeView>

Поля (56)

МодификаторыТипИмя
break
final long index
Vector3d var10
int var11
int var12
int var13
World var14
int var15
int var16
int var17
int var18
BitSet var19
var19
int var2
int var2
Int2ObjectMap var2
ChunkStore var20
Store var21
long var24
Ref var26
BlockChunk var27
int var29
TransformComponent var3
Blackboard var3
IntList var3
HytaleLogger.Api var3
HytaleLogger.Api var3
BlockSection var30
Ref var31
BlockPositionProvider var32
var32
var32
short var33
HytaleLogger.Api var34
HytaleLogger.Api var35
BlockTypeView var36
IBlockPositionData var37
var37
var37
double var38
var38
IBlockPositionData var39
BlockTypeView var4
IntSet var4
double var40
ResourceView var41
HytaleLogger.Api var42
BitSet var43
var43
var43
var43
BlackboardSubscription var5
IntIterator var5
IntList var6
int var6
TransformComponent var9

Методы (26)

МодификаторыВозвратСигнатура
private void addSearchedBlockSetvoid addSearchedBlockSet(int var1)
public void addSearchedBlockSetsvoid addSearchedBlockSets(@Nonnull Ref<EntityStore> var1, @Nonnull IntList var2)
for for(int var22 = var11 - var15 & -32; var22 < var11 + var15; var22 += 32)
for for(int var23 = var12 - var15 & -32; var23 < var12 + var15; var23 += 32)
for for(int var28 = var17; var28 < var18; var28 += 32)
abstract for for(int var4 = 0; var4 < var2.size()
abstract for for(int var25 = 0; var25 < this.foundBlocks.size()
abstract for for(int var3 = var1.nextSetBit(0)
public long getIndexlong getIndex()
if if(var3 != null)
if if(var2 == 0)
if if(var2 < 0)
if if(var2 == 0)
if if(var27 != null)
if if(this.aggregateNeedsRebuild)
if if(var19 == null)
if if(var32 != null)
if if(var36 != null)
if if(var6)
if if(var40 < var38)
if if(var3 == Integer.MAX_VALUE)
static void rebuildBlockTypeAggregatevoid rebuildBlockTypeAggregate(@Nonnull IntArrayList var0, @Nonnull BitSet var1)
abstract rebuildBlockTypeAggregate rebuildBlockTypeAggregate(this.blockSetAggregate, this.allBlockSets)
abstract rebuildBlockTypeAggregate rebuildBlockTypeAggregate(this.crossViewBlockSetAggregate, var43)
private void removeSearchedBlockSetvoid removeSearchedBlockSet(int var1)
public void removeSearchedBlockSetsvoid removeSearchedBlockSets(@Nonnull Ref<EntityStore> var1, @Nonnull IntList var2)

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.server.npc.blackboard.view.blocktype;

class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.math.random.RandomExtra;
class="kw">import com.hypixel.hytale.math.util.ChunkUtil;
class="kw">import com.hypixel.hytale.math.util.MathUtil;
class="kw">import com.hypixel.hytale.server.core.modules.blockset.BlockSetModule;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.BlockChunk;
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.blockpositions.BlockPositionProvider;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.section.blockpositions.IBlockPositionData;
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 com.hypixel.hytale.server.npc.blackboard.Blackboard;
class="kw">import com.hypixel.hytale.server.npc.blackboard.BlackboardSubscription;
class="kw">import com.hypixel.hytale.server.npc.blackboard.view.BlockRegionView;
class="kw">import com.hypixel.hytale.server.npc.blackboard.view.resource.ResourceView;
class="kw">import it.unimi.dsi.fastutil.ints.Int2IntMap;
class="kw">import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
class="kw">import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
class="kw">import it.unimi.dsi.fastutil.ints.IntArrayList;
class="kw">import it.unimi.dsi.fastutil.ints.IntIterator;
class="kw">import it.unimi.dsi.fastutil.ints.IntList;
class="kw">import it.unimi.dsi.fastutil.ints.IntSet;
class="kw">import it.unimi.dsi.fastutil.objects.ObjectArrayList;
class="kw">import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
class="kw">import java.util.BitSet;
class="kw">import java.util.List;
class="kw">import java.util.Set;
class="kw">import java.util.function.BiPredicate;
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 BlockTypeView class="kw">extends BlockRegionView<BlockTypeView> {
   class="kw">private class="kw">final long index;
   class="kw">private class="kw">final Blackboard blackboard;
   class="kw">private class="kw">final BitSet allBlockSets = new BitSet();
   class="kw">private class="kw">final Set<Ref<EntityStore>> entities = new ReferenceOpenHashSet();
   class="kw">private class="kw">final IntArrayList blockSetAggregate = new IntArrayList();
   class="kw">private class="kw">final IntArrayList crossViewBlockSetAggregate = new IntArrayList();
   class="kw">private boolean aggregateNeedsRebuild;
   class="kw">private class="kw">final Int2IntMap blockSetCounts = new Int2IntOpenHashMap();
   class="kw">private class="kw">final List<IBlockPositionData> foundBlocks = new ObjectArrayList();
   class="kw">private class="kw">final BlockPositionEntryGenerator generator;
   class="kw">private class="kw">final BiPredicate<IBlockPositionData, ResourceView> reservedBlockFilter = (var0, var1x) -> var1x.isBlockReserved(
      var0.getX(), var0.getY(), var0.getZ()
   );

   class="kw">public BlockTypeView(long var1, Blackboard var3, BlockPositionEntryGenerator var4) {
      this.index = var1;
      this.blackboard = var3;
      this.generator = var4;
   }

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

   @Override
   class="kw">public boolean isOutdated(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2) {
      TransformComponent var3 = var2.getComponent(var1, TransformComponent.getComponentType());
      assert var3 != null;
      class="kw">return indexViewFromWorldPosition(var3.getPosition()) != this.index;
   }

   @Nonnull
   class="kw">public BlockTypeView getUpdatedView(@Nonnull Ref<EntityStore> var1, @Nonnull ComponentAccessor<EntityStore> var2) {
      Blackboard var3 = var2.getResource(Blackboard.getResourceType());
      BlockTypeView var4 = var3.getView(BlockTypeView.class, var1, var2);
      BlackboardSubscription var5 = var2.getComponent(var1, BlackboardSubscription.getComponentType());
      assert var5 != null;
      IntList var6 = var5.getBlockTypeSets();
      assert var6 != null;
      this.removeSearchedBlockSets(var1, var6);
      var4.addSearchedBlockSets(var1, var6);
      class="kw">return var4;
   }

   @Override
   class="kw">public void initialiseEntity(@Nonnull Ref<EntityStore> var1, @Nonnull BlackboardSubscription var2) {
      IntList var3 = var2.getBlockTypeSets();
      if (var3 != null) {
         this.addSearchedBlockSets(var1, var3);
      }
   }

   @Override
   class="kw">public void cleanup() {
   }

   @Override
   class="kw">public void onWorldRemoved() {
   }

   class="kw">public void addSearchedBlockSets(@Nonnull Ref<EntityStore> var1, @Nonnull IntList var2) {
      HytaleLogger.Api var3 = Blackboard.LOGGER.at(Level.FINEST);
      if (var3.isEnabled()) {
         var3.log("Registering new entity (reference:%s) with partial blackboard view %s, %s", var1, xOfViewIndex(this.index), zOfViewIndex(this.index));
      }

      this.entities.add(var1);

      for (int var4 = 0; var4 < var2.size(); var4++) {
         this.addSearchedBlockSet(var2.getInt(var4));
      }
   }

   class="kw">private void addSearchedBlockSet(int var1) {
      int var2 = this.blockSetCounts.getOrDefault(var1, 0);
      if (var2 == 0) {
         this.allBlockSets.set(var1);
         this.aggregateNeedsRebuild = true;
      }

      this.blockSetCounts.put(var1, var2 + 1);
   }

   class="kw">public void removeSearchedBlockSets(@Nonnull Ref<EntityStore> var1, @Nonnull IntList var2) {
      if (!this.entities.remove(var1)) {
         throw new IllegalStateException(
            String.format(
               "Attempting to unregister entity (reference:%s) from partial blackboard view %s at %s, %s when not registered",
               var1,
               this.index,
               xOfViewIndex(this.index),
               zOfViewIndex(this.index)
            )
         );
      }

      HytaleLogger.Api var3 = Blackboard.LOGGER.at(Level.FINEST);
      if (var3.isEnabled()) {
         var3.log("Unregistering entity (reference:%s) from partial blackboard view %s, %s", var1, xOfViewIndex(this.index), zOfViewIndex(this.index));
      }

      for (int var4 = 0; var4 < var2.size(); var4++) {
         this.removeSearchedBlockSet(var2.getInt(var4));
      }
   }

   class="kw">private void removeSearchedBlockSet(int var1) {
      int var2 = this.blockSetCounts.getOrDefault(var1, 0) - 1;
      if (var2 < 0) {
         throw new IllegalStateException(
            String.format(
               "Attempting to unregister blockset %s from partial blackboard view %s at %s, %s when not registered",
               var1,
               this.index,
               xOfViewIndex(this.index),
               zOfViewIndex(this.index)
            )
         );
      }

      if (var2 == 0) {
         this.allBlockSets.clear(var1);
         this.aggregateNeedsRebuild = true;
      }

      this.blockSetCounts.put(var1, var2);
   }

   @Nullable
   class="kw">public IBlockPositionData findBlock(
      int var1, double var2, double var4, boolean var6, @Nonnull Ref<EntityStore> var7, @Nonnull ComponentAccessor<EntityStore> var8
   ) {
      TransformComponent var9 = var8.getComponent(var7, TransformComponent.getComponentType());
      assert var9 != null;
      Vector3d var10 = var9.getPosition();
      int var11 = MathUtil.floor(var10.x);
      int var12 = MathUtil.floor(var10.z);
      int var13 = MathUtil.floor(var10.y);
      World var14 = var8.getExternalData().getWorld();
      int var15 = MathUtil.ceil(var2);
      int var16 = MathUtil.ceil(var4);
      int var17 = MathUtil.clamp(var13 - var16 & -32, 0, 320);
      int var18 = MathUtil.clamp(var13 + var16, 0, 320);
      BitSet var19 = null;
      ChunkStore var20 = var14.getChunkStore();
      Store var21 = var20.getStore();

      for (int var22 = var11 - var15 & -32; var22 < var11 + var15; var22 += 32) {
         for (int var23 = var12 - var15 & -32; var23 < var12 + var15; var23 += 32) {
            long var24 = ChunkUtil.indexChunkFromBlock(var22, var23);
            Ref var26 = var20.getChunkReference(var24);
            if (var26 != null && var26.isValid()) {
               BlockChunk var27 = var21.getComponent(var26, BlockChunk.getComponentType());
               if (var27 != null) {
                  for (int var28 = var17; var28 < var18; var28 += 32) {
                     int var29 = ChunkUtil.indexSection(var28);
                     BlockSection var30 = var27.getSectionAtIndex(var29);
                     Ref var31 = var20.getChunkSectionReference(ChunkUtil.chunkCoordinate(var22), var29, ChunkUtil.chunkCoordinate(var23));
                     if (var31 != null && var31.isValid()) {
                        BlockPositionProvider var32 = var21.getComponent(var31, BlockPositionProvider.getComponentType());
                        if (var32 == null || var32.isStale(var1, var30)) {
                           short var33 = var30.getLocalChangeCounter();
                           if (indexViewFromChunkCoordinates(var22, var23) == this.index) {
                              if (this.aggregateNeedsRebuild) {
                                 HytaleLogger.Api var34 = Blackboard.LOGGER.at(Level.FINEST);
                                 if (var34.isEnabled()) {
                                    var34.log(
                                       "Rebuilding blocktype aggregate in partial blackboard view %s, %s with %s blocksets",
                                       xOfViewIndex(this.index),
                                       zOfViewIndex(this.index),
                                       this.allBlockSets.cardinality()
                                    );
                                 }

                                 this.aggregateNeedsRebuild = false;
                                 rebuildBlockTypeAggregate(this.blockSetAggregate, this.allBlockSets);
                              }

                              HytaleLogger.Api var42 = Blackboard.LOGGER.at(Level.FINEST);
                              if (var42.isEnabled()) {
                                 var42.log(
                                    "Entity (reference:%s) generating new entry for chunk %s section %s in view %s, %s",
                                    var7,
                                    var24,
                                    var29,
                                    xOfViewIndex(this.index),
                                    zOfViewIndex(this.index)
                                 );
                              }

                              if (var19 == null) {
                                 var19 = (BitSet)this.allBlockSets.clone();
                              }

                              var32 = this.generator.generate(var33, var29, var27, this.blockSetAggregate, var19);
                           } else {
                              HytaleLogger.Api var35 = Blackboard.LOGGER.at(Level.FINEST);
                              BitSet var43;
                              if (var32 != null) {
                                 if (var35.isEnabled()) {
                                    var35.log(
                                       "Entity (reference:%s) generating new entry for chunk %s section %s across border using existing entry",
                                       var7,
                                       var24,
                                       var29
                                    );
                                 }

                                 var43 = var32.getSearchedBlockSets();
                              } else {
                                 if (var35.isEnabled()) {
                                    var35.log("Entity (reference:%s) generating new entry for chunk %s section %s across border", var7, var24, var29);
                                 }

                                 BlockTypeView var36 = this.blackboard.getView(BlockTypeView.class, var22, var23);
                                 if (var36 != null) {
                                    var43 = (BitSet)var36.allBlockSets.clone();
                                 } else {
                                    var43 = new BitSet();
                                 }
                              }

                              var43.or(this.allBlockSets);
                              rebuildBlockTypeAggregate(this.crossViewBlockSetAggregate, var43);
                              var32 = this.generator.generate(var33, var29, var27, this.crossViewBlockSetAggregate, var43);
                           }

                           var21.putComponent(var31, BlockPositionProvider.getComponentType(), var32);
                        }

                        ResourceView var41 = this.blackboard.getIfExists(ResourceView.class, indexViewFromChunkCoordinates(var22, var23));
                        var32.findBlocks(this.foundBlocks, var1, var2, var16, var7, var41 != null ? this.reservedBlockFilter : null, var41, var8);
                     }
                  }
               }
            }
         }
      }

      if (this.foundBlocks.isEmpty()) {
         class="kw">return null;
      }

      IBlockPositionData var37 = null;
      if (var6) {
         var37 = RandomExtra.randomElement(this.foundBlocks);
      } else {
         double var38 = Double.MAX_VALUE;

         for (int var25 = 0; var25 < this.foundBlocks.size(); var25++) {
            IBlockPositionData var39 = this.foundBlocks.get(var25);
            double var40 = var10.distanceSquared(var39.getXCentre(), var39.getYCentre(), var39.getZCentre());
            if (var40 < var38) {
               var38 = var40;
               var37 = var39;
            }
         }
      }

      this.foundBlocks.clear();
      class="kw">return var37;
   }

   @Nonnull
   class="kw">public Set<Ref<EntityStore>> getEntities() {
      class="kw">return this.entities;
   }

   @Nonnull
   class="kw">public BitSet getAllBlockSets() {
      class="kw">return this.allBlockSets;
   }

   @Nonnull
   class="kw">public Int2IntMap getBlockSetCounts() {
      class="kw">return this.blockSetCounts;
   }

   class="kw">private class="kw">static void rebuildBlockTypeAggregate(@Nonnull IntArrayList var0, @Nonnull BitSet var1) {
      var0.clear();
      Int2ObjectMap var2 = BlockSetModule.getInstance().getBlockSets();

      for (int var3 = var1.nextSetBit(0); var3 >= 0; var3 = var1.nextSetBit(var3 + 1)) {
         IntSet var4 = (IntSet)var2.get(var3);
         IntIterator var5 = var4.iterator();

         while (var5.hasNext()) {
            int var6 = var5.nextInt();
            var0.add(var6);
         }

         if (var3 == Integer.MAX_VALUE) {
            break;
         }
      }
   }
}