Change how blocks/items are registered (desc)

tterrag is a meany face and yelled at me for using class.getSimpleName(). So here's an API-friendly re-work of the registration system. This allows all our Items/Blocks to be obtained via the API. Just add a new enum.
This commit is contained in:
Nick 2016-01-18 22:34:12 -08:00
parent 2a028414b1
commit fdfcb5c5b7
69 changed files with 260 additions and 15 deletions

View file

@ -35,8 +35,9 @@ public class BloodMagicAPI
private static Fluid lifeEssence;
/**
* Used to obtain Items from BloodMagic. Use the constants above for common
* items in case internal names change.
* Used to obtain Items from BloodMagic. Use
* {@link WayofTime.bloodmagic.api.Constants.BloodMagicItem} to get
* the registered name.
*
* @param name
* - The registered name of the item. Usually the same as the class
@ -48,6 +49,43 @@ public class BloodMagicAPI
return GameRegistry.findItem(Constants.Mod.MODID, name);
}
/**
* @see #getItem(String)
*
* @param bloodMagicItem
* - The {@link WayofTime.bloodmagic.api.Constants.BloodMagicItem} to get.
* @return - The requested Item
*/
public static Item getItem(Constants.BloodMagicItem bloodMagicItem) {
return getItem(bloodMagicItem.getRegName());
}
/**
* Used to obtain Blocks from BloodMagic. Use
* {@link WayofTime.bloodmagic.api.Constants.BloodMagicBlock} to get
* the registered name.
*
* @param name
* - The registered name of the block. Usually the same as the class
* name.
* @return - The requested Block
*/
public static Block getBlock(String name)
{
return GameRegistry.findBlock(Constants.Mod.MODID, name);
}
/**
* @see #getBlock(String)
*
* @param bloodMagicBlock
* - The {@link WayofTime.bloodmagic.api.Constants.BloodMagicBlock} to get.
* @return - The requested Block
*/
public static Block getBlock(Constants.BloodMagicBlock bloodMagicBlock) {
return getBlock(bloodMagicBlock.getRegName());
}
/**
* Used to add a {@link BlockStack} to the Teleposer blacklist that cannot
* be changed via Configuration files.

View file

@ -1,5 +1,8 @@
package WayofTime.bloodmagic.api;
import lombok.Getter;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.potion.Potion;
import java.util.Locale;
@ -131,4 +134,105 @@ public class Constants
{
public static final int POTION_ARRAY_SIZE = Potion.potionTypes.length;
}
public enum BloodMagicItem
{
ACTIVATION_CRYSTAL("ItemActivationCrystal"),
ALTAR_MAKER("ItemAltarMaker"),
ARCANE_ASHES("ItemArcaneAshes"),
BLOOD_ORB("ItemBloodOrb"),
BOUND_AXE("ItemBoundAxe"),
BLOOD_SHARD("ItemBloodShard"),
BOUND_PICKAXE("ItemBoundPickaxe"),
BOUND_SHOVEL("ItemBoundShovel"),
BOUND_SWORD("ItemBoundSword"),
BUCKET_ESSENCE("ItemBucketEssence"),
COMPONENT("ItemComponent"),
DAGGER_OF_SACRIFICE("ItemDaggerOfSacrifice"),
INSCRIPTION_TOOL("ItemInscriptionTool"),
LAVA_CRYSTAL("ItemLavaCrystal"),
LIVING_ARMOR_HELMET("ItemLivingArmourHelmet"),
LIVING_ARMOR_CHEST("ItemLivingArmourChest"),
LIVING_ARMOR_LEGS("ItemLivingArmourLegs"),
LIVING_ARMOR_BOOTS("ItemLivingArmourBoots"),
MONSTER_SOUL("ItemMonsterSoul"),
NODE_ROUTER("ItemNodeRouter"),
RITUAL_DIVINER("ItemRitualDiviner"),
ROUTER_FILTER("ItemRouterFilter"),
SACRIFICIAL_DAGGER("ItemSacrificialDagger"),
SACRIFICE_PACK("ItemPackSacrifice"),
SELF_SACRIFICE_PACK("ItemPackSelfSacrifice"),
SENTIENT_ARMOR_HELMET("ItemSentientArmourHelmet"),
SENTIENT_ARMOR_CHEST("ItemSentientArmourChest"),
SENTIENT_ARMOR_LEGS("ItemSentientArmourLegs"),
SENTIENT_ARMOR_BOOTS("ItemSentientArmourBoots"),
SENTIENT_ARMOR_GEM("ItemSentientArmourGem"),
SENTIENT_BOW("ItemSentientBow"),
SENTIENT_SWORD("ItemSentientSword"),
SOUL_GEM("ItemSoulGem"),
SOUL_SNARE("ItemSoulSnare"),
SIGIL_AIR("ItemSigilAir"),
SIGIL_BLOOD_LIGHT("ItemSigilBloodLight"),
SIGIL_COMPRESSION("ItemSigilCompression"),
SIGIL_DIVINATION("ItemSigilDivination"),
SIGIL_ELEMENTAL_AFFINITY("ItemSigilElementalAffinity"),
SIGIL_ENDER_SEVERANCE("ItemSigilEnderSeverance"),
SIGIL_FAST_MINER("ItemSigilFastMiner"),
SIGIL_GREEN_GROVE("ItemSigilGreenGrove"),
SIGIL_HASTE("ItemSigilHaste"),
SIGIL_LAVA("ItemSigilLava"),
SIGIL_MAGNETISM("ItemSigilMagnetism"),
SIGIL_PHANTOM_BRIDGE("ItemSigilPhantomBridge"),
SIGIL_SEER("ItemSigilSeer"),
SIGIL_SUPPRESION("ItemSigilSuppression"),
SIGIL_VOID("ItemSigilVoid"),
SIGIL_WATER("ItemSigilWater"),
SIGIL_WHIRLWIND("ItemSigilWhirlwind"),
SLATE("ItemSlate"),
TELEPOSITION_FOCUS("ItemTelepositionFocus"),
UPGRADE_TOME("ItemUpgradeTome");
@Getter
private final String regName;
BloodMagicItem(String regName) {
this.regName = regName;
}
public Item getItem() {
return BloodMagicAPI.getItem(getRegName());
}
}
public enum BloodMagicBlock {
ALCHEMY_ARRAY("BlockAlchemyArray"),
ALTAR("BlockAltar"),
BLOOD_LIGHT("BlockBloodLight"),
BLOOD_RUNE("BlockBloodRune"),
BLOOD_STONE("BlockBloodStoneBrick"),
CRYSTAL("BlockCrystal"),
INPUT_ROUTING_NODE("BlockInputRoutingNode"),
ITEM_ROUTING_NODE("BlockItemRoutingNode"),
LIFE_ESSENCE("BlockLifeEssence"),
MASTER_ROUTING_NODE("BlockMasterRoutingNode"),
OUTPUT_ROUTING_NODE("BlockOutputRoutingNode"),
PEDESTAL("BlockPedestal"),
PHANTOM("BlockPhantom"),
RITUAL_CONTROLLER("BlockRitualController"),
RITUAL_STONE("BlockRitualStone"),
SOUL_FORGE("BlockSoulForge"),
SPECTRAL("BlockSpectral"),
TELEPOSER("BlockTeleposer");
@Getter
private final String regName;
BloodMagicBlock(String regName) {
this.regName = regName;
}
public Block getBlock() {
return BloodMagicAPI.getBlock(getRegName());
}
}
}