added WIP 'custom_dimension' to the API

This commit is contained in:
gnembon committed 2020-08-17 00:36:01 -03:00
1 parent e2c8b9cc41
commit 598219608b
5 files changed
+152

No files matched your search

@@ -26,6 +26,7 @@ import carpet.script.exception.ExitStatement;
import carpet.script.exception.ExpressionException;
import carpet.script.exception.InternalExpressionException;
import carpet.script.utils.ShapeDispatcher;
import carpet.script.utils.WorldTools;
import carpet.script.value.BlockValue;
import carpet.script.value.EntityValue;
import carpet.script.value.FormattedTextValue;
@@ -1292,6 +1293,33 @@ public class CarpetExpression
return (_c, _t) -> ret;
});
this.expr.addLazyFunction("custom_dimension", -1, (c, t, lv) ->
{
if (lv.size() == 0) throw new InternalExpressionException("'custom_dimension' requires at least one argument");
CarpetContext cc = (CarpetContext)c;
String worldKey = lv.get(0).evalValue(c).getString();
Long seed = null;
if (lv.size() > 1)
{
String seedKey = lv.get(1).evalValue(c).getString();
try
{
seed = Long.parseLong(seedKey);
}
catch (NumberFormatException ignored)
{
throw new InternalExpressionException("Incorrect number format for seed: " + seedKey);
}
}
boolean success = WorldTools.createWorld(cc.s.getMinecraftServer(), worldKey, seed);
if (!success) return LazyValue.FALSE;
CarpetServer.settingsManager.notifyPlayersCommandsChanged();
return LazyValue.TRUE;
});
this.expr.addLazyFunction("reset_chunk", -1, (c, t, lv) ->
{
CarpetContext cc = (CarpetContext)c;