Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (โ‹ฎ) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hey,

I want to rotate my block, when I look into the direction like a furnace or a pumpkin.

I had a look into it, but found out nothing.

Thanks for help!

Assuming you mean that you want the block to rotate just when you first place it down, add this code to your block's class:

public void onBlockAdded(World par1World, int par2, int par3, int par4) {
super.onBlockAdded(par1World, par2, par3, par4);
this.setDefaultDirection(par1World, par2, par3, par4);
}

private void setDefaultDirection(World par1World, int par2, int par3, int par4) {
if (!par1World.isRemote) {
	Block l = par1World.getBlock(par2, par3, par4 - 1);
	Block i1 = par1World.getBlock(par2, par3, par4 + 1);
	Block j1 = par1World.getBlock(par2 - 1, par3, par4);
	Block k1 = par1World.getBlock(par2 + 1, par3, par4);
	byte b0 = 3;
	if (l.func_149730_j() && !i1.func_149730_j())
		b0 = 3;

	if (i1.func_149730_j() && !l.func_149730_j())
		b0 = 2;

	if (j1.func_149730_j() && !k1.func_149730_j())
		b0 = 5;

	if (k1.func_149730_j() && !j1.func_149730_j())
		b0 = 4;

	par1World.setBlockMetadataWithNotify(par2, par3, par4, b0, 2);
}
}

@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
return (side == world.getBlockMetadata(x, y, z)) ? this.frontIcon : this.blockIcon;
}

Lead DivineRPG Developer

You'll need to use block metadata to keep track of the orientation that the player places the block in, and you can use a method that pistons use to determine block facing:

ย 

@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack) {
// no need to figure out the right orientation again when the piston block can do it for us
int direction = BlockPistonBase.determineOrientation(world, x, y, z, entity);
world.setBlockMetadataWithNotify(x, y, z, direction, 2);
}

@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
return (side == world.getBlockMetadata(x, y, z)) ? this.frontIcon : this.blockIcon;
}

ย 

Note that you'll need to define a field "frontIcon" that contains the IIcon of the texture you want to draw on the front.

I like to make mods, just like you. Here's one worth checking out

Use mine if you only want the block to face north-south-east-west (like a furnace or a pumpkin). Use Jwosty's method if you want the front to be able to go up and down also (like a piston).

Lead DivineRPG Developer

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions โ†’ Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.