Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I have a feature whereby a user can set a predefined structure on and it will place the blocks both serverside and clientside once every few ticks (currently every 6 ticks). The general logic flow I have is:

  1. User selects and places a Building (array of BlockPos/BlockState pairs)
  2. Client -> Server packet to initialise a Building object containing this block data
  3. On every 6th tick:
    1. Server places a block from the array
    2. Server -> Client packet to place the same block

Video of this in action: https://imgur.com/a/gb9rpJ3

However, sometimes when I do this I get an error in the LongOpenHashSet java class after some of the blocks are placed.

java.lang.ArrayIndexOutOfBoundsException: Index 126 out of bounds for length 65 (note the index numbers are always different on each crash)

It seems random to me how many blocks it places before crashing or whether it even crashes at all.

Full crash log: https://pastebin.com/6JC9nm5B

Link to the code that seems to be causing the error (When I comment these lines out the issue stops, but of course, then I don't get the blocks placed clientside): https://github.com/SoLegendary/reignofnether/blob/1.19/src/main/java/com/solegendary/reignofnether/building/BuildingClientEvents.java#L358-L360

I tried wrapping the above lines in a try-catch block but it doesn't seem to actually catch anything.

Your code looks very broken. This is just what I found from a quick glance at your code.

 

1) Fundamentally, you are sending block place/remove events to all clients and then trying to place blocks regardless of whether the client knows about the location.

At no point do you check level.isLoaded(BlockPos) so you will be writing blocks (or at least trying to) into unloaded chunks. Which is probably the cause of your crash?

 

2) Your use of statics with a non-thread safe data type (ArrayList) is asking for trouble unless you can guarantee everything happens on the same thread. This could also be the cause?

 

3) Using statics like that is just wrong anyway. You want to store this data in a proper object like a Level or Chunk capability where you can save the data, otherwise all your data will be lost when the server reboots.

 

4) You are not checking the event.phase in your tick event, so your code will run twice per tick.

 

Finally on point (1) why are you doing all this extra work at all?

If you pass 3 to setBlock() - or use setBlockAndUpdate() - minecraft will handle all this processing for you.

i.e. You can do all the processing on the server and not worry about the client.

Minecraft will probably do it a lot more efficiently than you, e.g. sending block updates in groups, using smaller packets and not sending updates to clients it knows don't need them.

 

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.

  • Author

Thanks for the pointers... I probably will need to do quite a bit of refactoring - I also didn't know about a lot of these methods lie setBlockAndUpdate

  • Author

@warjort

I've removed the call from Server -> Client to update blocks and its seemed to have stopped the crashes for the time being.

However, when I use setBlockAndUpdate() it doesn't seem to trigger a BlockEvent.EntityPlaceEvent on the client side. I want to set and destroy a dummy block on the spot with each block creation so that we get the particle and sound effects on each block being built.

This is the code I added to BuildingClientEvents:
 

    @SubscribeEvent
    public static void onBlockPlace(BlockEvent.EntityPlaceEvent evt) {
        BlockPos bp = evt.getPos();
        BlockState bs = evt.getState();
        if (MC.level != null && MC.level.isLoaded(bp)) {
            MC.level.setBlock(bp.east(), bs, 1);
            MC.level.destroyBlock(bp, false);
        }
    }

 

You don't need to do this. You should be able to trigger these effects from the server without messing around with actually destroying blocks.

serverLevel.levelEvent(LevelEvent.PARTICLES_DESTROY_BLOCK, blockPos, Block.getId(blockState))

 

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.