mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-10 17:56:03 +00:00
Change Java whitespace handling in .editorconfig (#425)
* Change whitespace handling in .editorconfig * Reformat code * fix format error * Reformat code --------- Co-authored-by: Zoë Gidiere <duplexsys@protonmail.com>
This commit is contained in:
@@ -12,11 +12,11 @@ import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
public class ConstantSamplerFunction implements Function<Number> {
|
||||
private final Returnable<Number> x, y, z;
|
||||
private final NoiseSampler sampler;
|
||||
|
||||
|
||||
|
||||
|
||||
private final boolean twoD;
|
||||
private final Position position;
|
||||
|
||||
|
||||
public ConstantSamplerFunction(NoiseSampler sampler,
|
||||
Returnable<Number> x,
|
||||
Returnable<Number> y,
|
||||
@@ -30,14 +30,14 @@ public class ConstantSamplerFunction implements Function<Number> {
|
||||
this.twoD = twoD;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Number apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
double x = this.x.apply(implementationArguments, scope).doubleValue();
|
||||
|
||||
|
||||
double z = this.z.apply(implementationArguments, scope).doubleValue();
|
||||
|
||||
|
||||
if(twoD) {
|
||||
return sampler.noise(arguments.getWorld().getSeed(), x, z);
|
||||
} else {
|
||||
@@ -45,12 +45,12 @@ public class ConstantSamplerFunction implements Function<Number> {
|
||||
return sampler.noise(arguments.getWorld().getSeed(), x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
|
||||
@@ -14,12 +14,12 @@ import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
public class SamplerFunction implements Function<Number> {
|
||||
private final Returnable<Number> x, y, z;
|
||||
private final Returnable<String> function;
|
||||
|
||||
|
||||
private final java.util.function.Function<Supplier<String>, NoiseSampler> samplerFunction;
|
||||
|
||||
|
||||
private final boolean twoD;
|
||||
private final Position position;
|
||||
|
||||
|
||||
public SamplerFunction(Returnable<String> function,
|
||||
Returnable<Number> x,
|
||||
Returnable<Number> y,
|
||||
@@ -35,14 +35,14 @@ public class SamplerFunction implements Function<Number> {
|
||||
this.twoD = twoD;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Number apply(ImplementationArguments implementationArguments, Scope scope) {
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
double x = this.x.apply(implementationArguments, scope).doubleValue();
|
||||
|
||||
|
||||
double z = this.z.apply(implementationArguments, scope).doubleValue();
|
||||
|
||||
|
||||
NoiseSampler sampler = samplerFunction.apply(() -> function.apply(implementationArguments, scope));
|
||||
if(twoD) {
|
||||
return sampler.noise(arguments.getWorld().getSeed(), x, z);
|
||||
@@ -51,12 +51,12 @@ public class SamplerFunction implements Function<Number> {
|
||||
return sampler.noise(arguments.getWorld().getSeed(), x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
|
||||
@@ -17,11 +17,11 @@ import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
public class SamplerFunctionBuilder implements FunctionBuilder<com.dfsek.terra.addons.terrascript.parser.lang.functions.Function<Number>> {
|
||||
private final Map<String, DimensionApplicableNoiseSampler> samplers2d;
|
||||
private final Map<String, DimensionApplicableNoiseSampler> samplers3d;
|
||||
|
||||
|
||||
public SamplerFunctionBuilder(Map<String, DimensionApplicableNoiseSampler> samplers) {
|
||||
this.samplers2d = new HashMap<>();
|
||||
this.samplers3d = new HashMap<>();
|
||||
|
||||
|
||||
samplers.forEach((id, sampler) -> {
|
||||
if(sampler.getDimensions() == 2) {
|
||||
samplers2d.put(id, sampler);
|
||||
@@ -30,62 +30,62 @@ public class SamplerFunctionBuilder implements FunctionBuilder<com.dfsek.terra.a
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public com.dfsek.terra.addons.terrascript.parser.lang.functions.Function<Number> build(List<Returnable<?>> argumentList,
|
||||
Position position) {
|
||||
Returnable<String> arg = (Returnable<String>) argumentList.get(0);
|
||||
|
||||
|
||||
if(argumentList.size() == 3) { // 2D
|
||||
if(arg instanceof StringConstant constant) {
|
||||
return new ConstantSamplerFunction(Objects.requireNonNull(samplers2d.get(constant.getConstant()),
|
||||
"No such 2D noise function " + constant.getConstant())
|
||||
.getSampler(),
|
||||
(Returnable<Number>) argumentList.get(1),
|
||||
new NumericConstant(0, position),
|
||||
(Returnable<Number>) argumentList.get(2),
|
||||
true,
|
||||
position);
|
||||
"No such 2D noise function " + constant.getConstant())
|
||||
.getSampler(),
|
||||
(Returnable<Number>) argumentList.get(1),
|
||||
new NumericConstant(0, position),
|
||||
(Returnable<Number>) argumentList.get(2),
|
||||
true,
|
||||
position);
|
||||
} else {
|
||||
return new SamplerFunction((Returnable<String>) argumentList.get(0),
|
||||
(Returnable<Number>) argumentList.get(1),
|
||||
new NumericConstant(0, position),
|
||||
(Returnable<Number>) argumentList.get(2),
|
||||
s -> Objects.requireNonNull(samplers2d.get(s.get()), "No such 2D noise function " + s.get())
|
||||
.getSampler(),
|
||||
true,
|
||||
position);
|
||||
(Returnable<Number>) argumentList.get(1),
|
||||
new NumericConstant(0, position),
|
||||
(Returnable<Number>) argumentList.get(2),
|
||||
s -> Objects.requireNonNull(samplers2d.get(s.get()), "No such 2D noise function " + s.get())
|
||||
.getSampler(),
|
||||
true,
|
||||
position);
|
||||
}
|
||||
|
||||
|
||||
} else { // 3D
|
||||
if(arg instanceof StringConstant constant) {
|
||||
return new ConstantSamplerFunction(Objects.requireNonNull(samplers3d.get(constant.getConstant()),
|
||||
"No such 3D noise function " + constant.getConstant())
|
||||
.getSampler(),
|
||||
(Returnable<Number>) argumentList.get(1),
|
||||
(Returnable<Number>) argumentList.get(2),
|
||||
(Returnable<Number>) argumentList.get(3),
|
||||
true,
|
||||
position);
|
||||
"No such 3D noise function " + constant.getConstant())
|
||||
.getSampler(),
|
||||
(Returnable<Number>) argumentList.get(1),
|
||||
(Returnable<Number>) argumentList.get(2),
|
||||
(Returnable<Number>) argumentList.get(3),
|
||||
true,
|
||||
position);
|
||||
} else {
|
||||
return new SamplerFunction((Returnable<String>) argumentList.get(0),
|
||||
(Returnable<Number>) argumentList.get(1),
|
||||
(Returnable<Number>) argumentList.get(2),
|
||||
(Returnable<Number>) argumentList.get(3),
|
||||
s -> Objects.requireNonNull(samplers3d.get(s.get()), "No such 3D noise function " + s.get())
|
||||
.getSampler(),
|
||||
true,
|
||||
position);
|
||||
(Returnable<Number>) argumentList.get(1),
|
||||
(Returnable<Number>) argumentList.get(2),
|
||||
(Returnable<Number>) argumentList.get(3),
|
||||
s -> Objects.requireNonNull(samplers3d.get(s.get()), "No such 3D noise function " + s.get())
|
||||
.getSampler(),
|
||||
true,
|
||||
position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int argNumber() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ReturnType getArgument(int position) {
|
||||
return switch(position) {
|
||||
|
||||
@@ -13,22 +13,22 @@ import com.dfsek.terra.api.inject.annotations.Inject;
|
||||
public class TerraScriptSamplerFunctionAddon implements AddonInitializer {
|
||||
@Inject
|
||||
private Platform platform;
|
||||
|
||||
|
||||
@Inject
|
||||
private BaseAddon addon;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
platform.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(addon, ConfigPackPreLoadEvent.class)
|
||||
.priority(51)
|
||||
.then(event -> event
|
||||
.getPack()
|
||||
.getOrCreateRegistry(FunctionBuilder.class)
|
||||
.register(addon.key("sampler"), new SamplerFunctionBuilder(event.getPack().getContext().get(
|
||||
NoiseConfigPackTemplate.class).getSamplers())))
|
||||
.failThrough();
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(addon, ConfigPackPreLoadEvent.class)
|
||||
.priority(51)
|
||||
.then(event -> event
|
||||
.getPack()
|
||||
.getOrCreateRegistry(FunctionBuilder.class)
|
||||
.register(addon.key("sampler"), new SamplerFunctionBuilder(event.getPack().getContext().get(
|
||||
NoiseConfigPackTemplate.class).getSamplers())))
|
||||
.failThrough();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user