Jump to content

How would I set my blocks metadata depending on the players direction?


Recommended Posts

Posted

Sorry for two questions in a row, but my mod is nearly done and I just want to get these last bits finished.

 

An issue plaguing me since I started it, is I can't rotate the top texture of the block. I can rotate the side ones OK, but not the top. So my next approach, is to make metadata-based sub-blocks, 4 of each type, and pick which one to place depending on the direction the player is facing.

 

How would I go about doing this?

(Unless anyone knows a way to do it properly of course!)

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

Sorry for two questions in a row, but my mod is nearly done and I just want to get these last bits finished.

 

An issue plaguing me since I started it, is I can't rotate the top texture of the block. I can rotate the side ones OK, but not the top. So my next approach, is to make metadata-based sub-blocks, 4 of each type, and pick which one to place depending on the direction the player is facing.

 

How would I go about doing this?

(Unless anyone knows a way to do it properly of course!)

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

Put this code into your block's onBlockPlacedBy

int dir = MathHelper.floor_double((double)((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
world.setBlockMetadataWithNotify(i, j, k, dir, 0);

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Posted

Put this code into your block's onBlockPlacedBy

int dir = MathHelper.floor_double((double)((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
world.setBlockMetadataWithNotify(i, j, k, dir, 0);

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

Posted

Doesn't seem to be working. Here's the entire block's class, no matter what direction I face it's placing the same block.

 

package co.uk.silvania.roads.block;

import co.uk.silvania.roads.CommonProxy;
import co.uk.silvania.roads.Roads;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.util.Facing;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class RBDoubleYellowStripe extends Block {

    public RBDoubleYellowStripe(int id) {
        super(id, Material.rock);
        this.setCreativeTab(Roads.tabRoads);
        this.setHardness(1.0F);
        this.setStepSound(Block.soundStoneFootstep);
    }
    
    @Override
    public int getBlockTextureFromSideAndMetadata (int side, int metadata) {
    	return 0 + 4;
    }
    
    @Override
    public String getTextureFile () {
            return CommonProxy.BLOCK_PNG;
    }
  
    public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving)    {
    	int dir = MathHelper.floor_double((double)((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
    	world.setBlockMetadataWithNotify(i, j, k, dir);
    }
}

 

I'm assuming I've missed something, but I have no idea what...

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

Doesn't seem to be working. Here's the entire block's class, no matter what direction I face it's placing the same block.

 

package co.uk.silvania.roads.block;

import co.uk.silvania.roads.CommonProxy;
import co.uk.silvania.roads.Roads;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.util.Facing;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class RBDoubleYellowStripe extends Block {

    public RBDoubleYellowStripe(int id) {
        super(id, Material.rock);
        this.setCreativeTab(Roads.tabRoads);
        this.setHardness(1.0F);
        this.setStepSound(Block.soundStoneFootstep);
    }
    
    @Override
    public int getBlockTextureFromSideAndMetadata (int side, int metadata) {
    	return 0 + 4;
    }
    
    @Override
    public String getTextureFile () {
            return CommonProxy.BLOCK_PNG;
    }
  
    public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving)    {
    	int dir = MathHelper.floor_double((double)((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
    	world.setBlockMetadataWithNotify(i, j, k, dir);
    }
}

 

I'm assuming I've missed something, but I have no idea what...

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

Doesn't seem to be working. Here's the entire block's class, no matter what direction I face it's placing the same block.

 

package co.uk.silvania.roads.block;

import co.uk.silvania.roads.CommonProxy;
import co.uk.silvania.roads.Roads;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.util.Facing;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class RBDoubleYellowStripe extends Block {

    public RBDoubleYellowStripe(int id) {
        super(id, Material.rock);
        this.setCreativeTab(Roads.tabRoads);
        this.setHardness(1.0F);
        this.setStepSound(Block.soundStoneFootstep);
    }
    
    @Override
    public int getBlockTextureFromSideAndMetadata (int side, int metadata) {
    	return 0 + 4;
    }
    
    @Override
    public String getTextureFile () {
            return CommonProxy.BLOCK_PNG;
    }
  
    public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving)    {
    	int dir = MathHelper.floor_double((double)((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
    	world.setBlockMetadataWithNotify(i, j, k, dir);
    }
}

 

I'm assuming I've missed something, but I have no idea what...

 

 

It appears you are missing the flag argument in:

world.setBlockMetadataWithNotify(i, j, k, dir);

 

It should have a flag as that allows you to tell the clients to update with the proper information

ex:

world.setBlockMetadataWithNotify(i, j, k, dir,flag);

- I advise the flag to be 3 (I think this updates the server and client) I don't remember what 4 does. Anyway, by wading through tooltips in eclipse you should eventually figure out what the different values are for the flags.

Posted

Doesn't seem to be working. Here's the entire block's class, no matter what direction I face it's placing the same block.

 

package co.uk.silvania.roads.block;

import co.uk.silvania.roads.CommonProxy;
import co.uk.silvania.roads.Roads;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.util.Facing;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class RBDoubleYellowStripe extends Block {

    public RBDoubleYellowStripe(int id) {
        super(id, Material.rock);
        this.setCreativeTab(Roads.tabRoads);
        this.setHardness(1.0F);
        this.setStepSound(Block.soundStoneFootstep);
    }
    
    @Override
    public int getBlockTextureFromSideAndMetadata (int side, int metadata) {
    	return 0 + 4;
    }
    
    @Override
    public String getTextureFile () {
            return CommonProxy.BLOCK_PNG;
    }
  
    public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving)    {
    	int dir = MathHelper.floor_double((double)((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
    	world.setBlockMetadataWithNotify(i, j, k, dir);
    }
}

 

I'm assuming I've missed something, but I have no idea what...

 

 

It appears you are missing the flag argument in:

world.setBlockMetadataWithNotify(i, j, k, dir);

 

It should have a flag as that allows you to tell the clients to update with the proper information

ex:

world.setBlockMetadataWithNotify(i, j, k, dir,flag);

- I advise the flag to be 3 (I think this updates the server and client) I don't remember what 4 does. Anyway, by wading through tooltips in eclipse you should eventually figure out what the different values are for the flags.

Posted

Doesn't seem to be working. Here's the entire block's class, no matter what direction I face it's placing the same block.

 

package co.uk.silvania.roads.block;

import co.uk.silvania.roads.CommonProxy;
import co.uk.silvania.roads.Roads;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.util.Facing;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class RBDoubleYellowStripe extends Block {

    public RBDoubleYellowStripe(int id) {
        super(id, Material.rock);
        this.setCreativeTab(Roads.tabRoads);
        this.setHardness(1.0F);
        this.setStepSound(Block.soundStoneFootstep);
    }
    
    @Override
    public int getBlockTextureFromSideAndMetadata (int side, int metadata) {
    	return 0 + 4;
    }
    
    @Override
    public String getTextureFile () {
            return CommonProxy.BLOCK_PNG;
    }
  
    public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving)    {
    	int dir = MathHelper.floor_double((double)((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
    	world.setBlockMetadataWithNotify(i, j, k, dir);
    }
}

 

I'm assuming I've missed something, but I have no idea what...

 

 

It appears you are missing the flag argument in:

world.setBlockMetadataWithNotify(i, j, k, dir);

 

It should have a flag as that allows you to tell the clients to update with the proper information

ex:

world.setBlockMetadataWithNotify(i, j, k, dir,flag);

- I advise the flag to be 3 (I think this updates the server and client) I don't remember what 4 does. Anyway, by wading through tooltips in eclipse you should eventually figure out what the different values are for the flags.

 

Well that certainly did something.

Now, when holding my block it's showing texture at tile 4. When I place it, depending on my direction it's placing either air, stone, grass or dirt (ID's 0-3). It is placing the actual vanilla blocks, not just something textured the same (middle-clicking gives me the correct block)

 

 

m(

Show me your texture and subblocks.

 

I'm on 1.4.7 by the way (Mod is mainly for my server),

blocks.png

Edit: haha forgot the picture :P

I wanted to get this method working, then I was going to change that spritesheet to have rotations of each of the blocks which need them.

 

Do you mean the subblocks class file? From what I could see in the tutorial I followed, that was only required if you want each of the subblocks to appear in creative etc, which I don't. Maybe that's where I'm going wrong?

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

Doesn't seem to be working. Here's the entire block's class, no matter what direction I face it's placing the same block.

 

package co.uk.silvania.roads.block;

import co.uk.silvania.roads.CommonProxy;
import co.uk.silvania.roads.Roads;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.util.Facing;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class RBDoubleYellowStripe extends Block {

    public RBDoubleYellowStripe(int id) {
        super(id, Material.rock);
        this.setCreativeTab(Roads.tabRoads);
        this.setHardness(1.0F);
        this.setStepSound(Block.soundStoneFootstep);
    }
    
    @Override
    public int getBlockTextureFromSideAndMetadata (int side, int metadata) {
    	return 0 + 4;
    }
    
    @Override
    public String getTextureFile () {
            return CommonProxy.BLOCK_PNG;
    }
  
    public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving)    {
    	int dir = MathHelper.floor_double((double)((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
    	world.setBlockMetadataWithNotify(i, j, k, dir);
    }
}

 

I'm assuming I've missed something, but I have no idea what...

 

 

It appears you are missing the flag argument in:

world.setBlockMetadataWithNotify(i, j, k, dir);

 

It should have a flag as that allows you to tell the clients to update with the proper information

ex:

world.setBlockMetadataWithNotify(i, j, k, dir,flag);

- I advise the flag to be 3 (I think this updates the server and client) I don't remember what 4 does. Anyway, by wading through tooltips in eclipse you should eventually figure out what the different values are for the flags.

 

Well that certainly did something.

Now, when holding my block it's showing texture at tile 4. When I place it, depending on my direction it's placing either air, stone, grass or dirt (ID's 0-3). It is placing the actual vanilla blocks, not just something textured the same (middle-clicking gives me the correct block)

 

 

m(

Show me your texture and subblocks.

 

I'm on 1.4.7 by the way (Mod is mainly for my server),

blocks.png

Edit: haha forgot the picture :P

I wanted to get this method working, then I was going to change that spritesheet to have rotations of each of the blocks which need them.

 

Do you mean the subblocks class file? From what I could see in the tutorial I followed, that was only required if you want each of the subblocks to appear in creative etc, which I don't. Maybe that's where I'm going wrong?

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

Well, I haven't started programming for 1.4.7 yet, so I can only say what I have seen while modding for 1.5.1. But I would start by looking at the log placement code and copy that for the time being to be sure that your block can be oriented correctly first, then I would move over to looking that the players facing direction afterwards. The important thing is to be sure that you are handling the metadata correctly first then handle the more complicated things in terms of setting the metadata.

 

Anyway, good luck!

Posted

Well, I haven't started programming for 1.4.7 yet, so I can only say what I have seen while modding for 1.5.1. But I would start by looking at the log placement code and copy that for the time being to be sure that your block can be oriented correctly first, then I would move over to looking that the players facing direction afterwards. The important thing is to be sure that you are handling the metadata correctly first then handle the more complicated things in terms of setting the metadata.

 

Anyway, good luck!

Posted

I took that approach before.

 

My first attempt was the log code. However, when a log is on it's side, it only has TWO metadata positions, not 4; for north-south and east-west. Whether your facing north or south, it'll place the same texture. I couldn't quite work out why though.

 

My next approach was to try a piston, and that actually worked, but it was quite buggy. I managed to edit the code enough so I could place in the four directions and it would rotate, and it wouldn't rotate for up and down (which was good). However, the top texture mirrored around the left/right/bottom too, and I couldn't figure out why it did that. Also, the held item looked wrong, because technically the top of the block was actually it's side.

 

I can't understand why it's so complicated though. There must just be a simple method to rotate the top texture, surely? Even in Java itself, something to just rotate the image would be enough.

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

I took that approach before.

 

My first attempt was the log code. However, when a log is on it's side, it only has TWO metadata positions, not 4; for north-south and east-west. Whether your facing north or south, it'll place the same texture. I couldn't quite work out why though.

 

My next approach was to try a piston, and that actually worked, but it was quite buggy. I managed to edit the code enough so I could place in the four directions and it would rotate, and it wouldn't rotate for up and down (which was good). However, the top texture mirrored around the left/right/bottom too, and I couldn't figure out why it did that. Also, the held item looked wrong, because technically the top of the block was actually it's side.

 

I can't understand why it's so complicated though. There must just be a simple method to rotate the top texture, surely? Even in Java itself, something to just rotate the image would be enough.

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

I took that approach before.

 

My first attempt was the log code. However, when a log is on it's side, it only has TWO metadata positions, not 4; for north-south and east-west. Whether your facing north or south, it'll place the same texture. I couldn't quite work out why though.

 

My next approach was to try a piston, and that actually worked, but it was quite buggy. I managed to edit the code enough so I could place in the four directions and it would rotate, and it wouldn't rotate for up and down (which was good). However, the top texture mirrored around the left/right/bottom too, and I couldn't figure out why it did that. Also, the held item looked wrong, because technically the top of the block was actually it's side.

 

I can't understand why it's so complicated though. There must just be a simple method to rotate the top texture, surely? Even in Java itself, something to just rotate the image would be enough.

 

I do not wish to offend, but you don't seem to understand the switch statement that the log code has within. It checks for all possible cases 0-5, each is specified to a face, and in doing so sets metadata according to the case. 0 and 1 are up and down, 2 and 3 are north and south, 4 and 5 are east and west. (once again, I would like to mention that the version of code I am using is 1.5.1 and the log code could have very well changed in the transition)

 

Now, the log only needs to orient itself along 3 different axes where your block cares about the 4 or 6 potential directions. You can set the metadata according to the face that the player clicks on to place the block, that is what the log code is doing.

 

like I said, you should handle how you want your block to handle the metadata before the placement mechanism, that way you can iron out the bugs better.

 

edit:

I feel that I need to establish my last statement more.

I feel that you should test how your textures react to block metadata by setting the same metadata for each block as it is placed, this proves to you that the texture rendering code will handle proper metadata first. Setting the metadata with a placement handling code would be after you know that your metadata handling is correct (for example, if you want your block to face north, set 2 for the metadata, and have your texture rendering code handle facing the block north when metadata = 2 and so on.

Posted

I took that approach before.

 

My first attempt was the log code. However, when a log is on it's side, it only has TWO metadata positions, not 4; for north-south and east-west. Whether your facing north or south, it'll place the same texture. I couldn't quite work out why though.

 

My next approach was to try a piston, and that actually worked, but it was quite buggy. I managed to edit the code enough so I could place in the four directions and it would rotate, and it wouldn't rotate for up and down (which was good). However, the top texture mirrored around the left/right/bottom too, and I couldn't figure out why it did that. Also, the held item looked wrong, because technically the top of the block was actually it's side.

 

I can't understand why it's so complicated though. There must just be a simple method to rotate the top texture, surely? Even in Java itself, something to just rotate the image would be enough.

 

I do not wish to offend, but you don't seem to understand the switch statement that the log code has within. It checks for all possible cases 0-5, each is specified to a face, and in doing so sets metadata according to the case. 0 and 1 are up and down, 2 and 3 are north and south, 4 and 5 are east and west. (once again, I would like to mention that the version of code I am using is 1.5.1 and the log code could have very well changed in the transition)

 

Now, the log only needs to orient itself along 3 different axes where your block cares about the 4 or 6 potential directions. You can set the metadata according to the face that the player clicks on to place the block, that is what the log code is doing.

 

like I said, you should handle how you want your block to handle the metadata before the placement mechanism, that way you can iron out the bugs better.

 

edit:

I feel that I need to establish my last statement more.

I feel that you should test how your textures react to block metadata by setting the same metadata for each block as it is placed, this proves to you that the texture rendering code will handle proper metadata first. Setting the metadata with a placement handling code would be after you know that your metadata handling is correct (for example, if you want your block to face north, set 2 for the metadata, and have your texture rendering code handle facing the block north when metadata = 2 and so on.

Posted

No offence taken. I admit my Java knowledge is rather limited, but I'm a very hands-on learner and the best way for me to learn is simply trial and error. If I tried to read a book on Java, I'd get bored and give up after about 3 pages of trying to make Hello World, so things like what you just said are exactly what I need to help me learn.

 

However, I do know that when it boils down to it, that solution would be no different to my Piston one, because it's still just a block hacked to be on it's side. I know there must be something with that I can do, it's just a case of working it out. The metadata thing was just a totally different approach at it really :P

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

No offence taken. I admit my Java knowledge is rather limited, but I'm a very hands-on learner and the best way for me to learn is simply trial and error. If I tried to read a book on Java, I'd get bored and give up after about 3 pages of trying to make Hello World, so things like what you just said are exactly what I need to help me learn.

 

However, I do know that when it boils down to it, that solution would be no different to my Piston one, because it's still just a block hacked to be on it's side. I know there must be something with that I can do, it's just a case of working it out. The metadata thing was just a totally different approach at it really :P

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

How are you storing the data that controls the orientation of your block then?

 

Do you have the texture rendering code handling each possible wanted orientation of the block? If not, then this would be a good first step.

 

If you do not mind sharing it, I would like to see how you are handling block orientation.

Posted

How are you storing the data that controls the orientation of your block then?

 

Do you have the texture rendering code handling each possible wanted orientation of the block? If not, then this would be a good first step.

 

If you do not mind sharing it, I would like to see how you are handling block orientation.

Posted

package co.uk.silvania.roads.block;

import co.uk.silvania.roads.CommonProxy;
import co.uk.silvania.roads.Roads;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.Facing;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class RBDoubleYellowStripe extends Block
{
    public RBDoubleYellowStripe(int id) {
        super(id, Material.rock);
        this.setCreativeTab(Roads.tabRoads);
        this.setHardness(1.0F);
        this.setStepSound(Block.soundStoneFootstep);
    }
    
    @Override
    public String getTextureFile () {
            return CommonProxy.BLOCK_PNG;
    }
    
    @SideOnly(Side.CLIENT)
    public int getBlockTextureFromSideAndMetadata(int par1, int par2)
    {
        int var3 = getOrientation(par2);
        return var3 > 5 ? this.blockIndexInTexture : (par1 == var3 ? 
        		(this.blockIndexInTexture + 1 * 1) : (par1 == Facing.faceToSide[var3] ? 1 : 0));
    }

    public int getRenderType()
    {
        return 16;
    }
    
    public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving)
    {
        int var6 = determineOrientation(par1World, par2, par3, par4, (EntityPlayer)par5EntityLiving);
        par1World.setBlockMetadataWithNotify(par2, par3, par4, var6);
    }

    public static int getOrientation(int par0)
    {
        return par0 & 7;
    }

    public static int determineOrientation(World par0World, int par1, int par2, int par3, EntityPlayer par4EntityPlayer)
    {
        int var7 = MathHelper.floor_double((double)(par4EntityPlayer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
        return var7 == 0 ? 2 : (var7 == 1 ? 5 : (var7 == 2 ? 3 : (var7 == 3 ? 4 : 0)));
    }
}

 

That's the whole class file of a block which has the buggy rotation on.

The code I got, I managed to work out from piston. What I did was copied the whole piston code, and commented things out line by line to see what was important, and what wasn't. The code there is what was left at the end, everything "important"

(Personally, I see why it's all required except getRenderType. I don't know why it's needed, but if I comment it out it doesn't rotate, so obviously it is :P)

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

package co.uk.silvania.roads.block;

import co.uk.silvania.roads.CommonProxy;
import co.uk.silvania.roads.Roads;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.Facing;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class RBDoubleYellowStripe extends Block
{
    public RBDoubleYellowStripe(int id) {
        super(id, Material.rock);
        this.setCreativeTab(Roads.tabRoads);
        this.setHardness(1.0F);
        this.setStepSound(Block.soundStoneFootstep);
    }
    
    @Override
    public String getTextureFile () {
            return CommonProxy.BLOCK_PNG;
    }
    
    @SideOnly(Side.CLIENT)
    public int getBlockTextureFromSideAndMetadata(int par1, int par2)
    {
        int var3 = getOrientation(par2);
        return var3 > 5 ? this.blockIndexInTexture : (par1 == var3 ? 
        		(this.blockIndexInTexture + 1 * 1) : (par1 == Facing.faceToSide[var3] ? 1 : 0));
    }

    public int getRenderType()
    {
        return 16;
    }
    
    public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving)
    {
        int var6 = determineOrientation(par1World, par2, par3, par4, (EntityPlayer)par5EntityLiving);
        par1World.setBlockMetadataWithNotify(par2, par3, par4, var6);
    }

    public static int getOrientation(int par0)
    {
        return par0 & 7;
    }

    public static int determineOrientation(World par0World, int par1, int par2, int par3, EntityPlayer par4EntityPlayer)
    {
        int var7 = MathHelper.floor_double((double)(par4EntityPlayer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
        return var7 == 0 ? 2 : (var7 == 1 ? 5 : (var7 == 2 ? 3 : (var7 == 3 ? 4 : 0)));
    }
}

 

That's the whole class file of a block which has the buggy rotation on.

The code I got, I managed to work out from piston. What I did was copied the whole piston code, and commented things out line by line to see what was important, and what wasn't. The code there is what was left at the end, everything "important"

(Personally, I see why it's all required except getRenderType. I don't know why it's needed, but if I comment it out it doesn't rotate, so obviously it is :P)

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

Only easy way for is too make tileentity and rotate it's renderer... Hope there are more easy ways.

     

If i helped you, don't forget pressing "Thank You" button. Thanks for your time.

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.