From 8373a333015b8f33a75a83cf684e856ecace2bf0 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Mon, 2 Jun 2014 01:32:38 -0500 Subject: [PATCH 1/2] Interface now validates if its plan makes sense... --- helpers/DualityInterface.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/helpers/DualityInterface.java b/helpers/DualityInterface.java index 8503de489..a60d5ea71 100644 --- a/helpers/DualityInterface.java +++ b/helpers/DualityInterface.java @@ -242,6 +242,13 @@ public class DualityInterface implements IGridTickable, ISegmentedInventory, ISt if ( itemStack.getStackSize() > 0 ) { + // make sure strange things didn't happen... + if ( adaptor.simulateAdd( itemStack.getItemStack() ) != null ) + { + changed = true; + throw new GridAccessException(); + } + IAEItemStack aquired = Platform.poweredExtraction( src, destination, itemStack, mySrc ); if ( aquired != null ) { @@ -258,6 +265,14 @@ public class DualityInterface implements IGridTickable, ISegmentedInventory, ISt long diff = toStore.getStackSize(); + // make sure strange things didn't happen... + ItemStack canExtract = adaptor.simulateRemove( (int) diff, toStore.getItemStack(), null ); + if ( canExtract == null || canExtract.stackSize != diff ) + { + changed = true; + throw new GridAccessException(); + } + toStore = Platform.poweredInsert( src, destination, toStore, mySrc ); if ( toStore != null ) @@ -269,9 +284,9 @@ public class DualityInterface implements IGridTickable, ISegmentedInventory, ISt changed = true; ItemStack removed = adaptor.removeItems( (int) diff, null, null ); if ( removed == null ) - throw new RuntimeException( "bad attempt at managing inventory. ( addItems )" ); + throw new RuntimeException( "bad attempt at managing inventory. ( removeItems )" ); else if ( removed.stackSize != diff ) - throw new RuntimeException( "bad attempt at managing inventory. ( addItems )" ); + throw new RuntimeException( "bad attempt at managing inventory. ( removeItems )" ); } } // else wtf? From 10939b60017f6cc6a014d0e740d32381318218d8 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Mon, 2 Jun 2014 01:33:16 -0500 Subject: [PATCH 2/2] RF Now only inserts up to the overflow. --- tile/powersink/RedstoneFlux.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tile/powersink/RedstoneFlux.java b/tile/powersink/RedstoneFlux.java index 50f4ff2ee..765cda86c 100644 --- a/tile/powersink/RedstoneFlux.java +++ b/tile/powersink/RedstoneFlux.java @@ -21,10 +21,21 @@ public abstract class RedstoneFlux extends RotaryCraft implements IEnergyHandler } else { - double overFlow = injectExternalPower( PowerUnits.RF, maxReceive ); + int demand = (int) Math.floor( getExternalPowerDemand( PowerUnits.RF ) ); + + int ignored = 0; + int insertAmt = maxReceive; + + if ( insertAmt > demand ) + { + ignored = insertAmt - demand; + insertAmt = demand; + } + + double overFlow = injectExternalPower( PowerUnits.RF, insertAmt ); double ox = Math.floor( overFlow ); internalCurrentPower += PowerUnits.RF.convertTo( PowerUnits.AE, overFlow - ox ); - return maxReceive - (int) ox; + return maxReceive - ((int) ox + ignored); } }