-
[1.16.5] How to save map item data back to server
Method "update" doesn't work when I log out and log in to world. Also World#setMapData doesn't workd either.
-
[1.16.5] How to save map item data back to server
I looked up there are no methods that "update" map data neither in MapData nor FilledMapItem.
-
[1.16.5] How to save map item data back to server
Ok I assign mapdata.colors to my new data but I just can't save it back. Is there a way without packets?
-
[1.16.5] How to save map item data back to server
public class ImageSetter extends Item { public ImageSetter(Properties properties) { super(properties); } @Override public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) { World world = Objects.requireNonNull(context.getPlayer()).getCommandSenderWorld(); PlayerEntity player = context.getPlayer(); List<Entity> itemFrames = world.getEntities(player, new AxisAlignedBB( context.getClickedPos().getX() - 2, context.getClickedPos().getY() - 2, context.getClickedPos().getZ() - 2, context.getClickedPos().getX() + 2, context.getClickedPos().getY() + 2, context.getClickedPos().getZ() + 2 )); rightClickOnItemFrame(itemFrames, world, player); return ActionResultType.PASS; } private void rightClickOnItemFrame(List<Entity> entities, World world, PlayerEntity player) { for (Entity entity : entities) { if (entity instanceof ItemFrameEntity) { if (((ItemFrameEntity) entity).getItem().getItem() instanceof FilledMapItem) { MapData mapdata = FilledMapItem.getSavedData(((ItemFrameEntity) entity).getItem(), world); SetImage setter = new SetImage("ImageName"); if (mapdata == null) return; if(!world.isClientSide) return; mapdata.colors = setter.findImageAndReturnColors(); ((FilledMapItem) ((ItemFrameEntity) entity).getItem().getItem()).update(world, player, mapdata); } } } } } Here is the ImageSetter class. When I right click it gets list of entities and then I filter out just ItemFrames, then get item inside them and check if it's FilledMapItem but update for it doesn't work. (findImageAndReturnColors just gets an image converts it to byte array it works fine)
-
[1.16.5] How to save map item data back to server
So MapData hasn't got any method called update but FilledMapItem has. It does the job it changes the map in item frame but when I hold it in my hands it changes back.
-
[1.16.5] How to save map item data back to server
Hello So here is the code MapData mapdata = FilledMapItem.getSavedData(FilledMap, world); SetImage setter = new SetImage(); if (mapdata == null) return; mapdata.colors = setter.findImageAndReturnColors(); world.setMapData(mapdata); I looked to method and turned out it is abstract. Is there any other way that I could save mapData.
-
[1.16.5] How to get item in item frame
public static void getNBTDataFromItemFrameItem(ItemFrameEntity item, World world) throws IOException { if(item.getItem().sameItem(new ItemStack(Items.FILLED_MAP))){ fileCount++; File file = new File("anything", "data" + fileCount + ".dat"); try { MapData nbt = FilledMapItem.getOrCreateSavedData(item.getItem(), world); assert nbt != null; CompressedStreamTools.writeCompressed(nbt.serializeNBT(), file); System.out.println("done"); } catch (Exception e) { e.printStackTrace(); } } } Now I just get error that it cant serialize the data java.lang.NullPointerException [19:59:33] [Render thread/INFO] [STDERR/]: [me.hakak.entityfindmod.commands.findItemFrames:getNBTDataFromItemFrameItem:63]: at net.minecraft.world.storage.MapData.save(MapData.java:160) [19:59:33] [Render thread/INFO] [STDERR/]: [me.hakak.entityfindmod.commands.findItemFrames:getNBTDataFromItemFrameItem:63]: at net.minecraft.world.storage.WorldSavedData.serializeNBT(WorldSavedData.java:63) [19:59:33] [Render thread/INFO] [STDERR/]: [me.hakak.entityfindmod.commands.findItemFrames:getNBTDataFromItemFrameItem:63]: at me.hakak.entityfindmod.commands.findItemFrames.getNBTDataFromItemFrameItem(findItemFrames.java:60)
-
[1.16.5] How to get item in item frame
So how do I get the data. Is there other way?
-
[1.16.5] How to get item in item frame
I just need that for getting the image from map itself. I get the nbt data then get the image.
-
[1.16.5] How to get item in item frame
Here is the code List<Entity> itemFrames = world.getEntities(player, axisalignedBB); for (Entity entity: itemFrames) { if(entity.getType() == EntityType.ITEM_FRAME){ ItemFrameEntity Item_Frame = (ItemFrameEntity) entity; getNBTDataFromItemFrameItem(Item_Frame, file); } } And here is the getNBTDataFromItemFrameItem public static void getNBTDataFromItemFrameItem(ItemFrameEntity item, File file) throws IOException { if(item.getItem().sameItem(new ItemStack(Items.FILLED_MAP))){ Item map_item = item.getItem().getItem(); CompoundNBT nbt = map_item.getDefaultInstance().serializeNBT(); CompressedStreamTools.writeCompressed(nbt, file); } } But I have a problem with getting the nbt data of map item.
-
[1.16.5] How to get item in item frame
I had already found the entities and had list of them. I casted because ItemFrameEntity had getItem function and with that I found the item.
-
[1.16.5] How to get item in item frame
Oh thanks now I got it ItemFrameEntity has getItem function so I had to just cast it to ItemFrameEntity.
-
[1.16.5] How to get item in item frame
Yes I understand. I found entities and I have the list of them. They are Entity type.
-
[1.16.5] How to get item in item frame
Hi I'm new to mod programming. I am making mod where you need to get map that is in item frame. Now I just need to get the map and then grab it's NBT data but I can't get the item in item frame.
IPS spam blocked by CleanTalk.