Add demo thunder enchantment
Some checks failed
build / build (21) (push) Has been cancelled

This commit is contained in:
illyum 2024-09-29 04:26:46 -06:00
parent 4e1b7d8ade
commit 288c1d6e59
3 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,2 @@
// 1.21.1 2024-09-29T04:05:48.3198307 Custom Enchants/Enchantment Generator
4e507987cd1905de26693915dff86bcadec7e9a0 data\customenchants\enchantment\thundering.json

View File

@ -0,0 +1,36 @@
{
"anvil_cost": 7,
"description": {
"translate": "enchantment.customenchants.thundering"
},
"effects": {
"minecraft:post_attack": [
{
"affected": "victim",
"effect": {
"type": "customenchants:lightning",
"amount": {
"type": "minecraft:linear",
"base": 0.5,
"per_level_above_first": 0.15
}
},
"enchanted": "attacker"
}
]
},
"max_cost": {
"base": 1,
"per_level_above_first": 15
},
"max_level": 5,
"min_cost": {
"base": 1,
"per_level_above_first": 10
},
"slots": [
"hand"
],
"supported_items": "#minecraft:enchantable/sword",
"weight": 15
}

View File

@ -0,0 +1,38 @@
package com.itzilly.enchantments.effects;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.enchantment.EnchantmentEffectContext;
import net.minecraft.enchantment.EnchantmentLevelBasedValue;
import net.minecraft.enchantment.effect.EnchantmentEntityEffect;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnReason;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
public record LightningEnchantmentEffect(EnchantmentLevelBasedValue amount) implements EnchantmentEntityEffect {
public static final MapCodec<LightningEnchantmentEffect> CODEC = RecordCodecBuilder.mapCodec(
instance -> instance.group(
EnchantmentLevelBasedValue.CODEC.fieldOf("amount").forGetter(LightningEnchantmentEffect::amount)
).apply(instance, LightningEnchantmentEffect::new));
@Override
public void apply(ServerWorld world, int level, EnchantmentEffectContext context, Entity target, Vec3d pos) {
if(target instanceof LivingEntity living) {
float numberOfStrikes = this.amount.getValue(level);
BlockPos targetPosition = living.getBlockPos();
for (int i = 0; i < numberOfStrikes; i++) {
EntityType.LIGHTNING_BOLT.spawn(world, targetPosition, SpawnReason.TRIGGERED);
}
}
}
@Override
public MapCodec<? extends EnchantmentEntityEffect> getCodec() {
return CODEC;
}
}