mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-08 16:56:07 +00:00
basic structure implementation
This commit is contained in:
@@ -63,7 +63,6 @@ public class Parser {
|
||||
private Keyword<?> parseKeyword(List<Token> tokens, List<Token> functionAndArguments) throws ParseException {
|
||||
|
||||
Token identifier = functionAndArguments.remove(0);
|
||||
System.out.println("Parsing keyword at " + identifier.getStart());
|
||||
checkType(identifier, Token.Type.IDENTIFIER);
|
||||
if(!keywords.contains(identifier.getContent()))
|
||||
throw new ParseException("No such keyword " + identifier.getContent() + ": " + identifier.getStart());
|
||||
@@ -93,7 +92,7 @@ public class Parser {
|
||||
|
||||
private Expression<?> parseExpression(List<Token> tokens) throws ParseException {
|
||||
if(tokens.get(0).isConstant()) {
|
||||
return new ConstantExpression(tokens.remove(0));
|
||||
return new ConstantExpression(tokens.remove(0).getContent());
|
||||
} else return parseFunction(tokens, false);
|
||||
}
|
||||
|
||||
@@ -103,7 +102,6 @@ public class Parser {
|
||||
|
||||
while(tokens.size() > 0) {
|
||||
Token token = tokens.remove(0);
|
||||
System.out.println(token);
|
||||
if(token.getType().equals(Token.Type.BLOCK_END)) break;
|
||||
functionArgs.add(token);
|
||||
if(token.getType().equals(Token.Type.STATEMENT_END)) {
|
||||
@@ -119,7 +117,6 @@ public class Parser {
|
||||
|
||||
private Function<?> parseFunction(List<Token> functionAndArguments, boolean fullStatement) throws ParseException {
|
||||
Token identifier = functionAndArguments.remove(0);
|
||||
System.out.println("Parsing function at " + identifier.getStart());
|
||||
checkType(identifier, Token.Type.IDENTIFIER); // First token must be identifier
|
||||
|
||||
if(!functions.containsKey(identifier.getContent()))
|
||||
|
||||
@@ -15,6 +15,7 @@ public class ConstantExpression implements Expression<Object> {
|
||||
return constant;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object apply(Location location, Chunk chunk) {
|
||||
return constant;
|
||||
|
||||
@@ -16,6 +16,8 @@ public class EqualsStatement implements Statement {
|
||||
|
||||
@Override
|
||||
public Boolean apply(Location location) {
|
||||
System.out.println(left.apply(location));
|
||||
System.out.println(right.apply(location));
|
||||
return left.apply(location).equals(right.apply(location));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.dfsek.terra.api.structures.script.builders;
|
||||
|
||||
import com.dfsek.terra.api.platform.TerraPlugin;
|
||||
import com.dfsek.terra.api.structures.parser.FunctionBuilder;
|
||||
import com.dfsek.terra.api.structures.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.api.structures.script.functions.BlockFunction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BlockFunctionBuilder implements FunctionBuilder<BlockFunction> {
|
||||
private final TerraPlugin main;
|
||||
|
||||
public BlockFunctionBuilder(TerraPlugin main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockFunction build(List<String> argumentList) throws ParseException {
|
||||
return new BlockFunction(Integer.parseInt(argumentList.get(0)), Integer.parseInt(argumentList.get(1)), Integer.parseInt(argumentList.get(2)), main.getWorldHandle().createBlockData(argumentList.get(3)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArguments() {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.dfsek.terra.api.structures.script.builders;
|
||||
|
||||
import com.dfsek.terra.api.platform.TerraPlugin;
|
||||
import com.dfsek.terra.api.structures.parser.FunctionBuilder;
|
||||
import com.dfsek.terra.api.structures.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.api.structures.script.functions.CheckFunction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SpawnCheckBuilder implements FunctionBuilder<CheckFunction> {
|
||||
private final TerraPlugin main;
|
||||
|
||||
public SpawnCheckBuilder(TerraPlugin main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CheckFunction build(List<String> argumentList) throws ParseException {
|
||||
return new CheckFunction(main, Integer.parseInt(argumentList.get(0)), Integer.parseInt(argumentList.get(1)), Integer.parseInt(argumentList.get(2)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArguments() {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.dfsek.terra.api.structures.script.functions;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.structures.parser.lang.Function;
|
||||
|
||||
public class BlockFunction implements Function<Void> {
|
||||
private final BlockData data;
|
||||
private final int x, y, z;
|
||||
|
||||
public BlockFunction(int x, int y, int z, BlockData data) {
|
||||
this.data = data;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "block";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void apply(Location location) {
|
||||
location.clone().add(x, y, z).getBlock().setBlockData(data, false);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void apply(Location location, Chunk chunk) {
|
||||
//TODO: do
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.dfsek.terra.api.structures.script.functions;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.TerraPlugin;
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.structures.parser.lang.Function;
|
||||
import com.dfsek.terra.api.structures.world.LandCheck;
|
||||
import com.dfsek.terra.api.structures.world.OceanCheck;
|
||||
|
||||
public class CheckFunction implements Function<String> {
|
||||
private final TerraPlugin main;
|
||||
private final int x, y, z;
|
||||
|
||||
public CheckFunction(TerraPlugin main, int x, int y, int z) {
|
||||
this.main = main;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "check";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apply(Location location) {
|
||||
if(new LandCheck(location.getWorld(), main).check(location.getBlockX() + x, location.getBlockY() + y, location.getBlockZ() + z))
|
||||
return "LAND";
|
||||
if(new OceanCheck(location.getWorld(), main).check(location.getBlockX() + x, location.getBlockY() + y, location.getBlockZ() + z))
|
||||
return "OCEAN";
|
||||
return "AIR";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apply(Location location, Chunk chunk) {
|
||||
if(new LandCheck(location.getWorld(), main).check(location.getBlockX() + x, location.getBlockY() + y, location.getBlockZ() + z))
|
||||
return "LAND";
|
||||
if(new OceanCheck(location.getWorld(), main).check(location.getBlockX() + x, location.getBlockY() + y, location.getBlockZ() + z))
|
||||
return "OCEAN";
|
||||
return "AIR";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.dfsek.terra.api.structures.world;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.api.platform.TerraPlugin;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.world.generation.GenerationPhase;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.generation.config.WorldGenerator;
|
||||
|
||||
public class AirCheck extends SpawnCheck {
|
||||
public AirCheck(World world, TerraPlugin main) {
|
||||
super(world, main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(int x, int y, int z) {
|
||||
TerraWorld tw = main.getWorld(world);
|
||||
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||
BiomeTemplate c = b.getConfig();
|
||||
if(y <= c.getSeaLevel()) return false;
|
||||
double elevation = ((WorldGenerator) b.getGenerator()).getElevation(x, z);
|
||||
return b.getGenerator().getNoise(world, x, y, z) + elevation <= 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.dfsek.terra.api.structures.world;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.api.platform.TerraPlugin;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.world.generation.GenerationPhase;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.generation.config.WorldGenerator;
|
||||
|
||||
public class LandCheck extends SpawnCheck {
|
||||
public LandCheck(World world, TerraPlugin main) {
|
||||
super(world, main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(int x, int y, int z) {
|
||||
TerraWorld tw = main.getWorld(world);
|
||||
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||
double elevation = ((WorldGenerator) b.getGenerator()).getElevation(x, z);
|
||||
return b.getGenerator().getNoise(world, x, y, z) + elevation > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.dfsek.terra.api.structures.world;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.api.platform.TerraPlugin;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.world.generation.GenerationPhase;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.generation.config.WorldGenerator;
|
||||
|
||||
public class OceanCheck extends SpawnCheck {
|
||||
public OceanCheck(World world, TerraPlugin main) {
|
||||
super(world, main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(int x, int y, int z) {
|
||||
TerraWorld tw = main.getWorld(world);
|
||||
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
|
||||
BiomeTemplate c = b.getConfig();
|
||||
if(y > c.getSeaLevel()) return false;
|
||||
double elevation = ((WorldGenerator) b.getGenerator()).getElevation(x, z);
|
||||
return b.getGenerator().getNoise(world, x, y, z) + elevation <= 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.dfsek.terra.api.structures.world;
|
||||
|
||||
import com.dfsek.terra.api.platform.TerraPlugin;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
|
||||
public abstract class SpawnCheck {
|
||||
protected final World world;
|
||||
protected final TerraPlugin main;
|
||||
|
||||
protected SpawnCheck(World world, TerraPlugin main) {
|
||||
this.world = world;
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
public abstract boolean check(int x, int y, int z);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user