mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 11:49:37 +00:00
API: Added the SubTileSignature system.
This commit is contained in:
1 parent
97d6d3beed
commit
89aa43df98
10 files changed
+166
-12
No files matched your search
@@ -40,6 +40,8 @@ import vazkii.botania.api.recipe.RecipeManaInfusion;
|
||||
import vazkii.botania.api.recipe.RecipePetals;
|
||||
import vazkii.botania.api.recipe.RecipeRuneAltar;
|
||||
import vazkii.botania.api.subtile.SubTileEntity;
|
||||
import vazkii.botania.api.subtile.signature.BasicSignature;
|
||||
import vazkii.botania.api.subtile.signature.SubTileSignature;
|
||||
import vazkii.botania.api.wiki.IWikiProvider;
|
||||
import vazkii.botania.api.wiki.SimpleWikiProvider;
|
||||
import vazkii.botania.api.wiki.WikiHooks;
|
||||
@@ -60,6 +62,7 @@ public final class BotaniaAPI {
|
||||
public static List<RecipeElvenTrade> elvenTradeRecipes = new ArrayList<RecipeElvenTrade>();
|
||||
|
||||
private static BiMap<String, Class<? extends SubTileEntity>> subTiles = HashBiMap.<String, Class<? extends SubTileEntity>> create();
|
||||
private static Map<Class<? extends SubTileEntity>, SubTileSignature> subTileSignatures = new HashMap<Class<? extends SubTileEntity>, SubTileSignature>();
|
||||
public static Set<String> subtilesForCreativeMenu = new LinkedHashSet();
|
||||
|
||||
public static Map<String, Integer> oreWeights = new HashMap<String, Integer>();
|
||||
@@ -262,6 +265,34 @@ public final class BotaniaAPI {
|
||||
subTiles.put(key, subtileClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a SubTileEntity's signature.
|
||||
* @see SubTileSignature
|
||||
*/
|
||||
public static void registerSubTileSignature(Class<? extends SubTileEntity> subtileClass, SubTileSignature signature) {
|
||||
subTileSignatures.put(subtileClass, signature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the singleton signature for a SubTileEntity class. Registers a fallback if one wasn't registered
|
||||
* before the call.
|
||||
*/
|
||||
public static SubTileSignature getSignatureForClass(Class<? extends SubTileEntity> subtileClass) {
|
||||
if(!subTileSignatures.containsKey(subtileClass))
|
||||
registerSubTileSignature(subtileClass, new BasicSignature(subTiles.inverse().get(subtileClass)));
|
||||
|
||||
return subTileSignatures.get(subtileClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the singleton signature for a SubTileEntity's name. Registers a fallback if one wasn't registered
|
||||
* before the call.
|
||||
*/
|
||||
public static SubTileSignature getSignatureForName(String name) {
|
||||
Class<? extends SubTileEntity> subtileClass = subTiles.get(name);
|
||||
return getSignatureForClass(subtileClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the key for a SubTileEntity into the creative menu. This goes into the
|
||||
* subtilesForCreativeMenu Set.
|
||||
|
||||
@@ -14,6 +14,7 @@ package vazkii.botania.api.internal;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@@ -102,6 +103,11 @@ public class DummyMethodHandler implements IInternalMethodHandler {
|
||||
public IIcon getSubTileIconForName(String name) {
|
||||
return Blocks.red_flower.getIcon(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBasicSignatureIcons(String name, IIconRegister register) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public IManaNetwork getManaNetworkInstance() {
|
||||
@@ -132,4 +138,5 @@ public class DummyMethodHandler implements IInternalMethodHandler {
|
||||
public int getPassiveFlowerDecay() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@ package vazkii.botania.api.internal;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -66,6 +67,8 @@ public interface IInternalMethodHandler {
|
||||
public ItemStack getSubTileAsStack(String subTile);
|
||||
|
||||
public IIcon getSubTileIconForName(String name);
|
||||
|
||||
public void registerBasicSignatureIcons(String name, IIconRegister register);
|
||||
|
||||
public boolean shouldForceCheck();
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under a
|
||||
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
|
||||
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
|
||||
*
|
||||
* File Created @ [Oct 17, 2014, 5:34:35 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.api.subtile.signature;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
|
||||
public class BasicSignature extends SubTileSignature {
|
||||
|
||||
final String name;
|
||||
|
||||
public BasicSignature(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons(IIconRegister register) {
|
||||
BotaniaAPI.internalHandler.registerBasicSignatureIcons(name, register);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIconForStack(ItemStack stack) {
|
||||
return BotaniaAPI.internalHandler.getSubTileIconForName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedNameForStack(ItemStack stack) {
|
||||
return unlocalizedName("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedLoreTextForStack(ItemStack stack) {
|
||||
return unlocalizedName(".reference");
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
private String unlocalizedName(String end) {
|
||||
return "tile." + SubTileSignature.SPECIAL_FLOWER_PREFIX + name + end;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under a
|
||||
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
|
||||
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
|
||||
*
|
||||
* File Created @ [Oct 17, 2014, 5:29:26 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.api.subtile.signature;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
/**
|
||||
* A singleton instance for a SubTileEntity, this is called for a few methods.
|
||||
* You can attach this
|
||||
*/
|
||||
public abstract class SubTileSignature {
|
||||
|
||||
public static final String SPECIAL_FLOWER_PREFIX = "flower.";
|
||||
|
||||
/**
|
||||
* Equivalent to Block.registerBlockIcons.
|
||||
*/
|
||||
public abstract void registerIcons(IIconRegister register);
|
||||
|
||||
/**
|
||||
* Gets the icon to display for the flower item.
|
||||
*/
|
||||
public abstract IIcon getIconForStack(ItemStack stack);
|
||||
|
||||
/**
|
||||
* Gets the display name for the flower item.
|
||||
*/
|
||||
public abstract String getUnlocalizedNameForStack(ItemStack stack);
|
||||
|
||||
/**
|
||||
* Gets the lore text for the flower item, displayed in the item's tooltip.
|
||||
* If you do not want a reference return a key that does not have localization such
|
||||
* as "botaniamisc.noloc".
|
||||
*/
|
||||
public abstract String getUnlocalizedLoreTextForStack(ItemStack stack);
|
||||
|
||||
}
|
||||
@@ -121,12 +121,8 @@ public class BlockSpecialFlower extends BlockFlower implements ITileEntityProvid
|
||||
|
||||
@Override
|
||||
public void registerBlockIcons(IIconRegister par1IconRegister) {
|
||||
for(String s : BotaniaAPI.subtilesForCreativeMenu){
|
||||
IIcon normal = IconHelper.forName(par1IconRegister, s);
|
||||
IIcon alt = IconHelper.forName(par1IconRegister, BlockModFlower.ALT_DIR + "/" + s);
|
||||
icons.put(s, normal);
|
||||
iconsAlt.put(s, alt == null ? normal : alt);
|
||||
}
|
||||
for(String s : BotaniaAPI.subtilesForCreativeMenu)
|
||||
BotaniaAPI.getSignatureForName(s).registerIcons(par1IconRegister);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,6 +14,7 @@ package vazkii.botania.common.core.handler;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@@ -29,7 +30,9 @@ import vazkii.botania.api.recipe.RecipeManaInfusion;
|
||||
import vazkii.botania.api.recipe.RecipePetals;
|
||||
import vazkii.botania.api.recipe.RecipeRuneAltar;
|
||||
import vazkii.botania.client.core.handler.HUDHandler;
|
||||
import vazkii.botania.client.core.helper.IconHelper;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.block.BlockModFlower;
|
||||
import vazkii.botania.common.block.BlockSpecialFlower;
|
||||
import vazkii.botania.common.item.block.ItemBlockSpecialFlower;
|
||||
import vazkii.botania.common.lexicon.page.PageCraftingRecipe;
|
||||
@@ -69,6 +72,14 @@ public class InternalMethodHandler extends DummyMethodHandler {
|
||||
return icon == null ? Blocks.red_flower.getIcon(0, 0) : icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBasicSignatureIcons(String name, IIconRegister register) {
|
||||
IIcon normal = IconHelper.forName(register, name);
|
||||
IIcon alt = IconHelper.forName(register, BlockModFlower.ALT_DIR + "/" + name);
|
||||
BlockSpecialFlower.icons.put(name, normal);
|
||||
BlockSpecialFlower.iconsAlt.put(name, alt == null ? normal : alt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LexiconPage petalRecipesPage(String key, List<RecipePetals> recipes) {
|
||||
return new PagePetalRecipe(key, recipes);
|
||||
|
||||
@@ -24,6 +24,7 @@ import net.minecraft.world.World;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.lexicon.IRecipeKeyProvider;
|
||||
import vazkii.botania.api.subtile.SubTileEntity;
|
||||
import vazkii.botania.api.subtile.signature.SubTileSignature;
|
||||
import vazkii.botania.client.lib.LibResources;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.block.tile.TileSpecialFlower;
|
||||
@@ -39,7 +40,7 @@ public class ItemBlockSpecialFlower extends ItemBlockMod implements IRecipeKeyPr
|
||||
|
||||
@Override
|
||||
public IIcon getIconIndex(ItemStack stack) {
|
||||
return BotaniaAPI.internalHandler.getSubTileIconForName(getType(stack));
|
||||
return BotaniaAPI.getSignatureForName(getType(stack)).getIconForStack(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,13 +67,13 @@ public class ItemBlockSpecialFlower extends ItemBlockMod implements IRecipeKeyPr
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack stack) {
|
||||
return "tile." + LibBlockNames.SPECIAL_FLOWER_PREFIX + getType(stack);
|
||||
return BotaniaAPI.getSignatureForName(getType(stack)).getUnlocalizedNameForStack(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
|
||||
if(ConfigHandler.referencesEnabled) {
|
||||
String refUnlocalized = "tile." + LibResources.PREFIX_MOD + LibBlockNames.SPECIAL_FLOWER_PREFIX + getType(par1ItemStack) + ".reference";
|
||||
String refUnlocalized = "tile." + LibResources.PREFIX_MOD + SubTileSignature.SPECIAL_FLOWER_PREFIX + getType(par1ItemStack) + ".reference";
|
||||
String refLocalized = StatCollector.translateToLocal(refUnlocalized);
|
||||
if(!refLocalized.equals(refUnlocalized))
|
||||
par3List.add(EnumChatFormatting.ITALIC + refLocalized);
|
||||
|
||||
@@ -59,8 +59,6 @@ public final class LibBlockNames {
|
||||
public static final String RF_GENERATOR = "rfGenerator";
|
||||
public static final String ELF_GLASS = "elfGlass";
|
||||
|
||||
public static final String SPECIAL_FLOWER_PREFIX = FLOWER + ".";
|
||||
|
||||
public static final String SUBTILE_PUREDAISY = "puredaisy";
|
||||
public static final String SUBTILE_MANASTAR = "manastar";
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# MISC
|
||||
# MISC
|
||||
itemGroup.Botania=Botania
|
||||
|
||||
# Something that is not localized, translators, do NOT change this line.
|
||||
botaniamisc.noloc=botaniamisc.noloc
|
||||
|
||||
botaniamisc.nextPage=Next Page
|
||||
botaniamisc.prevPage=Previous Page
|
||||
botaniamisc.back=Back
|
||||
|
||||
Reference in new issue
Block a user