PrefabSpawnerBlock class

Пакет: com.hypixel.hytale.server.core.modules.prefabspawner

Файл: com/hypixel/hytale/server/core/modules/prefabspawner/PrefabSpawnerBlock.java

implements: Component<ChunkStore>

Поля (17)

МодификаторыТипИмя
public static final BuilderCodec<PrefabSpawnerBlock.PrefabSpawnerSettingsPageEventData> CODEC
final KeyedCodec<Boolean> FIT_HEIGHTMAP_CODEC
public static final String KEY_DEFAULT_WEIGHT
public static final String KEY_FIT_HEIGHTMAP
public static final String KEY_INHERIT_HEIGHT_CONDITION
public static final String KEY_INHERIT_SEED
public static final String KEY_PREFAB_PATH
public static final String KEY_PREFAB_WEIGHTS
private double defaultWeight
private boolean fitHeightmap
private final BlockModule.BlockStateInfo info
private boolean inheritHeightCondition
private boolean inheritSeed
private String prefabPath
private String prefabWeights
private final PrefabSpawnerBlock state
Player var4

Методы (16)

МодификаторыВозвратСигнатура
public PrefabSpawnerSettingsPagepublic PrefabSpawnerSettingsPage(@Nonnull PlayerRef var1, BlockModule.BlockStateInfo var2, PrefabSpawnerBlock var3, @Nonnull CustomPageLifetime var4)
public PrefabSpawnerSettingsPageEventDatapublic PrefabSpawnerSettingsPageEventData()
public void buildpublic void build(@Nonnull Ref<EntityStore> var1, @Nonnull UICommandBuilder var2, @Nonnull UIEventBuilder var3, @Nonnull Store<EntityStore> var4)
static ComponentType<ChunkStore, PrefabSpawnerBlock> getComponentTypeComponentType<ChunkStore, PrefabSpawnerBlock> getComponentType()
public String getPrefabPathString getPrefabPath()
public PrefabWeights getPrefabWeightsPrefabWeights getPrefabWeights()
public void handleDataEventpublic void handleDataEvent(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull PrefabSpawnerBlock.PrefabSpawnerSettingsPageEventData var3)
public boolean isFitHeightmapboolean isFitHeightmap()
public boolean isInheritHeightConditionboolean isInheritHeightCondition()
public boolean isInheritSeedboolean isInheritSeed()
public void setFitHeightmapvoid setFitHeightmap(boolean var1)
public void setInheritHeightConditionvoid setInheritHeightCondition(boolean var1)
public void setInheritSeedvoid setInheritSeed(boolean var1)
public void setPrefabPathvoid setPrefabPath(String var1)
public void setPrefabWeightsvoid setPrefabWeights(PrefabWeights var1)
abstract super super(var1, var4, PrefabSpawnerBlock.PrefabSpawnerSettingsPageEventData.CODEC)

Исходный код

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

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.Component;
class="kw">import com.hypixel.hytale.component.ComponentType;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.protocol.packets.interface_.CustomPageLifetime;
class="kw">import com.hypixel.hytale.protocol.packets.interface_.CustomUIEventBindingType;
class="kw">import com.hypixel.hytale.protocol.packets.interface_.Page;
class="kw">import com.hypixel.hytale.server.core.entity.entities.Player;
class="kw">import com.hypixel.hytale.server.core.entity.entities.player.pages.InteractiveCustomUIPage;
class="kw">import com.hypixel.hytale.server.core.modules.block.BlockModule;
class="kw">import com.hypixel.hytale.server.core.prefab.PrefabWeights;
class="kw">import com.hypixel.hytale.server.core.ui.builder.EventData;
class="kw">import com.hypixel.hytale.server.core.ui.builder.UICommandBuilder;
class="kw">import com.hypixel.hytale.server.core.ui.builder.UIEventBuilder;
class="kw">import com.hypixel.hytale.server.core.universe.PlayerRef;
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.Objects;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;

