Skip to content

Commit

Permalink
add display case BER
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabeHunger54 committed Dec 28, 2023
1 parent 2677a78 commit 44e123d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.minecraftschurlimods.bibliocraft.client;

import com.github.minecraftschurlimods.bibliocraft.Bibliocraft;
import com.github.minecraftschurlimods.bibliocraft.client.ber.DisplayCaseBER;
import com.github.minecraftschurlimods.bibliocraft.client.ber.FancyArmorStandBER;
import com.github.minecraftschurlimods.bibliocraft.client.ber.PotionShelfBER;
import com.github.minecraftschurlimods.bibliocraft.client.ber.ShelfBER;
Expand Down Expand Up @@ -50,6 +51,7 @@ static void registerGeometryLoaders(ModelEvent.RegisterGeometryLoaders event) {
@SubscribeEvent
static void registerRenderers(EntityRenderersEvent.RegisterRenderers event) {
event.registerEntityRenderer(BCEntities.FANCY_ARMOR_STAND.get(), ArmorStandRenderer::new);
event.registerBlockEntityRenderer(BCBlockEntities.DISPLAY_CASE.get(), DisplayCaseBER::new);
event.registerBlockEntityRenderer(BCBlockEntities.FANCY_ARMOR_STAND.get(), FancyArmorStandBER::new);
event.registerBlockEntityRenderer(BCBlockEntities.POTION_SHELF.get(), PotionShelfBER::new);
event.registerBlockEntityRenderer(BCBlockEntities.SHELF.get(), ShelfBER::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.github.minecraftschurlimods.bibliocraft.client.ber;

import com.github.minecraftschurlimods.bibliocraft.content.displaycase.DisplayCaseBlock;
import com.github.minecraftschurlimods.bibliocraft.content.displaycase.DisplayCaseBlockEntity;
import com.github.minecraftschurlimods.bibliocraft.content.displaycase.WallDisplayCaseBlock;
import com.github.minecraftschurlimods.bibliocraft.util.ClientUtil;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;

public class DisplayCaseBER implements BlockEntityRenderer<DisplayCaseBlockEntity> {
@SuppressWarnings("unused")
public DisplayCaseBER(BlockEntityRendererProvider.Context context) {
}

@Override
public void render(DisplayCaseBlockEntity blockEntity, float partialTick, PoseStack stack, MultiBufferSource buffer, int light, int overlay) {
stack.pushPose();
ClientUtil.setupCenteredBER(stack, blockEntity);
Block block = blockEntity.getBlockState().getBlock();
if (block instanceof WallDisplayCaseBlock) {
stack.mulPose(Axis.YP.rotationDegrees(180));
} else if (block instanceof DisplayCaseBlock) {
stack.mulPose(Axis.XP.rotationDegrees(90));
stack.mulPose(Axis.ZP.rotationDegrees(180));
}
stack.translate(0, 0, 0.25f);
stack.scale(0.5f, 0.5f, 0.5f);
ItemRenderer renderer = Minecraft.getInstance().getItemRenderer();
ItemStack item = blockEntity.getItem(0);
renderer.render(item, ItemDisplayContext.FIXED, false, stack, buffer, light, overlay, renderer.getModel(item, blockEntity.getLevel(), null, 0));
stack.popPose();
}
}

0 comments on commit 44e123d

Please sign in to comment.