Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fluid Integration #3341

Closed
wants to merge 10 commits into from
Closed

Fluid Integration #3341

wants to merge 10 commits into from

Conversation

DrummerMC
Copy link
Member

@DrummerMC DrummerMC commented Jan 18, 2018

Work in progress!

  • storage cells
  • storage bus
  • import/export bus
  • fluid terminal
  • recipes

@DrummerMC DrummerMC added this to the rv6.alpha - ? milestone Jan 18, 2018
@DrummerMC DrummerMC self-assigned this Jan 18, 2018
final short oldStoredItems = this.storedItems;

/*
* if ( tagType instanceof NBTTagShort ) ((NBTTagShort) tagType).data = storedItems = (short) cellItems.size();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR This block of commented-out lines of code should be removed. rule

@Override
public IItemList getAvailableItems( final IItemList out )
{
for( final T i : this.getCellItems() )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Rename "i" which hides the field declared at line 62. rule


for( int x = 0; x < this.maxItemTypes; x++ )
{
itemSlots[x] = ITEM_SLOT + x;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Remove this assignment of "itemSlots". rule

for( int x = 0; x < this.maxItemTypes; x++ )
{
itemSlots[x] = ITEM_SLOT + x;
itemSlotCount[x] = ITEM_SLOT_COUNT + x;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Remove this assignment of "itemSlotCount". rule


protected void saveChanges()
{
// cellItems.clean();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR This block of commented-out lines of code should be removed. rule

this.loadCellItem( compoundTag, stackSize );
}

// cellItems.clean();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR This block of commented-out lines of code should be removed. rule


if( o == null )
{
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL Define a constant instead of duplicating this literal "ItemStack was used as a cell, but was not a cell!" 3 times. rule

x++;
}

// NBTBase tagType = tagCompound.getTag( ITEM_TYPE_TAG );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR This block of commented-out lines of code should be removed. rule

this.itemsPerByte = itemsPerByte;
if( itemSlots == null )
{
itemSlots = new String[this.maxItemTypes];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Remove this assignment of "itemSlots". rule

}

/*
* if ( tagCount instanceof NBTTagInt ) ((NBTTagInt) tagCount).data = storedItemCount = itemCount; else

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR This block of commented-out lines of code should be removed. rule

if( itemSlots == null )
{
itemSlots = new String[this.maxItemTypes];
itemSlotCount = new String[this.maxItemTypes];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Remove this assignment of "itemSlotCount". rule

{
return FuzzyMode.valueOf( fz );
}
catch( final Throwable t )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Either log or rethrow this exception. rule
MAJOR Catch Exception instead of Throwable. rule

}
} );

if( player.inventoryContainer != null )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL Refactor this code to not nest more than 3 if/for/while/switch/try statements. rule

return new ActionResult<>( EnumActionResult.SUCCESS, player.getHeldItem( hand ) );
}

private boolean disassembleDrive( final ItemStack stack, final World world, final EntityPlayer player )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL The Cyclomatic Complexity of this method "disassembleDrive" is 12 which is greater than 10 authorized. rule
MAJOR Remove this unused method parameter "world". rule

{
final String list = ( handler.getIncludeExcludeMode() == IncludeExclude.WHITELIST ? GuiText.Included : GuiText.Excluded ).getLocal();

if( handler.isFuzzy() )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL Refactor this code to not nest more than 3 if/for/while/switch/try statements. rule


// drop core
final ItemStack extraB = ia.addItems( this.component.stack( 1 ) );
if( !extraB.isEmpty() )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL Refactor this code to not nest more than 3 if/for/while/switch/try statements. rule

// drop empty storage cell case
AEApi.instance().definitions().materials().emptyStorageCell().maybeStack( 1 ).ifPresent( is -> {
final ItemStack extraA = ia.addItems( is );
if( !extraA.isEmpty() )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL Refactor this code to not nest more than 3 if/for/while/switch/try statements. rule


// drop upgrades
final IItemHandler upgradesInventory = this.getUpgradesInventory( stack );
for( int upgradeIndex = 0; upgradeIndex < upgradesInventory.getSlots(); upgradeIndex++ )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL Refactor this code to not nest more than 3 if/for/while/switch/try statements. rule

}

@Override
public IAEItemStack injectItems( final IAEItemStack input, final Actionable mode, final IActionSource src )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL The Cyclomatic Complexity of this method "injectItems" is 18 which is greater than 10 authorized. rule

{
this.cellItems.add( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( t ) );
}
catch( Throwable ex )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Catch Exception instead of Throwable. rule

{
return new CellInventoryHandler( new ItemCellInventory( o, container2 ), AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
}
catch( final AppEngException e )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Either log or rethrow this exception. rule

{
final ItemStack toReturn = sharedItemStack.copy();
toReturn.setCount( sharedItemStack.getCount() - remainingItemCount );
if( mode == Actionable.MODULATE )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL Refactor this code to not nest more than 3 if/for/while/switch/try statements. rule

return !( (IStorageCell) type ).storableInStorageCell();
}
}
catch( final Throwable err )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Either log or rethrow this exception. rule
MAJOR Catch Exception instead of Throwable. rule

final Item type = i.getItem();
if( type instanceof IStorageCell )
{
if ( ( (IStorageCell) type ).getChannel() == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Merge this if statement with the enclosing one. rule

t = new ItemStack( compoundTag );
if( t.isEmpty() )
{
AELog.warn( "Removing item " + compoundTag + " from storage cell because the associated item type couldn't be found." );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL Define a constant instead of duplicating this literal "Removing item " 3 times. rule


final long size = Math.min( Integer.MAX_VALUE, request.getStackSize() );

IAEItemStack Results = null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Rename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'. rule

return;
}
}
catch( Throwable ex )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Catch Exception instead of Throwable. rule

private final double idleDrain;
public FluidBasicStorageCell( final MaterialType whichCell, final int kilobytes )
{
super(whichCell, kilobytes);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR '(' is not followed by whitespace. rule
MINOR ')' is not preceded with whitespace. rule

return;
}
}
catch( Throwable ex )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Catch Exception instead of Throwable. rule

{
this.cellItems.add( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createStack( t ) );
}
catch( Throwable ex )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Catch Exception instead of Throwable. rule

{
final FluidStack toReturn = sharedFluidStack.copy();
toReturn.amount = sharedFluidStack.amount - remainingItemCount;
if( mode == Actionable.MODULATE )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL Refactor this code to not nest more than 3 if/for/while/switch/try statements. rule

{
return new CellInventoryHandler( new FluidCellInventory( o, container2 ), AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) );
}
catch( final AppEngException e )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Either log or rethrow this exception. rule

final Item type = i.getItem();
if( type instanceof IStorageCell )
{
if( ( (IStorageCell) type ).getChannel() == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Merge this if statement with the enclosing one. rule

}

@Override
public IAEFluidStack injectItems( final IAEFluidStack input, final Actionable mode, final IActionSource src )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL The Cyclomatic Complexity of this method "injectItems" is 15 which is greater than 10 authorized. rule

return input;
}

final FluidStack sharedFluidStack = input.getFluidStack();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Move the declaration of "sharedFluidStack" closer to the code that uses it. rule

t = FluidStack.loadFluidStackFromNBT( compoundTag );
if( t == null )
{
AELog.warn( "Removing item " + compoundTag + " from storage cell because the associated item type couldn't be found." );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL Define a constant instead of duplicating this literal "Removing item " 3 times. rule

@@ -47,23 +50,34 @@
@Override
public boolean isCell( final ItemStack is )
{
return CellInventory.isCell( is );
return ItemCellInventory.isCell( is ) || FluidCellInventory.isCell( is );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be an idea to split it into two handler. Similar to the item and creative handler.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can add an api to add a default cell inventory for IStorageCell of each channel. We can check if the item is a IStorageCell and then use the registerd CellInventory

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already exists with ICellRegistry#getHandler(ItemStack is);

* @version rv6 - 2018-01-17
* @since rv6 2018-01-17
*/
public final class FluidBasicStorageCell extends ItemStorageCellBase<IAEFluidStack>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe BasicFluidStorageCell as well as BasicItemStorageCell?

