Skip to content

Commit

Permalink
Oh yea, spotless exists
Browse files Browse the repository at this point in the history
  • Loading branch information
M-W-K committed Jan 20, 2024
1 parent 1072796 commit e91fb37
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 65 deletions.
6 changes: 3 additions & 3 deletions src/main/java/gregtech/api/pipenet/FlowChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
import gregtech.api.cover.CoverHolder;
import gregtech.api.pipenet.block.IPipeType;

import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;

import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;

import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import org.jetbrains.annotations.Nullable;
import org.jgrapht.Graph;

Expand Down Expand Up @@ -66,6 +65,7 @@ protected void deactivate() {
}

protected abstract double getSourceValue(NodeG<PT, NDT> source);

protected abstract double getSinkValue(NodeG<PT, NDT> sink);

public void addSource(NodeG<PT, NDT> source) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/api/pipenet/NetGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public boolean splitEdge(NodeG<PipeType, NodeDataType> source, NodeG<PipeType, N
if (this.net.isFlow()) {
// remove our owned nodes from their manager, and remove their nodes from our manager.
new NetGroup<>(this.graph, this.net, targetGroup)
.setChannelManager(this.getChannelManager().subManager(this.nodes));
.setChannelManager(this.getChannelManager().subManager(this.nodes));
this.getChannelManager().removeNodes(targetGroup);
} else {
new NetGroup<>(this.graph, this.net, targetGroup);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/gregtech/api/pipenet/NodeG.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import gregtech.api.pipenet.block.IPipeType;
import gregtech.api.pipenet.tile.IPipeTile;

import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
Expand All @@ -14,6 +12,7 @@
import net.minecraftforge.fml.relauncher.SideOnly;

import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import org.jetbrains.annotations.Nullable;

import java.lang.ref.WeakReference;
Expand Down Expand Up @@ -289,6 +288,7 @@ public boolean canSupportChannel(FlowChannel<PipeType, NodeDataType> channel) {

/**
* Adds a channel to a node's collection. Cannot go over the node's chnnael limit.
*
* @param channel the channel to add.
* @return {@code true} if the channel was added.
*/
Expand All @@ -302,6 +302,7 @@ public boolean addChannel(FlowChannel<PipeType, NodeDataType> channel) {

/**
* Removes a channel from a node's collection.
*
* @param channel the channel to remove.
* @return {@code true} if the channel was in the node's collection.
*/
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/gregtech/api/pipenet/WorldPipeFlowNetG.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
import gregtech.api.pipenet.alg.MaximumFlowAlgorithm;
import gregtech.api.pipenet.block.IPipeType;

import net.minecraftforge.fluids.Fluid;

import org.jgrapht.graph.SimpleDirectedWeightedGraph;
import org.jgrapht.graph.SimpleWeightedGraph;

public abstract class WorldPipeFlowNetG<NodeDataType extends INodeData<NodeDataType>,
PipeType extends Enum<PipeType> & IPipeType<NodeDataType>> extends WorldPipeNetG<NodeDataType, PipeType> {

/**
* @param isDirected Determines whether this net needs directed graph handling.
* Used to respect filter directions in the item net and fluid net, for example.
* If the graph is not directed, pipes should not support blocked connections.
* @param isDirected Determines whether this net needs directed graph handling.
* Used to respect filter directions in the item net and fluid net, for example.
* If the graph is not directed, pipes should not support blocked connections.
*/
public WorldPipeFlowNetG(String name, boolean isDirected) {
super(name, isDirected, false, true);
Expand All @@ -37,7 +35,8 @@ public interface IFlowGraph<NDT extends INodeData<NDT>, PT extends Enum<PT> & IP
}

protected static class FlowUndirected<NDT extends INodeData<NDT>, PT extends Enum<PT> & IPipeType<NDT>>
extends SimpleWeightedGraph<NodeG<PT, NDT>, NetEdge> implements IFlowGraph<NDT, PT> {
extends SimpleWeightedGraph<NodeG<PT, NDT>, NetEdge>
implements IFlowGraph<NDT, PT> {

Object testObject;
FlowChannel<PT, NDT> queryingChannel;
Expand All @@ -64,7 +63,8 @@ public void setQueryingChannel(FlowChannel<PT, NDT> channel) {
}

protected static class FlowDirected<NDT extends INodeData<NDT>, PT extends Enum<PT> & IPipeType<NDT>>
extends SimpleDirectedWeightedGraph<NodeG<PT, NDT>, NetEdge> implements IFlowGraph<NDT, PT> {
extends SimpleDirectedWeightedGraph<NodeG<PT, NDT>, NetEdge>
implements IFlowGraph<NDT, PT> {

Object testObject;
FlowChannel<PT, NDT> queryingChannel;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/gregtech/api/pipenet/WorldPipeNetG.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ public WorldPipeNetG(String name, boolean isDirected, boolean isSinglePath) {
public final boolean isDirected() {
return isDirected;
}

public final boolean isSinglePath() {
return isSinglePath;
}

public final boolean isFlow() {
return isFlow;
}
Expand Down Expand Up @@ -505,5 +507,4 @@ public NBTTagCompound writeToNBT(@NotNull NBTTagCompound compound) {
* Used for reading persistent node data
*/
protected abstract NodeDataType readNodeData(NBTTagCompound tagCompound);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
import java.util.Map;

public final class MaximumFlowAlgorithm<PT extends Enum<PT> & IPipeType<NDT>, NDT extends INodeData<NDT>>
extends PushRelabelMFImpl<NodeG<PT, NDT>, NetEdge> implements NetAlgorithm<PT, NDT> {
extends PushRelabelMFImpl<NodeG<PT, NDT>, NetEdge>
implements NetAlgorithm<PT, NDT> {

private NodeG<PT, NDT> superSource = new NodeG<>();
private Map<NodeG<PT, NDT>, Double> activeSources = new Object2DoubleOpenHashMap<>();

private NodeG<PT, NDT> superSink = new NodeG<>();
private Map<NodeG<PT, NDT>, Double> activeSinks = new Object2DoubleOpenHashMap<>();


public MaximumFlowAlgorithm(Graph<NodeG<PT, NDT>, NetEdge> network) {
super(network);
}
Expand All @@ -40,7 +40,7 @@ public List<NetPath<PT, NDT>> getPathsList(NodeG<PT, NDT> source) {

for (NodeG<PT, NDT> v : source.getGroupSafe().getNodes()) {
if (v == source) continue;
// paths.add(new FlowPath<>(wrapper));
// paths.add(new FlowPath<>(wrapper));
}
return paths;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public final class ShortestPathsAlgorithm<PT extends Enum<PT> & IPipeType<NDT>,
NDT extends INodeData<NDT>> extends CHManyToManyShortestPaths<NodeG<PT, NDT>, NetEdge>
implements NetAlgorithm<PT, NDT> {
implements NetAlgorithm<PT, NDT> {

public ShortestPathsAlgorithm(Graph<NodeG<PT, NDT>, NetEdge> graph) {
super(graph);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.List;

public final class SinglePathAlgorithm<PT extends Enum<PT> & IPipeType<NDT>, NDT extends INodeData<NDT>>
implements NetAlgorithm<PT, NDT> {
implements NetAlgorithm<PT, NDT> {

private final Graph<NodeG<PT, NDT>, NetEdge> graph;
private final boolean isDirected;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import gregtech.api.util.GTUtility;
import gregtech.client.renderer.pipe.CableRenderer;
import gregtech.client.renderer.pipe.PipeRenderer;
import gregtech.common.pipelike.cable.net.WorldEnergyNet;
import gregtech.common.creativetab.GTCreativeTabs;
import gregtech.common.pipelike.cable.net.WorldEnergyNet;
import gregtech.common.pipelike.cable.tile.TileEntityCable;
import gregtech.common.pipelike.cable.tile.TileEntityCableTickable;
import gregtech.core.advancement.AdvancementTriggers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,27 @@

import gregtech.api.cover.Cover;
import gregtech.api.pipenet.FlowChannel;
import gregtech.api.pipenet.FlowChannelManager;
import gregtech.api.pipenet.NetEdge;
import gregtech.api.pipenet.NetGroup;
import gregtech.api.pipenet.NodeG;

import gregtech.api.pipenet.WorldPipeFlowNetG;
import gregtech.api.pipenet.alg.MaximumFlowAlgorithm;

import gregtech.api.unification.material.properties.FluidPipeProperties;
import gregtech.common.covers.CoverPump;
import gregtech.common.covers.CoverShutter;
import gregtech.common.covers.ManualImportExportMode;
import gregtech.common.covers.filter.FluidFilter;
import gregtech.common.covers.filter.FluidFilterContainer;
import gregtech.common.pipelike.fluidpipe.FluidPipeType;

import gregtech.common.pipelike.fluidpipe.tile.TileEntityFluidPipeTickable;

import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap;

import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;

import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;

import net.minecraftforge.fluids.capability.CapabilityFluidHandler;

import net.minecraftforge.fluids.capability.IFluidHandler;

import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import org.jgrapht.Graph;

import java.util.Map;
Expand Down Expand Up @@ -65,12 +55,11 @@ public void evaluate() {

activate();

if (network instanceof WorldPipeFlowNetG.IFlowGraph<?, ?> graph) {
if (network instanceof WorldPipeFlowNetG.IFlowGraph<?, ?>graph) {
graph.setTestObject(fluid.getFluid());
((WorldPipeFlowNetG.IFlowGraph<FluidPipeProperties, FluidPipeType>) graph)
.setQueryingChannel(this);
}
else throw new IllegalStateException("Attempted to do flow calculations on a non-flow graph!");
} else throw new IllegalStateException("Attempted to do flow calculations on a non-flow graph!");

if (alg == null) alg = new MaximumFlowAlgorithm<>(network);

Expand All @@ -87,7 +76,7 @@ public void evaluate() {
nodes.add((NodeG<FluidPipeType, FluidPipeProperties>) flow.getKey().getSource());
nodes.add((NodeG<FluidPipeType, FluidPipeProperties>) flow.getKey().getTarget());
}

for (NodeG<FluidPipeType, FluidPipeProperties> node : nodes) {
// dataless nodes are only the superSource and superSink
if (node.getData() == null) continue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gregtech.common.pipelike.fluidpipe.net;

import gregtech.api.pipenet.WorldPipeFlowNetG;
import gregtech.api.pipenet.WorldPipeNetG;
import gregtech.api.pipenet.tile.IPipeTile;
import gregtech.api.unification.material.properties.FluidPipeProperties;
import gregtech.common.pipelike.fluidpipe.FluidPipeType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,34 +73,34 @@ public <T> T getCapabilityInternal(Capability<T> capability, @Nullable EnumFacin

@Override
public void update() {
// timer++;
// timer++;
getCoverableImplementation().update();
// if (!world.isRemote && getOffsetTimer() % FREQUENCY == 0) {
// lastReceivedFrom &= 63;
// if (lastReceivedFrom == 63) {
// lastReceivedFrom = 0;
// }
//
// boolean shouldDistribute = (oldLastReceivedFrom == lastReceivedFrom);
// int tanks = getNodeData().getTanks();
// for (int i = 0, j = GTValues.RNG.nextInt(tanks); i < tanks; i++) {
// int index = (i + j) % tanks;
// FluidTank tank = getFluidTanks()[index];
// FluidStack fluid = tank.getFluid();
// if (fluid == null)
// continue;
// if (fluid.amount <= 0) {
// tank.setFluid(null);
// continue;
// }
//
// if (shouldDistribute) {
// distributeFluid(index, tank, fluid);
// lastReceivedFrom = 0;
// }
// }
// oldLastReceivedFrom = lastReceivedFrom;
// }
// if (!world.isRemote && getOffsetTimer() % FREQUENCY == 0) {
// lastReceivedFrom &= 63;
// if (lastReceivedFrom == 63) {
// lastReceivedFrom = 0;
// }
//
// boolean shouldDistribute = (oldLastReceivedFrom == lastReceivedFrom);
// int tanks = getNodeData().getTanks();
// for (int i = 0, j = GTValues.RNG.nextInt(tanks); i < tanks; i++) {
// int index = (i + j) % tanks;
// FluidTank tank = getFluidTanks()[index];
// FluidStack fluid = tank.getFluid();
// if (fluid == null)
// continue;
// if (fluid.amount <= 0) {
// tank.setFluid(null);
// continue;
// }
//
// if (shouldDistribute) {
// distributeFluid(index, tank, fluid);
// lastReceivedFrom = 0;
// }
// }
// oldLastReceivedFrom = lastReceivedFrom;
// }
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public boolean canBridge(@NotNull Collection<IOpticalComputationProvider> seen)
}

private void setPipesActive() {
NetGroup<OpticalPipeType, OpticalPipeProperties> group = getNet().getNode(this.pipe.getPipePos()).getGroupSafe();
NetGroup<OpticalPipeType, OpticalPipeProperties> group = getNet().getNode(this.pipe.getPipePos())
.getGroupSafe();
if (group != null) {
for (NodeG<OpticalPipeType, OpticalPipeProperties> node : group.getNodes()) {
if (node.getHeldMTE() instanceof TileEntityOpticalPipe opticalPipe) {
Expand Down

0 comments on commit e91fb37

Please sign in to comment.