More SonarQube fixes.
This commit is contained in:
		@@ -54,4 +54,7 @@ public final class RSContainers {
 | 
				
			|||||||
    public static final ContainerType<CraftingMonitorContainer> CRAFTING_MONITOR = null;
 | 
					    public static final ContainerType<CraftingMonitorContainer> CRAFTING_MONITOR = null;
 | 
				
			||||||
    @ObjectHolder("wireless_crafting_monitor")
 | 
					    @ObjectHolder("wireless_crafting_monitor")
 | 
				
			||||||
    public static final ContainerType<CraftingMonitorContainer> WIRELESS_CRAFTING_MONITOR = null;
 | 
					    public static final ContainerType<CraftingMonitorContainer> WIRELESS_CRAFTING_MONITOR = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private RSContainers() {
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -123,54 +123,15 @@ public class CraftingManager implements ICraftingManager {
 | 
				
			|||||||
    public void update() {
 | 
					    public void update() {
 | 
				
			||||||
        if (network.canRun()) {
 | 
					        if (network.canRun()) {
 | 
				
			||||||
            if (tasksToRead != null) {
 | 
					            if (tasksToRead != null) {
 | 
				
			||||||
                for (int i = 0; i < tasksToRead.size(); ++i) {
 | 
					                readTasks();
 | 
				
			||||||
                    CompoundNBT taskTag = tasksToRead.getCompound(i);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    ResourceLocation taskType = new ResourceLocation(taskTag.getString(NBT_TASK_TYPE));
 | 
					 | 
				
			||||||
                    CompoundNBT taskData = taskTag.getCompound(NBT_TASK_DATA);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    ICraftingTaskFactory factory = API.instance().getCraftingTaskRegistry().get(taskType);
 | 
					 | 
				
			||||||
                    if (factory != null) {
 | 
					 | 
				
			||||||
                        try {
 | 
					 | 
				
			||||||
                            ICraftingTask task = factory.createFromNbt(network, taskData);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                            tasks.put(task.getId(), task);
 | 
					 | 
				
			||||||
                        } catch (CraftingTaskReadException e) {
 | 
					 | 
				
			||||||
                            LOGGER.error("Could not deserialize crafting task", e);
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                this.tasksToRead = null;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            boolean changed = !tasksToCancel.isEmpty() || !tasksToAdd.isEmpty();
 | 
					            boolean changed = !tasksToCancel.isEmpty() || !tasksToAdd.isEmpty();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for (UUID idToCancel : tasksToCancel) {
 | 
					            processTasksToCancel();
 | 
				
			||||||
                if (this.tasks.containsKey(idToCancel)) {
 | 
					            processTasksToAdd();
 | 
				
			||||||
                    this.tasks.get(idToCancel).onCancelled();
 | 
					 | 
				
			||||||
                    this.tasks.remove(idToCancel);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            this.tasksToCancel.clear();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for (ICraftingTask task : this.tasksToAdd) {
 | 
					            boolean anyFinished = updateTasks();
 | 
				
			||||||
                this.tasks.put(task.getId(), task);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            this.tasksToAdd.clear();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            boolean anyFinished = false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            Iterator<Map.Entry<UUID, ICraftingTask>> it = tasks.entrySet().iterator();
 | 
					 | 
				
			||||||
            while (it.hasNext()) {
 | 
					 | 
				
			||||||
                ICraftingTask task = it.next().getValue();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if (task.update()) {
 | 
					 | 
				
			||||||
                    anyFinished = true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    it.remove();
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (changed || anyFinished) {
 | 
					            if (changed || anyFinished) {
 | 
				
			||||||
                onTaskChanged();
 | 
					                onTaskChanged();
 | 
				
			||||||
@@ -182,6 +143,62 @@ public class CraftingManager implements ICraftingManager {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void processTasksToCancel() {
 | 
				
			||||||
 | 
					        for (UUID idToCancel : tasksToCancel) {
 | 
				
			||||||
 | 
					            if (this.tasks.containsKey(idToCancel)) {
 | 
				
			||||||
 | 
					                this.tasks.get(idToCancel).onCancelled();
 | 
				
			||||||
 | 
					                this.tasks.remove(idToCancel);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        this.tasksToCancel.clear();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void processTasksToAdd() {
 | 
				
			||||||
 | 
					        for (ICraftingTask task : this.tasksToAdd) {
 | 
				
			||||||
 | 
					            this.tasks.put(task.getId(), task);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        this.tasksToAdd.clear();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private boolean updateTasks() {
 | 
				
			||||||
 | 
					        boolean anyFinished = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Iterator<Map.Entry<UUID, ICraftingTask>> it = tasks.entrySet().iterator();
 | 
				
			||||||
 | 
					        while (it.hasNext()) {
 | 
				
			||||||
 | 
					            ICraftingTask task = it.next().getValue();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (task.update()) {
 | 
				
			||||||
 | 
					                anyFinished = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                it.remove();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return anyFinished;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void readTasks() {
 | 
				
			||||||
 | 
					        for (int i = 0; i < tasksToRead.size(); ++i) {
 | 
				
			||||||
 | 
					            CompoundNBT taskTag = tasksToRead.getCompound(i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            ResourceLocation taskType = new ResourceLocation(taskTag.getString(NBT_TASK_TYPE));
 | 
				
			||||||
 | 
					            CompoundNBT taskData = taskTag.getCompound(NBT_TASK_DATA);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            ICraftingTaskFactory factory = API.instance().getCraftingTaskRegistry().get(taskType);
 | 
				
			||||||
 | 
					            if (factory != null) {
 | 
				
			||||||
 | 
					                try {
 | 
				
			||||||
 | 
					                    ICraftingTask task = factory.createFromNbt(network, taskData);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    tasks.put(task.getId(), task);
 | 
				
			||||||
 | 
					                } catch (CraftingTaskReadException e) {
 | 
				
			||||||
 | 
					                    LOGGER.error("Could not deserialize crafting task", e);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        this.tasksToRead = null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void readFromNbt(CompoundNBT tag) {
 | 
					    public void readFromNbt(CompoundNBT tag) {
 | 
				
			||||||
        this.tasksToRead = tag.getList(NBT_TASKS, Constants.NBT.TAG_COMPOUND);
 | 
					        this.tasksToRead = tag.getList(NBT_TASKS, Constants.NBT.TAG_COMPOUND);
 | 
				
			||||||
@@ -230,10 +247,8 @@ public class CraftingManager implements ICraftingManager {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (ICraftingTask task : getTasks()) {
 | 
					        for (ICraftingTask task : getTasks()) {
 | 
				
			||||||
            if (task.getRequested().getItem() != null) {
 | 
					            if (task.getRequested().getItem() != null && API.instance().getComparer().isEqualNoQuantity(task.getRequested().getItem(), stack)) {
 | 
				
			||||||
                if (API.instance().getComparer().isEqualNoQuantity(task.getRequested().getItem(), stack)) {
 | 
					                amount -= task.getQuantity();
 | 
				
			||||||
                    amount -= task.getQuantity();
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -242,6 +257,8 @@ public class CraftingManager implements ICraftingManager {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            if (result.isOk()) {
 | 
					            if (result.isOk()) {
 | 
				
			||||||
                start(result.getTask());
 | 
					                start(result.getTask());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                return result.getTask();
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                throttle(source);
 | 
					                throttle(source);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -258,10 +275,8 @@ public class CraftingManager implements ICraftingManager {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (ICraftingTask task : getTasks()) {
 | 
					        for (ICraftingTask task : getTasks()) {
 | 
				
			||||||
            if (task.getRequested().getFluid() != null) {
 | 
					            if (task.getRequested().getFluid() != null && API.instance().getComparer().isEqual(task.getRequested().getFluid(), stack, IComparer.COMPARE_NBT)) {
 | 
				
			||||||
                if (API.instance().getComparer().isEqual(task.getRequested().getFluid(), stack, IComparer.COMPARE_NBT)) {
 | 
					                amount -= task.getQuantity();
 | 
				
			||||||
                    amount -= task.getQuantity();
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -270,6 +285,8 @@ public class CraftingManager implements ICraftingManager {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            if (result.isOk()) {
 | 
					            if (result.isOk()) {
 | 
				
			||||||
                start(result.getTask());
 | 
					                start(result.getTask());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                return result.getTask();
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                throttle(source);
 | 
					                throttle(source);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -345,15 +362,7 @@ public class CraftingManager implements ICraftingManager {
 | 
				
			|||||||
        this.containerInventories.clear();
 | 
					        this.containerInventories.clear();
 | 
				
			||||||
        this.patternToContainer.clear();
 | 
					        this.patternToContainer.clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        List<ICraftingPatternContainer> containers = new ArrayList<>();
 | 
					        List<ICraftingPatternContainer> containers = getContainers();
 | 
				
			||||||
 | 
					 | 
				
			||||||
        for (INetworkNode node : network.getNodeGraph().all()) {
 | 
					 | 
				
			||||||
            if (node instanceof ICraftingPatternContainer && node.isActive()) {
 | 
					 | 
				
			||||||
                containers.add((ICraftingPatternContainer) node);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        containers.sort((a, b) -> b.getPosition().compareTo(a.getPosition()));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (ICraftingPatternContainer container : containers) {
 | 
					        for (ICraftingPatternContainer container : containers) {
 | 
				
			||||||
            for (ICraftingPattern pattern : container.getPatterns()) {
 | 
					            for (ICraftingPattern pattern : container.getPatterns()) {
 | 
				
			||||||
@@ -367,12 +376,8 @@ public class CraftingManager implements ICraftingManager {
 | 
				
			|||||||
                    network.getFluidStorageCache().getCraftablesList().add(output);
 | 
					                    network.getFluidStorageCache().getCraftablesList().add(output);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                Set<ICraftingPatternContainer> list = this.patternToContainer.get(pattern);
 | 
					                Set<ICraftingPatternContainer> containersForPattern = this.patternToContainer.computeIfAbsent(pattern, (key) -> new LinkedHashSet<>());
 | 
				
			||||||
                if (list == null) {
 | 
					                containersForPattern.add(container);
 | 
				
			||||||
                    list = new LinkedHashSet<>();
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                list.add(container);
 | 
					 | 
				
			||||||
                this.patternToContainer.put(pattern, list);
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            IItemHandlerModifiable handler = container.getPatternInventory();
 | 
					            IItemHandlerModifiable handler = container.getPatternInventory();
 | 
				
			||||||
@@ -385,6 +390,20 @@ public class CraftingManager implements ICraftingManager {
 | 
				
			|||||||
        this.network.getFluidStorageCache().reAttachListeners();
 | 
					        this.network.getFluidStorageCache().reAttachListeners();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private List<ICraftingPatternContainer> getContainers() {
 | 
				
			||||||
 | 
					        List<ICraftingPatternContainer> containers = new ArrayList<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (INetworkNode node : network.getNodeGraph().all()) {
 | 
				
			||||||
 | 
					            if (node instanceof ICraftingPatternContainer && node.isActive()) {
 | 
				
			||||||
 | 
					                containers.add((ICraftingPatternContainer) node);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        containers.sort((a, b) -> b.getPosition().compareTo(a.getPosition()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return containers;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public Set<ICraftingPatternContainer> getAllContainers(ICraftingPattern pattern) {
 | 
					    public Set<ICraftingPatternContainer> getAllContainers(ICraftingPattern pattern) {
 | 
				
			||||||
        return patternToContainer.getOrDefault(pattern, Collections.emptySet());
 | 
					        return patternToContainer.getOrDefault(pattern, Collections.emptySet());
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -67,7 +67,7 @@ public class NetworkNodeManager extends WorldSavedData implements INetworkNodeMa
 | 
				
			|||||||
                        this.nodes.put(pos, node);
 | 
					                        this.nodes.put(pos, node);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    logger.warn("Factory for " + id + " not found in network node registry");
 | 
					                    logger.warn("Factory for {} not found in network node registry", id);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,6 @@
 | 
				
			|||||||
package com.refinedmods.refinedstorage.apiimpl.network.grid;
 | 
					package com.refinedmods.refinedstorage.apiimpl.network.grid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.refinedmods.refinedstorage.api.network.grid.GridFactoryType;
 | 
				
			||||||
import com.refinedmods.refinedstorage.api.network.grid.IGrid;
 | 
					import com.refinedmods.refinedstorage.api.network.grid.IGrid;
 | 
				
			||||||
import com.refinedmods.refinedstorage.api.network.grid.IGridFactory;
 | 
					import com.refinedmods.refinedstorage.api.network.grid.IGridFactory;
 | 
				
			||||||
import com.refinedmods.refinedstorage.api.network.grid.IGridManager;
 | 
					import com.refinedmods.refinedstorage.api.network.grid.IGridManager;
 | 
				
			||||||
@@ -70,13 +71,10 @@ public class GridManager implements IGridManager {
 | 
				
			|||||||
        IGrid grid = null;
 | 
					        IGrid grid = null;
 | 
				
			||||||
        TileEntity tile = factory.getRelevantTile(player.world, pos);
 | 
					        TileEntity tile = factory.getRelevantTile(player.world, pos);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        switch (factory.getType()) {
 | 
					        if (factory.getType() == GridFactoryType.STACK) {
 | 
				
			||||||
            case STACK:
 | 
					            grid = factory.createFromStack(player, stack, slotId);
 | 
				
			||||||
                grid = factory.createFromStack(player, stack, slotId);
 | 
					        } else if (factory.getType() == GridFactoryType.BLOCK) {
 | 
				
			||||||
                break;
 | 
					            grid = factory.createFromBlock(player, pos);
 | 
				
			||||||
            case BLOCK:
 | 
					 | 
				
			||||||
                grid = factory.createFromBlock(player, pos);
 | 
					 | 
				
			||||||
                break;
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (grid == null) {
 | 
					        if (grid == null) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user