use of com.demod.fbsr.BlueprintEntity in project Factorio-FBSR by demodude4u.
the class BlueprintBotDiscordService method handleBlueprintUpgradeBeltsCommand.
private void handleBlueprintUpgradeBeltsCommand(SlashCommandEvent event) {
String content = event.getCommandString();
Optional<Attachment> attachment = event.optParamAttachment("file");
if (attachment.isPresent()) {
content += " " + attachment.get().getUrl();
}
List<BlueprintStringData> blueprintStringDatas = BlueprintFinder.search(content, event.getReporting());
int upgradedCount = 0;
for (BlueprintStringData blueprintStringData : blueprintStringDatas) {
for (Blueprint blueprint : blueprintStringData.getBlueprints()) {
for (BlueprintEntity blueprintEntity : blueprint.getEntities()) {
String upgradeName = upgradeBeltsEntityMapping.get(blueprintEntity.getName());
if (upgradeName != null) {
blueprintEntity.json().put("name", upgradeName);
upgradedCount++;
}
}
}
}
if (upgradedCount > 0) {
for (BlueprintStringData blueprintStringData : blueprintStringDatas) {
try {
event.replyFile(BlueprintStringData.encode(blueprintStringData.json()).getBytes(), "blueprint.txt");
} catch (IOException e) {
event.getReporting().addException(e);
}
}
event.reply("Upgraded " + upgradedCount + " entities.");
} else if (blueprintStringDatas.stream().anyMatch(d -> !d.getBlueprints().isEmpty())) {
event.replyIfNoException("I couldn't find anything to upgrade!");
} else {
event.replyIfNoException("No blueprint found!");
}
}
use of com.demod.fbsr.BlueprintEntity in project Factorio-FBSR by demodude4u.
the class AssemblingMachineRendering method populateWorldMap.
@Override
public void populateWorldMap(WorldMap map, DataTable dataTable, BlueprintEntity entity, EntityPrototype prototype) {
String recipeName = entity.json().optString("recipe", null);
boolean hasFluid = false;
if (recipeName != null) {
Optional<RecipePrototype> optRecipe = dataTable.getRecipe(recipeName);
if (optRecipe.isPresent()) {
RecipePrototype protoRecipe = optRecipe.get();
List<LuaValue> items = new ArrayList<>();
Utils.forEach(protoRecipe.lua().get("ingredients"), (Consumer<LuaValue>) items::add);
LuaValue resultsLua = protoRecipe.lua().get("results");
if (resultsLua != LuaValue.NIL) {
items.add(resultsLua);
}
hasFluid = items.stream().anyMatch(lua -> {
LuaValue typeLua = lua.get("type");
return typeLua != LuaValue.NIL && typeLua.toString().equals("fluid");
});
}
}
LuaValue fluidBoxesLua = prototype.lua().get("fluid_boxes");
boolean offWhenNoFluidRecipe = fluidBoxesLua.isnil() ? true : fluidBoxesLua.get("off_when_no_fluid_recipe").optboolean(false);
if (!fluidBoxesLua.isnil() && (!offWhenNoFluidRecipe || hasFluid)) {
Utils.forEach(fluidBoxesLua, fluidBoxLua -> {
if (!fluidBoxLua.istable()) {
return;
}
Utils.forEach(fluidBoxLua.get("pipe_connections"), pipeConnectionLua -> {
Point2D.Double offset = Utils.parsePoint2D(pipeConnectionLua.get("position"));
if (Math.abs(offset.y) > Math.abs(offset.x)) {
offset.y += -Math.signum(offset.y);
} else {
offset.x += -Math.signum(offset.x);
}
Point2D.Double pos = entity.getDirection().left().offset(entity.getDirection().back().offset(entity.getPosition(), offset.y), offset.x);
Direction direction = offset.y > 0 ? entity.getDirection().back() : entity.getDirection();
map.setPipe(pos, direction);
});
});
}
}
Aggregations