Skip to content

Commit

Permalink
Made nullable behavior by default, conditionals added to items
Browse files Browse the repository at this point in the history
  • Loading branch information
bibi-reden committed Jun 28, 2024
1 parent c0021aa commit b439000
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ abstract class ItemStackMixin {
@Inject(method = "<init>(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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit b439000

Please sign in to comment.