generated from TropheusJ/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/1.20.1' into 1.20.1
- Loading branch information
Showing
8 changed files
with
100 additions
and
10 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...rc/main/java/io/github/fabricators_of_create/porting_lib/models/CustomBlendModeModel.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,54 @@ | ||
package io.github.fabricators_of_create.porting_lib.models; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import net.fabricmc.fabric.api.renderer.v1.Renderer; | ||
import net.fabricmc.fabric.api.renderer.v1.RendererAccess; | ||
import net.fabricmc.fabric.api.renderer.v1.material.BlendMode; | ||
import net.fabricmc.fabric.api.renderer.v1.material.MaterialFinder; | ||
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; | ||
import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel; | ||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; | ||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext.QuadTransform; | ||
import net.minecraft.client.resources.model.BakedModel; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.BlockAndTintGetter; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
public class CustomBlendModeModel extends ForwardingBakedModel { | ||
private final QuadTransform transform; | ||
|
||
|
||
public CustomBlendModeModel(BakedModel owner, BlendMode blendMode) { | ||
this.wrapped = owner; | ||
|
||
Renderer renderer = RendererAccess.INSTANCE.getRenderer(); | ||
MaterialFinder finder = renderer == null ? null : renderer.materialFinder(); | ||
this.transform = finder == null ? quad -> true : quad -> { | ||
RenderMaterial newMaterial = finder.copyFrom(quad.material()).blendMode(blendMode).find(); | ||
quad.material(newMaterial); | ||
return true; | ||
}; | ||
} | ||
|
||
@Override | ||
public boolean isVanillaAdapter() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void emitBlockQuads(BlockAndTintGetter blockView, BlockState state, BlockPos pos, Supplier<RandomSource> randomSupplier, RenderContext context) { | ||
context.pushTransform(this.transform); | ||
super.emitBlockQuads(blockView, state, pos, randomSupplier, context); | ||
context.popTransform(); | ||
} | ||
|
||
@Override | ||
public void emitItemQuads(ItemStack stack, Supplier<RandomSource> randomSupplier, RenderContext context) { | ||
context.pushTransform(this.transform); | ||
super.emitItemQuads(stack, randomSupplier, context); | ||
context.popTransform(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...a/io/github/fabricators_of_create/porting_lib/models/extensions/BlockModelExtensions.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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package io.github.fabricators_of_create.porting_lib.models.extensions; | ||
|
||
import net.fabricmc.fabric.api.renderer.v1.material.BlendMode; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; | ||
|
||
@ApiStatus.Internal | ||
public interface BlockModelExtensions { | ||
void port_lib$setRenderMaterial(RenderMaterial material); | ||
void port_lib$setBlendMode(BlendMode blendMode); | ||
} |
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
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
7 changes: 7 additions & 0 deletions
7
modules/models/src/testmod/resources/assets/porting_lib/blockstates/not_glass.json
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,7 @@ | ||
{ | ||
"variants": { | ||
"": { | ||
"model": "porting_lib:block/not_glass" | ||
} | ||
} | ||
} |
4 changes: 3 additions & 1 deletion
4
modules/models/src/testmod/resources/assets/porting_lib/lang/en_us.json
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{ | ||
"item.porting_lib.derp_helmet": "Derpy Helmet" | ||
"item.porting_lib.derp_helmet": "Derpy Helmet", | ||
"item.porting_lib.stone_2": "Stone 2", | ||
"block.porting_lib.not_glass": "Not Glass" | ||
} |
7 changes: 7 additions & 0 deletions
7
modules/models/src/testmod/resources/assets/porting_lib/models/block/not_glass.json
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,7 @@ | ||
{ | ||
"parent": "minecraft:block/cube_all", | ||
"textures": { | ||
"all": "minecraft:block/glass" | ||
}, | ||
"render_type": "cutout" | ||
} |