WeatherTriggerCondition class

Пакет: com.hypixel.hytale.builtin.adventure.objectives.config.triggercondition

Файл: com/hypixel/hytale/builtin/adventure/objectives/config/triggercondition/WeatherTriggerCondition.java

extends: ObjectiveLocationTriggerCondition

Поля (12)

МодификаторыТипИмя
Ref var10
BlockChunk var11
int var12
int var13
String var2
int var3
WeatherResource var4
TransformComponent var5
World var6
Store var7
Ref var8
ChunkSection var9

Методы (5)

МодификаторыВозвратСигнатура
abstract throw new IllegalArgumentExceptionthrow new IllegalArgumentException("Unknown key! " + var2)
for for(int var1 = 0; var1 < var0.weatherIds.length; var1++)
if if(var0.weatherIds != null)
if if(var3 == Integer.MIN_VALUE)
if if(var9 == null)

Исходный код

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

class="kw">import com.hypixel.hytale.builtin.adventure.objectives.markers.objectivelocation.ObjectiveLocationMarker;
class="kw">import com.hypixel.hytale.builtin.weather.resources.WeatherResource;
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.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.ComponentType;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.ResourceType;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.server.core.asset.type.weather.config.Weather;
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.ChunkSection;
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 java.util.Arrays;
class="kw">import javax.annotation.Nonnull;

class="kw">public class WeatherTriggerCondition class="kw">extends ObjectiveLocationTriggerCondition {
   @Nonnull
   class="kw">public class="kw">static class="kw">final BuilderCodec<WeatherTriggerCondition> CODEC = BuilderCodec.builder(WeatherTriggerCondition.class, WeatherTriggerCondition::new)
      .append(new KeyedCodec<>("WeatherIds", Codec.STRING_ARRAY), (var0, var1) -> var0.weatherIds = var1, var0 -> var0.weatherIds)
      .addValidator(Validators.nonEmptyArray())
      .addValidator(Weather.VALIDATOR_CACHE.getArrayValidator())
      .add()
      .afterDecode(var0 -> {
         if (var0.weatherIds != null) {
            var0.weatherIndexes = new int[var0.weatherIds.length];

            for (int var1 = 0; var1 < var0.weatherIds.length; var1++) {
               String var2 = var0.weatherIds[var1];
               int var3 = Weather.getAssetMap().getIndex(var2);
               if (var3 == Integer.MIN_VALUE) {
                  throw new IllegalArgumentException("Unknown key! " + var2);
               }

               var0.weatherIndexes[var1] = var3;
            }

            Arrays.sort(var0.weatherIndexes);
         }
      })
      .build();
   @Nonnull
   class="kw">protected class="kw">static class="kw">final ResourceType<EntityStore, WeatherResource> WEATHER_RESOURCE_RESOURCE_TYPE = WeatherResource.getResourceType();
   @Nonnull
   class="kw">protected class="kw">static class="kw">final ComponentType<EntityStore, TransformComponent> TRANSFORM_COMPONENT_TYPE = TransformComponent.getComponentType();
   class="kw">protected String[] weatherIds;
   class="kw">protected int[] weatherIndexes;

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

   @Override
   class="kw">public boolean isConditionMet(@Nonnull ComponentAccessor<EntityStore> var1, @Nonnull Ref<EntityStore> var2, ObjectiveLocationMarker var3) {
      WeatherResource var4 = var1.getResource(WEATHER_RESOURCE_RESOURCE_TYPE);
      TransformComponent var5 = var1.getComponent(var2, TRANSFORM_COMPONENT_TYPE);
      assert var5 != null;
      World var6 = var1.getExternalData().getWorld();
      Store var7 = var6.getChunkStore().getStore();
      Ref var8 = var5.getSectionRef();
      if (var8 != null && var8.isValid()) {
         ChunkSection var9 = var7.getComponent(var8, ChunkSection.getComponentType());
         if (var9 == null) {
            class="kw">return false;
         } else {
            Ref var10 = var9.getChunkColumnReference();
            if (var10 != null && var10.isValid()) {
               BlockChunk var11 = var7.getComponent(var10, BlockChunk.getComponentType());
               assert var11 != null;
               int var12 = var11.getEnvironment(var5.getPosition());
               int var13 = var4.getWeatherIndexForEnvironment(var12);
               class="kw">return Arrays.binarySearch(this.weatherIndexes, var13) >= 0;
            } else {
               class="kw">return false;
            }
         }
      } else {
         class="kw">return false;
      }
   }

   @Nonnull
   @Override
   class="kw">public String toString() {
      class="kw">return "WeatherTriggerCondition{weatherIds=" + Arrays.toString(this.weatherIds) + "} " + super.toString();
   }
}