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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello?? Am I not gonna receive any assistance from anybody??? I still need help here!!
    • Hi Everyone, I'm new to the sub but needed some help figuring out a lot of the server tick issues and errors I have been getting. I run a small 1-3 player 1.19.2 forge minecraft server with around 215 or so mods (mix of QoL, server sided, performance, and client/ui mods). I run a Ryzen 5600x, 48gb of ram, and an Asus tuf 1650s. Current jvm allocation is for 12gb (overkill I know, but thought it would require so for the amount of mods I have). Typically my server had ran <20ms avg. tick, but currently has been going up closer and closer to 50ms, with sky rockets to >100ms up to around even 700ms at times. I assume it has to do with an entity ticking loop or something of the sort butn my knowledge of servers ands mods is very inept. Here is my mod list: https://mclo.gs/Yh3uW9J Here is the link to my latest.log: https://mclo.gs/uXtekkO In addition here is my debug.log: https://mclo.gs/f4zMNQQ I see a lot of errors in both logs, but cannot figure out for the life of me what mod(s) are causing them. If there is anymore info that I can provide that can help me sort this out, I am more than willing to provide it. Just want my server to run nicely lol. edit: i know the current logs show missing content. those are mods that i have already deemed not needed/not working well/as intended so they have been removed. edit #2: i have already tried using spark profiler to find the mod that is using the most resources, but to no avail. here is the link to the latest profiler i ran: https://spark.lucko.me/dIAmpPkGdo Thank you in advance!
    • i recheck the kapenjoe tutorial from another stance and actually manage to make custom trades for the villagers and the trader    seems like the wanderer has 64 normal trades and 6 especial  ### addCustomWandererTrades( generic 64) ### addCustomWandererTrades( rare    6)   ################################################## the problem is that the 3 custome trades i add rarely gets loaded in the wanderer offered item list but are there  if i delete the list whit generic.clear() before adding mi things then only mi things get loaded an a ice cube i dont know where is coming              generic.add((trader, rand) -> new MerchantOffer(                 new ItemStack(Items.EMERALD, 6),                 new ItemStack(BlockInit.POTTED_BLUE_HERB.get().asItem(), 2),                 2, 10, 0.02F)         ); it dont seems to be a weight variable to increase the possibility of mi custom trades ######################### what i want is  to increase the chance of mi custome trades to be vissible  how can i do that....          
    • For Example, Simply swords is a mod that i think looks cool. I've noticed I can use it in a world but friends can't join. Error is "Registry remapping failed: null". Is there a way to fix this or is it not possible to use with friends?
    • You could try using spark (https://www.curseforge.com/minecraft/mc-mods/spark) to see if it gives you any other insight into what is making ticks take too long, perhaps it's a combination of mods. If it's simply the yuushya mod processing that is causing it to hang, the only solution would be removing that mod, or possibly updating/downgrading to a version that doesn't make ticks take too long.
  • Topics

×
×
  • Create New...

Important Information

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