Jump to content

I need some help figuring out this java.lang.ArrayIndexOutOfBoundsException: 4


TheRPGAdventurer

Recommended Posts

I googled this before and it say that happens if you are calling an array in a restricted 

 

EnumDragonLifeStage: https://pastebin.com/RhcFuqw9

 

Crash

java.lang.ArrayIndexOutOfBoundsException: 4
	at com.TheRPGAdventurer.ROTD.server.entity.helper.EnumDragonLifeStage.fromTickCount(EnumDragonLifeStage.java:31)
	at com.TheRPGAdventurer.ROTD.server.entity.helper.DragonLifeStageHelper.getLifeStage(DragonLifeStageHelper.java:128)
	at com.TheRPGAdventurer.ROTD.server.entity.helper.DragonLifeStageHelper.updateLifeStage(DragonLifeStageHelper.java:278)
	at com.TheRPGAdventurer.ROTD.server.entity.helper.DragonLifeStageHelper.onLivingUpdate(DragonLifeStageHelper.java:267)
	at java.util.HashMap$Values.forEach(HashMap.java:972)
	at com.TheRPGAdventurer.ROTD.server.entity.EntityTameableDragon.func_70636_d(EntityTameableDragon.java:923)
	at net.minecraft.entity.EntityLivingBase.func_70071_h_(EntityLivingBase.java:2179)
	at net.minecraft.entity.EntityLiving.func_70071_h_(EntityLiving.java:295)
	at com.TheRPGAdventurer.ROTD.server.entity.EntityTameableDragon.func_70071_h_(EntityTameableDragon.java:847)
	at net.minecraft.world.World.func_72866_a(World.java:1993)
	at net.minecraft.world.WorldServer.func_72866_a(WorldServer.java:832)
	at net.minecraft.world.World.func_72870_g(World.java:1955)
	at net.minecraft.world.World.func_72939_s(World.java:1759)
	at net.minecraft.world.WorldServer.func_72939_s(WorldServer.java:613)
	at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:767)
	at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:668)
	at net.minecraft.server.integrated.IntegratedServer.func_71217_p(IntegratedServer.java:185)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526)
	at java.lang.Thread.run(Thread.java:745)

To be fair i didnt write thi code thi wa written years ago im here to revive it.

Edited by TheRPGAdventurer
Link to comment
Share on other sites

    public static int clampTickCount(int ticksSinceCreation) {
        return MathHelper.clamp(ticksSinceCreation, 0, VALUES.length * TICKS_PER_STAGE);
    }
 
    public static EnumDragonLifeStage fromTickCount(int ticksSinceCreation) {
        return VALUES[clampTickCount(ticksSinceCreation) / TICKS_PER_STAGE];
    }

Your enum has only 4 elements; therefore, the maximum value for the index can only be 3.

However, in your clampTickCount, it clamps the value as if there are 5 elements in your enum (hint: off by one). 

 

Note that MathHelper#clamp is inclusive on both the min value and the max value.

Edited by DavidM

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

VALUES.length is equal to 4, which, after multiplying and dividing by the same constant, still equals to 4.

 

Let's say we set the TICKS_PER_STAGE constant to 10, in which case

VALUES.length * TICKS_PER_STAGE

equals to 40.

40 divided by TICKS_PER_STAGE (10 in this case) is 4, which is out of bound for your enum.

 

However, if you change the return statement in your clampTickCount to:

return MathHelper.clamp(ticksSinceCreation, 0, (VALUES.length * TICKS_PER_STAGE) - 1);

, it will clamp everything into the range of [0, 39].

Now, the maximum return value is 39, which, after being divided by TICKS_PER_STAGE (10 in this case), is 3. This matches the highest dragon growth stage in your enum.

 

TL;DR:

Spoiler

Change your return statement in your clampTickCount to:


