Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6811093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:17:06+00:00 2026-05-26T20:17:06+00:00

I am attempting to make an infinite world 2d game source for the class

  • 0

I am attempting to make an infinite world 2d game

source for the class is here:

package com.blazingkin.world;
import java.util.LinkedList;
import java.util.List;

import com.blazingkin.atrox.AtroxAdventrum;

public class World {

    public World(AtroxAdventrum aa){
        chunks = new LinkedList<List<Chunk>>();
    }

    public void setBlock(int x, int y, int newBlock){

    }

    public void setMetadata(int x, int y, int newMeta){

    }
    public int getBlock(int x, int y){
        try{
            Chunk c = chunks.get(x/64 - x%64).get(y/64 - y%64);
            return c.chunk[x%64][y%64];
        }
        catch(Exception e){
            try{
            Chunk c = new Chunk(y, x/64 - x%64, y/64 - y%64);
            chunks.get(x/64 - x%64).add(y/64 - y%64 - 1, c);
            return c.chunk[x%64][y%64]; 
        }catch(Exception e1){
            Chunk c = new Chunk(y, x/64 - x%64, y/64 - y%64);
            List<Chunk> newlist = new LinkedList<Chunk>();
            System.out.println(""+x+", "+y);
            for (int i = 0; i<y/64 - y%64; i++){
                newlist.add(i, new Chunk(y - (y/64 - y%64 - i), x/64 - x%64, y/64 - y%64 - (y/64 - y%64 - i)));
            }
            newlist.add(y/64 - y%64 - 1, c);
            for (int i = 0; i<x/64 - x%64; i++){
                newlist.add(i, new Chunk(x - (x/64 - x%64 - i), x/64 - x%64, x/64 - x%64 - (x/64 - x%64 - i)));
            }
            chunks.add(x/64 - 1 - x%64, null);

            return 0;
        }
        }




    }
    public int getMetadata(int x, int y){
        return 1;
    }



    public List<List<Chunk>> chunks;

}

However, when i attempt to run this code i get the following error:

Exception in thread “main” java.lang.IndexOutOfBoundsException: Index: 23, Size: 0
at java.util.LinkedList.entry(Unknown Source)
at java.util.LinkedList.add(Unknown Source)
at com.blazingkin.world.World.getBlock(World.java:41)
at com.blazingkin.render.ScreenOutput.render(ScreenOutput.java:30)
at com.blazingkin.atrox.AtroxAdventrum.draw(AtroxAdventrum.java:34)
at com.blazingkin.atrox.Core.gameLoop(Core.java:60)
at com.blazingkin.atrox.Core.run(Core.java:27)
at com.blazingkin.atrox.AtroxAdventrum.main(AtroxAdventrum.java:14)

Any suggestions as to how i could fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:17:07+00:00Added an answer on May 26, 2026 at 8:17 pm

    A LinkedList is not a good choice for what you are trying to do. First, attempting to access elements of LinkedList by index is bad (performs O(n) instead of O(1)).

    Use:

    Map<Integer,Map<Integer,Chunk>> chunks = new HashMap<Integer,Map<Integer,Chunk>>();
    
    private void setChunk(Integer x, Integer y, Chunk c) {
        if(chunks.get(x) == null) {
            chunks.put(x, new HashMap<Integer, Chunk>());
        }
        chunks.get(x).put(y, c);
    }
    private Chunk getChunk(Integer x, Integer y) {
        if(chunks.get(x) == null)
            return null;
        return chunks.get(x).get(y);
    }
    

    In your code, you can use setChunk(1238238, -12938123, new Chunk(…)) and it will key the chunk under the x and y coordinate. To retrieve the value, use getChunk(1238238, -12938123). If no chunk exists for a given x, y, null will be returned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

You can see my project here - http://www.inluxphoto.com/custom/jsgallery/index.php I am attempting to make the
I'm attempting to make a class that holds a (in theory) infinite amount of
I'm attempting to make a tank game in java in the vein of Scorched
I'm attempting to make a simple game of Pairs for Android. Program Structure Menu.java
I'm attempting to make a simple game of Pairs for Android. Program Structure: Menu.java
I was attempting to make a simple pokemon text game in c++. I created
I am attempting to make a simple class that serializes itself to disk when
I'm attempting to make a messaging system in which any class derived from Messageable
On http://judi.simpleupdates.com/ I am attempting to make a slideshow of images on a page
I am attempting to make a full scale game for the first time and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.