Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void showGhostRecipe(RecipeEntry<?> recipe, List<Slot> slots) {
this.ghostSlots.addSlot(brewingRecipe.inputIngredient(items), firstInputSlot.x, firstInputSlot.y);

Slot ingredientSlot = this.craftingScreenHandler.getSlot(BrewingStandMenuDelegate.INGREDIENT_SLOT);
this.ghostSlots.addSlot(brewingRecipe.additionIngredient(), ingredientSlot.x, ingredientSlot.y);
this.ghostSlots.addSlot(brewingRecipe.reagent(), ingredientSlot.x, ingredientSlot.y);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.errorcraft.itematic.mixin.client.gui.screen.ingame;

import net.errorcraft.itematic.access.screen.BrewingStandScreenHandlerAccess;
import net.errorcraft.itematic.screen.BrewingStandMenuDelegate;
import net.minecraft.client.gui.screen.ingame.BrewingStandScreen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
Expand All @@ -8,6 +9,8 @@
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(BrewingStandScreen.class)
Expand All @@ -24,4 +27,14 @@ public BrewingStandScreenExtender(BrewingStandMenuDelegate handler, PlayerInvent
private int useDirectXPosition(int original) {
return this.x;
}

@ModifyConstant(
method = "drawBackground",
constant = @Constant(
floatValue = 400.0f
)
)
private float useRecipeForBrewingTime(float original) {
return ((BrewingStandScreenHandlerAccess) this.handler).itematic$maxBrewingTime();
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,111 @@
package net.errorcraft.itematic.mixin.client.gui.screen.recipebook;

import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import net.errorcraft.itematic.access.recipe.RecipeAccess;
import net.errorcraft.itematic.recipe.brewing.BrewingRecipe;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.recipebook.RecipeAlternativesWidget;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeEntry;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Iterator;
import java.util.List;

@Mixin(RecipeAlternativesWidget.class)
public interface RecipeAlternativesWidgetAccessor {
@Accessor("client")
MinecraftClient itematic$client();

@Mixin(targets = "net.minecraft.client.gui.screen.recipebook.RecipeAlternativesWidget$AlternativeButtonWidget")
class AlternativeButtonWidgetExtender {
@Mixin(RecipeAlternativesWidget.AlternativeButtonWidget.class)
abstract class AlternativeButtonWidgetExtender extends ClickableWidget {
@Shadow
@Final
RecipeAlternativesWidget field_3113;

@Shadow
@Final
private boolean craftable;

@Shadow
@Final
protected List<RecipeAlternativesWidget.AlternativeButtonWidget.InputSlot> slots;

@Unique
private static final Identifier BREWING_TEXTURE_ENABLED = Identifier.ofVanilla("recipe_book/brewing_stand_overlay");
@Unique
private static final Identifier BREWING_TEXTURE_ENABLED_HIGHLIGHTED = Identifier.ofVanilla("recipe_book/brewing_stand_overlay_highlighted");
@Unique
private static final Identifier BREWING_TEXTURE_DISABLED = Identifier.ofVanilla("recipe_book/brewing_stand_overlay_disabled");
@Unique
private static final Identifier BREWING_TEXTURE_DISABLED_HIGHLIGHTED = Identifier.ofVanilla("recipe_book/brewing_stand_overlay_disabled_highlighted");

@Unique
private boolean isBrewingRecipe;

public AlternativeButtonWidgetExtender(int x, int y, int width, int height, Text message) {
super(x, y, width, height, message);
}

@Inject(
method = "<init>",
at = @At("TAIL")
)
private void setBrewingRecipe(RecipeAlternativesWidget parent, int x, int y, RecipeEntry<?> recipe, boolean craftable, CallbackInfo info) {
this.isBrewingRecipe = recipe.value() instanceof BrewingRecipe<?>;
}

@WrapWithCondition(
method = "alignRecipe",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/screen/recipebook/RecipeAlternativesWidget$AlternativeButtonWidget;alignRecipeToGrid(IIILnet/minecraft/recipe/RecipeEntry;Ljava/util/Iterator;I)V"
)
)
private <T> boolean checkBrewingRecipe(RecipeAlternativesWidget.AlternativeButtonWidget instance, int gridWidth, int gridHeight, int gridOutputSlot, RecipeEntry<?> recipe, Iterator<T> inputs, int amount) {
if (!(recipe.value() instanceof BrewingRecipe<?> brewingRecipe)) {
return true;
}

ClientWorld world = ((RecipeAlternativesWidgetAccessor) this.field_3113).itematic$client().world;
if (world == null) {
return false;
}

DynamicRegistryManager registries = world.getRegistryManager();
ItemStack[] bases = brewingRecipe.inputIngredient(registries.getWrapperOrThrow(RegistryKeys.ITEM))
.itematic$getMatchingStacks(registries);
if (bases.length > 0) {
this.slots.add(InputSlotAccessor.create(instance, 3, 17, bases));
}

ItemStack[] reagents = brewingRecipe.reagent().itematic$getMatchingStacks(registries);
if (reagents.length > 0) {
this.slots.add(InputSlotAccessor.create(instance, 10, 3, reagents));
}

return false;
}

@Redirect(
method = "alignRecipe",
at = @At(
Expand Down Expand Up @@ -58,6 +137,33 @@ private ItemStack[] getMatchingStacksUseDynamicRegistry(Ingredient instance) {

return instance.itematic$getMatchingStacks(world.getRegistryManager());
}

@ModifyArg(
method = "renderWidget",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Lnet/minecraft/util/Identifier;IIII)V"
)
)
private Identifier getBrewingStandOverlayTexture(Identifier texture) {
if (!this.isBrewingRecipe) {
return texture;
}

if (this.craftable) {
return this.isSelected() ? BREWING_TEXTURE_ENABLED_HIGHLIGHTED : BREWING_TEXTURE_ENABLED;
}

return this.isSelected() ? BREWING_TEXTURE_DISABLED_HIGHLIGHTED : BREWING_TEXTURE_DISABLED;
}

@Mixin(RecipeAlternativesWidget.AlternativeButtonWidget.InputSlot.class)
interface InputSlotAccessor {
@Invoker("<init>")
static RecipeAlternativesWidget.AlternativeButtonWidget.InputSlot create(RecipeAlternativesWidget.AlternativeButtonWidget widget, final int y, final int x, final ItemStack[] stacks) {
throw new AssertionError();
}
}
}

@Mixin(targets = "net.minecraft.client.gui.screen.recipebook.RecipeAlternativesWidget$FurnaceAlternativeButtonWidget")
Expand Down
1 change: 1 addition & 0 deletions src/client/resources/itematic.client.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"gui.screen.recipebook.AbstractFurnaceRecipeBookScreenExtender",
"gui.screen.recipebook.RecipeAlternativesWidgetAccessor",
"gui.screen.recipebook.RecipeAlternativesWidgetAccessor$AlternativeButtonWidgetExtender",
"gui.screen.recipebook.RecipeAlternativesWidgetAccessor$AlternativeButtonWidgetExtender$InputSlotAccessor",
"gui.screen.recipebook.RecipeAlternativesWidgetAccessor$FurnaceAlternativeButtonWidgetExtender",
"gui.screen.recipebook.RecipeBookGhostSlotsExtender$GhostInputSlotExtender",
"gui.screen.recipebook.RecipeBookWidgetExtender",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void generate() {
.save(this.exporter);
this.modify(PotionKeys.WATER, ItemKeys.GLOWSTONE_DUST, PotionKeys.THICK)
.save(this.exporter);
this.modify(PotionKeys.WATER, ItematicItemTags.MUNDANE_POTION_ADDITIONS, PotionKeys.MUNDANE)
this.modify(PotionKeys.WATER, ItematicItemTags.MUNDANE_POTION_REAGENTS, PotionKeys.MUNDANE)
.save(this.exporter);
this.modify(PotionKeys.WATER, ItemKeys.NETHER_WART, PotionKeys.AWKWARD)
.save(this.exporter);
Expand Down Expand Up @@ -164,8 +164,8 @@ public void generate() {
.save(this.exporter);
}

private AmplifyBrewingRecipeBuilder amplify(RegistryKey<Item> base, RegistryKey<Item> addition, RegistryKey<Item> result) {
RegistryEntry<Item> item = this.items.getOrThrow(addition);
private AmplifyBrewingRecipeBuilder amplify(RegistryKey<Item> base, RegistryKey<Item> reagent, RegistryKey<Item> result) {
RegistryEntry<Item> item = this.items.getOrThrow(reagent);
return new AmplifyBrewingRecipeBuilder(
this.items.getOrThrow(base),
Ingredient.ofStacks(new ItemStack(item)),
Expand All @@ -175,24 +175,24 @@ private AmplifyBrewingRecipeBuilder amplify(RegistryKey<Item> base, RegistryKey<
);
}

private ModifyBrewingRecipeBuilder modify(RegistryKey<Potion> base, RegistryKey<Item> addition, RegistryKey<Potion> result) {
RegistryEntry<Item> item = this.items.getOrThrow(addition);
private ModifyBrewingRecipeBuilder modify(RegistryKey<Potion> base, RegistryKey<Item> reagent, RegistryKey<Potion> result) {
RegistryEntry<Item> item = this.items.getOrThrow(reagent);
return this.modify(base, Ingredient.ofStacks(new ItemStack(item)), RegistryEntryList.of(item), result, potionName(result));
}

private ModifyBrewingRecipeBuilder modify(RegistryKey<Potion> base, TagKey<Item> addition, RegistryKey<Potion> result) {
return this.modify(base, Ingredient.fromTag(addition), this.items.getOrThrow(addition), result, potionName(result));
private ModifyBrewingRecipeBuilder modify(RegistryKey<Potion> base, TagKey<Item> reagent, RegistryKey<Potion> result) {
return this.modify(base, Ingredient.fromTag(reagent), this.items.getOrThrow(reagent), result, potionName(result));
}

private ModifyBrewingRecipeBuilder modify(RegistryKey<Potion> base, RegistryKey<Item> addition, RegistryKey<Potion> result, String name) {
RegistryEntry<Item> item = this.items.getOrThrow(addition);
private ModifyBrewingRecipeBuilder modify(RegistryKey<Potion> base, RegistryKey<Item> reagent, RegistryKey<Potion> result, String name) {
RegistryEntry<Item> item = this.items.getOrThrow(reagent);
return this.modify(base, Ingredient.ofStacks(new ItemStack(item)), RegistryEntryList.of(item), result, name);
}

private ModifyBrewingRecipeBuilder modify(RegistryKey<Potion> base, Ingredient addition, RegistryEntryList<Item> conditionItems, RegistryKey<Potion> result, String name) {
private ModifyBrewingRecipeBuilder modify(RegistryKey<Potion> base, Ingredient reagent, RegistryEntryList<Item> conditionItems, RegistryKey<Potion> result, String name) {
return new ModifyBrewingRecipeBuilder(
this.potions.getOrThrow(base),
addition,
reagent,
this.potions.getOrThrow(result),
conditionItems,
Identifier.ofVanilla(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
import net.minecraft.util.Identifier;

public class AmplifyBrewingRecipeBuilder extends BrewingRecipeBuilder<Item> {
public AmplifyBrewingRecipeBuilder(RegistryEntry<Item> base, Ingredient addition, RegistryEntry<Item> result, RegistryEntryList<Item> conditionItems, Identifier name) {
super(base, addition, result, conditionItems, name);
public AmplifyBrewingRecipeBuilder(RegistryEntry<Item> base, Ingredient reagent, RegistryEntry<Item> result, RegistryEntryList<Item> conditionItems, Identifier name) {
super(base, reagent, result, conditionItems, name);
}

@Override
protected BrewingRecipe<Item> createRecipe() {
return new AmplifyBrewingRecipe(
"",
this.base,
this.addition,
this.reagent,
this.result
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@

public abstract class BrewingRecipeBuilder<T> {
protected final RegistryEntry<T> base;
protected final Ingredient addition;
protected final Ingredient reagent;
protected final RegistryEntry<T> result;
private final RegistryEntryList<Item> conditionItems;
private final Identifier name;

protected BrewingRecipeBuilder(RegistryEntry<T> base, Ingredient addition, RegistryEntry<T> result, RegistryEntryList<Item> conditionItems, Identifier name) {
protected BrewingRecipeBuilder(RegistryEntry<T> base, Ingredient reagent, RegistryEntry<T> result, RegistryEntryList<Item> conditionItems, Identifier name) {
this.base = base;
this.addition = addition;
this.reagent = reagent;
this.result = result;
this.conditionItems = conditionItems;
this.name = name;
}

public BrewingRecipeBuilder<T> remainder(RegistryEntry<Item> remainder) {
this.addition.itematic$setRemainder(Optional.of(new ItemStack(remainder)));
this.reagent.itematic$setRemainder(Optional.of(new ItemStack(remainder)));
return this;
}

public void save(RecipeExporter exporter) {
Advancement.Builder advancementBuilder = exporter.getAdvancementBuilder()
.criterion("has_the_recipe", RecipeUnlockedCriterion.create(this.name))
.criterion("has_addition", InventoryChangedCriterion.Conditions.items(
.criterion("has_reagent", InventoryChangedCriterion.Conditions.items(
ItemPredicate.Builder.create()
.itematic$items(this.conditionItems)
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
import net.minecraft.util.Identifier;

public class ModifyBrewingRecipeBuilder extends BrewingRecipeBuilder<Potion> {
public ModifyBrewingRecipeBuilder(RegistryEntry<Potion> base, Ingredient addition, RegistryEntry<Potion> result, RegistryEntryList<Item> conditionItems, Identifier name) {
super(base, addition, result, conditionItems, name);
public ModifyBrewingRecipeBuilder(RegistryEntry<Potion> base, Ingredient reagent, RegistryEntry<Potion> result, RegistryEntryList<Item> conditionItems, Identifier name) {
super(base, reagent, result, conditionItems, name);
}

@Override
protected BrewingRecipe<Potion> createRecipe() {
return new ModifyBrewingRecipe(
"",
this.base,
this.addition,
this.reagent,
this.result
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ protected void configure(RegistryWrapper.WrapperLookup arg) {
.add(ItemKeys.POTION)
.add(ItemKeys.SPLASH_POTION)
.add(ItemKeys.LINGERING_POTION);
this.getOrCreateTagBuilder(ItematicItemTags.MUNDANE_POTION_ADDITIONS)
this.getOrCreateTagBuilder(ItematicItemTags.MUNDANE_POTION_REAGENTS)
.add(ItemKeys.REDSTONE)
.add(ItemKeys.MAGMA_CREAM)
.add(ItemKeys.GLISTERING_MELON_SLICE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_addition": {
"has_reagent": {
"conditions": {
"items": [
{
Expand All @@ -21,7 +21,7 @@
"requirements": [
[
"has_the_recipe",
"has_addition"
"has_reagent"
]
],
"rewards": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_addition": {
"has_reagent": {
"conditions": {
"items": [
{
Expand All @@ -21,7 +21,7 @@
"requirements": [
[
"has_the_recipe",
"has_addition"
"has_reagent"
]
],
"rewards": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_addition": {
"has_reagent": {
"conditions": {
"items": [
{
Expand All @@ -21,7 +21,7 @@
"requirements": [
[
"has_the_recipe",
"has_addition"
"has_reagent"
]
],
"rewards": {
Expand Down
Loading