Skip to content

Commit

Permalink
Merge pull request #472 from refinedmods/feat/GH-93/portable-grid-item
Browse files Browse the repository at this point in the history
feat: portable grid item
  • Loading branch information
raoulvdberge authored Feb 17, 2024
2 parents f29f89a + bca26d6 commit 80a9ef1
Show file tree
Hide file tree
Showing 34 changed files with 951 additions and 212 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.refinedmods.refinedstorage2.api.network.impl.energy;

import com.refinedmods.refinedstorage2.api.core.Action;
import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage;

public abstract class AbstractProxyEnergyStorage implements EnergyStorage {
private final EnergyStorage energyStorage;

public AbstractProxyEnergyStorage(final EnergyStorage energyStorage) {
this.energyStorage = energyStorage;
}

@Override
public long getStored() {
return energyStorage.getStored();
}

@Override
public long getCapacity() {
return energyStorage.getCapacity();
}

@Override
public long receive(final long amount, final Action action) {
return energyStorage.receive(amount, action);
}

@Override
public long extract(final long amount, final Action action) {
return energyStorage.extract(amount, action);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.refinedmods.refinedstorage2.api.network.impl.energy;

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

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class ProxyEnergyStorageTest {
AbstractProxyEnergyStorage sut;

@BeforeEach
void setUp() {
sut = new AbstractProxyEnergyStorage(new EnergyStorageImpl(100)) {
};
}

@Test
void testProxy() {
// Act
final long capacity = sut.getCapacity();
final long received = sut.receive(100, Action.EXECUTE);
final long extracted = sut.extract(15, Action.EXECUTE);
final long stored = sut.getStored();

// Assert
assertThat(capacity).isEqualTo(100);
assertThat(received).isEqualTo(100);
assertThat(extracted).isEqualTo(15);
assertThat(stored).isEqualTo(100 - 15);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ 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);
registration.register(Menus.INSTANCE.getPortableGridBlock(), PortableGridScreen::new);
registration.register(Menus.INSTANCE.getPortableGridItem(), PortableGridScreen::new);
}

protected static void registerAlternativeGridHints() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@
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.PortableGridBlockContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridBlockItem;
import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridItemContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridLootItemFunction;
import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridType;
import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.FluidStorageBlock;
Expand Down Expand Up @@ -304,7 +305,9 @@ protected final void registerItems(
final RegistryCallback<Item> callback,
final Supplier<RegulatorUpgradeItem> regulatorUpgradeItemSupplier,
final Supplier<WirelessGridItem> wirelessGridItemSupplier,
final Supplier<WirelessGridItem> creativeWirelessGridItemSupplier
final Supplier<WirelessGridItem> creativeWirelessGridItemSupplier,
final Supplier<PortableGridBlockItem> portableGridBlockItemSupplier,
final Supplier<PortableGridBlockItem> creativePortableGridBlockItemSupplier
) {
registerSimpleItems(callback);
Blocks.INSTANCE.getGrid().registerItems(callback);
Expand All @@ -329,13 +332,10 @@ protected final void registerItems(
creativeWirelessGridItemSupplier
));
callback.register(STORAGE_MONITOR, () -> new SimpleBlockItem(Blocks.INSTANCE.getStorageMonitor()));
Items.INSTANCE.setPortableGrid(callback.register(
PORTABLE_GRID,
() -> new PortableGridItem(Blocks.INSTANCE.getPortableGrid())
));
Items.INSTANCE.setPortableGrid(callback.register(PORTABLE_GRID, portableGridBlockItemSupplier));
Items.INSTANCE.setCreativePortableGrid(callback.register(
CREATIVE_PORTABLE_GRID,
() -> new PortableGridItem(Blocks.INSTANCE.getCreativePortableGrid())
creativePortableGridBlockItemSupplier
));
}

Expand Down Expand Up @@ -706,9 +706,13 @@ 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)
Menus.INSTANCE.setPortableGridBlock(callback.register(
createIdentifier("portable_grid_block"),
() -> menuTypeFactory.create(PortableGridBlockContainerMenu::new)
));
Menus.INSTANCE.setPortableGridItem(callback.register(
createIdentifier("portable_grid_item"),
() -> menuTypeFactory.create(PortableGridItemContainerMenu::new)
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private static void appendBlocks(final Consumer<ItemStack> consumer) {
appendBlockColors(consumer, Blocks.INSTANCE.getGrid());
appendBlockColors(consumer, Blocks.INSTANCE.getCraftingGrid());
itemConsumer.accept(Items.INSTANCE.getPortableGrid());
consumer.accept(Items.INSTANCE.getPortableGrid().createAtEnergyCapacity());
itemConsumer.accept(Items.INSTANCE.getCreativePortableGrid());
Items.INSTANCE.getDetectors().stream().map(Supplier::get).forEach(itemConsumer);
itemConsumer.accept(Blocks.INSTANCE.getInterface());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.refinedmods.refinedstorage2.platform.common.misc.ProcessorItem;
import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType;
import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType;
import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridBlockItem;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -87,9 +88,9 @@ public final class Items {
@Nullable
private Supplier<Item> networkCard;
@Nullable
private Supplier<Item> portableGrid;
private Supplier<PortableGridBlockItem> portableGrid;
@Nullable
private Supplier<Item> creativePortableGrid;
private Supplier<PortableGridBlockItem> creativePortableGrid;

private Items() {
}
Expand Down Expand Up @@ -398,19 +399,19 @@ public void setNetworkCard(final Supplier<Item> supplier) {
this.networkCard = supplier;
}

public Item getPortableGrid() {
public PortableGridBlockItem getPortableGrid() {
return requireNonNull(portableGrid).get();
}

public void setPortableGrid(final Supplier<Item> supplier) {
public void setPortableGrid(final Supplier<PortableGridBlockItem> supplier) {
this.portableGrid = supplier;
}

public Item getCreativePortableGrid() {
public PortableGridBlockItem getCreativePortableGrid() {
return requireNonNull(creativePortableGrid).get();
}

public void setCreativePortableGrid(final Supplier<Item> supplier) {
public void setCreativePortableGrid(final Supplier<PortableGridBlockItem> supplier) {
this.creativePortableGrid = supplier;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
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.portablegrid.PortableGridBlockContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridItemContainerMenu;
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;
Expand Down Expand Up @@ -67,7 +68,9 @@ public final class Menus {
@Nullable
private Supplier<MenuType<NetworkTransmitterContainerMenu>> networkTransmitter;
@Nullable
private Supplier<MenuType<PortableGridContainerMenu>> portableGrid;
private Supplier<MenuType<PortableGridBlockContainerMenu>> portableGridBlock;
@Nullable
private Supplier<MenuType<PortableGridItemContainerMenu>> portableGridItem;

private Menus() {
}
Expand Down Expand Up @@ -216,11 +219,19 @@ public void setNetworkTransmitter(final Supplier<MenuType<NetworkTransmitterCont
this.networkTransmitter = supplier;
}

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

public void setPortableGridBlock(final Supplier<MenuType<PortableGridBlockContainerMenu>> portableGridBlock) {
this.portableGridBlock = portableGridBlock;
}

public MenuType<PortableGridItemContainerMenu> getPortableGridItem() {
return requireNonNull(portableGridItem).get();
}

public void setPortableGrid(final Supplier<MenuType<PortableGridContainerMenu>> portableGrid) {
this.portableGrid = portableGrid;
public void setPortableGridItem(final Supplier<MenuType<PortableGridItemContainerMenu>> portableGridItem) {
this.portableGridItem = portableGridItem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public boolean canPlaceItem(final int slot, final ItemStack stack) {
public ItemStack removeItem(final int slot, final int amount) {
// Forge InvWrapper calls this instead of setItem.
final ItemStack result = super.removeItem(slot, amount);
listener.onDiskChanged(slot);
listener.onDiskChanged(this, slot);
return result;
}

@Override
public void setItem(final int slot, final ItemStack stack) {
super.setItem(slot, stack);
listener.onDiskChanged(slot);
listener.onDiskChanged(this, slot);
}

@Override
Expand Down Expand Up @@ -108,6 +108,6 @@ private StorageState getState(final CompoundTag tag) {

@FunctionalInterface
public interface DiskListener {
void onDiskChanged(int slot);
void onDiskChanged(DiskInventory inventory, int slot);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected AbstractDiskDriveBlockEntity(final BlockPos pos, final BlockState stat
PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getAll(),
AMOUNT_OF_DISKS
));
this.diskInventory = new DiskInventory(this::onDiskChanged, getNode().getSize());
this.diskInventory = new DiskInventory((inventory, slot) -> onDiskChanged(slot), getNode().getSize());
this.filter = FilterWithFuzzyMode.createAndListenForUniqueTemplates(
ResourceContainerImpl.createForFilter(),
this::setChanged,
Expand Down
Loading

0 comments on commit 80a9ef1

Please sign in to comment.