*/
public class FluidCellInventory extends CellInventoryBase<IAEFluidStack>
{
private static final HashSet<String> BLACK_LIST = new HashSet<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove the blacklist completely. It is mostly obsolete since custom storage channels and it was mostly intended to allow addons to blacklist fake itemstacks for other types. Similar to AE1 and EC1.

Or alternatively it should be extended at some point, but then include API endpoints to allow blacklisting items like containers to avoid NBT/packet corruption due to size limits.

* @version rv6 - 2018-01-17
* @since rv6 2018-01-17
*/
public abstract class ItemStorageCellBase<T extends IAEStack<T>> extends AEBaseItem implements IStorageCell<T>, IItemGroup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming it ItemStorageCellBase might be a bit confusing when later extending it for a fluid version.

Maybe name it AbstractStorageCell to follow the panels/terminals/monitors naming scheme, which is mainly influenced by the naming of java collections or similar classes.

* @version rv6 - 2018-01-17
* @since rv6 2018-01-17
*/
public abstract class CellInventoryBase<T extends IAEStack<T>> implements ICellInventory<T>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here with AbstractCellInventory.


public class ItemCellInventory extends CellInventoryBase<IAEItemStack>
{
private static final HashSet<Integer> BLACK_LIST = new HashSet<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blacklist again.

@leagris
Copy link

leagris commented Jan 18, 2018

Do you plan to implement the most useful feature with liquids, that is:

  • Patterns with fluids and items for workbench machine process

Implementation by ExtraCells2 is:

Create machine pattern with fluid:

In pattern terminal, place fluid containers with required fluid amount and items.
Place result item or fluid container.
Encode machine pattern.
Place pattern in fluid interface.

On-demand crafting:

Fluids in exact amount and items will be transfered to machine via interface.

@yueh
Copy link
Member

yueh commented Jan 18, 2018

No

@yueh
Copy link
Member

yueh commented May 27, 2018

Closed in favour of #3510

@yueh yueh closed this May 27, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 27, 2020
@yueh yueh deleted the feature-fluids branch June 9, 2020 13:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants