Skip to content

Commit

Permalink
Fix only overriding one set stack method causing QIO drives to be abl…
Browse files Browse the repository at this point in the history
…e to be duped mekanism#6860
  • Loading branch information
pupnewfster committed Jan 31, 2021
1 parent e385cc0 commit 05d0f8b
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/main/java/mekanism/common/inventory/slot/QIODriveSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import mekanism.common.content.qio.QIOFrequency;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

@FieldsAreNonnullByDefault
@ParametersAreNonnullByDefault
Expand Down Expand Up @@ -42,6 +43,21 @@ public void setStack(ItemStack stack) {
}
}

@Override
protected void setStackUnchecked(ItemStack stack) {
// if we're about to empty this slot and a drive already exists here, remove the current drive from the frequency
// Note: We don't check to see if the new stack is empty so that we properly are able to handle direct changes
if (!isRemote() && !isEmpty()) {
removeDrive();
}
super.setStackUnchecked(stack);
// if we just added a new drive, add it to the frequency
// (note that both of these operations can happen in this order if a user replaces the drive in the slot)
if (!isRemote() && !isEmpty()) {
addDrive(getStack());
}
}

@Override
public ItemStack insertItem(ItemStack stack, Action action, AutomationType automationType) {
ItemStack ret = super.insertItem(stack, action, automationType);
Expand All @@ -67,7 +83,10 @@ public QIODriveKey getKey() {
}

private boolean isRemote() {
return ((TileEntity) driveHolder).getWorld().isRemote();
World world = ((TileEntity) driveHolder).getWorld();
//Treat world as remote if it is null (hasn't been assigned yet)
// which may happen when loading the drives from memory
return world == null || world.isRemote();
}

private void addDrive(ItemStack stack) {
Expand Down

0 comments on commit 05d0f8b

Please sign in to comment.