Jump to content

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


Recommended Posts

Posted

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?

Posted (edited)
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
Posted (edited)
58 minutes ago, diesieben07 said:

Yes, that is correct. getEntitiesWithinAABB should do what you need.

Alright thanks for the running start. I will give it a go. Appreciate it.

Edited by HalestormXV
Posted (edited)

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
Posted
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?

Posted (edited)
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

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

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

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