Skip to content

Commit

Permalink
Bug Fixes, Dependency Clarification
Browse files Browse the repository at this point in the history
 - Explicitly depend on `>=1.20.0 <=1.20.1` of `Minecraft`
 - Fixed #253, No longer crash when using something other than a healing potion with Dipping Poison. (Thank you, @Aesthir!)
 - Fixed #252, Ranged Enchantments now apply correctly on bows and crossbows and do not trigger when melee attacking with the bow or crossbow. (Thank you, @Scizith!)
  • Loading branch information
chronosacaria committed Dec 21, 2023
1 parent 202c424 commit ce0b1e7
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public interface IMcdwEnchantedArrow {
int mcdw$getEnigmaResonatorLevel();
void mcdw$setEnigmaResonatorLevel(int enigmaResonatorLevel);

int mcdw$getFreezingLevel();
void mcdw$setFreezingLevel(int freezingLevel);

int mcdw$getFuseShotLevel();
void mcdw$setFuseShotLevel(int fuseShotLevel);

Expand Down
86 changes: 86 additions & 0 deletions src/main/java/chronosacaria/mcdw/api/util/CleanlinessHelper.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package chronosacaria.mcdw.api.util;

import chronosacaria.mcdw.api.interfaces.IMcdwEnchantedArrow;
import chronosacaria.mcdw.api.interfaces.IOffhandAttack;
import chronosacaria.mcdw.bases.McdwLongbow;
import chronosacaria.mcdw.bases.McdwShortbow;
import chronosacaria.mcdw.configs.CompatibilityFlags;
import chronosacaria.mcdw.registries.EnchantsRegistry;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -99,4 +102,87 @@ public static void playCenteredSound (LivingEntity center, SoundEvent soundEvent
}

}

