Skip to content

Commit

Permalink
wip: Continue port to Minecraft 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Oct 24, 2024
1 parent b5eefd4 commit 7c48def
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 124 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.blay09.mods.cookingforblockheads.api;

import net.blay09.mods.cookingforblockheads.crafting.RecipeWithStatus;
import net.blay09.mods.cookingforblockheads.crafting.CraftableWithStatus;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
Expand All @@ -12,7 +12,7 @@ public interface ISortButton {

Component getTooltip();

Comparator<RecipeWithStatus> getComparator(Player player);
Comparator<CraftableWithStatus> getComparator(Player player);

int getIconTextureX();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.blay09.mods.cookingforblockheads.CookingForBlockheads;
import net.blay09.mods.cookingforblockheads.api.ISortButton;
import net.blay09.mods.cookingforblockheads.crafting.RecipeWithStatus;
import net.blay09.mods.cookingforblockheads.crafting.CraftableWithStatus;
import net.blay09.mods.cookingforblockheads.menu.comparator.ComparatorHunger;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -25,7 +25,7 @@ public Component getTooltip() {
}

@Override
public Comparator<RecipeWithStatus> getComparator(Player player) {
public Comparator<CraftableWithStatus> getComparator(Player player) {
return new ComparatorHunger(player);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.blay09.mods.cookingforblockheads.CookingForBlockheads;
import net.blay09.mods.cookingforblockheads.api.ISortButton;
import net.blay09.mods.cookingforblockheads.crafting.RecipeWithStatus;
import net.blay09.mods.cookingforblockheads.crafting.CraftableWithStatus;
import net.blay09.mods.cookingforblockheads.menu.comparator.ComparatorName;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -25,8 +25,8 @@ public Component getTooltip() {
}

@Override
public Comparator<RecipeWithStatus> getComparator(Player player) {
return new ComparatorName(player);
public Comparator<CraftableWithStatus> getComparator(Player player) {
return new ComparatorName();
}

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

import net.blay09.mods.cookingforblockheads.CookingForBlockheads;
import net.blay09.mods.cookingforblockheads.api.ISortButton;
import net.blay09.mods.cookingforblockheads.crafting.RecipeWithStatus;
import net.blay09.mods.cookingforblockheads.crafting.CraftableWithStatus;
import net.blay09.mods.cookingforblockheads.menu.comparator.ComparatorSaturation;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -25,7 +25,7 @@ public Component getTooltip() {
}

@Override
public Comparator<RecipeWithStatus> getComparator(Player player) {
public Comparator<CraftableWithStatus> getComparator(Player player) {
return new ComparatorSaturation(player);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.blay09.mods.cookingforblockheads.client.gui;

import net.blay09.mods.cookingforblockheads.api.ISortButton;
import net.blay09.mods.cookingforblockheads.crafting.RecipeWithStatus;
import net.blay09.mods.cookingforblockheads.crafting.CraftableWithStatus;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.Tooltip;
Expand Down Expand Up @@ -35,7 +35,7 @@ public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float
guiGraphics.blit(RenderType::guiTextured, button.getIcon(), getX(), getY(), button.getIconTextureX(), texY, width, height, 256, 256);
}

public Comparator<RecipeWithStatus> getComparator(Player player) {
public Comparator<CraftableWithStatus> getComparator(Player player) {
return button.getComparator(player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.blay09.mods.cookingforblockheads.CookingForBlockheads;
import net.blay09.mods.cookingforblockheads.CookingForBlockheadsConfig;
import net.blay09.mods.cookingforblockheads.client.gui.SortButton;
import net.blay09.mods.cookingforblockheads.crafting.RecipeWithStatus;
import net.blay09.mods.cookingforblockheads.menu.KitchenMenu;
import net.blay09.mods.cookingforblockheads.menu.slot.CraftMatrixFakeSlot;
import net.blay09.mods.cookingforblockheads.menu.slot.CraftableListingFakeSlot;
Expand All @@ -24,7 +23,6 @@
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.display.FurnaceRecipeDisplay;
import org.lwjgl.glfw.GLFW;

Expand Down Expand Up @@ -158,7 +156,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (mouseSlot instanceof CraftMatrixFakeSlot fakeSlot) {
if (button == 0) {
ItemStack itemStack = mouseSlot.getItem();
RecipeWithStatus recipe = menu.findRecipeForResultItem(itemStack);
final var recipe = menu.findCraftableForResultItem(itemStack);
if (recipe != null) {
menu.selectCraftable(recipe);
setCurrentOffset(menu.getRecipesForSelectionIndex());
Expand Down Expand Up @@ -281,8 +279,8 @@ protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
guiGraphics.blit(RenderType::guiTextured, guiTexture, slot.x, slot.y, 176, 76, 16, 16, 256, 256);
}

final var recipe = fakeSlot.getCraftable();
if (recipe != null && recipe.isMissingUtensils()) {
final var craftable = fakeSlot.getCraftable();
if (craftable != null && craftable.missingUtensils()) {
guiGraphics.blit(RenderType::guiTextured, guiTexture, slot.x, slot.y, 176, 92, 16, 16, 256, 256);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package net.blay09.mods.cookingforblockheads.crafting;

import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

public record CraftableWithStatus(ItemStack itemStack, boolean missingIngredients, boolean missingUtensils) {
public static final StreamCodec<RegistryFriendlyByteBuf, CraftableWithStatus> STREAM_CODEC = StreamCodec.composite(
ItemStack.STREAM_CODEC,
CraftableWithStatus::itemStack,
ByteBufCodecs.BOOL,
CraftableWithStatus::missingIngredients,
ByteBufCodecs.BOOL,
CraftableWithStatus::missingUtensils,
CraftableWithStatus::new
);

public static CraftableWithStatus best(@Nullable CraftableWithStatus first, @Nullable CraftableWithStatus second) {
if (first == null) {
return second;
} else if (second == null) {
return first;
}

if (!first.missingIngredients && second.missingIngredients) {
return first;
} else if (!second.missingIngredients && first.missingIngredients) {
return second;
} else if (!first.missingUtensils && second.missingUtensils) {
return first;
} else if (!second.missingUtensils && first.missingUtensils) {
return second;
}

return first;
}
}
Loading

0 comments on commit 7c48def

Please sign in to comment.