Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #3225 Server error when deleting items in multiplayer
- Loading branch information
Showing
9 changed files
with
109 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
Core/src/main/java/mezz/jei/core/util/function/CachedFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package mezz.jei.core.util.function; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.function.Function; | ||
|
||
public class CachedFunction<T, R> implements Function<T, R> { | ||
private final Function<T, R> function; | ||
@Nullable | ||
private T previousValue; | ||
@Nullable | ||
private R cachedResult; | ||
|
||
public CachedFunction(Function<T, R> function) { | ||
this.function = function; | ||
} | ||
|
||
@Override | ||
public R apply(T currentValue) { | ||
if (currentValue.equals(previousValue)) { | ||
assert cachedResult != null; | ||
return cachedResult; | ||
} | ||
cachedResult = function.apply(currentValue); | ||
previousValue = currentValue; | ||
return cachedResult; | ||
} | ||
} |
19 changes: 4 additions & 15 deletions
19
Core/src/main/java/mezz/jei/core/util/function/CachedSupplierTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,20 @@ | ||
package mezz.jei.core.util.function; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
public class CachedSupplierTransformer<T, R> implements Supplier<R> { | ||
private final Supplier<T> supplier; | ||
private final Function<T, R> transformer; | ||
@Nullable | ||
private T previousValue; | ||
@Nullable | ||
private R cachedResult; | ||
private final CachedFunction<T, R> cachedFunction; | ||
|
||
public CachedSupplierTransformer(Supplier<T> supplier, Function<T, R> transformer) { | ||
public CachedSupplierTransformer(Supplier<T> supplier, Function<T, R> function) { | ||
this.supplier = supplier; | ||
this.transformer = transformer; | ||
this.cachedFunction = new CachedFunction<>(function); | ||
} | ||
|
||
@Override | ||
public R get() { | ||
T currentValue = supplier.get(); | ||
if (cachedResult != null && currentValue.equals(previousValue)) { | ||
return cachedResult; | ||
} | ||
cachedResult = transformer.apply(currentValue); | ||
previousValue = currentValue; | ||
return cachedResult; | ||
return cachedFunction.apply(currentValue); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Core/src/main/java/mezz/jei/core/util/function/LazySupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package mezz.jei.core.util.function; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class LazySupplier<T> implements Supplier<T> { | ||
private final Supplier<T> supplier; | ||
@Nullable | ||
private T cachedResult; | ||
|
||
public LazySupplier(Supplier<T> supplier) { | ||
this.supplier = supplier; | ||
} | ||
|
||
@Override | ||
public T get() { | ||
if (cachedResult == null) { | ||
cachedResult = supplier.get(); | ||
} | ||
return cachedResult; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters