Jump to content

Minor rotation bug


Flenix

Recommended Posts

Hey guys,

 

I'm very close to finishing my first mod, just rounding off the last few bugs.

 

This is the main real bug left. Most of my blocks are rotatable, and a key factor is the top-facing texture has to rotate. To get that, I did some hacking around with the log and piston code, and managed to do it.

 

HOWEVER, the texture is always facing the wrong way from the player when placed. For example, I have two blocks which make up big letters saying "STOP", but they are placed to appear upside down, like so:

51af8b525ac13.jpg

 

(What's interesting; in my inventory it's correct, in my hand it's not)

 

 

How would I fix this so it's readable on place? Here's my code for the same block shown above:

 

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.client.renderer.texture.IconRegister;
import net.minecraft.entity.EntityLiving;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class RBOP extends Block {

    public RBOP (int id) {
        super(id, Material.rock);
        this.setHardness(1.0F);
	this.setStepSound(Block.soundStoneFootstep);
	this.setCreativeTab(Roads.tabRoads);
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.825F, 1.0F);
    }
       
@SideOnly(Side.CLIENT)
private Icon sides;
@SideOnly(Side.CLIENT)
private Icon top;

public void registerIcons(IconRegister iconRegister) {
        this.top = iconRegister.registerIcon("Roads:TarmacStop1");
        this.sides = iconRegister.registerIcon("Roads:TarmacPlain");
}

    public int getRenderType() {
        return 16;
        }

    public boolean isOpaqueCube() {
    	return false;
        }
        
    public boolean renderAsNormalBlock() {
    	return false;
        }

    @SideOnly(Side.CLIENT)
    public Icon getIcon(int side, int meta) {
        int k = meta;
        if (k == 0 && (side == 1)) {
         	return top;
     	} else if (k == 1 && (side == 1)) {
           	return top;
       	} else if (k == 2 && (side == 1)) {
           	return top;
        } else if (k == 3 && (side == 1)) {
          	return top;
        } else if (k == 4 && (side == 1)) {
           	return top;
        } else if (k == 5 && (side == 1)) {
           	return top;
        }
   		return sides;
    }

    public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving entity, ItemStack item) {
        int l = determineOrientation(par1World, par2, par3, par4, entity);
        par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2);

    }

    public static int determineOrientation(World world, int par1, int par2, int par3, EntityLiving entity) {
        if (MathHelper.abs((float)entity.posX - (float)par1) < 2.0F && MathHelper.abs((float)entity.posZ - (float)par3) < 2.0F) {
            double d0 = entity.posY + 1.82D - (double)entity.yOffset;

            if (d0 - (double)par2 > 2.0D) {
                return 1;
            }

            if ((double)par2 - d0 > 0.0D) {
                return 0;
            }
        }

        int l = MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
        return l == 0 ? 2 : (l == 1 ? 5 : (l == 2 ? 3 : (l == 3 ? 4 : 0)));
    }
}

 

 

Let me know if you need more info,

 

Cheers :)

width=463 height=200

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

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Link to comment
Share on other sites

You could just rotate your Texture

Or (My way of doing this):

    public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving, ItemStack par6ItemStack)
    {
        int l = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
        par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2);
    }

PM's regarding modding questions should belong in the Modder Support sub-forum and won't be answered.

Link to comment
Share on other sites

I'm not sure why you made this a new post when I'm pretty sure it's the same problem you had in http://www.minecraftforge.net/forum/index.php?topic=8862.0 but...

 

You seem to have taken the route of using one texture that you rotate using the renderer by telling the game to render your block as a piston base. This is baffling to me. I'm not even sure how you got your block working as well as it is. You are making this way more complicated than it needs to be.

 

Go look at the BlockBasePressurePlate class. The important method is the setBlockBoundsBasedOnState method. Following that to its helper method you will see that it changes the size of the block based on a set of data you can specify. Specifically, the method setBlockBounds is used. Call this in the constructor of your block and use it to set appropriate bounds for your block. This will can you that nice flat block you seem to be trying to make.

 

Now go back to your old topic and look at the last post I made. When you set your meta data you should use that onBlockPlacedBy because it sets your blocks to face you. This means they face you in your hand, inventory, etc. The meta data ranges from 0-3 depending on which direction you are looking.

 

Now compare your getIcon method to mine. Mine uses 4 different top textures. You should be able to go into your image editor and just rotate the image by 90 degrees at a time so you have 4 images that face 4 directions. Now, your method uses a lot of checks that all return the same icon. That defeats the purpose of making the checks when they all return the same thing.

 

I can (visually) make your block in 30 minutes. You can do it: I believe in you. Stop making it so difficult!

 

EDIT

 

I looked again and you do set block bounds already. But I don't understand them either, since they describe a block that is almost full height instead of a block that is super thin. I really don't understand how you have your block working as it is right now.

