Utilities for writing / updating data pack files
patch_block_trade_provider_function(provider_function_path=None)
If you're looking to keep the block trades, then update the block trade provider so that it knows where to find them
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provider_function_path |
path
|
The file to update (in case it's in a weird place). If None is provided, this method will look for "provide_block_trades.mcfunction" within the default pack folder. |
None
|
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the destination trade provider file doesn't exist |
PermissionError
|
If you don't have the ability to write to the trade file |
ValueError
|
If the trade provider file could not be properly munged |
Notes
- This method will not convert the function file between versions, so make sure that your "donor" pack is of the target Minecraft version.
- This method expects that the donor pack is set up with a single "function(s)" directory. It will first try modifying the "function" folder and won't check if "functions" exists unless "function" does not. If, for some reason, you have both folders in your data pack, this will likely cause undesired behavior.
Source code in head_hunter/write.py
update_trade_count(lower_bound, upper_bound, trade_provider)
Update the "provide trades" function file to generate a random number from the specified bounds
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lower_bound |
int
|
The number of the first trade (inclusive) |
required |
upper_bound |
int
|
The number of the last trade (inclusive) |
required |
trade_provider |
str or path
|
Which trade provider to update. Should either be "head", "block" or
the path to the actual |
required |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the destination trade provider file doesn't exist |
PermissionError
|
If you don't have the ability to write to the trade file |
ValueError
|
If the trade provider file could not be properly munged |
Notes
- This method will not convert the function file between versions, so make sure that your "donor" pack is of the target Minecraft version.
- This method expects that the donor pack is set up with a single "function(s)" directory. It will first try modifying the "function" folder and won't check if "functions" exists unless "function" does not. If, for some reason, you have both folders in your data pack, this will likely cause undesired behavior.
Source code in head_hunter/write.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
|
write_block_trades(commands, start_at=1002)
Render the file add_block_trade.mcfunction
that will separately specify
the list of block trades to provide the Wandering Trader
Parameters:
Name | Type | Description | Default |
---|---|---|---|
commands |
Iterable[str]
|
The commands extracted from the original |
required |
start_at |
int
|
The starting value for the trade index. Default is 1000. |
1002
|
Returns:
Type | Description |
---|---|
(int, int) tuple
|
The lower and upper bounds of the trade indices corresponding to the written trades (note that if start_at is negative, then the start_at value will be the upper bound) |
Notes
If the return values are such that the upper bound is less than the lower bound, that means that no trades were actually written.
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the pack folder or function(s) subdirectory doesn't exist (meaning you haven't downloaded the base data pack or that the file structure is corrupted. See Notes. |
PermissionError
|
If you don't have the ability to write to the pack folder |
Notes
- This method will not convert block trades between versions, so make sure that your "donor" pack is of the target Minecraft version.
- This method expects that the donor pack is set up with a single "function(s)" directory. It will first try writing to the "function" folder and won't check if "functions" exists unless "function" does not. If, for some reason, you have both folders in your data pack, this will likely cause undesired behavior.
Source code in head_hunter/write.py
write_head_trades(trades, price=None, purchase_limit=3, xp_bonus=0, pack_format=48, freeze_textures=True)
Render the add_trade.mcfunction
file that will give the
Wandering Trader a specified list of head trades
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trades |
Iterable[HeadSpec]
|
list of player-head specifications, either in the form of player names, such that calling would give you the specified head, or single-item dicts {player_name: full_spec} such that calling would give you that head |
required |
price |
tuple of (str, int)
|
The price of a head, structured in the form (item, quantity). Default price is one emerald. |
None
|
purchase_limit |
int
|
The number of each head you can buy per trader. Default is 3. |
3
|
xp_bonus |
int
|
The amount of XP you get from buying a player head. Default behavior is that buying player heads does not award experience. |
0
|
pack_format |
int
|
By default, this function will generate function files compatible with Minecraft 1.21 and above. To instead wreite the function for an older version of Minecraft, pass the pack format version here (see: https://minecraft.wiki/w/Data_pack#Pack_format). |
48
|
freeze_textures |
bool
|
To avoid scenarios where traded heads have their textures dynamically
update—or worse, fail to fetch at all in-game—any trades that were
specified via username alone will have their current texture pulled
from the Mojang API when this method is called. To disable this
feature (for example, if you're running this on a computer without
internet access), pass in |
True
|
Returns:
Type | Description |
---|---|
(int, int) tuple
|
The (inclusive) lower and upper bounds of the trade indices corresponding
to the written trades (the lower bound is hard-coded as
|
Notes
If the return values are such that the upper bound is less than the lower bound, that means that no trades were actually written.
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the pack folder or function(s) subdirectory doesn't exist (meaning you haven't downloaded the base data pack or that the file structure is corrupted |
PermissionError
|
If you don't have the ability to write to the pack folder |
NotImplementedError
|
If the specified |
Source code in head_hunter/write.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
write_meta_files(*template_paths, version=None, pack_format=48)
Write a metadata file (or files), using the template in the templates folder (or one(s) you brought yourself)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
template_paths |
path - like
|
The paths to template files. If None is provided, the files in the templates folder will be used. |
()
|
version |
str
|
The version to give to the pack. If None is provided, one will be generated based on the current date (calver). |
None
|
pack_format |
int
|
By default, this function will create meta files indicating that the pack is written for Minecraft 1.21 and above. To instead set for compatibility with an older version of Minecraft, pass the pack format version here (see: https://minecraft.wiki/w/Data_pack#Pack_format). |
48
|
Returns:
Type | Description |
---|---|
None
|
|
Notes
- The list of supported metadata files is hard-coded in this module as
META_FILES
.
Raises:
Type | Description |
---|---|
ValueError
|
If the template file is not recognized (filename should match the file name of the metadata file). |
FileNotFoundError
|
If the specified template file doesn't exist |
PermissionError
|
If you don't have the ability to open the template file or write to the pack folder |