Unify the client/server-side shared itemstack registry to avoid over-dependence on the current thread
when this class is used. Otherwise if a thread is not correctly detected to be part of the server or client thread groups, a shared item stack from the wrong domain is returned.
This commit is contained in:
@@ -33,20 +33,11 @@ import net.minecraft.item.ItemStack;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public final class AEItemStackRegistry {
|
||||
private static final WeakHashMap<AESharedItemStack, WeakReference<AESharedItemStack>> SERVER_REGISTRY = new WeakHashMap<>();
|
||||
private static final WeakHashMap<AESharedItemStack, WeakReference<AESharedItemStack>> CLIENT_REGISTRY = new WeakHashMap<>();
|
||||
private static final WeakHashMap<AESharedItemStack, WeakReference<AESharedItemStack>> REGISTRY = new WeakHashMap<>();
|
||||
|
||||
private AEItemStackRegistry() {
|
||||
}
|
||||
|
||||
private static WeakHashMap<AESharedItemStack, WeakReference<AESharedItemStack>> registry() {
|
||||
if (Platform.isClient()) {
|
||||
return CLIENT_REGISTRY;
|
||||
} else {
|
||||
return SERVER_REGISTRY;
|
||||
}
|
||||
}
|
||||
|
||||
static synchronized AESharedItemStack getRegisteredStack(final @Nonnull ItemStack itemStack) {
|
||||
if (itemStack.isEmpty()) {
|
||||
throw new IllegalArgumentException("stack cannot be empty");
|
||||
@@ -56,7 +47,7 @@ public final class AEItemStackRegistry {
|
||||
itemStack.setCount(1);
|
||||
|
||||
AESharedItemStack search = new AESharedItemStack(itemStack);
|
||||
WeakReference<AESharedItemStack> weak = registry().get(search);
|
||||
WeakReference<AESharedItemStack> weak = REGISTRY.get(search);
|
||||
AESharedItemStack ret = null;
|
||||
|
||||
if (weak != null) {
|
||||
@@ -65,7 +56,7 @@ public final class AEItemStackRegistry {
|
||||
|
||||
if (ret == null) {
|
||||
ret = new AESharedItemStack(itemStack.copy());
|
||||
registry().put(ret, new WeakReference<>(ret));
|
||||
REGISTRY.put(ret, new WeakReference<>(ret));
|
||||
}
|
||||
itemStack.setCount(oldStackSize);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user