Skip to content

Commit 50e0c4f

Browse files
committed
Merge remote-tracking branch 'upstream/1.20' into 1.20.1-update
# Conflicts: # src/main/java/slimeknights/mantle/Mantle.java # src/main/java/slimeknights/mantle/recipe/ingredient/PotionIngredient.java # src/main/java/slimeknights/mantle/util/RetexturedHelper.java # src/main/resources/assets/mantle/lang/en_us.json
2 parents af52def + 47af8f9 commit 50e0c4f

35 files changed

Lines changed: 778 additions & 194 deletions

src/main/java/slimeknights/mantle/Mantle.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import slimeknights.mantle.recipe.condition.TagFilledCondition;
6464
import slimeknights.mantle.recipe.helper.TagPreference;
6565
import slimeknights.mantle.recipe.ingredient.FluidContainerIngredient;
66+
import slimeknights.mantle.recipe.ingredient.PotionDisplayIngredient;
6667
import slimeknights.mantle.recipe.ingredient.PotionIngredient;
6768
import slimeknights.mantle.registration.MantleRegistrations;
6869
import slimeknights.mantle.registration.RegistrationHelper;
@@ -126,6 +127,7 @@ private void register() {
126127
ResourceConditions.register(TagCombinationCondition.ID, TagCombinationCondition::test);
127128
CustomIngredientSerializer.register(FluidContainerIngredient.SERIALIZER);
128129
CustomIngredientSerializer.register(PotionIngredient.SERIALIZER);
130+
CraftingHelper.register(getResource("potion_display"), PotionDisplayIngredient.SERIALIZER);
129131

130132
// fluid container transfer
131133
FluidContainerTransferManager.TRANSFER_LOADERS.registerDeserializer(EmptyFluidContainerTransfer.ID, EmptyFluidContainerTransfer.DESERIALIZER);
@@ -143,7 +145,7 @@ private void register() {
143145
BlockPredicate.LOADER.register(getResource("block_properties"), BlockPropertiesPredicate.LOADER);
144146

145147
// item predicates
146-
ItemPredicate.LOADER.register(getResource("has_container"), ItemPredicate.MAY_HAVE_TRANSFER.getLoader());
148+
ItemPredicate.LOADER.register(getResource("has_container"), ItemPredicate.HAS_CONTAINER.getLoader());
147149
ItemPredicate.LOADER.register(getResource("may_have_transfer"), ItemPredicate.MAY_HAVE_TRANSFER.getLoader());
148150

149151
// entity predicates
@@ -157,7 +159,7 @@ private void register() {
157159
LivingEntityPredicate.LOADER.register(getResource("on_ground"), LivingEntityPredicate.ON_GROUND.getLoader());
158160
LivingEntityPredicate.LOADER.register(getResource("crouching"), LivingEntityPredicate.CROUCHING.getLoader());
159161
LivingEntityPredicate.LOADER.register(getResource("sprinting"), LivingEntityPredicate.SPRINTING.getLoader());
160-
LivingEntityPredicate.LOADER.register(getResource("has_effect"), HasMobEffectPredicate.LOADER);
162+
LivingEntityPredicate.LOADER.register(getResource("blocking"), LivingEntityPredicate.BLOCKING.getLoader());LivingEntityPredicate.LOADER.register(getResource("has_effect"), HasMobEffectPredicate.LOADER);
161163
LivingEntityPredicate.LOADER.register(getResource("block_at_entity"), BlockAtEntityPredicate.LOADER);
162164
LivingEntityPredicate.LOADER.register(getResource("eyes_in_water"), LivingEntityPredicate.EYES_IN_WATER.getLoader());
163165
LivingEntityPredicate.LOADER.register(getResource("feet_in_water"), LivingEntityPredicate.FEET_IN_WATER.getLoader());

src/main/java/slimeknights/mantle/block/RetexturedBlock.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public ItemStack getPickedStack(BlockState state, BlockGetter world, BlockPos po
4242
}
4343

4444
@Override
45-
public void appendHoverText(ItemStack stack, @Nullable BlockGetter pLevel, List<Component> tooltip, TooltipFlag pFlag) {
46-
RetexturedHelper.addTooltip(stack, tooltip);
45+
public void appendHoverText(ItemStack stack, @Nullable BlockGetter pLevel, List<Component> tooltip, TooltipFlag flag) {
46+
RetexturedHelper.addTooltip(stack, tooltip, flag);
4747
}
4848

4949

src/main/java/slimeknights/mantle/client/book/data/content/ContentPageIconList.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ public static List<ContentPageIconList> getPagesNeededForItemCount(int count, Se
170170
padding.load();
171171
// hack: add padding to the previous section so section links start at the index
172172
int sectionIndex = data.parent.sections.indexOf(data);
173-
if (data.pages.isEmpty() && sectionIndex > 0) {
173+
if (sectionIndex > 0) {
174174
data.parent.sections.get(sectionIndex - 1).pages.add(padding);
175175
} else {
176-
data.pages.add(padding);
176+
newPages.add(0, padding);
177177
}
178178
}
179179

180-
// padding done, can add new pages
181-
data.pages.addAll(newPages);
180+
// padding done, can add new pages at the start of the section
181+
data.pages.addAll(0, newPages);
182182

183183
return listPages;
184184
}
@@ -191,15 +191,33 @@ public record PageWithIcon(SizedBookElement icon, PageData page) {}
191191
* @param data Section to receive pages
192192
* @param indexList List of indexes from {@link #getPagesNeededForItemCount(int, SectionData, String, String)}
193193
* @param pages List of pages to add to the indexes.
194+
* @param index Start index to insert new pages. Should generally be the size of {@link #getPagesNeededForItemCount(int, SectionData, String, String)},
195+
* though you may need to compare {@link SectionData#pages} count if not using {@link slimeknights.mantle.client.book.transformer.IndexTransformer}.
194196
*/
195-
public static void addPages(SectionData data, List<ContentPageIconList> indexList, Collection<PageWithIcon> pages) {
197+
public static void addPages(SectionData data, List<ContentPageIconList> indexList, Collection<PageWithIcon> pages, int index) {
196198
Iterator<ContentPageIconList> indexes = indexList.iterator();
197199
ContentPageIconList overview = indexes.next();
200+
List<PageData> newPages = new ArrayList<>(pages.size());
198201
for (PageWithIcon page : pages) {
199-
data.pages.add(page.page);
202+
newPages.add(page.page);
200203
while (!overview.addLink(page.icon, Component.literal(page.page.getTitle()), page.page)) {
201204
overview = indexes.next();
202205
}
203206
}
207+
if (index == -1) {
208+
data.pages.addAll(newPages);
209+
} else {
210+
data.pages.addAll(index, newPages);
211+
}
212+
}
213+
214+
/**
215+
* Adds the list of pages with icons to the indexes and the book
216+
* @param data Section to receive pages
217+
* @param indexList List of indexes from {@link #getPagesNeededForItemCount(int, SectionData, String, String)}
218+
* @param pages List of pages to add to the indexes.
219+
*/
220+
public static void addPages(SectionData data, List<ContentPageIconList> indexList, Collection<PageWithIcon> pages) {
221+
addPages(data, indexList, pages, indexList.size());
204222
}
205223
}

src/main/java/slimeknights/mantle/client/book/transformer/ContentGroupingSectionTransformer.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import slimeknights.mantle.client.screen.book.TextDataRenderer;
1515

1616
import javax.annotation.Nullable;
17+
import java.util.ArrayList;
1718
import java.util.List;
1819

1920
/**
@@ -52,6 +53,7 @@ public void transform(BookData book, SectionData data) {
5253
// add padding page to keep indexes stretching over two pages together
5354
int i = 0;
5455
List<ContentListing> finishedListings = builder.getFinishedListings();
56+
List<PageData> newPages = new ArrayList<>(finishedListings.size() + 1);
5557
if (finishedListings.size() % 2 == 0) {
5658
PageData padding = new PageData(true);
5759
padding.source = data.source;
@@ -63,8 +65,7 @@ public void transform(BookData book, SectionData data) {
6365
if (sectionIndex > 0) {
6466
data.parent.sections.get(sectionIndex - 1).pages.add(padding);
6567
} else {
66-
data.pages.add(padding);
67-
i++;
68+
newPages.add(padding);
6869
}
6970
}
7071

@@ -76,9 +77,10 @@ public void transform(BookData book, SectionData data) {
7677
listingPage.parent = data;
7778
listingPage.content = listing;
7879
listingPage.load();
79-
data.pages.add(i, listingPage);
80-
i++;
80+
newPages.add(listingPage);
8181
}
82+
// add new pages at the start of the section
83+
data.pages.addAll(0, newPages);
8284
}
8385
}
8486

src/main/java/slimeknights/mantle/client/screen/book/BookScreen.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@ public class BookScreen extends Screen {
5959
@Nullable
6060
private static Font altFont;
6161

62-
// Used for the book to image exporter to disable arrows and mouse input
62+
/** If true, shows next and previous page buttons. Set to false during export. */
6363
public boolean drawArrows = true;
64+
/** If true, the mouse may be used to interact with book elements. Set to false during export. */
6465
public boolean mouseInput = true;
66+
/** If true, animated elements can animate. Set to false during export to ensure first element consistently shows. */
67+
public boolean enableAnimations = true;
6568

6669
private ArrowButton previousArrow, nextArrow, backArrow, indexArrow;
6770

@@ -708,10 +711,10 @@ private void buildPages() {
708711
}
709712

710713
for (BookElement element : this.leftElements) {
711-
element.parent = this;
714+
element.setParent(this);
712715
}
713716
for (BookElement element : this.rightElements) {
714-
element.parent = this;
717+
element.setParent(this);
715718
}
716719
}
717720

src/main/java/slimeknights/mantle/client/screen/book/element/BookElement.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package slimeknights.mantle.client.screen.book.element;
22

3+
import lombok.Setter;
34
import net.minecraft.client.Minecraft;
45
import net.minecraft.client.gui.Font;
56
import net.minecraft.client.gui.GuiGraphics;
@@ -20,6 +21,8 @@
2021

2122
public abstract class BookElement {
2223

24+
/** TODO 1.21: make this field protected instead of public to ensure setter is used. */
25+
@Setter
2326
public BookScreen parent;
2427

2528
protected Minecraft mc = Minecraft.getInstance();

src/main/java/slimeknights/mantle/client/screen/book/element/ImageElement.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.minecraft.client.renderer.texture.TextureManager;
77
import net.minecraft.resources.ResourceLocation;
88
import slimeknights.mantle.client.book.data.element.ImageData;
9+
import slimeknights.mantle.client.screen.book.BookScreen;
910

1011
import static java.util.Objects.requireNonNullElse;
1112

@@ -60,6 +61,14 @@ public ImageElement(int x, int y, int width, int height, ImageData image, int co
6061
}
6162
}
6263

64+
@Override
65+
public void setParent(BookScreen parent) {
66+
super.setParent(parent);
67+
if (itemElement != null) {
68+
itemElement.setParent(parent);
69+
}
70+
}
71+
6372
@Override
6473
public void draw(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks, Font fontRenderer) {
6574
float r = ((this.colorMultiplier >> 16) & 0xff) / 255.F;

src/main/java/slimeknights/mantle/client/screen/book/element/ItemElement.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,18 @@ public void scale(float scale) {
8484
public void draw(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks, Font fontRenderer) {
8585
long nano = Util.getNanos();
8686

87-
if(nano > lastTime + ITEM_SWITCH_TIME) {
88-
this.lastTime = nano;
89-
this.currentItem++;
90-
91-
if (this.currentItem >= this.itemCycle.size()) {
92-
this.currentItem = 0;
87+
// don't cycle items during export
88+
if (parent == null || parent.enableAnimations) {
89+
if (nano > lastTime + ITEM_SWITCH_TIME){
90+
this.lastTime = nano;
91+
this.currentItem++;
92+
93+
if (this.currentItem >= this.itemCycle.size()) {
94+
this.currentItem = 0;
95+
}
9396
}
97+
} else {
98+
this.currentItem = 0;
9499
}
95100

96101
if (this.currentItem < this.itemCycle.size()) {

src/main/java/slimeknights/mantle/client/screen/book/element/PageIconLinkElement.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import slimeknights.mantle.client.book.action.StringActionProcessor;
99
import slimeknights.mantle.client.book.data.PageData;
1010
import slimeknights.mantle.client.book.data.element.TextData;
11+
import slimeknights.mantle.client.screen.book.BookScreen;
1112

1213
/** Link elements for {@link slimeknights.mantle.client.book.data.content.ContentPageIconList} */
1314
public class PageIconLinkElement extends SizedBookElement {
@@ -32,6 +33,12 @@ public PageIconLinkElement(int x, int y, int w, int h, SizedBookElement displayE
3233
this.name = name;
3334
}
3435

36+
@Override
37+
public void setParent(BookScreen parent) {
38+
super.setParent(parent);
39+
displayElement.setParent(parent);
40+
}
41+
3542
@Override
3643
public void draw(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks, Font fontRenderer) {
3744
boolean hover = this.isHovered(mouseX, mouseY);

src/main/java/slimeknights/mantle/client/screen/book/element/SelectionElement.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.minecraft.client.gui.GuiGraphics;
77
import net.minecraft.network.chat.Component;
88
import slimeknights.mantle.client.book.data.SectionData;
9+
import slimeknights.mantle.client.screen.book.BookScreen;
910
import slimeknights.mantle.client.screen.book.TextDataRenderer;
1011

1112
import java.util.ArrayList;
@@ -34,6 +35,12 @@ public SelectionElement(int x, int y, SectionData section) {
3435
this.iconRenderer = new ImageElement(this.iconX, this.iconY, IMG_SIZE, IMG_SIZE, section.icon);
3536
}
3637

38+
@Override
39+
public void setParent(BookScreen parent) {
40+
super.setParent(parent);
41+
iconRenderer.setParent(parent);
42+
}
43+
3744
@Override
3845
public void draw(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks, Font fontRenderer) {
3946
boolean unlocked = this.section.isUnlocked(this.parent.advancementCache);

0 commit comments

Comments
 (0)