添加卓越物品接口UI
This commit is contained in:
parent
b92c421b83
commit
42f38d53f9
5 changed files with 120 additions and 3 deletions
|
@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.block.entity;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.block.SuperbItemInterfaceBlock;
|
import com.atsuishio.superbwarfare.block.SuperbItemInterfaceBlock;
|
||||||
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
||||||
|
import com.atsuishio.superbwarfare.menu.SuperbItemInterfaceMenu;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.HolderLookup;
|
import net.minecraft.core.HolderLookup;
|
||||||
|
@ -31,7 +32,7 @@ public class SuperbItemInterfaceBlockEntity extends BaseContainerBlockEntity {
|
||||||
private NonNullList<ItemStack> items = NonNullList.withSize(CONTAINER_SIZE, ItemStack.EMPTY);
|
private NonNullList<ItemStack> items = NonNullList.withSize(CONTAINER_SIZE, ItemStack.EMPTY);
|
||||||
private int cooldownTime = -1;
|
private int cooldownTime = -1;
|
||||||
|
|
||||||
private Direction facing;
|
private final Direction facing;
|
||||||
|
|
||||||
|
|
||||||
public SuperbItemInterfaceBlockEntity(BlockPos pPos, BlockState pBlockState) {
|
public SuperbItemInterfaceBlockEntity(BlockPos pPos, BlockState pBlockState) {
|
||||||
|
@ -110,10 +111,9 @@ public class SuperbItemInterfaceBlockEntity extends BaseContainerBlockEntity {
|
||||||
return Component.translatable("container.superbwarfare.superb_item_interface");
|
return Component.translatable("container.superbwarfare.superb_item_interface");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 实现菜单
|
|
||||||
@Override
|
@Override
|
||||||
protected @NotNull AbstractContainerMenu createMenu(int pContainerId, @NotNull Inventory pInventory) {
|
protected @NotNull AbstractContainerMenu createMenu(int pContainerId, @NotNull Inventory pInventory) {
|
||||||
return null;
|
return new SuperbItemInterfaceMenu(pContainerId, pInventory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.atsuishio.superbwarfare.client.screens;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.menu.SuperbItemInterfaceMenu;
|
||||||
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.neoforged.api.distmarker.Dist;
|
||||||
|
import net.neoforged.api.distmarker.OnlyIn;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
public class SuperbItemInterfaceScreen extends AbstractContainerScreen<SuperbItemInterfaceMenu> {
|
||||||
|
private static final ResourceLocation HOPPER_LOCATION = ResourceLocation.withDefaultNamespace("textures/gui/container/hopper.png");
|
||||||
|
|
||||||
|
public SuperbItemInterfaceScreen(SuperbItemInterfaceMenu menu, Inventory playerInventory, Component title) {
|
||||||
|
super(menu, playerInventory, title);
|
||||||
|
this.imageHeight = 133;
|
||||||
|
this.inventoryLabelY = this.imageHeight - 94;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
|
||||||
|
super.render(guiGraphics, mouseX, mouseY, partialTick);
|
||||||
|
this.renderTooltip(guiGraphics, mouseX, mouseY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void renderBg(GuiGraphics guiGraphics, float partialTick, int mouseX, int mouseY) {
|
||||||
|
int i = (this.width - this.imageWidth) / 2;
|
||||||
|
int j = (this.height - this.imageHeight) / 2;
|
||||||
|
guiGraphics.blit(HOPPER_LOCATION, i, j, 0, 0, this.imageWidth, this.imageHeight);
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,6 +22,9 @@ public class ModMenuTypes {
|
||||||
public static final Supplier<MenuType<VehicleMenu>> VEHICLE_MENU =
|
public static final Supplier<MenuType<VehicleMenu>> VEHICLE_MENU =
|
||||||
REGISTRY.register("vehicle_menu",
|
REGISTRY.register("vehicle_menu",
|
||||||
() -> IMenuTypeExtension.create((windowId, inv, data) -> new VehicleMenu(windowId, inv)));
|
() -> IMenuTypeExtension.create((windowId, inv, data) -> new VehicleMenu(windowId, inv)));
|
||||||
|
public static final Supplier<MenuType<SuperbItemInterfaceMenu>> SUPERB_ITEM_INTERFACE_MENU =
|
||||||
|
REGISTRY.register("superb_item_interface_menu",
|
||||||
|
() -> IMenuTypeExtension.create((windowId, inv, data) -> new SuperbItemInterfaceMenu(windowId, inv)));
|
||||||
public static final Supplier<MenuType<FuMO25Menu>> FUMO_25_MENU =
|
public static final Supplier<MenuType<FuMO25Menu>> FUMO_25_MENU =
|
||||||
REGISTRY.register("fumo_25_menu",
|
REGISTRY.register("fumo_25_menu",
|
||||||
() -> IMenuTypeExtension.create((windowId, inv, data) -> new FuMO25Menu(windowId, inv)));
|
() -> IMenuTypeExtension.create((windowId, inv, data) -> new FuMO25Menu(windowId, inv)));
|
||||||
|
|
|
@ -15,6 +15,7 @@ public class ModScreens {
|
||||||
event.register(ModMenuTypes.REFORGING_TABLE_MENU.get(), ReforgingTableScreen::new);
|
event.register(ModMenuTypes.REFORGING_TABLE_MENU.get(), ReforgingTableScreen::new);
|
||||||
event.register(ModMenuTypes.CHARGING_STATION_MENU.get(), ChargingStationScreen::new);
|
event.register(ModMenuTypes.CHARGING_STATION_MENU.get(), ChargingStationScreen::new);
|
||||||
event.register(ModMenuTypes.VEHICLE_MENU.get(), VehicleScreen::new);
|
event.register(ModMenuTypes.VEHICLE_MENU.get(), VehicleScreen::new);
|
||||||
|
event.register(ModMenuTypes.SUPERB_ITEM_INTERFACE_MENU.get(), SuperbItemInterfaceScreen::new);
|
||||||
event.register(ModMenuTypes.FUMO_25_MENU.get(), FuMO25Screen::new);
|
event.register(ModMenuTypes.FUMO_25_MENU.get(), FuMO25Screen::new);
|
||||||
event.register(ModMenuTypes.DOG_TAG_EDITOR_MENU.get(), DogTagEditorScreen::new);
|
event.register(ModMenuTypes.DOG_TAG_EDITOR_MENU.get(), DogTagEditorScreen::new);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
package com.atsuishio.superbwarfare.menu;
|
||||||
|
|
||||||
|
import net.minecraft.world.Container;
|
||||||
|
import net.minecraft.world.SimpleContainer;
|
||||||
|
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.MenuType;
|
||||||
|
import net.minecraft.world.inventory.Slot;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class SuperbItemInterfaceMenu extends AbstractContainerMenu {
|
||||||
|
|
||||||
|
public static final int CONTAINER_SIZE = 5;
|
||||||
|
private final Container container;
|
||||||
|
|
||||||
|
public SuperbItemInterfaceMenu(int containerId, Inventory playerInventory) {
|
||||||
|
this(containerId, playerInventory, new SimpleContainer(CONTAINER_SIZE));
|
||||||
|
}
|
||||||
|
|
||||||
|
public SuperbItemInterfaceMenu(int containerId, Inventory playerInventory, Container container) {
|
||||||
|
super(MenuType.HOPPER, containerId);
|
||||||
|
this.container = container;
|
||||||
|
checkContainerSize(container, CONTAINER_SIZE);
|
||||||
|
container.startOpen(playerInventory.player);
|
||||||
|
|
||||||
|
for (int j = 0; j < CONTAINER_SIZE; j++) {
|
||||||
|
this.addSlot(new Slot(container, j, 44 + j * 18, 20));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int l = 0; l < 3; l++) {
|
||||||
|
for (int k = 0; k < 9; k++) {
|
||||||
|
this.addSlot(new Slot(playerInventory, k + l * 9 + 9, 8 + k * 18, l * 18 + 51));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i1 = 0; i1 < 9; i1++) {
|
||||||
|
this.addSlot(new Slot(playerInventory, i1, 8 + i1 * 18, 109));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean stillValid(@NotNull Player player) {
|
||||||
|
return this.container.stillValid(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ItemStack quickMoveStack(@NotNull Player player, int index) {
|
||||||
|
var stack = ItemStack.EMPTY;
|
||||||
|
var slot = this.slots.get(index);
|
||||||
|
if (slot.hasItem()) {
|
||||||
|
var slotItem = slot.getItem();
|
||||||
|
stack = slotItem.copy();
|
||||||
|
if (index < this.container.getContainerSize()) {
|
||||||
|
if (!this.moveItemStackTo(slotItem, this.container.getContainerSize(), this.slots.size(), true)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
} else if (!this.moveItemStackTo(slotItem, 0, this.container.getContainerSize(), false)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (slotItem.isEmpty()) {
|
||||||
|
slot.setByPlayer(ItemStack.EMPTY);
|
||||||
|
} else {
|
||||||
|
slot.setChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removed(@NotNull Player player) {
|
||||||
|
super.removed(player);
|
||||||
|
this.container.stopOpen(player);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue