fixed pipe network

This commit is contained in:
Ell 2024-03-07 18:58:30 +01:00
parent cca0f12f1a
commit c8fee33ca5
3 changed files with 9 additions and 15 deletions

View file

@ -39,7 +39,6 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
// TODO it appears that this doesn't save properly yet :(
public class PipeNetwork extends SavedData implements GraphListener<BlockPos, NetworkEdge> {
private static final Factory<PipeNetwork> FACTORY = new Factory<>(PipeNetwork::new, PipeNetwork::new);
@ -518,11 +517,13 @@ public class PipeNetwork extends SavedData implements GraphListener<BlockPos, Ne
}
public void startProfile(String name) {
this.level.getProfiler().push(() -> PrettyPipes.ID + ":pipe_network_" + name);
if (this.level != null)
this.level.getProfiler().push(() -> PrettyPipes.ID + ":pipe_network_" + name);
}
public void endProfile() {
this.level.getProfiler().pop();
if (this.level != null)
this.level.getProfiler().pop();
}
public static PipeNetwork get(Level level) {

View file

@ -268,6 +268,11 @@ public class PipeBlock extends BaseEntityBlock {
var network = PipeNetwork.get(worldIn);
network.removeNode(pos);
network.onPipeChanged(pos, state);
if (worldIn.getBlockEntity(pos) instanceof PipeBlockEntity pipe) {
pipe.getItems().clear();
for (var lock : pipe.craftIngredientRequests)
network.resolveNetworkLock(lock);
}
super.onRemove(state, worldIn, pos, newState, isMoving);
}
}

View file

@ -33,9 +33,6 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import net.neoforged.neoforge.capabilities.BlockCapability;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.common.util.Lazy;
@ -391,15 +388,6 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
}).filter(Objects::nonNull).collect(Collectors.toList());
}
@Override
public void setRemoved() {
super.setRemoved();
this.getItems().clear();
var network = PipeNetwork.get(this.level);
for (var lock : this.craftIngredientRequests)
network.resolveNetworkLock(lock);
}
@Override
public Component getDisplayName() {
return Component.translatable("container." + PrettyPipes.ID + ".pipe");