Jump to content

Recommended Posts

Posted

Hello guys.

 

So, to tell a bit more about what i really want to do here..

I have a few special blocks. These blocks should only be able to be placed, on other special blocks. I tried looking something up in-game, that i could just grab and modify, but i couldn't seem to find something that did the job. Thats why i'm asking if anyone got ideas of how to do this?

 

Thank you :)

Posted

You could use onBlockPlacedBy and check if block under is your block.

 

There might be cases when block is not placed by player (piston) - you can utilize onNeighborBlockChanged.

1.7.10 is no longer supported by forge, you are on your own.

Posted

Thank you for the quick response.

I think you're right about the onBlockPlacedBy. Pistons won't be a problem, as this block needs to be placed by a player..

I'll try this out later, thank you :)

Posted

Pistons won't be a problem, as this block needs to be placed by a player.

 

Is it movable by pistons?  Doesn't matter if the player "must" place it, once in the world and piston-movable, the player can push it around wherever he likes.

 

Anyway, look at blocks like BlockRail and BlockRedstone to see how they insure valid placement.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Arrrh.. I see what you ment.. I'll take a look at that redstone code.. Thank you.

 

Anyway, do any of you, have a suggestion for how i could insure that the block only is placed when a specific block is underneath? OnBlockPlacedBy may work, but do you maybe have a suggestion for that piece of code?

 

Thanks :)

Posted

*cough*

There's an "canPlaceBlockAt" function.  Return false there.

 

That's why I said "look at redstone."

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Hey

So, this is what i got from those files..

It throws no errors, but i'm not able to place the block at all. Not even on the "obsidanBase".

 

    
    @SideOnly(Side.CLIENT)
    public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
    {
        return worldIn.getBlockState(pos).getBlock() == CDBlocks.obsidianBase;
    }

 

What do i need to get the desired effect?

 

Sorry for the stupidity, but i'm new to it.

 

Thanks :)

Posted

Don't use @SideOnly(Side.CLIENT), google why and what it does.

 

I never used method but I belive your return is not valid. You need to offset BlockPos by 1 down.

 

EDIT

Short explanation about SideOnly - method/field marked with it will be totally removed from classLoader (might be bad terminology) on provided side.

CLIENT is the client.jar (not logical thread side)

Using @SideOnly(Side.CLIENT) will make your method never work on dedicated.jar

Using @SideOnly(Side.SERVER) will cause your method to only exist in dedicated.jar

1.7.10 is no longer supported by forge, you are on your own.

Posted

BlockPos is wrapped x/y/z, if I am right (again - I never used that method) the "pos" param in method is the position you want to place the block in, so in probably 100% cases it will be air. You want to check (I think) what is under block, so you need to get Block in BlockPos below the one provided (pos).

1.7.10 is no longer supported by forge, you are on your own.

Posted

Thank you Ernio.

It works now, you were right. I changed the

 

return worldIn.getBlockState(pos).getBlock() == CDBlocks.obsidianBase;

 

to

 

return worldIn.getBlockState(pos.down()).getBlock() == CDBlocks.obsidianBase;

 

Thanks :D

 

 

Posted

Not sure if pos.down() actually offsets by 1 in the downward direction.  Just double check (ctrl-click the function name).

(Admittedly I haven't messed with 1.8 yet)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I Think it does(not sure, not pro), i did click on it and found a place in the code, specifying what position it should look at. Down was the block underneath :)

Posted

pos.down() does NOT permanently lower pos, it tells the value to give the modified value instead.

 

for example

boolean check() {
    BlockPos pos = player.getPosition();
    BlockPos pos2 = pos.down();
    if (pos == pos2) {
        return true;
    } else {
        return false;
    }
}

Will return False. I have been using this quite a bit.

Posted

I Think it does(not sure, not pro), i did click on it and found a place in the code, specifying what position it should look at. Down was the block underneath :)

 

Cool, just wanted to make sure you weren't blindly using the function thinking it did X and it actually did Y.

 

pos.down() does NOT permanently lower pos, it tells the value to give the modified value instead.

 

Which is fine.  It was whether or not it returned a blockPos that was 1 unit away or if it returned the offset necessary to calculate the block 1 away.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

pos.down() does NOT permanently lower pos, it tells the value to give the modified value instead.

 

Which is fine.  It was whether or not it returned a blockPos that was 1 unit away or if it returned the offset necessary to calculate the block 1 away.

Oh I misunderstood you, it returns the block that is 1 or however many, if you specify farther, away.

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.