|
1 | 1 | # Summoning Entity |
2 | 2 |
|
3 | | -Work in progress! |
| 3 | +`SummoningEntity` is a utility binding that allows you to easily create complex instances of `EntityInput`s and `EntityOutput`s via the `EntityInputBuilder` and `EntityOutputBuilder`. The builders offer functionality to add tooltips, offset and spread values, as well as NBT to entities, which is otherwise not possible, if you only provide a simple [entity input](../recipe/inputs.md#entity-inputs) or [entity output](../recipe/outputs.md#entity-outputs) instance. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +- access in recipes event via: `SummoningEntity` |
| 8 | +- functions: |
| 9 | + - `input(EntityInfo entity)` |
| 10 | + - creates an `EntityInputBuilder` with the specified `EntityInfo` |
| 11 | + - `input(Holder<EntityType<?>> entity, Integer count)` |
| 12 | + - creates an `EntityInputBuilder` with the specified entity and the specified count |
| 13 | + - `output(EntityInfo entity)` |
| 14 | + - creates an `EntityOutputBuilder` with the specified `EntityInfo` |
| 15 | + - `output(Holder<EntityType<?>> entity, Integer count)` |
| 16 | + - creates an `EntityOutputBuilder` with the specified entity and the specified count |
| 17 | + |
| 18 | +```js |
| 19 | +SummoningEntity.input("pig") |
| 20 | +SummoningEntity.input("5x minecraft:ghast") |
| 21 | +SummoningEntity.input("minecraft:fox", 3) |
| 22 | + |
| 23 | +SummoningEntity.output("cow") |
| 24 | +SummoningEntity.output("3x sheep") |
| 25 | +SummoningEntity.output("iron_golem", 2) |
| 26 | +``` |
| 27 | + |
| 28 | +## Entity Input Builder |
| 29 | + |
| 30 | +After obtaining the `EntityInputBuilder` instance through the binding, you can chain more functions to it. It is not required to finish the builder because the `entityInputs` function accepts builder instances as well. |
| 31 | + |
| 32 | +- properties: |
| 33 | + - `entity` |
| 34 | + - description: specifies the input entity; defined via the binding function to obtain the builder |
| 35 | + - type: `Holder<EntityType<?>>` |
| 36 | + - required: yes |
| 37 | + - `count` |
| 38 | + - description: specifies the count of the input entity; defined via the binding function to obtain the builder |
| 39 | + - type: `Integer` |
| 40 | + - required: no |
| 41 | + - default: `1` |
| 42 | + - `data` |
| 43 | + - description: specifies the data (NBT) of the input entity; only used for rendering |
| 44 | + - type: `CompoundTag` (JsonObject) |
| 45 | + - required: no |
| 46 | + - default: empty |
| 47 | + - `tooltip` |
| 48 | + - description: specifies additional tooltip lines shown in recipe viewer pages |
| 49 | + - type: `List<Component>` |
| 50 | + - required: no |
| 51 | + - default: empty list |
| 52 | + - `validator` |
| 53 | + - description: specifies the validator function to check the entity data (NBT) |
| 54 | + - type: `Predicate<Entity>` |
| 55 | + - required: no |
| 56 | + - default: always `true` |
| 57 | +- functions: |
| 58 | + - `data(CompoundTag data)` |
| 59 | + - assigns the given NBT data to the `EntityInput` |
| 60 | + - `tooltip(List<Component> tooltip)` |
| 61 | + - assigns the given tooltip lines to the `EntityInput` |
| 62 | + - `validator(Predicate<Entity> validator)` |
| 63 | + - assigns the given validator to the `EntityInput` |
| 64 | + |
| 65 | +> [!TIP] What is a validator? |
| 66 | +> You might ask why a custom `validator` is required if `data` is already provided. For inputs, the `data` property is only used for rendering purposes in recipe viewers. If you give an entity a sword via the `data` property, it will be displayed in the recipe viewer page, but it won't be checked if the entity actually has a sword when being sacrificed. |
| 67 | +> |
| 68 | +> **Why is that?<br>** |
| 69 | +> Because vanilla Minecraft only checks entity data (NBT) for exact matches, there is no way to always cover all desired functionality. If you want to ensure that an entity has at least 10 HP, this wouldn't be possible because Minecraft would check for the exact value only. That's why you have to use a custom validator with your own logic to check if the respective values are correct. |
| 70 | +
|
| 71 | +```js |
| 72 | +.entityInputs([ |
| 73 | + SummoningEntity.input("cat", 3).tooltip("Meow"), // [!code focus:13] |
| 74 | + SummoningEntity.input("zombie") |
| 75 | + .data({ |
| 76 | + HandItems: [ |
| 77 | + { |
| 78 | + id: "minecraft:diamond_sword", |
| 79 | + Count: 1, |
| 80 | + tag: { ench: [{ id: 16, lvl: 1 }] }, |
| 81 | + }, |
| 82 | + ], |
| 83 | + }) |
| 84 | + .tooltip("Needs any sword") |
| 85 | + .validator((e) => e.mainHandItem.id.contains("sword")), |
| 86 | +]) |
| 87 | +``` |
| 88 | + |
| 89 | +## Entity Output Builder |
| 90 | + |
| 91 | +After obtaining the `EntityOutputBuilder` instance through the binding, you can chain more functions to it. It is not required to finish the builder because the `entityOutputs` function accepts builder instances as well. |
| 92 | + |
| 93 | +- properties: |
| 94 | + - `entity` |
| 95 | + - description: specifies the output entity; defined via the binding function to obtain the builder |
| 96 | + - type: `Holder<EntityType<?>>` |
| 97 | + - required: yes |
| 98 | + - `count` |
| 99 | + - description: specifies the count of the output entity; defined via the binding function to obtain the builder |
| 100 | + - type: `Integer` |
| 101 | + - required: no |
| 102 | + - default: `1` |
| 103 | + - `data` |
| 104 | + - description: specifies the data (NBT) of the output entity |
| 105 | + - type: `CompoundTag` (JsonObject) |
| 106 | + - required: no |
| 107 | + - default: empty |
| 108 | + - `tooltip` |
| 109 | + - description: specifies additional tooltip lines shown in recipe viewer pages |
| 110 | + - type: `List<Component>` |
| 111 | + - required: no |
| 112 | + - default: empty list |
| 113 | + - `offset` |
| 114 | + - description: specifies the offset to the altar block where to spawn the output entity at |
| 115 | + - type: `BlockPos` |
| 116 | + - required: no |
| 117 | + - default: `[0, 2, 0]` |
| 118 | + - `spread` |
| 119 | + - description: specifies the spread of the output entities; output entities are spawned at different positions within the spread area; a single entity can spawn at a position before a new random position is calculated |
| 120 | + - type: `BlockPos` |
| 121 | + - required: no |
| 122 | + - default: `[1, 0, 1]` |
| 123 | +- functions: |
| 124 | + - `data(CompoundTag data)` |
| 125 | + - assigns the given NBT data to the `EntityOutput` |
| 126 | + - `tooltip(List<Component> tooltip)` |
| 127 | + - assigns the given tooltip lines to the `EntityOutput` |
| 128 | + - `offset(BlockPos offset)` |
| 129 | + - assigns the given offset to the `EntityOutput` |
| 130 | + - `spread(BlockPos spread)` |
| 131 | + - assigns the given spread to the `EntityOutput` |
| 132 | + |
| 133 | +```js |
| 134 | +.entityOutputs([ |
| 135 | + SummoningEntity.output("5x creeper").tooltip("Kaboom"), // [!code focus:18] |
| 136 | + SummoningEntity.output("skeleton", 2) |
| 137 | + .data({ |
| 138 | + HandItems: [ |
| 139 | + { |
| 140 | + id: "minecraft:diamond_sword", |
| 141 | + Count: 1, |
| 142 | + tag: { ench: [{ id: 16, lvl: 1 }] }, |
| 143 | + }, |
| 144 | + ], |
| 145 | + }), |
| 146 | + SummoningEntity.output("6x sheep") |
| 147 | + .offset([1, 2, 2]) |
| 148 | + .spread([4, 2, 4]) |
| 149 | + .data({ |
| 150 | + Health: 50, |
| 151 | + attributes: [{ id: "generic.max_health", base: 50 }], |
| 152 | + }), |
| 153 | +]) |
| 154 | +``` |
0 commit comments