Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.18.2] Render an entity at a certain position


Recommended Posts

Posted (edited)

Hey !

I'm trying to render an entity (for example a cow) just above a custom block entity. Of course, the renderer is correctly registered.

final EntityRenderDispatcher entityDispatcher = Minecraft.getInstance().getEntityRenderDispatcher();
final BlockRenderDispatcher dispatcher = this.context.getBlockRenderDispatcher();
//        pPoseStack.pushPose();
//        pPoseStack.translate(0.5f, 0.5f, 0.5f);
//        dispatcher.renderSingleBlock(Blocks.GLASS.defaultBlockState(), pPoseStack, pBufferSource, pPackedLight, pPackedOverlay,
//                EmptyModelData.INSTANCE);

//        pPoseStack.popPose();

Entity entityToSpawn = EntityType.COW.create(pBlockEntity.getLevel());
//        LOGGER.debug("ENTITY TO SPAWN " + entityToSpawn.getName());
//        pPoseStack.pushPose();
pPoseStack.translate(0.5f, 2f, 0.5f);
pPoseStack.scale(2f, 2f, 2f);
entityDispatcher.render(entityToSpawn, pBlockEntity.getBlockPos().getX(), pBlockEntity.getBlockPos().getY(), pBlockEntity.getBlockPos().getZ(),
                0.0f, pPartialTick, pPoseStack, pBufferSource, pPackedLight);
pPoseStack.popPose();

Is there something I do not correctly ?

Edited by Sweetmimike
Add info
Link to comment
Share on other sites

I finally solved the problem !

If anyone is interested on how render an entity, you can find the code I used just below

final EntityRenderDispatcher entityDispatcher = Minecraft.getInstance().getEntityRenderDispatcher();
Entity entityToSpawn = entityType.create(pBlockEntity.getLevel());

float scale = 0.3f;
pPoseStack.pushPose();
pPoseStack.translate(0.5f, 1f, 0.5f);
pPoseStack.scale(scale, scale, scale);

entityDispatcher.render(entityToSpawn, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, pPoseStack, pBufferSource, 15728880);
pPoseStack.popPose();

 

Link to comment
Share on other sites

22 minutes ago, diesieben07 said:

Do not create a new entity instance every time.

Right.

I modified the code just as follows

	final EntityRenderDispatcher entityDispatcher = Minecraft.getInstance().getEntityRenderDispatcher();
        Entity entityToSpawn = pBlockEntity.getEntityToDisplay();
        if(entityToSpawn == null || entityToSpawn.getType() != entityType) {
            LOGGER.debug("NEED TO CREATE A NEW ENTITY");
            entityToSpawn = entityType.create(pBlockEntity.getLevel());
            pBlockEntity.setEntityToDisplay(entityToSpawn);
        }

        float scale = 0.3f;
        pPoseStack.pushPose();
        pPoseStack.translate(0.5f, 1f, 0.5f);
        pPoseStack.scale(scale, scale, scale);

        entityDispatcher.render(entityToSpawn, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, pPoseStack, pBufferSource, 15728880);
        pPoseStack.popPose();

