Skip to content

Commit

Permalink
feat: the pattern output is now always rendered in the result slot
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed Aug 8, 2024
1 parent 2e39bd6 commit 1deb3ae
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- 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.
- The Pattern output is now always rendered in the Pattern Grid result slot.

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.ResultContainer;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SmithingTemplateItem;
Expand Down Expand Up @@ -58,6 +59,8 @@ public class PatternGridContainerMenu extends AbstractGridContainerMenu {
private PatternGridListener listener;
@Nullable
private PatternGridBlockEntity patternGrid;
@Nullable
private Slot patternOutputSlot;

public PatternGridContainerMenu(final int syncId,
final Inventory playerInventory,
Expand Down Expand Up @@ -198,7 +201,7 @@ private void addPatternSlots(final int playerInventoryY) {
playerInventoryY - Y_OFFSET_BETWEEN_PLAYER_INVENTORY_AND_PATTERN_INPUT_SLOT,
PatternGridBlockEntity::isValidPattern
));
addSlot(new ValidatedSlot(
patternOutputSlot = addSlot(new ValidatedSlot(
patternOutput,
0,
152,
Expand All @@ -224,6 +227,11 @@ public void set(final ItemStack stack) {
transferManager.addTransfer(patternOutput, playerInventory);
}

@Nullable
Slot getPatternOutputSlot() {
return patternOutputSlot;
}

private void addCraftingMatrixSlots(final int playerInventoryY) {
for (int y = 0; y < 3; ++y) {
for (int x = 0; x < 3; ++x) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.util.Optional;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
Expand All @@ -16,7 +17,18 @@ private PatternRendering() {
}

public static boolean canDisplayOutput(final ItemStack stack) {
return stack.getItem() instanceof PatternProviderItem && Screen.hasShiftDown();
if (!(stack.getItem() instanceof PatternProviderItem)) {
return false;
}
if (Screen.hasShiftDown()) {
return true;
}
final Screen screen = Minecraft.getInstance().screen;
if (screen instanceof PatternGridScreen patternGridScreen) {
return patternGridScreen.getMenu().getPatternOutputSlot() != null
&& patternGridScreen.getMenu().getPatternOutputSlot().getItem() == stack;
}
return false;
}

public static Optional<ItemStack> getOutput(final ItemStack stack) {
Expand Down

0 comments on commit 1deb3ae

Please sign in to comment.