2017-02-26 13:56:36 +01:00
/ *
2016-09-29 16:19:16 +02:00
* This file is part of Industrial Wires .
2017-02-26 13:56:36 +01:00
* Copyright ( C ) 2016 - 2017 malte0811
2016-09-29 16:19:16 +02:00
*
* Industrial Wires is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* Industrial Wires 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 General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires . If not , see < http : //www.gnu.org/licenses/>.
2017-02-26 13:56:36 +01:00
* /
2016-09-15 20:43:18 +02:00
package malte0811.industrialWires ;
2016-09-22 19:52:01 +02:00
import blusunrize.immersiveengineering.api.tool.AssemblerHandler ;
2016-12-19 18:16:46 +01:00
import blusunrize.immersiveengineering.api.tool.AssemblerHandler.IRecipeAdapter ;
2016-09-22 19:52:01 +02:00
import blusunrize.immersiveengineering.api.tool.AssemblerHandler.RecipeQuery ;
2016-09-15 20:43:18 +02:00
import blusunrize.immersiveengineering.common.IEContent ;
2017-03-03 19:04:08 +01:00
import blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_Connector ;
2016-12-19 18:16:46 +01:00
import blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecoration0 ;
2016-09-15 20:43:18 +02:00
import blusunrize.immersiveengineering.common.blocks.stone.BlockTypes_StoneDecoration ;
import ic2.api.item.IC2Items ;
2017-02-26 13:56:36 +01:00
import malte0811.industrialWires.blocks.BlockJacobsLadder ;
import malte0811.industrialWires.blocks.TileEntityJacobsLadder ;
2017-05-09 17:25:03 +02:00
import malte0811.industrialWires.blocks.controlpanel.* ;
2016-12-13 21:00:07 +01:00
import malte0811.industrialWires.blocks.converter.BlockMechanicalConverter ;
import malte0811.industrialWires.blocks.converter.TileEntityIEMotor ;
import malte0811.industrialWires.blocks.converter.TileEntityMechICtoIE ;
import malte0811.industrialWires.blocks.converter.TileEntityMechIEtoIC ;
2017-04-04 17:07:45 +02:00
import malte0811.industrialWires.blocks.wire.* ;
2017-05-09 17:25:03 +02:00
import malte0811.industrialWires.controlpanel.PanelUtils ;
2016-09-22 19:52:01 +02:00
import malte0811.industrialWires.crafting.RecipeCoilLength ;
2016-09-15 20:43:18 +02:00
import malte0811.industrialWires.items.ItemIC2Coil ;
2017-04-13 17:14:05 +02:00
import malte0811.industrialWires.items.ItemPanelComponent ;
2017-04-20 20:44:08 +02:00
import malte0811.industrialWires.network.MessageComponentSync ;
2017-04-09 16:59:57 +02:00
import malte0811.industrialWires.network.MessageGUIInteract ;
2017-04-04 17:07:45 +02:00
import malte0811.industrialWires.network.MessagePanelInteract ;
2017-02-26 13:56:36 +01:00
import malte0811.industrialWires.network.MessageTileSyncIW ;
2016-09-15 20:43:18 +02:00
import malte0811.industrialWires.wires.IC2Wiretype ;
import net.minecraft.creativetab.CreativeTabs ;
2017-03-03 19:04:08 +01:00
import net.minecraft.init.Blocks ;
2016-09-15 20:43:18 +02:00
import net.minecraft.item.Item ;
import net.minecraft.item.ItemStack ;
import net.minecraftforge.fml.common.Mod ;
import net.minecraftforge.fml.common.Mod.EventHandler ;
import net.minecraftforge.fml.common.SidedProxy ;
import net.minecraftforge.fml.common.event.FMLInitializationEvent ;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent ;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent ;
2017-02-26 13:56:36 +01:00
import net.minecraftforge.fml.common.network.NetworkRegistry ;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper ;
2016-09-15 20:43:18 +02:00
import net.minecraftforge.fml.common.registry.GameRegistry ;
2017-02-26 13:56:36 +01:00
import net.minecraftforge.fml.relauncher.Side ;
2016-09-22 19:52:01 +02:00
import net.minecraftforge.oredict.RecipeSorter ;
import net.minecraftforge.oredict.RecipeSorter.Category ;
2016-09-15 20:43:18 +02:00
import net.minecraftforge.oredict.ShapedOreRecipe ;
2017-05-09 17:25:03 +02:00
import net.minecraftforge.oredict.ShapelessOreRecipe ;
2016-09-15 20:43:18 +02:00
2017-04-04 17:07:45 +02:00
import java.util.ArrayList ;
import java.util.List ;
2017-05-08 17:20:04 +02:00
@Mod ( modid = IndustrialWires . MODID , version = IndustrialWires . VERSION , dependencies = " required-after:immersiveengineering@[0.10-58,);required-after:IC2 " )
2016-09-15 20:43:18 +02:00
public class IndustrialWires {
public static final String MODID = " industrialwires " ;
public static final String VERSION = " ${version} " ;
public static BlockIC2Connector ic2conn ;
2016-12-13 21:00:07 +01:00
public static BlockMechanicalConverter mechConv ;
2017-02-26 13:56:36 +01:00
public static BlockJacobsLadder jacobsLadder ;
2017-03-24 17:40:05 +01:00
public static BlockPanel panel ;
2016-09-15 20:43:18 +02:00
public static ItemIC2Coil coil ;
2017-04-13 17:14:05 +02:00
public static ItemPanelComponent panelComponent ;
2017-02-26 13:56:36 +01:00
public static final SimpleNetworkWrapper packetHandler = NetworkRegistry . INSTANCE . newSimpleChannel ( MODID ) ;
2017-04-09 16:59:57 +02:00
@Mod.Instance ( MODID )
public static IndustrialWires instance = new IndustrialWires ( ) ;
2016-09-15 20:43:18 +02:00
public static CreativeTabs creativeTab = new CreativeTabs ( MODID ) {
2016-12-19 18:16:46 +01:00
2016-09-15 20:43:18 +02:00
@Override
public Item getTabIconItem ( ) {
return null ;
}
public ItemStack getIconItemStack ( ) {
return new ItemStack ( coil , 1 , 2 ) ;
}
} ;
@SidedProxy ( clientSide = " malte0811.industrialWires.client.ClientProxy " , serverSide = " malte0811.industrialWires.CommonProxy " )
public static CommonProxy proxy ;
@EventHandler
public void preInit ( FMLPreInitializationEvent e ) {
2016-12-13 21:00:07 +01:00
new IWConfig ( ) ;
2016-09-15 20:43:18 +02:00
ic2conn = new BlockIC2Connector ( ) ;
2016-12-20 17:05:20 +01:00
if ( IWConfig . enableConversion )
mechConv = new BlockMechanicalConverter ( ) ;
2017-02-26 13:56:36 +01:00
jacobsLadder = new BlockJacobsLadder ( ) ;
2016-09-15 20:43:18 +02:00
coil = new ItemIC2Coil ( ) ;
2017-04-13 17:14:05 +02:00
panelComponent = new ItemPanelComponent ( ) ;
2017-03-24 17:40:05 +01:00
panel = new BlockPanel ( ) ;
2017-02-26 13:56:36 +01:00
//TODO change to MODID+ when changing to a new MC version
2016-09-15 20:43:18 +02:00
GameRegistry . registerTileEntity ( TileEntityIC2ConnectorTin . class , " ic2ConnectorTin " ) ;
GameRegistry . registerTileEntity ( TileEntityIC2ConnectorCopper . class , " ic2ConnectorCopper " ) ;
GameRegistry . registerTileEntity ( TileEntityIC2ConnectorGold . class , " ic2ConnectorGold " ) ;
GameRegistry . registerTileEntity ( TileEntityIC2ConnectorHV . class , " ic2ConnectorHV " ) ;
2016-09-22 19:52:01 +02:00
GameRegistry . registerTileEntity ( TileEntityIC2ConnectorGlass . class , " ic2ConnectorGlass " ) ;
2017-02-26 13:56:36 +01:00
GameRegistry . registerTileEntity ( TileEntityJacobsLadder . class , MODID + " :jacobsLadder " ) ;
2017-03-28 18:15:41 +02:00
GameRegistry . registerTileEntity ( TileEntityPanel . class , MODID + " :control_panel " ) ;
GameRegistry . registerTileEntity ( TileEntityRSPanelConn . class , MODID + " :control_panel_rs " ) ;
2017-04-10 16:20:39 +02:00
GameRegistry . registerTileEntity ( TileEntityPanelCreator . class , MODID + " :panel_creator " ) ;
2016-12-20 17:05:20 +01:00
if ( mechConv ! = null ) {
GameRegistry . registerTileEntity ( TileEntityIEMotor . class , MODID + " :ieMotor " ) ;
GameRegistry . registerTileEntity ( TileEntityMechICtoIE . class , MODID + " :mechIcToIe " ) ;
GameRegistry . registerTileEntity ( TileEntityMechIEtoIC . class , MODID + " :mechIeToIc " ) ;
}
2016-09-15 20:43:18 +02:00
if ( IC2Wiretype . IC2_TYPES = = null ) {
throw new IllegalStateException ( " No IC2 wires registered " ) ;
}
proxy . preInit ( ) ;
}
@EventHandler
public void init ( FMLInitializationEvent e ) {
2016-09-22 19:52:01 +02:00
ItemStack glassCable = IC2Items . getItem ( " cable " , " type:glass,insulation:0 " ) ;
2016-09-15 20:43:18 +02:00
//CONNECTORS
2016-09-22 19:52:01 +02:00
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( ic2conn , 4 , 0 ) , " t " , " rtr " , " rtr " , 't' , " ingotTin " , 'r' , " itemRubber " ) ) ;
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( ic2conn , 4 , 2 ) , " c " , " rcr " , " rcr " , 'c' , " ingotCopper " , 'r' , " itemRubber " ) ) ;
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( ic2conn , 4 , 4 ) , " g " , " rgr " , " rgr " , 'g' , " ingotGold " , 'r' , " itemRubber " ) ) ;
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( ic2conn , 4 , 6 ) , " i " , " rir " , " rir " , 'i' , " ingotIron " , 'r' , " itemRubber " ) ) ;
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( ic2conn , 4 , 8 ) , " c " , " rcr " , " rcr " , 'c' , glassCable , 'r' , " itemRubber " ) ) ;
2016-09-15 20:43:18 +02:00
//RELAYS
2016-09-22 19:52:01 +02:00
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( ic2conn , 4 , 1 ) , " t " , " rtr " , 't' , " ingotTin " , 'r' , " itemRubber " ) ) ;
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( ic2conn , 4 , 3 ) , " c " , " rcr " , 'c' , " ingotCopper " , 'r' , " itemRubber " ) ) ;
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( ic2conn , 4 , 5 ) , " g " , " rgr " , 'g' , " ingotGold " , 'r' , " itemRubber " ) ) ;
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( ic2conn , 4 , 7 ) , " i " , " gig " , " gig " , 'i' , " ingotIron " , 'g' , new ItemStack ( IEContent . blockStoneDecoration , 1 , BlockTypes_StoneDecoration . INSULATING_GLASS . getMeta ( ) ) ) ) ;
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( ic2conn , 2 , 9 ) , " c " , " grg " , " grg " , 'r' , " itemRubber " , 'c' , glassCable , 'g' , new ItemStack ( IEContent . blockStoneDecoration , 1 , BlockTypes_StoneDecoration . INSULATING_GLASS . getMeta ( ) ) ) ) ;
//WIRES
RecipeSorter . register ( " industrialwires:coilLength " , RecipeCoilLength . class , Category . SHAPELESS , " after:forge:shapelessore " ) ;
for ( int i = 0 ; i < IC2Wiretype . IC2_TYPES . length ; i + + ) {
GameRegistry . addRecipe ( new RecipeCoilLength ( i ) ) ;
}
2016-12-19 18:16:46 +01:00
AssemblerHandler . registerRecipeAdapter ( RecipeCoilLength . class , new CoilLengthAdapter ( ) ) ;
// MECH CONVERTERS
2016-12-20 17:05:20 +01:00
if ( mechConv ! = null ) {
ItemStack shaftIron = IC2Items . getItem ( " crafting " , " iron_shaft " ) ;
ItemStack shaftSteel = IC2Items . getItem ( " crafting " , " steel_shaft " ) ;
ItemStack ironMechComponent = new ItemStack ( IEContent . itemMaterial , 1 , 8 ) ;
ItemStack steelMechComponent = new ItemStack ( IEContent . itemMaterial , 1 , 9 ) ;
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( mechConv , 1 , 0 ) , " s " , " ici " , " mum " , 's' , " stickIron " ,
'i' , " ingotIron " , 'c' , new ItemStack ( IEContent . blockMetalDecoration0 , 1 , BlockTypes_MetalDecoration0 . COIL_LV . getMeta ( ) ) ,
'u' , " ingotCopper " , 'm' , ironMechComponent ) ) ;
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( mechConv , 1 , 2 ) , " iIi " , " sbS " , " mrm " , 's' , " blockSheetmetalIron " ,
'i' , " plateIron " , 'I' , shaftIron ,
'b' , " ingotBronze " , 'm' , steelMechComponent ,
'S' , " blockSheetmetalSteel " , 'r' , " stickSteel " ) ) ;
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( mechConv , 1 , 1 ) , " mrm " , " sbS " , " iIi " , 's' , " blockSheetmetalIron " ,
'i' , " plateSteel " , 'I' , shaftSteel ,
'b' , " ingotBronze " , 'm' , ironMechComponent ,
'S' , " blockSheetmetalSteel " , 'r' , " stickIron " ) ) ;
}
2017-03-03 19:04:08 +01:00
// JACOB'S LADDERS
ItemStack mvTransformer = IC2Items . getItem ( " te " , " mv_transformer " ) ;
ItemStack copperCable = IC2Items . getItem ( " cable " , " type:copper,insulation:0 " ) ;
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( jacobsLadder , 1 , 0 ) , " c c " , " h " , " sts " , 'c' , copperCable , 'h' , Blocks . HARDENED_CLAY ,
's' , " ingotSteel " , 't' , mvTransformer ) ) ;
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( jacobsLadder , 1 , 1 ) , " c c " , " h h " , " sts " , 'c' , " ingotCopper " , 'h' , Blocks . HARDENED_CLAY ,
's' , " ingotSteel " , 't' , new ItemStack ( IEContent . blockConnectors , 1 , BlockTypes_Connector . TRANSFORMER . ordinal ( ) ) ) ) ;
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( jacobsLadder , 1 , 2 ) , " c c " , " hhh " , " sts " , 'c' , " blockCopper " , 'h' , Blocks . HARDENED_CLAY ,
's' , " ingotSteel " , 't' , new ItemStack ( IEContent . blockConnectors , 1 , BlockTypes_Connector . TRANSFORMER_HV . ordinal ( ) ) ) ) ;
2017-05-09 17:25:03 +02:00
// CONTROL PANELS
ItemStack drillHeadIron = new ItemStack ( IEContent . itemDrillhead , 1 , 1 ) ;
ItemStack motor = IC2Items . getItem ( " crafting " , " electric_motor " ) ;
ItemStack advAlloy = IC2Items . getItem ( " crafting " , " alloy " ) ;
ItemStack coil = IC2Items . getItem ( " crafting " , " coil " ) ;
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( panel , 1 , BlockTypes_Panel . CREATOR . ordinal ( ) ) ,
" rmr " , " rdr " , " rar " , 'r' , " stickSteel " , 'm' , motor , 'd' , drillHeadIron , 'a' , advAlloy ) ) ;
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( panel , 8 , BlockTypes_Panel . DUMMY . ordinal ( ) ) ,
" r " , " rmr " , " r " , 'r' , " dustRedstone " , 'm' , PanelUtils . getPanelBase ( ) ) ) ;
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( panel , 1 , BlockTypes_Panel . RS_WIRE . ordinal ( ) ) ,
" c " , " d " , 'd' , new ItemStack ( panel , 1 , BlockTypes_Panel . DUMMY . ordinal ( ) ) , 'c' ,
new ItemStack ( IEContent . blockConnectors , 1 , BlockTypes_Connector . CONNECTOR_REDSTONE . ordinal ( ) ) ) ) ;
// PANEL COMPONENTS
GameRegistry . addRecipe ( new ShapelessOreRecipe ( new ItemStack ( panelComponent , 1 , 0 ) ,
" dustGlowstone " , Blocks . STONE_BUTTON , " wireCopper " ) ) ;
GameRegistry . addRecipe ( new ShapelessOreRecipe ( new ItemStack ( panelComponent , 4 , 1 ) ,
" paper " , " plateIron " ) ) ;
GameRegistry . addRecipe ( new ShapelessOreRecipe ( new ItemStack ( panelComponent , 1 , 2 ) ,
" dustGlowstone " , " dustRedstone " , " wireCopper " ) ) ;
GameRegistry . addRecipe ( new ShapelessOreRecipe ( new ItemStack ( panelComponent , 1 , 3 ) ,
Blocks . STONE_BUTTON , new ItemStack ( IEContent . itemWireCoil , 1 , 2 ) , " wireCopper " ) ) ;
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( panelComponent , 1 , 4 ) ,
" r " , " g " , " c " , 'r' , " itemRubber " , 'g' , " ingotHOPGraphite " , 'c' , coil ) ) ;
GameRegistry . addRecipe ( new ShapelessOreRecipe ( new ItemStack ( panelComponent , 1 , 5 ) ,
" stickIron " , Blocks . LEVER , " wireCopper " ) ) ;
GameRegistry . addRecipe ( new ShapedOreRecipe ( new ItemStack ( panelComponent , 1 , 6 ) ,
" aaa " , " asa " , 'a' , " plateAluminum " , 's' , new ItemStack ( panelComponent , 2 , 5 ) ) ) ;
2017-03-03 19:04:08 +01:00
2017-02-26 13:56:36 +01:00
packetHandler . registerMessage ( MessageTileSyncIW . HandlerClient . class , MessageTileSyncIW . class , 0 , Side . CLIENT ) ;
2017-04-04 17:07:45 +02:00
packetHandler . registerMessage ( MessagePanelInteract . HandlerServer . class , MessagePanelInteract . class , 1 , Side . SERVER ) ;
2017-04-09 16:59:57 +02:00
packetHandler . registerMessage ( MessageGUIInteract . HandlerServer . class , MessageGUIInteract . class , 2 , Side . SERVER ) ;
2017-04-20 20:44:08 +02:00
packetHandler . registerMessage ( MessageComponentSync . HandlerServer . class , MessageComponentSync . class , 3 , Side . SERVER ) ;
2017-04-09 16:59:57 +02:00
NetworkRegistry . INSTANCE . registerGuiHandler ( instance , proxy ) ;
2016-09-15 20:43:18 +02:00
}
@EventHandler
public void postInit ( FMLPostInitializationEvent e ) {
proxy . postInit ( ) ;
}
2016-12-19 18:16:46 +01:00
private class CoilLengthAdapter implements IRecipeAdapter < RecipeCoilLength > {
@Override
public RecipeQuery [ ] getQueriedInputs ( RecipeCoilLength recipe , ItemStack [ ] in ) {
List < RecipeQuery > ret = new ArrayList < > ( ) ;
for ( int i = 0 ; i < in . length - 1 ; i + + ) {
boolean added = false ;
for ( int j = 0 ; j < ret . size ( ) ; j + + ) {
if ( ItemStack . areItemStacksEqual ( ( ItemStack ) ret . get ( j ) . query , in [ i ] ) ) {
ret . get ( j ) . querySize + + ;
added = true ;
break ;
}
}
if ( ! added ) {
ret . add ( new RecipeQuery ( in [ i ] , 1 ) ) ;
}
}
return ret . toArray ( new RecipeQuery [ ret . size ( ) ] ) ;
}
@Override
public RecipeQuery [ ] getQueriedInputs ( RecipeCoilLength arg0 ) {
return new RecipeQuery [ 0 ] ;
}
}
2016-09-15 20:43:18 +02:00
}