Skip to content

Commit

Permalink
Removed Ambiguity of Class Names, Fixed Cooldown Bug, Version Bump
Browse files Browse the repository at this point in the history
- Renamed the local version of EnchantmentHelper -> McdarEnchantmentHelper to alleviate ambiguity with the vanilla EnchantmentHelper
- Fixed a bug where the cooldown of some artifacts was not triggering properly, especially quivers, causing them to not function at all
- Added a method overload for `mcdar$cooldownHelper` to allow for more flexibility with cooldown implementation with certain artifacts
chronosacaria committed Feb 13, 2024
1 parent 50f31c4 commit 40b94de
Showing 20 changed files with 70 additions and 109 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ minecraft_version=1.20.1
yarn_mappings=1.20.1+build.9
loader_version=0.14.21
# Mod Properties
mod_version=4.0.0
mod_version=4.0.1
maven_group=chronosacaria
archives_base_name=mcdar
# Dependencies
18 changes: 9 additions & 9 deletions src/main/java/chronosacaria/mcdar/api/CleanlinessHelper.java
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import chronosacaria.mcdar.enums.*;
import chronosacaria.mcdar.registries.EnchantsRegistry;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
@@ -104,7 +105,7 @@ public static boolean isCoolingDown(PlayerEntity player, Item item) {
}
if (!player.isCreative())
itemStack.damage(1, player, (entity) -> entity.sendToolBreakStatus(hand));
EnchantmentHelper.mcdar$cooldownHelper(player, artifact, mcdar$artifactIDToItemCooldownTime(artifact));
McdarEnchantmentHelper.mcdar$cooldownHelper(player, artifact);
return new TypedActionResult<>(ActionResult.SUCCESS, itemStack);
}

@@ -125,20 +126,19 @@ public static boolean isCoolingDown(PlayerEntity player, Item item) {
itemUsageContext.getStack().damage(1, itemUsageContextPlayer,
(entity) -> entity.sendToolBreakStatus(itemUsageContext.getHand()));

EnchantmentHelper.mcdar$cooldownHelper(
McdarEnchantmentHelper.mcdar$cooldownHelper(
itemUsageContextPlayer,
artifact,
mcdar$artifactIDToItemCooldownTime(artifact));
artifact);
return ActionResult.CONSUME;
}
}
}
return ActionResult.SUCCESS;
}

