2015-06-08 01:41:35 +02:00
|
|
|
/*
|
|
|
|
* 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.api.definitions.IBlockDefinition;
|
|
|
|
import appeng.api.definitions.IBlocks;
|
|
|
|
import appeng.api.definitions.ITileDefinition;
|
|
|
|
import appeng.api.util.IOrientableBlock;
|
|
|
|
import appeng.core.AELog;
|
|
|
|
import appeng.helpers.Reflected;
|
2015-09-25 23:28:57 +02:00
|
|
|
import appeng.integration.IIntegrationModule;
|
2015-08-06 16:01:56 +02:00
|
|
|
import appeng.integration.IntegrationHelper;
|
2015-06-08 01:41:35 +02:00
|
|
|
import appeng.integration.modules.BCHelpers.AECableSchematicTile;
|
|
|
|
import appeng.integration.modules.BCHelpers.AEGenericSchematicTile;
|
|
|
|
import appeng.integration.modules.BCHelpers.AERotatableBlockSchematic;
|
2017-04-12 16:10:13 +02:00
|
|
|
import buildcraft.api.blueprints.BuilderAPI;
|
|
|
|
import buildcraft.api.blueprints.ISchematicRegistry;
|
|
|
|
import com.google.common.base.Optional;
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.lang.reflect.Method;
|
2015-06-08 01:41:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The builder has no interface, because it provides no functionality
|
|
|
|
*
|
|
|
|
* @author thatsIch
|
|
|
|
* @version rv3 - 12.06.2015
|
|
|
|
* @since rv3 12.06.2015
|
|
|
|
*/
|
|
|
|
@Reflected
|
2015-09-25 23:28:57 +02:00
|
|
|
public class BuildCraftBuilder implements IIntegrationModule
|
2015-06-08 01:41:35 +02:00
|
|
|
{
|
|
|
|
@Reflected
|
|
|
|
public static BuildCraftBuilder instance;
|
|
|
|
|
|
|
|
@Reflected
|
|
|
|
public BuildCraftBuilder()
|
|
|
|
{
|
2015-08-06 16:01:56 +02:00
|
|
|
IntegrationHelper.testClassExistence( this, buildcraft.api.blueprints.BuilderAPI.class );
|
|
|
|
IntegrationHelper.testClassExistence( this, buildcraft.api.blueprints.IBuilderContext.class );
|
|
|
|
IntegrationHelper.testClassExistence( this, buildcraft.api.blueprints.ISchematicRegistry.class );
|
|
|
|
IntegrationHelper.testClassExistence( this, buildcraft.api.blueprints.SchematicTile.class );
|
|
|
|
IntegrationHelper.testClassExistence( this, buildcraft.api.blueprints.SchematicBlock.class );
|
2015-06-08 01:41:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void init() throws Throwable
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
this.initBuilderSupport();
|
|
|
|
}
|
2015-09-25 23:10:56 +02:00
|
|
|
catch( final Exception builderSupport )
|
2015-06-08 01:41:35 +02:00
|
|
|
{
|
|
|
|
// not supported?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void postInit()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initBuilderSupport()
|
|
|
|
{
|
|
|
|
final ISchematicRegistry schematicRegistry = BuilderAPI.schematicRegistry;
|
|
|
|
|
|
|
|
final IBlocks blocks = AEApi.instance().definitions().blocks();
|
|
|
|
final IBlockDefinition maybeMultiPart = blocks.multiPart();
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final Method blockDefinition : blocks.getClass().getMethods() )
|
2015-06-08 01:41:35 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final IBlockDefinition def = (IBlockDefinition) blockDefinition.invoke( blocks );
|
|
|
|
final Optional<Block> maybeBlock = def.maybeBlock();
|
|
|
|
if( !maybeBlock.isPresent() )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Block block = maybeBlock.get();
|
|
|
|
if( block instanceof IOrientableBlock && ( (IOrientableBlock) block ).usesMetadata() && !( def instanceof ITileDefinition ) )
|
|
|
|
{
|
|
|
|
schematicRegistry.registerSchematicBlock( block, AERotatableBlockSchematic.class );
|
|
|
|
}
|
|
|
|
else if( maybeMultiPart.isSameAs( new ItemStack( block ) ) )
|
|
|
|
{
|
|
|
|
schematicRegistry.registerSchematicBlock( block, AECableSchematicTile.class );
|
|
|
|
}
|
|
|
|
else if( def instanceof ITileDefinition )
|
|
|
|
{
|
|
|
|
schematicRegistry.registerSchematicBlock( block, AEGenericSchematicTile.class );
|
|
|
|
}
|
|
|
|
}
|
2015-09-25 23:10:56 +02:00
|
|
|
catch( final InvocationTargetException ignore )
|
2015-06-08 01:41:35 +02:00
|
|
|
{
|
2015-11-22 15:54:29 +01:00
|
|
|
AELog.warn( "Encountered problems while initializing the BuildCraft Builder support. Can not invoke the method %s", blockDefinition );
|
2015-06-08 01:41:35 +02:00
|
|
|
}
|
2015-09-25 23:10:56 +02:00
|
|
|
catch( final IllegalAccessException ignore )
|
2015-06-08 01:41:35 +02:00
|
|
|
{
|
2015-11-22 15:54:29 +01:00
|
|
|
AELog.warn( "Encountered problems while initializing the BuildCraft Builder support. Can not access the method %s", blockDefinition );
|
2015-06-08 01:41:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|