From 7a731ec6584b268917119622929e22dd750c9f07 Mon Sep 17 00:00:00 2001 From: thatsIch Date: Tue, 2 Jun 2015 22:21:37 +0200 Subject: [PATCH] Closes #1541: Implements Thermal Dynamics attunements Adds itemduct to item P2P Adds fluiducts to fluid P2P Adds fluxduct to RF P2P --- .../api/features/IP2PTunnelRegistry.java | 11 ++- .../registries/P2PTunnelRegistry.java | 73 ++++++++++--------- .../java/appeng/integration/modules/RF.java | 18 ++++- 3 files changed, 61 insertions(+), 41 deletions(-) diff --git a/src/api/java/appeng/api/features/IP2PTunnelRegistry.java b/src/api/java/appeng/api/features/IP2PTunnelRegistry.java index 69e474cd..fa627247 100644 --- a/src/api/java/appeng/api/features/IP2PTunnelRegistry.java +++ b/src/api/java/appeng/api/features/IP2PTunnelRegistry.java @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2013 AlgorithmX2 + * Copyright (c) 2013 - 2015 AlgorithmX2 * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -24,6 +24,8 @@ package appeng.api.features; +import javax.annotation.Nullable; + import net.minecraft.item.ItemStack; import appeng.api.config.TunnelType; @@ -39,10 +41,10 @@ public interface IP2PTunnelRegistry * Allows third parties to register items from their mod as potential * attunements for AE's P2P Tunnels * - * @param trigger - the item which triggers attunement - * @param type - the type of tunnel + * @param trigger - the item which triggers attunement. Nullable, but then ignored + * @param type - the type of tunnel. Nullable, but then ignored */ - void addNewAttunement( ItemStack trigger, TunnelType type ); + void addNewAttunement( @Nullable ItemStack trigger, @Nullable TunnelType type ); /** * returns null if no attunement can be found. @@ -51,5 +53,6 @@ public interface IP2PTunnelRegistry * * @return null if no attunement can be found or attunement */ + @Nullable TunnelType getTunnelTypeByItem( ItemStack trigger ); } \ No newline at end of file diff --git a/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java b/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java index b512e114..8495c3f6 100644 --- a/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java +++ b/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * 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 @@ -20,6 +20,8 @@ package appeng.core.features.registries; import java.util.HashMap; +import java.util.Map; +import javax.annotation.Nullable; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -40,10 +42,11 @@ import appeng.api.util.AEColor; import appeng.util.Platform; -public class P2PTunnelRegistry implements IP2PTunnelRegistry +public final class P2PTunnelRegistry implements IP2PTunnelRegistry { + private static final int INITIAL_CAPACITY = 40; - final HashMap Tunnels = new HashMap(); + private final Map tunnels = new HashMap( INITIAL_CAPACITY ); public void configure() { @@ -88,6 +91,7 @@ public class P2PTunnelRegistry implements IP2PTunnelRegistry 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 ); /** * attune based on lots of random item related stuff @@ -101,6 +105,7 @@ public class P2PTunnelRegistry implements IP2PTunnelRegistry 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 ); for( AEColor c : AEColor.values() ) { @@ -112,17 +117,46 @@ public class P2PTunnelRegistry implements IP2PTunnelRegistry } @Override - public void addNewAttunement( ItemStack trigger, TunnelType type ) + public void addNewAttunement( @Nullable ItemStack trigger, @Nullable TunnelType type ) { if( type == null || trigger == null ) { return; } - this.Tunnels.put( trigger, type ); + this.tunnels.put( trigger, type ); } - public ItemStack getModItem( String modID, String name, int meta ) + @Nullable + @Override + public TunnelType getTunnelTypeByItem( ItemStack trigger ) + { + if( trigger != null ) + { + if( FluidContainerRegistry.isContainer( trigger ) ) + { + return TunnelType.FLUID; + } + + for( ItemStack is : this.tunnels.keySet() ) + { + if( is.getItem() == trigger.getItem() && is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) + { + return this.tunnels.get( is ); + } + + if( Platform.isSameItem( is, trigger ) ) + { + return this.tunnels.get( is ); + } + } + } + + return null; + } + + @Nullable + private ItemStack getModItem( String modID, String name, int meta ) { ItemStack myItemStack = GameRegistry.findItemStack( modID, name, 1 ); @@ -142,31 +176,4 @@ public class P2PTunnelRegistry implements IP2PTunnelRegistry this.addNewAttunement( definitionStack, type ); } } - - @Override - public TunnelType getTunnelTypeByItem( ItemStack trigger ) - { - if( trigger != null ) - { - if( FluidContainerRegistry.isContainer( trigger ) ) - { - return TunnelType.FLUID; - } - - for( ItemStack is : this.Tunnels.keySet() ) - { - if( is.getItem() == trigger.getItem() && is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) - { - return this.Tunnels.get( is ); - } - - if( Platform.isSameItem( is, trigger ) ) - { - return this.Tunnels.get( is ); - } - } - } - - return null; - } } diff --git a/src/main/java/appeng/integration/modules/RF.java b/src/main/java/appeng/integration/modules/RF.java index 920bd837..96631ec4 100644 --- a/src/main/java/appeng/integration/modules/RF.java +++ b/src/main/java/appeng/integration/modules/RF.java @@ -26,12 +26,13 @@ import cpw.mods.fml.common.registry.GameRegistry; import appeng.api.AEApi; import appeng.api.config.TunnelType; +import appeng.helpers.Reflected; import appeng.integration.BaseModule; -public class RF extends BaseModule +public final class RF extends BaseModule { - + @Reflected public static RF instance; public RF() @@ -58,14 +59,23 @@ public class RF extends BaseModule this.registerRFAttunement( "ThermalExpansion", "Cell", OreDictionary.WILDCARD_VALUE ); this.registerRFAttunement( "ThermalExpansion", "Dynamo", OreDictionary.WILDCARD_VALUE ); + // Fluxduct + this.registerRFAttunement( "ThermalDynamics", "ThermalDynamics_0", 0 ); + this.registerRFAttunement( "EnderIO", "itemPowerConduit", OreDictionary.WILDCARD_VALUE ); this.registerRFAttunement( "EnderIO", "blockCapacitorBank", 0 ); this.registerRFAttunement( "EnderIO", "blockPowerMonitor", 0 ); } - void registerRFAttunement( String mod, String name, int dmg ) + private void registerRFAttunement( String mod, String name, int dmg ) { - ItemStack modItem = GameRegistry.findItemStack( mod, name, 1 ); + assert mod != null; + assert !mod.isEmpty(); + assert name != null; + assert !name.isEmpty(); + assert dmg >= 0; + + final ItemStack modItem = GameRegistry.findItemStack( mod, name, 1 ); if( modItem != null ) { modItem.setItemDamage( dmg );