use of me.deecaad.weaponmechanics.weapon.explode.regeneration.RegenerationData 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);
}
Aggregations