package de.craften.plugins.educraft.luaapi.functions;

import de.craften.plugins.educraft.luaapi.EduCraftApiFunction;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Varargs;

import java.util.Collection;

/**
 * Lua API function to move one block forward.
 */
public class MoveForwardFunction extends EduCraftApiFunction {
    @Override
    public Varargs execute(Varargs varargs) {
        Block blockAhead = getApi().getBlockAhead();
        Location locationAhead = blockAhead.getLocation();
        Collection<Entity> entities = getApi().getEntitiesAhead();

        if (!blockAhead.getType().isSolid()
                && !blockAhead.getRelative(BlockFace.UP).getType().isSolid()
                && getApi().getEnvironment().getSheepAt(locationAhead) == null
                && getApi().getEnvironment().contains(locationAhead)) {
            getApi().moveTo(locationAhead, false);
        }

        return LuaValue.NIL;
    }
}

@@ -209,41 +209,8 @@
 ce;%0A
-import org.bukkit.entity.Entity;%0A
 impo
@@ -269,38 +269,8 @@
 s;%0A%0A
-import java.util.Collection;%0A%0A
 /**%0A
@@ -558,75 +558,8 @@
 n();
-%0A        Collection%3CEntity%3E entities = getApi().getEntitiesAhead();
 %0A%0A  
@@ -890,16 +890,253 @@
      %7D%0A%0A
+        while (!blockAhead.getRelative(BlockFace.DOWN).getType().isSolid() && blockAhead.getY() %3E 0) %7B%0A            blockAhead = blockAhead.getRelative(BlockFace.DOWN);%0A        %7D%0A        getApi().moveTo(blockAhead.getLocation(), false);%0A%0A
         

Make entity fall if there is no solid block below it.