Posted March 2, 201312 yr So, I'm using the Event PlayerEvent.HarvestCheck and I'm trying to make the harvested block explode in the player's face. Don't ask why. However, I've run into a bit of a problem. There doesn't seem to be any way whatsoever to actually get the location of a block (to make an explosion) with nothing but the block object itself. Entities have static variables that are very easy to use to get an explosion, but I want the explosion to actually originate from the block itself. @ForgeSubscribe public void blockHarvested(PlayerEvent.HarvestCheck event) { event.entityPlayer.worldObj.createExplosion((Entity)null, event.block.posX., event.block.posY, event.block.posZ, 4.0F, true); } Yep, that's all I have. Obviously it doesnt work - the Block class doesn't have posX, or posY, or posZ. Anyone have any clue how this could be accomplished?
March 2, 201312 yr what if you give the block a tile entity and create the explosion from the tile entity.
March 2, 201312 yr what if you give the block a tile entity and create the explosion from the tile entity. That would be wasteful. Try adding the onBlockAdded(World, x, y, z) method. This is called whenever the block is added to the world (placed, oregen, setBlockWithNotify...). From there, set 3 variables - x, y, and z. Then, in the blockDestroyedByPlayer (or whatever it is called), you can use those variables. Follow my mod(s) here: http://www.minecraftforum.net/topic/1969694-
March 2, 201312 yr If you need to use PlayerEvent.HarvestCheck and really want to make the block explode, not the player, its not possible, not even with a TileEntity (to get the TE you'd need the Coordinates as well). I mean that you create the explosion in the tile entity. Not get the coordinates from the tile entity and then create the explosion in the block
March 2, 201312 yr you have a player entity so you could do something like this maybe player.rayTrace to get the active block? mnn.getNativeLang() != English If I helped you please click on the "thank you" button.
March 3, 201312 yr @Reika: That wouldn't work, because there is only one instance of each block. So if you mined a block it would always make the block explode, that was placed last. If you need to use PlayerEvent.HarvestCheck and really want to make the block explode, not the player, its not possible, not even with a TileEntity (to get the TE you'd need the Coordinates as well). Are you sure? I have had my blocks have variables store internal data (like "int dropmeta") which was unique to each block. Follow my mod(s) here: http://www.minecraftforum.net/topic/1969694-
March 3, 201312 yr @ Are you sure? I have had my blocks have variables store internal data (like "int dropmeta") which was unique to each block. Yes, I am sure. If you used TileEntities thats something else. TileEntities exist multiple times. Only the Block exists once. Then explain how I was able to make the same block have different light values dependent on its metadata (multiple values in the world at once) - using vanilla code - and no Tile Entities... Follow my mod(s) here: http://www.minecraftforum.net/topic/1969694-
March 3, 201312 yr You already gave the answer: Metadata. But light value is not metadata-sensitive. It, of all things, should be "static". Follow my mod(s) here: http://www.minecraftforum.net/topic/1969694-
March 3, 201312 yr couldn't one do the explosion in front of the player, based on his location and the way he is facing? If you guys dont get it.. then well ya.. try harder...
March 3, 201312 yr couldn't one do the explosion in front of the player, based on his location and the way he is facing? I wrote possible solution quite time ago, it does exactly what you're saying: you have a player entity so you could do something like this maybe player.rayTrace to get the active block? mnn.getNativeLang() != English If I helped you please click on the "thank you" button.
March 3, 201312 yr This option is the easiest: use the player.getLook(1.0F); to obtain the normalized vector the player is heading. Then get his position, add this vector and make an explosion at these coordinates - exactly 1 meter in front of the player. My other idea is to use Minecraft.objectMouseOver object to obtain the coordinates of the block the player is currently looking at. If during the event call objectMouseOver is already updated ( so that there's no block being destroyed there ), just monitor this variable and store the coordinates somewhere. Just my few cents.
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.