Skip to content

Commit

Permalink
Merge pull request #649 from refinedmods/feat/GH-104/smithing-table
Browse files Browse the repository at this point in the history
feat: smithing table pattern encoding
  • Loading branch information
raoulvdberge authored Aug 7, 2024
2 parents a4bd22d + dfc2675 commit fca1612
Show file tree
Hide file tree
Showing 55 changed files with 1,744 additions and 858 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/refinedstorage.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Changed

- The Pattern now shows the crafting recipe in the tooltip.
- When a Pattern is created for a crafting recipe, the Pattern will have a different texture and name to differentiate between empty patterns.
- The Pattern Grid now has additional support for stonecutter recipes.
- The Pattern now shows the recipe in the tooltip.
- When a Pattern is created for a recipe, the Pattern will have a different texture and name to differentiate between empty patterns.
- The Pattern Grid now has additional support for encoding stonecutter and smithing table recipes.

### Fixed

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.refinedmods.refinedstorage.common.autocrafting.PatternItem;
import com.refinedmods.refinedstorage.common.autocrafting.PatternState;
import com.refinedmods.refinedstorage.common.autocrafting.ProcessingPatternState;
import com.refinedmods.refinedstorage.common.autocrafting.SmithingTablePatternState;
import com.refinedmods.refinedstorage.common.autocrafting.StonecutterPatternState;
import com.refinedmods.refinedstorage.common.configurationcard.ConfigurationCardItem;
import com.refinedmods.refinedstorage.common.configurationcard.ConfigurationCardState;
Expand Down Expand Up @@ -880,6 +881,12 @@ protected final void registerDataComponents(final RegistryCallback<DataComponent
.persistent(StonecutterPatternState.CODEC)
.networkSynchronized(StonecutterPatternState.STREAM_CODEC)
.build()));
DataComponents.INSTANCE.setSmithingTablePatternState(
callback.register(createIdentifier("smithing_table_pattern_state"),
() -> DataComponentType.<SmithingTablePatternState>builder()
.persistent(SmithingTablePatternState.CODEC)
.networkSynchronized(SmithingTablePatternState.STREAM_CODEC)
.build()));
}

protected final void registerInventorySlotReference() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.refinedmods.refinedstorage.common.autocrafting;

