mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-23 21:49:46 +00:00
1.21.3 update
This commit is contained in:
806 files changed
+6314
-10501
No files matched your search
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.util;
|
||||
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.saveddata.SavedData;
|
||||
|
||||
public class DummySavedData extends SavedData {
|
||||
public static final DummySavedData DUMMY = new DummySavedData();
|
||||
private DummySavedData() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag save(final CompoundTag compound, HolderLookup.Provider lookup) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,7 @@ import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class RecipeMatcher
|
||||
{
|
||||
public class RecipeMatcher {
|
||||
/**
|
||||
* Attempts to match inputs to the specified tests. In the best way that all inputs are used by one test.
|
||||
* Will return null in any of these cases:
|
||||
@@ -23,8 +22,7 @@ public class RecipeMatcher
|
||||
*
|
||||
* @return An array mapping inputs to tests. ret[x] = y means input[x] = test[y]
|
||||
*/
|
||||
public static <T> int[] findMatches(List<T> inputs, List<? extends Predicate<T>> tests)
|
||||
{
|
||||
public static <T> int[] findMatches(List<T> inputs, List<? extends Predicate<T>> tests) {
|
||||
int elements = inputs.size();
|
||||
if (elements != tests.size())
|
||||
return null; // There will not be a 1:1 mapping of inputs -> tests
|
||||
@@ -35,19 +33,16 @@ public class RecipeMatcher
|
||||
|
||||
// [UnusedInputs] [UnusedIngredients] [IngredientMatchMask]...
|
||||
BitSet data = new BitSet((elements + 2) * elements);
|
||||
for (int x = 0; x < elements; x++)
|
||||
{
|
||||
for (int x = 0; x < elements; x++) {
|
||||
int matched = 0;
|
||||
int offset = (x + 2) * elements;
|
||||
Predicate<T> test = tests.get(x);
|
||||
|
||||
for (int y = 0; y < elements; y++)
|
||||
{
|
||||
for (int y = 0; y < elements; y++) {
|
||||
if (data.get(y))
|
||||
continue;
|
||||
|
||||
if (test.test(inputs.get(y)))
|
||||
{
|
||||
if (test.test(inputs.get(y))) {
|
||||
data.set(offset + y);
|
||||
matched++;
|
||||
}
|
||||
@@ -56,8 +51,7 @@ public class RecipeMatcher
|
||||
if (matched == 0)
|
||||
return null; //We have an test that matched non of the inputs
|
||||
|
||||
if (matched == 1)
|
||||
{
|
||||
if (matched == 1) {
|
||||
if (!claim(ret, data, x, elements))
|
||||
return null; //We failed to claim this index, which means it caused something else to go to 0 matches, which makes the whole thing fail
|
||||
}
|
||||
@@ -66,7 +60,7 @@ public class RecipeMatcher
|
||||
if (data.nextClearBit(0) >= elements) //All items have been used, which means all tests have a match!
|
||||
return ret;
|
||||
|
||||
// We should be in a state where multiple tests are satified by multiple inputs. So we need to try a branching recursive test.
|
||||
// We should be in a state where multiple tests are satisfied by multiple inputs. So we need to try a branching recursive test.
|
||||
// However for performance reasons, we should probably make that check a sub-set of the entire graph.
|
||||
if (backtrack(data, ret, 0, elements))
|
||||
return ret;
|
||||
@@ -75,13 +69,11 @@ public class RecipeMatcher
|
||||
}
|
||||
|
||||
// This is bad... need to think of a better cascade, recursion instead of stack?
|
||||
private static boolean claim(int[] ret, BitSet data, int claimed, int elements)
|
||||
{
|
||||
private static boolean claim(int[] ret, BitSet data, int claimed, int elements) {
|
||||
Queue<Integer> pending = new LinkedList<Integer>();
|
||||
pending.add(claimed);
|
||||
|
||||
while (pending.peek() != null)
|
||||
{
|
||||
while (pending.peek() != null) {
|
||||
int test = pending.poll();
|
||||
int offset = (test + 2) * elements;
|
||||
int used = data.nextSetBit(offset) - offset;
|
||||
@@ -93,11 +85,9 @@ public class RecipeMatcher
|
||||
data.set(elements + test);
|
||||
ret[used] = test;
|
||||
|
||||
for (int x = 0; x < elements; x++)
|
||||
{
|
||||
for (int x = 0; x < elements; x++) {
|
||||
offset = (x + 2) * elements;
|
||||
if (data.get(offset + used) && !data.get(elements + x))
|
||||
{
|
||||
if (data.get(offset + used) && !data.get(elements + x)) {
|
||||
data.clear(offset + used);
|
||||
int count = 0;
|
||||
for (int y = offset; y < offset + elements; y++)
|
||||
@@ -117,32 +107,29 @@ public class RecipeMatcher
|
||||
}
|
||||
|
||||
//We use recursion here, why? Because I feel like it. Also because we should only ever be working in data sets < 9
|
||||
private static boolean backtrack(BitSet data, int[] ret, int start, int elements)
|
||||
{
|
||||
int test = data.nextClearBit(elements + start) - elements;
|
||||
if (test >= elements)
|
||||
return true; //Could not find the next unused test.
|
||||
private static boolean backtrack(BitSet data, int[] ret, int start, int elements) {
|
||||
int test = data.nextClearBit(elements + start) - elements;
|
||||
if (test >= elements)
|
||||
return true; //Could not find the next unused test.
|
||||
|
||||
if (test < 0)
|
||||
throw new IllegalStateException("This should never happen, negative test in backtrack!");
|
||||
if (test < 0)
|
||||
throw new IllegalStateException("This should never happen, negative test in backtrack!");
|
||||
|
||||
int offset = (test + 2) * elements;
|
||||
for (int x = 0; x < elements; x++)
|
||||
{
|
||||
if (!data.get(offset + x) || data.get(x))
|
||||
continue;
|
||||
int offset = (test + 2) * elements;
|
||||
for (int x = 0; x < elements; x++) {
|
||||
if (!data.get(offset + x) || data.get(x))
|
||||
continue;
|
||||
|
||||
data.set(x);
|
||||
data.set(x);
|
||||
|
||||
if (backtrack(data, ret, test + 1, elements))
|
||||
{
|
||||
ret[x] = test;
|
||||
return true;
|
||||
if (backtrack(data, ret, test + 1, elements)) {
|
||||
ret[x] = test;
|
||||
return true;
|
||||
}
|
||||
|
||||
data.clear(x);
|
||||
}
|
||||
|
||||
data.clear(x);
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user