Skip to content

Commit

Permalink
chore: 临时修复货运系统可能不生效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
mcchampions committed Oct 7, 2024
1 parent 0cb59b6 commit 073c980
Showing 1 changed file with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import com.xzavier0722.mc.plugin.slimefuncomplib.event.cargo.CargoInsertEvent;
import com.xzavier0722.mc.plugin.slimefuncomplib.event.cargo.CargoWithdrawEvent;
import io.github.bakedlibs.dough.inventory.InvUtils;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -65,7 +68,7 @@ static boolean hasInventory(@Nullable Block block) {
static int[] getInputSlotRange(Inventory inv, @Nullable ItemStack item) {
if (inv instanceof FurnaceInventory) {
if (item != null && item.getType().isFuel()) {
if (isSmeltable(item, true)) {
if (isSmeltable(item)) {
// Any non-smeltable items should not land in the upper slot
return new int[]{0, 2};
} else {
Expand Down Expand Up @@ -116,13 +119,29 @@ static ItemStackAndInteger withdraw(
if (event.isCancelled()) {
return null;
}

for (int slot : menu.getPreset().getSlotsAccessedByItemTransport(menu, ItemTransportFlow.WITHDRAW, null)) {
ItemStack is = menu.getItemInSlot(slot);

if (matchesFilter(network, node, is)) {
menu.replaceExistingItem(slot, null);
return new ItemStackAndInteger(is, slot);
BlockMenuPreset preset = menu.getPreset();
try {
for (int slot : preset.getSlotsAccessedByItemTransport(menu, ItemTransportFlow.WITHDRAW, null)) {
ItemStack is = menu.getItemInSlot(slot);

if (matchesFilter(network, node, is)) {
menu.replaceExistingItem(slot, null);
return new ItemStackAndInteger(is, slot);
}
}
} catch (NullPointerException ex) {
SlimefunItem sfItem = preset.getSlimefunItem();
int[] slots;
if (sfItem instanceof InventoryBlock block) {
slots = block.getOutputSlots();
for (int slot : slots) {
ItemStack is = menu.getItemInSlot(slot);

if (matchesFilter(network, node, is)) {
menu.replaceExistingItem(slot, null);
return new ItemStackAndInteger(is, slot);
}
}
}
}
} else if (hasInventory(target)) {
Expand Down Expand Up @@ -324,15 +343,10 @@ static boolean matchesFilter(AbstractItemNetwork network, Block node, @Nullable
* Otherwise the "lazyness" can be turned off in the future.
*
* @param stack The {@link ItemStack} to test
* @param lazy Whether or not to perform a "lazy" but performance-saving check
* @return Whether the given {@link ItemStack} can be smelted or not
*/
private static boolean isSmeltable(@Nullable ItemStack stack, boolean lazy) {
if (lazy) {
return stack != null && Tag.LOGS.isTagged(stack.getType());
} else {
return Slimefun.getMinecraftRecipeService().isSmeltable(stack);
}
private static boolean isSmeltable(@Nullable ItemStack stack) {
return stack != null && Tag.LOGS.isTagged(stack.getType());
}

private static boolean isPotion(@Nullable ItemStack item) {
Expand Down

0 comments on commit 073c980

Please sign in to comment.