Skip to content

Commit

Permalink
Do not allow items to be inserted into the Matter Condenser when the …
Browse files Browse the repository at this point in the history
…output is full

Closes #8311
  • Loading branch information
62832 committed Jan 18, 2025
1 parent 27ae40d commit 8d9e31d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/main/java/appeng/blockentity/misc/CondenserBlockEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,25 @@ public void addPower(double rawPower) {

private void fillOutput() {
var requiredPower = this.getRequiredPower();
var output = this.getOutput();
while (requiredPower <= this.getStoredPower() && !output.isEmpty() && requiredPower > 0) {
if (this.canAddOutput(output)) {
while (requiredPower <= this.getStoredPower() && !getOutput().isEmpty() && requiredPower > 0) {
if (this.canAddOutput()) {
this.setStoredPower(this.getStoredPower() - requiredPower);
this.addOutput(output);
this.addOutput();
} else {
break;
}
}
}

private boolean canAddOutput(ItemStack output) {
return this.outputSlot.insertItem(0, output, true).isEmpty();
boolean canAddOutput() {
return this.outputSlot.insertItem(0, getOutput(), true).isEmpty();
}

/**
* make sure you validate with canAddOutput prior to this.
*
* @param output to be added output
*/
private void addOutput(ItemStack output) {
this.outputSlot.insertItem(0, output, false);
private void addOutput() {
this.outputSlot.insertItem(0, getOutput(), false);
}

InternalInventory getOutputSlot() {
Expand Down Expand Up @@ -200,6 +197,11 @@ public ItemStack getStackInSlot(int slot) {
return ItemStack.EMPTY;
}

@Override
public boolean isItemValid(int slot, ItemStack stack) {
return canAddOutput();
}

@Override
public void setItemDirect(int slotIndex, ItemStack stack) {
if (!stack.isEmpty()) {
Expand All @@ -209,6 +211,9 @@ public void setItemDirect(int slotIndex, ItemStack stack) {

@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
if (!canAddOutput()) {
return stack;
}
if (!simulate && !stack.isEmpty()) {
CondenserBlockEntity.this.addPower(stack.getCount());
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/appeng/blockentity/misc/CondenserMEStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class CondenserMEStorage implements MEStorage {
@Override
public long insert(AEKey what, long amount, Actionable mode, IActionSource source) {
MEStorage.checkPreconditions(what, amount, mode, source);
if (!target.canAddOutput()) {
return 0;
}
if (mode == Actionable.MODULATE) {
this.target.addPower(amount / what.getAmountPerOperation());
}
Expand Down

0 comments on commit 8d9e31d

Please sign in to comment.