Jump to content

Recommended Posts

Posted

Hey, I just started modding (looks at watch) 8 hours ago, and I've run into a weird problem.

 

I'm making a decay mod, and I've overridden the BlockWood class with a custom class. The issue is: all wood-type blocks such as stairs and slabs have the wrong texture.

 

package lethman.DecayMod;

import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import java.util.Random;
import java.util.logging.Level;

import net.minecraft.block.Block;
import net.minecraft.block.BlockWood;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.MinecraftForge;

public class BlockCustomWood extends BlockWood
{
    /** The type of tree this block came from. */
    public static final String[] woodType = new String[] {"oak", "spruce", "birch", "jungle"};
    @SideOnly(Side.CLIENT)
    private Icon[] iconArray;

    public BlockCustomWood()
    {
    	super(5);
        this.setCreativeTab(CreativeTabs.tabBlock);
        needsRandomTick = true;  
        setBurnProperties(5, 5, 20);      
    }

    @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));
    }
    
    /**
     * 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.iconArray = new Icon[woodType.length];

        for (int i = 0; i < this.iconArray.length; ++i)
        {
            this.iconArray[i] = par1IconRegister.registerIcon("minecraft:planks_" + woodType[i]);
        }
    }
    
    @SideOnly(Side.CLIENT)
    public Icon getBlockTextureFromSideAndMetadata(int side, int meta)
    {
    	return iconArray[meta];
    }
    
    /**
     * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
     */
    public Icon getIcon(int par1, int par2)
    {
        if (par2 < 0 || par2 >= this.iconArray.length)
        {
            par2 = 0;
        }

        return this.iconArray[par2];
    }
            
    /**
     * Determines the damage on the item the block drops. Used in cloth and wood.
     */
    public int damageDropped(int par1)
    {
    	return par1;    	
    }
    
/**
 * Called whenever the block is added into the world. Args: world, x, y, z
 */
public void onBlockAdded(World par1World, int par2, int par3, int par4)
{
	super.onBlockAdded(par1World, par2, par3, par4);
    par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate(par1World));
}

/**
 * How many world ticks before ticking
 */
public int tickRate(World par1World)
{
    return 30 + par1World.rand.nextInt(20);
}

/**
 * Ticks the block if it's been scheduled
 */
public void updateTick(World par1World, int x, int y, int z, Random par5Random)
{
	super.updateTick(par1World, x, y, z, par5Random);

    	if (par1World.isRaining())
    	{
    		if (par5Random.nextInt(lethman.DecayMod.Generic.WoodInRain) == 0 && par1World.canBlockSeeTheSky(x, y + 1, z))
    		{
    			par1World.setBlock(x, y, z, lethman.DecayMod.Generic.rottenWoodID
    					, par1World.getBlockMetadata(x, y, z), 2);
    		}
    	}
    	
    	if (par1World.getBlockMaterial(x, y-1, z) == Material.water |
    			par1World.getBlockMaterial(x, y + 1, z) == Material.water |
    			par1World.getBlockMaterial(x - 1, y, z) == Material.water |
    			par1World.getBlockMaterial(x + 1, y, z) == Material.water |
    			par1World.getBlockMaterial(x, y, z - 1) == Material.water |
    			par1World.getBlockMaterial(x, y, z + 1) == Material.water)
    			{
    				if (par5Random.nextInt(lethman.DecayMod.Generic.WoodInWater) == 0)
    	    			par1World.setBlock(x, y, z, 
    	    					lethman.DecayMod.Generic.rottenWoodID, 
    	    					par1World.getBlockMetadata(x, y, z), 2);
    			}

    par1World.scheduleBlockUpdate(x, y, z, this.blockID, this.tickRate(par1World));
}
}

 

And here's a pic:

 

s6PxuYJ.png

I'm new to using other people's API's, and I rarely ever code in java. Any way someone could try to point out any mistakes?

 

Thanks :P

Posted

