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

@ -31,15 +31,15 @@ public class VaultContainer
public MenuConstructor serverMenu;
public UUID owner;
private MinecraftServer server;
private final int VAULT_NUMBER;
public final int VAULT_NUMBER;
public final UUID VaultID;
public VaultContainer(ServerPlayer player, int vaultNum) {
myInventory = new ItemStackHandler(54); // Vaults have a fixed size at the same as a double chest
theContainer = new VaultMenu(player.containerCounter+1, player.getInventory(), myInventory, BlockPos.ZERO);
theContainer = new VaultMenu(player.containerCounter+1, player.getInventory(), myInventory, BlockPos.ZERO, player, vaultNum);
VaultID = theContainer.VaultMenuID;
owner = player.getUUID();
server=player.server;
serverMenu = theContainer.getServerMenu(myInventory);
serverMenu = theContainer.getServerMenu(myInventory, vaultNum);
VAULT_NUMBER=vaultNum;
if(VAULT_NUMBER == -1)return; // Trash ID

View file

@ -8,6 +8,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.inventory.MenuConstructor;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
@ -19,16 +20,20 @@ public class VaultMenu extends AbstractContainerMenu
{
//private final ContainerLevelAccess containerAccess;
public final UUID VaultMenuID;
public final Player thePlayer;
public final int VAULT_NUMBER;
public VaultMenu (int id, Inventory player)
{
this(id, player, new ItemStackHandler(54), BlockPos.ZERO);
this(id, player, new ItemStackHandler(54), BlockPos.ZERO, player.player, 0);
}
public VaultMenu (int id, Inventory player, IItemHandler slots, BlockPos pos)
public VaultMenu (int id, Inventory player, IItemHandler slots, BlockPos pos, Player play, int vaultNum)
{
super(ModMenuTypes.VAULT.get(), id);
thePlayer=play;
VaultMenuID=UUID.randomUUID();
VAULT_NUMBER=vaultNum;
//this.containerAccess = ContainerLevelAccess.create(player.player.level, pos);
final int slotSize = 18;
@ -104,8 +109,8 @@ public class VaultMenu extends AbstractContainerMenu
return true; // We have no block
}
public static MenuConstructor getServerMenu (ItemStackHandler inventory){
return (id, player, play) -> new VaultMenu(id, player, inventory, BlockPos.ZERO);
public static MenuConstructor getServerMenu (ItemStackHandler inventory, int vaultNum){
return (id, player, play) -> new VaultMenu(id, player, inventory, BlockPos.ZERO, player.player, vaultNum);
}

View file

@ -6,25 +6,39 @@ import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.commands.vaults.VaultCommand;
import dev.zontreck.otemod.networking.ModMessages;
import dev.zontreck.otemod.networking.packets.OpenVaultPacket;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.Button.OnPress;
import net.minecraft.client.gui.font.TextFieldHelper;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.network.NetworkHooks;
public class VaultScreen extends AbstractContainerScreen <VaultMenu>
{
// 176x224
public final UUID VaultMenuID;
public final Player thePlayer;
public final VaultMenu THE_CONTAINER;
private static final ResourceLocation TEXTURE = new ResourceLocation(OTEMod.MOD_ID, "textures/gui/vault.png");
public VaultScreen(VaultMenu container, Inventory playerInv, Component comp){
super(container, playerInv, comp);
thePlayer=playerInv.player;
this.VaultMenuID = container.VaultMenuID;
this.leftPos = 0;
this.topPos = 0;
this.THE_CONTAINER=container;
this.imageWidth = 207;
this.imageHeight = 238;
@ -54,6 +68,17 @@ public class VaultScreen extends AbstractContainerScreen <VaultMenu>
{
super.init();
// This is where custom controls would be added!
this.addWidget(new Button(this.leftPos+7,this.topPos+84,16,16,Component.literal(""), (button)->{
thePlayer.closeContainer();
ModMessages.sendToServer(new OpenVaultPacket(0,true,-1));
} ));
this.addWidget(new Button(this.leftPos+187,this.topPos+84,16,16,Component.literal(""), (button)->{
thePlayer.closeContainer();
ModMessages.sendToServer(new OpenVaultPacket(0, true, 1));
} ));
}
@Override