Read my thoughts on my summer mod work and tell me what you think!

http://www.minecraftforge.net/forum/index.php/topic,8396.0.html

 

I absolutely love her when she smiles

Link to comment
Share on other sites

I'm not sure why you made this a new post when I'm pretty sure it's the same problem you had in http://www.minecraftforge.net/forum/index.php?topic=8862.0 but...

 

You seem to have taken the route of using one texture that you rotate using the renderer by telling the game to render your block as a piston base. This is baffling to me. I'm not even sure how you got your block working as well as it is. You are making this way more complicated than it needs to be.

 

Go look at the BlockBasePressurePlate class. The important method is the setBlockBoundsBasedOnState method. Following that to its helper method you will see that it changes the size of the block based on a set of data you can specify. Specifically, the method setBlockBounds is used. Call this in the constructor of your block and use it to set appropriate bounds for your block. This will can you that nice flat block you seem to be trying to make.

 

Now go back to your old topic and look at the last post I made. When you set your meta data you should use that onBlockPlacedBy because it sets your blocks to face you. This means they face you in your hand, inventory, etc. The meta data ranges from 0-3 depending on which direction you are looking.

 

Now compare your getIcon method to mine. Mine uses 4 different top textures. You should be able to go into your image editor and just rotate the image by 90 degrees at a time so you have 4 images that face 4 directions. Now, your method uses a lot of checks that all return the same icon. That defeats the purpose of making the checks when they all return the same thing.

 

I can (visually) make your block in 30 minutes. You can do it: I believe in you. Stop making it so difficult!

 

EDIT

 

I looked again and you do set block bounds already. But I don't understand them either, since they describe a block that is almost full height instead of a block that is super thin. I really don't understand how you have your block working as it is right now.

 

Honetly I never saw the last reply on the other thread, I thought it was dead, but that thread was referring to getting rotation working in the first place.

Anyways. I'm not sure why you think I want a flat block... It's the exact height I want it to be, 7/8ths the height of a standard block (so there's a slight step up from this to a full block)

 

Onto the onBlockPlacedBy method; This does not work. It's the very first thing I tried actually. It rotates the entire block, like a pumpkin. Go place a pumpkin 4 directions, and notice the top texture is always facing the same way. That's the issue here; it's the top texture that needs to rotate, hence my hacky piston approach.

 

As for the texture thing, why is using four textures better than one? I just don't understand that, it's 4x the file size of my mod, and if someone wants to add texture pack support it's 4x the work for them to. Surely if there's any way of doing it with a single texture file (which I've almost managed to do), then that's the best thing to do?

At this point I'm not going to make 3 more textures for every single block (There's about 45 that all use this code) - If it comes to no solution, I'll just flip the textures so they're upside down.

 

You could just rotate your Texture

Or (My way of doing this):

    public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving, ItemStack par6ItemStack)
    {
        int l = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
        par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2);
    }

 

As said above, that only rotates the block itself; the top texture will stay facing the same way.

 

width=463 height=200

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

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Link to comment
Share on other sites

Anyone interested, I fixed it now.

 

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.client.renderer.texture.IconRegister;
import net.minecraft.entity.EntityLiving;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class RBOP extends Block {

    public RBOP (int id) {
        super(id, Material.rock);
        this.setHardness(1.0F);
	this.setStepSound(Block.soundStoneFootstep);
	this.setCreativeTab(Roads.tabRoads);
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.825F, 1.0F);
    }
       
@SideOnly(Side.CLIENT)
private Icon sides;
@SideOnly(Side.CLIENT)
private Icon top;

public void registerIcons(IconRegister iconRegister) {
        this.top = iconRegister.registerIcon("Roads:TarmacStop1");
        this.sides = iconRegister.registerIcon("Roads:TarmacPlain");
}

    public int getRenderType() {
        return 16;
        }

    public boolean isOpaqueCube() {
    	return false;
        }
        
    public boolean renderAsNormalBlock() {
    	return false;
        }

    @SideOnly(Side.CLIENT)
    public Icon getIcon(int side, int meta) {
        int k = meta;
        if (k == 0 && (side == 1)) {
         	return top;
     	} else if (k == 1 && (side == 1)) {
           	return top;
       	} else if (k == 2 && (side == 1)) {
           	return top;
        } else if (k == 3 && (side == 1)) {
          	return top;
        } else if (k == 4 && (side == 1)) {
           	return top;
        } else if (k == 5 && (side == 1)) {
           	return top;
        }
   		return sides;
    }

    public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving entity, ItemStack item) {
        int l = determineOrientation(par1World, par2, par3, par4, entity);
        par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2);
    }

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

 

It still renders upside-down in your hand, but it places the right way up, so it's merely a graphical glitch now.

width=463 height=200

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

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Link to comment
Share on other sites

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.