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)