mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-11 18:26:08 +00:00
make registry return optional for get operations
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -26,9 +28,6 @@ import com.dfsek.terra.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class LootFunction implements Function<Void> {
|
||||
private final Registry<LootTable> registry;
|
||||
@@ -61,16 +60,12 @@ public class LootFunction implements Function<Void> {
|
||||
RotationUtil.rotateVector(xz, arguments.getRotation());
|
||||
|
||||
String id = data.apply(implementationArguments, variableMap);
|
||||
LootTable table = registry.get(id);
|
||||
|
||||
if(table == null) {
|
||||
LOGGER.error("No such loot table {}", id);
|
||||
return null;
|
||||
}
|
||||
|
||||
arguments.getBuffer().addItem(new BufferedLootApplication(table, platform, script),
|
||||
new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).intValue(),
|
||||
FastMath.roundToInt(xz.getZ())));
|
||||
registry.get(id).ifPresentOrElse(table -> arguments.getBuffer().addItem(new BufferedLootApplication(table, platform, script),
|
||||
new Vector3(FastMath.roundToInt(xz.getX()),
|
||||
y.apply(implementationArguments, variableMap)
|
||||
.intValue(),
|
||||
FastMath.roundToInt(xz.getZ()))),
|
||||
() -> LOGGER.error("No such loot table {}", id));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,26 +70,25 @@ public class StructureFunction implements Function<Boolean> {
|
||||
RotationUtil.rotateVector(xz, arguments.getRotation());
|
||||
|
||||
String app = id.apply(implementationArguments, variableMap);
|
||||
Structure script = registry.get(app);
|
||||
if(script == null) {
|
||||
LOGGER.warn("No such structure {}", app);
|
||||
return null;
|
||||
}
|
||||
|
||||
Rotation rotation1;
|
||||
String rotString = rotations.get(arguments.getRandom().nextInt(rotations.size())).apply(implementationArguments, variableMap);
|
||||
try {
|
||||
rotation1 = Rotation.valueOf(rotString);
|
||||
} catch(IllegalArgumentException e) {
|
||||
LOGGER.warn("Invalid rotation {}", rotString);
|
||||
return null;
|
||||
}
|
||||
|
||||
Vector3 offset = new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).doubleValue(),
|
||||
FastMath.roundToInt(xz.getZ()));
|
||||
|
||||
return script.generate(new IntermediateBuffer(arguments.getBuffer(), offset), arguments.getWorld(), arguments.getRandom(),
|
||||
arguments.getRotation().rotate(rotation1), arguments.getRecursions() + 1);
|
||||
return registry.get(app).map(script -> {
|
||||
Rotation rotation1;
|
||||
String rotString = rotations.get(arguments.getRandom().nextInt(rotations.size())).apply(implementationArguments, variableMap);
|
||||
try {
|
||||
rotation1 = Rotation.valueOf(rotString);
|
||||
} catch(IllegalArgumentException e) {
|
||||
LOGGER.warn("Invalid rotation {}", rotString);
|
||||
return null;
|
||||
}
|
||||
|
||||
Vector3 offset = new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).doubleValue(),
|
||||
FastMath.roundToInt(xz.getZ()));
|
||||
|
||||
return script.generate(new IntermediateBuffer(arguments.getBuffer(), offset), arguments.getWorld(), arguments.getRandom(),
|
||||
arguments.getRotation().rotate(rotation1), arguments.getRecursions() + 1);
|
||||
}).orElseGet(() -> {
|
||||
LOGGER.error("No such structure {}", app);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user