Skip to content

Commit

Permalink
fix: scientific notation without period should convert to float
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Jan 13, 2024
1 parent 995d311 commit 5bc14d3
Show file tree
Hide file tree
Showing 3 changed files with 240 additions and 1 deletion.
117 changes: 117 additions & 0 deletions examples/basic_json/src/data/demo/loot_tables/zombified_piglin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"type": "minecraft:fishing",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:loot_table",
"name": "gm4_orb_of_ankou:items/soul_essence/aggressive"
}
],
"conditions": [
{
"condition": "minecraft:table_bonus",
"enchantment": "minecraft:looting",
"chances": [
6e-05,
0.00024,
0.0015,
0.00492,
0.01158,
0.02256,
0.03894,
0.0618,
0.09222,
0.13128,
0.18006
]
}
]
},
{
"rolls": 1,
"entries": [
{
"type": "minecraft:loot_table",
"name": "gm4_orb_of_ankou:items/soul_essence/incombustible"
}
],
"conditions": [
{
"condition": "minecraft:table_bonus",
"enchantment": "minecraft:looting",
"chances": [
4.8e-05,
0.000192,
0.0012,
0.003936,
0.009264,
0.018048,
0.031152,
0.04944,
0.073776,
0.105024,
0.144048
]
}
]
},
{
"rolls": 1,
"entries": [
{
"type": "minecraft:loot_table",
"name": "gm4_orb_of_ankou:items/soul_essence/lifeless"
}
],
"conditions": [
{
"condition": "minecraft:table_bonus",
"enchantment": "minecraft:looting",
"chances": [
5.5e-05,
0.00022,
0.001375,
0.00451,
0.010615,
0.02068,
0.035695,
0.05665,
0.084535,
0.12034,
0.165055
]
}
]
},
{
"rolls": 1,
"entries": [
{
"type": "minecraft:loot_table",
"name": "gm4_orb_of_ankou:items/soul_essence/rushing"
}
],
"conditions": [
{
"condition": "minecraft:table_bonus",
"enchantment": "minecraft:looting",
"chances": [
3.7e-05,
0.000148,
0.000925,
0.003034,
0.007141,
0.013912,
0.024013,
0.03811,
0.056869,
0.080956,
0.111037
]
}
]
}
]
}
2 changes: 1 addition & 1 deletion mecha/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def normalize_whitespace(op: str) -> str:

def string_to_number(string: str) -> Union[int, float]:
"""Helper for converting numbers to string and keeping their original type."""
return float(string) if "." in string else int(string)
return float(string) if "." in string or "e" in string else int(string)


def number_to_string(number: Union[int, float]) -> str:
Expand Down
122 changes: 122 additions & 0 deletions tests/snapshots/examples__build_basic_json__0.pack.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,128 @@ tellraw @p {"text": "empty"}
}
```

`@loot_table demo:zombified_piglin`

```json
{
"type": "minecraft:fishing",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:loot_table",
"name": "gm4_orb_of_ankou:items/soul_essence/aggressive"
}
],
"conditions": [
{
"condition": "minecraft:table_bonus",
"enchantment": "minecraft:looting",
"chances": [
6e-05,
0.00024,
0.0015,
0.00492,
0.01158,
0.02256,
0.03894,
0.0618,
0.09222,
0.13128,
0.18006
]
}
]
},
{
"rolls": 1,
"entries": [
{
"type": "minecraft:loot_table",
"name": "gm4_orb_of_ankou:items/soul_essence/incombustible"
}
],
"conditions": [
{
"condition": "minecraft:table_bonus",
"enchantment": "minecraft:looting",
"chances": [
4.8e-05,
0.000192,
0.0012,
0.003936,
0.009264,
0.018048,
0.031152,
0.04944,
0.073776,
0.105024,
0.144048
]
}
]
},
{
"rolls": 1,
"entries": [
{
"type": "minecraft:loot_table",
"name": "gm4_orb_of_ankou:items/soul_essence/lifeless"
}
],
"conditions": [
{
"condition": "minecraft:table_bonus",
"enchantment": "minecraft:looting",
"chances": [
5.5e-05,
0.00022,
0.001375,
0.00451,
0.010615,
0.02068,
0.035695,
0.05665,
0.084535,
0.12034,
0.165055
]
}
]
},
{
"rolls": 1,
"entries": [
{
"type": "minecraft:loot_table",
"name": "gm4_orb_of_ankou:items/soul_essence/rushing"
}
],
"conditions": [
{
"condition": "minecraft:table_bonus",
"enchantment": "minecraft:looting",
"chances": [
3.7e-05,
0.000148,
0.000925,
0.003034,
0.007141,
0.013912,
0.024013,
0.03811,
0.056869,
0.080956,
0.111037
]
}
]
}
]
}
```

`@loot_table demo:bar`

```json
Expand Down

0 comments on commit 5bc14d3

Please sign in to comment.