Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to replenish items from Sophisticated inventory when crafting with a Crafting Upgrade #73

Open
wants to merge 1 commit into
base: 1.18.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public interface ICraftingContainer {
List<Slot> getRecipeSlots();

Container getCraftMatrix();

boolean shouldReplenish();
}
Original file line number Diff line number Diff line change
Expand Up @@ -967,8 +967,17 @@ protected void doClick(int slotId, int dragType, ClickType clickType, Player pla
quickMoveStack(this.player, slotId).copy();
} else {
ItemStack itemstack8 = quickMoveStack(this.player, slotId);
while (!itemstack8.isEmpty() && ItemStack.isSame(slot6.getItem(), itemstack8)) {
itemstack8 = quickMoveStack(this.player, slotId);
if (getOpenOrFirstCraftingContainer().map(ICraftingContainer::shouldReplenish).orElse(false)) {
int i = 1;
int maxStackSize = itemstack8.getMaxStackSize();
while (!itemstack8.isEmpty() && ItemStack.isSame(slot6.getItem(), itemstack8) && i < maxStackSize) {
itemstack8 = quickMoveStack(this.player, slotId);
i++;
}
} else {
while (!itemstack8.isEmpty() && ItemStack.isSame(slot6.getItem(), itemstack8)) {
itemstack8 = quickMoveStack(this.player, slotId);
}
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ public void setEnabled(boolean enabled) {
save();
storageWrapper.getUpgradeHandler().refreshWrappersThatImplementAndTypeWrappers();
}

public IStorageWrapper getStorageWrapper() {
return storageWrapper;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.p3pp3rf1y.sophisticatedcore.common.gui.StorageContainerMenuBase;
import net.p3pp3rf1y.sophisticatedcore.common.gui.UpgradeContainerBase;
import net.p3pp3rf1y.sophisticatedcore.common.gui.UpgradeContainerType;
import net.p3pp3rf1y.sophisticatedcore.util.InventoryHelper;
import net.p3pp3rf1y.sophisticatedcore.util.NBTHelper;

import javax.annotation.Nullable;
Expand All @@ -26,6 +27,7 @@

public class CraftingUpgradeContainer extends UpgradeContainerBase<CraftingUpgradeWrapper, CraftingUpgradeContainer> implements ICraftingContainer {
private static final String DATA_SHIFT_CLICK_INTO_STORAGE = "shiftClickIntoStorage";
private static final String DATA_REPLENISH = "replenish";
private final ResultContainer craftResult = new ResultContainer();
private final CraftingItemHandler craftMatrix;
private final ResultSlot craftingResultSlot;
Expand Down Expand Up @@ -63,7 +65,15 @@ public void onTake(Player thePlayer, ItemStack stack) {
ItemStack itemstack = craftMatrix.getItem(i);
ItemStack itemstack1 = nonnulllist.get(i);
if (!itemstack.isEmpty()) {
craftMatrix.removeItem(i, 1);
if (shouldReplenish()) {
if (InventoryHelper.extractFromInventory(itemstack.getItem(), 1, upgradeWrapper.getStorageWrapper().getInventoryHandler(), false).isEmpty()) {
craftMatrix.removeItem(i, 1);
} else {
onCraftMatrixChanged(craftMatrix);
}
} else {
craftMatrix.removeItem(i, 1);
}
itemstack = craftMatrix.getItem(i);
}

Expand Down Expand Up @@ -133,6 +143,9 @@ public void handleMessage(CompoundTag data) {
if (data.contains(DATA_SHIFT_CLICK_INTO_STORAGE)) {
setShiftClickIntoStorage(data.getBoolean(DATA_SHIFT_CLICK_INTO_STORAGE));
}
if (data.contains(DATA_REPLENISH)) {
setReplenish(data.getBoolean(DATA_REPLENISH));
}
}

@Override
Expand Down Expand Up @@ -164,6 +177,15 @@ public void setShiftClickIntoStorage(boolean shiftClickIntoStorage) {
sendDataToServer(() -> NBTHelper.putBoolean(new CompoundTag(), DATA_SHIFT_CLICK_INTO_STORAGE, shiftClickIntoStorage));
}

public boolean shouldReplenish() {
return upgradeWrapper.shouldReplenish();
}

public void setReplenish(boolean replenish) {
upgradeWrapper.setReplenish(replenish);
sendDataToServer(() -> NBTHelper.putBoolean(new CompoundTag(), DATA_REPLENISH, replenish));
}

@Override
public boolean mergeIntoStorageFirst(Slot slot) {
return !(slot instanceof ResultSlot) || shouldShiftClickIntoStorage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ public class CraftingUpgradeTab extends UpgradeSettingsTab<CraftingUpgradeContai

private final ICraftingUIPart craftingUIAddition;

public CraftingUpgradeTab(CraftingUpgradeContainer upgradeContainer, Position position, StorageScreenBase<?> screen, ButtonDefinition.Toggle<Boolean> shiftClickTargetButton) {
public CraftingUpgradeTab(CraftingUpgradeContainer upgradeContainer, Position position, StorageScreenBase<?> screen, ButtonDefinition.Toggle<Boolean> shiftClickTargetButton, ButtonDefinition.Toggle<Boolean> replenishButton) {
super(upgradeContainer, position, screen, TranslationHelper.INSTANCE.translUpgrade("crafting"), TranslationHelper.INSTANCE.translUpgradeTooltip("crafting"));
addHideableChild(new ToggleButton<>(new Position(x + 3, y + 24), shiftClickTargetButton, button -> getContainer().setShiftClickIntoStorage(!getContainer().shouldShiftClickIntoStorage()),
getContainer()::shouldShiftClickIntoStorage));
addHideableChild(new ToggleButton<>(new Position(x + 21, y + 24), replenishButton, button -> getContainer().setReplenish(!getContainer().shouldReplenish()),
getContainer()::shouldReplenish));
craftingUIAddition = screen.getCraftingUIAddition();
openTabDimension = new Dimension(63 + craftingUIAddition.getWidth(), 142);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@ public void setShiftClickIntoStorage(boolean shiftClickIntoStorage) {
NBTHelper.setBoolean(upgrade, "shiftClickIntoStorage", shiftClickIntoStorage);
save();
}

public boolean shouldReplenish() {
return NBTHelper.getBoolean(upgrade, "replenish").orElse(false);
}

public void setReplenish(boolean replenish) {
NBTHelper.setBoolean(upgrade, "replenish", replenish);
save();
}
}
Binary file modified src/main/resources/assets/sophisticatedcore/textures/gui/icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.