mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-05 19:47:00 -04:00
Co-authored-by: Player <player@player.to>
This commit is contained in:
parent
e369698318
commit
00066f1e8d
3 changed files with 44 additions and 2 deletions
fabric-events-interaction-v0/src
main/java/net/fabricmc/fabric/mixin/event/interaction
testmod
|
@ -105,7 +105,7 @@ public abstract class MixinMinecraftClient {
|
|||
@Shadow
|
||||
public abstract ItemStack addBlockEntityNbt(ItemStack itemStack_1, BlockEntity blockEntity_1);
|
||||
|
||||
@ModifyVariable(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerInventory;getSlotWithStack(Lnet/minecraft/item/ItemStack;)I"), method = "doItemPick", ordinal = 0)
|
||||
@ModifyVariable(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerInventory;getSlotWithStack(Lnet/minecraft/item/ItemStack;)I", shift = At.Shift.BEFORE), method = "doItemPick", ordinal = 0)
|
||||
public ItemStack modifyItemPick(ItemStack stack) {
|
||||
MinecraftClient client = (MinecraftClient) (Object) this;
|
||||
ItemStack result = ClientPickBlockApplyCallback.EVENT.invoker().pick(client.player, client.crosshairTarget, stack);
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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.test.event.interaction;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.util.Hand;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.event.client.player.ClientPickBlockApplyCallback;
|
||||
|
||||
public class PlayerPickBlockTests implements ModInitializer {
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
ClientPickBlockApplyCallback.EVENT.register((player, result, stack) -> {
|
||||
if (player.getStackInHand(Hand.MAIN_HAND).getItem() == Items.DIAMOND) {
|
||||
return new ItemStack(Items.OBSIDIAN);
|
||||
}
|
||||
|
||||
if (stack.getItem() == Items.GRASS_BLOCK) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return stack;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -10,7 +10,8 @@
|
|||
},
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"net.fabricmc.fabric.test.event.interaction.PlayerBreakBlockTests"
|
||||
"net.fabricmc.fabric.test.event.interaction.PlayerBreakBlockTests",
|
||||
"net.fabricmc.fabric.test.event.interaction.PlayerPickBlockTests"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue