Fixed, look in limpBlockLogAspen for details (in red)
Hello! I have been working on my mod for a while. I have a custom creative tab that works fine, but as soon as I added my custom wood (log) block to be shown in the creative tab, it crashes the game upon clicking the creative tab. I am able to place the log down on the ground (via already having it by making the log load as a normal block, selecting it, then changing the code to make it a "log" block.) if i already have it in my inventory. How can i get it to stop crashing the game and show in the creative tab right?
public class limpBlockLogAspen extends Block
{
/** The type of tree this log came from. */
public static final String[] woodType = new String[] {"aspen"};
public static final String[] treeTextureTypes = new String[] {"logAspen"};
@SideOnly(Side.CLIENT)
private Icon[] iconArray;
@SideOnly(Side.CLIENT)
private Icon logAspenTop;
/**
* The type of render function that is called for this block
*/
public int getRenderType()
{
return 31;
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random par1Random)
{
return 1;
}
/**
* Returns the ID of the items to drop on destruction.
*/
public int idDropped(int par1, Random par2Random, int par3)
{
return limpBase.logAspen.blockID;
}
/**
* ejects contained items into the world, and notifies neighbours of an update, as appropriate
*/
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
{
byte b0 = 4;
int j1 = b0 + 1;
/**
* Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata
*/
public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9)
{
int j1 = par9 & 3;
byte b0 = 0;
switch (par5)
{
case 0:
case 1:
b0 = 0;
break;
case 2:
case 3:
b0 = 8;
break;
case 4:
case 5:
b0 = 4;
}
return j1 | b0;
}
@SideOnly(Side.CLIENT)
/**
* From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
*/
public Icon getIcon(int par1, int par2)
{
int k = par2 & 12;
int l = par2 & 3;
return k == 0 && (par1 == 1 || par1 == 0) ? this.logAspenTop : (k == 4 && (par1 == 5 || par1 == 4) ? this.logAspenTop : (k == 8 && (par1 == 2 || par1 == 3) ? this.logAspenTop : this.iconArray[l]));
}
/**
* Determines the damage on the item the block drops. Used in cloth and wood.
*/
public int damageDropped(int par1)
{
return par1 & 3;
}
/**
* returns a number between 0 and 3
*/
public static int limitToValidMetadata(int par0)
{
return par0 & 3;
}
@SideOnly(Side.CLIENT)
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
par3List.add(new ItemStack(par1, 1, 2));
par3List.add(new ItemStack(par1, 1, 3));
}
//REMOVE THIS TO FIX FOR THOSE WITH THE SAME PROBLEM!
/**
* Returns an item stack containing a single instance of the current block type. 'i' is the block's subtype/damage
* and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null.
*/
protected ItemStack createStackedBlock(int par1)
{
return new ItemStack(this.blockID, 1, limitToValidMetadata(par1));
}
@SideOnly(Side.CLIENT)
/**
* When this method is called, your block should register all the icons it needs with the given IconRegister. This
* is the only chance you get to register icons.
*/
public void registerIcons(IconRegister par1IconRegister)
{
this.logAspenTop = par1IconRegister.registerIcon(limpBase.modid + ":" + "logAspenTop");
this.iconArray = new Icon[treeTextureTypes.length];
for (int i = 0; i < this.iconArray.length; ++i)
{
this.iconArray[i] = par1IconRegister.registerIcon(limpBase.modid + ":" + treeTextureTypes[i]);
}
}
@Override
public boolean canSustainLeaves(World world, int x, int y, int z)
{
return true;
}
@Override
public boolean isWood(World world, int x, int y, int z)
{
return true;
}
}
limpCreativeTab
package limpcraft.common;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentData;
import net.minecraft.enchantment.EnumEnchantmentType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StringTranslate;
final class limpCreativeTab extends CreativeTabs
{
public final static CreativeTabs tabLimpCraft = new limpCreativeTab(CreativeTabs.getNextID(), "LimpCraft");
public String getTranslatedTabLabel()
{
return "LimpCraft";
}
limpCreativeTab(int par1, String par2Str)
{
super(par1, par2Str);
}
@SideOnly(Side.CLIENT)
//Item to be displayed on the tab
public int getTabIconItemIndex()
{
return limpBase.pickaxeLimpiumGiga.itemID;
}
@Init
public void load(FMLInitializationEvent event)
{
LanguageRegistry.instance().addStringLocalization("itemGroup.LimpCraft", "en_US", "LimpCraft");
LanguageRegistry.instance().addStringLocalization("itemGroup.LimpCraft", "en_UK", "LimpCraft");
}
}
I don't think you need the Base Mod class because it is just defined like a regular block of mine, and all the other blocks show up fine.
It was because I only have 1 log, not 4...I suppose you may be able to just delete the last 3 par3List's but I haven't tested and don't know how it works with the metadata if there really isn't actual "metadata"...
Rollback Post to RevisionRollBack
Mod Author and Owner of Blockhole
Owner of other discontinued or status frozen work: LimpCraft2, LimpCore, InventoryCalculator, VillageTech, Bitto'Color.
Hello! I have been working on my mod for a while. I have a custom creative tab that works fine, but as soon as I added my custom wood (log) block to be shown in the creative tab, it crashes the game upon clicking the creative tab. I am able to place the log down on the ground (via already having it by making the log load as a normal block, selecting it, then changing the code to make it a "log" block.) if i already have it in my inventory. How can i get it to stop crashing the game and show in the creative tab right?
limpBlockLogAspen
package limpcraft.common;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
public class limpBlockLogAspen extends Block
{
/** The type of tree this log came from. */
public static final String[] woodType = new String[] {"aspen"};
public static final String[] treeTextureTypes = new String[] {"logAspen"};
@SideOnly(Side.CLIENT)
private Icon[] iconArray;
@SideOnly(Side.CLIENT)
private Icon logAspenTop;
protected limpBlockLogAspen(int par1)
{
super(par1, Material.wood);
this.setCreativeTab(limpCreativeTab.tabLimpCraft);
}
/**
* The type of render function that is called for this block
*/
public int getRenderType()
{
return 31;
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random par1Random)
{
return 1;
}
/**
* Returns the ID of the items to drop on destruction.
*/
public int idDropped(int par1, Random par2Random, int par3)
{
return limpBase.logAspen.blockID;
}
/**
* ejects contained items into the world, and notifies neighbours of an update, as appropriate
*/
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
{
byte b0 = 4;
int j1 = b0 + 1;
if (par1World.checkChunksExist(par2 - j1, par3 - j1, par4 - j1, par2 + j1, par3 + j1, par4 + j1))
{
for (int k1 = -b0; k1 <= b0; ++k1)
{
for (int l1 = -b0; l1 <= b0; ++l1)
{
for (int i2 = -b0; i2 <= b0; ++i2)
{
int j2 = par1World.getBlockId(par2 + k1, par3 + l1, par4 + i2);
if (Block.blocksList[j2] != null)
{
Block.blocksList[j2].beginLeavesDecay(par1World, par2 + k1, par3 + l1, par4 + i2);
}
}
}
}
}
}
/**
* Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata
*/
public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9)
{
int j1 = par9 & 3;
byte b0 = 0;
switch (par5)
{
case 0:
case 1:
b0 = 0;
break;
case 2:
case 3:
b0 = 8;
break;
case 4:
case 5:
b0 = 4;
}
return j1 | b0;
}
@SideOnly(Side.CLIENT)
/**
* From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
*/
public Icon getIcon(int par1, int par2)
{
int k = par2 & 12;
int l = par2 & 3;
return k == 0 && (par1 == 1 || par1 == 0) ? this.logAspenTop : (k == 4 && (par1 == 5 || par1 == 4) ? this.logAspenTop : (k == 8 && (par1 == 2 || par1 == 3) ? this.logAspenTop : this.iconArray[l]));
}
/**
* Determines the damage on the item the block drops. Used in cloth and wood.
*/
public int damageDropped(int par1)
{
return par1 & 3;
}
/**
* returns a number between 0 and 3
*/
public static int limitToValidMetadata(int par0)
{
return par0 & 3;
}
@SideOnly(Side.CLIENT)
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
par3List.add(new ItemStack(par1, 1, 2));
par3List.add(new ItemStack(par1, 1, 3));
}
//REMOVE THIS TO FIX FOR THOSE WITH THE SAME PROBLEM!
/**
* Returns an item stack containing a single instance of the current block type. 'i' is the block's subtype/damage
* and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null.
*/
protected ItemStack createStackedBlock(int par1)
{
return new ItemStack(this.blockID, 1, limitToValidMetadata(par1));
}
@SideOnly(Side.CLIENT)
/**
* When this method is called, your block should register all the icons it needs with the given IconRegister. This
* is the only chance you get to register icons.
*/
public void registerIcons(IconRegister par1IconRegister)
{
this.logAspenTop = par1IconRegister.registerIcon(limpBase.modid + ":" + "logAspenTop");
this.iconArray = new Icon[treeTextureTypes.length];
for (int i = 0; i < this.iconArray.length; ++i)
{
this.iconArray[i] = par1IconRegister.registerIcon(limpBase.modid + ":" + treeTextureTypes[i]);
}
}
@Override
public boolean canSustainLeaves(World world, int x, int y, int z)
{
return true;
}
@Override
public boolean isWood(World world, int x, int y, int z)
{
return true;
}
}
limpCreativeTab
I don't think you need the Base Mod class because it is just defined like a regular block of mine, and all the other blocks show up fine.
Thank you!
Mod Author and Owner of Blockhole
Owner of other discontinued or status frozen work: LimpCraft2, LimpCore, InventoryCalculator, VillageTech, Bitto'Color.
if anyone is interested in how to fix, it was dealing with this code:
Just remove it!
Mod Author and Owner of Blockhole
Owner of other discontinued or status frozen work: LimpCraft2, LimpCore, InventoryCalculator, VillageTech, Bitto'Color.
It was because I only have 1 log, not 4...I suppose you may be able to just delete the last 3 par3List's but I haven't tested and don't know how it works with the metadata if there really isn't actual "metadata"...
Mod Author and Owner of Blockhole
Owner of other discontinued or status frozen work: LimpCraft2, LimpCore, InventoryCalculator, VillageTech, Bitto'Color.