Created
June 30, 2021 21:51
-
-
Save Lanse505/36ffafc412c6e088bb91a33f2d7b95a2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 com.teamacronymcoders.epos.api.event; | |
import com.teamacronymcoders.epos.api.capability.EposCapabilities; | |
import com.teamacronymcoders.epos.api.character.ICharacterSheet; | |
import com.teamacronymcoders.epos.path.Path; | |
import com.teamacronymcoders.epos.skill.Skill; | |
import net.minecraft.entity.LivingEntity; | |
import net.minecraft.util.ResourceLocation; | |
import net.minecraftforge.common.util.LazyOptional; | |
import net.minecraftforge.event.entity.living.LivingEvent; | |
import net.minecraftforge.eventbus.api.Cancelable; | |
/** | |
* The core event for experience-based interactions. | |
* Currently the main event(s) are: | |
* - {@link EposExperienceEvent.GainExperience.Pre} | |
* - {@link EposExperienceEvent.GainExperience} | |
* | |
* More events may be added later for example for dealing with losing experience. | |
*/ | |
public class EposExperienceEvent extends LivingEvent { | |
private final LazyOptional<ICharacterSheet> sheet; | |
private final Type type; | |
private final ResourceLocation typeObjectId; | |
public EposExperienceEvent(LivingEntity entity, Type type, ResourceLocation typeObjectId) { | |
super(entity); | |
this.sheet = entity.getCapability(EposCapabilities.CHARACTER_SHEET); | |
this.type = type; | |
this.typeObjectId = typeObjectId; | |
} | |
/** | |
* @return Returns the {@link LazyOptional<ICharacterSheet>} of the {@link ICharacterSheet} Capability. | |
*/ | |
public LazyOptional<ICharacterSheet> getSheet() { | |
return sheet; | |
} | |
/** | |
* Returns the type of experienced gained, which will be either {@link Type#PATH} or {@link Type#SKILL} | |
* @return Returns what type of experience was gained. | |
*/ | |
public Type getType() { | |
return type; | |
} | |
/** | |
* Returns the {@link ResourceLocation} id of the type object gaining the experience. | |
* @return Returns the {@link ResourceLocation} id of the type object. | |
*/ | |
public ResourceLocation getTypeObjectId() { | |
return typeObjectId; | |
} | |
/** | |
* The {@link EposExperienceEvent.GainExperience} event used for when an Character is gaining experience in either a {@link Path} or a {@link Skill}. | |
*/ | |
public static class GainExperience extends EposExperienceEvent { | |
private final int experienceAmount; | |
/** | |
* Constructor for the {@link GainExperience.Pre} event. | |
* @param entity The "Character" {@link LivingEntity}. | |
*/ | |
public GainExperience(LivingEntity entity, Type type, ResourceLocation typeObjectId) { | |
super(entity, type, typeObjectId); | |
this.experienceAmount = 0; | |
} | |
/** | |
* Constructor for the main {@link GainExperience} event. | |
* @param entity The "Character" {@link LivingEntity}. | |
* @param experienceAmount The amount of experience being gained. | |
*/ | |
public GainExperience(LivingEntity entity, Type type, ResourceLocation typeObjectId, int experienceAmount) { | |
super(entity, type, typeObjectId); | |
this.experienceAmount = experienceAmount; | |
} | |
/** | |
* @return Returns the Experience Amount being gained. | |
*/ | |
public int getExperienceAmount() { | |
return experienceAmount; | |
} | |
/** | |
* The {@link EposExperienceEvent.GainExperience.Pre} event is what modders should subscribe to to alter the amount of experience gained for {@link Path}(s) and {@link Skill}(s). | |
* This event is also a {@link Cancelable} event, which means that you can cancel it to disallow the "Character" gaining experience. | |
*/ | |
@Cancelable | |
public static class Pre extends GainExperience { | |
private int experienceAmount; | |
public Pre(LivingEntity entity, Type type, ResourceLocation typeObjectId, int experienceAmount) { | |
super(entity, type, typeObjectId); | |
this.experienceAmount = experienceAmount; | |
} | |
/** | |
* @return Returns the current experience amount being gained. | |
*/ | |
@Override | |
public int getExperienceAmount() { | |
return this.experienceAmount; | |
} | |
/** | |
* Sets the current experience amount to X value. | |
* @param experienceAmount The experience amount to override with. | |
*/ | |
public void setExperienceAmount(int experienceAmount) { | |
this.experienceAmount = experienceAmount; | |
} | |
/** | |
* Increments the current experience amount by X value. | |
* @param increment The experience amount to increment the current amount by. | |
*/ | |
public void increaseExperienceAmount(int increment) { | |
this.experienceAmount += increment; | |
} | |
/** | |
* Decrements the current experience amount by X value, with a {@link Math#max(int, int)} check so it never goes below 0. | |
* @param decrement The experience amount to decrement the current amount by. | |
*/ | |
public void decreaseExperienceAmount(int decrement) { | |
this.experienceAmount = Math.max(this.experienceAmount - decrement, 0); | |
} | |
} | |
} | |
public enum Type { | |
PATH, SKILL | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment