|
1 | 1 | --- |
2 | | -title: TagPrefixes and the power of .setIgnored() |
| 2 | +title: TagPrefixes and .setIgnored() |
3 | 3 | --- |
| 4 | + |
| 5 | + |
| 6 | +# TagPrefixes And The Power Of `.setIgnored()` |
| 7 | + |
4 | 8 | ## What is a TagPrefix? |
5 | | -TagPrefixes are GTCEu Modern's way of streamlining applying item and block tags to Materials, along with some other functions. The `TagPrefix` class, |
6 | | -available for use in startup and server scripts, contains a number of predefined TagPrefixes that |
7 | | -associate potentially everything from drill heads to flawless gemstones with a material. A common and easy-to-understand example is `TagPrefix.ingot`, |
8 | | -which associates with all Materials that have an IngotProperty and thus an associated ingot item, including custom ones defined via KubeJS. |
9 | | -TagPrefixes provide localization, item and block tagging, and influence many crafting recipes, and are integral to the functioning of GTCEu's material definition system. |
| 9 | + |
| 10 | +TagPrefixes are GTCEu Modern's way of streamlining applying item and block tags to Materials, along with some other |
| 11 | +functions. The `TagPrefix` class, available for use in startup and server scripts, contains a number of predefined |
| 12 | +TagPrefixes that associate potentially everything from drill heads to flawless gemstones with a material. |
| 13 | + |
| 14 | +A common and easy-to-understand example is `TagPrefix.ingot`, which associates with all Materials that have an |
| 15 | +IngotProperty and thus an associated ingot item, including custom ones defined via KubeJS. |
| 16 | +TagPrefixes provide localization, item and block tagging, and influence many crafting recipes, and are integral to the |
| 17 | +functioning of GTCEu's material definition system. |
10 | 18 |
|
11 | 19 | !!! tip "What TagPrefixes are there?" |
12 | | - A list of all availabe TagPrefixes can be found in GTCEu Modern's GitHub or in the .JAR file, in the class `TagPrefix`. |
| 20 | +A list of all available TagPrefixes can be found in GTCEu Modern's GitHub, in the class `TagPrefix`. |
| 21 | + |
13 | 22 |
|
14 | | -## What is .setIgnored()? |
| 23 | +## What is `.setIgnored()`? |
| 24 | + |
| 25 | +While trawling through GTCEu Modern's codebase, or simply by playing Minecraft, you may have noticed that GTCEu Modern |
| 26 | +treats some vanilla materials differently. For example, iron ingots are a vanilla item, yet GTCEu Modern does not create |
| 27 | +a duplicate iron ingot, as its Material definition would suggest it is meant to do. |
| 28 | + |
| 29 | +Instead, the GTCEu Modern Material entry for iron treats the vanilla iron ingot as the material's ingot, and thus |
| 30 | +produces no duplicates. |
| 31 | +This functionality is governed by TagPrefixes, and can also be harnessed by packmakers for their own custom items, or |
| 32 | +when writing compatibility between GTCEu Modern and another mod. |
15 | 33 |
|
16 | | -While trawling thorugh GTCEu Modern's codebase, or simply by playing Minecraft, you may have noticed that GTCEu Modern treats some vanilla materials differently. |
17 | | -For example, iron ingots are a vanilla item, yet GTCEu Modern does not create a duplicate iron ingot, as its Material definition would suggest it is meant to do. |
18 | | -Instead, the GTCEu Modern Material entry for iron treats the vanilla iron ingot as the material's ingot, and thus produces no duplicates. |
19 | | -This functionality is governed by TagPrefixes, and can also be harnessed by packmakers for their own custom items, or when writing compatibility between GTCEu Modern and another mod. |
20 | 34 |
|
21 | 35 | ## Okay, but how do I use this? |
22 | 36 |
|
23 | 37 | This functionality can be leveraged in the material modification event, which is a startup event. |
24 | | -The material modification event occurs in Minecraft's boot sequence after Material registration is finalized, but before the Material registry is closed; you won't be able to define any new Materials using it. |
| 38 | +The material modification event occurs in Minecraft's boot sequence after Material registration is finalized, but before |
| 39 | +the Material registry is closed; you won't be able to define any new Materials using it. |
| 40 | + |
25 | 41 | The following calls are available for each TagPrefix: |
26 | | - - `.setIgnored()` with one input parameter: Takes a `Material` as input and prevents GTCEu from associating that specific TagPrefix with that Material. |
27 | | - - `.setIgnored()` with two input parameters: Takes a `Material` and an `Item` or `Block` (or any class that that implements the `ItemLike` interface) as input; causes GTCEu to treat the passed `ItemLike` as whatever item the TagPrefix would have originally generated for the Material. An `ItemLike...` varargs in the form of a JS array may also be passed to perform the action on multiple blocks and/or items at once. |
28 | | - - `.removeIgnored()`: takes a `Material` as input and re-enables generation of the item associated with the TagPrefix for that material. |
29 | 42 |
|
30 | | -!!! caution "Beware of `Item.of()`!" The classic way to retrieve an `Item` in KubeJS, namely the `Item.of()` wrapper, doesn't work here. You will need to directly pass an `ItemLike` from a Java class for `.setIgnored()` to work correctly. |
| 43 | +- `.setIgnored()` with one input parameter: |
| 44 | + Takes a `Material` as input and prevents GTCEu from associating that specific TagPrefix with that Material. |
| 45 | +- `.setIgnored()` with two input parameters: |
| 46 | + Takes a `Material` and an `Item` or `Block` (or any class that that implements the `ItemLike` interface) as input; |
| 47 | + causes GTCEu to treat the passed `ItemLike` as whatever item the TagPrefix would have originally generated for the |
| 48 | + Material. An `ItemLike...` varargs in the form of a JS array may also be passed to perform the action on multiple |
| 49 | + blocks and/or items at once. |
| 50 | +- `.removeIgnored()`: |
| 51 | + Takes a `Material` as input and re-enables generation of the item associated with the TagPrefix for that material. |
| 52 | + |
| 53 | +!!! caution "Beware of `Item.of()`!" |
| 54 | +The classic way to retrieve an `Item` in KubeJS, namely the `Item.of()` wrapper, doesn't work here. |
| 55 | +You will need to directly pass an `ItemLike` from a Java class for `.setIgnored()` to work correctly. |
31 | 56 |
|
32 | 57 | A more illustrative example, using some Applied Energistics 2 items: |
33 | 58 |
|
34 | | - ```js title="setignored_usage_example.js" |
35 | | - GTCEuStartupEvents.materialModification(event => { // (1) |
36 | | - TagPrefix.gemChipped.setIgnored(GTMaterialRegistry.getMaterial("fluix_crystal")) // (2) |
37 | | - TagPrefix.rock.setIgnored(GTMaterialRegistry.getMaterial("sky_stone"), AEBlocks.SKY_STONE_BLOCK) // (3) |
38 | | - TagPrefix.ingot.removeIgnored(GTMaterials.Iron) // (4) |
39 | | - }) |
40 | | - ``` |
41 | | - 1. This event has no methods such as `event.create()`, as it is not intended to be used to create anything, only tweak pre-existing Material associations. In fact, this event has no accessible methods whatsoever. |
42 | | - 2. This call prevents GTCEu Modern from creating a chipped gem variant of the custom 'fluix_crystal' Material. |
43 | | - 3. This call makes GTCEu Modern associate AE2's Sky Stone block as a rock type (like vanilla stone is associated with the GTCEu Modern stone `Material`) with the custom 'sky_stone' Material. It may be necessary to manually load whatever data definition class contains the `ItemLike` you wish to associate with your `Material`, depending on how the mod's author has provided KubeJS access to the modn's classes. |
44 | | - 4. This call makes GTCEu Modern de-associate vanilla iron ingots from GTCEu Modern's iron Material entry, causing it to generate a duplicate iron ingot. |
45 | | - |
46 | | -The `Material` for which you are adjusting the TagPrefix must be registered in GTCEu Modern's material registry; if this material is custom, this is done using `GTCEuStartupEvents.registry()`, as depicted in these docs. |
| 59 | +```js title="setignored_usage_example.js" |
| 60 | +GTCEuStartupEvents.materialModification(event => { // (1) |
| 61 | + TagPrefix.gemChipped.setIgnored(GTMaterialRegistry.getMaterial("fluix_crystal")) // (2) |
| 62 | + TagPrefix.rock.setIgnored(GTMaterialRegistry.getMaterial("sky_stone"), AEBlocks.SKY_STONE_BLOCK) // (3) |
| 63 | + TagPrefix.ingot.removeIgnored(GTMaterials.Iron) // (4) |
| 64 | +}) |
| 65 | +``` |
| 66 | + |
| 67 | +1. This event has no methods such as `event.create()`, as it is not intended to be used to create anything, only tweak |
| 68 | + pre-existing Material associations. In fact, this event has no accessible methods whatsoever. |
| 69 | +2. This call prevents GTCEu Modern from creating a chipped gem variant of the custom `fluix_crystal` Material. |
| 70 | +3. This call makes GTCEu Modern associate AE2's Sky Stone block as a rock type (like vanilla stone is associated with |
| 71 | + the GTCEu Modern stone `Material`) with the custom `sky_stone` Material. It may be necessary to manually load |
| 72 | + whatever data definition class contains the `ItemLike` you wish to associate with your `Material`, depending on how |
| 73 | + the mod's author has provided KubeJS access to the mod's classes. |
| 74 | +4. This call makes GTCEu Modern de-associate vanilla iron ingots from GTCEu Modern's iron Material entry, causing it to |
| 75 | + generate a duplicate iron ingot. |
| 76 | + |
| 77 | +The `Material` for which you are adjusting the TagPrefix must be registered in GTCEu Modern's material registry; if this |
| 78 | +material is custom, this is done using `GTCEuStartupEvents.registry()`, as depicted in these docs. |
0 commit comments