-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let vanilla try to handle Container interactions before checking for …
…item handlers (#1787)
- Loading branch information
1 parent
05084dc
commit 3de035b
Showing
6 changed files
with
207 additions
and
216 deletions.
There are no files selected for viewing
32 changes: 25 additions & 7 deletions
32
patches/net/minecraft/world/level/block/CrafterBlock.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,11 +1,29 @@ | ||
--- a/net/minecraft/world/level/block/CrafterBlock.java | ||
+++ b/net/minecraft/world/level/block/CrafterBlock.java | ||
@@ -214,6 +_,8 @@ | ||
@@ -194,7 +_,8 @@ | ||
ServerLevel p_335887_, BlockPos p_307620_, CrafterBlockEntity p_307387_, ItemStack p_307296_, BlockState p_307501_, RecipeHolder<?> p_335494_ | ||
) { | ||
Direction direction = p_307501_.getValue(ORIENTATION).front(); | ||
- Container container = HopperBlockEntity.getContainerAt(p_335887_, p_307620_.relative(direction)); | ||
+ var containerOrHandler = HopperBlockEntity.getContainerOrHandlerAt(p_335887_, p_307620_.relative(direction), direction.getOpposite()); | ||
+ Container container = containerOrHandler.container(); | ||
ItemStack itemstack = p_307296_.copy(); | ||
if (container != null && (container instanceof CrafterBlockEntity || p_307296_.getCount() > container.getMaxStackSize(p_307296_))) { | ||
while (!itemstack.isEmpty()) { | ||
@@ -206,10 +_,14 @@ | ||
|
||
itemstack.shrink(1); | ||
} | ||
- } else if (container != null) { | ||
+ } else if (!containerOrHandler.isEmpty()) { | ||
while (!itemstack.isEmpty()) { | ||
int i = itemstack.getCount(); | ||
- itemstack = HopperBlockEntity.addItem(p_307387_, container, itemstack, direction.getOpposite()); | ||
+ if (container != null) { | ||
+ itemstack = HopperBlockEntity.addItem(p_307387_, container, itemstack, direction.getOpposite()); | ||
+ } else { | ||
+ itemstack = net.neoforged.neoforge.items.ItemHandlerHelper.insertItem(containerOrHandler.itemHandler(), itemstack, false); | ||
+ } | ||
if (i == itemstack.getCount()) { | ||
break; | ||
} | ||
} | ||
+ } else { | ||
+ itemstack = net.neoforged.neoforge.items.VanillaInventoryCodeHooks.insertCrafterOutput(p_335887_, p_307620_, p_307387_, itemstack); | ||
} | ||
|
||
if (!itemstack.isEmpty()) { |
23 changes: 17 additions & 6 deletions
23
patches/net/minecraft/world/level/block/DropperBlock.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,11 +1,22 @@ | ||
--- a/net/minecraft/world/level/block/DropperBlock.java | ||
+++ b/net/minecraft/world/level/block/DropperBlock.java | ||
@@ -56,7 +_,7 @@ | ||
p_52944_.levelEvent(1001, p_52945_, 0); | ||
} else { | ||
@@ -58,12 +_,16 @@ | ||
ItemStack itemstack = dispenserblockentity.getItem(i); | ||
- if (!itemstack.isEmpty()) { | ||
+ if (!itemstack.isEmpty() && net.neoforged.neoforge.items.VanillaInventoryCodeHooks.dropperInsertHook(p_52944_, p_52945_, dispenserblockentity, i, itemstack)) { | ||
if (!itemstack.isEmpty()) { | ||
Direction direction = p_52944_.getBlockState(p_52945_).getValue(FACING); | ||
Container container = HopperBlockEntity.getContainerAt(p_52944_, p_52945_.relative(direction)); | ||
- Container container = HopperBlockEntity.getContainerAt(p_52944_, p_52945_.relative(direction)); | ||
+ var containerOrHandler = HopperBlockEntity.getContainerOrHandlerAt(p_52944_, p_52945_.relative(direction), direction.getOpposite()); | ||
ItemStack itemstack1; | ||
- if (container == null) { | ||
+ if (containerOrHandler.isEmpty()) { | ||
itemstack1 = DISPENSE_BEHAVIOUR.dispense(blocksource, itemstack); | ||
} else { | ||
- itemstack1 = HopperBlockEntity.addItem(dispenserblockentity, container, itemstack.copyWithCount(1), direction.getOpposite()); | ||
+ if (containerOrHandler.container() != null) { | ||
+ itemstack1 = HopperBlockEntity.addItem(dispenserblockentity, containerOrHandler.container(), itemstack.copyWithCount(1), direction.getOpposite()); | ||
+ } else { | ||
+ itemstack1 = net.neoforged.neoforge.items.ItemHandlerHelper.insertItem(containerOrHandler.itemHandler(), itemstack.copyWithCount(1), false); | ||
+ } | ||
if (itemstack1.isEmpty()) { | ||
itemstack1 = itemstack.copy(); | ||
itemstack1.shrink(1); |
84 changes: 75 additions & 9 deletions
84
patches/net/minecraft/world/level/block/entity/HopperBlockEntity.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
25 changes: 25 additions & 0 deletions
25
src/main/java/net/neoforged/neoforge/items/ContainerOrHandler.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,25 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.items; | ||
|
||
import net.minecraft.world.Container; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public record ContainerOrHandler( | ||
@Nullable Container container, | ||
@Nullable IItemHandler itemHandler) { | ||
public ContainerOrHandler { | ||
if (container != null && itemHandler != null) { | ||
throw new IllegalArgumentException("Cannot have both a container and an item handler."); | ||
} | ||
} | ||
|
||
public static final ContainerOrHandler EMPTY = new ContainerOrHandler(null, null); | ||
|
||
public boolean isEmpty() { | ||
return container == null && itemHandler == null; | ||
} | ||
} |
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
Oops, something went wrong.
3de035b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This crashes my game when launching it
3de035b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@azalty Please make a fresh new issue report with logs and reproduction steps so we can see what exactly is crashing and if this code is even the true cause