use of java.util.function.Function in project ImmersiveEngineering by BluSunrize.
the class ClientUtils method createBakedBox.
public static Set<BakedQuad> createBakedBox(Vector3f from, Vector3f to, Matrix4 matrix, EnumFacing facing, Function<Vector3f[], Vector3f[]> vertexTransformer, Function<EnumFacing, TextureAtlasSprite> textureGetter, float[] colour) {
HashSet quads = new HashSet();
if (vertexTransformer == null)
vertexTransformer = v -> v;
Vector3f[] vertices = { new Vector3f(from.x, from.y, from.z), new Vector3f(from.x, from.y, to.z), new Vector3f(to.x, from.y, to.z), new Vector3f(to.x, from.y, from.z) };
TextureAtlasSprite sprite = textureGetter.apply(EnumFacing.DOWN);
if (sprite != null)
quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.DOWN, facing), sprite, new double[] { from.x * 16, 16 - from.z * 16, to.x * 16, 16 - to.z * 16 }, colour, true));
for (Vector3f v : vertices) v.setY(to.y);
sprite = textureGetter.apply(EnumFacing.UP);
if (sprite != null)
quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.UP, facing), sprite, new double[] { from.x * 16, from.z * 16, to.x * 16, to.z * 16 }, colour, false));
vertices = new Vector3f[] { new Vector3f(to.x, to.y, from.z), new Vector3f(to.x, from.y, from.z), new Vector3f(from.x, from.y, from.z), new Vector3f(from.x, to.y, from.z) };
sprite = textureGetter.apply(EnumFacing.NORTH);
if (sprite != null)
quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.NORTH, facing), sprite, new double[] { from.x * 16, 16 - to.y * 16, to.x * 16, 16 - from.y * 16 }, colour, false));
for (Vector3f v : vertices) v.setZ(to.z);
sprite = textureGetter.apply(EnumFacing.SOUTH);
if (sprite != null)
quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.SOUTH, facing), sprite, new double[] { to.x * 16, 16 - to.y * 16, from.x * 16, 16 - from.y * 16 }, colour, true));
vertices = new Vector3f[] { new Vector3f(from.x, to.y, to.z), new Vector3f(from.x, from.y, to.z), new Vector3f(from.x, from.y, from.z), new Vector3f(from.x, to.y, from.z) };
sprite = textureGetter.apply(EnumFacing.WEST);
if (sprite != null)
quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.WEST, facing), sprite, new double[] { to.z * 16, 16 - to.y * 16, from.z * 16, 16 - from.y * 16 }, colour, true));
for (Vector3f v : vertices) v.setX(to.x);
sprite = textureGetter.apply(EnumFacing.EAST);
if (sprite != null)
quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.EAST, facing), sprite, new double[] { from.z * 16, 16 - to.y * 16, to.z * 16, 16 - from.y * 16 }, colour, false));
return quads;
}
use of java.util.function.Function in project opennms by OpenNMS.
the class LayoutManager method isPersistedLayoutEqualToCurrentLayout.
public boolean isPersistedLayoutEqualToCurrentLayout(Graph graph) {
LayoutEntity layoutEntity = loadLayout(graph);
if (layoutEntity != null) {
// If we have a layout persisted, we verify if it is equal.
final Map<VertexRef, Point> persistedLocations = layoutEntity.getVertexPositions().stream().collect(Collectors.toMap((Function<VertexPositionEntity, VertexRef>) vertexPositionEntity -> {
VertexRefEntity vertexRefEntity = vertexPositionEntity.getVertexRef();
return new DefaultVertexRef(vertexRefEntity.getNamespace(), vertexRefEntity.getId());
}, vertexPositionEntity -> {
PointEntity position = vertexPositionEntity.getPosition();
return new Point(position.getX(), position.getY());
}));
// The locations may contain elements currently not visible, we filter them
final Map<VertexRef, Point> manualLocations = new HashMap<>();
graph.getLayout().getLocations().forEach((key, value) -> {
if (persistedLocations.containsKey(key)) {
// layoutEntity stores int coordinates, but manualLocations are stored as double.
// Convert to int to make it comparable.
manualLocations.put(key, new Point((int) value.getX(), (int) value.getY()));
}
});
final boolean layoutIsEqual = manualLocations.equals(persistedLocations);
return layoutIsEqual;
}
// We don't have anything persisted, so they are not equal
return false;
}
use of java.util.function.Function in project POL-POM-5 by PlayOnLinux.
the class NashornEngineFactory method createEngine.
NashornEngine createEngine() {
final Set<List<String>> includedScripts = new HashSet<>();
final NashornEngine nashornEngine = new NashornEngine(new ScriptEngineManager().getEngineByName("nashorn"));
nashornEngine.eval(new InputStreamReader(getClass().getResourceAsStream("utils.js")), this::throwException);
nashornEngine.put("Bean", (Function<String, Object>) title -> applicationContext.getBean(title), this::throwException);
nashornEngine.put("SetupWizard", (Function<String, UiSetupWizardImplementation>) (name) -> {
final UiSetupWizardImplementation uiSetupWizardImplementation = uiSetupWizardFactory.create(name);
nashornEngine.addErrorHandler(e -> uiSetupWizardImplementation.close());
return uiSetupWizardImplementation;
}, this::throwException);
nashornEngine.put("EngineProgressUi", (Function<String, UiProgressWizardImplementation>) (name) -> {
final UiProgressWizardImplementation uiProgressWizardImplementation = uiProgressWizardFactory.create(name);
nashornEngine.addErrorHandler(e -> uiProgressWizardImplementation.close());
return uiProgressWizardImplementation;
}, this::throwException);
nashornEngine.put("include", (Consumer<ScriptObjectMirror>) args -> {
final String[] arguments = args.to(String[].class);
final String script = scriptFetcher.getScript(arguments);
if (script == null) {
throwException(new ScriptException(Arrays.asList(arguments).toString() + " is not found"));
}
if (includedScripts.add(Arrays.asList(arguments))) {
nashornEngine.eval("//# sourceURL=" + Arrays.asList(arguments).toString() + "\n" + script, this::throwException);
}
}, this::throwException);
return nashornEngine;
}
use of java.util.function.Function in project Skree by Skelril.
the class PatientXManager method setupBossManager.
private void setupBossManager() {
Sponge.getEventManager().registerListeners(SkreePlugin.inst(), new BossListener<>(bossManager, Zombie.class));
List<Instruction<BindCondition, Boss<Zombie, ZoneBossDetail<PatientXInstance>>>> bindProcessor = bossManager.getBindProcessor();
bindProcessor.add((condition, boss) -> {
Optional<Zombie> optBossEnt = boss.getTargetEntity();
if (optBossEnt.isPresent()) {
Zombie bossEnt = optBossEnt.get();
bossEnt.offer(Keys.DISPLAY_NAME, Text.of("Patient X"));
setMaxHealth(bossEnt, config.bossHealth, true);
}
return Optional.empty();
});
bindProcessor.add((condition, boss) -> {
Optional<Zombie> optBoss = boss.getTargetEntity();
if (optBoss.isPresent()) {
optBoss.get().offer(Keys.PERSISTS, true);
}
return Optional.empty();
});
bindProcessor.add((condition, boss) -> {
boss.getDetail().getZone().getPlayerMessageChannel(PlayerClassifier.SPECTATOR).send(Text.of(TextColors.GOLD, "Ice to meet you again!"));
return Optional.empty();
});
List<Instruction<UnbindCondition, Boss<Zombie, ZoneBossDetail<PatientXInstance>>>> unbindProcessor = bossManager.getUnbindProcessor();
unbindProcessor.add((condition, boss) -> {
PatientXInstance inst = boss.getDetail().getZone();
Location<World> target = inst.getCenter();
for (Player player : inst.getPlayers(PlayerClassifier.PARTICIPANT)) {
player.setLocation(target);
boolean useX = Probability.getChance(2);
int accel = Probability.getChance(2) ? 1 : -1;
Vector3d v = new Vector3d(useX ? accel : 0, 0, !useX ? accel : 0);
player.setVelocity(v);
}
inst.freezeBlocks(100, false);
// Reset respawn mechanics
inst.bossDied();
return Optional.empty();
});
List<Instruction<DamageCondition, Boss<Zombie, ZoneBossDetail<PatientXInstance>>>> damageProcessor = bossManager.getDamageProcessor();
damageProcessor.add((condition, boss) -> {
PatientXInstance inst = boss.getDetail().getZone();
DamageEntityEvent event = condition.getEvent();
// Nullify all modifiers
for (Tuple<DamageModifier, Function<? super Double, Double>> modifier : event.getModifiers()) {
event.setDamage(modifier.getFirst(), (a) -> a);
}
event.setBaseDamage(inst.getDifficulty() * config.baseBossHit);
return Optional.empty();
});
List<Instruction<DamagedCondition, Boss<Zombie, ZoneBossDetail<PatientXInstance>>>> damagedProcessor = bossManager.getDamagedProcessor();
damagedProcessor.add((condition, boss) -> {
DamageEntityEvent event = condition.getEvent();
Optional<DamageSource> optDamageSource = condition.getDamageSource();
if (optDamageSource.isPresent() && blockedDamage.contains(optDamageSource.get().getType())) {
event.setCancelled(true);
return Optional.empty();
}
return Optional.of((damagedCondition, zombieZoneBossDetailBoss) -> {
PatientXInstance inst = boss.getDetail().getZone();
if (optDamageSource.isPresent() && optDamageSource.get() instanceof EntityDamageSource) {
if (optDamageSource.get() instanceof IndirectEntityDamageSource) {
Task.builder().execute(() -> {
VelocityEntitySpawner.sendRadial(EntityTypes.SNOWBALL, inst.getBoss().get(), Cause.source(SpawnCause.builder().type(SpawnTypes.PROJECTILE).build()).build());
}).delayTicks(1).submit(SkreePlugin.inst());
} else {
Entity srcEntity = ((EntityDamageSource) optDamageSource.get()).getSource();
if (srcEntity instanceof Player) {
Optional<ItemStack> optHeld = ((Player) srcEntity).getItemInHand(HandTypes.MAIN_HAND);
if (optHeld.isPresent() && optHeld.get().getItem() == ItemTypes.BLAZE_ROD) {
inst.modifyDifficulty(2);
}
}
}
}
inst.modifyDifficulty(.5);
inst.teleportRandom(true);
return Optional.empty();
});
});
}
use of java.util.function.Function in project Skree by Skelril.
the class JarResourceLoader method loadFromResources.
public void loadFromResources(Consumer<Function<String, Path>> execute) {
try {
URI uri = getClass().getResource(baseResourcePathName).toURI();
if (uri.getScheme().equals("jar")) {
try (FileSystem fileSystem = getFileSystem(uri)) {
Function<String, Path> providerFunction = (resourceName) -> {
return fileSystem.getPath(baseResourcePathName + resourceName);
};
execute.accept(providerFunction);
}
} else {
execute.accept(Paths::get);
}
} catch (Exception e) {
System.err.println("Error loading: " + baseResourcePathName);
e.printStackTrace();
}
}
Aggregations