Applied-Energistics-2-tiler.../src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java

177 lines
6.8 KiB
Java
Raw Normal View History

2014-11-14 12:02:52 +01:00
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
2014-11-14 12:02:52 +01:00
*
* 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>.
*/
2014-09-24 02:26:27 +02:00
package appeng.core.features.registries;
2014-09-24 02:26:27 +02:00
import java.util.HashMap;
import java.util.Map;
2015-06-16 02:44:59 +02:00
import javax.annotation.Nullable;
2014-09-24 02:26:27 +02:00
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
2015-06-16 02:44:59 +02:00
import net.minecraft.item.Item;
2014-09-24 02:26:27 +02:00
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
2015-12-24 02:07:03 +01:00
2014-09-24 02:26:27 +02:00
import appeng.api.AEApi;
import appeng.api.config.TunnelType;
import appeng.api.definitions.IBlocks;
import appeng.api.definitions.IDefinitions;
import appeng.api.definitions.IItemDefinition;
import appeng.api.definitions.IParts;
2014-09-24 02:26:27 +02:00
import appeng.api.features.IP2PTunnelRegistry;
import appeng.api.util.AEColor;
import appeng.util.Platform;
public final class P2PTunnelRegistry implements IP2PTunnelRegistry
2014-09-24 02:26:27 +02:00
{
private static final int INITIAL_CAPACITY = 40;
2014-09-24 02:26:27 +02:00
private final Map<ItemStack, TunnelType> tunnels = new HashMap<ItemStack, TunnelType>( INITIAL_CAPACITY );
2014-09-24 02:26:27 +02:00
public void configure()
{
/**
* light!
*/
this.addNewAttunement( new ItemStack( Blocks.TORCH ), TunnelType.LIGHT );
this.addNewAttunement( new ItemStack( Blocks.GLOWSTONE ), TunnelType.LIGHT );
2014-09-24 02:26:27 +02:00
/**
* attune based on most redstone base items.
*/
this.addNewAttunement( new ItemStack( Items.REDSTONE ), TunnelType.REDSTONE );
this.addNewAttunement( new ItemStack( Items.REPEATER ), TunnelType.REDSTONE );
this.addNewAttunement( new ItemStack( Blocks.REDSTONE_LAMP ), TunnelType.REDSTONE );
this.addNewAttunement( new ItemStack( Blocks.UNPOWERED_COMPARATOR ), TunnelType.REDSTONE );
this.addNewAttunement( new ItemStack( Blocks.POWERED_COMPARATOR ), TunnelType.REDSTONE );
this.addNewAttunement( new ItemStack( Blocks.POWERED_REPEATER ), TunnelType.REDSTONE );
this.addNewAttunement( new ItemStack( Blocks.UNPOWERED_REPEATER ), TunnelType.REDSTONE );
this.addNewAttunement( new ItemStack( Blocks.DAYLIGHT_DETECTOR ), TunnelType.REDSTONE );
this.addNewAttunement( new ItemStack( Blocks.REDSTONE_WIRE ), TunnelType.REDSTONE );
this.addNewAttunement( new ItemStack( Blocks.REDSTONE_BLOCK ), TunnelType.REDSTONE );
this.addNewAttunement( new ItemStack( Blocks.LEVER ), TunnelType.REDSTONE );
2014-12-29 15:13:47 +01:00
this.addNewAttunement( this.getModItem( "EnderIO", "itemRedstoneConduit", OreDictionary.WILDCARD_VALUE ), TunnelType.REDSTONE );
2014-09-24 02:26:27 +02:00
/**
* attune based on lots of random item related stuff
*/
final IDefinitions definitions = AEApi.instance().definitions();
final IBlocks blocks = definitions.blocks();
final IParts parts = definitions.parts();
this.addNewAttunement( blocks.iface(), TunnelType.ITEM );
this.addNewAttunement( parts.iface(), TunnelType.ITEM );
this.addNewAttunement( parts.storageBus(), TunnelType.ITEM );
this.addNewAttunement( parts.importBus(), TunnelType.ITEM );
this.addNewAttunement( parts.exportBus(), TunnelType.ITEM );
this.addNewAttunement( new ItemStack( Blocks.HOPPER ), TunnelType.ITEM );
this.addNewAttunement( new ItemStack( Blocks.CHEST ), TunnelType.ITEM );
this.addNewAttunement( new ItemStack( Blocks.TRAPPED_CHEST ), TunnelType.ITEM );
2014-12-29 15:13:47 +01:00
this.addNewAttunement( this.getModItem( "ExtraUtilities", "extractor_base", 0 ), TunnelType.ITEM );
this.addNewAttunement( this.getModItem( "Mekanism", "PartTransmitter", 9 ), TunnelType.ITEM );
this.addNewAttunement( this.getModItem( "EnderIO", "itemItemConduit", OreDictionary.WILDCARD_VALUE ), TunnelType.ITEM );
this.addNewAttunement( this.getModItem( "ThermalDynamics", "ThermalDynamics_32", 0 ), TunnelType.ITEM );
2014-09-24 02:26:27 +02:00
/**
* attune based on lots of random item related stuff
*/
this.addNewAttunement( new ItemStack( Items.BUCKET ), TunnelType.FLUID );
this.addNewAttunement( new ItemStack( Items.LAVA_BUCKET ), TunnelType.FLUID );
this.addNewAttunement( new ItemStack( Items.MILK_BUCKET ), TunnelType.FLUID );
this.addNewAttunement( new ItemStack( Items.WATER_BUCKET ), TunnelType.FLUID );
2014-12-29 15:13:47 +01:00
this.addNewAttunement( this.getModItem( "Mekanism", "MachineBlock2", 11 ), TunnelType.FLUID );
this.addNewAttunement( this.getModItem( "Mekanism", "PartTransmitter", 4 ), TunnelType.FLUID );
this.addNewAttunement( this.getModItem( "ExtraUtilities", "extractor_base", 6 ), TunnelType.FLUID );
this.addNewAttunement( this.getModItem( "ExtraUtilities", "drum", OreDictionary.WILDCARD_VALUE ), TunnelType.FLUID );
this.addNewAttunement( this.getModItem( "EnderIO", "itemLiquidConduit", OreDictionary.WILDCARD_VALUE ), TunnelType.FLUID );
this.addNewAttunement( this.getModItem( "ThermalDynamics", "ThermalDynamics_16", 0 ), TunnelType.FLUID );
2014-09-24 02:26:27 +02:00
2015-09-30 14:24:40 +02:00
for( final AEColor c : AEColor.values() )
2014-09-24 02:26:27 +02:00
{
this.addNewAttunement( parts.cableGlass().stack( c, 1 ), TunnelType.ME );
this.addNewAttunement( parts.cableCovered().stack( c, 1 ), TunnelType.ME );
this.addNewAttunement( parts.cableSmart().stack( c, 1 ), TunnelType.ME );
this.addNewAttunement( parts.cableDense().stack( c, 1 ), TunnelType.ME );
}
}
2014-09-24 02:26:27 +02:00
@Override
2015-09-30 14:24:40 +02:00
public void addNewAttunement( @Nullable final ItemStack trigger, @Nullable final TunnelType type )
2014-09-24 02:26:27 +02:00
{
if( type == null || trigger == null )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
return;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
this.tunnels.put( trigger, type );
}
@Nullable
2014-09-24 02:26:27 +02:00
@Override
2015-09-30 14:24:40 +02:00
public TunnelType getTunnelTypeByItem( final ItemStack trigger )
2014-09-24 02:26:27 +02:00
{
if( trigger != null )
2014-09-24 02:26:27 +02:00
{
2016-12-08 12:42:00 +01:00
// if( FluidRegistry.isContainer( trigger ) )
// {
// return TunnelType.FLUID;
// }
2014-09-24 02:26:27 +02:00
2015-09-30 14:24:40 +02:00
for( final ItemStack is : this.tunnels.keySet() )
2014-09-24 02:26:27 +02:00
{
if( is.getItem() == trigger.getItem() && is.getItemDamage() == OreDictionary.WILDCARD_VALUE )
2015-04-29 02:30:53 +02:00
{
return this.tunnels.get( is );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
if( Platform.itemComparisons().isEqualItem( is, trigger ) )
2015-04-29 02:30:53 +02:00
{
return this.tunnels.get( is );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
}
}
return null;
}
@Nullable
2015-09-30 14:24:40 +02:00
private ItemStack getModItem( final String modID, final String name, final int meta )
{
2016-12-08 12:42:00 +01:00
final Item item = Item.getByNameOrId( modID + ":" + name );
2015-06-16 02:44:59 +02:00
if( item == null )
{
return ItemStack.EMPTY;
}
2015-12-24 02:03:16 +01:00
final ItemStack myItemStack = new ItemStack( item, 1, meta );
return myItemStack;
}
2015-09-30 14:24:40 +02:00
private void addNewAttunement( final IItemDefinition definition, final TunnelType type )
{
definition.maybeStack( 1 ).ifPresent( definitionStack -> addNewAttunement( definitionStack, type ) );
}
2014-09-24 02:26:27 +02:00
}