Skip to content

Commit

Permalink
Enchantment Refactoring, Fixed Registry Error, Removed Unnecessary Co…
Browse files Browse the repository at this point in the history
…de, Fixed Conditions, Clarified Variable Names, Added Recipe Expansions, Optimised Imports

 - Refactored Enchantments to allow for more configurability
 - Fixed duplicate registry attempts within enchantments
 - Removed `BeeStingerItem` and `EnchantsLists` classes
 - Added `BusyBeeEnchantment` and `MultishotBowEnchantment` as separate enchantments
 - Added notations in various places to note nullability and more explicitly and clearly stated notes that were already present in the code (this is ongoing)
 - Explicitly renamed `POISONING` to `JUNGLE_POISON` where used to be more consistent and to be in line with Minecraft Dungeons
 - Rewrote `EnchantsRegistry` to use a Switch Statement rather than individual calls. This may change depending on need, but it is functionally the same thing as was already in place
 - Added fallbacks for the icons in the `ItemGroupRegistry` in case the items that are used by default are disabled in order to prevent a crash when the creative tabs are viewed
 - Optimised `LootTablesRegistry`
 - Updated lang entries to reflect more readable layout and groupings
 - Fixed recipe and advancement data files to allow for disabling of items without console spam
  • Loading branch information
chronosacaria committed Apr 12, 2024
1 parent 9e811d3 commit 3148878
Show file tree
Hide file tree
Showing 375 changed files with 9,709 additions and 8,908 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

