Jump to content

[Resolved][1.7.2] Custom Log causing crash when rendered


Recommended Posts

Posted

Hi all, sorry for appearing so often with these questions.

I'm trying to make a custom log that will replace an oak log and keep it's orientation (right click an oak tree with an axe, the bark is stripped off and will regrow over time) but so far, although eclipse isn't throwing up any errors with the code, I've clearly buggered up somewhere. The texture icon fails to load and if the block is displayed in a creative tab, search tab or such, the client crashes out immediately.

 

Block Class:

 

  Reveal hidden contents

 

 

Main Class:

 

  Reveal hidden contents

 

 

Console Log:

 

  Reveal hidden contents

 

 

Image:

<assets.bigassbarrels.textures.blocks>

StrippedLog.png

 

Cheers again for any help offered, Modding is proving frustrating, but bloody fun too!

Posted

Cheers Link, the trouble I'm getting there though, is that Eclipse screams at me that BlockRotatedPillar must implement getSideIcon() (I was looking at the wood log source code to try and make this function in an identical manner, just without the metadata subblocks. :/

 

  On 3/14/2014 at 6:40 PM, diesieben07 said:

This people, is why you use @Override.

I did originally have @Override on each method originally, I majorly derped a bit then, I made the assumption that the client side annotation would override as well.

Posted

Everybody using eclipse and others like it should know this. The @Override annotation is put there as an error catcher!!! if you remove it, then you are ignoring some serious error you might be creating. Obviously any attempt to subclass a class and override methods (usually what you want) will be caught and signalled as errors only if the annotation is left in place. If it is removed, fine. Just beware that you are not actually overriding any method (you are creating a similar method). And your method may never be called. Worse, the original method will still be called. So, don't remove @Override!!!

Posted

Cheers for explaining @Override's functionality in greater depth Sequiturian.

I've tried extending blockLog instead of blockRotatedPillar,  but I get all kinds of issues with methods not accepting overrides unless they're made final,  usually happens with the protected ones.  I think I'll have to try and transplant over more code than I first thought.  I'll update this thread if I can get it working.  Cheers to everyone who has taken the time to reply so far though!

Posted

I have the same problem when using getSideIcon in any class. I've tried using @Override and also tried changing it to getIcon instead, as suggested, but as you've said, it still doesn't work. I doesn't work even if you do a direct copy of the vanilla code. Have you found any solution yet?

Posted

Hi Silas, Not Yet I'm afraid, assigning text name is working if I have it instead of any GetIcon/GetSideIcon code.

At the moment that best I've managed is to isolate it down to a NullPointer exception in the getIcon return so for some reason, the icons array is getting filled with Null Objects. I can't say if this is the same problem for you, we could both be missing something completely obvious.

Posted

getSideIcon is not a method in block or BlockFire. Why would expect to implement a nonexistent method? Did you mean GetIcon(side,meta) or GetFireIcon(index)?

 

Let me speak plainer Ingrish, @Override is used for methods you are wanting/expecting/desiring/needing to override. There is nothing that says you cannot implement your own private or public methods in your extended class.

Posted

In my case, I'm using getSideIcon when extendind BlockRotatedPillar and getIcon with plain old Block. Neither one is working and it appears to be when I'm calling RegisterIcon()

 

Here's the class as it currently stands, commenting out the fuctions was the only way to stop it auto-crashing the game until I can work out what's up when I try to register the icons.

 

package minothor.bab.blocks;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.util.IIcon;
import net.minecraft.block.*;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.world.World;

public class blockStrippedOak extends Block{


public blockStrippedOak() {
	super(Material.wood);
	setBlockName("BlockStrippedOak");
	setHarvestLevel("axe",0);
	setHardness(0.5F);
	setStepSound(Block.soundTypeWood);
	// TODO Auto-generated constructor stub

}

@SideOnly(Side.CLIENT)
protected IIcon[] icons;


@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister par1IconRegister)
{
	this.icons = new IIcon[2];
	System.out.println("Icon Array Length: "+ icons.length);
	this.icons[0] = par1IconRegister.registerIcon("bigassbarrels" + ":" + "StrippedLog");
	System.out.println("icons 0 :" + icons[0]);
	this.icons[1] = par1IconRegister.registerIcon("bigassbarrels" + ":" + "StrippedLog");
	System.out.println("icons 1 :" + icons[1]);
}