...Oops. Okay, so tearing out the texture related stuff means that my custom blocks use the missing texture and all other blocks are still messed... Could it possibly be the fact that I'm replacing id 5 in block.blockList with my custom class?

 

Block.blocksList[5] = null;   

                Block wood = new BlockCustomWood();
                LanguageRegistry.addName(wood, "Wood");  
                GameRegistry.registerBlock(wood, CustomWoodItemBlock.class); 
                MinecraftForge.setBlockHarvestLevel(wood, "axe", 0);  

Posted

First, check that your new block works as intended. (obviously you need to initialize it the same way as Mojang, if you don't want to change that)

Then if that is what you want, you can register recipes with your block as a input or output to override vanilla ones.

You can't change the blocks into the blockList because they are "final". ;)

Posted

First, check that your new block works as intended. (obviously you need to initialize it the same way as Mojang, if you don't want to change that)

Then if that is what you want, you can register recipes with your block as a input or output to override vanilla ones.

You can't change the blocks into the blockList because they are "final". ;)

gotchya...

 

Is there any way to quickly replace all recipes using planks with my planks? Or do I manually have to re-add each recipe using planks. Sorry for the noobish questions. I really have no excuse... :-[

Posted

First, check that your new block works as intended. (obviously you need to initialize it the same way as Mojang, if you don't want to change that)

Then if that is what you want, you can register recipes with your block as a input or output to override vanilla ones.

You can't change the blocks into the blockList because they are "final". ;)

gotchya...

 

Is there any way to quickly replace all recipes using planks with my planks? Or do I manually have to re-add each recipe using planks. Sorry for the noobish questions. I really have no excuse... :-[

 

You could use the ore dictionary. Try removing the vanilla wood and adding your own instead...

Posted

Hmm. The craftingHandler looks like an awesome bit of code. But I'm not sure on how to implement it. I can replace the recipes that output default planks with my planks, but then my planks can't do anything, like make chests. Here's the code so far:

		if(item.itemID == lethman.DecayMod.Generic.newWoodID){
		item.itemID = Block.planks.blockID;

		if (lethman.DecayMod.Generic.DebugLog)
			System.out.println("Overrode custom planks.");
		return;
		}		

	if(item.itemID == Block.planks.blockID){
		item.itemID = lethman.DecayMod.Generic.newWoodID;

		if (lethman.DecayMod.Generic.DebugLog)
			System.out.println("Overrode generic planks.");
		return;
		}	

 

Any good articles or something on how to use it?

Posted

OOOHHHhhhhKay.So. I'm using both the OreDictionary and CraftingHandlers. It works awesome, but shift-clicking the recipe balls things up. Here's in the mod.load():

                GameRegistry.registerCraftingHandler(new PlankCraftingHandler());
                OreDictionary.registerOre("plankWood", wood);    

 

and PlankCraftingHandler():

 

		
	if(item.itemID == Block.planks.blockID){
		item.itemID = lethman.DecayMod.Generic.newWoodID;

		if (lethman.DecayMod.Generic.DebugLog)
			System.out.println("Overrode generic planks.");
		}	

 

How should I fix shift-clicking?

Posted

...Oops. Okay, so tearing out the texture related stuff means that my custom blocks use the missing texture and all other blocks are still messed... Could it possibly be the fact that I'm replacing id 5 in block.blockList with my custom class?

 

Block.blocksList[5] = null;   

                Block wood = new BlockCustomWood();
                LanguageRegistry.addName(wood, "Wood");  
                GameRegistry.registerBlock(wood, CustomWoodItemBlock.class); 
                MinecraftForge.setBlockHarvestLevel(wood, "axe", 0);  

 

well actually, im not saying you should do this, but essentially i have a super small mod that changes the behavior of wood (so that when you break 1 wood block all other above break also) and this is how i did it.  maybe in your case its a bad idea but depending on the goal its doable

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

Give a proper description of your shift-click issue if you want some help ;)

 

Maybe you should open a new thread too.

 

Aight, so the issue is when crafting just one item, it works and my new planks are returned. Shift clicking though, causes it to return the items as normal planks.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.