package com.thebrokenrail.scriptcraft.api.bridge;
import com.thebrokenrail.scriptcraft.core.ScriptCraftCore;
import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.Material;
import net.minecraft.block.MaterialColor;
import java.util.Locale;
class BlockSettingsBridges {
static void register() {
ScriptCraftCore.addBridge("BlockSettings.create", args -> {
try {
String materialID = ((String) args[0]).toUpperCase(Locale.ROOT);
Material material = (Material) Material.class.getField(materialID).get(null);
MaterialColor materialColor;
if (args[1] != null) {
String materialColorID = ((String) args[1]).toUpperCase(Locale.ROOT);
materialColor = (MaterialColor) MaterialColor.class.getField(materialColorID).get(null);
} else {
materialColor = material.getColor();
}
FabricBlockSettings settings = FabricBlockSettings.of(material, materialColor);
settings.hardness(((Double) args[2]).floatValue());
settings.resistance(((Double) args[3]).floatValue());
return settings.build();
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
});