Search in sources :

Example 1 with IAcoustic

use of org.blockartistry.DynSurround.client.footsteps.interfaces.IAcoustic in project DynamicSurroundings by OreCruncher.

the class FootstepsRegistry method resolvePrimitive.

/**
 * Used to determine what acoustics to play based on the block's sound
 * attributes. It's a fallback method in case there isn't a configuration
 * defined acoustic profile for a block state.
 *
 * @param state
 *            BlockState for which the acoustic profile is being generated
 * @return Acoustic profile for the BlockState, if any
 */
@Nullable
public IAcoustic[] resolvePrimitive(@Nonnull final IBlockState state) {
    if (state == Blocks.AIR.getDefaultState())
        return AcousticsManager.NOT_EMITTER;
    final SoundType type = MCHelper.getSoundType(state);
    if (type == null)
        return AcousticsManager.NOT_EMITTER;
    final String soundName;
    boolean flag = false;
    if (type.getStepSound() == null || type.getStepSound().getSoundName().getResourcePath().isEmpty()) {
        soundName = "UNDEFINED";
        flag = true;
    } else
        soundName = type.getStepSound().getSoundName().toString();
    final String substrate = String.format(Locale.ENGLISH, "%.2f_%.2f", type.getVolume(), type.getPitch());
    // Check for primitive in register
    IAcoustic[] primitive = this.primitiveMap.getPrimitiveMapSubstrate(soundName, substrate);
    if (primitive == null) {
        if (flag) {
            // Check sound
            primitive = this.primitiveMap.getPrimitiveMapSubstrate(soundName, "break_" + soundName);
        }
        if (primitive == null) {
            primitive = this.primitiveMap.getPrimitiveMap(soundName);
        }
    }
    if (primitive == null) {
    // TODO: Generate an acoustic profile on the fly and insert into the map?
    }
    return primitive;
}
Also used : SoundType(net.minecraft.block.SoundType) IAcoustic(org.blockartistry.DynSurround.client.footsteps.interfaces.IAcoustic) Nullable(javax.annotation.Nullable)

Example 2 with IAcoustic

use of org.blockartistry.DynSurround.client.footsteps.interfaces.IAcoustic in project DynamicSurroundings by OreCruncher.

the class AcousticsJsonReader method solveAcousticsCompound.

private IAcoustic solveAcousticsCompound(final JsonObject unsolved) throws JsonParseException {
    IAcoustic ret = null;
    if (!unsolved.has("type") || unsolved.get("type").getAsString().equals("basic")) {
        final BasicAcoustic a = new BasicAcoustic();
        prepareDefaults(a);
        setupClassics(a, unsolved);
        ret = a;
    } else {
        final String type = unsolved.get("type").getAsString();
        if (type.equals("simultaneous")) {
            final List<IAcoustic> acoustics = new ArrayList<>();
            final JsonArray sim = unsolved.getAsJsonArray("array");
            final Iterator<JsonElement> iter = sim.iterator();
            while (iter.hasNext()) {
                final JsonElement subElement = iter.next();
                acoustics.add(solveAcoustic(subElement));
            }
            final SimultaneousAcoustic a = new SimultaneousAcoustic(acoustics);
            ret = a;
        } else if (type.equals("delayed")) {
            final DelayedAcoustic a = new DelayedAcoustic();
            prepareDefaults(a);
            setupClassics(a, unsolved);
            if (unsolved.has("delay")) {
                a.setDelayMin(unsolved.get("delay").getAsInt());
                a.setDelayMax(unsolved.get("delay").getAsInt());
            } else {
                a.setDelayMin(unsolved.get("delay_min").getAsInt());
                a.setDelayMax(unsolved.get("delay_max").getAsInt());
            }
            ret = a;
        } else if (type.equals("probability")) {
            final List<Integer> weights = new ArrayList<>();
            final List<IAcoustic> acoustics = new ArrayList<>();
            final JsonArray sim = unsolved.getAsJsonArray("array");
            final Iterator<JsonElement> iter = sim.iterator();
            while (iter.hasNext()) {
                JsonElement subElement = iter.next();
                weights.add(subElement.getAsInt());
                if (!iter.hasNext())
                    throw new JsonParseException("Probability has odd number of children!");
                subElement = iter.next();
                acoustics.add(solveAcoustic(subElement));
            }
            final ProbabilityWeightsAcoustic a = new ProbabilityWeightsAcoustic(acoustics, weights);
            ret = a;
        }
    }
    return ret;
}
Also used : SimultaneousAcoustic(org.blockartistry.DynSurround.client.footsteps.implem.SimultaneousAcoustic) IAcoustic(org.blockartistry.DynSurround.client.footsteps.interfaces.IAcoustic) ProbabilityWeightsAcoustic(org.blockartistry.DynSurround.client.footsteps.implem.ProbabilityWeightsAcoustic) ArrayList(java.util.ArrayList) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) DelayedAcoustic(org.blockartistry.DynSurround.client.footsteps.implem.DelayedAcoustic) BasicAcoustic(org.blockartistry.DynSurround.client.footsteps.implem.BasicAcoustic)

Example 3 with IAcoustic

use of org.blockartistry.DynSurround.client.footsteps.interfaces.IAcoustic in project DynamicSurroundings by OreCruncher.

