diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b3eecf88..31587aba8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,9 +15,11 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - Ported to Minecraft 1.19.3. - The regular Grid now shows fluids as well. -- You can insert fluids in the Grid by right-clicking a fluid container item in the Grid slots. -- You can no longer insert fluids straight from the player slots, you have to insert the fluid while holding the - fluid container item. +- You can insert fluids in the Grid by right-clicking a fluid container in the Grid slots. +- You no longer have to explicitly select a resource type for the filter configuration slots. You can set a fluid + by right-clicking a fluid container in the filter slots. +- You can no longer insert fluids into the Grid or filter slots straight from the player inventory slots, you have to + insert the fluid while holding the fluid container. ### Removed diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java index d57e8493a..dd476d122 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApi.java @@ -20,7 +20,7 @@ import com.refinedmods.refinedstorage2.platform.api.network.node.externalstorage.PlatformExternalStorageProviderFactory; import com.refinedmods.refinedstorage2.platform.api.network.node.importer.ImporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; +import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResourceFactory; import com.refinedmods.refinedstorage2.platform.api.storage.StorageRepository; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.api.storage.type.StorageType; @@ -61,8 +61,6 @@ Set getExternalStorageProviderFactor MutableComponent createTranslation(String category, String value, Object... args); - OrderedRegistry getResourceTypeRegistry(); - ComponentMapFactory getNetworkComponentMapFactory(); OrderedRegistry getGridSynchronizerRegistry(); @@ -93,4 +91,8 @@ GridScrollingStrategy createGridScrollingStrategy(AbstractContainerMenu containe GridServiceFactory gridServiceFactory); void addGridScrollingStrategyFactory(GridScrollingStrategyFactory scrollingStrategyFactory); + + void addFilteredResourceFactory(FilteredResourceFactory factory); + + FilteredResourceFactory getFilteredResourceFactory(); } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java index cda768ba8..57970b06f 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/PlatformApiProxy.java @@ -20,7 +20,7 @@ import com.refinedmods.refinedstorage2.platform.api.network.node.externalstorage.PlatformExternalStorageProviderFactory; import com.refinedmods.refinedstorage2.platform.api.network.node.importer.ImporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; +import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResourceFactory; import com.refinedmods.refinedstorage2.platform.api.storage.StorageRepository; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.api.storage.type.StorageType; @@ -95,11 +95,6 @@ public MutableComponent createTranslation(final String category, final String va return ensureLoaded().createTranslation(category, value, args); } - @Override - public OrderedRegistry getResourceTypeRegistry() { - return ensureLoaded().getResourceTypeRegistry(); - } - @Override public ComponentMapFactory getNetworkComponentMapFactory() { return ensureLoaded().getNetworkComponentMapFactory(); @@ -175,6 +170,16 @@ public void addGridScrollingStrategyFactory(final GridScrollingStrategyFactory s ensureLoaded().addGridScrollingStrategyFactory(scrollingStrategyFactory); } + @Override + public void addFilteredResourceFactory(final FilteredResourceFactory factory) { + ensureLoaded().addFilteredResourceFactory(factory); + } + + @Override + public FilteredResourceFactory getFilteredResourceFactory() { + return ensureLoaded().getFilteredResourceFactory(); + } + private PlatformApi ensureLoaded() { if (delegate == null) { throw new IllegalStateException("Platform API not loaded yet"); diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/PlatformGridResource.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/PlatformGridResource.java index c69971de7..ed43b9320 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/PlatformGridResource.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/grid/PlatformGridResource.java @@ -18,7 +18,7 @@ void onExtract(GridExtractMode extractMode, void onScroll(GridScrollMode scrollMode, GridScrollingStrategy scrollingStrategy); - void render(PoseStack poseStack, int slotX, int slotY); + void render(PoseStack poseStack, int x, int y); String getDisplayedAmount(); diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/resource/filter/FilteredResource.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/resource/filter/FilteredResource.java index 337c508f1..7b25a572f 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/resource/filter/FilteredResource.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/resource/filter/FilteredResource.java @@ -1,34 +1,28 @@ package com.refinedmods.refinedstorage2.platform.api.resource.filter; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; + import java.util.List; -import javax.annotation.Nullable; import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Player; import org.apiguardian.api.API; @API(status = API.Status.STABLE, since = "2.0.0-milestone.2.0") -public interface FilteredResource { - void writeToPacket(FriendlyByteBuf buf); - - CompoundTag toTag(); - +public interface FilteredResource { void render(PoseStack poseStack, int x, int y, int z); - Object getValue(); + T getValue(); - long getAmount(); + FilteredResource withAmount(long newAmount); - FilteredResource withAmount(long newAmount); + long getAmount(); long getMaxAmount(); - String getFormattedAmount(); + String getDisplayedAmount(); - ResourceType getType(); + List getTooltip(); - List getTooltipLines(@Nullable Player player); + PlatformStorageChannelType getStorageChannelType(); } diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/resource/filter/FilteredResourceFactory.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/resource/filter/FilteredResourceFactory.java new file mode 100644 index 000000000..a52cd36c0 --- /dev/null +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/resource/filter/FilteredResourceFactory.java @@ -0,0 +1,11 @@ +package com.refinedmods.refinedstorage2.platform.api.resource.filter; + +import java.util.Optional; + +import net.minecraft.world.item.ItemStack; +import org.apiguardian.api.API; + +@API(status = API.Status.STABLE, since = "2.0.0-milestone.2.6") +public interface FilteredResourceFactory { + Optional> create(ItemStack stack, boolean tryAlternatives); +} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/resource/filter/ResourceType.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/resource/filter/ResourceType.java deleted file mode 100644 index 4efc43d29..000000000 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/resource/filter/ResourceType.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.api.resource.filter; - -import java.util.Optional; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.Component; -import net.minecraft.world.item.ItemStack; -import org.apiguardian.api.API; - -@API(status = API.Status.STABLE, since = "2.0.0-milestone.2.0") -public interface ResourceType { - Component getName(); - - Optional translate(ItemStack stack); - - Optional fromTag(CompoundTag tag); - - FilteredResource fromPacket(FriendlyByteBuf buf); -} diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/channel/AbstractPlatformStorageChannelType.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/channel/AbstractPlatformStorageChannelType.java index e9b561d8d..d504d1e7c 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/channel/AbstractPlatformStorageChannelType.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/channel/AbstractPlatformStorageChannelType.java @@ -5,11 +5,11 @@ import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; -import java.util.Optional; import java.util.function.BiConsumer; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.MutableComponent; +import net.minecraft.resources.ResourceLocation; import org.apiguardian.api.API; @API(status = API.Status.STABLE, since = "2.0.0-milestone.2.4") @@ -20,13 +20,22 @@ public abstract class AbstractPlatformStorageChannelType implements PlatformS private final String name; private final StorageChannelType delegate; private final MutableComponent title; + private final ResourceLocation textureIdentifier; + private final int textureX; + private final int textureY; protected AbstractPlatformStorageChannelType(final String name, final StorageChannelType delegate, - final MutableComponent title) { + final MutableComponent title, + final ResourceLocation textureIdentifier, + final int textureX, + final int textureY) { this.name = name; this.delegate = CoreValidations.validateNotNull(delegate, "Delegate cannot be null"); this.title = title; + this.textureIdentifier = textureIdentifier; + this.textureX = textureX; + this.textureY = textureY; } @Override @@ -37,8 +46,6 @@ public CompoundTag toTag(final T resource, final TrackedResource trackedResource return tag; } - protected abstract CompoundTag toTag(T resource); - @Override public void fromTag(final CompoundTag tag, final BiConsumer acceptor) { fromTag(tag).ifPresent(resource -> { @@ -48,8 +55,6 @@ public void fromTag(final CompoundTag tag, final BiConsumer }); } - protected abstract Optional fromTag(CompoundTag tag); - @Override public StorageChannel create() { return delegate.create(); @@ -60,6 +65,21 @@ public MutableComponent getTitle() { return title; } + @Override + public ResourceLocation getTextureIdentifier() { + return textureIdentifier; + } + + @Override + public int getXTexture() { + return textureX; + } + + @Override + public int getYTexture() { + return textureY; + } + @Override public String toString() { return name; diff --git a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/channel/PlatformStorageChannelType.java b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/channel/PlatformStorageChannelType.java index 2473a48f7..842cdd267 100644 --- a/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/channel/PlatformStorageChannelType.java +++ b/refinedstorage2-platform-api/src/main/java/com/refinedmods/refinedstorage2/platform/api/storage/channel/PlatformStorageChannelType.java @@ -4,6 +4,7 @@ import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; import com.refinedmods.refinedstorage2.api.storage.channel.StorageChannelType; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; +import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResource; import java.util.Optional; import java.util.function.BiConsumer; @@ -16,16 +17,22 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.2.5") public interface PlatformStorageChannelType extends StorageChannelType { + CompoundTag toTag(T resource); + CompoundTag toTag(T resource, TrackedResource trackedResource); void fromTag(CompoundTag tag, BiConsumer acceptor); + Optional fromTag(CompoundTag tag); + void toBuffer(T resource, FriendlyByteBuf buf); T fromBuffer(FriendlyByteBuf buf); Optional toGridResource(ResourceAmount resourceAmount); + Optional> toFilteredResource(ResourceAmount resourceAmount); + boolean isGridResourceBelonging(GridResource gridResource); MutableComponent getTitle(); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java index 17e229504..fbf091dbb 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/AbstractModInitializer.java @@ -7,7 +7,7 @@ import com.refinedmods.refinedstorage2.api.network.impl.component.StorageNetworkComponentImpl; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.PlatformApiProxy; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.fluid.FluidResourceType; +import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.fluid.FluidFilteredResourceFactory; import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.common.internal.storage.type.FluidStorageType; import com.refinedmods.refinedstorage2.platform.common.internal.upgrade.UpgradeDestinations; @@ -43,6 +43,10 @@ protected void registerAdditionalStorageChannelTypes() { ); } + protected void registerAdditionalFilteredResourceFactories() { + PlatformApi.INSTANCE.addFilteredResourceFactory(new FluidFilteredResourceFactory()); + } + protected void registerNetworkComponents() { PlatformApi.INSTANCE.getNetworkComponentMapFactory().addFactory( EnergyNetworkComponent.class, @@ -58,13 +62,6 @@ protected void registerNetworkComponents() { ); } - protected void registerAdditionalResourceTypes() { - PlatformApi.INSTANCE.getResourceTypeRegistry().register( - createIdentifier(FLUID_REGISTRY_KEY), - FluidResourceType.INSTANCE - ); - } - protected void addApplicableUpgrades(final Supplier speedUpgrade, final Supplier stackUpgrade) { PlatformApi.INSTANCE.getUpgradeRegistry().addApplicableUpgrade( diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java index 43ec27bae..17a986122 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/PlatformApiImpl.java @@ -26,7 +26,7 @@ import com.refinedmods.refinedstorage2.platform.api.network.node.externalstorage.PlatformExternalStorageProviderFactory; import com.refinedmods.refinedstorage2.platform.api.network.node.importer.ImporterTransferStrategyFactory; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; +import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResourceFactory; import com.refinedmods.refinedstorage2.platform.api.storage.StorageRepository; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.api.storage.type.StorageType; @@ -38,7 +38,8 @@ import com.refinedmods.refinedstorage2.platform.common.internal.grid.PlatformGridServiceFactoryImpl; import com.refinedmods.refinedstorage2.platform.common.internal.item.StorageContainerHelperImpl; import com.refinedmods.refinedstorage2.platform.common.internal.network.LevelConnectionProvider; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.item.ItemResourceType; +import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.CompositeFilteredResourceFactory; +import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.item.ItemFilteredResourceFactory; import com.refinedmods.refinedstorage2.platform.common.internal.storage.ClientStorageRepository; import com.refinedmods.refinedstorage2.platform.common.internal.storage.StorageRepositoryImpl; import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; @@ -72,8 +73,6 @@ public class PlatformApiImpl implements PlatformApi { private final StorageRepository clientStorageRepository = new ClientStorageRepository(Platform.INSTANCE.getClientToServerCommunications()::sendStorageInfoRequest); - private final OrderedRegistry resourceTypeRegistry = - new OrderedRegistryImpl<>(createIdentifier(ITEM_REGISTRY_KEY), ItemResourceType.INSTANCE); private final ComponentMapFactory networkComponentMapFactory = new ComponentMapFactory<>(); private final NetworkBuilder networkBuilder = @@ -97,6 +96,9 @@ public class PlatformApiImpl implements PlatformApi { private final List gridInsertionStrategyFactories = new ArrayList<>(); private final List gridExtractionStrategyFactories = new ArrayList<>(); private final List gridScrollingStrategyFactories = new ArrayList<>(); + private final CompositeFilteredResourceFactory filteredResourceFactory = new CompositeFilteredResourceFactory( + new ItemFilteredResourceFactory() + ); @Override public OrderedRegistry> getStorageTypeRegistry() { @@ -173,11 +175,6 @@ public MutableComponent createTranslation(final String category, final String va return IdentifierUtil.createTranslation(category, value, args); } - @Override - public OrderedRegistry getResourceTypeRegistry() { - return resourceTypeRegistry; - } - @Override public ComponentMapFactory getNetworkComponentMapFactory() { return networkComponentMapFactory; @@ -281,4 +278,14 @@ public GridScrollingStrategy createGridScrollingStrategy(final AbstractContainer public void addGridScrollingStrategyFactory(final GridScrollingStrategyFactory scrollingStrategyFactory) { gridScrollingStrategyFactories.add(scrollingStrategyFactory); } + + @Override + public void addFilteredResourceFactory(final FilteredResourceFactory factory) { + filteredResourceFactory.addAlternativeFactory(factory); + } + + @Override + public FilteredResourceFactory getFilteredResourceFactory() { + return filteredResourceFactory; + } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/FilterWithFuzzyMode.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/FilterWithFuzzyMode.java index 7b331e3dd..914dd5759 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/FilterWithFuzzyMode.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/FilterWithFuzzyMode.java @@ -1,8 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.block.entity; -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.resource.FuzzyModeNormalizer; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.FilteredResourceFilterContainer; import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.ResourceFilterContainer; @@ -24,32 +23,30 @@ public final class FilterWithFuzzyMode { private boolean fuzzyMode; - public FilterWithFuzzyMode(final ResourceType resourceType, + public FilterWithFuzzyMode(final PlatformStorageChannelType storageChannelType, final Runnable listener, final Consumer> templatesAcceptor, final Consumer> orderedTemplatesAcceptor) { this.filterContainer = new FilteredResourceFilterContainer( - PlatformApi.INSTANCE.getResourceTypeRegistry(), 9, this::filterContainerChanged, - resourceType + storageChannelType ); this.listener = listener; this.templatesAcceptor = templatesAcceptor; this.orderedTemplatesAcceptor = orderedTemplatesAcceptor; } - public FilterWithFuzzyMode(final ResourceType resourceType, + public FilterWithFuzzyMode(final PlatformStorageChannelType storageChannelType, final Runnable listener, final Consumer> templatesAcceptor, final Consumer> orderedTemplatesAcceptor, final int size, final long maxAmount) { this.filterContainer = new FilteredResourceFilterContainer( - PlatformApi.INSTANCE.getResourceTypeRegistry(), size, this::filterContainerChanged, - resourceType, + storageChannelType, maxAmount ); this.listener = listener; @@ -60,11 +57,7 @@ public FilterWithFuzzyMode(final ResourceType resourceType, public FilterWithFuzzyMode(final Runnable listener, final Consumer> templatesAcceptor, final Consumer> orderedTemplatesAcceptor) { - this.filterContainer = new ResourceFilterContainer( - PlatformApi.INSTANCE.getResourceTypeRegistry(), - 9, - this::filterContainerChanged - ); + this.filterContainer = new ResourceFilterContainer(9, this::filterContainerChanged); this.listener = listener; this.templatesAcceptor = templatesAcceptor; this.orderedTemplatesAcceptor = orderedTemplatesAcceptor; @@ -91,7 +84,7 @@ public void setFuzzyMode(final boolean fuzzyMode) { public void load(final CompoundTag tag) { if (tag.contains(TAG_RESOURCE_FILTER)) { - filterContainer.load(tag.getCompound(TAG_RESOURCE_FILTER)); + filterContainer.fromTag(tag.getCompound(TAG_RESOURCE_FILTER)); } if (tag.contains(TAG_FUZZY_MODE)) { fuzzyMode = tag.getBoolean(TAG_FUZZY_MODE); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/InterfaceBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/InterfaceBlockEntity.java index fdf3bb5c5..72d8e8042 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/InterfaceBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/InterfaceBlockEntity.java @@ -15,7 +15,6 @@ import com.refinedmods.refinedstorage2.platform.common.containermenu.InterfaceContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.item.ItemFilteredResource; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.item.ItemResourceType; import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.common.menu.ExtendedMenuProvider; @@ -63,7 +62,7 @@ public InterfaceBlockEntity(final BlockPos pos, final BlockState state) { getNode().setExportState(this); getNode().setTransferQuota(64); this.filter = new FilterWithFuzzyMode( - ItemResourceType.INSTANCE, + StorageChannelTypes.ITEM, this::setChanged, value -> { }, @@ -158,7 +157,7 @@ public boolean isCurrentlyExportedResourceValid(final ItemResource want, final I @Nullable @Override public ItemResource getRequestedResource(final int index) { - final FilteredResource filteredResource = filter.getFilterContainer().get(index); + final FilteredResource filteredResource = filter.getFilterContainer().get(index); if (!(filteredResource instanceof ItemFilteredResource itemFilteredResource)) { return null; } @@ -167,7 +166,7 @@ public ItemResource getRequestedResource(final int index) { @Override public long getRequestedResourceAmount(final int index) { - final FilteredResource filteredResource = filter.getFilterContainer().get(index); + final FilteredResource filteredResource = filter.getFilterContainer().get(index); if (filteredResource == null) { return 0; } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/AbstractStorageBlockBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/AbstractStorageBlockBlockEntity.java index 484717c6e..e250bc013 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/AbstractStorageBlockBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/AbstractStorageBlockBlockEntity.java @@ -3,8 +3,8 @@ import com.refinedmods.refinedstorage2.api.network.impl.node.storage.StorageNetworkNode; import com.refinedmods.refinedstorage2.api.storage.Storage; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; import com.refinedmods.refinedstorage2.platform.api.storage.StorageRepository; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.common.block.entity.AbstractInternalNetworkNodeContainerBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.FilterWithFuzzyMode; import com.refinedmods.refinedstorage2.platform.common.block.entity.StorageConfigurationContainerImpl; @@ -43,10 +43,14 @@ protected AbstractStorageBlockBlockEntity(final BlockEntityType type, final BlockPos pos, final BlockState state, final StorageNetworkNode node, - final ResourceType resourceType) { + final PlatformStorageChannelType storageChannelType) { super(type, pos, state, node); - this.filter = new FilterWithFuzzyMode(resourceType, this::setChanged, getNode()::setFilterTemplates, value -> { - }); + this.filter = new FilterWithFuzzyMode( + storageChannelType, + this::setChanged, + getNode()::setFilterTemplates, value -> { + } + ); this.configContainer = new StorageConfigurationContainerImpl( getNode(), filter, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/FluidStorageBlockBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/FluidStorageBlockBlockEntity.java index 45dcb98eb..bd088eac3 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/FluidStorageBlockBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/FluidStorageBlockBlockEntity.java @@ -10,7 +10,6 @@ import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.block.FluidStorageBlockContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.fluid.FluidResourceType; import com.refinedmods.refinedstorage2.platform.common.internal.storage.LimitedPlatformStorage; import com.refinedmods.refinedstorage2.platform.common.internal.storage.PlatformStorage; import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; @@ -37,7 +36,7 @@ public FluidStorageBlockBlockEntity(final BlockPos pos, pos, state, new StorageNetworkNode<>(getEnergyUsage(variant), StorageChannelTypes.FLUID), - FluidResourceType.INSTANCE + StorageChannelTypes.FLUID ); this.variant = variant; this.displayName = createTranslation( diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/ItemStorageBlockBlockEntity.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/ItemStorageBlockBlockEntity.java index 739db505d..c61f30b5b 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/ItemStorageBlockBlockEntity.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/block/entity/storage/ItemStorageBlockBlockEntity.java @@ -10,7 +10,6 @@ import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.block.ItemStorageBlockContainerMenu; import com.refinedmods.refinedstorage2.platform.common.content.BlockEntities; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.item.ItemResourceType; import com.refinedmods.refinedstorage2.platform.common.internal.storage.LimitedPlatformStorage; import com.refinedmods.refinedstorage2.platform.common.internal.storage.PlatformStorage; import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; @@ -37,7 +36,7 @@ public ItemStorageBlockBlockEntity(final BlockPos pos, pos, state, new StorageNetworkNode<>(getEnergyUsage(variant), StorageChannelTypes.ITEM), - ItemResourceType.INSTANCE + StorageChannelTypes.ITEM ); this.variant = variant; this.displayName = createTranslation("block", String.format("%s_storage_block", variant.getName())); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractResourceFilterContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractResourceFilterContainerMenu.java index 5bf38e50e..6f7a61d95 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractResourceFilterContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractResourceFilterContainerMenu.java @@ -1,10 +1,8 @@ package com.refinedmods.refinedstorage2.platform.common.containermenu; -import com.refinedmods.refinedstorage2.api.core.registry.OrderedRegistry; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; +import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResource; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.ResourceFilterSlot; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.ResourceFilterContainer; import java.util.ArrayList; import java.util.List; @@ -12,45 +10,27 @@ import javax.annotation.Nullable; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.ClickType; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -public abstract class AbstractResourceFilterContainerMenu extends AbstractBaseContainerMenu - implements ResourceTypeAccessor { - private final OrderedRegistry resourceTypeRegistry; +public abstract class AbstractResourceFilterContainerMenu extends AbstractBaseContainerMenu { private final List resourceFilterSlots = new ArrayList<>(); @Nullable private final Player player; - @Nullable - private ResourceType currentResourceType; - protected AbstractResourceFilterContainerMenu(final MenuType type, - final int syncId, - final OrderedRegistry rtr, - final Player player, - final ResourceFilterContainer container) { + protected AbstractResourceFilterContainerMenu(final MenuType type, final int syncId, final Player player) { super(type, syncId); - this.resourceTypeRegistry = rtr; this.player = player; - this.currentResourceType = container.determineDefaultType(); } - protected AbstractResourceFilterContainerMenu(final MenuType type, - final int syncId, - final OrderedRegistry rtr) { + protected AbstractResourceFilterContainerMenu(final MenuType type, final int syncId) { super(type, syncId); - this.resourceTypeRegistry = rtr; this.player = null; } protected void initializeResourceFilterSlots(final FriendlyByteBuf buf) { - final ResourceLocation type = buf.readResourceLocation(); - this.currentResourceType = resourceTypeRegistry.getOrElseDefault(type); for (final ResourceFilterSlot resourceFilterSlot : resourceFilterSlots) { resourceFilterSlot.readFromUpdatePacket(buf); } @@ -66,8 +46,17 @@ private Optional getResourceFilterSlot(final int slotIndex) return Optional.empty(); } - public void readResourceFilterSlotUpdate(final int slotIndex, final FriendlyByteBuf buf) { - getResourceFilterSlot(slotIndex).ifPresent(slot -> slot.readFromUpdatePacket(buf)); + public void handleResourceFilterSlotUpdate(final int slotIndex, + @Nullable final FilteredResource filteredResource) { + getResourceFilterSlot(slotIndex).ifPresent(slot -> slot.change(filteredResource)); + } + + public void handleResourceFilterSlotChange(final int slotIndex, final boolean tryAlternatives) { + getResourceFilterSlot(slotIndex).ifPresent(slot -> slot.change(getCarried(), tryAlternatives)); + } + + public void sendResourceFilterSlotChange(final int slotIndex, final boolean tryAlternatives) { + Platform.INSTANCE.getClientToServerCommunications().sendResourceFilterSlotChange(slotIndex, tryAlternatives); } public void handleResourceFilterSlotAmountChange(final int slotIndex, final long amount) { @@ -99,50 +88,19 @@ protected void resetSlots() { resourceFilterSlots.clear(); } - @Override - public void clicked(final int id, final int dragType, final ClickType actionType, final Player actor) { - final Slot slot = id >= 0 && id < slots.size() ? getSlot(id) : null; - if (currentResourceType != null && slot instanceof ResourceFilterSlot resourceFilterSlot) { - resourceFilterSlot.change(getCarried(), currentResourceType); - } else { - super.clicked(id, dragType, actionType, actor); - } - } - public void addToFilterIfNotExisting(final ItemStack stack) { - if (currentResourceType == null) { - return; - } for (final ResourceFilterSlot resourceFilterSlot : resourceFilterSlots) { - if (resourceFilterSlot.contains(stack, currentResourceType)) { + if (resourceFilterSlot.contains(stack)) { return; } } for (final ResourceFilterSlot resourceFilterSlot : resourceFilterSlots) { - if (resourceFilterSlot.changeIfEmpty(stack, currentResourceType)) { + if (resourceFilterSlot.changeIfEmpty(stack)) { return; } } } - @Override - public Component getCurrentResourceTypeName() { - return currentResourceType != null ? currentResourceType.getName() : Component.empty(); - } - - public void setCurrentResourceType(final ResourceLocation id) { - this.currentResourceType = resourceTypeRegistry.getOrElseDefault(id); - } - - @Override - public void toggleResourceType() { - if (currentResourceType == null) { - return; - } - this.currentResourceType = resourceTypeRegistry.next(currentResourceType); - Platform.INSTANCE.getClientToServerCommunications().sendResourceTypeChange(this.currentResourceType); - } - @Override public boolean canTakeItemForPickAll(final ItemStack stack, final Slot slot) { return !(slot instanceof ResourceFilterSlot); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractSimpleFilterContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractSimpleFilterContainerMenu.java index c0548dae2..dffcef458 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractSimpleFilterContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/AbstractSimpleFilterContainerMenu.java @@ -1,49 +1,43 @@ package com.refinedmods.refinedstorage2.platform.common.containermenu; -import com.refinedmods.refinedstorage2.api.core.registry.OrderedRegistry; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; import com.refinedmods.refinedstorage2.platform.common.block.entity.UpgradeContainer; import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.ResourceFilterSlot; import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.ResourceFilterContainer; import com.refinedmods.refinedstorage2.platform.common.internal.upgrade.UpgradeDestinations; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.inventory.Slot; import net.minecraft.world.level.block.entity.BlockEntity; public abstract class AbstractSimpleFilterContainerMenu - extends AbstractResourceFilterContainerMenu - implements ResourceTypeAccessor { + extends AbstractResourceFilterContainerMenu { private static final int FILTER_SLOT_X = 8; private static final int FILTER_SLOT_Y = 20; protected AbstractSimpleFilterContainerMenu(final MenuType type, final int syncId, - final OrderedRegistry rtr, final Player player, final ResourceFilterContainer resourceFilterContainer, final UpgradeContainer upgradeContainer, final T blockEntity) { - super(type, syncId, rtr, player, resourceFilterContainer); + super(type, syncId, player); registerServerProperties(blockEntity); addSlots(player, resourceFilterContainer, upgradeContainer); } protected AbstractSimpleFilterContainerMenu(final MenuType type, final int syncId, - final OrderedRegistry rtr, final Player player, final FriendlyByteBuf buf, final UpgradeDestinations upgradeDestination) { - super(type, syncId, rtr); + super(type, syncId); registerClientProperties(); addSlots( player, - new ResourceFilterContainer(PlatformApi.INSTANCE.getResourceTypeRegistry(), 9), + new ResourceFilterContainer(9), new UpgradeContainer(upgradeDestination, PlatformApi.INSTANCE.getUpgradeRegistry()) ); initializeResourceFilterSlots(buf); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/ExporterContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/ExporterContainerMenu.java index 7c2b05a85..1a1f72edd 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/ExporterContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/ExporterContainerMenu.java @@ -1,6 +1,5 @@ package com.refinedmods.refinedstorage2.platform.common.containermenu; -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.common.block.entity.UpgradeContainer; import com.refinedmods.refinedstorage2.platform.common.block.entity.exporter.ExporterBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.exporter.ExporterSchedulingModeSettings; @@ -16,13 +15,11 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; -public class ExporterContainerMenu extends AbstractSimpleFilterContainerMenu - implements ResourceTypeAccessor { +public class ExporterContainerMenu extends AbstractSimpleFilterContainerMenu { public ExporterContainerMenu(final int syncId, final Inventory playerInventory, final FriendlyByteBuf buf) { super( Menus.INSTANCE.getExporter(), syncId, - PlatformApi.INSTANCE.getResourceTypeRegistry(), playerInventory.player, buf, UpgradeDestinations.EXPORTER @@ -37,7 +34,6 @@ public ExporterContainerMenu(final int syncId, super( Menus.INSTANCE.getExporter(), syncId, - PlatformApi.INSTANCE.getResourceTypeRegistry(), player, resourceFilterContainer, upgradeContainer, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/ImporterContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/ImporterContainerMenu.java index 1bc4902cf..054c486a3 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/ImporterContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/ImporterContainerMenu.java @@ -1,7 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.containermenu; import com.refinedmods.refinedstorage2.api.core.filter.FilterMode; -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.common.block.entity.ImporterBlockEntity; import com.refinedmods.refinedstorage2.platform.common.block.entity.UpgradeContainer; import com.refinedmods.refinedstorage2.platform.common.containermenu.property.ClientProperty; @@ -16,13 +15,11 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; -public class ImporterContainerMenu extends AbstractSimpleFilterContainerMenu - implements ResourceTypeAccessor { +public class ImporterContainerMenu extends AbstractSimpleFilterContainerMenu { public ImporterContainerMenu(final int syncId, final Inventory playerInventory, final FriendlyByteBuf buf) { super( Menus.INSTANCE.getImporter(), syncId, - PlatformApi.INSTANCE.getResourceTypeRegistry(), playerInventory.player, buf, UpgradeDestinations.IMPORTER @@ -37,7 +34,6 @@ public ImporterContainerMenu(final int syncId, super( Menus.INSTANCE.getImporter(), syncId, - PlatformApi.INSTANCE.getResourceTypeRegistry(), player, resourceFilterContainer, upgradeContainer, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/InterfaceContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/InterfaceContainerMenu.java index 63d85c1a5..6e27238fb 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/InterfaceContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/InterfaceContainerMenu.java @@ -1,6 +1,5 @@ package com.refinedmods.refinedstorage2.platform.common.containermenu; -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.common.block.entity.InterfaceBlockEntity; import com.refinedmods.refinedstorage2.platform.common.containermenu.property.ClientProperty; import com.refinedmods.refinedstorage2.platform.common.containermenu.property.PropertyTypes; @@ -9,7 +8,7 @@ import com.refinedmods.refinedstorage2.platform.common.content.Menus; import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.FilteredResourceFilterContainer; import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.ResourceFilterContainer; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.item.ItemResourceType; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import com.refinedmods.refinedstorage2.platform.common.util.RedstoneMode; import net.minecraft.network.FriendlyByteBuf; @@ -29,15 +28,8 @@ public InterfaceContainerMenu(final int syncId, final InterfaceBlockEntity blockEntity, final ResourceFilterContainer exportConfig, final Container exportedItems) { - super( - Menus.INSTANCE.getInterface(), - syncId, - PlatformApi.INSTANCE.getResourceTypeRegistry(), - player, - exportConfig - ); + super(Menus.INSTANCE.getInterface(), syncId, player); addSlots(player, exportConfig, exportedItems); - registerProperty(new ServerProperty<>( PropertyTypes.FUZZY_MODE, blockEntity::isFuzzyMode, @@ -51,19 +43,13 @@ public InterfaceContainerMenu(final int syncId, } public InterfaceContainerMenu(final int syncId, final Inventory playerInventory, final FriendlyByteBuf buf) { - super(Menus.INSTANCE.getInterface(), syncId, PlatformApi.INSTANCE.getResourceTypeRegistry()); + super(Menus.INSTANCE.getInterface(), syncId); addSlots( playerInventory.player, - new FilteredResourceFilterContainer( - PlatformApi.INSTANCE.getResourceTypeRegistry(), - 9, - ItemResourceType.INSTANCE, - 64 - ), + new FilteredResourceFilterContainer(9, StorageChannelTypes.ITEM, 64), new SimpleContainer(9) ); initializeResourceFilterSlots(buf); - registerProperty(new ClientProperty<>(PropertyTypes.FUZZY_MODE, false)); registerProperty(new ClientProperty<>(PropertyTypes.REDSTONE_MODE, RedstoneMode.IGNORE)); } @@ -77,9 +63,7 @@ private void addSlots(final Player player, for (int i = 0; i < exportedItems.getContainerSize(); ++i) { addSlot(createExportedItemSlot(exportedItems, i)); } - addPlayerInventory(player.getInventory(), 8, 100); - transferManager.addBiTransfer(exportedItems, player.getInventory()); transferManager.addFilterTransfer(player.getInventory()); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/ResourceTypeAccessor.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/ResourceTypeAccessor.java deleted file mode 100644 index f8ffa0892..000000000 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/ResourceTypeAccessor.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.common.containermenu; - -import net.minecraft.network.chat.Component; - -public interface ResourceTypeAccessor { - Component getCurrentResourceTypeName(); - - void toggleResourceType(); -} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/slot/ResourceFilterSlot.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/slot/ResourceFilterSlot.java index 4e0700982..5dd9c3e09 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/slot/ResourceFilterSlot.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/slot/ResourceFilterSlot.java @@ -1,7 +1,7 @@ package com.refinedmods.refinedstorage2.platform.common.containermenu.slot; +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResource; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.ResourceFilterContainer; @@ -27,7 +27,7 @@ public class ResourceFilterSlot extends Slot { private final ResourceFilterContainer resourceFilterContainer; private final int containerIndex; @Nullable - private FilteredResource cachedResource; + private FilteredResource cachedResource; public ResourceFilterSlot(final ResourceFilterContainer resourceFilterContainer, final int index, @@ -48,7 +48,7 @@ public boolean supportsAmount() { } @Nullable - public FilteredResource getFilteredResource() { + public FilteredResource getFilteredResource() { return resourceFilterContainer.get(containerIndex); } @@ -56,42 +56,66 @@ private static SimpleContainer createDummyContainer() { return new SimpleContainer(1); } - public void change(final ItemStack stack, final ResourceType type) { - type.translate(stack).ifPresentOrElse( - resource -> resourceFilterContainer.set(containerIndex, resource), + public void change(final ItemStack stack, final boolean tryAlternatives) { + PlatformApi.INSTANCE.getFilteredResourceFactory().create(stack, tryAlternatives).ifPresentOrElse( + translated -> resourceFilterContainer.set(containerIndex, translated), () -> resourceFilterContainer.remove(containerIndex) ); } - public boolean changeIfEmpty(final ItemStack stack, final ResourceType type) { - final FilteredResource existing = resourceFilterContainer.get(containerIndex); + public void change(@Nullable final FilteredResource filteredResource) { + if (filteredResource == null) { + resourceFilterContainer.remove(containerIndex); + } else { + resourceFilterContainer.set(containerIndex, filteredResource); + } + } + + public boolean changeIfEmpty(final ItemStack stack) { + final FilteredResource existing = resourceFilterContainer.get(containerIndex); if (existing != null) { return false; } - change(stack, type); + PlatformApi.INSTANCE.getFilteredResourceFactory().create(stack, false).ifPresent(this::change); return true; } - public boolean contains(final ItemStack stack, final ResourceType type) { - final Optional translated = type.translate(stack); - final Optional current = Optional.ofNullable(resourceFilterContainer.get(containerIndex)); - return translated.equals(current); + public void changeAmount(final long amount) { + resourceFilterContainer.setAmount(containerIndex, amount); + } + + public void changeAmountOnClient(final long amount) { + Platform.INSTANCE.getClientToServerCommunications().sendResourceFilterSlotAmountChange(index, amount); + } + + public boolean contains(final ItemStack stack) { + final Optional> converted = PlatformApi.INSTANCE.getFilteredResourceFactory().create( + stack, + false + ); + final Optional> current = Optional.ofNullable(resourceFilterContainer.get(containerIndex)); + return converted.equals(current); } public void broadcastChanges(final Player player) { - final FilteredResource currentResource = resourceFilterContainer.get(containerIndex); + final FilteredResource currentResource = resourceFilterContainer.get(containerIndex); if (!Objects.equals(currentResource, cachedResource)) { LOGGER.info("Resource filter slot {} has changed", containerIndex); this.cachedResource = currentResource; - Platform.INSTANCE.getServerToClientCommunications().sendResourceFilterSlotUpdate( - (ServerPlayer) player, - resourceFilterContainer, - index, - containerIndex - ); + broadcastChange((ServerPlayer) player, currentResource); } } + private void broadcastChange(final ServerPlayer player, @Nullable final FilteredResource filteredResource) { + Platform.INSTANCE.getServerToClientCommunications().sendResourceFilterSlotUpdate( + player, + filteredResource == null ? null : filteredResource.getStorageChannelType(), + filteredResource == null ? null : filteredResource.getValue(), + filteredResource == null ? 0 : filteredResource.getAmount(), + index + ); + } + public void readFromUpdatePacket(final FriendlyByteBuf buf) { resourceFilterContainer.readFromUpdatePacket(containerIndex, buf); } @@ -101,22 +125,16 @@ public boolean mayPickup(final Player player) { return false; } - public List getTooltipLines(@Nullable final Player player) { - final FilteredResource filteredResource = resourceFilterContainer.get(containerIndex); + @Override + public boolean mayPlace(final ItemStack stack) { + return false; + } + + public List getTooltip() { + final FilteredResource filteredResource = resourceFilterContainer.get(containerIndex); if (filteredResource == null) { return Collections.emptyList(); } - return filteredResource.getTooltipLines(player); - } - - public void changeAmount(final long amount) { - resourceFilterContainer.setAmount(containerIndex, amount); - } - - public void changeAmountOnClient(final long amount) { - Platform.INSTANCE.getClientToServerCommunications().sendResourceFilterSlotAmountChange( - index, - amount - ); + return filteredResource.getTooltip(); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/AbstractStorageContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/AbstractStorageContainerMenu.java index c98e940fe..8de1a16df 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/AbstractStorageContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/AbstractStorageContainerMenu.java @@ -1,26 +1,19 @@ package com.refinedmods.refinedstorage2.platform.common.containermenu.storage; import com.refinedmods.refinedstorage2.api.core.filter.FilterMode; -import com.refinedmods.refinedstorage2.api.core.registry.OrderedRegistry; import com.refinedmods.refinedstorage2.api.storage.AccessMode; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; import com.refinedmods.refinedstorage2.platform.common.containermenu.AbstractResourceFilterContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.property.ClientProperty; import com.refinedmods.refinedstorage2.platform.common.containermenu.property.PropertyTypes; import com.refinedmods.refinedstorage2.platform.common.containermenu.property.ServerProperty; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.ResourceFilterContainer; import com.refinedmods.refinedstorage2.platform.common.util.RedstoneMode; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.MenuType; public abstract class AbstractStorageContainerMenu extends AbstractResourceFilterContainerMenu { - protected AbstractStorageContainerMenu(final MenuType type, - final int syncId, - final OrderedRegistry resourceTypeRegistry) { - super(type, syncId, resourceTypeRegistry); - + protected AbstractStorageContainerMenu(final MenuType type, final int syncId) { + super(type, syncId); registerProperty(new ClientProperty<>(PropertyTypes.PRIORITY, 0)); registerProperty(new ClientProperty<>(PropertyTypes.FILTER_MODE, FilterMode.BLOCK)); registerProperty(new ClientProperty<>(PropertyTypes.FUZZY_MODE, false)); @@ -30,12 +23,9 @@ protected AbstractStorageContainerMenu(final MenuType type, protected AbstractStorageContainerMenu(final MenuType type, final int syncId, - final OrderedRegistry resourceTypeRegistry, final Player player, - final StorageConfigurationContainer configContainer, - final ResourceFilterContainer container) { - super(type, syncId, resourceTypeRegistry, player, container); - + final StorageConfigurationContainer configContainer) { + super(type, syncId, player); registerProperty(new ServerProperty<>( PropertyTypes.PRIORITY, configContainer::getPriority, diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/ExternalStorageContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/ExternalStorageContainerMenu.java index 2f6219465..8934cd844 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/ExternalStorageContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/ExternalStorageContainerMenu.java @@ -1,7 +1,5 @@ package com.refinedmods.refinedstorage2.platform.common.containermenu.storage; -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.common.containermenu.ResourceTypeAccessor; import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.ResourceFilterSlot; import com.refinedmods.refinedstorage2.platform.common.content.Menus; import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.ResourceFilterContainer; @@ -11,18 +9,13 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.Slot; -public class ExternalStorageContainerMenu extends AbstractStorageContainerMenu implements ResourceTypeAccessor { +public class ExternalStorageContainerMenu extends AbstractStorageContainerMenu { private static final int FILTER_SLOT_X = 8; private static final int FILTER_SLOT_Y = 20; public ExternalStorageContainerMenu(final int syncId, final Inventory playerInventory, final FriendlyByteBuf buf) { - super(Menus.INSTANCE.getExternalStorage(), syncId, PlatformApi.INSTANCE.getResourceTypeRegistry()); - - addSlots( - playerInventory.player, - new ResourceFilterContainer(PlatformApi.INSTANCE.getResourceTypeRegistry(), 9) - ); - + super(Menus.INSTANCE.getExternalStorage(), syncId); + addSlots(playerInventory.player, new ResourceFilterContainer(9)); initializeResourceFilterSlots(buf); } @@ -30,15 +23,7 @@ public ExternalStorageContainerMenu(final int syncId, final Player player, final ResourceFilterContainer resourceFilterContainer, final StorageConfigurationContainer configContainer) { - super( - Menus.INSTANCE.getExternalStorage(), - syncId, - PlatformApi.INSTANCE.getResourceTypeRegistry(), - player, - configContainer, - resourceFilterContainer - ); - + super(Menus.INSTANCE.getExternalStorage(), syncId, player, configContainer); addSlots(player, resourceFilterContainer); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/StorageAccessor.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/StorageAccessor.java index e664f17d0..9b3b90882 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/StorageAccessor.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/StorageAccessor.java @@ -1,8 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.containermenu.storage; -import com.refinedmods.refinedstorage2.platform.common.containermenu.ResourceTypeAccessor; - -public interface StorageAccessor extends ResourceTypeAccessor { +public interface StorageAccessor { long getStored(); long getCapacity(); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/AbstractStorageBlockContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/AbstractStorageBlockContainerMenu.java index 098e59bfa..4a18a9d51 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/AbstractStorageBlockContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/AbstractStorageBlockContainerMenu.java @@ -1,8 +1,6 @@ package com.refinedmods.refinedstorage2.platform.common.containermenu.storage.block; -import com.refinedmods.refinedstorage2.api.core.registry.OrderedRegistry; -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.ResourceFilterSlot; import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.AbstractStorageContainerMenu; import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.StorageAccessor; @@ -11,7 +9,6 @@ import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.ResourceFilterContainer; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.inventory.Slot; @@ -26,30 +23,22 @@ public abstract class AbstractStorageBlockContainerMenu extends AbstractStorageC protected AbstractStorageBlockContainerMenu(final MenuType type, final int syncId, - final OrderedRegistry resourceRegistry, final Player player, final FriendlyByteBuf buf, - final ResourceType resourceType) { - super(type, syncId, resourceRegistry); - + final PlatformStorageChannelType storageChannelType) { + super(type, syncId); this.stored = buf.readLong(); this.capacity = buf.readLong(); - - addSlots( - player, - new FilteredResourceFilterContainer(PlatformApi.INSTANCE.getResourceTypeRegistry(), 9, resourceType) - ); - + addSlots(player, new FilteredResourceFilterContainer(9, storageChannelType)); initializeResourceFilterSlots(buf); } protected AbstractStorageBlockContainerMenu(final MenuType type, final int syncId, - final OrderedRegistry rtr, final Player player, final ResourceFilterContainer resourceFilterContainer, final StorageConfigurationContainer configContainer) { - super(type, syncId, rtr, player, configContainer, resourceFilterContainer); + super(type, syncId, player, configContainer); addSlots(player, resourceFilterContainer); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/FluidStorageBlockContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/FluidStorageBlockContainerMenu.java index 38ca3a50f..a06cc9ae8 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/FluidStorageBlockContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/FluidStorageBlockContainerMenu.java @@ -1,10 +1,9 @@ package com.refinedmods.refinedstorage2.platform.common.containermenu.storage.block; -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.StorageConfigurationContainer; import com.refinedmods.refinedstorage2.platform.common.content.Menus; import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.ResourceFilterContainer; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.fluid.FluidResourceType; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.entity.player.Inventory; @@ -14,28 +13,14 @@ public class FluidStorageBlockContainerMenu extends AbstractStorageBlockContaine public FluidStorageBlockContainerMenu(final int syncId, final Inventory playerInventory, final FriendlyByteBuf buf) { - super( - Menus.INSTANCE.getFluidStorage(), - syncId, - PlatformApi.INSTANCE.getResourceTypeRegistry(), - playerInventory.player, - buf, - FluidResourceType.INSTANCE - ); + super(Menus.INSTANCE.getFluidStorage(), syncId, playerInventory.player, buf, StorageChannelTypes.FLUID); } public FluidStorageBlockContainerMenu(final int syncId, final Player player, final ResourceFilterContainer resourceFilterContainer, final StorageConfigurationContainer configContainer) { - super( - Menus.INSTANCE.getFluidStorage(), - syncId, - PlatformApi.INSTANCE.getResourceTypeRegistry(), - player, - resourceFilterContainer, - configContainer - ); + super(Menus.INSTANCE.getFluidStorage(), syncId, player, resourceFilterContainer, configContainer); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/ItemStorageBlockContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/ItemStorageBlockContainerMenu.java index e1d449b73..8fa8cb419 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/ItemStorageBlockContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/block/ItemStorageBlockContainerMenu.java @@ -1,10 +1,9 @@ package com.refinedmods.refinedstorage2.platform.common.containermenu.storage.block; -import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.common.containermenu.storage.StorageConfigurationContainer; import com.refinedmods.refinedstorage2.platform.common.content.Menus; import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.ResourceFilterContainer; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.item.ItemResourceType; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.entity.player.Inventory; @@ -12,28 +11,14 @@ public class ItemStorageBlockContainerMenu extends AbstractStorageBlockContainerMenu { public ItemStorageBlockContainerMenu(final int syncId, final Inventory playerInventory, final FriendlyByteBuf buf) { - super( - Menus.INSTANCE.getItemStorage(), - syncId, - PlatformApi.INSTANCE.getResourceTypeRegistry(), - playerInventory.player, - buf, - ItemResourceType.INSTANCE - ); + super(Menus.INSTANCE.getItemStorage(), syncId, playerInventory.player, buf, StorageChannelTypes.ITEM); } public ItemStorageBlockContainerMenu(final int syncId, final Player player, final ResourceFilterContainer resourceFilterContainer, final StorageConfigurationContainer configContainer) { - super( - Menus.INSTANCE.getItemStorage(), - syncId, - PlatformApi.INSTANCE.getResourceTypeRegistry(), - player, - resourceFilterContainer, - configContainer - ); + super(Menus.INSTANCE.getItemStorage(), syncId, player, resourceFilterContainer, configContainer); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/diskdrive/DiskDriveContainerMenu.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/diskdrive/DiskDriveContainerMenu.java index e2ff3b7ae..39a90cead 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/diskdrive/DiskDriveContainerMenu.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/containermenu/storage/diskdrive/DiskDriveContainerMenu.java @@ -35,18 +35,11 @@ public class DiskDriveContainerMenu extends AbstractStorageContainerMenu impleme private final List diskSlots = new ArrayList<>(); public DiskDriveContainerMenu(final int syncId, final Inventory playerInventory, final FriendlyByteBuf buf) { - super(Menus.INSTANCE.getDiskDrive(), syncId, PlatformApi.INSTANCE.getResourceTypeRegistry()); - + super(Menus.INSTANCE.getDiskDrive(), syncId); this.storageInfoAccessor = new StorageDiskInfoAccessorImpl(PlatformApi.INSTANCE.getStorageRepository( playerInventory.player.getLevel() )); - - addSlots( - playerInventory.player, - new SimpleContainer(9), - new ResourceFilterContainer(PlatformApi.INSTANCE.getResourceTypeRegistry(), 9) - ); - + addSlots(playerInventory.player, new SimpleContainer(9), new ResourceFilterContainer(9)); initializeResourceFilterSlots(buf); } @@ -56,14 +49,7 @@ public DiskDriveContainerMenu(final int syncId, final ResourceFilterContainer resourceFilterContainer, final StorageConfigurationContainer configContainer, final StorageDiskInfoAccessor storageInfoAccessor) { - super( - Menus.INSTANCE.getDiskDrive(), - syncId, - PlatformApi.INSTANCE.getResourceTypeRegistry(), - player, - configContainer, - resourceFilterContainer - ); + super(Menus.INSTANCE.getDiskDrive(), syncId, player, configContainer); this.storageInfoAccessor = storageInfoAccessor; addSlots(player, diskInventory, resourceFilterContainer); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/view/FluidGridResource.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/view/FluidGridResource.java index 8437b6c6e..ddf408260 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/view/FluidGridResource.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/view/FluidGridResource.java @@ -62,11 +62,11 @@ public void onScroll(final GridScrollMode scrollMode, final GridScrollingStrateg } @Override - public void render(final PoseStack poseStack, final int slotX, final int slotY) { + public void render(final PoseStack poseStack, final int x, final int y) { Platform.INSTANCE.getFluidRenderer().render( poseStack, - slotX, - slotY, + x, + y, 0, fluidResource ); diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/view/ItemGridResource.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/view/ItemGridResource.java index b2a331bba..6d43760d9 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/view/ItemGridResource.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/grid/view/ItemGridResource.java @@ -72,11 +72,11 @@ public void onScroll(final GridScrollMode scrollMode, final GridScrollingStrateg } @Override - public void render(final PoseStack poseStack, final int slotX, final int slotY) { + public void render(final PoseStack poseStack, final int x, final int y) { final ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer(); final Font font = Minecraft.getInstance().font; - itemRenderer.renderGuiItem(itemStack, slotX, slotY); - itemRenderer.renderGuiItemDecorations(font, itemStack, slotX, slotY, null); + itemRenderer.renderGuiItem(itemStack, x, y); + itemRenderer.renderGuiItemDecorations(font, itemStack, x, y, null); } @Override diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/CompositeFilteredResourceFactory.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/CompositeFilteredResourceFactory.java new file mode 100644 index 000000000..5754cb847 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/CompositeFilteredResourceFactory.java @@ -0,0 +1,36 @@ +package com.refinedmods.refinedstorage2.platform.common.internal.resource.filter; + +import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResource; +import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResourceFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import net.minecraft.world.item.ItemStack; + +public class CompositeFilteredResourceFactory implements FilteredResourceFactory { + private final FilteredResourceFactory defaultFactory; + private final List alternatives = new ArrayList<>(); + + public CompositeFilteredResourceFactory(final FilteredResourceFactory defaultFactory) { + this.defaultFactory = defaultFactory; + } + + public void addAlternativeFactory(final FilteredResourceFactory factory) { + alternatives.add(factory); + } + + @Override + public Optional> create(final ItemStack stack, final boolean tryAlternatives) { + if (tryAlternatives) { + for (final FilteredResourceFactory factory : alternatives) { + final Optional> filteredResource = factory.create(stack, true); + if (filteredResource.isPresent()) { + return filteredResource; + } + } + } + return defaultFactory.create(stack, false); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/FilteredResourceFilterContainer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/FilteredResourceFilterContainer.java index 55318401e..6ead9afa5 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/FilteredResourceFilterContainer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/FilteredResourceFilterContainer.java @@ -1,55 +1,43 @@ package com.refinedmods.refinedstorage2.platform.common.internal.resource.filter; -import com.refinedmods.refinedstorage2.api.core.registry.OrderedRegistry; import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResource; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; - -import net.minecraft.resources.ResourceLocation; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; public class FilteredResourceFilterContainer extends ResourceFilterContainer { - private final ResourceType allowedType; + private final PlatformStorageChannelType allowedType; - public FilteredResourceFilterContainer(final OrderedRegistry resourceTypeRegistry, - final int size, - final ResourceType allowedType) { - this(resourceTypeRegistry, size, () -> { + public FilteredResourceFilterContainer(final int size, + final PlatformStorageChannelType allowedType) { + this(size, () -> { }, allowedType, -1); } - public FilteredResourceFilterContainer(final OrderedRegistry resourceTypeRegistry, - final int size, - final ResourceType allowedType, + public FilteredResourceFilterContainer(final int size, + final PlatformStorageChannelType allowedType, final long maxAmount) { - this(resourceTypeRegistry, size, () -> { + this(size, () -> { }, allowedType, maxAmount); } - public FilteredResourceFilterContainer(final OrderedRegistry resourceTypeRegistry, - final int size, + public FilteredResourceFilterContainer(final int size, final Runnable listener, - final ResourceType allowedType) { - this(resourceTypeRegistry, size, listener, allowedType, -1); + final PlatformStorageChannelType allowedType) { + this(size, listener, allowedType, -1); } - public FilteredResourceFilterContainer(final OrderedRegistry resourceTypeRegistry, - final int size, + public FilteredResourceFilterContainer(final int size, final Runnable listener, - final ResourceType allowedType, + final PlatformStorageChannelType allowedType, final long maxAmount) { - super(resourceTypeRegistry, size, listener, maxAmount); + super(size, listener, maxAmount); this.allowedType = allowedType; } @Override - public void set(final int index, final FilteredResource resource) { - if (resource.getType() != allowedType) { + public void set(final int index, final FilteredResource resource) { + if (resource.getStorageChannelType() != allowedType) { return; } super.set(index, resource); } - - @Override - public ResourceType determineDefaultType() { - return allowedType; - } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/ResourceFilterContainer.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/ResourceFilterContainer.java index 26ab0e879..ffb781857 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/ResourceFilterContainer.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/ResourceFilterContainer.java @@ -1,15 +1,14 @@ package com.refinedmods.refinedstorage2.platform.common.internal.resource.filter; -import com.refinedmods.refinedstorage2.api.core.registry.OrderedRegistry; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResource; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.List; -import java.util.Objects; import java.util.Set; import javax.annotation.Nullable; @@ -17,41 +16,31 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class ResourceFilterContainer { - private static final Logger LOGGER = LoggerFactory.getLogger(ResourceFilterContainer.class); - - private final OrderedRegistry resourceTypeRegistry; - private final FilteredResource[] items; + private final FilteredResource[] items; private final Runnable listener; private final long maxAmount; - public ResourceFilterContainer(final OrderedRegistry resourceTypeRegistry, - final int size, + public ResourceFilterContainer(final int size, final long maxAmount) { - this(resourceTypeRegistry, size, () -> { + this(size, () -> { }, maxAmount); } - public ResourceFilterContainer(final OrderedRegistry resourceTypeRegistry, - final int size) { - this(resourceTypeRegistry, size, () -> { + public ResourceFilterContainer(final int size) { + this(size, () -> { }, -1); } - public ResourceFilterContainer(final OrderedRegistry resourceTypeRegistry, - final int size, + public ResourceFilterContainer(final int size, final Runnable listener) { - this(resourceTypeRegistry, size, listener, -1); + this(size, listener, -1); } - public ResourceFilterContainer(final OrderedRegistry resourceTypeRegistry, - final int size, + public ResourceFilterContainer(final int size, final Runnable listener, final long maxAmount) { - this.resourceTypeRegistry = resourceTypeRegistry; this.items = new FilteredResource[size]; this.listener = listener; this.maxAmount = maxAmount; @@ -61,16 +50,20 @@ public boolean supportsAmount() { return maxAmount >= 0; } - public void set(final int index, final FilteredResource resource) { + public void set(final int index, final FilteredResource resource) { setSilently(index, resource); listener.run(); } + private void setSilently(final int index, final FilteredResource resource) { + items[index] = resource; + } + public void setAmount(final int index, final long amount) { if (!supportsAmount()) { return; } - final FilteredResource filteredResource = get(index); + final FilteredResource filteredResource = get(index); if (filteredResource == null) { return; } @@ -82,10 +75,6 @@ public void setAmount(final int index, final long amount) { set(index, filteredResource.withAmount(newAmount)); } - private void setSilently(final int index, final FilteredResource resource) { - items[index] = resource; - } - public void remove(final int index) { removeSilently(index); listener.run(); @@ -100,7 +89,7 @@ public int size() { } @Nullable - public FilteredResource get(final int index) { + public FilteredResource get(final int index) { return items[index]; } @@ -114,7 +103,7 @@ public List getTemplates() { private > C getTemplates(final C result) { for (int i = 0; i < size(); ++i) { - final FilteredResource item = items[i]; + final FilteredResource item = items[i]; if (item == null) { continue; } @@ -123,40 +112,26 @@ private > C getTemplates(final C result) { return result; } - public ResourceType determineDefaultType() { - final List distinctTypes = Arrays.stream(items) - .filter(Objects::nonNull) - .map(FilteredResource::getType) - .distinct() - .toList(); - if (distinctTypes.size() == 1) { - return distinctTypes.get(0); - } - return resourceTypeRegistry.getDefault(); - } - public void writeToUpdatePacket(final FriendlyByteBuf buf) { - buf.writeResourceLocation(resourceTypeRegistry.getId(determineDefaultType()) - .orElseThrow(() -> new IllegalStateException("Default resource type not registered"))); for (int index = 0; index < items.length; ++index) { - writeToUpdatePacket(index, buf); + final FilteredResource item = items[index]; + if (item == null) { + buf.writeBoolean(false); + continue; + } + writeToUpdatePacket(buf, item); } } - public void writeToUpdatePacket(final int index, final FriendlyByteBuf buf) { - final FilteredResource item = items[index]; - if (item == null) { - buf.writeBoolean(false); - return; - } - resourceTypeRegistry.getId(item.getType()).ifPresentOrElse( - id -> { - buf.writeBoolean(true); - buf.writeResourceLocation(id); - item.writeToPacket(buf); - }, - () -> buf.writeBoolean(false) - ); + private void writeToUpdatePacket(final FriendlyByteBuf buf, + final FilteredResource item) { + final PlatformStorageChannelType storageChannelType = item.getStorageChannelType(); + PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getId(storageChannelType).ifPresentOrElse(id -> { + buf.writeBoolean(true); + buf.writeResourceLocation(id); + storageChannelType.toBuffer(item.getValue(), buf); + buf.writeLong(item.getAmount()); + }, () -> buf.writeBoolean(false)); } public void readFromUpdatePacket(final int index, final FriendlyByteBuf buf) { @@ -166,58 +141,78 @@ public void readFromUpdatePacket(final int index, final FriendlyByteBuf buf) { return; } final ResourceLocation id = buf.readResourceLocation(); - resourceTypeRegistry.get(id).ifPresentOrElse( - type -> setSilently(index, type.fromPacket(buf)), - () -> LOGGER.warn("Resource type {} is not registered on the client, cannot read from packet", id) + PlatformApi.INSTANCE.getStorageChannelTypeRegistry().get(id).ifPresent( + storageChannelType -> readFromUpdatePacket(index, buf, storageChannelType) + ); + } + + private void readFromUpdatePacket(final int index, + final FriendlyByteBuf buf, + final PlatformStorageChannelType storageChannelType) { + final T resource = storageChannelType.fromBuffer(buf); + final long amount = buf.readLong(); + storageChannelType.toFilteredResource(new ResourceAmount<>(resource, amount)).ifPresent( + filteredResource -> setSilently(index, filteredResource) ); } public CompoundTag toTag() { final CompoundTag tag = new CompoundTag(); for (int i = 0; i < size(); ++i) { - final FilteredResource item = items[i]; + final FilteredResource item = items[i]; if (item == null) { continue; } - final int index = i; - resourceTypeRegistry.getId(item.getType()).ifPresentOrElse( - id -> addToTag(tag, index, item, id), - () -> LOGGER.warn("Resource type {} is not registered, cannot serialize", item.getType()) - ); + addToTag(tag, i, item); } return tag; } - private void addToTag(final CompoundTag tag, - final int index, - final FilteredResource item, - final ResourceLocation typeId) { + private void addToTag(final CompoundTag tag, + final int index, + final FilteredResource item) { + final PlatformStorageChannelType storageChannelType = item.getStorageChannelType(); + PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getId(storageChannelType).ifPresent( + storageChannelTypeId -> addToTag(tag, index, item, storageChannelType, storageChannelTypeId) + ); + } + + private void addToTag(final CompoundTag tag, + final int index, + final FilteredResource filteredResource, + final PlatformStorageChannelType storageChannelType, + final ResourceLocation storageChannelTypeId) { final CompoundTag serialized = new CompoundTag(); - serialized.putString("t", typeId.toString()); - serialized.put("v", item.toTag()); + serialized.putString("t", storageChannelTypeId.toString()); + serialized.put("v", storageChannelType.toTag(filteredResource.getValue())); + serialized.putLong("a", filteredResource.getAmount()); tag.put("s" + index, serialized); } - public void load(final CompoundTag tag) { + public void fromTag(final CompoundTag tag) { for (int i = 0; i < size(); ++i) { final String key = "s" + i; if (!tag.contains(key)) { continue; } final CompoundTag item = tag.getCompound(key); - load(i, item); + fromTag(i, item); } } - private void load(final int index, final CompoundTag item) { - final ResourceLocation typeId = new ResourceLocation(item.getString("t")); - resourceTypeRegistry.get(typeId).ifPresentOrElse( - type -> load(index, item, type), - () -> LOGGER.warn("Resource type {} is not registered, cannot deserialize", typeId) + private void fromTag(final int index, final CompoundTag tag) { + final ResourceLocation storageChannelTypeId = new ResourceLocation(tag.getString("t")); + PlatformApi.INSTANCE.getStorageChannelTypeRegistry().get(storageChannelTypeId).ifPresent( + storageChannelType -> fromTag(index, tag, storageChannelType) ); } - private void load(final int index, final CompoundTag item, final ResourceType type) { - type.fromTag(item.getCompound("v")).ifPresent(resource -> setSilently(index, resource)); + private void fromTag(final int index, + final CompoundTag tag, + final PlatformStorageChannelType storageChannelType) { + final long amount = tag.getLong("a"); + storageChannelType.fromTag(tag.getCompound("v")) + .flatMap(resource -> storageChannelType.toFilteredResource(new ResourceAmount<>(resource, amount))) + .ifPresent(filteredResource -> setSilently(index, filteredResource)); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/fluid/FluidFilteredResource.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/fluid/FluidFilteredResource.java index 1eb0cc369..7e5cb9f80 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/fluid/FluidFilteredResource.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/fluid/FluidFilteredResource.java @@ -2,57 +2,34 @@ import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResource; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import java.util.List; -import javax.annotation.Nullable; import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Player; - -public record FluidFilteredResource(FluidResource value, long amount) implements FilteredResource { - private static final String TAG_AMOUNT = "amt"; - - public static long getAmountFromTag(final CompoundTag tag) { - return tag.getLong(TAG_AMOUNT); - } - - @Override - public void writeToPacket(final FriendlyByteBuf buf) { - PacketUtil.writeFluidResource(buf, value); - buf.writeLong(amount); - } - - @Override - public CompoundTag toTag() { - final CompoundTag tag = FluidResource.toTag(value); - tag.putLong(TAG_AMOUNT, amount); - return tag; - } +public record FluidFilteredResource(FluidResource value, long amount) implements FilteredResource { @Override public void render(final PoseStack poseStack, final int x, final int y, final int z) { Platform.INSTANCE.getFluidRenderer().render(poseStack, x, y, z, value); } @Override - public Object getValue() { + public FluidResource getValue() { return value; } @Override - public long getAmount() { - return amount; + public FilteredResource withAmount(final long newAmount) { + return new FluidFilteredResource(value, newAmount); } @Override - public FilteredResource withAmount(final long newAmount) { - return new FluidFilteredResource(value, newAmount); + public long getAmount() { + return amount; } @Override @@ -61,17 +38,17 @@ public long getMaxAmount() { } @Override - public String getFormattedAmount() { + public String getDisplayedAmount() { return Platform.INSTANCE.getBucketQuantityFormatter().formatWithUnits(amount); } @Override - public ResourceType getType() { - return FluidResourceType.INSTANCE; + public List getTooltip() { + return Platform.INSTANCE.getFluidRenderer().getTooltip(value); } @Override - public List getTooltipLines(@Nullable final Player player) { - return Platform.INSTANCE.getFluidRenderer().getTooltip(value); + public PlatformStorageChannelType getStorageChannelType() { + return StorageChannelTypes.FLUID; } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/fluid/FluidFilteredResourceFactory.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/fluid/FluidFilteredResourceFactory.java new file mode 100644 index 000000000..9018e0507 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/fluid/FluidFilteredResourceFactory.java @@ -0,0 +1,18 @@ +package com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.fluid; + +import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResource; +import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResourceFactory; +import com.refinedmods.refinedstorage2.platform.common.Platform; + +import java.util.Optional; + +import net.minecraft.world.item.ItemStack; + +public class FluidFilteredResourceFactory implements FilteredResourceFactory { + @Override + public Optional> create(final ItemStack stack, final boolean tryAlternatives) { + return Platform.INSTANCE.convertToFluid(stack).map( + fluidResource -> new FluidFilteredResource(fluidResource, Platform.INSTANCE.getBucketAmount()) + ); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/fluid/FluidResourceType.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/fluid/FluidResourceType.java deleted file mode 100644 index c83ceae19..000000000 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/fluid/FluidResourceType.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.fluid; - -import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResource; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; -import com.refinedmods.refinedstorage2.platform.common.Platform; -import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; - -import java.util.Optional; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.world.item.ItemStack; - -import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; - -public class FluidResourceType implements ResourceType { - public static final FluidResourceType INSTANCE = new FluidResourceType(); - - private static final MutableComponent NAME = createTranslation("misc", "resource_type.fluid"); - - private FluidResourceType() { - } - - @Override - public Component getName() { - return NAME; - } - - @Override - public Optional translate(final ItemStack stack) { - return Platform.INSTANCE.convertToFluid(stack).map(fluid -> new FluidFilteredResource( - fluid, - Platform.INSTANCE.getBucketAmount() - )); - } - - @Override - public FilteredResource fromPacket(final FriendlyByteBuf buf) { - return new FluidFilteredResource(PacketUtil.readFluidResource(buf), buf.readLong()); - } - - @Override - public Optional fromTag(final CompoundTag tag) { - return FluidResource.fromTag(tag) - .map(fluidResource -> new FluidFilteredResource( - fluidResource, - FluidFilteredResource.getAmountFromTag(tag) - )); - } -} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/item/ItemFilteredResource.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/item/ItemFilteredResource.java index 580ae9a24..e2ce51d5f 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/item/ItemFilteredResource.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/item/ItemFilteredResource.java @@ -3,58 +3,35 @@ import com.refinedmods.refinedstorage2.api.core.QuantityFormatter; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResource; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; -import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; +import com.refinedmods.refinedstorage2.platform.common.internal.storage.channel.StorageChannelTypes; import java.util.List; -import javax.annotation.Nullable; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.TooltipFlag; -public record ItemFilteredResource(ItemResource value, long amount) implements FilteredResource { - private static final String TAG_AMOUNT = "amt"; - - public static long getAmountFromTag(final CompoundTag tag) { - return tag.getLong(TAG_AMOUNT); - } - - @Override - public void writeToPacket(final FriendlyByteBuf buf) { - PacketUtil.writeItemResource(buf, value); - buf.writeLong(amount); - } - - @Override - public CompoundTag toTag() { - final CompoundTag tag = ItemResource.toTag(value); - tag.putLong(TAG_AMOUNT, amount); - return tag; - } - +public record ItemFilteredResource(ItemResource value, long amount) implements FilteredResource { @Override public void render(final PoseStack poseStack, final int x, final int y, final int z) { Minecraft.getInstance().getItemRenderer().renderAndDecorateItem(value.toItemStack(), x, y); } @Override - public Object getValue() { + public ItemResource getValue() { return value; } @Override - public long getAmount() { - return amount; + public FilteredResource withAmount(final long newAmount) { + return new ItemFilteredResource(value, newAmount); } @Override - public FilteredResource withAmount(final long newAmount) { - return new ItemFilteredResource(value, newAmount); + public long getAmount() { + return amount; } @Override @@ -63,7 +40,7 @@ public long getMaxAmount() { } @Override - public String getFormattedAmount() { + public String getDisplayedAmount() { if (amount == 1) { return ""; } @@ -71,15 +48,16 @@ public String getFormattedAmount() { } @Override - public ResourceType getType() { - return ItemResourceType.INSTANCE; + public List getTooltip() { + final Minecraft minecraft = Minecraft.getInstance(); + return value.toItemStack().getTooltipLines( + minecraft.player, + minecraft.options.advancedItemTooltips ? TooltipFlag.ADVANCED : TooltipFlag.NORMAL + ); } @Override - public List getTooltipLines(@Nullable final Player player) { - final TooltipFlag.Default flag = Minecraft.getInstance().options.advancedItemTooltips - ? TooltipFlag.Default.ADVANCED - : TooltipFlag.Default.NORMAL; - return value.toItemStack().getTooltipLines(player, flag); + public PlatformStorageChannelType getStorageChannelType() { + return StorageChannelTypes.ITEM; } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/item/ItemFilteredResourceFactory.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/item/ItemFilteredResourceFactory.java new file mode 100644 index 000000000..9f5e13fb8 --- /dev/null +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/item/ItemFilteredResourceFactory.java @@ -0,0 +1,19 @@ +package com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.item; + +import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResource; +import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResourceFactory; + +import java.util.Optional; + +import net.minecraft.world.item.ItemStack; + +public class ItemFilteredResourceFactory implements FilteredResourceFactory { + @Override + public Optional> create(final ItemStack stack, final boolean tryAlternatives) { + if (!stack.isEmpty()) { + return Optional.of(new ItemFilteredResource(ItemResource.ofItemStack(stack), stack.getCount())); + } + return Optional.empty(); + } +} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/item/ItemResourceType.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/item/ItemResourceType.java deleted file mode 100644 index f62ec5af3..000000000 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/item/ItemResourceType.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.item; - -import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResource; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; -import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; - -import java.util.Optional; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.world.item.ItemStack; - -import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; - -public class ItemResourceType implements ResourceType { - public static final ItemResourceType INSTANCE = new ItemResourceType(); - - private static final MutableComponent NAME = createTranslation("misc", "resource_type.item"); - - private ItemResourceType() { - } - - @Override - public Component getName() { - return NAME; - } - - @Override - public Optional translate(final ItemStack stack) { - return stack.isEmpty() - ? Optional.empty() - : Optional.of(doTranslate(stack)); - } - - private static ItemFilteredResource doTranslate(final ItemStack stack) { - return new ItemFilteredResource( - new ItemResource(stack.getItem(), stack.getTag()), - stack.getCount() - ); - } - - @Override - public FilteredResource fromPacket(final FriendlyByteBuf buf) { - return new ItemFilteredResource(PacketUtil.readItemResource(buf), buf.readLong()); - } - - @Override - public Optional fromTag(final CompoundTag tag) { - return ItemResource.fromTag(tag) - .map(itemResource -> new ItemFilteredResource( - itemResource, - ItemFilteredResource.getAmountFromTag(tag) - )); - } -} diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/channel/FluidStorageChannelType.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/channel/FluidStorageChannelType.java index 8c5a4d8c6..0d6ac33f8 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/channel/FluidStorageChannelType.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/channel/FluidStorageChannelType.java @@ -5,12 +5,14 @@ import com.refinedmods.refinedstorage2.api.resource.list.ResourceList; import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl; import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; +import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResource; import com.refinedmods.refinedstorage2.platform.api.resource.list.FuzzyResourceList; import com.refinedmods.refinedstorage2.platform.api.resource.list.FuzzyResourceListImpl; import com.refinedmods.refinedstorage2.platform.api.storage.channel.AbstractPlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.api.storage.channel.FuzzyStorageChannelImpl; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.internal.grid.view.FluidGridResource; +import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.fluid.FluidFilteredResource; import com.refinedmods.refinedstorage2.platform.common.screen.widget.AbstractSideButtonWidget; import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; @@ -18,7 +20,6 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; @@ -31,7 +32,10 @@ class FluidStorageChannelType extends AbstractPlatformStorageChannelType fuzzyList = new FuzzyResourceListImpl<>(list); return new FuzzyStorageChannelImpl<>(fuzzyList); }, - createTranslation("misc", "storage_channel_type.fluid") + createTranslation("misc", "storage_channel_type.fluid"), + AbstractSideButtonWidget.DEFAULT_TEXTURE, + 16, + 128 ); } @@ -51,32 +55,25 @@ public Optional toGridResource(final ResourceAmount resourceAmo } @Override - public boolean isGridResourceBelonging(final GridResource gridResource) { - return gridResource instanceof FluidGridResource; - } - - @Override - public ResourceLocation getTextureIdentifier() { - return AbstractSideButtonWidget.DEFAULT_TEXTURE; + public Optional> toFilteredResource(final ResourceAmount resourceAmount) { + if (resourceAmount.getResource() instanceof FluidResource fluidResource) { + return Optional.of(new FluidFilteredResource(fluidResource, resourceAmount.getAmount())); + } + return Optional.empty(); } @Override - public int getXTexture() { - return 16; - } - - @Override - public int getYTexture() { - return 128; + public boolean isGridResourceBelonging(final GridResource gridResource) { + return gridResource instanceof FluidGridResource; } @Override - protected CompoundTag toTag(final FluidResource resource) { + public CompoundTag toTag(final FluidResource resource) { return FluidResource.toTag(resource); } @Override - protected Optional fromTag(final CompoundTag tag) { + public Optional fromTag(final CompoundTag tag) { return FluidResource.fromTag(tag); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/channel/ItemStorageChannelType.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/channel/ItemStorageChannelType.java index 4407c2e40..c61ec67d9 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/channel/ItemStorageChannelType.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/internal/storage/channel/ItemStorageChannelType.java @@ -5,12 +5,14 @@ import com.refinedmods.refinedstorage2.api.resource.list.ResourceList; import com.refinedmods.refinedstorage2.api.resource.list.ResourceListImpl; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; +import com.refinedmods.refinedstorage2.platform.api.resource.filter.FilteredResource; import com.refinedmods.refinedstorage2.platform.api.resource.list.FuzzyResourceList; import com.refinedmods.refinedstorage2.platform.api.resource.list.FuzzyResourceListImpl; import com.refinedmods.refinedstorage2.platform.api.storage.channel.AbstractPlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.api.storage.channel.FuzzyStorageChannelImpl; import com.refinedmods.refinedstorage2.platform.common.Platform; import com.refinedmods.refinedstorage2.platform.common.internal.grid.view.ItemGridResource; +import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.item.ItemFilteredResource; import com.refinedmods.refinedstorage2.platform.common.screen.widget.AbstractSideButtonWidget; import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; @@ -18,7 +20,6 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; import static com.refinedmods.refinedstorage2.platform.common.util.IdentifierUtil.createTranslation; @@ -31,7 +32,10 @@ class ItemStorageChannelType extends AbstractPlatformStorageChannelType fuzzyList = new FuzzyResourceListImpl<>(list); return new FuzzyStorageChannelImpl<>(fuzzyList); }, - createTranslation("misc", "storage_channel_type.item") + createTranslation("misc", "storage_channel_type.item"), + AbstractSideButtonWidget.DEFAULT_TEXTURE, + 0, + 128 ); } @@ -51,32 +55,25 @@ public Optional toGridResource(final ResourceAmount resourceAmo } @Override - public boolean isGridResourceBelonging(final GridResource gridResource) { - return gridResource instanceof ItemGridResource; - } - - @Override - public ResourceLocation getTextureIdentifier() { - return AbstractSideButtonWidget.DEFAULT_TEXTURE; + public Optional> toFilteredResource(final ResourceAmount resourceAmount) { + if (resourceAmount.getResource() instanceof ItemResource itemResource) { + return Optional.of(new ItemFilteredResource(itemResource, resourceAmount.getAmount())); + } + return Optional.empty(); } @Override - public int getXTexture() { - return 0; - } - - @Override - public int getYTexture() { - return 128; + public boolean isGridResourceBelonging(final GridResource gridResource) { + return gridResource instanceof ItemGridResource; } @Override - protected CompoundTag toTag(final ItemResource resource) { + public CompoundTag toTag(final ItemResource resource) { return ItemResource.toTag(resource); } @Override - protected Optional fromTag(final CompoundTag tag) { + public Optional fromTag(final CompoundTag tag) { return ItemResource.fromTag(tag); } } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/packet/ClientToServerCommunications.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/packet/ClientToServerCommunications.java index e0a5c8d1e..d185e2353 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/packet/ClientToServerCommunications.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/packet/ClientToServerCommunications.java @@ -3,7 +3,6 @@ import com.refinedmods.refinedstorage2.api.grid.service.GridExtractMode; import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.common.containermenu.property.PropertyType; @@ -24,9 +23,9 @@ void sendGridScroll(PlatformStorageChannelType storageChannelType, void sendPropertyChange(PropertyType type, T value); - void sendResourceTypeChange(ResourceType type); - void sendStorageInfoRequest(UUID storageId); + void sendResourceFilterSlotChange(int slotIndex, boolean tryAlternatives); + void sendResourceFilterSlotAmountChange(int slotIndex, long amount); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/packet/ServerToClientCommunications.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/packet/ServerToClientCommunications.java index 801cd2bd2..cc9b53a2e 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/packet/ServerToClientCommunications.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/packet/ServerToClientCommunications.java @@ -3,7 +3,6 @@ import com.refinedmods.refinedstorage2.api.storage.StorageInfo; import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.ResourceFilterContainer; import java.util.UUID; import javax.annotation.Nullable; @@ -21,10 +20,11 @@ void sendGridUpdate(ServerPlayer player, long change, @Nullable TrackedResource trackedResource); - void sendResourceFilterSlotUpdate(ServerPlayer player, - ResourceFilterContainer resourceFilterContainer, - int slotIndex, - int containerIndex); + void sendResourceFilterSlotUpdate(ServerPlayer player, + @Nullable PlatformStorageChannelType storageChannelType, + @Nullable T resource, + long amount, + int slotIndex); void sendStorageInfoResponse(ServerPlayer player, UUID id, StorageInfo storageInfo); } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/AbstractBaseScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/AbstractBaseScreen.java index 4ced7503f..6c3b0aafd 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/AbstractBaseScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/AbstractBaseScreen.java @@ -5,7 +5,6 @@ import com.refinedmods.refinedstorage2.platform.common.containermenu.slot.ResourceFilterSlot; import com.refinedmods.refinedstorage2.platform.common.screen.amount.ResourceAmountScreen; import com.refinedmods.refinedstorage2.platform.common.screen.widget.AbstractSideButtonWidget; -import com.refinedmods.refinedstorage2.platform.common.screen.widget.ResourceFilterButtonWidget; import java.util.List; import java.util.Objects; @@ -19,7 +18,6 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.inventory.ClickType; import net.minecraft.world.inventory.Slot; public abstract class AbstractBaseScreen extends AbstractContainerScreen { @@ -39,35 +37,6 @@ protected void init() { clearWidgets(); super.init(); sideButtonY = 6; - tryAddResourceFilterButton(); - } - - private void tryAddResourceFilterButton() { - if (!(menu instanceof AbstractResourceFilterContainerMenu resourceFilterMenu)) { - return; - } - if (!isResourceFilterButtonVisible()) { - return; - } - final ResourceFilterButtonWidget resourceFilterButton = new ResourceFilterButtonWidget( - getResourceFilterButtonX(), - topPos + 4, - resourceFilterMenu - ); - resourceFilterButton.active = isResourceFilterButtonActive(); - addRenderableWidget(resourceFilterButton); - } - - protected int getResourceFilterButtonX() { - return leftPos + imageWidth - ResourceFilterButtonWidget.WIDTH - 7; - } - - protected boolean isResourceFilterButtonVisible() { - return true; - } - - protected boolean isResourceFilterButtonActive() { - return true; } protected abstract ResourceLocation getTexture(); @@ -107,7 +76,7 @@ private void tryRenderResourceFilterSlot(final PoseStack poseStack, final Slot s if (!(slot instanceof ResourceFilterSlot resourceFilterSlot)) { return; } - final FilteredResource filteredResource = resourceFilterSlot.getFilteredResource(); + final FilteredResource filteredResource = resourceFilterSlot.getFilteredResource(); if (filteredResource == null) { return; } @@ -125,7 +94,7 @@ private void renderResourceFilterSlot(final PoseStack poseStack, final int x, final int y, final int z, - final FilteredResource filteredResource, + final FilteredResource filteredResource, final boolean supportsAmount) { filteredResource.render(poseStack, x, y, z); if (supportsAmount) { @@ -136,12 +105,12 @@ private void renderResourceFilterSlot(final PoseStack poseStack, protected void renderResourceFilterSlotAmount(final PoseStack poseStack, final int x, final int y, - final FilteredResource filteredResource) { + final FilteredResource filteredResource) { renderAmount( poseStack, x, y, - filteredResource.getFormattedAmount(), + filteredResource.getDisplayedAmount(), Objects.requireNonNullElse(ChatFormatting.WHITE.getColor(), 15), true ); @@ -190,7 +159,7 @@ protected void renderTooltip(final PoseStack poseStack, final int x, final int y if (minecraft != null && menu.getCarried().isEmpty() && hoveredSlot instanceof ResourceFilterSlot resourceFilterSlot) { - final List lines = resourceFilterSlot.getTooltipLines(minecraft.player); + final List lines = resourceFilterSlot.getTooltip(); if (!lines.isEmpty()) { this.renderComponentTooltip(poseStack, lines, x, y); } @@ -198,22 +167,27 @@ protected void renderTooltip(final PoseStack poseStack, final int x, final int y } @Override - protected void slotClicked(final Slot slot, final int slotId, final int mouseButton, final ClickType type) { - if (!tryOpenResourceFilterAmountScreen(slot, type)) { - super.slotClicked(slot, slotId, mouseButton, type); + public boolean mouseClicked(final double mouseX, final double mouseY, final int clickedButton) { + if (hoveredSlot instanceof ResourceFilterSlot + && getMenu() instanceof AbstractResourceFilterContainerMenu containerMenu) { + if (!tryOpenResourceFilterAmountScreen(hoveredSlot)) { + containerMenu.sendResourceFilterSlotChange(hoveredSlot.index, clickedButton == 1); + } + return true; } + return super.mouseClicked(mouseX, mouseY, clickedButton); } - protected boolean tryOpenResourceFilterAmountScreen(final Slot slot, final ClickType type) { + protected boolean tryOpenResourceFilterAmountScreen(final Slot slot) { final boolean isFilterSlot = slot instanceof ResourceFilterSlot filterSlot && filterSlot.getFilteredResource() != null; final boolean doesFilterSlotSupportAmount = isFilterSlot && ((ResourceFilterSlot) slot).supportsAmount(); - final boolean isRegularClick = type != ClickType.QUICK_MOVE; + final boolean isNotTryingToRemoveFilter = !hasShiftDown(); final boolean isNotCarryingItem = getMenu().getCarried().isEmpty(); final boolean canChangeAmount = - isFilterSlot && doesFilterSlotSupportAmount && isRegularClick && isNotCarryingItem; + isFilterSlot && doesFilterSlotSupportAmount && isNotTryingToRemoveFilter && isNotCarryingItem; if (canChangeAmount && minecraft != null) { - minecraft.setScreen(new ResourceAmountScreen(this, playerInventory, ((ResourceFilterSlot) slot))); + minecraft.setScreen(new ResourceAmountScreen(this, playerInventory, (ResourceFilterSlot) slot)); } return canChangeAmount; } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/AbstractStorageBlockScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/AbstractStorageBlockScreen.java index 7ebd59c66..7c349c920 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/AbstractStorageBlockScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/AbstractStorageBlockScreen.java @@ -17,11 +17,6 @@ protected AbstractStorageBlockScreen(final AbstractStorageBlockContainerMenu men super(menu, inventory, title, 80); } - @Override - protected boolean isResourceFilterButtonActive() { - return false; - } - @Override protected ResourceLocation getTexture() { return TEXTURE; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/DiskDriveScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/DiskDriveScreen.java index ee3cbe005..d7ef0b0b3 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/DiskDriveScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/DiskDriveScreen.java @@ -19,11 +19,6 @@ public DiskDriveScreen(final DiskDriveContainerMenu menu, final Inventory player super(menu, playerInventory, text, 99); } - @Override - protected boolean isResourceFilterButtonActive() { - return true; - } - @Override protected ResourceLocation getTexture() { return TEXTURE; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/ExporterScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/ExporterScreen.java index f2e2af333..2202c2f06 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/ExporterScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/ExporterScreen.java @@ -25,7 +25,6 @@ public ExporterScreen(final ExporterContainerMenu menu, final Inventory playerIn @Override protected void init() { super.init(); - addSideButton(new RedstoneModeSideButtonWidget( getMenu().getProperty(PropertyTypes.REDSTONE_MODE), this::renderComponentTooltip @@ -40,11 +39,6 @@ protected void init() { )); } - @Override - protected int getResourceFilterButtonX() { - return super.getResourceFilterButtonX() - 34; - } - @Override protected ResourceLocation getTexture() { return TEXTURE; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/ImporterScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/ImporterScreen.java index a0872d839..b1f11a3df 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/ImporterScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/ImporterScreen.java @@ -25,7 +25,6 @@ public ImporterScreen(final ImporterContainerMenu menu, final Inventory playerIn @Override protected void init() { super.init(); - addSideButton(new RedstoneModeSideButtonWidget( getMenu().getProperty(PropertyTypes.REDSTONE_MODE), this::renderComponentTooltip @@ -40,11 +39,6 @@ protected void init() { )); } - @Override - protected int getResourceFilterButtonX() { - return super.getResourceFilterButtonX() - 34; - } - @Override protected ResourceLocation getTexture() { return TEXTURE; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/InterfaceScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/InterfaceScreen.java index 985a17e60..18e4599f7 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/InterfaceScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/InterfaceScreen.java @@ -26,7 +26,6 @@ public InterfaceScreen(final InterfaceContainerMenu menu, @Override protected void init() { super.init(); - addSideButton(new RedstoneModeSideButtonWidget( getMenu().getProperty(PropertyTypes.REDSTONE_MODE), this::renderComponentTooltip @@ -37,11 +36,6 @@ protected void init() { )); } - @Override - protected boolean isResourceFilterButtonVisible() { - return false; - } - @Override protected ResourceLocation getTexture() { return TEXTURE; diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/amount/ResourceAmountScreen.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/amount/ResourceAmountScreen.java index e9d47477f..8b2b583a5 100644 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/amount/ResourceAmountScreen.java +++ b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/amount/ResourceAmountScreen.java @@ -10,7 +10,6 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.inventory.ClickType; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import org.joml.Vector3f; @@ -67,7 +66,7 @@ protected ResourceLocation getTexture() { } @Override - protected boolean tryOpenResourceFilterAmountScreen(final Slot clickedSlot, final ClickType type) { + protected boolean tryOpenResourceFilterAmountScreen(final Slot clickedSlot) { return false; } @@ -75,7 +74,7 @@ protected boolean tryOpenResourceFilterAmountScreen(final Slot clickedSlot, fina protected void renderResourceFilterSlotAmount(final PoseStack poseStack, final int x, final int y, - final FilteredResource filteredResource) { + final FilteredResource filteredResource) { // should not render amount here } diff --git a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/widget/ResourceFilterButtonWidget.java b/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/widget/ResourceFilterButtonWidget.java deleted file mode 100644 index 712ee6f93..000000000 --- a/refinedstorage2-platform-common/src/main/java/com/refinedmods/refinedstorage2/platform/common/screen/widget/ResourceFilterButtonWidget.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.common.screen.widget; - -import com.refinedmods.refinedstorage2.platform.common.containermenu.ResourceTypeAccessor; - -import net.minecraft.client.gui.components.Button; - -public class ResourceFilterButtonWidget extends Button { - public static final int WIDTH = 50; - - public ResourceFilterButtonWidget(final int x, final int y, final ResourceTypeAccessor resourceTypeAccessor) { - super( - x, - y, - WIDTH, - 15, - resourceTypeAccessor.getCurrentResourceTypeName(), - createPressAction(resourceTypeAccessor), - DEFAULT_NARRATION - ); - } - - private static OnPress createPressAction(final ResourceTypeAccessor resourceTypeAccessor) { - return btn -> { - resourceTypeAccessor.toggleResourceType(); - btn.setMessage(resourceTypeAccessor.getCurrentResourceTypeName()); - }; - } -} diff --git a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json index 0adce6eee..1406cbe6c 100644 --- a/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json +++ b/refinedstorage2-platform-common/src/main/resources/assets/refinedstorage2/lang/en_us.json @@ -121,8 +121,6 @@ "misc.refinedstorage2.last_modified.weeks": "Last modified %d weeks ago by %s", "misc.refinedstorage2.last_modified.year": "Last modified %d year ago by %s", "misc.refinedstorage2.last_modified.years": "Last modified %d years ago by %s", - "misc.refinedstorage2.resource_type.item": "Item", - "misc.refinedstorage2.resource_type.fluid": "Fluid", "misc.refinedstorage2.storage_channel_type.item": "Item", "misc.refinedstorage2.storage_channel_type.fluid": "Fluid", "key.refinedstorage2.focus_search_bar": "Focus Search Bar", diff --git a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/PlatformTestFixtures.java b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/PlatformTestFixtures.java index da3ee26ae..3b0768a78 100644 --- a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/PlatformTestFixtures.java +++ b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/PlatformTestFixtures.java @@ -2,23 +2,15 @@ import com.refinedmods.refinedstorage2.api.core.registry.OrderedRegistry; import com.refinedmods.refinedstorage2.api.core.registry.OrderedRegistryImpl; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; import com.refinedmods.refinedstorage2.platform.api.storage.type.StorageType; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.fluid.FluidResourceType; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.item.ItemResourceType; import com.refinedmods.refinedstorage2.platform.common.internal.storage.type.ItemStorageType; import net.minecraft.resources.ResourceLocation; public final class PlatformTestFixtures { - public static final OrderedRegistry RESOURCE_TYPE_REGISTRY = - new OrderedRegistryImpl<>(new ResourceLocation("item"), ItemResourceType.INSTANCE); public static final OrderedRegistry> STORAGE_TYPE_REGISTRY = new OrderedRegistryImpl<>(new ResourceLocation("item"), ItemStorageType.INSTANCE); - static { - RESOURCE_TYPE_REGISTRY.register(new ResourceLocation("fluid"), FluidResourceType.INSTANCE); - } private PlatformTestFixtures() { } diff --git a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/ResourceFilterContainerTest.java b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/ResourceFilterContainerTest.java index 8ea07508e..a00ecef07 100644 --- a/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/ResourceFilterContainerTest.java +++ b/refinedstorage2-platform-common/src/test/java/com/refinedmods/refinedstorage2/platform/common/internal/resource/filter/ResourceFilterContainerTest.java @@ -1,21 +1,11 @@ package com.refinedmods.refinedstorage2.platform.common.internal.resource.filter; -import com.refinedmods.refinedstorage2.platform.api.resource.FluidResource; import com.refinedmods.refinedstorage2.platform.api.resource.ItemResource; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; -import com.refinedmods.refinedstorage2.platform.common.PlatformTestFixtures; import com.refinedmods.refinedstorage2.platform.common.SimpleListener; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.fluid.FluidFilteredResource; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.fluid.FluidResourceType; import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.item.ItemFilteredResource; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.item.ItemResourceType; import com.refinedmods.refinedstorage2.platform.test.SetupMinecraft; -import io.netty.buffer.Unpooled; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.item.Items; -import net.minecraft.world.level.material.Fluids; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -31,7 +21,7 @@ class ResourceFilterContainerTest { @BeforeEach void setUp() { listener = new SimpleListener(); - sut = new ResourceFilterContainer(PlatformTestFixtures.RESOURCE_TYPE_REGISTRY, 3, listener, 64); + sut = new ResourceFilterContainer(3, listener, 64); } @Test @@ -44,7 +34,6 @@ void testInitialState() { assertThat(sut.size()).isEqualTo(3); assertThat(sut.getTemplates()).isEmpty(); assertThat(sut.getUniqueTemplates()).isEmpty(); - assertThat(sut.determineDefaultType()).isEqualTo(PlatformTestFixtures.RESOURCE_TYPE_REGISTRY.getDefault()); } @Test @@ -63,7 +52,6 @@ void shouldSetFilter() { assertThat(sut.size()).isEqualTo(3); assertThat(sut.getTemplates()).containsExactly(value); assertThat(sut.getUniqueTemplates()).containsExactly(value); - assertThat(sut.determineDefaultType()).isEqualTo(ItemResourceType.INSTANCE); } @ParameterizedTest @@ -84,7 +72,6 @@ void shouldChangeAmount(final long newAmount) { assertThat(sut.size()).isEqualTo(3); assertThat(sut.getTemplates()).containsExactly(value); assertThat(sut.getUniqueTemplates()).containsExactly(value); - assertThat(sut.determineDefaultType()).isEqualTo(ItemResourceType.INSTANCE); } @ParameterizedTest @@ -105,7 +92,6 @@ void shouldNotChangeAmountIfTooSmall(final long newAmount) { assertThat(sut.size()).isEqualTo(3); assertThat(sut.getTemplates()).containsExactly(value); assertThat(sut.getUniqueTemplates()).containsExactly(value); - assertThat(sut.determineDefaultType()).isEqualTo(ItemResourceType.INSTANCE); } @ParameterizedTest @@ -126,7 +112,6 @@ void shouldNotChangeAmountIfTooLargeRespectingMaxAmountInContainer(final long ne assertThat(sut.size()).isEqualTo(3); assertThat(sut.getTemplates()).containsExactly(value); assertThat(sut.getUniqueTemplates()).containsExactly(value); - assertThat(sut.determineDefaultType()).isEqualTo(ItemResourceType.INSTANCE); } @ParameterizedTest @@ -147,7 +132,6 @@ void shouldNotChangeAmountIfTooLargeRespectingMaxAmountInFilteredResource(final assertThat(sut.size()).isEqualTo(3); assertThat(sut.getTemplates()).containsExactly(value); assertThat(sut.getUniqueTemplates()).containsExactly(value); - assertThat(sut.determineDefaultType()).isEqualTo(ItemResourceType.INSTANCE); } @Test @@ -167,13 +151,12 @@ void shouldNotChangeAmountIfResourceIsNotPresent() { assertThat(sut.size()).isEqualTo(3); assertThat(sut.getTemplates()).containsExactly(value); assertThat(sut.getUniqueTemplates()).containsExactly(value); - assertThat(sut.determineDefaultType()).isEqualTo(ItemResourceType.INSTANCE); } @Test void shouldNotChangeAmountIfAmountIsUnsupported() { // Arrange - sut = new ResourceFilterContainer(PlatformTestFixtures.RESOURCE_TYPE_REGISTRY, 3, listener); + sut = new ResourceFilterContainer(3, listener); final ItemResource value = new ItemResource(Items.DIRT, null); sut.set(1, new ItemFilteredResource(value, 1)); @@ -188,7 +171,6 @@ void shouldNotChangeAmountIfAmountIsUnsupported() { assertThat(sut.size()).isEqualTo(3); assertThat(sut.getTemplates()).containsExactly(value); assertThat(sut.getUniqueTemplates()).containsExactly(value); - assertThat(sut.determineDefaultType()).isEqualTo(ItemResourceType.INSTANCE); } @Test @@ -208,7 +190,6 @@ void shouldSetDuplicatedFilter() { assertThat(sut.size()).isEqualTo(3); assertThat(sut.getTemplates()).containsExactly(value, value); assertThat(sut.getUniqueTemplates()).containsExactly(value); - assertThat(sut.determineDefaultType()).isEqualTo(ItemResourceType.INSTANCE); } @Test @@ -228,169 +209,5 @@ void shouldRemoveFilter() { assertThat(sut.size()).isEqualTo(3); assertThat(sut.getTemplates()).isEmpty(); assertThat(sut.getUniqueTemplates()).isEmpty(); - assertThat(sut.determineDefaultType()).isEqualTo(PlatformTestFixtures.RESOURCE_TYPE_REGISTRY.getDefault()); - } - - @Test - void shouldSerializeAndDeserialize() { - // Arrange - final ItemResource itemValue = new ItemResource(Items.DIRT, null); - sut.set(0, new ItemFilteredResource(itemValue, 1)); - final FluidResource fluidValue = new FluidResource(Fluids.LAVA, null); - sut.set(2, new FluidFilteredResource(fluidValue, 1)); - listener.reset(); - - // Act - final CompoundTag serialized = sut.toTag(); - final ResourceFilterContainer deserialized = - new ResourceFilterContainer(PlatformTestFixtures.RESOURCE_TYPE_REGISTRY, 3, listener); - deserialized.load(serialized); - - // Assert - assertThat(listener.isChanged()).isFalse(); - assertThat(deserialized.get(0)).usingRecursiveComparison().isEqualTo(new ItemFilteredResource(itemValue, 1)); - assertThat(deserialized.get(1)).isNull(); - assertThat(deserialized.get(2)).usingRecursiveComparison().isEqualTo(new FluidFilteredResource(fluidValue, 1)); - assertThat(deserialized.size()).isEqualTo(3); - assertThat(deserialized.getTemplates()).containsExactlyInAnyOrder(itemValue, fluidValue); - assertThat(deserialized.getUniqueTemplates()).containsExactlyInAnyOrder(itemValue, fluidValue); - assertThat(deserialized.determineDefaultType()).isEqualTo(ItemResourceType.INSTANCE); - } - - @Test - void shouldSerializeAndDeserializeWithInvalidType() { - // Arrange - final ItemResource itemValue = new ItemResource(Items.DIRT, null); - sut.set(0, new ItemFilteredResource(itemValue, 1)); - final FluidResource fluidValue = new FluidResource(Fluids.LAVA, null); - sut.set(2, new FluidFilteredResource(fluidValue, 1)); - listener.reset(); - - // Act - final CompoundTag serialized = sut.toTag(); - serialized.getCompound("s0").putString("t", "invalid"); - final ResourceFilterContainer deserialized = - new ResourceFilterContainer(PlatformTestFixtures.RESOURCE_TYPE_REGISTRY, 3, listener); - deserialized.load(serialized); - - // Assert - assertThat(listener.isChanged()).isFalse(); - assertThat(deserialized.get(0)).isNull(); - assertThat(deserialized.get(1)).isNull(); - assertThat(deserialized.get(2)).usingRecursiveComparison().isEqualTo(new FluidFilteredResource(fluidValue, 1)); - assertThat(deserialized.size()).isEqualTo(3); - assertThat(deserialized.getTemplates()).containsExactly(fluidValue); - assertThat(deserialized.getUniqueTemplates()).containsExactly(fluidValue); - assertThat(deserialized.determineDefaultType()).isEqualTo(FluidResourceType.INSTANCE); - } - - @Test - void shouldUseUniqueItemResourceTypeToDetermineDefaultType() { - // Arrange - sut.set(0, new ItemFilteredResource(new ItemResource(Items.DIRT, null), 1)); - - // Act - final ResourceType defaultType = sut.determineDefaultType(); - - // Assert - assertThat(defaultType).isEqualTo(ItemResourceType.INSTANCE); - } - - @Test - void shouldUseUniqueFluidResourceTypeToDetermineDefaultType() { - // Arrange - sut.set(0, new FluidFilteredResource(new FluidResource(Fluids.LAVA, null), 1)); - - // Act - final ResourceType defaultType = sut.determineDefaultType(); - - // Assert - assertThat(defaultType).isEqualTo(FluidResourceType.INSTANCE); - } - - @Test - void shouldUseRegistryDefaultResourceTypeWhenDeterminingDefaultTypeWithMixedResourceTypes() { - // Arrange - sut.set(0, new ItemFilteredResource(new ItemResource(Items.DIRT, null), 1)); - sut.set(1, new FluidFilteredResource(new FluidResource(Fluids.LAVA, null), 1)); - - // Act - final ResourceType defaultType = sut.determineDefaultType(); - - // Assert - assertThat(defaultType).isEqualTo(ItemResourceType.INSTANCE); - } - - @Test - void shouldSerializeAndDeserializeInNetwork() { - // Arrange - final ItemResource itemValue = new ItemResource(Items.DIRT, null); - sut.set(0, new ItemFilteredResource(itemValue, 1)); - final FluidResource fluidValue = new FluidResource(Fluids.LAVA, null); - sut.set(2, new FluidFilteredResource(fluidValue, 1)); - listener.reset(); - - final FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); - - // Act - sut.writeToUpdatePacket(0, buf); - sut.writeToUpdatePacket(1, buf); - sut.writeToUpdatePacket(2, buf); - - final ResourceFilterContainer deserialized = - new ResourceFilterContainer(PlatformTestFixtures.RESOURCE_TYPE_REGISTRY, 3, listener); - deserialized.readFromUpdatePacket(0, buf); - deserialized.readFromUpdatePacket(1, buf); - deserialized.readFromUpdatePacket(2, buf); - - // Assert - assertThat(listener.isChanged()).isFalse(); - assertThat(deserialized.get(0)).usingRecursiveComparison().isEqualTo(new ItemFilteredResource(itemValue, 1)); - assertThat(deserialized.get(1)).isNull(); - assertThat(deserialized.get(2)).usingRecursiveComparison().isEqualTo(new FluidFilteredResource(fluidValue, 1)); - assertThat(deserialized.size()).isEqualTo(3); - assertThat(deserialized.getTemplates()).containsExactlyInAnyOrder(itemValue, fluidValue); - assertThat(deserialized.getUniqueTemplates()).containsExactlyInAnyOrder(itemValue, fluidValue); - assertThat(deserialized.determineDefaultType()).isEqualTo(ItemResourceType.INSTANCE); - } - - @Test - void shouldSerializeAndDeserializeInNetworkWithInvalidType() { - // Arrange - final ItemResource itemValue = new ItemResource(Items.DIRT, null); - sut.set(0, new ItemFilteredResource(itemValue, 1)); - final FluidResource fluidValue = new FluidResource(Fluids.LAVA, null); - final FluidFilteredResource fluidFilteredResource = new FluidFilteredResource(fluidValue, 1); - sut.set(2, fluidFilteredResource); - listener.reset(); - - final FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); - - // Act - sut.writeToUpdatePacket(0, buf); - sut.writeToUpdatePacket(1, buf); - - buf.writeBoolean(true); - buf.writeUtf("invalid"); - fluidFilteredResource.writeToPacket(buf); - - final ResourceFilterContainer deserialized = new ResourceFilterContainer( - PlatformTestFixtures.RESOURCE_TYPE_REGISTRY, - 3, - listener - ); - deserialized.readFromUpdatePacket(0, buf); - deserialized.readFromUpdatePacket(1, buf); - deserialized.readFromUpdatePacket(2, buf); - - // Assert - assertThat(listener.isChanged()).isFalse(); - assertThat(deserialized.get(0)).usingRecursiveComparison().isEqualTo(new ItemFilteredResource(itemValue, 1)); - assertThat(deserialized.get(1)).isNull(); - assertThat(deserialized.get(2)).isNull(); - assertThat(deserialized.size()).isEqualTo(3); - assertThat(deserialized.getTemplates()).containsExactly(itemValue); - assertThat(deserialized.getUniqueTemplates()).containsExactly(itemValue); - assertThat(deserialized.determineDefaultType()).isEqualTo(ItemResourceType.INSTANCE); } } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ModInitializerImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ModInitializerImpl.java index afa5fc79c..546b8a23a 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ModInitializerImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/ModInitializerImpl.java @@ -78,7 +78,7 @@ import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.GridScrollPacket; import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.PropertyChangePacket; import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.ResourceFilterSlotAmountChangePacket; -import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.ResourceTypeChangePacket; +import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.ResourceFilterSlotChangePacket; import com.refinedmods.refinedstorage2.platform.fabric.packet.c2s.StorageInfoRequestPacket; import com.refinedmods.refinedstorage2.platform.fabric.util.VariantUtil; @@ -159,6 +159,7 @@ public void onInitialize() { initializePlatformApi(); registerAdditionalStorageTypes(); registerAdditionalStorageChannelTypes(); + registerAdditionalFilteredResourceFactories(); registerAdditionalGridInsertionStrategyFactories(); registerGridExtractionStrategyFactories(); registerGridScrollingStrategyFactories(); @@ -171,7 +172,6 @@ public void onInitialize() { registerPackets(); registerSounds(); registerSidedHandlers(); - registerAdditionalResourceTypes(); registerTickHandler(); registerEvents(); @@ -736,11 +736,14 @@ private void registerPackets() { ServerPlayNetworking.registerGlobalReceiver(PacketIds.GRID_EXTRACT, new GridExtractPacket()); ServerPlayNetworking.registerGlobalReceiver(PacketIds.GRID_SCROLL, new GridScrollPacket()); ServerPlayNetworking.registerGlobalReceiver(PacketIds.PROPERTY_CHANGE, new PropertyChangePacket()); - ServerPlayNetworking.registerGlobalReceiver(PacketIds.RESOURCE_TYPE_CHANGE, new ResourceTypeChangePacket()); ServerPlayNetworking.registerGlobalReceiver( PacketIds.RESOURCE_FILTER_SLOT_AMOUNT_CHANGE, new ResourceFilterSlotAmountChangePacket() ); + ServerPlayNetworking.registerGlobalReceiver( + PacketIds.RESOURCE_FILTER_SLOT_CHANGE, + new ResourceFilterSlotChangePacket() + ); } private void registerSounds() { diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/PacketIds.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/PacketIds.java index b2dcd2514..b918b017d 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/PacketIds.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/PacketIds.java @@ -15,7 +15,7 @@ public final class PacketIds { public static final ResourceLocation GRID_EXTRACT = createIdentifier("grid_extract"); public static final ResourceLocation GRID_SCROLL = createIdentifier("grid_scroll"); public static final ResourceLocation RESOURCE_FILTER_SLOT_UPDATE = createIdentifier("resource_filter_slot_update"); - public static final ResourceLocation RESOURCE_TYPE_CHANGE = createIdentifier("resource_type_change"); + public static final ResourceLocation RESOURCE_FILTER_SLOT_CHANGE = createIdentifier("resource_filter_slot_change"); public static final ResourceLocation RESOURCE_FILTER_SLOT_AMOUNT_CHANGE = createIdentifier("resource_filter_slot_amount_change"); diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ClientToServerCommunicationsImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ClientToServerCommunicationsImpl.java index f1e17db44..85ed79460 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ClientToServerCommunicationsImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ClientToServerCommunicationsImpl.java @@ -4,7 +4,6 @@ import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.common.containermenu.property.PropertyType; import com.refinedmods.refinedstorage2.platform.common.packet.ClientToServerCommunications; @@ -68,15 +67,16 @@ public void sendPropertyChange(final PropertyType type, final T value) { } @Override - public void sendResourceTypeChange(final ResourceType type) { - PlatformApi.INSTANCE.getResourceTypeRegistry() - .getId(type) - .ifPresent(id -> sendToServer(PacketIds.RESOURCE_TYPE_CHANGE, buf -> buf.writeResourceLocation(id))); + public void sendStorageInfoRequest(final UUID storageId) { + sendToServer(PacketIds.STORAGE_INFO_REQUEST, buf -> buf.writeUUID(storageId)); } @Override - public void sendStorageInfoRequest(final UUID storageId) { - sendToServer(PacketIds.STORAGE_INFO_REQUEST, buf -> buf.writeUUID(storageId)); + public void sendResourceFilterSlotChange(final int slotIndex, final boolean tryAlternatives) { + sendToServer(PacketIds.RESOURCE_FILTER_SLOT_CHANGE, buf -> { + buf.writeInt(slotIndex); + buf.writeBoolean(tryAlternatives); + }); } @Override diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ResourceTypeChangePacket.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ResourceFilterSlotChangePacket.java similarity index 72% rename from refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ResourceTypeChangePacket.java rename to refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ResourceFilterSlotChangePacket.java index 3900ba385..23d9746b4 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ResourceTypeChangePacket.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/c2s/ResourceFilterSlotChangePacket.java @@ -5,23 +5,22 @@ import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerGamePacketListenerImpl; -public class ResourceTypeChangePacket implements ServerPlayNetworking.PlayChannelHandler { +public class ResourceFilterSlotChangePacket implements ServerPlayNetworking.PlayChannelHandler { @Override public void receive(final MinecraftServer server, final ServerPlayer player, final ServerGamePacketListenerImpl handler, final FriendlyByteBuf buf, final PacketSender responseSender) { - final ResourceLocation id = buf.readResourceLocation(); - + final int slotIndex = buf.readInt(); + final boolean tryAlternatives = buf.readBoolean(); server.execute(() -> { - if (player.containerMenu instanceof AbstractResourceFilterContainerMenu resourceFilterable) { - resourceFilterable.setCurrentResourceType(id); + if (player.containerMenu instanceof AbstractResourceFilterContainerMenu resourceFilterContainerMenu) { + resourceFilterContainerMenu.handleResourceFilterSlotChange(slotIndex, tryAlternatives); } }); } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ResourceFilterSlotUpdatePacket.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ResourceFilterSlotUpdatePacket.java index 4cf35aa1d..00347075c 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ResourceFilterSlotUpdatePacket.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ResourceFilterSlotUpdatePacket.java @@ -1,12 +1,18 @@ package com.refinedmods.refinedstorage2.platform.fabric.packet.s2c; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.common.containermenu.AbstractResourceFilterContainerMenu; +import java.util.function.Consumer; + import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; public class ResourceFilterSlotUpdatePacket implements ClientPlayNetworking.PlayChannelHandler { @Override @@ -15,8 +21,34 @@ public void receive(final Minecraft client, final FriendlyByteBuf buf, final PacketSender responseSender) { final int slotIndex = buf.readInt(); - if (client.player.containerMenu instanceof AbstractResourceFilterContainerMenu containerMenu) { - containerMenu.readResourceFilterSlotUpdate(slotIndex, buf); + final boolean present = buf.readBoolean(); + if (present) { + final ResourceLocation id = buf.readResourceLocation(); + PlatformApi.INSTANCE.getStorageChannelTypeRegistry().get(id).ifPresent( + type -> handle(type, buf, client, slotIndex) + ); + } else { + handle(client, containerMenu -> containerMenu.handleResourceFilterSlotUpdate(slotIndex, null)); } } + + private void handle(final PlatformStorageChannelType type, + final FriendlyByteBuf buf, + final Minecraft client, + final int slotIndex) { + final T resource = type.fromBuffer(buf); + final long amount = buf.readLong(); + handle(client, containerMenu -> type.toFilteredResource(new ResourceAmount<>(resource, amount)).ifPresent( + filteredResource -> containerMenu.handleResourceFilterSlotUpdate(slotIndex, filteredResource) + )); + } + + private void handle(final Minecraft client, + final Consumer containerMenuConsumer) { + client.execute(() -> { + if (client.player.containerMenu instanceof AbstractResourceFilterContainerMenu containerMenu) { + containerMenuConsumer.accept(containerMenu); + } + }); + } } diff --git a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ServerToClientCommunicationsImpl.java b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ServerToClientCommunicationsImpl.java index f3339dd9b..e26b65be3 100644 --- a/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ServerToClientCommunicationsImpl.java +++ b/refinedstorage2-platform-fabric/src/main/java/com/refinedmods/refinedstorage2/platform/fabric/packet/s2c/ServerToClientCommunicationsImpl.java @@ -4,7 +4,6 @@ import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.ResourceFilterContainer; import com.refinedmods.refinedstorage2.platform.common.packet.ServerToClientCommunications; import com.refinedmods.refinedstorage2.platform.common.util.PacketUtil; import com.refinedmods.refinedstorage2.platform.fabric.packet.PacketIds; @@ -52,16 +51,33 @@ public void sendGridUpdate(final ServerPlayer player, } @Override - public void sendResourceFilterSlotUpdate(final ServerPlayer player, - final ResourceFilterContainer resourceFilterContainer, - final int slotIndex, - final int containerIndex) { + public void sendResourceFilterSlotUpdate(final ServerPlayer player, + @Nullable final PlatformStorageChannelType storageChannelType, + @Nullable final T resource, + final long amount, + final int slotIndex) { sendToPlayer(player, PacketIds.RESOURCE_FILTER_SLOT_UPDATE, buf -> { buf.writeInt(slotIndex); - resourceFilterContainer.writeToUpdatePacket(containerIndex, buf); + if (storageChannelType != null && resource != null) { + sendResourceFilterSlotUpdate(storageChannelType, resource, amount, buf); + } else { + buf.writeBoolean(false); + } }); } + private void sendResourceFilterSlotUpdate(final PlatformStorageChannelType storageChannelType, + final T resource, + final long amount, + final FriendlyByteBuf buf) { + PlatformApi.INSTANCE.getStorageChannelTypeRegistry().getId(storageChannelType).ifPresentOrElse(id -> { + buf.writeBoolean(true); + buf.writeResourceLocation(id); + storageChannelType.toBuffer(resource, buf); + buf.writeLong(amount); + }, () -> buf.writeBoolean(false)); + } + @Override public void sendStorageInfoResponse(final ServerPlayer player, final UUID id, final StorageInfo storageInfo) { sendToPlayer(player, PacketIds.STORAGE_INFO_RESPONSE, bufToSend -> { diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ModInitializer.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ModInitializer.java index d65983be1..fd42e94e0 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ModInitializer.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/ModInitializer.java @@ -168,6 +168,7 @@ public ModInitializer() { initializePlatformApi(); registerAdditionalStorageTypes(); registerAdditionalStorageChannelTypes(); + registerAdditionalFilteredResourceFactories(); registerAdditionalGridInsertionStrategyFactories(); registerGridExtractionStrategyFactories(); registerGridScrollingStrategyFactories(); @@ -177,7 +178,6 @@ public ModInitializer() { registerExternalStorageProviderFactories(); registerContent(); registerSounds(); - registerAdditionalResourceTypes(); registerTickHandler(); DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/NetworkManager.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/NetworkManager.java index 03f4244a8..1f0c1d57a 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/NetworkManager.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/NetworkManager.java @@ -5,7 +5,7 @@ import com.refinedmods.refinedstorage2.platform.forge.packet.c2s.GridScrollPacket; import com.refinedmods.refinedstorage2.platform.forge.packet.c2s.PropertyChangePacket; import com.refinedmods.refinedstorage2.platform.forge.packet.c2s.ResourceFilterSlotAmountChangePacket; -import com.refinedmods.refinedstorage2.platform.forge.packet.c2s.ResourceTypeChangePacket; +import com.refinedmods.refinedstorage2.platform.forge.packet.c2s.ResourceFilterSlotChangePacket; import com.refinedmods.refinedstorage2.platform.forge.packet.c2s.StorageInfoRequestPacket; import com.refinedmods.refinedstorage2.platform.forge.packet.s2c.ControllerEnergyInfoPacket; import com.refinedmods.refinedstorage2.platform.forge.packet.s2c.GridActivePacket; @@ -62,13 +62,6 @@ public NetworkManager() { StorageInfoResponsePacket::decode, StorageInfoResponsePacket::handle ); - handler.registerMessage( - id++, - ResourceTypeChangePacket.class, - ResourceTypeChangePacket::encode, - ResourceTypeChangePacket::decode, - ResourceTypeChangePacket::handle - ); handler.registerMessage( id++, ResourceFilterSlotUpdatePacket.class, @@ -118,6 +111,13 @@ public NetworkManager() { ResourceFilterSlotAmountChangePacket::decode, ResourceFilterSlotAmountChangePacket::handle ); + handler.registerMessage( + id++, + ResourceFilterSlotChangePacket.class, + ResourceFilterSlotChangePacket::encode, + ResourceFilterSlotChangePacket::decode, + ResourceFilterSlotChangePacket::handle + ); } public void send(final ServerPlayer player, final Object message) { diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ClientToServerCommunicationsImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ClientToServerCommunicationsImpl.java index e24fe9142..2da03f273 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ClientToServerCommunicationsImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ClientToServerCommunicationsImpl.java @@ -4,7 +4,6 @@ import com.refinedmods.refinedstorage2.api.grid.service.GridInsertMode; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.grid.GridScrollMode; -import com.refinedmods.refinedstorage2.platform.api.resource.filter.ResourceType; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.common.containermenu.property.PropertyType; import com.refinedmods.refinedstorage2.platform.common.packet.ClientToServerCommunications; @@ -62,15 +61,13 @@ public void sendPropertyChange(final PropertyType type, final T value) { } @Override - public void sendResourceTypeChange(final ResourceType type) { - PlatformApi.INSTANCE.getResourceTypeRegistry() - .getId(type) - .ifPresent(id -> networkManager.send(new ResourceTypeChangePacket(id))); + public void sendStorageInfoRequest(final UUID storageId) { + networkManager.send(new StorageInfoRequestPacket(storageId)); } @Override - public void sendStorageInfoRequest(final UUID storageId) { - networkManager.send(new StorageInfoRequestPacket(storageId)); + public void sendResourceFilterSlotChange(final int slotIndex, final boolean tryAlternatives) { + networkManager.send(new ResourceFilterSlotChangePacket(slotIndex, tryAlternatives)); } @Override diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceFilterSlotAmountChangePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceFilterSlotAmountChangePacket.java index 6f1ba01cc..cc0d04aec 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceFilterSlotAmountChangePacket.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceFilterSlotAmountChangePacket.java @@ -37,8 +37,8 @@ public static void handle(final ResourceFilterSlotAmountChangePacket packet, } private static void handle(final ResourceFilterSlotAmountChangePacket packet, final Player player) { - if (player.containerMenu instanceof AbstractResourceFilterContainerMenu resourceFilterable) { - resourceFilterable.handleResourceFilterSlotAmountChange(packet.slotIndex, packet.amount); + if (player.containerMenu instanceof AbstractResourceFilterContainerMenu containerMenu) { + containerMenu.handleResourceFilterSlotAmountChange(packet.slotIndex, packet.amount); } } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceFilterSlotChangePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceFilterSlotChangePacket.java new file mode 100644 index 000000000..1156fda54 --- /dev/null +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceFilterSlotChangePacket.java @@ -0,0 +1,44 @@ +package com.refinedmods.refinedstorage2.platform.forge.packet.c2s; + +import com.refinedmods.refinedstorage2.platform.common.containermenu.AbstractResourceFilterContainerMenu; + +import java.util.function.Supplier; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Player; +import net.minecraftforge.network.NetworkEvent; + +public class ResourceFilterSlotChangePacket { + private final int slotIndex; + private final boolean tryAlternatives; + + public ResourceFilterSlotChangePacket(final int slotIndex, final boolean tryAlternatives) { + this.slotIndex = slotIndex; + this.tryAlternatives = tryAlternatives; + } + + public static ResourceFilterSlotChangePacket decode(final FriendlyByteBuf buf) { + return new ResourceFilterSlotChangePacket(buf.readInt(), buf.readBoolean()); + } + + public static void encode(final ResourceFilterSlotChangePacket packet, final FriendlyByteBuf buf) { + buf.writeInt(packet.slotIndex); + buf.writeBoolean(packet.tryAlternatives); + } + + public static void handle(final ResourceFilterSlotChangePacket packet, + final Supplier ctx) { + final ServerPlayer player = ctx.get().getSender(); + if (player != null) { + ctx.get().enqueueWork(() -> handle(packet, player)); + } + ctx.get().setPacketHandled(true); + } + + private static void handle(final ResourceFilterSlotChangePacket packet, final Player player) { + if (player.containerMenu instanceof AbstractResourceFilterContainerMenu containerMenu) { + containerMenu.handleResourceFilterSlotChange(packet.slotIndex, packet.tryAlternatives); + } + } +} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceTypeChangePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceTypeChangePacket.java deleted file mode 100644 index c03edb2cb..000000000 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/c2s/ResourceTypeChangePacket.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.refinedmods.refinedstorage2.platform.forge.packet.c2s; - -import com.refinedmods.refinedstorage2.platform.common.containermenu.AbstractResourceFilterContainerMenu; - -import java.util.function.Supplier; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.player.Player; -import net.minecraftforge.network.NetworkEvent; - -public class ResourceTypeChangePacket { - private final ResourceLocation id; - - public ResourceTypeChangePacket(final ResourceLocation id) { - this.id = id; - } - - public static ResourceTypeChangePacket decode(final FriendlyByteBuf buf) { - return new ResourceTypeChangePacket(buf.readResourceLocation()); - } - - public static void encode(final ResourceTypeChangePacket packet, final FriendlyByteBuf buf) { - buf.writeResourceLocation(packet.id); - } - - public static void handle(final ResourceTypeChangePacket packet, final Supplier ctx) { - final ServerPlayer player = ctx.get().getSender(); - if (player != null) { - ctx.get().enqueueWork(() -> handle(packet, player)); - } - ctx.get().setPacketHandled(true); - } - - private static void handle(final ResourceTypeChangePacket packet, final Player player) { - if (player.containerMenu instanceof AbstractResourceFilterContainerMenu resourceFilterable) { - resourceFilterable.setCurrentResourceType(packet.id); - } - } -} diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/ResourceFilterSlotUpdatePacket.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/ResourceFilterSlotUpdatePacket.java index 73b1eb24b..087258239 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/ResourceFilterSlotUpdatePacket.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/ResourceFilterSlotUpdatePacket.java @@ -1,59 +1,101 @@ package com.refinedmods.refinedstorage2.platform.forge.packet.s2c; +import com.refinedmods.refinedstorage2.api.resource.ResourceAmount; +import com.refinedmods.refinedstorage2.platform.api.PlatformApi; +import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; import com.refinedmods.refinedstorage2.platform.common.containermenu.AbstractResourceFilterContainerMenu; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.ResourceFilterContainer; -import java.util.Objects; import java.util.function.Supplier; import javax.annotation.Nullable; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraftforge.network.NetworkEvent; -public class ResourceFilterSlotUpdatePacket { +public class ResourceFilterSlotUpdatePacket { private final int slotIndex; - private final int containerIndex; @Nullable - private final FriendlyByteBuf buf; + private final PlatformStorageChannelType storageChannelType; @Nullable - private final ResourceFilterContainer resourceFilterContainer; + private final ResourceLocation storageChannelTypeId; + @Nullable + private final T resource; + private final long amount; - public ResourceFilterSlotUpdatePacket(final int slotIndex, final FriendlyByteBuf buf) { + public ResourceFilterSlotUpdatePacket(final int slotIndex, + @Nullable final PlatformStorageChannelType storageChannelType, + @Nullable final ResourceLocation storageChannelTypeId, + @Nullable final T resource, + final long amount) { this.slotIndex = slotIndex; - this.containerIndex = -1; - this.buf = buf; - this.resourceFilterContainer = null; + this.storageChannelType = storageChannelType; + this.storageChannelTypeId = storageChannelTypeId; + this.resource = resource; + this.amount = amount; } - public ResourceFilterSlotUpdatePacket(final int slotIndex, - final int containerIndex, - final ResourceFilterContainer resourceFilterContainer) { - this.slotIndex = slotIndex; - this.containerIndex = containerIndex; - this.buf = null; - this.resourceFilterContainer = resourceFilterContainer; + public static ResourceFilterSlotUpdatePacket decode(final FriendlyByteBuf buf) { + final int slotIndex = buf.readInt(); + final boolean present = buf.readBoolean(); + if (!present) { + return new ResourceFilterSlotUpdatePacket<>(slotIndex, null, null, null, 0); + } + final ResourceLocation storageChannelTypeId = buf.readResourceLocation(); + return PlatformApi.INSTANCE.getStorageChannelTypeRegistry().get(storageChannelTypeId).map( + storageChannelType -> decode(buf, slotIndex, storageChannelTypeId, storageChannelType) + ).orElseGet(() -> new ResourceFilterSlotUpdatePacket<>(slotIndex, null, null, null, 0)); } - public static ResourceFilterSlotUpdatePacket decode(final FriendlyByteBuf buf) { - return new ResourceFilterSlotUpdatePacket(buf.readInt(), buf); + private static ResourceFilterSlotUpdatePacket decode(final FriendlyByteBuf buf, + final int slotIndex, + final ResourceLocation storageChannelTypeId, + final PlatformStorageChannelType type) { + final T resource = type.fromBuffer(buf); + final long amount = buf.readLong(); + return new ResourceFilterSlotUpdatePacket<>( + slotIndex, + type, + storageChannelTypeId, + resource, + amount + ); } - public static void encode(final ResourceFilterSlotUpdatePacket packet, final FriendlyByteBuf buf) { + public static void encode(final ResourceFilterSlotUpdatePacket packet, final FriendlyByteBuf buf) { buf.writeInt(packet.slotIndex); - Objects.requireNonNull(packet.resourceFilterContainer).writeToUpdatePacket(packet.containerIndex, buf); + final boolean present = packet.storageChannelType != null + && packet.storageChannelTypeId != null + && packet.resource != null; + buf.writeBoolean(present); + if (present) { + buf.writeResourceLocation(packet.storageChannelTypeId); + packet.storageChannelType.toBuffer(packet.resource, buf); + buf.writeLong(packet.amount); + } } - public static void handle(final ResourceFilterSlotUpdatePacket packet, final Supplier ctx) { + public static void handle(final ResourceFilterSlotUpdatePacket packet, + final Supplier ctx) { ClientProxy.getPlayer().ifPresent(player -> handle(player, packet)); ctx.get().setPacketHandled(true); } - private static void handle(final Player player, final ResourceFilterSlotUpdatePacket packet) { + private static void handle(final Player player, final ResourceFilterSlotUpdatePacket packet) { final AbstractContainerMenu menu = player.containerMenu; - if (menu instanceof AbstractResourceFilterContainerMenu resourceFilterable) { - resourceFilterable.readResourceFilterSlotUpdate(packet.slotIndex, Objects.requireNonNull(packet.buf)); + if (menu instanceof AbstractResourceFilterContainerMenu containerMenu) { + if (packet.storageChannelType != null && packet.resource != null) { + packet.storageChannelType.toFilteredResource(new ResourceAmount<>( + packet.resource, + packet.amount + )).ifPresent(filteredResource -> containerMenu.handleResourceFilterSlotUpdate( + packet.slotIndex, + filteredResource + )); + } else { + containerMenu.handleResourceFilterSlotUpdate(packet.slotIndex, null); + } } } } diff --git a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/ServerToClientCommunicationsImpl.java b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/ServerToClientCommunicationsImpl.java index 307c54227..a48eadf96 100644 --- a/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/ServerToClientCommunicationsImpl.java +++ b/refinedstorage2-platform-forge/src/main/java/com/refinedmods/refinedstorage2/platform/forge/packet/s2c/ServerToClientCommunicationsImpl.java @@ -4,7 +4,6 @@ import com.refinedmods.refinedstorage2.api.storage.tracked.TrackedResource; import com.refinedmods.refinedstorage2.platform.api.PlatformApi; import com.refinedmods.refinedstorage2.platform.api.storage.channel.PlatformStorageChannelType; -import com.refinedmods.refinedstorage2.platform.common.internal.resource.filter.ResourceFilterContainer; import com.refinedmods.refinedstorage2.platform.common.packet.ServerToClientCommunications; import com.refinedmods.refinedstorage2.platform.forge.packet.NetworkManager; @@ -49,14 +48,31 @@ public void sendGridUpdate(final ServerPlayer player, } @Override - public void sendResourceFilterSlotUpdate(final ServerPlayer player, - final ResourceFilterContainer resourceFilterContainer, - final int slotIndex, - final int containerIndex) { - networkManager.send( - player, - new ResourceFilterSlotUpdatePacket(slotIndex, containerIndex, resourceFilterContainer) - ); + public void sendResourceFilterSlotUpdate(final ServerPlayer player, + @Nullable final PlatformStorageChannelType storageChannelType, + @Nullable final T resource, + final long amount, + final int slotIndex) { + if (storageChannelType != null && resource != null) { + PlatformApi.INSTANCE + .getStorageChannelTypeRegistry() + .getId(storageChannelType) + .ifPresent(id -> networkManager.send(player, new ResourceFilterSlotUpdatePacket<>( + slotIndex, + storageChannelType, + id, + resource, + amount + ))); + } else { + networkManager.send(player, new ResourceFilterSlotUpdatePacket<>( + slotIndex, + null, + null, + null, + amount + )); + } } @Override