Skip to content

Commit

Permalink
feat: Add a blade inside the blender
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Dec 31, 2023
1 parent 318f512 commit 679a949
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public RenderShape getRenderShape(BlockState state) {

@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
return defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
return defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(UGLY, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public class ForbiddenSmoothiesClient {
public static void initialize() {
ModRenderers.initialize(BalmClient.getRenderers());
ModScreens.initialize(BalmClient.getScreens());
ModModels.initialize(BalmClient.getModels());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.blay09.mods.forbiddensmoothies.client;

import net.blay09.mods.balm.api.DeferredObject;
import net.blay09.mods.balm.api.client.rendering.BalmModels;
import net.blay09.mods.forbiddensmoothies.ForbiddenSmoothies;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.resources.ResourceLocation;

public class ModModels {
public static DeferredObject<BakedModel> blenderBlade;

public static void initialize(BalmModels models) {
blenderBlade = models.loadModel(id("block/blender_blade"));
}

private static ResourceLocation id(String path) {
return new ResourceLocation(ForbiddenSmoothies.MOD_ID, path);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,30 @@
import com.mojang.blaze3d.vertex.PoseStack;
import net.blay09.mods.forbiddensmoothies.block.CustomBlockStateProperties;
import net.blay09.mods.forbiddensmoothies.block.entity.BlenderBlockEntity;
import net.blay09.mods.forbiddensmoothies.client.ModModels;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.util.RandomSource;
import org.joml.AxisAngle4f;
import org.joml.Quaternionf;

public class BlenderRenderer implements BlockEntityRenderer<BlenderBlockEntity> {

private static final RandomSource random = RandomSource.create();

public BlenderRenderer(BlockEntityRendererProvider.Context context) {
}

@Override
public void render(BlenderBlockEntity blockEntity, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int combinedLight, int combinedOverlayIn) {
final var level = blockEntity.getLevel();
if (level == null) {
return;
}

final var state = blockEntity.getBlockState();
if (state.hasProperty(CustomBlockStateProperties.UGLY) && state.getValue(CustomBlockStateProperties.UGLY)) {
return;
Expand Down Expand Up @@ -53,6 +64,25 @@ public void render(BlenderBlockEntity blockEntity, float partialTicks, PoseStack
poseStack.popPose();
}
poseStack.popPose();

final var dispatcher = Minecraft.getInstance().getBlockRenderer();
poseStack.pushPose();
final var speedBlade = 0.5f;
poseStack.translate(0.5f, 0, 0.5f);
poseStack.mulPose(new Quaternionf(new AxisAngle4f(animationTime * speedBlade, 0f, 1f, 0f)));
poseStack.translate(-0.5f, 0, -0.5f);
dispatcher.getModelRenderer()
.tesselateBlock(level,
ModModels.blenderBlade.get(),
blockEntity.getBlockState(),
blockEntity.getBlockPos(),
poseStack,
buffer.getBuffer(RenderType.solid()),
false,
random,
0,
0);
poseStack.popPose();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"credit": "Made with Blockbench",
"parent": "block/block",
"render_type": "cutout",
"textures": {
"1": "forbiddensmoothies:block/blender_frame",
"particle": "forbiddensmoothies:block/blender_frame"
},
"elements": [
{
"name": "blade",
"from": [7.5, 2, 7.5],
"to": [8.5, 14, 8.5],
"faces": {
"north": {"uv": [0, 2, 1, 14], "texture": "#1"},
"east": {"uv": [0, 2, 1, 14], "texture": "#1"},
"south": {"uv": [0, 2, 1, 14], "texture": "#1"},
"west": {"uv": [0, 2, 1, 14], "texture": "#1"},
"up": {"uv": [0, 13, 1, 14], "texture": "#1"},
"down": {"uv": [0, 2, 1, 3], "texture": "#1"}
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 679a949

Please sign in to comment.