diff --git a/src/main/java/com/atsuishio/superbwarfare/block/entity/SuperbItemInterfaceBlockEntity.java b/src/main/java/com/atsuishio/superbwarfare/block/entity/SuperbItemInterfaceBlockEntity.java index 3a1a0cb52..b7ea7f968 100644 --- a/src/main/java/com/atsuishio/superbwarfare/block/entity/SuperbItemInterfaceBlockEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/block/entity/SuperbItemInterfaceBlockEntity.java @@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.block.entity; import com.atsuishio.superbwarfare.block.SuperbItemInterfaceBlock; import com.atsuishio.superbwarfare.init.ModBlockEntities; +import com.atsuishio.superbwarfare.menu.SuperbItemInterfaceMenu; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.HolderLookup; @@ -31,7 +32,7 @@ public class SuperbItemInterfaceBlockEntity extends BaseContainerBlockEntity { private NonNullList items = NonNullList.withSize(CONTAINER_SIZE, ItemStack.EMPTY); private int cooldownTime = -1; - private Direction facing; + private final Direction facing; public SuperbItemInterfaceBlockEntity(BlockPos pPos, BlockState pBlockState) { @@ -110,10 +111,9 @@ public class SuperbItemInterfaceBlockEntity extends BaseContainerBlockEntity { return Component.translatable("container.superbwarfare.superb_item_interface"); } - // TODO 实现菜单 @Override protected @NotNull AbstractContainerMenu createMenu(int pContainerId, @NotNull Inventory pInventory) { - return null; + return new SuperbItemInterfaceMenu(pContainerId, pInventory); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/client/screens/SuperbItemInterfaceScreen.java b/src/main/java/com/atsuishio/superbwarfare/client/screens/SuperbItemInterfaceScreen.java new file mode 100644 index 000000000..d14aa48f7 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/client/screens/SuperbItemInterfaceScreen.java @@ -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 { + 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); + } +} diff --git a/src/main/java/com/atsuishio/superbwarfare/init/ModMenuTypes.java b/src/main/java/com/atsuishio/superbwarfare/init/ModMenuTypes.java index 36042791d..d1558caf4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/init/ModMenuTypes.java +++ b/src/main/java/com/atsuishio/superbwarfare/init/ModMenuTypes.java @@ -22,6 +22,9 @@ public class ModMenuTypes { public static final Supplier> VEHICLE_MENU = REGISTRY.register("vehicle_menu", () -> IMenuTypeExtension.create((windowId, inv, data) -> new VehicleMenu(windowId, inv))); + public static final Supplier> SUPERB_ITEM_INTERFACE_MENU = + REGISTRY.register("superb_item_interface_menu", + () -> IMenuTypeExtension.create((windowId, inv, data) -> new SuperbItemInterfaceMenu(windowId, inv))); public static final Supplier> FUMO_25_MENU = REGISTRY.register("fumo_25_menu", () -> IMenuTypeExtension.create((windowId, inv, data) -> new FuMO25Menu(windowId, inv))); diff --git a/src/main/java/com/atsuishio/superbwarfare/init/ModScreens.java b/src/main/java/com/atsuishio/superbwarfare/init/ModScreens.java index 9218b2b7f..2c4326b7d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/init/ModScreens.java +++ b/src/main/java/com/atsuishio/superbwarfare/init/ModScreens.java @@ -15,6 +15,7 @@ public class ModScreens { event.register(ModMenuTypes.REFORGING_TABLE_MENU.get(), ReforgingTableScreen::new); event.register(ModMenuTypes.CHARGING_STATION_MENU.get(), ChargingStationScreen::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.DOG_TAG_EDITOR_MENU.get(), DogTagEditorScreen::new); } diff --git a/src/main/java/com/atsuishio/superbwarfare/menu/SuperbItemInterfaceMenu.java b/src/main/java/com/atsuishio/superbwarfare/menu/SuperbItemInterfaceMenu.java new file mode 100644 index 000000000..d7385e7fc --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/menu/SuperbItemInterfaceMenu.java @@ -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); + } +}