Skip to content

Commit

Permalink
Modularize TConstruct using Pulsar
Browse files Browse the repository at this point in the history
  • Loading branch information
mDiyo committed Jun 30, 2014
1 parent edfe9ae commit 3de90bd
Show file tree
Hide file tree
Showing 24 changed files with 511 additions and 3,048 deletions.
63 changes: 35 additions & 28 deletions src/main/java/tconstruct/TConstruct.java
Expand Up @@ -3,30 +3,32 @@
import java.util.Random;

import mantle.lib.TabTools;
import mantle.module.ModuleController;
import mantle.pulsar.control.PulseManager;
import mantle.pulsar.pulse.IPulse;
import net.minecraft.world.gen.structure.MapGenStructureIO;
import net.minecraftforge.common.MinecraftForge;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import tconstruct.armor.TinkerArmor;
import tconstruct.client.TControls;
import tconstruct.client.event.EventCloakRender;
import tconstruct.common.TProxyCommon;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.Detailing;
import tconstruct.library.crafting.LiquidCasting;
import tconstruct.mechworks.TinkerMechworks;
import tconstruct.mechworks.landmine.behavior.Behavior;
import tconstruct.mechworks.landmine.behavior.stackCombo.SpecialStackHandler;
import tconstruct.smeltery.TinkerSmeltery;
import tconstruct.tools.TinkerTools;
import tconstruct.util.EnvironmentChecks;
import tconstruct.util.config.DimensionBlacklist;
import tconstruct.util.config.PHConstruct;
import tconstruct.util.network.packet.PacketPipeline;
import tconstruct.util.player.TPlayerHandler;
import tconstruct.world.TinkerWorld;
import tconstruct.world.gen.SlimeIslandGen;
import tconstruct.world.gen.TBaseWorldGenerator;
import tconstruct.world.gen.TerrainGenEventHandler;
import tconstruct.world.village.ComponentSmeltery;
import tconstruct.world.village.ComponentToolWorkshop;
import tconstruct.world.village.TVillageTrades;
Expand Down Expand Up @@ -54,7 +56,7 @@
*/

