forked from xsun2001/Applied-Energistics-2-Unofficial
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from repo-alt/master
Explicit Jabba integration
- Loading branch information
Showing
5 changed files
with
209 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package appeng.integration.modules; | ||
|
||
import appeng.api.AEApi; | ||
import appeng.api.storage.IMEInventory; | ||
import appeng.api.storage.data.IAEItemStack; | ||
import appeng.helpers.Reflected; | ||
import appeng.integration.IIntegrationModule; | ||
import appeng.integration.IntegrationHelper; | ||
import appeng.integration.modules.helpers.JabbaBarrel; | ||
import appeng.integration.modules.helpers.JabbaStorageHandler; | ||
import mcp.mobius.betterbarrels.common.blocks.TileEntityBarrel; | ||
import net.minecraft.tileentity.TileEntity; | ||
|
||
public class Jabba implements IIntegrationModule { | ||
@Reflected | ||
public static Jabba instance; | ||
@Reflected | ||
public Jabba() | ||
{ | ||
IntegrationHelper.testClassExistence( this, mcp.mobius.betterbarrels.common.blocks.TileEntityBarrel.class ); | ||
} | ||
public boolean isBarrel( final TileEntity te ) | ||
{ | ||
return te instanceof TileEntityBarrel; | ||
} | ||
|
||
public IMEInventory<IAEItemStack> getBarrel( final TileEntity te ) | ||
{ | ||
return new JabbaBarrel( te ); | ||
} | ||
|
||
@Override | ||
public void init() | ||
{ | ||
} | ||
|
||
@Override | ||
public void postInit() | ||
{ | ||
AEApi.instance().registries().externalStorage().addExternalStorageInterface( new JabbaStorageHandler() ); | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
src/main/java/appeng/integration/modules/helpers/JabbaBarrel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package appeng.integration.modules.helpers; | ||
|
||
import appeng.api.config.Actionable; | ||
import appeng.api.networking.security.BaseActionSource; | ||
import appeng.api.storage.IMEInventory; | ||
import appeng.api.storage.StorageChannel; | ||
import appeng.api.storage.data.IAEItemStack; | ||
import appeng.api.storage.data.IItemList; | ||
import appeng.util.item.AEItemStack; | ||
import mcp.mobius.betterbarrels.common.blocks.TileEntityBarrel; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.tileentity.TileEntity; | ||
|
||
public class JabbaBarrel implements IMEInventory<IAEItemStack> { | ||
private final TileEntityBarrel barrel; | ||
public JabbaBarrel( final TileEntity te ) | ||
{ | ||
barrel = (TileEntityBarrel)te; | ||
} | ||
@Override | ||
public IAEItemStack injectItems(final IAEItemStack input, final Actionable mode, final BaseActionSource src ) | ||
{ | ||
final ItemStack is = this.barrel.getStoredItemType(); | ||
if( is != null ) | ||
{ | ||
if( input.equals( is ) ) | ||
{ | ||
final long max = this.barrel.getMaxStoredCount(); | ||
long storedItems = is.stackSize; | ||
if( max == storedItems ) | ||
{ | ||
return input; | ||
} | ||
|
||
storedItems += input.getStackSize(); | ||
if( storedItems > max && !barrel.getStorage().isVoid() ) | ||
{ | ||
final IAEItemStack overflow = AEItemStack.create( is ); | ||
overflow.setStackSize( storedItems - max ); | ||
if( mode == Actionable.MODULATE ) | ||
{ | ||
this.barrel.setStoredItemCount( (int) max ); | ||
} | ||
return overflow; | ||
} | ||
else | ||
{ | ||
if( mode == Actionable.MODULATE ) | ||
{ | ||
this.barrel.setStoredItemCount( is.stackSize + (int) input.getStackSize() ); | ||
} | ||
return null; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
if( input.getTagCompound() != null ) | ||
{ | ||
return input; | ||
} | ||
long max = ((long)this.barrel.getStorage().getMaxStacks()) * input.getItemStack().getMaxStackSize(); | ||
if( input.getStackSize() <= max || barrel.getStorage().isVoid() ) | ||
{ | ||
if( mode == Actionable.MODULATE ) | ||
{ | ||
this.barrel.setStoredItemType( input.getItemStack(), (int) input.getStackSize() ); | ||
} | ||
} | ||
else | ||
{ | ||
final IAEItemStack overflow = AEItemStack.create(input.getItemStack()); | ||
overflow.setStackSize(input.getStackSize() - max); | ||
if( mode == Actionable.MODULATE ) | ||
{ | ||
this.barrel.setStoredItemType( input.getItemStack(), (int) max ); | ||
} | ||
return overflow; | ||
} | ||
return null; | ||
} | ||
return input; | ||
} | ||
|
||
@Override | ||
public IAEItemStack extractItems( final IAEItemStack request, final Actionable mode, final BaseActionSource src ) | ||
{ | ||
ItemStack is = this.barrel.getStoredItemType(); | ||
if( request.equals( is ) ) | ||
{ | ||
if( request.getStackSize() >= is.stackSize ) | ||
{ | ||
is = is.copy(); | ||
if( mode == Actionable.MODULATE ) | ||
{ | ||
this.barrel.setStoredItemCount( 0 ); | ||
} | ||
return AEItemStack.create( is ); | ||
} | ||
else | ||
{ | ||
if( mode == Actionable.MODULATE ) | ||
{ | ||
this.barrel.setStoredItemCount( is.stackSize - (int) request.getStackSize() ); | ||
} | ||
return request.copy(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public IItemList<IAEItemStack> getAvailableItems(final IItemList<IAEItemStack> out ) | ||
{ | ||
final ItemStack is = this.barrel.getStoredItemType(); | ||
if( is != null ) | ||
{ | ||
out.add( AEItemStack.create( is ) ); | ||
} | ||
return out; | ||
} | ||
|
||
@Override | ||
public StorageChannel getChannel() | ||
{ | ||
return StorageChannel.ITEMS; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/appeng/integration/modules/helpers/JabbaStorageHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package appeng.integration.modules.helpers; | ||
|
||
import appeng.api.networking.security.BaseActionSource; | ||
import appeng.api.storage.IExternalStorageHandler; | ||
import appeng.api.storage.IMEInventory; | ||
import appeng.api.storage.StorageChannel; | ||
import appeng.api.storage.data.IAEItemStack; | ||
import appeng.integration.modules.Jabba; | ||
import appeng.me.storage.MEMonitorIInventory; | ||
import appeng.util.inv.IMEAdaptor; | ||
import net.minecraft.tileentity.TileEntity; | ||
import net.minecraftforge.common.util.ForgeDirection; | ||
|
||
public class JabbaStorageHandler implements IExternalStorageHandler | ||
{ | ||
@Override | ||
public boolean canHandle( final TileEntity te, final ForgeDirection d, final StorageChannel chan, final BaseActionSource mySrc ) | ||
{ | ||
return chan == StorageChannel.ITEMS && Jabba.instance.isBarrel( te ); | ||
} | ||
|
||
@Override | ||
public IMEInventory<IAEItemStack> getInventory( final TileEntity te, final ForgeDirection d, final StorageChannel chan, final BaseActionSource src ) | ||
{ | ||
if( chan == StorageChannel.ITEMS ) | ||
{ | ||
return new MEMonitorIInventory( new IMEAdaptor( Jabba.instance.getBarrel( te ), src ) ); | ||
} | ||
|
||
return null; | ||
} | ||
} |