Skip to content

Instantly share code, notes, and snippets.

@Lanse505
Created June 30, 2021 23:52
Show Gist options
  • Save Lanse505/95f30907a4a7c5247da2365d39d14f7e to your computer and use it in GitHub Desktop.
Save Lanse505/95f30907a4a7c5247da2365d39d14f7e to your computer and use it in GitHub Desktop.
package com.teamacronymcoders.epos.api.event;
import com.teamacronymcoders.epos.api.capability.EposCapabilities;
import com.teamacronymcoders.epos.api.character.ICharacterSheet;
import com.teamacronymcoders.epos.api.event.enums.EposEventType;
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;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* The core event for experience-based interactions.
* Currently the main event(s) are:
* - {@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;
@Nonnull
private final EposEventType type;
@Nullable
private final ResourceLocation typeObjectId;
public EposExperienceEvent(LivingEntity entity, @Nonnull EposEventType type, @Nullable 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 EposEventType#CHARACTER}, {@link EposEventType#PATH} or {@link EposEventType#SKILL}
* @return Returns what type of experience was gained.
*/
@Nonnull
public EposEventType 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.
*/
@Nullable
public ResourceLocation getTypeObjectId() {
return typeObjectId;
}
/**
* The {@link EposExperienceEvent.GainExperience} event used for when an Character is gaining either {@link com.teamacronymcoders.epos.api.character.CharacterSheet}, {@link Path} or {@link Skill} experience.
* 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 GainExperience extends EposExperienceEvent {
private int experienceAmount;
/**
* 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, EposEventType type, ResourceLocation typeObjectId, int experienceAmount) {
super(entity, type, typeObjectId);
this.experienceAmount = experienceAmount;
}
/**
* @return Returns the Experience Amount being gained.
*/
public int getExperienceAmount() {
return 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);
}
}
}
package com.teamacronymcoders.epos.api.event;
import com.teamacronymcoders.epos.api.event.enums.EposEventType;
import com.teamacronymcoders.epos.api.event.enums.EposGrantOperator;
import com.teamacronymcoders.epos.api.event.enums.EposGrantType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.eventbus.api.Cancelable;
/**
* The core event for level-based interactions.
* Currently the main event(s) are:
* - {@link EposGrantEvent.Path}
* - {@link EposGrantEvent.Skill}
* - {@link EposGrantEvent.Feat}
*
* More events may be added later.
*/
public class EposGrantEvent extends LivingEvent {
private final EposGrantType type;
private final EposGrantOperator operator;
private final ResourceLocation typeObjectId;
public EposGrantEvent(LivingEntity entity, EposGrantType type, EposGrantOperator operator, ResourceLocation typeObjectId) {
super(entity);
this.type = type;
this.operator = operator;
this.typeObjectId = typeObjectId;
}
/**
* Returns the type of experienced gained, which will be either {@link EposEventType#CHARACTER}, {@link EposEventType#PATH} or {@link EposEventType#SKILL}
* @return Returns what type of experience was gained.
*/
public EposGrantType getType() {
return type;
}
/**
* Returns the Operator setting of either {@link EposGrantOperator#UNLOCK} or {@link EposGrantOperator#LOCK} which dictates if the event is used to unlock or lock.
* @return Returns the {@link EposGrantOperator} type for the Event.
*/
public EposGrantOperator getOperator() {
return operator;
}
/**
* 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 EposGrantEvent.Path} event is fired when Unlocking or Locking a {@link com.teamacronymcoders.epos.path.Path} on the Character.
* This event is also a {@link Cancelable} event, which means that you can cancel it to disallow the "Character" unlocking or locking a specific {@link com.teamacronymcoders.epos.path.Path}.
*/
@Cancelable
public static class Path extends EposGrantEvent {
public Path(LivingEntity entity, EposGrantOperator operator, ResourceLocation typeObjectId) {
super(entity, EposGrantType.PATH, operator, typeObjectId);
}
}
/**
* The {@link EposGrantEvent.Skill} event is fired when Unlocking or Locking a {@link com.teamacronymcoders.epos.skill.Skill} on the Character.
* This event is also a {@link Cancelable} event, which means that you can cancel it to disallow the "Character" unlocking or locking a specific {@link com.teamacronymcoders.epos.skill.Skill}.
*/
@Cancelable
public static class Skill extends EposGrantEvent {
public Skill(LivingEntity entity, EposGrantOperator operator, ResourceLocation typeObjectId) {
super(entity, EposGrantType.SKILL, operator, typeObjectId);
}
}
/**
* The {@link EposGrantEvent.Feat} event is fired when Unlocking or Locking a {@link com.teamacronymcoders.epos.feat.Feat} on the Character.
* This event is also a {@link Cancelable} event, which means that you can cancel it to disallow the "Character" unlocking or locking a specific {@link com.teamacronymcoders.epos.feat.Feat}.
*/
@Cancelable
public static class Feat extends EposGrantEvent {
public Feat(LivingEntity entity, EposGrantOperator operator, ResourceLocation typeObjectId) {
super(entity, EposGrantType.FEAT, operator, typeObjectId);
}
}
}
package com.teamacronymcoders.epos.api.event;
import com.teamacronymcoders.epos.api.capability.EposCapabilities;
import com.teamacronymcoders.epos.api.character.ICharacterSheet;
import com.teamacronymcoders.epos.api.event.enums.EposEventType;
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;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* The core event for level-based interactions.
* Currently the main event(s) are:
* - {@link EposLevelEvent.LevelUpEvent}
* - {@link EposLevelEvent.LevelDownEvent}
*
* More events may be added later.
*/
public class EposLevelEvent extends LivingEvent {
private final LazyOptional<ICharacterSheet> sheet;
@Nonnull
private final EposEventType type;
@Nullable
private final ResourceLocation typeObjectId;
private final int oldLevel;
private final int newLevel;
public EposLevelEvent(LivingEntity entity, @Nonnull EposEventType type, @Nullable ResourceLocation typeObjectId, int oldLevel, int newLevel) {
super(entity);
this.sheet = entity.getCapability(EposCapabilities.CHARACTER_SHEET);
this.type = type;
this.typeObjectId = typeObjectId;
this.oldLevel = oldLevel;
this.newLevel = newLevel;
}
/**
* @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 EposEventType#CHARACTER}, {@link EposEventType#PATH} or {@link EposEventType#SKILL}
* @return Returns what type of experience was gained.
*/
@Nonnull
public EposEventType 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.
*/
@Nullable
public ResourceLocation getTypeObjectId() {
return typeObjectId;
}
/**
* Returns the old level.
* @return Returns the level pre-change.
*/
public int getOldLevel() {
return oldLevel;
}
/**
* Returns the new level.
* @return Returns the level post-change.
*/
public int getNewLevel() {
return newLevel;
}
/**
* The {@link EposLevelEvent.LevelUpEvent} event used for when a Character is leveling-up either as a Character, or leveling-up an {@link com.teamacronymcoders.epos.path.Path} or an {@link com.teamacronymcoders.epos.skill.Skill}.
* This event is also a {@link Cancelable} event, which means that you can cancel it to disallow the "Character" leveling-up.
*/
@Cancelable
public static class LevelUpEvent extends EposLevelEvent {
public LevelUpEvent(LivingEntity entity, EposEventType type, ResourceLocation typeObjectId, int oldLevel, int newLevel) {
super(entity, type, typeObjectId, oldLevel, newLevel);
}
}
/**
* The {@link EposLevelEvent.LevelDownEvent} event used for when a Character is leveling-down either as a Character, or leveling-down an {@link com.teamacronymcoders.epos.path.Path} or an {@link com.teamacronymcoders.epos.skill.Skill}.
* This event is also a {@link Cancelable} event, which means that you can cancel it to disallow the "Character" leveling-down.
*/
@Cancelable
public static class LevelDownEvent extends EposLevelEvent {
public LevelDownEvent(LivingEntity entity, EposEventType type, ResourceLocation typeObjectId, int oldLevel, int newLevel) {
super(entity, type, typeObjectId, oldLevel, newLevel);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment