mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-30 13:05:25 -05:00
[ci skip] Introduce item as an additional context (#189)
* Introduce item as an additional context * Remove @Internal
This commit is contained in:
@@ -23,12 +23,15 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dev.architectury.event.Event;
|
||||
import dev.architectury.event.EventFactory;
|
||||
import dev.architectury.event.EventResult;
|
||||
import dev.architectury.impl.TooltipAdditionalContextsImpl;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -51,6 +54,18 @@ public interface ClientTooltipEvent {
|
||||
*/
|
||||
Event<RenderModifyColor> RENDER_MODIFY_COLOR = EventFactory.createLoop();
|
||||
|
||||
static AdditionalContexts additionalContexts() {
|
||||
return TooltipAdditionalContextsImpl.get();
|
||||
}
|
||||
|
||||
@ApiStatus.NonExtendable
|
||||
interface AdditionalContexts {
|
||||
@Nullable
|
||||
ItemStack getItem();
|
||||
|
||||
void setItem(@Nullable ItemStack stack);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
interface Item {
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This file is part of architectury.
|
||||
* Copyright (C) 2020, 2021, 2022 architectury
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package dev.architectury.impl;
|
||||
|
||||
import dev.architectury.event.events.client.ClientTooltipEvent;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TooltipAdditionalContextsImpl implements ClientTooltipEvent.AdditionalContexts {
|
||||
private static final ThreadLocal<TooltipAdditionalContextsImpl> INSTANCE_LOCAL = ThreadLocal.withInitial(TooltipAdditionalContextsImpl::new);
|
||||
|
||||
public static ClientTooltipEvent.AdditionalContexts get() {
|
||||
return INSTANCE_LOCAL.get();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ItemStack item;
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(@Nullable ItemStack item) {
|
||||
this.item = item;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user