@Mod(modid = "TConstruct", name = "TConstruct", version = "${version}",
dependencies = "required-after:Forge@[9.11,);required-after:Mantle;after:ForgeMultipart;after:MineFactoryReloaded;after:NotEnoughItems;after:Waila;after:ThermalExpansion")
dependencies = "required-after:Forge@[9.11,);required-after:Mantle;after:MineFactoryReloaded;after:NotEnoughItems;after:Waila;after:ThermalExpansion")
public class TConstruct
{
/** The value of one ingot in millibuckets */
Expand All @@ -65,32 +67,23 @@ public class TConstruct
public static final int nuggetLiquidValue = ingotLiquidValue / 9;

public static final int liquidUpdateAmount = 6;

// the entire mod
public static final String modID = "TConstruct";

// Shared mod logger
public static final Logger logger = LogManager.getLogger(modID);
public static final PacketPipeline packetPipeline = new PacketPipeline();
public static Random random = new Random();

/* Instance of this mod, used for grabbing prototype fields */
@Instance(modID)
public static TConstruct instance;
/* Proxies for sides, used for graphics processing */
/* Proxies for sides, used for graphics processing and client controls */
@SidedProxy(clientSide = "tconstruct.client.TProxyClient", serverSide = "tconstruct.common.TProxyCommon")
public static TProxyCommon proxy;

// Module loader
public static final ModuleController moduleLoader = new ModuleController("TDynstruct.cfg", modID);

// The packet pipeline
public static final PacketPipeline packetPipeline = new PacketPipeline();

public static Random random = new Random();
/* Loads modules in a way that doesn't clutter the @Mod list */
private PulseManager pulsar = new PulseManager(modID); //Scheduled to change shortly.

public TConstruct()
{

//logger.setParent(FMLCommonHandler.instance().getFMLLogger());
if (Loader.isModLoaded("Natura"))
{
logger.info("Natura, what are we going to do tomorrow night?");
Expand All @@ -102,14 +95,29 @@ public TConstruct()
}

EnvironmentChecks.verifyEnvironmentSanity();
//PluginController.registerModules();
}

@EventHandler
public void preInit (FMLPreInitializationEvent event)
{
PHConstruct.initProps(event.getModConfigurationDirectory());

//Temporarily hijacked
if (PHConstruct.worldModule)
pulsar.registerPulse(new TinkerWorld());
if (PHConstruct.toolModule)
pulsar.registerPulse(new TinkerTools());
if (PHConstruct.smelteryModule)
pulsar.registerPulse(new TinkerSmeltery());
if (PHConstruct.mechworksModule)
pulsar.registerPulse(new TinkerMechworks());
if (PHConstruct.armorModule)
pulsar.registerPulse(new TinkerArmor());
/*if (PHConstruct.prayerModule)
pulsar.registerPulse(new TinkerPrayers());
if (PHConstruct.cropifyModule)
pulsar.registerPulse(new TinkerCropify());*/

PHConstruct.initProps(event.getSuggestedConfigurationFile());
TConstructRegistry.materialTab = new TabTools("TConstructMaterials");
TConstructRegistry.toolTab = new TabTools("TConstructTools");
TConstructRegistry.partTab = new TabTools("TConstructParts");
Expand All @@ -119,10 +127,7 @@ public void preInit (FMLPreInitializationEvent event)
basinCasting = new LiquidCasting();
chiselDetailing = new Detailing();

GameRegistry.registerWorldGenerator(new TBaseWorldGenerator(), 0);
MinecraftForge.TERRAIN_GEN_BUS.register(new TerrainGenEventHandler());
//GameRegistry.registerFuelHandler(content);
//NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);

if (PHConstruct.addToVillages)
{
Expand All @@ -147,13 +152,14 @@ public void preInit (FMLPreInitializationEvent event)
// GameRegistry.registerPlayerTracker(playerTracker);
FMLCommonHandler.instance().bus().register(playerTracker);
MinecraftForge.EVENT_BUS.register(playerTracker);
NetworkRegistry.INSTANCE.registerGuiHandler(TConstruct.instance, proxy);

if (event.getSide() == Side.CLIENT)
{
FMLCommonHandler.instance().bus().register(new TControls());
}

moduleLoader.preInit();
pulsar.preInit(event);
}

@EventHandler
Expand All @@ -168,17 +174,18 @@ public void init (FMLInitializationEvent event)
DimensionBlacklist.getBadBimensions();
GameRegistry.registerWorldGenerator(new SlimeIslandGen(TinkerWorld.slimePool, 2), 2);

moduleLoader.init();
pulsar.init(event);
}

@EventHandler
public void postInit (FMLPostInitializationEvent evt)
public void postInit (FMLPostInitializationEvent event)
{
packetPipeline.postInitialise();
Behavior.registerBuiltInBehaviors();
SpecialStackHandler.registerBuiltInStackHandlers();

moduleLoader.postInit();
proxy.initialize();
pulsar.postInit(event);
}

public static LiquidCasting getTableCasting ()
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/tconstruct/armor/ArmorProxyClient.java
Expand Up @@ -47,6 +47,7 @@
import tconstruct.client.tabs.InventoryTabKnapsack;
import tconstruct.client.tabs.InventoryTabVanilla;
import tconstruct.client.tabs.TabRegistry;
import tconstruct.common.TProxyCommon;
import tconstruct.mechworks.MechworksProxyCommon;
import tconstruct.mechworks.inventory.ContainerLandmine;
import tconstruct.mechworks.logic.TileEntityLandmine;
Expand All @@ -68,9 +69,19 @@ public class ArmorProxyClient extends ArmorProxyCommon
{
public ArmorProxyClient()
{
registerGuiHandler();
MinecraftForge.EVENT_BUS.register(this);
}

@Override
protected void registerGuiHandler()
{
super.registerGuiHandler();
TProxyCommon.registerClientGuiHandler(inventoryGui, this);
TProxyCommon.registerClientGuiHandler(armorGuiID, this);
TProxyCommon.registerClientGuiHandler(knapsackGuiID, this);
}

@Override
public Object getClientGuiElement (int ID, EntityPlayer player, World world, int x, int y, int z)
{
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/tconstruct/armor/ArmorProxyCommon.java
Expand Up @@ -2,6 +2,7 @@

import tconstruct.armor.inventory.ArmorExtendedContainer;
import tconstruct.armor.inventory.KnapsackContainer;
import tconstruct.common.TProxyCommon;
import tconstruct.util.player.TPlayerStats;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
Expand All @@ -12,6 +13,17 @@ public class ArmorProxyCommon implements IGuiHandler
public static final int inventoryGui = 100;
public static final int armorGuiID = 101;
public static final int knapsackGuiID = 102;
public ArmorProxyCommon()
{
registerGuiHandler();
}

protected void registerGuiHandler()
{
TProxyCommon.registerServerGuiHandler(inventoryGui, this);
TProxyCommon.registerServerGuiHandler(armorGuiID, this);
TProxyCommon.registerServerGuiHandler(knapsackGuiID, this);
}

@Override
public Object getServerGuiElement (int ID, EntityPlayer player, World world, int x, int y, int z)
Expand Down
25 changes: 16 additions & 9 deletions src/main/java/tconstruct/armor/TinkerArmor.java
@@ -1,5 +1,8 @@
package tconstruct.armor;

import mantle.pulsar.pulse.IPulse;
import mantle.pulsar.pulse.Pulse;
import mantle.pulsar.pulse.PulseProxy;
import net.minecraft.block.Block;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
Expand All @@ -17,34 +20,36 @@
import tconstruct.armor.items.HeartCanister;
import tconstruct.armor.items.Jerky;
import tconstruct.armor.items.Knapsack;
import tconstruct.blocks.logic.DryingRackLogic;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.armor.EnumArmorPart;
import tconstruct.library.crafting.DryingRackRecipes;
import tconstruct.library.crafting.LiquidCasting;
import tconstruct.library.crafting.ToolBuilder;
import tconstruct.smeltery.SmelteryProxyCommon;
import tconstruct.tools.TinkerTools;
import tconstruct.util.config.PHConstruct;
import tconstruct.world.TinkerWorld;
import tconstruct.world.items.GoldenHead;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.GameRegistry.ObjectHolder;

@Mod(modid = "TinkerArmor", name = "TinkerArmor", version = "${tinkerarmorversion}")
public class TinkerArmor
@ObjectHolder(TConstruct.modID)
@Pulse(id = TConstruct.modID)
public class TinkerArmor implements IPulse //TODO: Remove IPulse implementation, keep annotation
{
@Instance("TinkerArmor")
public static TinkerArmor instance;
@SidedProxy(clientSide = "tconstruct.armor.ArmorProxyClient", serverSide = "tconstruct.armor.ArmorProxyCommon")
@PulseProxy(client = "tconstruct.armor.ArmorProxyClient", server = "tconstruct.armor.ArmorProxyCommon")
public static ArmorProxyCommon proxy;

public static Item diamondApple;
public static Item jerky;
// public static Item stonePattern;
Expand All @@ -69,7 +74,7 @@ public class TinkerArmor
public static Item exoShoes;
public static Item bootsWood;
public static ArmorMaterial materialWood;

public TinkerArmor()
{
MinecraftForge.EVENT_BUS.register(new TinkerArmorEvents());
Expand All @@ -79,6 +84,8 @@ public TinkerArmor()
public void preInit (FMLPreInitializationEvent event)
{
TinkerArmor.dryingRack = new DryingRack().setBlockName("Armor.DryingRack");
GameRegistry.registerBlock(TinkerArmor.dryingRack, "Armor.DryingRack");
GameRegistry.registerTileEntity(DryingRackLogic.class, "Armor.DryingRack");
TinkerArmor.diamondApple = new DiamondApple().setUnlocalizedName("tconstruct.apple.diamond");
GameRegistry.registerItem(TinkerArmor.diamondApple, "diamondApple");
boolean foodOverhaul = false;
Expand Down Expand Up @@ -121,7 +128,7 @@ public void preInit (FMLPreInitializationEvent event)
TinkerArmor.exoChest = new ExoArmor(EnumArmorPart.CHEST, "exosuit").setUnlocalizedName("tconstruct.exoChest");
TinkerArmor.exoPants = new ExoArmor(EnumArmorPart.PANTS, "exosuit").setUnlocalizedName("tconstruct.exoPants");
TinkerArmor.exoShoes = new ExoArmor(EnumArmorPart.SHOES, "exosuit").setUnlocalizedName("tconstruct.exoShoes");

GameRegistry.registerItem(TinkerArmor.exoGoggles, "helmetExo");
GameRegistry.registerItem(TinkerArmor.exoChest, "chestplateExo");
GameRegistry.registerItem(TinkerArmor.exoPants, "leggingsExo");
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/tconstruct/blocks/slime/SlimeFluid.java
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.world.World;
import net.minecraftforge.fluids.BlockFluidClassic;
import net.minecraftforge.fluids.Fluid;
import tconstruct.world.TinkerWorld;
import tconstruct.world.entity.BlueSlime;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
Expand All @@ -31,6 +32,8 @@ public void registerBlockIcons (IIconRegister iconRegister)
{
stillIcon = iconRegister.registerIcon("tinker:slime_blue");
flowIcon = iconRegister.registerIcon("tinker:slime_blue_flow");
TinkerWorld.blueSlimeFluid.setStillIcon(stillIcon);
TinkerWorld.blueSlimeFluid.setFlowingIcon(flowIcon);
}

@Override
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/tconstruct/client/TProxyClient.java
Expand Up @@ -157,14 +157,21 @@

public class TProxyClient extends TProxyCommon
{
/* TODO: Split this class up into its respective parts */
public static SmallFontRenderer smallFontRenderer;
public static IIcon metalBall;
public static Minecraft mc;
public static RenderItem itemRenderer = new RenderItem();

public static ArmorExtended armorExtended = new ArmorExtended();
public static KnapsackInventory knapsack = new KnapsackInventory();


public void initialize()
{
registerRenderer();
readManuals();
}

/* Registers any rendering code. */
public void registerRenderer ()
{
Expand Down

0 comments on commit 3de90bd

Please sign in to comment.