hello guys
I'm trying to render blockentity,it works,but seem too dark in world.
I have read botania code to comparison my code,but I got no idea
here is game picture
https://pic.jitudisk.com/public/2022/06/16/5b537605e5e76.png
here is my code
package cn.tohsaka.factory.rotationcraft.blocks.test;
import cn.tohsaka.factory.rotationcraft.Rotationcraft;
import cn.tohsaka.factory.rotationcraft.prefab.BlockMod;
import com.mojang.datafixers.types.Type;
import com.mojang.datafixers.types.constant.EmptyPartPassthrough;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.datafix.fixes.References;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.IForgeRegistry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class BlockTest extends BlockMod implements EntityBlock {
public static BlockTest INSTANCE;
public static ResourceLocation NAME = new ResourceLocation(Rotationcraft.MOD_ID,"blocktest");
public static BlockEntityType<TileTest> TILE_TEST;
private static <T extends BlockEntity> BlockEntityType<T> register(String p_58957_, BlockEntityType.Builder<T> p_58958_) {
var t = p_58958_.build(new EmptyPartPassthrough());
ForgeRegistries.BLOCK_ENTITIES.register(t.setRegistryName(new ResourceLocation(Rotationcraft.MOD_ID,"tiletest")));
return t;
}
public static final EnumProperty<Direction> FACING = DirectionalBlock.FACING;
public BlockTest(BlockBehaviour.Properties builder) {
super(builder);
registerDefaultState(defaultBlockState().setValue(FACING, Direction.NORTH));
}
public BlockEntity newBlockEntity(BlockPos p_154552_, BlockState p_154553_) {
return new TileTest(p_154552_, p_154553_);
}
@Nullable
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level p_154543_, BlockState p_154544_, BlockEntityType<T> p_154545_) {
return createTickerHelper(p_154545_, TILE_TEST, TileTest::tick);
}
@Nonnull
@Override
public RenderShape getRenderShape(BlockState state) {
return RenderShape.ENTITYBLOCK_ANIMATED;
}
public BlockState getStateForPlacement(BlockPlaceContext p_56198_) {
return this.defaultBlockState().setValue(FACING, p_56198_.getClickedFace());
}
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> p_56249_) {
p_56249_.add(FACING);
}
public PushReaction getPistonPushReaction(BlockState p_56265_) {
return PushReaction.IGNORE;
}
public VoxelShape getShape(BlockState p_56257_, BlockGetter p_56258_, BlockPos p_56259_, CollisionContext p_56260_) {
return Shapes.block();
}
public BlockState rotate(BlockState p_56243_, Rotation p_56244_) {
return p_56243_.setValue(FACING, p_56244_.rotate(p_56243_.getValue(FACING)));
}
public BlockState mirror(BlockState p_56240_, Mirror p_56241_) {
return p_56240_.rotate(p_56241_.getRotation(p_56240_.getValue(FACING)));
}
public static void register(IForgeRegistry<Block> registry){
INSTANCE = new BlockTest(BlockBehaviour.Properties.of(Material.STONE));
INSTANCE.setRegistryName(NAME);
registry.register(INSTANCE);
Rotationcraft.blocks.put(NAME,INSTANCE);
TILE_TEST = register("blocktest", BlockEntityType.Builder.of(TileTest::new, INSTANCE));
}
public static void registerItem(IForgeRegistry<Item> registry){
BlockItem item = new BlockItem(Rotationcraft.blocks.get(NAME),new Item.Properties().tab(CreativeModeTab.TAB_BUILDING_BLOCKS));
item.setRegistryName(NAME);
registry.register(item);
Rotationcraft.items.put(NAME,item);
}
}
package cn.tohsaka.factory.rotationcraft.client.render;
import cn.tohsaka.factory.rotationcraft.Rotationcraft;
import cn.tohsaka.factory.rotationcraft.blocks.test.TileTest;
import cn.tohsaka.factory.rotationcraft.client.ModLayerDefinitions;
import cn.tohsaka.factory.rotationcraft.client.ModModelLayers;
import cn.tohsaka.factory.rotationcraft.client.etc.ModelRenderer;
import cn.tohsaka.factory.rotationcraft.client.model.custom_model;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import com.mojang.math.Matrix4f;
import net.minecraft.Util;
import net.minecraft.client.model.Model;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.StonecutterBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.lighting.BlockLightEngine;
import java.awt.*;
import java.util.function.Function;
public class RotaryMachineRender implements BlockEntityRenderer {
public static ResourceLocation texture = new ResourceLocation(Rotationcraft.MOD_ID,"textures/render/meter.png");
public custom_model model;
private final BlockRenderDispatcher blockRenderDispatcher;
public RotaryMachineRender(BlockEntityRendererProvider.Context context) {
this.blockRenderDispatcher = context.getBlockRenderDispatcher();
model = new custom_model(context.bakeLayer(ModModelLayers.BlockTest));
}
@Override
public void render(BlockEntity te, float partialTick, PoseStack matrix, MultiBufferSource renderer, int light, int overlayLight) {
matrix.pushPose();
//int c = LevelRenderer.getLightColor(te.getLevel(), te.getBlockPos().offset(0,256,0));
matrix.translate(0.5F, -0.5F, 0.5F);
RenderType layer = RenderType.entityTranslucentCull(texture);
model.renderToBuffer(te,matrix,renderer.getBuffer(layer),light,overlayLight);
matrix.popPose();
}
public static class TestBlockEntityRenderer<T extends BlockEntity> implements BlockEntityRenderer<T> {
public custom_model model;
public TestBlockEntityRenderer(custom_model model) {
this.model = model;
}
@Override
public void render(T te, float partialTick, PoseStack matrix, MultiBufferSource renderer, int light, int overlayLight) {
}
}
}
please help me,thanks a lot!