diff --git a/src/main/java/com/bibireden/data_attributes/api/item/ItemHelper.java b/src/main/java/com/bibireden/data_attributes/api/item/ItemHelper.java index 92bc51b9..daa124cd 100644 --- a/src/main/java/com/bibireden/data_attributes/api/item/ItemHelper.java +++ b/src/main/java/com/bibireden/data_attributes/api/item/ItemHelper.java @@ -23,8 +23,7 @@ public interface ItemHelper { * @param itemStack * @param count */ - default void onStackCreated(final ItemStack itemStack, final int count) { - } + default void onStackCreated(final ItemStack itemStack, final int count) {} /** * ItemStack dependent version of SwordItem#getAttackDamage and @@ -34,9 +33,7 @@ default void onStackCreated(final ItemStack itemStack, final int count) { * @param itemStack * @return */ - default float getAttackDamage(final ItemStack itemStack) { - return 0.0F; - } + default Float getAttackDamage(final ItemStack itemStack) { return null; } /** * ItemStack dependent version of ArmorItem#getProtection. Default @@ -45,19 +42,19 @@ default float getAttackDamage(final ItemStack itemStack) { * @param itemStack * @return */ - default int getProtection(final ItemStack itemStack) { - return 0; + default Integer getProtection(final ItemStack itemStack) { + return null; } /** * ItemStack dependent version of ArmorItem#getToughness. Default implementation - * returns aforementioned. + * returns the aforementioned. * * @param itemStack * @return */ - default float getToughness(final ItemStack itemStack) { - return 0.0F; + default Float getToughness(final ItemStack itemStack) { + return null; } /** diff --git a/src/main/java/com/bibireden/data_attributes/mixin/MobEntityMixin.java b/src/main/java/com/bibireden/data_attributes/mixin/MobEntityMixin.java index d534a629..daaa9838 100644 --- a/src/main/java/com/bibireden/data_attributes/mixin/MobEntityMixin.java +++ b/src/main/java/com/bibireden/data_attributes/mixin/MobEntityMixin.java @@ -17,82 +17,98 @@ @Mixin(MobEntity.class) abstract class MobEntityMixin { @ModifyExpressionValue(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/SwordItem;getAttackDamage()F", ordinal = 0)) - private float data_getAttackDamage_0(float original, @Local(ordinal = 0) SwordItem swordItem, @Local(ordinal = 0, argsOnly = true) ItemStack newStack) { - return ((ItemHelper) swordItem).getAttackDamage(newStack); + private float data_attributes$getAttackDamage_0(float og, @Local(ordinal = 0) SwordItem swordItem, @Local(ordinal = 0, argsOnly = true) ItemStack newStack) { + Float value = ((ItemHelper) swordItem).getAttackDamage(newStack); + return value != null ? value : og; } @ModifyExpressionValue(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/SwordItem;getAttackDamage()F", ordinal = 1)) - private float data_getAttackDamage_1(float original, @Local(ordinal = 1) SwordItem swordItem2, @Local(ordinal = 1, argsOnly = true) ItemStack oldStack) { - return ((ItemHelper) swordItem2).getAttackDamage(oldStack); + private float data_attributes$getAttackDamage_1(float og, @Local(ordinal = 1) SwordItem swordItem2, @Local(ordinal = 1, argsOnly = true) ItemStack oldStack) { + Float value = ((ItemHelper) swordItem2).getAttackDamage(oldStack); + return value != null ? value : og; } @ModifyExpressionValue(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/SwordItem;getAttackDamage()F", ordinal = 2)) - private float data_getAttackDamage_2(float original, @Local(ordinal = 0) SwordItem swordItem, @Local(ordinal = 0, argsOnly = true) ItemStack newStack) { - return ((ItemHelper) swordItem).getAttackDamage(newStack); + private float data_attributes$getAttackDamage_2(float og, @Local(ordinal = 0) SwordItem swordItem, @Local(ordinal = 0, argsOnly = true) ItemStack newStack) { + Float value = ((ItemHelper) swordItem).getAttackDamage(newStack); + return value != null ? value : og; } @ModifyExpressionValue(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/SwordItem;getAttackDamage()F", ordinal = 3)) - private float data_getAttackDamage_3(float original, @Local(ordinal = 1) SwordItem swordItem2, @Local(ordinal = 1, argsOnly = true) ItemStack oldStack) { - return ((ItemHelper) swordItem2).getAttackDamage(oldStack); + private float data_attributes$getAttackDamage_3(float og, @Local(ordinal = 1) SwordItem swordItem2, @Local(ordinal = 1, argsOnly = true) ItemStack oldStack) { + Float value = ((ItemHelper) swordItem2).getAttackDamage(oldStack); + return value != null ? value : og; } @ModifyExpressionValue(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ArmorItem;getProtection()I", ordinal = 0)) - private int data_getProtection_0(int og, @Local(ordinal = 0) ArmorItem armorItem, @Local(ordinal = 0, argsOnly = true) ItemStack newStack) { - return ((ItemHelper) armorItem).getProtection(newStack); + private int data_attributes$getProtection_0(int og, @Local(ordinal = 0) ArmorItem armorItem, @Local(ordinal = 0, argsOnly = true) ItemStack newStack) { + Integer value = ((ItemHelper) armorItem).getProtection(newStack); + return value != null ? value : og; } @ModifyExpressionValue(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ArmorItem;getProtection()I", ordinal = 1)) - private int data_getProtection_1(int og, @Local(ordinal = 1) ArmorItem armorItem2, @Local(ordinal = 1, argsOnly = true) ItemStack oldStack) { - return ((ItemHelper) armorItem2).getProtection(oldStack); + private int data_attributes$getProtection_1(int og, @Local(ordinal = 1) ArmorItem armorItem2, @Local(ordinal = 1, argsOnly = true) ItemStack oldStack) { + Integer value = ((ItemHelper) armorItem2).getProtection(oldStack); + return value != null ? value : og; } @ModifyExpressionValue(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ArmorItem;getProtection()I", ordinal = 2)) - private int data_getProtection_2(int og, @Local(ordinal = 0) ArmorItem armorItem, @Local(ordinal = 0, argsOnly = true) ItemStack newStack) { - return ((ItemHelper) armorItem).getProtection(newStack); + private int data_attributes$getProtection_2(int og, @Local(ordinal = 0) ArmorItem armorItem, @Local(ordinal = 0, argsOnly = true) ItemStack newStack) { + Integer value = ((ItemHelper) armorItem).getProtection(newStack); + return value != null ? value : og; } @ModifyExpressionValue(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ArmorItem;getProtection()I", ordinal = 3)) - private int data_getProtection_3(int og, @Local(ordinal = 1) ArmorItem armorItem2, @Local(ordinal = 1, argsOnly = true) ItemStack oldStack) { - return ((ItemHelper) armorItem2).getProtection(oldStack); + private int data_attributes$getProtection_3(int og, @Local(ordinal = 1) ArmorItem armorItem2, @Local(ordinal = 1, argsOnly = true) ItemStack oldStack) { + Integer value = ((ItemHelper) armorItem2).getProtection(oldStack); + return value != null ? value : og; } @ModifyExpressionValue(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ArmorItem;getToughness()F", ordinal = 0)) - private float data_getToughness_0(float og, @Local(ordinal = 0) ArmorItem armorItem, @Local(ordinal = 0, argsOnly = true) ItemStack newStack) { - return ((ItemHelper) armorItem).getToughness(newStack); + private float data_attributes$getToughness_0(float og, @Local(ordinal = 0) ArmorItem armorItem, @Local(ordinal = 0, argsOnly = true) ItemStack newStack) { + Float value = ((ItemHelper) armorItem).getToughness(newStack); + return value != null ? value : og; } @ModifyExpressionValue(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ArmorItem;getToughness()F", ordinal = 1)) - private float data_getToughness_1(float og, @Local(ordinal = 1) ArmorItem armorItem2, @Local(ordinal = 1, argsOnly = true) ItemStack oldStack) { - return ((ItemHelper) armorItem2).getToughness(oldStack); + private float data_attributes$getToughness_1(float og, @Local(ordinal = 1) ArmorItem armorItem2, @Local(ordinal = 1, argsOnly = true) ItemStack oldStack) { + Float value = ((ItemHelper) armorItem2).getToughness(oldStack); + return value != null ? value : og; } @ModifyExpressionValue(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ArmorItem;getToughness()F", ordinal = 2)) - private float data_getToughness_2(float og, @Local(ordinal = 0) ArmorItem armorItem, @Local(ordinal = 0, argsOnly = true) ItemStack newStack) { - return ((ItemHelper) armorItem).getToughness(newStack); + private float data_attributes$getToughness_2(float og, @Local(ordinal = 0) ArmorItem armorItem, @Local(ordinal = 0, argsOnly = true) ItemStack newStack) { + Float value = ((ItemHelper) armorItem).getToughness(newStack); + return value != null ? value : og; } @ModifyExpressionValue(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ArmorItem;getToughness()F", ordinal = 3)) - private float data_getToughness_3(float og, @Local(ordinal = 1) ArmorItem armorItem2, @Local(ordinal = 1, argsOnly = true) ItemStack oldStack) { - return ((ItemHelper) armorItem2).getToughness(oldStack); + private float data_attributes$getToughness_3(float og, @Local(ordinal = 1) ArmorItem armorItem2, @Local(ordinal = 1, argsOnly = true) ItemStack oldStack) { + Float value = ((ItemHelper) armorItem2).getToughness(oldStack); + return value != null ? value : og; } @ModifyExpressionValue(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/MiningToolItem;getAttackDamage()F", ordinal = 0)) - private float data_getAttackDamage_0(float og, @Local(ordinal = 0) MiningToolItem miningToolItem, @Local(ordinal = 0, argsOnly = true) ItemStack newStack) { - return ((ItemHelper) miningToolItem).getAttackDamage(newStack); + private float data_attributes$getAttackDamage_0(float og, @Local(ordinal = 0) MiningToolItem miningToolItem, @Local(ordinal = 0, argsOnly = true) ItemStack newStack) { + Float value = ((ItemHelper) miningToolItem).getAttackDamage(newStack); + return value != null ? value : og; } @ModifyExpressionValue(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/MiningToolItem;getAttackDamage()F", ordinal = 1)) - private float data_getAttackDamage_1(float og, @Local(ordinal = 1) MiningToolItem miningToolItem2, @Local(ordinal = 1, argsOnly = true) ItemStack oldStack) { - return ((ItemHelper) miningToolItem2).getAttackDamage(oldStack); + private float data_attributes$getAttackDamage_1(float og, @Local(ordinal = 1) MiningToolItem miningToolItem2, @Local(ordinal = 1, argsOnly = true) ItemStack oldStack) { + Float value = ((ItemHelper) miningToolItem2).getAttackDamage(oldStack); + return value != null ? value : og; } @ModifyExpressionValue(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/MiningToolItem;getAttackDamage()F", ordinal = 2)) - private float data_getAttackDamage_2(float og, @Local(ordinal = 0) MiningToolItem miningToolItem, @Local(ordinal = 0, argsOnly = true) ItemStack newStack) { - return ((ItemHelper) miningToolItem).getAttackDamage(newStack); + private float data_attributes$getAttackDamage_2(float og, @Local(ordinal = 0) MiningToolItem miningToolItem, @Local(ordinal = 0, argsOnly = true) ItemStack newStack) { + Float value = ((ItemHelper) miningToolItem).getAttackDamage(newStack); + return value != null ? value : og; } @ModifyExpressionValue(method = "prefersNewEquipment", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/MiningToolItem;getAttackDamage()F", ordinal = 3)) - private float data_getAttackDamage_3(float og, @Local(ordinal = 1) MiningToolItem miningToolItem2, @Local(ordinal = 1, argsOnly = true) ItemStack oldStack) { - return ((ItemHelper) miningToolItem2).getAttackDamage(oldStack); + private float data_attributes$getAttackDamage_3(float og, @Local(ordinal = 1) MiningToolItem miningToolItem2, @Local(ordinal = 1, argsOnly = true) ItemStack oldStack) { + Float value = ((ItemHelper) miningToolItem2).getAttackDamage(oldStack); + return value != null ? value : og; } } diff --git a/src/main/java/com/bibireden/data_attributes/mixin/item/ArmorItemMixin.java b/src/main/java/com/bibireden/data_attributes/mixin/item/ArmorItemMixin.java index 577a9b8f..71ee75eb 100644 --- a/src/main/java/com/bibireden/data_attributes/mixin/item/ArmorItemMixin.java +++ b/src/main/java/com/bibireden/data_attributes/mixin/item/ArmorItemMixin.java @@ -7,14 +7,13 @@ @Mixin(ArmorItem.class) abstract class ArmorItemMixin extends ItemMixin { - @Override - public int getProtection(final ItemStack itemStack) { + public Integer getProtection(final ItemStack itemStack) { return ((ArmorItem) (Object) this).getProtection(); } @Override - public float getToughness(final ItemStack itemStack) { + public Float getToughness(final ItemStack itemStack) { return ((ArmorItem) (Object) this).getToughness(); } } \ No newline at end of file diff --git a/src/main/java/com/bibireden/data_attributes/mixin/item/ItemMixin.java b/src/main/java/com/bibireden/data_attributes/mixin/item/ItemMixin.java index bc84977c..050d3495 100644 --- a/src/main/java/com/bibireden/data_attributes/mixin/item/ItemMixin.java +++ b/src/main/java/com/bibireden/data_attributes/mixin/item/ItemMixin.java @@ -1,6 +1,5 @@ package com.bibireden.data_attributes.mixin.item; -import com.bibireden.data_attributes.DataAttributes; import org.spongepowered.asm.mixin.Mixin; import com.bibireden.data_attributes.api.item.ItemHelper; diff --git a/src/main/java/com/bibireden/data_attributes/mixin/item/ItemStackMixin.java b/src/main/java/com/bibireden/data_attributes/mixin/item/ItemStackMixin.java index 26c74148..11f9a3a1 100644 --- a/src/main/java/com/bibireden/data_attributes/mixin/item/ItemStackMixin.java +++ b/src/main/java/com/bibireden/data_attributes/mixin/item/ItemStackMixin.java @@ -15,7 +15,6 @@ abstract class ItemStackMixin { @Inject(method = "(Lnet/minecraft/item/ItemConvertible;I)V", at = @At("TAIL")) private void data_init(ItemConvertible item, int count, CallbackInfo ci) { ItemStack stack = (ItemStack) (Object) this; - if (item != null) { ((ItemHelper) item.asItem()).onStackCreated(stack, count); } diff --git a/src/main/java/com/bibireden/data_attributes/mixin/item/MiningToolItemMixin.java b/src/main/java/com/bibireden/data_attributes/mixin/item/MiningToolItemMixin.java index e44df617..22a563bb 100644 --- a/src/main/java/com/bibireden/data_attributes/mixin/item/MiningToolItemMixin.java +++ b/src/main/java/com/bibireden/data_attributes/mixin/item/MiningToolItemMixin.java @@ -10,7 +10,7 @@ abstract class MiningToolItemMixin extends ItemMixin { // Overrides the getAttackDamage method from ItemMixin @Override - public float getAttackDamage(final ItemStack itemStack) { + public Float getAttackDamage(final ItemStack itemStack) { // Calls the original getAttackDamage method from MiningToolItem return ((MiningToolItem) (Object) this).getAttackDamage(); } diff --git a/src/main/java/com/bibireden/data_attributes/mixin/item/SwordItemMixin.java b/src/main/java/com/bibireden/data_attributes/mixin/item/SwordItemMixin.java index 898cae06..7b6f3c6e 100644 --- a/src/main/java/com/bibireden/data_attributes/mixin/item/SwordItemMixin.java +++ b/src/main/java/com/bibireden/data_attributes/mixin/item/SwordItemMixin.java @@ -7,10 +7,9 @@ @Mixin(SwordItem.class) abstract class SwordItemMixin extends ItemMixin { - // Overrides the getAttackDamage method from ItemMixin @Override - public float getAttackDamage(final ItemStack itemStack) { + public Float getAttackDamage(final ItemStack itemStack) { // Calls the original getAttackDamage method from SwordItem return ((SwordItem) (Object) this).getAttackDamage(); }