Jump to content

[solved] Maps - How do they render their pixels?


Draco18s

Recommended Posts

The ItemMap class is poorly deobfuscated (a lot of "l2" "j1" and so on variable names) and rather complex.

 

My new item extends ItemMap (so I don't have to duplicate the other methods) and am overriding updateMapData to build a different kind of map data.

 

My code is running and producing expected output and saving that output back to mapData.colors[], but none of it renders.

 

I started off by essentially only pulling a single pixel value per chunk (regardless of how many pixels represent that chunk) to start with, and will figure out how much of the chunk area to look at later once I have it working.

 

public void updateMapData(World world, Entity playerEnt, MapData mapData)
    {
        if (world.provider.dimensionId == mapData.dimension && playerEnt instanceof EntityPlayer)
        {
            short short1 = 128;
            short short2 = 128;
            int mapScale = 1 << mapData.scale;
            int mapxCenter = mapData.xCenter;
            int mapyCenter = mapData.zCenter;
            int mapxPos = MathHelper.floor_double(playerEnt.posX - (double)mapxCenter) / mapScale + short1 / 2;
            int mapzPos = MathHelper.floor_double(playerEnt.posZ - (double)mapyCenter) / mapScale + short2 / 2;
            int mapRadius = 128 / mapScale;

            if (world.provider.hasNoSky)
            {
                mapRadius /= 2;
            }

            MapInfo mapinfo = mapData.func_82568_a((EntityPlayer)playerEnt);
            ++mapinfo.field_82569_d;

            for (int mX = mapxPos - mapRadius + 1; mX < mapxPos + mapRadius; ++mX)
            {
                if ((mX & 15) == (mapinfo.field_82569_d & 15))
                {
                    int l1 = 255;
                    int i2 = 0;
                    double d0 = 0.0D;

                    for (int mZ = mapzPos - mapRadius - 1; mZ < mapzPos + mapRadius; ++mZ)
                    {
                        if (mX >= 0 && mZ >= -1 && mX < short1 && mZ < short2)
                        {
                            int k2 = mX - mapxPos;
                            int l2 = mZ - mapzPos;
                            //boolean flag = k2 * k2 + l2 * l2 > (mapRadius - 2) * (mapRadius - 2);
                            int chunkX = (mapxCenter / mapScale + mX - short1 / 2) * mapScale;
                            int chunkZ = (mapyCenter / mapScale + mZ - short2 / 2) * mapScale;
                            int[] aint = new int[block.blocksList.length];
                            Chunk chunk = world.getChunkFromBlockCoords(chunkX, chunkZ);

                            if (!chunk.isEmpty())
                            {
                            	int cx = chunkX & 15;
                                int cz = chunkZ & 15;

                                //loops through a chunk at mapscale
                                /*for (int ox = 0; ox < mapScale; ++ox)
                                {
                                    for (int oz = 0; oz < mapScale; ++oz)
                                    {
                                    	chunk.getHeightValue(ox + cx, oz + cz) + 1;
                                    }
                                }*/
                                
                            	//figure out what color to use
                            	//static (black) for sake of example
                            	colorIndex = 0;
                            	
                            	if(mapData.colors[mX + mZ * short1] != colorIndex) {
                            		mapData.colors[mX + mZ * short1] = colorIndex;
                            		if (l1 > mZ)
                                    {
                                        l1 = mZ;
                                    }

                                    if (i2 < mZ)
                                    {
                                        i2 = mZ;
                                    }
                                    System.out.println((chunk.xPosition+cx) + "," + (chunk.zPosition+cz) + ":" + colorIndex);
                            	}
                            }
                        }
                    }

                    if (l1 <= i2)
                    {
                        mapData.setColumnDirty(mX, l1, i2);
                    }
                }
            }
        }
    }

 

Edit:

As it turns out, it has nothing to do with that function, but the getMapData function.  It didn't like me altering how maps make themselves unique:

 

String s = "map_" + par1ItemStack.getItemDamage();

 

Which I edited to make it unique from normal maps, changing "map_" to another string.

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

The ItemMap class is poorly deobfuscated (a lot of "l2" "j1" and so on variable names) and rather complex.

 

My new item extends ItemMap (so I don't have to duplicate the other methods) and am overriding updateMapData to build a different kind of map data.

 

My code is running and producing expected output and saving that output back to mapData.colors[], but none of it renders.

 

I started off by essentially only pulling a single pixel value per chunk (regardless of how many pixels represent that chunk) to start with, and will figure out how much of the chunk area to look at later once I have it working.

 

public void updateMapData(World world, Entity playerEnt, MapData mapData)
    {
        if (world.provider.dimensionId == mapData.dimension && playerEnt instanceof EntityPlayer)
        {
            short short1 = 128;
            short short2 = 128;
            int mapScale = 1 << mapData.scale;
            int mapxCenter = mapData.xCenter;
            int mapyCenter = mapData.zCenter;
            int mapxPos = MathHelper.floor_double(playerEnt.posX - (double)mapxCenter) / mapScale + short1 / 2;
            int mapzPos = MathHelper.floor_double(playerEnt.posZ - (double)mapyCenter) / mapScale + short2 / 2;
            int mapRadius = 128 / mapScale;

            if (world.provider.hasNoSky)
            {
                mapRadius /= 2;
            }

            MapInfo mapinfo = mapData.func_82568_a((EntityPlayer)playerEnt);
            ++mapinfo.field_82569_d;

            for (int mX = mapxPos - mapRadius + 1; mX < mapxPos + mapRadius; ++mX)
            {
                if ((mX & 15) == (mapinfo.field_82569_d & 15))
                {
                    int l1 = 255;
                    int i2 = 0;
                    double d0 = 0.0D;

                    for (int mZ = mapzPos - mapRadius - 1; mZ < mapzPos + mapRadius; ++mZ)
                    {
                        if (mX >= 0 && mZ >= -1 && mX < short1 && mZ < short2)
                        {
                            int k2 = mX - mapxPos;
                            int l2 = mZ - mapzPos;
                            //boolean flag = k2 * k2 + l2 * l2 > (mapRadius - 2) * (mapRadius - 2);
                            int chunkX = (mapxCenter / mapScale + mX - short1 / 2) * mapScale;
                            int chunkZ = (mapyCenter / mapScale + mZ - short2 / 2) * mapScale;
                            int[] aint = new int[block.blocksList.length];
                            Chunk chunk = world.getChunkFromBlockCoords(chunkX, chunkZ);

                            if (!chunk.isEmpty())
                            {
                            	int cx = chunkX & 15;
                                int cz = chunkZ & 15;

                                //loops through a chunk at mapscale
                                /*for (int ox = 0; ox < mapScale; ++ox)
                                {
                                    for (int oz = 0; oz < mapScale; ++oz)
                                    {
                                    	chunk.getHeightValue(ox + cx, oz + cz) + 1;
                                    }
                                }*/
                                
                            	//figure out what color to use
                            	//static (black) for sake of example
                            	colorIndex = 0;
                            	
                            	if(mapData.colors[mX + mZ * short1] != colorIndex) {
                            		mapData.colors[mX + mZ * short1] = colorIndex;
                            		if (l1 > mZ)
                                    {
                                        l1 = mZ;
                                    }

                                    if (i2 < mZ)
                                    {
                                        i2 = mZ;
                                    }
                                    System.out.println((chunk.xPosition+cx) + "," + (chunk.zPosition+cz) + ":" + colorIndex);
                            	}
                            }
                        }
                    }

                    if (l1 <= i2)
                    {
                        mapData.setColumnDirty(mX, l1, i2);
                    }
                }
            }
        }
    }

 

Edit:

As it turns out, it has nothing to do with that function, but the getMapData function.  It didn't like me altering how maps make themselves unique:

 

String s = "map_" + par1ItemStack.getItemDamage();

 

Which I edited to make it unique from normal maps, changing "map_" to another string.

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.



×
×
  • Create New...

Important Information

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