Jump to content

[1.12.x/1.11.x] [UNSOLVED] Bounding Boxes IndexOutOfBoundsException


Bektor

Recommended Posts

Hi there,

 

I've got the problem that I want to set the bounding box which appears when hovering over the block to acount for all possible connections of the block.

    @Override
    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
        state = this.getActualState(state, source, pos);
        return BB.get(this.getBoundingBoxIndex(state));
    }
    
    private int getBoundingBoxIndex(IBlockState state) {
        int index = 0;
        
        for(int i = 0; i <= CONNECTED.size(); i++) {
            PropertyBool value = (PropertyBool) CONNECTED.get(i);
            
            if((Boolean)state.getValue(value).booleanValue())
                index |= 1 << EnumFacing.getFront(i).getIndex();
        }
        
        return index;
    }

 

My data (the values NORTH, EAST, UP etc.) is stored in an ImmutableList sorted in D-U-N-S-W-E order.

 

The current code however does not work and results into the following error which occurs in the line BB.get(this.getBoundingBoxIndex(state)); :

Quote

java.lang.IndexOutOfBoundsException: index (6) must be less than size (6)

 

I guess the problem here is that I just copied over the bit operation from the BlockFence which doesn't need to account for possible connections UP and DOWN.

If this is the case, how do I need to change the bit operation?

 

Thx in advance.

Bektor

Edited by Bektor

Developer of Primeval Forest.

Link to comment
Share on other sites

i <= CONNECTED.size()

This is wrong.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

46 minutes ago, Draco18s said:

i <= CONNECTED.size()

This is wrong.

Hm... I don't quite get why and to what I should change it.

EDIT: After debugging I figured out that when the value i is 5 the value index jumps to 36 (I just placed directly under the if-statement a syso statement and put there the breakpoint). Thought why does it jump to 36 there??? And to what would I need to change the for-loop? (4 would also crash)

Edited by Bektor

Developer of Primeval Forest.

Link to comment
Share on other sites

First of all, in computing you count starting at zero. So the maximum your index should be is the size-1. In a bounding box there are six elements (three for each of the opposite min max corners) so you should only ever index up to 5. The error says you're indexing to 6 and your code does a <= size() when it should be simply < size().

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

5 minutes ago, jabelar said:

First of all, in computing you count starting at zero. So the maximum your index should be is the size-1. In a bounding box there are six elements (three for each of the opposite min max corners) so you should only ever index up to 5. The error says you're indexing to 6 and your code does a <= size() when it should be simply < size().

Oh, yeah. Didn't noticed that with the size-1. ^^

Thought even when changint the <= size() to <size() it still crashes:

 

    private int getBoundingBoxIndex(IBlockState state) {
        int index = 0;
        
        System.out.println(CONNECTED_PROPERTIES.size()); // prints out 6
        for(int i = 0; i < CONNECTED_PROPERTIES.size(); i++) {
            PropertyBool value = (PropertyBool) CONNECTED_PROPERTIES.get(i);
            
            if((Boolean)state.getValue(value).booleanValue())
                index |= 1 << EnumFacing.getFront(i).getIndex();
        }
        
        return index;
    }

 

Quote

java.lang.IndexOutOfBoundsException: index (36) must be less than size (6)

 

Edited by Bektor

Developer of Primeval Forest.

Link to comment
Share on other sites

6 minutes ago, Bektor said:

The error is still very clear -- you are passing an index of 36 to it. Either put some console statements to trace the value or set a breakpoint and trace in Eclipse debug mode. This is a very standard array debug situation, you just gotta roll up your sleeves and trace the value of the index. It will become very clear where it is getting set wrong.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

11 minutes ago, jabelar said:
19 minutes ago, Bektor said:

The error is still very clear -- you are passing an index of 36 to it. Either put some console statements to trace the value or set a breakpoint and trace in Eclipse debug mode. This is a very standard array debug situation, you just gotta roll up your sleeves and trace the value of the index. It will become very clear where it is getting set wrong.

 

45 minutes ago, Bektor said:

EDIT: After debugging I figured out that when the value i is 5 the value index jumps to 36 (I just placed directly under the if-statement a syso statement and put there the breakpoint).

