Skip to content

Commit

Permalink
Combatify 1.1.8.2 1.20.5 - Fixed eating interruption on potions & imp…
Browse files Browse the repository at this point in the history
…roved enchants
  • Loading branch information
Alexandra-Myers committed Feb 12, 2024
1 parent 2914071 commit acc4937
Show file tree
Hide file tree
Showing 20 changed files with 149 additions and 135 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs = -Xmx3G
org.gradle.parallel = true

# Mod Properties
version = 1.20.5-1.1.8.1
version = 1.20.5-1.1.8.2
maven_group = net.atlas
archives_base_name = combatify
owo_version=0.11.0+1.20
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package net.atlas.combatify.enchantment;

import net.atlas.combatify.extensions.CustomEnchantment;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.DamageEnchantment;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.TridentImpalerEnchantment;

public class CleavingEnchantment extends Enchantment implements CustomEnchantment {
public class CleavingEnchantment extends Enchantment {
public int level;

public CleavingEnchantment() {
Expand Down Expand Up @@ -37,16 +35,6 @@ public float getDamageBonus(int level, EntityType<?> group) {
return (float)1 + level;
}

@Override
public boolean isAcceptibleConditions(ItemStack stack) {
return this.canEnchant(stack);
}

@Override
public boolean isAcceptibleAnvil(ItemStack stack) {
return this.canEnchant(stack);
}

@Override
protected boolean checkCompatibility(Enchantment enchantment) {
return super.checkCompatibility(enchantment) && !(enchantment instanceof PiercingEnchantment || enchantment instanceof DamageEnchantment || enchantment instanceof TridentImpalerEnchantment);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.atlas.combatify.enchantment;

import net.atlas.combatify.Combatify;
import net.atlas.combatify.extensions.CustomEnchantment;
import net.atlas.combatify.extensions.ItemExtensions;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.entity.EquipmentSlot;
Expand All @@ -10,7 +9,7 @@

import static net.atlas.combatify.Combatify.id;

public class DefendingEnchantment extends Enchantment implements CustomEnchantment {
public class DefendingEnchantment extends Enchantment {
public static final Enchantment DEFENDER = EnchantmentRegistry.registerEnchant(id("defender"), new DefendingEnchantment());

public DefendingEnchantment() {
Expand All @@ -32,15 +31,6 @@ public boolean canEnchant(ItemStack stack) {
return !((ItemExtensions) stack.getItem()).getBlockingType().isEmpty() && (!((ItemExtensions)stack.getItem()).getBlockingType().requiresSwordBlocking() || Combatify.CONFIG.swordBlocking());
}

@Override
public boolean isAcceptibleConditions(ItemStack stack) {
return this.canEnchant(stack);
}

@Override
public boolean isAcceptibleAnvil(ItemStack stack) {
return this.canEnchant(stack);
}
public static void registerEnchants() {

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.atlas.combatify.enchantment;

import net.atlas.combatify.extensions.CustomEnchantment;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ItemStack;
Expand All @@ -12,11 +11,11 @@

import static net.atlas.combatify.Combatify.id;

public class PiercingEnchantment extends Enchantment implements CustomEnchantment {
public class PiercingEnchantment extends Enchantment {
public static final Enchantment PIERCER = EnchantmentRegistry.registerEnchant(id("piercer"), new PiercingEnchantment());

public PiercingEnchantment() {
super(Rarity.VERY_RARE, ItemTags.WEAPON_ENCHANTABLE, new EquipmentSlot[]{EquipmentSlot.MAINHAND});
super(Rarity.RARE, ItemTags.WEAPON_ENCHANTABLE, new EquipmentSlot[]{EquipmentSlot.MAINHAND});
}

@Override
Expand All @@ -39,16 +38,6 @@ public boolean canEnchant(ItemStack stack) {
return stack.getItem() instanceof TieredItem || stack.getItem() instanceof TridentItem;
}

@Override
public boolean isAcceptibleConditions(ItemStack stack) {
return this.canEnchant(stack);
}

@Override
public boolean isAcceptibleAnvil(ItemStack stack) {
return this.canEnchant(stack);
}

@Override
protected boolean checkCompatibility(Enchantment enchantment) {
return super.checkCompatibility(enchantment) && !(enchantment instanceof CleavingEnchantment || enchantment instanceof DamageEnchantment || enchantment instanceof TridentImpalerEnchantment);
Expand Down

This file was deleted.

5 changes: 1 addition & 4 deletions src/main/java/net/atlas/combatify/item/WeaponType.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,7 @@ public boolean hasSwordEnchants() {
if (configurableWeaponData.hasSwordEnchants != null)
return configurableWeaponData.hasSwordEnchants;
}
return switch (this) {
case SWORD, AXE, LONGSWORD, KNIFE -> true;
default -> false;
};
return false;
}
public boolean isEmpty() {
return this == EMPTY;
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/net/atlas/combatify/mixin/AnvilMenuMixin.java

This file was deleted.

19 changes: 0 additions & 19 deletions src/main/java/net/atlas/combatify/mixin/EnchantCommandMixin.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@
import com.llamalad7.mixinextras.sugar.Local;
import net.atlas.combatify.Combatify;
import net.atlas.combatify.config.ConfigurableItemData;
import net.atlas.combatify.extensions.CustomEnchantment;
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.injection.At;

@SuppressWarnings("unused")
@Mixin(EnchantmentHelper.class)
public abstract class EnchantmentHelperMixin {
@ModifyExpressionValue(method = "getAvailableEnchantmentResults", 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, argsOnly = true) ItemStack itemStack) {
return itemStack != null ? original || ((CustomEnchantment)currentEnchantment).isAcceptibleConditions(itemStack) : original;
}

@ModifyExpressionValue(method = "getEnchantmentCost", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/Item;getEnchantmentValue()I"))
private static int getEnchantmentValue(int original, @Local(ordinal = 0, argsOnly = true) ItemStack stack) {
if(Combatify.ITEMS != null && Combatify.ITEMS.configuredItems.containsKey(stack.getItem())) {
Expand Down
34 changes: 2 additions & 32 deletions src/main/java/net/atlas/combatify/mixin/EnchantmentMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.atlas.combatify.Combatify;
import net.atlas.combatify.config.ConfigurableItemData;
import net.atlas.combatify.extensions.CustomEnchantment;
import net.atlas.combatify.extensions.WeaponWithType;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagKey;
Expand All @@ -16,10 +15,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Enchantment.class)
public abstract class EnchantmentMixin implements CustomEnchantment {
@Shadow
public abstract boolean canEnchant(ItemStack stack);

public abstract class EnchantmentMixin {
@Shadow
@Final
private TagKey<Item> match;
Expand All @@ -34,33 +30,7 @@ public void canEnchant(ItemStack stack, CallbackInfoReturnable<Boolean> cir) {
if (configurableItemData.hasSwordEnchants != null)
hasSwordEnchants = configurableItemData.hasSwordEnchants;
}
if (match.equals(ItemTags.WEAPON_ENCHANTABLE) && hasSwordEnchants)
if ((match.equals(ItemTags.SWORD_ENCHANTABLE) || match.equals(ItemTags.WEAPON_ENCHANTABLE)) && hasSwordEnchants)
cir.setReturnValue(true);
}

@Override
public boolean isAcceptibleConditions(ItemStack stack) {
boolean hasSwordEnchants = false;
if (stack.getItem() instanceof WeaponWithType weaponWithType)
hasSwordEnchants = weaponWithType.getWeaponType().hasSwordEnchants();
if (Combatify.ITEMS != null && Combatify.ITEMS.configuredItems.containsKey(stack.getItem())) {
ConfigurableItemData configurableItemData = Combatify.ITEMS.configuredItems.get(stack.getItem());
if (configurableItemData.hasSwordEnchants != null)
hasSwordEnchants = configurableItemData.hasSwordEnchants;
}
return stack.is(match) || (match.equals(ItemTags.WEAPON_ENCHANTABLE) && hasSwordEnchants);
}

@Override
public boolean isAcceptibleAnvil(ItemStack stack) {
boolean hasSwordEnchants = false;
if (stack.getItem() instanceof WeaponWithType weaponWithType)
hasSwordEnchants = weaponWithType.getWeaponType().hasSwordEnchants();
if (Combatify.ITEMS != null && Combatify.ITEMS.configuredItems.containsKey(stack.getItem())) {
ConfigurableItemData configurableItemData = Combatify.ITEMS.configuredItems.get(stack.getItem());
if (configurableItemData.hasSwordEnchants != null)
hasSwordEnchants = configurableItemData.hasSwordEnchants;
}
return canEnchant(stack) || (match.equals(ItemTags.WEAPON_ENCHANTABLE) && hasSwordEnchants);
}
}
18 changes: 12 additions & 6 deletions src/main/java/net/atlas/combatify/mixin/LivingEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public LivingEntityMixin(EntityType<?> entityType, Level level) {
@Shadow
protected int useItemRemaining;

@Shadow
public abstract ItemStack getUseItem();

@SuppressWarnings("unused")
@ModifyReturnValue(method = "isBlocking", at = @At(value="RETURN"))
public boolean isBlocking(boolean original) {
Expand Down Expand Up @@ -188,12 +191,15 @@ public int changeIFrames(int constant, @Local(ordinal = 0, argsOnly = true) fina
}
@Inject(method = "hurt", at = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/LivingEntity;invulnerableTime:I", ordinal = 0))
public void injectEatingInterruption(DamageSource source, float f, CallbackInfoReturnable<Boolean> cir) {
if(thisEntity.isUsingItem() && thisEntity.getUseItem().isEdible() && !source.is(DamageTypeTags.IS_FIRE) && !source.is(DamageTypeTags.WITCH_RESISTANT_TO) && !source.is(DamageTypeTags.IS_FALL) && !source.is(DamageTypes.STARVE) && Combatify.CONFIG.eatingInterruption()) {
useItemRemaining = thisEntity.getUseItem().getUseDuration();
if (level() instanceof ServerLevel serverLevel)
for (UUID playerUUID : Combatify.moddedPlayers)
if (serverLevel.getPlayerByUUID(playerUUID) instanceof ServerPlayer serverPlayer)
ServerPlayNetworking.send(serverPlayer, new NetworkingHandler.RemainingUseSyncPacket(getId(), useItemRemaining));
Entity entity = source.getEntity();
if (entity instanceof LivingEntity) {
if (thisEntity.isUsingItem() && (getUseItem().getUseAnimation() == UseAnim.EAT || getUseItem().getUseAnimation() == UseAnim.DRINK) && Combatify.CONFIG.eatingInterruption()) {
useItemRemaining = thisEntity.getUseItem().getUseDuration();
if (level() instanceof ServerLevel serverLevel)
for (UUID playerUUID : Combatify.moddedPlayers)
if (serverLevel.getPlayerByUUID(playerUUID) instanceof ServerPlayer serverPlayer)
ServerPlayNetworking.send(serverPlayer, new NetworkingHandler.RemainingUseSyncPacket(getId(), useItemRemaining));
}
}
}
@ModifyExpressionValue(method = "hurt", at = @At(value = "CONSTANT", args = "floatValue=10.0F", ordinal = 0))
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/atlas/combatify/mixin/PlayerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ public void injectCrit(Entity target, CallbackInfo ci, @Local(ordinal = 0) Local
bl3.set(isCrit);
if (isCrit)
attackDamage.set(attackDamage.get() * 1.5F);

}
@Redirect(method = "attack", 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 Expand Up @@ -231,6 +230,7 @@ public void attackAir() {
double var5 = (-Mth.sin(player.yBodyRot * 0.017453292F)) * 2.0;
double var7 = Mth.cos(player.yBodyRot * 0.017453292F) * 2.0;
AABB var9 = player.getBoundingBox().inflate(1.0, 0.25, 1.0).move(var5, 0.0, var7);
Combatify.LOGGER.info("Swept");
betterSweepAttack(var9, var2, attackDamage, null);
}

Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/combatify.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
"compatibilityLevel": "JAVA_17",
"mixins": [
"AbstractWindChargeMixin",
"AnvilMenuMixin",
"AttributeModifierMixin",
"AxeItemMixin",
"BowItemMixin",
"ClientboundUpdateAttributesPacketMixin",
"DiggerItemMixin",
"EggMixin",
"EnchantCommandMixin",
"EnchantmentHelperMixin",
"EnchantmentMixin",
"EnchantmentsMixin",
Expand Down
29 changes: 29 additions & 0 deletions src/main/resources/data/combatify/tags/items/knives.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"replace": false,
"values": [
{
"id": "combatify:wooden_knife",
"required": false
},
{
"id": "combatify:stone_knife",
"required": false
},
{
"id": "combatify:golden_knife",
"required": false
},
{
"id": "combatify:iron_knife",
"required": false
},
{
"id": "combatify:diamond_knife",
"required": false
},
{
"id": "combatify:netherite_knife",
"required": false
}
]
}
29 changes: 29 additions & 0 deletions src/main/resources/data/combatify/tags/items/longswords.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"replace": false,
"values": [
{
"id": "combatify:wooden_longsword",
"required": false
},
{
"id": "combatify:stone_longsword",
"required": false
},
{
"id": "combatify:golden_longsword",
"required": false
},
{
"id": "combatify:iron_longsword",
"required": false
},
{
"id": "combatify:diamond_longsword",
"required": false
},
{
"id": "combatify:netherite_longsword",
"required": false
}
]
}
25 changes: 25 additions & 0 deletions src/main/resources/data/combatify/tags/items/tiered_shields.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"replace": false,
"values": [
{
"id": "combatify:wooden_shield",
"required": false
},
{
"id": "combatify:golden_shield",
"required": false
},
{
"id": "combatify:iron_shield",
"required": false
},
{
"id": "combatify:diamond_shield",
"required": false
},
{
"id": "combatify:netherite_shield",
"required": false
}
]
}
Loading

0 comments on commit acc4937

Please sign in to comment.