Skip to content

Commit

Permalink
Merge pull request #135 from wdfaESfaef/bugfix
Browse files Browse the repository at this point in the history
自动合成器物品闪烁修复
  • Loading branch information
Gu-ZT authored Apr 4, 2024
2 parents 7439915 + f938598 commit b41d030
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public AutoCrafterMenu(int containerId, @NotNull Inventory inventory, @NotNull C
}
this.updateResult();
}

public @Nullable IFilterBlockEntity getEntity() {
return this.machine instanceof IFilterBlockEntity entity ? entity : null;
}
Expand Down
26 changes: 21 additions & 5 deletions src/main/java/dev/dubhe/anvilcraft/inventory/BaseMachineMenu.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package dev.dubhe.anvilcraft.inventory;

import dev.dubhe.anvilcraft.block.entity.BaseMachineBlockEntity;
import dev.dubhe.anvilcraft.block.entity.IFilterBlockEntity;
import lombok.Getter;
import net.minecraft.core.Direction;
import net.minecraft.core.NonNullList;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
Expand All @@ -29,11 +31,7 @@ protected BaseMachineMenu(@Nullable MenuType<?> menuType, int containerId, @NotN
if (!slot.hasItem()) return itemStack;
ItemStack itemStack2 = slot.getItem();
itemStack = itemStack2.copy();
if (
index < this.machine.getContainerSize() ?
!this.moveItemStackTo(itemStack2, this.machine.getContainerSize(), this.machine.getContainerSize() + 36, true) :
!this.moveItemStackTo(itemStack2, 0, this.machine.getContainerSize(), false)
) {
if (quickMoveFilter(index,itemStack2)) {
return ItemStack.EMPTY;
}
if (itemStack2.isEmpty()) slot.setByPlayer(ItemStack.EMPTY);
Expand All @@ -43,6 +41,24 @@ protected BaseMachineMenu(@Nullable MenuType<?> menuType, int containerId, @NotN
return itemStack;
}

private boolean quickMoveFilter(int index,ItemStack itemStack){
if(index < this.machine.getContainerSize()){
return !this.moveItemStackTo(itemStack, this.machine.getContainerSize(), this.machine.getContainerSize() + 36, true);
}else{
boolean bl = false;
if (this.getMachine() instanceof IFilterBlockEntity entity) {
for (int i = 0; i < this.machine.getContainerSize(); i++) {
ItemStack filter = entity.getFilter().get(i);
NonNullList<Boolean> disableds = entity.getDisabled();
if (filter.is(itemStack.getItem()) || !disableds.get(i)) {
bl = !this.moveItemStackTo(itemStack, i, i + 1, false);
}
}
}
return bl;
}
}

@Override
public boolean stillValid(Player player) {
return this.machine.stillValid(player);
Expand Down

0 comments on commit b41d030

Please sign in to comment.