I've been trying for hours to get a custom status effect to deal damage to a player that has the custom status effect for every 25 seconds.
To no avail, I can't seem to get it to work.
It's suppose to deal half a heart of damage every 500 ticks(25 seconds) but every 500 ticks, it goes back to 0 and starts again as intended but no damage is dealt.
Sometimes it works but sometimes it doesn't and it really confuses me a lot.
public class SomethingEventHandler {
private Integer minorCutTimer = new Integer(0);
@SubscribeEvent
public void onEntityUpdate(LivingUpdateEvent event)
{
if (event.entityLiving.isPotionActive(Effects.MinorCut))
{
One other *tiny* thing, it makes no difference in the end (both are optimized just as well) but another way you can increment is with:
minorCutTimer++;
I find it more readable so that's how I do it, but this is entirely personal choice. += is just as good for addition, but I like to use "++" since it's easier to spot at a glance, therefore realizing that this method uses a counter.
Hi,
I've been trying for hours to get a custom status effect to deal damage to a player that has the custom status effect for every 25 seconds.
To no avail, I can't seem to get it to work.
It's suppose to deal half a heart of damage every 500 ticks(25 seconds) but every 500 ticks, it goes back to 0 and starts again as intended but no damage is dealt.
Sometimes it works but sometimes it doesn't and it really confuses me a lot.
public class SomethingEventHandler {
private Integer minorCutTimer = new Integer(0);
@SubscribeEvent
public void onEntityUpdate(LivingUpdateEvent event)
{
if (event.entityLiving.isPotionActive(Effects.MinorCut))
{
minorCutTimer += 1;
System.out.println(minorCutTimer);
if(minorCutTimer == 500)
{
event.entityLiving.attackEntityFrom(DamageSource.generic, 1);
System.out.println("hurt");
minorCutTimer = 0;
}
if (event.entityLiving.getActivePotionEffect(Effects.MinorCut).getDuration()==0)
{
event.entityLiving.removePotionEffect(Effects.MinorCut.getId());
return;
}
}
}
Yeh sure
Argh! My eyes!
Why are you using the Integer object instead of just a regular "int" primitive? It's unnecessary and expensive. And difficult to read.
Apart from that, not sure sorry. Maybe it needs to run on the server side?
Oh uh, sorry about that. I was trying everything in order to make it work. I had used regular int primitives at first but I changed it to that
when I wanted to increment a int by one so I read something about it and followed it.
I have changed the ints to what I was using at first.
And thanks, I'll try out the server side thing you've suggested and I'll report back.
Yeh sure
It worked! It seems to deal half a heart of damage every 25 seconds like it should.
I can't thank you enough for helping out with this problem. Thank you very much.
This is what I used:
public class SomethingEventHandler {
private int minorCutTimer = 0;
@SubscribeEvent
public void onEntityUpdate(LivingUpdateEvent event)
{
if(!event.entityLiving.worldObj.isRemote) {
if (event.entityLiving.isPotionActive(Effects.MinorCut))
{
minorCutTimer += 1;
System.out.println(minorCutTimer);
if(minorCutTimer == 500)
{
event.entityLiving.attackEntityFrom(DamageSource.generic, 1);
System.out.println("hurt");
minorCutTimer = 0;
}
if (event.entityLiving.getActivePotionEffect(Effects.MinorCut).getDuration()==0)
{
event.entityLiving.removePotionEffect(Effects.MinorCut.getId());
return;
}
}
}
}
Yeh sure
No problem
One other *tiny* thing, it makes no difference in the end (both are optimized just as well) but another way you can increment is with:
I find it more readable so that's how I do it, but this is entirely personal choice. += is just as good for addition, but I like to use "++" since it's easier to spot at a glance, therefore realizing that this method uses a counter.