-
Notifications
You must be signed in to change notification settings - Fork 3
Pathos
Gaspunk bundles a pseudo-library called Pathos. What this means is that it is technically a part of the mod but everything is setup to allow a painless split in case another mod unrelated to gaspunk would need it.
The goal of Pathos is to provide a simple API to add sicknesses. A sickness is basically a potion effect with no predefined duration and a variable severity.
Like gases, sicknesses have their own registry, so you can register your own sicknesses through the event:
@SubscribeEvent
public void addSicknesses(RegistryEvent.Register<ISickness> event) {
event.getRegistry().register(new MySickness().setRegistryName(YourMod.MOD_ID, "cancer"));
}
This also means that the ObjectHolder
annotation is compatible with sicknesses.
The class needs to implement ISickness, which has a single required method, performEffect
. This method is the equivalent to the eponymous method in the Potion
class. It is called each tick when an entity is afflicted by your sickness, with a reference to the entity and the carried SicknessEffect
. This effect gives you access to various informations like the number of ticks since the effect was contracted or the current severity of the effect. The method returns true if a real effect was performed. What can be considered a real effect is left to the implementation. In essence, a return value of true
resets the ticksSinceLastPerform
timer on the effect. This timer is mostly intended as a convenience (it is not used anywhere by default) though it should remain meaningful as other mechanisms could use it.
To afflict a living entity with a sickness, simply create a new SicknessEffect
with the desired ISickness
and severity and add it to the entity's ISicknessHandler
capability.
Ex:
@CapabilityInject(ISicknessHandler.class)
public static Capability<ISicknessHandler> CAPABILITY_SICKNESS;
public void addCancerToEntity(EntityLivingBase entity) {
ISicknessHandler handler = entity.getCapability(CAPABILITY_SICKNESS, null);
SicknessEffect effect = new SicknessEffect(ModSicknesses.CANCER, 0.6f);
handler.addSickness(effect);
}