Scripting engine

This commit is contained in:
Daniel Mills
2021-08-07 23:11:09 -04:00
parent 897669a069
commit 8e032fa26a
70 changed files with 470 additions and 9450 deletions

View File

@@ -19,11 +19,22 @@
package com.volmit.iris.engine.scripting;
import com.volmit.iris.engine.framework.Engine;
import org.apache.bsf.BSFManager;
public interface EngineExecutionEnvironment
{
Engine getEngine();
BSFManager getManager();
void execute(String script);
Object evaluate(String script);
void execute(String script, double x, double y, double z);
Object evaluate(String script, double x, double y, double z);
default void close()
{

View File

@@ -0,0 +1,104 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.scripting;
import com.volmit.iris.Iris;
import com.volmit.iris.core.project.loader.IrisData;
import com.volmit.iris.engine.IrisComplex;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.framework.EngineFramework;
import com.volmit.iris.engine.object.biome.IrisBiome;
import com.volmit.iris.engine.object.dimensional.IrisDimension;
import com.volmit.iris.engine.object.noise.IrisExpression;
import lombok.Data;
@Data
public class IrisScriptingAPI {
private final Engine engine;
private double x = 0;
private double y = 0;
private double z = 0;
public IrisScriptingAPI(Engine engine)
{
this.engine = engine;
}
public IrisData getData()
{
return getEngine().getData();
}
public EngineFramework getFramework()
{
return getEngine().getFramework();
}
public IrisComplex getComplex()
{
return getFramework().getComplex();
}
public long getSeed()
{
return getEngine().getTarget().getWorld().seed();
}
public double expression(String expressionName, double x, double y, double z)
{
IrisExpression expression = getData().getExpressionLoader().load(expressionName);
return expression.evaluate(getComplex().getRng(), x, y, z);
}
public double expression(String expressionName, double x, double z)
{
IrisExpression expression = getData().getExpressionLoader().load(expressionName);
return expression.evaluate(getComplex().getRng(), x, z);
}
public IrisBiome getBiomeAt(int x, int z)
{
return getEngine().getSurfaceBiome(x, z);
}
public IrisDimension getDimension()
{
return getEngine().getDimension();
}
public void info(String log)
{
Iris.info(log);
}
public void debug(String log)
{
Iris.debug(log);
}
public void warn(String log)
{
Iris.warn(log);
}
public void error(String log)
{
Iris.error(log);
}
}