Skip to content

Commit

Permalink
Fixed result item with Use Item feature
Browse files Browse the repository at this point in the history
  • Loading branch information
GirafiStudios committed Aug 7, 2019
1 parent b0e01e4 commit f1b5243
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraftforge.fml.network.NetworkEvent;

Expand All @@ -29,16 +31,17 @@ public static void handle(PacketUseItem message, Supplier<NetworkEvent.Context>
ServerPlayerEntity player = ctx.get().getSender();
if (player != null) {
ItemStack slotStack = player.inventory.getStackInSlot(message.slot);
ItemStack held = player.getHeldItemMainhand();
ItemStack heldSaved = player.getHeldItemMainhand();
Hand hand = Hand.MAIN_HAND;
EquipmentSlotType slot = getSlotFromHand(hand);

player.setItemStackToSlot(slot, slotStack);
ItemStack heldItem = player.getHeldItem(hand);
if (!heldItem.isEmpty()) {
heldItem.useItemRightClick(player.world, player, hand).getResult();
ActionResult<ItemStack> useStack = heldItem.useItemRightClick(player.world, player, hand);
if (useStack.getType() == ActionResultType.SUCCESS) {
player.inventory.mainInventory.set(message.slot, useStack.getResult());
}
player.setItemStackToSlot(slot, held);
player.setItemStackToSlot(slot, heldSaved);

player.sendContainerToPlayer(player.container);

Expand Down

0 comments on commit f1b5243

Please sign in to comment.