Jump to content

Trying to place extra blocks with metadata... Not going well.


Recommended Posts

Posted

http://pastebin.com/jB1xJe1W is the code in question.

 

What I want to happen, is depending on the blocks rotation, it should place extra "gag blocks" to fill out some gaps. And, for meta 0, this works brilliantly:

51e7dfc78127d.jpg

 

However, when I try and place in another direction, I want the blocks to obviously be placed in the correct direction again. But, the extra blocks always go to the same place, like so:

51e7dff76a729.jpg

 

Probably some sort of really simple mistake, but can anyone point me in the right direction? Sorry for posting something so trivial, but noone on IRC could help :P

width=463 height=200

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

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

It appears to me that you are checking the block metadata as soon as it is placed, then setting the rotation from the players look vector. As the metadata is 0 when you place it, and you use the metadata from when it is placed, this will always be 0.

 

try this instead:

    @Override
    public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityliving, ItemStack itemStack) {
        int meta = world.getBlockMetadata(x, y, z);
            int blockSet = meta / 4;
            int direction = MathHelper.floor_double((double)(entityliving.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
            int newMeta = (blockSet * 4) + direction;
            world.setBlockMetadataWithNotify(x, y, z, newMeta, 0);
            if (newMeta == 0) {
                world.setBlock(x + 1, y, z, Roads.blockGag1.blockID);
                world.setBlock(x + 2, y, z, Roads.blockGag2.blockID);
                world.setBlock(x + 3, y, z, Roads.blockGag3.blockID);
        } else if (newMeta == 1) {
                world.setBlock(x - 1, y, z, Roads.blockGag1.blockID);
                world.setBlock(x - 2, y, z, Roads.blockGag2.blockID);
                world.setBlock(x - 3, y, z, Roads.blockGag3.blockID);
            } else if (newMeta == 2) {
                world.setBlock(x, y, z + 1, Roads.blockGag1.blockID);
                world.setBlock(x, y, z + 2, Roads.blockGag2.blockID);
                world.setBlock(x, y, z + 3, Roads.blockGag3.blockID);
            } else if (newMeta == 3) {
                world.setBlock(x, y, z - 1, Roads.blockGag1.blockID);
                world.setBlock(x, y, z - 2, Roads.blockGag2.blockID);
                world.setBlock(x, y, z - 3, Roads.blockGag3.blockID);
            }
    }

 

no promise but worth a shot.

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.