Added Smack effect
This commit is contained in:
parent
2d6e677029
commit
dffdb168ac
|
|
@ -8,6 +8,7 @@ import net.minecraft.resources.ResourceKey;
|
|||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect;
|
||||
import xyz.nearmisses.patience.mc_rebalance.enchantment.effect.SmackEffect;
|
||||
import xyz.nearmisses.patience.mc_rebalance.enchantment.effect.WindupEffect;
|
||||
|
||||
// Copied off the Fabric wiki. I don't think I like this code.
|
||||
|
|
@ -15,6 +16,7 @@ public class ModEnchantments {
|
|||
|
||||
public static final ResourceKey<Enchantment> Windup = of("windup");
|
||||
public static MapCodec<WindupEffect> Effect_Windup = register("windup_effect", WindupEffect.CODEC);
|
||||
public static MapCodec<SmackEffect> Effect_Smack = register("smack_effect", SmackEffect.CODEC);
|
||||
|
||||
private static ResourceKey<Enchantment> of(String path) {
|
||||
ResourceLocation id = ResourceLocation.fromNamespaceAndPath(MCRebalance.MOD_ID, path);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
package xyz.nearmisses.patience.mc_rebalance.enchantment.effect;
|
||||
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.enchantment.EnchantedItemInUse;
|
||||
import net.minecraft.world.item.enchantment.LevelBasedValue;
|
||||
import net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record SmackEffect(LevelBasedValue amount) implements EnchantmentEntityEffect {
|
||||
public static final MapCodec<SmackEffect> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
||||
instance.group(
|
||||
LevelBasedValue.CODEC.fieldOf("amount").forGetter(SmackEffect::amount)
|
||||
).apply(instance, SmackEffect::new)
|
||||
);
|
||||
|
||||
@Override
|
||||
public void apply(ServerLevel world, int level, EnchantedItemInUse context, Entity target, Vec3 pos) {
|
||||
/*boolean playerAndCharged;
|
||||
if(context.owner()!=null && context.owner() instanceof Player player && player){
|
||||
playerAndCharged=true;
|
||||
}*/
|
||||
if (context.owner() != null && target instanceof Player player && player.getInventory().getArmor(1).is(Items.ELYTRA)) {
|
||||
player.getCooldowns().addCooldown(Items.ELYTRA, (int)(20 * this.amount.calculate(level)) ); // Tick conversion
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull MapCodec<? extends EnchantmentEntityEffect> codec() {
|
||||
return CODEC;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue