Add Logistics Pipes integration

This commit is contained in:
Timo Ley 2021-03-19 11:41:03 +01:00
parent 9f6daacb2d
commit 62b0907395
7 changed files with 441 additions and 0 deletions

View File

@ -34,6 +34,7 @@ code_chicken_lib_version=1.1.3.140
code_chicken_core_version=1.0.7.47
nei_version=1.0.5.120
bc_version=7.0.9
logisticspipes_build=128
opencomputers_version=1.5.12.26
pneumaticcraft_version=1.9.15-105

View File

@ -62,6 +62,13 @@ repositories {
artifactPattern "http://www.mod-buildcraft.com/releases/BuildCraft/[revision]/[module]-[revision]-[classifier].[ext]"
}
ivy {
url "https://ci.rs485.network/job/LogisticsPipes-0.9-mc17-bc7"
layout "pattern", {
artifact "[revision]/artifact/build/libs/[artifact]-0.9.3.[revision](-[classifier]).[ext]"
}
}
// CurseForge DNS for TE is not available or I am just being unlucky, code part can stay since this is applicable to any other curseforge mod though
// ivy {
// name = "CoFHLib"
@ -99,6 +106,7 @@ dependencies {
// mods "net.mcft.copy.betterstorage:BetterStorage:${minecraft_version}-${betterstorage_version}:deobf"
mods "inventorytweaks:InventoryTweaks:${invtweaks_version}:deobf"
mods "li.cil.oc:OpenComputers:MC${minecraft_version}-${opencomputers_version}:dev"
compile "logisticspipes:logisticspipes:${logisticspipes_build}:dev"
// mods name: 'CoFHLib', version: "[${minecraft_version}]${cofhlib_version}-dev", ext: 'jar'
// mods name: 'CoFHCore', version: "[${minecraft_version}]${cofhcore_version}-dev", ext: 'jar'

View File

@ -33,6 +33,8 @@ public enum IntegrationType
BuildCraftBuilder( IntegrationSide.BOTH, "BuildCraft Builders", "BuildCraft|Builders" ),
LogisticsPipes( IntegrationSide.BOTH, "Logistics Pipes", "LogisticsPipes" ),
RF( IntegrationSide.BOTH, "RedstoneFlux Power - Tiles", "CoFHAPI" ),
RFItem( IntegrationSide.BOTH, "RedstoneFlux Power - Items", "CoFHAPI" ),

View File

@ -0,0 +1,59 @@
/*
* 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.integration.abstraction;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* Contains pipe logic to interact between storage buses and pipes
*
* @author Second_Fry
* @version rv3 01.01.2017
* @since rv3 01.01.2017
*/
public interface ILogisticsPipes
{
/**
* checks weather if the {@code te} is injectable and simulates to inject the item
*
* @param te instanceof ILPPipe
* @param is to be injected item
* @param dir direction of the pipe
* @return {@code true} if items were simulated successfully being added
*/
boolean canAddItemsToPipe( TileEntity te, ItemStack is, ForgeDirection dir );
/**
* checks weather if the {@code te} is injectable, simulates the inject and tries to inject the item
*
* @param te instanceof ILPPipe
* @param is to be injected item
* @param dir direction of the pipe
* @return {@code true} if items were added to the buildcraft pipe
*/
boolean addItemsToPipe( @Nullable TileEntity te, @Nullable ItemStack is, @Nonnull ForgeDirection dir );
}

View File

@ -0,0 +1,60 @@
/*
* 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.integration.modules.LPHelpers;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IExternalStorageHandler;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.StorageChannel;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.integration.abstraction.ILogisticsPipes;
import appeng.me.storage.MEMonitorIInventory;
import appeng.util.inv.IMEAdaptor;
import logisticspipes.api.ILPPipeTile;
import logisticspipes.pipes.basic.CoreUnroutedPipe;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class LPPipeHandler implements IExternalStorageHandler
{
@Override
public boolean canHandle( final TileEntity te, final ForgeDirection d, final StorageChannel channel, final BaseActionSource mySrc )
{
if( IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.LogisticsPipes ) )
{
return channel == StorageChannel.ITEMS && te instanceof ILPPipeTile &&
( (CoreUnroutedPipe) ( (ILPPipeTile) te ).getLPPipe() ).canPipeConnect( te, d );
}
return false;
}
@Override
public IMEInventory getInventory( final TileEntity te, final ForgeDirection d, final StorageChannel channel, final BaseActionSource src )
{
if( channel == StorageChannel.ITEMS )
{
return new MEMonitorIInventory( new IMEAdaptor( new LPPipeInventory( te, d ), src ) );
}
return null;
}
}

View File

@ -0,0 +1,200 @@
/*
* 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.integration.modules.LPHelpers;
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.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.integration.abstraction.ILogisticsPipes;
import appeng.tile.grid.AENetworkInvTile;
import appeng.util.item.AEItemStack;
import logisticspipes.api.ILPPipe;
import logisticspipes.api.ILPPipeTile;
import logisticspipes.api.IRequestAPI;
import logisticspipes.pipes.basic.CoreRoutedPipe;
import logisticspipes.proxy.SimpleServiceLocator;
import logisticspipes.routing.ExitRoute;
import logisticspipes.utils.AdjacentTile;
import logisticspipes.utils.item.ItemIdentifier;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class LPPipeInventory implements IMEInventory<IAEItemStack>
{
private final TileEntity te;
private final ForgeDirection direction;
public LPPipeInventory( final TileEntity te, final ForgeDirection direction )
{
this.te = te;
this.direction = direction;
}
@Override
public IAEItemStack injectItems( IAEItemStack input, Actionable type, BaseActionSource src )
{
if( IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.LogisticsPipes ) )
{
ILogisticsPipes registry = (ILogisticsPipes) IntegrationRegistry.INSTANCE.getInstance( IntegrationType.LogisticsPipes );
if( type == Actionable.SIMULATE )
{
if( registry.canAddItemsToPipe( this.te, input.getItemStack(), this.direction ) )
{
return null;
}
return input;
}
if( registry.addItemsToPipe( this.te, input.getItemStack(), this.direction ) )
{
return null;
}
}
return input;
}
@Override
public IAEItemStack extractItems( IAEItemStack request, Actionable type, BaseActionSource src )
{
if( IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.LogisticsPipes ) )
{
ILPPipe pipe = ( (ILPPipeTile) this.te ).getLPPipe();
if( pipe instanceof IRequestAPI )
{
IRequestAPI requestAPI = (IRequestAPI) pipe;
if( type == Actionable.SIMULATE )
{
IRequestAPI.SimulationResult simulation = requestAPI.simulateRequest( request.getItemStack() );
if( simulation.used.size() == 0 )
{
return null;
}
return AEItemStack.create( simulation.used.get( 0 ) );
}
List<ItemStack> returned = requestAPI.performRequest( request.getItemStack() );
if( returned.size() == 0 )
{
return null;
}
return AEItemStack.create( returned.get( 0 ) );
}
}
return null;
}
@Override
public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
{
ILPPipe pipe = ( (ILPPipeTile) this.te ).getLPPipe();
if( pipe instanceof IRequestAPI )
{
List<ItemStack> provided = this.getLPItems( pipe );
for( ItemStack is : provided )
{
out.add( AEItemStack.create( is ) );
}
}
return out;
}
/**
* Get items from Logistics Pipes network _excluding_ AE2 network items. Brilliant!
* (basically rewrite of CoreRoutedPipe.getProvidedItems() (implementation of IRequestAPI.getProvidedItems())
*
* @param pipe IRequestAPI pipe
* @return list of items in shared networks
*/
public List<ItemStack> getLPItems( ILPPipe pipe )
{
CoreRoutedPipe coreRoutedPipeCast = (CoreRoutedPipe) pipe;
if( coreRoutedPipeCast.stillNeedReplace() )
{
return new ArrayList<ItemStack>();
}
else
{
List<ExitRoute> exitRoutes = coreRoutedPipeCast.getRouter().getIRoutersByCost();
ArrayList<ExitRoute> exitRoutesProcessed = new ArrayList<ExitRoute>();
for( ExitRoute exitRoute : exitRoutes )
{
if( !isExitToAE( exitRoute ) )
{
exitRoutesProcessed.add( exitRoute );
}
}
Map items = SimpleServiceLocator.logisticsManager.getAvailableItems( exitRoutesProcessed );
ArrayList list = new ArrayList( items.size() );
for( Object o : items.entrySet() )
{
Map.Entry item = (Map.Entry) o;
ItemStack is = ( (ItemIdentifier) item.getKey() ).unsafeMakeNormalStack( ( (Integer) item.getValue() ).intValue() );
list.add( is );
}
return list;
}
}
/**
* Checks ExitRoute for connected AENetworkInvTiles
*
* @param exitRoute Logistics Pipes exit route to check
* @return true if AENetworkInvTiles is connected, otherwise false
*/
private boolean isExitToAE( ExitRoute exitRoute )
{
LinkedList<AdjacentTile> connectedEntities = exitRoute.destination.getPipe().getConnectedEntities();
for( AdjacentTile connectedEntity : connectedEntities )
{
if( connectedEntity.tile instanceof AENetworkInvTile )
{
return true;
}
}
return false;
}
@Override
public StorageChannel getChannel()
{
return StorageChannel.ITEMS;
}
}

