package com.yolp900.itsjustacharm.common.blocks.base;
import com.yolp900.itsjustacharm.ItsJustaCharm;
import com.yolp900.itsjustacharm.api.IJCConstants;
import com.yolp900.itsjustacharm.common.blocks.ModBlocks;
import com.yolp900.itsjustacharm.reference.LibLocations;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public abstract class ModBlock extends Block implements IModBlock {
public ModBlock(IJCConstants.Blocks block, Material material) {
super(material);
this.setUnlocalizedName(block.getUnlocalizedName());
this.setRegistryName(block.getRegistryName());
this.setCreativeTab(ItsJustaCharm.creativeTab);
ModBlocks.modBlocks.add(this);
}
@Override
public void registerBlock() {
ItemBlock itemBlock = new ModItemBlock(this);
itemBlock.setRegistryName(getRegistryName());
itemBlock.setUnlocalizedName(getUnlocalizedName());
registerBlock(this);
registerItemBlock(itemBlock);
}
protected void registerBlock(Block block) {
GameRegistry.register(block);
}
protected void registerItemBlock(ItemBlock itemBlock) {
GameRegistry.register(itemBlock);
}
@Override
@SideOnly (Side.CLIENT)
public void registerRender() {
Item item = Item.getItemFromBlock(this);
if (item == null || !(item instanceof ModItemBlock)) {
return;
}
ModItemBlock itemBlock = (ModItemBlock)item;
registerRender(this);
registerRender(itemBlock);
}
@SideOnly(Side.CLIENT)
protected void registerRender(Block block) {
// Used for special rendering
}
@SideOnly(Side.CLIENT)
protected void registerRender(ItemBlock itemBlock) {
ResourceLocation registryName = itemBlock.getRegistryName();
String domain = registryName.getResourceDomain();
String path = LibLocations.ITEMBLOCK_MODEL_FOLDER_PREFIX + registryName.getResourcePath();
ResourceLocation location = new ResourceLocation(domain, path);
ModelLoader.setCustomModelResourceLocation(itemBlock, 0, new ModelResourceLocation(location.toString()));
}
public class ModItemBlock extends ItemBlock {
public ModItemBlock(Block block) {
super(block);
setHasSubtypes(false);
}
@Override
public int getMetadata(int damage) {
return damage;
}
}
}