Skip to content

Commit

Permalink
Merge pull request #688 from refinedmods/feat/GH-98/crafting-preview
Browse files Browse the repository at this point in the history
Crafting preview
  • Loading branch information
raoulvdberge authored Oct 4, 2024
2 parents 91a274f + fb0c927 commit d35175f
Show file tree
Hide file tree
Showing 68 changed files with 1,712 additions and 101 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Resources in the Grid that are autocraftable now display an orange backdrop and tooltip to indicate whether the resource is autocraftable at a glance.
- Slots used in the Pattern Grid for pattern encoding and Crafting Grid crafting matrix slots now display an orange backdrop and tooltip to indicate whether the item is autocraftable at a glance. This checks patterns from your network and from your inventory.
- Added help tooltip for filtering based on recipe items in the Crafting Grid.
- The crafting amount and crafting preview screens have been merged. Changing the amount will update the live preview.
- The numbers on the crafting preview screen are now compacted with units.
- When requesting autocrafting multiple resources at once, which can happen via a recipe mod, all the crafting requests are now listed on the side of the GUI.
- You can now request autocrafting from the Storage Monitor if the resource count reaches zero.

### Fixed

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.refinedmods.refinedstorage.api.autocrafting;

import java.util.List;

public record AutocraftingPreview(AutocraftingPreviewType type, List<AutocraftingPreviewItem> items) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.refinedmods.refinedstorage.api.autocrafting;

import com.refinedmods.refinedstorage.api.resource.ResourceKey;

public record AutocraftingPreviewItem(ResourceKey resource, long available, long missing, long toCraft) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.refinedmods.refinedstorage.api.autocrafting;

import com.refinedmods.refinedstorage.api.resource.ResourceKey;

import java.util.Optional;