View File

@ -0,0 +1,111 @@
/*
* 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.integration.modules;
import appeng.api.AEApi;
import appeng.helpers.Reflected;
import appeng.integration.IIntegrationModule;
import appeng.integration.IntegrationHelper;
import appeng.integration.abstraction.ILogisticsPipes;
import appeng.integration.modules.LPHelpers.LPPipeHandler;
import buildcraft.api.transport.IInjectable;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import javax.annotation.Nonnull;
/**
* @author Second_Fry
* @version rv3 - 12.06.2015
* @since rv3 12.06.2015
*/
@Reflected
public class LogisticsPipes implements ILogisticsPipes, IIntegrationModule
{
@Reflected
public static LogisticsPipes instance;
@Reflected
public LogisticsPipes()
{
IntegrationHelper.testClassExistence( this, logisticspipes.api.ILPPipe.class );
IntegrationHelper.testClassExistence( this, logisticspipes.api.ILPPipeTile.class );
IntegrationHelper.testClassExistence( this, logisticspipes.api.IRequestAPI.class );
IntegrationHelper.testClassExistence( this, logisticspipes.pipes.basic.CoreRoutedPipe.class );
IntegrationHelper.testClassExistence( this, logisticspipes.proxy.SimpleServiceLocator.class );
IntegrationHelper.testClassExistence( this, logisticspipes.routing.ExitRoute.class );
IntegrationHelper.testClassExistence( this, logisticspipes.utils.AdjacentTile.class );
IntegrationHelper.testClassExistence( this, logisticspipes.utils.item.ItemIdentifier.class );
}
@Override
public void init() throws Throwable
{
}
@Override
public void postInit()
{
AEApi.instance().registries().externalStorage().addExternalStorageInterface( new LPPipeHandler() );
}
@Override
public boolean canAddItemsToPipe( final TileEntity te, final ItemStack is, final ForgeDirection direction )
{
if( is != null && te != null && te instanceof IInjectable )
{
final IInjectable pt = (IInjectable) te;
if( pt.canInjectItems( direction ) )
{
final int amt = pt.injectItem( is, false, direction, null );
if( amt == is.stackSize )
{
return true;
}
}
}
return false;
}
@Override
public boolean addItemsToPipe( final TileEntity te, final ItemStack is, @Nonnull final ForgeDirection direction )
{
if( is != null && te != null && te instanceof IInjectable )
{
final IInjectable pt = (IInjectable) te;
if( pt.canInjectItems( direction ) )
{
final int amt = pt.injectItem( is, false, direction, null );
if( amt == is.stackSize )
{
pt.injectItem( is, true, direction, null );
return true;
}
}
}
return false;
}
}