Skip to content

Commit

Permalink
Menu WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed Dec 30, 2023
1 parent bc8bca8 commit 4d86e64
Show file tree
Hide file tree
Showing 23 changed files with 371 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -97,6 +98,8 @@ public interface PlatformApi {

PlatformRegistry<GridSynchronizer> getGridSynchronizerRegistry();

MenuProvider getGridMenuProvider(Grid grid, MenuProvider menuProvider);

UpgradeRegistry getUpgradeRegistry();

BuiltinUpgradeDestinations getBuiltinUpgradeDestinations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -161,6 +162,11 @@ public PlatformRegistry<GridSynchronizer> getGridSynchronizerRegistry() {
return ensureLoaded().getGridSynchronizerRegistry();
}

@Override
public MenuProvider getGridMenuProvider(final Grid grid, final MenuProvider menuProvider) {
return ensureLoaded().getGridMenuProvider(grid, menuProvider);
}

@Override
public UpgradeRegistry getUpgradeRegistry() {
return ensureLoaded().getUpgradeRegistry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType;
import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveScreen;
import com.refinedmods.refinedstorage2.platform.common.storage.externalstorage.ExternalStorageScreen;
import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridScreen;
import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.FluidStorageBlockScreen;
import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.ItemStorageBlockScreen;
import com.refinedmods.refinedstorage2.platform.common.storagemonitor.StorageMonitorScreen;
Expand Down Expand Up @@ -64,6 +65,7 @@ protected static void registerScreens(final ScreenRegistration registration) {
registration.register(Menus.INSTANCE.getWirelessTransmitter(), WirelessTransmitterScreen::new);
registration.register(Menus.INSTANCE.getStorageMonitor(), StorageMonitorScreen::new);
registration.register(Menus.INSTANCE.getNetworkTransmitter(), NetworkTransmitterScreen::new);
registration.register(Menus.INSTANCE.getPortableGrid(), PortableGridScreen::new);
}

protected static void registerAlternativeGridHints() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import com.refinedmods.refinedstorage2.platform.common.storage.externalstorage.ExternalStorageContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.AbstractPortableGridBlockEntity;
import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridBlock;
import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridItem;
import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridLootItemFunctionSerializer;
import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridType;
Expand Down Expand Up @@ -704,6 +705,10 @@ protected final void registerMenus(final RegistryCallback<MenuType<?>> callback,
NETWORK_TRANSMITTER,
() -> menuTypeFactory.create(NetworkTransmitterContainerMenu::new)
));
Menus.INSTANCE.setPortableGrid(callback.register(
PORTABLE_GRID,
() -> menuTypeFactory.create(PortableGridContainerMenu::new)
));
}

