Skip to content

Commit

Permalink
feat: New conditions for titles, added support for Lucky's Armory
Browse files Browse the repository at this point in the history
  • Loading branch information
Senior-S committed Aug 22, 2024
1 parent 57848c2 commit c7ec5d3
Show file tree
Hide file tree
Showing 22 changed files with 570 additions and 75 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.9
1.1.0
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mod_name=JustLevelingFork
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=APACHE
# The mod version. See https://semver.org/
mod_version=1.0.9
mod_version=1.1.0
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import com.seniors.justlevelingfork.config.Configuration;
import com.seniors.justlevelingfork.config.models.EAptitude;
import com.seniors.justlevelingfork.config.models.LockItem;
import com.seniors.justlevelingfork.handler.HandlerCommonConfig;
import com.seniors.justlevelingfork.handler.HandlerConfigCommon;
import com.seniors.justlevelingfork.handler.HandlerCurios;
import com.seniors.justlevelingfork.handler.HandlerLockItemsConfig;
import com.seniors.justlevelingfork.handler.*;
import com.seniors.justlevelingfork.integration.CrayfishGunModIntegration;
import com.seniors.justlevelingfork.integration.IronsSpellsbooksIntegration;
import com.seniors.justlevelingfork.integration.ScorchedGuns2Integration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.common.util.INBTSerializable;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.registries.ForgeRegistries;

import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -88,8 +90,14 @@ public void setCounterAttackTimer(int timer) {
this.counterAttackTimer = timer;
}

@Nullable
public static AptitudeCapability get(Player player) {
return player.getCapability(RegistryCapabilities.APTITUDE).orElseThrow(() -> new IllegalArgumentException("Player " + player.getName() + " does not have Capabilities!"));
LazyOptional<AptitudeCapability> capability = player.getCapability(RegistryCapabilities.APTITUDE);
if(capability.isPresent() && capability.resolve().isPresent()){
return capability.resolve().get();
}

return null;
}

public static AptitudeCapability get() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.seniors.justlevelingfork.config.conditions;

import com.seniors.justlevelingfork.JustLevelingFork;
import com.seniors.justlevelingfork.config.models.TitleModel;
import net.minecraft.advancements.Advancement;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;

import java.util.Objects;

