Fix ClientPickBlockApplyCallback.EVENT not working as expected Fixes ()

Co-authored-by: Player <player@player.to>
This commit is contained in:
Frieder Hannenheim 2021-06-20 16:25:14 +02:00 committed by GitHub
parent e369698318
commit 00066f1e8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 2 deletions
fabric-events-interaction-v0/src
main/java/net/fabricmc/fabric/mixin/event/interaction
testmod
java/net/fabricmc/fabric/test/event/interaction
resources

View file

@ -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);

View file

@ -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;
});
}
}

View file

@ -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"
]
}
}