Skip to content

Commit

Permalink
Merge pull request #83 from repo-alt/master
Browse files Browse the repository at this point in the history
Explicit Jabba integration
  • Loading branch information
Dream-Master authored Dec 18, 2021
2 parents 9732688 + 4815c81 commit 9154b44
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 1 deletion.
3 changes: 3 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ dependencies {
compileOnly("com.github.GTNewHorizons:Railcraft:master-SNAPSHOT:api") {
transitive = false
}
compileOnly("com.github.GTNewHorizons:Jabba:master-SNAPSHOT:dev") {
transitive = false
}

compileOnly("com.mod-buildcraft:buildcraft:7.1.23:dev") {
transitive = false
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/appeng/integration/IntegrationType.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ public enum IntegrationType

GT( IntegrationSide.BOTH, "GregTech", "gregtech" ),

Chisel(IntegrationSide.BOTH, "Chisel", "chisel");
Chisel(IntegrationSide.BOTH, "Chisel", "chisel"),

Jabba(IntegrationSide.BOTH, "Jabba", "JABBA")
;

public final IntegrationSide side;
public final String dspName;
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/appeng/integration/modules/Jabba.java
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 src/main/java/appeng/integration/modules/helpers/JabbaBarrel.java
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;
}
}
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;
}
}

0 comments on commit 9154b44

Please sign in to comment.