Skip to content

Commit

Permalink
mostly fixed 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke100000 committed Jun 14, 2023
1 parent a4d7184 commit c13dfc0
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 32 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 7.5.3

* Ported to 1.20
* Invalid skins are now hidden by default in the Skin Library
* Added even more sanity checks when uploading stuff
* Fixed father/mother at baby item not always being correct
Expand Down
10 changes: 10 additions & 0 deletions common/src/main/java/net/mca/client/book/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Book {
private Identifier background = new Identifier("textures/gui/book.png");
private Formatting textFormatting = Formatting.BLACK;
private boolean pageTurnSound = true;
private boolean textShadow;

public Book(String bookName) {
this(bookName, Text.translatable(String.format("mca.books.%s.author", bookName)).formatted(Formatting.GRAY));
Expand All @@ -38,6 +39,11 @@ public Book setTextFormatting(Formatting textFormatting) {
return this;
}

public Book setTextShadow(boolean textShadow) {
this.textShadow = textShadow;
return this;
}

public Book setPageTurnSound(boolean pageTurnSound) {
this.pageTurnSound = pageTurnSound;
return this;
Expand Down Expand Up @@ -95,6 +101,10 @@ public Formatting getTextFormatting() {
return textFormatting;
}

public boolean hasTextShadow() {
return textShadow;
}

public boolean hasPageTurnSound() {
return pageTurnSound;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.mca.client.gui.ExtendedBookScreen;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.OrderedText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
Expand Down Expand Up @@ -32,18 +31,18 @@ int getEntriesPerPage() {
return 11;
}

private static void drawCenteredText(DrawContext context, TextRenderer textRenderer, Text text, int centerX, int y, int color) {
private static void drawCenteredText(ExtendedBookScreen screen, DrawContext context, TextRenderer textRenderer, Text text, int centerX, int y, int color) {
OrderedText orderedText = text.asOrderedText();
context.drawTextWithShadow(textRenderer, orderedText, (centerX - textRenderer.getWidth(orderedText) / 2), y, color);
context.drawText(textRenderer, orderedText, (centerX - textRenderer.getWidth(orderedText) / 2), y, color, screen.getBook().hasTextShadow());
}

@Override
public void render(ExtendedBookScreen screen, DrawContext context, int mouseX, int mouseY, float delta) {
drawCenteredText(context, screen.getTextRenderer(), title, screen.width / 2, 35, 0xFFFFFFFF);
drawCenteredText(screen, context, screen.getTextRenderer(), title, screen.width / 2, 35, 0xFFFFFFFF);

int y = 48;
for (int i = page * ENTRIES_PER_PAGE; i < Math.min(text.size(), (page + 1) * ENTRIES_PER_PAGE); i++) {
drawCenteredText(context, screen.getTextRenderer(), text.get(i), screen.width / 2 - 4, y, 0xFFFFFFFF);
drawCenteredText(screen, context, screen.getTextRenderer(), text.get(i), screen.width / 2 - 4, y, 0xFFFFFFFF);
y += 10;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.mca.client.gui.ExtendedBookScreen;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.OrderedText;

public class CenteredTextPage extends TextPage {
Expand All @@ -27,7 +26,7 @@ public void render(ExtendedBookScreen screen, DrawContext context, int mouseX, i
for (int m = 0; m < l; ++m) {
OrderedText orderedText = getCachedPage(screen).get(m);
int x = i + 36;
context.drawTextWithShadow(textRenderer, orderedText, x + 114 / 2 - textRenderer.getWidth(orderedText) / 2, (32 + (m + 7 - (l / 2)) * 9), 0);
context.drawText(textRenderer, orderedText, x + 114 / 2 - textRenderer.getWidth(orderedText) / 2, (32 + (m + 7 - (l / 2)) * 9), 0, screen.getBook().hasTextShadow());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.mca.client.gui.ExtendedBookScreen;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;

import java.util.List;
Expand All @@ -21,7 +20,7 @@ int getEntriesPerPage() {
public void render(ExtendedBookScreen screen, DrawContext context, int mouseX, int mouseY, float delta) {
int y = 20;
for (int i = page * getEntriesPerPage(); i < Math.min(text.size(), (page + 1) * getEntriesPerPage()); i++) {
context.drawTextWithShadow(screen.getTextRenderer(), text.get(i), (screen.width - 192) / 2 + 36, y, 0xFF000000);
context.drawText(screen.getTextRenderer(), text.get(i), (screen.width - 192) / 2 + 36, y, 0xFF000000, screen.getBook().hasTextShadow());
y += 10;
}
}
Expand Down
3 changes: 1 addition & 2 deletions common/src/main/java/net/mca/client/book/pages/TextPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.mca.client.gui.ExtendedBookScreen;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.*;

import java.util.LinkedList;
Expand Down Expand Up @@ -50,7 +49,7 @@ public void render(ExtendedBookScreen screen, DrawContext context, int mouseX, i
for (int m = 0; m < l; ++m) {
OrderedText orderedText = getCachedPage(screen).get(m);
int x = i + 36;
context.drawTextWithShadow(screen.getTextRenderer(), orderedText, x, (32 + m * 9), 0);
context.drawText(screen.getTextRenderer(), orderedText, x, (32 + m * 9), 0, screen.getBook().hasTextShadow());
}
}
}
Expand Down
13 changes: 6 additions & 7 deletions common/src/main/java/net/mca/client/book/pages/TitlePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.mca.client.gui.ExtendedBookScreen;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.OrderedText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
Expand Down Expand Up @@ -36,24 +35,24 @@ public TitlePage(Text title, Text subtitle) {
this.subtitle = subtitle;
}

private static void drawCenteredText(DrawContext context, TextRenderer textRenderer, Text text, int centerX, int y, int color) {
private static void drawCenteredText(ExtendedBookScreen screen, DrawContext context, TextRenderer textRenderer, Text text, int centerX, int y, int color) {
OrderedText orderedText = text.asOrderedText();
drawCenteredText(context, textRenderer, orderedText, centerX, y, color);
drawCenteredText(screen, context, textRenderer, orderedText, centerX, y, color);
}

private static void drawCenteredText(DrawContext context, TextRenderer textRenderer, OrderedText text, int centerX, int y, int color) {
context.drawTextWithShadow(textRenderer, text, (centerX - textRenderer.getWidth(text) / 2), y, color);
private static void drawCenteredText(ExtendedBookScreen screen, DrawContext context, TextRenderer textRenderer, OrderedText text, int centerX, int y, int color) {
context.drawText(textRenderer, text, (centerX - textRenderer.getWidth(text) / 2), y, color, screen.getBook().hasTextShadow());
}

@Override
public void render(ExtendedBookScreen screen, DrawContext context, int mouseX, int mouseY, float delta) {
List<OrderedText> texts = screen.getTextRenderer().wrapLines(title, 114);
int y = 80 - 5 * texts.size();
for (OrderedText t : texts) {
drawCenteredText(context, screen.getTextRenderer(), t, screen.width / 2 - 2, y, 0xFFFFFF);
drawCenteredText(screen, context, screen.getTextRenderer(), t, screen.width / 2 - 2, y, 0xFFFFFF);
y += 10;
}
y = 82 + 5 * texts.size();
drawCenteredText(context, screen.getTextRenderer(), subtitle, screen.width / 2 - 2, y, 0xFFFFFF);
drawCenteredText(screen, context, screen.getTextRenderer(), subtitle, screen.width / 2 - 2, y, 0xFFFFFF);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.mca.client.gui;

import com.mojang.blaze3d.systems.RenderSystem;
import net.mca.client.book.Book;
import net.mca.client.book.pages.Page;
import net.mca.client.gui.widget.ExtendedPageTurnWidget;
Expand All @@ -10,7 +9,6 @@
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.PageTurnWidget;
import net.minecraft.client.util.NarratorManager;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.Style;
Expand Down Expand Up @@ -122,7 +120,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
if (book.showPageCount()) {
Text pageIndexText = Text.translatable("book.pageIndicator", this.pageIndex + 1, Math.max(book.getPageCount(), 1)).formatted(book.getTextFormatting());
int k = textRenderer.getWidth(pageIndexText);
context.drawTextWithShadow(textRenderer, pageIndexText, i - k + 192 - 44, 18, 0);
context.drawText(textRenderer, pageIndexText, i - k + 192 - 44, 18, 0, getBook().hasTextShadow());
}

Page page = book.getPage(pageIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public float[] getColor(float u, float v, float greenShift) {
int color = data.colors[y * data.height + x];

float[] result = new float[] {
ColorHelper.Abgr.getRed(color) / 255F,
ColorHelper.Abgr.getBlue(color) / 255F,
ColorHelper.Abgr.getGreen(color) / 255F,
ColorHelper.Abgr.getBlue(color) / 255F
ColorHelper.Abgr.getRed(color) / 255F
};

if (greenShift > 0) {
Expand Down
18 changes: 9 additions & 9 deletions common/src/main/java/net/mca/entity/EquipmentSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
import net.minecraft.item.Items;

public enum EquipmentSet {
NAKED(null, null, null, null, null, null),
NAKED(Items.AIR, Items.AIR, Items.AIR, Items.AIR, Items.AIR, Items.AIR),

GUARD_0(Items.IRON_SWORD, null, null, Items.IRON_CHESTPLATE, Items.LEATHER_LEGGINGS, Items.LEATHER_BOOTS),
GUARD_0_LEFT(null, Items.IRON_SWORD, null, Items.IRON_CHESTPLATE, Items.LEATHER_LEGGINGS, Items.LEATHER_BOOTS),
GUARD_0(Items.IRON_SWORD, Items.AIR, Items.AIR, Items.IRON_CHESTPLATE, Items.LEATHER_LEGGINGS, Items.LEATHER_BOOTS),
GUARD_0_LEFT(Items.AIR, Items.IRON_SWORD, Items.AIR, Items.IRON_CHESTPLATE, Items.LEATHER_LEGGINGS, Items.LEATHER_BOOTS),
GUARD_1(Items.IRON_SWORD, Items.SHIELD, Items.IRON_HELMET, Items.IRON_CHESTPLATE, Items.LEATHER_LEGGINGS, Items.IRON_BOOTS),
GUARD_2(Items.DIAMOND_SWORD, Items.SHIELD, Items.IRON_HELMET, Items.IRON_CHESTPLATE, Items.IRON_LEGGINGS, Items.IRON_BOOTS),

ARCHER_0(Items.BOW, null, null, Items.LEATHER_CHESTPLATE, null, null),
ARCHER_0_LEFT(null, Items.BOW, null, Items.LEATHER_CHESTPLATE, null, null),
ARCHER_1(Items.BOW, null, null, Items.IRON_CHESTPLATE, Items.LEATHER_LEGGINGS, Items.LEATHER_BOOTS),
ARCHER_1_LEFT(null, Items.BOW, null, Items.IRON_CHESTPLATE, Items.LEATHER_LEGGINGS, Items.LEATHER_BOOTS),
ARCHER_2(Items.BOW, null, null, Items.DIAMOND_CHESTPLATE, Items.LEATHER_LEGGINGS, Items.IRON_BOOTS),
ARCHER_2_LEFT(null, Items.BOW, null, Items.DIAMOND_CHESTPLATE, Items.LEATHER_LEGGINGS, Items.IRON_BOOTS),
ARCHER_0(Items.BOW, Items.AIR, Items.AIR, Items.LEATHER_CHESTPLATE, Items.AIR, Items.AIR),
ARCHER_0_LEFT(Items.AIR, Items.BOW, Items.AIR, Items.LEATHER_CHESTPLATE, Items.AIR, Items.AIR),
ARCHER_1(Items.BOW, Items.AIR, Items.AIR, Items.IRON_CHESTPLATE, Items.LEATHER_LEGGINGS, Items.LEATHER_BOOTS),
ARCHER_1_LEFT(Items.AIR, Items.BOW, Items.AIR, Items.IRON_CHESTPLATE, Items.LEATHER_LEGGINGS, Items.LEATHER_BOOTS),
ARCHER_2(Items.BOW, Items.AIR, Items.AIR, Items.DIAMOND_CHESTPLATE, Items.LEATHER_LEGGINGS, Items.IRON_BOOTS),
ARCHER_2_LEFT(Items.AIR, Items.BOW, Items.AIR, Items.DIAMOND_CHESTPLATE, Items.LEATHER_LEGGINGS, Items.IRON_BOOTS),

ELITE(Items.NETHERITE_SWORD, Items.NETHERITE_SWORD, Items.DIAMOND_HELMET, Items.NETHERITE_CHESTPLATE, Items.GOLDEN_LEGGINGS, Items.NETHERITE_BOOTS),
ROYAL(Items.TRIDENT, Items.DIAMOND_AXE, Items.GOLDEN_HELMET, Items.GOLDEN_CHESTPLATE, Items.GOLDEN_LEGGINGS, Items.GOLDEN_BOOTS);
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/java/net/mca/item/ItemsMCA.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public interface ItemsMCA {
RegistrySupplier<Item> BOOK_DEATH = register("book_death", () -> new ExtendedWrittenBookItem(baseProps(), new Book("death")
.setBackground(MCA.locate("textures/gui/books/death.png"))
.setTextFormatting(Formatting.WHITE)
.setTextShadow(true)
.addPage(new TitlePage("death", Formatting.GRAY))
.addSimplePages(3, 0)
.addPage(new ScribbleTextPage(MCA.locate("textures/gui/scribbles/test.png"), "death", 3))
Expand Down Expand Up @@ -102,6 +103,7 @@ public interface ItemsMCA {
RegistrySupplier<Item> BOOK_BLUEPRINT = register("book_blueprint", () -> new ExtendedWrittenBookItem(baseProps(), new Book("blueprint")
.setBackground(MCA.locate("textures/gui/books/blueprint.png"))
.setTextFormatting(Formatting.WHITE)
.setTextShadow(true)
.addPage(new TitlePage("blueprint", Formatting.WHITE))
.addSimplePages(6)));

Expand Down

0 comments on commit c13dfc0

Please sign in to comment.