Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ComponentLike for ItemStack #3562

Merged
merged 1 commit into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion SpongeAPI
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multimap;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.EquipmentSlot;
Expand Down Expand Up @@ -60,7 +62,7 @@

@Mixin(net.minecraft.world.item.ItemStack.class)
@Implements(@Interface(iface = ItemStack.class, prefix = "itemStack$", remap = Remap.NONE)) // We need to soft implement this interface due to a synthetic bridge method
public abstract class ItemStackMixin_API implements SerializableDataHolder.Mutable { // conflict from overriding ValueContainer#copy() from DataHolder
public abstract class ItemStackMixin_API implements SerializableDataHolder.Mutable, ComponentLike { // conflict from overriding ValueContainer#copy() from DataHolder

// @formatter:off
@Shadow public abstract int shadow$getCount();
Expand All @@ -76,6 +78,7 @@ public abstract class ItemStackMixin_API implements SerializableDataHolder.Mutab
@Shadow public abstract Item shadow$getItem();
@Shadow public abstract Multimap<Attribute, net.minecraft.world.entity.ai.attributes.AttributeModifier> shadow$getAttributeModifiers(EquipmentSlot equipmentSlot);
@Shadow public abstract void shadow$addAttributeModifier(Attribute attribute, net.minecraft.world.entity.ai.attributes.AttributeModifier modifier, @Nullable EquipmentSlot equipmentSlot);
@Shadow public abstract String shadow$getDescriptionId();
// @formatter:on

public int itemStack$quantity() {
Expand Down Expand Up @@ -206,4 +209,8 @@ public DataContainer toContainer() {
return this.shadow$isEmpty();
}

@Override
public Component asComponent() {
return Component.translatable(this.shadow$getDescriptionId());
}
}