Search in sources :

Example 51 with Function

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;
}
Also used : net.minecraft.util(net.minecraft.util) Normal(net.minecraftforge.client.model.obj.OBJModel.Normal) ModelBox(net.minecraft.client.model.ModelBox) AttenuationType(net.minecraft.client.audio.ISound.AttenuationType) FluidRegistry(net.minecraftforge.fluids.FluidRegistry) ModelRenderer(net.minecraft.client.model.ModelRenderer) I18n(net.minecraft.client.resources.I18n) Vec3i(net.minecraft.util.math.Vec3i) Vec3d(net.minecraft.util.math.Vec3d) Lib(blusunrize.immersiveengineering.api.Lib) GL11(org.lwjgl.opengl.GL11) IEProperties(blusunrize.immersiveengineering.api.IEProperties) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) Quat4d(javax.vecmath.Quat4d) Vector3f(org.lwjgl.util.vector.Vector3f) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidTank(net.minecraftforge.fluids.IFluidTank) net.minecraft.client.renderer(net.minecraft.client.renderer) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) java.util(java.util) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) SmartLightingQuad(blusunrize.immersiveengineering.client.models.SmartLightingQuad) Function(java.util.function.Function) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) ItemStack(net.minecraft.item.ItemStack) IEFluid(blusunrize.immersiveengineering.common.util.IEFluid) net.minecraft.block(net.minecraft.block) Minecraft(net.minecraft.client.Minecraft) Nonnull(javax.annotation.Nonnull) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Entity(net.minecraft.entity.Entity) Utils(blusunrize.immersiveengineering.common.util.Utils) World(net.minecraft.world.World) TextFormatting(net.minecraft.util.text.TextFormatting) TextureMap(net.minecraft.client.renderer.texture.TextureMap) Timer(net.minecraft.util.Timer) BlockPos(net.minecraft.util.math.BlockPos) TextureManager(net.minecraft.client.renderer.texture.TextureManager) ModelBase(net.minecraft.client.model.ModelBase) IETileSound(blusunrize.immersiveengineering.common.util.sound.IETileSound) IBlockState(net.minecraft.block.state.IBlockState) GuiScreen(net.minecraft.client.gui.GuiScreen) FontRenderer(net.minecraft.client.gui.FontRenderer) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) Material(net.minecraft.block.material.Material) TileEntity(net.minecraft.tileentity.TileEntity) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Vector3f(org.lwjgl.util.vector.Vector3f)

Example 52 with Function

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;
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) Date(java.util.Date) Vertex(org.opennms.features.topology.api.topo.Vertex) HashMap(java.util.HashMap) Hashing(com.google.common.hash.Hashing) Function(java.util.function.Function) VertexPositionEntity(org.opennms.netmgt.topology.persistence.api.VertexPositionEntity) Point(org.opennms.features.topology.api.Point) Layout(org.opennms.features.topology.api.Layout) Map(java.util.Map) LayoutDao(org.opennms.netmgt.topology.persistence.api.LayoutDao) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) Collection(java.util.Collection) Graph(org.opennms.features.topology.api.Graph) Collectors(java.util.stream.Collectors) PointEntity(org.opennms.netmgt.topology.persistence.api.PointEntity) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) TransactionAwareBeanProxyFactory(org.opennms.netmgt.vaadin.core.TransactionAwareBeanProxyFactory) List(java.util.List) VertexRefEntity(org.opennms.netmgt.topology.persistence.api.VertexRefEntity) TransactionOperations(org.springframework.transaction.support.TransactionOperations) LayoutEntity(org.opennms.netmgt.topology.persistence.api.LayoutEntity) Comparator(java.util.Comparator) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Function(java.util.function.Function) VertexRefEntity(org.opennms.netmgt.topology.persistence.api.VertexRefEntity) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) HashMap(java.util.HashMap) LayoutEntity(org.opennms.netmgt.topology.persistence.api.LayoutEntity) PointEntity(org.opennms.netmgt.topology.persistence.api.PointEntity) Point(org.opennms.features.topology.api.Point) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 53 with Function

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;
}
Also used : Arrays(java.util.Arrays) UiProgressWizardFactory(org.phoenicis.scripts.wizard.UiProgressWizardFactory) ScriptException(org.phoenicis.scripts.interpreter.ScriptException) UiSetupWizardFactory(org.phoenicis.scripts.wizard.UiSetupWizardFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ScriptEngineManager(javax.script.ScriptEngineManager) Set(java.util.Set) ScriptFetcher(org.phoenicis.scripts.interpreter.ScriptFetcher) ApplicationContext(org.springframework.context.ApplicationContext) InputStreamReader(java.io.InputStreamReader) Function(java.util.function.Function) UiSetupWizardImplementation(org.phoenicis.scripts.wizard.UiSetupWizardImplementation) HashSet(java.util.HashSet) Consumer(java.util.function.Consumer) List(java.util.List) UiProgressWizardImplementation(org.phoenicis.scripts.wizard.UiProgressWizardImplementation) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InputStreamReader(java.io.InputStreamReader) UiSetupWizardImplementation(org.phoenicis.scripts.wizard.UiSetupWizardImplementation) ScriptEngineManager(javax.script.ScriptEngineManager) ScriptException(org.phoenicis.scripts.interpreter.ScriptException) UiProgressWizardImplementation(org.phoenicis.scripts.wizard.UiProgressWizardImplementation) List(java.util.List) HashSet(java.util.HashSet)

Example 54 with Function

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();
        });
    });
}
Also used : Entity(org.spongepowered.api.entity.Entity) Instruction(com.skelril.openboss.Instruction) World(org.spongepowered.api.world.World) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) Function(java.util.function.Function) DamageModifier(org.spongepowered.api.event.cause.entity.damage.DamageModifier) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) Player(org.spongepowered.api.entity.living.player.Player) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) Zombie(org.spongepowered.api.entity.living.monster.Zombie) Vector3d(com.flowpowered.math.vector.Vector3d) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 55 with Function

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();
    }
}
Also used : Consumer(java.util.function.Consumer) IOException(java.io.IOException) URI(java.net.URI) Collections(java.util.Collections) Function(java.util.function.Function) java.nio.file(java.nio.file) URI(java.net.URI) IOException(java.io.IOException)

Aggregations

Function (java.util.function.Function)176 List (java.util.List)75 ArrayList (java.util.ArrayList)55 Map (java.util.Map)51 Test (org.junit.Test)47 IOException (java.io.IOException)44 HashMap (java.util.HashMap)37 Set (java.util.Set)36 Collectors (java.util.stream.Collectors)33 Arrays (java.util.Arrays)30 Collections (java.util.Collections)26 Collection (java.util.Collection)25 File (java.io.File)20 HashSet (java.util.HashSet)19 Supplier (java.util.function.Supplier)19 BiFunction (java.util.function.BiFunction)18 Consumer (java.util.function.Consumer)16 Test (org.testng.annotations.Test)16 Stream (java.util.stream.Stream)14 Assert.assertEquals (org.junit.Assert.assertEquals)13