Remove calculation threads causing concurrency issues (#3002)

This commit is contained in:
Anton Bulakh
2021-06-09 18:54:49 +03:00
committed by GitHub
parent c45991ed83
commit 7a888aaf3e
2 changed files with 53 additions and 61 deletions

View File

@@ -99,40 +99,36 @@ public class FluidGridHandler implements IFluidGridHandler {
FluidStack stack = network.getFluidStorageCache().getCraftablesList().get(id); FluidStack stack = network.getFluidStorageCache().getCraftablesList().get(id);
if (stack != null) { if (stack != null) {
Thread calculationThread = new Thread(() -> { ICalculationResult result = network.getCraftingManager().create(stack, quantity);
ICalculationResult result = network.getCraftingManager().create(stack, quantity); if (result == null) {
if (result == null) { return;
return; }
}
if (!result.isOk() && result.getType() != CalculationResultType.MISSING) { if (!result.isOk() && result.getType() != CalculationResultType.MISSING) {
RS.NETWORK_HANDLER.sendTo( RS.NETWORK_HANDLER.sendTo(
player, player,
new GridCraftingPreviewResponseMessage( new GridCraftingPreviewResponseMessage(
Collections.singletonList(new ErrorCraftingPreviewElement(result.getType(), result.getRecursedPattern() == null ? ItemStack.EMPTY : result.getRecursedPattern().getStack())), Collections.singletonList(new ErrorCraftingPreviewElement(result.getType(), result.getRecursedPattern() == null ? ItemStack.EMPTY : result.getRecursedPattern().getStack())),
id, id,
quantity, quantity,
true true
) )
); );
} else if (result.isOk() && noPreview) { } else if (result.isOk() && noPreview) {
network.getCraftingManager().start(result.getTask()); network.getCraftingManager().start(result.getTask());
RS.NETWORK_HANDLER.sendTo(player, new GridCraftingStartResponseMessage()); RS.NETWORK_HANDLER.sendTo(player, new GridCraftingStartResponseMessage());
} else { } else {
RS.NETWORK_HANDLER.sendTo( RS.NETWORK_HANDLER.sendTo(
player, player,
new GridCraftingPreviewResponseMessage( new GridCraftingPreviewResponseMessage(
result.getPreviewElements(), result.getPreviewElements(),
id, id,
quantity, quantity,
true true
) )
); );
} }
}, "RS crafting preview calculation");
calculationThread.start();
} }
} }

View File

@@ -190,37 +190,33 @@ public class ItemGridHandler implements IItemGridHandler {
ItemStack stack = network.getItemStorageCache().getCraftablesList().get(id); ItemStack stack = network.getItemStorageCache().getCraftablesList().get(id);
if (stack != null) { if (stack != null) {
Thread calculationThread = new Thread(() -> { ICalculationResult result = network.getCraftingManager().create(stack, quantity);
ICalculationResult result = network.getCraftingManager().create(stack, quantity);
if (!result.isOk() && result.getType() != CalculationResultType.MISSING) { if (!result.isOk() && result.getType() != CalculationResultType.MISSING) {
RS.NETWORK_HANDLER.sendTo( RS.NETWORK_HANDLER.sendTo(
player, player,
new GridCraftingPreviewResponseMessage( new GridCraftingPreviewResponseMessage(
Collections.singletonList(new ErrorCraftingPreviewElement(result.getType(), result.getRecursedPattern() == null ? ItemStack.EMPTY : result.getRecursedPattern().getStack())), Collections.singletonList(new ErrorCraftingPreviewElement(result.getType(), result.getRecursedPattern() == null ? ItemStack.EMPTY : result.getRecursedPattern().getStack())),
id, id,
quantity, quantity,
false false
) )
); );
} else if (result.isOk() && noPreview) { } else if (result.isOk() && noPreview) {
network.getCraftingManager().start(result.getTask()); network.getCraftingManager().start(result.getTask());
RS.NETWORK_HANDLER.sendTo(player, new GridCraftingStartResponseMessage()); RS.NETWORK_HANDLER.sendTo(player, new GridCraftingStartResponseMessage());
} else { } else {
RS.NETWORK_HANDLER.sendTo( RS.NETWORK_HANDLER.sendTo(
player, player,
new GridCraftingPreviewResponseMessage( new GridCraftingPreviewResponseMessage(
result.getPreviewElements(), result.getPreviewElements(),
id, id,
quantity, quantity,
false false
) )
); );
} }
}, "RS crafting preview calculation");
calculationThread.start();
} }
} }