From 657e3cddf9046052e8dd31d2a4aa58ff53590eab Mon Sep 17 00:00:00 2001 From: DarkGuardsman Date: Fri, 20 Sep 2013 08:10:30 -0400 Subject: [PATCH] Toying with annotations Plan is to replace IExtraObjectInfo with annotations to be used in combo with the new reflection based block registration system. Might try this on a few more things and see were it goes. --- src/dark/core/common/DarkMain.java | 1 + src/dark/core/common/debug/BlockDebug.java | 2 +- .../common/machines/BlockBasicMachine.java | 2 +- src/dark/core/common/transmit/BlockWire.java | 2 +- src/dark/core/prefab/ModPrefab.java | 2 +- .../core/prefab/machine/BlockMachine.java | 2 +- .../core/registration/BlockConfigFile.java | 13 ++++++++++++ .../ModObjectRegistry.java | 9 +++++++-- .../core/registration/TileEntityUser.java | 20 +++++++++++++++++++ 9 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 src/dark/core/registration/BlockConfigFile.java rename src/dark/core/{common => registration}/ModObjectRegistry.java (97%) create mode 100644 src/dark/core/registration/TileEntityUser.java diff --git a/src/dark/core/common/DarkMain.java b/src/dark/core/common/DarkMain.java index 84d25a19..51914e5f 100644 --- a/src/dark/core/common/DarkMain.java +++ b/src/dark/core/common/DarkMain.java @@ -55,6 +55,7 @@ import dark.core.prefab.ModPrefab; import dark.core.prefab.helpers.FluidHelper; import dark.core.prefab.items.ItemBlockHolder; import dark.core.prefab.machine.BlockMulti; +import dark.core.registration.ModObjectRegistry; /** @author HangCow, DarkGuardsman */ @Mod(modid = DarkMain.MOD_ID, name = DarkMain.MOD_NAME, version = DarkMain.VERSION, dependencies = "after:BuildCraft|Energy", useMetadata = true) diff --git a/src/dark/core/common/debug/BlockDebug.java b/src/dark/core/common/debug/BlockDebug.java index a6acec13..bc886f54 100644 --- a/src/dark/core/common/debug/BlockDebug.java +++ b/src/dark/core/common/debug/BlockDebug.java @@ -13,11 +13,11 @@ import net.minecraft.world.World; import net.minecraftforge.common.Configuration; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import dark.core.common.ModObjectRegistry.BlockBuildData; import dark.core.common.DarkMain; import dark.core.prefab.IExtraObjectInfo; import dark.core.prefab.helpers.Pair; import dark.core.prefab.machine.BlockMachine; +import dark.core.registration.ModObjectRegistry.BlockBuildData; public class BlockDebug extends BlockMachine implements IExtraObjectInfo { diff --git a/src/dark/core/common/machines/BlockBasicMachine.java b/src/dark/core/common/machines/BlockBasicMachine.java index 9554346b..e5915c02 100644 --- a/src/dark/core/common/machines/BlockBasicMachine.java +++ b/src/dark/core/common/machines/BlockBasicMachine.java @@ -13,12 +13,12 @@ import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; import net.minecraftforge.common.Configuration; import universalelectricity.core.UniversalElectricity; -import dark.core.common.ModObjectRegistry.BlockBuildData; import dark.core.common.CommonProxy; import dark.core.common.DarkMain; import dark.core.prefab.IExtraObjectInfo; import dark.core.prefab.helpers.Pair; import dark.core.prefab.machine.BlockMachine; +import dark.core.registration.ModObjectRegistry.BlockBuildData; public class BlockBasicMachine extends BlockMachine implements IExtraObjectInfo { diff --git a/src/dark/core/common/transmit/BlockWire.java b/src/dark/core/common/transmit/BlockWire.java index ae942cc7..650326d2 100644 --- a/src/dark/core/common/transmit/BlockWire.java +++ b/src/dark/core/common/transmit/BlockWire.java @@ -16,11 +16,11 @@ import net.minecraftforge.common.Configuration; import universalelectricity.core.block.IConductor; import universalelectricity.core.vector.Vector3; import universalelectricity.prefab.tile.TileEntityConductor; -import dark.core.common.ModObjectRegistry.BlockBuildData; import dark.core.common.DarkMain; import dark.core.prefab.IExtraObjectInfo; import dark.core.prefab.helpers.Pair; import dark.core.prefab.machine.BlockMachine; +import dark.core.registration.ModObjectRegistry.BlockBuildData; public class BlockWire extends BlockMachine implements IExtraObjectInfo { diff --git a/src/dark/core/prefab/ModPrefab.java b/src/dark/core/prefab/ModPrefab.java index 2f7843e7..af670462 100644 --- a/src/dark/core/prefab/ModPrefab.java +++ b/src/dark/core/prefab/ModPrefab.java @@ -10,7 +10,7 @@ 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.relauncher.Side; -import dark.core.common.ModObjectRegistry; +import dark.core.registration.ModObjectRegistry; public abstract class ModPrefab { diff --git a/src/dark/core/prefab/machine/BlockMachine.java b/src/dark/core/prefab/machine/BlockMachine.java index 9680af6e..aef1dbec 100644 --- a/src/dark/core/prefab/machine/BlockMachine.java +++ b/src/dark/core/prefab/machine/BlockMachine.java @@ -12,8 +12,8 @@ import universalelectricity.prefab.block.BlockTile; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import dark.api.parts.INetworkPart; -import dark.core.common.ModObjectRegistry.BlockBuildData; import dark.core.common.DarkMain; +import dark.core.registration.ModObjectRegistry.BlockBuildData; /** Basic TileEntity Container class designed to be used by generic machines. It is suggested that * each mod using this create there own basic block extending this to reduce need to input config diff --git a/src/dark/core/registration/BlockConfigFile.java b/src/dark/core/registration/BlockConfigFile.java new file mode 100644 index 00000000..5eed3e78 --- /dev/null +++ b/src/dark/core/registration/BlockConfigFile.java @@ -0,0 +1,13 @@ +package dark.core.registration; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface BlockConfigFile +{ + +} diff --git a/src/dark/core/common/ModObjectRegistry.java b/src/dark/core/registration/ModObjectRegistry.java similarity index 97% rename from src/dark/core/common/ModObjectRegistry.java rename to src/dark/core/registration/ModObjectRegistry.java index 3a89db89..cf25e196 100644 --- a/src/dark/core/common/ModObjectRegistry.java +++ b/src/dark/core/registration/ModObjectRegistry.java @@ -1,4 +1,4 @@ -package dark.core.common; +package dark.core.registration; import java.io.File; import java.lang.reflect.Constructor; @@ -16,6 +16,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.Configuration; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.registry.GameRegistry; +import dark.core.common.DarkMain; import dark.core.prefab.IExtraObjectInfo; import dark.core.prefab.helpers.Pair; import dark.core.prefab.machine.BlockMachine; @@ -110,7 +111,7 @@ public class ModObjectRegistry public static void finishCreation(Block block, BlockBuildData data) { - if (data != null) + if (data != null && block != null) { if (data.tiles != null) { @@ -119,6 +120,10 @@ public class ModObjectRegistry GameRegistry.registerTileEntityWithAlternatives(par.getValue(), par.getKey(), "DM" + par.getKey()); } } + if (data.creativeTab != null) + { + block.setCreativeTab(data.creativeTab); + } } if (block instanceof IExtraObjectInfo) { diff --git a/src/dark/core/registration/TileEntityUser.java b/src/dark/core/registration/TileEntityUser.java new file mode 100644 index 00000000..3f14745d --- /dev/null +++ b/src/dark/core/registration/TileEntityUser.java @@ -0,0 +1,20 @@ +package dark.core.registration; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import net.minecraft.tileentity.TileEntity; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface TileEntityUser +{ + /** Array of tile entities this tile uses. Is a parallel array in combo with tileEntitiesName */ + Class[] tileEntities() default {}; + + /** Array of tile entities names that are used to register the tile entity. Is a parallel array + * in combo with tileEntities */ + Class[] tileEntitiesNames() default {}; +}