Skip to content

Commit

Permalink
Merge pull request #308 from refinedmods/feature/GH-243/insert-contai…
Browse files Browse the repository at this point in the history
…ned-resource

Remove resource type mode in device GUIs
  • Loading branch information
raoulvdberge authored Jan 31, 2023
2 parents b25d28a + 05b9ec7 commit f5f24d7
Show file tree
Hide file tree
Showing 70 changed files with 705 additions and 1,106 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,8 +61,6 @@ <T> Set<PlatformExternalStorageProviderFactory> getExternalStorageProviderFactor

MutableComponent createTranslation(String category, String value, Object... args);

OrderedRegistry<ResourceLocation, ResourceType> getResourceTypeRegistry();

ComponentMapFactory<NetworkComponent, Network> getNetworkComponentMapFactory();

OrderedRegistry<ResourceLocation, GridSynchronizer> getGridSynchronizerRegistry();
Expand Down Expand Up @@ -93,4 +91,8 @@ GridScrollingStrategy createGridScrollingStrategy(AbstractContainerMenu containe
GridServiceFactory gridServiceFactory);

void addGridScrollingStrategyFactory(GridScrollingStrategyFactory scrollingStrategyFactory);

void addFilteredResourceFactory(FilteredResourceFactory factory);

FilteredResourceFactory getFilteredResourceFactory();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -95,11 +95,6 @@ public MutableComponent createTranslation(final String category, final String va
return ensureLoaded().createTranslation(category, value, args);
}

@Override
public OrderedRegistry<ResourceLocation, ResourceType> getResourceTypeRegistry() {
return ensureLoaded().getResourceTypeRegistry();
}

@Override
public ComponentMapFactory<NetworkComponent, Network> getNetworkComponentMapFactory() {
return ensureLoaded().getNetworkComponentMapFactory();
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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<T> {
void render(PoseStack poseStack, int x, int y, int z);

Object getValue();
T getValue();

long getAmount();
FilteredResource<T> withAmount(long newAmount);

FilteredResource withAmount(long newAmount);
long getAmount();

long getMaxAmount();

String getFormattedAmount();
String getDisplayedAmount();

ResourceType getType();
List<Component> getTooltip();

List<Component> getTooltipLines(@Nullable Player player);
PlatformStorageChannelType<T> getStorageChannelType();
}
Original file line number Diff line number Diff line change
@@ -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<FilteredResource<?>> create(ItemStack stack, boolean tryAlternatives);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -20,13 +20,22 @@ public abstract class AbstractPlatformStorageChannelType<T> implements PlatformS
private final String name;
private final StorageChannelType<T> delegate;
private final MutableComponent title;
private final ResourceLocation textureIdentifier;
private final int textureX;
private final int textureY;

protected AbstractPlatformStorageChannelType(final String name,
final StorageChannelType<T> 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
Expand All @@ -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<T, TrackedResource> acceptor) {
fromTag(tag).ifPresent(resource -> {
Expand All @@ -48,8 +55,6 @@ public void fromTag(final CompoundTag tag, final BiConsumer<T, TrackedResource>
});
}

protected abstract Optional<T> fromTag(CompoundTag tag);

@Override
public StorageChannel<T> create() {
return delegate.create();
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,16 +17,22 @@

@API(status = API.Status.STABLE, since = "2.0.0-milestone.2.5")
public interface PlatformStorageChannelType<T> extends StorageChannelType<T> {
CompoundTag toTag(T resource);

CompoundTag toTag(T resource, TrackedResource trackedResource);

void fromTag(CompoundTag tag, BiConsumer<T, TrackedResource> acceptor);

Optional<T> fromTag(CompoundTag tag);

void toBuffer(T resource, FriendlyByteBuf buf);

T fromBuffer(FriendlyByteBuf buf);

Optional<GridResource> toGridResource(ResourceAmount<?> resourceAmount);

Optional<FilteredResource<T>> toFilteredResource(ResourceAmount<?> resourceAmount);

boolean isGridResourceBelonging(GridResource gridResource);

MutableComponent getTitle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,6 +43,10 @@ protected void registerAdditionalStorageChannelTypes() {
);
}

protected void registerAdditionalFilteredResourceFactories() {
PlatformApi.INSTANCE.addFilteredResourceFactory(new FluidFilteredResourceFactory());
}

protected void registerNetworkComponents() {
PlatformApi.INSTANCE.getNetworkComponentMapFactory().addFactory(
EnergyNetworkComponent.class,
Expand All @@ -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<Item> speedUpgrade,
final Supplier<Item> stackUpgrade) {
PlatformApi.INSTANCE.getUpgradeRegistry().addApplicableUpgrade(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -72,8 +73,6 @@ public class PlatformApiImpl implements PlatformApi {

private final StorageRepository clientStorageRepository =
new ClientStorageRepository(Platform.INSTANCE.getClientToServerCommunications()::sendStorageInfoRequest);
private final OrderedRegistry<ResourceLocation, ResourceType> resourceTypeRegistry =
new OrderedRegistryImpl<>(createIdentifier(ITEM_REGISTRY_KEY), ItemResourceType.INSTANCE);
private final ComponentMapFactory<NetworkComponent, Network> networkComponentMapFactory =
new ComponentMapFactory<>();
private final NetworkBuilder networkBuilder =
Expand All @@ -97,6 +96,9 @@ public class PlatformApiImpl implements PlatformApi {
private final List<GridInsertionStrategyFactory> gridInsertionStrategyFactories = new ArrayList<>();
private final List<GridExtractionStrategyFactory> gridExtractionStrategyFactories = new ArrayList<>();
private final List<GridScrollingStrategyFactory> gridScrollingStrategyFactories = new ArrayList<>();
private final CompositeFilteredResourceFactory filteredResourceFactory = new CompositeFilteredResourceFactory(
new ItemFilteredResourceFactory()
);

@Override
public OrderedRegistry<ResourceLocation, StorageType<?>> getStorageTypeRegistry() {
Expand Down Expand Up @@ -173,11 +175,6 @@ public MutableComponent createTranslation(final String category, final String va
return IdentifierUtil.createTranslation(category, value, args);
}

@Override
public OrderedRegistry<ResourceLocation, ResourceType> getResourceTypeRegistry() {
return resourceTypeRegistry;
}

@Override
public ComponentMapFactory<NetworkComponent, Network> getNetworkComponentMapFactory() {
return networkComponentMapFactory;
Expand Down Expand Up @@ -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;
}
}
Loading

0 comments on commit f5f24d7

Please sign in to comment.