Search in sources :

Example 1 with IMixinHoverEvent

use of org.spongepowered.common.interfaces.text.IMixinHoverEvent in project SpongeCommon by SpongePowered.

the class SpongeHoverAction method getHandle.

public static HoverEvent getHandle(HoverAction<?> action) {
    HoverEvent.Action type = getType(action);
    ITextComponent component;
    switch(type) {
        case SHOW_ENTITY:
            {
                HoverAction.ShowEntity.Ref entity = ((HoverAction.ShowEntity) action).getResult();
                NBTTagCompound nbt = new NBTTagCompound();
                nbt.setString("id", entity.getUniqueId().toString());
                if (entity.getType().isPresent()) {
                    nbt.setString("type", EntityList.getKey(((SpongeEntityType) entity.getType().get()).entityClass).toString());
                }
                nbt.setString("name", entity.getName());
                component = new TextComponentString(nbt.toString());
                break;
            }
        case SHOW_ITEM:
            {
                ItemStack item = (ItemStack) ((ItemStackSnapshot) action.getResult()).createStack();
                NBTTagCompound nbt = new NBTTagCompound();
                item.writeToNBT(nbt);
                component = new TextComponentString(nbt.toString());
                break;
            }
        case SHOW_TEXT:
            component = SpongeTexts.toComponent((Text) action.getResult());
            break;
        default:
            throw new AssertionError();
    }
    HoverEvent event = new HoverEvent(type, component);
    ((IMixinHoverEvent) event).setHandle(action);
    return event;
}
Also used : HoverEvent(net.minecraft.util.text.event.HoverEvent) IMixinHoverEvent(org.spongepowered.common.interfaces.text.IMixinHoverEvent) ITextComponent(net.minecraft.util.text.ITextComponent) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Text(org.spongepowered.api.text.Text) IMixinHoverEvent(org.spongepowered.common.interfaces.text.IMixinHoverEvent) TextComponentString(net.minecraft.util.text.TextComponentString) HoverAction(org.spongepowered.api.text.action.HoverAction) SpongeEntityType(org.spongepowered.common.entity.SpongeEntityType) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 HoverEvent (net.minecraft.util.text.event.HoverEvent)1 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)1 Text (org.spongepowered.api.text.Text)1 HoverAction (org.spongepowered.api.text.action.HoverAction)1 SpongeEntityType (org.spongepowered.common.entity.SpongeEntityType)1 IMixinHoverEvent (org.spongepowered.common.interfaces.text.IMixinHoverEvent)1