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.

Saving decorations to a FilledMapItem so that it does not disappear when saving & reentering a world

Featured Replies

Posted

Hi! I'm trying to create a Mushroom Explorer Map, similar to Woodland/Ocean Explorer Maps ingame. I've got the biome searcher and mapData generator figured out, but I found that the red x disappears upon reentering a world (the rest of the mapData, like scale, xCenter, zCenter, etc, remain unchanged when reentering). I've tried saving the Decorations to the NBT tag of the map, but apparantly this does not work. Can anybody please help me save the decoration so that it remains on the map upon reentering a world?

Here's my code for the map data creator, which is called when the player crafts the map and after the target biome has been found:
(And here's my github page, if you need to reference by biome finder or MushroomExplorerMapItem class)

 public static void BiomeMapCreator(BlockPos targetPos, ItemStack stack, World world){
        ServerWorld serverWorld = (ServerWorld) world;
        MapIdTracker mapIdTracker = serverWorld.getServer().overworld().getDataStorage().computeIfAbsent(MapIdTracker::new, "idcounts");
        int nextMapId = mapIdTracker.getFreeAuxValueForMap();
        stack.getOrCreateTag().putInt("map", nextMapId);
        MapData mapData = FilledMapItem.getOrCreateSavedData(stack, world);
        mapData.setProperties(targetPos.getX(), targetPos.getZ(), 4, true, true, World.OVERWORLD);
        byte x = (byte) ((targetPos.getX() - mapData.x)/4);
        byte z = (byte) ((targetPos.getZ() - mapData.z)/4);
        MapDecoration marker = new MapDecoration(MapDecoration.Type.RED_X, x, z, (byte) 0, null);
        String markerKey = "biome_red_x";
        mapData.decorations.put(markerKey, marker);
        mapData.setDirty();
        CompoundNBT mapNBT = new CompoundNBT();
        CompoundNBT decorationNBT = new CompoundNBT();
        ListNBT decorationList = new ListNBT();
        Map.Entry<String, MapDecoration> entry = mapData.decorations.entrySet().iterator().next();
        decorationNBT.putString("id", entry.getKey());
        decorationNBT.putInt("type", 26);
        decorationNBT.putInt("x", 0);
        decorationNBT.putInt("z", 0);
        decorationNBT.putInt("rot", entry.getValue().getRot());
        decorationList.add(decorationNBT);
        stack.getOrCreateTag().put("Decorations", decorationList);
    }

 

Edited by James Zhang

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.