Skip to content

Commit

Permalink
Fix removing conduits not removing from node graph
Browse files Browse the repository at this point in the history
  • Loading branch information
jumanji144 committed Apr 9, 2024
1 parent 7946865 commit 312a5a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,20 @@
import com.enderio.EnderIO;
import com.refinedmods.refinedstorage.RS;
import com.refinedmods.refinedstorage.api.network.INetwork;
import com.refinedmods.refinedstorage.api.network.INetworkNodeVisitor;
import com.refinedmods.refinedstorage.api.network.node.INetworkNode;
import com.refinedmods.refinedstorage.apiimpl.network.node.NetworkNode;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.UUID;

public class RSNetworkNode implements INetworkNode, INetworkNodeVisitor {
public class RSNetworkNode extends NetworkNode {

public static final ResourceLocation ID = EnderIO.loc("rs_conduit");
private final Level level;
private final BlockPos pos;
private INetwork network;
private UUID owner;

public RSNetworkNode(Level level, BlockPos pos) {
this.level = level;
this.pos = pos;
super(level, pos);
}

@NotNull
Expand All @@ -36,16 +25,6 @@ public ItemStack getItemStack() {
return new ItemStack(RSIntegration.NORMAL_ITEM.get());
}

@Override
public void onConnected(INetwork network) {
this.network = network;
}

@Override
public void onDisconnected(INetwork network) {
this.network = null;
}

@Override
public boolean isActive() {
return true;
Expand All @@ -57,39 +36,6 @@ public INetwork getNetwork() {
return network;
}

@Override
public void update() {

}

@Override
public CompoundTag write(CompoundTag compoundTag) {
if (owner != null)
compoundTag.putUUID("owner", owner);
return compoundTag;
}

public void read(CompoundTag compoundTag) {
if (compoundTag.contains("owner"))
owner = compoundTag.getUUID("owner");
}

@Override
public BlockPos getPos() {
return pos;
}

@Override
public Level getLevel() {
return level;
}

@Override
public void markDirty() {
if (!level.isClientSide())
RSNodeHost.RSAPI.getNetworkNodeManager((ServerLevel) level).markForSaving();
}

@Override
public int getEnergyUsage() {
return RS.SERVER_CONFIG.getCable().getUsage();
Expand All @@ -100,23 +46,4 @@ public ResourceLocation getId() {
return ID;
}

@Nullable
@Override
public UUID getOwner() {
return owner;
}

@Override
public void setOwner(@Nullable UUID uuid) {
this.owner = uuid;
}

@Override
public void visit(Operator operator) {
for (Direction value : Direction.values()) {
if (canConduct(value)) {
operator.apply(level, pos.relative(value), value);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class RSNodeHost implements IExtendedConduitData<RSNodeHost>, INetworkNod
@RSAPIInject
public static IRSAPI RSAPI;

private RSNetworkNode node;
private LazyOptional<RSNodeHost> selfCap = LazyOptional.of(() -> this);
private final RSNetworkNode node;
private final LazyOptional<RSNodeHost> selfCap = LazyOptional.of(() -> this);
private final Level level;
private final BlockPos pos;

Expand Down Expand Up @@ -49,14 +49,13 @@ public RSNetworkNode getNode() {
}

public LazyOptional<RSNodeHost> getSelfCap() {
if (!selfCap.isPresent()) {
selfCap = LazyOptional.of(() -> this);
}
return selfCap;
}

@Override
public void onRemoved(IConduitType<?> type, Level level, BlockPos pos) {
selfCap.invalidate();

INetworkNodeManager manager = RSAPI.getNetworkNodeManager((ServerLevel) level);

INetworkNode node = manager.getNode(pos);
Expand All @@ -65,10 +64,8 @@ public void onRemoved(IConduitType<?> type, Level level, BlockPos pos) {
manager.markForSaving();

if (node != null && node.getNetwork() != null) {
node.getNetwork().getNodeGraph().invalidate(Action.PERFORM, level, pos);
node.getNetwork().getNodeGraph().invalidate(Action.PERFORM, node.getNetwork().getLevel(), node.getNetwork().getPosition());
}

selfCap.invalidate();
}

@Override
Expand Down

0 comments on commit 312a5a0

Please sign in to comment.