Jump to content

(1.18.2) Block entity renderer disappears after leaving the world


ElTotisPro50

Recommended Posts

So i have my block entity, that renders the item that the container has in the slot, but when i leave the world the item rendering doesnt show up, i have to "update" the block by opening the menu, and it is not very nice because every time you would have to update the block.

 

I want that the rendering never disappears

private void registerRenderers(final EntityRenderersEvent.RegisterRenderers event) {
        event.registerBlockEntityRenderer(ModBlockEntities.MYBLOCK_BLOCKENTITY.get(), MyBlockEntityRender::new);
}

 

 

public class MyBlockEntityRender implements BlockEntityRenderer<MyBlockBlockEntity> {

    private final BlockEntityRendererProvider.Context context;
    private final Minecraft mc = Minecraft.getInstance();

    public MyBlockEntityRender(BlockEntityRendererProvider.Context context) {
        this.context = context;
    }

    @Override
    public void render(MyBlockBlockEntity blockEntity, float partialTicks, PoseStack stack,MultiBufferSource buffer,
                       int combinedLightIn,int combinedOverlayIn) {
        final LocalPlayer player = mc.player;
        final ItemRenderer itemRenderer = mc.getItemRenderer();

        if (blockEntity.getItemSlot0().getItem().equals(Items.AIR) || blockEntity.getItemSlot0().getItem().equals(ItemStack.EMPTY))
            return;

        renderItem(blockEntity.getItemSlot0(), new double[]{0,1,0}, Vector3f.XP.rotationDegrees(0), 0.5f, stack,buffer, combinedLightIn, OverlayTexture.NO_OVERLAY);
    }

    public void renderItem(ItemStack item, double[] translation, Quaternion rotation, float scale, PoseStack stack, MultiBufferSource buffer, int combinedLightIn, int combinedOverlayIn) {
        final LocalPlayer player = mc.player;
        final ItemRenderer itemRenderer = mc.getItemRenderer();
        stack.pushPose();
        stack.translate(translation[0],translation[1],translation[2]);
        stack.mulPose(rotation);
        stack.scale(scale,scale,scale);
        itemRenderer.renderStatic(player, item, ItemTransforms.TransformType.FIXED, false, stack,buffer, mc.level, combinedLightIn,combinedOverlayIn, 0);
        stack.popPose();
    }
}

 

I dont think is necessary to show all the other clases, both of this are the ones that controls the rendering

Link to comment
Share on other sites

12 hours ago, vemerion said:

You need to synch the inventory of the blockEntity to the client! You can do it either with a custom packet, or by overriding relevant methods in your block entity (getUpdatePacket/onDataPacket/getUpdateTag/handleUpdateTag).

not working 

/*Synchronization to the client*/
    @Nullable
    @Override
    public Packet<ClientGamePacketListener> getUpdatePacket() {
        return ClientboundBlockEntityDataPacket.create(this);
    }
    @Override
    public CompoundTag getUpdateTag() {
        CompoundTag tag = super.getUpdateTag();
        return tag;
    }
    @Override
    public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) {
        super.onDataPacket(net, pkt);
    }
    @Override
    public void handleUpdateTag(CompoundTag tag) {
        super.handleUpdateTag(tag);
    }

 

A dude asked for something about fluids in his GUI, and he also needed to sync it to the client, "used the 4 same methods like me"

 

Edited by ElTotisPro50
Link to comment
Share on other sites

The inventory is only sent when you right click a block as part of showing the screen.

If you want data to always be available you need to tell minecraft how to do this.

BlockEntity already has some infrastructure for this, but its default logic does nothing - as will overriding the methods and just calling super() like you have.

 

For reference look at something like BeaconBlockEntity which sends data to the client so it can for example draw the beam correctly.

 

1) getUpdatePacket() says how to create your network packet, by default this returns null so nothing happens.

You need to change this to actually do something, e.g. the beacon does

   @Override
   public ClientboundBlockEntityDataPacket getUpdatePacket() {
      return ClientboundBlockEntityDataPacket.create(this);
   }

2) The above logic calls back to your getUpdateTag() to actually get the data. By default this just returns an empty CompundTag.

