Jump to content

Recommended Posts

Posted (edited)

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
Posted (edited)
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

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • But what could be the issue with that? Maybe the confiq file?  
    • There is an issue with legendarysurvivaloverhaul
    • I am playing on a nitrado server with friends and everytime i try to join i am getting the same crash.log Does somebody understand what the problem here could be?  Crash Log
    • I see. I'm sure I tried again with a lower case word, a few times. I ended up doing the same thing as pixxy in the end. Is this beyond the scope of the admins to fix? Are they already aware of it, or should I use 'contact us' to post a ticket?
    • I’m working on a Manta Ray entity in MCreator using GeckoLib animations, and my goal is to have a looping (flip) animation that ends at −360°, then transitions seamlessly into a swim animation starting at 0°. However, every method I’ve tried—like quickly interpolating the angle, inserting a brief keyframe at 0°, or using a micro “bridge” animation—still causes a visible “flash” https://imgur.com/a/5ucjUb9 or "jump" when the rotation resets. I want a perfectly smooth motion from the flip’s final rotation to the swim’s initial rotation. If anyone has solved this in MCreator/GeckoLib, or found a better trick for handling the −360° →0° gap without a snap, I’d appreciate some advice ! P.S.- I cannot set swim to start at -360 because I would have the same issue but in reverse. Here's the custom LoopingAnimationGoal :   class LoopingAnimationGoal extends Goal { private final MantaRayEntity entity; private final int cooldownTime; private int animationTimer; private int cooldownTimer; // New boolean to prevent double calls private boolean isLoopingActive = false; public LoopingAnimationGoal(MantaRayEntity entity, int cooldownTime) { this.entity = entity; this.cooldownTime = cooldownTime; this.animationTimer = 0; this.cooldownTimer = 0; this.setFlags(EnumSet.of(Flag.MOVE, Flag.LOOK)); } @Override public boolean canUse() { System.out.println("[DEBUG] LoopingGoal canUse => cooldownTimer=" + cooldownTimer); if (cooldownTimer > 0) { cooldownTimer--; return false; } BlockPos entityPos = entity.blockPosition(); boolean canUse = entity.isWaterAbove(entityPos, 4); System.out.println("[DEBUG] LoopingGoal canUse => WATER " + (canUse ? "DETECTED" : "NOT DETECTED") + " at " + entityPos + ", returning " + canUse); return canUse; } @Override public void start() { entity.setAnimation("looping"); animationTimer = 63; isLoopingActive = true; System.out.println("[DEBUG] Looping animation STARTED. Timer=" + animationTimer + ", gameTime=" + entity.level().getGameTime()); } @Override public boolean canContinueToUse() { System.out.println("[DEBUG] LoopingGoal canContinueToUse => animationTimer=" + animationTimer); return animationTimer > 0; } @Override public void tick() { animationTimer--; System.out.println("[DEBUG] LoopingGoal TICK => animationTimer=" + animationTimer); // We stop ONLY if we are still looping if (animationTimer <= 0 && isLoopingActive) { System.out.println("[DEBUG] condition => animationTimer <= 0 && isLoopingActive"); stop(); } } @Override public void stop() { // Check if already stopped if (!isLoopingActive) { System.out.println("[DEBUG] stop() called again, but isLoopingActive = false. Doing nothing."); return; } System.out.println("[DEBUG] Looping STOP at tick=" + entity.level().getGameTime() + ", last known rotation=" + entity.getXRot() + "/" + entity.getYRot() + ", animationTimer=" + animationTimer); // Immediately switch to "swim" entity.setAnimation("swim"); // Reset cooldown cooldownTimer = cooldownTime; // Disable looping to prevent a second stop isLoopingActive = false; System.out.println("[DEBUG] Looping STOP => setAnimation('swim'), cooldownTimer=" + cooldownTimer); } }  
  • Topics

×
×
  • Create New...

Important Information

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