-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add first iteration of custom block-renderers (#561)
- Loading branch information
Showing
15 changed files
with
239 additions
and
89 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
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
27 changes: 27 additions & 0 deletions
27
core/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/BlockRenderer.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,27 @@ | ||
package de.bluecolored.bluemap.core.map.hires.blockmodel; | ||
|
||
import de.bluecolored.bluemap.core.map.hires.TileModelView; | ||
import de.bluecolored.bluemap.core.resources.pack.resourcepack.blockstate.Variant; | ||
import de.bluecolored.bluemap.core.util.math.Color; | ||
import de.bluecolored.bluemap.core.world.block.BlockNeighborhood; | ||
|
||
public interface BlockRenderer { | ||
|
||
/** | ||
* Renders the given blocks (block-state-)variant into the given blockModel, and sets the given blockColor to the | ||
* color that represents the rendered block. | ||
* <p> | ||
* <b>Implementation Note:</b><br> | ||
* This method is guaranteed to be called only on <b>one thread per BlockRenderer instance</b>, so you can use this | ||
* for optimizations.<br> | ||
* Keep in mind this method will be called once for every block that is being rendered, so be very careful | ||
* about performance and instance-creations. | ||
* </p> | ||
* @param block The block information that should be rendered. | ||
* @param variant The block-state variant that should be rendered. | ||
* @param blockModel The model(-view) where the block should be rendered to. | ||
* @param blockColor The color that should be set to the color that represents the rendered block. | ||
*/ | ||
void render(BlockNeighborhood<?> block, Variant variant, TileModelView blockModel, Color blockColor); | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
.../src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/BlockRendererFactory.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,11 @@ | ||
package de.bluecolored.bluemap.core.map.hires.blockmodel; | ||
|
||
import de.bluecolored.bluemap.core.map.TextureGallery; | ||
import de.bluecolored.bluemap.core.map.hires.RenderSettings; | ||
import de.bluecolored.bluemap.core.resources.pack.resourcepack.ResourcePack; | ||
|
||
public interface BlockRendererFactory { | ||
|
||
BlockRenderer create(ResourcePack resourcePack, TextureGallery textureGallery, RenderSettings renderSettings); | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
core/src/main/java/de/bluecolored/bluemap/core/map/hires/blockmodel/BlockRendererType.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,56 @@ | ||
package de.bluecolored.bluemap.core.map.hires.blockmodel; | ||
|
||
import de.bluecolored.bluemap.core.map.TextureGallery; | ||
import de.bluecolored.bluemap.core.map.hires.RenderSettings; | ||
import de.bluecolored.bluemap.core.resources.pack.resourcepack.ResourcePack; | ||
import de.bluecolored.bluemap.core.util.Key; | ||
import de.bluecolored.bluemap.core.util.Keyed; | ||
import de.bluecolored.bluemap.core.util.Registry; | ||
import de.bluecolored.bluemap.core.world.BlockState; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
public interface BlockRendererType extends Keyed, BlockRendererFactory { | ||
|
||
BlockRendererType DEFAULT = new Impl(Key.bluemap("default"), ResourceModelRenderer::new); | ||
BlockRendererType LIQUID = new Impl(Key.bluemap("liquid"), LiquidModelRenderer::new); | ||
BlockRendererType MISSING = new Impl(Key.bluemap("missing"), MissingModelRenderer::new); | ||
|
||
Registry<BlockRendererType> REGISTRY = new Registry<>( | ||
DEFAULT, | ||
LIQUID, | ||
MISSING | ||
); | ||
|
||
/** | ||
* If the loaded resourcepack does not have any resources for this blockState, this method will be called. | ||
* If this method returns true, this renderer will be used to render the block instead of rendering the default | ||
* black-purple "missing block" model. | ||
* When rendering, the provided "variant" will always be bluemaps default "missing-block" resource. | ||
* | ||
* <p> | ||
* This can (and should only then) be used to provide a way of rendering blocks that are completely dynamically | ||
* created by a mod, and there is no way to provide static block-state resources that point at the correct renderer. | ||
* </p> | ||
* | ||
* @param blockState The {@link BlockState} that was not found in the loaded resources. | ||
* @return true if this renderer-type can render the provided {@link BlockState} despite missing resources. | ||
*/ | ||
default boolean isFallbackFor(BlockState blockState) { | ||
return false; | ||
} | ||
|
||
@RequiredArgsConstructor | ||
class Impl implements BlockRendererType { | ||
|
||
@Getter private final Key key; | ||
private final BlockRendererFactory rendererFactory; | ||
|
||
@Override | ||
public BlockRenderer create(ResourcePack resourcePack, TextureGallery textureGallery, RenderSettings renderSettings) { | ||
return rendererFactory.create(resourcePack, textureGallery, renderSettings); | ||
} | ||
|
||
} | ||
|
||
} |
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
Oops, something went wrong.