Add priority system for external storage provider. Fixes conflicts with RS' default handlers and API users. Fixes #1979
This commit is contained in:
@@ -35,6 +35,7 @@ import net.minecraftforge.fluids.FluidStack;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Refined Storage API implementation.
|
* Represents a Refined Storage API implementation.
|
||||||
@@ -154,9 +155,9 @@ public interface IRSAPI {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param type the type
|
* @param type the type
|
||||||
* @return a list of external storage providers
|
* @return a set of external storage providers
|
||||||
*/
|
*/
|
||||||
List<IExternalStorageProvider> getExternalStorageProviders(StorageType type);
|
Set<IExternalStorageProvider> getExternalStorageProviders(StorageType type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param world the world
|
* @param world the world
|
||||||
|
|||||||
@@ -27,4 +27,13 @@ public interface IExternalStorageProvider<T> {
|
|||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
IStorageExternal<T> provide(IExternalStorageContext context, Supplier<TileEntity> tile, EnumFacing direction);
|
IStorageExternal<T> provide(IExternalStorageContext context, Supplier<TileEntity> tile, EnumFacing direction);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the priority of this external storage provider.
|
||||||
|
* The one with the highest priority is chosen.
|
||||||
|
* Refined Storage's default handlers for {@link net.minecraftforge.items.IItemHandler} and {@link net.minecraftforge.fluids.capability.IFluidHandler} return 0.
|
||||||
|
*
|
||||||
|
* @return the priority
|
||||||
|
*/
|
||||||
|
int getPriority();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public class API implements IRSAPI {
|
|||||||
private IStorageDiskRegistry storageDiskRegistry = new StorageDiskRegistry();
|
private IStorageDiskRegistry storageDiskRegistry = new StorageDiskRegistry();
|
||||||
private IStorageDiskSync storageDiskSync = new StorageDiskSync();
|
private IStorageDiskSync storageDiskSync = new StorageDiskSync();
|
||||||
private IOneSixMigrationHelper oneSixMigrationHelper = new OneSixMigrationHelper();
|
private IOneSixMigrationHelper oneSixMigrationHelper = new OneSixMigrationHelper();
|
||||||
private Map<StorageType, List<IExternalStorageProvider>> externalStorageProviders = new HashMap<>();
|
private Map<StorageType, TreeSet<IExternalStorageProvider>> externalStorageProviders = new HashMap<>();
|
||||||
private List<ICraftingPatternRenderHandler> patternRenderHandlers = new LinkedList<>();
|
private List<ICraftingPatternRenderHandler> patternRenderHandlers = new LinkedList<>();
|
||||||
|
|
||||||
public static IRSAPI instance() {
|
public static IRSAPI instance() {
|
||||||
@@ -227,14 +227,14 @@ public class API implements IRSAPI {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addExternalStorageProvider(StorageType type, IExternalStorageProvider provider) {
|
public void addExternalStorageProvider(StorageType type, IExternalStorageProvider provider) {
|
||||||
externalStorageProviders.computeIfAbsent(type, k -> new ArrayList<>()).add(provider);
|
externalStorageProviders.computeIfAbsent(type, k -> new TreeSet<>((a, b) -> Integer.compare(b.getPriority(), a.getPriority()))).add(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<IExternalStorageProvider> getExternalStorageProviders(StorageType type) {
|
public Set<IExternalStorageProvider> getExternalStorageProviders(StorageType type) {
|
||||||
List<IExternalStorageProvider> providers = externalStorageProviders.get(type);
|
TreeSet<IExternalStorageProvider> providers = externalStorageProviders.get(type);
|
||||||
|
|
||||||
return providers == null ? Collections.emptyList() : providers;
|
return providers == null ? Collections.emptySet() : providers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -233,12 +233,16 @@ public class NetworkNodeExternalStorage extends NetworkNode implements IStorageP
|
|||||||
for (IExternalStorageProvider provider : API.instance().getExternalStorageProviders(StorageType.ITEM)) {
|
for (IExternalStorageProvider provider : API.instance().getExternalStorageProviders(StorageType.ITEM)) {
|
||||||
if (provider.canProvide(facing, getDirection())) {
|
if (provider.canProvide(facing, getDirection())) {
|
||||||
itemStorages.add(provider.provide(this, () -> getFacingTile(), getDirection()));
|
itemStorages.add(provider.provide(this, () -> getFacingTile(), getDirection()));
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (type == IType.FLUIDS) {
|
} else if (type == IType.FLUIDS) {
|
||||||
for (IExternalStorageProvider provider : API.instance().getExternalStorageProviders(StorageType.FLUID)) {
|
for (IExternalStorageProvider provider : API.instance().getExternalStorageProviders(StorageType.FLUID)) {
|
||||||
if (provider.canProvide(facing, getDirection())) {
|
if (provider.canProvide(facing, getDirection())) {
|
||||||
fluidStorages.add(provider.provide(this, () -> getFacingTile(), getDirection()));
|
fluidStorages.add(provider.provide(this, () -> getFacingTile(), getDirection()));
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,4 +23,9 @@ public class ExternalStorageProviderFluid implements IExternalStorageProvider<Fl
|
|||||||
public IStorageExternal<FluidStack> provide(IExternalStorageContext context, Supplier<TileEntity> tile, EnumFacing direction) {
|
public IStorageExternal<FluidStack> provide(IExternalStorageContext context, Supplier<TileEntity> tile, EnumFacing direction) {
|
||||||
return new StorageExternalFluid(context, () -> WorldUtils.getFluidHandler(tile.get(), direction.getOpposite()), tile.get() instanceof TileFluidInterface);
|
return new StorageExternalFluid(context, () -> WorldUtils.getFluidHandler(tile.get(), direction.getOpposite()), tile.get() instanceof TileFluidInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPriority() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,4 +33,9 @@ public class ExternalStorageProviderItem implements IExternalStorageProvider<Ite
|
|||||||
public IStorageExternal<ItemStack> provide(IExternalStorageContext context, Supplier<TileEntity> tile, EnumFacing direction) {
|
public IStorageExternal<ItemStack> provide(IExternalStorageContext context, Supplier<TileEntity> tile, EnumFacing direction) {
|
||||||
return new StorageExternalItem(context, () -> WorldUtils.getItemHandler(tile.get(), direction.getOpposite()), tile.get() instanceof TileInterface);
|
return new StorageExternalItem(context, () -> WorldUtils.getItemHandler(tile.get(), direction.getOpposite()), tile.get() instanceof TileInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPriority() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user