Merge pull request #13 from GTNewHorizons/overflow

fix int overflow in fluid storage cell
This commit is contained in:
Martin Robertz authored and GitHub committed 2022-09-01 11:32:26 +02:00
commit 76f2ddf18e
2 files changed
+12 -11

No files matched your search

+1 -1
View File
@@ -4,7 +4,7 @@ dependencies {
compile('com.github.GTNewHorizons:NotEnoughItems:2.2.17-GTNH:dev') compile('com.github.GTNewHorizons:NotEnoughItems:2.2.17-GTNH:dev')
compile('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-92-GTNH:dev') compile('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-92-GTNH:dev')
compile('curse.maven:cofh-core-69162:2388751') compile('curse.maven:cofh-core-69162:2388751')
compile('com.github.GTNewHorizons:ExtraCells2:2.5.9:dev') {transitive = false} compile('com.github.GTNewHorizons:ExtraCells2:2.5.20:dev') {transitive = false}
compile("com.github.GTNewHorizons:WirelessCraftingTerminal:1.8.8.5:dev") compile("com.github.GTNewHorizons:WirelessCraftingTerminal:1.8.8.5:dev")
compileOnly("com.github.GTNewHorizons:ForestryMC:4.4.7:dev") compileOnly("com.github.GTNewHorizons:ForestryMC:4.4.7:dev")
@@ -31,7 +31,7 @@ public class FluidCellInventory implements IFluidCellInventory {
private final ItemStack cellItem; private final ItemStack cellItem;
private final ISaveProvider container; private final ISaveProvider container;
private final static int MAX_TYPE = 1; private final static int MAX_TYPE = 1;
private int storedFluidCount; private long storedFluidCount;
private short storedFluids; private short storedFluids;
private IItemList<IAEFluidStack> cellItems; private IItemList<IAEFluidStack> cellItems;
private final NBTTagCompound tagCompound; private final NBTTagCompound tagCompound;
@@ -78,7 +78,7 @@ public class FluidCellInventory implements IFluidCellInventory {
this.container = container; this.container = container;
this.tagCompound = Platform.openNbtData( o ); this.tagCompound = Platform.openNbtData( o );
this.storedFluids = this.tagCompound.getShort( FLUID_TYPE_TAG ); this.storedFluids = this.tagCompound.getShort( FLUID_TYPE_TAG );
this.storedFluidCount = this.tagCompound.getInteger( FLUID_COUNT_TAG ); this.storedFluidCount = this.tagCompound.getLong( FLUID_COUNT_TAG );
this.cellItems = null; this.cellItems = null;
} }
@@ -221,14 +221,15 @@ public class FluidCellInventory implements IFluidCellInventory {
for( int x = 0; x < types; x++ ) for( int x = 0; x < types; x++ )
{ {
final FluidStack t = FluidStack.loadFluidStackFromNBT( this.tagCompound.getCompoundTag( fluidSlots[x] ) ); final FluidStack t = FluidStack.loadFluidStackFromNBT( this.tagCompound.getCompoundTag( fluidSlots[x] ) );
final AEFluidStack aet = AEFluidStack.create( t );
if( t != null ) if( aet != null )
{ {
t.amount = this.tagCompound.getInteger( fluidSlotCount[x] ); aet.setStackSize( this.tagCompound.getLong( fluidSlotCount[x] ) );
if( t.amount > 0 ) if( aet.getStackSize() > 0 )
{ {
this.cellItems.add( AEFluidStack.create( t ) ); this.cellItems.add( aet );
} }
} }
} }
@@ -247,12 +248,12 @@ public class FluidCellInventory implements IFluidCellInventory {
private void updateFluidCount( final long delta ) private void updateFluidCount( final long delta )
{ {
this.storedFluidCount += delta; this.storedFluidCount += delta;
this.tagCompound.setInteger( FLUID_COUNT_TAG, this.storedFluidCount ); this.tagCompound.setLong( FLUID_COUNT_TAG, this.storedFluidCount );
} }
private void saveChanges() private void saveChanges()
{ {
int itemCount = 0; long itemCount = 0;
int x = 0; int x = 0;
@@ -277,7 +278,7 @@ public class FluidCellInventory implements IFluidCellInventory {
* NBTBase tagSlotCount = tagCompound.getTag( itemSlotCount[x] ); if ( tagSlotCount instanceof * NBTBase tagSlotCount = tagCompound.getTag( itemSlotCount[x] ); if ( tagSlotCount instanceof
* NBTTagInt ) ((NBTTagInt) tagSlotCount).data = (int) v.getStackSize(); else * NBTTagInt ) ((NBTTagInt) tagSlotCount).data = (int) v.getStackSize(); else
*/ */
this.tagCompound.setInteger( fluidSlotCount[x], (int) v.getStackSize() ); this.tagCompound.setLong( fluidSlotCount[x], v.getStackSize() );
x++; x++;
} }
@@ -312,7 +313,7 @@ public class FluidCellInventory implements IFluidCellInventory {
} }
else else
{ {
this.tagCompound.setInteger( FLUID_COUNT_TAG, itemCount ); this.tagCompound.setLong( FLUID_COUNT_TAG, itemCount );
} }
// clean any old crusty stuff... // clean any old crusty stuff...