HyCodeYourTale
classpublicPriority 3

PlayerChunkTrackerSystems

com.hypixel.hytale.server.core.modules.entity.player.PlayerChunkTrackerSystems

4

Methods

4

Public Methods

0

Fields

1

Constructors

Constants

ComponentType<EntityStore, ChunkTracker>CHUNK_TRACKER_COMPONENT_TYPE= ChunkTracker.getComponentType()
ComponentType<EntityStore, ChunkTracker>CHUNK_TRACKER_COMPONENT_TYPE= ChunkTracker.getComponentType()

Constructors

public
PlayerChunkTrackerSystems()

Methods

Public Methods (4)

public
Query<EntityStore> getQuery()
@Override
public
boolean isParallel(int archetypeChunkSize, int taskCount)
@Override
public
void onEntityAdd(Holder<EntityStore> holder, AddReason reason, Store<EntityStore> store)
@Override
public
void onEntityRemoved(Holder<EntityStore> holder, RemoveReason reason, Store<EntityStore> store)
@Override

Related Classes

Source Code

package com.hypixel.hytale.server.core.modules.entity.player;

import com.hypixel.hytale.component.AddReason;
import com.hypixel.hytale.component.ArchetypeChunk;
import com.hypixel.hytale.component.CommandBuffer;
import com.hypixel.hytale.component.ComponentType;
import com.hypixel.hytale.component.Holder;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.component.RemoveReason;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.component.query.Query;
import com.hypixel.hytale.component.system.HolderSystem;
import com.hypixel.hytale.component.system.tick.EntityTickingSystem;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import javax.annotation.Nonnull;

public class PlayerChunkTrackerSystems {
   public PlayerChunkTrackerSystems() {
   }

   public static class AddSystem extends HolderSystem<EntityStore> {
      @Nonnull
      private static final ComponentType<EntityStore, ChunkTracker> CHUNK_TRACKER_COMPONENT_TYPE = ChunkTracker.getComponentType();

      public AddSystem() {
      }

      @Override
      public Query<EntityStore> getQuery() {
         return CHUNK_TRACKER_COMPONENT_TYPE;
      }

      @Override
      public void onEntityAdd(@Nonnull Holder<EntityStore> holder, @Nonnull AddReason reason, @Nonnull Store<EntityStore> store) {
         ChunkTracker chunkTrackerComponent = holder.getComponent(CHUNK_TRACKER_COMPONENT_TYPE);

         assert chunkTrackerComponent != null;

         chunkTrackerComponent.setReadyForChunks(true);
      }

      @Override
      public void onEntityRemoved(@Nonnull Holder<EntityStore> holder, @Nonnull RemoveReason reason, @Nonnull Store<EntityStore> store) {
      }
   }

   public static class UpdateSystem extends EntityTickingSystem<EntityStore> {
      @Nonnull
      private static final ComponentType<EntityStore, ChunkTracker> CHUNK_TRACKER_COMPONENT_TYPE = ChunkTracker.getComponentType();

      public UpdateSystem() {
      }

      @Override
      public Query<EntityStore> getQuery() {
         return CHUNK_TRACKER_COMPONENT_TYPE;
      }

      @Override
      public boolean isParallel(int archetypeChunkSize, int taskCount) {
         return false;
      }

      @Override
      public void tick(
         float dt,
         int index,
         @Nonnull ArchetypeChunk<EntityStore> archetypeChunk,
         @Nonnull Store<EntityStore> store,
         @Nonnull CommandBuffer<EntityStore> commandBuffer
      ) {
         Ref<EntityStore> ref = archetypeChunk.getReferenceTo(index);
         ChunkTracker chunkTrackerComponent = archetypeChunk.getComponent(index, CHUNK_TRACKER_COMPONENT_TYPE);

         assert chunkTrackerComponent != null;

         chunkTrackerComponent.tick(ref, dt, commandBuffer);
      }
   }
}