import com.refinedmods.refinedstorage.common.Platform;
import com.refinedmods.refinedstorage.common.support.ResourceSlotRendering;
import com.refinedmods.refinedstorage.common.support.TextureIds;
import com.refinedmods.refinedstorage.common.support.amount.AbstractAmountScreen;
import com.refinedmods.refinedstorage.common.support.amount.AmountScreenConfiguration;
Expand Down Expand Up @@ -273,7 +274,7 @@ private static int getOverflowRows(final Alternative alternative) {

@Override
protected void renderResourceSlots(final GuiGraphics graphics) {
tryRenderResourceSlot(graphics, getMenu().getAmountSlot());
ResourceSlotRendering.render(graphics, getMenu().getAmountSlot(), leftPos, topPos);
}

@Override
Expand Down Expand Up @@ -416,7 +417,7 @@ private void renderSlots(final List<AlternativeSlot> slots,
final int mouseY) {
for (final ResourceSlot resourceSlot : slots) {
if (resourceSlot.isActive()) {
tryRenderResourceSlot(graphics, resourceSlot);
ResourceSlotRendering.render(graphics, resourceSlot, leftPos, topPos);
if (isHovering(resourceSlot.x, resourceSlot.y, 16, 16, mouseX, mouseY)
&& canInteractWithResourceSlot(resourceSlot, mouseX, mouseY)) {
renderSlotHighlight(graphics, leftPos + resourceSlot.x, topPos + resourceSlot.y, 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.refinedmods.refinedstorage.common.autocrafting;

import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.common.api.autocrafting.Pattern;
import com.refinedmods.refinedstorage.common.api.support.resource.PlatformResourceKey;

import java.util.List;

record CraftingPattern(List<List<PlatformResourceKey>> inputs, ResourceAmount output, List<ResourceAmount> byproducts)
implements Pattern {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.refinedmods.refinedstorage.common.autocrafting;

import com.refinedmods.refinedstorage.common.api.RefinedStorageApi;
import com.refinedmods.refinedstorage.common.api.autocrafting.CraftingPattern;
import com.refinedmods.refinedstorage.common.api.support.resource.PlatformResourceKey;
import com.refinedmods.refinedstorage.common.support.resource.ItemResource;

Expand All @@ -23,7 +22,7 @@
import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier;
import static java.util.Objects.requireNonNullElse;

public class CraftingPatternClientTooltipComponent implements ClientTooltipComponent {
class CraftingPatternClientTooltipComponent implements ClientTooltipComponent {
private static final long CYCLE_MS = 1000;
private static final int ARROW_SPACING = 8;
private static final ResourceLocation LARGE_SLOT = createIdentifier("large_slot");
Expand All @@ -42,9 +41,7 @@ public class CraftingPatternClientTooltipComponent implements ClientTooltipCompo
private long cycleStart = 0;
private int currentCycle = 0;

public CraftingPatternClientTooltipComponent(final int width,
final int height,
final CraftingPattern craftingPattern) {
CraftingPatternClientTooltipComponent(final int width, final int height, final CraftingPattern craftingPattern) {
this.width = width;
this.height = height;
this.craftingPattern = craftingPattern;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.refinedmods.refinedstorage.common.autocrafting;

import com.refinedmods.refinedstorage.common.support.widget.CustomCheckboxWidget;

import java.util.function.Consumer;
import javax.annotation.Nullable;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;

import static com.refinedmods.refinedstorage.common.autocrafting.PatternGridScreen.INSET_PADDING;
import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier;
import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation;

class CraftingPatternGridRenderer implements PatternGridRenderer {
private static final ResourceLocation CRAFTING = createIdentifier("pattern_grid/crafting");
private static final MutableComponent FUZZY_MODE = createTranslation("gui", "pattern_grid.fuzzy_mode");
private static final MutableComponent FUZZY_MODE_ON_HELP =
createTranslation("gui", "pattern_grid.fuzzy_mode.on.help");
private static final MutableComponent FUZZY_MODE_OFF_HELP =
createTranslation("gui", "pattern_grid.fuzzy_mode.off.help");

@Nullable
private CustomCheckboxWidget fuzzyModeCheckbox;

private final PatternGridContainerMenu menu;
private final int leftPos;
private final int x;
private final int y;

CraftingPatternGridRenderer(final PatternGridContainerMenu menu, final int leftPos, final int x, final int y) {
this.menu = menu;
this.leftPos = leftPos;
this.x = x;
this.y = y;
}

@Override
public void addWidgets(final Consumer<AbstractWidget> widgets, final Consumer<AbstractWidget> renderables) {
this.fuzzyModeCheckbox = createFuzzyModeCheckbox();
renderables.accept(fuzzyModeCheckbox);
}

private CustomCheckboxWidget createFuzzyModeCheckbox() {
final CustomCheckboxWidget checkbox = new CustomCheckboxWidget(
x + INSET_PADDING,
y + INSET_PADDING + 54 + INSET_PADDING - 2,
FUZZY_MODE,
Minecraft.getInstance().font,
menu.isFuzzyMode(),
CustomCheckboxWidget.Size.SMALL
);
checkbox.setOnPressed((c, selected) -> menu.setFuzzyMode(selected));
checkbox.setTooltip(getFuzzyModeTooltip(menu.isFuzzyMode()));
checkbox.visible = isFuzzyModeCheckboxVisible();
return checkbox;
}

private static Tooltip getFuzzyModeTooltip(final boolean fuzzyMode) {
return fuzzyMode ? Tooltip.create(FUZZY_MODE_ON_HELP) : Tooltip.create(FUZZY_MODE_OFF_HELP);
}

@Override
public int getClearButtonX() {
return leftPos + 68;
}

@Override
public int getClearButtonY() {
return y + INSET_PADDING;
}

@Override
public void patternTypeChanged(final PatternType newPatternType) {
if (fuzzyModeCheckbox != null) {
fuzzyModeCheckbox.visible = isFuzzyModeCheckboxVisible();
}
}

private boolean isFuzzyModeCheckboxVisible() {
return menu.getPatternType() == PatternType.CRAFTING;
}

@Override
public void fuzzyModeChanged(final boolean newFuzzyMode) {
if (fuzzyModeCheckbox == null) {
return;
}
fuzzyModeCheckbox.setSelected(newFuzzyMode);
fuzzyModeCheckbox.setTooltip(getFuzzyModeTooltip(newFuzzyMode));
}

@Override
public void renderBackground(final GuiGraphics graphics,
final float partialTicks,
final int mouseX,
final int mouseY) {
graphics.blitSprite(CRAFTING, x + INSET_PADDING, y + INSET_PADDING, 130, 54);
}
}
Loading

0 comments on commit fca1612

Please sign in to comment.