Jump to content

Recommended Posts

Posted

Hi everyone.

 

So, I am a bit stumped on a problem here. I can't seem to figure out how to display the side icons on my machine in a GUI.

 

The icons work fine when in the world, but when as an ItemBlock in a GUI, the top and bottom icons are fine, as they are constant, but the front, back, left and right don't get displayed, instead, they default to the "blockIcon" IIcon, which I use as the back icon.

 

How can I set the side each icon goes on when my machine is an ItemBlock?

 

Thanks.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

There really isn't any code you couldn't have already guessed I have. but anyway...

                                                                                //Side id		- Relative		        -ForgeDirection
public IIcon sideBottom; 				        //Side 0 		- Bottom		        -DOWN
public IIcon sideTop;					//Side 1 		- Top			-UP
public IIcon sideFrontOn, sideFrontOff;	        //Side 2 		- Front			-NORTH
public IIcon blockIcon;					//Side 3 		- Back			-SOUTH
public IIcon sideLeft;	 				//Side 4 		- Left			-WEST
public IIcon sideRight;	 				//Side 5		- Right			-EAST

        @Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta) {

	if (side == 0 || side == 1) {
		if (side == 0) return this.sideBottom;
		if (side == 1) return this.sideTop;
	} else if (tileMachine != null) {
		if (meta == 0 || meta == 1) {
			if (this.tileMachine.isActive) return side == 2 ? this.sideFrontOn : this.blockIcon;
			else return side == 2 ? this.sideFrontOff : this.blockIcon;
		} if (meta == 2 || meta == 3) {
			if (this.tileMachine.isActive) return side == 5 ? this.sideFrontOn : this.blockIcon;
			else return side == 5 ? this.sideFrontOff : this.blockIcon;
		} if (meta == 4 || meta == 5) {
			if (this.tileMachine.isActive) return side == 3 ? this.sideFrontOn : this.blockIcon;
			else return side == 3 ? this.sideFrontOff : this.blockIcon;
		} if (meta == 6 || meta == 7) {
			if (this.tileMachine.isActive) return side == 4 ? this.sideFrontOn : this.blockIcon;
			else return side == 4 ? this.sideFrontOff : this.blockIcon;
		}
	}
	return blockIcon;
}

@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister icon) {
	this.sideBottom = icon.registerIcon(modid + ":" + this.getUnlocalizedName().substring(5) + "_Bottom");
	this.sideTop = icon.registerIcon(modid + ":" + this.getUnlocalizedName().substring(5) + "_Top");
	this.sideFrontOn = icon.registerIcon(modid + ":" + this.getUnlocalizedName().substring(5) + "_Front_on");
	this.sideFrontOff = icon.registerIcon(modid + ":" + this.getUnlocalizedName().substring(5) + "_Front_off");
	this.sideLeft = icon.registerIcon(modid + ":" + this.getUnlocalizedName().substring(5) +  "_Left");
	this.sideRight = icon.registerIcon(modid + ":" + this.getUnlocalizedName().substring(5) + "_Right");
	this.blockIcon = icon.registerIcon(modid + ":" + this.getUnlocalizedName().substring(5) + "_Back");
}

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Hi

 

I am extremely suspicious of this line

} else if (tileMachine != null) {

 

Where is tileMachine stored?  I think you have a likely "all machines will face the same way" bug there.

 

About your original question:

> they default to the "blockIcon" IIcon, which I use as the back icon

 

That's probably because your tileMachine is null and it drops through to your final statement.

 

You need to handle the null case properly.  Or better yet, fix the tileMachine bug, eg use meta instead.

 

-TGG

 

 

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.