Jump to content

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


James Zhang

Recommended Posts

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
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



×
×
  • Create New...

Important Information

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