the class Generator method findAssociationMessyFoliage.

@Nullable
protected Association findAssociationMessyFoliage(@Nonnull final World world, @Nonnull final BlockPos pos) {
    Association result = null;
    final BlockPos up = pos.up();
    final IBlockState above = WorldUtils.getBlockState(world, up);
    if (above != Blocks.AIR.getDefaultState()) {
        IAcoustic[] acoustics = this.blockMap.getBlockAcoustics(world, above, up, Substrate.MESSY);
        if (acoustics == AcousticsManager.MESSY_GROUND) {
            acoustics = this.blockMap.getBlockAcoustics(world, above, up, Substrate.FOLIAGE);
            if (acoustics != null && acoustics != AcousticsManager.NOT_EMITTER)
                result = new Association(acoustics);
        }
    }
    return result;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IAcoustic(org.blockartistry.DynSurround.client.footsteps.interfaces.IAcoustic) BlockPos(net.minecraft.util.math.BlockPos) Nullable(javax.annotation.Nullable)

Example 4 with IAcoustic

use of org.blockartistry.DynSurround.client.footsteps.interfaces.IAcoustic in project DynamicSurroundings by OreCruncher.

the class Generator method findAssociationForBlock.

/**
 * Find an association for a certain block assuming the player is standing on
 * it. This will sometimes select the block above because some block act like
 * carpets. This also applies when the block targeted by the location is
 * actually not emitting, such as lilypads on water.
 *
 * Returns null if the block is not a valid emitting block (this causes the
 * engine to continue looking for valid blocks). This also happens if the carpet
 * is non-emitting.
 *
 * Returns a string that begins with "_NO_ASSOCIATION" if the block is valid,
 * but has no association in the blockmap. If the carpet was selected, this
 * solves to the carpet.
 */
@Nonnull
protected Association findAssociationForBlock(@Nonnull final World world, @Nonnull BlockPos pos) {
    final IBlockState airState = Blocks.AIR.getDefaultState();
    IBlockState in = WorldUtils.getBlockState(world, pos);
    BlockPos tPos = pos.up();
    final IBlockState above = WorldUtils.getBlockState(world, tPos);
    IAcoustic[] association = null;
    if (above != airState)
        association = this.blockMap.getBlockAcoustics(world, above, tPos, Substrate.CARPET);
    if (association == null || association == AcousticsManager.NOT_EMITTER) {
        if (in == airState) {
            tPos = pos.down();
            final IBlockState below = WorldUtils.getBlockState(world, tPos);
            association = this.blockMap.getBlockAcoustics(world, below, tPos, Substrate.FENCE);
            if (association != null) {
                pos = tPos;
                in = below;
            }
        }
        if (association == null) {
            association = this.blockMap.getBlockAcoustics(world, in, pos);
        }
        if (association != null && association != AcousticsManager.NOT_EMITTER) {
            if (above != airState) {
                final IAcoustic[] foliage = this.blockMap.getBlockAcoustics(world, above, pos.up(), Substrate.FOLIAGE);
                if (foliage != null && foliage != AcousticsManager.NOT_EMITTER) {
                    association = MyUtils.concatenate(association, foliage);
                }
            }
        }
    } else {
        pos = tPos;
        in = above;
    }
    if (association != null) {
        if (association == AcousticsManager.NOT_EMITTER) {
            // Player has stepped on a non-emitter block as defined in the blockmap
            return null;
        } else {
            // Let's play the fancy acoustics we have defined for the block
            return new Association(in, pos, association);
        }
    } else {
        // step sound if available.
        return new Association(in, pos);
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IAcoustic(org.blockartistry.DynSurround.client.footsteps.interfaces.IAcoustic) BlockPos(net.minecraft.util.math.BlockPos) Nonnull(javax.annotation.Nonnull)

Example 5 with IAcoustic

use of org.blockartistry.DynSurround.client.footsteps.interfaces.IAcoustic in project DynamicSurroundings by OreCruncher.

the class BlockMap method put.

private void put(@Nonnull final Block block, final int meta, @Nonnull final String substrate, @Nonnull final String value) {
    final Substrate s = Substrate.get(substrate);
    final IAcoustic[] acoustics = this.acousticsManager.compileAcoustics(value);
    final BlockInfo info = new BlockInfo(block, meta);
    if (s == null) {
        this.metaMap.put(info, acoustics);
    } else {
        BlockAcousticMap sub = this.substrateMap.get(s);
        if (sub == null)
            this.substrateMap.put(s, sub = new BlockAcousticMap());
        sub.put(info, acoustics);
    }
}
Also used : IAcoustic(org.blockartistry.DynSurround.client.footsteps.interfaces.IAcoustic) BlockInfo(org.blockartistry.DynSurround.registry.BlockInfo)

Aggregations

IAcoustic (org.blockartistry.DynSurround.client.footsteps.interfaces.IAcoustic)8 Nonnull (javax.annotation.Nonnull)3 Nullable (javax.annotation.Nullable)3 IBlockState (net.minecraft.block.state.IBlockState)3 JsonElement (com.google.gson.JsonElement)2 SoundType (net.minecraft.block.SoundType)2 BlockPos (net.minecraft.util.math.BlockPos)2 JsonArray (com.google.gson.JsonArray)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Scanner (java.util.Scanner)1