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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ repositories {
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.

maven { url 'https://jitpack.io' }
}

dependencies {
Expand All @@ -22,6 +24,9 @@ dependencies {

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation "com.github.Chocohead:Fabric-ASM:v2.3"
include "com.github.Chocohead:Fabric-ASM:v2.3"
}

processResources {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.18.4

# Mod Properties
mod_version = 0.4.1+1.21.1
mod_version = 0.5.0+1.21.1
maven_group = net.errorcraft
archives_base_name = itematic

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package net.errorcraft.itematic.client.gui.screen.ingame;

import net.errorcraft.itematic.client.gui.screen.recipebook.BrewingRecipeBookWidget;
import net.errorcraft.itematic.mixin.client.gui.screen.ingame.BrewingStandScreenAccessor;
import net.errorcraft.itematic.mixin.client.gui.screen.ingame.HandledScreenAccessor;
import net.errorcraft.itematic.screen.BrewingStandMenuDelegate;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.BrewingStandScreen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider;
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
import net.minecraft.client.gui.widget.TexturedButtonWidget;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.text.Text;

public class BrewingStandScreenDelegate extends HandledScreen<BrewingStandMenuDelegate> implements RecipeBookProvider {
private final BrewingStandScreen delegate;
private final RecipeBookWidget recipeBook = new BrewingRecipeBookWidget();
private boolean narrow;

public BrewingStandScreenDelegate(BrewingStandMenuDelegate handler, PlayerInventory inventory, Text title, BrewingStandScreen delegate) {
super(handler, inventory, title);
this.delegate = delegate;
}

@Override
@SuppressWarnings("DataFlowIssue")
protected void init() {
this.delegate.init(this.client, this.width, this.height);
super.init();
this.narrow = this.width < 379;
this.recipeBook.initialize(this.width, this.height, this.client, this.narrow, this.handler);
this.x = this.recipeBook.findLeftEdge(this.width, this.backgroundWidth);
((HandledScreenAccessor) this.delegate).itematic$setX(this.x);
this.addDrawableChild(new TexturedButtonWidget(this.x + 15, this.y + 50, 20, 18, RecipeBookWidget.BUTTON_TEXTURES, button -> {
this.recipeBook.toggleOpen();
this.x = this.recipeBook.findLeftEdge(this.width, this.backgroundWidth);
((HandledScreenAccessor) this.delegate).itematic$setX(this.x);
button.setPosition(this.x + 15, this.y + 50);
}));
this.titleX = (this.backgroundWidth - this.textRenderer.getWidth(this.title)) / 2;
}

@Override
protected void handledScreenTick() {
super.handledScreenTick();
this.recipeBook.update();
}

@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
if (this.recipeBook.isOpen() && this.narrow) {
this.renderBackground(context, mouseX, mouseY, delta);
this.recipeBook.render(context, mouseX, mouseY, delta);
} else {
super.render(context, mouseX, mouseY, delta);
this.recipeBook.render(context, mouseX, mouseY, delta);
this.recipeBook.drawGhostSlots(context, this.x, this.y, false, delta);
}

this.drawMouseoverTooltip(context, mouseX, mouseY);
this.recipeBook.drawTooltip(context, this.x, this.y, mouseX, mouseY);
}

@Override
protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) {
((BrewingStandScreenAccessor) this.delegate).itematic$drawBackground(context, delta, mouseX, mouseY);
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (this.recipeBook.mouseClicked(mouseX, mouseY, button)) {
return true;
}

return this.narrow && this.recipeBook.isOpen() || super.mouseClicked(mouseX, mouseY, button);
}

@Override
protected void onMouseClick(Slot slot, int slotId, int button, SlotActionType actionType) {
super.onMouseClick(slot, slotId, button, actionType);
this.recipeBook.slotClicked(slot);
}

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
return this.recipeBook.keyPressed(keyCode, scanCode, modifiers) || super.keyPressed(keyCode, scanCode, modifiers);
}

@Override
protected boolean isClickOutsideBounds(double mouseX, double mouseY, int left, int top, int button) {
boolean clickedOutside = mouseX < left || mouseY < top || mouseX >= left + this.backgroundWidth || mouseY >= top + this.backgroundHeight;
return this.recipeBook.isClickOutsideBounds(mouseX, mouseY, this.x, this.y, this.backgroundWidth, this.backgroundHeight, button) && clickedOutside;
}

@Override
public boolean charTyped(char chr, int modifiers) {
return this.recipeBook.charTyped(chr, modifiers) || super.charTyped(chr, modifiers);
}

@Override
public void refreshRecipeBook() {
this.recipeBook.refresh();
}

