Skip to content

Commit

Permalink
Fixed crashing the game when a network block was removed in a bad way.
Browse files Browse the repository at this point in the history
…Fixes #3326
  • Loading branch information
raoulvdberge committed Aug 6, 2022
1 parent a0c31f6 commit 885d46c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Fixed Storage Monitor not showing all matching items in non-exact mode
- Fixed items getting lost on Creative Disk when more than 2,147,483,647 of one type is stored
- Fixed incorrect autocrafting keybind prompt on macOS
- Fixed crashing the game when a network block was removed in a bad way

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import com.refinedmods.refinedstorage.api.util.Action;
import com.refinedmods.refinedstorage.apiimpl.API;
import com.refinedmods.refinedstorage.apiimpl.network.node.NetworkNode;
import com.refinedmods.refinedstorage.capability.NetworkNodeProxyCapability;
import com.refinedmods.refinedstorage.blockentity.config.IRedstoneConfigurable;
import com.refinedmods.refinedstorage.blockentity.config.RedstoneMode;
import com.refinedmods.refinedstorage.blockentity.data.BlockEntitySynchronizationParameter;
import com.refinedmods.refinedstorage.capability.NetworkNodeProxyCapability;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
Expand All @@ -18,6 +18,8 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -28,6 +30,8 @@ public abstract class NetworkNodeBlockEntity<N extends NetworkNode> extends Base
private N clientNode;
private N removedNode;

private static final Logger LOGGER = LogManager.getLogger();

protected NetworkNodeBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);

Expand Down Expand Up @@ -61,7 +65,10 @@ public N getNode() {
INetworkNode node = manager.getNode(worldPosition);

if (node == null) {
throw new IllegalStateException("No network node present at " + worldPosition.toString() + ", consider removing the block at this position");
LOGGER.warn("Expected a node @ {} but couldn't find it, creating a new one...", worldPosition);
node = createNode(level, worldPosition);
manager.setNode(worldPosition, node);
manager.markForSaving();
}

return (N) node;
Expand Down

0 comments on commit 885d46c

Please sign in to comment.