-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
71 additions
and
5 deletions.
There are no files selected for viewing
7 changes: 5 additions & 2 deletions
7
patches/net/minecraft/world/inventory/FurnaceResultSlot.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
--- a/net/minecraft/world/inventory/FurnaceResultSlot.java | ||
+++ b/net/minecraft/world/inventory/FurnaceResultSlot.java | ||
@@ -49,5 +_,6 @@ | ||
@@ -48,6 +_,9 @@ | ||
abstractfurnaceblockentity.awardUsedRecipesAndPopExperience(serverplayer); | ||
} | ||
|
||
+ if (this.removeCount != 0) { | ||
+ net.neoforged.neoforge.event.EventHooks.firePlayerSmeltedEvent(this.player, p_39558_, this.removeCount); | ||
+ } | ||
this.removeCount = 0; | ||
+ net.neoforged.neoforge.event.EventHooks.firePlayerSmeltedEvent(this.player, p_39558_); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
tests/src/main/java/net/neoforged/neoforge/debug/crafting/CraftingEventTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.debug.crafting; | ||
|
||
import com.mojang.blaze3d.platform.InputConstants; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.gametest.framework.GameTest; | ||
import net.minecraft.world.inventory.ClickType; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.Items; | ||
import net.minecraft.world.level.GameType; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.entity.FurnaceBlockEntity; | ||
import net.neoforged.neoforge.event.entity.player.PlayerEvent; | ||
import net.neoforged.testframework.DynamicTest; | ||
import net.neoforged.testframework.annotation.ForEachTest; | ||
import net.neoforged.testframework.annotation.TestHolder; | ||
import net.neoforged.testframework.gametest.EmptyTemplate; | ||
|
||
@ForEachTest(groups = "crafting.event") | ||
public class CraftingEventTests { | ||
@GameTest | ||
@EmptyTemplate | ||
@TestHolder(description = "Tests that ItemSmeltedEvent is fired correctly") | ||
static void itemSmeltedEventTest(final DynamicTest test) { | ||
AtomicInteger timesFired = new AtomicInteger(0); | ||
test.whenEnabled(listeners -> { | ||
listeners.forge().addListener((final PlayerEvent.ItemSmeltedEvent event) -> { | ||
timesFired.incrementAndGet(); | ||
var removed = event.getAmountRemoved(); | ||
if (removed != 32) { | ||
test.fail("Test should be removing half of a stack, yet extracted a different amount"); | ||
} | ||
}); | ||
}); | ||
test.onGameTest(helper -> { | ||
helper.setBlock(BlockPos.ZERO, Blocks.FURNACE); | ||
var be = helper.getBlockEntity(BlockPos.ZERO, FurnaceBlockEntity.class); | ||
helper.assertFalse(be == null, "FurnaceBlockEntity was not found for furnace position"); | ||
// Slot 2 is the result slot | ||
be.setItem(2, new ItemStack(Items.IRON_INGOT, 64)); | ||
var player = helper.makeTickingMockServerPlayerInLevel(GameType.CREATIVE); | ||
player.openMenu(be); | ||
// Test that right-clicking half of the stack out of the FurnaceResultSlot functions as expected | ||
player.containerMenu.clicked(2, InputConstants.MOUSE_BUTTON_RIGHT, ClickType.PICKUP, player); | ||
player.containerMenu.setCarried(ItemStack.EMPTY); | ||
// Test that shift-left-clicking the rest of the stack out works (should only fire once, not twice) | ||
player.containerMenu.clicked(2, InputConstants.MOUSE_BUTTON_LEFT, ClickType.QUICK_MOVE, player); | ||
helper.assertTrue(timesFired.getPlain() == 2, "Event was not fired the expected number of times. Fired: " + timesFired.getPlain()); | ||
helper.succeed(); | ||
}); | ||
} | ||
} |