Skip to content

Commit

Permalink
Fix ModelEvent.RegisterAdditional and BakedModelRenderable
Browse files Browse the repository at this point in the history
  • Loading branch information
XFactHD committed Jun 10, 2024
1 parent 66909ae commit 44ce5d3
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
--- a/net/minecraft/client/resources/model/ModelBakery.java
+++ b/net/minecraft/client/resources/model/ModelBakery.java
@@ -117,6 +_,14 @@
@@ -117,6 +_,13 @@
p_252014_.popPush("special");
this.loadSpecialItemModelAndDependencies(ItemRenderer.TRIDENT_IN_HAND_MODEL);
this.loadSpecialItemModelAndDependencies(ItemRenderer.SPYGLASS_IN_HAND_MODEL);
+ Set<ResourceLocation> additionalModels = new HashSet<>();
+ Set<ModelResourceLocation> additionalModels = new HashSet<>();
+ net.neoforged.neoforge.client.ClientHooks.onRegisterAdditionalModels(additionalModels);
+ for (ResourceLocation rl : additionalModels) {
+ UnbakedModel unbakedmodel = this.getModel(rl); // loadTopLevel(...), but w/o ModelResourceLocation limitation
+ this.unbakedCache.put(rl, unbakedmodel);
+ // TODO 1.21 - Port model loading to handle MRLs
+ //this.topLevelModels.put(rl, unbakedmodel);
+ for (ModelResourceLocation rl : additionalModels) {
+ UnbakedModel unbakedmodel = this.getModel(rl.id());
+ this.unbakedCache.put(rl.id(), unbakedmodel);
+ this.topLevelModels.put(rl, unbakedmodel);
+ }
this.topLevelModels.values().forEach(p_247954_ -> p_247954_.resolveParents(this::getModel));
p_252014_.pop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@

public ModelManager(TextureManager p_119406_, BlockColors p_119407_, int p_119408_) {
this.blockColors = p_119407_;
@@ -78,6 +_,10 @@
this.atlases = new AtlasSet(VANILLA_ATLASES, p_119406_);
}

+ public BakedModel getModel(ResourceLocation modelLocation) {
+ return this.bakedRegistry.getOrDefault(modelLocation, this.missingModel);
+ }
+
public BakedModel getModel(ModelResourceLocation p_119423_) {
return this.bakedRegistry.getOrDefault(p_119423_, this.missingModel);
}
@@ -100,6 +_,7 @@
Executor p_249221_
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ public static void onRegisterKeyMappings(Options options) {
ModLoader.postEvent(new RegisterKeyMappingsEvent(options));
}

public static void onRegisterAdditionalModels(Set<ResourceLocation> additionalModels) {
public static void onRegisterAdditionalModels(Set<ModelResourceLocation> additionalModels) {
ModLoader.postEvent(new ModelEvent.RegisterAdditional(additionalModels));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,17 @@ public ModelBakery getModelBakery() {
* <p>This event is fired on the mod-specific event bus, only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
*/
public static class RegisterAdditional extends ModelEvent implements IModBusEvent {
private final Set<ResourceLocation> models;
private final Set<ModelResourceLocation> models;

@ApiStatus.Internal
public RegisterAdditional(Set<ResourceLocation> models) {
public RegisterAdditional(Set<ModelResourceLocation> models) {
this.models = models;
}

/**
* Registers a model to be loaded, along with its dependencies.
*/
public void register(ResourceLocation model) {
public void register(ModelResourceLocation model) {
models.add(model);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import net.minecraft.util.Unit;
import net.minecraft.world.inventory.InventoryMenu;
Expand All @@ -37,7 +37,7 @@ public class BakedModelRenderable implements IRenderable<BakedModelRenderable.Co
*
* @see ModelEvent.RegisterAdditional
*/
public static BakedModelRenderable of(ResourceLocation model) {
public static BakedModelRenderable of(ModelResourceLocation model) {
return of(Minecraft.getInstance().getModelManager().getModel(model));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
Expand Down Expand Up @@ -55,7 +56,7 @@ public class RenderableTest {
public static final String MODID = "renderable_test";
private static final Logger LOGGER = LogManager.getLogger();

public static final boolean ENABLED = false; // Renders at (0, 120, 0)
public static final boolean ENABLED = true; // Renders at (0, 120, 0)

public RenderableTest(IEventBus modEventBus) {
if (ENABLED) {
Expand All @@ -66,7 +67,9 @@ public RenderableTest(IEventBus modEventBus) {
}

private static class Client {
private static ResourceLocation MODEL_LOC = ResourceLocation.fromNamespaceAndPath("minecraft", "block/blue_stained_glass");
private static ModelResourceLocation MODEL_LOC = new ModelResourceLocation(
ResourceLocation.fromNamespaceAndPath("minecraft", "block/blue_stained_glass"),
"");

private static IRenderable<CompositeRenderable.Transforms> renderable;
private static IRenderable<ModelData> bakedRenderable;
Expand Down

0 comments on commit 44ce5d3

Please sign in to comment.