forked from FabricMC/fabric
Add ItemStack Tooltip event (#302)
This commit is contained in:
parent
f0fe03ff28
commit
eff46b3d8e
4 changed files with 87 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
|||
archivesBaseName = "fabric-events-lifecycle-v0"
|
||||
version = getSubprojectVersion(project, "0.1.0")
|
||||
version = getSubprojectVersion(project, "0.1.1")
|
||||
|
||||
dependencies {
|
||||
compile project(path: ':fabric-api-base', configuration: 'dev')
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.api.event.client;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.client.item.TooltipContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ItemTooltipCallback {
|
||||
|
||||
/** Fired after the game has appended all base tooltip lines to the list */
|
||||
Event<ItemTooltipCallback> EVENT = EventFactory.createArrayBacked(ItemTooltipCallback.class, (listeners) ->
|
||||
(stack, tooltipContext, lines) -> {
|
||||
for(ItemTooltipCallback callback : listeners){
|
||||
callback.getTooltip(stack, tooltipContext, lines);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Called when an item stack's tooltip is rendered. Text added to {@code lines} will be
|
||||
* rendered with the tooltip.
|
||||
* @param lines the list containing the lines of text displayed on the stack's tooltip
|
||||
*/
|
||||
void getTooltip(ItemStack stack, TooltipContext tooltipContext, List<Text> lines);
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.fabricmc.fabric.mixin.eventslifecycle;
|
||||
|
||||
import net.fabricmc.fabric.api.event.client.ItemTooltipCallback;
|
||||
import net.minecraft.client.item.TooltipContext;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.Text;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(ItemStack.class)
|
||||
public class MixinItemStack {
|
||||
|
||||
@Inject(method = "getTooltip", at = @At("RETURN"))
|
||||
private void getTooltip(PlayerEntity entity, TooltipContext tooltipContext, CallbackInfoReturnable<List<Text>> info){
|
||||
ItemTooltipCallback.EVENT.invoker().getTooltip((ItemStack) (Object)this, tooltipContext, info.getReturnValue());
|
||||
}
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
"MixinWorld"
|
||||
],
|
||||
"client": [
|
||||
"MixinItemStack",
|
||||
"MixinMinecraftClient"
|
||||
],
|
||||
"injectors": {
|
||||
|
|
Loading…
Reference in a new issue