Skip to content

Commit

Permalink
Merge pull request #13 from heisluft/vanish-bugfix
Browse files Browse the repository at this point in the history
Fix Shift-Click Mechanics for Big filters, Up- and Downgrades (Fixes #11)
  • Loading branch information
ThePansmith authored May 19, 2024
2 parents 2086582 + 70fe970 commit db16ad8
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,89 @@ public ConduitMenu(@Nullable ConduitBlockEntity blockEntity, Inventory inventory
addInventorySlots(23,113);
}

// EnderIO Unofficial: Override parent method
@Override
protected boolean moveItemStackTo(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection) {
boolean flag = false;
int i = reverseDirection ? endIndex - 1 : startIndex;
Slot slot1;
ItemStack itemstack;
if (stack.isStackable()) {
while(!stack.isEmpty()) {
if (reverseDirection) {
if (i < startIndex) break;
} else if (i >= endIndex) break;

slot1 = this.slots.get(i);
itemstack = slot1.getItem();
if (!itemstack.isEmpty() && ItemStack.isSameItemSameTags(stack, itemstack)) {
int j = itemstack.getCount() + stack.getCount();
// EnderIO Unofficial: Allow Stack-dependent maxStackSize in ConduitSlots
int maxSize = Math.min(slot1 instanceof ConduitSlot cs ? cs.getMaxStackSizeItemAware(stack) : slot1.getMaxStackSize(), stack.getMaxStackSize());
if (j <= maxSize) {
stack.setCount(0);
itemstack.setCount(j);
slot1.setChanged();
flag = true;
} else if (itemstack.getCount() < maxSize) {
stack.shrink(maxSize - itemstack.getCount());
itemstack.setCount(maxSize);
slot1.setChanged();
flag = true;
}
}

if (reverseDirection) {
--i;
} else {
++i;
}
}
}

if (!stack.isEmpty()) {
if (reverseDirection) {
i = endIndex - 1;
} else {
i = startIndex;
}

while(true) {
if (reverseDirection) {
if (i < startIndex) {
break;
}
} else if (i >= endIndex) {
break;
}

slot1 = this.slots.get(i);
itemstack = slot1.getItem();
if (itemstack.isEmpty() && slot1.mayPlace(stack)) {
// EnderIO Unofficial: Allow Stack-dependent maxStackSize in ConduitSlots
int slotMaxStackSize = slot1 instanceof ConduitSlot cs ? cs.getMaxStackSizeItemAware(stack) : slot1.getMaxStackSize();
if (stack.getCount() > slotMaxStackSize) {
slot1.setByPlayer(stack.split(slotMaxStackSize));
} else {
slot1.setByPlayer(stack.split(stack.getCount()));
}

slot1.setChanged();
flag = true;
break;
}

if (reverseDirection) {
--i;
} else {
++i;
}
}
}

return flag;
}

@Override
public ItemStack quickMoveStack(Player pPlayer, int pIndex) {
ItemStack itemstack = ItemStack.EMPTY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ public Slot setBackground(ResourceLocation atlas, ResourceLocation sprite) {
return super.setBackground(atlas, sprite);
}

//EnderIO Unofficial: Called from ConduitMenu to provide accurate Shift-Click mechanics
public int getMaxStackSizeItemAware(ItemStack stack) {
if(slotType != SlotType.UPGRADE_EXTRACT) return 1;
return stack.is(ConduitItems.SPEED_UPGRADE.asItem()) ? 15 : stack.is(ConduitItems.SPEED_DOWNGRADE.asItem()) ? 3 : 64;
}

@Override
public boolean mayPlace(ItemStack stack) {
// TODO check slot type, fluid filter for fluid etc...
return isVisible() && super.mayPlace(stack) && (
stack.is(ConduitItems.BASIC_ITEM_FILTER.asItem()))
|| stack.is(ConduitItems.BIG_ITEM_FILTER.asItem())
|| stack.is(ConduitItems.SPEED_UPGRADE.asItem())
|| stack.is(ConduitItems.SPEED_DOWNGRADE.asItem());
return isVisible() && super.mayPlace(stack) && slotType.acceptsItem(stack.getItem());
}

@Override
Expand Down

0 comments on commit db16ad8

Please sign in to comment.