mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-26 14:52:55 +00:00
Update bs and deps
This commit is contained in:
1 parent
19fb4c49c3
commit
296a2bdf29
108 files changed
+2886
-1739
No files matched your search
@@ -10,21 +10,25 @@ 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 net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
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
|
||||
* Date: 17-10-6.
|
||||
* Date: 17-10-6.
|
||||
*/
|
||||
@MethodsReturnNonnullByDefault
|
||||
@ParametersAreNonnullByDefault
|
||||
public class Recipe {
|
||||
|
||||
public static final String KEY_INPUT = "input";
|
||||
public static final String KEY_CATALYST = "catalyst";
|
||||
public static final String KEY_OUTPUT = "output";
|
||||
@@ -34,15 +38,18 @@ public class Recipe {
|
||||
|
||||
public Recipe(NBTTagCompound nbt) {
|
||||
this(
|
||||
readNbtList(nbt.getTagList(KEY_INPUT, 10)),
|
||||
readNbtList(nbt.getTagList(KEY_CATALYST, 10)),
|
||||
readNbtList(nbt.getTagList(KEY_OUTPUT, 10)));
|
||||
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;
|
||||
@@ -51,16 +58,17 @@ public class Recipe {
|
||||
|
||||
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);
|
||||
@@ -73,7 +81,8 @@ public class Recipe {
|
||||
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;
|
||||
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);
|
||||
@@ -126,7 +135,8 @@ public class Recipe {
|
||||
}
|
||||
|
||||
NBTTagList r = new NBTTagList();
|
||||
new Utilities.ReversedIterator<>(labels).stream().forEach(l -> r.appendTag(ILabel.SERIALIZER.serialize(l)));
|
||||
new Utilities.ReversedIterator<>(labels).stream()
|
||||
.forEach(l -> r.appendTag(ILabel.SERIALIZER.serialize(l)));
|
||||
return r;
|
||||
};
|
||||
ret.setTag(KEY_INPUT, convert.apply(input));
|
||||
@@ -137,25 +147,30 @@ public class Recipe {
|
||||
|
||||
public Optional<ILabel> matches(ILabel label) {
|
||||
return output.stream()
|
||||
.filter(i -> ILabel.MERGER.merge(label, i).isPresent())
|
||||
.findAny();
|
||||
.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);
|
||||
.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;
|
||||
|
||||
Reference in new issue
Block a user