mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-21 12:42:50 +00:00
Icon and unlocalized name calls from the SubTile.
This commit is contained in:
1 parent
6097122735
commit
e41c92f61c
4 files changed
+81
-2
No files matched your search
@@ -12,10 +12,12 @@
|
||||
package vazkii.botania.common.block;
|
||||
|
||||
import net.minecraft.block.BlockFlower;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import vazkii.botania.api.ISpecialFlower;
|
||||
import vazkii.botania.common.block.tile.TileSpecialFlower;
|
||||
import vazkii.botania.common.core.BotaniaCreativeTab;
|
||||
|
||||
public class BlockSpecialFlower<T extends TileEntity> extends BlockFlower implements ISpecialFlower {
|
||||
@@ -32,7 +34,12 @@ public class BlockSpecialFlower<T extends TileEntity> extends BlockFlower implem
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, int metadata) {
|
||||
return super.createTileEntity(world, metadata);
|
||||
return new TileSpecialFlower();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getBlockTexture(IBlockAccess par1iBlockAccess, int par2, int par3, int par4, int par5) {
|
||||
return ((TileSpecialFlower) par1iBlockAccess.getBlockTileEntity(par2, par3, par4)).getIcon();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,7 @@ public final class ModBlocks {
|
||||
|
||||
public static Block flower;
|
||||
public static Block altar;
|
||||
public static Block specialFlower;
|
||||
|
||||
public static void init() {
|
||||
flower = new BlockModFlower();
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* 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 @ [Jan 25, 2014, 2:04:15 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.item.block;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Icon;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.subtile.SubTileEntity;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.core.helper.ItemNBTHelper;
|
||||
import vazkii.botania.common.lib.LibBlockNames;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemBlockSpecialFlower extends ItemBlock {
|
||||
|
||||
private static String TAG_TYPE = "type";
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static Map<String, Icon> iconsForType = new HashMap();
|
||||
|
||||
public ItemBlockSpecialFlower(int par1) {
|
||||
super(par1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon(ItemStack stack, int pass) {
|
||||
String type = getType(stack);
|
||||
if(!iconsForType.containsKey(type)) {
|
||||
try {
|
||||
SubTileEntity tile = BotaniaAPI.getSubTileMapping(type).newInstance();
|
||||
iconsForType.put(type, tile.getIcon());
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return iconsForType.get(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack stack) {
|
||||
return LibBlockNames.SPECIAL_FLOWER_PREFIX + getType(stack);
|
||||
}
|
||||
|
||||
public static String getType(ItemStack stack) {
|
||||
return ItemNBTHelper.getString(stack, TAG_TYPE, "");
|
||||
}
|
||||
|
||||
public static ItemStack ofType(String type) {
|
||||
ItemStack stack = new ItemStack(ModBlocks.specialFlower);
|
||||
ItemNBTHelper.setString(null, TAG_TYPE, type);
|
||||
return stack;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,5 +17,7 @@ public final class LibBlockNames {
|
||||
|
||||
public static final String FLOWER = LibResources.PREFIX_MOD + "flower";
|
||||
public static final String ALTAR = LibResources.PREFIX_MOD + "altar";
|
||||
|
||||
public static final String SPECIAL_FLOWER_PREFIX = FLOWER + ".";
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user