mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-23 08:38:51 +00:00
refactor createBlockState to use new error API
This commit is contained in:
@@ -10,6 +10,10 @@ package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
import com.dfsek.seismic.math.floatingpoint.FloatingPointFunctions;
|
||||
import com.dfsek.seismic.type.vector.Vector2;
|
||||
import com.dfsek.seismic.type.vector.Vector3;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -85,7 +89,11 @@ public class BlockFunction implements Function<Void> {
|
||||
}
|
||||
|
||||
protected BlockState getBlockState(ImplementationArguments arguments, Scope scope) {
|
||||
return data.computeIfAbsent(blockData.apply(arguments, scope), platform.getWorldHandle()::createBlockState);
|
||||
WorldHandle handle = platform.getWorldHandle();
|
||||
return data.computeIfAbsent(blockData.apply(arguments, scope), s -> handle.createBlockState(s).collect(left -> {
|
||||
logger.error("Invalid block state \"" + s + "\": " + left.message());
|
||||
return handle.air();
|
||||
}, java.util.function.Function.identity()));
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +103,8 @@ public class BlockFunction implements Function<Void> {
|
||||
public Constant(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, StringConstant blockData,
|
||||
Returnable<Boolean> overwrite, Returnable<Boolean> physics, Platform platform, Position position) {
|
||||
super(x, y, z, blockData, overwrite, physics, platform, position);
|
||||
this.state = platform.getWorldHandle().createBlockState(blockData.getConstant());
|
||||
this.state = platform.getWorldHandle().createBlockState(blockData.getConstant()).collectThrow(
|
||||
left -> new ParseException("Invalid block state: \"" + blockData.getConstant() + "\": " + left.message(), position));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,7 +33,9 @@ public class PullFunction implements Function<Void> {
|
||||
this.position = position;
|
||||
if(!(data instanceof ConstantExpression)) throw new ParseException("Block data must be constant", data.getPosition());
|
||||
|
||||
this.data = platform.getWorldHandle().createBlockState(((ConstantExpression<String>) data).getConstant());
|
||||
String constant = ((ConstantExpression<String>) data).getConstant();
|
||||
this.data = platform.getWorldHandle().createBlockState(constant).collectThrow(
|
||||
left -> new ParseException("Invalid block state: \"" + constant + "\": " + left.message(), position));
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
Reference in New Issue
Block a user