From 577b1fa757d82b264994195e4cdcce92fbc9df18 Mon Sep 17 00:00:00 2001 From: Gunther De Wachter Date: Fri, 14 Jul 2017 22:54:19 +0200 Subject: [PATCH] Add a method to attune the P2P Tunnel by (supported) ModId, or check for ForgeEnergy support if it's not listed. --- .../api/features/IP2PTunnelRegistry.java | 1 + .../registries/P2PTunnelRegistry.java | 58 ++++++++++++++++++- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/api/java/appeng/api/features/IP2PTunnelRegistry.java b/src/api/java/appeng/api/features/IP2PTunnelRegistry.java index d5191722..acfe7f22 100644 --- a/src/api/java/appeng/api/features/IP2PTunnelRegistry.java +++ b/src/api/java/appeng/api/features/IP2PTunnelRegistry.java @@ -46,6 +46,7 @@ public interface IP2PTunnelRegistry * @param type - the type of tunnel. Nullable, but then ignored */ void addNewAttunement( @Nonnull ItemStack trigger, @Nullable TunnelType type ); + void addNewAttunement( @Nonnull String ModId, @Nullable TunnelType type ); /** * returns null if no attunement can be found. diff --git a/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java b/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java index b6fa8552..0d7779a9 100644 --- a/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java +++ b/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java @@ -29,6 +29,8 @@ import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.oredict.OreDictionary; import appeng.api.AEApi; @@ -47,15 +49,30 @@ public final class P2PTunnelRegistry implements IP2PTunnelRegistry private static final int INITIAL_CAPACITY = 40; private final Map tunnels = new HashMap( INITIAL_CAPACITY ); + private final Map modIdTunnels = new HashMap<>( INITIAL_CAPACITY ); public void configure() { + + final IDefinitions definitions = AEApi.instance().definitions(); + final IBlocks blocks = definitions.blocks(); + final IParts parts = definitions.parts(); + /** * light! */ this.addNewAttunement( new ItemStack( Blocks.TORCH ), TunnelType.LIGHT ); this.addNewAttunement( new ItemStack( Blocks.GLOWSTONE ), TunnelType.LIGHT ); + /** + * Forge energy tunnel items + */ + + this.addNewAttunement( blocks.energyCellDense(), TunnelType.FE_POWER ); + this.addNewAttunement( blocks.energyAcceptor(), TunnelType.FE_POWER ); + this.addNewAttunement( blocks.energyCell(), TunnelType.FE_POWER ); + this.addNewAttunement( blocks.energyCellCreative(), TunnelType.FE_POWER ); + /** * RF tunnel items */ @@ -96,9 +113,6 @@ public final class P2PTunnelRegistry implements IP2PTunnelRegistry /** * 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 ); @@ -141,6 +155,26 @@ public final class P2PTunnelRegistry implements IP2PTunnelRegistry this.addNewAttunement( parts.cableSmart().stack( c, 1 ), TunnelType.ME ); this.addNewAttunement( parts.cableDense().stack( c, 1 ), TunnelType.ME ); } + + /** + * attune based on the ItemStack's modId + */ + + this.addNewAttunement( "thermaldynamics", TunnelType.RF_POWER ); + this.addNewAttunement( "enderio", TunnelType.RF_POWER ); + this.addNewAttunement( "mekanism", TunnelType.RF_POWER ); + this.addNewAttunement( "rftools", TunnelType.RF_POWER ); + this.addNewAttunement( "ic2", TunnelType.IC2_POWER ); + + } + + public void addNewAttunement( @Nonnull final String modId, @Nullable final TunnelType type ) + { + if( type == null || modId == null ) + { + return; + } + this.modIdTunnels.put( modId, type ); } @Override @@ -177,6 +211,24 @@ public final class P2PTunnelRegistry implements IP2PTunnelRegistry return this.tunnels.get( is ); } } + + // Try by ModId next + for( final String modId : this.modIdTunnels.keySet() ) + { + if( trigger.getItem().getRegistryName() != null && trigger.getItem().getRegistryName().getResourceDomain().equals( modId )) + { + return this.modIdTunnels.get( modId ); + } + } + + // Next, check if the Item you're holding supports Forge Energy + for( EnumFacing face : EnumFacing.VALUES ) + { + if( trigger.hasCapability( CapabilityEnergy.ENERGY, face ) ) + { + return TunnelType.FE_POWER; + } + } } return null;