-
-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.21.4] Add event for registering custom special block model rendere…
…rs (#1777)
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...main/java/net/neoforged/neoforge/client/event/RegisterSpecialBlockModelRendererEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.client.event; | ||
|
||
import java.util.Map; | ||
import net.minecraft.client.renderer.special.SpecialModelRenderer; | ||
import net.minecraft.world.level.block.Block; | ||
import net.neoforged.bus.api.Event; | ||
import net.neoforged.fml.LogicalSide; | ||
import net.neoforged.fml.event.IModBusEvent; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
/** | ||
* Event fired when special block model renderers are created. | ||
* <p> | ||
* This event is fired on a worker thread during model loading. It is used to register custom special block model | ||
* renderers which handle dynamic rendering when the associated block is rendered in a non-placed context such | ||
* as in a minecart, a display entity or the Enderman's hands. | ||
* <p> | ||
* This event is fired on the mod-specific event bus, only on the {@linkplain LogicalSide#CLIENT logical client}. | ||
*/ | ||
public class RegisterSpecialBlockModelRendererEvent extends Event implements IModBusEvent { | ||
private final Map<Block, SpecialModelRenderer.Unbaked> renderers; | ||
|
||
@ApiStatus.Internal | ||
public RegisterSpecialBlockModelRendererEvent(Map<Block, SpecialModelRenderer.Unbaked> renderers) { | ||
this.renderers = renderers; | ||
} | ||
|
||
public void register(Block block, SpecialModelRenderer.Unbaked unbakedRenderer) { | ||
SpecialModelRenderer.Unbaked prev = this.renderers.putIfAbsent(block, unbakedRenderer); | ||
if (prev != null) { | ||
throw new IllegalStateException("Duplicate block model renderer registration for " + block); | ||
} | ||
} | ||
} |