class="kw">public class PrefabSpawnerBlock class="kw">implements Component<ChunkStore> {
   class="kw">public class="kw">static class="kw">final KeyedCodec<Boolean> FIT_HEIGHTMAP_CODEC = new KeyedCodec<>("FitHeightmap", Codec.BOOLEAN);
   class="kw">public class="kw">static class="kw">final KeyedCodec<Boolean> INHERIT_SEED_CODEC = new KeyedCodec<>("InheritSeed", Codec.BOOLEAN);
   class="kw">public class="kw">static class="kw">final KeyedCodec<Boolean> INHERIT_HEIGHT_CONDITION_CODEC = new KeyedCodec<>("InheritHeightCondition", Codec.BOOLEAN);
   class="kw">public class="kw">static class="kw">final KeyedCodec<PrefabWeights> PREFAB_WEIGHTS_CODEC = new KeyedCodec<>("PrefabWeights", PrefabWeights.CODEC);
   @Nonnull
   class="kw">public class="kw">static class="kw">final BuilderCodec<PrefabSpawnerBlock> CODEC = BuilderCodec.builder(PrefabSpawnerBlock.class, PrefabSpawnerBlock::new)
      .append(new KeyedCodec<>("PrefabPath", Codec.STRING), (var0, var1) -> var0.prefabPath = var1, var0 -> var0.prefabPath)
      .documentation("The prefab path where the prefab is located. This uses the dot-notation. 'folder.folder.folder.filename'")
      .add()
      .<Boolean>append(FIT_HEIGHTMAP_CODEC, (var0, var1) -> var0.fitHeightmap = var1, var0 -> var0.fitHeightmap)
      .documentation("Determines if the child prefab should follow the heightmap during generation in worldgen.")
      .add()
      .<Boolean>append(INHERIT_SEED_CODEC, (var0, var1) -> var0.inheritSeed = var1, var0 -> var0.inheritSeed)
      .documentation("Determines if the child prefab should inherit the worldgen-id from the parent. This allows child prefabs to have independent markers.")
      .add()
      .<Boolean>append(INHERIT_HEIGHT_CONDITION_CODEC, (var0, var1) -> var0.inheritHeightCondition = var1, var0 -> var0.inheritHeightCondition)
      .documentation(
         "Determines if the child prefab should inherit the HeightCondition from the parent. Setting to false allows child prefabs to bypass the height condition check."
      )
      .add()
      .append(PREFAB_WEIGHTS_CODEC, PrefabSpawnerBlock::setPrefabWeights, PrefabSpawnerBlock::getPrefabWeightsNullable)
      .documentation(
         "Determines the probability of each individual prefab file being selected to generate when the PrefabPath points to a folder containing multiple prefabs."
      )
      .add()
      .build();
   class="kw">private String prefabPath;
   class="kw">private boolean fitHeightmap;
   class="kw">private boolean inheritSeed;
   class="kw">private boolean inheritHeightCondition;
   class="kw">private PrefabWeights prefabWeights;

   class="kw">public class="kw">static ComponentType<ChunkStore, PrefabSpawnerBlock> getComponentType() {
      class="kw">return PrefabSpawnerModule.get().getPrefabSpawnerBlockType();
   }

   class="kw">public PrefabSpawnerBlock() {
      this.fitHeightmap = false;
      this.inheritSeed = true;
      this.inheritHeightCondition = true;
      this.prefabWeights = PrefabWeights.NONE;
   }

   class="kw">public PrefabSpawnerBlock(String var1, boolean var2, boolean var3, boolean var4, PrefabWeights var5) {
      this.prefabPath = var1;
      this.fitHeightmap = var2;
      this.inheritSeed = var3;
      this.inheritHeightCondition = var4;
      this.prefabWeights = var5;
   }

   class="kw">public String getPrefabPath() {
      class="kw">return this.prefabPath;
   }

   class="kw">public void setPrefabPath(String var1) {
      this.prefabPath = var1;
   }

   class="kw">public boolean isFitHeightmap() {
      class="kw">return this.fitHeightmap;
   }

   class="kw">public void setFitHeightmap(boolean var1) {
      this.fitHeightmap = var1;
   }

   class="kw">public boolean isInheritSeed() {
      class="kw">return this.inheritSeed;
   }

   class="kw">public void setInheritSeed(boolean var1) {
      this.inheritSeed = var1;
   }

   class="kw">public boolean isInheritHeightCondition() {
      class="kw">return this.inheritHeightCondition;
   }

   class="kw">public void setInheritHeightCondition(boolean var1) {
      this.inheritHeightCondition = var1;
   }

   class="kw">public PrefabWeights getPrefabWeights() {
      class="kw">return this.prefabWeights;
   }

   class="kw">public void setPrefabWeights(PrefabWeights var1) {
      this.prefabWeights = var1;
   }

   @Nullable
   class="kw">private PrefabWeights getPrefabWeightsNullable() {
      class="kw">return this.prefabWeights.size() == 0 ? null : this.prefabWeights;
   }

   @Nullable
   @Override
   class="kw">public Component<ChunkStore> clone() {
      class="kw">return new PrefabSpawnerBlock(this.prefabPath, this.fitHeightmap, this.inheritSeed, this.inheritHeightCondition, this.prefabWeights);
   }

   class="kw">public class="kw">static class PrefabSpawnerSettingsPage class="kw">extends InteractiveCustomUIPage<PrefabSpawnerBlock.PrefabSpawnerSettingsPageEventData> {
      class="kw">private class="kw">final BlockModule.BlockStateInfo info;
      class="kw">private class="kw">final PrefabSpawnerBlock state;

      class="kw">public PrefabSpawnerSettingsPage(@Nonnull PlayerRef var1, BlockModule.BlockStateInfo var2, PrefabSpawnerBlock var3, @Nonnull CustomPageLifetime var4) {
         super(var1, var4, PrefabSpawnerBlock.PrefabSpawnerSettingsPageEventData.CODEC);
         this.info = var2;
         this.state = var3;
      }