public static void addPPEEnchantments(ItemStack itemStack, IMcdwEnchantedArrow ppe) {
int chainReactionLevel = EnchantmentHelper.getLevel(EnchantsRegistry.CHAIN_REACTION, itemStack);
if (chainReactionLevel > 0) {
ppe.mcdw$setChainReactionLevel(chainReactionLevel);
}
int chargeLevel = EnchantmentHelper.getLevel(EnchantsRegistry.CHARGE, itemStack);
if (chargeLevel > 0) {
ppe.mcdw$setChargeLevel(chargeLevel);
}
int cobwebShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.COBWEB_SHOT, itemStack);
if (cobwebShotLevel > 0) {
ppe.mcdw$setCobwebShotLevel(cobwebShotLevel);
}
int dynamoLevel = EnchantmentHelper.getLevel(EnchantsRegistry.DYNAMO, itemStack);
if (dynamoLevel > 0) {
ppe.mcdw$setDynamoLevel(dynamoLevel);
}
int enigmaResonatorLevel = EnchantmentHelper.getLevel(EnchantsRegistry.ENIGMA_RESONATOR, itemStack);
if (enigmaResonatorLevel > 0) {
ppe.mcdw$setEnigmaResonatorLevel(enigmaResonatorLevel);
}
int fuseShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.FUSE_SHOT, itemStack);
if (fuseShotLevel > 0) {
ppe.mcdw$setFuseShotLevel(fuseShotLevel);
}
int freezingLevel = EnchantmentHelper.getLevel(EnchantsRegistry.FREEZING, itemStack);
if (freezingLevel > 0) {
ppe.mcdw$setFreezingLevel(freezingLevel);
}
int gravityLevel = EnchantmentHelper.getLevel(EnchantsRegistry.GRAVITY, itemStack);
if (gravityLevel > 0) {
ppe.mcdw$setGravityLevel(gravityLevel);
}
int growingLevel = EnchantmentHelper.getLevel(EnchantsRegistry.GROWING, itemStack);
if (growingLevel > 0) {
ppe.mcdw$setGrowingLevel(growingLevel);
}
int levitationShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.LEVITATION_SHOT, itemStack);
if (levitationShotLevel > 0) {
ppe.mcdw$setLevitationShotLevel(levitationShotLevel);
}
int phantomsMarkLevel = EnchantmentHelper.getLevel(EnchantsRegistry.PHANTOMS_MARK, itemStack);
if (phantomsMarkLevel > 0) {
ppe.mcdw$setPhantomsMarkLevel(phantomsMarkLevel);
}
int poisonCloudLevel = EnchantmentHelper.getLevel(EnchantsRegistry.POISON_CLOUD, itemStack);
if (poisonCloudLevel > 0) {
ppe.mcdw$setPoisonCloudLevel(poisonCloudLevel);
}
int radianceLevel = EnchantmentHelper.getLevel(EnchantsRegistry.RADIANCE, itemStack);
if (radianceLevel > 0) {
ppe.mcdw$setRadianceLevel(radianceLevel);
}
int replenishLevel = EnchantmentHelper.getLevel(EnchantsRegistry.REPLENISH, itemStack);
if (replenishLevel > 0) {
ppe.mcdw$setReplenishLevel(replenishLevel);
}
int ricochetLevel = EnchantmentHelper.getLevel(EnchantsRegistry.RICOCHET, itemStack);
if (ricochetLevel > 0) {
ppe.mcdw$setRicochetLevel(ricochetLevel);
}
int shadowShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.SHADOW_SHOT, itemStack);
if (shadowShotLevel > 0) {
ppe.mcdw$setShadowShotLevel(shadowShotLevel);
}
int tempoTheftLevel = EnchantmentHelper.getLevel(EnchantsRegistry.TEMPO_THEFT, itemStack);
if (tempoTheftLevel > 0) {
ppe.mcdw$setTempoTheftLevel(tempoTheftLevel);
}
int thunderingLevel = EnchantmentHelper.getLevel(EnchantsRegistry.THUNDERING, itemStack);
if (thunderingLevel > 0) {
ppe.mcdw$setThunderingLevel(thunderingLevel);
}
int voidShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.VOID_SHOT, itemStack);
if (voidShotLevel > 0) {
ppe.mcdw$setVoidShotLevel(voidShotLevel);
}
int wildRageLevel = EnchantmentHelper.getLevel(EnchantsRegistry.WILD_RAGE, itemStack);
if (wildRageLevel > 0){
ppe.mcdw$setWildRageLevel(wildRageLevel);
}
}
}
10 changes: 10 additions & 0 deletions src/main/java/chronosacaria/mcdw/effects/EnchantmentEffects.java
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,16 @@ public static void applyFuseShot(LivingEntity shooter, LivingEntity target, Pers
}
}

public static void applyFreezingShot(LivingEntity target, PersistentProjectileEntity ppe) {
int freezingLevel = ((IMcdwEnchantedArrow) ppe).mcdw$getFreezingLevel();
if (freezingLevel > 0) {

if (CleanlinessHelper.percentToOccur(CONFIG.mcdwEnchantmentsConfig.ENCHANTMENT_CONFIG.get(EnchantmentsID.FREEZING).mcdw$getProcChance() + (10 * freezingLevel))) {
AbilityHelper.causeFreezing(target, 100);
}
}
}

