Skip to content

Commit

Permalink
feat: Improve printer fancy rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Jan 1, 2024
1 parent 00e0f70 commit 2e05728
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

public class ForbiddenSmoothies {

// TODO fancy in-world rendering for printer
// TODO better textures for the models

// TODO Slightly different blender UI?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.blay09.mods.forbiddensmoothies.block;

import com.google.common.collect.ImmutableMap;
import net.blay09.mods.balm.api.Balm;
import net.blay09.mods.balm.api.container.BalmContainerProvider;
import net.blay09.mods.forbiddensmoothies.block.entity.ModBlockEntities;
Expand Down Expand Up @@ -33,8 +32,6 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;

import java.util.function.Function;

public class PrinterBlock extends BaseEntityBlock {

private static final EnumProperty<Direction> FACING = BlockStateProperties.HORIZONTAL_FACING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ public void load(CompoundTag tag) {
if (tag.contains("CurrentResultItem")) {
currentResultItem = ItemStack.of(tag.getCompound("CurrentResultItem"));
}

energyCostPerTick = tag.getInt("EnergyCostPerTick");
}

protected void saveAdditional(CompoundTag tag) {
Expand All @@ -183,6 +185,7 @@ protected void saveAdditional(CompoundTag tag) {
@Override
protected void writeUpdateTag(CompoundTag tag) {
tag.put("CurrentResultItem", currentResultItem.save(new CompoundTag()));
tag.putInt("EnergyCostPerTick", energyCostPerTick);
}

@Override
Expand Down Expand Up @@ -297,7 +300,7 @@ public void setChanged() {
}

public float animate(float partialTicks) {
if (energyCostPerTick > 0 || true) {
if (energyCostPerTick > 0) {
animationTime += partialTicks;
}
return animationTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.blay09.mods.forbiddensmoothies.ForbiddenSmoothiesConfig;
import net.blay09.mods.forbiddensmoothies.block.CustomBlockStateProperties;
import net.blay09.mods.forbiddensmoothies.block.entity.PrinterBlockEntity;
import net.blay09.mods.forbiddensmoothies.client.ModModels;
Expand Down Expand Up @@ -75,11 +76,16 @@ public void render(PrinterBlockEntity blockEntity, float partialTicks, PoseStack
0);
poseStack.popPose();

final var animationTime = blockEntity.animate(partialTicks);
final var scaledAnimationTime = animationTime * 2;

final var itemStack = blockEntity.getCurrentResultItem();
poseStack.pushPose();
poseStack.translate(0.5f, 0f, 0.5f);
final var itemScale = 0.3f;
poseStack.translate(-0.08f, 0.43f, 0.115f);
poseStack.translate(-0.08f, 0.43f, 0.116f);
final var maxTime = ForbiddenSmoothiesConfig.getActive().printer.processingTicks + 20;
poseStack.translate(0f, 0, -(animationTime % maxTime) / (float) maxTime * 0.003f);
poseStack.mulPose(new Quaternionf(new AxisAngle4f((float) Math.toRadians(22.5f), 1f, 0f, 0f)));
poseStack.scale(itemScale, itemScale, 0.1f);
final var itemRenderer = Minecraft.getInstance().getItemRenderer();
Expand All @@ -88,27 +94,25 @@ public void render(PrinterBlockEntity blockEntity, float partialTicks, PoseStack
itemRenderer.render(itemStack, ItemDisplayContext.FIXED, false, poseStack, buffer, combinedLight, combinedOverlay, model);
poseStack.popPose();

final var animationTime = blockEntity.animate(partialTicks);

poseStack.pushPose();
poseStack.translate(0.5f, 0f, 0.5f);
poseStack.mulPose(new Quaternionf(new AxisAngle4f((float) Math.toRadians(180), 1f, 0f, 0f)));
poseStack.mulPose(new Quaternionf(new AxisAngle4f((float) Math.toRadians(120), 0f, 1f, 0f)));
poseStack.translate(-0.2f, -0.95f, 0.1f);
poseStack.mulPose(new Quaternionf(new AxisAngle4f((float) Math.toRadians(100), 0f, 1f, 0f)));
poseStack.translate(-0.2f, -0.95f, 0.18f);
final var humanScale = 0.55f;
poseStack.scale(humanScale, humanScale, humanScale);
final GameProfile gameProfile = null; // TODO
final var profileTexture = getPlayerSkin(gameProfile).orElse(null);
final var playerModel = getPlayerModel(profileTexture);
final var skinTexture = getPlayerSkinTexture(profileTexture);
playerModel.animate(animationTime);
playerModel.animate(scaledAnimationTime);
playerModel.renderToBuffer(poseStack, buffer.getBuffer(RenderType.entitySolid(skinTexture)), combinedLight, combinedOverlay, 1f, 1f, 1f, 1f);
poseStack.popPose();

poseStack.pushPose();
final var handItemScale = 0.3f;
poseStack.translate(0.5f, 0f, 0.5f);
poseStack.translate(-0.08f, 0.4f, 0.06f);
poseStack.translate(0.025f, 0.4f, 0.06f);
poseStack.mulPose(Axis.ZP.rotationDegrees(45f));
poseStack.mulPose(Axis.YP.rotation(0.1f));
final var originX = 0.1f;
Expand All @@ -117,7 +121,7 @@ public void render(PrinterBlockEntity blockEntity, float partialTicks, PoseStack
poseStack.mulPose(Axis.YN.rotationDegrees(10));
poseStack.mulPose(Axis.XP.rotationDegrees(15));
poseStack.translate(originX, originY, originZ);
poseStack.mulPose(Axis.ZP.rotation((float) (-Math.sin(animationTime / 20f) * 0.5f - Math.toRadians(30f))));
poseStack.mulPose(Axis.ZP.rotation((float) (-Math.sin(scaledAnimationTime / 20f) * 0.5f - Math.toRadians(30f))));
poseStack.translate(-originX, -originY, -originZ);
poseStack.scale(handItemScale, handItemScale, handItemScale);
final var handItem = new ItemStack(Items.BRUSH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,78 @@
"up": {"uv": [0, 0, 7, 1], "texture": "#0"},
"down": {"uv": [0, 0, 7, 1], "texture": "#0"}
}
},
{
"name": "overlay",
"from": [4, 10.5, 4.995],
"to": [11, 11, 5],
"rotation": {"angle": 22.5, "axis": "x", "origin": [0, 0, 0]},
"faces": {
"north": {"uv": [0, 2, 7, 3], "texture": "#0"}
}
},
{
"name": "overlay",
"from": [4, 10, 4.99],
"to": [11, 10.5, 5],
"rotation": {"angle": 22.5, "axis": "x", "origin": [0, 0, 0]},
"faces": {
"north": {"uv": [0, 2, 7, 3], "texture": "#0"}
}
},
{
"name": "overlay",
"from": [4, 9.5, 4.985],
"to": [11, 10, 5],
"rotation": {"angle": 22.5, "axis": "x", "origin": [0, 0, 0]},
"faces": {
"north": {"uv": [0, 3, 7, 4], "texture": "#0"}
}
},
{
"name": "overlay",
"from": [4, 9, 4.98],
"to": [11, 9.5, 5],
"rotation": {"angle": 22.5, "axis": "x", "origin": [0, 0, 0]},
"faces": {
"north": {"uv": [0, 3, 7, 4], "texture": "#0"}
}
},
{
"name": "overlay",
"from": [4, 8.5, 4.975],
"to": [11, 9, 5],
"rotation": {"angle": 22.5, "axis": "x", "origin": [0, 0, 0]},
"faces": {
"north": {"uv": [0, 3, 7, 4], "texture": "#0"}
}
},
{
"name": "overlay",
"from": [4, 8, 4.97],
"to": [11, 8.5, 5],
"rotation": {"angle": 22.5, "axis": "x", "origin": [0, 0, 0]},
"faces": {
"north": {"uv": [0, 4, 7, 5], "texture": "#0"}
}
},
{
"name": "overlay",
"from": [4, 7.5, 4.965],
"to": [11, 8, 5],
"rotation": {"angle": 22.5, "axis": "x", "origin": [0, 0, 0]},
"faces": {
"north": {"uv": [0, 6, 7, 7], "texture": "#0"}
}
},
{
"name": "overlay",
"from": [4, 7, 4.96],
"to": [11, 7.5, 5],
"rotation": {"angle": 22.5, "axis": "x", "origin": [0, 0, 0]},
"faces": {
"north": {"uv": [0, 6, 7, 7], "texture": "#0"}
}
}
]
}

0 comments on commit 2e05728

Please sign in to comment.