Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #26 from replaceitem/main
Browse files Browse the repository at this point in the history
Updated to Minecraft 1.20.2
  • Loading branch information
Bawnorton authored Nov 12, 2023
2 parents b51f3bc + 0c91b28 commit 64dcb76
Show file tree
Hide file tree
Showing 48 changed files with 148 additions and 110 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ The settings menu can be accessed by clicking the settings button in the top rig
- Values over 10 are not recommended when surrounded by a lot of unbroken blocks as highlighting blocks is somewhat intensive

## Dependencies
- [Minecraft Fabric 1.20](https://fabricmc.net/)
- [Fabric API ≥ 0.83.0+1.20](https://modrinth.com/mod/fabric-api)
- [Minecraft Fabric 1.20.2](https://fabricmc.net/)
- [Fabric API ≥ 0.89.0+1.20.2](https://modrinth.com/mod/fabric-api)
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.2
loader_version=0.14.21
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.4
loader_version=0.14.24

# Mod Properties
mod_version=1.5.0
maven_group=com.bawnorton.randoassistant
archives_base_name=randoassistant

# Dependencies
fabric_version=0.83.1+1.20.1
fabric_version=0.90.7+1.20.2
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public abstract class CraftingScreenMixin extends HandledScreenMixin {
@Shadow @Final private RecipeBookWidget recipeBook;

@ModifyArg(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/TexturedButtonWidget;<init>(IIIIIIILnet/minecraft/util/Identifier;Lnet/minecraft/client/gui/widget/ButtonWidget$PressAction;)V"), index = 8)
@ModifyArg(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/TexturedButtonWidget;<init>(IIIILnet/minecraft/client/gui/screen/ButtonTextures;Lnet/minecraft/client/gui/widget/ButtonWidget$PressAction;)V"), index = 5)
private ButtonWidget.PressAction onAddDrawableChild(ButtonWidget.PressAction pressAction) {
return (button) -> {
recipeBook.toggleOpen();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bawnorton.randoassistant.mixin.client;

import com.bawnorton.randoassistant.RandoAssistant;
import com.bawnorton.randoassistant.RandoAssistantClient;
import com.bawnorton.randoassistant.extend.InventoryScreenExtender;
import com.bawnorton.randoassistant.networking.client.Networking;
Expand All @@ -8,6 +9,7 @@
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.screen.ButtonTextures;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
import net.minecraft.client.gui.tooltip.Tooltip;
Expand All @@ -18,6 +20,7 @@
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.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
Expand All @@ -31,29 +34,27 @@
@Mixin(InventoryScreen.class)
public abstract class InventoryScreenMixin extends AbstractInventoryScreenMixin implements InventoryScreenExtender {

private static final Identifier LOOT_BUTTON_TEXTURE = new Identifier("randoassistant", "textures/gui/loot_button.png");
@Unique
private static final ButtonTextures LOOT_BUTTON_TEXTURES = new ButtonTextures(
new Identifier(RandoAssistant.MOD_ID, "loot_button"),
new Identifier(RandoAssistant.MOD_ID, "loot_button_focused")
);

@Shadow
@Final
private RecipeBookWidget recipeBook;
@Shadow
private boolean narrow;

@Shadow protected abstract void drawBackground(DrawContext context, float delta, int mouseX, int mouseY);

private TexturedButtonWidget lootButton;
private TexturedButtonWidget recipeButton;

@Inject(method = "handledScreenTick", at = @At("TAIL"))
private void onHandledScreenTick(CallbackInfo ci) {
LootBookWidget.getInstance().tick();
}

@Inject(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/InventoryScreen;addDrawableChild(Lnet/minecraft/client/gui/Element;)Lnet/minecraft/client/gui/Element;", shift = At.Shift.AFTER))
private void onInit(CallbackInfo ci) {
LootBookWidget lootBook = LootBookWidget.getInstance();
lootBook.initialise((InventoryScreen) (Object) this);
Networking.requestStatsPacket();
lootButton = new TexturedButtonWidget(this.x + 126, this.height / 2 - 22, 20, 18, 0, 0, 19, LOOT_BUTTON_TEXTURE, (button) -> {
lootButton = new TexturedButtonWidget(this.x + 126, this.height / 2 - 22, 20, 18, LOOT_BUTTON_TEXTURES, (button) -> {
if(!RandoAssistantClient.isInstalledOnServer) return;
lootBook.toggleOpen();
if (lootBook.isOpen() && recipeBook.isOpen()) {
Expand Down Expand Up @@ -116,7 +117,7 @@ private Element onAddRecipeButton(Element button) {
return button;
}

@ModifyArg(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/TexturedButtonWidget;<init>(IIIIIIILnet/minecraft/util/Identifier;Lnet/minecraft/client/gui/widget/ButtonWidget$PressAction;)V"), index = 8)
@ModifyArg(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/TexturedButtonWidget;<init>(IIIILnet/minecraft/client/gui/screen/ButtonTextures;Lnet/minecraft/client/gui/widget/ButtonWidget$PressAction;)V"), index = 5)
private ButtonWidget.PressAction onAddDrawableChild(ButtonWidget.PressAction pressAction) {
return (button) -> {
recipeBook.toggleOpen();
Expand All @@ -136,11 +137,10 @@ private ButtonWidget.PressAction onAddDrawableChild(ButtonWidget.PressAction pre
};
}

@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/InventoryScreen;renderBackground(Lnet/minecraft/client/gui/DrawContext;)V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/AbstractInventoryScreen;render(Lnet/minecraft/client/gui/DrawContext;IIF)V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
private void onRender(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
LootBookWidget lootBook = LootBookWidget.getInstance();
if (lootBook.isOpen()) {
drawBackground(context, delta, mouseX, mouseY);
lootBook.render(context, mouseX, mouseY, delta);
}
}
Expand Down Expand Up @@ -192,8 +192,8 @@ protected void onClose(CallbackInfo ci) {
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
return LootBookWidget.getInstance().mouseScrolled(mouseX, mouseY, amount);
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
return LootBookWidget.getInstance().mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
import java.awt.geom.Point2D;

public class RenderingHelper {
private static final Identifier STAR = new Identifier(RandoAssistant.MOD_ID, "textures/gui/item_stars.png");
private static final Identifier STAR_TEXTURE = new Identifier(RandoAssistant.MOD_ID, "item_star");
private static final Identifier STAR_SILKTOUCH_TEXTURE = new Identifier(RandoAssistant.MOD_ID, "item_star_silktouch");
private static final MinecraftClient client = MinecraftClient.getInstance();

public static void renderIdentifier(Identifier id, DrawContext context, double scale, int x, int y, boolean preferEntity) {
Expand Down Expand Up @@ -139,7 +140,7 @@ private static void drawEntity(double scale, int x, int y, LivingEntity entity)
matrices.translate(-3, 0, 100);

Box box = entity.getBoundingBox();
float entityScale = 1.0f / (float) (Math.max(box.getXLength(), Math.max(box.getYLength(), box.getZLength())));
float entityScale = 1.0f / (float) (Math.max(box.getLengthX(), Math.max(box.getLengthY(), box.getLengthZ())));
matrices.scale(entityScale, entityScale, entityScale);

if(entity instanceof SquidEntity) {
Expand Down Expand Up @@ -211,7 +212,7 @@ public static void renderStar(DrawContext context, int x, int y, boolean silkTou
MatrixStack matrices = context.getMatrices();
matrices.push();
matrices.translate(0, -Easing.ease(0, 1, timeOffset), 300);
context.drawTexture(STAR, x, y, silkTouch ? 8 : 0, 0, 8, 8, 16, 16);
context.drawGuiTexture(silkTouch ? STAR_SILKTOUCH_TEXTURE : STAR_TEXTURE, x, y, 8, 8);
matrices.pop();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bawnorton.randoassistant.screen;

import com.bawnorton.randoassistant.RandoAssistant;
import com.bawnorton.randoassistant.RandoAssistantClient;
import com.bawnorton.randoassistant.config.Config;
import com.bawnorton.randoassistant.config.ConfigManager;
Expand All @@ -8,9 +9,11 @@
import com.bawnorton.randoassistant.tracking.trackable.TrackableCrawler;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ButtonTextures;
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.gui.widget.*;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -20,6 +23,25 @@
import static com.bawnorton.randoassistant.screen.LootTableGraphWidget.HEIGHT;

public class LootBookSettingsWidget {
public static final ButtonTextures BACK_TEXTURES = new ButtonTextures(
new Identifier(RandoAssistant.MOD_ID, "loot_book/back"),
new Identifier(RandoAssistant.MOD_ID, "loot_book/back_focused")
);
public static final ButtonTextures NEXT_TEXTURES = new ButtonTextures(
new Identifier(RandoAssistant.MOD_ID, "loot_book/next"),
new Identifier(RandoAssistant.MOD_ID, "loot_book/next_focused")
);
public static final ButtonTextures PREV_TEXTURES = new ButtonTextures(
new Identifier(RandoAssistant.MOD_ID, "loot_book/prev"),
new Identifier(RandoAssistant.MOD_ID, "loot_book/prev_focused")
);
public static final ButtonTextures TOGGLE_TEXTURES = new ButtonTextures(
new Identifier(RandoAssistant.MOD_ID, "loot_book/toggle_enabled"),
new Identifier(RandoAssistant.MOD_ID, "loot_book/toggle_disabled"),
new Identifier(RandoAssistant.MOD_ID, "loot_book/toggle_enabled_focused"),
new Identifier(RandoAssistant.MOD_ID, "loot_book/toggle_disabled_focused")
);

private final MinecraftClient client;
private final int x;
private int y;
Expand Down Expand Up @@ -50,16 +72,16 @@ public LootBookSettingsWidget(MinecraftClient client, int x, int y) {

pages = new ArrayList<>();

backButton = new TexturedButtonWidget(x + 10, y + 10, 16, 16, 206, 41, 18, LootBookWidget.TEXTURE, (button) -> LootBookWidget.getInstance().closeSettings());
backButton = new TexturedButtonWidget(x + 10, y + 10, 16, 16, BACK_TEXTURES, (button) -> LootBookWidget.getInstance().closeSettings());
backButton.setTooltip(Tooltip.of(Text.of("Save and Exit")));
nextButton = new TexturedButtonWidget(x + 106, y + 136, 12, 17, 1, 208, 18, LootBookWidget.TEXTURE, (button) -> {
nextButton = new TexturedButtonWidget(x + 106, y + 136, 12, 17, NEXT_TEXTURES, (button) -> {
pages.get(pageNum).forEach((name, widget) -> widget.active = false);
pageNum++;
if (pageNum >= pages.size()) pageNum = 0;
pages.get(pageNum).forEach((name, widget) -> widget.active = true);
});
nextButton.setTooltip(Tooltip.of(Text.of("Next Page")));
prevButton = new TexturedButtonWidget(x + 31, y + 136, 12, 17, 14, 208, 18, LootBookWidget.TEXTURE, (button) -> {
prevButton = new TexturedButtonWidget(x + 31, y + 136, 12, 17, PREV_TEXTURES, (button) -> {
pages.get(pageNum).forEach((name, widget) -> widget.active = false);
pageNum--;
if (pageNum < 0) pageNum = pages.size() - 1;
Expand All @@ -82,7 +104,7 @@ public LootBookSettingsWidget(MinecraftClient client, int x, int y) {

private ToggleButtonWidget createButton(String name, String tooltip, boolean toggled) {
ToggleButtonWidget button = new ToggleButtonWidget(x + 120, y + 33, 16, 16, toggled);
button.setTextureUV(170, 41, 18, 18, LootBookWidget.TEXTURE);
button.setTextures(TOGGLE_TEXTURES);
button.setTooltip(Tooltip.of(Text.of(tooltip)));
button.setY(button.getY() + addToPages(name, button));
return button;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public LootBookStatsWidget(MinecraftClient client, int x, int y) {
this.y = y;

backButton = new ToggleButtonWidget(x + 10, y + 10, 16, 16, false);
backButton.setTextureUV(206, 41, 0, 18, LootBookWidget.TEXTURE);
backButton.setTextures(LootBookSettingsWidget.BACK_TEXTURES);
backButton.setTooltip(Tooltip.of(Text.of("Exit")));

refresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.client.gui.Drawable;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.Selectable;
import net.minecraft.client.gui.screen.ButtonTextures;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
Expand All @@ -27,7 +28,17 @@

@SuppressWarnings("DataFlowIssue")
public class LootBookWidget implements Drawable, Element, Selectable {
public static final Identifier TEXTURE = new Identifier(RandoAssistant.MOD_ID, "textures/gui/loot_book.png");
public static final ButtonTextures SETTINGS_TEXTURES = new ButtonTextures(
new Identifier(RandoAssistant.MOD_ID, "loot_book/settings"),
new Identifier(RandoAssistant.MOD_ID, "loot_book/settings_focused")
);
public static final ButtonTextures STATS_TEXTURES = new ButtonTextures(
new Identifier(RandoAssistant.MOD_ID, "loot_book/stats"),
new Identifier(RandoAssistant.MOD_ID, "loot_book/stats_focused")
);

public static final Identifier BACKGROUND_TEXTURE = new Identifier(RandoAssistant.MOD_ID, "loot_book/background");

private static LootBookWidget INSTANCE;

private MinecraftClient client;
Expand Down Expand Up @@ -81,11 +92,11 @@ public void reset() {
this.lootTableArea = new LootTableListWidget(client, x + 11, y + 32);
this.settingsWidget = new LootBookSettingsWidget(client, x, y);
this.settingsButton = new ToggleButtonWidget(x + 120, y + 12, 16, 16, false);
this.settingsButton.setTextureUV(152, 41, 0, 18, TEXTURE);
this.settingsButton.setTextures(SETTINGS_TEXTURES);
this.settingsButton.setTooltip(Tooltip.of(Text.of("Settings")));
this.statsWidget = new LootBookStatsWidget(client, x, y);
this.statsButton = new ToggleButtonWidget(x + 100, y + 12, 16, 16, false);
this.statsButton.setTextureUV(152, 77, 0, 18, TEXTURE);
this.statsButton.setTextures(STATS_TEXTURES);
this.statsButton.setTooltip(Tooltip.of(Text.of("Stats")));
}
public void toggleOpen() {
Expand Down Expand Up @@ -124,10 +135,6 @@ public void closeStats() {
this.statsOpen = false;
}

public void tick() {
if(!this.isOpen()) return;
this.searchField.tick();
}

@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
Expand All @@ -140,7 +147,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
if(LootTableResultButton.isGraphOpen()) {
y += HEIGHT / 2;
}
context.drawTexture(TEXTURE, x, y, 1, 1, 147, 166);
context.drawGuiTexture(BACKGROUND_TEXTURE, x, y, 147, 166);
if(settingsOpen) {
this.settingsWidget.render(context, mouseX, mouseY, delta);
this.lootTableArea.renderLastClickedGraph(context, mouseX, mouseY);
Expand Down Expand Up @@ -176,12 +183,12 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double del
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
if(!this.isOpen()) return false;
LootTableResultButton lastClicked = LootTableResultButton.getLastClicked();
if(lastClicked == null) return false;
LootTableGraphWidget graphWidget = lastClicked.graphWidget;
return graphWidget != null && graphWidget.mouseScrolled(mouseX, mouseY, amount);
return graphWidget != null && graphWidget.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount);
}

@Override
Expand Down
Loading

0 comments on commit 64dcb76

Please sign in to comment.