Skip to content

Commit

Permalink
Merge pull request #492 from refinedmods/fix/GH-456/carryon
Browse files Browse the repository at this point in the history
fix: problems moving network devices with Carry On mod
  • Loading branch information
raoulvdberge authored Mar 11, 2024
2 parents e58e472 + cdbf4d1 commit 971b44e
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Fixed changing side buttons not working on Forge.
- Fixed External Storage not displaying empty allowlist warning.
- Fixed incrementing starting from 1 in amount screens not having an intended off-by-one.
- Fixed problems moving network devices with "Carry On" mod.

## [2.0.0-milestone.3.3] - 2024-02-17

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.refinedmods.refinedstorage2.api.network.Network;
import com.refinedmods.refinedstorage2.api.network.component.NetworkComponent;
import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage;
import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer;
import com.refinedmods.refinedstorage2.api.resource.ResourceKey;
import com.refinedmods.refinedstorage2.platform.api.constructordestructor.ConstructorStrategyFactory;
import com.refinedmods.refinedstorage2.platform.api.constructordestructor.DestructorStrategyFactory;
Expand All @@ -28,6 +27,7 @@
import com.refinedmods.refinedstorage2.platform.api.storagemonitor.StorageMonitorExtractionStrategy;
import com.refinedmods.refinedstorage2.platform.api.storagemonitor.StorageMonitorInsertionStrategy;
import com.refinedmods.refinedstorage2.platform.api.support.energy.EnergyItemHelper;
import com.refinedmods.refinedstorage2.platform.api.support.network.PlatformNetworkNodeContainer;
import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.NetworkBoundItemHelper;
import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference;
import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReferenceFactory;
Expand Down Expand Up @@ -103,11 +103,11 @@ public interface PlatformApi {

BuiltinUpgradeDestinations getBuiltinUpgradeDestinations();

void requestNetworkNodeInitialization(NetworkNodeContainer container, Level level, Runnable callback);
void requestNetworkNodeInitialization(PlatformNetworkNodeContainer container, Level level, Runnable callback);

void requestNetworkNodeRemoval(NetworkNodeContainer container, Level level);
void requestNetworkNodeRemoval(PlatformNetworkNodeContainer container, Level level);

void requestNetworkNodeUpdate(NetworkNodeContainer container, Level level);
void requestNetworkNodeUpdate(PlatformNetworkNodeContainer container, Level level);

GridInsertionStrategy createGridInsertionStrategy(AbstractContainerMenu containerMenu,
Player player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.refinedmods.refinedstorage2.api.network.Network;
import com.refinedmods.refinedstorage2.api.network.component.NetworkComponent;
import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage;
import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer;
import com.refinedmods.refinedstorage2.api.resource.ResourceKey;
import com.refinedmods.refinedstorage2.platform.api.constructordestructor.ConstructorStrategyFactory;
import com.refinedmods.refinedstorage2.platform.api.constructordestructor.DestructorStrategyFactory;
Expand All @@ -28,6 +27,7 @@
import com.refinedmods.refinedstorage2.platform.api.storagemonitor.StorageMonitorExtractionStrategy;
import com.refinedmods.refinedstorage2.platform.api.storagemonitor.StorageMonitorInsertionStrategy;
import com.refinedmods.refinedstorage2.platform.api.support.energy.EnergyItemHelper;
import com.refinedmods.refinedstorage2.platform.api.support.network.PlatformNetworkNodeContainer;
import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.NetworkBoundItemHelper;
import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference;
import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReferenceFactory;
Expand Down Expand Up @@ -177,19 +177,19 @@ public BuiltinUpgradeDestinations getBuiltinUpgradeDestinations() {
}

@Override
public void requestNetworkNodeInitialization(final NetworkNodeContainer container,
public void requestNetworkNodeInitialization(final PlatformNetworkNodeContainer container,
final Level level,
final Runnable callback) {
ensureLoaded().requestNetworkNodeInitialization(container, level, callback);
}

@Override
public void requestNetworkNodeRemoval(final NetworkNodeContainer container, final Level level) {
public void requestNetworkNodeRemoval(final PlatformNetworkNodeContainer container, final Level level) {
ensureLoaded().requestNetworkNodeRemoval(container, level);
}

@Override
public void requestNetworkNodeUpdate(final NetworkNodeContainer container, final Level level) {
public void requestNetworkNodeUpdate(final PlatformNetworkNodeContainer container, final Level level) {
ensureLoaded().requestNetworkNodeUpdate(container, level);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public void clearRemoved() {
PlatformApi.INSTANCE.requestNetworkNodeInitialization(this, level, this::onNetworkInNodeInitialized);
}

@Override
public boolean isContainerRemoved() {
return isRemoved();
}

protected void onNetworkInNodeInitialized() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public interface PlatformNetworkNodeContainer extends NetworkNodeContainer {
* Called when a node is about to be added into the network graph.
* Add outgoing connections here.
* If the outgoing connections ever change, call {@link
* com.refinedmods.refinedstorage2.platform.api.PlatformApi#requestNetworkNodeUpdate(NetworkNodeContainer, Level)}.
* com.refinedmods.refinedstorage2.platform.api.PlatformApi#requestNetworkNodeUpdate(
*PlatformNetworkNodeContainer, Level)}.
*
* @param sink the sink that accepts outgoing connections
*/
Expand All @@ -24,7 +25,8 @@ public interface PlatformNetworkNodeContainer extends NetworkNodeContainer {
* Returns whether the (not yet discovered) node can accept an incoming connection.
* Changes to this return value won't cause a rebuild of the network state.
* If the return value ever changes, call {@link
* com.refinedmods.refinedstorage2.platform.api.PlatformApi#requestNetworkNodeUpdate(NetworkNodeContainer, Level)}.
* com.refinedmods.refinedstorage2.platform.api.PlatformApi#requestNetworkNodeUpdate(
*PlatformNetworkNodeContainer, Level)}.
*
* @param incomingDirection the incoming direction
* @param connectingState the state wanting to connect
Expand All @@ -35,4 +37,6 @@ public interface PlatformNetworkNodeContainer extends NetworkNodeContainer {
BlockState getContainerBlockState();

GlobalPos getContainerPosition();

boolean isContainerRemoved();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.refinedmods.refinedstorage2.api.network.energy.EnergyStorage;
import com.refinedmods.refinedstorage2.api.network.impl.NetworkBuilderImpl;
import com.refinedmods.refinedstorage2.api.network.impl.NetworkFactory;
import com.refinedmods.refinedstorage2.api.network.node.container.NetworkNodeContainer;
import com.refinedmods.refinedstorage2.api.resource.ResourceKey;
import com.refinedmods.refinedstorage2.platform.api.PlatformApi;
import com.refinedmods.refinedstorage2.platform.api.constructordestructor.ConstructorStrategyFactory;
Expand All @@ -32,6 +31,7 @@
import com.refinedmods.refinedstorage2.platform.api.storagemonitor.StorageMonitorExtractionStrategy;
import com.refinedmods.refinedstorage2.platform.api.storagemonitor.StorageMonitorInsertionStrategy;
import com.refinedmods.refinedstorage2.platform.api.support.energy.EnergyItemHelper;
import com.refinedmods.refinedstorage2.platform.api.support.network.PlatformNetworkNodeContainer;
import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.NetworkBoundItemHelper;
import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReference;
import com.refinedmods.refinedstorage2.platform.api.support.network.bounditem.SlotReferenceFactory;
Expand Down Expand Up @@ -295,24 +295,40 @@ public BuiltinUpgradeDestinations getBuiltinUpgradeDestinations() {
}

@Override
public void requestNetworkNodeInitialization(final NetworkNodeContainer container,
public void requestNetworkNodeInitialization(final PlatformNetworkNodeContainer container,
final Level level,
final Runnable callback) {
final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(level);
ServerEventQueue.queue(() -> {
// The container could've been removed by the time it has been placed, and by the time the event queue has
// run. In that case, don't initialize the network node because it no longer exists.
// This is a workaround for the "Carry On" mod. The mod places the block (which creates a block entity and
// requests this network node initialization) and then overrides the placed block entity with their own
// block entity. This triggers a new initialization, but then this one can no longer run!
if (container.isContainerRemoved()) {
return;
}
networkBuilder.initialize(container, connectionProvider);
callback.run();
});
}

@Override
public void requestNetworkNodeRemoval(final NetworkNodeContainer container, final Level level) {
public void requestNetworkNodeRemoval(final PlatformNetworkNodeContainer container, final Level level) {
// "Carry On" mod places the block (which creates a block entity and requests network node initialization)
// and then overrides the placed block entity with their own information.
// However, when the placed block entity is replaced, the server event queue hasn't run yet and there is
// no network loaded yet, even though the network node initialization was requested.
// Stop continuing here to avoid further code failing due to a missing network.
if (container.getNode().getNetwork() == null) {
return;
}
final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(level);
networkBuilder.remove(container, connectionProvider);
}

@Override
public void requestNetworkNodeUpdate(final NetworkNodeContainer container, final Level level) {
public void requestNetworkNodeUpdate(final PlatformNetworkNodeContainer container, final Level level) {
final ConnectionProviderImpl connectionProvider = new ConnectionProviderImpl(level);
networkBuilder.update(container, connectionProvider);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private BlockEntity getBlockEntitySafely(final Level level, final BlockPos pos)
}
// Avoid using EntityCreationType.IMMEDIATE.
// By default, the block is removed first and then the block entity (see BaseBlock#onRemove).
// But, when using mods like Carrier or Carpet that allow for moving block entities,
// But, when using mods like "Carrier", "Carpet" or "Carry On" that allow for moving block entities,
// they remove the block entity first and then the block.
// When removing a block with Carrier for example,
// this causes a problematic situation that the block entity IS gone,
Expand Down

0 comments on commit 971b44e

Please sign in to comment.