System.out.println(i + " " + index);

[STDOUT]: 0 0
[STDOUT]: 1 0
[STDOUT]: 2 4
[STDOUT]: 3 4
[STDOUT]: 4 4
[STDOUT]: 5 36

Edited by Bektor

Developer of Primeval Forest.

Link to comment
Share on other sites

You're bitshifting the results.

0 and 1 are both false, so they aren't doing anything.

2 is true, so it bitshifts 1 << 2 (or 4)

3 and 4 are both false, so nothing

5 is then true, so it adds to the 4 the value 1 << 5 (or 32).

 

However, you need to look at where this value is passed back to: an array.  Of size 6.

(You haven't shown us the declaration/definition of BB)

 

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

21 minutes ago, Draco18s said:

You haven't shown us the declaration/definition of BB)

 

BB is an ArrayList which holds all bounding boxes, so UP, DOWN, WEST, SOUTH etc.

All those bounding boxes are created seperatly, but then stored in this ArrayList.

The size of BB is 6.

 

Current code iteration (I changed this one class really way too often ^^):

private static final ArrayList<AxisAlignedBB> BB = new ArrayList<>();

 

Developer of Primeval Forest.

Link to comment
Share on other sites

Then why the devil are you doing what you're doing?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

6 minutes ago, Draco18s said:

Then why the devil are you doing what you're doing?

Because I looked at BlockFence as a reference on how Minecraft does the same think I want to do. (As I had no clue before which method was there for changing the bounding box)

And Minecraft got an Array and the index for this error is calculated in getBoundingBoxIdx with bitshifting. Though BlockFence has less possible connections which could change the bounding box.

Developer of Primeval Forest.

Link to comment
Share on other sites

You mean this declaration, right?

protected static final AxisAlignedBB[] BOUNDING_BOXES = new AxisAlignedBB[] {new AxisAlignedBB(0.375D, 0.0D, 0.375D, 0.625D, 1.0D, 0.625D), new AxisAlignedBB(0.375D, 0.0D, 0.375D, 0.625D, 1.0D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.375D, 0.625D, 1.0D, 0.625D), new AxisAlignedBB(0.0D, 0.0D, 0.375D, 0.625D, 1.0D, 1.0D), new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.0D, 0.625D), new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.0D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.625D, 1.0D, 0.625D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.625D, 1.0D, 1.0D), new AxisAlignedBB(0.375D, 0.0D, 0.375D, 1.0D, 1.0D, 0.625D), new AxisAlignedBB(0.375D, 0.0D, 0.375D, 1.0D, 1.0D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.0D, 0.625D), new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.0D, 1.0D), new AxisAlignedBB(0.375D, 0.0D, 0.0D, 1.0D, 1.0D, 0.625D), new AxisAlignedBB(0.375D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.625D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D)};
   

Because that's a lot more than 6. Specifically, 16: 4 directions. 2^4. 16.

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

5 minutes ago, Draco18s said:

Because that's a lot more than 6. Specifically, 16: 4 directions. 2^4. 16.

Oh, never looked at it so closely (all those numbers in one line).

 

Tought writing down 16 possible bounding boxes which are just used once (when the player hovers over the block).... I feel that this is a lot of work.

Isn't there any automated way of doing creating all those bounding boxes? Basically, it's just the simplex bounding boxes already in use for collision + all

possible variants of these.

Thought this let's me think.... Why does addCollisionBoxToList works perfectly with 6 collision boxes + one base collision box and for getBoundingBox all possible variants (I guess) are also defined resulting in the case of the fence into 16.

Edited by Bektor

Developer of Primeval Forest.

Link to comment
Share on other sites

addCollisionBoxToList doesn't require that the boxes be contiguous. getBoundingBox is specifically a single cuboid.

 

Think about the outline around Stairs vs. its actual collision hull.

 

For your block you wouldn't need 16 AABBs for your bounding box...you'd need sixty four.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

2 minutes ago, Draco18s said:

addCollisionBoxToList doesn't require that the boxes be contiguous. getBoundingBox is specifically a single cuboid.

 

Think about the outline around Stairs vs. its actual collision hull.

 

For your block you wouldn't need 16 AABBs for your bounding box...you'd need sixty four.

