Jump to content

Adding a potion effect, and removing it in certain situations


Flenix

Recommended Posts

Hey guys,

 

I've had an idea I want to add to the mod I run on my server (which is a collection of small things which don't really need their own mod), but I'm not quite sure how to implement it.

 

Basically, the entire world would be "radiated", and if you're just standing there, you'll get a "Radiation" potion effect, which will slowly kill you, damaing half a heart every 10 seconds or so. It would eventually kill you, and the effect remains for about 30 seconds even after you're "safe".

 

There are two ways to become safe- The first is to wear a full set of special armour which will be included with the mod. The armour will lose durability very slowly, with a set lasting roughly 1 hour. You spawn with a set and it's easy to make.

The second is to be within the radius of an Air Filter, which is a block that makes you safe as long as you're close enough to it.

 

Now, I'm not sure how to implement any of those really- it's not something I've done before. So this thread really has 3 questions:

 

1. How would I make and apply the potion effect? It doesn't need a potion item or anything, it just needs to take effect when the player is "unsafe".

2. How would I make the player safe when wearing armour, and damage that armour? I understand I need a tick handler, but I've got no idea how those work and couldn't find any examples.

3. How would I make the Air Filter block work? Would it be better to just do a simple radius, or clean the chunk it's placed in, or something else? I assume it would require a tick handler, just like the armour... Would it need to be a Tile Entity? (I'd rather it wasn't)

 

If there's a tutorial or an example of any of these that'd be great, if not any advice would be really helpful too. Thanks :)

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Link to comment
Share on other sites

Yes, you would need to set up a tick handler for the server side to manage all of those conditions. There are plenty of tutorials on doing TickHandlers, just make sure it runs on the server (otherwise you get client/server de-syncing and other nasty things).

 

You should probably do something similar to the Beacon, where a small internal timer runs in the TileEntity (except you would be doing it in the TickHandler). This timer would count up once per tick, and once it reaches some arbitrary value (say 40, for a 2 second update cycle), reset it and calculate all of your stuff. That way you don't have to run potentially expensive calculations that you don't need to every single tick.

 

Basically, each time that update fires, you need to:

 

1. Iterate over every player.

2. Discover if they have the armor set, and if so, do nothing.

3. If not, use some kind of iteration to search the nearby blocks in the world for the Air Filter, and if you find it, do nothing.

4. If both of those last conditions were false, (i.e., the player is not safe) add the Radiation effect for 600 ticks (30 seconds) or reset it to 600 if it already is on the player.

 

Since the two "safe" conditions only prevent the radiation from being renewed to 30 seconds, that will give you the 30 second cool-down you want.

 

That's how I would implement that, at least.

 

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.