-
Notifications
You must be signed in to change notification settings - Fork 538
Expand file tree
/
Copy pathCustomEnchantmentEffectsTest.java
More file actions
81 lines (74 loc) · 3.36 KB
/
CustomEnchantmentEffectsTest.java
File metadata and controls
81 lines (74 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.test.item;
import net.minecraft.advancements.predicates.DamageSourcePredicate;
import net.minecraft.advancements.predicates.entity.EntityPredicate;
import net.minecraft.advancements.predicates.entity.EntityTypePredicate;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.EnchantmentTags;
import net.minecraft.world.entity.EntityTypes;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentEffectComponents;
import net.minecraft.world.item.enchantment.EnchantmentTarget;
import net.minecraft.world.item.enchantment.LevelBasedValue;
import net.minecraft.world.item.enchantment.effects.AddValue;
import net.minecraft.world.item.enchantment.effects.Ignite;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.predicates.DamageSourceCondition;
import net.minecraft.world.level.storage.loot.predicates.LootItemEntityPropertyCondition;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.item.v1.EnchantmentEvents;
public class CustomEnchantmentEffectsTest implements ModInitializer {
// weird impaling is a copy of impaling used for testing (just in case minecraft changes impaling for some reason)
public static final ResourceKey<Enchantment> WEIRD_IMPALING = ResourceKey.create(
Registries.ENCHANTMENT,
Identifier.fromNamespaceAndPath("fabric-item-api-v1-testmod", "weird_impaling")
);
@Override
public void onInitialize() {
EnchantmentEvents.MODIFY_WITH_LOOKUP.register(
(key, builder, source, registries) -> {
if (source.isBuiltin() && key == WEIRD_IMPALING) {
// make impaling set things on fire
builder.withEffect(
EnchantmentEffectComponents.POST_ATTACK,
EnchantmentTarget.ATTACKER,
EnchantmentTarget.VICTIM,
new Ignite(LevelBasedValue.perLevel(4.0f)),
DamageSourceCondition.hasDamageSource(
DamageSourcePredicate.Builder.damageType().isDirect(true)
)
);
// add bonus impaling damage to zombie
builder.withEffect(
EnchantmentEffectComponents.DAMAGE,
new AddValue(LevelBasedValue.perLevel(2.5f)),
LootItemEntityPropertyCondition.hasProperties(
LootContext.EntityTarget.THIS,
EntityPredicate.Builder.entity()
.entityType(EntityTypePredicate.of(BuiltInRegistries.ENTITY_TYPE, EntityTypes.ZOMBIE))
)
);
// make it exclusive with treasure enchantments
builder.exclusiveWith(registries.lookup(Registries.ENCHANTMENT).orElseThrow().getter().getOrThrow(EnchantmentTags.TREASURE));
}
}
);
}
}