Skip to content

Commit

Permalink
Enchantment changes and fixes for Beta 12
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandra-Myers committed Aug 22, 2023
1 parent c6713f3 commit a94496f
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 58 deletions.

This file was deleted.

18 changes: 18 additions & 0 deletions src/main/java/net/atlas/combatify/mixin/EnchantCommandMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.atlas.combatify.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import net.atlas.combatify.extensions.CustomEnchantment;
import net.minecraft.server.commands.EnchantCommand;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(EnchantCommand.class)
public class EnchantCommandMixin {
@ModifyExpressionValue(method = "enchant", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/enchantment/Enchantment;canEnchant(Lnet/minecraft/world/item/ItemStack;)Z"))
private static boolean redirectCanEnchant(boolean original, @Local(ordinal = 0) Enchantment currentEnchantment, @Local(ordinal = 0) ItemStack itemStack) {
return currentEnchantment instanceof CustomEnchantment customEnchantment && itemStack != null ? customEnchantment.isAcceptibleConditions(itemStack) : original;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,15 @@
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import net.atlas.combatify.extensions.CustomEnchantment;
import net.atlas.combatify.extensions.IEnchantmentHelper;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobType;
import net.atlas.combatify.util.CustomEnchantmentHelper;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;

import static net.minecraft.world.item.enchantment.EnchantmentHelper.getItemEnchantmentLevel;

@Mixin(EnchantmentHelper.class)
public abstract class EnchantmentHelperMixin implements IEnchantmentHelper {
@Shadow
public static float getDamageBonus(ItemStack par1, MobType par2) {
return 0;
}

@Override
public float getDamageBonus(ItemStack level, LivingEntity entity){
if(entity.getMobType() == MobType.WATER || entity.isInWaterOrRain()) {
return getDamageBonus(level, MobType.WATER);
}
return getDamageBonus(level, entity.getMobType());
}

@Override
public float getKnockbackDebuff(ItemStack level, LivingEntity entity){
return getDamageBonus(level, MobType.WATER)/2.5F;
}
@Override
public int getFullEnchantmentLevel(Enchantment enchantment, LivingEntity entity) {
Iterable<ItemStack> iterable = enchantment.getSlotItems(entity).values();
int i = 0;

for(ItemStack itemStack : iterable) {
int j = getItemEnchantmentLevel(enchantment, itemStack);
i += j;
}

return i;
}
public abstract class EnchantmentHelperMixin implements CustomEnchantmentHelper {
@ModifyExpressionValue(method = "getAvailableEnchantmentResults", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/enchantment/EnchantmentCategory;canEnchant(Lnet/minecraft/world/item/Item;)Z"))
private static boolean redirectCanEnchant(boolean original, @Local(ordinal = 0) Enchantment currentEnchantment, @Local(ordinal = 0) ItemStack itemStack) {
return currentEnchantment instanceof CustomEnchantment customEnchantment && itemStack != null ? customEnchantment.isAcceptibleConditions(itemStack) : original;
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/net/atlas/combatify/mixin/MobMixin.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package net.atlas.combatify.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import net.atlas.combatify.extensions.IEnchantmentHelper;
import net.atlas.combatify.util.CustomEnchantmentHelper;
import net.atlas.combatify.extensions.LivingEntityExtensions;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
Expand All @@ -17,8 +16,7 @@
public class MobMixin {
@Redirect(method = "doHurtTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/enchantment/EnchantmentHelper;getDamageBonus(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/entity/MobType;)F"))
public float getDamageBonus(ItemStack itemStack, MobType mobType, @Local(ordinal = 0) Entity entity) {
EnchantmentHelper helper = new EnchantmentHelper();
return ((IEnchantmentHelper)helper).getDamageBonus(itemStack, (LivingEntity) entity);
return CustomEnchantmentHelper.getDamageBonus(itemStack, (LivingEntity) entity);
}
@Redirect(method = "doHurtTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;knockback(DDD)V"))
public void knockback(LivingEntity instance, double d, double e, double f) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/atlas/combatify/mixin/PlayerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.atlas.combatify.Combatify;
import net.atlas.combatify.config.CombatifyConfig;
import net.atlas.combatify.item.NewAttributes;
import net.atlas.combatify.util.CustomEnchantmentHelper;
import net.atlas.combatify.util.UtilClass;
import net.atlas.combatify.extensions.*;
import net.minecraft.core.particles.ParticleTypes;
Expand Down Expand Up @@ -149,8 +150,7 @@ public void doThings(Entity target, CallbackInfo ci, @Local(ordinal = 0) LocalFl
if(bl)
((LivingEntityExtensions)livingEntity).setEnemy(player);
if(player.getItemInHand(InteractionHand.MAIN_HAND).getItem() instanceof TridentItem && bl) {
EnchantmentHelper helper = new EnchantmentHelper();
attackDamageBonus.set(((IEnchantmentHelper)helper).getDamageBonus(player.getMainHandItem(), livingEntity));
attackDamageBonus.set(CustomEnchantmentHelper.getDamageBonus(player.getMainHandItem(), livingEntity));
}
attackDamage.set((float) ((IAttributeInstance) Objects.requireNonNull(player.getAttribute(Attributes.ATTACK_DAMAGE))).calculateValue(attackDamageBonus.get()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package net.atlas.combatify.mixin;

import net.atlas.combatify.extensions.IEnchantmentHelper;
import net.atlas.combatify.util.CustomEnchantmentHelper;
import net.atlas.combatify.extensions.IThrownTrident;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.entity.projectile.ThrownTrident;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec3;
Expand Down Expand Up @@ -75,8 +74,7 @@ public void extractTarget(EntityHitResult p_37573_, CallbackInfo ci) {
}
@Redirect(method = "onHitEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/enchantment/EnchantmentHelper;getDamageBonus(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/entity/MobType;)F"))
public float dealtDamage(ItemStack p_44834_, MobType p_44835_) {
EnchantmentHelper helper = new EnchantmentHelper();
return ((IEnchantmentHelper)helper).getDamageBonus(this.tridentItem, livingEntity);
return CustomEnchantmentHelper.getDamageBonus(this.tridentItem, livingEntity);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package net.atlas.combatify.util;

import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;

import static net.minecraft.world.item.enchantment.EnchantmentHelper.getItemEnchantmentLevel;

public interface CustomEnchantmentHelper {
static float getDamageBonus(ItemStack level, LivingEntity entity) {
if(entity.getMobType() == MobType.WATER || entity.isInWaterOrRain()) {
return EnchantmentHelper.getDamageBonus(level, MobType.WATER);
}
return EnchantmentHelper.getDamageBonus(level, entity.getMobType());
}
static float getKnockbackDebuff(ItemStack level, LivingEntity entity) {
return getDamageBonus(level, entity) / 2.5F;
}

static int getFullEnchantmentLevel(Enchantment enchantment, LivingEntity entity) {
Iterable<ItemStack> iterable = enchantment.getSlotItems(entity).values();
int i = 0;

for(ItemStack itemStack : iterable) {
int j = getItemEnchantmentLevel(enchantment, itemStack);
i += j;
}

return i;
}
}
1 change: 1 addition & 0 deletions src/main/resources/combatify.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"EffectsMixin",
"EggItemMixin",
"EggMixin",
"EnchantCommandMixin",
"EnchantmentHelperMixin",
"EnchantmentMixin",
"EnchantmentsMixin",
Expand Down

0 comments on commit a94496f

Please sign in to comment.