Skip to content

Commit

Permalink
fix Crystal growth chamber from consuming power even when buffer is full
Browse files Browse the repository at this point in the history
buff advanced inscriber speed
  • Loading branch information
ProjectET committed Jul 30, 2024
1 parent 5ef4e01 commit 35ffd03
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class BEAdvancedInscriber extends AENetworkPowerBlockEntity implements IG
private final IUpgradeInventory upgrades;
private InscriberRecipe cachedTask;
private int processingTime = 0;
private final int maxProcessingTime = 100;
private final int maxProcessingTime = 50;
private boolean working;

public boolean topLock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,88 +102,71 @@ public boolean hasWork() {
}
return !cachedRecipes.isEmpty();
}

private boolean outputhasItem() {
for (InternalInventory inv: progress.keySet()) {
if(inv.getStackInSlot(3).getItem() != Items.AIR) {
return false;
}
}
return true;
}
private boolean outputIsFull() {
private int howManyFull() {
int full = 0;
for (InternalInventory inv: progress.keySet()) {
if(inv.getStackInSlot(3).getCount() != 64) {
return false;
if(inv.getStackInSlot(3).getCount() == 64) {
full++;
}
}
return true;
return full;
}

@Override
public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) {
if (isWorking()) {
final int speedFactor = 1 + this.upgrades.getInstalledUpgrades(AEItems.SPEED_CARD);
final IEnergyService[] eg = new IEnergyService[1];
IEnergySource src = this;
getMainNode().ifPresent(iGrid -> eg[0] = iGrid.getEnergyService());
if (eg[0] == null) {
return TickRateModulation.IDLE;
}

final int powerConsumption = 10 * speedFactor * cachedRecipes.size();
final double powerThreshold = powerConsumption - 0.01;
double powerReq = this.extractAEPower(powerConsumption, Actionable.SIMULATE, PowerMultiplier.CONFIG);
if (powerReq <= powerThreshold) {
src = eg[0];
powerReq = eg[0].extractAEPower(powerConsumption, Actionable.SIMULATE, PowerMultiplier.CONFIG);
}

if (powerReq > powerThreshold) {
if (!isWorking()) {
isWorking = true;
markForUpdate();
getMainNode().ifPresent(iGrid -> {
int speedFactor = 1 + this.upgrades.getInstalledUpgrades(AEItems.SPEED_CARD);
IEnergyService eg = iGrid.getEnergyService();
IEnergySource src = this;
final int powerConsumption = 10 * speedFactor * (cachedRecipes.size() - howManyFull());
final double powerThreshold = powerConsumption - 0.01;
double powerReq = this.extractAEPower(powerConsumption, Actionable.SIMULATE, PowerMultiplier.CONFIG);
if (powerReq <= powerThreshold) {
src = eg;
powerReq = eg.extractAEPower(powerConsumption, Actionable.SIMULATE, PowerMultiplier.CONFIG);
}
src.extractAEPower(powerConsumption, Actionable.MODULATE, PowerMultiplier.CONFIG);
cachedRecipes.forEach((inventory, recipe) -> {
if(recipe != null) {
int d = progress.get(inventory);
if(d >= 100) {
ItemStack resultItem = recipe.getResultItem(RegistryAccess.EMPTY);
if(inventory.insertItem(3, resultItem, true).getCount() != 0)
return;
int i = 2;
while(inventory.getStackInSlot(i).getItem() == Items.AIR && i >= 1) {
i--;
}
ItemStack stack = inventory.getStackInSlot(i);
if(stack.getItem() != Items.AIR) {
Item item = recipe.nextStage(stack);
if(r.nextInt(12) == 0 && !recipe.isFlawless(stack)) {
inventory.getStackInSlot(i).shrink(1);
if(item != Items.AIR && i != 2) {
inventory.setItemDirect(i + 1, new ItemStack(item));
if(powerReq > powerThreshold) {
if(!isWorking()) {
isWorking = true;
markForUpdate();
}
src.extractAEPower(powerConsumption, Actionable.MODULATE, PowerMultiplier.CONFIG);
cachedRecipes.forEach((inventory, recipe) -> {
if(recipe != null) {
int d = progress.get(inventory);
if(d >= 100) {
ItemStack resultItem = recipe.getResultItem(RegistryAccess.EMPTY);
if(inventory.insertItem(3, resultItem, true).getCount() != 0)
return;
int i = 2;
while(inventory.getStackInSlot(i).getItem() == Items.AIR && i >= 1) {
i--;
}
ItemStack stack = inventory.getStackInSlot(i);
if(stack.getItem() != Items.AIR) {
Item item = recipe.nextStage(stack);
if(r.nextInt(12) == 0 && !recipe.isFlawless(stack)) {
inventory.getStackInSlot(i).shrink(1);
if(item != Items.AIR && i != 2) {
inventory.setItemDirect(i + 1, new ItemStack(item));
}
else
inventory.getStackInSlot(i + 1).grow(1);
}
else
inventory.getStackInSlot(i + 1).grow(1);
}
inventory.insertItem(3, resultItem, false);
progress.put(inventory, 0);
saveChanges();
}
else {
if(inventory.getStackInSlot(3).getCount() != 64)
progress.put(inventory, d + speedFactor);
}
inventory.insertItem(3, resultItem, false);
progress.put(inventory, 0);
saveChanges();
}
else {
progress.put(inventory, d + speedFactor);
}
}
});
} else {
if (isWorking()) {
isWorking = false;
this.markForUpdate();
});
}
return TickRateModulation.SLEEP;
}
});
}
clearEmptyCache();
matchWork();
Expand All @@ -199,6 +182,7 @@ public void onReady() {
private void clearEmptyCache() {
for (InternalInventory inv: toRemove) {
cachedRecipes.remove(inv);
progress.put(inv, 0);
}
toRemove.clear();
}
Expand Down Expand Up @@ -300,6 +284,7 @@ public void onChangeInventory(InternalInventory inv, int slot) {
CrystalGrowthRecipe recipe = CrystalGrowthRecipe.getRecipefromStack(this.level, inv.getStackInSlot(slot));
if(cachedRecipes.get(inv) != recipe && recipe != null) {
cachedRecipes.put(inv, recipe);
progress.put(inv, 0);
}
else if(!hasIngredients(inv)) {
toRemove.add(inv);
Expand Down

0 comments on commit 35ffd03

Please sign in to comment.