The beacon changes it to use the same logic as the data saved to disk.

   @Override
   public CompoundTag getUpdateTag() {
      return this.saveWithoutMetadata();
   }

3) When the data arrives on the client it will call onDataPacket() - the default behaviour for this is to call load()

 

NOTE: After your block entity is initially loaded and sent to the client, additional packets will only be sent when the block is marked as "dirty".

This is the same call that needs to be made to make sure your changed data is saved to disk.

You can do this by either by calling setChanged on your BlockEntity or by calling Level.blockEntityChanged().

You can see BeaconMenu uses the second method in updateEffects().

 

 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

20 minutes ago, warjort said:

The inventory is only sent when you right click a block as part of showing the screen.

If you want data to always be available you need to tell minecraft how to do this.

BlockEntity already has some infrastructure for this, but its default logic does nothing - as will overriding the methods and just calling super() like you have.

 

For reference look at something like BeaconBlockEntity which sends data to the client so it can for example draw the beam correctly.

 

1) getUpdatePacket() says how to create your network packet, by default this returns null so nothing happens.

You need to change this to actually do something, e.g. the beacon does

   @Override
   public ClientboundBlockEntityDataPacket getUpdatePacket() {
      return ClientboundBlockEntityDataPacket.create(this);
   }

2) The above logic calls back to your getUpdateTag() to actually get the data. By default this just returns an empty CompundTag.

The beacon changes it to use the same logic as the data saved to disk.

   @Override
   public CompoundTag getUpdateTag() {
      return this.saveWithoutMetadata();
   }

3) When the data arrives on the client it will call onDataPacket() - the default behaviour for this is to call load()

 

NOTE: After your block entity is initially loaded and sent to the client, additional packets will only be sent when the block is marked as "dirty".

This is the same call that needs to be made to make sure your changed data is saved to disk.

You can do this by either by calling setChanged on your BlockEntity or by calling Level.blockEntityChanged().

You can see BeaconMenu uses the second method in updateEffects().

 

 

 

It works now, thanks

/*Synchronization to the client*/
    @Nullable
    @Override
    public Packet<ClientGamePacketListener> getUpdatePacket() {
        return ClientboundBlockEntityDataPacket.create(this);
    }
    @Override
    public CompoundTag getUpdateTag() {
        return this.saveWithoutMetadata();
    }
    @Override
    public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) {
        super.onDataPacket(net, pkt);
        load(pkt.getTag());
    }
    @Override
    public void handleUpdateTag(CompoundTag tag) {
        super.handleUpdateTag(tag);
    }

 

Link to comment
Share on other sites

