Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed Dec 27, 2023
1 parent 3e6d61c commit 9457191
Show file tree
Hide file tree
Showing 46 changed files with 1,108 additions and 61 deletions.
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,9 @@
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.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 +125,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 +141,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 @@ -279,6 +284,12 @@ 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
)));
Blocks.INSTANCE.setCreativePortableGrid(callback.register(CREATIVE_PORTABLE_GRID, () -> new PortableGridBlock(
PortableGridType.CREATIVE
)));
}

protected final void registerItems(
Expand Down Expand Up @@ -310,6 +321,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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.refinedmods.refinedstorage2.platform.common.networking.CableBlock;
import com.refinedmods.refinedstorage2.platform.common.networking.NetworkReceiverBlock;
import com.refinedmods.refinedstorage2.platform.common.networking.NetworkTransmitterBlock;
import com.refinedmods.refinedstorage2.platform.common.portablegrid.PortableGridBlock;
import com.refinedmods.refinedstorage2.platform.common.storage.FluidStorageType;
import com.refinedmods.refinedstorage2.platform.common.storage.ItemStorageType;
import com.refinedmods.refinedstorage2.platform.common.storage.diskdrive.DiskDriveBlock;
Expand All @@ -26,12 +27,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.item.DyeColor;

import static java.util.Objects.requireNonNull;

public final class Blocks {
public static final DyeColor COLOR = DyeColor.LIGHT_BLUE;
public static final DyeColor CABLE_LIKE_COLOR = DyeColor.GRAY;
Expand Down Expand Up @@ -146,6 +148,10 @@ public final class Blocks {
private Supplier<InterfaceBlock> iface;
@Nullable
private Supplier<StorageMonitorBlock> storageMonitor;
@Nullable
private Supplier<PortableGridBlock> portableGrid;
@Nullable
private Supplier<PortableGridBlock> creativePortableGrid;

private Blocks() {
}
Expand All @@ -155,15 +161,15 @@ public BlockColorMap<CableBlock> getCable() {
}

public SimpleBlock getQuartzEnrichedIronBlock() {
return Objects.requireNonNull(quartzEnrichedIronBlock).get();
return requireNonNull(quartzEnrichedIronBlock).get();
}

public DiskDriveBlock getDiskDrive() {
return Objects.requireNonNull(diskDrive).get();
return requireNonNull(diskDrive).get();
}

public SimpleBlock getMachineCasing() {
return Objects.requireNonNull(machineCasing).get();
return requireNonNull(machineCasing).get();
}

public BlockColorMap<GridBlock> getGrid() {
Expand Down Expand Up @@ -224,7 +230,7 @@ public void setInterface(final Supplier<InterfaceBlock> interfaceSupplier) {
}

public InterfaceBlock getInterface() {
return Objects.requireNonNull(iface).get();
return requireNonNull(iface).get();
}

public BlockColorMap<ExternalStorageBlock> getExternalStorage() {
Expand Down Expand Up @@ -252,7 +258,7 @@ public void setStorageMonitor(final Supplier<StorageMonitorBlock> supplier) {
}

public StorageMonitorBlock getStorageMonitor() {
return Objects.requireNonNull(storageMonitor).get();
return requireNonNull(storageMonitor).get();
}

public BlockColorMap<NetworkReceiverBlock> getNetworkReceiver() {
Expand All @@ -262,4 +268,20 @@ public BlockColorMap<NetworkReceiverBlock> getNetworkReceiver() {
public BlockColorMap<NetworkTransmitterBlock> getNetworkTransmitter() {
return networkTransmitter;
}

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

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

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

public void setCreativePortableGrid(final Supplier<PortableGridBlock> supplier) {
this.creativePortableGrid = supplier;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public final class ContentIds {
public static final ResourceLocation NETWORK_RECEIVER = createIdentifier("network_receiver");
public static final ResourceLocation NETWORK_CARD = createIdentifier("network_card");
public static final ResourceLocation NETWORK_TRANSMITTER = createIdentifier("network_transmitter");
public static final ResourceLocation PORTABLE_GRID = createIdentifier("portable_grid");
public static final ResourceLocation CREATIVE_PORTABLE_GRID = createIdentifier("creative_portable_grid");

private ContentIds() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ private static void appendBlocks(final Consumer<ItemStack> consumer) {
itemConsumer.accept(Blocks.INSTANCE.getDiskDrive());
appendBlockColors(consumer, Blocks.INSTANCE.getGrid());
appendBlockColors(consumer, Blocks.INSTANCE.getCraftingGrid());
itemConsumer.accept(Items.INSTANCE.getPortableGrid());
itemConsumer.accept(Items.INSTANCE.getCreativePortableGrid());
Items.INSTANCE.getDetectors().stream().map(Supplier::get).forEach(itemConsumer);
itemConsumer.accept(Blocks.INSTANCE.getInterface());
Arrays.stream(ItemStorageType.Variant.values()).forEach(variant -> itemConsumer.accept(
Expand Down
Loading

0 comments on commit 9457191

Please sign in to comment.