Jump to content

[1.15.2] Blocking Checking Radius? Effective or Better Way?


HalestormXV

Recommended Posts

Another general question. No real code to go with it just yet. Is it plausible to have a block that Ticks, and it checks the area around it for players, getPos

X+16,

Y+16

Z+16,

X2-16,

Y2-16,

Z2-16

(Or perhaps there is a better way to check around a particular position? Vecs maybe? I haven't done too much with them just yet as i only just picked up 1.15.2 a few days ago after some time off)

 

etc. And if a player enters within that range it will apply a PotionEffect (or even a vanilla effect like MiningFatigue) and then a listener will cancel a breakEvent so long as the player is afflicted with that effect (and some other criteria so it doesn't happen ALL the time a blockBreak occurs)

 

The objective is to have a central block that is generated with some structures and if the player is within the "field" of that block they cannot break any blocks within that field thus protecting the structure. Think Elder Guardian but on a Block Level instead of an Entity Level. OR perhaps the way it should be done if a Block shouldn't/can't achieve this is via a TileEntity that is applied/attached to the Block on creation?

Link to comment
Share on other sites

2 hours ago, diesieben07 said:

A tile entity is what you need here.

Understood, yes as I am browsing the TileEntity class I see it'll need to implement Tickable and will be able to essentially take care of everything. As for gathering players in the area of the TileEntity is there an "effective/preferred/proper" way to do that or pretty much how the Elder Guardian does it would be best? 

 

Essentially a: TECreate -> newAxisAligned for the radius/cuboid -> Tick, get all entities in the AxisAligned -> filter the players -> apply the effect to the players, repeat (minus the TECreate and new Axis of course)

Edited by HalestormXV
Link to comment
Share on other sites

Please someone punch me. Rather than make a new thread as this issue is still the same I think it better and more proper to simply make the post in the same thread. So after the discussion above I understand that this feat need be accomplished via TileEntity.. Not a problem.. I also get that it will use the getEntitiesWithinAABB, since a number of forum searches show a great many of these types of rather simple tasks like checking players around the TileEntity in say a 16 block radius.

 

Mine flat out fails. I am getting a null pointer exception right when my code attempts to do the getEntities. I am CERTAIN it is completely obvious and my general rusty-ness and newness to 1.15.2 is the cause coupled with working on the same piece of code for WAY to long. So please can anyone take a look at this and knock some sense into me as to what I am doing wrong? Specifically line 57 is where the null pointer occurs. 

https://pastebin.com/fcnEAzkk

As an aside, my TileEntity works if i take out the AABB code line and utilize the code starting on line 76 but that is not the proper way to do it and it is essentially an eternal debuff with that method as opposed to a range/radius dependent debuff.

Edited by HalestormXV
Link to comment
Share on other sites

1 hour ago, HalestormXV said:

Specifically line 57 is where the null pointer occurs. 

Have you tried using the debugger to find out why the exception occurs? If it is line 57, the problem is almost certainly that containmentField is null. Perhaps it never get initialized to a value?

Link to comment
Share on other sites

8 hours ago, vemerion said:

Have you tried using the debugger to find out why the exception occurs? If it is line 57, the problem is almost certainly that containmentField is null. Perhaps it never get initialized to a value?

Brain freeze - yeah I should have thought of that. I was incredibly frustrated and totally forgot. Turns out that was exactly the issue and diesieben07 (Sorry if this tags you, it kinda just did it automatically) was spot on.

 

8 hours ago, diesieben07 said:

Don't create the containmentField in setPos. Initialize it on demand in tick.

100% right and corrected the problem. So i thank you. But perhaps this is a stupid question but why? Is setPos not actually being called? I mean i know it is part of ChunkPrimer which is why I used it in the first place being that this particular Block & TE are part of one of my structures that already generate in the world or is Primer's functionality just totally going over my head and is it just infact a "setup" the chunk itself type of class?

 

Edited by HalestormXV
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.