More SonarQube fixes.

This commit is contained in:
raoulvdberge
2020-10-17 14:10:54 +02:00
parent 9bf1fb892a
commit b57cddf8fa
4 changed files with 36 additions and 80 deletions

View File

@@ -214,17 +214,17 @@ public class ProcessingNode extends Node {
}
public void updateFinishedQuantity() {
int quantityFinished = totalQuantity;
int tempQuantityFinished = totalQuantity;
for (StackListEntry<ItemStack> toReceive : singleItemSetToReceive.getStacks()) {
if (itemsReceived.get(toReceive.getStack()) != null) {
int ratioReceived = itemsReceived.get(toReceive.getStack()).getCount() / toReceive.getStack().getCount();
if (quantityFinished > ratioReceived) {
quantityFinished = ratioReceived;
if (tempQuantityFinished > ratioReceived) {
tempQuantityFinished = ratioReceived;
}
} else {
quantityFinished = 0;
tempQuantityFinished = 0;
}
}
@@ -232,15 +232,15 @@ public class ProcessingNode extends Node {
if (fluidsReceived.get(toReceive.getStack()) != null) {
int ratioReceived = fluidsReceived.get(toReceive.getStack()).getAmount() / toReceive.getStack().getAmount();
if (quantityFinished > ratioReceived) {
quantityFinished = ratioReceived;
if (tempQuantityFinished > ratioReceived) {
tempQuantityFinished = ratioReceived;
}
} else {
quantityFinished = 0;
tempQuantityFinished = 0;
}
}
this.quantityFinished = quantityFinished;
this.quantityFinished = tempQuantityFinished;
if (this.quantityFinished == this.totalQuantity) {
this.state = ProcessingState.PROCESSED;

View File

@@ -22,87 +22,45 @@ public class CraftingPreviewElementFactory {
for (StackListEntry<ItemStack> stack : info.getMissing().getStacks()) {
int hash = API.instance().getItemStackHashCode(stack.getStack());
ItemCraftingPreviewElement previewStack = map.get(hash);
if (previewStack == null) {
previewStack = new ItemCraftingPreviewElement(stack.getStack());
}
ItemCraftingPreviewElement previewStack = map.computeIfAbsent(hash, key -> new ItemCraftingPreviewElement(stack.getStack()));
previewStack.setMissing(true);
previewStack.addToCraft(stack.getStack().getCount());
map.put(hash, previewStack);
}
for (StackListEntry<FluidStack> stack : info.getMissingFluids().getStacks()) {
int hash = API.instance().getFluidStackHashCode(stack.getStack());
FluidCraftingPreviewElement previewStack = mapFluids.get(hash);
if (previewStack == null) {
previewStack = new FluidCraftingPreviewElement(stack.getStack());
}
FluidCraftingPreviewElement previewStack = mapFluids.computeIfAbsent(hash, key -> new FluidCraftingPreviewElement(stack.getStack()));
previewStack.setMissing(true);
previewStack.addToCraft(stack.getStack().getAmount());
mapFluids.put(hash, previewStack);
}
for (ItemStack stack : ImmutableList.copyOf(info.getToCraft()).reverse()) {
int hash = API.instance().getItemStackHashCode(stack);
ItemCraftingPreviewElement previewStack = map.get(hash);
if (previewStack == null) {
previewStack = new ItemCraftingPreviewElement(stack.getStack());
}
ItemCraftingPreviewElement previewStack = map.computeIfAbsent(hash, key -> new ItemCraftingPreviewElement(stack.getStack()));
previewStack.addToCraft(stack.getCount());
map.put(hash, previewStack);
}
for (FluidStack stack : ImmutableList.copyOf(info.getToCraftFluids()).reverse()) {
int hash = API.instance().getFluidStackHashCode(stack);
FluidCraftingPreviewElement previewStack = mapFluids.get(hash);
if (previewStack == null) {
previewStack = new FluidCraftingPreviewElement(stack);
}
FluidCraftingPreviewElement previewStack = mapFluids.computeIfAbsent(hash, key -> new FluidCraftingPreviewElement(stack));
previewStack.addToCraft(stack.getAmount());
mapFluids.put(hash, previewStack);
}
for (StackListEntry<ItemStack> stack : info.getToTake().getStacks()) {
int hash = API.instance().getItemStackHashCode(stack.getStack());
ItemCraftingPreviewElement previewStack = map.get(hash);
if (previewStack == null) {
previewStack = new ItemCraftingPreviewElement(stack.getStack());
}
ItemCraftingPreviewElement previewStack = map.computeIfAbsent(hash, key -> new ItemCraftingPreviewElement(stack.getStack()));
previewStack.addAvailable(stack.getStack().getCount());
map.put(hash, previewStack);
}
for (StackListEntry<FluidStack> stack : info.getToTakeFluids().getStacks()) {
int hash = API.instance().getFluidStackHashCode(stack.getStack());
FluidCraftingPreviewElement previewStack = mapFluids.get(hash);
if (previewStack == null) {
previewStack = new FluidCraftingPreviewElement(stack.getStack());
}
FluidCraftingPreviewElement previewStack = mapFluids.computeIfAbsent(hash, key -> new FluidCraftingPreviewElement(stack.getStack()));
previewStack.addAvailable(stack.getStack().getAmount());
mapFluids.put(hash, previewStack);
}
List<ICraftingPreviewElement<?>> elements = new ArrayList<>();

View File

@@ -10,8 +10,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
public class NetworkListener {
@SubscribeEvent
public void onWorldTick(TickEvent.WorldTickEvent e) {
if (!e.world.isRemote()) {
if (e.phase == TickEvent.Phase.END) {
if (!e.world.isRemote() && e.phase == TickEvent.Phase.END) {
e.world.getProfiler().startSection("network ticking");
for (INetwork network : API.instance().getNetworkManager((ServerWorld) e.world).all()) {
@@ -29,5 +28,4 @@ public class NetworkListener {
e.world.getProfiler().endSection();
}
}
}
}

View File

@@ -100,14 +100,6 @@ public class NetworkNodeGraph implements INetworkNodeGraph {
return network.getWorld();
}
private void dropConflictingBlock(World world, BlockPos pos) {
if (!network.getPosition().equals(pos)) {
Block.spawnDrops(world.getBlockState(pos), world, pos, world.getTileEntity(pos));
world.removeBlock(pos, false);
}
}
private class Operator implements INetworkNodeVisitor.Operator {
private final Set<INetworkNode> foundNodes = Sets.newConcurrentHashSet(); // All scanned nodes
@@ -152,6 +144,14 @@ public class NetworkNodeGraph implements INetworkNodeGraph {
}
}
private void dropConflictingBlock(World world, BlockPos pos) {
if (!network.getPosition().equals(pos)) {
Block.spawnDrops(world.getBlockState(pos), world, pos, world.getTileEntity(pos));
world.removeBlock(pos, false);
}
}
@Override
public Action getAction() {
return action;