public static void applyGravityShot(LivingEntity shooter, LivingEntity target, PersistentProjectileEntity ppe) {
int gravityLevel = ((IMcdwEnchantedArrow) ppe).mcdw$getGravityLevel();
if (gravityLevel > 0) {
Expand Down
75 changes: 2 additions & 73 deletions src/main/java/chronosacaria/mcdw/mixin/mcdw/BowItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import chronosacaria.mcdw.Mcdw;
import chronosacaria.mcdw.api.interfaces.IMcdwEnchantedArrow;
import chronosacaria.mcdw.api.util.CleanlinessHelper;
import chronosacaria.mcdw.api.util.ProjectileEffectHelper;
import chronosacaria.mcdw.api.util.RangedAttackHelper;
import chronosacaria.mcdw.bases.McdwBow;
Expand Down Expand Up @@ -85,79 +86,7 @@ public void setLivingEntity(LivingEntity livingEntity){
if (overcharge > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setOvercharge(overcharge);
}

int chainReactionLevel = EnchantmentHelper.getLevel(EnchantsRegistry.CHAIN_REACTION, stack);
if (chainReactionLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setChainReactionLevel(chainReactionLevel);
}
int chargeLevel = EnchantmentHelper.getLevel(EnchantsRegistry.CHARGE, stack);
if (chargeLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setChargeLevel(chargeLevel);
}
int cobwebShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.COBWEB_SHOT, stack);
if (cobwebShotLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setCobwebShotLevel(cobwebShotLevel);
}
int dynamoLevel = EnchantmentHelper.getLevel(EnchantsRegistry.DYNAMO, stack);
if (dynamoLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setDynamoLevel(dynamoLevel);
}
int enigmaResonatorLevel = EnchantmentHelper.getLevel(EnchantsRegistry.ENIGMA_RESONATOR, stack);
if (enigmaResonatorLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setEnigmaResonatorLevel(enigmaResonatorLevel);
}
int fuseShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.FUSE_SHOT, stack);
if (fuseShotLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setFuseShotLevel(fuseShotLevel);
}
int gravityLevel = EnchantmentHelper.getLevel(EnchantsRegistry.GRAVITY, stack);
if (gravityLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setGravityLevel(gravityLevel);
}
int growingLevel = EnchantmentHelper.getLevel(EnchantsRegistry.GROWING, stack);
if (growingLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setGrowingLevel(growingLevel);
}
int levitationShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.LEVITATION_SHOT, stack);
if (levitationShotLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setLevitationShotLevel(levitationShotLevel);
}
int phantomsMarkLevel = EnchantmentHelper.getLevel(EnchantsRegistry.PHANTOMS_MARK, stack);
if (phantomsMarkLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setPhantomsMarkLevel(phantomsMarkLevel);
}
int poisonCloudLevel = EnchantmentHelper.getLevel(EnchantsRegistry.POISON_CLOUD, stack);
if (poisonCloudLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setPoisonCloudLevel(poisonCloudLevel);
}
int radianceLevel = EnchantmentHelper.getLevel(EnchantsRegistry.RADIANCE, stack);
if (radianceLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setRadianceLevel(radianceLevel);
}
int replenishLevel = EnchantmentHelper.getLevel(EnchantsRegistry.REPLENISH, stack);
if (replenishLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setReplenishLevel(replenishLevel);
}
int ricochetLevel = EnchantmentHelper.getLevel(EnchantsRegistry.RICOCHET, stack);
if (ricochetLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setRicochetLevel(ricochetLevel);
}
int tempoTheftLevel = EnchantmentHelper.getLevel(EnchantsRegistry.TEMPO_THEFT, stack);
if (tempoTheftLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setTempoTheftLevel(tempoTheftLevel);
}
//int thunderingLevel = EnchantmentHelper.getLevel(EnchantsRegistry.THUNDERING, stack);
//if (thunderingLevel > 0) {
// ((IMcdwEnchantedArrow)ppe).mcdw$setThunderingLevel(thunderingLevel);
//}
int voidShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.VOID_SHOT, stack);
if (voidShotLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setVoidShotLevel(voidShotLevel);
}
int wildRageLevel = EnchantmentHelper.getLevel(EnchantsRegistry.WILD_RAGE, stack);
if (wildRageLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setWildRageLevel(wildRageLevel);
}
CleanlinessHelper.addPPEEnchantments(stack, (IMcdwEnchantedArrow) ppe);
}