private static int mcdar$artifactIDToItemCooldownTime(Item artifactItem) {
int cooldownLevel = net.minecraft.enchantment.EnchantmentHelper.getLevel(EnchantsRegistry.COOLDOWN, artifactItem.getDefaultStack());
if (artifactItem instanceof IArtifactItem) {
public static int mcdar$artifactIDToItemCooldownTime(Item artifactItem) {
int cooldownLevel = EnchantmentHelper.getLevel(EnchantsRegistry.COOLDOWN, artifactItem.getDefaultStack());
//if (artifactItem instanceof IArtifactItem) {
for (AgilityArtifactID agilityArtifactID : AgilityArtifactID.values())
if (artifactItem.asItem() == agilityArtifactID.mcdar$getItem()
&& Mcdar.CONFIG.mcdarArtifactsStatsConfig.AGILITY_ARTIFACT_STATS.get(agilityArtifactID)
@@ -154,7 +154,7 @@ public static boolean isCoolingDown(PlayerEntity player, Item item) {
for (DefensiveArtifactID defensiveArtifactID : DefensiveArtifactID.values())
if (artifactItem.asItem() == defensiveArtifactID.mcdar$getItem()
&& Mcdar.CONFIG.mcdarArtifactsStatsConfig.DEFENSIVE_ARTIFACT_STATS.get(defensiveArtifactID)
.mcdar$getIsEnabled())
.mcdar$getIsEnabled() && artifactItem.asItem() != DefensiveArtifactID.SOUL_HEALER.mcdar$getItem())
return Mcdar.CONFIG.mcdarArtifactsStatsConfig.DEFENSIVE_ARTIFACT_STATS.get(defensiveArtifactID)
.mcdar$getMaxCooldownEnchantmentTime();
for (QuiverArtifactID quiverArtifactID : QuiverArtifactID.values())
@@ -175,7 +175,7 @@ public static boolean isCoolingDown(PlayerEntity player, Item item) {
.mcdar$getIsEnabled())
return Mcdar.CONFIG.mcdarArtifactsStatsConfig.SUMMONING_ARTIFACT_STATS.get(summoningArtifactID)
.mcdar$getMaxCooldownEnchantmentTime();
}
//}
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class EnchantmentHelper {
public class McdarEnchantmentHelper {

public static void mcdar$cooldownHelper(PlayerEntity player, Item item, int maxCooldown) {
int cooldownLevel = mcdar$getCooldownLevel(EnchantsRegistry.COOLDOWN, player);
@@ -15,6 +15,14 @@ public class EnchantmentHelper {
(int) (maxCooldown - (maxCooldown * mcdar$cooldownCalcHelper(cooldownLevel))));
}

public static void mcdar$cooldownHelper(PlayerEntity player, Item item) {
int cooldownLevel = mcdar$getCooldownLevel(EnchantsRegistry.COOLDOWN, player);
int maxCooldown = CleanlinessHelper.mcdar$artifactIDToItemCooldownTime(item);
player.getItemCooldownManager().set(item,
cooldownLevel == 0 ? maxCooldown :
(int) (maxCooldown - (maxCooldown * mcdar$cooldownCalcHelper(cooldownLevel))));
}

public static float mcdar$cooldownCalcHelper(int level) {
float modifier = 0.18f;
for (int i = 0 ; i < level - 1 ; i++) {
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

import chronosacaria.mcdar.Mcdar;
import chronosacaria.mcdar.api.CleanlinessHelper;
import chronosacaria.mcdar.api.EnchantmentHelper;
import chronosacaria.mcdar.api.McdarEnchantmentHelper;
import chronosacaria.mcdar.effects.ArtifactEffects;
import chronosacaria.mcdar.enums.DamagingArtifactID;
import net.minecraft.client.item.TooltipContext;
@@ -35,12 +35,9 @@ public TypedActionResult<ItemStack> use (World world, PlayerEntity user, Hand ha
if (!user.isCreative()){
itemStack.damage(1, user, (entity) -> entity.sendToolBreakStatus(hand));
}
EnchantmentHelper.mcdar$cooldownHelper(
McdarEnchantmentHelper.mcdar$cooldownHelper(
user,
this,
Mcdar.CONFIG.mcdarArtifactsStatsConfig.DAMAGING_ARTIFACT_STATS
.get(DamagingArtifactID.BLAST_FUNGUS)
.mcdar$getMaxCooldownEnchantmentTime()
this
);

return new TypedActionResult<>(ActionResult.SUCCESS, itemStack);
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
import chronosacaria.mcdar.Mcdar;
import chronosacaria.mcdar.api.AOEHelper;
import chronosacaria.mcdar.api.CleanlinessHelper;
import chronosacaria.mcdar.api.EnchantmentHelper;
import chronosacaria.mcdar.api.McdarEnchantmentHelper;
import chronosacaria.mcdar.enums.StatusInflictingArtifactID;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.effect.StatusEffectInstance;
@@ -36,12 +36,9 @@ public TypedActionResult<ItemStack> use (World world, PlayerEntity user, Hand ha
if (!user.isCreative())
itemStack.damage(1, user, (entity) -> entity.sendToolBreakStatus(hand));

EnchantmentHelper.mcdar$cooldownHelper(
McdarEnchantmentHelper.mcdar$cooldownHelper(
user,
this,
Mcdar.CONFIG.mcdarArtifactsStatsConfig.STATUS_INFLICTING_ARTIFACT_STATS
.get(StatusInflictingArtifactID.CORRUPTED_SEEDS)
.mcdar$getMaxCooldownEnchantmentTime()
this
);

return new TypedActionResult<>(ActionResult.SUCCESS, itemStack);
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

import chronosacaria.mcdar.Mcdar;
import chronosacaria.mcdar.api.CleanlinessHelper;
import chronosacaria.mcdar.api.EnchantmentHelper;
import chronosacaria.mcdar.api.McdarEnchantmentHelper;
import chronosacaria.mcdar.api.SummoningHelper;
import chronosacaria.mcdar.enums.SummoningArtifactID;
import net.minecraft.client.item.TooltipContext;
@@ -46,12 +46,10 @@ public ActionResult useOnBlock (ItemUsageContext itemUsageContext){
itemUsageContext.getStack().damage(1, itemUsageContextPlayer,
(entity) -> entity.sendToolBreakStatus(itemUsageContext.getHand()));

EnchantmentHelper.mcdar$cooldownHelper(
McdarEnchantmentHelper.mcdar$cooldownHelper(
itemUsageContextPlayer,
this,
Mcdar.CONFIG.mcdarArtifactsStatsConfig.SUMMONING_ARTIFACT_STATS
.get(SummoningArtifactID.ENCHANTED_GRASS)
.mcdar$getMaxCooldownEnchantmentTime());
this
);
return ActionResult.CONSUME;
}
}
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

import chronosacaria.mcdar.Mcdar;
import chronosacaria.mcdar.api.CleanlinessHelper;
import chronosacaria.mcdar.api.EnchantmentHelper;
import chronosacaria.mcdar.api.McdarEnchantmentHelper;
import chronosacaria.mcdar.effects.ArtifactEffects;
import chronosacaria.mcdar.enums.DefensiveArtifactID;
import net.minecraft.client.item.TooltipContext;
@@ -32,12 +32,9 @@ public TypedActionResult<ItemStack> use (World world, PlayerEntity user, Hand ha
if (!user.isCreative())
itemStack.damage(1, user, (entity) -> entity.sendToolBreakStatus(hand));

EnchantmentHelper.mcdar$cooldownHelper(
McdarEnchantmentHelper.mcdar$cooldownHelper(
user,
this,
Mcdar.CONFIG.mcdarArtifactsStatsConfig.DEFENSIVE_ARTIFACT_STATS
.get(DefensiveArtifactID.ENCHANTERS_TOME)
.mcdar$getMaxCooldownEnchantmentTime()
this
);

return new TypedActionResult<>(ActionResult.SUCCESS, itemStack);
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
import chronosacaria.mcdar.Mcdar;
import chronosacaria.mcdar.api.AOEHelper;
import chronosacaria.mcdar.api.CleanlinessHelper;
import chronosacaria.mcdar.api.EnchantmentHelper;
import chronosacaria.mcdar.api.McdarEnchantmentHelper;
import chronosacaria.mcdar.enums.StatusInflictingArtifactID;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.effect.StatusEffectInstance;
@@ -42,12 +42,9 @@ public TypedActionResult<ItemStack> use (World world, PlayerEntity user, Hand ha
if (!user.isCreative())
itemStack.damage(1, user, (entity) -> entity.sendToolBreakStatus(hand));

EnchantmentHelper.mcdar$cooldownHelper(
McdarEnchantmentHelper.mcdar$cooldownHelper(
user,
this,
Mcdar.CONFIG.mcdarArtifactsStatsConfig.STATUS_INFLICTING_ARTIFACT_STATS
.get(StatusInflictingArtifactID.GONG_OF_WEAKENING)
.mcdar$getMaxCooldownEnchantmentTime()
this
);
return new TypedActionResult<>(ActionResult.SUCCESS, itemStack);
}
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
import chronosacaria.mcdar.api.AOECloudHelper;
import chronosacaria.mcdar.api.AOEHelper;
import chronosacaria.mcdar.api.CleanlinessHelper;
import chronosacaria.mcdar.api.EnchantmentHelper;
import chronosacaria.mcdar.api.McdarEnchantmentHelper;
import chronosacaria.mcdar.enums.DamagingArtifactID;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.player.PlayerEntity;
@@ -39,12 +39,9 @@ public TypedActionResult<ItemStack> use (World world, PlayerEntity user, Hand ha
user.addExperience(-40);
itemStack.damage(1, user, (entity) -> entity.sendToolBreakStatus(hand));
}
EnchantmentHelper.mcdar$cooldownHelper(
McdarEnchantmentHelper.mcdar$cooldownHelper(
user,
this,
Mcdar.CONFIG.mcdarArtifactsStatsConfig.DAMAGING_ARTIFACT_STATS
.get(DamagingArtifactID.HARVESTER)
.mcdar$getMaxCooldownEnchantmentTime()
this
);
}
return new TypedActionResult<>(ActionResult.SUCCESS, itemStack);
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
import chronosacaria.mcdar.api.AOEHelper;
import chronosacaria.mcdar.api.AbilityHelper;
import chronosacaria.mcdar.api.CleanlinessHelper;
import chronosacaria.mcdar.api.EnchantmentHelper;
import chronosacaria.mcdar.api.McdarEnchantmentHelper;
import chronosacaria.mcdar.enums.AgilityArtifactID;
import chronosacaria.mcdar.registries.StatusEffectInit;
import net.minecraft.client.item.TooltipContext;
@@ -47,12 +47,9 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han
if (!user.isCreative())
itemStack.damage(1, user, (entity) -> entity.sendToolBreakStatus(hand));

EnchantmentHelper.mcdar$cooldownHelper(
McdarEnchantmentHelper.mcdar$cooldownHelper(
user,
this,
Mcdar.CONFIG.mcdarArtifactsStatsConfig.AGILITY_ARTIFACT_STATS
.get(AgilityArtifactID.LIGHT_FEATHER)
.mcdar$getMaxCooldownEnchantmentTime()
this
);

return new TypedActionResult<>(ActionResult.SUCCESS, itemStack);
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
import chronosacaria.mcdar.Mcdar;
import chronosacaria.mcdar.api.AOEHelper;
import chronosacaria.mcdar.api.CleanlinessHelper;
import chronosacaria.mcdar.api.EnchantmentHelper;
import chronosacaria.mcdar.api.McdarEnchantmentHelper;
import chronosacaria.mcdar.enums.DamagingArtifactID;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.player.PlayerEntity;
@@ -35,12 +35,9 @@ public TypedActionResult<ItemStack> use (World world, PlayerEntity user, Hand ha
user.addExperience(-15);
itemStack.damage(1, user, (entity) -> entity.sendToolBreakStatus(hand));
}
EnchantmentHelper.mcdar$cooldownHelper(
McdarEnchantmentHelper.mcdar$cooldownHelper(
user,
this,
Mcdar.CONFIG.mcdarArtifactsStatsConfig.DAMAGING_ARTIFACT_STATS
.get(DamagingArtifactID.LIGHTNING_ROD)
.mcdar$getMaxCooldownEnchantmentTime()
this
);
}
return new TypedActionResult<>(ActionResult.SUCCESS, itemStack);
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
import chronosacaria.mcdar.api.AOEHelper;
import chronosacaria.mcdar.api.AbilityHelper;
import chronosacaria.mcdar.api.CleanlinessHelper;
import chronosacaria.mcdar.api.EnchantmentHelper;
import chronosacaria.mcdar.api.McdarEnchantmentHelper;
import chronosacaria.mcdar.enums.StatusInflictingArtifactID;
import chronosacaria.mcdar.registries.StatusEffectInit;
import net.minecraft.client.item.TooltipContext;
@@ -50,12 +50,9 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han
if (!user.isCreative())
itemStack.damage(1, user, (entity) -> entity.sendToolBreakStatus(hand));

EnchantmentHelper.mcdar$cooldownHelper(
McdarEnchantmentHelper.mcdar$cooldownHelper(
user,
this,
Mcdar.CONFIG.mcdarArtifactsStatsConfig.STATUS_INFLICTING_ARTIFACT_STATS
.get(StatusInflictingArtifactID.LOVE_MEDALLION)
.mcdar$getMaxCooldownEnchantmentTime()
this
);

return new TypedActionResult<>(ActionResult.SUCCESS, itemStack);
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
import chronosacaria.mcdar.Mcdar;
import chronosacaria.mcdar.api.AOEHelper;
import chronosacaria.mcdar.api.CleanlinessHelper;
import chronosacaria.mcdar.api.EnchantmentHelper;
import chronosacaria.mcdar.api.McdarEnchantmentHelper;
import chronosacaria.mcdar.enums.StatusInflictingArtifactID;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.player.PlayerEntity;
@@ -35,12 +35,9 @@ public TypedActionResult<ItemStack> use (World world, PlayerEntity user, Hand ha
user.addExperience(-15);
itemStack.damage(1, user, (entity) -> entity.sendToolBreakStatus(hand));
}
EnchantmentHelper.mcdar$cooldownHelper(
McdarEnchantmentHelper.mcdar$cooldownHelper(
user,
this,
Mcdar.CONFIG.mcdarArtifactsStatsConfig.STATUS_INFLICTING_ARTIFACT_STATS
.get(StatusInflictingArtifactID.SATCHEL_OF_ELEMENTS)
.mcdar$getMaxCooldownEnchantmentTime()
this
);
}
return new TypedActionResult<>(ActionResult.SUCCESS, itemStack);
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
import chronosacaria.mcdar.Mcdar;
import chronosacaria.mcdar.api.AOEHelper;
import chronosacaria.mcdar.api.CleanlinessHelper;
import chronosacaria.mcdar.api.EnchantmentHelper;
import chronosacaria.mcdar.api.McdarEnchantmentHelper;
import chronosacaria.mcdar.enums.StatusInflictingArtifactID;
import chronosacaria.mcdar.registries.StatusEffectInit;
import net.minecraft.client.item.TooltipContext;
@@ -39,12 +39,9 @@ public TypedActionResult<ItemStack> use (World world, PlayerEntity user, Hand ha
if (!user.isCreative())
itemStack.damage(1, user, (entity) -> entity.sendToolBreakStatus(hand));

EnchantmentHelper.mcdar$cooldownHelper(
McdarEnchantmentHelper.mcdar$cooldownHelper(
user,
this,
Mcdar.CONFIG.mcdarArtifactsStatsConfig.STATUS_INFLICTING_ARTIFACT_STATS
.get(StatusInflictingArtifactID.SHOCK_POWDER)
.mcdar$getMaxCooldownEnchantmentTime()
this
);
return new TypedActionResult<>(ActionResult.SUCCESS, itemStack);
}
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
import chronosacaria.mcdar.api.AOEHelper;
import chronosacaria.mcdar.api.AbilityHelper;
import chronosacaria.mcdar.api.CleanlinessHelper;
import chronosacaria.mcdar.api.EnchantmentHelper;
import chronosacaria.mcdar.api.McdarEnchantmentHelper;
import chronosacaria.mcdar.enums.DefensiveArtifactID;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.LivingEntity;
@@ -39,7 +39,7 @@ public TypedActionResult<ItemStack> use (World world, PlayerEntity user, Hand ha
if (healedAmount > 0) {
user.addExperience((int) (-healedAmount));
itemStack.damage(1, user, (entity) -> entity.sendToolBreakStatus(hand));
EnchantmentHelper.mcdar$cooldownHelper(
McdarEnchantmentHelper.mcdar$cooldownHelper(
user,
this,
bl ? 20
Loading

0 comments on commit 40b94de

Please sign in to comment.