Add a new requested enchantment

This commit is contained in:
zontreck 2024-04-02 13:22:57 -07:00
parent a1ddd055c4
commit 82b2f62d27
4 changed files with 88 additions and 0 deletions

View file

@ -27,6 +27,7 @@ public class EnchantmentEvents
FlightEnchantment.runEntityTick(sp); FlightEnchantment.runEntityTick(sp);
ConsumptionMending.onEntityTick(sp); ConsumptionMending.onEntityTick(sp);
NightVisionEnchantment.runEntityTick(sp); NightVisionEnchantment.runEntityTick(sp);
WaterBreathingEnchantment.runEntityTick(sp);
} }
TICKS=0; TICKS=0;

View file

@ -24,6 +24,7 @@ public class ModEnchantments {
public static final RegistryObject<Enchantment> NIGHT_VISION_ENCHANT = REGISTERS.register("night_vision", ()->new NightVisionEnchantment(EquipmentSlot.HEAD)); public static final RegistryObject<Enchantment> NIGHT_VISION_ENCHANT = REGISTERS.register("night_vision", ()->new NightVisionEnchantment(EquipmentSlot.HEAD));
public static final RegistryObject<Enchantment> WATER_BREATHING_ENCHANT = REGISTERS.register("water_breathing", ()->new NightVisionEnchantment(EquipmentSlot.HEAD));
public static void register(IEventBus bus){ public static void register(IEventBus bus){
REGISTERS.register(bus); REGISTERS.register(bus);

View file

@ -0,0 +1,84 @@
package dev.zontreck.otemod.enchantments;
import dev.zontreck.libzontreck.util.ItemUtils;
import dev.zontreck.libzontreck.util.ServerUtilities;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.configs.snbt.ServerConfig;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;
public class WaterBreathingEnchantment extends Enchantment
{
public WaterBreathingEnchantment(EquipmentSlot... slots)
{
super(Rarity.VERY_RARE, EnchantmentCategory.ARMOR_HEAD, slots);
}
@Override
public int getMaxLevel()
{
return 1;
}
@Override
public boolean isTreasureOnly(){
return true;
}
@Override
public boolean isTradeable()
{
return true;
}
// Not a bug. Flight is meant to be a permanent upgrade to a item. It is considered a curse due to unstable behavior. Flight will eat up durability and forge energy
// Flight should NOT be able to be removed via the grindstone
@Override
public boolean isCurse()
{
return false;
}
public static void runEntityTick(ServerPlayer sp)
{
if(ServerUtilities.isClient()) return;
if(ServerConfig.general.debug)
{
OTEMod.LOGGER.info("> WBreath Enchantment Tick <");
}
ItemStack feet = sp.getItemBySlot(EquipmentSlot.HEAD);
boolean hasNV = false;
if(ItemUtils.getEnchantmentLevel(ModEnchantments.WATER_BREATHING_ENCHANT.get(), feet)>0)hasNV=true;
if(hasNV)
{
MobEffectInstance inst = new MobEffectInstance(MobEffects.WATER_BREATHING, 60*20, 4, false, false, true);
MobEffectInstance existing = sp.getEffect(MobEffects.WATER_BREATHING);
if(existing != null)
{
if(existing.getDuration() <= (30*20))
{
sp.addEffect(inst);
return;
}else return;
}
sp.addEffect(inst);
}
}
}

View file

@ -146,6 +146,8 @@
"enchantment.otemod.borrowed_protection.desc": "Borrows protection from any nearby player.", "enchantment.otemod.borrowed_protection.desc": "Borrows protection from any nearby player.",
"enchantment.otemod.night_vision": "Night Vision", "enchantment.otemod.night_vision": "Night Vision",
"enchantment.otemod.night_vision.desc": "See in the dark!", "enchantment.otemod.night_vision.desc": "See in the dark!",
"enchantment.otemod.water_breathing": "Water Breathing",
"enchantment.otemod.water_breathing.desc": "Become one with the fishy",
"enchantment.otemod.consumption_mending": "Consumption Mending", "enchantment.otemod.consumption_mending": "Consumption Mending",
"enchantment.otemod.consumption_mending.desc": "Consumes items to repair durability. May consume curses.", "enchantment.otemod.consumption_mending.desc": "Consumes items to repair durability. May consume curses.",