/*@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int side, int meta)
{
	switch(side)
	{
	case 0:
		return this.icons[0];
	case 1:
		return this.icons[0];
	default:
		return this.icons[1];

	}
}
 */
public int onBlockPlaced (World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metaD)
{
	// This metadata code comes from Natura's Darkwood Log, pasted here as a reminder and notepad of sorts.
	/*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;
	 */
	System.out.println("Placed against side: " + side);
	System.out.println("Side / 2: " + (side/2));
	System.out.println("Side % 2: " + (side%2));
	return metaD;
}

}

Posted

Here's the Latest run:

 

package minothor.bab.blocks;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.util.IIcon;
import net.minecraft.block.*;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.world.World;

public class blockStrippedOak extends BlockRotatedPillar{


public blockStrippedOak() {
	super(Material.wood);
	setBlockName("BlockStrippedOak");
	setHarvestLevel("axe",0);
	setHardness(0.5F);
	setStepSound(Block.soundTypeWood);
	// TODO Auto-generated constructor stub

}

@SideOnly(Side.CLIENT)
protected IIcon[] icons;


@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IIconRegister par1IconRegister)
{
	this.icons = new IIcon[2];
	System.out.println("Icon Array Length: "+ icons.length);
	this.icons[0] = par1IconRegister.registerIcon("bigassbarrels" + ":" + "StrippedLog");
	System.out.println("icons 0 :" + icons[0]);
	this.icons[1] = par1IconRegister.registerIcon("bigassbarrels" + ":" + "StrippedLog");
	System.out.println("icons 1 :" + icons[1]);
}

@SideOnly(Side.CLIENT)
@Override
public IIcon getSideIcon(int side)
{
	switch(side)
	{
	case 0:
		return this.icons[0];
	case 1:
		return this.icons[0];
	default:
		return this.icons[1];

	}
}
public int onBlockPlaced (World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metaD)
{
	/*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;
	 */
	System.out.println("Placed against side: " + side);
	System.out.println("Side / 2: " + (side/2));
	System.out.println("Side % 2: " + (side%2));
	return metaD;
}

}

 

and the console output:

 

  Reveal hidden contents

 

Posted

getSideIcon and getTopIcon only pass in the lower 2 bits of meta data. No side information is passed. All sides are expected to use the same icon, only the metadata bits determine the look of the side. In other words, It's bark (side) or rings (top).

Posted

Cheers Sequiturian! That explanation of what the parameters are was the final piece of the puzzle for me!

I've now got the custom texture icon working and I've changed the block to extend BlockLog.

All I need to do now is work out how to correctly reference the vanilla tree_top.png texture.

I'll see if I can dig the original out of the TextureAtlas.

 

blockStrippedOak class now:

 

package minothor.bab.blocks;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.util.IIcon;
import net.minecraft.block.*;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.world.World;

public class blockStrippedOak extends BlockLog{


public blockStrippedOak() {
	super();
	setBlockName("BlockStrippedOak");
	setHarvestLevel("axe",0);
	setHardness(0.5F);
	setStepSound(Block.soundTypeWood);

}

@SideOnly(Side.CLIENT)
protected IIcon[] icons;


@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister par1IconRegister)
{
	this.icons = new IIcon[2];
	//System.out.println("Icon Array Length: "+ icons.length);
	this.icons[0] = par1IconRegister.registerIcon("minecraft:Tree_Top");
	System.out.println("icons 0 :" + icons[0]);
	this.icons[1] = par1IconRegister.registerIcon("bigassbarrels:StrippedLog");
	//System.out.println("icons 1 :" + icons[1]);
}

@SideOnly(Side.CLIENT)
@Override
public IIcon getSideIcon(int metaD)
{
	return this.icons[1];
}

@SideOnly(Side.CLIENT)
@Override
public IIcon getTopIcon(int metaD)
{
	return this.icons[0];
}


public int onBlockPlaced (World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metaD)
{
	/*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;
	 */
	System.out.println("Placed against side: " + side);
	System.out.println("Side / 2: " + (side/2));
	System.out.println("Side % 2: " + (side%2));
	return metaD;
}

}

 

Console Log:

 

  Reveal hidden contents

 

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.