Jump to content

[Solved]canplaceblock at "method"


Shanedublin

Recommended Posts

I have an Item that places blocks when you right click and it almost works' except that it is placing the blocks like you could place a torch. Ex: when you right click right under you it will place the block, then the block will push you out of the way.  I am having a hard time finding the method that is for block placement and not item placement.    If anyone could point me in the right direction I'd be grateful. 

Link to comment
Share on other sites

if i understand correctly, you want it to work like a normal block? meaning, instead of it placing the block down and pushing you out, it shouldn't be placed at all unless you move out of the way?

 

anyway, just take a look at ItemBlock.class. you'll probably find what you want there

Link to comment
Share on other sites

I've looked in that class And I see the onItemUse Method , the description says it's for items and not for blocks.  And I see the canPlaceItemBlockOnSide method and that one isn't quite working... It's checking for for a player that is one block lower than the player is. I'll try adding some +1s some where to seed if I can get it to work.  Thanks for your help.

Link to comment
Share on other sites

I figured it out.. when I was checking where to place the block I was increment the (x,y,z) location twice.  I end up using a combination of the onItemUse and the canPlaceItemBlockAt method.  There is probably some easier way to do it, but it works so I wont touch it for a while.

 

When In doubt print all the vars!

Link to comment
Share on other sites

if you actually read and understood the code, you'd know it's for blocks. almost all the vanilla blocks use that class. if you wanna make sure what you made is clean and if you wanna understand better how vanilla mc places its blocks down, here are some things you can do:

 

if you're patient and thorough enough, start at clickMouse(int par1) in Minecraft.class. follow and understand the code until you reach the point where it tries to use an item (or place a block down). it might take a while, but you'd get a pretty good understanding of how blocks are placed after you do that.

 

or you can try making a new block for testing. just a plain basic one and then create your own item for it that extends ItemBlock (doesn't have to be a subclass of ItemBlock if you know what you're doing). then play around with both your item class and your block class to see how they work together. canPlaceItemBlockAt is probably not working for you because you're probably already doing something else that's messing it up. which is why i suggest making a new block for testing (something clean).

 

of course you can just stick with what you have since you say it's working already, but then i doubt you really understand why it's working. it could help loads in the future if you really understand what's happening

Link to comment
Share on other sites

if you actually read and understood the code, you'd know it's for blocks. almost all the vanilla blocks use that class. ...

I know that that class is for blocks, that is why i used it. I have an Item that places blocks when you right click on a surface.  I know why it wasn't working. 

 

 

... if you're patient and thorough enough, start at clickMouse(int par1) in Minecraft.class. follow and understand the code until you reach the point where it tries to use an item (or place a block down). it might take a while, but you'd get a pretty good understanding of how blocks are placed after you do that. ...

 

I didn't know where clicks where initially handled thanks for pointing that out.

 

 

 

 

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.