public interface AutocraftingPreviewProvider {
Optional<AutocraftingPreview> getPreview(ResourceKey resource, long amount);

boolean start(ResourceKey resource, long amount);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.refinedmods.refinedstorage.api.autocrafting;

public enum AutocraftingPreviewType {
SUCCESS,
MISSING_RESOURCES
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.refinedmods.refinedstorage.api.network.energy.EnergyStorage;
import com.refinedmods.refinedstorage.api.network.node.NetworkNode;
import com.refinedmods.refinedstorage.api.network.security.SecurityPolicy;
import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.api.resource.ResourceKey;
import com.refinedmods.refinedstorage.common.api.constructordestructor.ConstructorStrategyFactory;
import com.refinedmods.refinedstorage.common.api.constructordestructor.DestructorStrategyFactory;
Expand Down Expand Up @@ -46,6 +47,7 @@
import com.refinedmods.refinedstorage.common.api.wirelesstransmitter.WirelessTransmitterRangeModifier;

import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -203,4 +205,6 @@ EnergyStorage asBlockItemEnergyStorage(
boolean canPlaceNetworkNode(ServerPlayer player, Level level, BlockPos pos, BlockState state);

Optional<Pattern> getPattern(ItemStack stack, Level level);

void openCraftingPreview(List<ResourceAmount> requests);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.refinedmods.refinedstorage.api.network.energy.EnergyStorage;
import com.refinedmods.refinedstorage.api.network.node.NetworkNode;
import com.refinedmods.refinedstorage.api.network.security.SecurityPolicy;
import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.api.resource.ResourceKey;
import com.refinedmods.refinedstorage.common.api.constructordestructor.ConstructorStrategyFactory;
import com.refinedmods.refinedstorage.common.api.constructordestructor.DestructorStrategyFactory;
Expand Down Expand Up @@ -46,6 +47,7 @@
import com.refinedmods.refinedstorage.common.api.wirelesstransmitter.WirelessTransmitterRangeModifier;

import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -401,6 +403,11 @@ public Optional<Pattern> getPattern(final ItemStack stack, final Level level) {
return ensureLoaded().getPattern(stack, level);
}

@Override
public void openCraftingPreview(final List<ResourceAmount> requests) {
ensureLoaded().openCraftingPreview(requests);
}

private RefinedStorageApi ensureLoaded() {
if (delegate == null) {
throw new IllegalStateException("API not loaded yet");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.refinedmods.refinedstorage.common.api.grid;

import com.refinedmods.refinedstorage.api.autocrafting.AutocraftingPreviewProvider;
import com.refinedmods.refinedstorage.api.grid.operations.GridOperations;
import com.refinedmods.refinedstorage.api.grid.watcher.GridWatcher;
import com.refinedmods.refinedstorage.api.storage.Actor;
Expand All @@ -15,7 +16,7 @@
import org.apiguardian.api.API;

@API(status = API.Status.STABLE, since = "2.0.0-milestone.3.0")
public interface Grid {
public interface Grid extends AutocraftingPreviewProvider {
void addWatcher(GridWatcher watcher, Class<? extends Actor> actorType);

void removeWatcher(GridWatcher watcher);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.refinedmods.refinedstorage.api.grid.operations.GridExtractMode;
import com.refinedmods.refinedstorage.api.grid.view.GridResource;
import com.refinedmods.refinedstorage.api.grid.view.GridView;
import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.common.api.grid.GridScrollMode;
import com.refinedmods.refinedstorage.common.api.grid.strategy.GridExtractionStrategy;
import com.refinedmods.refinedstorage.common.api.grid.strategy.GridScrollingStrategy;
Expand Down Expand Up @@ -47,6 +48,9 @@ void onScroll(GridScrollMode scrollMode,

List<ClientTooltipComponent> getExtractionHints(ItemStack carriedStack, GridView view);

@Nullable
ResourceAmount getAutocraftingRequest();

@Nullable
@API(status = API.Status.INTERNAL)
PlatformResourceKey getResourceForRecipeMods();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.refinedmods.refinedstorage.common.api.upgrade.UpgradeMapping;
import com.refinedmods.refinedstorage.common.autocrafting.CrafterScreen;
import com.refinedmods.refinedstorage.common.autocrafting.PatternGridScreen;
import com.refinedmods.refinedstorage.common.autocrafting.preview.AutocraftingPreviewContainerMenu;
import com.refinedmods.refinedstorage.common.autocrafting.preview.AutocraftingPreviewScreen;
import com.refinedmods.refinedstorage.common.constructordestructor.ConstructorScreen;
import com.refinedmods.refinedstorage.common.constructordestructor.DestructorScreen;
import com.refinedmods.refinedstorage.common.content.Items;
Expand Down Expand Up @@ -93,6 +95,15 @@ protected static void registerScreens(final ScreenRegistration registration) {
registration.register(Menus.INSTANCE.getRelay(), RelayScreen::new);
registration.register(Menus.INSTANCE.getDiskInterface(), DiskInterfaceScreen::new);
registration.register(Menus.INSTANCE.getCrafter(), CrafterScreen::new);
registration.register(Menus.INSTANCE.getAutocraftingStorageMonitor(),
new ScreenConstructor<AutocraftingPreviewContainerMenu, AutocraftingPreviewScreen>() {
@Override
public AutocraftingPreviewScreen create(final AutocraftingPreviewContainerMenu menu,
final Inventory inventory,
final Component title) {
return new AutocraftingPreviewScreen(menu, inventory, title);
}
});
}

protected static void registerAlternativeGridHints() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
import com.refinedmods.refinedstorage.common.storage.storageblock.StorageBlockLootItemFunction;
import com.refinedmods.refinedstorage.common.storage.storagedisk.FluidStorageDiskItem;
import com.refinedmods.refinedstorage.common.storage.storagedisk.ItemStorageDiskItem;
import com.refinedmods.refinedstorage.common.storagemonitor.AutocraftingStorageMonitorContainerMenu;
import com.refinedmods.refinedstorage.common.storagemonitor.FluidStorageMonitorExtractionStrategy;
import com.refinedmods.refinedstorage.common.storagemonitor.FluidStorageMonitorInsertionStrategy;
import com.refinedmods.refinedstorage.common.storagemonitor.ItemStorageMonitorExtractionStrategy;
Expand All @@ -136,6 +137,7 @@
import com.refinedmods.refinedstorage.common.support.network.component.PlatformStorageNetworkComponent;
import com.refinedmods.refinedstorage.common.support.resource.FluidResourceContainerInsertStrategy;
import com.refinedmods.refinedstorage.common.support.resource.FluidResourceFactory;
import com.refinedmods.refinedstorage.common.support.resource.ResourceCodecs;
import com.refinedmods.refinedstorage.common.support.resource.ResourceContainerData;
import com.refinedmods.refinedstorage.common.support.resource.ResourceTypes;
import com.refinedmods.refinedstorage.common.support.slotreference.InventorySlotReferenceFactory;
Expand Down Expand Up @@ -745,6 +747,13 @@ protected final void registerMenus(final RegistryCallback<MenuType<?>> callback,
ContentIds.STORAGE_MONITOR,
() -> extendedMenuTypeFactory.create(StorageMonitorContainerMenu::new, ResourceContainerData.STREAM_CODEC)
));
Menus.INSTANCE.setAutocraftingStorageMonitor(callback.register(
createIdentifier("autocrafting_storage_monitor"),
() -> extendedMenuTypeFactory.create(
(syncId, playerInventory, data) -> new AutocraftingStorageMonitorContainerMenu(syncId, data),
ResourceCodecs.STREAM_CODEC
)
));
Menus.INSTANCE.setNetworkTransmitter(callback.register(
ContentIds.NETWORK_TRANSMITTER,
() -> extendedMenuTypeFactory.create(NetworkTransmitterContainerMenu::new,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.refinedmods.refinedstorage.api.network.impl.NetworkFactory;
import com.refinedmods.refinedstorage.api.network.node.NetworkNode;
import com.refinedmods.refinedstorage.api.network.security.SecurityPolicy;
import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.api.resource.ResourceKey;
import com.refinedmods.refinedstorage.common.api.RefinedStorageApi;
import com.refinedmods.refinedstorage.common.api.autocrafting.PatternProviderItem;
Expand Down Expand Up @@ -49,6 +50,8 @@
import com.refinedmods.refinedstorage.common.api.support.slotreference.SlotReferenceProvider;
import com.refinedmods.refinedstorage.common.api.upgrade.UpgradeRegistry;
import com.refinedmods.refinedstorage.common.api.wirelesstransmitter.WirelessTransmitterRangeModifier;
import com.refinedmods.refinedstorage.common.autocrafting.preview.AutocraftingPreviewScreen;
import com.refinedmods.refinedstorage.common.autocrafting.preview.AutocraftingRequest;
import com.refinedmods.refinedstorage.common.grid.NoopGridSynchronizer;
import com.refinedmods.refinedstorage.common.grid.screen.hint.GridInsertionHintsImpl;
import com.refinedmods.refinedstorage.common.grid.screen.hint.ItemGridInsertionHint;
Expand Down Expand Up @@ -99,12 +102,14 @@
import java.util.stream.Collectors;
import javax.annotation.Nullable;

import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -595,4 +600,21 @@ public Optional<Pattern> getPattern(final ItemStack stack, final Level level) {
i -> providerItem.getPattern(stack, level).orElse(null)
));
}

@Override
public void openCraftingPreview(final List<ResourceAmount> requests) {
if (requests.isEmpty()) {
return;
}
final Minecraft minecraft = Minecraft.getInstance();
if (minecraft.screen == null || minecraft.player == null) {
return;
}
final Inventory inventory = minecraft.player.getInventory();
minecraft.setScreen(new AutocraftingPreviewScreen(
minecraft.screen,
inventory,
requests.stream().map(AutocraftingRequest::of).toList()
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import static com.refinedmods.refinedstorage.common.autocrafting.AlternativesScreen.ALTERNATIVE_ROW_HEIGHT;
import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.getTagTranslationKey;

public class AlternativeContainerMenu extends AbstractResourceContainerMenu {
class AlternativeContainerMenu extends AbstractResourceContainerMenu {
private final List<Alternative> alternatives;
private final ResourceSlot amountSlot;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ protected ResourceLocation getTexture() {
}

@Override
protected void accept(final Double amount) {
protected boolean confirm(final Double amount) {
slot.changeAmountOnClient(amount);
final Set<Alternative> allowedAlternatives = new HashSet<>();
for (int i = 0; i < alternativeCheckboxes.size(); ++i) {
Expand All @@ -502,6 +502,7 @@ protected void accept(final Double amount) {
}
}
getMenu().sendAllowedAlternatives(allowedAlternatives);
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import static com.refinedmods.refinedstorage.common.support.AbstractDirectionalBlock.tryExtractDirection;

// TODO: More energy usage for more patterns.
public class CrafterBlockEntity extends AbstractBaseNetworkNodeContainerBlockEntity<PatternProviderNetworkNode>
implements ExtendedMenuProvider<CrafterData>, BlockEntityWithDrops, PatternInventory.Listener {
static final int PATTERNS = 9;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static com.refinedmods.refinedstorage.common.support.Sprites.LIGHT_ARROW_WIDTH;
import static com.refinedmods.refinedstorage.common.support.Sprites.SLOT;
import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier;
import static java.util.Objects.requireNonNullElse;

class CraftingPatternClientTooltipComponent implements ClientTooltipComponent {
private static final long CYCLE_MS = 1000;
Expand Down Expand Up @@ -78,7 +77,7 @@ public void renderImage(final Font font, final int x, final int y, final GuiGrap
cycleStart = now;
}
if (outputText != null) {
graphics.drawString(font, outputText, x, y, requireNonNullElse(ChatFormatting.GRAY.getColor(), 15));
graphics.drawString(font, outputText, x, y, 0xAAAAAA);
}
renderInputSlots(x, y + 9 + 2, graphics);
renderArrow(x, y + 9 + 2, graphics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static com.refinedmods.refinedstorage.common.support.Sprites.LIGHT_ARROW_HEIGHT;
import static com.refinedmods.refinedstorage.common.support.Sprites.LIGHT_ARROW_WIDTH;
import static com.refinedmods.refinedstorage.common.support.Sprites.SLOT;
import static java.util.Objects.requireNonNullElse;

class ProcessingPatternClientTooltipComponent implements ClientTooltipComponent {
private static final long CYCLE_MS = 1000;
Expand Down Expand Up @@ -162,7 +161,7 @@ private void renderOutputText(final Font font, final int x, final int y, final G
outputTexts.get(i),
x,
y + (i * 9),
requireNonNullElse(ChatFormatting.GRAY.getColor(), 15)
0xAAAAAA
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import static com.refinedmods.refinedstorage.common.support.Sprites.LIGHT_ARROW;
import static com.refinedmods.refinedstorage.common.support.Sprites.LIGHT_ARROW_HEIGHT;
import static com.refinedmods.refinedstorage.common.support.Sprites.LIGHT_ARROW_WIDTH;
import static java.util.Objects.requireNonNullElse;

class SmithingTablePatternClientTooltipComponent implements ClientTooltipComponent {
private static final int ARROW_SPACING = 8;
Expand All @@ -29,7 +28,7 @@ class SmithingTablePatternClientTooltipComponent implements ClientTooltipCompone

@Override
public void renderImage(final Font font, final int x, final int y, final GuiGraphics graphics) {
graphics.drawString(font, outputText, x, y, requireNonNullElse(ChatFormatting.GRAY.getColor(), 15));
graphics.drawString(font, outputText, x, y, 0xAAAAAA);
final int slotsY = y + 9 + 2;
graphics.blitSprite(Sprites.SLOT, x, slotsY, 18, 18);
final ResourceRendering rendering = RefinedStorageApi.INSTANCE.getResourceRendering(ItemResource.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import static com.refinedmods.refinedstorage.common.support.Sprites.LIGHT_ARROW_HEIGHT;
import static com.refinedmods.refinedstorage.common.support.Sprites.LIGHT_ARROW_WIDTH;
import static com.refinedmods.refinedstorage.common.support.Sprites.SLOT;
import static java.util.Objects.requireNonNullElse;

class StonecutterPatternClientTooltipComponent implements ClientTooltipComponent {
private static final int ARROW_SPACING = 8;
Expand All @@ -32,7 +31,7 @@ class StonecutterPatternClientTooltipComponent implements ClientTooltipComponent

@Override
public void renderImage(final Font font, final int x, final int y, final GuiGraphics graphics) {
graphics.drawString(font, outputText, x, y, requireNonNullElse(ChatFormatting.GRAY.getColor(), 15));
graphics.drawString(font, outputText, x, y, 0xAAAAAA);
graphics.blitSprite(SLOT, x, y + 9 + 2, 18, 18);
final ResourceRendering rendering = RefinedStorageApi.INSTANCE.getResourceRendering(ItemResource.class);
rendering.render(input, graphics, x + 1, y + 9 + 2 + 1);
Expand Down
Loading

0 comments on commit d35175f

Please sign in to comment.