fix: crashing issues due to node desync

This commit is contained in:
raoulvdberge
2023-11-05 13:19:44 +01:00
parent 327c97b58d
commit 9b30bece19
26 changed files with 67 additions and 42 deletions

View File

@@ -1,5 +1,9 @@
apply from: "https://raw.githubusercontent.com/refinedmods/refinedarchitect/v0.7.1/helper.gradle"
ext {
forgeVersion = "47.1.0"
}
repositories {
maven {
name = 'JEI'
@@ -38,10 +42,7 @@ dependencies {
compileOnly fg.deobf('curse.maven:crafting-tweaks-233071:4596466')
// TODO mixin issue
// runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:5.2.0-beta.3+1.20.1")
// can't depend on API due to Javadoc build error (CuriosApi imports stuff from common)
compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:5.2.0-beta.3+1.20.1")
implementation fg.deobf("top.theillusivec4.curios:curios-forge:5.2.0-beta.3+1.20.1")
}
minecraft {

View File

@@ -122,6 +122,7 @@ public class CableBlock extends NetworkNodeBlock implements SimpleWaterloggedBlo
}
@Override
@SuppressWarnings("deprecation")
public boolean isPathfindable(BlockState state, BlockGetter worldIn, BlockPos pos, PathComputationType type) {
return false;
}

View File

@@ -27,7 +27,7 @@ public class CableBlockEntity extends NetworkNodeBlockEntity<CableNetworkNode> {
.build();
public CableBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.CABLE.get(), pos, state, SPEC);
super(RSBlockEntities.CABLE.get(), pos, state, SPEC, CableNetworkNode.class);
}
@Override

View File

@@ -42,7 +42,7 @@ public class ConstructorBlockEntity extends NetworkNodeBlockEntity<ConstructorNe
.build();
public ConstructorBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.CONSTRUCTOR.get(), pos, state, SPEC);
super(RSBlockEntities.CONSTRUCTOR.get(), pos, state, SPEC, ConstructorNetworkNode.class);
}
@Override

View File

@@ -33,7 +33,7 @@ public class CrafterBlockEntity extends NetworkNodeBlockEntity<CrafterNetworkNod
private final LazyOptional<IItemHandler> patternsCapability = LazyOptional.of(() -> getNode().getPatternInventory());
public CrafterBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.CRAFTER.get(), pos, state, SPEC);
super(RSBlockEntities.CRAFTER.get(), pos, state, SPEC, CrafterNetworkNode.class);
}
@Override

View File

@@ -35,7 +35,7 @@ public class CrafterManagerBlockEntity extends NetworkNodeBlockEntity<CrafterMan
.build();
public CrafterManagerBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.CRAFTER_MANAGER.get(), pos, state, SPEC);
super(RSBlockEntities.CRAFTER_MANAGER.get(), pos, state, SPEC, CrafterManagerNetworkNode.class);
}
@Override

View File

@@ -45,7 +45,7 @@ public class DestructorBlockEntity extends NetworkNodeBlockEntity<DestructorNetw
.build();
public DestructorBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.DESTRUCTOR.get(), pos, state, SPEC);
super(RSBlockEntities.DESTRUCTOR.get(), pos, state, SPEC, DestructorNetworkNode.class);
}
@Override

View File

@@ -43,7 +43,7 @@ public class DetectorBlockEntity extends NetworkNodeBlockEntity<DetectorNetworkN
private static final String NBT_POWERED = "Powered";
public DetectorBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.DETECTOR.get(), pos, state, SPEC);
super(RSBlockEntities.DETECTOR.get(), pos, state, SPEC, DetectorNetworkNode.class);
}
@Override

View File

@@ -99,7 +99,7 @@ public class DiskDriveBlockEntity extends NetworkNodeBlockEntity<DiskDriveNetwor
private final DiskState[] diskState = new DiskState[8];
public DiskDriveBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.DISK_DRIVE.get(), pos, state, SPEC);
super(RSBlockEntities.DISK_DRIVE.get(), pos, state, SPEC, DiskDriveNetworkNode.class);
Arrays.fill(diskState, DiskState.NONE);
}

View File

@@ -57,7 +57,7 @@ public class DiskManipulatorBlockEntity extends NetworkNodeBlockEntity<DiskManip
private final DiskState[] diskState = new DiskState[6];
public DiskManipulatorBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.DISK_MANIPULATOR.get(), pos, state, SPEC);
super(RSBlockEntities.DISK_MANIPULATOR.get(), pos, state, SPEC, DiskManipulatorNetworkNode.class);
Arrays.fill(diskState, DiskState.NONE);
}

View File

@@ -38,7 +38,7 @@ public class ExporterBlockEntity extends NetworkNodeBlockEntity<ExporterNetworkN
.build();
public ExporterBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.EXPORTER.get(), pos, state, SPEC);
super(RSBlockEntities.EXPORTER.get(), pos, state, SPEC, ExporterNetworkNode.class);
}
@Override

