Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ public InteractionResult onSneakWrenched(BlockState state, UseOnContext c) {
@Override
public void neighborChanged(BlockState state, Level worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) {
BlockEntity blockEntity = state.hasBlockEntity() ? worldIn.getBlockEntity(pos) : null;
if(blockEntity != null) {
if(blockEntity instanceof AbstractConnectorBlockEntity) {
((AbstractConnectorBlockEntity)blockEntity).updateExternalEnergyStorage();
}
}
if (!state.canSurvive(worldIn, pos)) {
dropResources(state, worldIn, pos, blockEntity);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,10 @@ public void firstTick() {
this.wasContraption = false;
validateNodes();
}

updateExternalEnergyStorage();
}

protected void specialTick() {}

boolean externalStorageInvalid = false;
@Override
public void tick() {
if (this.firstTick) firstTick();
Expand All @@ -274,15 +271,18 @@ public void tick() {
if(awakeNetwork(level)) notifyUpdate();

networkTick(network);

if (externalStorageInvalid) updateExternalEnergyStorage();

}

private void networkTick(EnergyNetwork network) {
ConnectorMode mode = getMode();
if(level == null) return;
if(level.isClientSide()) return;
if(external == null) {
updateExternalEnergyStorage();
if(external == null) {
return;
}
}
IEnergyStorage otherStorage = external.getCapability();
if (otherStorage == null) return;

Expand Down Expand Up @@ -316,7 +316,6 @@ public void remove() {
}

invalidateNodeCache();
// invalidateCaps();

// Invalidate
if (network != null) network.invalidate();
Expand Down Expand Up @@ -369,32 +368,14 @@ public void updateExternalEnergyStorage() {
if (!(level instanceof ServerLevel)) return;
if (!level.isLoaded(getBlockPos())) return;
var side = getBlockState().getValue(AbstractConnectorBlock.FACING);
if (!level.isLoaded(getBlockPos().relative(side))) return;
externalStorageInvalid = false;

//if (!level.isLoaded(worldPosition.relative(side))) {
// external = LazyOptional.empty();
// return;
//}
//BlockEntity te = level.getBlockEntity(worldPosition.relative(side));
//if(te == null) {
// external = LazyOptional.empty();
// return;
//}
//LazyOptional<IEnergyStorage> le = te.getCapability(ForgeCapabilities.ENERGY, side.getOpposite());
//if(ignoreCapSide() && !le.isPresent()) le = te.getCapability(ForgeCapabilities.ENERGY);
// Make sure the side isn't already cached.
//if (le.equals(external)) return;
//external = le;
//le.addListener((es) -> { externalStorageInvalid = true; });

external = BlockCapabilityCache.create(
Capabilities.EnergyStorage.BLOCK, // capability to cache
(ServerLevel) level, // level
getPos().relative(side),
side.getOpposite(),
() -> !this.isRemoved(), // validity check (because the cache might outlive the object it belongs to)
() -> externalStorageInvalid = true // invalidation listener
() -> {} // invalidation listener
);
}

Expand Down