package com.hypixel.hytale.builtin.hytalegenerator.assets.density;
import com.hypixel.hytale.builtin.hytalegenerator.LoggerUtil;
import com.hypixel.hytale.builtin.hytalegenerator.density.Density;
import com.hypixel.hytale.builtin.hytalegenerator.density.nodes.ConstantValueDensity;
import com.hypixel.hytale.codec.Codec;
import com.hypixel.hytale.codec.KeyedCodec;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import javax.annotation.Nonnull;
public class ExportedDensityAsset extends DensityAsset {
public static final BuilderCodec<ExportedDensityAsset> CODEC;
private boolean singleInstance = false;
public ExportedDensityAsset() {
}
@Nonnull
public Density build(@Nonnull DensityAsset.Argument argument) {
if (!this.isSkipped() && this.inputs().length != 0) {
DensityAsset.Exported exported = getExportedAsset(this.exportName);
if (exported == null) {
LoggerUtil.getLogger().severe("Couldn't find Density asset exported with name: '" + this.exportName + "'. This could indicate a defect in the HytaleGenerator assets.");
return this.firstInput().build(argument);
} else if (exported.singleInstance) {
if (exported.builtInstance == null) {
exported.builtInstance = this.firstInput().build(argument);
}
return exported.builtInstance;
} else {
return this.firstInput().build(argument);
}
} else {
return new ConstantValueDensity(0.0);
}
}
public void cleanUp() {
this.cleanUpInputs();
DensityAsset.Exported exported = getExportedAsset(this.exportName);
if (exported != null) {
exported.builtInstance = null;
for(DensityAsset input : this.inputs()) {
input.cleanUp();
}
}
}
public boolean isSingleInstance() {
return this.singleInstance;
}
static {
CODEC = ((BuilderCodec.Builder)BuilderCodec.builder(ExportedDensityAsset.class, ExportedDensityAsset::new, DensityAsset.ABSTRACT_CODEC).append(new KeyedCodec("SingleInstance", Codec.BOOLEAN, false), (asset, value) -> asset.singleInstance = value, (asset) -> asset.singleInstance).add()).build();
}
}