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;
}
Aggregations