mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-26 06:42:55 +00:00
Spotless
This commit is contained in:
1 parent
dfe94d1549
commit
d15ceed3d9
95 files changed
+1756
-2338
No files matched your search
@@ -1,13 +1,5 @@
|
||||
package me.towdium.jecalculation.data.structure;
|
||||
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
|
||||
import me.towdium.jecalculation.polyfill.NBTHelper;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -18,6 +10,13 @@ import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import me.towdium.jecalculation.data.label.ILabel;
|
||||
import me.towdium.jecalculation.polyfill.MethodsReturnNonnullByDefault;
|
||||
import me.towdium.jecalculation.polyfill.NBTHelper;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
@@ -34,35 +33,34 @@ public class Recipe {
|
||||
List<ILabel> output;
|
||||
|
||||
public Recipe(NBTTagCompound nbt) {
|
||||
this(readNbtList(nbt.getTagList(KEY_INPUT, 10)), readNbtList(nbt.getTagList(KEY_CATALYST, 10)),
|
||||
readNbtList(nbt.getTagList(KEY_OUTPUT, 10)));
|
||||
this(
|
||||
readNbtList(nbt.getTagList(KEY_INPUT, 10)),
|
||||
readNbtList(nbt.getTagList(KEY_CATALYST, 10)),
|
||||
readNbtList(nbt.getTagList(KEY_OUTPUT, 10)));
|
||||
}
|
||||
|
||||
public Recipe(List<ILabel> input, List<ILabel> catalyst, List<ILabel> output) {
|
||||
boolean a = Stream.of(input, output, catalyst).anyMatch(i ->
|
||||
!i.isEmpty() && i.get(i.size() - 1) == ILabel.EMPTY);
|
||||
boolean b = Stream.of(input, output).anyMatch(i ->
|
||||
i.stream().allMatch(j -> j == ILabel.EMPTY));
|
||||
boolean a =
|
||||
Stream.of(input, output, catalyst).anyMatch(i -> !i.isEmpty() && i.get(i.size() - 1) == ILabel.EMPTY);
|
||||
boolean b = Stream.of(input, output).anyMatch(i -> i.stream().allMatch(j -> j == ILabel.EMPTY));
|
||||
if (a || b) throw new IllegalArgumentException("Invalid recipe");
|
||||
this.input = input;
|
||||
this.catalyst = catalyst;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
|
||||
static private List<ILabel> readNbtList(NBTTagList list) {
|
||||
private static List<ILabel> readNbtList(NBTTagList list) {
|
||||
return StreamSupport.stream(NBTHelper.spliterator(list), false)
|
||||
.filter(n -> n instanceof NBTTagCompound)
|
||||
.map(n -> ILabel.SERIALIZER.deserialize((NBTTagCompound) n))
|
||||
.collect(Collectors.toList());
|
||||
.filter(n -> n instanceof NBTTagCompound)
|
||||
.map(n -> ILabel.SERIALIZER.deserialize((NBTTagCompound) n))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int[] hash = new int[1];
|
||||
Consumer<List<ILabel>> hasher = (ls) -> ls.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(i -> hash[0] ^= i.hashCode());
|
||||
Consumer<List<ILabel>> hasher =
|
||||
(ls) -> ls.stream().filter(Objects::nonNull).forEach(i -> hash[0] ^= i.hashCode());
|
||||
hasher.accept(input);
|
||||
hasher.accept(catalyst);
|
||||
hasher.accept(output);
|
||||
@@ -71,15 +69,11 @@ public class Recipe {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof Recipe))
|
||||
return false;
|
||||
if (!(obj instanceof Recipe)) return false;
|
||||
Recipe r = (Recipe) obj;
|
||||
BiPredicate<List<ILabel>, List<ILabel>> p = (i, j) -> {
|
||||
if (i.size() != j.size())
|
||||
return false;
|
||||
for (int k = 0; k < i.size(); k++)
|
||||
if (!i.get(k).equals(j.get(k)))
|
||||
return false;
|
||||
if (i.size() != j.size()) return false;
|
||||
for (int k = 0; k < i.size(); k++) if (!i.get(k).equals(j.get(k))) return false;
|
||||
return true;
|
||||
};
|
||||
return p.test(input, r.input) && p.test(catalyst, r.catalyst) && p.test(output, r.output);
|
||||
@@ -115,9 +109,7 @@ public class Recipe {
|
||||
}
|
||||
|
||||
public ILabel getRep() {
|
||||
for (int i = 0; i < 8; i++)
|
||||
if (output.get(i) != ILabel.EMPTY)
|
||||
return output.get(i);
|
||||
for (int i = 0; i < 8; i++) if (output.get(i) != ILabel.EMPTY) return output.get(i);
|
||||
return ILabel.EMPTY;
|
||||
}
|
||||
|
||||
@@ -144,23 +136,29 @@ public class Recipe {
|
||||
}
|
||||
|
||||
public Optional<ILabel> matches(ILabel label) {
|
||||
return output.stream().filter(i -> ILabel.MERGER.merge(label, i).isPresent()).findAny();
|
||||
return output.stream()
|
||||
.filter(i -> ILabel.MERGER.merge(label, i).isPresent())
|
||||
.findAny();
|
||||
}
|
||||
|
||||
public long multiplier(ILabel label) {
|
||||
return output.stream().filter(i -> ILabel.MERGER.merge(label, i).isPresent()).findAny().map(i -> {
|
||||
long amountA = label.getAmount();
|
||||
if (!label.isPercent())
|
||||
amountA = Math.multiplyExact(amountA, 100L);
|
||||
long amountB = i.getAmount();
|
||||
if (!i.isPercent())
|
||||
amountB = Math.multiplyExact(amountB, 100L);
|
||||
return (amountB + Math.abs(amountA) - 1) / amountB;
|
||||
}).orElse(0L);
|
||||
return output.stream()
|
||||
.filter(i -> ILabel.MERGER.merge(label, i).isPresent())
|
||||
.findAny()
|
||||
.map(i -> {
|
||||
long amountA = label.getAmount();
|
||||
if (!label.isPercent()) amountA = Math.multiplyExact(amountA, 100L);
|
||||
long amountB = i.getAmount();
|
||||
if (!i.isPercent()) amountB = Math.multiplyExact(amountB, 100L);
|
||||
return (amountB + Math.abs(amountA) - 1) / amountB;
|
||||
})
|
||||
.orElse(0L);
|
||||
}
|
||||
|
||||
public enum IO {
|
||||
INPUT, OUTPUT, CATALYST;
|
||||
INPUT,
|
||||
OUTPUT,
|
||||
CATALYST;
|
||||
|
||||
public static IO isInput(boolean b) {
|
||||
return b ? INPUT : OUTPUT;
|
||||
|
||||
Reference in new issue
Block a user