@Inject(method = "onStoppedUsing", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/BowItem;getMaxUseTime(Lnet/minecraft/item/ItemStack;)I"))
Expand Down
83 changes: 5 additions & 78 deletions src/main/java/chronosacaria/mcdw/mixin/mcdw/CrossbowItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import chronosacaria.mcdw.Mcdw;
import chronosacaria.mcdw.api.interfaces.IMcdwEnchantedArrow;
import chronosacaria.mcdw.api.util.CleanlinessHelper;
import chronosacaria.mcdw.api.util.ProjectileEffectHelper;
import chronosacaria.mcdw.api.util.RangedAttackHelper;
import chronosacaria.mcdw.bases.McdwCrossbow;
Expand Down Expand Up @@ -46,86 +47,11 @@ public class CrossbowItemMixin {
CallbackInfoReturnable<PersistentProjectileEntity> cir, ArrowItem arrowItem,
PersistentProjectileEntity ppe){
if (CrossbowItem.isCharged(crossbow)) {

int chainReactionLevel = EnchantmentHelper.getLevel(EnchantsRegistry.CHAIN_REACTION, crossbow);
if (chainReactionLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setChainReactionLevel(chainReactionLevel);
}
int chargeLevel = EnchantmentHelper.getLevel(EnchantsRegistry.CHARGE, crossbow);
if (chargeLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setChargeLevel(chargeLevel);
}
int cobwebShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.COBWEB_SHOT, crossbow);
if (cobwebShotLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setCobwebShotLevel(cobwebShotLevel);
}
int dynamoLevel = EnchantmentHelper.getLevel(EnchantsRegistry.DYNAMO, crossbow);
if (dynamoLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setDynamoLevel(dynamoLevel);
}
int enigmaResonatorLevel = EnchantmentHelper.getLevel(EnchantsRegistry.ENIGMA_RESONATOR, crossbow);
if (enigmaResonatorLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setEnigmaResonatorLevel(enigmaResonatorLevel);
}
int fuseShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.FUSE_SHOT, crossbow);
if (fuseShotLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setFuseShotLevel(fuseShotLevel);
}
int gravityLevel = EnchantmentHelper.getLevel(EnchantsRegistry.GRAVITY, crossbow);
if (gravityLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setGravityLevel(gravityLevel);
}
int growingLevel = EnchantmentHelper.getLevel(EnchantsRegistry.GROWING, crossbow);
if (growingLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setGrowingLevel(growingLevel);
}
int levitationShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.LEVITATION_SHOT, crossbow);
if (levitationShotLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setLevitationShotLevel(levitationShotLevel);
}
CleanlinessHelper.addPPEEnchantments(crossbow, (IMcdwEnchantedArrow) ppe);
// For Drag in Water for Nautilus Crossbow
((IMcdwEnchantedArrow)ppe).mcdw$setNautilusBoolean(crossbow.isOf(ItemsRegistry.CROSSBOW_ITEMS.get(CrossbowsID.CROSSBOW_NAUTICAL_CROSSBOW)));
int phantomsMarkLevel = EnchantmentHelper.getLevel(EnchantsRegistry.PHANTOMS_MARK, crossbow);
if (phantomsMarkLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setPhantomsMarkLevel(phantomsMarkLevel);
}
int poisonCloudLevel = EnchantmentHelper.getLevel(EnchantsRegistry.POISON_CLOUD, crossbow);
if (poisonCloudLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setPoisonCloudLevel(poisonCloudLevel);
}
int radianceLevel = EnchantmentHelper.getLevel(EnchantsRegistry.RADIANCE, crossbow);
if (radianceLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setRadianceLevel(radianceLevel);
}
int replenishLevel = EnchantmentHelper.getLevel(EnchantsRegistry.REPLENISH, crossbow);
if (replenishLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setReplenishLevel(replenishLevel);
}
int ricochetLevel = EnchantmentHelper.getLevel(EnchantsRegistry.RICOCHET, crossbow);
if (ricochetLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setRicochetLevel(ricochetLevel);
}
((IMcdwEnchantedArrow)ppe).mcdw$setShadowBarbBoolean(crossbow.isOf(ItemsRegistry.CROSSBOW_ITEMS.get(CrossbowsID.CROSSBOW_VEILED_CROSSBOW)));
int shadowShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.SHADOW_SHOT, crossbow);
if (shadowShotLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setShadowShotLevel(shadowShotLevel);
}
int tempoTheftLevel = EnchantmentHelper.getLevel(EnchantsRegistry.TEMPO_THEFT, crossbow);
if (tempoTheftLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setTempoTheftLevel(tempoTheftLevel);
}
int thunderingLevel = EnchantmentHelper.getLevel(EnchantsRegistry.THUNDERING, crossbow);
if (thunderingLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setThunderingLevel(thunderingLevel);
}
int voidShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.VOID_SHOT, crossbow);
if (voidShotLevel > 0) {
((IMcdwEnchantedArrow)ppe).mcdw$setVoidShotLevel(voidShotLevel);
}
int wildRageLevel = EnchantmentHelper.getLevel(EnchantsRegistry.WILD_RAGE, crossbow);
if (wildRageLevel > 0){
((IMcdwEnchantedArrow)ppe).mcdw$setWildRageLevel(wildRageLevel);
}


