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

Hi,

 

i'm trying to create a custom FilledMapItem which are filled with one color.

When I had one map (white) everything worked fine. The problem is that after creating a second map both maps appear the same and are flickering with white and black colors.

I don't know where else to search for help with this :/

 

package com.example.examplemod;

import net.minecraft.block.material.MaterialColor;
import net.minecraft.entity.Entity;
import net.minecraft.item.FilledMapItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.storage.MapData;

public class ModImageMapItem extends FilledMapItem {
   public ModImageMapItem(Item.Properties builder) {
	      super(builder);
   }

   protected MapData getCustomMapData(ItemStack stack, World worldIn) {
      MapData mapdata = func_219994_a(stack, worldIn);
      if (mapdata == null && !worldIn.isRemote) {
         mapdata = createMapData(stack, worldIn, worldIn.getWorldInfo().getSpawnX(), worldIn.getWorldInfo().getSpawnZ(), 3, false, false, worldIn.dimension.getType());
      }

      drawMyMap(worldIn, null, mapdata, this);      
      return mapdata;
   }

   private static MapData createMapData(ItemStack p_195951_0_, World p_195951_1_, int p_195951_2_, int p_195951_3_, int p_195951_4_, boolean p_195951_5_, boolean p_195951_6_, DimensionType p_195951_7_) {
      int i = p_195951_1_.getNextMapId();
      MapData mapdata = new MapData(func_219993_a(i));
      mapdata.func_212440_a(p_195951_2_, p_195951_3_, p_195951_4_, p_195951_5_, p_195951_6_, p_195951_7_);
      p_195951_1_.func_217399_a(mapdata);
      p_195951_0_.getOrCreateTag().putInt("map", i);
      
      return mapdata;
   }

   public void updateMapData(World worldIn, Entity viewer, MapData mapdata) {
	   drawMyMap(worldIn, viewer, mapdata, this);
   }
   
   private static void drawMyMap(World worldIn, Entity viewer, MapData mapdata, ModImageMapItem item) {
	  byte bColor = 0;
	  
      if (item.getName().toString().contains("item.poison64.image_map_white")) {
	      bColor = (byte)(MaterialColor.SNOW.colorIndex*4+2); 
      } else if (item.getName().toString().contains("item.poison64.image_map_black")) {
	      bColor = (byte)(MaterialColor.BLACK.colorIndex*4+2);  
      }

	   for(int x=0;x<128;x++) {
	      for(int y=0;y<128;y++) {
	    	  mapdata.colors[y*128+x] = bColor;  
	    	  mapdata.updateMapData(x, y);
	      }
      }
      mapdata.mapDecorations.clear();
      mapdata.trackingPosition = false;
      mapdata.markDirty();
   }
}

 

   new ModImageMapItem(new Item.Properties().group(ItemGroup.MISC).rarity(Rarity.RARE)).setRegistryName("poison64", "image_map_white"),
   new ModImageMapItem(new Item.Properties().group(ItemGroup.MISC).rarity(Rarity.RARE)).setRegistryName("poison64", "image_map_black")

 

Thanks in advance,

poison64

Edited by poison64

49 minutes ago, poison64 said:

item.getName().toString().contains("item.poison64.image_map_white")

This is not good code, but this isn't the source of your problem. Never covert things to strings in order to compare them, it makes your code incredibly stringly typed and impossible to refactor.

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.

  • Author
1 minute ago, Draco18s said:

This is not good code, but this isn't the source of your problem. Never covert things to strings in order to compare them, it makes your code incredibly stringly typed and impossible to refactor.

I'm aware of that, it's just a proof of concept. I had enums defining type in constructor before.

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.