      @Override
      class="kw">public void build(@Nonnull Ref<EntityStore> var1, @Nonnull UICommandBuilder var2, @Nonnull UIEventBuilder var3, @Nonnull Store<EntityStore> var4) {
         var2.append("Pages/PrefabSpawnerSettingsPage.ui");
         var2.set("#PrefabPath.Value", Objects.requireNonNullElse(this.state.prefabPath, ""));
         var2.set("#FitHeightmap #CheckBox.Value", this.state.fitHeightmap);
         var2.set("#InheritSeed #CheckBox.Value", this.state.inheritSeed);
         var2.set("#InheritHeightCondition #CheckBox.Value", this.state.inheritHeightCondition);
         var2.set("#DefaultWeight.Value", this.state.getPrefabWeights().getDefaultWeight());
         var2.set("#PrefabWeights.Value", this.state.getPrefabWeights().getMappingString());
         var3.addEventBinding(
            CustomUIEventBindingType.Activating,
            "#SaveButton",
            new EventData()
               .append("@PrefabPath", "#PrefabPath.Value")
               .append("@FitHeightmap", "#FitHeightmap #CheckBox.Value")
               .append("@InheritSeed", "#InheritSeed #CheckBox.Value")
               .append("@InheritHeightCondition", "#InheritHeightCondition #CheckBox.Value")
               .append("@DefaultWeight", "#DefaultWeight.Value")
               .append("@PrefabWeights", "#PrefabWeights.Value")
         );
      }

      class="kw">public void handleDataEvent(
         @Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull PrefabSpawnerBlock.PrefabSpawnerSettingsPageEventData var3
      ) {
         this.state.prefabPath = var3.prefabPath;
         this.state.fitHeightmap = var3.fitHeightmap;
         this.state.inheritSeed = var3.inheritSeed;
         this.state.inheritHeightCondition = var3.inheritHeightCondition;
         this.state.prefabWeights = PrefabWeights.parse(var3.prefabWeights);
         this.state.prefabWeights.setDefaultWeight(var3.defaultWeight);
         this.info.markNeedsSaving();
         Player var4 = var2.getComponent(var1, Player.getComponentType());
         var4.getPageManager().setPage(var1, var2, Page.None);
      }
   }

   class="kw">public class="kw">static class PrefabSpawnerSettingsPageEventData {
      class="kw">public class="kw">static class="kw">final String KEY_PREFAB_PATH = "@PrefabPath";
      class="kw">public class="kw">static class="kw">final String KEY_FIT_HEIGHTMAP = "@FitHeightmap";
      class="kw">public class="kw">static class="kw">final String KEY_INHERIT_SEED = "@InheritSeed";
      class="kw">public class="kw">static class="kw">final String KEY_INHERIT_HEIGHT_CONDITION = "@InheritHeightCondition";
      class="kw">public class="kw">static class="kw">final String KEY_DEFAULT_WEIGHT = "@DefaultWeight";
      class="kw">public class="kw">static class="kw">final String KEY_PREFAB_WEIGHTS = "@PrefabWeights";
      class="kw">public class="kw">static class="kw">final BuilderCodec<PrefabSpawnerBlock.PrefabSpawnerSettingsPageEventData> CODEC = BuilderCodec.builder(
            PrefabSpawnerBlock.PrefabSpawnerSettingsPageEventData.class, PrefabSpawnerBlock.PrefabSpawnerSettingsPageEventData::new
         )
         .append(new KeyedCodec<>("@PrefabPath", Codec.STRING), (var0, var1) -> var0.prefabPath = var1, var0 -> var0.prefabPath)
         .add()
         .append(new KeyedCodec<>("@FitHeightmap", Codec.BOOLEAN), (var0, var1) -> var0.fitHeightmap = var1, var0 -> var0.fitHeightmap)
         .add()
         .append(new KeyedCodec<>("@InheritSeed", Codec.BOOLEAN), (var0, var1) -> var0.inheritSeed = var1, var0 -> var0.inheritSeed)
         .add()
         .append(
            new KeyedCodec<>("@InheritHeightCondition", Codec.BOOLEAN), (var0, var1) -> var0.inheritHeightCondition = var1, var0 -> var0.inheritHeightCondition
         )
         .add()
         .<Double>append(new KeyedCodec<>("@DefaultWeight", Codec.DOUBLE), (var0, var1) -> var0.defaultWeight = var1, var0 -> var0.defaultWeight)
         .addValidator(Validators.greaterThanOrEqual(0.0))
         .add()
         .append(new KeyedCodec<>("@PrefabWeights", Codec.STRING), (var0, var1) -> var0.prefabWeights = var1, var0 -> var0.prefabWeights)
         .add()
         .build();
      class="kw">private String prefabPath;
      class="kw">private boolean fitHeightmap;
      class="kw">private boolean inheritSeed;
      class="kw">private boolean inheritHeightCondition;
      class="kw">private double defaultWeight;
      class="kw">private String prefabWeights;

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