mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-14 19:25:23 -05:00
Remove FabricItem.getAttributeModifiers.
This commit is contained in:
parent
c585e0a241
commit
afdfc921b8
4 changed files with 9 additions and 51 deletions
|
@ -16,7 +16,6 @@
|
|||
|
||||
package net.fabricmc.fabric.api.item.v1;
|
||||
|
||||
import net.minecraft.component.type.AttributeModifiersComponent;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
|
@ -64,19 +63,6 @@ public interface FabricItem {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the attribute modifiers to apply when this stack is worn in a living entity equipment slot.
|
||||
* Stack-aware version of {@link Item#getAttributeModifiers()}.
|
||||
*
|
||||
* <p>Note that attribute modifiers are only updated when the stack changes, i.e. when {@code ItemStack.areEqual(old, new)} is false.
|
||||
*
|
||||
* @param stack the current stack
|
||||
* @return the attribute modifiers
|
||||
*/
|
||||
default AttributeModifiersComponent getAttributeModifiers(ItemStack stack) {
|
||||
return ((Item) this).getAttributeModifiers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a leftover item stack after {@code stack} is consumed in a recipe.
|
||||
* (This is also known as "recipe remainder".)
|
||||
|
|
|
@ -25,10 +25,7 @@ import org.apache.commons.lang3.mutable.MutableBoolean;
|
|||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import net.minecraft.component.ComponentType;
|
||||
import net.minecraft.component.type.AttributeModifiersComponent;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.Item;
|
||||
|
@ -75,27 +72,4 @@ public abstract class ItemStackMixin implements FabricItemStack {
|
|||
|
||||
original.call(instance, amount, serverWorld, serverPlayerEntity, consumer);
|
||||
}
|
||||
|
||||
@Redirect(
|
||||
method = "appendAttributeModifiersTooltip",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/item/ItemStack;getOrDefault(Lnet/minecraft/component/ComponentType;Ljava/lang/Object;)Ljava/lang/Object;"
|
||||
)
|
||||
)
|
||||
public Object appendAttributeModifiersTooltip(ItemStack stack, ComponentType<AttributeModifiersComponent> type, Object fallback) {
|
||||
return getItem().getAttributeModifiers(stack);
|
||||
}
|
||||
|
||||
@Redirect(
|
||||
method = {"applyAttributeModifier", "applyAttributeModifiers"},
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/item/Item;getAttributeModifiers()Lnet/minecraft/component/type/AttributeModifiersComponent;"
|
||||
)
|
||||
)
|
||||
public AttributeModifiersComponent applyAttributeModifiers(Item item) {
|
||||
ItemStack stack = (ItemStack) (Object) this;
|
||||
return item.getAttributeModifiers(stack);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package net.fabricmc.fabric.test.item;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.AttributeModifierSlot;
|
||||
import net.minecraft.component.type.AttributeModifiersComponent;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
@ -37,7 +38,12 @@ public class UpdatingItem extends Item {
|
|||
private final boolean allowUpdateAnimation;
|
||||
|
||||
public UpdatingItem(boolean allowUpdateAnimation) {
|
||||
super(new Settings());
|
||||
super(new Settings()
|
||||
.component(DataComponentTypes.ATTRIBUTE_MODIFIERS, AttributeModifiersComponent.builder()
|
||||
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, PLUS_FIVE, AttributeModifierSlot.MAINHAND)
|
||||
.build()
|
||||
)
|
||||
);
|
||||
this.allowUpdateAnimation = allowUpdateAnimation;
|
||||
}
|
||||
|
||||
|
@ -63,14 +69,6 @@ public class UpdatingItem extends Item {
|
|||
return !stack.contains(ItemUpdateAnimationTest.TICKS) || stack.getOrDefault(ItemUpdateAnimationTest.TICKS, 0) % 600 < 300;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeModifiersComponent getAttributeModifiers(ItemStack stack) {
|
||||
// Give + 5 attack damage for 15 seconds every 30 seconds.
|
||||
return AttributeModifiersComponent.builder()
|
||||
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, PLUS_FIVE, AttributeModifierSlot.MAINHAND)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMiningSpeed(ItemStack stack, BlockState state) {
|
||||
return isEnabled(stack) ? 20 : super.getMiningSpeed(stack, state);
|
||||
|
|
|
@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx2560M
|
|||
org.gradle.parallel=true
|
||||
fabric.loom.multiProjectOptimisation=true
|
||||
|
||||
version=0.99.3
|
||||
version=0.99.4
|
||||
minecraft_version=1.21-pre1
|
||||
yarn_version=+build.2
|
||||
loader_version=0.15.11
|
||||
|
@ -30,7 +30,7 @@ fabric-entity-events-v1-version=1.6.12
|
|||
fabric-events-interaction-v0-version=0.7.10
|
||||
fabric-game-rule-api-v1-version=1.0.52
|
||||
fabric-gametest-api-v1-version=2.0.0
|
||||
fabric-item-api-v1-version=10.0.1
|
||||
fabric-item-api-v1-version=11.0.0
|
||||
fabric-item-group-api-v1-version=4.0.43
|
||||
fabric-key-binding-api-v1-version=1.0.47
|
||||
fabric-keybindings-v0-version=0.2.45
|
||||
|
|
Loading…
Reference in a new issue