Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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?

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.

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

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.

@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.

@

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...

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...

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.

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.

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.