Expand All @@ -30,7 +30,7 @@ public interface IInnateEnchantment {
* The following code is from Spectrum and can be found here:<br/>
* <a href = "https://github.com/DaFuqs/Spectrum/blob/1.19-deeper-down/src/main/java/de/dafuqs/spectrum/items/Preenchanted.java#L13">Preenchanted#getDefaultEnchantedStack</a>
*/
default @NotNull ItemStack getInnateEnchantedStack(Item item) {
default @Nullable ItemStack getInnateEnchantedStack(Item item) {
ItemStack itemStack = new ItemStack(item);
if (Mcdw.CONFIG.mcdwEnchantmentSettingsConfig.ENABLE_ENCHANTMENT_SETTINGS.get(SettingsID.ENABLE_INNATE_ENCHANTMENTS)) {
Map<Enchantment, Integer> map = getInnateEnchantments();
Expand Down
41 changes: 21 additions & 20 deletions src/main/java/chronosacaria/mcdw/api/util/CleanlinessHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import chronosacaria.mcdw.bases.McdwLongbow;
import chronosacaria.mcdw.bases.McdwShortbow;
import chronosacaria.mcdw.configs.CompatibilityFlags;
import chronosacaria.mcdw.enums.EnchantmentsID;
import chronosacaria.mcdw.registries.EnchantsRegistry;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.enchantment.EnchantmentHelper;
Expand Down Expand Up @@ -104,83 +105,83 @@ public static void playCenteredSound (LivingEntity center, SoundEvent soundEvent
}

public static void addPPEEnchantments(ItemStack itemStack, IMcdwEnchantedArrow ppe) {
int chainReactionLevel = EnchantmentHelper.getLevel(EnchantsRegistry.CHAIN_REACTION, itemStack);
int chainReactionLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.CHAIN_REACTION), itemStack);
if (chainReactionLevel > 0) {
ppe.mcdw$setChainReactionLevel(chainReactionLevel);
}
int chargeLevel = EnchantmentHelper.getLevel(EnchantsRegistry.CHARGE, itemStack);
int chargeLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.CHARGE), itemStack);
if (chargeLevel > 0) {
ppe.mcdw$setChargeLevel(chargeLevel);
}
int cobwebShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.COBWEB_SHOT, itemStack);
int cobwebShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.COBWEB_SHOT), itemStack);
if (cobwebShotLevel > 0) {
ppe.mcdw$setCobwebShotLevel(cobwebShotLevel);
}
int dynamoLevel = EnchantmentHelper.getLevel(EnchantsRegistry.DYNAMO, itemStack);
int dynamoLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.DYNAMO), itemStack);
if (dynamoLevel > 0) {
ppe.mcdw$setDynamoLevel(dynamoLevel);
}
int enigmaResonatorLevel = EnchantmentHelper.getLevel(EnchantsRegistry.ENIGMA_RESONATOR, itemStack);
int enigmaResonatorLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.ENIGMA_RESONATOR), itemStack);
if (enigmaResonatorLevel > 0) {
ppe.mcdw$setEnigmaResonatorLevel(enigmaResonatorLevel);
}
int fuseShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.FUSE_SHOT, itemStack);
int fuseShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.FUSE_SHOT), itemStack);
if (fuseShotLevel > 0) {
ppe.mcdw$setFuseShotLevel(fuseShotLevel);
}
int freezingLevel = EnchantmentHelper.getLevel(EnchantsRegistry.FREEZING, itemStack);
int freezingLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.FREEZING), itemStack);
if (freezingLevel > 0) {
ppe.mcdw$setFreezingLevel(freezingLevel);
}
int gravityLevel = EnchantmentHelper.getLevel(EnchantsRegistry.GRAVITY, itemStack);
int gravityLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.GRAVITY), itemStack);
if (gravityLevel > 0) {
ppe.mcdw$setGravityLevel(gravityLevel);
}
int growingLevel = EnchantmentHelper.getLevel(EnchantsRegistry.GROWING, itemStack);
int growingLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.GROWING), itemStack);
if (growingLevel > 0) {
ppe.mcdw$setGrowingLevel(growingLevel);
}
int levitationShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.LEVITATION_SHOT, itemStack);
int levitationShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.LEVITATION_SHOT), itemStack);
if (levitationShotLevel > 0) {
ppe.mcdw$setLevitationShotLevel(levitationShotLevel);
}
int phantomsMarkLevel = EnchantmentHelper.getLevel(EnchantsRegistry.PHANTOMS_MARK, itemStack);
int phantomsMarkLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.PHANTOMS_MARK), itemStack);
if (phantomsMarkLevel > 0) {
ppe.mcdw$setPhantomsMarkLevel(phantomsMarkLevel);
}
int poisonCloudLevel = EnchantmentHelper.getLevel(EnchantsRegistry.POISON_CLOUD, itemStack);
int poisonCloudLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.POISON_CLOUD), itemStack);
if (poisonCloudLevel > 0) {
ppe.mcdw$setPoisonCloudLevel(poisonCloudLevel);
}
int radianceLevel = EnchantmentHelper.getLevel(EnchantsRegistry.RADIANCE, itemStack);
int radianceLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.RADIANCE), itemStack);
if (radianceLevel > 0) {
ppe.mcdw$setRadianceLevel(radianceLevel);
}
int replenishLevel = EnchantmentHelper.getLevel(EnchantsRegistry.REPLENISH, itemStack);
int replenishLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.REPLENISH), itemStack);
if (replenishLevel > 0) {
ppe.mcdw$setReplenishLevel(replenishLevel);
}
int ricochetLevel = EnchantmentHelper.getLevel(EnchantsRegistry.RICOCHET, itemStack);
int ricochetLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.RICOCHET), itemStack);
if (ricochetLevel > 0) {
ppe.mcdw$setRicochetLevel(ricochetLevel);
}
int shadowShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.SHADOW_SHOT, itemStack);
int shadowShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.SHADOW_SHOT), itemStack);
if (shadowShotLevel > 0) {
ppe.mcdw$setShadowShotLevel(shadowShotLevel);
}
int tempoTheftLevel = EnchantmentHelper.getLevel(EnchantsRegistry.TEMPO_THEFT, itemStack);
int tempoTheftLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.TEMPO_THEFT), itemStack);
if (tempoTheftLevel > 0) {
ppe.mcdw$setTempoTheftLevel(tempoTheftLevel);
}
int thunderingLevel = EnchantmentHelper.getLevel(EnchantsRegistry.THUNDERING, itemStack);
int thunderingLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.THUNDERING), itemStack);
if (thunderingLevel > 0) {
ppe.mcdw$setThunderingLevel(thunderingLevel);
}
int voidShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.VOID_SHOT, itemStack);
int voidShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.VOID_SHOT), itemStack);
if (voidShotLevel > 0) {
ppe.mcdw$setVoidShotLevel(voidShotLevel);
}
int wildRageLevel = EnchantmentHelper.getLevel(EnchantsRegistry.WILD_RAGE, itemStack);
int wildRageLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.WILD_RAGE), itemStack);
if (wildRageLevel > 0){
ppe.mcdw$setWildRageLevel(wildRageLevel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static float getVanillaArrowVelocity(ItemStack stack, int charge){

public static float getVanillaBowChargeTime(ItemStack stack){
int quickChargeLevel = EnchantmentHelper.getLevel(Enchantments.QUICK_CHARGE, stack);
//int accelerateLevel = EnchantmentHelper.getLevel(EnchantsRegistry.ACCELERATE, stack);
//int accelerateLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.ACCELERATE, stack);

float bowChargeTime = 30 * (Math.max(20.0F - 5 * quickChargeLevel, 0));
long lastFiredtime = (long)(McdwBow.getPullProgress(22) * (Math.max(20.0F - 5 * quickChargeLevel, 0)));
Expand All @@ -38,7 +38,7 @@ public static float getVanillaBowChargeTime(ItemStack stack){

public static float getShortBowChargeTime(ItemStack stack){
int quickChargeLevel = EnchantmentHelper.getLevel(Enchantments.QUICK_CHARGE, stack);
//int accelerateLevel = EnchantmentHelper.getLevel(EnchantsRegistry.ACCELERATE, stack);
//int accelerateLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.ACCELERATE, stack);

float bowChargeTime = 15 * (Math.max(10.0F - 5 * quickChargeLevel, 0));
long lastFiredtime = (long)(McdwShortbow.getPullProgress(11) * (Math.max(10.0F - 5 * quickChargeLevel, 0)));
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/chronosacaria/mcdw/bases/McdwDagger.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -45,11 +46,13 @@ public boolean canRepair(ItemStack stack, ItemStack ingredient) {

@Override
public ItemStack getDefaultStack() {
if (getInnateEnchantedStack(this) == null)
return this.getDefaultStack();
return getInnateEnchantedStack(this);
}

@Override
public Map<Enchantment, Integer> getInnateEnchantments() {
public @Nullable Map<Enchantment, Integer> getInnateEnchantments() {
return this.daggersEnum.getInnateEnchantments();
}

Expand Down
4 changes: 0 additions & 4 deletions src/main/java/chronosacaria/mcdw/bases/McdwSword.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import chronosacaria.mcdw.enums.SwordsID;
import chronosacaria.mcdw.mixin.mcdw.InsulatedAxeItemAccessor;
import chronosacaria.mcdw.registries.ItemGroupRegistry;
import chronosacaria.mcdw.registries.ItemsRegistry;
import com.google.common.collect.BiMap;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.advancement.criterion.Criteria;
Expand All @@ -24,7 +23,6 @@
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
Expand Down Expand Up @@ -123,7 +121,5 @@ public Map<Enchantment, Integer> getInnateEnchantments() {
public void appendTooltip(ItemStack stack, World world, List<Text> tooltip, TooltipContext tooltipContext){
super.appendTooltip(stack, world, tooltip, tooltipContext);
CleanlinessHelper.mcdw$tooltipHelper(stack, tooltip, 16);
if (stack.getItem() == ItemsRegistry.SWORD_ITEMS.get(SwordsID.SWORD_BEESTINGER))
tooltip.add(Text.translatable("tooltip_ench_item.mcdw.beestinger_1").formatted(Formatting.GRAY));
}
}
14 changes: 7 additions & 7 deletions src/main/java/chronosacaria/mcdw/client/McdwClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public static void registerRangedWeaponPredicates(Item item) {
if (livingEntity == null) {
return 0.0F;
} else if (item instanceof McdwBow bow) {
return drawSpeedModification(itemStack, livingEntity, bow.getDrawSpeed());
return calculateDrawSpeed(itemStack, livingEntity, bow.getDrawSpeed());
} else if (item instanceof McdwShortbow shortbow) {
return drawSpeedModification(itemStack, livingEntity, shortbow.getDrawSpeed());
return calculateDrawSpeed(itemStack, livingEntity, shortbow.getDrawSpeed());
} else if (item instanceof McdwLongbow longbow) {
return drawSpeedModification(itemStack, livingEntity, longbow.getDrawSpeed());
return calculateDrawSpeed(itemStack, livingEntity, longbow.getDrawSpeed());
} else if (item instanceof McdwCrossbow crossbow) {
return drawSpeedModification(itemStack, livingEntity, crossbow.getDrawSpeed());
return calculateDrawSpeed(itemStack, livingEntity, crossbow.getDrawSpeed());
}
return 0.0F;
});
Expand Down Expand Up @@ -91,10 +91,10 @@ public static void registerShieldPredicates(McdwShield shield) {
livingEntity.getActiveItem() == itemStack ? 1.0F : 0.0F
);
}
private static float drawSpeedModification(ItemStack itemStack, LivingEntity livingEntity, float drawSpeed) {
private static float calculateDrawSpeed(ItemStack itemStack, LivingEntity livingEntity, float drawSpeed) {
int useTicks = itemStack.getMaxUseTime() - livingEntity.getItemUseTimeLeft();
if (Mcdw.CONFIG.mcdwEnchantmentsConfig.ENCHANTMENT_CONFIG.get(EnchantmentsID.ACCELERATE).mcdw$getIsEnabled()) {
int accelerateLevel = EnchantmentHelper.getLevel(EnchantsRegistry.ACCELERATE, itemStack);
int accelerateLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.ACCELERATE), itemStack);
if (accelerateLevel > 0) {
StatusEffectInstance accelerateInstance = livingEntity.getStatusEffect(StatusEffectsRegistry.ACCELERATE);
int consecutiveShots = accelerateInstance != null ? accelerateInstance.getAmplifier() + 1 : 0;
Expand All @@ -103,7 +103,7 @@ private static float drawSpeedModification(ItemStack itemStack, LivingEntity liv
}
}
if (Mcdw.CONFIG.mcdwEnchantmentsConfig.ENCHANTMENT_CONFIG.get(EnchantmentsID.OVERCHARGE).mcdw$getIsEnabled()) {
int overchargeLevel = EnchantmentHelper.getLevel(EnchantsRegistry.OVERCHARGE, itemStack);
int overchargeLevel = EnchantmentHelper.getLevel(EnchantsRegistry.enchantments.get(EnchantmentsID.OVERCHARGE), itemStack);
if (overchargeLevel > 0) {
int overcharge = (int) Math.min((useTicks / drawSpeed) - 1, overchargeLevel);
useTicks = overcharge == overchargeLevel ? useTicks : (int) (useTicks % drawSpeed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public McdwEnchantmentsConfig(){
)
);
ENCHANTMENT_CONFIG.put(
EnchantmentsID.BUZZY_BEE,
EnchantmentsID.BUSY_BEE,
new EnchantmentIDConfigHelper(
true,
false,
Expand Down Expand Up @@ -299,7 +299,7 @@ public McdwEnchantmentsConfig(){
)
);
ENCHANTMENT_CONFIG.put(
EnchantmentsID.POISONING,
EnchantmentsID.JUNGLE_POISON,
new EnchantmentIDConfigHelper(
true,
true,
Expand Down Expand Up @@ -337,8 +337,8 @@ public McdwEnchantmentsConfig(){
EnchantmentsID.MULTI_SHOT,
new EnchantmentIDConfigHelper(
true,
true,
true,
false,
false,
1,
null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,52 @@
public class ConfigItemEnabledCondition {

public static void register() {
// Register a resource condition for checking if multiple config values are all true
ResourceConditions.register(new Identifier(Mcdw.MOD_ID, "config_enabled"), jsonObject -> {
JsonArray jsonArray = JsonHelper.getArray(jsonObject, "values");
List<Boolean> booleanArrayList = new ArrayList<>();
JsonArray values = JsonHelper.getArray(jsonObject, "values");
List<Boolean> booleanList = new ArrayList<>();

for (JsonElement jsonElement : jsonArray) {
if (jsonElement.isJsonPrimitive()) {
for (JsonElement element : values) {
if (element.isJsonPrimitive()) {
String elementString = element.getAsString();
List<String> configClasses = Arrays.asList(elementString.split("\\."));
try {
String jsonElementString = jsonElement.getAsString();
List<String> configClasses = Arrays.stream(jsonElementString.split("\\.")).toList();
if (configClasses.size() > 1) {
booleanArrayList.add(Mcdw.CONFIG.getClass().getField(configClasses.get(0)).get(Mcdw.CONFIG).getClass().getField(configClasses.get(1)).getBoolean(Mcdw.CONFIG.getClass().getField(configClasses.get(0)).get(Mcdw.CONFIG)));
} else
booleanArrayList.add(Mcdw.CONFIG.getClass().getField(jsonElementString).getBoolean(Mcdw.CONFIG));
// Retrieve the config value and add it to the boolean list
booleanList.add(
Mcdw.CONFIG
.getClass().getField(configClasses.get(0))
.get(Mcdw.CONFIG).getClass().getField(configClasses.get(1))
.getBoolean(Mcdw.CONFIG.getClass().getField(configClasses.get(0))
.get(Mcdw.CONFIG)));
} else {
// Retrieve the config value and add it to the boolean list
booleanList.add(Mcdw.CONFIG.getClass().getField(elementString).getBoolean(Mcdw.CONFIG));
}
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
return booleanArrayList.stream().allMatch(aBoolean -> aBoolean);
// Check if all config values are true
return booleanList.stream().allMatch(Boolean::booleanValue);
});

// Register a resource condition for checking if an item is enabled
ResourceConditions.register(new Identifier(Mcdw.MOD_ID, "item_enabled"), jsonObject -> {
JsonArray jsonArray = JsonHelper.getArray(jsonObject, "values");
JsonArray values = JsonHelper.getArray(jsonObject, "values");

for (JsonElement jsonElement : jsonArray) {
if (jsonElement.isJsonPrimitive()) {
return Registries.ITEM.get(new Identifier(jsonElement.getAsString())) != Items.AIR;
for (JsonElement element : values) {
if (element.isJsonPrimitive()) {
try {
// Check if the item exists in the item registry
return Registries.ITEM.get(new Identifier(element.getAsString())) != Items.AIR;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
// If no item is specified, default to true
return true;
});
}
Expand Down
Loading

0 comments on commit 3148878

Please sign in to comment.