11 minutes ago, ElTotisPro50 said:

 

    // This now calls load() twice, you don't need to override this method if you want it to use load()
    @Override
    public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) {
        super.onDataPacket(net, pkt);
        load(pkt.getTag());
    }

    // Overriding a method and just calling super() is redundant, you can remove this
    @Override
    public void handleUpdateTag(CompoundTag tag) {
        super.handleUpdateTag(tag);
    }

 

 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • The log is here https://pastebin.com/eK7U0a9b I have the following mods: 1.alexsdelight-1.4.1 2.alexsmobs-1.21.1 3.citadel-2.1.4-1.19 4.FarmersDelight-1.19.2-1.2.3 5.jei-1.19.2-forge-11.5.0.297 6.journeymap-1.19.2-5.9.0-forge 7.Optifine_1.19.2_HD_U_H9 8.sophisticatedbackpacks-1.19.2-3.19.1.960 9.sophisticatedcore-1.19.2-0.5.106.503 The error code is -1. If anyone can help please do.
    • i think the more suitable would be using the nbt format and use the ChestBlockEntity methods to get the items other could be list all the registered items make a list and get the item from the list  Map<String, Item> lista_de_items = new HashMap<String, Item>(); int count = 0; for (Map.Entry<net.minecraft.resources.ResourceKey<Item>, Item> ResourceKey : ForgeRegistries.ITEMS.getEntries()) { Item actualItem = ResourceKey.getValue();//.defaultBlockState().getBlock(); String nnn = ForgeRegistries.ITEMS.getKey(actualItem).toString(); lista_de_items.put(nnn, actualItem); System.out.println( count + " [" + nnn + "]" ); count++; } Item cosa = lista_de_items.get("minecraft:apple");
    • I am hosting a server on oracle cloud free tier. It has 24GB RAM and 4 OCPUs. I use pterodactyl panel to manage my servers. I have added -Xmx21G in the user_jvm_args.txt file. It is using 9GiB of ram and 120% CPU (max 400%). I have restarted several times. I have a lot of mods. It is running on Forge 1.19.2-43.2.14. Pterodactyl Panel has not put any resource allocation restraints on it. Here is my log. I get a message like this: [13:17:53] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 13315ms or 266 ticks behind [13:18:21] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 13002ms or 260 ticks behind [13:18:49] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 12868ms or 257 ticks behind [13:19:16] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 11789ms or 235 ticks behind [13:19:43] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 12087ms or 241 ticks behind [13:20:10] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 12050ms or 241 ticks behind [13:20:37] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 12003ms or 240 ticks behind [13:21:04] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 11758ms or 235 ticks behind [13:21:31] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 12128ms or 242 ticks behind [13:21:59] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 13573ms or 271 ticks behind [13:22:27] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 13200ms or 264 ticks behind [13:22:54] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 11192ms or 223 ticks behind [13:23:21] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 12861ms or 257 ticks behind [13:23:50] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 13288ms or 265 ticks behind [13:24:17] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 12314ms or 246 ticks behind [13:24:43] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 11276ms or 225 ticks behind [13:25:10] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 11444ms or 228 ticks behind [13:25:36] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 11400ms or 228 ticks behind [13:26:03] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 11670ms or 233 ticks behind [13:26:29] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 11382ms or 227 ticks behind [13:26:55] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 11085ms or 221 ticks behind [13:27:22] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 11568ms or 231 ticks behind [13:27:48] [Server thread/WARN] [minecraft/MinecraftServer]: Can't keep up! Is the server overloaded? Running 11736ms or 234 ticks behind Here are all my mods (ik its a lot): [1.19.2] SecurityCraft v1.9.6.1.jar alchemind-0.1.2.a-1.19.2-create0.5.1.jar animalistics v0.1.jar architectury-6.5.85-forge.jar BofferNBeems.jar bronze_age-0.0.2-1.19.2.jar cfm-7.0.0-pre35-1.19.2.jar cgm-1.3.4-1.19.2.jar compressedcreativity-1.19.2-0.1.6.jar CraftTweaker-forge-1.19.2-10.1.46.jar Create Deco Casing 1.1.0 1.19 Fix.jar Create Train Additions 0.3.0-1.19.2.jar create_central_kitchen-1.19.2-for-create-0.5.1.b-1.3.7.d.jar create_crystal_clear-0.2.1-1.19.2.jar create_enchantment_industry-1.19.2-for-create-0.5.1.b-1.2.5.jar create_mechanical_extruder-1.19.2-1.4.1.b-30.jar create_misc_and_things_++1.19.2_3.0.jar create_so-1.3.3+forge-1.19.2.jar create-1.19.2-0.5.1.b.jar Create-Dreams-n-Desires-1.19.2-0.0.2c.ALPHA.jar create-electric-stonks-1.19.2-1.2.5.jar create-mosaicadditions_1.19.2.jar create-renewable-ores-1.jar create-ruins-1.19.2-1.0.0.jar create-structures-0.1.0.jar createaddition-1.19.2-20230527a.jar createcafe-1.1.8-1.19.2.jar createdieselgenerators-1.19.2-1.1.jar createendertransmission-1.2.4.jar createfoundry-forge-1.1.0-1.19.2.jar creategoggles-0.5.5-beta-[FORGE].jar createoreexcavation-1.19-1.2.1.jar createsifter-1.19.2-1.5.1.b-30.jar CreateTweaker-1.19.2-3.0.0.6.jar createunlimited-0.3.1+1.19.2.jar curios-forge-1.19.2-5.1.4.3.jar dragonmounts-1.19.2-1.1.4a.jar ferritecore-5.0.3-forge.jar framework-0.4.2-1.19.2.jar garnished-0.2.2+1.19.2.jar geckolib-forge-1.19-3.1.40.jar jei-1.19.2-forge-11.6.0.1016.jar journeymap-1.19.2-5.9.7-forge.jar kotlinforforge-3.12.0-all.jar kubejs-forge-1902.6.0-build.142.jar liquidburner-1.19.2-0.4.jar MechanicalMachinery-1.19.2-1.1.1.jar memoryleakfix-forge-1.17+-1.1.1.jar moderntrainparts-mc1.19.2-0.2.2-forge.jar molten_geodes-1.19.2-0.3.1.jar molten_vents-1.19.2-0.2.0.jar Patchouli-1.19.2-77.jar pneumaticcraft-repressurized-1.19.2-4.3.5-25.jar rhino-forge-1902.2.2-build.268.jar simpleplanes-1.19.2-5.2.2.jar starlight-1.1.1+forge.cf5b10b.jar Steam_Rails-1.3.5+forge-mc1.19.2.jar unlockschematics-1.19.2-1.0.0.jar worldedit-mod-7.2.12.jar
    • I randomly got this error when I tried to build my game, tried reverting everything I did and it still did not do anything, and nothing is working. I don't think it's to do with my code, but it randomly happened after I made some changes? 1:28:28 pm: Executing 'assemble'... > Configure project : Java: 17.0.6, JVM: 17.0.6+10 (Eclipse Adoptium), Arch: amd64 WARNING: This project is configured to use the official obfuscation mappings provided by Mojang. These mapping fall under their associated license, you should be fully aware of this license. For the latest license text, refer below, or the reference copy here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md, You can hide this warning by running the `hideOfficialWarningUntilChanged` task WARNING: (c) 2020 Microsoft Corporation. These mappings are provided "as-is" and you bear the risk of using them. You may copy and use the mappings for development purposes, but you may not redistribute the mappings complete and unmodified. Microsoft makes no warranties, express or implied, with respect to the mappings provided here. Use and modification of this document or the source code (in any form) of Minecraft: Java Edition is governed by the Minecraft End User License Agreement available at https://account.mojang.com/documents/minecraft_eula. > Task :compileJava FAILED Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0. You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. See https://docs.gradle.org/7.5.1/userguide/command_line_interface.html#sec:command_line_warnings 1 actionable task: 1 executed FAILURE: Build completed with 2 failures. 1: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':compileJava'. > Cannot fingerprint input file property 'stableSources': java.io.IOException: Cannot snapshot C:\Users\jbart\OneDrive\Documents\Minecraft\Mods\Forge\1.19.3\JaspersStarWarsMod\src\main\java\net\jasper\jstarwars\classes\client\ClientForceData.java: not a regular file * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. ============================================================================== 2: Task failed with an exception. ----------- * What went wrong: java.lang.StackOverflowError (no error message) * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. ============================================================================== * Get more help at https://help.gradle.org BUILD FAILED in 888ms 1:28:29 pm: Execution finished 'assemble'. ClientForceData.java: package net.jasper.jstarwars.classes.client; public class ClientForceData { private static int playerForce; public static void set(int force) { ClientForceData.playerForce = force; } public static int getPlayerForce() { return ClientForceData.playerForce; } }
    • good days  i was updating to 1.20 and have this problem  i need to check the material in blocks for many items and things but the class material exist no more  Material pmat = tmpstate.getMaterial(); if ((pmat == Material.AIR) || (pmat == Material.PLANT) || (pmat == Material.LEAVES) || (pmat == Material.REPLACEABLE_PLANT)) { return false; } also the .getMaterial() method is gonne an without being market as deprecated so i dont find the replacement  forums says //import net.minecraft.world.level.material.Material; that class dont exist on mi forge-1.20.2-48.0.49-mdk.zip i was thingking in using soundtype instead  //import net.minecraft.world.level.block.SoundType but its a little uncosistent coze is designed for other thing and i would have to write custom functions everywhere just to check if a block  like isMetal() could be SoundType.ANVIL SoundType.METAL SoundType.CHAIN and i hand an custome ladder ladder made of iron   
  • Topics

×
×
  • Create New...

Important Information

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