Jump to content

Recommended Posts

Posted

Is there any easy way to check if a given block can stand on its own? For example, buttons can't, wall signs can't (but standing signs can), levers can't, etc. I can't use the isNormalCube() because some blocks aren't opaque but can still stand on their own. I'd rather not have to compile a list of blocks that can or can't manually, so if there's some easier way I'm missing, can someone please let me know?

 

Right now, I'm getting the item equivalent, then using onItemUse to simulate the nearest player placing it on the ground nearby, then checking its return value...but that's very hacky, and it still doesn't work for standing signs.

Whatever Minecraft needs, it is most likely not yet another tool tier.

Posted

All you need is:

 

public boolean canPlaceBlockAt(World world, int x, int y, int z)

and

public void onNeighborBlockChange(World world, int x, int y, int z, Block block)

 

Both methods can be found in the Block class, there is no reason to do it through an Item class

Posted

Hm. For some reason, I didn't think the BlockButton class overrode the canPlaceBlockAt method properly, though it seems it does.

 

But that leads to my next question. Keeping in mind I'm getting the blocks from an ItemStack using Block.getBlockFromItem(), for those blocks which must have a certain metadata to be placed in an area, what's the best way to figure out what that metadata should be? For example, if it's a button, would I need to check every surrounding side to see which are solid? Also, it seems that some items don't work properly with that method; if I try something like Block.getBlockFromItem(Items.sign), it actually returns Block.air as though there's no such item as Items.sign. How can I make sure to get the proper block from an ItemStack?

Whatever Minecraft needs, it is most likely not yet another tool tier.

Posted

if I try something like Block.getBlockFromItem(Items.sign), it actually returns Block.air as though there's no such item as Items.sign. How can I make sure to get the proper block from an ItemStack?

Some items place entities in the world rather than blocks. I know that paintings and item-frames are entities. I haven't worked with signs, but their text suggests they may be too.

 

When you ask about a "given block", are you asking about a block archetype, or are you asking about an instance (the block currently at a particular position)?

 

I suggest that you put a break point in onNeighborBlockChange, run in the debugger, and start breaking the blocks that interest you. Find out how they decide to drop when support breaks. Tell us what you discover.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

Signs are blocks with a TileEntity.  They are specifically Blocks 63 and 68 (minecraft:standing_sign and minecraft:wall_sign).

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

Hm. For some reason, I didn't think the BlockButton class overrode the canPlaceBlockAt method properly, though it seems it does.

 

But that leads to my next question. Keeping in mind I'm getting the blocks from an ItemStack using Block.getBlockFromItem(), for those blocks which must have a certain metadata to be placed in an area, what's the best way to figure out what that metadata should be? For example, if it's a button, would I need to check every surrounding side to see which are solid? Also, it seems that some items don't work properly with that method; if I try something like Block.getBlockFromItem(Items.sign), it actually returns Block.air as though there's no such item as Items.sign. How can I make sure to get the proper block from an ItemStack?

 

I think the canPlaceBlockAt() method should contain the logic to check whether a neighboring block is required and present. Then when you actually place it, it will convert to the right metadata. You shouldn't have to know the metadata to determine if it a standalone block.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

if I try something like Block.getBlockFromItem(Items.sign), it actually returns Block.air as though there's no such item as Items.sign. How can I make sure to get the proper block from an ItemStack?

Some items place entities in the world rather than blocks. I know that paintings and item-frames are entities. I haven't worked with signs, but their text suggests they may be too.

 

When you ask about a "given block", are you asking about a block archetype, or are you asking about an instance (the block currently at a particular position)?

 

I suggest that you put a break point in onNeighborBlockChange, run in the debugger, and start breaking the blocks that interest you. Find out how they decide to drop when support breaks. Tell us what you discover.

I can work with either the block singleton or the class itself; either is fine, I'd think. It just has to be the appropriate one. Signs are in fact blocks with tile entities. Two different types of blocks, actually--wall and standing signs--which may be part of the problem here, but it doesn't help me solve the issue.

 

Hm. For some reason, I didn't think the BlockButton class overrode the canPlaceBlockAt method properly, though it seems it does.

 

But that leads to my next question. Keeping in mind I'm getting the blocks from an ItemStack using Block.getBlockFromItem(), for those blocks which must have a certain metadata to be placed in an area, what's the best way to figure out what that metadata should be? For example, if it's a button, would I need to check every surrounding side to see which are solid? Also, it seems that some items don't work properly with that method; if I try something like Block.getBlockFromItem(Items.sign), it actually returns Block.air as though there's no such item as Items.sign. How can I make sure to get the proper block from an ItemStack?

 

I think the canPlaceBlockAt() method should contain the logic to check whether a neighboring block is required and present. Then when you actually place it, it will convert to the right metadata. You shouldn't have to know the metadata to determine if it a standalone block.

 

That doesn't work. If I try to have a tile entity place a block like this, it just sets the metadata to 0 unless I manually specify a value. For example, using World#setBlock with a wall sign just has it floating in midair, even though there's a valid block on one side for it to attach to. (Note: the block won't always be in the same direction, or even there at all, which is why I need to know the valid metadata.)

 

It's looking more and more like I need to do my own checking and check all 6 sides, though it seems like that would be specific to signs only. I don't have any access to my own laptop right now due to hardware failure, but I'm worried if there are any other similar blocks I'd have to manually handle like this...and then with other mods' blocks, keeping compatibility sounds like a potential nightmare.

 

But if I have to do it, I have to, I guess.

Whatever Minecraft needs, it is most likely not yet another tool tier.

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.