Skip to content

Commit

Permalink
Update to 1.21 (#753)
Browse files Browse the repository at this point in the history
* Port from 1.20.6 to 1.21

* Update build number

* Fix jenkinsfile targeting invalid jdk

* Update NeoForge, Fabric and JEI

* Fix creative mode inventory crash

* Remove need to specify item/ prefix on model

---------

Co-authored-by: Minecraftschurli <[email protected]>
  • Loading branch information
Mrbysco and Minecraftschurli authored Jul 19, 2024
1 parent a62f3fb commit 0e367b2
Show file tree
Hide file tree
Showing 58 changed files with 212 additions and 186 deletions.
6 changes: 3 additions & 3 deletions Fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ dependencies {
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:0.15.11"

modImplementation "net.fabricmc.fabric-api:fabric-api:0.100.0+1.20.6"
modImplementation "net.fabricmc.fabric-api:fabric-api:0.100.7+1.21"
compileOnly project(":Xplat")

modCompileOnly "mezz.jei:jei-1.20.6-common-api:18.0.0.62"
modCompileOnly "mezz.jei:jei-1.21-common-api:19.1.1.19"

modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-fabric:16.0.729") { transitive = false }
modCompileOnly("me.shedaniel.cloth:cloth-config-fabric:14.0.126") { transitive = false }
modCompileOnly("me.shedaniel.cloth:cloth-config-fabric:15.0.127") { transitive = false }
}

compileJava {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin;
import net.fabricmc.fabric.api.client.model.loading.v1.ModelModifier;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
Expand All @@ -12,8 +11,6 @@
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.item.ItemProperties;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.resources.ResourceManager;
Expand All @@ -36,8 +33,6 @@
import vazkii.patchouli.network.MessageOpenBookGui;
import vazkii.patchouli.network.MessageReloadBookContents;

import org.jetbrains.annotations.Nullable;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

Expand All @@ -57,28 +52,31 @@ public void onInitializeClient() {

ModelLoadingPlugin.register(pluginContext -> {
for (Book book : BookRegistry.INSTANCE.books.values()) {
pluginContext.addModels(new ModelResourceLocation(book.model, "inventory"));
PatchouliAPI.LOGGER.info("Adding model {}", book.model);
pluginContext.addModels(book.model);
}

pluginContext.modifyModelAfterBake().register(
(@Nullable BakedModel oldModel, ModelModifier.AfterBake.Context ctx) -> {
if (ctx.id() instanceof ModelResourceLocation key
&& PatchouliItems.BOOK_ID.equals(key) // checks namespace and path
&& key.getVariant().equals("inventory")
(oldModel, ctx) -> {
if (ctx.topLevelId() != null &&
PatchouliItems.BOOK_ID.equals(ctx.topLevelId().id()) // checks namespace and path
&& ctx.topLevelId().getVariant().equals("inventory")
&& oldModel != null) {
return new BookModel(oldModel, ctx.loader());
return new BookModel(oldModel, ctx.loader(), (model) -> {
return Minecraft.getInstance().getModelManager().getModel(model);
});
}
return oldModel;
}
);
});

ItemProperties.register(PatchouliItems.BOOK,
new ResourceLocation(PatchouliAPI.MOD_ID, "completion"),
ResourceLocation.fromNamespaceAndPath(PatchouliAPI.MOD_ID, "completion"),
(stack, world, entity, seed) -> ItemModBook.getCompletion(stack));

ResourceManagerHelper.get(PackType.CLIENT_RESOURCES).registerReloadListener(new IdentifiableResourceReloadListener() {
private static final ResourceLocation id = new ResourceLocation(PatchouliAPI.MOD_ID, "resource_pack_books");
private static final ResourceLocation id = ResourceLocation.fromNamespaceAndPath(PatchouliAPI.MOD_ID, "resource_pack_books");

@Override
public CompletableFuture<Void> reload(PreparationBarrier barrier, ResourceManager manager, ProfilerFiller preparationsProfiler, ProfilerFiller reloadProfiler, Executor backgroundExecutor, Executor gameExecutor) {
Expand All @@ -91,7 +89,7 @@ public ResourceLocation getFabricId() {
}
});
ResourceManagerHelper.get(PackType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
private static final ResourceLocation id = new ResourceLocation(PatchouliAPI.MOD_ID, "reload_hook");
private static final ResourceLocation id = ResourceLocation.fromNamespaceAndPath(PatchouliAPI.MOD_ID, "reload_hook");

@Override
public ResourceLocation getFabricId() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package vazkii.patchouli.mixin.client;

import net.minecraft.client.DeltaTracker;
import net.minecraft.client.renderer.GameRenderer;

import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -11,13 +12,13 @@

@Mixin(GameRenderer.class)
public class MixinGameRenderer {
@Inject(at = @At("HEAD"), method = "render(FJZ)V")
public void patchouli_renderStart(float tickDelta, long startTime, boolean tick, CallbackInfo info) {
ClientTicker.renderTickStart(tickDelta);
@Inject(at = @At("HEAD"), method = "render(Lnet/minecraft/client/DeltaTracker;Z)V")
public void patchouli_renderStart(DeltaTracker deltaTracker, boolean tick, CallbackInfo info) {
ClientTicker.renderTickStart(deltaTracker.getGameTimeDeltaPartialTick(false));
}

@Inject(at = @At("RETURN"), method = "render(FJZ)V")
public void patchouli_renderEnd(float tickDelta, long startTime, boolean tick, CallbackInfo info) {
@Inject(at = @At("RETURN"), method = "render(Lnet/minecraft/client/DeltaTracker;Z)V")
public void patchouli_renderEnd(DeltaTracker deltaTracker, boolean tick, CallbackInfo info) {
ClientTicker.renderTickEnd();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package vazkii.patchouli.mixin.client;

public class MixinModelBakery {
}
6 changes: 3 additions & 3 deletions Fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
],

"depends": {
"fabricloader": ">=0.15.10",
"fabric": ">=0.97.6",
"minecraft": ">=1.20.6 <1.21"
"fabricloader": ">=0.15.11",
"fabric": ">=0.100.3",
"minecraft": ">=1.21 <1.22"
}
}
6 changes: 3 additions & 3 deletions NeoForge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ runs {
}

dependencies {
implementation "net.neoforged:neoforge:20.6.115"
implementation "net.neoforged:neoforge:21.0.106-beta"
implementation project(":Xplat")

compileOnly "mezz.jei:jei-1.20.6-common-api:18.0.0.62"
testCompileOnly "mezz.jei:jei-1.20.6-common-api:18.0.0.62"
compileOnly "mezz.jei:jei-1.21-common-api:19.5.0.33"
testCompileOnly "mezz.jei:jei-1.21-common-api:19.5.0.33"
}

tasks.named('test').configure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ private static List<ResourceLocation> getBookModels() {
public static void modelRegistry(ModelEvent.RegisterAdditional e) {
getBookModels()
.stream()
.map(model -> new ModelResourceLocation(model, "inventory"))
.map(ModelResourceLocation::standalone)
.forEach(e::register);

ItemPropertyFunction prop = (stack, world, entity, seed) -> ItemModBook.getCompletion(stack);
ItemProperties.register(PatchouliItems.BOOK, new ResourceLocation(PatchouliAPI.MOD_ID, "completion"), prop);
ItemProperties.register(PatchouliItems.BOOK, ResourceLocation.fromNamespaceAndPath(PatchouliAPI.MOD_ID, "completion"), prop);
}

@SubscribeEvent
Expand All @@ -105,10 +105,10 @@ public static void registerReloadListeners(RegisterClientReloadListenersEvent e)

@SubscribeEvent
public static void registerOverlays(RegisterGuiLayersEvent evt) {
evt.registerAbove(VanillaGuiLayers.CROSSHAIR, new ResourceLocation(PatchouliAPI.MOD_ID, "book_overlay"),
evt.registerAbove(VanillaGuiLayers.CROSSHAIR, ResourceLocation.fromNamespaceAndPath(PatchouliAPI.MOD_ID, "book_overlay"),
BookRightClickHandler::onRenderHUD
);
evt.registerBelow(VanillaGuiLayers.BOSS_OVERLAY, new ResourceLocation(PatchouliAPI.MOD_ID, "multiblock_progress"),
evt.registerBelow(VanillaGuiLayers.BOSS_OVERLAY, ResourceLocation.fromNamespaceAndPath(PatchouliAPI.MOD_ID, "multiblock_progress"),
MultiblockVisualizationHandler::onRenderHUD
);
}
Expand All @@ -133,7 +133,7 @@ public static void onInitializeClient(FMLClientSetupEvent evt) {
});

NeoForge.EVENT_BUS.addListener((RenderFrameEvent.Pre e) -> {
ClientTicker.renderTickStart(e.getPartialTick());
ClientTicker.renderTickStart(e.getPartialTick().getGameTimeDeltaPartialTick(false));
});
NeoForge.EVENT_BUS.addListener((RenderFrameEvent.Post e) -> {
ClientTicker.renderTickEnd();
Expand All @@ -150,7 +150,10 @@ public static void onInitializeClient(FMLClientSetupEvent evt) {

@SubscribeEvent
public static void replaceBookModel(ModelEvent.ModifyBakingResult evt) {
ModelResourceLocation key = new ModelResourceLocation(PatchouliItems.BOOK_ID, "inventory");
evt.getModels().computeIfPresent(key, (k, oldModel) -> new BookModel(oldModel, evt.getModelBakery()));
ModelResourceLocation key = ModelResourceLocation.inventory(PatchouliItems.BOOK_ID);
evt.getModels().computeIfPresent(key, (k, oldModel) -> new BookModel(oldModel, evt.getModelBakery(), (model) -> {
ModelResourceLocation modelPath = ModelResourceLocation.standalone(model);
return Minecraft.getInstance().getModelManager().getModel(modelPath);
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ public static void processCreativeTabs(BuildCreativeModeTabContentsEvent evt) {
BookRegistry.INSTANCE.books.values().forEach(b -> {
if (!b.noBook) {
ItemStack book = ItemModBook.forBook(b);
if (evt.getTab() == CreativeModeTabs.searchTab()) {
evt.accept(book, CreativeModeTab.TabVisibility.SEARCH_TAB_ONLY);
if (evt.getTabKey() == CreativeModeTabs.SEARCH) {
if (!evt.getSearchEntries().contains(book)) {
evt.accept(book, CreativeModeTab.TabVisibility.SEARCH_TAB_ONLY);
}
} else if (b.creativeTab != null) {
if (evt.getTab() == CreativeModeTabRegistry.getTab(b.creativeTab)) {
evt.accept(book);
Expand Down
6 changes: 3 additions & 3 deletions NeoForge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
modLoader="javafml"
license="CC BY-NC-SA 3.0"
loaderVersion="[3,)"
loaderVersion="[4,)"
issueTrackerURL="https://github.com/VazkiiMods/Patchouli"
logoFile="logo.png"

Expand All @@ -16,12 +16,12 @@ Accessible, Data-Driven, Dependency-Free Documentation for Minecraft Modders and
[[dependencies.patchouli]]
modId="neoforge"
type="REQUIRED"
versionRange="[20.6.1-beta,)"
versionRange="[21.0.31-beta,)"

[[dependencies.patchouli]]
modId="minecraft"
type="REQUIRED"
versionRange="[1.20.6,1.21)"
versionRange="[1.21,1.22)"

[[mixins]]
config="patchouli_xplat.mixins.json"
2 changes: 1 addition & 1 deletion Xplat/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repositories {

dependencies {
compileOnly group: 'org.spongepowered', name: 'mixin', version: '0.8.5'
compileOnly "mezz.jei:jei-1.20.6-common-api:18.0.0.62"
compileOnly "mezz.jei:jei-1.21-common-api:19.1.1.19"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.1'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public IMultiblock setSymmetrical(boolean symmetrical) {

@Override
public ResourceLocation getID() {
return new ResourceLocation("patchouli", "stub");
return ResourceLocation.fromNamespaceAndPath("patchouli", "stub");
}

@Override
Expand Down
23 changes: 16 additions & 7 deletions Xplat/src/main/java/vazkii/patchouli/client/base/BookModel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package vazkii.patchouli.client.base;

import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.BlockModel;
Expand All @@ -17,6 +16,7 @@

import vazkii.patchouli.common.book.Book;
import vazkii.patchouli.common.item.ItemModBook;
import vazkii.patchouli.mixin.client.AccessorModelBakery;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -29,21 +29,31 @@ public class BookModel implements BakedModel {
private final BakedModel original;
private final ItemOverrides itemHandler;

public BookModel(BakedModel original, ModelBakery loader) {
public BookModel(BakedModel original, ModelBakery loader, Function<ResourceLocation, BakedModel> modelGetter) {
this.original = original;
BlockModel missing = (BlockModel) loader.getModel(ModelBakery.MISSING_MODEL_LOCATION);
BlockModel missing = (BlockModel) ((AccessorModelBakery) loader).invokeGetModel(ModelBakery.MISSING_MODEL_LOCATION);

this.itemHandler = new ItemOverrides(new ModelBaker() {
// soft implement IForgeModelBaker
// soft implement IModelBakerExtension
public Function<Material, TextureAtlasSprite> getModelTextureGetter() {
return null;
}

// soft implement IForgeModelBaker
// soft implement IModelBakerExtension
public BakedModel bake(ResourceLocation location, ModelState state, Function<Material, TextureAtlasSprite> sprites) {
return null;
}

// soft implement IModelBakerExtension
public BakedModel bakeUncached(UnbakedModel model, ModelState state, Function<Material, TextureAtlasSprite> sprites) {
return null;
}

// soft implement IModelBakerExtension
public UnbakedModel getTopLevelModel(ModelResourceLocation location) {
return null;
}

@Override
public UnbakedModel getModel(ResourceLocation resourceLocation) {
return null;
Expand All @@ -60,8 +70,7 @@ public BakedModel resolve(@NotNull BakedModel original, @NotNull ItemStack stack
@Nullable ClientLevel world, @Nullable LivingEntity entity, int seed) {
Book book = ItemModBook.getBook(stack);
if (book != null) {
ModelResourceLocation modelPath = new ModelResourceLocation(book.model, "inventory");
return Minecraft.getInstance().getModelManager().getModel(modelPath);
return modelGetter.apply(book.model);
}
return original;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static void sendBookToast(Book book) {
}

public static class LexiconToast implements Toast {
private static final ResourceLocation BACKGROUND_SPRITE = new ResourceLocation("toast/advancement");
private static final ResourceLocation BACKGROUND_SPRITE = ResourceLocation.withDefaultNamespace("toast/advancement");
private final Book book;

public LexiconToast(Book book) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public DataHolder(JsonObject root) {
var obj = GsonHelper.getAsJsonObject(root, "bookData", new JsonObject());

for (var e : obj.entrySet()) {
this.bookData.put(new ResourceLocation(e.getKey()), new BookData(e.getValue().getAsJsonObject()));
this.bookData.put(ResourceLocation.tryParse(e.getKey()), new BookData(e.getValue().getAsJsonObject()));
}
}

Expand Down Expand Up @@ -98,7 +98,7 @@ public Bookmark(ResourceLocation entry, int spread) {
}

public Bookmark(JsonObject root) {
this.entry = new ResourceLocation(GsonHelper.getAsString(root, "entry"));
this.entry = ResourceLocation.tryParse(GsonHelper.getAsString(root, "entry"));
this.spread = GsonHelper.getAsInt(root, "page"); // Serialized as page for legacy reasons
}

Expand All @@ -123,16 +123,16 @@ public static final class BookData {
public BookData(JsonObject root) {
var emptyArray = new JsonArray();
for (var e : GsonHelper.getAsJsonArray(root, "viewedEntries", emptyArray)) {
viewedEntries.add(new ResourceLocation(e.getAsString()));
viewedEntries.add(ResourceLocation.tryParse(e.getAsString()));
}
for (var e : GsonHelper.getAsJsonArray(root, "bookmarks", emptyArray)) {
bookmarks.add(new Bookmark(e.getAsJsonObject()));
}
for (var e : GsonHelper.getAsJsonArray(root, "history", emptyArray)) {
history.add(new ResourceLocation(e.getAsString()));
history.add(ResourceLocation.tryParse(e.getAsString()));
}
for (var e : GsonHelper.getAsJsonArray(root, "completedManualQuests", emptyArray)) {
completedManualQuests.add(new ResourceLocation(e.getAsString()));
completedManualQuests.add(ResourceLocation.tryParse(e.getAsString()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void build(BookContentsBuilder builder) {

if (!isRootCategory()) {
if (parent.contains(":")) {
var parentCat = builder.getCategory(new ResourceLocation(parent));
var parentCat = builder.getCategory(ResourceLocation.tryParse(parent));
if (parentCat == null) {
var msg = String.format("Category %s specifies parent %s, but it could not be found", id, parent);
throw new RuntimeException(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private ResourceLocation relativize(File root, File f) {
String filePath = f.getAbsolutePath().substring(rootPath.length() + 1);
String cleanPath = FilenameUtils.removeExtension(FilenameUtils.separatorsToUnix(filePath));

return new ResourceLocation(PatchouliAPI.MOD_ID, cleanPath);
return ResourceLocation.fromNamespaceAndPath(PatchouliAPI.MOD_ID, cleanPath);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void findFiles(Book book, String dir, List<ResourceLocation> list) {
if (newPath.startsWith("/")) {
newPath = newPath.substring(1);
}
return new ResourceLocation(file.getNamespace(), newPath);
return ResourceLocation.fromNamespaceAndPath(file.getNamespace(), newPath);
})
.forEach(list::add);
}
Expand Down
Loading

0 comments on commit 0e367b2

Please sign in to comment.