@Override
public RecipeBookWidget getRecipeBookWidget() {
return this.recipeBook;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package net.errorcraft.itematic.client.gui.screen.recipebook;

import net.errorcraft.itematic.recipe.brewing.BrewingRecipe;
import net.errorcraft.itematic.screen.BrewingStandMenuDelegate;
import net.minecraft.client.gui.screen.ButtonTextures;
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
import net.minecraft.item.Item;
import net.minecraft.recipe.RecipeEntry;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.screen.slot.Slot;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import java.util.List;

public class BrewingRecipeBookWidget extends RecipeBookWidget {
private static final ButtonTextures TEXTURES = new ButtonTextures(
Identifier.ofVanilla("recipe_book/brewing_stand_filter_enabled"),
Identifier.ofVanilla("recipe_book/brewing_stand_filter_disabled"),
Identifier.ofVanilla("recipe_book/brewing_stand_filter_enabled_highlighted"),
Identifier.ofVanilla("recipe_book/brewing_stand_filter_disabled_highlighted")
);
private static final Text TOGGLE_BREWABLE_TEXT = Text.translatable("gui.recipebook.toggleRecipes.brewable");

@Override
protected void setBookButtonTexture() {
this.toggleCraftableButton.setTextures(TEXTURES);
}

@Override
protected Text getToggleCraftableButtonText() {
return TOGGLE_BREWABLE_TEXT;
}

@Override
@SuppressWarnings("DataFlowIssue")
public void showGhostRecipe(RecipeEntry<?> recipe, List<Slot> slots) {
this.ghostSlots.setRecipe(recipe);
DynamicRegistryManager registryManager = this.client.world.getRegistryManager();
RegistryWrapper.Impl<Item> items = registryManager.getWrapperOrThrow(RegistryKeys.ITEM);
if (recipe.value() instanceof BrewingRecipe<?> brewingRecipe) {
Slot firstInputSlot = this.craftingScreenHandler.getSlot(BrewingStandMenuDelegate.FIRST_INPUT_SLOT);
this.ghostSlots.addSlot(brewingRecipe.inputIngredient(items), firstInputSlot.x, firstInputSlot.y);

Slot ingredientSlot = this.craftingScreenHandler.getSlot(BrewingStandMenuDelegate.INGREDIENT_SLOT);
this.ghostSlots.addSlot(brewingRecipe.reagent(), ingredientSlot.x, ingredientSlot.y);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.errorcraft.itematic.client.recipebook;

import com.chocohead.mm.api.ClassTinkerers;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.recipebook.RecipeBookGroup;

import java.util.List;

public class ItematicRecipeBookGroups {
public static final RecipeBookGroup BREWING_SEARCH = ClassTinkerers.getEnum(RecipeBookGroup.class, "ITEMATIC$BREWING_SEARCH");
public static final RecipeBookGroup BREWING_MODIFY = ClassTinkerers.getEnum(RecipeBookGroup.class, "ITEMATIC$BREWING_MODIFY");
public static final RecipeBookGroup BREWING_AMPLIFY = ClassTinkerers.getEnum(RecipeBookGroup.class, "ITEMATIC$BREWING_AMPLIFY");

public static final List<RecipeBookGroup> BREWING = ImmutableList.of(
BREWING_SEARCH,
BREWING_MODIFY,
BREWING_AMPLIFY
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.errorcraft.itematic.mixin.client.gui.screen.ingame;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.BrewingStandScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(BrewingStandScreen.class)
public interface BrewingStandScreenAccessor {
@Invoker("drawBackground")
void itematic$drawBackground(DrawContext context, float delta, int mouseX, int mouseY);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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;
import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider;
import net.minecraft.entity.player.PlayerInventory;
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)
public abstract class BrewingStandScreenExtender extends HandledScreen<BrewingStandMenuDelegate> implements RecipeBookProvider {
public BrewingStandScreenExtender(BrewingStandMenuDelegate handler, PlayerInventory inventory, Text title) {
super(handler, inventory, title);
}

@ModifyVariable(
method = "drawBackground",
ordinal = 2,
at = @At("STORE:FIRST")
)
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
@@ -0,0 +1,11 @@
package net.errorcraft.itematic.mixin.client.gui.screen.ingame;

import net.minecraft.client.gui.screen.ingame.HandledScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(HandledScreen.class)
public interface HandledScreenAccessor {
@Accessor("x")
void itematic$setX(int x);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package net.errorcraft.itematic.mixin.client.gui.screen.ingame;

import net.errorcraft.itematic.client.gui.screen.ingame.BrewingStandScreenDelegate;
import net.errorcraft.itematic.screen.BrewingStandMenuDelegate;
import net.minecraft.client.gui.screen.ingame.BrewingStandScreen;
import net.minecraft.client.gui.screen.ingame.HandledScreens;
import net.minecraft.screen.BrewingStandScreenHandler;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Slice;

@Mixin(HandledScreens.class)
public class HandledScreensExtender {
@ModifyArg(
method = "<clinit>",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreens;register(Lnet/minecraft/screen/ScreenHandlerType;Lnet/minecraft/client/gui/screen/ingame/HandledScreens$Provider;)V",
ordinal = 0
),
slice = @Slice(
from = @At(
value = "FIELD",
target = "Lnet/minecraft/screen/ScreenHandlerType;BREWING_STAND:Lnet/minecraft/screen/ScreenHandlerType;",
opcode = Opcodes.GETSTATIC
)
)
)
private static HandledScreens.Provider<BrewingStandMenuDelegate, BrewingStandScreenDelegate> useDelegate(HandledScreens.Provider<BrewingStandScreenHandler, BrewingStandScreen> provider) {
return (handler, inventory, title) -> new BrewingStandScreenDelegate(handler, inventory, title, provider.create(handler.delegate(), inventory, title));
}
}
Loading