Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- You can now register custom ExternalStorageProviders for specific blocks by calling addExternalStorageProviderBlockFactory inside registerCustomExternalStorageProviderFactories in the ModInitializer class

### Fixed

- Fixed Crafting Grid failing to pull additional items for crafts with External Storage inventories that have more than the maximum stack size in 1 slot.
Expand Down Expand Up @@ -1015,9 +1019,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- The Grid can now use smooth scrolling.
- The Grid now has syntax highlighting for the search query.

[Unreleased]: https://github.com/refinedmods/refinedstorage2/compare/v2.0.0-beta.8...HEAD

[2.0.0-beta.8]: https://github.com/refinedmods/refinedstorage2/compare/v2.0.0-beta.7...v2.0.0-beta.8
[Unreleased]: https://github.com/refinedmods/refinedstorage2/compare/v2.0.0-beta.7...HEAD

[2.0.0-beta.7]: https://github.com/refinedmods/refinedstorage2/compare/v2.0.0-beta.6...v2.0.0-beta.7

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public interface RefinedStorageApi {

Collection<ExternalStorageProviderFactory> getExternalStorageProviderFactories();

void addExternalStorageProviderBlockFactory(ExternalStorageProviderFactory factory, ResourceLocation blockId);

PlatformRegistry<ExternalStorageProviderFactory> getExternalStorageProviderBlocks();

Collection<DestructorStrategyFactory> getDestructorStrategyFactories();

void addDestructorStrategyFactory(DestructorStrategyFactory factory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ public Collection<ExternalStorageProviderFactory> getExternalStorageProviderFact
return ensureLoaded().getExternalStorageProviderFactories();
}

@Override
public void addExternalStorageProviderBlockFactory(final ExternalStorageProviderFactory factory,
final ResourceLocation blockId) {
ensureLoaded().addExternalStorageProviderBlockFactory(factory, blockId);
}

@Override
public PlatformRegistry<ExternalStorageProviderFactory> getExternalStorageProviderBlocks() {
return ensureLoaded().getExternalStorageProviderBlocks();
}

@Override
public Collection<DestructorStrategyFactory> getDestructorStrategyFactories() {
return ensureLoaded().getDestructorStrategyFactories();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ public class RefinedStorageApiImpl implements RefinedStorageApi {
new PlatformRegistryImpl<>();
private final UpgradeRegistry upgradeRegistry = new UpgradeRegistryImpl();
private final List<ExternalStorageProviderFactory> externalStorageProviderFactories = new ArrayList<>();
private final PlatformRegistry<ExternalStorageProviderFactory> customExternalStorageProviderBlocks =
new PlatformRegistryImpl<>();
private final Queue<DestructorStrategyFactory> destructorStrategyFactories = new PriorityQueue<>(
Comparator.comparingInt(DestructorStrategyFactory::getPriority)
);
Expand Down Expand Up @@ -236,6 +238,17 @@ public Collection<ExternalStorageProviderFactory> getExternalStorageProviderFact
return externalStorageProviderFactories;
}

@Override
public void addExternalStorageProviderBlockFactory(final ExternalStorageProviderFactory factory,
final ResourceLocation blockId) {
customExternalStorageProviderBlocks.register(blockId, factory);
}

@Override
public PlatformRegistry<ExternalStorageProviderFactory> getExternalStorageProviderBlocks() {
return customExternalStorageProviderBlocks;
}

@Override
public Collection<DestructorStrategyFactory> getDestructorStrategyFactories() {
return destructorStrategyFactories;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import com.refinedmods.refinedstorage.common.api.RefinedStorageApi;
import com.refinedmods.refinedstorage.common.content.BlockEntities;
import com.refinedmods.refinedstorage.common.content.ContentNames;
import com.refinedmods.refinedstorage.common.iface.InterfaceBlock;
import com.refinedmods.refinedstorage.common.iface.InterfaceProxyExternalStorageProvider;
import com.refinedmods.refinedstorage.common.storage.StorageConfigurationContainerImpl;
import com.refinedmods.refinedstorage.common.support.AbstractCableLikeBlockEntity;
import com.refinedmods.refinedstorage.common.support.AbstractDirectionalBlock;
Expand All @@ -24,10 +22,12 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.codec.StreamEncoder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Inventory;
Expand Down Expand Up @@ -101,15 +101,15 @@ void loadStorage(final ServerLevel serverLevel) {
}
final Direction incomingDirection = direction.getOpposite();
final BlockPos sourcePosition = worldPosition.relative(direction);
if (serverLevel.getBlockState(sourcePosition).getBlock() instanceof InterfaceBlock) {
mainNetworkNode.initialize(new InterfaceProxyExternalStorageProvider(serverLevel, sourcePosition));
} else {
mainNetworkNode.initialize(new CompositeExternalStorageProvider(RefinedStorageApi.INSTANCE
final ResourceLocation target = BuiltInRegistries.BLOCK.getKey(serverLevel.getBlockState(sourcePosition).getBlock());
RefinedStorageApi.INSTANCE.getExternalStorageProviderBlocks()
.get(target).ifPresentOrElse(
provider -> mainNetworkNode.initialize(provider.create(serverLevel, sourcePosition, incomingDirection)),
() -> mainNetworkNode.initialize(new CompositeExternalStorageProvider(RefinedStorageApi.INSTANCE
.getExternalStorageProviderFactories()
.stream()
.map(factory -> factory.create(serverLevel, sourcePosition, incomingDirection))
.toList()));
}
.toList())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.refinedmods.refinedstorage.common.storage.externalstorage;

import com.refinedmods.refinedstorage.common.api.RefinedStorageApi;
import com.refinedmods.refinedstorage.common.content.BlockColorMap;
import com.refinedmods.refinedstorage.common.content.BlockEntities;
import com.refinedmods.refinedstorage.common.content.BlockEntityProvider;
import com.refinedmods.refinedstorage.common.content.Blocks;
import com.refinedmods.refinedstorage.common.iface.InterfaceBlock;
import com.refinedmods.refinedstorage.common.support.AbstractBlockEntityTicker;
import com.refinedmods.refinedstorage.common.support.AbstractDirectionalCableBlock;
import com.refinedmods.refinedstorage.common.support.BaseBlockItem;
Expand All @@ -19,8 +19,10 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.level.Level;
Expand Down Expand Up @@ -87,9 +89,11 @@ public void neighborChanged(final BlockState state,
super.neighborChanged(state, level, pos, block, fromPos, moving);
if (level instanceof ServerLevel serverLevel
&& level.getBlockEntity(pos) instanceof AbstractExternalStorageBlockEntity blockEntity) {
final boolean didBreakInterfaceBlock = block instanceof InterfaceBlock;
final boolean didPlacePotentialInterfaceBlock = block instanceof AirBlock;
if (didBreakInterfaceBlock || didPlacePotentialInterfaceBlock) {
final ResourceLocation blockId = BuiltInRegistries.BLOCK.getKey(block);
// final boolean brokeSpecialBlock =
// RefinedStorageApi.INSTANCE.getExternalStorageProviderBlocks().get(blockId).isPresent();
final boolean placedSomething = block instanceof AirBlock;
if (placedSomething) {
blockEntity.loadStorage(serverLevel);
} else {
blockEntity.neighborChanged();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.refinedmods.refinedstorage.common.storage.externalstorage;

import com.refinedmods.refinedstorage.api.storage.external.ExternalStorageProvider;
import com.refinedmods.refinedstorage.common.api.storage.externalstorage.ExternalStorageProviderFactory;
import com.refinedmods.refinedstorage.common.iface.InterfaceProxyExternalStorageProvider;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;

public class InterfaceExternalStorageProviderFactory implements ExternalStorageProviderFactory {
@Override
public ExternalStorageProvider create(final ServerLevel level, final BlockPos pos, final Direction direction) {
return new InterfaceProxyExternalStorageProvider(level, pos);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.refinedmods.refinedstorage.common.storage.ItemStorageVariant;
import com.refinedmods.refinedstorage.common.storage.diskdrive.AbstractDiskDriveBlockEntity;
import com.refinedmods.refinedstorage.common.storage.diskinterface.AbstractDiskInterfaceBlockEntity;
import com.refinedmods.refinedstorage.common.storage.externalstorage.InterfaceExternalStorageProviderFactory;
import com.refinedmods.refinedstorage.common.storage.portablegrid.PortableGridBlockItem;
import com.refinedmods.refinedstorage.common.storage.portablegrid.PortableGridType;
import com.refinedmods.refinedstorage.common.support.AbstractBaseBlock;
Expand Down Expand Up @@ -143,6 +144,7 @@
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
Expand All @@ -165,15 +167,7 @@
import org.slf4j.LoggerFactory;
import team.reborn.energy.api.EnergyStorage;

import static com.refinedmods.refinedstorage.common.content.ContentIds.CREATIVE_PORTABLE_GRID;
import static com.refinedmods.refinedstorage.common.content.ContentIds.CREATIVE_WIRELESS_AUTOCRAFTING_MONITOR;
import static com.refinedmods.refinedstorage.common.content.ContentIds.CREATIVE_WIRELESS_GRID;
import static com.refinedmods.refinedstorage.common.content.ContentIds.FALLBACK_SECURITY_CARD;
import static com.refinedmods.refinedstorage.common.content.ContentIds.PORTABLE_GRID;
import static com.refinedmods.refinedstorage.common.content.ContentIds.REGULATOR_UPGRADE;
import static com.refinedmods.refinedstorage.common.content.ContentIds.SECURITY_CARD;
import static com.refinedmods.refinedstorage.common.content.ContentIds.WIRELESS_AUTOCRAFTING_MONITOR;
import static com.refinedmods.refinedstorage.common.content.ContentIds.WIRELESS_GRID;
import static com.refinedmods.refinedstorage.common.content.ContentIds.*;
import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier;
import static com.refinedmods.refinedstorage.fabric.support.resource.VariantUtil.toFluidVariant;
import static com.refinedmods.refinedstorage.fabric.support.resource.VariantUtil.toItemVariant;
Expand Down Expand Up @@ -211,6 +205,7 @@ public void onInitialize() {
registerExternalStorageProviderFactories();
registerExternalPatternSinkStrategyFactories();
registerContent();
registerCustomExternalStorageProviderFactories();
registerPackets();
registerPacketHandlers();
registerSounds(new DirectRegistryCallback<>(BuiltInRegistries.SOUND_EVENT));
Expand Down Expand Up @@ -317,6 +312,12 @@ private void registerExternalStorageProviderFactories() {
);
}

private void registerCustomExternalStorageProviderFactories() {
RefinedStorageApi.INSTANCE.addExternalStorageProviderBlockFactory(
new InterfaceExternalStorageProviderFactory(), INTERFACE
);
}

private void registerExternalPatternSinkStrategyFactories() {
RefinedStorageFabricApi.INSTANCE.addStorageExternalPatternSinkStrategyFactory(
new FabricStorageExternalPatternSinkStrategyFactoryImpl<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import com.refinedmods.refinedstorage.common.content.MenuTypeFactory;
import com.refinedmods.refinedstorage.common.content.RegistryCallback;
import com.refinedmods.refinedstorage.common.grid.WirelessGridItem;
import com.refinedmods.refinedstorage.common.iface.InterfaceBlock;
import com.refinedmods.refinedstorage.common.security.FallbackSecurityCardItem;
import com.refinedmods.refinedstorage.common.security.SecurityCardItem;
import com.refinedmods.refinedstorage.common.storage.FluidStorageVariant;
import com.refinedmods.refinedstorage.common.storage.ItemStorageVariant;
import com.refinedmods.refinedstorage.common.storage.diskinterface.AbstractDiskInterfaceBlockEntity;
import com.refinedmods.refinedstorage.common.storage.externalstorage.InterfaceExternalStorageProviderFactory;
import com.refinedmods.refinedstorage.common.storage.portablegrid.PortableGridBlockItem;
import com.refinedmods.refinedstorage.common.storage.portablegrid.PortableGridType;
import com.refinedmods.refinedstorage.common.support.AbstractBaseBlock;
Expand Down Expand Up @@ -173,15 +175,7 @@
import net.neoforged.neoforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.RegisterEvent;

import static com.refinedmods.refinedstorage.common.content.ContentIds.CREATIVE_PORTABLE_GRID;
import static com.refinedmods.refinedstorage.common.content.ContentIds.CREATIVE_WIRELESS_AUTOCRAFTING_MONITOR;
import static com.refinedmods.refinedstorage.common.content.ContentIds.CREATIVE_WIRELESS_GRID;
import static com.refinedmods.refinedstorage.common.content.ContentIds.FALLBACK_SECURITY_CARD;
import static com.refinedmods.refinedstorage.common.content.ContentIds.PORTABLE_GRID;
import static com.refinedmods.refinedstorage.common.content.ContentIds.REGULATOR_UPGRADE;
import static com.refinedmods.refinedstorage.common.content.ContentIds.SECURITY_CARD;
import static com.refinedmods.refinedstorage.common.content.ContentIds.WIRELESS_AUTOCRAFTING_MONITOR;
import static com.refinedmods.refinedstorage.common.content.ContentIds.WIRELESS_GRID;
import static com.refinedmods.refinedstorage.common.content.ContentIds.*;
import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.MOD_ID;
import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier;
import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation;
Expand Down Expand Up @@ -304,7 +298,12 @@ private void registerExternalStorageProviderFactories() {
RefinedStorageApi.INSTANCE.addExternalStorageProviderFactory(
new ItemHandlerPlatformExternalStorageProviderFactory());
RefinedStorageApi.INSTANCE.addExternalStorageProviderFactory(
new FluidHandlerExternalStorageProviderFactory()
new FluidHandlerExternalStorageProviderFactory());
}

private void registerCustomExternalStorageProviderFactories() {
RefinedStorageApi.INSTANCE.addExternalStorageProviderBlockFactory(
new InterfaceExternalStorageProviderFactory(), INTERFACE
);
}

Expand Down Expand Up @@ -605,6 +604,7 @@ private void registerTickHandler() {

@SubscribeEvent
public void onCommonSetup(final FMLCommonSetupEvent e) {
registerCustomExternalStorageProviderFactories();
registerUpgradeMappings();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@

public void initialize(final ExternalStorageProvider provider) {
storage.tryClearDelegate();
// if (this.externalStorage != null
// && provider instanceof this.externalStorage.getProvider().) {
// externalStorage = new ExternalStorage(provider, storage);
// }

Check failure on line 41 in refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/externalstorage/ExternalStorageNetworkNode.java

View workflow job for this annotation

GitHub Actions / build / build

Comment has incorrect indentation level 0, expected is 8, indentation should be the same level as line 42.
externalStorage = new ExternalStorage(provider, storage);
if (isActive()) {
setVisible(true);
Expand Down
Loading