WildernessLocation class

Пакет: com.hypixel.hytale.builtin.adventure.wilderness.component

Файл: com/hypixel/hytale/builtin/adventure/wilderness/component/WildernessLocation.java

implements: EventLocation

Поля (31)

МодификаторыТипИмя
public static final BuilderCodec<WildernessLocation.Config> CODEC
public static final WildernessLocation.Config DEFAULT
public static final int DEFAULT_MAX_DISTANCE
public static final int DEFAULT_MAX_VERTICAL_DISTANCE
public static final int DEFAULT_MIN_DISTANCE
public static final int DEFAULT_MIN_VERTICAL_DISTANCE
final String ID
protected static final int MAX_DISTANCE_COMPONENT_2D
protected transient int maxDistanceSq
protected int maxHorizontalDistance
protected int maxVerticalDistance
protected transient int minDistanceSq
protected int minHorizontalDistance
protected int minVerticalDistance
WildernessLocation var1
int var10
int var11
int var12
int var13
int var14
int var15
int var16
World var2
Vector3iList var3
ThreadLocalRandom var3
ThreadLocalRandom var4
int var5
int var6
Wilderness var6
int var7
int var8

Методы (14)

МодификаторыВозвратСигнатура
public Configpublic Config()
protected void afterDecodeprotected void afterDecode()
protected void collectWildernessvoid collectWilderness(@Nonnull ArchetypeChunk<EntityStore> var1, @Nonnull CommandBuffer<EntityStore> var2)
public EventLocation createpublic EventLocation create()
for for(int var9 = 0; var9 < 3; var9++)
abstract for for(int var5 = this.selected.begin()
abstract for for(int var4 = 0; var4 < var1.size()
if if(this.selected == null)
if if(var15 >= this.config.minDistanceSq && var15 <= this.config.maxDistanceSq)
if if(var16 >= this.config.minVerticalDistance && var16 <= this.config.maxVerticalDistance)
if if(var5 > this.selectedBestScore)
if if(this.minDistanceSq >= 0 && this.maxDistanceSq >= 0)
if if(this.maxHorizontalDistance < this.minHorizontalDistance)
if if(this.maxVerticalDistance < this.minVerticalDistance)

Исходный код

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

class="kw">import com.hypixel.hytale.builtin.adventure.wilderness.resource.WildernessTracker;
class="kw">import com.hypixel.hytale.builtin.adventure.worldevents.condition.location.EventLocation;
class="kw">import com.hypixel.hytale.builtin.adventure.worldevents.util.Vector3iList;
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.validation.Validators;
class="kw">import com.hypixel.hytale.component.ArchetypeChunk;
class="kw">import com.hypixel.hytale.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.component.query.Query;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.math.util.ChunkUtil;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.Spectating;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import java.util.concurrent.CompletableFuture;
class="kw">import java.util.concurrent.ThreadLocalRandom;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;

class="kw">public class WildernessLocation class="kw">implements EventLocation {
   class="kw">public class="kw">static class="kw">final String ID = "WildernessLocation";
   class="kw">protected class="kw">static class="kw">final int CANDIDATES_PER_CHUNK = 3;
   class="kw">protected class="kw">static class="kw">final int SELECTED_MIN_SCORE = Integer.MIN_VALUE;
   class="kw">protected class="kw">static class="kw">final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
   class="kw">protected class="kw">static class="kw">final Query<EntityStore> WILDERNESS_QUERY = Query.and(Wilderness.getComponentType(), Query.not(Spectating.getComponentType()));
   class="kw">protected WildernessLocation.Config config = WildernessLocation.Config.DEFAULT;
   @Nullable
   class="kw">protected class="kw">transient Wilderness selected = null;
   class="kw">protected class="kw">transient int selectedBestScore = Integer.MIN_VALUE;

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

   @Nonnull
   @Override
   class="kw">public CompletableFuture<Vector3iList> find(@Nonnull Store<EntityStore> var1) {
      World var2 = var1.getExternalData().getWorld();
      if (WildernessTracker.getTracker(var2).isDisabled()) {
         class="kw">return CompletableFuture.completedFuture(new Vector3iList());
      }

      try {
         var1.forEachChunk(WILDERNESS_QUERY, this::collectWilderness);
         if (this.selected == null) {
            class="kw">return CompletableFuture.completedFuture(new Vector3iList());
         }

         Vector3iList var3 = new Vector3iList();
         ThreadLocalRandom var4 = ThreadLocalRandom.current();

         for (int var5 = this.selected.begin(); var5 != -1; var5 = this.selected.next(var5)) {
            int var6 = this.selected.xFromIndex(var5);
            int var7 = this.selected.yFromIndex(var5);
            int var8 = this.selected.zFromIndex(var5);

            for (int var9 = 0; var9 < 3; var9++) {
               int var10 = ChunkUtil.worldCoordFromLocalCoord(var6, var4.nextInt(32));
               int var11 = ChunkUtil.worldCoordFromLocalCoord(var7, var4.nextInt(32));
               int var12 = ChunkUtil.worldCoordFromLocalCoord(var8, var4.nextInt(32));
               int var13 = var10 - this.selected.getX();
               int var14 = var12 - this.selected.getZ();
               int var15 = var13 * var13 + var14 * var14;
               if (var15 >= this.config.minDistanceSq && var15 <= this.config.maxDistanceSq) {
                  int var16 = Math.abs(var11 - this.selected.getY());
                  if (var16 >= this.config.minVerticalDistance && var16 <= this.config.maxVerticalDistance) {
                     var3.add(var10, var11, var12);
                  }
               }
            }
         }

         class="kw">return CompletableFuture.completedFuture(var3);
      } class="kw">finally {
         this.selected = null;
         this.selectedBestScore = Integer.MIN_VALUE;
      }
   }

   class="kw">protected void collectWilderness(@Nonnull ArchetypeChunk<EntityStore> var1, @Nonnull CommandBuffer<EntityStore> var2) {
      ThreadLocalRandom var3 = ThreadLocalRandom.current();

      for (int var4 = 0; var4 < var1.size(); var4++) {
         int var5 = var3.nextInt();
         if (var5 > this.selectedBestScore) {
            Wilderness var6 = var1.getComponent(var4, Wilderness.getComponentType());
            if (var6 != null && !var6.empty()) {
               this.selected = var6;
               this.selectedBestScore = var5;
            }
         }
      }
   }

   class="kw">public class="kw">static class Config class="kw">implements EventLocation.Config {
      class="kw">protected class="kw">static class="kw">final int MAX_DISTANCE_COMPONENT_2D = (int)Math.floor(Math.sqrt(1.0737418235E9));
      class="kw">public class="kw">static class="kw">final BuilderCodec<WildernessLocation.Config> CODEC = BuilderCodec.builder(WildernessLocation.Config.class, WildernessLocation.Config::new)
         .documentation("An event location finds random wilderness positions nearby a player.")
         .<Integer>append(
            new KeyedCodec<>("MinHorizontalDistance", Codec.INTEGER), (var0, var1) -> var0.minHorizontalDistance = var1, var0 -> var0.minHorizontalDistance
         )
         .documentation("Minimum horizontal distance from the player in blocks.")
         .addValidator(Validators.range(0, MAX_DISTANCE_COMPONENT_2D))
         .add()
         .<Integer>append(
            new KeyedCodec<>("MaxHorizontalDistance", Codec.INTEGER), (var0, var1) -> var0.maxHorizontalDistance = var1, var0 -> var0.maxHorizontalDistance
         )
         .documentation("Maximum horizontal distance from the player in blocks.")
         .addValidator(Validators.range(0, MAX_DISTANCE_COMPONENT_2D))
         .add()
         .<Integer>append(
            new KeyedCodec<>("MinVerticalDistance", Codec.INTEGER), (var0, var1) -> var0.minVerticalDistance = var1, var0 -> var0.minVerticalDistance
         )
         .documentation("Minimum vertical distance from the player in blocks.")
         .addValidator(Validators.range(0, MAX_DISTANCE_COMPONENT_2D))
         .add()
         .<Integer>append(
            new KeyedCodec<>("MaxVerticalDistance", Codec.INTEGER), (var0, var1) -> var0.maxVerticalDistance = var1, var0 -> var0.maxVerticalDistance
         )
         .documentation("Maximum vertical distance from the player in blocks.")
         .addValidator(Validators.range(0, MAX_DISTANCE_COMPONENT_2D))
         .add()
         .afterDecode(WildernessLocation.Config::afterDecode)
         .build();
      class="kw">public class="kw">static class="kw">final int DEFAULT_MIN_DISTANCE = 32;
      class="kw">public class="kw">static class="kw">final int DEFAULT_MAX_DISTANCE = 64;
      class="kw">public class="kw">static class="kw">final int DEFAULT_MIN_VERTICAL_DISTANCE = 0;
      class="kw">public class="kw">static class="kw">final int DEFAULT_MAX_VERTICAL_DISTANCE = 32;
      class="kw">public class="kw">static class="kw">final WildernessLocation.Config DEFAULT = new WildernessLocation.Config();
      class="kw">protected int minHorizontalDistance = 32;
      class="kw">protected int maxHorizontalDistance = 64;
      class="kw">protected int minVerticalDistance = 0;
      class="kw">protected int maxVerticalDistance = 32;
      class="kw">protected class="kw">transient int minDistanceSq = -1;
      class="kw">protected class="kw">transient int maxDistanceSq = -1;

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

      @Nonnull
      @Override
      class="kw">public EventLocation create() {
         if (this.minDistanceSq >= 0 && this.maxDistanceSq >= 0) {
            WildernessLocation var1 = new WildernessLocation();
            var1.config = this;
            class="kw">return var1;
         } else {
            throw new IllegalStateException("WildernessLocation.Config not fully decoded (#afterDecode not called)");
         }
      }

      class="kw">protected void afterDecode() {
         this.minHorizontalDistance = Math.clamp(this.minHorizontalDistance, 0, MAX_DISTANCE_COMPONENT_2D);
         this.maxHorizontalDistance = Math.clamp(this.maxHorizontalDistance, 0, MAX_DISTANCE_COMPONENT_2D);
         if (this.maxHorizontalDistance < this.minHorizontalDistance) {
            this.maxHorizontalDistance = this.minHorizontalDistance;
            WildernessLocation.LOGGER.at(Level.WARNING).log("Max horizontal distance is invalid. Clamping to min");
         }

         this.minDistanceSq = this.minHorizontalDistance * this.minHorizontalDistance;
         this.maxDistanceSq = this.maxHorizontalDistance * this.maxHorizontalDistance;
         this.minVerticalDistance = Math.abs(this.minVerticalDistance);
         this.maxVerticalDistance = Math.abs(this.maxVerticalDistance);
         if (this.maxVerticalDistance < this.minVerticalDistance) {
            this.maxVerticalDistance = this.minVerticalDistance;
            WildernessLocation.LOGGER.at(Level.WARNING).log("Max vertical distance is invalid. Clamping to min");
         }
      }
   }
}