View File

@@ -10,6 +10,7 @@ import com.refinedmods.refinedstorage.blockentity.config.*;
import com.refinedmods.refinedstorage.blockentity.data.BlockEntitySynchronizationParameter;
import com.refinedmods.refinedstorage.blockentity.data.BlockEntitySynchronizationSpec;
import com.refinedmods.refinedstorage.blockentity.data.RSSerializers;
import com.refinedmods.refinedstorage.config.ServerConfig;
import com.refinedmods.refinedstorage.util.LevelUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
@@ -72,7 +73,7 @@ public class ExternalStorageBlockEntity extends NetworkNodeBlockEntity<ExternalS
.build();
public ExternalStorageBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.EXTERNAL_STORAGE.get(), pos, state, SPEC);
super(RSBlockEntities.EXTERNAL_STORAGE.get(), pos, state, SPEC, ExternalStorageNetworkNode.class);
}
@Override

View File

@@ -35,7 +35,7 @@ public class FluidInterfaceBlockEntity extends NetworkNodeBlockEntity<FluidInter
private final LazyOptional<IItemHandler> inCapability = LazyOptional.of(() -> getNode().getIn());
public FluidInterfaceBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.FLUID_INTERFACE.get(), pos, state, SPEC);
super(RSBlockEntities.FLUID_INTERFACE.get(), pos, state, SPEC, FluidInterfaceNetworkNode.class);
}
@Nonnull

View File

@@ -39,7 +39,7 @@ public class FluidStorageBlockEntity extends NetworkNodeBlockEntity<FluidStorage
private final FluidStorageType type;
public FluidStorageBlockEntity(FluidStorageType type, BlockPos pos, BlockState state) {
super(getType(type), pos, state, SPEC);
super(getType(type), pos, state, SPEC, FluidStorageNetworkNode.class);
this.type = type;
}

View File

@@ -36,7 +36,7 @@ public class ImporterBlockEntity extends NetworkNodeBlockEntity<ImporterNetworkN
.build();
public ImporterBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.IMPORTER.get(), pos, state, SPEC);
super(RSBlockEntities.IMPORTER.get(), pos, state, SPEC, ImporterNetworkNode.class);
}
@Override

View File

@@ -30,7 +30,7 @@ public class InterfaceBlockEntity extends NetworkNodeBlockEntity<InterfaceNetwor
private final LazyOptional<IItemHandler> itemsCapability = LazyOptional.of(() -> getNode().getItems());
public InterfaceBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.INTERFACE.get(), pos, state, SPEC);
super(RSBlockEntities.INTERFACE.get(), pos, state, SPEC, InterfaceNetworkNode.class);
}
@Nonnull

View File

@@ -28,16 +28,26 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public abstract class NetworkNodeBlockEntity<N extends NetworkNode> extends BaseBlockEntity implements INetworkNodeProxy<N>, IRedstoneConfigurable {
public static final BlockEntitySynchronizationParameter<Integer, NetworkNodeBlockEntity> REDSTONE_MODE = RedstoneMode.createParameter(new ResourceLocation(RS.ID, "redstone_mode"));
public static final BlockEntitySynchronizationParameter<Integer, NetworkNodeBlockEntity<?>> REDSTONE_MODE = RedstoneMode.createParameter(new ResourceLocation(RS.ID, "redstone_mode"));
private final LazyOptional<INetworkNodeProxy<N>> networkNodeProxy = LazyOptional.of(() -> this);
private final Class<N> networkNodeClass;
private N clientNode;
private N removedNode;
private static final Logger LOGGER = LogManager.getLogger();
// TODO: remove this ctor in 1.21
@Deprecated
protected NetworkNodeBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state, BlockEntitySynchronizationSpec syncSpec) {
super(type, pos, state, syncSpec);
this.networkNodeClass = null;
}
protected NetworkNodeBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state, BlockEntitySynchronizationSpec syncSpec,
Class<N> networkNodeClass) {
super(type, pos, state, syncSpec);
this.networkNodeClass = networkNodeClass;
}
@Override
@@ -72,13 +82,20 @@ public abstract class NetworkNodeBlockEntity<N extends NetworkNode> extends Base
node = createAndSetNode(manager);
}
return (N) node;
return doCast(node);
} catch (ClassCastException e) {
LOGGER.warn("Node @ {} got desynced with it's block entity container, recreating", worldPosition, e);
return (N) createAndSetNode(manager);
}
}
private N doCast(INetworkNode node) {
if (networkNodeClass == null) {
return (N) node;
}
return networkNodeClass.cast(node);
}
private INetworkNode createAndSetNode(INetworkNodeManager manager) {
INetworkNode node = createNode(level, worldPosition);
manager.setNode(worldPosition, node);
@@ -110,7 +127,11 @@ public abstract class NetworkNodeBlockEntity<N extends NetworkNode> extends Base
INetworkNode node = manager.getNode(worldPosition);
if (node != null) {
removedNode = (N) node;
try {
removedNode = doCast(node);
} catch (ClassCastException e) {
removedNode = null;
}
}
manager.removeNode(worldPosition);

View File

@@ -15,7 +15,7 @@ public class NetworkReceiverBlockEntity extends NetworkNodeBlockEntity<NetworkRe
.build();
public NetworkReceiverBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.NETWORK_RECEIVER.get(), pos, state, SPEC);
super(RSBlockEntities.NETWORK_RECEIVER.get(), pos, state, SPEC, NetworkReceiverNetworkNode.class);
}
@Override