So the entity I want to display is stored in a block entity

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
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.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • deleted the folder, and still, not working.
    • Im literally so confused. Ive followed so many directions, and done so much and it's not working..
    • the i have no idea, Forge tries to load this file as a Mod then it must exists you could delete the mods folder and see whats happen then
    • [03Jul2022 15:58:31.768] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, BradyDyson, --version, 1.19-forge-41.0.62, --gameDir, /Users/bradydyson/Library/Application Support/minecraft, --assetsDir, /Users/bradydyson/Library/Application Support/minecraft/assets, --assetIndex, 1.19, --uuid, 518f76ab883b4d1a826ecb2231ce9a9e, --accessToken, ❄❄❄❄❄❄❄❄, --clientId, MjgwREQ1MEY5NzNCNEZGM0JGNEIwRTI2MThBRkNEOEI=, --xuid, 2535470977180090, --userType, msa, --versionType, release, --launchTarget, forgeclient, --fml.forgeVersion, 41.0.62, --fml.mcVersion, 1.19, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20220607.102129] [03Jul2022 15:58:31.771] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 10.0.1+10.0.1+main.e9521dc3 starting: java version 17.0.3 by Microsoft; OS Mac OS X arch aarch64 version 12.0.1 [03Jul2022 15:58:31.803] [main/ERROR] [net.minecraftforge.fml.loading.ModDirTransformerDiscoverer/]: Zip Error when loading jar file /Users/bradydyson/Library/Application Support/minecraft/mods/BiomesOPlenty-1.19-17.0.0.136.jar java.util.zip.ZipException: zip END header not found     at java.util.zip.ZipFile$Source.findEND(ZipFile.java:1469) ~[?:?]     at java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1477) ~[?:?]     at java.util.zip.ZipFile$Source.<init>(ZipFile.java:1315) ~[?:?]     at java.util.zip.ZipFile$Source.get(ZipFile.java:1277) ~[?:?]     at java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:709) ~[?:?]     at java.util.zip.ZipFile.<init>(ZipFile.java:243) ~[?:?]     at java.util.zip.ZipFile.<init>(ZipFile.java:172) ~[?:?]     at java.util.zip.ZipFile.<init>(ZipFile.java:186) ~[?:?]     at net.minecraftforge.fml.loading.ModDirTransformerDiscoverer.visitFile(ModDirTransformerDiscoverer.java:54) ~[fmlloader-1.19-41.0.62.jar%2393!/:1.0]     at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) ~[?:?]     at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) ~[?:?]     at java.util.Iterator.forEachRemaining(Iterator.java:133) ~[?:?]     at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845) ~[?:?]     at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) ~[?:?]     at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[?:?]     at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) ~[?:?]     at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) ~[?:?]     at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:?]     at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596) ~[?:?]     at net.minecraftforge.fml.loading.ModDirTransformerDiscoverer.scan(ModDirTransformerDiscoverer.java:44) ~[fmlloader-1.19-41.0.62.jar%2393!/:1.0]     at net.minecraftforge.fml.loading.ModDirTransformerDiscoverer.candidates(ModDirTransformerDiscoverer.java:27) ~[fmlloader-1.19-41.0.62.jar%2393!/:1.0]     at cpw.mods.modlauncher.serviceapi.ITransformerDiscoveryService.candidates(ITransformerDiscoveryService.java:48) ~[modlauncher-10.0.1.jar%2381!/:10.0.1+10.0.1+main.e9521dc3]     at cpw.mods.modlauncher.TransformationServicesHandler.lambda$discoverServices$14(TransformationServicesHandler.java:123) ~[modlauncher-10.0.1.jar%2381!/:?]     at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) [?:?]     at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179) [?:?]     at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) [?:?]     at java.util.ServiceLoader$ProviderSpliterator.tryAdvance(ServiceLoader.java:1499) [?:?]     at java.util.Spliterator.forEachRemaining(Spliterator.java:332) [?:?]     at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) [?:?]     at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) [?:?]     at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:575) [?:?]     at java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260) [?:?]     at java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:616) [?:?]     at java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:622) [?:?]     at java.util.stream.ReferencePipeline.toList(ReferencePipeline.java:627) [?:?]     at cpw.mods.modlauncher.TransformationServicesHandler.discoverServices(TransformationServicesHandler.java:125) [modlauncher-10.0.1.jar%2381!/:?]     at cpw.mods.modlauncher.Launcher.run(Launcher.java:86) [modlauncher-10.0.1.jar%2381!/:?]     at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-10.0.1.jar%2381!/:?]     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-10.0.1.jar%2381!/:?]     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-10.0.1.jar%2381!/:?]     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) [bootstraplauncher-1.1.1.jar:?] [03Jul2022 15:58:31.857] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFineTransformationService.onLoad [03Jul2022 15:58:31.857] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFine ZIP file URL: union:/Users/bradydyson/Library/Application%20Support/minecraft/mods/preview_OptiFine_1.19_HD_U_H8_pre1.jar%23144!/ [03Jul2022 15:58:31.861] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFine ZIP file: /Users/bradydyson/Library/Application Support/minecraft/mods/preview_OptiFine_1.19_HD_U_H8_pre1.jar [03Jul2022 15:58:31.862] [main/INFO] [optifine.OptiFineTransformer/]: Target.PRE_CLASS is available [03Jul2022 15:58:31.890] [main/INFO] [mixin/]: SpongePowered MIXIN Subsystem Version=0.8.5 Source=union:/Users/bradydyson/Library/Application%20Support/minecraft/libraries/org/spongepowered/mixin/0.8.5/mixin-0.8.5.jar%2390!/ Service=ModLauncher Env=CLIENT [03Jul2022 15:58:31.894] [main/INFO] [optifine.OptiFineTransformationService/]: OptiFineTransformationService.initialize   I have and it's labeled as latest log. 
  • Topics

×
×
  • Create New...

Important Information

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