@@ -30,13 +30,14 @@ public final class EnergyNetworkHelper {
3030
3131 private EnergyNetworkHelper () {}
3232
33- public record CondenserNetwork (Set <BlockPos > condensers , Set <BlockPos > solarPanels ) {}
33+ public record CondenserNetwork (Set <BlockPos > condensers , Set <BlockPos > solarPanels , Set < BlockPos > parabolas ) {}
3434 public record EnergyNetworkSnapshot (int storedEnergy ,
3535 int capacity ,
3636 int condenserCount ,
3737 int panelCount ,
38- int activePanelCount ) {
39- public static final EnergyNetworkSnapshot EMPTY = new EnergyNetworkSnapshot (0 , 0 , 0 , 0 , 0 );
38+ int activePanelCount ,
39+ int parabolaCount ) {
40+ public static final EnergyNetworkSnapshot EMPTY = new EnergyNetworkSnapshot (0 , 0 , 0 , 0 , 0 , 0 );
4041
4142 public int chargePercent () {
4243 if (capacity <= 0 ) return 0 ;
@@ -54,12 +55,12 @@ public static CondenserNetwork scanCondenserNetwork(ServerLevel level, BlockPos
5455 }
5556
5657 if (startConduits .isEmpty ()) {
57- return new CondenserNetwork (condensers , Set .of ());
58+ return new CondenserNetwork (condensers , Set .of (), Set . of () );
5859 }
5960
6061 ConduitScanResult scan = scanConduits (level , startConduits );
6162 condensers .addAll (scan .condensers ());
62- return new CondenserNetwork (condensers , scan .solarPanels ());
63+ return new CondenserNetwork (condensers , scan .solarPanels (), scan . parabolas () );
6364 }
6465
6566 public static BlockPos findNetworkLeader (Set <BlockPos > condensers ) {
@@ -110,10 +111,75 @@ public static EnergyNetworkSnapshot getNetworkSnapshot(ServerLevel level, BlockP
110111 capacity ,
111112 condensers .size (),
112113 network .solarPanels ().size (),
113- activePanels
114+ activePanels ,
115+ network .parabolas ().size ()
114116 );
115117 }
116118
119+ public static boolean isParabolaOnNetwork (ServerLevel level , BlockPos startNode ) {
120+ Set <BlockPos > startConduits = new HashSet <>();
121+ collectAdjacentConduits (level , startNode , startConduits );
122+ if (startConduits .isEmpty ()) return false ;
123+
124+ ConduitScanResult scan = scanConduits (level , startConduits );
125+ return !scan .parabolas ().isEmpty ();
126+ }
127+
128+ public static boolean isPoweredParabolaOnNetwork (ServerLevel level , BlockPos startNode ) {
129+ Set <BlockPos > startConduits = new HashSet <>();
130+ collectAdjacentConduits (level , startNode , startConduits );
131+ if (startConduits .isEmpty ()) return false ;
132+
133+ ConduitScanResult scan = scanConduits (level , startConduits );
134+ for (BlockPos pos : scan .parabolas ()) {
135+ BlockEntity be = level .getBlockEntity (pos );
136+ if (be instanceof ParabolaBlockEntity parabola && parabola .isPowered ()) {
137+ return true ;
138+ }
139+ }
140+ return false ;
141+ }
142+
143+ public static boolean consumeEnergyFromNetwork (ServerLevel level , BlockPos startNode , int amount ) {
144+ Set <BlockPos > startConduits = new HashSet <>();
145+ collectAdjacentConduits (level , startNode , startConduits );
146+
147+ // Also check if startNode itself is a condenser (though usually we call this from a machine)
148+ if (level .getBlockState (startNode ).is (ModBlocks .ENERGY_CONDENSER )) {
149+ // Logic if starting from a condenser, but usually machines connect TO conduits.
150+ }
151+
152+ if (startConduits .isEmpty ()) return false ;
153+
154+ ConduitScanResult scan = scanConduits (level , startConduits );
155+ return consumeFromCondensers (level , scan .condensers (), amount );
156+ }
157+
158+ private static boolean consumeFromCondensers (ServerLevel level , Set <BlockPos > condenserPositions , int amount ) {
159+ if (condenserPositions .isEmpty ()) return false ;
160+ int totalStored = 0 ;
161+ List <EnergyCondenserBlockEntity > condensers = getCondensers (level , condenserPositions );
162+
163+ for (EnergyCondenserBlockEntity condenser : condensers ) {
164+ totalStored += condenser .getStoredEnergy ();
165+ }
166+
167+ if (totalStored < amount ) return false ;
168+
169+ condensers .sort (Comparator
170+ .comparingInt (EnergyCondenserBlockEntity ::getStoredEnergy )
171+ .reversed ()
172+ .thenComparing (be -> be .getBlockPos (), POS_COMPARATOR ));
173+
174+ int remaining = amount ;
175+ for (EnergyCondenserBlockEntity condenser : condensers ) {
176+ if (remaining <= 0 ) break ;
177+ remaining -= condenser .extractEnergy (remaining );
178+ }
179+
180+ return remaining <= 0 ;
181+ }
182+
117183 public static int distributeEnergy (ServerLevel level , Set <BlockPos > condenserPositions , int amount ) {
118184 if (amount <= 0 || condenserPositions .isEmpty ()) return 0 ;
119185
@@ -210,13 +276,14 @@ private static List<EnergyCondenserBlockEntity> getCondensers(ServerLevel level,
210276 return condensers ;
211277 }
212278
213- private record ConduitScanResult (Set <BlockPos > condensers , Set <BlockPos > solarPanels ) {}
279+ private record ConduitScanResult (Set <BlockPos > condensers , Set <BlockPos > solarPanels , Set < BlockPos > parabolas ) {}
214280
215281 private static ConduitScanResult scanConduits (ServerLevel level , Set <BlockPos > startConduits ) {
216282 Set <BlockPos > visited = new HashSet <>();
217283 ArrayDeque <BlockPos > queue = new ArrayDeque <>();
218284 Set <BlockPos > condensers = new HashSet <>();
219285 Set <BlockPos > solarPanels = new HashSet <>();
286+ Set <BlockPos > parabolas = new HashSet <>();
220287
221288 for (BlockPos start : startConduits ) {
222289 if (level .getBlockState (start ).is (ModBlocks .ENERGY_CONDUIT ) && visited .add (start .immutable ())) {
@@ -245,14 +312,19 @@ private static ConduitScanResult scanConduits(ServerLevel level, Set<BlockPos> s
245312 condensers .add (neighborPos .immutable ());
246313 continue ;
247314 }
315+
316+ if (neighborState .is (ModBlocks .PARABOLA_BLOCK )) {
317+ parabolas .add (neighborPos .immutable ());
318+ continue ;
319+ }
248320
249321 if (isSolarPanelSocketConnection (neighborState , direction )) {
250322 solarPanels .add (neighborPos .immutable ());
251323 }
252324 }
253325 }
254326
255- return new ConduitScanResult (condensers , solarPanels );
327+ return new ConduitScanResult (condensers , solarPanels , parabolas );
256328 }
257329
258330 private static boolean isSolarPanelSocketConnection (BlockState panelState , Direction directionFromConduitToPanel ) {
0 commit comments