protected final void registerLootFunctions(final RegistryCallback<LootItemFunctionType> callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.refinedmods.refinedstorage2.platform.api.upgrade.BuiltinUpgradeDestinations;
import com.refinedmods.refinedstorage2.platform.api.upgrade.UpgradeRegistry;
import com.refinedmods.refinedstorage2.platform.api.wirelesstransmitter.WirelessTransmitterRangeModifier;
import com.refinedmods.refinedstorage2.platform.common.grid.GridExtendedMenuProvider;
import com.refinedmods.refinedstorage2.platform.common.grid.NoOpGridSynchronizer;
import com.refinedmods.refinedstorage2.platform.common.grid.screen.hint.GridInsertionHintsImpl;
import com.refinedmods.refinedstorage2.platform.common.grid.screen.hint.ItemGridInsertionHint;
Expand Down Expand Up @@ -95,6 +96,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -277,6 +279,15 @@ public PlatformRegistry<GridSynchronizer> getGridSynchronizerRegistry() {
return gridSynchronizerRegistry;
}

@Override
public MenuProvider getGridMenuProvider(final Grid grid, final MenuProvider menuProvider) {
return new GridExtendedMenuProvider(
grid,
storageChannelTypeRegistry,
menuProvider
);
}

@Override
public UpgradeRegistry getUpgradeRegistry() {
return upgradeRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public final class ContentNames {
public static final MutableComponent DISK_DRIVE = createTranslation("block", "disk_drive");
public static final MutableComponent NETWORK_RECEIVER = createTranslation("block", "network_receiver");
public static final MutableComponent NETWORK_TRANSMITTER = createTranslation("block", "network_transmitter");
public static final MutableComponent PORTABLE_GRID = createTranslation("block", "portable_grid");

private ContentNames() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@
import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.storage.externalstorage.ExternalStorageContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.FluidStorageBlockContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.ItemStorageBlockContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.storagemonitor.StorageMonitorContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.upgrade.RegulatorUpgradeContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.wirelesstransmitter.WirelessTransmitterContainerMenu;

import java.util.Objects;
import java.util.function.Supplier;
import javax.annotation.Nullable;

import net.minecraft.world.inventory.MenuType;

import static java.util.Objects.requireNonNull;

public final class Menus {
public static final Menus INSTANCE = new Menus();

Expand Down Expand Up @@ -64,36 +66,38 @@ public final class Menus {
private Supplier<MenuType<StorageMonitorContainerMenu>> storageMonitor;
@Nullable
private Supplier<MenuType<NetworkTransmitterContainerMenu>> networkTransmitter;
@Nullable
private Supplier<MenuType<PortableGridContainerMenu>> portableGrid;

private Menus() {
}

public MenuType<DiskDriveContainerMenu> getDiskDrive() {
return Objects.requireNonNull(diskDrive).get();
return requireNonNull(diskDrive).get();
}

public MenuType<GridContainerMenu> getGrid() {
return Objects.requireNonNull(grid).get();
return requireNonNull(grid).get();
}

public MenuType<CraftingGridContainerMenu> getCraftingGrid() {
return Objects.requireNonNull(craftingGrid).get();
return requireNonNull(craftingGrid).get();
}

public void setCraftingGrid(final Supplier<MenuType<CraftingGridContainerMenu>> supplier) {
this.craftingGrid = supplier;
}

public MenuType<WirelessGridContainerMenu> getWirelessGrid() {
return Objects.requireNonNull(wirelessGrid).get();
return requireNonNull(wirelessGrid).get();
}

public void setWirelessGrid(final Supplier<MenuType<WirelessGridContainerMenu>> supplier) {
this.wirelessGrid = supplier;
}

public MenuType<ControllerContainerMenu> getController() {
return Objects.requireNonNull(controller).get();
return requireNonNull(controller).get();
}

public void setDiskDrive(final Supplier<MenuType<DiskDriveContainerMenu>> supplier) {
Expand All @@ -109,106 +113,114 @@ public void setController(final Supplier<MenuType<ControllerContainerMenu>> supp
}

public MenuType<ItemStorageBlockContainerMenu> getItemStorage() {
return Objects.requireNonNull(itemStorage).get();
return requireNonNull(itemStorage).get();
}

public void setItemStorage(final Supplier<MenuType<ItemStorageBlockContainerMenu>> supplier) {
this.itemStorage = supplier;
}

public MenuType<FluidStorageBlockContainerMenu> getFluidStorage() {
return Objects.requireNonNull(fluidStorage).get();
return requireNonNull(fluidStorage).get();
}

public void setFluidStorage(final Supplier<MenuType<FluidStorageBlockContainerMenu>> supplier) {
this.fluidStorage = supplier;
}

public MenuType<ImporterContainerMenu> getImporter() {
return Objects.requireNonNull(importer).get();
return requireNonNull(importer).get();
}

public void setImporter(final Supplier<MenuType<ImporterContainerMenu>> supplier) {
this.importer = supplier;
}

public MenuType<ExporterContainerMenu> getExporter() {
return Objects.requireNonNull(exporter).get();
return requireNonNull(exporter).get();
}

public void setExporter(final Supplier<MenuType<ExporterContainerMenu>> supplier) {
this.exporter = supplier;
}

public MenuType<InterfaceContainerMenu> getInterface() {
return Objects.requireNonNull(iface).get();
return requireNonNull(iface).get();
}

public void setInterface(final Supplier<MenuType<InterfaceContainerMenu>> supplier) {
this.iface = supplier;
}

public MenuType<ExternalStorageContainerMenu> getExternalStorage() {
return Objects.requireNonNull(externalStorage).get();
return requireNonNull(externalStorage).get();
}

public void setExternalStorage(final Supplier<MenuType<ExternalStorageContainerMenu>> supplier) {
this.externalStorage = supplier;
}

public MenuType<DetectorContainerMenu> getDetector() {
return Objects.requireNonNull(detector).get();
return requireNonNull(detector).get();
}

public void setDetector(final Supplier<MenuType<DetectorContainerMenu>> supplier) {
this.detector = supplier;
}

public MenuType<DestructorContainerMenu> getDestructor() {
return Objects.requireNonNull(destructor).get();
return requireNonNull(destructor).get();
}

public void setDestructor(final Supplier<MenuType<DestructorContainerMenu>> supplier) {
this.destructor = supplier;
}

public MenuType<ConstructorContainerMenu> getConstructor() {
return Objects.requireNonNull(constructor).get();
return requireNonNull(constructor).get();
}

public void setConstructor(final Supplier<MenuType<ConstructorContainerMenu>> supplier) {
this.constructor = supplier;
}

public MenuType<RegulatorUpgradeContainerMenu> getRegulatorUpgrade() {
return Objects.requireNonNull(regulatorUpgrade).get();
return requireNonNull(regulatorUpgrade).get();
}

public void setRegulatorUpgrade(final Supplier<MenuType<RegulatorUpgradeContainerMenu>> supplier) {
this.regulatorUpgrade = supplier;
}

public MenuType<WirelessTransmitterContainerMenu> getWirelessTransmitter() {
return Objects.requireNonNull(wirelessTransmitter).get();
return requireNonNull(wirelessTransmitter).get();
}

public void setWirelessTransmitter(final Supplier<MenuType<WirelessTransmitterContainerMenu>> supplier) {
this.wirelessTransmitter = supplier;
}

public MenuType<StorageMonitorContainerMenu> getStorageMonitor() {
return Objects.requireNonNull(storageMonitor).get();
return requireNonNull(storageMonitor).get();
}

public void setStorageMonitor(final Supplier<MenuType<StorageMonitorContainerMenu>> supplier) {
this.storageMonitor = supplier;
}

public MenuType<NetworkTransmitterContainerMenu> getNetworkTransmitter() {
return Objects.requireNonNull(networkTransmitter).get();
return requireNonNull(networkTransmitter).get();
}

public void setNetworkTransmitter(final Supplier<MenuType<NetworkTransmitterContainerMenu>> supplier) {
this.networkTransmitter = supplier;
}

public MenuType<PortableGridContainerMenu> getPortableGrid() {
return requireNonNull(portableGrid).get();
}

public void setPortableGrid(final Supplier<MenuType<PortableGridContainerMenu>> portableGrid) {
this.portableGrid = portableGrid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ public boolean canAlwaysConnect() {
public MenuProvider getMenuProvider(final BlockState state, final Level level, final BlockPos pos) {
final BlockEntity blockEntity = level.getBlockEntity(pos);
if (blockEntity instanceof Grid grid && blockEntity instanceof MenuProvider menuProvider) {
return new GridExtendedMenuProvider(
grid,
PlatformApi.INSTANCE.getStorageChannelTypeRegistry(),
menuProvider
);
return PlatformApi.INSTANCE.getGridMenuProvider(grid, menuProvider);
}
return null;
}
Expand Down
Loading

0 comments on commit 4d86e64

Please sign in to comment.