64 sounds like more anyone would want to write. ^^

 

Isn't there a way to get around manually writing 64 bounding boxes?

I don't think that Buildcraft, ExtraUtilities or especially ThermalDynamics manually wrote down 64 bounding boxes in 1.7.10 (no clue how they look in newer versions of MC).

Developer of Primeval Forest.

Link to comment
Share on other sites

Write code to compute the bounds.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • If you’ve ever experienced the sinking feeling of losing funds online, you’re not alone. Enter recovery services like ADWARE RECOVERY SPECIALIST, the heroes of the digital age who help individuals track down and retrieve lost funds. These services act as modern-day sheriffs in the Wild West of the internet, bringing justice to those who have fallen victim to online scams and fraud. In a world where online transactions are as common as selfies, the need for recovery services is more pressing than ever. Individuals worldwide are vulnerable to various online schemes, from investment fraud to phishing scams. Recovery services provide a glimmer of hope for those who have lost money, offering a chance to recover what's rightfully theirs and restore faith in the digital realm. The beauty of recovery services like ADWARE RECOVERY SPECIALIST lies in their global reach. Email: Adwarerecoveryspecialist@auctioneer. net  Regardless of where individuals are located worldwide, these services extend their virtual arms to help victims of online fraud. From bustling metropolises to remote villages, no corner of the world is beyond the grasp of these modern-day Robin Hoods. Thanks to the wonders of globalization, recovery services have transcended geographical boundaries to serve individuals worldwide. The interconnected nature of the digital world means that help is just a click away, bridging gaps between nations and bringing relief to those in need. In a world where borders are becoming increasingly blurred, recovery services stand as beacons of accessibility and assistance. When a broker stole from me and withheld access from me for five months, I had no idea that I would be able to recover my trading money back. I'm relieved that I was able to get my money returned without any issues. The impact of recovery services like ADWARE RECOVERY SPECIALIST extends far beyond individual wallets. Communities worldwide have experienced a renewed sense of trust and security, knowing that there are dedicated professionals working tirelessly to recover their lost assets. These services not only bring financial relief but also restore faith in the integrity of the digital world. Trust is the cornerstone of any successful recovery service, and building credibility in a global market can pose unique challenges. ADWARE RECOVERY SPECIALIST strives to maintain transparency and reliability in all its interactions, earning the trust of clients worldwide. ADWARE RECOVERY SPECIALIST can be talked to through:  Website: www.adwarerecoveryspecialist.expert  Telegram: @ADWARE_RECOVERY_SPECIALIST
    • The game wont start and keeps crashing everytime I hit play "The game crashed whilst rendering overlay Error: java.lang.IllegalAccessError: failed to access class com.mojang.blaze3d.platform.GlStateManager$TextureState from class net.coderbot.iris.gl.IrisRenderSystem$DSAARB (com.mojang.blaze3d.platform.GlStateManager$TextureState is in module minecraft@1.18.2 of loader 'TRANSFORMER' @724b939e; net.coderbot.iris.gl.IrisRenderSystem$DSAARB is in module oculus@1.6.4 of loader 'TRANSFORMER' @724b939e)" How do I get it to stop? Log error here: https://pastebin.com/byv1dR54
    • In case anyone happens on this with the same issue, I was able to overcome it. After re-reading @Paint_Ninja's last post numerous time, it finally dawned on me that he was referring wholly to the forge installer, which has nothing to do with the packaged modpack installer. As such, I downloaded the new copy of the forge installer and copied it to my linux host, then opened a second ssh session and prepared a cp command to move the new (correct) installer over to the install directory where I was installing the modpack. After the modpack installer had just about finished retrieving files, I overwrote the installer.jar file with the correct one in a seperate ssh session. The modpack (packaged) installer then used that jar to install forge with the included files, and the install finished as I would have expected. Thanks all!
    • Just tried it again removed directory entirely, downloaded a brand new, fresh copy and did a fresh install, even going as far as running as root for the install to make sure I didn't hose something up permissions wise (I know its a terrible idea.), but same thing, failed install. This is making me feel mighty dumb, I must say... any help anyone could provide would be greatly appreciated.
  • Topics

×
×
  • Create New...

Important Information

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