Generic ICellInventoryHandler (#3624)
Allows addons who register a custom IStorageChannel to use the IStorageCell interface without registering a cell handler. Also adds some helpers (poweredInsert/poweredExtract). This breaks API!
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.core.features.registries.cell;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.storage.ICellHandler;
|
||||
import appeng.api.storage.ICellInventory;
|
||||
import appeng.api.storage.ICellInventoryHandler;
|
||||
import appeng.api.storage.ISaveProvider;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.me.storage.BasicCellInventory;
|
||||
import appeng.me.storage.BasicCellInventoryHandler;
|
||||
|
||||
|
||||
public class BasicCellHandler implements ICellHandler
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean isCell( final ItemStack is )
|
||||
{
|
||||
return BasicCellInventory.isCell( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends IAEStack<T>> ICellInventoryHandler<T> getCellInventory( final ItemStack is, final ISaveProvider container, final IStorageChannel<T> channel )
|
||||
{
|
||||
final ICellInventory<T> inv = BasicCellInventory.createInventory( is, container );
|
||||
if( inv == null || inv.getChannel() != channel )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new BasicCellInventoryHandler<>( inv, channel );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
package appeng.core.features.registries.cell;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.implementations.tiles.IChestOrDrive;
|
||||
import appeng.api.storage.ICellGuiHandler;
|
||||
import appeng.api.storage.ICellHandler;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class BasicItemCellGuiHandler implements ICellGuiHandler
|
||||
{
|
||||
@Override
|
||||
public <T extends IAEStack<T>> boolean isHandlerFor( final IStorageChannel<T> channel )
|
||||
{
|
||||
return channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openChestGui( final EntityPlayer player, final IChestOrDrive chest, final ICellHandler cellHandler, final IMEInventoryHandler inv, final ItemStack is, final IStorageChannel chan )
|
||||
{
|
||||
Platform.openGUI( player, (TileEntity) chest, AEPartLocation.fromFacing( chest.getUp() ), GuiBridge.GUI_ME );
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.core.features.registries.cell;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.implementations.tiles.IChestOrDrive;
|
||||
import appeng.api.storage.ICellHandler;
|
||||
import appeng.api.storage.ICellInventory;
|
||||
import appeng.api.storage.ICellInventoryHandler;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.ISaveProvider;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.me.storage.ItemCellInventory;
|
||||
import appeng.me.storage.ItemCellInventoryHandler;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class BasicItemCellHandler implements ICellHandler
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean isCell( final ItemStack is )
|
||||
{
|
||||
return ItemCellInventory.isCell( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends IAEStack<T>> ICellInventoryHandler<T> getCellInventory( final ItemStack is, final ISaveProvider container, final IStorageChannel<T> channel )
|
||||
{
|
||||
if( channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
|
||||
{
|
||||
return (ICellInventoryHandler<T>) ItemCellInventory.getCell( is, container );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openChestGui( final EntityPlayer player, final IChestOrDrive chest, final ICellHandler cellHandler, final IMEInventoryHandler inv, final ItemStack is, final IStorageChannel chan )
|
||||
{
|
||||
if( chan == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
|
||||
{
|
||||
Platform.openGUI( player, (TileEntity) chest, AEPartLocation.fromFacing( chest.getUp() ), GuiBridge.GUI_ME );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatusForCell( final ItemStack is, final IMEInventory handler )
|
||||
{
|
||||
if( handler instanceof ItemCellInventoryHandler )
|
||||
{
|
||||
final ItemCellInventoryHandler ci = (ItemCellInventoryHandler) handler;
|
||||
return ci.getStatusForCell();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double cellIdleDrain( final ItemStack is, final IMEInventory handler )
|
||||
{
|
||||
final ICellInventory inv = ( (ICellInventoryHandler) handler ).getCellInv();
|
||||
return inv.getIdleDrain();
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import com.google.common.base.Verify;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.storage.ICellGuiHandler;
|
||||
import appeng.api.storage.ICellHandler;
|
||||
import appeng.api.storage.ICellInventoryHandler;
|
||||
import appeng.api.storage.ICellRegistry;
|
||||
@@ -39,10 +40,12 @@ public class CellRegistry implements ICellRegistry
|
||||
{
|
||||
|
||||
private final List<ICellHandler> handlers;
|
||||
private final List<ICellGuiHandler> guiHandlers;
|
||||
|
||||
public CellRegistry()
|
||||
{
|
||||
this.handlers = new ArrayList<>();
|
||||
this.guiHandlers = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,7 +57,7 @@ public class CellRegistry implements ICellRegistry
|
||||
this.handlers.add( handler );
|
||||
|
||||
// Verify that the first entry is always our own handler.
|
||||
Verify.verify( this.handlers.get( 0 ) instanceof BasicItemCellHandler );
|
||||
Verify.verify( this.handlers.get( 0 ) instanceof BasicCellHandler );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,4 +110,33 @@ public class CellRegistry implements ICellRegistry
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCellGuiHandler( ICellGuiHandler handler )
|
||||
{
|
||||
this.guiHandlers.add( handler );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends IAEStack<T>> ICellGuiHandler getGuiHandler( final IStorageChannel<T> channel, final ItemStack is )
|
||||
{
|
||||
ICellGuiHandler fallBack = null;
|
||||
|
||||
for( final ICellGuiHandler ch : this.guiHandlers )
|
||||
{
|
||||
if( ch.isHandlerFor( channel ) )
|
||||
{
|
||||
if( ch.isSpecializedFor( is ) )
|
||||
{
|
||||
return ch;
|
||||
}
|
||||
|
||||
if( fallBack == null )
|
||||
{
|
||||
fallBack = ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
return fallBack;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,24 +19,16 @@
|
||||
package appeng.core.features.registries.cell;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.implementations.tiles.IChestOrDrive;
|
||||
import appeng.api.storage.ICellHandler;
|
||||
import appeng.api.storage.ICellInventoryHandler;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.ISaveProvider;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.items.storage.ItemCreativeStorageCell;
|
||||
import appeng.me.storage.CreativeCellInventory;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public final class CreativeCellHandler implements ICellHandler
|
||||
@@ -60,19 +52,13 @@ public final class CreativeCellHandler implements ICellHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openChestGui( final EntityPlayer player, final IChestOrDrive chest, final ICellHandler cellHandler, final IMEInventoryHandler inv, final ItemStack is, final IStorageChannel chan )
|
||||
{
|
||||
Platform.openGUI( player, (TileEntity) chest, AEPartLocation.fromFacing( chest.getUp() ), GuiBridge.GUI_ME );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatusForCell( final ItemStack is, final IMEInventory handler )
|
||||
public int getStatusForCell( final ItemStack is, final ICellInventoryHandler handler )
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double cellIdleDrain( final ItemStack is, final IMEInventory handler )
|
||||
public double cellIdleDrain( final ItemStack is, final ICellInventoryHandler handler )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user