package com.hypixel.hytale.builtin.hytalegenerator.assets.materialproviders;
import com.hypixel.hytale.builtin.hytalegenerator.framework.interfaces.functions.BiDouble2DoubleFunction;
import com.hypixel.hytale.builtin.hytalegenerator.material.Material;
import com.hypixel.hytale.builtin.hytalegenerator.materialproviders.HorizontalMaterialProvider;
import com.hypixel.hytale.builtin.hytalegenerator.materialproviders.MaterialProvider;
import com.hypixel.hytale.builtin.hytalegenerator.materialproviders.functions.DoubleFunctionXZ;
import com.hypixel.hytale.builtin.hytalegenerator.referencebundle.BaseHeightReference;
import com.hypixel.hytale.codec.Codec;
import com.hypixel.hytale.codec.KeyedCodec;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import com.hypixel.hytale.logger.HytaleLogger;
import java.util.Objects;
import javax.annotation.Nonnull;
public class SimpleHorizontalMaterialProviderAsset extends MaterialProviderAsset {
public static final BuilderCodec<SimpleHorizontalMaterialProviderAsset> CODEC;
private int topY = 0;
private int bottomY = 0;
private MaterialProviderAsset materialProviderAsset = new ConstantMaterialProviderAsset();
private String topBaseHeightName = "";
private String bottomBaseHeightName = "";
public SimpleHorizontalMaterialProviderAsset() {
}
@Nonnull
public MaterialProvider<Material> build(@Nonnull MaterialProviderAsset.Argument argument) {
if (super.skip()) {
return MaterialProvider.<Material>noMaterialProvider();
} else {
BiDouble2DoubleFunction topFunction = (x, z) -> (double)this.topY;
BiDouble2DoubleFunction bottomFunction = (x, z) -> (double)this.bottomY;
if (!this.topBaseHeightName.isEmpty()) {
BaseHeightReference topHeightDataLayer = (BaseHeightReference)argument.referenceBundle.getLayerWithName(this.topBaseHeightName, BaseHeightReference.class);
if (topHeightDataLayer != null) {
BiDouble2DoubleFunction baseHeight = topHeightDataLayer.getHeightFunction();
topFunction = (x, z) -> baseHeight.apply(x, z) + (double)this.topY;
} else {
((HytaleLogger.Api)HytaleLogger.getLogger().atConfig()).log("Couldn't find height data layer with name \"" + this.topBaseHeightName + "\", using a zero-constant Density node.");
}
}
if (!this.bottomBaseHeightName.isEmpty()) {
BaseHeightReference bottomHeightDataLayer = (BaseHeightReference)argument.referenceBundle.getLayerWithName(this.bottomBaseHeightName, BaseHeightReference.class);
if (bottomHeightDataLayer != null) {
BiDouble2DoubleFunction baseHeight = bottomHeightDataLayer.getHeightFunction();
bottomFunction = (x, z) -> baseHeight.apply(x, z) + (double)this.bottomY;
} else {
((HytaleLogger.Api)HytaleLogger.getLogger().atConfig()).log("Couldn't find height data layer with name \"" + this.bottomBaseHeightName + "\", using a zero-constant Density node.");
}
}
MaterialProvider var10002 = this.materialProviderAsset.build(argument);
Objects.requireNonNull(topFunction);
DoubleFunctionXZ var10003 = topFunction::apply;
Objects.requireNonNull(bottomFunction);
return new HorizontalMaterialProvider<Material>(var10002, var10003, bottomFunction::apply);
}
}
public void cleanUp() {
this.materialProviderAsset.cleanUp();
}
static {
CODEC = ((BuilderCodec.Builder)((BuilderCodec.Builder)((BuilderCodec.Builder)((BuilderCodec.Builder)((BuilderCodec.Builder)BuilderCodec.builder(SimpleHorizontalMaterialProviderAsset.class, SimpleHorizontalMaterialProviderAsset::new, MaterialProviderAsset.ABSTRACT_CODEC).append(new KeyedCodec("TopY", Codec.INTEGER, true), (t, k) -> t.topY = k, (k) -> k.topY).add()).append(new KeyedCodec("BottomY", Codec.INTEGER, true), (t, k) -> t.bottomY = k, (k) -> k.bottomY).add()).append(new KeyedCodec("Material", MaterialProviderAsset.CODEC, true), (t, k) -> t.materialProviderAsset = k, (k) -> k.materialProviderAsset).add()).append(new KeyedCodec("TopBaseHeight", Codec.STRING, false), (t, k) -> t.topBaseHeightName = k, (t) -> t.topBaseHeightName).add()).append(new KeyedCodec("BottomBaseHeight", Codec.STRING, false), (t, k) -> t.bottomBaseHeightName = k, (t) -> t.bottomBaseHeightName).add()).build();
}
}