Created
June 4, 2016 01:20
-
-
Save kvverti/14d5050414483acf6a1189663a9b98e7 to your computer and use it in GitHub Desktop.
Current non-server-friendly workaround
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package kvverti.enim.entity; | |
/* imports... */ | |
/** Utility class for working with Entitys and TileEntitys. */ | |
public final class Entities { | |
/* methods... */ | |
public static class TickEventHandler { | |
public static final TickEventHandler INSTANCE = new TickEventHandler(); | |
private static final WeakHashMap<Entity, IntCounter> entityCounters = new WeakHashMap<>(); | |
private static final WeakHashMap<TileEntity, IntCounter> tileCounters = new WeakHashMap<>(); | |
private static final WeakHashMap<Entity, IntCounter> jumpCounters = new WeakHashMap<>(); | |
private byte slow = 0; | |
private TickEventHandler() { } | |
@SubscribeEvent //Increment every world tick. Event is sent only by the server :( | |
public void onWorldTick(WorldTickEvent event) { | |
if(event.phase == Phase.START && ++slow % 3 == 0) { | |
entityCounters.values().forEach(IntCounter::preIncrement); | |
tileCounters.values().forEach(IntCounter::preIncrement); | |
jumpCounters.values().stream() | |
.filter(counter -> counter.get() >= 0) | |
.forEach(IntCounter::preIncrement); | |
} | |
} | |
@SubscribeEvent //Event is sent only by the server :( | |
public void onLivingJump(LivingJumpEvent event) { | |
jumpCounters.computeIfAbsent(event.entityLiving, e -> new IntCounter()).reset(); | |
} | |
/* getters, etc... */ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment