WeightedPrefabMapJsonLoader class
Пакет: com.hypixel.hytale.server.worldgen.loader.prefab
Файл: com/hypixel/hytale/server/worldgen/loader/prefab/WeightedPrefabMapJsonLoader.java
extends: JsonLoader<SeedStringResource, IWeightedMap<WorldGenPrefabSupplier>>
Поля (15)
| Модификаторы | Тип | Имя |
|---|---|---|
|
String |
ERROR_ENTRY_NO_PREFAB |
|
String |
ERROR_ENTRY_WEIGHT_SIZE |
|
String |
ERROR_NO_PREFABS |
final |
String |
prefabsKey |
|
WorldGenPrefabLoader |
var1 |
|
double |
var10 |
|
String |
var16 |
|
WorldGenPrefabSupplier[] |
var17 |
|
WeightedMap.Builder |
var2 |
|
JsonElement |
var3 |
|
JsonArray |
var4 |
|
JsonArray |
var5 |
|
JsonElement |
var7 |
|
String |
var8 |
|
WorldGenPrefabSupplier[] |
var9 |
Методы (7)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException(this.prefabsKey) |
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("Weight array size is different from prefab name array.") |
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("Prefabs are defined but could not find a valid entry!") |
|
|
for for(WorldGenPrefabSupplier var15 : var9) |
|
|
for for(WorldGenPrefabSupplier var21 : var17) |
abstract |
|
for for(int var6 = 0; var6 < var4.size() |
public |
IWeightedMap<WorldGenPrefabSupplier> |
loadIWeightedMap<WorldGenPrefabSupplier> load() |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.worldgen.loader.prefab;
class="kw">import com.google.gson.JsonArray;
class="kw">import com.google.gson.JsonElement;
class="kw">import com.hypixel.hytale.common.map.IWeightedMap;
class="kw">import com.hypixel.hytale.common.map.WeightedMap;
class="kw">import com.hypixel.hytale.procedurallib.json.JsonLoader;
class="kw">import com.hypixel.hytale.procedurallib.json.SeedString;
class="kw">import com.hypixel.hytale.server.worldgen.SeedStringResource;
class="kw">import com.hypixel.hytale.server.worldgen.loader.WorldGenPrefabLoader;
class="kw">import com.hypixel.hytale.server.worldgen.loader.WorldGenPrefabSupplier;
class="kw">import java.nio.file.Path;
class="kw">import javax.annotation.Nonnull;
class="kw">public class WeightedPrefabMapJsonLoader class="kw">extends JsonLoader<SeedStringResource, IWeightedMap<WorldGenPrefabSupplier>> {
class="kw">protected class="kw">final String prefabsKey;
class="kw">protected class="kw">final String weightsKey;
class="kw">public WeightedPrefabMapJsonLoader(@Nonnull SeedString<SeedStringResource> var1, Path var2, JsonElement var3, String var4, String var5) {
super(var1.append(".WeightedPrefabMap"), var2, var3);
this.prefabsKey = var4;
this.weightsKey = var5;
}
class="kw">public IWeightedMap<WorldGenPrefabSupplier> load() {
WorldGenPrefabLoader var1 = this.seed.get().getLoader();
WeightedMap.Builder var2 = WeightedMap.builder(WorldGenPrefabSupplier.EMPTY_ARRAY);
if (!this.has(this.prefabsKey)) {
throw new IllegalArgumentException(this.prefabsKey);
}
JsonElement var3 = this.get(this.prefabsKey);
if (var3.isJsonArray()) {
JsonArray var4 = var3.getAsJsonArray();
JsonArray var5 = this.has(this.weightsKey) ? this.get(this.weightsKey).getAsJsonArray() : null;
if (var5 != null && var4.size() != var5.size()) {
throw new IllegalArgumentException("Weight array size is different from prefab name array.");
}
for (int var6 = 0; var6 < var4.size(); var6++) {
JsonElement var7 = var4.get(var6);
String var8 = var7.getAsString();
WorldGenPrefabSupplier[] var9 = var1.get(var8);
double var10 = var5 != null ? var5.get(var6).getAsDouble() / var9.length : 1.0;
for (WorldGenPrefabSupplier var15 : var9) {
var2.put(var15, var10);
}
}
} else {
String var16 = var3.getAsString();
WorldGenPrefabSupplier[] var17 = var1.get(var16);
for (WorldGenPrefabSupplier var21 : var17) {
var2.put(var21, 1.0);
}
}
if (var2.size() <= 0) {
throw new IllegalArgumentException("Prefabs are defined but could not find a valid entry!");
} else {
class="kw">return var2.build();
}
}
class="kw">public class="kw">interface Constants {
String ERROR_ENTRY_NO_PREFAB = "Could not find prefab names. Keyword: %s";
String ERROR_ENTRY_WEIGHT_SIZE = "Weight array size is different from prefab name array.";
String ERROR_NO_PREFABS = "Prefabs are defined but could not find a valid entry!";
}
}