public class AdvancementCondition extends ConditionImpl<Boolean> {

public AdvancementCondition(){
super("Advancement");
}

@Override
public void ProcessVariable(String value, ServerPlayer serverPlayer) {
Advancement advancement = Objects.requireNonNull(serverPlayer.getServer()).getAdvancements().getAdvancement(new ResourceLocation(value.replace("-", "/")));
if (advancement == null){
JustLevelingFork.getLOGGER().error(">> Error! Advancement name {} not found!", value);
setProcessedValue(false);
return;
}

setProcessedValue(serverPlayer.getAdvancements().getOrStartProgress(advancement).isDone());
}

@Override
public boolean MeetCondition(String value, TitleModel.EComparator comparator) {
return getProcessedValue();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.seniors.justlevelingfork.config.conditions;

import com.seniors.justlevelingfork.common.capability.AptitudeCapability;
import com.seniors.justlevelingfork.config.models.EAptitude;
import com.seniors.justlevelingfork.config.models.TitleModel;
import com.seniors.justlevelingfork.registry.RegistryAptitudes;
import net.minecraft.server.level.ServerPlayer;
import org.apache.commons.lang3.StringUtils;

public class AptitudeCondition extends ConditionImpl<Integer> {

public AptitudeCondition() {
super("Aptitude");
}

@Override
public void ProcessVariable(String value, ServerPlayer serverPlayer) {
EAptitude aptitude = EAptitude.valueOf(StringUtils.capitalize(value));
int aptitudeLevel = AptitudeCapability.get(serverPlayer).getAptitudeLevel(RegistryAptitudes.getAptitude(aptitude.toString()));

setProcessedValue(aptitudeLevel);
}

@Override
public boolean MeetCondition(String value, TitleModel.EComparator comparator) {
int parsedValue = Integer.parseInt(value);

return switch (comparator) {
case EQUALS -> getProcessedValue().equals(parsedValue);
case GREATER -> getProcessedValue() > parsedValue;
case LESS -> getProcessedValue() < parsedValue;
case GREATER_OR_EQUAL -> getProcessedValue() >= parsedValue;
case LESS_OR_EQUAL -> getProcessedValue() <= parsedValue;
default -> false;
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.seniors.justlevelingfork.config.conditions;

import com.seniors.justlevelingfork.JustLevelingFork;
import com.seniors.justlevelingfork.config.models.TitleModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.stats.Stats;

import java.util.Optional;

public class BlockMinedCondition extends ConditionImpl<Integer> {

public BlockMinedCondition(){
super("BlockMined");
}

@Override
public void ProcessVariable(String value, ServerPlayer serverPlayer) {
var optionalStat = Optional.ofNullable(ResourceLocation.tryParse(value.toLowerCase())).flatMap(Stats.BLOCK_MINED.getRegistry()::getOptional).map(Stats.BLOCK_MINED::get);
if (optionalStat.isEmpty()) {
JustLevelingFork.getLOGGER().error(">> Error! Block name {} not found!", value);
setProcessedValue(0);
return;
}

setProcessedValue(serverPlayer.getStats().getValue(Stats.BLOCK_MINED, optionalStat.get().getValue()));
}

@Override
public boolean MeetCondition(String value, TitleModel.EComparator comparator) {
int parsedValue = Integer.parseInt(value);

return switch (comparator) {
case EQUALS -> getProcessedValue().equals(parsedValue);
case GREATER -> getProcessedValue() > parsedValue;
case LESS -> getProcessedValue() < parsedValue;
case GREATER_OR_EQUAL -> getProcessedValue() >= parsedValue;
case LESS_OR_EQUAL -> getProcessedValue() <= parsedValue;
default -> false;
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.seniors.justlevelingfork.config.conditions;

import com.seniors.justlevelingfork.config.models.TitleModel;
import net.minecraft.server.level.ServerPlayer;

public abstract class ConditionImpl<T> {

private String _conditionName;
public String getConditionName(){
return _conditionName;
}

private T _processedValue;
public T getProcessedValue(){
return _processedValue;
}
public void setProcessedValue(T value)
{
_processedValue = value;
}

public ConditionImpl(String conditionName){
_conditionName = conditionName;
}

public abstract void ProcessVariable(String value, ServerPlayer serverPlayer);

public abstract boolean MeetCondition(String value, TitleModel.EComparator comparator);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.seniors.justlevelingfork.config.conditions;

import com.seniors.justlevelingfork.config.models.TitleModel;
import net.minecraft.server.level.ServerPlayer;

public class DimensionCondition extends ConditionImpl<String> {

public DimensionCondition(){
super("Special");
}

@Override
public void ProcessVariable(String value, ServerPlayer serverPlayer) {
setProcessedValue(serverPlayer.level().dimension().location().toString());
}

@Override
public boolean MeetCondition(String value, TitleModel.EComparator comparator) {
return getProcessedValue().equalsIgnoreCase(value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.seniors.justlevelingfork.config.conditions;

import com.seniors.justlevelingfork.JustLevelingFork;
import com.seniors.justlevelingfork.config.models.TitleModel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.stats.Stats;
import net.minecraft.world.entity.EntityType;

public class EntityKilledByCondition extends ConditionImpl<Integer> {

public EntityKilledByCondition(){
super("EntiyKilledBy");
}

@Override
public void ProcessVariable(String value, ServerPlayer serverPlayer) {
var entityType = EntityType.byString(value);
if (entityType.isEmpty()) {
setProcessedValue(0);
JustLevelingFork.getLOGGER().error(">> Error! Entity name {} not found!", value);
return;
}

setProcessedValue(serverPlayer.getStats().getValue(Stats.ENTITY_KILLED_BY.get(entityType.get())));
}

@Override
public boolean MeetCondition(String value, TitleModel.EComparator comparator) {
int parsedValue = Integer.parseInt(value);

return switch (comparator) {
case EQUALS -> getProcessedValue().equals(parsedValue);
case GREATER -> getProcessedValue() > parsedValue;
case LESS -> getProcessedValue() < parsedValue;
case GREATER_OR_EQUAL -> getProcessedValue() >= parsedValue;
case LESS_OR_EQUAL -> getProcessedValue() <= parsedValue;
default -> false;
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.seniors.justlevelingfork.config.conditions;

import com.seniors.justlevelingfork.JustLevelingFork;
import com.seniors.justlevelingfork.config.models.TitleModel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.stats.Stats;
import net.minecraft.world.entity.EntityType;

public class EntityKilledCondition extends ConditionImpl<Integer> {

public EntityKilledCondition(){
super("EntityKilled");
}

@Override
public void ProcessVariable(String value, ServerPlayer serverPlayer) {
var entityType = EntityType.byString(value);
if (entityType.isEmpty()) {
JustLevelingFork.getLOGGER().error(">> Error! Entity name {} not found!", value);
setProcessedValue(0);
return;
}

setProcessedValue(serverPlayer.getStats().getValue(Stats.ENTITY_KILLED.get(entityType.get())));
}

@Override
public boolean MeetCondition(String value, TitleModel.EComparator comparator) {
int parsedValue = Integer.parseInt(value);

return switch (comparator) {
case EQUALS -> getProcessedValue().equals(parsedValue);
case GREATER -> getProcessedValue() > parsedValue;
case LESS -> getProcessedValue() < parsedValue;
case GREATER_OR_EQUAL -> getProcessedValue() >= parsedValue;
case LESS_OR_EQUAL -> getProcessedValue() <= parsedValue;
default -> false;
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.seniors.justlevelingfork.config.conditions;

import com.seniors.justlevelingfork.JustLevelingFork;
import com.seniors.justlevelingfork.config.models.TitleModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.stats.Stats;

import java.util.Optional;

public class ItemBrokenCondition extends ConditionImpl<Integer> {
public ItemBrokenCondition(){
super("ItemBroken");
}

@Override
public void ProcessVariable(String value, ServerPlayer serverPlayer) {
var optionalStat = Optional.ofNullable(ResourceLocation.tryParse(value.toLowerCase())).flatMap(Stats.ITEM_BROKEN.getRegistry()::getOptional).map(Stats.ITEM_BROKEN::get);
if (optionalStat.isEmpty()) {
JustLevelingFork.getLOGGER().error(">> Error! Item name {} not found!", value);
setProcessedValue(0);
return;
}

setProcessedValue(serverPlayer.getStats().getValue(Stats.ITEM_BROKEN, optionalStat.get().getValue()));
}

@Override
public boolean MeetCondition(String value, TitleModel.EComparator comparator) {
int parsedValue = Integer.parseInt(value);

return switch (comparator) {
case EQUALS -> getProcessedValue().equals(parsedValue);
case GREATER -> getProcessedValue() > parsedValue;
case LESS -> getProcessedValue() < parsedValue;
case GREATER_OR_EQUAL -> getProcessedValue() >= parsedValue;
case LESS_OR_EQUAL -> getProcessedValue() <= parsedValue;
default -> false;
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.seniors.justlevelingfork.config.conditions;

import com.seniors.justlevelingfork.JustLevelingFork;
import com.seniors.justlevelingfork.config.models.TitleModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.stats.Stats;

import java.util.Optional;

public class ItemCraftedCondition extends ConditionImpl<Integer> {

public ItemCraftedCondition(){
super("ItemCrafted");
}

@Override
public void ProcessVariable(String value, ServerPlayer serverPlayer) {
var optionalStat = Optional.ofNullable(ResourceLocation.tryParse(value.toLowerCase())).flatMap(Stats.ITEM_CRAFTED.getRegistry()::getOptional).map(Stats.ITEM_CRAFTED::get);
if (optionalStat.isEmpty()) {
JustLevelingFork.getLOGGER().error(">> Error! Item name {} not found!", value);
setProcessedValue(0);
return;
}

setProcessedValue(serverPlayer.getStats().getValue(Stats.ITEM_CRAFTED, optionalStat.get().getValue()));
}

@Override
public boolean MeetCondition(String value, TitleModel.EComparator comparator) {
int parsedValue = Integer.parseInt(value);

return switch (comparator) {
case EQUALS -> getProcessedValue().equals(parsedValue);
case GREATER -> getProcessedValue() > parsedValue;
case LESS -> getProcessedValue() < parsedValue;
case GREATER_OR_EQUAL -> getProcessedValue() >= parsedValue;
case LESS_OR_EQUAL -> getProcessedValue() <= parsedValue;
default -> false;
};
}
}
Loading

0 comments on commit c7ec5d3

Please sign in to comment.