return MathHelper.clamp(ticksSinceCreation, 0, (VALUES.length * TICKS_PER_STAGE) - 1);

 

 

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

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

    • S1288POKER Rasakan sensasi bertaruh Mix Parlay yang tak terlupakan dengan bonus fantastis di situs judi terpercaya kami! Kami menawarkan bonus Mix Parlay terbesar di Asia dengan berbagai pilihan taruhan dan minimal deposit rendah. Dapatkan bonus hingga jutaan rupiah untuk taruhan Mix Parlay Anda dan nikmati keuntungan berlipat ganda.
    • Situs Akun Pro Peru adalah pilihan terbaik bagi Anda yang mencari situs terpercaya untuk bermain slot dan taruhan bola. Berikut adalah beberapa alasan mengapa Anda harus memilih Situs Akun Pro Peru: Slot Populer Kami menyajikan koleksi slot yang populer dan menarik dengan berbagai tema yang beragam. Dari slot klasik hingga slot video modern, setiap pemain dapat menemukan permainan favorit mereka dengan mudah. Taruhan Bola Terpercaya Selain slot, kami juga menyediakan taruhan bola dengan pasaran terlengkap dan odds yang kompetitif. Dengan berbagai pertandingan dan liga yang tersedia, Anda dapat menikmati pengalaman taruhan bola yang seru dan menguntungkan. Transaksi Mudah dengan Bank BTN Kami menyediakan layanan transaksi yang mudah dan aman melalui Bank BTN. Dengan dukungan dari sistem pembayaran yang terpercaya, Anda dapat melakukan deposit dan penarikan dana dengan cepat dan tanpa hambatan.  
    • Ngamenslot adalah pilihan terbaik bagi Anda yang mencari situs terpercaya untuk bermain slot dan taruhan bola. Berikut adalah beberapa alasan mengapa Anda harus memilih Ngamenslot: Kombinasi Slot & Bola Kami menyajikan kombinasi terbaik antara permainan slot yang seru dan taruhan bola yang menegangkan. Dengan pilihan permainan yang beragam, setiap pemain dapat menikmati pengalaman bermain yang unik dan menyenangkan. Transaksi Mudah melalui Bank Ekonomi Kami menyediakan layanan transaksi yang mudah dan aman melalui Bank Ekonomi. Dengan dukungan dari sistem pembayaran yang terpercaya, Anda dapat melakukan deposit dan penarikan dana dengan cepat dan tanpa hambatan. Terpercaya dan Terjamin Ngamenslot telah terbukti sebagai situs terpercaya dengan ribuan pemain yang puas. Kami mengutamakan keamanan dan kenyamanan para pemain, sehingga Anda dapat bermain dengan tenang dan fokus pada permainan.  
    • Tambang88 adalah pilihan terbaik bagi Anda yang mencari pengalaman bermain slot gacor dengan transaksi mudah menggunakan Bank Sinarmas. Berikut adalah beberapa alasan mengapa Anda harus memilih Tambang88: Raja Slot Gacor Kami merupakan raja slot gacor dengan koleksi permainan terbaik yang menawarkan kesenangan bermain dan peluang kemenangan besar. Dengan fitur-fitur unggulan dan tema-tema menarik, setiap putaran permainan akan memberikan Anda pengalaman yang tak terlupakan. Transaksi Mudah dengan Bank Sinarmas Kami menyediakan layanan transaksi mudah melalui Bank Sinarmas untuk kenyamanan dan keamanan Anda. Dengan proses yang cepat dan efisien, Anda dapat melakukan deposit dan penarikan dana dengan lancar dan tanpa hambatan. Profesional dan Menguntungkan Tambang88 mengutamakan profesionalitas dalam memberikan layanan kepada para pemainnya. Kami juga menawarkan kesempatan untuk meraih keuntungan yang besar dengan jackpot dan hadiah-hadiah menarik lainnya.    
    • TRIK POLA SL0T GAC0R MAHJONG WAYS 1 DAN 2 HARI INI Sekarang Anda dapat meningkatkan peluang Bermain dengan langsung menggunakan situs resmi dari permainan Mahjong (PG SOFT). Cukup daftar dan siapkan hanya mulai dari 50K hingga 200K, Anda sudah memiliki peluang untuk memenangkan hadiah besar. Jika tidak memiliki dana sebanyak itu, Anda dapat mencoba dengan dana 50K dan memanfaatkan bonus member baru untuk menambah modal. Berikut adalah Situs Resmi Mahjong yang dapat Anda kunjungi: >> SITUS RESMI MAHJONG YANG TERBUKTI << >> SITUS RESMI MAHJONG YANG TERBUKTI << Setelah mendaftar, Anda dapat menggunakan pola yang sering saya gunakan: 🔥 25 Manual TURBO OFF 🔥 15 Manual TURBO ON 🔥 30 Auto TURBO OFF 🔥 10 Manual TURBO ON Pola ini biasanya memberikan hasil yang konsisten.
  • Topics

×
×
  • Create New...

Important Information

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