Jump to content

rendering model to blockentity is too dark


xmsoft

Recommended Posts

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!

Edited by xmsoft
Link to comment
Share on other sites

9 hours ago, bradsk88 said:

It's probably this line

```

RenderType layer = RenderType.entityTranslucentCull(texture);

```

 

Try a different render type.

thank you for your reply

I tried other options ,but it not work

as I see, this problem maybe bright issue, somehere wrong?

 

I edit this line :

```

model.renderToBuffer(te,matrix,renderer.getBuffer(layer),light,overlayLight);

```

the variable `light` changed to   LightTexture.FULL_BLOCK = 240    it can be render fully bright

 

like this:

 615109a40ad78.png

 

but my blockrender can't get ambient light value,  the variable `light` is always  ZERO

 

this argument is affected by what?

Edited by xmsoft
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.