Skip to content

Commit

Permalink
feat: content for portable grid
Browse files Browse the repository at this point in the history
Block, recipe and models.
  • Loading branch information
raoulvdberge committed Dec 29, 2023
1 parent 3ce4d47 commit e24705a
Show file tree
Hide file tree
Showing 83 changed files with 1,972 additions and 327 deletions.
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 @@ -55,6 +55,10 @@
import com.refinedmods.refinedstorage2.platform.common.networking.NetworkReceiverBlockEntity;
import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterBlockEntity;
import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterContainerMenu;
import com.refinedmods.refinedstorage2.platform.common.portablegrid.AbstractPortableGridBlockEntity;
import com.refinedmods.refinedstorage2.platform.common.portablegrid.PortableGridBlock;
import com.refinedmods.refinedstorage2.platform.common.portablegrid.PortableGridItem;
import com.refinedmods.refinedstorage2.platform.common.portablegrid.PortableGridType;
import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType;
import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType;
import com.refinedmods.refinedstorage2.platform.common.storage.StorageTypes;
Expand Down Expand Up @@ -122,6 +126,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 +142,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 +250,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 +287,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 +326,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 +505,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 +616,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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.refinedmods.refinedstorage2.platform.common.importer.ImporterBlockEntity;
import com.refinedmods.refinedstorage2.platform.common.networking.NetworkReceiverBlockEntity;
import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterBlockEntity;
import com.refinedmods.refinedstorage2.platform.common.portablegrid.AbstractPortableGridBlockEntity;
import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType;
import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType;
import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.AbstractDiskDriveBlockEntity;
Expand All @@ -24,12 +25,13 @@

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

import net.minecraft.world.level.block.entity.BlockEntityType;

import static java.util.Objects.requireNonNull;

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

Expand Down Expand Up @@ -71,12 +73,16 @@ public final class BlockEntities {
private Supplier<BlockEntityType<NetworkReceiverBlockEntity>> networkReceiver;
@Nullable
private Supplier<BlockEntityType<NetworkTransmitterBlockEntity>> networkTransmitter;
@Nullable
private Supplier<BlockEntityType<AbstractPortableGridBlockEntity>> portableGrid;
@Nullable
private Supplier<BlockEntityType<AbstractPortableGridBlockEntity>> creativePortableGrid;

private BlockEntities() {
}

public BlockEntityType<NetworkNodeContainerBlockEntityImpl<SimpleNetworkNode>> getCable() {
return Objects.requireNonNull(cable).get();
return requireNonNull(cable).get();
}

public void setCable(
Expand All @@ -86,39 +92,39 @@ public void setCable(
}

public BlockEntityType<? extends AbstractDiskDriveBlockEntity> getDiskDrive() {
return Objects.requireNonNull(diskDrive).get();
return requireNonNull(diskDrive).get();
}

public void setDiskDrive(final Supplier<BlockEntityType<? extends AbstractDiskDriveBlockEntity>> supplier) {
this.diskDrive = supplier;
}

public BlockEntityType<GridBlockEntity> getGrid() {
return Objects.requireNonNull(grid).get();
return requireNonNull(grid).get();
}

public void setGrid(final Supplier<BlockEntityType<GridBlockEntity>> supplier) {
this.grid = supplier;
}

public BlockEntityType<CraftingGridBlockEntity> getCraftingGrid() {
return Objects.requireNonNull(craftingGrid).get();
return requireNonNull(craftingGrid).get();
}

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

public BlockEntityType<ControllerBlockEntity> getController() {
return Objects.requireNonNull(controller).get();
return requireNonNull(controller).get();
}

public void setController(final Supplier<BlockEntityType<ControllerBlockEntity>> supplier) {
this.controller = supplier;
}

public BlockEntityType<ControllerBlockEntity> getCreativeController() {
return Objects.requireNonNull(creativeController).get();
return requireNonNull(creativeController).get();
}

public void setCreativeController(final Supplier<BlockEntityType<ControllerBlockEntity>> supplier) {
Expand All @@ -144,92 +150,106 @@ public BlockEntityType<FluidStorageBlockBlockEntity> getFluidStorageBlock(final
}

public BlockEntityType<ImporterBlockEntity> getImporter() {
return Objects.requireNonNull(importer).get();
return requireNonNull(importer).get();
}

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

public BlockEntityType<ExporterBlockEntity> getExporter() {
return Objects.requireNonNull(exporter).get();
return requireNonNull(exporter).get();
}

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

public BlockEntityType<InterfaceBlockEntity> getInterface() {
return Objects.requireNonNull(iface).get();
return requireNonNull(iface).get();
}

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

public BlockEntityType<ExternalStorageBlockEntity> getExternalStorage() {
return Objects.requireNonNull(externalStorage).get();
return requireNonNull(externalStorage).get();
}

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

public BlockEntityType<DetectorBlockEntity> getDetector() {
return Objects.requireNonNull(detector).get();
return requireNonNull(detector).get();
}

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

public BlockEntityType<DestructorBlockEntity> getDestructor() {
return Objects.requireNonNull(destructor).get();
return requireNonNull(destructor).get();
}

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

public BlockEntityType<ConstructorBlockEntity> getConstructor() {
return Objects.requireNonNull(constructor).get();
return requireNonNull(constructor).get();
}

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

public BlockEntityType<WirelessTransmitterBlockEntity> getWirelessTransmitter() {
return Objects.requireNonNull(wirelessTransmitter).get();
return requireNonNull(wirelessTransmitter).get();
}

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

public BlockEntityType<StorageMonitorBlockEntity> getStorageMonitor() {
return Objects.requireNonNull(storageMonitor).get();
return requireNonNull(storageMonitor).get();
}

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

public BlockEntityType<NetworkReceiverBlockEntity> getNetworkReceiver() {
return Objects.requireNonNull(networkReceiver).get();
return requireNonNull(networkReceiver).get();
}

public void setNetworkReceiver(final Supplier<BlockEntityType<NetworkReceiverBlockEntity>> supplier) {
this.networkReceiver = supplier;
}

public BlockEntityType<NetworkTransmitterBlockEntity> getNetworkTransmitter() {
return Objects.requireNonNull(networkTransmitter).get();
return requireNonNull(networkTransmitter).get();
}

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

public BlockEntityType<AbstractPortableGridBlockEntity> getPortableGrid() {
return requireNonNull(portableGrid).get();
}

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

public BlockEntityType<AbstractPortableGridBlockEntity> getCreativePortableGrid() {
return requireNonNull(creativePortableGrid).get();
}

public void setCreativePortableGrid(final Supplier<BlockEntityType<AbstractPortableGridBlockEntity>> supplier) {
this.creativePortableGrid = supplier;
}
}
Loading

0 comments on commit e24705a

Please sign in to comment.