if (Mcdw.CONFIG.mcdwEnchantmentsConfig.ENCHANTMENT_CONFIG.get(EnchantmentsID.BONUS_SHOT).mcdw$getIsEnabled()) {
int bonusShotLevel = EnchantmentHelper.getLevel(EnchantsRegistry.BONUS_SHOT, crossbow);
Expand All @@ -139,7 +65,8 @@ public class CrossbowItemMixin {
}
}
}



@Inject(method = "onStoppedUsing", at = @At(value = "HEAD"))
private void mcdw$livingEntityGetter(ItemStack stack, World world, LivingEntity user, int remainingUseTicks, CallbackInfo ci) {
this.mcdw$setLivingEntity(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.PotionItem;
import net.minecraft.potion.PotionUtil;
import net.minecraft.potion.Potions;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -47,6 +48,7 @@
@SuppressWarnings("ConstantValue")
@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin extends Entity {

@Unique
public final EntityType<SummonedBeeEntity> mcdw$summoned_bee =
SummonedEntityRegistry.SUMMONED_BEE_ENTITY;
Expand Down Expand Up @@ -162,10 +164,18 @@ public LivingEntityMixin(EntityType<?> type, World world) {
ItemStack poisonTippedArrow = PotionUtil.setPotion(new ItemStack(Items.TIPPED_ARROW, 8), Potions.POISON);

if (Mcdw.CONFIG.mcdwEnchantmentsConfig.ENCHANTMENT_CONFIG.get(EnchantmentsID.DIPPING_POISON).mcdw$getIsEnabled()) {
if (user.getOffHandStack() != null && (EnchantmentHelper.getLevel(EnchantsRegistry.DIPPING_POISON, user.getOffHandStack()) > 0)) {
if (!(user.getMainHandStack().getItem() instanceof PotionItem))
return;

if (user.getOffHandStack() != null
&& (EnchantmentHelper.getLevel(EnchantsRegistry.DIPPING_POISON, user.getOffHandStack()) > 0)
) {
int level = EnchantmentHelper.getLevel(EnchantsRegistry.DIPPING_POISON, user.getOffHandStack());
if (level > 0) {
List<StatusEffectInstance> potionEffects = PotionUtil.getPotionEffects(user.getMainHandStack());
if (!(potionEffects.get(0).getEffectType() == StatusEffects.INSTANT_HEALTH)) {
return;
}
if (potionEffects.get(0).getEffectType() == StatusEffects.INSTANT_HEALTH) {
CleanlinessHelper.mcdw$dropItem(user, poisonTippedArrow);
}
Expand Down
Loading

0 comments on commit ce0b1e7

Please sign in to comment.