Search in sources :

Example 1 with ExplosionExposure

use of me.deecaad.weaponmechanics.weapon.explode.exposures.ExplosionExposure in project MechanicsMain by WeaponMechanics.

the class Explosion method serialize.

@Override
@Nonnull
public Explosion serialize(SerializeData data) throws SerializerException {
    // We don't need to get the values here since we add them to the map
    // later. We should still make sure these are positive numbers, though.
    data.of("Explosion_Type_Data.Yield").assertPositive();
    data.of("Explosion_Type_Data.Angle").assertPositive();
    data.of("Explosion_Type_Data.Height").assertPositive();
    data.of("Explosion_Type_Data.Width").assertPositive();
    data.of("Explosion_Type_Data.Radius").assertPositive();
    data.of("Rays").assertPositive();
    // We always want at least one.
    if (!data.config.contains(data.key + ".Explosion_Type_Data")) {
        throw new SerializerMissingKeyException(data.serializer, "Explosion_Type_Data", data.of("Explosion_Type_Data").getLocation());
    }
    Map<String, Object> typeData = data.config.getConfigurationSection(data.key + ".Explosion_Type_Data").getValues(false);
    // most people will not understand hat it means. Vanilla MC uses 16.
    if (!typeData.containsKey("Rays"))
        typeData.put("Rays", 16);
    ExplosionExposure exposure;
    ExplosionShape shape;
    try {
        exposure = ExposureFactory.getInstance().get(data.of("Explosion_Exposure").get("DEFAULT"), typeData);
        shape = ShapeFactory.getInstance().get(data.of("Explosion_Shape").get("DEFAULT"), typeData);
    } catch (SerializerException ex) {
        // We need to manually set the file and path, since the Factory
        // class does not get enough information to fill it.
        ex.setLocation(data.of("Explosion_Type_Data").getLocation());
        throw ex;
    }
    BlockDamage blockDamage = data.of("Block_Damage").serialize(BlockDamage.class);
    RegenerationData regeneration = data.of("Regeneration").serialize(RegenerationData.class);
    // to make when copying/pasting and deleting chunks of config.
    if ((blockDamage == null || !blockDamage.isBreakBlocks()) && regeneration != null) {
        throw data.exception(null, "Found an Explosion that defines 'Regeneration' when 'Block_Damage' cannot break blocks!", "This happens when 'Block_Damage.Break_Blocks: false' or when 'Block_Damage' was not added AND you tried to add 'Regeneration'");
    }
    // This is a required argument to determine when a projectile using this
    // explosion should explode (onEntityHit, onBlockHit, after delay, etc.)
    Detonation detonation = data.of("Detonation").assertExists().serialize(Detonation.class);
    Double blockChance = data.of("Block_Damage.Spawn_Falling_Block_Chance").serializeNonStandardSerializer(new ChanceSerializer());
    if (blockChance == null)
        blockChance = 0.0;
    boolean isKnockback = !data.of("Disable_Vanilla_Knockback").getBool(false);
    // These 4 options are all nullable and not required for an explosion
    // to occur. It is very interesting when they are all used together :p
    ClusterBomb clusterBomb = data.of("Cluster_Bomb").serialize(ClusterBomb.class);
    AirStrike airStrike = data.of("Airstrike").serialize(AirStrike.class);
    Flashbang flashbang = data.of("Flashbang").serialize(Flashbang.class);
    Mechanics mechanics = data.of("Mechanics").serialize(Mechanics.class);
    return new Explosion(shape, exposure, blockDamage, regeneration, detonation, blockChance, isKnockback, clusterBomb, airStrike, flashbang, mechanics);
}
Also used : ChanceSerializer(me.deecaad.core.file.serializers.ChanceSerializer) ExplosionExposure(me.deecaad.weaponmechanics.weapon.explode.exposures.ExplosionExposure) SerializerException(me.deecaad.core.file.SerializerException) RegenerationData(me.deecaad.weaponmechanics.weapon.explode.regeneration.RegenerationData) ExplosionShape(me.deecaad.weaponmechanics.weapon.explode.shapes.ExplosionShape) Mechanics(me.deecaad.weaponmechanics.mechanics.Mechanics) WeaponMechanics(me.deecaad.weaponmechanics.WeaponMechanics) SerializerMissingKeyException(me.deecaad.core.file.SerializerMissingKeyException) Nonnull(javax.annotation.Nonnull)

Aggregations

Nonnull (javax.annotation.Nonnull)1 SerializerException (me.deecaad.core.file.SerializerException)1 SerializerMissingKeyException (me.deecaad.core.file.SerializerMissingKeyException)1 ChanceSerializer (me.deecaad.core.file.serializers.ChanceSerializer)1 WeaponMechanics (me.deecaad.weaponmechanics.WeaponMechanics)1 Mechanics (me.deecaad.weaponmechanics.mechanics.Mechanics)1 ExplosionExposure (me.deecaad.weaponmechanics.weapon.explode.exposures.ExplosionExposure)1 RegenerationData (me.deecaad.weaponmechanics.weapon.explode.regeneration.RegenerationData)1 ExplosionShape (me.deecaad.weaponmechanics.weapon.explode.shapes.ExplosionShape)1