Jump to content

When Placing a Block, Assign it an ID


GeoDoX

Recommended Posts

What Im trying to do is after a player places a block, the block, located by its XYZ coords, is given an ID(int), aswell as who placed it(playername).

 

Im sure I need to use the BlockPlaceEvent to do this, but Im not sure how I would give it an ID, and who placed it.

 

Then after that when the block is broken, it needs to check the player's name that broke it and compare it to who placed it, if they match, the block is broken, if not, the block isnt.

 

Any ideas how to do this?

 

PS: This needs to be done for EVERY block placed.

Link to comment
Share on other sites

unfortunately, forge standard doesnt have a OnBlockPlaced Event, yet you are lucky because i made those events a couple of weeks ago (just didnt do a pull request yet) so if you're interrested on those events, tell me i can send you the modified classes needed to use those events. also, for putting the "owner of a block, youll need to use a tile Entity. Look it up on the wiki tutorial its very well made and explain everything needed to be done.

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

You're looking for PlayerInteractEvent, but wouldn't it be better to do it with a tile entity and NBT?

Protip: try and find answers yourself before asking on the forum.

It's pretty likely that there is an answer.

 

Was I helpful? Give me a thank you!

 

 

width=635 height=903http://bit.ly/HZ03zy[/img]

 

 

Tired of waiting for mods to port to bukkit?

use BukkitForge! (now with a working version of WorldEdit!)

Link to comment
Share on other sites

keepcalm, there are problems when you consider playerInteractEvent as a blockplaceevent or a block removeevent that cannot be fixed without creating the proper event by modifying the src. for exemple, if you cancel ALL right click block (like you were canceling all blockPlaced) you can still place blocks by spaming right click.

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

If you're trying to do it for every vanilla block then you're going to have to modify base classes.

 

It's possible (and rather simple) to do this on your own blocks just by checking against TileEntity data with RemoveBlockByPlayer, setting the placer during OnBlockPlacedBy, and upping the resistance to make sure it's not damaged during explosions.

Link to comment
Share on other sites

if you need to do this for every vanilla block instead of changing every base class you could keep track of who owns what block in a data structure and cancel inapropriate action by tchecking in that datastructure if the owner of the block is the same as the one breaking  it. you will need a super efficient data structure thought (like the nbt)

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

A sorted list of block locations per player might work, with simple binary search. Not the most efficient, but quick to implement and simple to use.

 

Either way, from my knowledge, it's not possible to do this without quite a few Forge additions. And all mods having to change the way they set blocks.

Link to comment
Share on other sites

he'll need at least a onBlockPlacedEvent, who would add the coord and owner to the database, then he could use the PlayerInteractEvent to detect action.leftclickblock and cancel it if the owner of the owner of the block is not the same as the breaker (tcheck that by asking the database, wtv the kind of structure used) take note that youll need a faster response time depending on how many players are playing. more player mean it need to be faster. (at least fast enough to not create lag)

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

For it to be effective the event would need to be fired including the Entity that caused the place event, which would mean that a modified setBlock/completely new method is required and all vanilla/mod files where a block is placed would have to use the new method and signature.

 

Am I making sense or am I completely off the mark here?

Link to comment
Share on other sites

Any code on the direction of where to go, I kinda got confused after reading all of that :P

 

And how would I store all the data? In an ArrayList? And when a block is successfully broken I want it to be removed from the list...

 

No, research Tile entities. This is all you need.

 

No need to be rude about it, especially when you had no input on it in the first place.

Link to comment
Share on other sites

Any code on the direction of where to go, I kinda got confused after reading all of that :P

 

And how would I store all the data? In an ArrayList? And when a block is successfully broken I want it to be removed from the list...

 

No, research Tile entities. This is all you need.

 

No need to be rude about it, especially when you had no input on it in the first place.

Who was being rude? I was trying to help you by putting you in the right direction. If you research what tile entities are, you will see it is exactly what you need.

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.