Skip to content

Commit

Permalink
Simplify book model
Browse files Browse the repository at this point in the history
  • Loading branch information
Minecraftschurli committed Aug 24, 2024
1 parent f0df654 commit 7e1ccf5
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public void onInitializeClient() {
PatchouliItems.BOOK_ID.equals(ctx.topLevelId().id()) // checks namespace and path
&& ctx.topLevelId().getVariant().equals("inventory")
&& oldModel != null) {
return new BookModel(oldModel, ctx.loader(), (model) -> {
return Minecraft.getInstance().getModelManager().getModel(model);
});
return new BookModel(oldModel, (model) -> Minecraft.getInstance().getModelManager().getModel(model));
}
return oldModel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ public static void onInitializeClient(FMLClientSetupEvent evt) {
@SubscribeEvent
public static void replaceBookModel(ModelEvent.ModifyBakingResult evt) {
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);
}));
evt.getModels().computeIfPresent(key, (k, oldModel) -> new BookModel(oldModel, (model) -> Minecraft.getInstance().getModelManager().getModel(ModelResourceLocation.standalone(model))));
}
}
72 changes: 36 additions & 36 deletions Xplat/src/main/java/vazkii/patchouli/client/base/BookModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.renderer.block.model.ItemOverrides;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
Expand All @@ -16,7 +15,6 @@

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,42 +27,10 @@ public class BookModel implements BakedModel {
private final BakedModel original;
private final ItemOverrides itemHandler;

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

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

// 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;
}

@Nullable
@Override
public BakedModel bake(ResourceLocation resourceLocation, ModelState modelState) {
return null;
}
}, missing, Collections.emptyList()) {
this.itemHandler = new ItemOverrides(DummyModelBaker.INSTANCE, null, Collections.emptyList()) {
@Override
public BakedModel resolve(@NotNull BakedModel original, @NotNull ItemStack stack,
@Nullable ClientLevel world, @Nullable LivingEntity entity, int seed) {
Expand Down Expand Up @@ -119,4 +85,38 @@ public TextureAtlasSprite getParticleIcon() {
public ItemTransforms getTransforms() {
return original.getTransforms();
}

private static class DummyModelBaker implements ModelBaker {
static ModelBaker INSTANCE = new DummyModelBaker();
// soft implement IModelBakerExtension
public Function<Material, TextureAtlasSprite> getModelTextureGetter() {
return null;
}

// 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;
}

@Nullable
@Override
public BakedModel bake(ResourceLocation resourceLocation, ModelState modelState) {
return null;
}
}
}

This file was deleted.

1 change: 0 additions & 1 deletion Xplat/src/main/resources/patchouli_xplat.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"client": [
"client.AccessorClientAdvancements",
"client.AccessorKeyMapping",
"client.AccessorModelBakery",
"client.AccessorMultiBufferSource",
"client.AccessorScreen",
"client.MixinClientAdvancements",
Expand Down

0 comments on commit 7e1ccf5

Please sign in to comment.