Skip to content

Commit

Permalink
Apply edit suggestions
Browse files Browse the repository at this point in the history
Co-authored-by: ChampionAsh5357 <[email protected]>
  • Loading branch information
hjake123 and ChampionAsh5357 authored Oct 10, 2024
1 parent a13c73a commit f93862b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/resources/server/enchantments/builtin.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Other:

_See also: [Location Based Effect Components] on the Minecraft Wiki_

Location based effect components are components that contain an `EnchantmentLocationBasedEffect`. These components define actions to take that need to know where in the level the wielder of the enchantment is. They operate using two major methods: `EnchantmentEntityEffect#onChangedBlock`, which is called when the enchanted item is equipped and when the wielder changes their `BlockPos`, and `onDeactivate`, which is called when the enchanted item is removed.
Location based effect components are components that implement `EnchantmentLocationBasedEffect`. These components define actions to take that need to know where in the level the wielder of the enchantment is. They operate using two major methods: `EnchantmentEntityEffect#onChangedBlock`, which is called when the enchanted item is equipped and when the wielder changes their `BlockPos`, and `onDeactivate`, which is called when the enchanted item is removed.

Custom `EnchantmentLocationBasedEffect` extensions can be registered through `BuiltInRegistries.ENCHANTMENT_LOCATION_BASED_EFFECT_TYPE`.

Expand Down Expand Up @@ -120,7 +120,7 @@ Vanilla adds the following location based events:

_See also [Entity Effect Components] on the Minecraft Wiki._

Entity effect components are components that contain an `EnchantmentEntityEffect`, an extension of `EnchantmentLocationBasedEffect`. These override `EnchantmentLocationBasedEffect#onChangedBlock` to run `EnchantmentEntityEffect#apply` instead; this `apply` method is also directly invoked somewhere else in the codebase depending on the specific type of the component.
Entity effect components are components that implement `EnchantmentEntityEffect`, an subtype of `EnchantmentLocationBasedEffect`. These override `EnchantmentLocationBasedEffect#onChangedBlock` to run `EnchantmentEntityEffect#apply` instead; this `apply` method is also directly invoked somewhere else in the codebase depending on the specific type of the component.

Custom `EnchantmentEntityEffect` extensions can be registered through `BuiltInRegistries.ENCHANTMENT_ENTITY_EFFECT_TYPE`.

Expand Down
6 changes: 3 additions & 3 deletions docs/resources/server/enchantments/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ A new enchantment can be added by creating a JSON file in your namespace's `ench

The `max_cost` and `min_cost` fields specify boundaries for how much enchanting power is needed to create this enchantment. There is a somewhat convoluted procedure to actually make use of these values, however.

First, the table takes into account the return value of `IBlockStateExtension#getEnchantPowerBonus()` for the surrounding blocks. From this, it derives a 'base cost' for each slot. This cost is shown in-game as the green numbers besides the enchantments in the menu. For each enchantment, the base cost is modified twice by a random value derived from the item's enchantability (its return value from `IItemStackExtension#getEnchantmentValue()`), like so:
First, the table takes into account the return value of `IBlockExtension#getEnchantPowerBonus()` for the surrounding blocks. From this, it derives a 'base cost' for each slot. This cost is shown in-game as the green numbers besides the enchantments in the menu. For each enchantment, the base cost is modified twice by a random value derived from the item's enchantability (its return value from `IItemExtension#getEnchantmentValue()`), like so:

`(Modified Cost) = (Base Cost) + random.nextInt(e / 4 + 1) + random.nextInt(e / 4 + 1)`, where `e` is the enchantability score.

Expand Down Expand Up @@ -165,7 +165,7 @@ Here is a full example using vanilla helper methods to work with a custom enchan
```java
// Define an example data-bearing record.
public record Increment(int value) {
public static final Codec<BoundEntity> CODEC = RecordCodecBuilder.create(instance ->
public static final Codec<Increment> CODEC = RecordCodecBuilder.create(instance ->
instance.group(
Codec.INT.fieldOf("value").forGetter(Increment::value),
).apply(instance, Increment::new)
Expand All @@ -192,7 +192,7 @@ public static final DeferredHolder<DataComponentType<?>, DataComponentType<Condi
MutableInt mutableValue = new MutableInt(unmodifiedValue);
EnchantmentHelper.runIterationOnItem(itemStack, (enchantmentHolder, enchantLevel) -> Enchantment.applyEffects(
// Isolates the ConditionalEffect<Increment> from the provided holder and wraps it in a list for applyEffects.
enchantmentHolder.value().getEffects(INCREMENT.value()),
enchantmentHolder.value().getEffects(INCREMENT.get()),

// Produces a LootContext. Other context helpers from the Enchantment class
// include itemContext, locationContext, entityContext, and blockHitContext.
Expand Down

0 comments on commit f93862b

Please sign in to comment.