Skip to content

Commit

Permalink
feat: storage monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed Oct 30, 2023
1 parent 08463b3 commit 7602449
Show file tree
Hide file tree
Showing 96 changed files with 2,492 additions and 944 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- "Open Wireless Grid" keybinding.
- Curios integration on Forge.
- Trinkets integration on Fabric.
- Storage Monitor

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer;
import com.refinedmods.refinedstorage2.platform.api.blockentity.constructor.ConstructorStrategyFactory;
import com.refinedmods.refinedstorage2.platform.api.blockentity.destructor.DestructorStrategyFactory;
import com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor.StorageMonitorExtractionStrategy;
import com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor.StorageMonitorInsertionStrategy;
import com.refinedmods.refinedstorage2.platform.api.blockentity.wirelesstransmitter.WirelessTransmitterRangeModifier;
import com.refinedmods.refinedstorage2.platform.api.grid.Grid;
import com.refinedmods.refinedstorage2.platform.api.grid.GridExtractionStrategy;
Expand Down Expand Up @@ -81,6 +83,14 @@ public interface PlatformApi {

void addConstructorStrategyFactory(ConstructorStrategyFactory factory);

void addStorageMonitorExtractionStrategy(StorageMonitorExtractionStrategy strategy);

StorageMonitorExtractionStrategy getStorageMonitorExtractionStrategy();

void addStorageMonitorInsertionStrategy(StorageMonitorInsertionStrategy strategy);

StorageMonitorInsertionStrategy getStorageMonitorInsertionStrategy();

MutableComponent createTranslation(String category, String value, Object... args);

ComponentMapFactory<NetworkComponent, Network> getNetworkComponentMapFactory();
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor;

import com.refinedmods.refinedstorage2.api.network.Network;
import com.refinedmods.refinedstorage2.api.storage.Actor;

import net.minecraft.world.entity.player.Player;
import org.apiguardian.api.API;

@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1")
@FunctionalInterface
public interface StorageMonitorExtractionStrategy {
boolean extract(Object resource, boolean fullStack, Player player, Actor actor, Network network);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor;

import com.refinedmods.refinedstorage2.api.network.Network;
import com.refinedmods.refinedstorage2.api.storage.Actor;

import java.util.Optional;

import net.minecraft.world.item.ItemStack;
import org.apiguardian.api.API;

@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.1")
@FunctionalInterface
public interface StorageMonitorInsertionStrategy {
Optional<ItemStack> insert(Object configuredResource, ItemStack stack, Actor actor, Network network);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@ParametersAreNonnullByDefault
@FieldsAndMethodsAreNonnullByDefault
package com.refinedmods.refinedstorage2.platform.api.blockentity.storagemonitor;

import com.refinedmods.refinedstorage2.api.core.FieldsAndMethodsAreNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@

import java.util.List;

import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.Level;
import org.apiguardian.api.API;

@API(status = API.Status.STABLE, since = "2.0.0-milestone.2.13")
public interface ResourceRendering<T> {
String getDisplayedAmount(long amount);
String getDisplayedAmount(long amount, boolean withUnits);

Component getDisplayName(T resource);

List<Component> getTooltip(T resource);

void render(T resource, GuiGraphics graphics, int x, int y);

void render(T resource, PoseStack poseStack, MultiBufferSource renderTypeBuffer, int light, Level level);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.refinedmods.refinedstorage2.platform.common.screen.InterfaceScreen;
import com.refinedmods.refinedstorage2.platform.common.screen.ItemStorageBlockScreen;
import com.refinedmods.refinedstorage2.platform.common.screen.RegulatorUpgradeScreen;
import com.refinedmods.refinedstorage2.platform.common.screen.StorageMonitorScreen;
import com.refinedmods.refinedstorage2.platform.common.screen.WirelessTransmitterScreen;
import com.refinedmods.refinedstorage2.platform.common.screen.amount.DetectorScreen;
import com.refinedmods.refinedstorage2.platform.common.screen.grid.CraftingGridScreen;
Expand Down Expand Up @@ -55,6 +56,7 @@ protected static void registerScreens(final ScreenRegistration registration) {
registration.register(Menus.INSTANCE.getConstructor(), ConstructorScreen::new);
registration.register(Menus.INSTANCE.getRegulatorUpgrade(), RegulatorUpgradeScreen::new);
registration.register(Menus.INSTANCE.getWirelessTransmitter(), WirelessTransmitterScreen::new);
registration.register(Menus.INSTANCE.getStorageMonitor(), StorageMonitorScreen::new);
}

protected static void registerAlternativeGridHints() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.refinedmods.refinedstorage2.platform.common.block.InterfaceBlock;
import com.refinedmods.refinedstorage2.platform.common.block.ItemStorageBlock;
import com.refinedmods.refinedstorage2.platform.common.block.SimpleBlock;
import com.refinedmods.refinedstorage2.platform.common.block.StorageMonitorBlock;
import com.refinedmods.refinedstorage2.platform.common.block.entity.CableBlockEntity;
import com.refinedmods.refinedstorage2.platform.common.block.entity.ControllerBlockEntity;
import com.refinedmods.refinedstorage2.platform.common.block.entity.ImporterBlockEntity;
Expand All @@ -34,6 +35,11 @@
import com.refinedmods.refinedstorage2.platform.common.block.entity.iface.InterfaceBlockEntity;
import com.refinedmods.refinedstorage2.platform.common.block.entity.storage.FluidStorageBlockBlockEntity;
import com.refinedmods.refinedstorage2.platform.common.block.entity.storage.ItemStorageBlockBlockEntity;
import com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor.FluidStorageMonitorExtractionStrategy;
import com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor.FluidStorageMonitorInsertionStrategy;
import com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor.ItemStorageMonitorExtractionStrategy;
import com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor.ItemStorageMonitorInsertionStrategy;
import com.refinedmods.refinedstorage2.platform.common.block.entity.storagemonitor.StorageMonitorBlockEntity;
import com.refinedmods.refinedstorage2.platform.common.block.entity.wirelesstransmitter.BaseWirelessTransmitterRangeModifier;
import com.refinedmods.refinedstorage2.platform.common.block.entity.wirelesstransmitter.CreativeRangeUpgradeWirelessTransmitterRangeModifier;
import com.refinedmods.refinedstorage2.platform.common.block.entity.wirelesstransmitter.RangeUpgradeWirelessTransmitterRangeModifier;
Expand All @@ -45,6 +51,7 @@
import com.refinedmods.refinedstorage2.platform.common.containermenu.ImporterContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.containermenu.InterfaceContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.containermenu.RegulatorUpgradeContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.containermenu.StorageMonitorContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.containermenu.WirelessTransmitterContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.containermenu.detector.DetectorContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.containermenu.grid.CraftingGridContainerMenu;
Expand Down Expand Up @@ -108,6 +115,7 @@
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.CONTROLLER;
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.CRAFTING_GRID;
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.CREATIVE_CONTROLLER;
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.CREATIVE_WIRELESS_GRID;
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.DESTRUCTION_CORE;
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.DESTRUCTOR;
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.DETECTOR;
Expand All @@ -127,6 +135,7 @@
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.SILICON;
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.STORAGE_BLOCK;
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.STORAGE_HOUSING;
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.STORAGE_MONITOR;
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.WIRELESS_GRID;
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.WIRELESS_TRANSMITTER;
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.WRENCH;
Expand All @@ -153,6 +162,8 @@ protected final void initializePlatformApi() {
registerAdditionalResourceFactories();
registerDestructorStrategyFactories();
registerConstructorStrategyFactories();
registerStorageMonitorInsertionStrategies();
registerStorageMonitorExtractionStrategies();
registerNetworkComponents();
registerWirelessTransmitterRangeModifiers();
}
Expand Down Expand Up @@ -191,6 +202,16 @@ private void registerConstructorStrategyFactories() {
PlatformApi.INSTANCE.addConstructorStrategyFactory(new ItemDropConstructorStrategyFactory());
}

private void registerStorageMonitorInsertionStrategies() {
PlatformApi.INSTANCE.addStorageMonitorInsertionStrategy(new ItemStorageMonitorInsertionStrategy());
PlatformApi.INSTANCE.addStorageMonitorInsertionStrategy(new FluidStorageMonitorInsertionStrategy());
}

private void registerStorageMonitorExtractionStrategies() {
PlatformApi.INSTANCE.addStorageMonitorExtractionStrategy(new ItemStorageMonitorExtractionStrategy());
PlatformApi.INSTANCE.addStorageMonitorExtractionStrategy(new FluidStorageMonitorExtractionStrategy());
}

private void registerNetworkComponents() {
PlatformApi.INSTANCE.getNetworkComponentMapFactory().addFactory(
EnergyNetworkComponent.class,
Expand Down Expand Up @@ -250,6 +271,7 @@ protected final void registerBlocks(
Blocks.INSTANCE.getDestructor().registerBlocks(callback);
Blocks.INSTANCE.setInterface(callback.register(INTERFACE, InterfaceBlock::new));
Blocks.INSTANCE.getWirelessTransmitter().registerBlocks(callback);
Blocks.INSTANCE.setStorageMonitor(callback.register(STORAGE_MONITOR, StorageMonitorBlock::new));
}

protected final void registerItems(
Expand All @@ -273,11 +295,12 @@ protected final void registerItems(
Blocks.INSTANCE.getWirelessTransmitter().registerItems(callback, Items.INSTANCE::addWirelessTransmitter);
registerStorageItems(callback);
registerUpgrades(callback, regulatorUpgradeItemSupplier);
Items.INSTANCE.setWirelessGrid(callback.register(ContentIds.WIRELESS_GRID, wirelessGridItemSupplier));
Items.INSTANCE.setWirelessGrid(callback.register(WIRELESS_GRID, wirelessGridItemSupplier));
Items.INSTANCE.setCreativeWirelessGrid(callback.register(
ContentIds.CREATIVE_WIRELESS_GRID,
CREATIVE_WIRELESS_GRID,
creativeWirelessGridItemSupplier
));
callback.register(STORAGE_MONITOR, () -> new SimpleBlockItem(Blocks.INSTANCE.getStorageMonitor()));
}

private void registerSimpleItems(final RegistryCallback<Item> callback) {
Expand Down Expand Up @@ -531,6 +554,10 @@ protected final void registerBlockEntities(
Blocks.INSTANCE.getWirelessTransmitter().toArray()
)
));
BlockEntities.INSTANCE.setStorageMonitor(callback.register(
STORAGE_MONITOR,
() -> typeFactory.create(StorageMonitorBlockEntity::new, Blocks.INSTANCE.getStorageMonitor())
));
}

protected final void registerMenus(final RegistryCallback<MenuType<?>> callback,
Expand Down Expand Up @@ -599,6 +626,10 @@ protected final void registerMenus(final RegistryCallback<MenuType<?>> callback,
WIRELESS_TRANSMITTER,
() -> menuTypeFactory.create(WirelessTransmitterContainerMenu::new)
));
Menus.INSTANCE.setStorageMonitor(callback.register(
STORAGE_MONITOR,
() -> menuTypeFactory.create(StorageMonitorContainerMenu::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,8 @@ public interface Config {

WirelessTransmitterEntry getWirelessTransmitter();

SimpleEnergyUsageEntry getStorageMonitor();

interface SimpleEnergyUsageEntry {
long getEnergyUsage();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.refinedmods.refinedstorage2.platform.common;

import com.refinedmods.refinedstorage2.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource;

import net.minecraft.world.item.ItemStack;

public record ContainedFluid(ItemStack remainderContainer, ResourceAmount<FluidResource> fluid) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.refinedmods.refinedstorage2.api.core.Action;
import com.refinedmods.refinedstorage2.api.grid.view.GridResourceFactory;
import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage;
import com.refinedmods.refinedstorage2.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage2.platform.api.grid.GridInsertionStrategyFactory;
import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource;
import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource;
Expand Down Expand Up @@ -74,7 +73,7 @@ public interface Platform {

FluidRenderer getFluidRenderer();

Optional<ResourceAmount<FluidResource>> convertToFluid(ItemStack stack);
Optional<ContainedFluid> getContainedFluid(ItemStack stack);

Optional<FluidResource> convertJeiIngredientToFluid(Object ingredient);

Expand Down
Loading

0 comments on commit 7602449

Please sign in to comment.