View File

@@ -40,7 +40,7 @@ public class NetworkTransmitterBlockEntity extends NetworkNodeBlockEntity<Networ
private final LazyOptional<IItemHandler> networkCardCapability = LazyOptional.of(() -> getNode().getNetworkCard());
public NetworkTransmitterBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.NETWORK_TRANSMITTER.get(), pos, state, SPEC);
super(RSBlockEntities.NETWORK_TRANSMITTER.get(), pos, state, SPEC, NetworkTransmitterNetworkNode.class);
}
@Override

View File

@@ -15,7 +15,7 @@ public class RelayBlockEntity extends NetworkNodeBlockEntity<RelayNetworkNode> {
.build();
public RelayBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.RELAY.get(), pos, state, SPEC);
super(RSBlockEntities.RELAY.get(), pos, state, SPEC, RelayNetworkNode.class);
}
@Override

View File

@@ -15,7 +15,7 @@ public class SecurityManagerBlockEntity extends NetworkNodeBlockEntity<SecurityM
.build();
public SecurityManagerBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.SECURITY_MANAGER.get(), pos, state, SPEC);
super(RSBlockEntities.SECURITY_MANAGER.get(), pos, state, SPEC, SecurityManagerNetworkNode.class);
}
@Override

View File

@@ -39,7 +39,7 @@ public class StorageBlockEntity extends NetworkNodeBlockEntity<StorageNetworkNod
private final ItemStorageType type;
public StorageBlockEntity(ItemStorageType type, BlockPos pos, BlockState state) {
super(getType(type), pos, state, SPEC);
super(getType(type), pos, state, SPEC, StorageNetworkNode.class);
this.type = type;
}

View File

@@ -7,6 +7,7 @@ import com.refinedmods.refinedstorage.blockentity.config.IComparable;
import com.refinedmods.refinedstorage.blockentity.config.IType;
import com.refinedmods.refinedstorage.blockentity.data.BlockEntitySynchronizationParameter;
import com.refinedmods.refinedstorage.blockentity.data.BlockEntitySynchronizationSpec;
import com.refinedmods.refinedstorage.config.ServerConfig;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
@@ -40,7 +41,7 @@ public class StorageMonitorBlockEntity extends NetworkNodeBlockEntity<StorageMon
private FluidStack fluidStack = FluidStack.EMPTY;
public StorageMonitorBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.STORAGE_MONITOR.get(), pos, state, SPEC);
super(RSBlockEntities.STORAGE_MONITOR.get(), pos, state, SPEC, StorageMonitorNetworkNode.class);
}
@Override

View File

@@ -22,7 +22,7 @@ public class WirelessTransmitterBlockEntity extends NetworkNodeBlockEntity<Wirel
.build();
public WirelessTransmitterBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.WIRELESS_TRANSMITTER.get(), pos, state, SPEC);
super(RSBlockEntities.WIRELESS_TRANSMITTER.get(), pos, state, SPEC, WirelessTransmitterNetworkNode.class);
}
@Override

View File

@@ -41,7 +41,7 @@ public class CraftingMonitorBlockEntity extends NetworkNodeBlockEntity<CraftingM
.build();
public CraftingMonitorBlockEntity(BlockPos pos, BlockState state) {
super(RSBlockEntities.CRAFTING_MONITOR.get(), pos, state, SPEC);
super(RSBlockEntities.CRAFTING_MONITOR.get(), pos, state, SPEC, CraftingMonitorNetworkNode.class);
}
@Override

View File

@@ -119,7 +119,7 @@ public class GridBlockEntity extends NetworkNodeBlockEntity<GridNetworkNode> {
private final LazyOptional<IItemHandler> diskCapability = LazyOptional.of(() -> getNode().getPatterns());
public GridBlockEntity(GridType type, BlockPos pos, BlockState state) {
super(getType(type), pos, state, SPEC);
super(getType(type), pos, state, SPEC, GridNetworkNode.class);
this.type = type;
}