More SonarQube fixes.
This commit is contained in:
@@ -111,7 +111,7 @@ public final class IoUtil {
|
|||||||
boolean success = current == null && stacks.isEmpty();
|
boolean success = current == null && stacks.isEmpty();
|
||||||
|
|
||||||
if (!success && action == Action.PERFORM) {
|
if (!success && action == Action.PERFORM) {
|
||||||
LOGGER.warn("Inventory unexpectedly didn't accept " + (current != null ? current.getTranslationKey() : null) + ", the remainder has been voided!");
|
LOGGER.warn("Inventory unexpectedly didn't accept {}, the remainder has been voided!", current != null ? current.getTranslationKey() : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
@@ -123,7 +123,7 @@ public final class IoUtil {
|
|||||||
|
|
||||||
if (filled != entry.getStack().getAmount()) {
|
if (filled != entry.getStack().getAmount()) {
|
||||||
if (action == Action.PERFORM) {
|
if (action == Action.PERFORM) {
|
||||||
LOGGER.warn("Inventory unexpectedly didn't accept all of " + entry.getStack().getTranslationKey() + ", the remainder has been voided!");
|
LOGGER.warn("Inventory unexpectedly didn't accept all of {}, the remainder has been voided!", entry.getStack().getTranslationKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@@ -21,6 +21,9 @@ public class SerializationUtil {
|
|||||||
private static final String NBT_PATTERN_STACK = "Stack";
|
private static final String NBT_PATTERN_STACK = "Stack";
|
||||||
private static final String NBT_PATTERN_CONTAINER_POS = "ContainerPos";
|
private static final String NBT_PATTERN_CONTAINER_POS = "ContainerPos";
|
||||||
|
|
||||||
|
private SerializationUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
public static ListNBT writeItemStackList(IStackList<ItemStack> stacks) {
|
public static ListNBT writeItemStackList(IStackList<ItemStack> stacks) {
|
||||||
ListNBT list = new ListNBT();
|
ListNBT list = new ListNBT();
|
||||||
|
|
||||||
|
@@ -8,7 +8,7 @@ import javax.annotation.Nullable;
|
|||||||
public class CraftingCalculatorException extends Exception {
|
public class CraftingCalculatorException extends Exception {
|
||||||
private final CalculationResultType type;
|
private final CalculationResultType type;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final ICraftingPattern recursedPattern;
|
private final transient ICraftingPattern recursedPattern;
|
||||||
|
|
||||||
public CraftingCalculatorException(CalculationResultType type) {
|
public CraftingCalculatorException(CalculationResultType type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
@@ -24,12 +24,12 @@ public abstract class Node {
|
|||||||
|
|
||||||
protected final NodeRequirements requirements = new NodeRequirements();
|
protected final NodeRequirements requirements = new NodeRequirements();
|
||||||
|
|
||||||
public Node(ICraftingPattern pattern, boolean root) {
|
protected Node(ICraftingPattern pattern, boolean root) {
|
||||||
this.pattern = pattern;
|
this.pattern = pattern;
|
||||||
this.root = root;
|
this.root = root;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Node(INetwork network, CompoundNBT tag) throws CraftingTaskReadException {
|
protected Node(INetwork network, CompoundNBT tag) throws CraftingTaskReadException {
|
||||||
this.quantity = tag.getInt(NBT_QUANTITY);
|
this.quantity = tag.getInt(NBT_QUANTITY);
|
||||||
this.totalQuantity = tag.getInt(NBT_QUANTITY_TOTAL);
|
this.totalQuantity = tag.getInt(NBT_QUANTITY_TOTAL);
|
||||||
this.pattern = SerializationUtil.readPatternFromNbt(tag.getCompound(NBT_PATTERN), network.getWorld());
|
this.pattern = SerializationUtil.readPatternFromNbt(tag.getCompound(NBT_PATTERN), network.getWorld());
|
||||||
|
@@ -40,11 +40,7 @@ public class NodeList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Node createOrAddToExistingNode(ICraftingPattern pattern, boolean root, NonNullList<ItemStack> recipe, int qty) {
|
public Node createOrAddToExistingNode(ICraftingPattern pattern, boolean root, NonNullList<ItemStack> recipe, int qty) {
|
||||||
Node node = nodes.get(pattern);
|
Node node = nodes.computeIfAbsent(pattern, key -> createNode(key, root, recipe));
|
||||||
if (node == null) {
|
|
||||||
nodes.put(pattern, node = createNode(pattern, root, recipe));
|
|
||||||
}
|
|
||||||
|
|
||||||
node.addQuantity(qty);
|
node.addQuantity(qty);
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
|
@@ -35,11 +35,7 @@ public class NodeRequirements {
|
|||||||
itemsNeededPerCraft.put(ingredientNumber, perCraft);
|
itemsNeededPerCraft.put(ingredientNumber, perCraft);
|
||||||
}
|
}
|
||||||
|
|
||||||
IStackList<ItemStack> list = itemRequirements.get(ingredientNumber);
|
IStackList<ItemStack> list = itemRequirements.computeIfAbsent(ingredientNumber, key -> API.instance().createItemStackList());
|
||||||
if (list == null) {
|
|
||||||
itemRequirements.put(ingredientNumber, list = API.instance().createItemStackList());
|
|
||||||
}
|
|
||||||
|
|
||||||
list.add(stack, size);
|
list.add(stack, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,11 +44,7 @@ public class NodeRequirements {
|
|||||||
fluidsNeededPerCraft.put(ingredientNumber, perCraft);
|
fluidsNeededPerCraft.put(ingredientNumber, perCraft);
|
||||||
}
|
}
|
||||||
|
|
||||||
IStackList<FluidStack> list = fluidRequirements.get(ingredientNumber);
|
IStackList<FluidStack> list = fluidRequirements.computeIfAbsent(ingredientNumber, key -> API.instance().createFluidStackList());
|
||||||
if (list == null) {
|
|
||||||
fluidRequirements.put(ingredientNumber, list = API.instance().createFluidStackList());
|
|
||||||
}
|
|
||||||
|
|
||||||
list.add(stack, size);
|
list.add(stack, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,41 +125,41 @@ public class NodeRequirements {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void readFromNbt(CompoundNBT tag) throws CraftingTaskReadException {
|
public void readFromNbt(CompoundNBT tag) throws CraftingTaskReadException {
|
||||||
ListNBT itemRequirements = tag.getList(NBT_ITEMS_TO_USE, Constants.NBT.TAG_LIST);
|
ListNBT itemRequirementsTag = tag.getList(NBT_ITEMS_TO_USE, Constants.NBT.TAG_LIST);
|
||||||
for (int i = 0; i < itemRequirements.size(); i++) {
|
for (int i = 0; i < itemRequirementsTag.size(); i++) {
|
||||||
this.itemRequirements.put(i, SerializationUtil.readItemStackList(itemRequirements.getList(i)));
|
itemRequirements.put(i, SerializationUtil.readItemStackList(itemRequirementsTag.getList(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Integer> itemsNeededPerCraft = Ints.asList(tag.getIntArray(NBT_ITEMS_NEEDED_PER_CRAFT));
|
List<Integer> itemsNeededPerCraftTag = Ints.asList(tag.getIntArray(NBT_ITEMS_NEEDED_PER_CRAFT));
|
||||||
for (int i = 0; i < itemsNeededPerCraft.size(); i++) {
|
for (int i = 0; i < itemsNeededPerCraftTag.size(); i++) {
|
||||||
this.itemsNeededPerCraft.put(i, itemsNeededPerCraft.get(i));
|
itemsNeededPerCraft.put(i, itemsNeededPerCraftTag.get(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
ListNBT fluidRequirements = tag.getList(NBT_FLUIDS_TO_USE, Constants.NBT.TAG_LIST);
|
ListNBT fluidRequirementsTag = tag.getList(NBT_FLUIDS_TO_USE, Constants.NBT.TAG_LIST);
|
||||||
for (int i = 0; i < fluidRequirements.size(); i++) {
|
for (int i = 0; i < fluidRequirementsTag.size(); i++) {
|
||||||
this.fluidRequirements.put(i, SerializationUtil.readFluidStackList(fluidRequirements.getList(i)));
|
fluidRequirements.put(i, SerializationUtil.readFluidStackList(fluidRequirementsTag.getList(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Integer> fluidsNeededPerCraft = Ints.asList(tag.getIntArray(NBT_FLUIDS_NEEDED_PER_CRAFT));
|
List<Integer> fluidsNeededPerCraftTag = Ints.asList(tag.getIntArray(NBT_FLUIDS_NEEDED_PER_CRAFT));
|
||||||
for (int i = 0; i < fluidsNeededPerCraft.size(); i++) {
|
for (int i = 0; i < fluidsNeededPerCraftTag.size(); i++) {
|
||||||
this.fluidsNeededPerCraft.put(i, fluidsNeededPerCraft.get(i));
|
fluidsNeededPerCraft.put(i, fluidsNeededPerCraftTag.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompoundNBT writeToNbt(CompoundNBT tag) {
|
public CompoundNBT writeToNbt(CompoundNBT tag) {
|
||||||
ListNBT itemRequirements = new ListNBT();
|
ListNBT itemRequirementsTag = new ListNBT();
|
||||||
for (IStackList<ItemStack> list : this.itemRequirements.values()) {
|
for (IStackList<ItemStack> list : itemRequirements.values()) {
|
||||||
itemRequirements.add(SerializationUtil.writeItemStackList(list));
|
itemRequirementsTag.add(SerializationUtil.writeItemStackList(list));
|
||||||
}
|
}
|
||||||
tag.put(NBT_ITEMS_TO_USE, itemRequirements);
|
tag.put(NBT_ITEMS_TO_USE, itemRequirementsTag);
|
||||||
|
|
||||||
tag.putIntArray(NBT_ITEMS_NEEDED_PER_CRAFT, Ints.toArray(itemsNeededPerCraft.values()));
|
tag.putIntArray(NBT_ITEMS_NEEDED_PER_CRAFT, Ints.toArray(itemsNeededPerCraft.values()));
|
||||||
|
|
||||||
ListNBT fluidRequirements = new ListNBT();
|
ListNBT fluidRequirementsTag = new ListNBT();
|
||||||
for (IStackList<FluidStack> list : this.fluidRequirements.values()) {
|
for (IStackList<FluidStack> list : fluidRequirements.values()) {
|
||||||
fluidRequirements.add(SerializationUtil.writeFluidStackList(list));
|
fluidRequirementsTag.add(SerializationUtil.writeFluidStackList(list));
|
||||||
}
|
}
|
||||||
tag.put(NBT_FLUIDS_TO_USE, fluidRequirements);
|
tag.put(NBT_FLUIDS_TO_USE, fluidRequirementsTag);
|
||||||
|
|
||||||
tag.putIntArray(NBT_FLUIDS_NEEDED_PER_CRAFT, Ints.toArray(fluidsNeededPerCraft.values()));
|
tag.putIntArray(NBT_FLUIDS_NEEDED_PER_CRAFT, Ints.toArray(fluidsNeededPerCraft.values()));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user