Revise the vault menu

Adds a keybind to open the vaults
Fixes flight being disabled by the server on a relog
Adds a flight enchantment to boots and leggings (Tier 1 max)
DB Profile has additional column for flight as a boolean.
Network packet added for client to server to request the vault to open.

Added translation entries to en_us.json
This commit is contained in:
Tara 2023-01-23 00:04:59 -07:00
parent da5d53fb88
commit 91fdf78a57
21 changed files with 396 additions and 38 deletions

View file

@ -0,0 +1,99 @@
package dev.zontreck.otemod.enchantments;
import dev.zontreck.otemod.OTEMod;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Abilities;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;
import net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
public class FlightEnchantment extends Enchantment
{
@Mod.EventBusSubscriber(modid = OTEMod.MOD_ID, bus=Mod.EventBusSubscriber.Bus.FORGE)
public static class EventHandler{
@SubscribeEvent
public static void onLivingUpdate(LivingEquipmentChangeEvent ev)
{
if(ev.getEntity() instanceof Player)
{
if(ev.getEntity().level.isClientSide)return;
ServerPlayer sp = (ServerPlayer)ev.getEntity();
ItemStack feet = sp.getItemBySlot(EquipmentSlot.FEET);
ItemStack legs = sp.getItemBySlot(EquipmentSlot.LEGS);
boolean hasFlight = false;
if(feet.getEnchantmentLevel(ModEnchantments.FLIGHT_ENCHANTMENT.get())>0)hasFlight=true;
if(legs.getEnchantmentLevel(ModEnchantments.FLIGHT_ENCHANTMENT.get())>0)hasFlight=true;
Abilities playerAbilities = sp.getAbilities();
if(playerAbilities.mayfly == false)
{
if(hasFlight){
playerAbilities.mayfly=true;
sp.onUpdateAbilities();
}
}else {
if(!hasFlight){
playerAbilities.mayfly=false;
playerAbilities.flying=false;
sp.onUpdateAbilities();
}
}
}
}
}
public FlightEnchantment()
{
super(Rarity.RARE, EnchantmentCategory.ARMOR, new EquipmentSlot[] {EquipmentSlot.FEET, EquipmentSlot.LEGS});
}
@Override
public int getMaxLevel()
{
return 1;
}
@Override
public int getMinCost(int level)
{
return 28 + (level - 1) * 15;
}
@Override
public int getMaxCost(int level)
{
return this.getMinCost(level) + 15;
}
@Override
public boolean canApplyAtEnchantingTable(ItemStack stack)
{
return false;
}
@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 that can randomly happen if the enchantment level is now maxxed out.
@Override
public boolean isCurse()
{
return true;
}
}

View file

@ -17,7 +17,7 @@ public class MobEggEnchantment extends Enchantment
@Override
public int getMaxLevel()
{
return 4;
return 6;
}
@Override
@ -38,5 +38,21 @@ public class MobEggEnchantment extends Enchantment
{
return super.canApplyAtEnchantingTable(stack);
}
@Override
public boolean isTreasureOnly(){
return false;
}
@Override
public boolean isTradeable()
{
return true;
}
@Override
public boolean isDiscoverable()
{
return false;
}
}

View file

@ -12,6 +12,8 @@ public class ModEnchantments {
public static final RegistryObject<Enchantment> MOB_EGGING_ENCHANTMENT = REGISTERS.register("mob_egging", ()->new MobEggEnchantment());
public static final RegistryObject<Enchantment> FLIGHT_ENCHANTMENT = REGISTERS.register("player_flight", ()->new FlightEnchantment());
public static void register(IEventBus bus){
REGISTERS.register(bus);
}