Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic portable grid content #454

Merged
merged 4 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Added

- Custom disk models. Fluid disks now have a different model.
- Portable Grid

## [2.0.0-milestone.3.2] - 2023-11-03

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <T> void onChanged(
);

/**
* Called when the grid network has been changed.
* Usually called when the grid network has been changed.
*/
void onNetworkChanged();
void clear();
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public GridOperationsImpl(final StorageChannel<T> storageChannel,
}

@Override
public boolean extract(final T resource, final GridExtractMode extractMode,
public boolean extract(final T resource,
final GridExtractMode extractMode,
final InsertableStorage<T> destination) {
final long amount = getExtractableAmount(resource, extractMode);
if (amount == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
import java.util.HashMap;
import java.util.Map;

public class GridWatcherRegistration {
class GridWatcherRegistration {
private final GridWatcher watcher;
private final Class<? extends Actor> actorType;
private final Map<StorageChannelType<?>, ResourceListListener<?>> listeners = new HashMap<>();

public GridWatcherRegistration(final GridWatcher watcher, final Class<? extends Actor> actorType) {
GridWatcherRegistration(final GridWatcher watcher, final Class<? extends Actor> actorType) {
this.watcher = watcher;
this.actorType = actorType;
}

public <T> void attach(final StorageChannel<T> storageChannel, final StorageChannelType<T> storageChannelType) {
<T> void attach(final StorageChannel<T> storageChannel, final StorageChannelType<T> storageChannelType) {
final ResourceListListener<T> listener = change -> watcher.onChanged(
storageChannelType,
change.resourceAmount().getResource(),
Expand All @@ -34,7 +34,7 @@ public <T> void attach(final StorageChannel<T> storageChannel, final StorageChan
}

@SuppressWarnings("unchecked")
public <T> void detach(final StorageChannel<T> storageChannel, final StorageChannelType<T> storageChannelType) {
<T> void detach(final StorageChannel<T> storageChannel, final StorageChannelType<T> storageChannelType) {
final ResourceListListener<T> listener = (ResourceListListener<T>) listeners.get(storageChannelType);
storageChannel.removeListener(listener);
listeners.remove(storageChannelType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void addWatcher(

public void attachAll(final Network network) {
watchers.forEach((watcher, registration) -> {
watcher.onNetworkChanged();
watcher.clear();
attachAll(registration, network);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void shouldRespectPriorityWhenSplitting() {

// Here we ensure that container 4 (the grid) is initialized *after* container 3 (the storage),
// according to the priority declared above.
verify(watcher, times(1)).onNetworkChanged();
verify(watcher, times(1)).clear();
verify(watcher).onChanged(
NetworkTestFixtures.STORAGE_CHANNEL_TYPE,
"N3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void shouldDetachWatchersFromOldNetworkAndReattachToNewNetwork(
storageChannel.insert("D", 10, Action.EXECUTE, EmptyActor.INSTANCE);

// Assert
verify(watcher, times(1)).onNetworkChanged();
verify(watcher, times(1)).clear();

final ArgumentCaptor<TrackedResource> trackedResources1 = ArgumentCaptor.forClass(TrackedResource.class);
verify(watcher, times(1)).onChanged(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.storage.externalstorage.ExternalStorageBlockEntity;
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.PortableGridItem;
import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridLootItemFunctionSerializer;
import com.refinedmods.refinedstorage2.platform.common.storage.portablegrid.PortableGridType;
import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.FluidStorageBlock;
import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.FluidStorageBlockBlockEntity;
import com.refinedmods.refinedstorage2.platform.common.storage.storageblock.FluidStorageBlockBlockItem;
Expand Down Expand Up @@ -122,6 +127,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_PORTABLE_GRID;
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;
Expand All @@ -137,6 +143,7 @@
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.MACHINE_CASING;
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.NETWORK_RECEIVER;
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.NETWORK_TRANSMITTER;
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.PORTABLE_GRID;
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.PROCESSOR_BINDING;
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.QUARTZ_ENRICHED_IRON;
import static com.refinedmods.refinedstorage2.platform.common.content.ContentIds.QUARTZ_ENRICHED_IRON_BLOCK;
Expand Down Expand Up @@ -244,7 +251,9 @@ private void registerWirelessTransmitterRangeModifiers() {

protected final void registerBlocks(
final RegistryCallback<Block> callback,
final BiFunction<BlockPos, BlockState, AbstractDiskDriveBlockEntity> diskDriveBlockEntityFactory
final BiFunction<BlockPos, BlockState, AbstractDiskDriveBlockEntity> diskDriveBlockEntityFactory,
final BiFunction<BlockPos, BlockState, AbstractPortableGridBlockEntity> portableGridBlockEntityFactory,
final BiFunction<BlockPos, BlockState, AbstractPortableGridBlockEntity> creativePortableGridBlockEntityFactory
) {
Blocks.INSTANCE.setQuartzEnrichedIronBlock(callback.register(QUARTZ_ENRICHED_IRON_BLOCK, SimpleBlock::new));
Blocks.INSTANCE.setDiskDrive(
Expand Down Expand Up @@ -279,6 +288,14 @@ protected final void registerBlocks(
Blocks.INSTANCE.setStorageMonitor(callback.register(STORAGE_MONITOR, StorageMonitorBlock::new));
Blocks.INSTANCE.getNetworkReceiver().registerBlocks(callback);
Blocks.INSTANCE.getNetworkTransmitter().registerBlocks(callback);
Blocks.INSTANCE.setPortableGrid(callback.register(PORTABLE_GRID, () -> new PortableGridBlock(
PortableGridType.NORMAL,
portableGridBlockEntityFactory
)));
Blocks.INSTANCE.setCreativePortableGrid(callback.register(CREATIVE_PORTABLE_GRID, () -> new PortableGridBlock(
PortableGridType.CREATIVE,
creativePortableGridBlockEntityFactory
)));
}

protected final void registerItems(
Expand Down Expand Up @@ -310,6 +327,14 @@ 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.setCreativePortableGrid(callback.register(
CREATIVE_PORTABLE_GRID,
() -> new PortableGridItem(Blocks.INSTANCE.getCreativePortableGrid())
));
}

private void registerSimpleItems(final RegistryCallback<Item> callback) {
Expand Down Expand Up @@ -481,7 +506,11 @@ protected final void registerBlockEntities(
final RegistryCallback<BlockEntityType<?>> callback,
final BlockEntityTypeFactory typeFactory,
final BlockEntityTypeFactory.BlockEntitySupplier<? extends AbstractDiskDriveBlockEntity>
diskDriveBlockEntitySupplier
diskDriveBlockEntitySupplier,
final BlockEntityTypeFactory.BlockEntitySupplier<? extends AbstractPortableGridBlockEntity>
portableGridBlockEntitySupplier,
final BlockEntityTypeFactory.BlockEntitySupplier<? extends AbstractPortableGridBlockEntity>
creativePortableGridBlockEntitySupplier
) {
BlockEntities.INSTANCE.setCable(callback.register(
CABLE,
Expand Down Expand Up @@ -588,6 +617,17 @@ protected final void registerBlockEntities(
Blocks.INSTANCE.getNetworkTransmitter().toArray()
)
));
BlockEntities.INSTANCE.setPortableGrid(callback.register(
PORTABLE_GRID,
() -> typeFactory.create(portableGridBlockEntitySupplier::create, Blocks.INSTANCE.getPortableGrid())
));
BlockEntities.INSTANCE.setCreativePortableGrid(callback.register(
CREATIVE_PORTABLE_GRID,
() -> typeFactory.create(
creativePortableGridBlockEntitySupplier::create,
Blocks.INSTANCE.getCreativePortableGrid()
)
));
}

protected final void registerMenus(final RegistryCallback<MenuType<?>> callback,
Expand Down Expand Up @@ -671,6 +711,10 @@ protected final void registerLootFunctions(final RegistryCallback<LootItemFuncti
STORAGE_BLOCK,
() -> new LootItemFunctionType(new StorageBlockLootItemFunctionSerializer())
));
LootFunctions.INSTANCE.setPortableGrid(callback.register(
PORTABLE_GRID,
() -> new LootItemFunctionType(new PortableGridLootItemFunctionSerializer())
));
LootFunctions.INSTANCE.setEnergy(callback.register(
createIdentifier("energy"),
() -> new LootItemFunctionType(new EnergyLootItemFunctionSerializer())
Expand Down
Loading
Loading