Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ae2 undisabling a connection with a yeta wrench now properly reconnects #355

Merged
merged 2 commits into from
Jul 26, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ public Optional<GraphObject<Mergeable.Dummy>> tryConnectTo(Direction dir, ICondu
return Optional.of(conduit.bundle.getNodeFor(type));
} else if (type.getTicker().canConnectTo(level, getBlockPos(), dir)) {
connectEnd(dir, type);
updateConnectionToData(type);
}
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.enderio.conduits.common.integrations.ae2;

import appeng.api.networking.GridHelper;
import appeng.api.networking.IInWorldGridNodeHost;
import com.enderio.EnderIO;
import com.enderio.api.conduit.IConduitMenuData;
Expand All @@ -18,7 +19,6 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import org.apache.commons.lang3.function.TriFunction;
Expand All @@ -38,38 +38,7 @@ public AE2ConduitType(boolean dense) {

@Override
public IConduitTicker getTicker() {
return new IConduitTicker() {
@Override
public void tickGraph(IConduitType<?> type, Graph<Mergeable.Dummy> graph, ServerLevel level, TriFunction<ServerLevel, BlockPos, ColorControl, Boolean> isRedstoneActive) {
//ae2 graphs don't actually do anything, that's all done by ae2
}

@Override
public boolean canConnectTo(Level level, BlockPos conduitPos, Direction direction) {
BlockEntity blockEntity = level.getBlockEntity(conduitPos.relative(direction));
if (blockEntity instanceof IInWorldGridNodeHost host && canConnectTo(host, direction))
return true;
return blockEntity != null && blockEntity
.getCapability(getCapability(), direction.getOpposite())
.resolve()
.map(node -> canConnectTo(node, direction))
.orElse(false);
}

private static boolean canConnectTo(IInWorldGridNodeHost host, Direction direction) {
return Optional.ofNullable(host.getGridNode(direction.getOpposite())).map(node -> node.getConnectedSides().contains(direction.getOpposite())).orElse(false);
}

@Override
public boolean hasConnectionDelay() {
return true;
}

@Override
public boolean canConnectTo(IConduitType<?> thisType, IConduitType<?> other) {
return other instanceof AE2ConduitType;
}
};
return Ticker.INSTANCE;
}

@Override
Expand Down Expand Up @@ -149,4 +118,28 @@ public boolean showRedstoneExtract() {
return false;
}
}

private static final class Ticker implements IConduitTicker {

private static final Ticker INSTANCE = new Ticker();
@Override
public void tickGraph(IConduitType<?> type, Graph<Mergeable.Dummy> graph, ServerLevel level, TriFunction<ServerLevel, BlockPos, ColorControl, Boolean> isRedstoneActive) {
//ae2 graphs don't actually do anything, that's all done by ae2
}

@Override
public boolean canConnectTo(Level level, BlockPos conduitPos, Direction direction) {
return GridHelper.getExposedNode(level, conduitPos.relative(direction), direction.getOpposite()) != null;
}

@Override
public boolean hasConnectionDelay() {
return true;
}

@Override
public boolean canConnectTo(IConduitType<?> thisType, IConduitType<?> other) {
return other instanceof AE2ConduitType;
}
}
}