forked from MoriyaShiine/aylyth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When sodium has support for the renderer api, this can be enabled and the block entity renderer can be scrapped. Since the model is completely static, we can bake it to the chunk mesh rather than upload every frame
- Loading branch information
Showing
3 changed files
with
79 additions
and
4 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
67 changes: 67 additions & 0 deletions
67
src/client/java/moriyashiine/aylyth/client/model/block/SoulHearthBlockModel.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,67 @@ | ||
package moriyashiine.aylyth.client.model.block; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import moriyashiine.aylyth.common.block.SoulHearthBlock; | ||
import moriyashiine.aylyth.common.registry.ModBlocks; | ||
import moriyashiine.aylyth.common.registry.ModItems; | ||
import moriyashiine.aylyth.common.util.AylythUtil; | ||
import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel; | ||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.enums.DoubleBlockHalf; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.render.model.BakedModel; | ||
import net.minecraft.client.util.ModelIdentifier; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.RotationAxis; | ||
import net.minecraft.util.math.random.Random; | ||
import net.minecraft.world.BlockRenderView; | ||
import org.joml.Vector3f; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class SoulHearthBlockModel extends ForwardingBakedModel { | ||
|
||
public SoulHearthBlockModel(BakedModel model) { | ||
this.wrapped = model; | ||
} | ||
|
||
@Override | ||
public boolean isVanillaAdapter() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) { | ||
super.emitBlockQuads(blockView, state, pos, randomSupplier, context); | ||
if (state.isOf(ModBlocks.SOUL_HEARTH) && state.get(SoulHearthBlock.HALF) == DoubleBlockHalf.LOWER) { | ||
BakedModel model = MinecraftClient.getInstance().getBakedModelManager().getModel(new ModelIdentifier(AylythUtil.id("pomegranate"), "inventory")); | ||
MatrixStack stack = new MatrixStack(); | ||
stack.push(); | ||
float scale = 0.4f; | ||
stack.scale(scale, scale, scale); | ||
stack.translate(0.3/scale, 0.75/scale, 0.3/scale); | ||
for (int i = 0; i < state.get(SoulHearthBlock.CHARGES); i++) { | ||
stack.translate(0, 0.06, 0); | ||
stack.push(); | ||
stack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(90)); | ||
stack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(90 * i), 0.5f, 0.5f, 0.5f); | ||
context.pushTransform(quad -> { | ||
Vector3f posVec = new Vector3f(); | ||
for (int j = 0; j < 4; j++) { | ||
quad.copyPos(j, posVec); | ||
posVec.mulProject(stack.peek().getPositionMatrix()); | ||
quad.pos(j, posVec); | ||
} | ||
return true; | ||
}); | ||
model.emitItemQuads(new ItemStack(ModItems.POMEGRANATE), randomSupplier, context); | ||
context.popTransform(); | ||
stack.pop(); | ||
} | ||
stack.pop(); | ||
} | ||
} | ||
} |
4 changes: 0 additions & 4 deletions
4
src/client/java/moriyashiine/aylyth/client/util/RenderUtils.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