Skip to content

Commit

Permalink
Fix that kinetic stress output will never not stop
Browse files Browse the repository at this point in the history
  • Loading branch information
iamSmallY committed Apr 18, 2024
1 parent 2fdb851 commit 9e7e694
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.gregtechceu.gtceu.api.capability.recipe.IO;
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.TickableSubscription;
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMultiController;
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IWorkableMultiController;
import com.gregtechceu.gtceu.api.machine.multiblock.part.TieredIOPartMachine;
import com.gregtechceu.gtceu.common.machine.kinetic.IKineticMachine;
import com.gregtechceu.gtceu.common.machine.trait.NotifiableStressTrait;
Expand All @@ -14,6 +17,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.BlockHitResult;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

/**
Expand All @@ -30,9 +34,13 @@ public class KineticPartMachine extends TieredIOPartMachine implements IKineticM
@Persisted
protected final NotifiableStressTrait stressTrait;

@Nullable
private TickableSubscription stopWorkingSub;

public KineticPartMachine(IMachineBlockEntity holder, int tier, IO io, Object... args) {
super(holder, tier, io);
this.stressTrait = createStressTrait(args);
stopWorkingSub = subscribeServerTick(stopWorkingSub, this::stopWhenControllerNotWorking);
}

//////////////////////////////////////
Expand Down Expand Up @@ -62,6 +70,47 @@ public void onRotated(Direction oldFacing, Direction newFacing) {
}
}

@Override
public boolean onWorking(IWorkableMultiController controller) {
if (stopWorkingSub == null) {
stopWorkingSub = subscribeServerTick(this::stopWhenControllerNotWorking);
}
return super.onWorking(controller);
}

private void stopWhenControllerNotWorking() {
for (IMultiController controller : getControllers()) {
if (controller instanceof IWorkableMultiController workableMultiController) {
if (!workableMultiController.getRecipeLogic().isWorking()) {
getKineticHolder().stopWorking();
assert stopWorkingSub != null;
stopWorkingSub.unsubscribe();
stopWorkingSub = null;
}
}
}
}

@Override
public boolean onWaiting(IWorkableMultiController controller) {
getKineticHolder().stopWorking();
return super.onWaiting(controller);
}

@Override
public void removedFromController(IMultiController controller) {
super.removedFromController(controller);
getKineticHolder().stopWorking();
}

@Override
public void setWorkingEnabled(boolean workingEnabled) {
if (!workingEnabled) {
getKineticHolder().stopWorking();
}
super.setWorkingEnabled(workingEnabled);
}

//////////////////////////////////////
//********* GUI *********//
//////////////////////////////////////
Expand Down

0 comments on commit 9e7e694

Please sign in to comment.