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.common.integration.waila.IWailaStackProvider;
import com.yolp900.itsjustacharm.reference.LibLocations;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLog;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.registry.GameRegistry;
import javax.annotation.Nonnull;
public abstract class ModBlockLog extends BlockLog implements IModBlock, IWailaStackProvider {
public ModBlockLog(IJCConstants.Blocks block) {
this.setUnlocalizedName(block.getUnlocalizedName());
this.setRegistryName(block.getRegistryName());
this.setHardness(2.0F);
this.setSoundType(SoundType.WOOD);
this.setCreativeTab(ItsJustaCharm.creativeTab);
ModBlocks.modBlocks.add(this);
this.setDefaultState(this.blockState.getBaseState().withProperty(LOG_AXIS, BlockLog.EnumAxis.Y));
}
@Override
public void registerBlock() {
ItemBlock itemBlock = new ItemBlock(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
public void registerRender() {
Item item = Item.getItemFromBlock(this);
if (item == null || !(item instanceof ItemBlock)) {
return;
}
ItemBlock itemBlock = (ItemBlock)item;
registerRender(this);
registerRender(itemBlock);
}
protected void registerRender(Block block) {
// Used for special Rendering
}
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()));
}
@Override
@Nonnull
public IBlockState getStateFromMeta(int meta) {
IBlockState iblockstate = this.getDefaultState();
switch (meta & 12) {
case 0:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.Y);
break;
case 4:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.X);
break;
case 8:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.Z);
break;
default:
iblockstate = iblockstate.withProperty(LOG_AXIS, BlockLog.EnumAxis.NONE);
}
return iblockstate;
}
@Override
public int getMetaFromState(IBlockState state) {
int i = 0;
switch (state.getValue(LOG_AXIS)) {
case X:
i |= 4;
break;
case Z:
i |= 8;
break;
case NONE:
i |= 12;
}
return i;
}
@Override
@Nonnull
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, LOG_AXIS);
}
@Override
public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config) {
return new ItemStack(this);
}
}